@trigger.dev/sdk 0.0.0-python-preview-20250226140121 → 0.0.0-rc-4-8-0-20261021151928
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -9
- package/dist/commonjs/imports/ai-runtime-cjs.cjs.map +1 -0
- package/dist/commonjs/imports/ai-runtime.d.ts +1 -0
- package/dist/commonjs/imports/ai-runtime.js +31 -0
- package/dist/commonjs/imports/uncrypto.js +4 -4
- package/dist/commonjs/package.json +2 -1
- package/dist/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js +173 -0
- package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/commonjs/v3/ai-shared.d.ts +156 -0
- package/dist/commonjs/v3/ai-shared.js +215 -0
- package/dist/commonjs/v3/ai-shared.js.map +1 -0
- package/dist/commonjs/v3/ai.d.ts +4225 -0
- package/dist/commonjs/v3/ai.js +11569 -0
- package/dist/commonjs/v3/ai.js.map +1 -0
- package/dist/commonjs/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js +81 -0
- package/dist/commonjs/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/commonjs/v3/auth.d.ts +71 -10
- package/dist/commonjs/v3/auth.js +85 -19
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/batch.d.ts +3 -3
- package/dist/commonjs/v3/batch.js.map +1 -1
- package/dist/commonjs/v3/cache.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +324 -0
- package/dist/commonjs/v3/chat-client.js +774 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -0
- package/dist/commonjs/v3/chat-react.d.ts +244 -0
- package/dist/commonjs/v3/chat-react.js +463 -0
- package/dist/commonjs/v3/chat-react.js.map +1 -0
- package/dist/commonjs/v3/chat-server.d.ts +350 -0
- package/dist/commonjs/v3/chat-server.js +965 -0
- package/dist/commonjs/v3/chat-server.js.map +1 -0
- package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
- package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/commonjs/v3/chat.d.ts +792 -0
- package/dist/commonjs/v3/chat.js +1662 -0
- package/dist/commonjs/v3/chat.js.map +1 -0
- package/dist/commonjs/v3/chatRouteWait.d.ts +21 -0
- package/dist/commonjs/v3/chatRouteWait.js +43 -0
- package/dist/commonjs/v3/chatRouteWait.js.map +1 -0
- package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/commonjs/v3/chatSnapshotIo.js +173 -0
- package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
- package/dist/commonjs/v3/chatVersionSkew.d.ts +12 -0
- package/dist/commonjs/v3/chatVersionSkew.js +30 -0
- package/dist/commonjs/v3/chatVersionSkew.js.map +1 -0
- package/dist/commonjs/v3/compactionResponse.d.ts +9 -0
- package/dist/commonjs/v3/compactionResponse.js +37 -0
- package/dist/commonjs/v3/compactionResponse.js.map +1 -0
- package/dist/commonjs/v3/concurrency-shared.d.ts +13 -0
- package/dist/commonjs/v3/concurrency-shared.js +35 -0
- package/dist/commonjs/v3/concurrency-shared.js.map +1 -0
- package/dist/commonjs/v3/concurrencyLimits.d.ts +103 -0
- package/dist/commonjs/v3/concurrencyLimits.js +134 -0
- package/dist/commonjs/v3/concurrencyLimits.js.map +1 -0
- package/dist/commonjs/v3/config.js.map +1 -1
- package/dist/commonjs/v3/deployments.d.ts +25 -0
- package/dist/commonjs/v3/deployments.js +37 -0
- package/dist/commonjs/v3/deployments.js.map +1 -0
- package/dist/commonjs/v3/envvars.d.ts +5 -5
- package/dist/commonjs/v3/envvars.js.map +1 -1
- package/dist/commonjs/v3/externalDeploymentId.d.ts +23 -0
- package/dist/commonjs/v3/externalDeploymentId.js +43 -0
- package/dist/commonjs/v3/externalDeploymentId.js.map +1 -0
- package/dist/commonjs/v3/heartbeats.d.ts +37 -0
- package/dist/commonjs/v3/heartbeats.js +45 -0
- package/dist/commonjs/v3/heartbeats.js.map +1 -0
- package/dist/commonjs/v3/hooks.d.ts +26 -0
- package/dist/commonjs/v3/hooks.js +79 -0
- package/dist/commonjs/v3/hooks.js.map +1 -0
- package/dist/commonjs/v3/idempotencyKeys.d.ts +2 -1
- package/dist/commonjs/v3/idempotencyKeys.js +1 -0
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
- package/dist/commonjs/v3/index.d.ts +20 -5
- package/dist/commonjs/v3/index.js +56 -20
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/locals.d.ts +3 -0
- package/dist/commonjs/v3/locals.js +6 -0
- package/dist/commonjs/v3/locals.js.map +1 -0
- package/dist/commonjs/v3/managedChatResponse.d.ts +44 -0
- package/dist/commonjs/v3/managedChatResponse.js +221 -0
- package/dist/commonjs/v3/managedChatResponse.js.map +1 -0
- package/dist/commonjs/v3/metadata.d.ts +5 -2
- package/dist/commonjs/v3/metadata.js +8 -1
- package/dist/commonjs/v3/metadata.js.map +1 -1
- package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
- package/dist/commonjs/v3/modelFileDownload.js +164 -0
- package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
- package/dist/commonjs/v3/otel.d.ts +4 -0
- package/dist/commonjs/v3/otel.js +12 -0
- package/dist/commonjs/v3/otel.js.map +1 -0
- package/dist/commonjs/v3/prompt.d.ts +38 -0
- package/dist/commonjs/v3/prompt.js +146 -0
- package/dist/commonjs/v3/prompt.js.map +1 -0
- package/dist/commonjs/v3/promptManagement.d.ts +26 -0
- package/dist/commonjs/v3/promptManagement.js +180 -0
- package/dist/commonjs/v3/promptManagement.js.map +1 -0
- package/dist/commonjs/v3/prompts.d.ts +3 -0
- package/dist/commonjs/v3/prompts.js +15 -0
- package/dist/commonjs/v3/prompts.js.map +1 -0
- package/dist/commonjs/v3/query.d.ts +545 -0
- package/dist/commonjs/v3/query.js +163 -0
- package/dist/commonjs/v3/query.js.map +1 -0
- package/dist/commonjs/v3/queues.d.ts +107 -0
- package/dist/commonjs/v3/queues.js +225 -0
- package/dist/commonjs/v3/queues.js.map +1 -0
- package/dist/commonjs/v3/retry.d.ts +6 -2
- package/dist/commonjs/v3/retry.js +34 -23
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +182 -101
- package/dist/commonjs/v3/runs.js +99 -5
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/schedules/api.d.ts +8 -1
- package/dist/commonjs/v3/schedules/index.d.ts +29 -9
- package/dist/commonjs/v3/schedules/index.js +5 -1
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/schemas.d.ts +1 -0
- package/dist/commonjs/{integrations.js → v3/schemas.js} +1 -1
- package/dist/commonjs/v3/schemas.js.map +1 -0
- package/dist/commonjs/v3/sessionTracing.d.ts +7 -0
- package/dist/commonjs/v3/sessionTracing.js +44 -0
- package/dist/commonjs/v3/sessionTracing.js.map +1 -0
- package/dist/commonjs/v3/sessions.d.ts +268 -0
- package/dist/commonjs/v3/sessions.js +776 -0
- package/dist/commonjs/v3/sessions.js.map +1 -0
- package/dist/commonjs/v3/shared.d.ts +129 -24
- package/dist/commonjs/v3/shared.js +1527 -689
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/skill.d.ts +99 -0
- package/dist/commonjs/v3/skill.js +165 -0
- package/dist/commonjs/v3/skill.js.map +1 -0
- package/dist/commonjs/v3/skills.d.ts +2 -0
- package/dist/commonjs/v3/skills.js +6 -0
- package/dist/commonjs/v3/skills.js.map +1 -0
- package/dist/commonjs/v3/steeringContext.d.ts +41 -0
- package/dist/commonjs/v3/steeringContext.js +118 -0
- package/dist/commonjs/v3/steeringContext.js.map +1 -0
- package/dist/commonjs/v3/streams.d.ts +298 -0
- package/dist/commonjs/v3/streams.js +584 -0
- package/dist/commonjs/v3/streams.js.map +1 -0
- package/dist/commonjs/v3/tasks.d.ts +19 -4
- package/dist/commonjs/v3/tasks.js +15 -1
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/index.d.ts +5 -0
- package/dist/commonjs/v3/test/index.js +23 -0
- package/dist/commonjs/v3/test/index.js.map +1 -0
- package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
- package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
- package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +388 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +689 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
- package/dist/commonjs/v3/test/setup-catalog.js +18 -0
- package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
- package/dist/commonjs/v3/test/test-session-handle.d.ts +24 -0
- package/dist/commonjs/v3/test/test-session-handle.js +271 -0
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/commonjs/v3/toolResultOrder.d.ts +15 -0
- package/dist/commonjs/v3/toolResultOrder.js +58 -0
- package/dist/commonjs/v3/toolResultOrder.js.map +1 -0
- package/dist/commonjs/v3/transcriptStorage.d.ts +307 -0
- package/dist/commonjs/v3/transcriptStorage.js +445 -0
- package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
- package/dist/commonjs/v3/triggerClient.d.ts +45 -0
- package/dist/commonjs/v3/triggerClient.js +114 -0
- package/dist/commonjs/v3/triggerClient.js.map +1 -0
- package/dist/commonjs/v3/uiMessageChunks.d.ts +1 -0
- package/dist/commonjs/v3/uiMessageChunks.js +119 -0
- package/dist/commonjs/v3/uiMessageChunks.js.map +1 -0
- package/dist/commonjs/v3/usage.js +7 -6
- package/dist/commonjs/v3/usage.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +218 -3
- package/dist/commonjs/v3/wait.js +433 -7
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/v3/waitUntil.js.map +1 -1
- package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
- package/dist/commonjs/v3/webhookWaiters.js +156 -0
- package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
- package/dist/commonjs/v3/webhooks.d.ts +192 -2
- package/dist/commonjs/v3/webhooks.js +340 -2
- package/dist/commonjs/v3/webhooks.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/imports/ai-runtime.d.ts +2 -0
- package/dist/esm/imports/ai-runtime.js +16 -0
- package/dist/esm/imports/ai-runtime.js.map +1 -0
- package/dist/esm/package.json +2 -1
- package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
- package/dist/esm/v3/agentSkillsRuntime.js +136 -0
- package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
- package/dist/esm/v3/ai-shared.d.ts +156 -0
- package/dist/esm/v3/ai-shared.js +208 -0
- package/dist/esm/v3/ai-shared.js.map +1 -0
- package/dist/esm/v3/ai.d.ts +4225 -0
- package/dist/esm/v3/ai.js +11550 -0
- package/dist/esm/v3/ai.js.map +1 -0
- package/dist/esm/v3/aiAutoTelemetry.d.ts +2 -0
- package/dist/esm/v3/aiAutoTelemetry.js +78 -0
- package/dist/esm/v3/aiAutoTelemetry.js.map +1 -0
- package/dist/esm/v3/auth.d.ts +71 -10
- package/dist/esm/v3/auth.js +83 -17
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/batch.d.ts +3 -3
- package/dist/esm/v3/batch.js +2 -2
- package/dist/esm/v3/batch.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +324 -0
- package/dist/esm/v3/chat-client.js +769 -0
- package/dist/esm/v3/chat-client.js.map +1 -0
- package/dist/esm/v3/chat-react.d.ts +244 -0
- package/dist/esm/v3/chat-react.js +455 -0
- package/dist/esm/v3/chat-react.js.map +1 -0
- package/dist/esm/v3/chat-server.d.ts +350 -0
- package/dist/esm/v3/chat-server.js +962 -0
- package/dist/esm/v3/chat-server.js.map +1 -0
- package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
- package/dist/esm/v3/chat-tab-coordinator.js +231 -0
- package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
- package/dist/esm/v3/chat.d.ts +792 -0
- package/dist/esm/v3/chat.js +1655 -0
- package/dist/esm/v3/chat.js.map +1 -0
- package/dist/esm/v3/chatRouteWait.d.ts +21 -0
- package/dist/esm/v3/chatRouteWait.js +40 -0
- package/dist/esm/v3/chatRouteWait.js.map +1 -0
- package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/esm/v3/chatSnapshotIo.js +165 -0
- package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
- package/dist/esm/v3/chatVersionSkew.d.ts +12 -0
- package/dist/esm/v3/chatVersionSkew.js +27 -0
- package/dist/esm/v3/chatVersionSkew.js.map +1 -0
- package/dist/esm/v3/compactionResponse.d.ts +9 -0
- package/dist/esm/v3/compactionResponse.js +34 -0
- package/dist/esm/v3/compactionResponse.js.map +1 -0
- package/dist/esm/v3/concurrency-shared.d.ts +13 -0
- package/dist/esm/v3/concurrency-shared.js +31 -0
- package/dist/esm/v3/concurrency-shared.js.map +1 -0
- package/dist/esm/v3/concurrencyLimits.d.ts +103 -0
- package/dist/esm/v3/concurrencyLimits.js +126 -0
- package/dist/esm/v3/concurrencyLimits.js.map +1 -0
- package/dist/esm/v3/deployments.d.ts +25 -0
- package/dist/esm/v3/deployments.js +34 -0
- package/dist/esm/v3/deployments.js.map +1 -0
- package/dist/esm/v3/envvars.d.ts +5 -5
- package/dist/esm/v3/envvars.js.map +1 -1
- package/dist/esm/v3/externalDeploymentId.d.ts +23 -0
- package/dist/esm/v3/externalDeploymentId.js +38 -0
- package/dist/esm/v3/externalDeploymentId.js.map +1 -0
- package/dist/esm/v3/heartbeats.d.ts +37 -0
- package/dist/esm/v3/heartbeats.js +42 -0
- package/dist/esm/v3/heartbeats.js.map +1 -0
- package/dist/esm/v3/hooks.d.ts +26 -0
- package/dist/esm/v3/hooks.js +66 -0
- package/dist/esm/v3/hooks.js.map +1 -0
- package/dist/esm/v3/idempotencyKeys.d.ts +2 -1
- package/dist/esm/v3/idempotencyKeys.js +2 -1
- package/dist/esm/v3/idempotencyKeys.js.map +1 -1
- package/dist/esm/v3/index.d.ts +20 -5
- package/dist/esm/v3/index.js +16 -2
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/locals.d.ts +3 -0
- package/dist/esm/v3/locals.js +3 -0
- package/dist/esm/v3/locals.js.map +1 -0
- package/dist/esm/v3/managedChatResponse.d.ts +44 -0
- package/dist/esm/v3/managedChatResponse.js +216 -0
- package/dist/esm/v3/managedChatResponse.js.map +1 -0
- package/dist/esm/v3/metadata.d.ts +5 -2
- package/dist/esm/v3/metadata.js +8 -1
- package/dist/esm/v3/metadata.js.map +1 -1
- package/dist/esm/v3/modelFileDownload.d.ts +10 -0
- package/dist/esm/v3/modelFileDownload.js +161 -0
- package/dist/esm/v3/modelFileDownload.js.map +1 -0
- package/dist/esm/v3/otel.d.ts +4 -0
- package/dist/esm/v3/otel.js +9 -0
- package/dist/esm/v3/otel.js.map +1 -0
- package/dist/esm/v3/prompt.d.ts +38 -0
- package/dist/esm/v3/prompt.js +143 -0
- package/dist/esm/v3/prompt.js.map +1 -0
- package/dist/esm/v3/promptManagement.d.ts +26 -0
- package/dist/esm/v3/promptManagement.js +170 -0
- package/dist/esm/v3/promptManagement.js.map +1 -0
- package/dist/esm/v3/prompts.d.ts +3 -0
- package/dist/esm/v3/prompts.js +3 -0
- package/dist/esm/v3/prompts.js.map +1 -0
- package/dist/esm/v3/query.d.ts +545 -0
- package/dist/esm/v3/query.js +160 -0
- package/dist/esm/v3/query.js.map +1 -0
- package/dist/esm/v3/queues.d.ts +107 -0
- package/dist/esm/v3/queues.js +217 -0
- package/dist/esm/v3/queues.js.map +1 -0
- package/dist/esm/v3/retry.d.ts +6 -2
- package/dist/esm/v3/retry.js +27 -19
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +179 -98
- package/dist/esm/v3/runs.js +99 -5
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/schedules/api.d.ts +8 -1
- package/dist/esm/v3/schedules/index.d.ts +29 -9
- package/dist/esm/v3/schedules/index.js +6 -2
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/schemas.d.ts +1 -0
- package/dist/esm/v3/schemas.js +2 -0
- package/dist/esm/v3/schemas.js.map +1 -0
- package/dist/esm/v3/sessionTracing.d.ts +7 -0
- package/dist/esm/v3/sessionTracing.js +40 -0
- package/dist/esm/v3/sessionTracing.js.map +1 -0
- package/dist/esm/v3/sessions.d.ts +268 -0
- package/dist/esm/v3/sessions.js +767 -0
- package/dist/esm/v3/sessions.js.map +1 -0
- package/dist/esm/v3/shared.d.ts +129 -24
- package/dist/esm/v3/shared.js +1521 -688
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/skill.d.ts +99 -0
- package/dist/esm/v3/skill.js +128 -0
- package/dist/esm/v3/skill.js.map +1 -0
- package/dist/esm/v3/skills.d.ts +2 -0
- package/dist/esm/v3/skills.js +2 -0
- package/dist/esm/v3/skills.js.map +1 -0
- package/dist/esm/v3/steeringContext.d.ts +41 -0
- package/dist/esm/v3/steeringContext.js +113 -0
- package/dist/esm/v3/steeringContext.js.map +1 -0
- package/dist/esm/v3/streams.d.ts +298 -0
- package/dist/esm/v3/streams.js +580 -0
- package/dist/esm/v3/streams.js.map +1 -0
- package/dist/esm/v3/tasks.d.ts +19 -4
- package/dist/esm/v3/tasks.js +16 -2
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/index.d.ts +5 -0
- package/dist/esm/v3/test/index.js +15 -0
- package/dist/esm/v3/test/index.js.map +1 -0
- package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
- package/dist/esm/v3/test/mock-channel-connector.js +170 -0
- package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
- package/dist/esm/v3/test/mock-chat-agent.d.ts +388 -0
- package/dist/esm/v3/test/mock-chat-agent.js +685 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
- package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
- package/dist/esm/v3/test/setup-catalog.js +16 -0
- package/dist/esm/v3/test/setup-catalog.js.map +1 -0
- package/dist/esm/v3/test/test-session-handle.d.ts +24 -0
- package/dist/esm/v3/test/test-session-handle.js +268 -0
- package/dist/esm/v3/test/test-session-handle.js.map +1 -0
- package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
- package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/esm/v3/toolResultOrder.d.ts +15 -0
- package/dist/esm/v3/toolResultOrder.js +55 -0
- package/dist/esm/v3/toolResultOrder.js.map +1 -0
- package/dist/esm/v3/transcriptStorage.d.ts +307 -0
- package/dist/esm/v3/transcriptStorage.js +431 -0
- package/dist/esm/v3/transcriptStorage.js.map +1 -0
- package/dist/esm/v3/triggerClient.d.ts +45 -0
- package/dist/esm/v3/triggerClient.js +77 -0
- package/dist/esm/v3/triggerClient.js.map +1 -0
- package/dist/esm/v3/uiMessageChunks.d.ts +1 -0
- package/dist/esm/v3/uiMessageChunks.js +116 -0
- package/dist/esm/v3/uiMessageChunks.js.map +1 -0
- package/dist/esm/v3/usage.js +7 -6
- package/dist/esm/v3/usage.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +218 -3
- package/dist/esm/v3/wait.js +431 -7
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/v3/webhookWaiters.d.ts +80 -0
- package/dist/esm/v3/webhookWaiters.js +149 -0
- package/dist/esm/v3/webhookWaiters.js.map +1 -0
- package/dist/esm/v3/webhooks.d.ts +192 -2
- package/dist/esm/v3/webhooks.js +336 -2
- package/dist/esm/v3/webhooks.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/observability.mdx +174 -0
- package/docs/ai/prompts.mdx +426 -0
- package/docs/ai-chat/actions.mdx +148 -0
- package/docs/ai-chat/anatomy.mdx +87 -0
- package/docs/ai-chat/backend.mdx +933 -0
- package/docs/ai-chat/background-injection.mdx +320 -0
- package/docs/ai-chat/changelog.mdx +958 -0
- package/docs/ai-chat/chat-local.mdx +170 -0
- package/docs/ai-chat/client-protocol.mdx +1091 -0
- package/docs/ai-chat/compaction.mdx +413 -0
- package/docs/ai-chat/custom-agents.mdx +545 -0
- package/docs/ai-chat/error-handling.mdx +379 -0
- package/docs/ai-chat/fast-starts.mdx +764 -0
- package/docs/ai-chat/frontend.mdx +634 -0
- package/docs/ai-chat/how-it-works.mdx +226 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +532 -0
- package/docs/ai-chat/mcp.mdx +97 -0
- package/docs/ai-chat/migrating-from-a-route-handler.mdx +594 -0
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
- package/docs/ai-chat/overview.mdx +86 -0
- package/docs/ai-chat/patterns/branching-conversations.mdx +145 -0
- package/docs/ai-chat/patterns/code-sandbox.mdx +122 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +425 -0
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +281 -0
- package/docs/ai-chat/patterns/large-payloads.mdx +165 -0
- package/docs/ai-chat/patterns/native-compaction.mdx +310 -0
- package/docs/ai-chat/patterns/oom-resilience.mdx +116 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +218 -0
- package/docs/ai-chat/patterns/recovery-boot.mdx +233 -0
- package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
- package/docs/ai-chat/patterns/skills.mdx +214 -0
- package/docs/ai-chat/patterns/sub-agents.mdx +412 -0
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +145 -0
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +333 -0
- package/docs/ai-chat/patterns/version-upgrades.mdx +261 -0
- package/docs/ai-chat/pending-messages.mdx +363 -0
- package/docs/ai-chat/prompt-caching.mdx +204 -0
- package/docs/ai-chat/quick-start.mdx +163 -0
- package/docs/ai-chat/reference.mdx +1071 -0
- package/docs/ai-chat/server-chat.mdx +259 -0
- package/docs/ai-chat/sessions.mdx +334 -0
- package/docs/ai-chat/side-channels.mdx +172 -0
- package/docs/ai-chat/testing.mdx +691 -0
- package/docs/ai-chat/tools.mdx +192 -0
- package/docs/ai-chat/transcript-storage.mdx +247 -0
- package/docs/ai-chat/types.mdx +242 -0
- package/docs/ai-chat/upgrade-guide.mdx +511 -0
- package/docs/apikeys.mdx +170 -0
- package/docs/billing-limits.mdx +73 -0
- package/docs/building-with-ai.mdx +261 -0
- package/docs/bulk-actions.mdx +77 -0
- package/docs/changelog.mdx +6 -0
- package/docs/cli-deploy-commands.mdx +9 -0
- package/docs/cli-dev-commands.mdx +9 -0
- package/docs/cli-env-commands.mdx +115 -0
- package/docs/cli-init-commands.mdx +84 -0
- package/docs/cli-introduction.mdx +25 -0
- package/docs/cli-list-profiles-commands.mdx +42 -0
- package/docs/cli-login-commands.mdx +53 -0
- package/docs/cli-logout-commands.mdx +33 -0
- package/docs/cli-preview-archive.mdx +59 -0
- package/docs/cli-projects-commands.mdx +74 -0
- package/docs/cli-promote-commands.mdx +9 -0
- package/docs/cli-runs-commands.mdx +95 -0
- package/docs/cli-switch.mdx +43 -0
- package/docs/cli-tasks-commands.mdx +95 -0
- package/docs/cli-update-commands.mdx +48 -0
- package/docs/cli-whoami-commands.mdx +45 -0
- package/docs/community.mdx +6 -0
- package/docs/concurrency.mdx +416 -0
- package/docs/config/config-file.mdx +662 -0
- package/docs/config/extensions/additionalFiles.mdx +38 -0
- package/docs/config/extensions/additionalPackages.mdx +40 -0
- package/docs/config/extensions/aptGet.mdx +34 -0
- package/docs/config/extensions/audioWaveform.mdx +23 -0
- package/docs/config/extensions/custom.mdx +393 -0
- package/docs/config/extensions/emitDecoratorMetadata.mdx +52 -0
- package/docs/config/extensions/esbuildPlugin.mdx +31 -0
- package/docs/config/extensions/ffmpeg.mdx +45 -0
- package/docs/config/extensions/lightpanda.mdx +56 -0
- package/docs/config/extensions/overview.mdx +69 -0
- package/docs/config/extensions/playwright.mdx +195 -0
- package/docs/config/extensions/prismaExtension.mdx +1013 -0
- package/docs/config/extensions/puppeteer.mdx +28 -0
- package/docs/config/extensions/pythonExtension.mdx +190 -0
- package/docs/config/extensions/syncEnvVars.mdx +330 -0
- package/docs/context.mdx +235 -0
- package/docs/database-connections.mdx +213 -0
- package/docs/deploy-environment-variables.mdx +466 -0
- package/docs/deployment/atomic-deployment.mdx +470 -0
- package/docs/deployment/dev-branches.mdx +92 -0
- package/docs/deployment/overview.mdx +260 -0
- package/docs/deployment/preview-branches.mdx +227 -0
- package/docs/errors-retrying.mdx +383 -0
- package/docs/github-actions.mdx +260 -0
- package/docs/github-integration.mdx +148 -0
- package/docs/github-repo.mdx +8 -0
- package/docs/help-email.mdx +6 -0
- package/docs/help-slack.mdx +12 -0
- package/docs/hidden-tasks.mdx +56 -0
- package/docs/how-it-works.mdx +454 -0
- package/docs/how-to-reduce-your-spend.mdx +211 -0
- package/docs/idempotency.mdx +542 -0
- package/docs/introduction.mdx +135 -0
- package/docs/limits.mdx +284 -0
- package/docs/logging.mdx +195 -0
- package/docs/machines.mdx +952 -0
- package/docs/manual-setup.mdx +632 -0
- package/docs/mcp-agent-rules.mdx +41 -0
- package/docs/mcp-introduction.mdx +386 -0
- package/docs/mcp-tools.mdx +425 -0
- package/docs/migrating-from-v3.mdx +332 -0
- package/docs/observability/dashboards.mdx +166 -0
- package/docs/observability/query.mdx +614 -0
- package/docs/open-source-contributing.mdx +16 -0
- package/docs/private-networking/aws-console-setup.mdx +304 -0
- package/docs/private-networking/overview.mdx +144 -0
- package/docs/private-networking/troubleshooting.mdx +78 -0
- package/docs/queues.mdx +271 -0
- package/docs/quick-start.mdx +60 -0
- package/docs/realtime/auth.mdx +228 -0
- package/docs/realtime/backend/input-streams.mdx +159 -0
- package/docs/realtime/backend/overview.mdx +45 -0
- package/docs/realtime/backend/streams.mdx +433 -0
- package/docs/realtime/backend/subscribe.mdx +225 -0
- package/docs/realtime/how-it-works.mdx +94 -0
- package/docs/realtime/overview.mdx +63 -0
- package/docs/realtime/react-hooks/overview.mdx +73 -0
- package/docs/realtime/react-hooks/session-stream.mdx +126 -0
- package/docs/realtime/react-hooks/streams.mdx +517 -0
- package/docs/realtime/react-hooks/subscribe.mdx +690 -0
- package/docs/realtime/react-hooks/swr.mdx +87 -0
- package/docs/realtime/react-hooks/triggering.mdx +194 -0
- package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
- package/docs/realtime/run-object.mdx +197 -0
- package/docs/replaying.mdx +97 -0
- package/docs/reports.mdx +159 -0
- package/docs/request-feature.mdx +6 -0
- package/docs/roadmap.mdx +6 -0
- package/docs/run-tests.mdx +21 -0
- package/docs/run-usage.mdx +113 -0
- package/docs/runs/bulk-actions.mdx +183 -0
- package/docs/runs/heartbeats.mdx +38 -0
- package/docs/runs/list-best-practices.mdx +234 -0
- package/docs/runs/max-duration.mdx +143 -0
- package/docs/runs/metadata.mdx +731 -0
- package/docs/runs/priority.mdx +8 -0
- package/docs/runs.mdx +406 -0
- package/docs/self-hosting/docker.mdx +512 -0
- package/docs/self-hosting/env/supervisor.mdx +78 -0
- package/docs/self-hosting/env/webapp.mdx +305 -0
- package/docs/self-hosting/kubernetes.mdx +725 -0
- package/docs/self-hosting/overview.mdx +145 -0
- package/docs/self-hosting/security.mdx +67 -0
- package/docs/skills.mdx +85 -0
- package/docs/tags.mdx +126 -0
- package/docs/tasks/overview.mdx +695 -0
- package/docs/tasks/scheduled.mdx +479 -0
- package/docs/tasks/schemaTask.mdx +413 -0
- package/docs/tasks/streams.mdx +887 -0
- package/docs/triggering.mdx +1340 -0
- package/docs/troubleshooting-alerts.mdx +607 -0
- package/docs/troubleshooting-debugging-in-vscode.mdx +9 -0
- package/docs/troubleshooting-github-issues.mdx +6 -0
- package/docs/troubleshooting-uptime-status.mdx +7 -0
- package/docs/troubleshooting-zod.mdx +158 -0
- package/docs/troubleshooting.mdx +414 -0
- package/docs/upgrading-packages.mdx +80 -0
- package/docs/vercel-integration.mdx +250 -0
- package/docs/versioning.mdx +58 -0
- package/docs/video-walkthrough.mdx +23 -0
- package/docs/wait-for-token.mdx +540 -0
- package/docs/wait-for.mdx +42 -0
- package/docs/wait-until.mdx +53 -0
- package/docs/wait.mdx +18 -0
- package/docs/webhooks/channels.mdx +154 -0
- package/docs/webhooks/connect.mdx +91 -0
- package/docs/webhooks/deliveries.mdx +99 -0
- package/docs/webhooks/filters.mdx +146 -0
- package/docs/webhooks/human-in-the-loop.mdx +158 -0
- package/docs/webhooks/linear.mdx +186 -0
- package/docs/webhooks/overview.mdx +115 -0
- package/docs/webhooks/session-routing.mdx +141 -0
- package/docs/webhooks/slack.mdx +393 -0
- package/docs/webhooks/sources.mdx +250 -0
- package/docs/webhooks/waiters.mdx +190 -0
- package/docs/writing-tasks-introduction.mdx +34 -0
- package/package.json +143 -42
- package/skills/trigger-authoring-chat-agent/SKILL.md +308 -0
- package/skills/trigger-authoring-tasks/SKILL.md +254 -0
- package/skills/trigger-chat-agent-advanced/SKILL.md +403 -0
- package/skills/trigger-cost-savings/SKILL.md +116 -0
- package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
- package/dist/commonjs/apiClient.d.ts +0 -727
- package/dist/commonjs/apiClient.js +0 -692
- package/dist/commonjs/apiClient.js.map +0 -1
- package/dist/commonjs/concurrencyLimit.d.ts +0 -10
- package/dist/commonjs/concurrencyLimit.js +0 -17
- package/dist/commonjs/concurrencyLimit.js.map +0 -1
- package/dist/commonjs/errors.d.ts +0 -66
- package/dist/commonjs/errors.js +0 -109
- package/dist/commonjs/errors.js.map +0 -1
- package/dist/commonjs/httpEndpoint.d.ts +0 -87
- package/dist/commonjs/httpEndpoint.js +0 -130
- package/dist/commonjs/httpEndpoint.js.map +0 -1
- package/dist/commonjs/index.d.ts +0 -23
- package/dist/commonjs/index.js +0 -55
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/integrations.d.ts +0 -11
- package/dist/commonjs/integrations.js.map +0 -1
- package/dist/commonjs/io.d.ts +0 -441
- package/dist/commonjs/io.js +0 -1165
- package/dist/commonjs/io.js.map +0 -1
- package/dist/commonjs/ioWithIntegrations.d.ts +0 -4
- package/dist/commonjs/ioWithIntegrations.js +0 -32
- package/dist/commonjs/ioWithIntegrations.js.map +0 -1
- package/dist/commonjs/job.d.ts +0 -96
- package/dist/commonjs/job.js +0 -210
- package/dist/commonjs/job.js.map +0 -1
- package/dist/commonjs/retry.d.ts +0 -20
- package/dist/commonjs/retry.js +0 -22
- package/dist/commonjs/retry.js.map +0 -1
- package/dist/commonjs/runLocalStorage.d.ts +0 -8
- package/dist/commonjs/runLocalStorage.js +0 -6
- package/dist/commonjs/runLocalStorage.js.map +0 -1
- package/dist/commonjs/security.d.ts +0 -18
- package/dist/commonjs/security.js +0 -41
- package/dist/commonjs/security.js.map +0 -1
- package/dist/commonjs/status.d.ts +0 -19
- package/dist/commonjs/status.js +0 -38
- package/dist/commonjs/status.js.map +0 -1
- package/dist/commonjs/store/keyValueStore.d.ts +0 -17
- package/dist/commonjs/store/keyValueStore.js +0 -138
- package/dist/commonjs/store/keyValueStore.js.map +0 -1
- package/dist/commonjs/store/keyValueStoreClient.d.ts +0 -19
- package/dist/commonjs/store/keyValueStoreClient.js +0 -65
- package/dist/commonjs/store/keyValueStoreClient.js.map +0 -1
- package/dist/commonjs/triggerClient.d.ts +0 -290
- package/dist/commonjs/triggerClient.js +0 -1366
- package/dist/commonjs/triggerClient.js.map +0 -1
- package/dist/commonjs/triggers/dynamic.d.ts +0 -56
- package/dist/commonjs/triggers/dynamic.js +0 -97
- package/dist/commonjs/triggers/dynamic.js.map +0 -1
- package/dist/commonjs/triggers/eventTrigger.d.ts +0 -58
- package/dist/commonjs/triggers/eventTrigger.js +0 -69
- package/dist/commonjs/triggers/eventTrigger.js.map +0 -1
- package/dist/commonjs/triggers/externalSource.d.ts +0 -148
- package/dist/commonjs/triggers/externalSource.js +0 -106
- package/dist/commonjs/triggers/externalSource.js.map +0 -1
- package/dist/commonjs/triggers/invokeTrigger.d.ts +0 -39
- package/dist/commonjs/triggers/invokeTrigger.js +0 -58
- package/dist/commonjs/triggers/invokeTrigger.js.map +0 -1
- package/dist/commonjs/triggers/notifications.d.ts +0 -111
- package/dist/commonjs/triggers/notifications.js +0 -101
- package/dist/commonjs/triggers/notifications.js.map +0 -1
- package/dist/commonjs/triggers/scheduled.d.ts +0 -145
- package/dist/commonjs/triggers/scheduled.js +0 -208
- package/dist/commonjs/triggers/scheduled.js.map +0 -1
- package/dist/commonjs/triggers/webhook.d.ts +0 -143
- package/dist/commonjs/triggers/webhook.js +0 -133
- package/dist/commonjs/triggers/webhook.js.map +0 -1
- package/dist/commonjs/typed-emitter.d.ts +0 -37
- package/dist/commonjs/typed-emitter.js +0 -3
- package/dist/commonjs/typed-emitter.js.map +0 -1
- package/dist/commonjs/types.d.ts +0 -204
- package/dist/commonjs/types.js +0 -23
- package/dist/commonjs/types.js.map +0 -1
- package/dist/commonjs/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/commonjs/utils/formatSchemaErrors.js +0 -10
- package/dist/commonjs/utils/formatSchemaErrors.js.map +0 -1
- package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/commonjs/utils/typedAsyncLocalStorage.js +0 -18
- package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/commonjs/utils.d.ts +0 -1
- package/dist/commonjs/utils.js +0 -11
- package/dist/commonjs/utils.js.map +0 -1
- package/dist/esm/apiClient.d.ts +0 -727
- package/dist/esm/apiClient.js +0 -687
- package/dist/esm/apiClient.js.map +0 -1
- package/dist/esm/concurrencyLimit.d.ts +0 -10
- package/dist/esm/concurrencyLimit.js +0 -13
- package/dist/esm/concurrencyLimit.js.map +0 -1
- package/dist/esm/errors.d.ts +0 -66
- package/dist/esm/errors.js +0 -95
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/httpEndpoint.d.ts +0 -87
- package/dist/esm/httpEndpoint.js +0 -125
- package/dist/esm/httpEndpoint.js.map +0 -1
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/index.js +0 -35
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/integrations.d.ts +0 -11
- package/dist/esm/integrations.js +0 -2
- package/dist/esm/integrations.js.map +0 -1
- package/dist/esm/io.d.ts +0 -441
- package/dist/esm/io.js +0 -1159
- package/dist/esm/io.js.map +0 -1
- package/dist/esm/ioWithIntegrations.d.ts +0 -4
- package/dist/esm/ioWithIntegrations.js +0 -29
- package/dist/esm/ioWithIntegrations.js.map +0 -1
- package/dist/esm/job.d.ts +0 -96
- package/dist/esm/job.js +0 -206
- package/dist/esm/job.js.map +0 -1
- package/dist/esm/retry.d.ts +0 -20
- package/dist/esm/retry.js +0 -19
- package/dist/esm/retry.js.map +0 -1
- package/dist/esm/runLocalStorage.d.ts +0 -8
- package/dist/esm/runLocalStorage.js +0 -3
- package/dist/esm/runLocalStorage.js.map +0 -1
- package/dist/esm/security.d.ts +0 -18
- package/dist/esm/security.js +0 -34
- package/dist/esm/security.js.map +0 -1
- package/dist/esm/status.d.ts +0 -19
- package/dist/esm/status.js +0 -34
- package/dist/esm/status.js.map +0 -1
- package/dist/esm/store/keyValueStore.d.ts +0 -17
- package/dist/esm/store/keyValueStore.js +0 -134
- package/dist/esm/store/keyValueStore.js.map +0 -1
- package/dist/esm/store/keyValueStoreClient.d.ts +0 -19
- package/dist/esm/store/keyValueStoreClient.js +0 -61
- package/dist/esm/store/keyValueStoreClient.js.map +0 -1
- package/dist/esm/triggerClient.d.ts +0 -288
- package/dist/esm/triggerClient.js +0 -1359
- package/dist/esm/triggerClient.js.map +0 -1
- package/dist/esm/triggers/dynamic.d.ts +0 -56
- package/dist/esm/triggers/dynamic.js +0 -93
- package/dist/esm/triggers/dynamic.js.map +0 -1
- package/dist/esm/triggers/eventTrigger.d.ts +0 -58
- package/dist/esm/triggers/eventTrigger.js +0 -64
- package/dist/esm/triggers/eventTrigger.js.map +0 -1
- package/dist/esm/triggers/externalSource.d.ts +0 -148
- package/dist/esm/triggers/externalSource.js +0 -100
- package/dist/esm/triggers/externalSource.js.map +0 -1
- package/dist/esm/triggers/invokeTrigger.d.ts +0 -39
- package/dist/esm/triggers/invokeTrigger.js +0 -53
- package/dist/esm/triggers/invokeTrigger.js.map +0 -1
- package/dist/esm/triggers/notifications.d.ts +0 -111
- package/dist/esm/triggers/notifications.js +0 -94
- package/dist/esm/triggers/notifications.js.map +0 -1
- package/dist/esm/triggers/scheduled.d.ts +0 -145
- package/dist/esm/triggers/scheduled.js +0 -197
- package/dist/esm/triggers/scheduled.js.map +0 -1
- package/dist/esm/triggers/webhook.d.ts +0 -143
- package/dist/esm/triggers/webhook.js +0 -128
- package/dist/esm/triggers/webhook.js.map +0 -1
- package/dist/esm/typed-emitter.d.ts +0 -37
- package/dist/esm/typed-emitter.js +0 -2
- package/dist/esm/typed-emitter.js.map +0 -1
- package/dist/esm/types.d.ts +0 -204
- package/dist/esm/types.js +0 -19
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/utils/formatSchemaErrors.d.ts +0 -3
- package/dist/esm/utils/formatSchemaErrors.js +0 -7
- package/dist/esm/utils/formatSchemaErrors.js.map +0 -1
- package/dist/esm/utils/typedAsyncLocalStorage.d.ts +0 -6
- package/dist/esm/utils/typedAsyncLocalStorage.js +0 -14
- package/dist/esm/utils/typedAsyncLocalStorage.js.map +0 -1
- package/dist/esm/utils.d.ts +0 -1
- package/dist/esm/utils.js +0 -8
- package/dist/esm/utils.js.map +0 -1
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side API for chatting with Trigger.dev agents.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { AgentChat } from "@trigger.dev/sdk/chat";
|
|
7
|
+
*
|
|
8
|
+
* const chat = new AgentChat<typeof myAgent>({
|
|
9
|
+
* agent: "my-agent",
|
|
10
|
+
* clientData: { userId: "user_123" },
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const stream = await chat.sendMessage("Review PR #1");
|
|
14
|
+
* const text = await stream.text();
|
|
15
|
+
* await chat.close();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
// `readUIMessageStream` is a runtime value — via the ESM/CJS shim so the CJS
|
|
19
|
+
// build can `require` ESM-only `ai@7` (see ../imports/ai-runtime.ts).
|
|
20
|
+
import { readUIMessageStream } from "../imports/ai-runtime.js";
|
|
21
|
+
import { apiClientManager, controlSubtype, SSEStreamSubscription, TRIGGER_CONTROL_SUBTYPE, } from "@trigger.dev/core/v3";
|
|
22
|
+
import { chatRunTags, MAX_EOF_RESUBSCRIBES, slimSubmitMessageForWire, waitBeforeEofResubscribe, } from "./ai-shared.js";
|
|
23
|
+
import { triggerConcurrencyBody } from "./concurrency-shared.js";
|
|
24
|
+
import { sessions } from "./sessions.js";
|
|
25
|
+
/**
|
|
26
|
+
* A single turn's response stream from an agent.
|
|
27
|
+
*
|
|
28
|
+
* Pick one consumption mode:
|
|
29
|
+
* - `for await (const chunk of stream)` — typed UIMessageChunk iteration
|
|
30
|
+
* - `await stream.result()` — accumulated `{ text, toolCalls, toolResults }`
|
|
31
|
+
* - `await stream.text()` — just the text
|
|
32
|
+
* - `yield* stream.messages()` — sub-agent pattern (yields UIMessage snapshots)
|
|
33
|
+
*/
|
|
34
|
+
export class ChatStream {
|
|
35
|
+
_consumerStream;
|
|
36
|
+
_messageCollector;
|
|
37
|
+
resultPromise;
|
|
38
|
+
/** @internal Last UIMessage snapshot from the assistant's response. */
|
|
39
|
+
lastAssistantMessage;
|
|
40
|
+
/** @internal Callback to capture the assistant's response message for accumulation. */
|
|
41
|
+
onAssistantMessage;
|
|
42
|
+
constructor(stream, onAssistantMessage) {
|
|
43
|
+
this.onAssistantMessage = onAssistantMessage;
|
|
44
|
+
if (onAssistantMessage) {
|
|
45
|
+
// Tee the stream: one branch for the consumer, one for message collection
|
|
46
|
+
const [consumer, collector] = stream.tee();
|
|
47
|
+
this._consumerStream = consumer;
|
|
48
|
+
this._messageCollector = (async () => {
|
|
49
|
+
for await (const msg of readUIMessageStream({ stream: collector })) {
|
|
50
|
+
this.lastAssistantMessage = msg;
|
|
51
|
+
}
|
|
52
|
+
if (this.lastAssistantMessage) {
|
|
53
|
+
onAssistantMessage(this.lastAssistantMessage);
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this._consumerStream = stream;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** The raw ReadableStream for direct use with AI SDK utilities. */
|
|
62
|
+
get stream() {
|
|
63
|
+
return this._consumerStream;
|
|
64
|
+
}
|
|
65
|
+
async *[Symbol.asyncIterator]() {
|
|
66
|
+
const reader = this._consumerStream.getReader();
|
|
67
|
+
try {
|
|
68
|
+
while (true) {
|
|
69
|
+
const { done, value } = await reader.read();
|
|
70
|
+
if (done)
|
|
71
|
+
break;
|
|
72
|
+
yield value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
reader.releaseLock();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Yields accumulated UIMessage snapshots for the sub-agent tool pattern.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const stream = await chat.sendMessage("Research this topic");
|
|
85
|
+
* yield* stream.messages();
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
async *messages() {
|
|
89
|
+
for await (const message of readUIMessageStream({ stream: this._consumerStream })) {
|
|
90
|
+
this.lastAssistantMessage = message;
|
|
91
|
+
yield message;
|
|
92
|
+
}
|
|
93
|
+
// When the constructor set up `_messageCollector` (because
|
|
94
|
+
// `onAssistantMessage` was provided), that collector IIFE owns
|
|
95
|
+
// firing the callback. Skipping it here prevents a double-invoke.
|
|
96
|
+
if (this.lastAssistantMessage && this.onAssistantMessage && !this._messageCollector) {
|
|
97
|
+
this.onAssistantMessage(this.lastAssistantMessage);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Consume the stream and return the accumulated result. */
|
|
101
|
+
result() {
|
|
102
|
+
if (!this.resultPromise) {
|
|
103
|
+
this.resultPromise = this.consumeStream();
|
|
104
|
+
}
|
|
105
|
+
return this.resultPromise;
|
|
106
|
+
}
|
|
107
|
+
/** Consume the stream and return just the text. */
|
|
108
|
+
async text() {
|
|
109
|
+
return (await this.result()).text;
|
|
110
|
+
}
|
|
111
|
+
async consumeStream() {
|
|
112
|
+
let text = "";
|
|
113
|
+
const toolCalls = [];
|
|
114
|
+
const toolResults = [];
|
|
115
|
+
for await (const chunk of this) {
|
|
116
|
+
if (chunk.type === "text-delta") {
|
|
117
|
+
text += chunk.delta;
|
|
118
|
+
}
|
|
119
|
+
else if (chunk.type === "tool-input-available") {
|
|
120
|
+
toolCalls.push({
|
|
121
|
+
toolName: chunk.toolName,
|
|
122
|
+
toolCallId: chunk.toolCallId,
|
|
123
|
+
input: chunk.input,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else if (chunk.type === "tool-output-available") {
|
|
127
|
+
toolResults.push({
|
|
128
|
+
toolCallId: chunk.toolCallId,
|
|
129
|
+
output: chunk.output,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { text, toolCalls, toolResults };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// ─── AgentChat ─────────────────────────────────────────────────────
|
|
137
|
+
/**
|
|
138
|
+
* A chat conversation with a Trigger.dev agent.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* // Simple usage
|
|
143
|
+
* const chat = new AgentChat<typeof myAgent>({ agent: "my-agent" });
|
|
144
|
+
* const text = await (await chat.sendMessage("Hello")).text();
|
|
145
|
+
* await chat.close();
|
|
146
|
+
*
|
|
147
|
+
* // Stateless request handler — persist and restore session
|
|
148
|
+
* const chat = new AgentChat<typeof myAgent>({
|
|
149
|
+
* agent: "my-agent",
|
|
150
|
+
* id: chatId,
|
|
151
|
+
* session: { lastEventId: savedLastEventId },
|
|
152
|
+
* onTriggered: ({ runId }) => db.save(chatId, { runId }),
|
|
153
|
+
* onTurnComplete: ({ lastEventId }) => db.update(chatId, { lastEventId }),
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export class AgentChat {
|
|
158
|
+
taskId;
|
|
159
|
+
chatId;
|
|
160
|
+
streamTimeoutSeconds;
|
|
161
|
+
clientData;
|
|
162
|
+
triggerConfigDefault;
|
|
163
|
+
onTriggered;
|
|
164
|
+
onTurnComplete;
|
|
165
|
+
baseURLResolver;
|
|
166
|
+
fetchOverride;
|
|
167
|
+
state;
|
|
168
|
+
/**
|
|
169
|
+
* Which subscription armed `skipToTurnComplete`, so only that stream ends at
|
|
170
|
+
* the gated boundary. A later stream reads the same boundary as stale history
|
|
171
|
+
* and keeps reading to its own turn. Deliberately not in `state`: a stop does
|
|
172
|
+
* not outlive the process that issued it.
|
|
173
|
+
*/
|
|
174
|
+
streamSeq = 0;
|
|
175
|
+
stoppedStreamId;
|
|
176
|
+
constructor(options) {
|
|
177
|
+
this.taskId = options.agent;
|
|
178
|
+
this.chatId = options.id ?? crypto.randomUUID();
|
|
179
|
+
this.streamTimeoutSeconds = options.streamTimeoutSeconds ?? 120;
|
|
180
|
+
this.clientData = options.clientData;
|
|
181
|
+
this.triggerConfigDefault = options.triggerConfig;
|
|
182
|
+
this.onTriggered = options.onTriggered;
|
|
183
|
+
this.onTurnComplete = options.onTurnComplete;
|
|
184
|
+
const baseURLOption = options.baseURL;
|
|
185
|
+
this.baseURLResolver =
|
|
186
|
+
typeof baseURLOption === "function"
|
|
187
|
+
? baseURLOption
|
|
188
|
+
: () => baseURLOption ?? apiClientManager.baseURL ?? "https://api.trigger.dev";
|
|
189
|
+
this.fetchOverride = options.fetch;
|
|
190
|
+
// Hydration: a non-empty `session` means the caller knows the
|
|
191
|
+
// session already exists (started in a previous request). Mark
|
|
192
|
+
// `started` so we don't re-`sessions.start()` on first message.
|
|
193
|
+
const hydrated = !!options.session;
|
|
194
|
+
this.state = {
|
|
195
|
+
lastEventId: options.session?.lastEventId,
|
|
196
|
+
started: hydrated,
|
|
197
|
+
pinRefreshed: !hydrated,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** The conversation ID. */
|
|
201
|
+
get id() {
|
|
202
|
+
return this.chatId;
|
|
203
|
+
}
|
|
204
|
+
/** Persistable session state — pass back via `options.session` to resume. */
|
|
205
|
+
get session() {
|
|
206
|
+
return { lastEventId: this.state.lastEventId };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Eagerly start the session — creates the row and triggers the first
|
|
210
|
+
* run. The agent's `onPreload` hook fires immediately. Idempotent: a
|
|
211
|
+
* second call is a no-op.
|
|
212
|
+
*/
|
|
213
|
+
async preload(options) {
|
|
214
|
+
await this.ensureStarted({ idleTimeoutInSeconds: options?.idleTimeoutInSeconds });
|
|
215
|
+
return this.session;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Send a text message and get the response stream.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const stream = await chat.sendMessage("Review PR #1");
|
|
223
|
+
* const text = await stream.text();
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
async sendMessage(text, options) {
|
|
227
|
+
const msgId = `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
228
|
+
const message = {
|
|
229
|
+
id: msgId,
|
|
230
|
+
role: "user",
|
|
231
|
+
parts: [{ type: "text", text }],
|
|
232
|
+
};
|
|
233
|
+
const rawStream = await this.sendRaw([message], { abortSignal: options?.abortSignal });
|
|
234
|
+
return new ChatStream(rawStream);
|
|
235
|
+
}
|
|
236
|
+
/** Send raw UIMessage-like objects. Use `sendMessage()` for simple text. */
|
|
237
|
+
async sendRaw(messages, options) {
|
|
238
|
+
const triggerType = options?.trigger ?? "submit-message";
|
|
239
|
+
// Make sure the session exists (and a run is alive). The .in/append
|
|
240
|
+
// handler on the server probes currentRunId on every call and
|
|
241
|
+
// re-triggers if needed — so we don't need to track runId here.
|
|
242
|
+
await this.ensureStarted();
|
|
243
|
+
// Slim wire — at most ONE message per record. The agent rebuilds prior
|
|
244
|
+
// history from its durable S3 snapshot + session.out replay at run
|
|
245
|
+
// boot (or `hydrateMessages` if registered).
|
|
246
|
+
//
|
|
247
|
+
// For `submit-message`, assistant messages carrying resolved tool parts
|
|
248
|
+
// (HITL `addToolOutput` answers) are slimmed to just the resolution
|
|
249
|
+
// payload — reasoning blobs, text, and tool `input` come from the
|
|
250
|
+
// agent's authoritative chain. `regenerate-message` omits `message`.
|
|
251
|
+
if (triggerType === "submit-message" && messages.length === 0) {
|
|
252
|
+
throw new Error("AgentChat.sendRaw: 'submit-message' trigger requires at least one message");
|
|
253
|
+
}
|
|
254
|
+
const lastIfSubmit = triggerType === "submit-message"
|
|
255
|
+
? slimSubmitMessageForWire(messages.at(-1))
|
|
256
|
+
: undefined;
|
|
257
|
+
const payload = {
|
|
258
|
+
...(lastIfSubmit ? { message: lastIfSubmit } : {}),
|
|
259
|
+
chatId: this.chatId,
|
|
260
|
+
trigger: triggerType,
|
|
261
|
+
metadata: this.clientData,
|
|
262
|
+
};
|
|
263
|
+
await this.appendInputChunk(serializeInputChunk({ kind: "message", payload }));
|
|
264
|
+
return this.subscribeToSessionStream(options?.abortSignal, { resumeAfterEof: true });
|
|
265
|
+
}
|
|
266
|
+
/** Send a steering message during an active stream. */
|
|
267
|
+
async steer(text) {
|
|
268
|
+
if (!this.state.started)
|
|
269
|
+
return false;
|
|
270
|
+
const payload = {
|
|
271
|
+
message: {
|
|
272
|
+
id: `steer-${Date.now()}`,
|
|
273
|
+
role: "user",
|
|
274
|
+
parts: [{ type: "text", text }],
|
|
275
|
+
},
|
|
276
|
+
chatId: this.chatId,
|
|
277
|
+
trigger: "submit-message",
|
|
278
|
+
metadata: this.clientData,
|
|
279
|
+
};
|
|
280
|
+
try {
|
|
281
|
+
await this.appendInputChunk(serializeInputChunk({ kind: "message", payload }));
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** Stop the current generation (agent stays alive for next turn). */
|
|
289
|
+
async stop() {
|
|
290
|
+
if (!this.state.started)
|
|
291
|
+
return;
|
|
292
|
+
this.state.skipToTurnComplete = true;
|
|
293
|
+
this.stoppedStreamId = this.streamSeq;
|
|
294
|
+
await this.appendInputChunk(serializeInputChunk({ kind: "stop" })).catch(() => { });
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Hand over from a `chat.handover` route handler to a parked
|
|
298
|
+
* `handover-prepare` agent run. Wakes the run, which seeds its
|
|
299
|
+
* accumulators with `partialAssistantMessage` and continues from
|
|
300
|
+
* tool execution onward — the model call for step 1 is skipped.
|
|
301
|
+
*
|
|
302
|
+
* Used internally by `chat.handover`; not part of the customer
|
|
303
|
+
* surface.
|
|
304
|
+
*/
|
|
305
|
+
async sendHandover(args) {
|
|
306
|
+
await this.appendInputChunk(serializeInputChunk({
|
|
307
|
+
kind: "handover",
|
|
308
|
+
partialAssistantMessage: args.partialAssistantMessage,
|
|
309
|
+
messageId: args.messageId,
|
|
310
|
+
isFinal: args.isFinal,
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Tell a parked `handover-prepare` agent run that the customer's
|
|
315
|
+
* first turn finished pure-text (no tool calls) — the run exits
|
|
316
|
+
* cleanly without making an LLM call.
|
|
317
|
+
*
|
|
318
|
+
* Used internally by `chat.handover`; not part of the customer
|
|
319
|
+
* surface.
|
|
320
|
+
*/
|
|
321
|
+
async sendHandoverSkip() {
|
|
322
|
+
await this.appendInputChunk(serializeInputChunk({ kind: "handover-skip" }));
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Send a custom action to the agent.
|
|
326
|
+
*
|
|
327
|
+
* Actions are not turns. They wake the agent, fire `hydrateMessages`
|
|
328
|
+
* (if configured) and `onAction` only — no `onTurnStart` /
|
|
329
|
+
* `prepareMessages` / `onBeforeTurnComplete` / `onTurnComplete`, no
|
|
330
|
+
* `run()` invocation.
|
|
331
|
+
*
|
|
332
|
+
* The action payload is validated against the agent's `actionSchema`
|
|
333
|
+
* on the backend. Use `chat.history.*` inside `onAction` to mutate
|
|
334
|
+
* state. To produce a model response from the action, return a
|
|
335
|
+
* `StreamTextResult` (or `string` / `UIMessage`) from `onAction` —
|
|
336
|
+
* the returned stream is auto-piped over this stream. When `onAction`
|
|
337
|
+
* returns `void`, the action is side-effect-only and the returned
|
|
338
|
+
* stream completes immediately with `trigger:turn-complete`.
|
|
339
|
+
*
|
|
340
|
+
* @returns A `ChatStream`. For void actions the stream completes
|
|
341
|
+
* immediately. For actions that return a model response, the stream
|
|
342
|
+
* carries the assistant chunks.
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const stream = await agentChat.sendAction({ type: "undo" });
|
|
347
|
+
* for await (const chunk of stream) {
|
|
348
|
+
* if (chunk.type === "text-delta") process.stdout.write(chunk.delta);
|
|
349
|
+
* }
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
async sendAction(action, options) {
|
|
353
|
+
await this.ensureStarted();
|
|
354
|
+
const payload = {
|
|
355
|
+
chatId: this.chatId,
|
|
356
|
+
trigger: "action",
|
|
357
|
+
action,
|
|
358
|
+
metadata: this.clientData,
|
|
359
|
+
};
|
|
360
|
+
try {
|
|
361
|
+
await this.appendInputChunk(serializeInputChunk({ kind: "message", payload }));
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
throw new Error("Failed to send action. The session may have ended.");
|
|
365
|
+
}
|
|
366
|
+
const rawStream = this.subscribeToSessionStream(options?.abortSignal, {
|
|
367
|
+
resumeAfterEof: true,
|
|
368
|
+
});
|
|
369
|
+
return new ChatStream(rawStream);
|
|
370
|
+
}
|
|
371
|
+
/** Close the conversation — agent exits its loop gracefully. */
|
|
372
|
+
async close() {
|
|
373
|
+
if (!this.state.started)
|
|
374
|
+
return false;
|
|
375
|
+
try {
|
|
376
|
+
await this.appendInputChunk(serializeInputChunk({
|
|
377
|
+
kind: "message",
|
|
378
|
+
payload: {
|
|
379
|
+
chatId: this.chatId,
|
|
380
|
+
trigger: "close",
|
|
381
|
+
},
|
|
382
|
+
}));
|
|
383
|
+
this.state = { ...this.state, started: false };
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Reconnect to the response stream to resume an already-established session
|
|
392
|
+
* after a disconnect. Requests the caught-up settle probe (`X-Peek-Settled`)
|
|
393
|
+
* so a resumed stream already at a turn-complete tail closes promptly instead
|
|
394
|
+
* of holding the full SSE window, mirroring the browser transport's
|
|
395
|
+
* `reconnectToStream`.
|
|
396
|
+
*
|
|
397
|
+
* Do not call this immediately after `sendMessage()` to read a fresh turn: the
|
|
398
|
+
* settle probe can race the newly-triggered turn's first record, see the prior
|
|
399
|
+
* turn's `turn-complete` tail, and hand back an empty stream (unlike the
|
|
400
|
+
* browser transport, there is no auto-resubscribe). `sendMessage()` already
|
|
401
|
+
* returns the turn's stream; use `reconnect()` only to resume an idle or
|
|
402
|
+
* mid-turn stream.
|
|
403
|
+
*/
|
|
404
|
+
async reconnect(abortSignal) {
|
|
405
|
+
if (!this.state.started)
|
|
406
|
+
return null;
|
|
407
|
+
return this.subscribeToSessionStream(abortSignal, {
|
|
408
|
+
sendStopOnAbort: false,
|
|
409
|
+
peekSettled: true,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
// ─── Private ───────────────────────────────────────────────────
|
|
413
|
+
resolveBaseURL(endpoint) {
|
|
414
|
+
return this.baseURLResolver({ endpoint, chatId: this.chatId }).replace(/\/$/, "");
|
|
415
|
+
}
|
|
416
|
+
async doFetch(ctx, url, init) {
|
|
417
|
+
return this.fetchOverride ? this.fetchOverride(url, init, ctx) : fetch(url, init);
|
|
418
|
+
}
|
|
419
|
+
async appendInputChunk(body) {
|
|
420
|
+
const accessToken = apiClientManager.accessToken ?? "";
|
|
421
|
+
const ctx = { endpoint: "in", chatId: this.chatId };
|
|
422
|
+
const url = `${this.resolveBaseURL("in")}/realtime/v1/sessions/${encodeURIComponent(this.chatId)}/in/append`;
|
|
423
|
+
const headers = {
|
|
424
|
+
"Content-Type": "application/json",
|
|
425
|
+
Authorization: `Bearer ${accessToken}`,
|
|
426
|
+
"x-trigger-source": "sdk",
|
|
427
|
+
// Idempotency key: the server skips appends whose part id it has
|
|
428
|
+
// already committed, so a retried POST can't duplicate the record.
|
|
429
|
+
"X-Part-Id": crypto.randomUUID(),
|
|
430
|
+
};
|
|
431
|
+
// Preview-env sessions are branch-scoped, so the realtime in/out calls must
|
|
432
|
+
// carry the branch the session was created on. sessions.start sends it via
|
|
433
|
+
// the API client; these raw fetches have to set it themselves.
|
|
434
|
+
const branch = apiClientManager.branchName;
|
|
435
|
+
if (branch)
|
|
436
|
+
headers["x-trigger-branch"] = branch;
|
|
437
|
+
const response = await this.doFetch(ctx, url, { method: "POST", headers, body });
|
|
438
|
+
if (!response.ok) {
|
|
439
|
+
const text = await response.text().catch(() => "");
|
|
440
|
+
// Match the error shape that ApiClient/zodfetch produced before the
|
|
441
|
+
// inline-POST refactor so callers inspecting `error.name ===
|
|
442
|
+
// "TriggerApiError"` or `error.status` keep working.
|
|
443
|
+
const err = new Error(`appendToSessionStream failed: ${response.status} ${text}`);
|
|
444
|
+
err.name = "TriggerApiError";
|
|
445
|
+
err.status = response.status;
|
|
446
|
+
throw err;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Idempotent: `sessions.start` upserts on `(env, externalId)`. Two
|
|
451
|
+
* concurrent AgentChat instances on the same chatId converge to the
|
|
452
|
+
* same session.
|
|
453
|
+
*/
|
|
454
|
+
async ensureStarted(options) {
|
|
455
|
+
if (this.state.started && this.state.pinRefreshed)
|
|
456
|
+
return;
|
|
457
|
+
const idleTimeoutInSeconds = options?.idleTimeoutInSeconds ?? this.triggerConfigDefault?.idleTimeoutInSeconds;
|
|
458
|
+
const triggerConfig = {
|
|
459
|
+
basePayload: {
|
|
460
|
+
// `trigger: "preload"` mirrors the browser-mediated
|
|
461
|
+
// `chat.createStartSessionAction` shape so the agent runtime fires
|
|
462
|
+
// `onPreload` (not `onChatStart` with `preloaded: true`). Without
|
|
463
|
+
// this, AgentChat's first run skips both preload and start hooks,
|
|
464
|
+
// which is where customer apps typically upsert their Chat row.
|
|
465
|
+
// Slim wire — preload carries no message body.
|
|
466
|
+
trigger: "preload",
|
|
467
|
+
...(this.triggerConfigDefault?.basePayload ?? {}),
|
|
468
|
+
chatId: this.chatId,
|
|
469
|
+
...(this.clientData ? { metadata: this.clientData } : {}),
|
|
470
|
+
},
|
|
471
|
+
...(this.triggerConfigDefault?.machine ? { machine: this.triggerConfigDefault.machine } : {}),
|
|
472
|
+
...(this.triggerConfigDefault?.queue ? { queue: this.triggerConfigDefault.queue } : {}),
|
|
473
|
+
...(this.triggerConfigDefault?.concurrency !== undefined
|
|
474
|
+
? triggerConcurrencyBody(this.triggerConfigDefault.concurrency)
|
|
475
|
+
: {}),
|
|
476
|
+
...(this.triggerConfigDefault?.concurrencyKey !== undefined
|
|
477
|
+
? { concurrencyKey: this.triggerConfigDefault.concurrencyKey }
|
|
478
|
+
: {}),
|
|
479
|
+
tags: chatRunTags(this.chatId, this.triggerConfigDefault?.tags),
|
|
480
|
+
...(this.triggerConfigDefault?.maxAttempts !== undefined
|
|
481
|
+
? { maxAttempts: this.triggerConfigDefault.maxAttempts }
|
|
482
|
+
: {}),
|
|
483
|
+
...(this.triggerConfigDefault?.maxDuration !== undefined
|
|
484
|
+
? { maxDuration: this.triggerConfigDefault.maxDuration }
|
|
485
|
+
: {}),
|
|
486
|
+
...(this.triggerConfigDefault?.region ? { region: this.triggerConfigDefault.region } : {}),
|
|
487
|
+
...(this.triggerConfigDefault?.lockToVersion
|
|
488
|
+
? { lockToVersion: this.triggerConfigDefault.lockToVersion }
|
|
489
|
+
: {}),
|
|
490
|
+
...(this.triggerConfigDefault?.ttl !== undefined
|
|
491
|
+
? { ttl: this.triggerConfigDefault.ttl }
|
|
492
|
+
: {}),
|
|
493
|
+
// Not truthiness: `null` opts out and must reach the resolver in `sessions.start`.
|
|
494
|
+
...(this.triggerConfigDefault?.externalDeploymentId !== undefined
|
|
495
|
+
? { externalDeploymentId: this.triggerConfigDefault.externalDeploymentId }
|
|
496
|
+
: {}),
|
|
497
|
+
...(idleTimeoutInSeconds !== undefined ? { idleTimeoutInSeconds } : {}),
|
|
498
|
+
};
|
|
499
|
+
const created = await sessions.start({
|
|
500
|
+
type: "chat.agent",
|
|
501
|
+
externalId: this.chatId,
|
|
502
|
+
taskIdentifier: this.taskId,
|
|
503
|
+
triggerConfig,
|
|
504
|
+
});
|
|
505
|
+
const wasInitialStart = !this.state.started;
|
|
506
|
+
this.state.started = true;
|
|
507
|
+
this.state.pinRefreshed = true;
|
|
508
|
+
// `onTriggered` is documented as the initial start, so a restored session
|
|
509
|
+
// refreshing its config does not fire it: the caller handed us that
|
|
510
|
+
// session, and a hook that writes a row would write it again on every
|
|
511
|
+
// request that rehydrates the conversation.
|
|
512
|
+
if (wasInitialStart) {
|
|
513
|
+
await this.onTriggered?.({
|
|
514
|
+
runId: created.runId,
|
|
515
|
+
chatId: this.chatId,
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
subscribeToSessionStream(abortSignal, options) {
|
|
520
|
+
const state = this.state;
|
|
521
|
+
const streamId = ++this.streamSeq;
|
|
522
|
+
// A stop was outstanding when I subscribed and it isn't mine: my window
|
|
523
|
+
// replays the stopped turn's tail, so I drop records up to and including
|
|
524
|
+
// its boundary. Captured per subscription — the stopped stream is still
|
|
525
|
+
// live and may consume the shared seed before I reach that record.
|
|
526
|
+
let skipStaleBoundary = state.skipToTurnComplete === true && this.stoppedStreamId !== streamId;
|
|
527
|
+
const accessToken = apiClientManager.accessToken ?? "";
|
|
528
|
+
const onTurnComplete = this.onTurnComplete;
|
|
529
|
+
const chatId = this.chatId;
|
|
530
|
+
const sseCtx = { endpoint: "out", chatId };
|
|
531
|
+
const fetchOverride = this.fetchOverride;
|
|
532
|
+
const sseFetchClient = fetchOverride
|
|
533
|
+
? ((input, init) => {
|
|
534
|
+
if (typeof input === "string") {
|
|
535
|
+
return fetchOverride(input, init ?? {}, sseCtx);
|
|
536
|
+
}
|
|
537
|
+
if (input instanceof URL) {
|
|
538
|
+
return fetchOverride(input.toString(), init ?? {}, sseCtx);
|
|
539
|
+
}
|
|
540
|
+
// Request — preserve its url + intrinsic init, let any provided
|
|
541
|
+
// init override on top (matches fetch(Request, init) semantics).
|
|
542
|
+
return fetchOverride(input.url, {
|
|
543
|
+
method: input.method,
|
|
544
|
+
headers: input.headers,
|
|
545
|
+
signal: input.signal,
|
|
546
|
+
...(init ?? {}),
|
|
547
|
+
}, sseCtx);
|
|
548
|
+
})
|
|
549
|
+
: undefined;
|
|
550
|
+
const internalAbort = new AbortController();
|
|
551
|
+
const combinedSignal = abortSignal
|
|
552
|
+
? AbortSignal.any([abortSignal, internalAbort.signal])
|
|
553
|
+
: internalAbort.signal;
|
|
554
|
+
// Detached once the stream ends (see the `finally` below): a caller reusing
|
|
555
|
+
// one signal across turns would otherwise stack listeners, and a late abort
|
|
556
|
+
// would post a stop that gates the next turn.
|
|
557
|
+
const onExternalAbort = () => {
|
|
558
|
+
if (options?.sendStopOnAbort !== false) {
|
|
559
|
+
state.skipToTurnComplete = true;
|
|
560
|
+
this.stoppedStreamId = streamId;
|
|
561
|
+
this.appendInputChunk(serializeInputChunk({ kind: "stop" })).catch(() => { });
|
|
562
|
+
}
|
|
563
|
+
internalAbort.abort();
|
|
564
|
+
};
|
|
565
|
+
abortSignal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
566
|
+
const streamUrl = `${this.resolveBaseURL("out")}/realtime/v1/sessions/${encodeURIComponent(chatId)}/out`;
|
|
567
|
+
return new ReadableStream({
|
|
568
|
+
start: async (controller) => {
|
|
569
|
+
let eofResubscribes = 0;
|
|
570
|
+
let sawLiveTurn = false;
|
|
571
|
+
const closeController = () => {
|
|
572
|
+
try {
|
|
573
|
+
controller.close();
|
|
574
|
+
}
|
|
575
|
+
catch {
|
|
576
|
+
// Controller may already be closed
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
const openSubscription = () => new SSEStreamSubscription(streamUrl, {
|
|
580
|
+
headers: {
|
|
581
|
+
Authorization: `Bearer ${accessToken}`,
|
|
582
|
+
// Preview-env sessions are branch-scoped (see appendInputChunk).
|
|
583
|
+
...(apiClientManager.branchName
|
|
584
|
+
? { "x-trigger-branch": apiClientManager.branchName }
|
|
585
|
+
: {}),
|
|
586
|
+
...(options?.peekSettled ? { "X-Peek-Settled": "1" } : {}),
|
|
587
|
+
},
|
|
588
|
+
signal: combinedSignal,
|
|
589
|
+
timeoutInSeconds: this.streamTimeoutSeconds,
|
|
590
|
+
lastEventId: state.lastEventId,
|
|
591
|
+
fetchClient: sseFetchClient,
|
|
592
|
+
});
|
|
593
|
+
try {
|
|
594
|
+
while (true) {
|
|
595
|
+
const subscription = openSubscription();
|
|
596
|
+
const sseStream = await subscription.subscribe();
|
|
597
|
+
const reader = sseStream.getReader();
|
|
598
|
+
try {
|
|
599
|
+
while (true) {
|
|
600
|
+
const next = await reader.read();
|
|
601
|
+
if (next.done) {
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
if (combinedSignal.aborted) {
|
|
605
|
+
internalAbort.abort();
|
|
606
|
+
await reader.cancel();
|
|
607
|
+
closeController();
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
const value = next.value;
|
|
611
|
+
if (value.id)
|
|
612
|
+
state.lastEventId = value.id;
|
|
613
|
+
// Any record re-earns the resubscribe budget: a clean EOF is
|
|
614
|
+
// the normal end of every long-poll window, so a long turn
|
|
615
|
+
// spanning many windows must not exhaust it.
|
|
616
|
+
eofResubscribes = 0;
|
|
617
|
+
// Trigger control records (turn-complete, upgrade-required)
|
|
618
|
+
// route by header — see `client-protocol.mdx`. Their bodies
|
|
619
|
+
// are empty; everything substantive is on `value.headers`.
|
|
620
|
+
//
|
|
621
|
+
// Cross-version bridge: an old agent SDK still writing
|
|
622
|
+
// turn-complete / upgrade-required as `chunk.type` data
|
|
623
|
+
// records would otherwise stall this loop. Fall back to
|
|
624
|
+
// the legacy chunk-type form when no header is present
|
|
625
|
+
// so the deploy-skew window between an `AgentChat`
|
|
626
|
+
// consumer and a not-yet-redeployed agent doesn't hang.
|
|
627
|
+
let controlValue = controlSubtype(value.headers);
|
|
628
|
+
if (!controlValue && value.chunk && typeof value.chunk === "object") {
|
|
629
|
+
const chunk = value.chunk;
|
|
630
|
+
if (chunk.type === "trigger:turn-complete") {
|
|
631
|
+
controlValue = TRIGGER_CONTROL_SUBTYPE.TURN_COMPLETE;
|
|
632
|
+
}
|
|
633
|
+
else if (chunk.type === "trigger:upgrade-required") {
|
|
634
|
+
controlValue = TRIGGER_CONTROL_SUBTYPE.UPGRADE_REQUIRED;
|
|
635
|
+
}
|
|
636
|
+
else if (typeof chunk.type === "string" && chunk.type.startsWith("trigger:")) {
|
|
637
|
+
// Future / unknown `trigger:*` legacy control type —
|
|
638
|
+
// drop so it doesn't leak as a UIMessageChunk.
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
// Stale tail of a turn someone else stopped: swallow it and
|
|
643
|
+
// keep reading to my own turn.
|
|
644
|
+
if (skipStaleBoundary) {
|
|
645
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.TURN_COMPLETE) {
|
|
646
|
+
skipStaleBoundary = false;
|
|
647
|
+
state.skipToTurnComplete = false;
|
|
648
|
+
}
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
// I am the stopped stream, so this turn is over at its
|
|
652
|
+
// boundary: close rather than resume into windows it will
|
|
653
|
+
// never fill. Keyed on the id alone, so it holds however far
|
|
654
|
+
// the follow-up subscription has got.
|
|
655
|
+
if (this.stoppedStreamId === streamId) {
|
|
656
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.TURN_COMPLETE) {
|
|
657
|
+
state.skipToTurnComplete = false;
|
|
658
|
+
this.stoppedStreamId = undefined;
|
|
659
|
+
internalAbort.abort();
|
|
660
|
+
closeController();
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
// Both handover markers mean the turn carries on in a
|
|
666
|
+
// successor run, so they count as a live turn: its chunks
|
|
667
|
+
// may only arrive in a later window.
|
|
668
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.UPGRADE_REQUIRED) {
|
|
669
|
+
// Server has already triggered the new run via
|
|
670
|
+
// `end-and-continue`; v2's chunks arrive on the same
|
|
671
|
+
// S2 stream. Filter the marker for cleanliness and
|
|
672
|
+
// keep reading.
|
|
673
|
+
sawLiveTurn = true;
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.PENDING_VERSION) {
|
|
677
|
+
sawLiveTurn = true;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
// A standalone session-closed record is written after
|
|
681
|
+
// turn-complete, so only a reconnect ever reads it. The
|
|
682
|
+
// conversation is over: end the stream, no stop, no error.
|
|
683
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.SESSION_CLOSED) {
|
|
684
|
+
internalAbort.abort();
|
|
685
|
+
closeController();
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (controlValue === TRIGGER_CONTROL_SUBTYPE.TURN_COMPLETE) {
|
|
689
|
+
// Customer's callback may be async (e.g. persisting
|
|
690
|
+
// lastEventId to a DB). Wrap so a rejected Promise
|
|
691
|
+
// doesn't surface as an unhandled rejection — that
|
|
692
|
+
// would crash Node under `--unhandled-rejections=throw`.
|
|
693
|
+
Promise.resolve(onTurnComplete?.({
|
|
694
|
+
chatId,
|
|
695
|
+
lastEventId: state.lastEventId,
|
|
696
|
+
})).catch(() => { });
|
|
697
|
+
internalAbort.abort();
|
|
698
|
+
closeController();
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
// Data record — `value.chunk` is the parsed UIMessageChunk
|
|
702
|
+
// (the SSE parser does the JSON envelope unwrap). Drop
|
|
703
|
+
// empty/malformed payloads defensively.
|
|
704
|
+
if (value.chunk == null)
|
|
705
|
+
continue;
|
|
706
|
+
// Parts and the handover markers above are the only evidence of
|
|
707
|
+
// a live turn. Unknown control records stay neutral: they are no
|
|
708
|
+
// reason for a reconnect to pin another long-poll window.
|
|
709
|
+
sawLiveTurn = true;
|
|
710
|
+
controller.enqueue(value.chunk);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
catch (readError) {
|
|
714
|
+
reader.releaseLock();
|
|
715
|
+
throw readError;
|
|
716
|
+
}
|
|
717
|
+
reader.releaseLock();
|
|
718
|
+
// The body ended without a turn-complete. A turn is in flight
|
|
719
|
+
// either by construction (the send paths) or because records have
|
|
720
|
+
// already flowed on this stream — so unless the server says the
|
|
721
|
+
// session settled we lost the window mid-turn, and resubscribing
|
|
722
|
+
// from the last event id beats truncating the turn. A `reconnect()`
|
|
723
|
+
// that never saw a record can't tell a live turn from a dead
|
|
724
|
+
// session, so it closes rather than pin another long-poll window.
|
|
725
|
+
const turnInFlight = options?.resumeAfterEof || sawLiveTurn;
|
|
726
|
+
if (!turnInFlight || subscription.sessionSettled || combinedSignal.aborted) {
|
|
727
|
+
closeController();
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (eofResubscribes >= MAX_EOF_RESUBSCRIBES) {
|
|
731
|
+
throw new Error("Chat stream ended before the turn completed (reconnect budget exhausted).");
|
|
732
|
+
}
|
|
733
|
+
eofResubscribes++;
|
|
734
|
+
await waitBeforeEofResubscribe(eofResubscribes, combinedSignal);
|
|
735
|
+
if (combinedSignal.aborted) {
|
|
736
|
+
closeController();
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
catch (error) {
|
|
742
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
743
|
+
closeController();
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
controller.error(error);
|
|
747
|
+
}
|
|
748
|
+
finally {
|
|
749
|
+
abortSignal?.removeEventListener("abort", onExternalAbort);
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
// A consumer that stops reading must also stop the resubscribe loop —
|
|
753
|
+
// otherwise it keeps reopening a subscription nobody is draining.
|
|
754
|
+
cancel: () => {
|
|
755
|
+
internalAbort.abort();
|
|
756
|
+
},
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Serialize a {@link ChatInputChunk} for `POST …/sessions/:session/:io/append`.
|
|
762
|
+
* Session channel records are raw JSON strings — the server wraps them
|
|
763
|
+
* in `{ data: <body>, id }` for S2 storage and the subscribe side
|
|
764
|
+
* parses the string back for consumers.
|
|
765
|
+
*/
|
|
766
|
+
function serializeInputChunk(chunk) {
|
|
767
|
+
return JSON.stringify(chunk);
|
|
768
|
+
}
|
|
769
|
+
//# sourceMappingURL=chat-client.js.map
|