( requestPayload: Record<string, unknown>, options: CopilotLifecycleOptions )
| 79 | } |
| 80 | |
| 81 | export async function runCopilotLifecycle( |
| 82 | requestPayload: Record<string, unknown>, |
| 83 | options: CopilotLifecycleOptions |
| 84 | ): Promise<OrchestratorResult> { |
| 85 | const { |
| 86 | userId, |
| 87 | workflowId, |
| 88 | workspaceId, |
| 89 | chatId, |
| 90 | executionId, |
| 91 | runId, |
| 92 | goRoute = '/api/copilot', |
| 93 | } = options |
| 94 | const payloadMsgId = |
| 95 | typeof requestPayload?.messageId === 'string' ? requestPayload.messageId : generateId() |
| 96 | const runIdentity = await ensureHeadlessRunIdentity({ |
| 97 | requestPayload, |
| 98 | userId, |
| 99 | workflowId, |
| 100 | workspaceId, |
| 101 | chatId, |
| 102 | executionId, |
| 103 | runId, |
| 104 | messageId: payloadMsgId, |
| 105 | }) |
| 106 | const resolvedExecutionId = runIdentity.executionId ?? executionId |
| 107 | const resolvedRunId = runIdentity.runId ?? runId |
| 108 | const lifecycleOptions: CopilotLifecycleOptions = { |
| 109 | ...options, |
| 110 | executionId: resolvedExecutionId, |
| 111 | runId: resolvedRunId, |
| 112 | ...(options.executionContext |
| 113 | ? { |
| 114 | executionContext: { |
| 115 | ...options.executionContext, |
| 116 | messageId: payloadMsgId, |
| 117 | executionId: resolvedExecutionId, |
| 118 | runId: resolvedRunId, |
| 119 | abortSignal: options.abortSignal, |
| 120 | }, |
| 121 | } |
| 122 | : {}), |
| 123 | } |
| 124 | |
| 125 | const execContext = |
| 126 | lifecycleOptions.executionContext ?? |
| 127 | (await buildExecutionContext(requestPayload, { |
| 128 | userId, |
| 129 | workflowId, |
| 130 | workspaceId, |
| 131 | chatId, |
| 132 | executionId: resolvedExecutionId, |
| 133 | runId: resolvedRunId, |
| 134 | abortSignal: lifecycleOptions.abortSignal, |
| 135 | })) |
| 136 | |
| 137 | const context = createStreamingContext({ |
| 138 | chatId, |
no test coverage detected