(input: {
requestPayload: Record<string, unknown>
userId: string
workflowId?: string
workspaceId?: string
chatId?: string
executionId?: string
runId?: string
messageId: string
})
| 929 | } |
| 930 | |
| 931 | async function ensureHeadlessRunIdentity(input: { |
| 932 | requestPayload: Record<string, unknown> |
| 933 | userId: string |
| 934 | workflowId?: string |
| 935 | workspaceId?: string |
| 936 | chatId?: string |
| 937 | executionId?: string |
| 938 | runId?: string |
| 939 | messageId: string |
| 940 | }): Promise<{ executionId?: string; runId?: string }> { |
| 941 | if (!input.chatId || input.executionId || input.runId) { |
| 942 | return { |
| 943 | executionId: input.executionId, |
| 944 | runId: input.runId, |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | const executionId = generateId() |
| 949 | const runId = generateId() |
| 950 | |
| 951 | try { |
| 952 | await createRunSegment({ |
| 953 | id: runId, |
| 954 | executionId, |
| 955 | chatId: input.chatId, |
| 956 | userId: input.userId, |
| 957 | workflowId: input.workflowId, |
| 958 | workspaceId: input.workspaceId, |
| 959 | streamId: input.messageId, |
| 960 | model: typeof input.requestPayload?.model === 'string' ? input.requestPayload.model : null, |
| 961 | provider: |
| 962 | typeof input.requestPayload?.provider === 'string' ? input.requestPayload.provider : null, |
| 963 | requestContext: { |
| 964 | source: 'headless_lifecycle', |
| 965 | }, |
| 966 | }) |
| 967 | return { executionId, runId } |
| 968 | } catch (error) { |
| 969 | logger.warn('Failed to create headless run identity', { |
| 970 | chatId: input.chatId, |
| 971 | messageId: input.messageId, |
| 972 | error: toError(error).message, |
| 973 | }) |
| 974 | return {} |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | // --------------------------------------------------------------------------- |
| 979 | // Helpers |
no test coverage detected