agents 0.26.0 → 0.28.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 +8 -9
- package/dist/abortable-C1SpfVoi.js +21 -0
- package/dist/abortable-C1SpfVoi.js.map +1 -0
- package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-QDcchcQP.d.ts} +16 -16
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-DHL2XI7u.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-ahruGw7e.d.ts +239 -0
- package/dist/ai-sdk-Bdsf6mSA.js +2444 -0
- package/dist/ai-sdk-Bdsf6mSA.js.map +1 -0
- package/dist/apply-chunks-1FheRb9W.js +99 -0
- package/dist/apply-chunks-1FheRb9W.js.map +1 -0
- package/dist/broadcast-state-CEyI4uAK.js +69 -0
- package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
- package/dist/browser/ai.d.ts +8 -227
- package/dist/browser/ai.js +259 -1
- package/dist/browser/ai.js.map +1 -0
- package/dist/browser/index.d.ts +56 -46
- package/dist/browser/index.js +4 -361
- package/dist/browser/{ai-sdk.d.ts → tools/ai-sdk.d.ts} +7 -7
- package/dist/browser/{ai-sdk.js → tools/ai-sdk.js} +6 -5
- package/dist/browser/tools/ai-sdk.js.map +1 -0
- package/dist/browser/tools/pi.d.ts +111 -0
- package/dist/browser/tools/pi.js +119 -0
- package/dist/browser/tools/pi.js.map +1 -0
- package/dist/browser/{tanstack-ai.d.ts → tools/tanstack-ai.d.ts} +39 -37
- package/dist/browser/{tanstack-ai.js → tools/tanstack-ai.js} +73 -59
- package/dist/browser/tools/tanstack-ai.js.map +1 -0
- package/dist/browser-CEdNlsaD.js +481 -0
- package/dist/browser-CEdNlsaD.js.map +1 -0
- package/dist/{browser-DE3d-RLk.d.ts → browser-D30VlpcA.d.ts} +63 -37
- package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-4iomavs_.js} +198 -62
- package/dist/browser-tool-4iomavs_.js.map +1 -0
- package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-vtrPOV8e.d.ts} +25 -6
- package/dist/{capability-B4WbF81e.js → capability-DBAKc6UZ.js} +1 -3
- package/dist/capability-DBAKc6UZ.js.map +1 -0
- package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-BiVUtjqC.d.ts} +9 -7
- package/dist/channel-Bak_6zDP.d.ts +333 -0
- package/dist/chat/index.d.ts +11 -9
- package/dist/chat/index.js +5 -194
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/react.d.ts +2 -4
- package/dist/chat/react.js +3 -1
- package/dist/chat/react.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +144 -0
- package/dist/{client-je3koD9Z.d.ts → client-BGIQKJhX.d.ts} +2 -2
- package/dist/{client-fyQrLGkD.js → client-BnYbNT3z.js} +29 -5
- package/dist/client-BnYbNT3z.js.map +1 -0
- package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
- package/dist/client.d.ts +1 -1
- package/dist/{connector-58XDGvc3.js → connector-CtZylXdk.js} +3 -603
- package/dist/connector-CtZylXdk.js.map +1 -0
- package/dist/{connector-Cl-VqPmA.d.ts → connector-DEXzVoaY.d.ts} +9 -374
- package/dist/conversations-FjHDRZyD.d.ts +192 -0
- package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-CKgT5d1O.d.ts} +3 -5
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/daemon-core-Buubj-y1.js +481 -0
- package/dist/daemon-core-Buubj-y1.js.map +1 -0
- package/dist/daemon-core-CbohVPAu.d.ts +132 -0
- package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
- package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DOI_bzCH.d.ts} +2 -2
- package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
- package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
- package/dist/experimental/channels/email/index.js.map +1 -0
- package/dist/experimental/channels/index.d.ts +270 -0
- package/dist/experimental/channels/index.js +1186 -0
- package/dist/experimental/channels/index.js.map +1 -0
- package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
- package/dist/experimental/channels/slack/index.js +267 -0
- package/dist/experimental/channels/slack/index.js.map +1 -0
- package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
- package/dist/experimental/channels/telegram/index.js +198 -0
- package/dist/experimental/channels/telegram/index.js.map +1 -0
- package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
- package/dist/experimental/channels/web/ai-sdk.js +266 -0
- package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
- package/dist/experimental/channels/web/client.d.ts +97 -0
- package/dist/experimental/channels/web/client.js +349 -0
- package/dist/experimental/channels/web/client.js.map +1 -0
- package/dist/experimental/channels/web/index.d.ts +189 -0
- package/dist/experimental/channels/web/index.js +332 -0
- package/dist/experimental/channels/web/index.js.map +1 -0
- package/dist/gateway-BFO6vRDn.d.ts +100 -0
- package/dist/handle-zAzh0UW2.d.ts +460 -0
- package/dist/harness/ai-sdk/index.d.ts +175 -0
- package/dist/harness/ai-sdk/index.js +605 -0
- package/dist/harness/ai-sdk/index.js.map +1 -0
- package/dist/harness/container/daemon/index.d.ts +76 -0
- package/dist/harness/container/daemon/index.js +3 -0
- package/dist/harness/container/index.d.ts +740 -0
- package/dist/harness/container/index.js +2152 -0
- package/dist/harness/container/index.js.map +1 -0
- package/dist/harness/container/runtime/index.d.ts +144 -0
- package/dist/harness/container/runtime/index.js +1082 -0
- package/dist/harness/container/runtime/index.js.map +1 -0
- package/dist/harness/opencode/index.d.ts +369 -0
- package/dist/harness/opencode/index.js +1072 -0
- package/dist/harness/opencode/index.js.map +1 -0
- package/dist/harness/pi/index.d.ts +3 -2
- package/dist/harness/pi/index.js +3 -3
- package/dist/harness/store/index.d.ts +24 -0
- package/dist/harness/store/index.js +2 -0
- package/dist/harness/think/index.d.ts +821 -0
- package/dist/harness/think/index.js +2721 -0
- package/dist/harness/think/index.js.map +1 -0
- package/dist/harness-B6B9S3rb.d.ts +203 -0
- package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
- package/dist/images-Ce9SCu3X.js.map +1 -0
- package/dist/{index-BreL0YrQ.d.ts → index-BEL3ZV-s.d.ts} +2 -6
- package/dist/index-CBt8oRJt.d.ts +198 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/ingress-EFbrS547.js +9 -0
- package/dist/ingress-EFbrS547.js.map +1 -0
- package/dist/input-schema-BQykTEp_.js +20 -0
- package/dist/input-schema-BQykTEp_.js.map +1 -0
- package/dist/input-schema-D2QAtHZH.js +23 -0
- package/dist/input-schema-D2QAtHZH.js.map +1 -0
- package/dist/internal-kmw70xwR.js +46 -0
- package/dist/internal-kmw70xwR.js.map +1 -0
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +2 -2
- package/dist/{lifecycle-CFu6OV03.js → lifecycle-DGorpAmA.js} +2 -4
- package/dist/lifecycle-DGorpAmA.js.map +1 -0
- package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
- package/dist/mcp/client/do-oauth-client-provider.js +9 -0
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +1 -1
- package/dist/mcp/client/index.js +1 -1
- package/dist/mcp/client/x402.d.ts +35 -4
- package/dist/mcp/client/x402.js +24 -3
- package/dist/mcp/client/x402.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +2 -2
- package/dist/models/ai-sdk/index.d.ts +16 -14
- package/dist/models/ai-sdk/index.js +1 -2442
- package/dist/models/opencode/index.d.ts +65 -0
- package/dist/models/opencode/index.js +285 -0
- package/dist/models/opencode/index.js.map +1 -0
- package/dist/models/pi-ai/index.d.ts +9 -7
- package/dist/models/pi-ai/index.js +2 -1
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/options-CiIsJHXR.d.ts +130 -0
- package/dist/protocol-BEgrJYC5.d.ts +331 -0
- package/dist/protocol-CukuI73M.d.ts +386 -0
- package/dist/protocol-cOklVBBD.js +227 -0
- package/dist/protocol-cOklVBBD.js.map +1 -0
- package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
- package/dist/protocol-eXeJxhgu.js.map +1 -0
- package/dist/protocol-y2sSY584.js +148 -0
- package/dist/protocol-y2sSY584.js.map +1 -0
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-BB-zfIYF.js → queue-CcIjVYTE.js} +2 -2
- package/dist/{queue-BB-zfIYF.js.map → queue-CcIjVYTE.js.map} +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/routing/index.js +1 -1
- package/dist/{scheduler-RdACNXDP.d.ts → scheduler-BCLESHSC.d.ts} +2 -12
- package/dist/{scheduler-DZ3xQfeK.js → scheduler-FIHv2-kJ.js} +2 -4
- package/dist/scheduler-FIHv2-kJ.js.map +1 -0
- package/dist/schedules/index.d.ts +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/session-store-Do4xkDcf.js +606 -0
- package/dist/session-store-Do4xkDcf.js.map +1 -0
- package/dist/session-store-DoPY12xM.d.ts +383 -0
- package/dist/sessions/index.d.ts +11 -434
- package/dist/sessions/index.js +1 -2271
- package/dist/sessions-_vN5BEZX.js +2272 -0
- package/dist/sessions-_vN5BEZX.js.map +1 -0
- package/dist/settings-C45hDliX.js +253 -0
- package/dist/settings-C45hDliX.js.map +1 -0
- package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
- package/dist/{src-BZeu-SCD.js → src-CQxJFv4l.js} +8 -8
- package/dist/src-CQxJFv4l.js.map +1 -0
- package/dist/stall-watchdog-BpRF2uwG.js +195 -0
- package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/state/index.js +1 -3
- package/dist/state/index.js.map +1 -1
- package/dist/store-BKM4Xm9M.d.ts +332 -0
- package/dist/store-CslVzfN7.js +458 -0
- package/dist/store-CslVzfN7.js.map +1 -0
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/{streams-DW-UCOUc.js → streams-lsHMJhRW.js} +17 -4
- package/dist/streams-lsHMJhRW.js.map +1 -0
- package/dist/{streams-Cmkj9QfW.d.ts → streams-vrCtbUIn.d.ts} +2 -2
- package/dist/sub-routing.d.ts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-68DESxf0.js → tasks-BN_5AWqI.js} +3 -2
- package/dist/tasks-BN_5AWqI.js.map +1 -0
- package/dist/{tasks-9YxYtByh.d.ts → tasks-E89KdwkS.d.ts} +2 -2
- package/dist/tool-CTp72Jb_.d.ts +278 -0
- package/dist/tool-CxKsvxjm.js +1126 -0
- package/dist/tool-CxKsvxjm.js.map +1 -0
- package/dist/tool-DoVberpN.d.ts +301 -0
- package/dist/tool-cQRkwSZZ.js +410 -0
- package/dist/tool-cQRkwSZZ.js.map +1 -0
- package/dist/tool-helpers-O5BDVEAY.js +58 -0
- package/dist/tool-helpers-O5BDVEAY.js.map +1 -0
- package/dist/transport-k2mFrtL8.d.ts +200 -0
- package/dist/turns-DCV3ycDl.js +317 -0
- package/dist/turns-DCV3ycDl.js.map +1 -0
- package/dist/voice/client.js +1 -1
- package/dist/voice/index.d.ts +2 -2
- package/dist/voice/index.js +1 -1
- package/dist/web/fetch/index.d.ts +89 -0
- package/dist/web/fetch/index.js +20 -0
- package/dist/web/fetch/index.js.map +1 -0
- package/dist/web/fetch/tools/ai-sdk.d.ts +80 -0
- package/dist/web/fetch/tools/ai-sdk.js +47 -0
- package/dist/web/fetch/tools/ai-sdk.js.map +1 -0
- package/dist/web/fetch/tools/pi.d.ts +84 -0
- package/dist/web/fetch/tools/pi.js +88 -0
- package/dist/web/fetch/tools/pi.js.map +1 -0
- package/dist/web/fetch/tools/tanstack-ai.d.ts +78 -0
- package/dist/web/fetch/tools/tanstack-ai.js +45 -0
- package/dist/web/fetch/tools/tanstack-ai.js.map +1 -0
- package/dist/web/search/index.d.ts +58 -0
- package/dist/web/search/index.js +2 -0
- package/dist/web/search/tools/ai-sdk.d.ts +77 -0
- package/dist/web/search/tools/ai-sdk.js +46 -0
- package/dist/web/search/tools/ai-sdk.js.map +1 -0
- package/dist/web/search/tools/pi.d.ts +82 -0
- package/dist/web/search/tools/pi.js +89 -0
- package/dist/web/search/tools/pi.js.map +1 -0
- package/dist/web/search/tools/tanstack-ai.d.ts +71 -0
- package/dist/web/search/tools/tanstack-ai.js +46 -0
- package/dist/web/search/tools/tanstack-ai.js.map +1 -0
- package/dist/websockets/index.d.ts +12 -296
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-Ci-LZFHH.js → websockets-C3zy8YR0.js} +20 -8
- package/dist/websockets-C3zy8YR0.js.map +1 -0
- package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/dist/workflows.js +1 -1
- package/docs/browse-the-web.md +29 -1
- package/docs/fetch-the-web.md +276 -0
- package/docs/harnesses/pi.md +25 -0
- package/docs/harnesses/think.md +215 -0
- package/docs/index.md +99 -75
- package/docs/lifecycle.md +42 -3
- package/docs/queue.md +2 -3
- package/docs/scheduling.md +2 -6
- package/docs/search-the-web.md +135 -0
- package/package.json +148 -44
- package/dist/ai-fm7xx1BK.js +0 -312
- package/dist/ai-fm7xx1BK.js.map +0 -1
- package/dist/browser/ai-sdk.js.map +0 -1
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/tanstack-ai.js.map +0 -1
- package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
- package/dist/capability-B4WbF81e.js.map +0 -1
- package/dist/channel-Bnm4S7T2.d.ts +0 -491
- package/dist/channels/ai-sdk.d.ts +0 -46
- package/dist/channels/ai-sdk.js +0 -120
- package/dist/channels/ai-sdk.js.map +0 -1
- package/dist/channels/email.js.map +0 -1
- package/dist/channels/index.d.ts +0 -233
- package/dist/channels/index.js +0 -608
- package/dist/channels/index.js.map +0 -1
- package/dist/channels/slack.js +0 -614
- package/dist/channels/slack.js.map +0 -1
- package/dist/channels/tanstack-ai.d.ts +0 -39
- package/dist/channels/tanstack-ai.js +0 -17
- package/dist/channels/tanstack-ai.js.map +0 -1
- package/dist/channels/telegram.js +0 -427
- package/dist/channels/telegram.js.map +0 -1
- package/dist/channels/voice.d.ts +0 -45
- package/dist/channels/voice.js +0 -122
- package/dist/channels/voice.js.map +0 -1
- package/dist/client-fyQrLGkD.js.map +0 -1
- package/dist/connector-58XDGvc3.js.map +0 -1
- package/dist/images-iiTDSyRu.js.map +0 -1
- package/dist/index-BB0kqhIz.d.ts +0 -101
- package/dist/ingress-BfetZbMO.js +0 -83
- package/dist/ingress-BfetZbMO.js.map +0 -1
- package/dist/internal-CYlgHl1l.js +0 -59
- package/dist/internal-CYlgHl1l.js.map +0 -1
- package/dist/lifecycle-CFu6OV03.js.map +0 -1
- package/dist/models/ai-sdk/index.js.map +0 -1
- package/dist/protocol-kHsr-f0X.js.map +0 -1
- package/dist/scheduler-DZ3xQfeK.js.map +0 -1
- package/dist/sessions/index.js.map +0 -1
- package/dist/src-BZeu-SCD.js.map +0 -1
- package/dist/streams-DW-UCOUc.js.map +0 -1
- package/dist/surface-bZZJqBka.js +0 -17
- package/dist/surface-bZZJqBka.js.map +0 -1
- package/dist/tasks-68DESxf0.js.map +0 -1
- package/dist/tool-schema-CBjGPrsQ.js +0 -31
- package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
- package/dist/websockets-Ci-LZFHH.js.map +0 -1
- package/docs/channels.md +0 -323
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _assertClassBrand, t as _classPrivateFieldGet2 } from "../../classPrivateFieldGet2-DZBYAB34.js";
|
|
2
|
+
import { t as _classPrivateMethodInitSpec } from "../../classPrivateMethodInitSpec-qMjJ6sHQ.js";
|
|
3
|
+
import { t as LifecycleCapability } from "../../capability-DBAKc6UZ.js";
|
|
4
|
+
import { a as toTranscriptMessage, i as toResponseChunks, n as awaitsInput, o as toUIMessage, r as toResponseChunk, s as toUIMessageChunk, t as answerToolCall } from "../../turns-DCV3ycDl.js";
|
|
5
|
+
import { convertToModelMessages, jsonSchema, stepCountIs, streamText, toUIMessageStream, tool } from "ai";
|
|
6
|
+
//#region src/harness/ai-sdk/harness.ts
|
|
7
|
+
const PREFIX = "ai-sdk-harness:";
|
|
8
|
+
const WAKE_FN = "wake";
|
|
9
|
+
const DEFAULT_SESSION = "main";
|
|
10
|
+
const HEARTBEAT_MS = 3e4;
|
|
11
|
+
var _options = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
var _heartbeatMs = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var _runs = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
var _driving = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
var _watchers = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
var _waiters = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
var _AiSdkHarness_brand = /* @__PURE__ */ new WeakSet();
|
|
18
|
+
/**
|
|
19
|
+
* An agent harness around the AI SDK's `streamText`, hosted in a Durable
|
|
20
|
+
* Object: sessions, their transcripts, and a queue of operations, all in the
|
|
21
|
+
* object's storage. One operation runs at a time per session; a run is one
|
|
22
|
+
* `streamText` call over the session's transcript.
|
|
23
|
+
*
|
|
24
|
+
* The AI SDK keeps no state of its own, so a run that an eviction cuts short
|
|
25
|
+
* starts again from the saved transcript, and its unsaved output is lost.
|
|
26
|
+
* Steering is not supported: `whenBusy: "steer"` queues like a follow-up.
|
|
27
|
+
*
|
|
28
|
+
* @experimental The API may change between releases.
|
|
29
|
+
*/
|
|
30
|
+
var AiSdkHarness = class extends LifecycleCapability {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super("ai-sdk-harness");
|
|
33
|
+
_classPrivateMethodInitSpec(this, _AiSdkHarness_brand);
|
|
34
|
+
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
35
|
+
_classPrivateFieldInitSpec(this, _heartbeatMs, void 0);
|
|
36
|
+
_classPrivateFieldInitSpec(this, _runs, /* @__PURE__ */ new Map());
|
|
37
|
+
_classPrivateFieldInitSpec(this, _driving, /* @__PURE__ */ new Map());
|
|
38
|
+
_classPrivateFieldInitSpec(this, _watchers, /* @__PURE__ */ new Map());
|
|
39
|
+
_classPrivateFieldInitSpec(this, _waiters, /* @__PURE__ */ new Map());
|
|
40
|
+
_classPrivateFieldSet2(_options, this, options);
|
|
41
|
+
_classPrivateFieldSet2(_heartbeatMs, this, options.heartbeatMs ?? HEARTBEAT_MS);
|
|
42
|
+
this.sessions = {
|
|
43
|
+
create: async () => _assertClassBrand(_AiSdkHarness_brand, this, _create).call(this, { id: crypto.randomUUID() }),
|
|
44
|
+
fork: async (from) => {
|
|
45
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _ensure).call(this, from);
|
|
46
|
+
const session = _assertClassBrand(_AiSdkHarness_brand, this, _create).call(this, {
|
|
47
|
+
id: crypto.randomUUID(),
|
|
48
|
+
parent: from
|
|
49
|
+
});
|
|
50
|
+
for (const message of _assertClassBrand(_AiSdkHarness_brand, this, _messages).call(this, from)) _assertClassBrand(_AiSdkHarness_brand, this, _putMessage).call(this, session.id, message);
|
|
51
|
+
return session;
|
|
52
|
+
},
|
|
53
|
+
list: async () => {
|
|
54
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _ensure).call(this, DEFAULT_SESSION);
|
|
55
|
+
return [..._get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).list({ prefix: `${PREFIX}s:` })].map(([, { id, parent }]) => ({
|
|
56
|
+
id,
|
|
57
|
+
...parent !== void 0 && { parent },
|
|
58
|
+
busy: _assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, id).length > 0
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async onStart() {
|
|
64
|
+
const sessions = [..._get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).list({ prefix: `${PREFIX}s:` })];
|
|
65
|
+
for (const [, session] of sessions) if (_assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, session.id).length > 0) await _assertClassBrand(_AiSdkHarness_brand, this, _wake).call(this, session.id);
|
|
66
|
+
}
|
|
67
|
+
async onJob(context) {
|
|
68
|
+
if (context.job.fn !== WAKE_FN) return;
|
|
69
|
+
const session = context.job.payload?.session;
|
|
70
|
+
if (typeof session !== "string") return;
|
|
71
|
+
if (!_classPrivateFieldGet2(_driving, this).has(session) && _assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, session).length === 0) return;
|
|
72
|
+
this.lifecycle.trackAlarmWork(_assertClassBrand(_AiSdkHarness_brand, this, _drive).call(this, session));
|
|
73
|
+
return { rescheduleAt: Date.now() + _classPrivateFieldGet2(_heartbeatMs, this) };
|
|
74
|
+
}
|
|
75
|
+
session(id = DEFAULT_SESSION) {
|
|
76
|
+
return {
|
|
77
|
+
id,
|
|
78
|
+
submit: (input, options) => _assertClassBrand(_AiSdkHarness_brand, this, _submit).call(this, id, input, options),
|
|
79
|
+
abort: (operationId) => _assertClassBrand(_AiSdkHarness_brand, this, _abort).call(this, id, operationId),
|
|
80
|
+
wait: (operationId, signal) => _assertClassBrand(_AiSdkHarness_brand, this, _wait).call(this, id, operationId, signal),
|
|
81
|
+
reset: (handoff) => _assertClassBrand(_AiSdkHarness_brand, this, _reset).call(this, id, handoff),
|
|
82
|
+
watch: async () => _assertClassBrand(_AiSdkHarness_brand, this, _watch).call(this, id)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
async function _submit(session, input, options = {}) {
|
|
87
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _ensure).call(this, session);
|
|
88
|
+
const operationId = options.operationId ?? crypto.randomUUID();
|
|
89
|
+
if (_assertClassBrand(_AiSdkHarness_brand, this, _operation).call(this, session, operationId)) return {
|
|
90
|
+
operationId,
|
|
91
|
+
session,
|
|
92
|
+
accepted: false
|
|
93
|
+
};
|
|
94
|
+
const op = {
|
|
95
|
+
operationId,
|
|
96
|
+
seq: _assertClassBrand(_AiSdkHarness_brand, this, _nextSeq).call(this, session),
|
|
97
|
+
input,
|
|
98
|
+
status: "queued"
|
|
99
|
+
};
|
|
100
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _saveOperation).call(this, session, op);
|
|
101
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
102
|
+
type: "operation",
|
|
103
|
+
status: {
|
|
104
|
+
operationId,
|
|
105
|
+
status: "queued"
|
|
106
|
+
}
|
|
107
|
+
}]);
|
|
108
|
+
await _assertClassBrand(_AiSdkHarness_brand, this, _wake).call(this, session);
|
|
109
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _drive).call(this, session);
|
|
110
|
+
return {
|
|
111
|
+
operationId,
|
|
112
|
+
session,
|
|
113
|
+
accepted: true
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function _abort(session, operationId) {
|
|
117
|
+
const run = _classPrivateFieldGet2(_runs, this).get(session);
|
|
118
|
+
const targets = operationId ? [_assertClassBrand(_AiSdkHarness_brand, this, _operation).call(this, session, operationId)].filter((op) => op !== void 0 && isPending(op)) : _assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, session);
|
|
119
|
+
for (const op of targets) if (run?.operations.includes(op.operationId)) run.abort.abort();
|
|
120
|
+
else _assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, {
|
|
121
|
+
status: "unanswered",
|
|
122
|
+
reason: "withdrawn"
|
|
123
|
+
});
|
|
124
|
+
return targets.length > 0;
|
|
125
|
+
}
|
|
126
|
+
async function _wait(session, operationId, signal) {
|
|
127
|
+
const op = _assertClassBrand(_AiSdkHarness_brand, this, _operation).call(this, session, operationId);
|
|
128
|
+
if (!op) return {
|
|
129
|
+
operationId,
|
|
130
|
+
session,
|
|
131
|
+
status: "unanswered",
|
|
132
|
+
reason: "not_found"
|
|
133
|
+
};
|
|
134
|
+
const settled = isPending(op) ? await new Promise((resolve, reject) => {
|
|
135
|
+
if (signal?.aborted) {
|
|
136
|
+
reject(signal.reason);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const key = waiterKey(session, operationId);
|
|
140
|
+
const waiters = _classPrivateFieldGet2(_waiters, this).get(key) ?? /* @__PURE__ */ new Set();
|
|
141
|
+
_classPrivateFieldGet2(_waiters, this).set(key, waiters);
|
|
142
|
+
const done = (result) => {
|
|
143
|
+
signal?.removeEventListener("abort", aborted);
|
|
144
|
+
resolve(result);
|
|
145
|
+
};
|
|
146
|
+
const aborted = () => {
|
|
147
|
+
waiters.delete(done);
|
|
148
|
+
reject(signal?.reason);
|
|
149
|
+
};
|
|
150
|
+
waiters.add(done);
|
|
151
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
152
|
+
}) : op;
|
|
153
|
+
return settled.status === "done" ? {
|
|
154
|
+
operationId,
|
|
155
|
+
session,
|
|
156
|
+
status: "done",
|
|
157
|
+
...settled.text !== void 0 && { text: settled.text }
|
|
158
|
+
} : {
|
|
159
|
+
operationId,
|
|
160
|
+
session,
|
|
161
|
+
status: "unanswered",
|
|
162
|
+
...settled.reason !== void 0 && { reason: settled.reason }
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async function _reset(session, handoff) {
|
|
166
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _ensure).call(this, session);
|
|
167
|
+
await _assertClassBrand(_AiSdkHarness_brand, this, _abort).call(this, session);
|
|
168
|
+
await _classPrivateFieldGet2(_driving, this).get(session);
|
|
169
|
+
for (const [key] of _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).list({ prefix: messagePrefix(session) })) _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).delete(key);
|
|
170
|
+
const events = [{ type: "reset" }];
|
|
171
|
+
if (handoff) {
|
|
172
|
+
const note = {
|
|
173
|
+
id: crypto.randomUUID(),
|
|
174
|
+
role: "system",
|
|
175
|
+
parts: [{
|
|
176
|
+
type: "text",
|
|
177
|
+
text: handoff
|
|
178
|
+
}]
|
|
179
|
+
};
|
|
180
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _putMessage).call(this, session, note);
|
|
181
|
+
events.push({
|
|
182
|
+
type: "message",
|
|
183
|
+
message: _assertClassBrand(_AiSdkHarness_brand, this, _transcript).call(this, note)
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, events);
|
|
187
|
+
}
|
|
188
|
+
function _watch(session) {
|
|
189
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _ensure).call(this, session);
|
|
190
|
+
const run = _classPrivateFieldGet2(_runs, this).get(session);
|
|
191
|
+
const state = {
|
|
192
|
+
messages: _assertClassBrand(_AiSdkHarness_brand, this, _messages).call(this, session).map((m) => _assertClassBrand(_AiSdkHarness_brand, this, _transcript).call(this, m)),
|
|
193
|
+
pending: _assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, session).map((op) => ({
|
|
194
|
+
operationId: op.operationId,
|
|
195
|
+
status: op.status === "placed" ? "placed" : "queued"
|
|
196
|
+
})),
|
|
197
|
+
...run && { run: {
|
|
198
|
+
operations: [...run.operations],
|
|
199
|
+
...run.partial.length > 0 && { partial: [...run.partial] }
|
|
200
|
+
} }
|
|
201
|
+
};
|
|
202
|
+
const watchers = _classPrivateFieldGet2(_watchers, this).get(session) ?? /* @__PURE__ */ new Set();
|
|
203
|
+
_classPrivateFieldGet2(_watchers, this).set(session, watchers);
|
|
204
|
+
const watcher = new Watcher(state, () => watchers.delete(watcher));
|
|
205
|
+
watchers.add(watcher);
|
|
206
|
+
return watcher;
|
|
207
|
+
}
|
|
208
|
+
/** Run the session's operations in order until none are left. */
|
|
209
|
+
function _drive(session) {
|
|
210
|
+
let driving = _classPrivateFieldGet2(_driving, this).get(session);
|
|
211
|
+
if (!driving) {
|
|
212
|
+
driving = (async () => {
|
|
213
|
+
try {
|
|
214
|
+
for (;;) {
|
|
215
|
+
const next = _assertClassBrand(_AiSdkHarness_brand, this, _pending).call(this, session)[0];
|
|
216
|
+
if (!next) return;
|
|
217
|
+
await _assertClassBrand(_AiSdkHarness_brand, this, _run).call(this, session, next);
|
|
218
|
+
}
|
|
219
|
+
} finally {
|
|
220
|
+
_classPrivateFieldGet2(_driving, this).delete(session);
|
|
221
|
+
}
|
|
222
|
+
})();
|
|
223
|
+
_classPrivateFieldGet2(_driving, this).set(session, driving);
|
|
224
|
+
}
|
|
225
|
+
return driving;
|
|
226
|
+
}
|
|
227
|
+
async function _run(session, op) {
|
|
228
|
+
const { operationId } = op;
|
|
229
|
+
let owner = "parts" in op.input ? op.input.from?.participantId : void 0;
|
|
230
|
+
if (op.status === "queued") {
|
|
231
|
+
let placed;
|
|
232
|
+
if ("parts" in op.input) placed = {
|
|
233
|
+
id: op.input.messageId ?? operationId,
|
|
234
|
+
role: "user",
|
|
235
|
+
parts: op.input.parts.map(toUIPart)
|
|
236
|
+
};
|
|
237
|
+
else {
|
|
238
|
+
const answered = _assertClassBrand(_AiSdkHarness_brand, this, _answer).call(this, session, op.input);
|
|
239
|
+
if (typeof answered === "string") {
|
|
240
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, {
|
|
241
|
+
status: "unanswered",
|
|
242
|
+
reason: answered
|
|
243
|
+
});
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
placed = answered;
|
|
247
|
+
}
|
|
248
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _putMessage).call(this, session, placed);
|
|
249
|
+
op = {
|
|
250
|
+
...op,
|
|
251
|
+
status: "placed"
|
|
252
|
+
};
|
|
253
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _saveOperation).call(this, session, op);
|
|
254
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
255
|
+
type: "message",
|
|
256
|
+
message: _assertClassBrand(_AiSdkHarness_brand, this, _transcript).call(this, placed)
|
|
257
|
+
}, {
|
|
258
|
+
type: "operation",
|
|
259
|
+
status: {
|
|
260
|
+
operationId,
|
|
261
|
+
status: "placed"
|
|
262
|
+
}
|
|
263
|
+
}]);
|
|
264
|
+
}
|
|
265
|
+
const messages = _assertClassBrand(_AiSdkHarness_brand, this, _messages).call(this, session);
|
|
266
|
+
const last = messages.at(-1);
|
|
267
|
+
if (last?.role === "assistant") {
|
|
268
|
+
owner = last.metadata?.owner;
|
|
269
|
+
if (awaitsInput$1(last)) {
|
|
270
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, { status: "done" });
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const run = {
|
|
275
|
+
operations: [operationId],
|
|
276
|
+
partial: [],
|
|
277
|
+
abort: new AbortController()
|
|
278
|
+
};
|
|
279
|
+
_classPrivateFieldGet2(_runs, this).set(session, run);
|
|
280
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
281
|
+
type: "run-start",
|
|
282
|
+
operations: [operationId]
|
|
283
|
+
}]);
|
|
284
|
+
const { model, tools, system } = _classPrivateFieldGet2(_options, this);
|
|
285
|
+
let message;
|
|
286
|
+
let error;
|
|
287
|
+
try {
|
|
288
|
+
const stream = toUIMessageStream({
|
|
289
|
+
stream: streamText({
|
|
290
|
+
model,
|
|
291
|
+
...system !== void 0 && { system },
|
|
292
|
+
...tools && { tools },
|
|
293
|
+
stopWhen: _classPrivateFieldGet2(_options, this).stopWhen ?? stepCountIs(5),
|
|
294
|
+
messages: await convertToModelMessages(messages, tools && { tools }),
|
|
295
|
+
abortSignal: run.abort.signal
|
|
296
|
+
}).stream,
|
|
297
|
+
...tools && { tools },
|
|
298
|
+
originalMessages: messages,
|
|
299
|
+
generateMessageId: () => crypto.randomUUID(),
|
|
300
|
+
onEnd: ({ responseMessage }) => {
|
|
301
|
+
message = {
|
|
302
|
+
...responseMessage,
|
|
303
|
+
metadata: {
|
|
304
|
+
...responseMessage.metadata,
|
|
305
|
+
...owner !== void 0 && { owner }
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
for await (const chunk of toResponseChunks(stream, {
|
|
311
|
+
...tools && { tools },
|
|
312
|
+
...owner !== void 0 && { owner }
|
|
313
|
+
})) {
|
|
314
|
+
run.partial.push(chunk);
|
|
315
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
316
|
+
type: "chunk",
|
|
317
|
+
chunk
|
|
318
|
+
}]);
|
|
319
|
+
}
|
|
320
|
+
} catch (caught) {
|
|
321
|
+
error = caught;
|
|
322
|
+
}
|
|
323
|
+
if (message) {
|
|
324
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _putMessage).call(this, session, message);
|
|
325
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
326
|
+
type: "message",
|
|
327
|
+
message: _assertClassBrand(_AiSdkHarness_brand, this, _transcript).call(this, message)
|
|
328
|
+
}]);
|
|
329
|
+
}
|
|
330
|
+
_classPrivateFieldGet2(_runs, this).delete(session);
|
|
331
|
+
if (run.abort.signal.aborted) _assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, {
|
|
332
|
+
status: "unanswered",
|
|
333
|
+
reason: "aborted"
|
|
334
|
+
});
|
|
335
|
+
else if (error !== void 0) {
|
|
336
|
+
console.error(`AI SDK run for "${operationId}" failed`, error);
|
|
337
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, {
|
|
338
|
+
status: "unanswered",
|
|
339
|
+
reason: error instanceof Error ? error.message : "failed"
|
|
340
|
+
});
|
|
341
|
+
} else _assertClassBrand(_AiSdkHarness_brand, this, _settle).call(this, session, op, {
|
|
342
|
+
status: "done",
|
|
343
|
+
text: message ? textOf(message) : ""
|
|
344
|
+
});
|
|
345
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
346
|
+
type: "run-end",
|
|
347
|
+
operations: [operationId]
|
|
348
|
+
}]);
|
|
349
|
+
}
|
|
350
|
+
/** The message an answer updates, or why it is not wanted. */
|
|
351
|
+
function _answer(session, answer) {
|
|
352
|
+
const messages = _assertClassBrand(_AiSdkHarness_brand, this, _messages).call(this, session);
|
|
353
|
+
const event = answer.type === "approval" ? {
|
|
354
|
+
type: "approval-response",
|
|
355
|
+
approvalId: answer.approvalId,
|
|
356
|
+
approved: answer.approved,
|
|
357
|
+
...answer.reason !== void 0 && { reason: answer.reason }
|
|
358
|
+
} : {
|
|
359
|
+
type: "tool-result",
|
|
360
|
+
toolCallId: answer.toolCallId,
|
|
361
|
+
result: answer.result
|
|
362
|
+
};
|
|
363
|
+
if (answer.type === "tool-result") {
|
|
364
|
+
const owner = messages.find((m) => m.parts.some((p) => "toolCallId" in p && p.toolCallId === answer.toolCallId))?.metadata?.owner;
|
|
365
|
+
const from = answer.from?.participantId;
|
|
366
|
+
if (owner !== void 0 && from !== void 0 && owner !== from) return "not_owner";
|
|
367
|
+
}
|
|
368
|
+
return answerToolCall(messages, event) ?? "not_waiting";
|
|
369
|
+
}
|
|
370
|
+
function _settle(session, op, result) {
|
|
371
|
+
const settled = {
|
|
372
|
+
...op,
|
|
373
|
+
...result
|
|
374
|
+
};
|
|
375
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _saveOperation).call(this, session, settled);
|
|
376
|
+
const { operationId } = op;
|
|
377
|
+
_assertClassBrand(_AiSdkHarness_brand, this, _emit).call(this, session, [{
|
|
378
|
+
type: "operation",
|
|
379
|
+
status: result.status === "done" ? {
|
|
380
|
+
operationId,
|
|
381
|
+
status: "done",
|
|
382
|
+
...result.text !== void 0 && { text: result.text }
|
|
383
|
+
} : {
|
|
384
|
+
operationId,
|
|
385
|
+
status: "unanswered",
|
|
386
|
+
reason: result.reason
|
|
387
|
+
}
|
|
388
|
+
}]);
|
|
389
|
+
const key = waiterKey(session, operationId);
|
|
390
|
+
for (const waiter of _classPrivateFieldGet2(_waiters, this).get(key) ?? []) waiter(settled);
|
|
391
|
+
_classPrivateFieldGet2(_waiters, this).delete(key);
|
|
392
|
+
}
|
|
393
|
+
function _wake(session) {
|
|
394
|
+
return this.lifecycle.jobs.push({
|
|
395
|
+
id: `${PREFIX}wake:${session}`,
|
|
396
|
+
fn: WAKE_FN,
|
|
397
|
+
time: Date.now(),
|
|
398
|
+
payload: { session },
|
|
399
|
+
singleflight: true
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function _emit(session, events) {
|
|
403
|
+
for (const watcher of _classPrivateFieldGet2(_watchers, this).get(session) ?? []) watcher.push(events);
|
|
404
|
+
}
|
|
405
|
+
function _get_kv() {
|
|
406
|
+
return this.lifecycle.storage.kv;
|
|
407
|
+
}
|
|
408
|
+
function _create(session) {
|
|
409
|
+
_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(`${PREFIX}s:${session.id}`, session);
|
|
410
|
+
return this.session(session.id);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Sessions are created on first use, so any id names one. That is not an
|
|
414
|
+
* authorization gap: whoever reaches the agent may create sessions anyway.
|
|
415
|
+
*/
|
|
416
|
+
function _ensure(session) {
|
|
417
|
+
if (_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).get(`${PREFIX}s:${session}`) === void 0) _assertClassBrand(_AiSdkHarness_brand, this, _create).call(this, { id: session });
|
|
418
|
+
}
|
|
419
|
+
function _nextSeq(session) {
|
|
420
|
+
const key = `${PREFIX}seq:${session}`;
|
|
421
|
+
const seq = (_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).get(key) ?? 0) + 1;
|
|
422
|
+
_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(key, seq);
|
|
423
|
+
return seq;
|
|
424
|
+
}
|
|
425
|
+
function _messages(session) {
|
|
426
|
+
return [..._get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).list({ prefix: messagePrefix(session) })].map(([, message]) => message);
|
|
427
|
+
}
|
|
428
|
+
/** Save a message, in place of any with its id. */
|
|
429
|
+
function _putMessage(session, message) {
|
|
430
|
+
const indexKey = `${PREFIX}mi:${JSON.stringify(session)}:${message.id}`;
|
|
431
|
+
let key = _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).get(indexKey);
|
|
432
|
+
if (key === void 0 || _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).get(key) === void 0) {
|
|
433
|
+
key = messagePrefix(session) + pad(_assertClassBrand(_AiSdkHarness_brand, this, _nextSeq).call(this, session));
|
|
434
|
+
_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(indexKey, key);
|
|
435
|
+
}
|
|
436
|
+
_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(key, message);
|
|
437
|
+
}
|
|
438
|
+
function _operation(session, operationId) {
|
|
439
|
+
return _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).get(operationKey(session, operationId));
|
|
440
|
+
}
|
|
441
|
+
function _saveOperation(session, op) {
|
|
442
|
+
_get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(operationKey(session, op.operationId), op);
|
|
443
|
+
const pendingKey = `${pendingPrefix(session)}${pad(op.seq)}`;
|
|
444
|
+
if (isPending(op)) _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).put(pendingKey, op.operationId);
|
|
445
|
+
else _get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).delete(pendingKey);
|
|
446
|
+
}
|
|
447
|
+
/** Unsettled operations, oldest first. */
|
|
448
|
+
function _pending(session) {
|
|
449
|
+
return [..._get_kv.call(_assertClassBrand(_AiSdkHarness_brand, this)).list({ prefix: pendingPrefix(session) })].map(([, id]) => _assertClassBrand(_AiSdkHarness_brand, this, _operation).call(this, session, id)).filter((op) => op !== void 0);
|
|
450
|
+
}
|
|
451
|
+
function _transcript(message) {
|
|
452
|
+
const owner = message.metadata?.owner;
|
|
453
|
+
return toTranscriptMessage(message, {
|
|
454
|
+
..._classPrivateFieldGet2(_options, this).tools && { tools: _classPrivateFieldGet2(_options, this).tools },
|
|
455
|
+
...owner !== void 0 && { owner }
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
var _close = /* @__PURE__ */ new WeakMap();
|
|
459
|
+
var _listener = /* @__PURE__ */ new WeakMap();
|
|
460
|
+
var _queue = /* @__PURE__ */ new WeakMap();
|
|
461
|
+
var _draining = /* @__PURE__ */ new WeakMap();
|
|
462
|
+
var _stopped = /* @__PURE__ */ new WeakMap();
|
|
463
|
+
var _Watcher_brand = /* @__PURE__ */ new WeakSet();
|
|
464
|
+
/** One watch: events queue until `start`, then reach the listener in order. */
|
|
465
|
+
var Watcher = class {
|
|
466
|
+
constructor(state, onStop) {
|
|
467
|
+
this.state = state;
|
|
468
|
+
this.onStop = onStop;
|
|
469
|
+
_classPrivateMethodInitSpec(this, _Watcher_brand);
|
|
470
|
+
_classPrivateFieldInitSpec(this, _close, void 0);
|
|
471
|
+
_classPrivateFieldInitSpec(this, _listener, void 0);
|
|
472
|
+
_classPrivateFieldInitSpec(this, _queue, []);
|
|
473
|
+
_classPrivateFieldInitSpec(this, _draining, false);
|
|
474
|
+
_classPrivateFieldInitSpec(this, _stopped, false);
|
|
475
|
+
this.closed = new Promise((resolve) => {
|
|
476
|
+
_classPrivateFieldSet2(_close, this, resolve);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
start(listener) {
|
|
480
|
+
_classPrivateFieldSet2(_listener, this, listener);
|
|
481
|
+
_assertClassBrand(_Watcher_brand, this, _drain).call(this);
|
|
482
|
+
}
|
|
483
|
+
async stop() {
|
|
484
|
+
_classPrivateFieldSet2(_stopped, this, true);
|
|
485
|
+
this.onStop();
|
|
486
|
+
_classPrivateFieldGet2(_close, this).call(this);
|
|
487
|
+
}
|
|
488
|
+
push(events) {
|
|
489
|
+
if (_classPrivateFieldGet2(_stopped, this)) return;
|
|
490
|
+
_classPrivateFieldGet2(_queue, this).push(events);
|
|
491
|
+
_assertClassBrand(_Watcher_brand, this, _drain).call(this);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
async function _drain() {
|
|
495
|
+
if (!_classPrivateFieldGet2(_listener, this) || _classPrivateFieldGet2(_draining, this)) return;
|
|
496
|
+
_classPrivateFieldSet2(_draining, this, true);
|
|
497
|
+
try {
|
|
498
|
+
while (_classPrivateFieldGet2(_queue, this).length > 0 && !_classPrivateFieldGet2(_stopped, this)) {
|
|
499
|
+
const events = _classPrivateFieldGet2(_queue, this).shift();
|
|
500
|
+
try {
|
|
501
|
+
await _classPrivateFieldGet2(_listener, this).call(this, events);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
console.error("A session watcher failed", error);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
} finally {
|
|
507
|
+
_classPrivateFieldSet2(_draining, this, false);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function isPending(op) {
|
|
511
|
+
return op.status === "queued" || op.status === "placed";
|
|
512
|
+
}
|
|
513
|
+
/** Whether the message has a tool call waiting for a result or approval. */
|
|
514
|
+
function awaitsInput$1(message) {
|
|
515
|
+
return message.parts.some((part) => "toolCallId" in part && (part.state === "input-available" || part.state === "approval-requested"));
|
|
516
|
+
}
|
|
517
|
+
function textOf(message) {
|
|
518
|
+
return message.parts.map((part) => part.type === "text" ? part.text : "").join("");
|
|
519
|
+
}
|
|
520
|
+
function toUIPart(part) {
|
|
521
|
+
return part.type === "text" ? {
|
|
522
|
+
type: "text",
|
|
523
|
+
text: part.text
|
|
524
|
+
} : {
|
|
525
|
+
type: "file",
|
|
526
|
+
mediaType: part.mediaType,
|
|
527
|
+
url: part.url,
|
|
528
|
+
...part.filename !== void 0 && { filename: part.filename }
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function pad(seq) {
|
|
532
|
+
return String(seq).padStart(12, "0");
|
|
533
|
+
}
|
|
534
|
+
function messagePrefix(session) {
|
|
535
|
+
return `${PREFIX}m:${JSON.stringify(session)}:`;
|
|
536
|
+
}
|
|
537
|
+
function pendingPrefix(session) {
|
|
538
|
+
return `${PREFIX}p:${JSON.stringify(session)}:`;
|
|
539
|
+
}
|
|
540
|
+
function operationKey(session, operationId) {
|
|
541
|
+
return `${PREFIX}o:${JSON.stringify(session)}:${operationId}`;
|
|
542
|
+
}
|
|
543
|
+
function waiterKey(session, operationId) {
|
|
544
|
+
return JSON.stringify([session, operationId]);
|
|
545
|
+
}
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/experimental/channels/tool-schema.ts
|
|
548
|
+
const channelMessageJsonSchema = {
|
|
549
|
+
type: "object",
|
|
550
|
+
properties: {
|
|
551
|
+
title: {
|
|
552
|
+
type: "string",
|
|
553
|
+
description: "Optional title or topic for the message"
|
|
554
|
+
},
|
|
555
|
+
markdown: {
|
|
556
|
+
type: "string",
|
|
557
|
+
minLength: 1,
|
|
558
|
+
description: "Message content formatted as Markdown"
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
required: ["markdown"],
|
|
562
|
+
additionalProperties: false
|
|
563
|
+
};
|
|
564
|
+
function parseChannelMessage(value) {
|
|
565
|
+
if (typeof value === "object" && value !== null) {
|
|
566
|
+
const candidate = value;
|
|
567
|
+
if (typeof candidate.markdown === "string" && candidate.markdown.length > 0 && (candidate.title === void 0 || typeof candidate.title === "string")) return {
|
|
568
|
+
...typeof candidate.title === "string" ? { title: candidate.title } : {},
|
|
569
|
+
markdown: candidate.markdown
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
throw new Error("Expected an optional string title and a non-empty Markdown string");
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/harness/ai-sdk/send-message-tool.ts
|
|
576
|
+
const channelMessageSchema = jsonSchema(channelMessageJsonSchema, { validate(value) {
|
|
577
|
+
try {
|
|
578
|
+
return {
|
|
579
|
+
success: true,
|
|
580
|
+
value: parseChannelMessage(value)
|
|
581
|
+
};
|
|
582
|
+
} catch (error) {
|
|
583
|
+
return {
|
|
584
|
+
success: false,
|
|
585
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
} });
|
|
589
|
+
/**
|
|
590
|
+
* Adapt one Host-resolved surface to an AI SDK tool.
|
|
591
|
+
*
|
|
592
|
+
* The caller chooses the key used in its ToolSet and owns model-facing policy
|
|
593
|
+
* such as the description, examples, metadata, and approval requirement.
|
|
594
|
+
*/
|
|
595
|
+
function createSendMessageTool(gateway, surface, options = {}) {
|
|
596
|
+
return tool({
|
|
597
|
+
...options,
|
|
598
|
+
inputSchema: channelMessageSchema,
|
|
599
|
+
execute: (message) => gateway.deliver(surface, message)
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
//#endregion
|
|
603
|
+
export { AiSdkHarness, answerToolCall, awaitsInput, createSendMessageTool, toResponseChunk, toResponseChunks, toTranscriptMessage, toUIMessage, toUIMessageChunk };
|
|
604
|
+
|
|
605
|
+
//# sourceMappingURL=index.js.map
|