@langchain/langgraph-sdk 1.8.9 → 1.9.0
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 +90 -43
- package/dist/client/assistants/index.cjs +180 -0
- package/dist/client/assistants/index.cjs.map +1 -0
- package/dist/client/assistants/index.d.cts +155 -0
- package/dist/client/assistants/index.d.cts.map +1 -0
- package/dist/client/assistants/index.d.ts +155 -0
- package/dist/client/assistants/index.d.ts.map +1 -0
- package/dist/client/assistants/index.js +180 -0
- package/dist/client/assistants/index.js.map +1 -0
- package/dist/client/base.cjs +190 -0
- package/dist/client/base.cjs.map +1 -0
- package/dist/client/base.d.cts +84 -0
- package/dist/client/base.d.cts.map +1 -0
- package/dist/client/base.d.ts +84 -0
- package/dist/client/base.d.ts.map +1 -0
- package/dist/client/base.js +188 -0
- package/dist/client/base.js.map +1 -0
- package/dist/client/crons/index.cjs +159 -0
- package/dist/client/crons/index.cjs.map +1 -0
- package/dist/client/crons/index.d.cts +71 -0
- package/dist/client/crons/index.d.cts.map +1 -0
- package/dist/client/crons/index.d.ts +71 -0
- package/dist/client/crons/index.d.ts.map +1 -0
- package/dist/client/crons/index.js +159 -0
- package/dist/client/crons/index.js.map +1 -0
- package/dist/client/index.cjs +84 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +63 -0
- package/dist/client/index.d.cts.map +1 -0
- package/dist/client/index.d.ts +63 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +83 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/runs/index.cjs +275 -0
- package/dist/client/runs/index.cjs.map +1 -0
- package/dist/client/runs/index.d.cts +123 -0
- package/dist/client/runs/index.d.cts.map +1 -0
- package/dist/client/runs/index.d.ts +123 -0
- package/dist/client/runs/index.d.ts.map +1 -0
- package/dist/client/runs/index.js +275 -0
- package/dist/client/runs/index.js.map +1 -0
- package/dist/client/store/index.cjs +128 -0
- package/dist/client/store/index.cjs.map +1 -0
- package/dist/client/store/index.d.cts +75 -0
- package/dist/client/store/index.d.cts.map +1 -0
- package/dist/client/store/index.d.ts +75 -0
- package/dist/client/store/index.d.ts.map +1 -0
- package/dist/client/store/index.js +128 -0
- package/dist/client/store/index.js.map +1 -0
- package/dist/client/stream/error.cjs +18 -0
- package/dist/client/stream/error.cjs.map +1 -0
- package/dist/client/stream/error.d.cts +14 -0
- package/dist/client/stream/error.d.cts.map +1 -0
- package/dist/client/stream/error.d.ts +14 -0
- package/dist/client/stream/error.d.ts.map +1 -0
- package/dist/client/stream/error.js +18 -0
- package/dist/client/stream/error.js.map +1 -0
- package/dist/client/stream/handles/index.cjs +3 -0
- package/dist/client/stream/handles/index.d.ts +3 -0
- package/dist/client/stream/handles/index.js +4 -0
- package/dist/client/stream/handles/subagents.cjs +263 -0
- package/dist/client/stream/handles/subagents.cjs.map +1 -0
- package/dist/client/stream/handles/subagents.d.cts +45 -0
- package/dist/client/stream/handles/subagents.d.cts.map +1 -0
- package/dist/client/stream/handles/subagents.d.ts +45 -0
- package/dist/client/stream/handles/subagents.d.ts.map +1 -0
- package/dist/client/stream/handles/subagents.js +262 -0
- package/dist/client/stream/handles/subagents.js.map +1 -0
- package/dist/client/stream/handles/subgraphs.cjs +352 -0
- package/dist/client/stream/handles/subgraphs.cjs.map +1 -0
- package/dist/client/stream/handles/subgraphs.d.cts +82 -0
- package/dist/client/stream/handles/subgraphs.d.cts.map +1 -0
- package/dist/client/stream/handles/subgraphs.d.ts +82 -0
- package/dist/client/stream/handles/subgraphs.d.ts.map +1 -0
- package/dist/client/stream/handles/subgraphs.js +351 -0
- package/dist/client/stream/handles/subgraphs.js.map +1 -0
- package/dist/client/stream/handles/tools.cjs +92 -0
- package/dist/client/stream/handles/tools.cjs.map +1 -0
- package/dist/client/stream/handles/tools.d.cts +26 -0
- package/dist/client/stream/handles/tools.d.cts.map +1 -0
- package/dist/client/stream/handles/tools.d.ts +26 -0
- package/dist/client/stream/handles/tools.d.ts.map +1 -0
- package/dist/client/stream/handles/tools.js +92 -0
- package/dist/client/stream/handles/tools.js.map +1 -0
- package/dist/client/stream/index.cjs +1368 -0
- package/dist/client/stream/index.cjs.map +1 -0
- package/dist/client/stream/index.d.cts +238 -0
- package/dist/client/stream/index.d.cts.map +1 -0
- package/dist/client/stream/index.d.ts +238 -0
- package/dist/client/stream/index.d.ts.map +1 -0
- package/dist/client/stream/index.js +1367 -0
- package/dist/client/stream/index.js.map +1 -0
- package/dist/client/stream/media.cjs +506 -0
- package/dist/client/stream/media.cjs.map +1 -0
- package/dist/client/stream/media.d.cts +164 -0
- package/dist/client/stream/media.d.cts.map +1 -0
- package/dist/client/stream/media.d.ts +164 -0
- package/dist/client/stream/media.d.ts.map +1 -0
- package/dist/client/stream/media.js +505 -0
- package/dist/client/stream/media.js.map +1 -0
- package/dist/client/stream/messages.cjs +635 -0
- package/dist/client/stream/messages.cjs.map +1 -0
- package/dist/client/stream/messages.d.cts +139 -0
- package/dist/client/stream/messages.d.cts.map +1 -0
- package/dist/client/stream/messages.d.ts +139 -0
- package/dist/client/stream/messages.d.ts.map +1 -0
- package/dist/client/stream/messages.js +631 -0
- package/dist/client/stream/messages.js.map +1 -0
- package/dist/client/stream/multi-cursor-buffer.cjs +55 -0
- package/dist/client/stream/multi-cursor-buffer.cjs.map +1 -0
- package/dist/client/stream/multi-cursor-buffer.js +55 -0
- package/dist/client/stream/multi-cursor-buffer.js.map +1 -0
- package/dist/client/stream/subscription.cjs +85 -0
- package/dist/client/stream/subscription.cjs.map +1 -0
- package/dist/client/stream/subscription.d.cts +22 -0
- package/dist/client/stream/subscription.d.cts.map +1 -0
- package/dist/client/stream/subscription.d.ts +22 -0
- package/dist/client/stream/subscription.d.ts.map +1 -0
- package/dist/client/stream/subscription.js +84 -0
- package/dist/client/stream/subscription.js.map +1 -0
- package/dist/client/stream/transport/agent-server.cjs +45 -0
- package/dist/client/stream/transport/agent-server.cjs.map +1 -0
- package/dist/client/stream/transport/agent-server.d.cts +39 -0
- package/dist/client/stream/transport/agent-server.d.cts.map +1 -0
- package/dist/client/stream/transport/agent-server.d.ts +39 -0
- package/dist/client/stream/transport/agent-server.d.ts.map +1 -0
- package/dist/client/stream/transport/agent-server.js +45 -0
- package/dist/client/stream/transport/agent-server.js.map +1 -0
- package/dist/client/stream/transport/constants.cjs +10 -0
- package/dist/client/stream/transport/constants.cjs.map +1 -0
- package/dist/client/stream/transport/constants.js +10 -0
- package/dist/client/stream/transport/constants.js.map +1 -0
- package/dist/client/stream/transport/decoder.cjs +115 -0
- package/dist/client/stream/transport/decoder.cjs.map +1 -0
- package/dist/client/stream/transport/decoder.js +114 -0
- package/dist/client/stream/transport/decoder.js.map +1 -0
- package/dist/client/stream/transport/http.cjs +183 -0
- package/dist/client/stream/transport/http.cjs.map +1 -0
- package/dist/client/stream/transport/http.d.cts +45 -0
- package/dist/client/stream/transport/http.d.cts.map +1 -0
- package/dist/client/stream/transport/http.d.ts +45 -0
- package/dist/client/stream/transport/http.d.ts.map +1 -0
- package/dist/client/stream/transport/http.js +183 -0
- package/dist/client/stream/transport/http.js.map +1 -0
- package/dist/client/stream/transport/index.cjs +3 -0
- package/dist/client/stream/transport/index.js +4 -0
- package/dist/client/stream/transport/queue.cjs +55 -0
- package/dist/client/stream/transport/queue.cjs.map +1 -0
- package/dist/client/stream/transport/queue.js +55 -0
- package/dist/client/stream/transport/queue.js.map +1 -0
- package/dist/client/stream/transport/stream.cjs +79 -0
- package/dist/client/stream/transport/stream.cjs.map +1 -0
- package/dist/client/stream/transport/stream.js +79 -0
- package/dist/client/stream/transport/stream.js.map +1 -0
- package/dist/client/stream/transport/types.d.cts +29 -0
- package/dist/client/stream/transport/types.d.cts.map +1 -0
- package/dist/client/stream/transport/types.d.ts +29 -0
- package/dist/client/stream/transport/types.d.ts.map +1 -0
- package/dist/client/stream/transport/utils.cjs +45 -0
- package/dist/client/stream/transport/utils.cjs.map +1 -0
- package/dist/client/stream/transport/utils.js +39 -0
- package/dist/client/stream/transport/utils.js.map +1 -0
- package/dist/client/stream/transport/websocket.cjs +155 -0
- package/dist/client/stream/transport/websocket.cjs.map +1 -0
- package/dist/client/stream/transport/websocket.d.cts +36 -0
- package/dist/client/stream/transport/websocket.d.cts.map +1 -0
- package/dist/client/stream/transport/websocket.d.ts +36 -0
- package/dist/client/stream/transport/websocket.d.ts.map +1 -0
- package/dist/client/stream/transport/websocket.js +155 -0
- package/dist/client/stream/transport/websocket.js.map +1 -0
- package/dist/client/stream/transport.d.cts +104 -0
- package/dist/client/stream/transport.d.cts.map +1 -0
- package/dist/client/stream/transport.d.ts +104 -0
- package/dist/client/stream/transport.d.ts.map +1 -0
- package/dist/client/stream/types.d.cts +208 -0
- package/dist/client/stream/types.d.cts.map +1 -0
- package/dist/client/stream/types.d.ts +208 -0
- package/dist/client/stream/types.d.ts.map +1 -0
- package/dist/client/threads/index.cjs +271 -0
- package/dist/client/threads/index.cjs.map +1 -0
- package/dist/client/threads/index.d.cts +235 -0
- package/dist/client/threads/index.d.cts.map +1 -0
- package/dist/client/threads/index.d.ts +235 -0
- package/dist/client/threads/index.d.ts.map +1 -0
- package/dist/client/threads/index.js +270 -0
- package/dist/client/threads/index.js.map +1 -0
- package/dist/client/ui-internal/index.cjs +29 -0
- package/dist/client/ui-internal/index.cjs.map +1 -0
- package/dist/client/ui-internal/index.d.cts +11 -0
- package/dist/client/ui-internal/index.d.cts.map +1 -0
- package/dist/client/ui-internal/index.d.ts +11 -0
- package/dist/client/ui-internal/index.d.ts.map +1 -0
- package/dist/client/ui-internal/index.js +29 -0
- package/dist/client/ui-internal/index.js.map +1 -0
- package/dist/client.cjs +35 -1308
- package/dist/client.d.cts +19 -857
- package/dist/client.d.ts +19 -857
- package/dist/client.js +16 -1301
- package/dist/index.cjs +25 -4
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +14 -3
- package/dist/react/stream.cjs.map +1 -1
- package/dist/react/stream.custom.cjs +1 -1
- package/dist/react/stream.custom.js +1 -1
- package/dist/react/stream.d.cts +2 -1
- package/dist/react/stream.d.cts.map +1 -1
- package/dist/react/stream.d.ts +2 -1
- package/dist/react/stream.d.ts.map +1 -1
- package/dist/react/stream.js.map +1 -1
- package/dist/react/stream.lgp.cjs +8 -6
- package/dist/react/stream.lgp.cjs.map +1 -1
- package/dist/react/stream.lgp.js +6 -4
- package/dist/react/stream.lgp.js.map +1 -1
- package/dist/react/types.d.cts +1 -1
- package/dist/react/types.d.ts +1 -1
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react-ui/server/server.cjs +1 -1
- package/dist/react-ui/server/server.cjs.map +1 -1
- package/dist/react-ui/server/server.js +1 -1
- package/dist/react-ui/server/server.js.map +1 -1
- package/dist/react-ui/types.cjs.map +1 -1
- package/dist/react-ui/types.d.cts +1 -1
- package/dist/react-ui/types.d.cts.map +1 -1
- package/dist/react-ui/types.d.ts +1 -1
- package/dist/react-ui/types.d.ts.map +1 -1
- package/dist/react-ui/types.js.map +1 -1
- package/dist/stream/assembled-to-message.cjs +121 -0
- package/dist/stream/assembled-to-message.cjs.map +1 -0
- package/dist/stream/assembled-to-message.d.cts +35 -0
- package/dist/stream/assembled-to-message.d.cts.map +1 -0
- package/dist/stream/assembled-to-message.d.ts +35 -0
- package/dist/stream/assembled-to-message.d.ts.map +1 -0
- package/dist/stream/assembled-to-message.js +119 -0
- package/dist/stream/assembled-to-message.js.map +1 -0
- package/dist/stream/channel-registry.cjs +224 -0
- package/dist/stream/channel-registry.cjs.map +1 -0
- package/dist/stream/channel-registry.d.cts +102 -0
- package/dist/stream/channel-registry.d.cts.map +1 -0
- package/dist/stream/channel-registry.d.ts +102 -0
- package/dist/stream/channel-registry.d.ts.map +1 -0
- package/dist/stream/channel-registry.js +224 -0
- package/dist/stream/channel-registry.js.map +1 -0
- package/dist/stream/constants.cjs +11 -0
- package/dist/stream/constants.cjs.map +1 -0
- package/dist/stream/constants.d.cts +10 -0
- package/dist/stream/constants.d.cts.map +1 -0
- package/dist/stream/constants.d.ts +10 -0
- package/dist/stream/constants.d.ts.map +1 -0
- package/dist/stream/constants.js +11 -0
- package/dist/stream/constants.js.map +1 -0
- package/dist/stream/controller.cjs +933 -0
- package/dist/stream/controller.cjs.map +1 -0
- package/dist/stream/controller.d.cts +135 -0
- package/dist/stream/controller.d.cts.map +1 -0
- package/dist/stream/controller.d.ts +135 -0
- package/dist/stream/controller.d.ts.map +1 -0
- package/dist/stream/controller.js +910 -0
- package/dist/stream/controller.js.map +1 -0
- package/dist/stream/discovery/index.d.ts +2 -0
- package/dist/stream/discovery/subagents.cjs +235 -0
- package/dist/stream/discovery/subagents.cjs.map +1 -0
- package/dist/stream/discovery/subagents.d.cts +18 -0
- package/dist/stream/discovery/subagents.d.cts.map +1 -0
- package/dist/stream/discovery/subagents.d.ts +18 -0
- package/dist/stream/discovery/subagents.d.ts.map +1 -0
- package/dist/stream/discovery/subagents.js +235 -0
- package/dist/stream/discovery/subagents.js.map +1 -0
- package/dist/stream/discovery/subgraphs.cjs +153 -0
- package/dist/stream/discovery/subgraphs.cjs.map +1 -0
- package/dist/stream/discovery/subgraphs.d.cts +19 -0
- package/dist/stream/discovery/subgraphs.d.cts.map +1 -0
- package/dist/stream/discovery/subgraphs.d.ts +19 -0
- package/dist/stream/discovery/subgraphs.d.ts.map +1 -0
- package/dist/stream/discovery/subgraphs.js +153 -0
- package/dist/stream/discovery/subgraphs.js.map +1 -0
- package/dist/stream/index.cjs +36 -0
- package/dist/stream/index.d.cts +25 -0
- package/dist/stream/index.d.ts +25 -0
- package/dist/stream/index.js +16 -0
- package/dist/stream/lifecycle-loading-tracker.cjs +83 -0
- package/dist/stream/lifecycle-loading-tracker.cjs.map +1 -0
- package/dist/stream/lifecycle-loading-tracker.js +83 -0
- package/dist/stream/lifecycle-loading-tracker.js.map +1 -0
- package/dist/stream/message-metadata-tracker.cjs +165 -0
- package/dist/stream/message-metadata-tracker.cjs.map +1 -0
- package/dist/stream/message-metadata-tracker.d.cts +24 -0
- package/dist/stream/message-metadata-tracker.d.cts.map +1 -0
- package/dist/stream/message-metadata-tracker.d.ts +24 -0
- package/dist/stream/message-metadata-tracker.d.ts.map +1 -0
- package/dist/stream/message-metadata-tracker.js +165 -0
- package/dist/stream/message-metadata-tracker.js.map +1 -0
- package/dist/stream/message-reconciliation.cjs +118 -0
- package/dist/stream/message-reconciliation.cjs.map +1 -0
- package/dist/stream/message-reconciliation.js +115 -0
- package/dist/stream/message-reconciliation.js.map +1 -0
- package/dist/stream/namespace.cjs +54 -0
- package/dist/stream/namespace.cjs.map +1 -0
- package/dist/stream/namespace.js +49 -0
- package/dist/stream/namespace.js.map +1 -0
- package/dist/stream/projections/channel.cjs +53 -0
- package/dist/stream/projections/channel.cjs.map +1 -0
- package/dist/stream/projections/channel.d.cts +22 -0
- package/dist/stream/projections/channel.d.cts.map +1 -0
- package/dist/stream/projections/channel.d.ts +22 -0
- package/dist/stream/projections/channel.d.ts.map +1 -0
- package/dist/stream/projections/channel.js +53 -0
- package/dist/stream/projections/channel.js.map +1 -0
- package/dist/stream/projections/extension.cjs +29 -0
- package/dist/stream/projections/extension.cjs.map +1 -0
- package/dist/stream/projections/extension.d.cts +7 -0
- package/dist/stream/projections/extension.d.cts.map +1 -0
- package/dist/stream/projections/extension.d.ts +7 -0
- package/dist/stream/projections/extension.d.ts.map +1 -0
- package/dist/stream/projections/extension.js +29 -0
- package/dist/stream/projections/extension.js.map +1 -0
- package/dist/stream/projections/index.cjs +6 -0
- package/dist/stream/projections/index.d.ts +6 -0
- package/dist/stream/projections/index.js +7 -0
- package/dist/stream/projections/media.cjs +81 -0
- package/dist/stream/projections/media.cjs.map +1 -0
- package/dist/stream/projections/media.d.cts +18 -0
- package/dist/stream/projections/media.d.cts.map +1 -0
- package/dist/stream/projections/media.d.ts +18 -0
- package/dist/stream/projections/media.d.ts.map +1 -0
- package/dist/stream/projections/media.js +78 -0
- package/dist/stream/projections/media.js.map +1 -0
- package/dist/stream/projections/messages.cjs +121 -0
- package/dist/stream/projections/messages.cjs.map +1 -0
- package/dist/stream/projections/messages.d.cts +8 -0
- package/dist/stream/projections/messages.d.cts.map +1 -0
- package/dist/stream/projections/messages.d.ts +8 -0
- package/dist/stream/projections/messages.d.ts.map +1 -0
- package/dist/stream/projections/messages.js +121 -0
- package/dist/stream/projections/messages.js.map +1 -0
- package/dist/stream/projections/runtime.cjs +44 -0
- package/dist/stream/projections/runtime.cjs.map +1 -0
- package/dist/stream/projections/runtime.js +44 -0
- package/dist/stream/projections/runtime.js.map +1 -0
- package/dist/stream/projections/tool-calls.cjs +50 -0
- package/dist/stream/projections/tool-calls.cjs.map +1 -0
- package/dist/stream/projections/tool-calls.d.cts +8 -0
- package/dist/stream/projections/tool-calls.d.cts.map +1 -0
- package/dist/stream/projections/tool-calls.d.ts +8 -0
- package/dist/stream/projections/tool-calls.d.ts.map +1 -0
- package/dist/stream/projections/tool-calls.js +50 -0
- package/dist/stream/projections/tool-calls.js.map +1 -0
- package/dist/stream/projections/values.cjs +52 -0
- package/dist/stream/projections/values.cjs.map +1 -0
- package/dist/stream/projections/values.d.cts +7 -0
- package/dist/stream/projections/values.d.cts.map +1 -0
- package/dist/stream/projections/values.d.ts +6 -0
- package/dist/stream/projections/values.d.ts.map +1 -0
- package/dist/stream/projections/values.js +52 -0
- package/dist/stream/projections/values.js.map +1 -0
- package/dist/stream/root-message-projection.cjs +256 -0
- package/dist/stream/root-message-projection.cjs.map +1 -0
- package/dist/stream/root-message-projection.js +256 -0
- package/dist/stream/root-message-projection.js.map +1 -0
- package/dist/stream/store.cjs +32 -0
- package/dist/stream/store.cjs.map +1 -0
- package/dist/stream/store.d.cts +37 -0
- package/dist/stream/store.d.cts.map +1 -0
- package/dist/stream/store.d.ts +37 -0
- package/dist/stream/store.d.ts.map +1 -0
- package/dist/stream/store.js +32 -0
- package/dist/stream/store.js.map +1 -0
- package/dist/stream/submit-coordinator.cjs +399 -0
- package/dist/stream/submit-coordinator.cjs.map +1 -0
- package/dist/stream/submit-coordinator.d.cts +27 -0
- package/dist/stream/submit-coordinator.d.cts.map +1 -0
- package/dist/stream/submit-coordinator.d.ts +27 -0
- package/dist/stream/submit-coordinator.d.ts.map +1 -0
- package/dist/stream/submit-coordinator.js +397 -0
- package/dist/stream/submit-coordinator.js.map +1 -0
- package/dist/stream/tool-calls.cjs +15 -0
- package/dist/stream/tool-calls.cjs.map +1 -0
- package/dist/stream/tool-calls.js +15 -0
- package/dist/stream/tool-calls.js.map +1 -0
- package/dist/stream/types-inference.d.cts +43 -0
- package/dist/stream/types-inference.d.cts.map +1 -0
- package/dist/stream/types-inference.d.ts +43 -0
- package/dist/stream/types-inference.d.ts.map +1 -0
- package/dist/stream/types.d.cts +354 -0
- package/dist/stream/types.d.cts.map +1 -0
- package/dist/stream/types.d.ts +354 -0
- package/dist/stream/types.d.ts.map +1 -0
- package/dist/types.d.cts +2 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/index.cjs +1 -1
- package/dist/ui/index.d.cts +3 -3
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui/index.js +1 -1
- package/dist/ui/manager.cjs +2 -2
- package/dist/ui/manager.cjs.map +1 -1
- package/dist/ui/manager.d.cts +1 -0
- package/dist/ui/manager.d.cts.map +1 -1
- package/dist/ui/manager.d.ts +1 -0
- package/dist/ui/manager.d.ts.map +1 -1
- package/dist/ui/manager.js +2 -2
- package/dist/ui/manager.js.map +1 -1
- package/dist/ui/messages.cjs +50 -7
- package/dist/ui/messages.cjs.map +1 -1
- package/dist/ui/messages.d.cts.map +1 -1
- package/dist/ui/messages.d.ts.map +1 -1
- package/dist/ui/messages.js +51 -9
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/orchestrator-custom.cjs +1 -1
- package/dist/ui/orchestrator-custom.js +1 -1
- package/dist/ui/orchestrator.cjs +4 -3
- package/dist/ui/orchestrator.cjs.map +1 -1
- package/dist/ui/orchestrator.d.cts +1 -1
- package/dist/ui/orchestrator.d.cts.map +1 -1
- package/dist/ui/orchestrator.d.ts +1 -1
- package/dist/ui/orchestrator.d.ts.map +1 -1
- package/dist/ui/orchestrator.js +4 -3
- package/dist/ui/orchestrator.js.map +1 -1
- package/dist/ui/stream/agent.d.cts +1 -1
- package/dist/ui/stream/agent.d.cts.map +1 -1
- package/dist/ui/stream/agent.d.ts +1 -1
- package/dist/ui/stream/agent.d.ts.map +1 -1
- package/dist/ui/stream/base.d.cts +7 -6
- package/dist/ui/stream/base.d.cts.map +1 -1
- package/dist/ui/stream/base.d.ts +7 -6
- package/dist/ui/stream/base.d.ts.map +1 -1
- package/dist/ui/stream/deep-agent.d.cts +1 -1
- package/dist/ui/stream/deep-agent.d.cts.map +1 -1
- package/dist/ui/stream/deep-agent.d.ts +1 -1
- package/dist/ui/stream/deep-agent.d.ts.map +1 -1
- package/dist/ui/stream/index.d.cts +4 -4
- package/dist/ui/stream/index.d.cts.map +1 -1
- package/dist/ui/stream/index.d.ts +4 -4
- package/dist/ui/stream/index.d.ts.map +1 -1
- package/dist/ui/types.d.cts +3 -2
- package/dist/ui/types.d.cts.map +1 -1
- package/dist/ui/types.d.ts +2 -1
- package/dist/ui/types.d.ts.map +1 -1
- package/package.json +18 -8
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { v7 } from "uuid";
|
|
2
|
+
//#region src/stream/submit-coordinator.ts
|
|
3
|
+
/**
|
|
4
|
+
* Owns the run-submission lifecycle for a single
|
|
5
|
+
* {@link StreamController}.
|
|
6
|
+
*
|
|
7
|
+
* # What this module is
|
|
8
|
+
*
|
|
9
|
+
* The {@link SubmitCoordinator} is the piece of the controller that
|
|
10
|
+
* dispatches runs (`submit()`), enforces multitask strategies, queues
|
|
11
|
+
* deferred submissions, races dispatch against terminal lifecycle
|
|
12
|
+
* events, and surfaces errors back through the per-submit `onError`
|
|
13
|
+
* callback and the root snapshot.
|
|
14
|
+
*
|
|
15
|
+
* Conceptually a submit looks like:
|
|
16
|
+
*
|
|
17
|
+
* 1. Optionally rebind to a different thread (`options.threadId`).
|
|
18
|
+
* 2. Mint a thread id if one isn't bound yet.
|
|
19
|
+
* 3. Wait for the controller's root pump to be ready (so the
|
|
20
|
+
* transport is subscribed before the run is dispatched —
|
|
21
|
+
* otherwise we could miss replayed events).
|
|
22
|
+
* 4. Apply the {@link StreamSubmitOptions.multitaskStrategy} to
|
|
23
|
+
* decide whether to abort, enqueue, reject, or proceed.
|
|
24
|
+
* 5. Race the dispatch promise (`thread.submitRun()` or
|
|
25
|
+
* `thread.respondInput()` for resumes) against the next root
|
|
26
|
+
* terminal lifecycle event.
|
|
27
|
+
* 6. Settle the resulting state (loading flag, error slot) and
|
|
28
|
+
* drain the next queued submission, if any.
|
|
29
|
+
*
|
|
30
|
+
* # Why it lives in its own class
|
|
31
|
+
*
|
|
32
|
+
* The submit lifecycle is the most state-heavy part of the
|
|
33
|
+
* controller — six promises, an abort controller, a queue, a
|
|
34
|
+
* terminal-vs-command race, and bidirectional callback wiring with
|
|
35
|
+
* the controller. Splitting it out keeps `controller.ts` focused on
|
|
36
|
+
* subscription / projection wiring while letting the submit logic
|
|
37
|
+
* evolve independently.
|
|
38
|
+
*
|
|
39
|
+
* # Why we race "command" against "terminal"
|
|
40
|
+
*
|
|
41
|
+
* For fast runs, the server's terminal lifecycle event can arrive
|
|
42
|
+
* *before* the dispatch HTTP response has resolved. Racing the two
|
|
43
|
+
* lets us detect terminal early and not block waiting for a now-stale
|
|
44
|
+
* dispatch response. The dispatch response is still consumed (via
|
|
45
|
+
* `.then(notifyCreated).catch(reportError)`) so `onCreated` still
|
|
46
|
+
* fires and dispatch errors still surface through `onError`.
|
|
47
|
+
*
|
|
48
|
+
* # Queue semantics (`multitaskStrategy: "enqueue"`)
|
|
49
|
+
*
|
|
50
|
+
* When a run is already in flight, an `"enqueue"` submit is recorded
|
|
51
|
+
* into {@link queueStore} and the call returns immediately. After the
|
|
52
|
+
* active run terminates, `#drainQueue` schedules the head of the
|
|
53
|
+
* queue as a fresh submit on the next macrotask. Each drained
|
|
54
|
+
* submission has its own `multitaskStrategy` cleared so it doesn't
|
|
55
|
+
* recursively re-enqueue.
|
|
56
|
+
*
|
|
57
|
+
* @see StreamController - The owner; injects every collaborator dep.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Frozen empty queue value used as the initial / cleared snapshot.
|
|
61
|
+
*
|
|
62
|
+
* Reusing one frozen reference keeps store identity stable across
|
|
63
|
+
* empty resets, so React's `useSyncExternalStore` doesn't think the
|
|
64
|
+
* queue changed when it actually didn't.
|
|
65
|
+
*/
|
|
66
|
+
const EMPTY_QUEUE = Object.freeze([]);
|
|
67
|
+
/**
|
|
68
|
+
* Coordinates one controller's run-submission lifecycle.
|
|
69
|
+
*
|
|
70
|
+
* The constructor takes a bag of callbacks rather than a reference to
|
|
71
|
+
* the parent {@link StreamController} on purpose:
|
|
72
|
+
*
|
|
73
|
+
* - It keeps the dependency surface explicit and testable — every
|
|
74
|
+
* piece of controller state the submit lifecycle touches is one
|
|
75
|
+
* of these closures.
|
|
76
|
+
* - It avoids a cyclic dependency between controller and coordinator.
|
|
77
|
+
* - Tests can construct one with stub callbacks and assert behavior
|
|
78
|
+
* without mocking the entire controller.
|
|
79
|
+
*
|
|
80
|
+
* @typeParam StateType - Root state shape.
|
|
81
|
+
* @typeParam InterruptType - Root interrupt payload shape.
|
|
82
|
+
* @typeParam ConfigurableType - `config.configurable` shape accepted
|
|
83
|
+
* by submit (usually `Record<string, unknown>`).
|
|
84
|
+
*/
|
|
85
|
+
var SubmitCoordinator = class {
|
|
86
|
+
/** Controller-level options forwarded into `submitRun` / callbacks. */
|
|
87
|
+
#options;
|
|
88
|
+
/** Root snapshot store; written for `isLoading`, `error`, `interrupts`. */
|
|
89
|
+
#rootStore;
|
|
90
|
+
/** Pending submissions awaiting the active run to terminate. */
|
|
91
|
+
#queueStore;
|
|
92
|
+
/** Probes the controller's `disposed` flag from deferred work. */
|
|
93
|
+
#getDisposed;
|
|
94
|
+
/** Reads the controller's currently-bound thread id. */
|
|
95
|
+
#getCurrentThreadId;
|
|
96
|
+
/** Updates the controller's thread id (used when minting a new id). */
|
|
97
|
+
#setCurrentThreadId;
|
|
98
|
+
/** Records a thread id we created client-side so hydrate can skip a 404 round-trip. */
|
|
99
|
+
#rememberSelfCreatedThreadId;
|
|
100
|
+
/** Triggers a hydrate on the controller (used by `options.threadId` rebinds). */
|
|
101
|
+
#hydrate;
|
|
102
|
+
/** Lazily creates / returns the active {@link ThreadStream}. */
|
|
103
|
+
#ensureThread;
|
|
104
|
+
/** Resolves once the controller's root subscription pump is up. */
|
|
105
|
+
#waitForRootPumpReady;
|
|
106
|
+
/** Resolves on the next root terminal lifecycle (or on abort). */
|
|
107
|
+
#awaitNextTerminal;
|
|
108
|
+
/** Returns the most recent unresolved root interrupt, for resumes. */
|
|
109
|
+
#latestUnresolvedInterrupt;
|
|
110
|
+
/** Marks an interrupt id as resolved so it isn't re-targeted. */
|
|
111
|
+
#markInterruptResolved;
|
|
112
|
+
/**
|
|
113
|
+
* Active submission's abort controller. `undefined` between submits.
|
|
114
|
+
*
|
|
115
|
+
* Used both for `multitaskStrategy: "rollback"` (abort the previous
|
|
116
|
+
* controller's signal) and `stop()` (abort the current one without
|
|
117
|
+
* starting a new one).
|
|
118
|
+
*/
|
|
119
|
+
#runAbort;
|
|
120
|
+
constructor(params) {
|
|
121
|
+
this.#options = params.options;
|
|
122
|
+
this.#rootStore = params.rootStore;
|
|
123
|
+
this.#queueStore = params.queueStore;
|
|
124
|
+
this.#getDisposed = params.getDisposed;
|
|
125
|
+
this.#getCurrentThreadId = params.getCurrentThreadId;
|
|
126
|
+
this.#setCurrentThreadId = params.setCurrentThreadId;
|
|
127
|
+
this.#rememberSelfCreatedThreadId = params.rememberSelfCreatedThreadId;
|
|
128
|
+
this.#hydrate = params.hydrate;
|
|
129
|
+
this.#ensureThread = params.ensureThread;
|
|
130
|
+
this.#waitForRootPumpReady = params.waitForRootPumpReady;
|
|
131
|
+
this.#awaitNextTerminal = params.awaitNextTerminal;
|
|
132
|
+
this.#latestUnresolvedInterrupt = params.latestUnresolvedInterrupt;
|
|
133
|
+
this.#markInterruptResolved = params.markInterruptResolved;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Submit input or a resume command to the active thread.
|
|
137
|
+
*
|
|
138
|
+
* Honours {@link StreamSubmitOptions.multitaskStrategy}:
|
|
139
|
+
*
|
|
140
|
+
* - `"rollback"` (default) — aborts any in-flight run and
|
|
141
|
+
* dispatches immediately.
|
|
142
|
+
* - `"reject"` — throws synchronously when a run is
|
|
143
|
+
* already in flight.
|
|
144
|
+
* - `"enqueue"` — defers via {@link #enqueueSubmission};
|
|
145
|
+
* the call returns without dispatching.
|
|
146
|
+
* - `"interrupt"` — falls through to the default path
|
|
147
|
+
* (server-side cancellation lands with roadmap A0.3).
|
|
148
|
+
*
|
|
149
|
+
* Errors are routed through both the per-submit `onError` callback
|
|
150
|
+
* and `rootStore.error`. Aborts (controller dispose / rollback) are
|
|
151
|
+
* silently dropped.
|
|
152
|
+
*
|
|
153
|
+
* @param input - Input payload, or `null`/`undefined` for no input
|
|
154
|
+
* (typical for resume commands).
|
|
155
|
+
* @param options - Per-submit options (config, metadata, callbacks,
|
|
156
|
+
* strategy, etc).
|
|
157
|
+
*/
|
|
158
|
+
async submit(input, options) {
|
|
159
|
+
if (this.#getDisposed()) return;
|
|
160
|
+
const overrideThreadId = options?.threadId;
|
|
161
|
+
if (overrideThreadId !== void 0 && overrideThreadId !== this.#getCurrentThreadId()) await this.#hydrate(overrideThreadId);
|
|
162
|
+
if (this.#getCurrentThreadId() == null) {
|
|
163
|
+
const threadId = v7();
|
|
164
|
+
this.#setCurrentThreadId(threadId);
|
|
165
|
+
this.#rememberSelfCreatedThreadId(threadId);
|
|
166
|
+
this.#options.onThreadId?.(threadId);
|
|
167
|
+
this.#rootStore.setState((s) => ({
|
|
168
|
+
...s,
|
|
169
|
+
threadId
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
const currentThreadId = this.#getCurrentThreadId();
|
|
173
|
+
if (currentThreadId == null) return;
|
|
174
|
+
const thread = this.#ensureThread(currentThreadId);
|
|
175
|
+
const activeThreadId = currentThreadId;
|
|
176
|
+
await this.#waitForRootPumpReady();
|
|
177
|
+
const strategy = options?.multitaskStrategy ?? "rollback";
|
|
178
|
+
const hasActiveRun = this.#runAbort != null && !this.#runAbort.signal.aborted;
|
|
179
|
+
if (hasActiveRun && strategy === "reject") throw new Error("submit() rejected: a run is already in flight and multitaskStrategy is 'reject'.");
|
|
180
|
+
if (hasActiveRun && strategy === "enqueue") {
|
|
181
|
+
this.#enqueueSubmission(input, options);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.#runAbort?.abort();
|
|
185
|
+
const abort = new AbortController();
|
|
186
|
+
this.#runAbort = abort;
|
|
187
|
+
const resumeCommand = options?.command?.resume;
|
|
188
|
+
const isResume = resumeCommand !== void 0;
|
|
189
|
+
this.#rootStore.setState((s) => ({
|
|
190
|
+
...s,
|
|
191
|
+
interrupts: [],
|
|
192
|
+
interrupt: void 0,
|
|
193
|
+
error: void 0,
|
|
194
|
+
isLoading: true
|
|
195
|
+
}));
|
|
196
|
+
const boundConfig = bindThreadConfig(options?.config, currentThreadId);
|
|
197
|
+
const terminalPromise = this.#awaitNextTerminal(abort.signal);
|
|
198
|
+
let terminalSettled = false;
|
|
199
|
+
const reportError = (error) => {
|
|
200
|
+
if (abort.signal.aborted) return;
|
|
201
|
+
this.#rootStore.setState((s) => ({
|
|
202
|
+
...s,
|
|
203
|
+
error
|
|
204
|
+
}));
|
|
205
|
+
try {
|
|
206
|
+
options?.onError?.(error);
|
|
207
|
+
} catch {}
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
let terminal;
|
|
211
|
+
if (isResume) {
|
|
212
|
+
const target = this.#latestUnresolvedInterrupt();
|
|
213
|
+
if (target == null) throw new Error("submit({ command: { resume } }) called but no pending protocol interrupt is available.");
|
|
214
|
+
const commandPromise = thread.respondInput({
|
|
215
|
+
namespace: target.namespace,
|
|
216
|
+
interrupt_id: target.interruptId,
|
|
217
|
+
response: resumeCommand
|
|
218
|
+
});
|
|
219
|
+
this.#markInterruptResolved(target.interruptId);
|
|
220
|
+
const first = await Promise.race([terminalPromise.then((value) => ({
|
|
221
|
+
type: "terminal",
|
|
222
|
+
value
|
|
223
|
+
})), commandPromise.then(() => ({ type: "command" }), (error) => ({
|
|
224
|
+
type: "error",
|
|
225
|
+
error
|
|
226
|
+
}))]);
|
|
227
|
+
if (first.type === "error") throw first.error;
|
|
228
|
+
if (first.type === "terminal") {
|
|
229
|
+
terminal = first.value;
|
|
230
|
+
terminalSettled = true;
|
|
231
|
+
commandPromise.catch((error) => {
|
|
232
|
+
if (!terminalSettled) reportError(error);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
const commandPromise = thread.submitRun({
|
|
237
|
+
input: input ?? null,
|
|
238
|
+
config: boundConfig,
|
|
239
|
+
metadata: options?.metadata ?? void 0,
|
|
240
|
+
forkFrom: options?.forkFrom,
|
|
241
|
+
multitaskStrategy: options?.multitaskStrategy === "enqueue" ? "enqueue" : options?.multitaskStrategy
|
|
242
|
+
});
|
|
243
|
+
const notifyCreated = (result) => {
|
|
244
|
+
this.#options.onCreated?.({
|
|
245
|
+
run_id: result.run_id,
|
|
246
|
+
thread_id: activeThreadId
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
const first = await Promise.race([terminalPromise.then((value) => ({
|
|
250
|
+
type: "terminal",
|
|
251
|
+
value
|
|
252
|
+
})), commandPromise.then((result) => ({
|
|
253
|
+
type: "command",
|
|
254
|
+
result
|
|
255
|
+
}), (error) => ({
|
|
256
|
+
type: "error",
|
|
257
|
+
error
|
|
258
|
+
}))]);
|
|
259
|
+
if (first.type === "error") throw first.error;
|
|
260
|
+
if (first.type === "command") notifyCreated(first.result);
|
|
261
|
+
else {
|
|
262
|
+
terminal = first.value;
|
|
263
|
+
terminalSettled = true;
|
|
264
|
+
commandPromise.then(notifyCreated).catch((error) => {
|
|
265
|
+
if (!terminalSettled) reportError(error);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
terminal ??= await terminalPromise;
|
|
270
|
+
terminalSettled = true;
|
|
271
|
+
if (terminal.event === "failed" && !abort.signal.aborted) {
|
|
272
|
+
const runError = new Error(terminal.error ?? "Run failed with no error message");
|
|
273
|
+
this.#rootStore.setState((s) => ({
|
|
274
|
+
...s,
|
|
275
|
+
error: runError
|
|
276
|
+
}));
|
|
277
|
+
try {
|
|
278
|
+
options?.onError?.(runError);
|
|
279
|
+
} catch {}
|
|
280
|
+
}
|
|
281
|
+
} catch (error) {
|
|
282
|
+
reportError(error);
|
|
283
|
+
} finally {
|
|
284
|
+
this.#rootStore.setState((s) => ({
|
|
285
|
+
...s,
|
|
286
|
+
isLoading: false
|
|
287
|
+
}));
|
|
288
|
+
if (this.#runAbort === abort) this.#runAbort = void 0;
|
|
289
|
+
setTimeout(() => this.#drainQueue(), 0);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Abort the current run (if any) and force `isLoading=false`.
|
|
294
|
+
*
|
|
295
|
+
* Does NOT issue a server-side cancel — that lands with roadmap
|
|
296
|
+
* A0.3. Today this is a client-side stop only: subsequent events
|
|
297
|
+
* for the aborted run are ignored by the controller's pump because
|
|
298
|
+
* the abort signal is the same one `#awaitNextTerminal` is wired
|
|
299
|
+
* to.
|
|
300
|
+
*/
|
|
301
|
+
async stop() {
|
|
302
|
+
this.abortActiveRun();
|
|
303
|
+
this.#rootStore.setState((s) => ({
|
|
304
|
+
...s,
|
|
305
|
+
isLoading: false
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Abort the current run without forcing the loading flag down.
|
|
310
|
+
*
|
|
311
|
+
* Used by {@link StreamController.dispose}: disposal already tears
|
|
312
|
+
* down the root store, so flipping `isLoading` here is unnecessary
|
|
313
|
+
* and would race the dispose path.
|
|
314
|
+
*/
|
|
315
|
+
abortActiveRun() {
|
|
316
|
+
this.#runAbort?.abort();
|
|
317
|
+
this.#runAbort = void 0;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Cancel a queued submission by id.
|
|
321
|
+
*
|
|
322
|
+
* @param id - Client-side queue entry id to remove.
|
|
323
|
+
* @returns `true` when the entry was found and dropped, `false` otherwise.
|
|
324
|
+
*/
|
|
325
|
+
async cancelQueued(id) {
|
|
326
|
+
const current = this.#queueStore.getSnapshot();
|
|
327
|
+
const next = current.filter((entry) => entry.id !== id);
|
|
328
|
+
if (next.length === current.length) return false;
|
|
329
|
+
this.#queueStore.setState(() => next);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Drop every queued submission. Server-side cancel arrives with A0.3.
|
|
334
|
+
*/
|
|
335
|
+
async clearQueue() {
|
|
336
|
+
this.#queueStore.setState(() => EMPTY_QUEUE);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Append a submission to the queue without dispatching.
|
|
340
|
+
*
|
|
341
|
+
* The drained submission is later run via {@link #drainQueue} after
|
|
342
|
+
* the active run terminates.
|
|
343
|
+
*/
|
|
344
|
+
#enqueueSubmission(input, options) {
|
|
345
|
+
const entry = {
|
|
346
|
+
id: v7(),
|
|
347
|
+
values: input ?? void 0,
|
|
348
|
+
options,
|
|
349
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
350
|
+
};
|
|
351
|
+
this.#queueStore.setState((current) => [...current, entry]);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Drain the head of the queue if no run is active.
|
|
355
|
+
*
|
|
356
|
+
* Called from the `finally` block of `submit()` on the next
|
|
357
|
+
* macrotask (so the just-finished run's state flushes first).
|
|
358
|
+
* Strips the strategy off the dequeued options to prevent infinite
|
|
359
|
+
* re-enqueueing.
|
|
360
|
+
*/
|
|
361
|
+
#drainQueue() {
|
|
362
|
+
if (this.#getDisposed()) return;
|
|
363
|
+
if (this.#runAbort != null && !this.#runAbort.signal.aborted) return;
|
|
364
|
+
const current = this.#queueStore.getSnapshot();
|
|
365
|
+
if (current.length === 0) return;
|
|
366
|
+
const [next, ...rest] = current;
|
|
367
|
+
this.#queueStore.setState(() => rest);
|
|
368
|
+
const nextOptions = {
|
|
369
|
+
...next.options ?? {},
|
|
370
|
+
multitaskStrategy: void 0
|
|
371
|
+
};
|
|
372
|
+
this.submit(next.values, nextOptions).catch(() => {});
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Merge `thread_id` into a user-supplied `config.configurable` blob.
|
|
377
|
+
*
|
|
378
|
+
* The platform expects `config.configurable.thread_id` on every run
|
|
379
|
+
* dispatch; we set it last so user-supplied values can't accidentally
|
|
380
|
+
* override the active thread id (which would route the run to a
|
|
381
|
+
* different thread).
|
|
382
|
+
*/
|
|
383
|
+
function bindThreadConfig(config, threadId) {
|
|
384
|
+
const base = config != null && typeof config === "object" ? config : {};
|
|
385
|
+
const configurable = base.configurable != null && typeof base.configurable === "object" ? base.configurable : {};
|
|
386
|
+
return {
|
|
387
|
+
...base,
|
|
388
|
+
configurable: {
|
|
389
|
+
...configurable,
|
|
390
|
+
thread_id: threadId
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
//#endregion
|
|
395
|
+
export { EMPTY_QUEUE, SubmitCoordinator };
|
|
396
|
+
|
|
397
|
+
//# sourceMappingURL=submit-coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submit-coordinator.js","names":["#options","#rootStore","#queueStore","#getDisposed","#getCurrentThreadId","#setCurrentThreadId","#rememberSelfCreatedThreadId","#hydrate","#ensureThread","#waitForRootPumpReady","#awaitNextTerminal","#latestUnresolvedInterrupt","#markInterruptResolved","uuidv7","#runAbort","#enqueueSubmission","#drainQueue"],"sources":["../../src/stream/submit-coordinator.ts"],"sourcesContent":["/**\n * Owns the run-submission lifecycle for a single\n * {@link StreamController}.\n *\n * # What this module is\n *\n * The {@link SubmitCoordinator} is the piece of the controller that\n * dispatches runs (`submit()`), enforces multitask strategies, queues\n * deferred submissions, races dispatch against terminal lifecycle\n * events, and surfaces errors back through the per-submit `onError`\n * callback and the root snapshot.\n *\n * Conceptually a submit looks like:\n *\n * 1. Optionally rebind to a different thread (`options.threadId`).\n * 2. Mint a thread id if one isn't bound yet.\n * 3. Wait for the controller's root pump to be ready (so the\n * transport is subscribed before the run is dispatched —\n * otherwise we could miss replayed events).\n * 4. Apply the {@link StreamSubmitOptions.multitaskStrategy} to\n * decide whether to abort, enqueue, reject, or proceed.\n * 5. Race the dispatch promise (`thread.submitRun()` or\n * `thread.respondInput()` for resumes) against the next root\n * terminal lifecycle event.\n * 6. Settle the resulting state (loading flag, error slot) and\n * drain the next queued submission, if any.\n *\n * # Why it lives in its own class\n *\n * The submit lifecycle is the most state-heavy part of the\n * controller — six promises, an abort controller, a queue, a\n * terminal-vs-command race, and bidirectional callback wiring with\n * the controller. Splitting it out keeps `controller.ts` focused on\n * subscription / projection wiring while letting the submit logic\n * evolve independently.\n *\n * # Why we race \"command\" against \"terminal\"\n *\n * For fast runs, the server's terminal lifecycle event can arrive\n * *before* the dispatch HTTP response has resolved. Racing the two\n * lets us detect terminal early and not block waiting for a now-stale\n * dispatch response. The dispatch response is still consumed (via\n * `.then(notifyCreated).catch(reportError)`) so `onCreated` still\n * fires and dispatch errors still surface through `onError`.\n *\n * # Queue semantics (`multitaskStrategy: \"enqueue\"`)\n *\n * When a run is already in flight, an `\"enqueue\"` submit is recorded\n * into {@link queueStore} and the call returns immediately. After the\n * active run terminates, `#drainQueue` schedules the head of the\n * queue as a fresh submit on the next macrotask. Each drained\n * submission has its own `multitaskStrategy` cleared so it doesn't\n * recursively re-enqueue.\n *\n * @see StreamController - The owner; injects every collaborator dep.\n */\nimport { v7 as uuidv7 } from \"uuid\";\nimport type { ThreadStream } from \"../client/stream/index.js\";\nimport { StreamStore } from \"./store.js\";\nimport type {\n RootSnapshot,\n StreamControllerOptions,\n StreamSubmitOptions,\n} from \"./types.js\";\n\n/**\n * Pointer to a pending root protocol interrupt. Used to target\n * `respondInput` for resume submissions.\n */\ninterface ResolvedInterrupt {\n interruptId: string;\n namespace: string[];\n}\n\n/**\n * Result of awaiting the next root terminal lifecycle event. Mirrors\n * the four terminal lifecycle states the protocol surfaces, plus a\n * synthetic `\"aborted\"` for client-side cancellation.\n */\ntype TerminalResult = {\n event: \"completed\" | \"failed\" | \"interrupted\" | \"aborted\";\n error?: string;\n};\n\n/**\n * Queued submission entry mirrored from the server-side run queue.\n *\n * Surfaces the deferred submission to UI consumers via\n * {@link StreamController.queueStore}.\n */\nexport interface SubmissionQueueEntry<\n StateType extends object = Record<string, unknown>,\n> {\n /** Stable id minted on enqueue (uuidv7 — sortable by creation time). */\n readonly id: string;\n /** Original submit input, narrowed to the partial state shape. */\n readonly values: Partial<StateType> | null | undefined;\n /** Original submit options, minus the strategy slot which is reset on drain. */\n readonly options?: StreamSubmitOptions<StateType>;\n /** Wall-clock timestamp at enqueue. */\n readonly createdAt: Date;\n}\n\n/**\n * Read-only snapshot of the queue. The queue store hands this out\n * directly; consumers must not mutate the array.\n */\nexport type SubmissionQueueSnapshot<\n StateType extends object = Record<string, unknown>,\n> = ReadonlyArray<SubmissionQueueEntry<StateType>>;\n\n/**\n * Frozen empty queue value used as the initial / cleared snapshot.\n *\n * Reusing one frozen reference keeps store identity stable across\n * empty resets, so React's `useSyncExternalStore` doesn't think the\n * queue changed when it actually didn't.\n */\nexport const EMPTY_QUEUE: SubmissionQueueSnapshot<never> = Object.freeze([]);\n\n/**\n * Coordinates one controller's run-submission lifecycle.\n *\n * The constructor takes a bag of callbacks rather than a reference to\n * the parent {@link StreamController} on purpose:\n *\n * - It keeps the dependency surface explicit and testable — every\n * piece of controller state the submit lifecycle touches is one\n * of these closures.\n * - It avoids a cyclic dependency between controller and coordinator.\n * - Tests can construct one with stub callbacks and assert behavior\n * without mocking the entire controller.\n *\n * @typeParam StateType - Root state shape.\n * @typeParam InterruptType - Root interrupt payload shape.\n * @typeParam ConfigurableType - `config.configurable` shape accepted\n * by submit (usually `Record<string, unknown>`).\n */\nexport class SubmitCoordinator<\n StateType extends object = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> {\n /** Controller-level options forwarded into `submitRun` / callbacks. */\n readonly #options: StreamControllerOptions<StateType>;\n /** Root snapshot store; written for `isLoading`, `error`, `interrupts`. */\n readonly #rootStore: StreamStore<RootSnapshot<StateType, InterruptType>>;\n /** Pending submissions awaiting the active run to terminate. */\n readonly #queueStore: StreamStore<SubmissionQueueSnapshot<StateType>>;\n /** Probes the controller's `disposed` flag from deferred work. */\n readonly #getDisposed: () => boolean;\n /** Reads the controller's currently-bound thread id. */\n readonly #getCurrentThreadId: () => string | null;\n /** Updates the controller's thread id (used when minting a new id). */\n readonly #setCurrentThreadId: (threadId: string | null) => void;\n /** Records a thread id we created client-side so hydrate can skip a 404 round-trip. */\n readonly #rememberSelfCreatedThreadId: (threadId: string) => void;\n /** Triggers a hydrate on the controller (used by `options.threadId` rebinds). */\n readonly #hydrate: (threadId?: string | null) => Promise<void>;\n /** Lazily creates / returns the active {@link ThreadStream}. */\n readonly #ensureThread: (threadId: string) => ThreadStream;\n /** Resolves once the controller's root subscription pump is up. */\n readonly #waitForRootPumpReady: () => Promise<void> | undefined;\n /** Resolves on the next root terminal lifecycle (or on abort). */\n readonly #awaitNextTerminal: (signal: AbortSignal) => Promise<TerminalResult>;\n /** Returns the most recent unresolved root interrupt, for resumes. */\n readonly #latestUnresolvedInterrupt: () => ResolvedInterrupt | null;\n /** Marks an interrupt id as resolved so it isn't re-targeted. */\n readonly #markInterruptResolved: (interruptId: string) => void;\n\n /**\n * Active submission's abort controller. `undefined` between submits.\n *\n * Used both for `multitaskStrategy: \"rollback\"` (abort the previous\n * controller's signal) and `stop()` (abort the current one without\n * starting a new one).\n */\n #runAbort: AbortController | undefined;\n\n constructor(params: {\n options: StreamControllerOptions<StateType>;\n rootStore: StreamStore<RootSnapshot<StateType, InterruptType>>;\n queueStore: StreamStore<SubmissionQueueSnapshot<StateType>>;\n getDisposed: () => boolean;\n getCurrentThreadId: () => string | null;\n setCurrentThreadId: (threadId: string | null) => void;\n rememberSelfCreatedThreadId: (threadId: string) => void;\n hydrate: (threadId?: string | null) => Promise<void>;\n ensureThread: (threadId: string) => ThreadStream;\n waitForRootPumpReady: () => Promise<void> | undefined;\n awaitNextTerminal: (signal: AbortSignal) => Promise<TerminalResult>;\n latestUnresolvedInterrupt: () => ResolvedInterrupt | null;\n markInterruptResolved: (interruptId: string) => void;\n }) {\n this.#options = params.options;\n this.#rootStore = params.rootStore;\n this.#queueStore = params.queueStore;\n this.#getDisposed = params.getDisposed;\n this.#getCurrentThreadId = params.getCurrentThreadId;\n this.#setCurrentThreadId = params.setCurrentThreadId;\n this.#rememberSelfCreatedThreadId = params.rememberSelfCreatedThreadId;\n this.#hydrate = params.hydrate;\n this.#ensureThread = params.ensureThread;\n this.#waitForRootPumpReady = params.waitForRootPumpReady;\n this.#awaitNextTerminal = params.awaitNextTerminal;\n this.#latestUnresolvedInterrupt = params.latestUnresolvedInterrupt;\n this.#markInterruptResolved = params.markInterruptResolved;\n }\n\n /**\n * Submit input or a resume command to the active thread.\n *\n * Honours {@link StreamSubmitOptions.multitaskStrategy}:\n *\n * - `\"rollback\"` (default) — aborts any in-flight run and\n * dispatches immediately.\n * - `\"reject\"` — throws synchronously when a run is\n * already in flight.\n * - `\"enqueue\"` — defers via {@link #enqueueSubmission};\n * the call returns without dispatching.\n * - `\"interrupt\"` — falls through to the default path\n * (server-side cancellation lands with roadmap A0.3).\n *\n * Errors are routed through both the per-submit `onError` callback\n * and `rootStore.error`. Aborts (controller dispose / rollback) are\n * silently dropped.\n *\n * @param input - Input payload, or `null`/`undefined` for no input\n * (typical for resume commands).\n * @param options - Per-submit options (config, metadata, callbacks,\n * strategy, etc).\n */\n async submit(\n input: unknown,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void> {\n if (this.#getDisposed()) return;\n\n // Per-submit thread override: rebind first so the rest of the\n // submit operates against the new thread.\n const overrideThreadId = options?.threadId;\n if (\n overrideThreadId !== undefined &&\n overrideThreadId !== this.#getCurrentThreadId()\n ) {\n await this.#hydrate(overrideThreadId);\n }\n\n // Self-created thread id path: mint client-side so the controller\n // (and Suspense boundaries) get a stable id even before the run\n // is dispatched.\n if (this.#getCurrentThreadId() == null) {\n const threadId = uuidv7();\n this.#setCurrentThreadId(threadId);\n this.#rememberSelfCreatedThreadId(threadId);\n this.#options.onThreadId?.(threadId);\n this.#rootStore.setState((s) => ({\n ...s,\n threadId,\n }));\n }\n\n const currentThreadId = this.#getCurrentThreadId();\n if (currentThreadId == null) return;\n const thread = this.#ensureThread(currentThreadId);\n const activeThreadId = currentThreadId;\n // Wait for the root subscription to be live; otherwise the\n // dispatch could resolve before we're listening for events and\n // we'd miss the terminal that ends the run.\n await this.#waitForRootPumpReady();\n\n const strategy = options?.multitaskStrategy ?? \"rollback\";\n const hasActiveRun =\n this.#runAbort != null && !this.#runAbort.signal.aborted;\n if (hasActiveRun && strategy === \"reject\") {\n throw new Error(\n \"submit() rejected: a run is already in flight and multitaskStrategy is 'reject'.\"\n );\n }\n if (hasActiveRun && strategy === \"enqueue\") {\n this.#enqueueSubmission(input, options);\n return;\n }\n\n // Rollback: abort the previous run before starting a new one.\n this.#runAbort?.abort();\n const abort = new AbortController();\n this.#runAbort = abort;\n\n const resumeCommand = options?.command?.resume;\n const isResume = resumeCommand !== undefined;\n\n // Optimistically clear interrupts/error and flip loading. The\n // root pump's lifecycle listener will re-flip these as the run\n // terminates.\n this.#rootStore.setState((s) => ({\n ...s,\n interrupts: [],\n interrupt: undefined,\n error: undefined,\n isLoading: true,\n }));\n\n const boundConfig = bindThreadConfig(options?.config, currentThreadId);\n // Subscribe to the next terminal *before* dispatching so a fast\n // run's terminal can't race us.\n const terminalPromise = this.#awaitNextTerminal(abort.signal);\n\n let terminalSettled = false;\n const reportError = (error: unknown): void => {\n if (abort.signal.aborted) return;\n this.#rootStore.setState((s) => ({ ...s, error }));\n try {\n options?.onError?.(error);\n } catch {\n /* caller-supplied callback errors must not crash the submit */\n }\n };\n\n try {\n let terminal: TerminalResult | undefined;\n\n if (isResume) {\n const target = this.#latestUnresolvedInterrupt();\n if (target == null) {\n throw new Error(\n \"submit({ command: { resume } }) called but no pending protocol interrupt is available.\"\n );\n }\n const commandPromise = thread.respondInput({\n namespace: target.namespace,\n interrupt_id: target.interruptId,\n response: resumeCommand,\n });\n // Mark resolved synchronously: even if the response races and\n // the command settles after the terminal, we don't want to\n // re-target this same interrupt on the next submit.\n this.#markInterruptResolved(target.interruptId);\n const first = await Promise.race([\n terminalPromise.then((value) => ({\n type: \"terminal\" as const,\n value,\n })),\n commandPromise.then(\n () => ({ type: \"command\" as const }),\n (error) => ({ type: \"error\" as const, error })\n ),\n ]);\n if (first.type === \"error\") throw first.error;\n if (first.type === \"terminal\") {\n terminal = first.value;\n terminalSettled = true;\n // Stale command response — surface as error only if it\n // arrives with a real failure (not just our own abort).\n void commandPromise.catch((error) => {\n if (!terminalSettled) reportError(error);\n });\n }\n } else {\n const commandPromise = thread.submitRun({\n input: input ?? null,\n config: boundConfig,\n metadata: (options?.metadata ?? undefined) as Record<string, unknown>,\n forkFrom: options?.forkFrom,\n multitaskStrategy:\n options?.multitaskStrategy === \"enqueue\"\n ? \"enqueue\"\n : options?.multitaskStrategy,\n });\n const notifyCreated = (result: { run_id?: unknown }) => {\n this.#options.onCreated?.({\n run_id: result.run_id as string,\n thread_id: activeThreadId,\n });\n };\n const first = await Promise.race([\n terminalPromise.then((value) => ({\n type: \"terminal\" as const,\n value,\n })),\n commandPromise.then(\n (result) => ({ type: \"command\" as const, result }),\n (error) => ({ type: \"error\" as const, error })\n ),\n ]);\n if (first.type === \"error\") throw first.error;\n if (first.type === \"command\") {\n notifyCreated(first.result);\n } else {\n // Terminal landed first (very fast runs). Wait for the\n // dispatch response in the background so onCreated fires\n // and dispatch errors still surface.\n terminal = first.value;\n terminalSettled = true;\n void commandPromise.then(notifyCreated).catch((error) => {\n if (!terminalSettled) reportError(error);\n });\n }\n }\n\n terminal ??= await terminalPromise;\n terminalSettled = true;\n if (terminal.event === \"failed\" && !abort.signal.aborted) {\n const runError = new Error(\n terminal.error ?? \"Run failed with no error message\"\n );\n this.#rootStore.setState((s) => ({ ...s, error: runError }));\n try {\n options?.onError?.(runError);\n } catch {\n /* caller-supplied callback errors must not crash the submit */\n }\n }\n } catch (error) {\n reportError(error);\n } finally {\n // Always settle loading and clear our slot of the abort\n // controller. Schedule queue drain on the next macrotask so any\n // late state updates from this run finish flushing first.\n this.#rootStore.setState((s) => ({ ...s, isLoading: false }));\n if (this.#runAbort === abort) this.#runAbort = undefined;\n setTimeout(() => this.#drainQueue(), 0);\n }\n }\n\n /**\n * Abort the current run (if any) and force `isLoading=false`.\n *\n * Does NOT issue a server-side cancel — that lands with roadmap\n * A0.3. Today this is a client-side stop only: subsequent events\n * for the aborted run are ignored by the controller's pump because\n * the abort signal is the same one `#awaitNextTerminal` is wired\n * to.\n */\n async stop(): Promise<void> {\n this.abortActiveRun();\n this.#rootStore.setState((s) => ({ ...s, isLoading: false }));\n }\n\n /**\n * Abort the current run without forcing the loading flag down.\n *\n * Used by {@link StreamController.dispose}: disposal already tears\n * down the root store, so flipping `isLoading` here is unnecessary\n * and would race the dispose path.\n */\n abortActiveRun(): void {\n this.#runAbort?.abort();\n this.#runAbort = undefined;\n }\n\n /**\n * Cancel a queued submission by id.\n *\n * @param id - Client-side queue entry id to remove.\n * @returns `true` when the entry was found and dropped, `false` otherwise.\n */\n async cancelQueued(id: string): Promise<boolean> {\n const current = this.#queueStore.getSnapshot();\n const next = current.filter((entry) => entry.id !== id);\n if (next.length === current.length) return false;\n this.#queueStore.setState(() => next);\n return true;\n }\n\n /**\n * Drop every queued submission. Server-side cancel arrives with A0.3.\n */\n async clearQueue(): Promise<void> {\n this.#queueStore.setState(\n () => EMPTY_QUEUE as SubmissionQueueSnapshot<StateType>\n );\n }\n\n /**\n * Append a submission to the queue without dispatching.\n *\n * The drained submission is later run via {@link #drainQueue} after\n * the active run terminates.\n */\n #enqueueSubmission(\n input: unknown,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): void {\n const entry: SubmissionQueueEntry<StateType> = {\n id: uuidv7(),\n values: (input ?? undefined) as Partial<StateType> | null | undefined,\n options: options as StreamSubmitOptions<StateType> | undefined,\n createdAt: new Date(),\n };\n this.#queueStore.setState((current) => [...current, entry]);\n }\n\n /**\n * Drain the head of the queue if no run is active.\n *\n * Called from the `finally` block of `submit()` on the next\n * macrotask (so the just-finished run's state flushes first).\n * Strips the strategy off the dequeued options to prevent infinite\n * re-enqueueing.\n */\n #drainQueue(): void {\n if (this.#getDisposed()) return;\n if (this.#runAbort != null && !this.#runAbort.signal.aborted) return;\n const current = this.#queueStore.getSnapshot();\n if (current.length === 0) return;\n const [next, ...rest] = current;\n this.#queueStore.setState(() => rest);\n const nextOptions: StreamSubmitOptions<StateType, ConfigurableType> = {\n ...((next.options ?? {}) as StreamSubmitOptions<\n StateType,\n ConfigurableType\n >),\n multitaskStrategy: undefined,\n };\n void this.submit(next.values, nextOptions).catch(() => {\n /* submit() already routes errors through the per-submit onError\n * hook and the root store; swallow here so a failing drain does\n * not surface as an unhandled rejection. */\n });\n }\n}\n\n/**\n * Merge `thread_id` into a user-supplied `config.configurable` blob.\n *\n * The platform expects `config.configurable.thread_id` on every run\n * dispatch; we set it last so user-supplied values can't accidentally\n * override the active thread id (which would route the run to a\n * different thread).\n */\nfunction bindThreadConfig(\n config: unknown,\n threadId: string\n): Record<string, unknown> {\n const base =\n config != null && typeof config === \"object\"\n ? (config as Record<string, unknown>)\n : {};\n const configurable =\n base.configurable != null && typeof base.configurable === \"object\"\n ? (base.configurable as Record<string, unknown>)\n : {};\n return {\n ...base,\n configurable: {\n ...configurable,\n thread_id: threadId,\n },\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/stream/tool-calls.ts
|
|
2
|
+
/**
|
|
3
|
+
* Insert or replace an assembled tool call by call id.
|
|
4
|
+
*/
|
|
5
|
+
function upsertToolCall(current, next) {
|
|
6
|
+
const idx = current.findIndex((toolCall) => toolCall.callId === next.callId);
|
|
7
|
+
if (idx < 0) return [...current, next];
|
|
8
|
+
const updated = current.slice();
|
|
9
|
+
updated[idx] = next;
|
|
10
|
+
return updated;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.upsertToolCall = upsertToolCall;
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=tool-calls.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.cjs","names":[],"sources":["../../src/stream/tool-calls.ts"],"sourcesContent":["import type { AssembledToolCall } from \"../client/stream/handles/tools.js\";\n\n/**\n * Insert or replace an assembled tool call by call id.\n */\nexport function upsertToolCall(\n current: readonly AssembledToolCall[],\n next: AssembledToolCall\n): AssembledToolCall[] {\n const idx = current.findIndex((toolCall) => toolCall.callId === next.callId);\n if (idx < 0) return [...current, next];\n const updated = current.slice();\n updated[idx] = next;\n return updated;\n}\n"],"mappings":";;;;AAKA,SAAgB,eACd,SACA,MACqB;CACrB,MAAM,MAAM,QAAQ,WAAW,aAAa,SAAS,WAAW,KAAK,OAAO;AAC5E,KAAI,MAAM,EAAG,QAAO,CAAC,GAAG,SAAS,KAAK;CACtC,MAAM,UAAU,QAAQ,OAAO;AAC/B,SAAQ,OAAO;AACf,QAAO"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/stream/tool-calls.ts
|
|
2
|
+
/**
|
|
3
|
+
* Insert or replace an assembled tool call by call id.
|
|
4
|
+
*/
|
|
5
|
+
function upsertToolCall(current, next) {
|
|
6
|
+
const idx = current.findIndex((toolCall) => toolCall.callId === next.callId);
|
|
7
|
+
if (idx < 0) return [...current, next];
|
|
8
|
+
const updated = current.slice();
|
|
9
|
+
updated[idx] = next;
|
|
10
|
+
return updated;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { upsertToolCall };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=tool-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.js","names":[],"sources":["../../src/stream/tool-calls.ts"],"sourcesContent":["import type { AssembledToolCall } from \"../client/stream/handles/tools.js\";\n\n/**\n * Insert or replace an assembled tool call by call id.\n */\nexport function upsertToolCall(\n current: readonly AssembledToolCall[],\n next: AssembledToolCall\n): AssembledToolCall[] {\n const idx = current.findIndex((toolCall) => toolCall.callId === next.callId);\n if (idx < 0) return [...current, next];\n const updated = current.slice();\n updated[idx] = next;\n return updated;\n}\n"],"mappings":";;;;AAKA,SAAgB,eACd,SACA,MACqB;CACrB,MAAM,MAAM,QAAQ,WAAW,aAAa,SAAS,WAAW,KAAK,OAAO;AAC5E,KAAI,MAAM,EAAG,QAAO,CAAC,GAAG,SAAS,KAAK;CACtC,MAAM,UAAU,QAAQ,OAAO;AAC/B,SAAQ,OAAO;AACf,QAAO"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DefaultToolCall, ToolCallFromTool } from "../types.messages.cjs";
|
|
2
|
+
import { AgentTypeConfigLike, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, InferAgentToolCalls, InferDeepAgentSubagents, InferSubagentByName, InferSubagentNames, InferSubagentState, IsAgentLike, IsDeepAgentLike, SubAgentLike, SubagentStateMap, SubagentToolCall } from "../ui/types.cjs";
|
|
3
|
+
import { InferBag, InferNodeNames, InferStateType as InferStateType$1, InferSubagentStates as InferSubagentStates$1, InferToolCalls as InferToolCalls$1 } from "../ui/stream/index.cjs";
|
|
4
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
5
|
+
|
|
6
|
+
//#region src/stream/types-inference.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Unwrap the state shape from a compiled graph, a create-agent brand,
|
|
9
|
+
* or a plain type. Used by `useStream<T>()` to resolve `T = typeof
|
|
10
|
+
* agent` into the state the `values`/`messages` projections observe.
|
|
11
|
+
*
|
|
12
|
+
* Structurally identical to the legacy
|
|
13
|
+
* `@langchain/langgraph-sdk/ui` helper of the same name; kept here as
|
|
14
|
+
* a framework-facing re-export so bindings can import from the
|
|
15
|
+
* stream subpath without needing the UI module.
|
|
16
|
+
*/
|
|
17
|
+
type InferStateType<T> = InferStateType$1<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Infer the discriminated union of tool call shapes from an input that
|
|
20
|
+
* may be an agent brand, an array of LangGraph tools, or a direct
|
|
21
|
+
* `DefaultToolCall` shape.
|
|
22
|
+
*
|
|
23
|
+
* See {@link InferToolCallsFromUi} for the full resolution table.
|
|
24
|
+
*/
|
|
25
|
+
type InferToolCalls<T> = T extends readonly unknown[] ? ToolCallFromTool<T[number]> : InferToolCalls$1<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Infer the subagent → state map from a DeepAgent brand. Non-brands
|
|
28
|
+
* collapse to {@link DefaultSubagentStates}.
|
|
29
|
+
*/
|
|
30
|
+
type InferSubagentStates<T> = InferSubagentStates$1<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Widen an update type so its `messages` field also accepts
|
|
33
|
+
* `@langchain/core` {@link BaseMessage} class instances (single or
|
|
34
|
+
* array). Framework bindings apply this to `submit()` so callers can
|
|
35
|
+
* write `stream.submit({ messages: [new HumanMessage("hi")] })`.
|
|
36
|
+
*
|
|
37
|
+
* Port of the legacy `AcceptBaseMessages<T>` helper; the public name
|
|
38
|
+
* matches the v1 spec in `plan-types.md` §8.
|
|
39
|
+
*/
|
|
40
|
+
type WidenUpdateMessages<T> = T extends Record<string, unknown> ? { [K in keyof T]: K extends "messages" ? T[K] | BaseMessage | BaseMessage[] : T[K] } : T;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { InferStateType, InferSubagentStates, InferToolCalls, WidenUpdateMessages };
|
|
43
|
+
//# sourceMappingURL=types-inference.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-inference.d.cts","names":[],"sources":["../../src/stream/types-inference.ts"],"mappings":";;;;;;AA2DA;;;;;;;;;;AAAA,KATY,cAAA,MAAoB,gBAAA,CAAqB,CAAA;;;;;;;;KASzC,cAAA,MAEV,CAAA,8BACI,gBAAA,CAAiB,CAAA,YACjB,gBAAA,CAAqB,CAAA;;;;;KAMf,mBAAA,MAAyB,qBAAA,CAA0B,CAAA;;;;AAW/D;;;;;;KAAY,mBAAA,MACV,CAAA,SAAU,MAAA,kCAEQ,CAAA,GAAI,CAAA,sBACZ,CAAA,CAAE,CAAA,IAAK,WAAA,GAAc,WAAA,KACrB,CAAA,CAAE,CAAA,MAER,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DefaultToolCall, ToolCallFromTool } from "../types.messages.js";
|
|
2
|
+
import { AgentTypeConfigLike, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, InferAgentToolCalls, InferDeepAgentSubagents, InferSubagentByName, InferSubagentNames, InferSubagentState, IsAgentLike, IsDeepAgentLike, SubAgentLike, SubagentStateMap, SubagentToolCall } from "../ui/types.js";
|
|
3
|
+
import { InferBag, InferNodeNames, InferStateType as InferStateType$1, InferSubagentStates as InferSubagentStates$1, InferToolCalls as InferToolCalls$1 } from "../ui/stream/index.js";
|
|
4
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
5
|
+
|
|
6
|
+
//#region src/stream/types-inference.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Unwrap the state shape from a compiled graph, a create-agent brand,
|
|
9
|
+
* or a plain type. Used by `useStream<T>()` to resolve `T = typeof
|
|
10
|
+
* agent` into the state the `values`/`messages` projections observe.
|
|
11
|
+
*
|
|
12
|
+
* Structurally identical to the legacy
|
|
13
|
+
* `@langchain/langgraph-sdk/ui` helper of the same name; kept here as
|
|
14
|
+
* a framework-facing re-export so bindings can import from the
|
|
15
|
+
* stream subpath without needing the UI module.
|
|
16
|
+
*/
|
|
17
|
+
type InferStateType<T> = InferStateType$1<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Infer the discriminated union of tool call shapes from an input that
|
|
20
|
+
* may be an agent brand, an array of LangGraph tools, or a direct
|
|
21
|
+
* `DefaultToolCall` shape.
|
|
22
|
+
*
|
|
23
|
+
* See {@link InferToolCallsFromUi} for the full resolution table.
|
|
24
|
+
*/
|
|
25
|
+
type InferToolCalls<T> = T extends readonly unknown[] ? ToolCallFromTool<T[number]> : InferToolCalls$1<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Infer the subagent → state map from a DeepAgent brand. Non-brands
|
|
28
|
+
* collapse to {@link DefaultSubagentStates}.
|
|
29
|
+
*/
|
|
30
|
+
type InferSubagentStates<T> = InferSubagentStates$1<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Widen an update type so its `messages` field also accepts
|
|
33
|
+
* `@langchain/core` {@link BaseMessage} class instances (single or
|
|
34
|
+
* array). Framework bindings apply this to `submit()` so callers can
|
|
35
|
+
* write `stream.submit({ messages: [new HumanMessage("hi")] })`.
|
|
36
|
+
*
|
|
37
|
+
* Port of the legacy `AcceptBaseMessages<T>` helper; the public name
|
|
38
|
+
* matches the v1 spec in `plan-types.md` §8.
|
|
39
|
+
*/
|
|
40
|
+
type WidenUpdateMessages<T> = T extends Record<string, unknown> ? { [K in keyof T]: K extends "messages" ? T[K] | BaseMessage | BaseMessage[] : T[K] } : T;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { InferStateType, InferSubagentStates, InferToolCalls, WidenUpdateMessages };
|
|
43
|
+
//# sourceMappingURL=types-inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-inference.d.ts","names":[],"sources":["../../src/stream/types-inference.ts"],"mappings":";;;;;;AA2DA;;;;;;;;;;AAAA,KATY,cAAA,MAAoB,gBAAA,CAAqB,CAAA;;;;;;;;KASzC,cAAA,MAEV,CAAA,8BACI,gBAAA,CAAiB,CAAA,YACjB,gBAAA,CAAqB,CAAA;;;;;KAMf,mBAAA,MAAyB,qBAAA,CAA0B,CAAA;;;;AAW/D;;;;;;KAAY,mBAAA,MACV,CAAA,SAAU,MAAA,kCAEQ,CAAA,GAAI,CAAA,sBACZ,CAAA,CAAE,CAAA,IAAK,WAAA,GAAc,WAAA,KACrB,CAAA,CAAE,CAAA,MAER,CAAA"}
|