@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,262 @@
|
|
|
1
|
+
import { MultiCursorBuffer } from "../multi-cursor-buffer.js";
|
|
2
|
+
import { ToolCallAssembler } from "./tools.js";
|
|
3
|
+
import { StreamingMessageAssembler } from "../messages.js";
|
|
4
|
+
import { MediaAssembler } from "../media.js";
|
|
5
|
+
import { SubgraphDiscoveryHandle } from "./subgraphs.js";
|
|
6
|
+
//#region src/client/stream/handles/subagents.ts
|
|
7
|
+
/**
|
|
8
|
+
* Discovered subagent within a streaming session. Mirrors the
|
|
9
|
+
* in-process `SubagentRunStream` from DeepAgent.
|
|
10
|
+
*
|
|
11
|
+
* Each subagent is discovered when a `tool-started` event with
|
|
12
|
+
* `tool_name === "task"` is observed. The `taskInput` and `output`
|
|
13
|
+
* promises resolve from the task tool's lifecycle events.
|
|
14
|
+
*
|
|
15
|
+
* Use lazy getters (`sub.messages`, `sub.toolCalls`, etc.) for
|
|
16
|
+
* namespace-scoped projections.
|
|
17
|
+
*/
|
|
18
|
+
var SubagentHandle = class {
|
|
19
|
+
name;
|
|
20
|
+
callId;
|
|
21
|
+
taskInput;
|
|
22
|
+
output;
|
|
23
|
+
namespace;
|
|
24
|
+
#session;
|
|
25
|
+
#messagesIterable;
|
|
26
|
+
#toolCallsIterable;
|
|
27
|
+
#subgraphsIterable;
|
|
28
|
+
#mediaDispatcherStarted = false;
|
|
29
|
+
#audioBuffer;
|
|
30
|
+
#imagesBuffer;
|
|
31
|
+
#videoBuffer;
|
|
32
|
+
#filesBuffer;
|
|
33
|
+
constructor(name, callId, namespace, taskInput, output, session) {
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.callId = callId;
|
|
36
|
+
this.namespace = namespace;
|
|
37
|
+
this.taskInput = taskInput;
|
|
38
|
+
this.output = output;
|
|
39
|
+
this.#session = session;
|
|
40
|
+
}
|
|
41
|
+
get messages() {
|
|
42
|
+
if (this.#messagesIterable) return this.#messagesIterable;
|
|
43
|
+
const buffer = new MultiCursorBuffer();
|
|
44
|
+
this.#messagesIterable = buffer;
|
|
45
|
+
const assembler = new StreamingMessageAssembler();
|
|
46
|
+
this.#startProjection(["messages"], (event) => {
|
|
47
|
+
if (event.method !== "messages") return;
|
|
48
|
+
const msg = assembler.consume(event);
|
|
49
|
+
if (msg) buffer.push(msg);
|
|
50
|
+
}, () => buffer.close());
|
|
51
|
+
return buffer;
|
|
52
|
+
}
|
|
53
|
+
get toolCalls() {
|
|
54
|
+
if (this.#toolCallsIterable) return this.#toolCallsIterable;
|
|
55
|
+
const buffer = new MultiCursorBuffer();
|
|
56
|
+
this.#toolCallsIterable = buffer;
|
|
57
|
+
const assembler = new ToolCallAssembler();
|
|
58
|
+
this.#startProjection(["tools"], (event) => {
|
|
59
|
+
if (event.method !== "tools") return;
|
|
60
|
+
const tc = assembler.consume(event);
|
|
61
|
+
if (tc) buffer.push(tc);
|
|
62
|
+
}, () => buffer.close());
|
|
63
|
+
return buffer;
|
|
64
|
+
}
|
|
65
|
+
get audio() {
|
|
66
|
+
this.#ensureMediaDispatcher();
|
|
67
|
+
return this.#audioBuffer;
|
|
68
|
+
}
|
|
69
|
+
get images() {
|
|
70
|
+
this.#ensureMediaDispatcher();
|
|
71
|
+
return this.#imagesBuffer;
|
|
72
|
+
}
|
|
73
|
+
get video() {
|
|
74
|
+
this.#ensureMediaDispatcher();
|
|
75
|
+
return this.#videoBuffer;
|
|
76
|
+
}
|
|
77
|
+
get files() {
|
|
78
|
+
this.#ensureMediaDispatcher();
|
|
79
|
+
return this.#filesBuffer;
|
|
80
|
+
}
|
|
81
|
+
#ensureMediaDispatcher() {
|
|
82
|
+
if (this.#mediaDispatcherStarted) return;
|
|
83
|
+
this.#mediaDispatcherStarted = true;
|
|
84
|
+
const audio = new MultiCursorBuffer();
|
|
85
|
+
const images = new MultiCursorBuffer();
|
|
86
|
+
const video = new MultiCursorBuffer();
|
|
87
|
+
const files = new MultiCursorBuffer();
|
|
88
|
+
this.#audioBuffer = audio;
|
|
89
|
+
this.#imagesBuffer = images;
|
|
90
|
+
this.#videoBuffer = video;
|
|
91
|
+
this.#filesBuffer = files;
|
|
92
|
+
const assembler = new MediaAssembler({
|
|
93
|
+
onAudio: (m) => audio.push(m),
|
|
94
|
+
onImage: (m) => images.push(m),
|
|
95
|
+
onVideo: (m) => video.push(m),
|
|
96
|
+
onFile: (m) => files.push(m)
|
|
97
|
+
});
|
|
98
|
+
this.#startProjection(["messages"], (event) => {
|
|
99
|
+
if (event.method !== "messages") return;
|
|
100
|
+
assembler.consume(event);
|
|
101
|
+
}, () => {
|
|
102
|
+
assembler.close();
|
|
103
|
+
audio.close();
|
|
104
|
+
images.close();
|
|
105
|
+
video.close();
|
|
106
|
+
files.close();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
get subgraphs() {
|
|
110
|
+
if (this.#subgraphsIterable) return this.#subgraphsIterable;
|
|
111
|
+
const buffer = new MultiCursorBuffer();
|
|
112
|
+
this.#subgraphsIterable = buffer;
|
|
113
|
+
(async () => {
|
|
114
|
+
const discovery = new SubgraphDiscoveryHandle(await this.#session.subscribe({
|
|
115
|
+
channels: ["lifecycle"],
|
|
116
|
+
namespaces: [this.namespace]
|
|
117
|
+
}), this.#session, this.namespace);
|
|
118
|
+
for await (const sub of discovery) buffer.push(sub);
|
|
119
|
+
buffer.close();
|
|
120
|
+
})();
|
|
121
|
+
return buffer;
|
|
122
|
+
}
|
|
123
|
+
subscribe(paramsOrChannels, options = {}) {
|
|
124
|
+
if (typeof paramsOrChannels === "object" && !Array.isArray(paramsOrChannels) && "channels" in paramsOrChannels) return this.#session.subscribe({
|
|
125
|
+
...paramsOrChannels,
|
|
126
|
+
namespaces: paramsOrChannels.namespaces ?? [this.namespace]
|
|
127
|
+
});
|
|
128
|
+
return this.#session.subscribe(paramsOrChannels, {
|
|
129
|
+
...options,
|
|
130
|
+
namespaces: options.namespaces ?? [this.namespace]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async #startProjection(channels, onEvent, onDone) {
|
|
134
|
+
try {
|
|
135
|
+
const rawHandle = await this.#session.subscribe({
|
|
136
|
+
channels,
|
|
137
|
+
namespaces: [this.namespace]
|
|
138
|
+
});
|
|
139
|
+
for await (const event of rawHandle) onEvent(event);
|
|
140
|
+
} finally {
|
|
141
|
+
onDone();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Async iterable that yields {@link SubagentHandle} instances as task
|
|
147
|
+
* tool calls are discovered from the `tools` channel.
|
|
148
|
+
*
|
|
149
|
+
* Mirrors the in-process `createSubagentTransformer` from DeepAgent:
|
|
150
|
+
* watches for `tool_name === "task"` with `tool-started`, extracts
|
|
151
|
+
* `subagent_type` and `description` from the input, and resolves
|
|
152
|
+
* `output` on `tool-finished`.
|
|
153
|
+
*/
|
|
154
|
+
var SubagentDiscoveryHandle = class {
|
|
155
|
+
#source;
|
|
156
|
+
#session;
|
|
157
|
+
#queue = [];
|
|
158
|
+
#waiters = [];
|
|
159
|
+
#pending = /* @__PURE__ */ new Map();
|
|
160
|
+
#sourcePump;
|
|
161
|
+
#closed = false;
|
|
162
|
+
constructor(source, session) {
|
|
163
|
+
this.#source = source;
|
|
164
|
+
this.#session = session;
|
|
165
|
+
}
|
|
166
|
+
#processEvent(event) {
|
|
167
|
+
if (event.method !== "tools") return void 0;
|
|
168
|
+
const tools = event;
|
|
169
|
+
const data = tools.params.data;
|
|
170
|
+
const toolCallId = data.tool_call_id;
|
|
171
|
+
if (data.tool_name === "task" && data.event === "tool-started") {
|
|
172
|
+
const rawInput = data.input;
|
|
173
|
+
const input = typeof rawInput === "string" ? JSON.parse(rawInput) : rawInput ?? {};
|
|
174
|
+
const name = input.subagent_type ?? "unknown";
|
|
175
|
+
const description = input.description ?? "";
|
|
176
|
+
let resolveTaskInput;
|
|
177
|
+
let resolveOutput;
|
|
178
|
+
let rejectOutput;
|
|
179
|
+
const taskInput = new Promise((r) => {
|
|
180
|
+
resolveTaskInput = r;
|
|
181
|
+
});
|
|
182
|
+
const output = new Promise((res, rej) => {
|
|
183
|
+
resolveOutput = res;
|
|
184
|
+
rejectOutput = rej;
|
|
185
|
+
});
|
|
186
|
+
resolveTaskInput(description);
|
|
187
|
+
this.#pending.set(toolCallId, {
|
|
188
|
+
resolveOutput,
|
|
189
|
+
rejectOutput
|
|
190
|
+
});
|
|
191
|
+
return new SubagentHandle(name, toolCallId, [...tools.params.namespace], taskInput, output, this.#session);
|
|
192
|
+
}
|
|
193
|
+
if (toolCallId) {
|
|
194
|
+
const pending = this.#pending.get(toolCallId);
|
|
195
|
+
if (pending) {
|
|
196
|
+
if (data.event === "tool-finished") {
|
|
197
|
+
pending.resolveOutput(data.output);
|
|
198
|
+
this.#pending.delete(toolCallId);
|
|
199
|
+
} else if (data.event === "tool-error") {
|
|
200
|
+
const message = data.message ?? "unknown error";
|
|
201
|
+
pending.rejectOutput(new Error(message));
|
|
202
|
+
this.#pending.delete(toolCallId);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
#start() {
|
|
208
|
+
if (this.#sourcePump) return;
|
|
209
|
+
this.#sourcePump = (async () => {
|
|
210
|
+
for await (const event of this.#source) {
|
|
211
|
+
const handle = this.#processEvent(event);
|
|
212
|
+
if (!handle) continue;
|
|
213
|
+
const waiter = this.#waiters.shift();
|
|
214
|
+
if (waiter) waiter({
|
|
215
|
+
done: false,
|
|
216
|
+
value: handle
|
|
217
|
+
});
|
|
218
|
+
else this.#queue.push(handle);
|
|
219
|
+
}
|
|
220
|
+
this.#closed = true;
|
|
221
|
+
for (const pending of this.#pending.values()) pending.resolveOutput(void 0);
|
|
222
|
+
this.#pending.clear();
|
|
223
|
+
while (this.#waiters.length > 0) this.#waiters.shift()?.({
|
|
224
|
+
done: true,
|
|
225
|
+
value: void 0
|
|
226
|
+
});
|
|
227
|
+
})();
|
|
228
|
+
}
|
|
229
|
+
async close() {
|
|
230
|
+
this.#closed = true;
|
|
231
|
+
await this.#source.unsubscribe();
|
|
232
|
+
}
|
|
233
|
+
[Symbol.asyncIterator]() {
|
|
234
|
+
this.#start();
|
|
235
|
+
return {
|
|
236
|
+
next: async () => {
|
|
237
|
+
if (this.#queue.length > 0) return {
|
|
238
|
+
done: false,
|
|
239
|
+
value: this.#queue.shift()
|
|
240
|
+
};
|
|
241
|
+
if (this.#closed) return {
|
|
242
|
+
done: true,
|
|
243
|
+
value: void 0
|
|
244
|
+
};
|
|
245
|
+
return await new Promise((resolve) => {
|
|
246
|
+
this.#waiters.push(resolve);
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
return: async () => {
|
|
250
|
+
await this.close();
|
|
251
|
+
return {
|
|
252
|
+
done: true,
|
|
253
|
+
value: void 0
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
export { SubagentDiscoveryHandle, SubagentHandle };
|
|
261
|
+
|
|
262
|
+
//# sourceMappingURL=subagents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagents.js","names":["#session","#messagesIterable","#startProjection","#toolCallsIterable","#ensureMediaDispatcher","#audioBuffer","#imagesBuffer","#videoBuffer","#filesBuffer","#mediaDispatcherStarted","#subgraphsIterable","#source","#queue","#waiters","#pending","#sourcePump","#processEvent","#closed","#start"],"sources":["../../../../src/client/stream/handles/subagents.ts"],"sourcesContent":["import type {\n Channel,\n Event,\n MessagesEvent,\n SubscribeParams,\n ToolsEvent,\n} from \"@langchain/protocol\";\nimport type { SubscriptionHandle } from \"../index.js\";\nimport { MultiCursorBuffer } from \"../multi-cursor-buffer.js\";\nimport { StreamingMessageAssembler } from \"../messages.js\";\nimport type { StreamingMessage, StreamingMessageHandle } from \"../messages.js\";\nimport { ToolCallAssembler } from \"./tools.js\";\nimport type { AssembledToolCall } from \"./tools.js\";\nimport { MediaAssembler } from \"../media.js\";\nimport type {\n AudioMedia,\n FileMedia,\n ImageMedia,\n VideoMedia,\n} from \"../media.js\";\nimport type {\n EventForChannel,\n EventForChannels,\n SubscribeOptions,\n YieldForChannel,\n YieldForChannels,\n} from \"../types.js\";\nimport {\n type Subscribable,\n type SubgraphHandle,\n SubgraphDiscoveryHandle,\n} from \"./subgraphs.js\";\n\n/**\n * Discovered subagent within a streaming session. Mirrors the\n * in-process `SubagentRunStream` from DeepAgent.\n *\n * Each subagent is discovered when a `tool-started` event with\n * `tool_name === \"task\"` is observed. The `taskInput` and `output`\n * promises resolve from the task tool's lifecycle events.\n *\n * Use lazy getters (`sub.messages`, `sub.toolCalls`, etc.) for\n * namespace-scoped projections.\n */\nexport class SubagentHandle {\n readonly name: string;\n readonly callId: string;\n readonly taskInput: Promise<string>;\n readonly output: Promise<unknown>;\n readonly namespace: string[];\n readonly #session: Subscribable;\n\n #messagesIterable?: AsyncIterable<StreamingMessage>;\n #toolCallsIterable?: AsyncIterable<AssembledToolCall>;\n #subgraphsIterable?: AsyncIterable<SubgraphHandle>;\n\n #mediaDispatcherStarted = false;\n #audioBuffer?: MultiCursorBuffer<AudioMedia>;\n #imagesBuffer?: MultiCursorBuffer<ImageMedia>;\n #videoBuffer?: MultiCursorBuffer<VideoMedia>;\n #filesBuffer?: MultiCursorBuffer<FileMedia>;\n\n constructor(\n name: string,\n callId: string,\n namespace: string[],\n taskInput: Promise<string>,\n output: Promise<unknown>,\n session: Subscribable\n ) {\n this.name = name;\n this.callId = callId;\n this.namespace = namespace;\n this.taskInput = taskInput;\n this.output = output;\n this.#session = session;\n }\n\n get messages(): AsyncIterable<StreamingMessageHandle> {\n if (this.#messagesIterable) return this.#messagesIterable;\n const buffer = new MultiCursorBuffer<StreamingMessage>();\n this.#messagesIterable = buffer;\n const assembler = new StreamingMessageAssembler();\n void this.#startProjection(\n [\"messages\"],\n (event) => {\n if (event.method !== \"messages\") return;\n const msg = assembler.consume(event as MessagesEvent);\n if (msg) buffer.push(msg);\n },\n () => buffer.close()\n );\n return buffer;\n }\n\n get toolCalls(): AsyncIterable<AssembledToolCall> {\n if (this.#toolCallsIterable) return this.#toolCallsIterable;\n const buffer = new MultiCursorBuffer<AssembledToolCall>();\n this.#toolCallsIterable = buffer;\n const assembler = new ToolCallAssembler();\n void this.#startProjection(\n [\"tools\"],\n (event) => {\n if (event.method !== \"tools\") return;\n const tc = assembler.consume(event as ToolsEvent);\n if (tc) buffer.push(tc);\n },\n () => buffer.close()\n );\n return buffer;\n }\n\n get audio(): AsyncIterable<AudioMedia> {\n this.#ensureMediaDispatcher();\n return this.#audioBuffer!;\n }\n\n get images(): AsyncIterable<ImageMedia> {\n this.#ensureMediaDispatcher();\n return this.#imagesBuffer!;\n }\n\n get video(): AsyncIterable<VideoMedia> {\n this.#ensureMediaDispatcher();\n return this.#videoBuffer!;\n }\n\n get files(): AsyncIterable<FileMedia> {\n this.#ensureMediaDispatcher();\n return this.#filesBuffer!;\n }\n\n #ensureMediaDispatcher(): void {\n if (this.#mediaDispatcherStarted) return;\n this.#mediaDispatcherStarted = true;\n const audio = new MultiCursorBuffer<AudioMedia>();\n const images = new MultiCursorBuffer<ImageMedia>();\n const video = new MultiCursorBuffer<VideoMedia>();\n const files = new MultiCursorBuffer<FileMedia>();\n this.#audioBuffer = audio;\n this.#imagesBuffer = images;\n this.#videoBuffer = video;\n this.#filesBuffer = files;\n const assembler = new MediaAssembler({\n onAudio: (m: AudioMedia) => audio.push(m),\n onImage: (m: ImageMedia) => images.push(m),\n onVideo: (m: VideoMedia) => video.push(m),\n onFile: (m: FileMedia) => files.push(m),\n });\n void this.#startProjection(\n [\"messages\"],\n (event) => {\n if (event.method !== \"messages\") return;\n assembler.consume(event as MessagesEvent);\n },\n () => {\n assembler.close();\n audio.close();\n images.close();\n video.close();\n files.close();\n }\n );\n }\n\n get subgraphs(): AsyncIterable<SubgraphHandle> {\n if (this.#subgraphsIterable) return this.#subgraphsIterable;\n const buffer = new MultiCursorBuffer<SubgraphHandle>();\n this.#subgraphsIterable = buffer;\n void (async () => {\n const rawHandle = await this.#session.subscribe({\n channels: [\"lifecycle\"],\n namespaces: [this.namespace],\n });\n const discovery = new SubgraphDiscoveryHandle(\n rawHandle,\n this.#session,\n this.namespace\n );\n for await (const sub of discovery) {\n buffer.push(sub);\n }\n buffer.close();\n })();\n return buffer;\n }\n\n /**\n * Create a raw channel subscription scoped to this subagent's namespace.\n */\n subscribe<TChannel extends Channel>(\n channel: TChannel,\n options?: SubscribeOptions\n ): Promise<\n SubscriptionHandle<EventForChannel<TChannel>, YieldForChannel<TChannel>>\n >;\n subscribe<const TChannels extends readonly Channel[]>(\n channels: TChannels,\n options?: SubscribeOptions\n ): Promise<\n SubscriptionHandle<EventForChannels<TChannels>, YieldForChannels<TChannels>>\n >;\n subscribe(params: SubscribeParams): Promise<SubscriptionHandle<Event>>;\n subscribe(\n paramsOrChannels: SubscribeParams | Channel | string | readonly Channel[],\n options: SubscribeOptions = {}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n if (\n typeof paramsOrChannels === \"object\" &&\n !Array.isArray(paramsOrChannels) &&\n \"channels\" in paramsOrChannels\n ) {\n return this.#session.subscribe({\n ...paramsOrChannels,\n namespaces: paramsOrChannels.namespaces ?? [this.namespace],\n });\n }\n\n return this.#session.subscribe(paramsOrChannels as Channel, {\n ...options,\n namespaces: options.namespaces ?? [this.namespace],\n });\n }\n\n async #startProjection(\n channels: Channel[],\n onEvent: (event: Event) => void,\n onDone: () => void\n ): Promise<void> {\n try {\n const rawHandle = await this.#session.subscribe({\n channels,\n namespaces: [this.namespace],\n });\n for await (const event of rawHandle) {\n onEvent(event);\n }\n } finally {\n onDone();\n }\n }\n}\n\n/**\n * Async iterable that yields {@link SubagentHandle} instances as task\n * tool calls are discovered from the `tools` channel.\n *\n * Mirrors the in-process `createSubagentTransformer` from DeepAgent:\n * watches for `tool_name === \"task\"` with `tool-started`, extracts\n * `subagent_type` and `description` from the input, and resolves\n * `output` on `tool-finished`.\n */\nexport class SubagentDiscoveryHandle implements AsyncIterable<SubagentHandle> {\n readonly #source: SubscriptionHandle<Event>;\n readonly #session: Subscribable;\n readonly #queue: SubagentHandle[] = [];\n readonly #waiters: Array<(value: IteratorResult<SubagentHandle>) => void> =\n [];\n readonly #pending = new Map<\n string,\n {\n resolveOutput: (v: unknown) => void;\n rejectOutput: (e: unknown) => void;\n }\n >();\n #sourcePump?: Promise<void>;\n #closed = false;\n\n constructor(source: SubscriptionHandle<Event>, session: Subscribable) {\n this.#source = source;\n this.#session = session;\n }\n\n #processEvent(event: Event): SubagentHandle | undefined {\n if (event.method !== \"tools\") return undefined;\n const tools = event as ToolsEvent;\n const data = tools.params.data;\n const toolCallId = (data as Record<string, unknown>).tool_call_id as string;\n const toolName = (data as Record<string, unknown>).tool_name as string;\n\n if (toolName === \"task\" && data.event === \"tool-started\") {\n const rawInput = (data as Record<string, unknown>).input;\n const input: { description?: string; subagent_type?: string } =\n typeof rawInput === \"string\"\n ? JSON.parse(rawInput)\n : ((rawInput as Record<string, unknown>) ?? {});\n\n const name = input.subagent_type ?? \"unknown\";\n const description = input.description ?? \"\";\n\n let resolveTaskInput!: (v: string) => void;\n let resolveOutput!: (v: unknown) => void;\n let rejectOutput!: (e: unknown) => void;\n\n const taskInput = new Promise<string>((r) => {\n resolveTaskInput = r;\n });\n const output = new Promise<unknown>((res, rej) => {\n resolveOutput = res;\n rejectOutput = rej;\n });\n\n resolveTaskInput(description);\n this.#pending.set(toolCallId, { resolveOutput, rejectOutput });\n\n const namespace = [...tools.params.namespace];\n\n return new SubagentHandle(\n name,\n toolCallId,\n namespace,\n taskInput,\n output,\n this.#session\n );\n }\n\n if (toolCallId) {\n const pending = this.#pending.get(toolCallId);\n if (pending) {\n if (data.event === \"tool-finished\") {\n pending.resolveOutput((data as Record<string, unknown>).output);\n this.#pending.delete(toolCallId);\n } else if (data.event === \"tool-error\") {\n const message =\n ((data as Record<string, unknown>).message as string) ??\n \"unknown error\";\n pending.rejectOutput(new Error(message));\n this.#pending.delete(toolCallId);\n }\n }\n }\n\n return undefined;\n }\n\n #start(): void {\n if (this.#sourcePump) return;\n this.#sourcePump = (async () => {\n for await (const event of this.#source) {\n const handle = this.#processEvent(event);\n if (!handle) continue;\n\n const waiter = this.#waiters.shift();\n if (waiter) {\n waiter({ done: false, value: handle });\n } else {\n this.#queue.push(handle);\n }\n }\n this.#closed = true;\n for (const pending of this.#pending.values()) {\n pending.resolveOutput(undefined);\n }\n this.#pending.clear();\n while (this.#waiters.length > 0) {\n this.#waiters.shift()?.({ done: true, value: undefined });\n }\n })();\n }\n\n async close(): Promise<void> {\n this.#closed = true;\n await this.#source.unsubscribe();\n }\n\n [Symbol.asyncIterator](): AsyncIterator<SubagentHandle> {\n this.#start();\n return {\n next: async () => {\n if (this.#queue.length > 0) {\n return { done: false, value: this.#queue.shift()! };\n }\n if (this.#closed) {\n return { done: true, value: undefined };\n }\n return await new Promise<IteratorResult<SubagentHandle>>((resolve) => {\n this.#waiters.push(resolve);\n });\n },\n return: async () => {\n await this.close();\n return { done: true, value: undefined };\n },\n };\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
const require_multi_cursor_buffer = require("../multi-cursor-buffer.cjs");
|
|
2
|
+
const require_tools = require("./tools.cjs");
|
|
3
|
+
const require_messages = require("../messages.cjs");
|
|
4
|
+
const require_media = require("../media.cjs");
|
|
5
|
+
//#region src/client/stream/handles/subgraphs.ts
|
|
6
|
+
/**
|
|
7
|
+
* Discovered subgraph within a streaming session.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the in-process `SubgraphRunStream` pattern: each subgraph
|
|
10
|
+
* has `name`, `index`, `namespace`, and lazy getters for projections
|
|
11
|
+
* scoped to this subgraph's namespace.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* for await (const sub of session.subgraphs) {
|
|
15
|
+
* for await (const msg of sub.messages) { ... }
|
|
16
|
+
* const state = await sub.output;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var SubgraphHandle = class {
|
|
21
|
+
name;
|
|
22
|
+
index;
|
|
23
|
+
namespace;
|
|
24
|
+
/**
|
|
25
|
+
* Non-empty when upstream attached a `cause` to this subgraph's
|
|
26
|
+
* `lifecycle.started` event. Population is product-specific and
|
|
27
|
+
* performed by stream transformers on the runtime side (e.g.
|
|
28
|
+
* deepagents' `SubagentTransformer` emits
|
|
29
|
+
* `{ type: "toolCall", tool_call_id }`). Generic clients should
|
|
30
|
+
* treat `cause.type` as an open enum — the protocol allows future
|
|
31
|
+
* variants (`send`, `edge`, ...) to be forwarded verbatim without
|
|
32
|
+
* a SDK bump.
|
|
33
|
+
*/
|
|
34
|
+
cause;
|
|
35
|
+
graphName;
|
|
36
|
+
/**
|
|
37
|
+
* Raw `tool-started` event that triggered this subgraph, when
|
|
38
|
+
* `cause.type === "toolCall"` and the matching event has been
|
|
39
|
+
* observed on the `tools` channel.
|
|
40
|
+
*/
|
|
41
|
+
toolStartedEvent;
|
|
42
|
+
#session;
|
|
43
|
+
#messagesIterable;
|
|
44
|
+
#valuesProjection;
|
|
45
|
+
#toolCallsIterable;
|
|
46
|
+
#subgraphsIterable;
|
|
47
|
+
#subagentsIterable;
|
|
48
|
+
#outputPromise;
|
|
49
|
+
#mediaDispatcherStarted = false;
|
|
50
|
+
#audioBuffer;
|
|
51
|
+
#imagesBuffer;
|
|
52
|
+
#videoBuffer;
|
|
53
|
+
#filesBuffer;
|
|
54
|
+
constructor(name, index, namespace, session, options) {
|
|
55
|
+
this.name = name;
|
|
56
|
+
this.index = index;
|
|
57
|
+
this.namespace = namespace;
|
|
58
|
+
this.cause = options?.cause;
|
|
59
|
+
this.graphName = options?.graphName;
|
|
60
|
+
this.toolStartedEvent = options?.toolStartedEvent;
|
|
61
|
+
this.#session = session;
|
|
62
|
+
}
|
|
63
|
+
get messages() {
|
|
64
|
+
if (this.#messagesIterable) return this.#messagesIterable;
|
|
65
|
+
const buffer = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
66
|
+
this.#messagesIterable = buffer;
|
|
67
|
+
const assembler = new require_messages.StreamingMessageAssembler();
|
|
68
|
+
this.#startProjection(["messages"], (event) => {
|
|
69
|
+
if (event.method !== "messages") return;
|
|
70
|
+
const msg = assembler.consume(event);
|
|
71
|
+
if (msg) buffer.push(msg);
|
|
72
|
+
}, () => buffer.close());
|
|
73
|
+
return buffer;
|
|
74
|
+
}
|
|
75
|
+
get values() {
|
|
76
|
+
if (this.#valuesProjection) return this.#valuesProjection;
|
|
77
|
+
const buffer = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
78
|
+
let lastValue;
|
|
79
|
+
let resolveOutput;
|
|
80
|
+
const outputPromise = new Promise((resolve) => {
|
|
81
|
+
resolveOutput = resolve;
|
|
82
|
+
});
|
|
83
|
+
this.#outputPromise = outputPromise;
|
|
84
|
+
const projection = Object.assign(buffer, { then: (onfulfilled, onrejected) => outputPromise.then(onfulfilled, onrejected) });
|
|
85
|
+
this.#valuesProjection = projection;
|
|
86
|
+
this.#startProjection(["values"], (event) => {
|
|
87
|
+
if (event.method !== "values") return;
|
|
88
|
+
const data = event.params.data;
|
|
89
|
+
lastValue = data;
|
|
90
|
+
buffer.push(data);
|
|
91
|
+
}, () => {
|
|
92
|
+
resolveOutput(lastValue);
|
|
93
|
+
buffer.close();
|
|
94
|
+
});
|
|
95
|
+
return projection;
|
|
96
|
+
}
|
|
97
|
+
get toolCalls() {
|
|
98
|
+
if (this.#toolCallsIterable) return this.#toolCallsIterable;
|
|
99
|
+
const buffer = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
100
|
+
this.#toolCallsIterable = buffer;
|
|
101
|
+
const assembler = new require_tools.ToolCallAssembler();
|
|
102
|
+
this.#startProjection(["tools"], (event) => {
|
|
103
|
+
if (event.method !== "tools") return;
|
|
104
|
+
const tc = assembler.consume(event);
|
|
105
|
+
if (tc) buffer.push(tc);
|
|
106
|
+
}, () => buffer.close());
|
|
107
|
+
return buffer;
|
|
108
|
+
}
|
|
109
|
+
get subgraphs() {
|
|
110
|
+
if (this.#subgraphsIterable) return this.#subgraphsIterable;
|
|
111
|
+
const buffer = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
112
|
+
this.#subgraphsIterable = buffer;
|
|
113
|
+
(async () => {
|
|
114
|
+
const discovery = new SubgraphDiscoveryHandle(await this.#session.subscribe({
|
|
115
|
+
channels: ["lifecycle", "tools"],
|
|
116
|
+
namespaces: [this.namespace]
|
|
117
|
+
}), this.#session, this.namespace);
|
|
118
|
+
for await (const sub of discovery) buffer.push(sub);
|
|
119
|
+
buffer.close();
|
|
120
|
+
})();
|
|
121
|
+
return buffer;
|
|
122
|
+
}
|
|
123
|
+
get subagents() {
|
|
124
|
+
if (this.#subagentsIterable) return this.#subagentsIterable;
|
|
125
|
+
const buffer = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
126
|
+
this.#subagentsIterable = buffer;
|
|
127
|
+
(async () => {
|
|
128
|
+
const rawHandle = await this.#session.subscribe({
|
|
129
|
+
channels: ["tools", "lifecycle"],
|
|
130
|
+
namespaces: [this.namespace]
|
|
131
|
+
});
|
|
132
|
+
const { SubagentDiscoveryHandle: Discovery } = await Promise.resolve().then(() => require("./subagents.cjs"));
|
|
133
|
+
const discovery = new Discovery(rawHandle, this.#session);
|
|
134
|
+
for await (const sub of discovery) buffer.push(sub);
|
|
135
|
+
buffer.close();
|
|
136
|
+
})();
|
|
137
|
+
return buffer;
|
|
138
|
+
}
|
|
139
|
+
get audio() {
|
|
140
|
+
this.#ensureMediaDispatcher();
|
|
141
|
+
return this.#audioBuffer;
|
|
142
|
+
}
|
|
143
|
+
get images() {
|
|
144
|
+
this.#ensureMediaDispatcher();
|
|
145
|
+
return this.#imagesBuffer;
|
|
146
|
+
}
|
|
147
|
+
get video() {
|
|
148
|
+
this.#ensureMediaDispatcher();
|
|
149
|
+
return this.#videoBuffer;
|
|
150
|
+
}
|
|
151
|
+
get files() {
|
|
152
|
+
this.#ensureMediaDispatcher();
|
|
153
|
+
return this.#filesBuffer;
|
|
154
|
+
}
|
|
155
|
+
get output() {
|
|
156
|
+
this.values;
|
|
157
|
+
return this.#outputPromise;
|
|
158
|
+
}
|
|
159
|
+
#ensureMediaDispatcher() {
|
|
160
|
+
if (this.#mediaDispatcherStarted) return;
|
|
161
|
+
this.#mediaDispatcherStarted = true;
|
|
162
|
+
const audio = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
163
|
+
const images = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
164
|
+
const video = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
165
|
+
const files = new require_multi_cursor_buffer.MultiCursorBuffer();
|
|
166
|
+
this.#audioBuffer = audio;
|
|
167
|
+
this.#imagesBuffer = images;
|
|
168
|
+
this.#videoBuffer = video;
|
|
169
|
+
this.#filesBuffer = files;
|
|
170
|
+
const assembler = new require_media.MediaAssembler({
|
|
171
|
+
onAudio: (m) => audio.push(m),
|
|
172
|
+
onImage: (m) => images.push(m),
|
|
173
|
+
onVideo: (m) => video.push(m),
|
|
174
|
+
onFile: (m) => files.push(m)
|
|
175
|
+
});
|
|
176
|
+
this.#startProjection(["messages"], (event) => {
|
|
177
|
+
if (event.method !== "messages") return;
|
|
178
|
+
assembler.consume(event);
|
|
179
|
+
}, () => {
|
|
180
|
+
assembler.close();
|
|
181
|
+
audio.close();
|
|
182
|
+
images.close();
|
|
183
|
+
video.close();
|
|
184
|
+
files.close();
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
subscribe(paramsOrChannels, options = {}) {
|
|
188
|
+
if (typeof paramsOrChannels === "object" && !Array.isArray(paramsOrChannels) && "channels" in paramsOrChannels) return this.#session.subscribe({
|
|
189
|
+
...paramsOrChannels,
|
|
190
|
+
namespaces: paramsOrChannels.namespaces ?? [this.namespace]
|
|
191
|
+
});
|
|
192
|
+
return this.#session.subscribe(paramsOrChannels, {
|
|
193
|
+
...options,
|
|
194
|
+
namespaces: options.namespaces ?? [this.namespace]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
async #startProjection(channels, onEvent, onDone) {
|
|
198
|
+
try {
|
|
199
|
+
const rawHandle = await this.#session.subscribe({
|
|
200
|
+
channels,
|
|
201
|
+
namespaces: [this.namespace]
|
|
202
|
+
});
|
|
203
|
+
for await (const event of rawHandle) onEvent(event);
|
|
204
|
+
} finally {
|
|
205
|
+
onDone();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Async iterable that yields {@link SubgraphHandle} instances as new
|
|
211
|
+
* subgraph namespaces are discovered from `lifecycle` events.
|
|
212
|
+
*
|
|
213
|
+
* Mirrors the in-process `run.subgraphs` pattern. A new subgraph is
|
|
214
|
+
* discovered when a `lifecycle` event with `event: "started"` is
|
|
215
|
+
* received at a namespace depth of exactly `parentDepth + 1`.
|
|
216
|
+
*/
|
|
217
|
+
var SubgraphDiscoveryHandle = class {
|
|
218
|
+
#source;
|
|
219
|
+
#session;
|
|
220
|
+
#parentNamespace;
|
|
221
|
+
#discovered = /* @__PURE__ */ new Set();
|
|
222
|
+
#pendingToolStarts = /* @__PURE__ */ new Map();
|
|
223
|
+
#pendingToolCallHandles = /* @__PURE__ */ new Map();
|
|
224
|
+
#queue = [];
|
|
225
|
+
#waiters = [];
|
|
226
|
+
#sourcePump;
|
|
227
|
+
#closed = false;
|
|
228
|
+
constructor(source, session, parentNamespace = []) {
|
|
229
|
+
this.#source = source;
|
|
230
|
+
this.#session = session;
|
|
231
|
+
this.#parentNamespace = parentNamespace;
|
|
232
|
+
}
|
|
233
|
+
#emit(handle) {
|
|
234
|
+
const waiter = this.#waiters.shift();
|
|
235
|
+
if (waiter) waiter({
|
|
236
|
+
done: false,
|
|
237
|
+
value: handle
|
|
238
|
+
});
|
|
239
|
+
else this.#queue.push(handle);
|
|
240
|
+
}
|
|
241
|
+
#processToolEvent(event) {
|
|
242
|
+
if (event.method !== "tools") return false;
|
|
243
|
+
const tools = event;
|
|
244
|
+
const data = tools.params.data;
|
|
245
|
+
if (data.event !== "tool-started") return true;
|
|
246
|
+
const toolCallId = data.tool_call_id;
|
|
247
|
+
if (!toolCallId) return true;
|
|
248
|
+
const pendingHandle = this.#pendingToolCallHandles.get(toolCallId);
|
|
249
|
+
if (pendingHandle) {
|
|
250
|
+
pendingHandle.toolStartedEvent = tools;
|
|
251
|
+
this.#pendingToolCallHandles.delete(toolCallId);
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
this.#pendingToolStarts.set(toolCallId, tools);
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
#processEvent(event) {
|
|
258
|
+
if (this.#processToolEvent(event)) return void 0;
|
|
259
|
+
if (event.method !== "lifecycle") return void 0;
|
|
260
|
+
const lifecycle = event;
|
|
261
|
+
if (lifecycle.params.data.event !== "started") return void 0;
|
|
262
|
+
const ns = event.params.namespace;
|
|
263
|
+
if (ns.length !== this.#parentNamespace.length + 1) return void 0;
|
|
264
|
+
if (!this.#parentNamespace.every((seg, i) => ns[i] === seg)) return void 0;
|
|
265
|
+
const nsKey = ns.join("/");
|
|
266
|
+
if (this.#discovered.has(nsKey)) return void 0;
|
|
267
|
+
this.#discovered.add(nsKey);
|
|
268
|
+
const lastSegment = ns[ns.length - 1] ?? "";
|
|
269
|
+
const colonIdx = lastSegment.lastIndexOf(":");
|
|
270
|
+
let name;
|
|
271
|
+
let index;
|
|
272
|
+
if (colonIdx >= 0) {
|
|
273
|
+
name = lastSegment.slice(0, colonIdx);
|
|
274
|
+
const suffix = lastSegment.slice(colonIdx + 1);
|
|
275
|
+
index = /^\d+$/.test(suffix) ? Number(suffix) : 0;
|
|
276
|
+
} else {
|
|
277
|
+
name = lastSegment;
|
|
278
|
+
index = 0;
|
|
279
|
+
}
|
|
280
|
+
const data = lifecycle.params.data;
|
|
281
|
+
const cause = data.cause && typeof data.cause === "object" ? data.cause : void 0;
|
|
282
|
+
let toolStartedEvent;
|
|
283
|
+
if (cause?.type === "toolCall") {
|
|
284
|
+
const toolCallId = cause.tool_call_id;
|
|
285
|
+
if (toolCallId) {
|
|
286
|
+
toolStartedEvent = this.#pendingToolStarts.get(toolCallId);
|
|
287
|
+
this.#pendingToolStarts.delete(toolCallId);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const handle = new SubgraphHandle(name, index, [...ns], this.#session, {
|
|
291
|
+
cause,
|
|
292
|
+
graphName: data.graph_name,
|
|
293
|
+
toolStartedEvent
|
|
294
|
+
});
|
|
295
|
+
if (cause?.type === "toolCall" && toolStartedEvent == null) {
|
|
296
|
+
const toolCallId = cause.tool_call_id;
|
|
297
|
+
if (toolCallId) this.#pendingToolCallHandles.set(toolCallId, handle);
|
|
298
|
+
}
|
|
299
|
+
return handle;
|
|
300
|
+
}
|
|
301
|
+
#start() {
|
|
302
|
+
if (this.#sourcePump) return;
|
|
303
|
+
this.#sourcePump = (async () => {
|
|
304
|
+
for await (const event of this.#source) {
|
|
305
|
+
const handle = this.#processEvent(event);
|
|
306
|
+
if (!handle) continue;
|
|
307
|
+
this.#emit(handle);
|
|
308
|
+
}
|
|
309
|
+
this.#pendingToolStarts.clear();
|
|
310
|
+
this.#pendingToolCallHandles.clear();
|
|
311
|
+
this.#closed = true;
|
|
312
|
+
while (this.#waiters.length > 0) this.#waiters.shift()?.({
|
|
313
|
+
done: true,
|
|
314
|
+
value: void 0
|
|
315
|
+
});
|
|
316
|
+
})();
|
|
317
|
+
}
|
|
318
|
+
async close() {
|
|
319
|
+
this.#closed = true;
|
|
320
|
+
await this.#source.unsubscribe();
|
|
321
|
+
}
|
|
322
|
+
[Symbol.asyncIterator]() {
|
|
323
|
+
this.#start();
|
|
324
|
+
return {
|
|
325
|
+
next: async () => {
|
|
326
|
+
if (this.#queue.length > 0) return {
|
|
327
|
+
done: false,
|
|
328
|
+
value: this.#queue.shift()
|
|
329
|
+
};
|
|
330
|
+
if (this.#closed) return {
|
|
331
|
+
done: true,
|
|
332
|
+
value: void 0
|
|
333
|
+
};
|
|
334
|
+
return await new Promise((resolve) => {
|
|
335
|
+
this.#waiters.push(resolve);
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
return: async () => {
|
|
339
|
+
await this.close();
|
|
340
|
+
return {
|
|
341
|
+
done: true,
|
|
342
|
+
value: void 0
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
//#endregion
|
|
349
|
+
exports.SubgraphDiscoveryHandle = SubgraphDiscoveryHandle;
|
|
350
|
+
exports.SubgraphHandle = SubgraphHandle;
|
|
351
|
+
|
|
352
|
+
//# sourceMappingURL=subgraphs.cjs.map
|