chore: import upstream snapshot with attribution
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import {
|
||||
MothershipStreamV1ToolOutcome,
|
||||
type MothershipStreamV1ToolOutcome as TerminalToolCallStatus,
|
||||
} from '@/lib/copilot/generated/mothership-stream-v1'
|
||||
import type { ToolCallState, ToolCallStateResult } from '@/lib/copilot/request/types'
|
||||
|
||||
function hasOwnOutput(value: { output?: unknown }): value is { output: unknown } {
|
||||
return Object.hasOwn(value, 'output')
|
||||
}
|
||||
|
||||
export function isSuccessfulToolCallStatus(status: TerminalToolCallStatus): boolean {
|
||||
return (
|
||||
status === MothershipStreamV1ToolOutcome.success ||
|
||||
status === MothershipStreamV1ToolOutcome.skipped
|
||||
)
|
||||
}
|
||||
|
||||
export function createToolCallStateResult(input: {
|
||||
success: boolean
|
||||
output?: unknown
|
||||
}): ToolCallStateResult {
|
||||
return hasOwnOutput(input)
|
||||
? { success: input.success, output: input.output }
|
||||
: { success: input.success }
|
||||
}
|
||||
|
||||
export function getToolCallStateOutput(toolCall: Pick<ToolCallState, 'result'>): unknown {
|
||||
if (!toolCall.result || !hasOwnOutput(toolCall.result)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return toolCall.result.output
|
||||
}
|
||||
|
||||
export function requireToolCallStateResult(
|
||||
toolCall: Pick<ToolCallState, 'id' | 'status' | 'result'>
|
||||
): ToolCallStateResult {
|
||||
if (toolCall.result) {
|
||||
return toolCall.result
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Terminal tool call ${toolCall.id} is missing a canonical result for status ${toolCall.status}`
|
||||
)
|
||||
}
|
||||
|
||||
export function requireToolCallError(
|
||||
toolCall: Pick<ToolCallState, 'id' | 'status' | 'error'>
|
||||
): string {
|
||||
if (typeof toolCall.error === 'string' && toolCall.error.length > 0) {
|
||||
return toolCall.error
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Terminal tool call ${toolCall.id} is missing a canonical error for status ${toolCall.status}`
|
||||
)
|
||||
}
|
||||
|
||||
export function getToolCallTerminalData(
|
||||
toolCall: Pick<ToolCallState, 'id' | 'status' | 'result' | 'error'>
|
||||
): unknown {
|
||||
const output = getToolCallStateOutput(toolCall)
|
||||
if (output !== undefined) {
|
||||
return output
|
||||
}
|
||||
|
||||
if (
|
||||
toolCall.status === MothershipStreamV1ToolOutcome.success ||
|
||||
toolCall.status === MothershipStreamV1ToolOutcome.skipped
|
||||
) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return { error: requireToolCallError(toolCall) }
|
||||
}
|
||||
|
||||
export function setTerminalToolCallState(
|
||||
toolCall: ToolCallState,
|
||||
input: {
|
||||
status: TerminalToolCallStatus
|
||||
output?: unknown
|
||||
error?: string
|
||||
endTime?: number
|
||||
}
|
||||
): void {
|
||||
const success = isSuccessfulToolCallStatus(input.status)
|
||||
toolCall.status = input.status
|
||||
toolCall.endTime = input.endTime ?? Date.now()
|
||||
toolCall.result = createToolCallStateResult({
|
||||
success,
|
||||
...(Object.hasOwn(input, 'output') ? { output: input.output } : {}),
|
||||
})
|
||||
|
||||
if (success) {
|
||||
toolCall.error = undefined
|
||||
return
|
||||
}
|
||||
|
||||
toolCall.error = requireToolCallError({
|
||||
id: toolCall.id,
|
||||
status: input.status,
|
||||
error: input.error,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user