MCPcopy
hub / github.com/simstudioai/sim / buildOnComplete

Function buildOnComplete

apps/sim/lib/copilot/chat/post.ts:419–510  ·  view source on GitHub ↗
(params: {
  chatId?: string
  userMessageId: string
  requestId: string
  workspaceId?: string
  notifyWorkspaceStatus: boolean
  /**
   * Root agent span for this request. When present, the final
   * assistant message + invoked tool calls are recorded as
   * `gen_ai.output.messages` on it before persistence runs. Keeps
   * the Honeycomb Gen AI view complete across both the Sim root
   * span and the Go-side `llm.stream` spans.
   */
  otelRoot?: {
    setOutputMessages: (output: {
      assistantText?: string
      toolCalls?: Array<{ id: string; name: string; arguments?: Record<string, unknown> }>
    }) => void
  }
})

Source from the content-addressed store, hash-verified

417}
418
419function buildOnComplete(params: {
420 chatId?: string
421 userMessageId: string
422 requestId: string
423 workspaceId?: string
424 notifyWorkspaceStatus: boolean
425 /**
426 * Root agent span for this request. When present, the final
427 * assistant message + invoked tool calls are recorded as
428 * `gen_ai.output.messages` on it before persistence runs. Keeps
429 * the Honeycomb Gen AI view complete across both the Sim root
430 * span and the Go-side `llm.stream` spans.
431 */
432 otelRoot?: {
433 setOutputMessages: (output: {
434 assistantText?: string
435 toolCalls?: Array<{ id: string; name: string; arguments?: Record<string, unknown> }>
436 }) => void
437 }
438}) {
439 const { chatId, userMessageId, requestId, workspaceId, notifyWorkspaceStatus, otelRoot } = params
440
441 return async (result: OrchestratorResult) => {
442 if (otelRoot && result.success) {
443 otelRoot.setOutputMessages({
444 assistantText: result.content,
445 toolCalls: result.toolCalls?.map((tc) => ({
446 id: tc.id,
447 name: tc.name,
448 arguments: tc.params,
449 })),
450 })
451 }
452
453 if (!chatId) return
454
455 try {
456 if (result.cancelled) {
457 const finalization = await finalizeAssistantTurn({
458 chatId,
459 userMessageId,
460 assistantMessage: withStoppedContentBlock(
461 buildPersistedAssistantMessage(result, requestId)
462 ),
463 streamMarkerPolicy: 'active-or-cleared',
464 })
465 const shouldPublishCompletion =
466 finalization.updated ||
467 finalization.outcome === CopilotChatFinalizeOutcome.AssistantAlreadyPersisted
468
469 if (notifyWorkspaceStatus && workspaceId && shouldPublishCompletion) {
470 chatPubSub?.publishStatusChanged({
471 workspaceId,
472 chatId,
473 type: 'completed',
474 streamId: userMessageId,
475 })
476 }

Callers 1

handleUnifiedChatPostFunction · 0.85

Calls 5

finalizeAssistantTurnFunction · 0.90
withStoppedContentBlockFunction · 0.90
getErrorMessageFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected