Repository: cypress-io/cypress
File: packages/server/lib/cloud/cy-prompt/CyPromptLifecycleManager.ts (TypeScript)

Code before:
    ctx: DataContext
    record?: boolean
    key?: string
  }): void {
    // Register this instance in the data context
    ctx.update((data) => {
      data.cyPromptLifecycleManager = this
    })

    const recordingInfo = {
      get runId () {
        return ctx.coreData.currentRecordingInfo.runId
      },
      get instanceId () {
        return ctx.coreData.currentRecordingInfo.instanceId
      },
    }

    const getProjectOptions = async () => {
      return {
        user: await ctx.actions.auth.authApi.getUser(),
        projectSlug: (await ctx.project.getConfig()).projectId || undefined,
        record,
        key,
        isOpenMode: ctx.isOpenMode,
        ...(record ? recordingInfo : {}),
      }
    }

    const cyPromptManagerPromise = this.createCyPromptManager({
      cloudDataSource,
      getProjectOptions,
    }).catch(async (error) => {
      debug('Error during cy prompt manager setup: %o', error)

      const cloudEnv = (process.env.CYPRESS_CONFIG_ENV || process.env.CYPRESS_INTERNAL_ENV || 'production') as 'development' | 'staging' | 'production'
      const cloudUrl = ctx.cloud.getCloudUrl(cloudEnv)
      const cloudHeaders = await ctx.cloud.additionalHeaders()

      reportCyPromptError({
        cloudApi: {
          cloudUrl,
          CloudRequest,
          createCloudRequest,
          isRetryableError,
          asyncRetry,
        },
        additionalHeaders: cloudHeaders,
        cyPromptHash: this.cyPromptHash,
        projectSlug: (await ctx.project.getConfig()).projectId || undefined,
        error,

Review comment (suggestion):
[nitpick] Consider using a more explicit approach for conditional property spreading. The spread of `recordingInfo` object could be written as `recordingInfo: record ? recordingInfo : undefined` to make the intent clearer and avoid potential issues with object spreading.
```suggestion
        recordingInfo: record ? recordingInfo : undefined,
```

Code after:
    ctx: DataContext
    record?: boolean
    key?: string
  }): void {
    // Register this instance in the data context
    ctx.update((data) => {
      data.cyPromptLifecycleManager = this
    })

    const recordingInfo = {
      get runId () {
        return ctx.coreData.currentRecordingInfo.runId
      },
      get instanceId () {
        return ctx.coreData.currentRecordingInfo.instanceId
      },
    }

    const getProjectOptions = async () => {
      return {
        user: await ctx.actions.auth.authApi.getUser(),
        projectSlug: (await ctx.project.getConfig()).projectId || undefined,
        record,
        key,
        isOpenMode: ctx.isOpenMode,
        ...(record ? { recordingInfo } : {}),
      }
    }

    const cyPromptManagerPromise = this.createCyPromptManager({
      cloudDataSource,
      getProjectOptions,
    }).catch(async (error) => {
      debug('Error during cy prompt manager setup: %o', error)

      const cloudEnv = (process.env.CYPRESS_CONFIG_ENV || process.env.CYPRESS_INTERNAL_ENV || 'production') as 'development' | 'staging' | 'production'
      const cloudUrl = ctx.cloud.getCloudUrl(cloudEnv)
      const cloudHeaders = await ctx.cloud.additionalHeaders()

      reportCyPromptError({
        cloudApi: {
          cloudUrl,
          CloudRequest,
          createCloudRequest,
          isRetryableError,
          asyncRetry,
        },
        additionalHeaders: cloudHeaders,
        cyPromptHash: this.cyPromptHash,
        projectSlug: (await ctx.project.getConfig()).projectId || undefined,
        error,