d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
53 lines
2.4 KiB
TypeScript
53 lines
2.4 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { MothershipStreamV1EventType } from '@/lib/copilot/generated/mothership-stream-v1'
|
|
import type { StreamEvent, StreamingContext } from '@/lib/copilot/request/types'
|
|
import { handleCompleteEvent } from './complete'
|
|
import { handleErrorEvent } from './error'
|
|
import { handleResourceEvent } from './resource'
|
|
import { handleRunEvent } from './run'
|
|
import { handleSessionEvent } from './session'
|
|
import { handleSpanEvent } from './span'
|
|
import { handleTextEvent } from './text'
|
|
import { handleToolEvent, prePersistClientExecutableToolCall } from './tool'
|
|
import type { StreamHandler } from './types'
|
|
|
|
export { prePersistClientExecutableToolCall }
|
|
export type { StreamHandler } from './types'
|
|
|
|
const logger = createLogger('CopilotHandlerRouting')
|
|
|
|
export const sseHandlers: Record<string, StreamHandler> = {
|
|
[MothershipStreamV1EventType.session]: handleSessionEvent,
|
|
[MothershipStreamV1EventType.tool]: (e, c, ec, o) => handleToolEvent(e, c, ec, o, 'main'),
|
|
[MothershipStreamV1EventType.text]: handleTextEvent('main'),
|
|
[MothershipStreamV1EventType.resource]: handleResourceEvent,
|
|
[MothershipStreamV1EventType.run]: handleRunEvent,
|
|
[MothershipStreamV1EventType.complete]: handleCompleteEvent,
|
|
[MothershipStreamV1EventType.error]: handleErrorEvent,
|
|
[MothershipStreamV1EventType.span]: handleSpanEvent,
|
|
}
|
|
|
|
export const subAgentHandlers: Record<string, StreamHandler> = {
|
|
[MothershipStreamV1EventType.text]: handleTextEvent('subagent'),
|
|
[MothershipStreamV1EventType.tool]: (e, c, ec, o) => handleToolEvent(e, c, ec, o, 'subagent'),
|
|
[MothershipStreamV1EventType.span]: handleSpanEvent,
|
|
}
|
|
|
|
export function handleSubagentRouting(event: StreamEvent, _context: StreamingContext): boolean {
|
|
if (event.scope?.lane !== 'subagent') return false
|
|
|
|
// Scope-only attribution: a subagent event MUST carry its own parentToolCallId.
|
|
// With concurrent subagents there is no single "current" lane to fall back to —
|
|
// routing by a global pointer would mis-attribute interleaved events to the
|
|
// last-started subagent. A missing parentToolCallId is a contract violation
|
|
// (Go always stamps it), so warn and route to the main lane rather than guess.
|
|
if (!event.scope?.parentToolCallId) {
|
|
logger.warn('Subagent event missing parent tool call id; routing to main lane', {
|
|
type: event.type,
|
|
subagent: event.scope?.agentId,
|
|
})
|
|
return false
|
|
}
|
|
return true
|
|
}
|