MCPcopy Index your code
hub / github.com/simstudioai/sim / ensureHeadlessRunIdentity

Function ensureHeadlessRunIdentity

apps/sim/lib/copilot/request/lifecycle/run.ts:931–976  ·  view source on GitHub ↗
(input: {
  requestPayload: Record<string, unknown>
  userId: string
  workflowId?: string
  workspaceId?: string
  chatId?: string
  executionId?: string
  runId?: string
  messageId: string
})

Source from the content-addressed store, hash-verified

929}
930
931async 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

Callers 1

runCopilotLifecycleFunction · 0.85

Calls 4

generateIdFunction · 0.90
createRunSegmentFunction · 0.90
toErrorFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected