@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,767 @@
|
|
|
1
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
2
|
+
import { InputStreamOncePromise, ManualWaitpointPromise, SemanticInternalAttributes, SessionStreamInstance, WaitpointTimeoutError, accessoryAttributes, apiClientManager, ensureReadableStream, mergeRequestOptions, runtime, sessionStreams, taskContext, trimSessionStream, writeSessionControlRecord, } from "@trigger.dev/core/v3";
|
|
3
|
+
import { conditionallyImportAndParsePacket } from "@trigger.dev/core/v3/utils/ioSerialization";
|
|
4
|
+
import { withResolvedExternalDeploymentId } from "./externalDeploymentId.js";
|
|
5
|
+
import { tracer } from "./tracer.js";
|
|
6
|
+
import { traceSessionIdle, traceSessionWait } from "./sessionTracing.js";
|
|
7
|
+
export const sessions = {
|
|
8
|
+
start: startSession,
|
|
9
|
+
retrieve: retrieveSession,
|
|
10
|
+
update: updateSession,
|
|
11
|
+
close: closeSession,
|
|
12
|
+
list: listSessions,
|
|
13
|
+
open,
|
|
14
|
+
defineChannel,
|
|
15
|
+
};
|
|
16
|
+
let sessionOpenImpl;
|
|
17
|
+
export function __setSessionOpenImplForTests(impl) {
|
|
18
|
+
sessionOpenImpl = impl;
|
|
19
|
+
}
|
|
20
|
+
let sessionStartImpl;
|
|
21
|
+
export function __setSessionStartImplForTests(impl) {
|
|
22
|
+
sessionStartImpl = impl;
|
|
23
|
+
}
|
|
24
|
+
let sessionCloseImpl;
|
|
25
|
+
export function __setSessionCloseImplForTests(impl) {
|
|
26
|
+
sessionCloseImpl = impl;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Start a {@link Session} — a stateful execution of an agent, with
|
|
30
|
+
* two-way streaming and durable compute, that can span multiple runs.
|
|
31
|
+
* The server creates the row (idempotent on `externalId`)
|
|
32
|
+
* and triggers the first run from `triggerConfig` in one round-trip.
|
|
33
|
+
* Returns the new run's id and a session-scoped public access token
|
|
34
|
+
* for browser-side use against `.in/append`, `.out` SSE, and
|
|
35
|
+
* `end-and-continue`.
|
|
36
|
+
*
|
|
37
|
+
* If a session with the same `(env, externalId)` already exists,
|
|
38
|
+
* returns the existing row plus the live (or freshly re-triggered) run.
|
|
39
|
+
* Two browser tabs of the same chat converge to one session.
|
|
40
|
+
*/
|
|
41
|
+
function startSession(input, requestOptions) {
|
|
42
|
+
// Resolved before the test hook so fixtures observe the body that would go on the wire.
|
|
43
|
+
const body = withResolvedExternalDeploymentId(input);
|
|
44
|
+
if (sessionStartImpl) {
|
|
45
|
+
const result = sessionStartImpl(body);
|
|
46
|
+
return Promise.resolve(result);
|
|
47
|
+
}
|
|
48
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
49
|
+
const $requestOptions = mergeRequestOptions({
|
|
50
|
+
tracer,
|
|
51
|
+
name: "sessions.start()",
|
|
52
|
+
icon: "sessions",
|
|
53
|
+
attributes: sessionAttributes(body.externalId ?? body.type, {
|
|
54
|
+
type: body.type,
|
|
55
|
+
...(body.externalId ? { externalId: body.externalId } : {}),
|
|
56
|
+
}),
|
|
57
|
+
}, requestOptions);
|
|
58
|
+
return apiClient.createSession(body, $requestOptions);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve a Session by `friendlyId` (`session_*`) or user-supplied
|
|
62
|
+
* `externalId`. The server disambiguates via the `session_` prefix.
|
|
63
|
+
*/
|
|
64
|
+
function retrieveSession(sessionIdOrExternalId, requestOptions) {
|
|
65
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
66
|
+
const $requestOptions = mergeRequestOptions({
|
|
67
|
+
tracer,
|
|
68
|
+
name: "sessions.retrieve()",
|
|
69
|
+
icon: "sessions",
|
|
70
|
+
attributes: sessionAttributes(sessionIdOrExternalId),
|
|
71
|
+
}, requestOptions);
|
|
72
|
+
return apiClient.retrieveSession(sessionIdOrExternalId, $requestOptions);
|
|
73
|
+
}
|
|
74
|
+
/** Update mutable fields on a Session (tags, metadata, externalId). */
|
|
75
|
+
function updateSession(sessionIdOrExternalId, body, requestOptions) {
|
|
76
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
77
|
+
const $requestOptions = mergeRequestOptions({
|
|
78
|
+
tracer,
|
|
79
|
+
name: "sessions.update()",
|
|
80
|
+
icon: "sessions",
|
|
81
|
+
attributes: sessionAttributes(sessionIdOrExternalId),
|
|
82
|
+
}, requestOptions);
|
|
83
|
+
return apiClient.updateSession(sessionIdOrExternalId, body, $requestOptions);
|
|
84
|
+
}
|
|
85
|
+
/** Mark a Session as closed (terminal, idempotent). */
|
|
86
|
+
function closeSession(sessionIdOrExternalId, body, requestOptions) {
|
|
87
|
+
if (sessionCloseImpl) {
|
|
88
|
+
return Promise.resolve(sessionCloseImpl(sessionIdOrExternalId, body));
|
|
89
|
+
}
|
|
90
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
91
|
+
const $requestOptions = mergeRequestOptions({
|
|
92
|
+
tracer,
|
|
93
|
+
name: "sessions.close()",
|
|
94
|
+
icon: "sessions",
|
|
95
|
+
attributes: sessionAttributes(sessionIdOrExternalId, {
|
|
96
|
+
...(body?.reason ? { reason: body.reason } : {}),
|
|
97
|
+
}),
|
|
98
|
+
}, requestOptions);
|
|
99
|
+
return apiClient.closeSession(sessionIdOrExternalId, body, $requestOptions);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* List Sessions in the current environment with filters + cursor pagination.
|
|
103
|
+
* Returns a {@link CursorPagePromise} so callers can iterate pages with
|
|
104
|
+
* `for await`.
|
|
105
|
+
*/
|
|
106
|
+
function listSessions(options, requestOptions) {
|
|
107
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
108
|
+
const $requestOptions = mergeRequestOptions({
|
|
109
|
+
tracer,
|
|
110
|
+
name: "sessions.list()",
|
|
111
|
+
icon: "sessions",
|
|
112
|
+
attributes: {
|
|
113
|
+
...(options?.type ? { type: toAttr(options.type) } : {}),
|
|
114
|
+
...(options?.tag ? { tag: toAttr(options.tag) } : {}),
|
|
115
|
+
...(options?.status ? { status: toAttr(options.status) } : {}),
|
|
116
|
+
...(options?.externalId ? { externalId: options.externalId } : {}),
|
|
117
|
+
},
|
|
118
|
+
}, requestOptions);
|
|
119
|
+
return apiClient.listSessions(options, $requestOptions);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Open a lightweight handle to a Session's realtime channels. Does not
|
|
123
|
+
* perform a network call on its own — each channel method hits the
|
|
124
|
+
* corresponding realtime endpoint.
|
|
125
|
+
*/
|
|
126
|
+
function open(sessionIdOrExternalId) {
|
|
127
|
+
if (sessionOpenImpl)
|
|
128
|
+
return sessionOpenImpl(sessionIdOrExternalId);
|
|
129
|
+
return new SessionHandle(sessionIdOrExternalId);
|
|
130
|
+
}
|
|
131
|
+
export class SessionHandle {
|
|
132
|
+
id;
|
|
133
|
+
/**
|
|
134
|
+
* Producer-to-consumer channel: the task writes records; external
|
|
135
|
+
* clients read them. Mirrors `streams.define` — `append` / `pipe` /
|
|
136
|
+
* `writer` / `read`.
|
|
137
|
+
*/
|
|
138
|
+
out;
|
|
139
|
+
/**
|
|
140
|
+
* Consumer-to-producer channel: external clients call `.send()`; the
|
|
141
|
+
* task consumes via `.on` / `.once` / `.peek` / `.wait` /
|
|
142
|
+
* `.waitWithIdleTimeout`. Mirrors `streams.input` but keyed on the
|
|
143
|
+
* session so a conversation can survive across run boundaries.
|
|
144
|
+
*/
|
|
145
|
+
in;
|
|
146
|
+
constructor(id, overrides) {
|
|
147
|
+
this.id = id;
|
|
148
|
+
this.out = overrides?.out ?? new SessionOutputChannel(id);
|
|
149
|
+
this.in = overrides?.in ?? new SessionInputChannel(id);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Open a named side channel on this session: a durable, cross-run `.in`/`.out`
|
|
153
|
+
* pair addressed by `name` rather than the reserved default pair. Writing a
|
|
154
|
+
* side channel's `.in` does not wake or trigger a run; a run observes it via
|
|
155
|
+
* `.in.on()` / `.in.once()`. Records outlive any single run and are bounded by
|
|
156
|
+
* the org's stream retention, the same as the reserved chat streams.
|
|
157
|
+
*
|
|
158
|
+
* Pass a `sessions.defineChannel(...)` definition to type `.in`/`.out` records;
|
|
159
|
+
* a bare name string works too, with records typed `unknown`.
|
|
160
|
+
*/
|
|
161
|
+
channel(channel) {
|
|
162
|
+
const name = typeof channel === "string" ? channel : channel.name;
|
|
163
|
+
if (!SESSION_CHANNEL_NAME_REGEX.test(name)) {
|
|
164
|
+
throw new Error(`Invalid session channel name "${name}": use 1-128 chars from [A-Za-z0-9._-].`);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
out: new SessionOutputChannel(this.id, name),
|
|
169
|
+
in: new SessionInputChannel(this.id, name),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const SESSION_CHANNEL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
|
|
174
|
+
/**
|
|
175
|
+
* Declare a named Session channel with typed `.in` / `.out` records, inferred
|
|
176
|
+
* on both the producer and the consumer. The channel analogue of a task
|
|
177
|
+
* definition: pass the result to `session.channel(...)` / `chat.channel(...)`
|
|
178
|
+
* and to `useSessionStreamChannel<typeof channel>` so the record types line up
|
|
179
|
+
* on every side.
|
|
180
|
+
*/
|
|
181
|
+
function defineChannel(name) {
|
|
182
|
+
if (!SESSION_CHANNEL_NAME_REGEX.test(name)) {
|
|
183
|
+
throw new Error(`Invalid session channel name "${name}": use 1-128 chars from [A-Za-z0-9._-].`);
|
|
184
|
+
}
|
|
185
|
+
return { name };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The `.out` side of a Session's bidirectional channel pair. Mirrors the
|
|
189
|
+
* consume-side of {@link streams.define}: `pipe` / `writer` / `append`
|
|
190
|
+
* for the task to produce records, `read` for external clients to
|
|
191
|
+
* consume via SSE. S2 credentials for direct writes are fetched
|
|
192
|
+
* internally by `pipe`/`writer` — there's no public `initialize()`.
|
|
193
|
+
*/
|
|
194
|
+
export class SessionOutputChannel {
|
|
195
|
+
sessionId;
|
|
196
|
+
channel;
|
|
197
|
+
// Cache of the in-flight / resolved `initializeSessionStream` PUT for
|
|
198
|
+
// this channel. Every `pipe()` / `writer()` call needs the same S2
|
|
199
|
+
// credentials, so we share a single promise instead of re-PUTing on
|
|
200
|
+
// every chunk. Hot-loop writers (per-chunk `chat.response.write` /
|
|
201
|
+
// direct `session.out.writer` calls) drop from N PUTs to 1 PUT for
|
|
202
|
+
// the lifetime of the channel. The S2 access token has a 1-day TTL
|
|
203
|
+
// server-side so reusing it across calls within a single run is safe.
|
|
204
|
+
// Evicts on failure (so the next call retries) and on `reset()`.
|
|
205
|
+
#initPromise;
|
|
206
|
+
constructor(sessionId, channel) {
|
|
207
|
+
this.sessionId = sessionId;
|
|
208
|
+
this.channel = channel;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Drop the cached `initializeSessionStream` response. Surfaces for
|
|
212
|
+
* tests and lifecycle hooks that need the next write to re-mint S2
|
|
213
|
+
* credentials. The cache also self-evicts on `initializeSession`
|
|
214
|
+
* rejection, so callers don't need to invoke this on failures.
|
|
215
|
+
*
|
|
216
|
+
* @internal
|
|
217
|
+
*/
|
|
218
|
+
reset() {
|
|
219
|
+
this.#initPromise = undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Append a single record. Routes through {@link writer} internally so
|
|
223
|
+
* subscribers receive the same parsed-object shape as multi-record
|
|
224
|
+
* writes — the server-side append endpoint wraps the body in a string,
|
|
225
|
+
* which would give SSE consumers a JSON-string instead of an object.
|
|
226
|
+
* Mirrors how `streams.define.append` delegates to `streams.writer`.
|
|
227
|
+
*/
|
|
228
|
+
async append(value, options) {
|
|
229
|
+
const { waitUntilComplete } = this.writer({
|
|
230
|
+
...options,
|
|
231
|
+
spanName: "sessions.append()",
|
|
232
|
+
execute: ({ write }) => {
|
|
233
|
+
write(value);
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
await waitUntilComplete();
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Pipe an `AsyncIterable` / `ReadableStream` directly to S2. Fetches
|
|
240
|
+
* session S2 credentials internally and streams through
|
|
241
|
+
* {@link SessionStreamInstance}. Parallel to {@link streams.pipe} but
|
|
242
|
+
* session-scoped — no `target` option because the session is the target.
|
|
243
|
+
*/
|
|
244
|
+
pipe(value, options) {
|
|
245
|
+
return this.#pipeInternal(value, options, "sessions.pipe()");
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Mirror of {@link streams.writer}: runs `execute({ write, merge })`
|
|
249
|
+
* against an in-memory queue whose records are piped to S2. Returns
|
|
250
|
+
* `{ stream, waitUntilComplete }` so callers can observe the local
|
|
251
|
+
* stream and await completion. Span is collapsible via `options.spanName`
|
|
252
|
+
* / `options.collapsed`.
|
|
253
|
+
*/
|
|
254
|
+
writer(options) {
|
|
255
|
+
let controller;
|
|
256
|
+
const ongoingStreamPromises = [];
|
|
257
|
+
const stream = new ReadableStream({
|
|
258
|
+
start(controllerArg) {
|
|
259
|
+
controller = controllerArg;
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
const safeEnqueue = (data) => {
|
|
263
|
+
try {
|
|
264
|
+
controller.enqueue(data);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
// Suppress errors when the stream has been closed.
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
try {
|
|
271
|
+
const result = options.execute({
|
|
272
|
+
write(part) {
|
|
273
|
+
safeEnqueue(part);
|
|
274
|
+
},
|
|
275
|
+
merge(streamArg) {
|
|
276
|
+
ongoingStreamPromises.push((async () => {
|
|
277
|
+
const reader = streamArg.getReader();
|
|
278
|
+
while (true) {
|
|
279
|
+
const { done, value } = await reader.read();
|
|
280
|
+
if (done)
|
|
281
|
+
break;
|
|
282
|
+
safeEnqueue(value);
|
|
283
|
+
}
|
|
284
|
+
})().catch((error) => {
|
|
285
|
+
console.error(error);
|
|
286
|
+
}));
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
if (result) {
|
|
290
|
+
ongoingStreamPromises.push(result.catch((error) => {
|
|
291
|
+
console.error(error);
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
console.error(error);
|
|
297
|
+
}
|
|
298
|
+
const waitForStreams = new Promise((resolve, reject) => {
|
|
299
|
+
(async () => {
|
|
300
|
+
while (ongoingStreamPromises.length > 0) {
|
|
301
|
+
await ongoingStreamPromises.shift();
|
|
302
|
+
}
|
|
303
|
+
resolve();
|
|
304
|
+
})().catch(reject);
|
|
305
|
+
});
|
|
306
|
+
waitForStreams.finally(() => {
|
|
307
|
+
try {
|
|
308
|
+
controller.close();
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
// Already closed.
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return this.#pipeInternal(stream, options, options.spanName ?? "sessions.writer()");
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Subscribe to SSE records on `.out`. Returns an async-iterable stream —
|
|
318
|
+
* auto-retry, Last-Event-ID resume, and abort propagation come from the
|
|
319
|
+
* shared {@link SSEStreamSubscription} plumbing used by run-scoped
|
|
320
|
+
* realtime streams.
|
|
321
|
+
*/
|
|
322
|
+
async read(options) {
|
|
323
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
324
|
+
return apiClient.subscribeToSessionStream(this.sessionId, "out", {
|
|
325
|
+
signal: options?.signal,
|
|
326
|
+
channel: this.channel,
|
|
327
|
+
timeoutInSeconds: options?.timeoutInSeconds,
|
|
328
|
+
lastEventId: options?.lastEventId != null ? String(options.lastEventId) : undefined,
|
|
329
|
+
onPart: options?.onPart,
|
|
330
|
+
onControl: options?.onControl,
|
|
331
|
+
onComplete: options?.onComplete,
|
|
332
|
+
onError: options?.onError,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
#pipeInternal(value, options, spanName) {
|
|
336
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
337
|
+
const collapsed = options?.collapsed;
|
|
338
|
+
const span = tracer.startSpan(spanName, {
|
|
339
|
+
attributes: {
|
|
340
|
+
session: this.sessionId,
|
|
341
|
+
io: "out",
|
|
342
|
+
...(this.channel ? { channel: this.channel } : {}),
|
|
343
|
+
[SemanticInternalAttributes.ENTITY_TYPE]: "session-stream",
|
|
344
|
+
[SemanticInternalAttributes.ENTITY_ID]: `${this.sessionId}:${this.channel ?? ""}:out`,
|
|
345
|
+
[SemanticInternalAttributes.STYLE_ICON]: "sessions",
|
|
346
|
+
...(collapsed ? { [SemanticInternalAttributes.COLLAPSED]: true } : {}),
|
|
347
|
+
...(this.channel
|
|
348
|
+
? accessoryAttributes({
|
|
349
|
+
items: [
|
|
350
|
+
{ text: this.channel, variant: "normal" },
|
|
351
|
+
{ text: "out", variant: "normal" },
|
|
352
|
+
],
|
|
353
|
+
style: "codepath",
|
|
354
|
+
})
|
|
355
|
+
: {}),
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
const readableStreamSource = ensureReadableStream(value);
|
|
359
|
+
const abortController = new AbortController();
|
|
360
|
+
// `AbortSignal.any` lands in Node 20.3; the SDK still supports Node
|
|
361
|
+
// 18.20+. On older runtimes fall back to wiring `options.signal` into
|
|
362
|
+
// `abortController` manually so caller-driven cancellation propagates.
|
|
363
|
+
let combinedSignal = abortController.signal;
|
|
364
|
+
// Set in the Node 18 fallback path so the caller's `signal.addEventListener`
|
|
365
|
+
// registration can be cleared once the stream finishes. Without this, a
|
|
366
|
+
// long-lived caller signal (e.g. one reused across many `writer()` calls)
|
|
367
|
+
// accumulates listeners on every completed turn.
|
|
368
|
+
let removeCallerAbortListener;
|
|
369
|
+
if (options?.signal) {
|
|
370
|
+
if (typeof AbortSignal.any === "function") {
|
|
371
|
+
combinedSignal = AbortSignal.any([options.signal, abortController.signal]);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
const callerSignal = options.signal;
|
|
375
|
+
if (callerSignal.aborted) {
|
|
376
|
+
abortController.abort(callerSignal.reason);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
const onCallerAbort = () => abortController.abort(callerSignal.reason);
|
|
380
|
+
callerSignal.addEventListener("abort", onCallerAbort, { once: true });
|
|
381
|
+
removeCallerAbortListener = () => callerSignal.removeEventListener("abort", onCallerAbort);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Resolve the init promise eagerly so we can capture which one this
|
|
386
|
+
// writer uses for reactive invalidation below.
|
|
387
|
+
const writerInitPromise = (() => {
|
|
388
|
+
if (this.#initPromise) {
|
|
389
|
+
return this.#initPromise;
|
|
390
|
+
}
|
|
391
|
+
const fresh = apiClient.initializeSessionStream(this.sessionId, "out", options?.requestOptions, this.channel);
|
|
392
|
+
this.#initPromise = fresh;
|
|
393
|
+
// Evict on failure so the next call retries instead of returning a
|
|
394
|
+
// poisoned cache entry forever.
|
|
395
|
+
fresh.catch((err) => {
|
|
396
|
+
if (this.#initPromise === fresh) {
|
|
397
|
+
this.#initPromise = undefined;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return fresh;
|
|
401
|
+
})();
|
|
402
|
+
try {
|
|
403
|
+
const instance = new SessionStreamInstance({
|
|
404
|
+
apiClient,
|
|
405
|
+
baseUrl: apiClientManager.baseURL ?? "",
|
|
406
|
+
sessionId: this.sessionId,
|
|
407
|
+
io: "out",
|
|
408
|
+
source: readableStreamSource,
|
|
409
|
+
signal: combinedSignal,
|
|
410
|
+
requestOptions: options?.requestOptions,
|
|
411
|
+
initializeSession: () => writerInitPromise,
|
|
412
|
+
});
|
|
413
|
+
// Single internal chain that handles span lifecycle AND reactive
|
|
414
|
+
// invalidation. On rejection we evict the cached init promise so
|
|
415
|
+
// the next pipe()/writer() re-PUTs and recovers (e.g. when a
|
|
416
|
+
// cached S2 access token expired mid-process). Compare by identity
|
|
417
|
+
// so a concurrent caller's fresh promise isn't accidentally cleared.
|
|
418
|
+
// Customer awaiters still observe the rejection via the returned
|
|
419
|
+
// `waitUntilComplete()`; this chain just keeps the cleanup path
|
|
420
|
+
// from surfacing as unhandled.
|
|
421
|
+
instance.wait().then(() => {
|
|
422
|
+
removeCallerAbortListener?.();
|
|
423
|
+
span.end();
|
|
424
|
+
}, () => {
|
|
425
|
+
removeCallerAbortListener?.();
|
|
426
|
+
if (this.#initPromise === writerInitPromise) {
|
|
427
|
+
this.#initPromise = undefined;
|
|
428
|
+
}
|
|
429
|
+
span.end();
|
|
430
|
+
});
|
|
431
|
+
return {
|
|
432
|
+
stream: instance.stream,
|
|
433
|
+
waitUntilComplete: async () => {
|
|
434
|
+
return instance.wait();
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
removeCallerAbortListener?.();
|
|
440
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
441
|
+
span.end();
|
|
442
|
+
throw error;
|
|
443
|
+
}
|
|
444
|
+
if (error instanceof Error || typeof error === "string") {
|
|
445
|
+
span.recordException(error);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
span.recordException(String(error));
|
|
449
|
+
}
|
|
450
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
451
|
+
span.end();
|
|
452
|
+
throw error;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Write a single Trigger control record to `.out`. The record carries a
|
|
457
|
+
* `trigger-control` header valued with `subtype` plus any sibling
|
|
458
|
+
* `extraHeaders`; the body is empty. Control records are filtered out of
|
|
459
|
+
* the consumer-facing chunk stream by the SDK transport — readers route
|
|
460
|
+
* them via the `onControl` callback instead.
|
|
461
|
+
*
|
|
462
|
+
* The returned `lastEventId` is the S2 seq_num of the written record,
|
|
463
|
+
* useful for trim chains (e.g. trim back to the previous turn-complete).
|
|
464
|
+
*/
|
|
465
|
+
async writeControl(subtype, extraHeaders) {
|
|
466
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
467
|
+
return writeSessionControlRecord(apiClient, this.sessionId, "out", subtype, extraHeaders, this.channel);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Append an S2 `trim` command record to `.out`. Records with seq_num
|
|
471
|
+
* less than `earliestSeqNum` are eventually removed from the stream.
|
|
472
|
+
*
|
|
473
|
+
* Idempotent and monotonic at S2's layer (`max(existing, min(provided,
|
|
474
|
+
* current_tail))`) — backward trims are silently no-ops for deletion
|
|
475
|
+
* but still consume a seq_num. Used by `chat.agent`'s turn loop to
|
|
476
|
+
* keep `session.out` bounded to roughly one turn at steady state.
|
|
477
|
+
*/
|
|
478
|
+
async trimTo(earliestSeqNum) {
|
|
479
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
480
|
+
await trimSessionStream(apiClient, this.sessionId, earliestSeqNum, this.channel);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* The `.in` side of a Session's bidirectional channel pair. Mirrors
|
|
485
|
+
* {@link streams.input} — consumer-side primitives for the task
|
|
486
|
+
* (`on`/`once`/`peek`/`wait`/`waitWithIdleTimeout`) plus `send` for
|
|
487
|
+
* external clients. Keyed on the session rather than the run so a
|
|
488
|
+
* conversation can survive across run boundaries.
|
|
489
|
+
*/
|
|
490
|
+
export class SessionInputChannel {
|
|
491
|
+
sessionId;
|
|
492
|
+
channel;
|
|
493
|
+
constructor(sessionId, channel) {
|
|
494
|
+
this.sessionId = sessionId;
|
|
495
|
+
this.channel = channel;
|
|
496
|
+
}
|
|
497
|
+
#assertReservedChannelForWait(method) {
|
|
498
|
+
if (this.channel) {
|
|
499
|
+
throw new Error(`session.channel("${this.channel}").in.${method} is not supported: a named side channel does not wake a run. Use .in.on() / .in.once() to observe it instead.`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Send a single record to the channel. Called by external clients
|
|
504
|
+
* (browser, server action, another task) producing input for the run.
|
|
505
|
+
* Matches {@link streams.input.send} but session-scoped — the session
|
|
506
|
+
* is the address, no `runId` required.
|
|
507
|
+
*/
|
|
508
|
+
async send(value, requestOptions) {
|
|
509
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
510
|
+
const body = typeof value === "string" ? value : JSON.stringify(value);
|
|
511
|
+
const spanName = this.channel
|
|
512
|
+
? `sessions.open(${this.sessionId}).channel(${this.channel}).in.send()`
|
|
513
|
+
: `sessions.open(${this.sessionId}).in.send()`;
|
|
514
|
+
const $requestOptions = mergeRequestOptions({
|
|
515
|
+
tracer,
|
|
516
|
+
name: spanName,
|
|
517
|
+
icon: "sessions",
|
|
518
|
+
attributes: sessionAttributes(this.sessionId, {
|
|
519
|
+
io: "in",
|
|
520
|
+
...(this.channel ? { channel: this.channel } : {}),
|
|
521
|
+
}),
|
|
522
|
+
}, requestOptions);
|
|
523
|
+
await apiClient.appendToSessionStream(this.sessionId, "in", body, $requestOptions, this.channel);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Register a handler that fires for every record landing on `.in`.
|
|
527
|
+
* Buffered records are offered to the handler on attach, and handlers
|
|
528
|
+
* are cleaned up automatically when the task run completes. Returns
|
|
529
|
+
* `{ off }` to unsubscribe early.
|
|
530
|
+
*
|
|
531
|
+
* A handler that synchronously returns `true` CONSUMES the record: it
|
|
532
|
+
* won't be buffered for a later `once()` and won't be re-delivered on a
|
|
533
|
+
* future `on()` attach. Plain observers should return nothing.
|
|
534
|
+
*/
|
|
535
|
+
on(handler) {
|
|
536
|
+
return sessionStreams.on(this.sessionId, "in", handler, this.channel);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Wait for the next record on `.in` without suspending the run.
|
|
540
|
+
* Returns `{ ok: true, output }` on arrival or `{ ok: false, error }`
|
|
541
|
+
* when the timeout fires. Chain `.unwrap()` to get the data directly.
|
|
542
|
+
*/
|
|
543
|
+
once(options) {
|
|
544
|
+
const ctx = taskContext.ctx;
|
|
545
|
+
const runId = ctx?.run.id;
|
|
546
|
+
const innerPromise = sessionStreams.once(this.sessionId, "in", options, this.channel);
|
|
547
|
+
return new InputStreamOncePromise((resolve, reject) => {
|
|
548
|
+
tracer
|
|
549
|
+
.startActiveSpan(options?.spanName ?? `sessions.open(${this.sessionId}).in.once()`, async () => {
|
|
550
|
+
const result = await innerPromise;
|
|
551
|
+
resolve(result);
|
|
552
|
+
}, {
|
|
553
|
+
attributes: {
|
|
554
|
+
[SemanticInternalAttributes.STYLE_ICON]: "sessions",
|
|
555
|
+
[SemanticInternalAttributes.ENTITY_TYPE]: "session-stream",
|
|
556
|
+
...(runId
|
|
557
|
+
? {
|
|
558
|
+
[SemanticInternalAttributes.ENTITY_ID]: `${runId}:${this.sessionId}:${this.channel ?? ""}:in`,
|
|
559
|
+
}
|
|
560
|
+
: {}),
|
|
561
|
+
session: this.sessionId,
|
|
562
|
+
io: "in",
|
|
563
|
+
...(this.channel ? { channel: this.channel } : {}),
|
|
564
|
+
...accessoryAttributes({
|
|
565
|
+
items: this.channel
|
|
566
|
+
? [
|
|
567
|
+
{ text: this.channel, variant: "normal" },
|
|
568
|
+
{ text: "in", variant: "normal" },
|
|
569
|
+
]
|
|
570
|
+
: [{ text: `${this.sessionId}.in`, variant: "normal" }],
|
|
571
|
+
style: "codepath",
|
|
572
|
+
}),
|
|
573
|
+
},
|
|
574
|
+
})
|
|
575
|
+
.catch(reject);
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
/** Non-blocking peek at the head of the `.in` buffer. */
|
|
579
|
+
peek() {
|
|
580
|
+
return sessionStreams.peek(this.sessionId, "in", this.channel);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* The highest S2 sequence number that is safe to persist as consumed.
|
|
584
|
+
* This stays behind the earliest unconsumed record if a later record was
|
|
585
|
+
* handled first. Distinct from "last received", which advances for records
|
|
586
|
+
* that may still be pending.
|
|
587
|
+
*
|
|
588
|
+
* Used by `chat.agent` to persist the `.in` resume cursor on each
|
|
589
|
+
* `turn-complete` control record, so the next worker boot can subscribe
|
|
590
|
+
* past already-processed user messages.
|
|
591
|
+
*/
|
|
592
|
+
lastDispatchedSeqNum() {
|
|
593
|
+
return sessionStreams.lastDispatchedSeqNum(this.sessionId, "in", this.channel);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Suspend the current run until the next record arrives on `.in`.
|
|
597
|
+
* Unlike {@link once}, `wait()` frees compute while blocked — the
|
|
598
|
+
* run-engine waitpoint holds the run until the session append handler
|
|
599
|
+
* fires it. Only callable from inside `task.run()`.
|
|
600
|
+
*/
|
|
601
|
+
/**
|
|
602
|
+
* Suspend until the channel wakes this run, and read nothing.
|
|
603
|
+
*
|
|
604
|
+
* The waitpoint is only a wake signal: the append route commits the record to
|
|
605
|
+
* the channel before it drains any waitpoint, so once this resolves the
|
|
606
|
+
* record is durably readable from the channel itself, carrying its real
|
|
607
|
+
* sequence. Separating the wake from the read is what lets a consumer that
|
|
608
|
+
* owns its own delivery (the chat input router) reuse this without the
|
|
609
|
+
* channel also taking a record out from under it.
|
|
610
|
+
*
|
|
611
|
+
* @internal
|
|
612
|
+
*/
|
|
613
|
+
async awaitWake(options) {
|
|
614
|
+
this.#assertReservedChannelForWait("awaitWake()");
|
|
615
|
+
const ctx = taskContext.ctx;
|
|
616
|
+
if (!ctx) {
|
|
617
|
+
throw new Error("session.in.wait() can only be used from inside a task.run()");
|
|
618
|
+
}
|
|
619
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
620
|
+
const lastConsumedSeqNum = options?.lastSeqNum ?? sessionStreams.lastDispatchedSeqNum(this.sessionId, "in");
|
|
621
|
+
const response = await apiClient.createSessionStreamWaitpoint(ctx.run.id, {
|
|
622
|
+
session: this.sessionId,
|
|
623
|
+
io: "in",
|
|
624
|
+
timeout: options?.timeout,
|
|
625
|
+
idempotencyKey: options?.idempotencyKey,
|
|
626
|
+
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
627
|
+
tags: options?.tags,
|
|
628
|
+
lastSeqNum: lastConsumedSeqNum,
|
|
629
|
+
});
|
|
630
|
+
const waitResponse = await apiClient.waitForWaitpointToken({
|
|
631
|
+
runFriendlyId: ctx.run.id,
|
|
632
|
+
waitpointFriendlyId: response.waitpointId,
|
|
633
|
+
});
|
|
634
|
+
if (!waitResponse.success) {
|
|
635
|
+
throw new Error("Failed to block on session stream waitpoint");
|
|
636
|
+
}
|
|
637
|
+
sessionStreams.disconnectStream(this.sessionId, "in");
|
|
638
|
+
// Create the waitpoint span only once setup is complete, at the boundary
|
|
639
|
+
// where runtime.waitUntil pauses usage. Its identity must be present at
|
|
640
|
+
// span creation so the inspector also works while the run is waiting.
|
|
641
|
+
const wake = await traceSessionWait(this.sessionId, response.waitpointId, async () => {
|
|
642
|
+
const waitResult = await runtime.waitUntil(response.waitpointId);
|
|
643
|
+
if (!waitResult.ok) {
|
|
644
|
+
const parsed = waitResult.output !== undefined
|
|
645
|
+
? await conditionallyImportAndParsePacket({
|
|
646
|
+
data: waitResult.output,
|
|
647
|
+
dataType: waitResult.outputType ?? "application/json",
|
|
648
|
+
}, apiClient)
|
|
649
|
+
: undefined;
|
|
650
|
+
const error = new WaitpointTimeoutError(parsed?.message ?? "Timed out");
|
|
651
|
+
return { ok: false, error };
|
|
652
|
+
}
|
|
653
|
+
return { ok: true, waitpointId: response.waitpointId };
|
|
654
|
+
});
|
|
655
|
+
if (!wake.ok)
|
|
656
|
+
return wake;
|
|
657
|
+
sessionStreams.reconnectStream(this.sessionId, "in");
|
|
658
|
+
return wake;
|
|
659
|
+
}
|
|
660
|
+
wait(options) {
|
|
661
|
+
return new ManualWaitpointPromise(async (resolve, reject) => {
|
|
662
|
+
try {
|
|
663
|
+
this.#assertReservedChannelForWait("wait()");
|
|
664
|
+
const apiClient = apiClientManager.clientOrThrow();
|
|
665
|
+
const result = await tracer.startActiveSpan(options?.spanName ?? `sessions.open(${this.sessionId}).in.wait()`, async (span) => {
|
|
666
|
+
const wake = await this.awaitWake(options);
|
|
667
|
+
if (!wake.ok) {
|
|
668
|
+
span.recordException(wake.error);
|
|
669
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
670
|
+
return { ok: false, error: wake.error };
|
|
671
|
+
}
|
|
672
|
+
const record = await sessionStreams.onceRecord(this.sessionId, "in");
|
|
673
|
+
if (!record.ok) {
|
|
674
|
+
const error = new WaitpointTimeoutError("Timed out");
|
|
675
|
+
span.recordException(error);
|
|
676
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
677
|
+
return { ok: false, error };
|
|
678
|
+
}
|
|
679
|
+
sessionStreams.setLastSeqNum(this.sessionId, "in", record.output.seqNum);
|
|
680
|
+
const data = await conditionallyImportAndParsePacket({
|
|
681
|
+
data: typeof record.output.data === "string"
|
|
682
|
+
? record.output.data
|
|
683
|
+
: JSON.stringify(record.output.data),
|
|
684
|
+
dataType: "application/json",
|
|
685
|
+
}, apiClient);
|
|
686
|
+
return { ok: true, output: data };
|
|
687
|
+
}, {
|
|
688
|
+
attributes: {
|
|
689
|
+
[SemanticInternalAttributes.STYLE_ICON]: "sessions",
|
|
690
|
+
session: this.sessionId,
|
|
691
|
+
io: "in",
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
resolve(result);
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
reject(error);
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Wait for a record with an idle-then-suspend strategy. Keeps the run
|
|
703
|
+
* active (using compute) for `idleTimeoutInSeconds`, then suspends via
|
|
704
|
+
* {@link wait} if nothing arrives. If a record arrives during the idle
|
|
705
|
+
* phase the run responds without suspending.
|
|
706
|
+
*/
|
|
707
|
+
async waitWithIdleTimeout(options) {
|
|
708
|
+
this.#assertReservedChannelForWait("waitWithIdleTimeout()");
|
|
709
|
+
// eslint-disable-next-line no-this-alias
|
|
710
|
+
const self = this;
|
|
711
|
+
const spanName = options.spanName ?? `sessions.open(${this.sessionId}).in.waitWithIdleTimeout()`;
|
|
712
|
+
return tracer.startActiveSpan(spanName, async (span) => {
|
|
713
|
+
if (options.idleTimeoutInSeconds > 0) {
|
|
714
|
+
const warm = await traceSessionIdle(self.sessionId, options.idleTimeoutInSeconds, () => sessionStreams.once(self.sessionId, "in", {
|
|
715
|
+
timeoutMs: options.idleTimeoutInSeconds * 1000,
|
|
716
|
+
}));
|
|
717
|
+
if (warm.ok) {
|
|
718
|
+
span.setAttribute("wait.resolved", "idle");
|
|
719
|
+
return { ok: true, output: warm.output };
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (options.skipSuspend) {
|
|
723
|
+
// Match the cold-phase `self.wait()` result shape below so any
|
|
724
|
+
// caller that does `throw result.error` gets a real error
|
|
725
|
+
// instead of `undefined`.
|
|
726
|
+
span.setAttribute("wait.resolved", "skipped");
|
|
727
|
+
return {
|
|
728
|
+
ok: false,
|
|
729
|
+
error: new WaitpointTimeoutError("Idle timeout elapsed and skipSuspend is set"),
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
if (options.onSuspend) {
|
|
733
|
+
await options.onSuspend();
|
|
734
|
+
}
|
|
735
|
+
span.setAttribute("wait.resolved", "suspended");
|
|
736
|
+
const waitResult = await self.wait({
|
|
737
|
+
timeout: options.timeout,
|
|
738
|
+
spanName: "suspended",
|
|
739
|
+
});
|
|
740
|
+
if (waitResult.ok && options.onResume) {
|
|
741
|
+
await options.onResume();
|
|
742
|
+
}
|
|
743
|
+
return waitResult;
|
|
744
|
+
}, {
|
|
745
|
+
attributes: {
|
|
746
|
+
[SemanticInternalAttributes.STYLE_ICON]: "sessions",
|
|
747
|
+
session: self.sessionId,
|
|
748
|
+
io: "in",
|
|
749
|
+
},
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
// ─── helpers ────────────────────────────────────────────────────────
|
|
754
|
+
function sessionAttributes(id, extra) {
|
|
755
|
+
return {
|
|
756
|
+
session: id,
|
|
757
|
+
...(extra ?? {}),
|
|
758
|
+
...accessoryAttributes({
|
|
759
|
+
items: [{ text: id, variant: "normal" }],
|
|
760
|
+
style: "codepath",
|
|
761
|
+
}),
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function toAttr(value) {
|
|
765
|
+
return Array.isArray(value) ? value.join(",") : value;
|
|
766
|
+
}
|
|
767
|
+
//# sourceMappingURL=sessions.js.map
|