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

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

    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: {
            runId: ctx.coreData.currentRecordingInfo.runId,
            instanceId: ctx.coreData.currentRecordingInfo.instanceId,
          },
        } : {}),
      }
    }

    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 (refactor):
[nitpick] The conditional spread operator with nested object structure makes the code harder to read. Consider extracting this logic into a separate function or simplifying the conditional assignment.
```suggestion
        ...this.getRecordingInfo(record, ctx),
```

Code after:
    record,
    key,
  }: {
    cloudDataSource: CloudDataSource
    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,
        },