agents 0.26.0 → 0.27.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/{agent-routing-0DR0Tk2v.d.ts → agent-routing-Bhdbvf7s.d.ts} +13 -8
- 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-bJZwBMfq.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/ai-sdk-OoGkFy3s.js +2444 -0
- package/dist/ai-sdk-OoGkFy3s.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-sdk.d.ts +1 -1
- package/dist/browser/ai-sdk.js +2 -2
- package/dist/browser/ai-sdk.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/tanstack-ai.d.ts +1 -1
- package/dist/browser/tanstack-ai.js +1 -1
- package/dist/{browser-DE3d-RLk.d.ts → browser-tmkcAAI3.d.ts} +2 -2
- package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-Bn-nzJQI.d.ts} +3 -3
- package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-CBqs6hqa.js} +58 -18
- package/dist/browser-tool-CBqs6hqa.js.map +1 -0
- package/dist/capability-B4WbF81e.js.map +1 -1
- package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-O5VbQzqg.d.ts} +9 -1
- 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-fyQrLGkD.js → client-1tEQ1Oqz.js} +27 -2
- package/dist/{client-fyQrLGkD.js.map → client-1tEQ1Oqz.js.map} +1 -1
- package/dist/{client-je3koD9Z.d.ts → client-DS3Dz9l0.d.ts} +2 -2
- package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
- package/dist/client.d.ts +1 -1
- package/dist/conversations-DH0ut_8n.d.ts +192 -0
- package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-C07C5o5Y.d.ts} +3 -3
- 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-DRqp475_.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-BDC07gYO.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 +2 -1
- 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 +2529 -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-D0A5tbWu.d.ts} +2 -2
- package/dist/index-Ib_4dwOo.d.ts +200 -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-DNrpTu49.js +23 -0
- package/dist/input-schema-DNrpTu49.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/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-pwTNq9z6.d.ts +134 -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/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-RdACNXDP.d.ts → scheduler-CrFCnv_J.d.ts} +2 -2
- package/dist/schedules/index.d.ts +1 -1
- package/dist/serializable.d.ts +1 -1
- package/dist/sessions/index.d.ts +11 -434
- package/dist/sessions/index.js +1 -2271
- package/dist/sessions-B9pNuxdT.js +2272 -0
- package/dist/sessions-B9pNuxdT.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-DgCbZtIR.js} +4 -4
- package/dist/{src-BZeu-SCD.js.map → src-DgCbZtIR.js.map} +1 -1
- 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/store-DLeqKuj3.d.ts +310 -0
- package/dist/store-vgcPYo8K.js +432 -0
- package/dist/store-vgcPYo8K.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-CITClVer.js} +16 -3
- package/dist/streams-CITClVer.js.map +1 -0
- package/dist/{streams-Cmkj9QfW.d.ts → streams-fbG61qM8.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-CkTZNaV1.js} +2 -1
- package/dist/tasks-CkTZNaV1.js.map +1 -0
- package/dist/{tasks-9YxYtByh.d.ts → tasks-PtlB4Uyn.d.ts} +2 -2
- package/dist/tool-3PA8xjB_.js +421 -0
- package/dist/tool-3PA8xjB_.js.map +1 -0
- package/dist/tool-BPJEbwaX.d.ts +278 -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/websearch/index.d.ts +58 -0
- package/dist/websearch/index.js +2 -0
- package/dist/websearch/tools/ai-sdk.d.ts +77 -0
- package/dist/websearch/tools/ai-sdk.js +46 -0
- package/dist/websearch/tools/ai-sdk.js.map +1 -0
- package/dist/websearch/tools/pi.d.ts +82 -0
- package/dist/websearch/tools/pi.js +89 -0
- package/dist/websearch/tools/pi.js.map +1 -0
- package/dist/websearch/tools/tanstack-ai.d.ts +71 -0
- package/dist/websearch/tools/tanstack-ai.js +46 -0
- package/dist/websearch/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-CmENGb-Z.js} +18 -4
- package/dist/websockets-CmENGb-Z.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 +3 -0
- package/docs/harnesses/think.md +215 -0
- package/docs/index.md +2 -1
- package/docs/lifecycle.md +40 -0
- package/docs/search-the-web.md +133 -0
- package/package.json +117 -38
- package/dist/browser-tool-CQ10e6Kj.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/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/models/ai-sdk/index.js.map +0 -1
- package/dist/protocol-kHsr-f0X.js.map +0 -1
- package/dist/sessions/index.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,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
S as ConnectionContext,
|
|
3
|
+
T as WSMessage,
|
|
4
|
+
x as Connection
|
|
5
|
+
} from "./capability-runner-O5VbQzqg.js";
|
|
6
|
+
import { RpcTarget } from "cloudflare:workers";
|
|
7
|
+
|
|
8
|
+
//#region src/websockets/options.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* The part of a `State` capability the WebSockets capability uses. A
|
|
11
|
+
* structural port, so any `State<T>` fits without a cast and the
|
|
12
|
+
* capability never depends on the class itself.
|
|
13
|
+
*/
|
|
14
|
+
type SyncedState = {
|
|
15
|
+
/** Current state, or `undefined` when nothing is stored. */ get(): unknown /** Validate and persist a change; throws when the host rejects it. */;
|
|
16
|
+
set(nextState: never, source: Connection): void;
|
|
17
|
+
};
|
|
18
|
+
/** A frame delivered on a capability-owned WebSocket connection. */
|
|
19
|
+
type WebSocketMessage = WSMessage;
|
|
20
|
+
/**
|
|
21
|
+
* Connection handlers for the WebSockets capability. Handlers run inside
|
|
22
|
+
* the host invocation boundary with the live connection in ambient
|
|
23
|
+
* context (`getCurrentAgent().connection`).
|
|
24
|
+
*
|
|
25
|
+
* @experimental The API surface may change before stabilizing.
|
|
26
|
+
*/
|
|
27
|
+
type WebSocketHandlers = {
|
|
28
|
+
/** Handle a newly accepted hibernating WebSocket connection. */ onConnect?(
|
|
29
|
+
connection: Connection,
|
|
30
|
+
ctx: ConnectionContext
|
|
31
|
+
): void | Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Handle a message from a hibernating WebSocket connection. For handlers
|
|
34
|
+
* added with `WebSockets.use`, returning true claims the message, so
|
|
35
|
+
* later handlers do not see it.
|
|
36
|
+
*/
|
|
37
|
+
onMessage?(
|
|
38
|
+
connection: Connection,
|
|
39
|
+
message: WebSocketMessage
|
|
40
|
+
):
|
|
41
|
+
| void
|
|
42
|
+
| boolean
|
|
43
|
+
| Promise<
|
|
44
|
+
void | boolean
|
|
45
|
+
> /** Handle a closing hibernating WebSocket connection. */;
|
|
46
|
+
onClose?(
|
|
47
|
+
connection: Connection,
|
|
48
|
+
code: number,
|
|
49
|
+
reason: string,
|
|
50
|
+
wasClean: boolean
|
|
51
|
+
): void | Promise<void> /** Handle a mid-connection WebSocket error. */;
|
|
52
|
+
onError?(connection: Connection, error: unknown): void | Promise<void>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for the WebSockets capability.
|
|
56
|
+
*
|
|
57
|
+
* @experimental The API surface may change before stabilizing.
|
|
58
|
+
*/
|
|
59
|
+
interface WebSocketsOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Connection handlers for WebSocket clients. The capability accepts and
|
|
62
|
+
* tracks every WebSocket upgrade either way; handlers add behavior on
|
|
63
|
+
* connect, message, close and error.
|
|
64
|
+
*/
|
|
65
|
+
readonly handlers?: WebSocketHandlers;
|
|
66
|
+
/**
|
|
67
|
+
* An `RpcTarget` whose prototype methods are the host's complete remote
|
|
68
|
+
* interface, reached through `useAgent().call` and `.stub`. On the
|
|
69
|
+
* `cf-websocket` wire they are answered as JSON `rpc` frames. On the
|
|
70
|
+
* `capnweb` wire they are native Cap'n Web methods on the session root:
|
|
71
|
+
* an `RpcTarget` result becomes a live stub, a `ReadableStream` streams,
|
|
72
|
+
* and calls pipeline. Methods run through the host invocation boundary
|
|
73
|
+
* with the calling connection in scope. `Agent` answers its own
|
|
74
|
+
* decorated methods on the JSON wire and does not set this.
|
|
75
|
+
*/
|
|
76
|
+
readonly callables?: RpcTarget;
|
|
77
|
+
/**
|
|
78
|
+
* Whether a new connection gets the connect-time protocol frames —
|
|
79
|
+
* identity (`cf_agent_identity`), then the current state when `state`
|
|
80
|
+
* is set — and whether protocol frames reach it at all.
|
|
81
|
+
*
|
|
82
|
+
* - `true` (default): every connection.
|
|
83
|
+
* - a function: decided per connection at accept time. `false` marks
|
|
84
|
+
* the connection no-protocol: it gets no protocol text frames, on
|
|
85
|
+
* connect or via `broadcastState()`, but can still send and receive
|
|
86
|
+
* ordinary messages and use callables. For binary-only clients.
|
|
87
|
+
* - `false`: the host drives the connect sequence itself with
|
|
88
|
+
* `sendConnectFrames()` (or `sendIdentity()` and `sendState()`
|
|
89
|
+
* separately), and applies client state frames
|
|
90
|
+
* with `applyStateFrame()` — `Agent` does this, since it must decide
|
|
91
|
+
* whether a connection belongs to a facet before any frame is sent.
|
|
92
|
+
*/
|
|
93
|
+
readonly protocol?:
|
|
94
|
+
| boolean
|
|
95
|
+
| ((connection: Connection, ctx: ConnectionContext) => boolean);
|
|
96
|
+
/**
|
|
97
|
+
* Decide at accept time whether a connection is readonly. A readonly
|
|
98
|
+
* connection's `cf_agent_state` frames are refused with
|
|
99
|
+
* `cf_agent_state_error`; everything else works. Also settable later
|
|
100
|
+
* with `setReadonly()`.
|
|
101
|
+
*/
|
|
102
|
+
readonly readonly?: (
|
|
103
|
+
connection: Connection,
|
|
104
|
+
ctx: ConnectionContext
|
|
105
|
+
) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* A {@link SyncedState} — normally a `State` capability — to sync over
|
|
108
|
+
* connections. The capability pushes the current value to each new
|
|
109
|
+
* connection after identity and applies `cf_agent_state` frames a
|
|
110
|
+
* client sends: a readonly connection is refused, and a change the
|
|
111
|
+
* host's validator rejects is answered with `cf_agent_state_error`.
|
|
112
|
+
* Broadcasting a change is the state owner's call — wire the `State`'s
|
|
113
|
+
* `onChanged` to `broadcastState(source)`. Install the same instance on
|
|
114
|
+
* the lifecycle so it owns storage and validation; without this option
|
|
115
|
+
* state is never sent or accepted over connections.
|
|
116
|
+
*/
|
|
117
|
+
readonly state?: SyncedState;
|
|
118
|
+
/**
|
|
119
|
+
* Tags attached to each accepted connection, queryable through
|
|
120
|
+
* `getConnections(tag)`. The connection id is always the first tag.
|
|
121
|
+
*/
|
|
122
|
+
readonly getConnectionTags?: (
|
|
123
|
+
connection: Connection,
|
|
124
|
+
ctx: ConnectionContext
|
|
125
|
+
) => string[] | Promise<string[]>;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
export {
|
|
129
|
+
WebSocketsOptions as i,
|
|
130
|
+
WebSocketHandlers as n,
|
|
131
|
+
WebSocketMessage as r,
|
|
132
|
+
SyncedState as t
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=options-pwTNq9z6.d.ts.map
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
//#region src/harness/container/protocol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The wire between `ContainerHarness` (in a Durable Object) and the harness
|
|
4
|
+
* daemon (in the container). Isomorphic and dependency-free: the daemon
|
|
5
|
+
* imports it in Node, the harness in Workers.
|
|
6
|
+
*
|
|
7
|
+
* One WebSocket per session, dialled by the object through
|
|
8
|
+
* `ctx.container.getTcpPort(port)` at `/sessions/<id>`. The daemon speaks
|
|
9
|
+
* first with `hello`; the object answers with `open` (when the daemon does
|
|
10
|
+
* not hold the session yet) and `replay`, then delivers `prompt`s.
|
|
11
|
+
*
|
|
12
|
+
* Everything the daemon produces for a session is a numbered `frame`. The
|
|
13
|
+
* numbers start at 1 for each session in each container, so a frame is
|
|
14
|
+
* addressed by `(runtimeId, seq)`. The daemon keeps frames until they are
|
|
15
|
+
* acknowledged, so an object that lost its socket (evicted, redeployed)
|
|
16
|
+
* replays what it missed from its cursor. A different `runtimeId` in
|
|
17
|
+
* `hello` means a different container: its numbering starts again, and
|
|
18
|
+
* whatever the old container was doing is gone.
|
|
19
|
+
*
|
|
20
|
+
* @experimental The wire may change before it stabilizes. The object and the image are
|
|
21
|
+
* a matched pair; a version mismatch is reported in `hello`.
|
|
22
|
+
*/
|
|
23
|
+
/** Bumped on any incompatible change. */
|
|
24
|
+
declare const CONTAINER_PROTOCOL_VERSION = 1;
|
|
25
|
+
/** The daemon answers `200` here once it accepts connections. */
|
|
26
|
+
declare const CONTAINER_HEALTH_PATH = "/healthz";
|
|
27
|
+
/** The session socket: `/sessions/<encoded session id>`. */
|
|
28
|
+
declare const CONTAINER_SESSION_PATH = "/sessions/";
|
|
29
|
+
/** The shared secret the object passes on every request. */
|
|
30
|
+
declare const CONTAINER_TOKEN_HEADER = "x-cf-harness-token";
|
|
31
|
+
/** The environment variables the object starts the container with. */
|
|
32
|
+
declare const CONTAINER_ENV: {
|
|
33
|
+
/** Shared secret for `CONTAINER_TOKEN_HEADER`. */ readonly token: "CF_HARNESS_TOKEN" /** This container's id. Echoed in `hello`. */;
|
|
34
|
+
readonly runtimeId: "CF_HARNESS_RUNTIME_ID" /** The port the daemon listens on. */;
|
|
35
|
+
readonly port: "CF_HARNESS_PORT";
|
|
36
|
+
};
|
|
37
|
+
/** WebSocket close code: a newer connection for the session replaced this one. */
|
|
38
|
+
declare const CLOSE_REPLACED = 4001;
|
|
39
|
+
/** WebSocket close code: the request was not authorized. */
|
|
40
|
+
declare const CLOSE_UNAUTHORIZED = 4003;
|
|
41
|
+
/** A JSON value on the wire. */
|
|
42
|
+
type JsonValue =
|
|
43
|
+
| string
|
|
44
|
+
| number
|
|
45
|
+
| boolean
|
|
46
|
+
| null
|
|
47
|
+
| readonly JsonValue[]
|
|
48
|
+
| {
|
|
49
|
+
readonly [key: string]: JsonValue;
|
|
50
|
+
};
|
|
51
|
+
/** One part of a prompt. */
|
|
52
|
+
type ContainerInputPart =
|
|
53
|
+
| {
|
|
54
|
+
readonly type: "text";
|
|
55
|
+
readonly text: string;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
readonly type: "image" /** IANA media type, such as `image/png`. */;
|
|
59
|
+
readonly mediaType: string /** Base64 bytes. */;
|
|
60
|
+
readonly data: string;
|
|
61
|
+
};
|
|
62
|
+
/** What a prompt carries: plain text, or parts. */
|
|
63
|
+
type ContainerInput = string | readonly ContainerInputPart[];
|
|
64
|
+
/** What a submission does when the session is already running. */
|
|
65
|
+
type ContainerWhenBusy = "followUp" | "steer";
|
|
66
|
+
/**
|
|
67
|
+
* Per-session settings the object sends the adapter. `model` is the
|
|
68
|
+
* adapter's own model name; `options` is opaque to everything but the
|
|
69
|
+
* adapter.
|
|
70
|
+
*/
|
|
71
|
+
type ContainerSettings = {
|
|
72
|
+
readonly model?: string;
|
|
73
|
+
readonly options?: JsonValue;
|
|
74
|
+
};
|
|
75
|
+
/** One part of a transcript message. */
|
|
76
|
+
type ContainerPart =
|
|
77
|
+
| {
|
|
78
|
+
readonly type: "text";
|
|
79
|
+
readonly text: string;
|
|
80
|
+
}
|
|
81
|
+
| {
|
|
82
|
+
readonly type: "reasoning";
|
|
83
|
+
readonly text: string;
|
|
84
|
+
}
|
|
85
|
+
| {
|
|
86
|
+
readonly type: "image";
|
|
87
|
+
readonly mediaType: string;
|
|
88
|
+
readonly data: string;
|
|
89
|
+
}
|
|
90
|
+
| {
|
|
91
|
+
readonly type: "tool";
|
|
92
|
+
readonly toolCallId: string;
|
|
93
|
+
readonly toolName: string;
|
|
94
|
+
readonly input: JsonValue;
|
|
95
|
+
readonly state: "running" | "done" | "error";
|
|
96
|
+
readonly output?: JsonValue;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* A transcript message, in the one format every container adapter
|
|
100
|
+
* produces. An adapter emits a message again, under the same id, to update
|
|
101
|
+
* it (a tool result arriving, for example).
|
|
102
|
+
*/
|
|
103
|
+
type ContainerMessage = {
|
|
104
|
+
readonly id: string;
|
|
105
|
+
readonly role: "user" | "assistant";
|
|
106
|
+
readonly parts: readonly ContainerPart[] /** The operation the message belongs to. */;
|
|
107
|
+
readonly operationId?: string;
|
|
108
|
+
readonly createdAt: number;
|
|
109
|
+
};
|
|
110
|
+
/** What an adapter reports while it runs. */
|
|
111
|
+
type ContainerEvent =
|
|
112
|
+
/** Live text for an assistant message that is still being written. */ | {
|
|
113
|
+
readonly type: "text-delta";
|
|
114
|
+
readonly messageId: string;
|
|
115
|
+
readonly delta: string;
|
|
116
|
+
} /** Live reasoning for an assistant message that is still being written. */
|
|
117
|
+
| {
|
|
118
|
+
readonly type: "reasoning-delta";
|
|
119
|
+
readonly messageId: string;
|
|
120
|
+
readonly delta: string;
|
|
121
|
+
} /** A finished or updated transcript message. Stored. */
|
|
122
|
+
| {
|
|
123
|
+
readonly type: "message";
|
|
124
|
+
readonly message: ContainerMessage;
|
|
125
|
+
} /** Token and cost figures the adapter reports, as the adapter counts them. */
|
|
126
|
+
| {
|
|
127
|
+
readonly type: "usage";
|
|
128
|
+
readonly inputTokens?: number;
|
|
129
|
+
readonly outputTokens?: number;
|
|
130
|
+
readonly costUsd?: number;
|
|
131
|
+
} /** A diagnostic line. */
|
|
132
|
+
| {
|
|
133
|
+
readonly type: "log";
|
|
134
|
+
readonly level: "info" | "warn" | "error";
|
|
135
|
+
readonly message: string;
|
|
136
|
+
} /** Anything adapter-specific, passed through untouched. */
|
|
137
|
+
| {
|
|
138
|
+
readonly type: "raw";
|
|
139
|
+
readonly value: JsonValue;
|
|
140
|
+
};
|
|
141
|
+
/** How an operation ended, as the daemon reports it. */
|
|
142
|
+
type ContainerOutcome =
|
|
143
|
+
| {
|
|
144
|
+
readonly status: "done";
|
|
145
|
+
readonly text: string;
|
|
146
|
+
}
|
|
147
|
+
| {
|
|
148
|
+
readonly status: "unanswered";
|
|
149
|
+
readonly reason: string;
|
|
150
|
+
};
|
|
151
|
+
/** What the daemon knows about one operation it was given. */
|
|
152
|
+
type DaemonOperation =
|
|
153
|
+
| {
|
|
154
|
+
readonly operationId: string;
|
|
155
|
+
readonly status: "queued" | "running";
|
|
156
|
+
}
|
|
157
|
+
| {
|
|
158
|
+
readonly operationId: string;
|
|
159
|
+
readonly status: "settled";
|
|
160
|
+
readonly outcome: ContainerOutcome;
|
|
161
|
+
};
|
|
162
|
+
/** One numbered thing the daemon produced for a session. */
|
|
163
|
+
type DaemonFrame =
|
|
164
|
+
| {
|
|
165
|
+
readonly kind: "start";
|
|
166
|
+
readonly operationId: string;
|
|
167
|
+
}
|
|
168
|
+
| {
|
|
169
|
+
readonly kind: "event";
|
|
170
|
+
readonly operationId: string | null;
|
|
171
|
+
readonly event: ContainerEvent;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Adapter resume state to keep. The object stores these entries in order
|
|
175
|
+
* and hands all of them back in `open` on a new container.
|
|
176
|
+
*/
|
|
177
|
+
| {
|
|
178
|
+
readonly kind: "persist";
|
|
179
|
+
readonly entries: readonly JsonValue[];
|
|
180
|
+
}
|
|
181
|
+
| {
|
|
182
|
+
readonly kind: "settle";
|
|
183
|
+
readonly operationId: string;
|
|
184
|
+
readonly outcome: ContainerOutcome;
|
|
185
|
+
};
|
|
186
|
+
/** The adapter running in the container. */
|
|
187
|
+
type AdapterInfo = {
|
|
188
|
+
readonly id: string;
|
|
189
|
+
readonly version: string;
|
|
190
|
+
readonly capabilities: readonly string[];
|
|
191
|
+
};
|
|
192
|
+
/** Daemon → object. */
|
|
193
|
+
type DaemonMessage =
|
|
194
|
+
| {
|
|
195
|
+
readonly type: "hello";
|
|
196
|
+
readonly protocol: number;
|
|
197
|
+
readonly runtimeId: string;
|
|
198
|
+
readonly session: string;
|
|
199
|
+
readonly adapter: AdapterInfo /** The generation of the open adapter session, or null if none is open. */;
|
|
200
|
+
readonly open:
|
|
201
|
+
| number
|
|
202
|
+
| null /** The newest frame number for this session in this container. */;
|
|
203
|
+
readonly lastSeq: number /** Every operation this container was given for the session. */;
|
|
204
|
+
readonly operations: readonly DaemonOperation[];
|
|
205
|
+
}
|
|
206
|
+
| {
|
|
207
|
+
readonly type: "frame";
|
|
208
|
+
readonly seq: number;
|
|
209
|
+
readonly frame: DaemonFrame;
|
|
210
|
+
} /** Every kept frame after the `replay` cursor has been sent. */
|
|
211
|
+
| {
|
|
212
|
+
readonly type: "caught-up";
|
|
213
|
+
readonly lastSeq: number;
|
|
214
|
+
}
|
|
215
|
+
| {
|
|
216
|
+
readonly type: "error";
|
|
217
|
+
readonly message: string;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Most JSON characters the object puts in one `restore` message, and the
|
|
221
|
+
* daemon in one `persist` frame (a single larger entry travels alone).
|
|
222
|
+
* Keeps every message well inside WebSocket message limits.
|
|
223
|
+
*/
|
|
224
|
+
declare const MAX_CHUNK_CHARS: number;
|
|
225
|
+
/** Object → daemon. */
|
|
226
|
+
type HostMessage =
|
|
227
|
+
/**
|
|
228
|
+
* Part of the resume state for the next `open` of `generation`. Sent
|
|
229
|
+
* before that `open`, in order, so no single message grows with the
|
|
230
|
+
* session's history.
|
|
231
|
+
*/
|
|
232
|
+
| {
|
|
233
|
+
readonly type: "restore";
|
|
234
|
+
readonly generation: number;
|
|
235
|
+
readonly entries: readonly JsonValue[];
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Open the adapter session. Ignored when the same generation is already
|
|
239
|
+
* open; a different generation closes the open one first.
|
|
240
|
+
*/
|
|
241
|
+
| {
|
|
242
|
+
readonly type: "open";
|
|
243
|
+
readonly generation: number;
|
|
244
|
+
readonly settings: ContainerSettings;
|
|
245
|
+
/**
|
|
246
|
+
* The last of the entries the adapter persisted for this session,
|
|
247
|
+
* after any sent in `restore` messages for this generation.
|
|
248
|
+
*/
|
|
249
|
+
readonly restore: readonly JsonValue[];
|
|
250
|
+
} /** Send every kept frame after `after`, then live frames. */
|
|
251
|
+
| {
|
|
252
|
+
readonly type: "replay";
|
|
253
|
+
readonly after: number;
|
|
254
|
+
} /** Queue an operation. Idempotent on `operationId`. */
|
|
255
|
+
| {
|
|
256
|
+
readonly type: "prompt";
|
|
257
|
+
readonly operationId: string;
|
|
258
|
+
readonly input: ContainerInput;
|
|
259
|
+
readonly whenBusy: ContainerWhenBusy;
|
|
260
|
+
} /** Stop one operation, or every operation of the session. */
|
|
261
|
+
| {
|
|
262
|
+
readonly type: "abort";
|
|
263
|
+
readonly operationId?: string;
|
|
264
|
+
}
|
|
265
|
+
| {
|
|
266
|
+
readonly type: "configure";
|
|
267
|
+
readonly settings: ContainerSettings;
|
|
268
|
+
} /** Frames up to `seq` are stored; the daemon may forget them. */
|
|
269
|
+
| {
|
|
270
|
+
readonly type: "ack";
|
|
271
|
+
readonly seq: number;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Parse one message from the daemon.
|
|
275
|
+
*
|
|
276
|
+
* @param text - The raw WebSocket message.
|
|
277
|
+
* @returns The message, or `undefined` when it is not one.
|
|
278
|
+
*/
|
|
279
|
+
declare function parseDaemonMessage(text: string): DaemonMessage | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Parse one message from the object.
|
|
282
|
+
*
|
|
283
|
+
* @param text - The raw WebSocket message.
|
|
284
|
+
* @returns The message, or `undefined` when it is not one.
|
|
285
|
+
*/
|
|
286
|
+
declare function parseHostMessage(text: string): HostMessage | undefined;
|
|
287
|
+
/**
|
|
288
|
+
* The text of an input, with image parts left out.
|
|
289
|
+
*
|
|
290
|
+
* @param input - A prompt's input.
|
|
291
|
+
* @returns Its text.
|
|
292
|
+
*/
|
|
293
|
+
declare function inputText(input: ContainerInput): string;
|
|
294
|
+
/**
|
|
295
|
+
* Split entries into groups whose JSON stays under `MAX_CHUNK_CHARS`. An
|
|
296
|
+
* entry larger than that is a group of its own.
|
|
297
|
+
*
|
|
298
|
+
* @param entries - The entries, in order.
|
|
299
|
+
* @returns The groups, in order. Empty for no entries.
|
|
300
|
+
*/
|
|
301
|
+
declare function chunkEntries(entries: readonly JsonValue[]): JsonValue[][];
|
|
302
|
+
//#endregion
|
|
303
|
+
export {
|
|
304
|
+
chunkEntries as C,
|
|
305
|
+
parseHostMessage as E,
|
|
306
|
+
MAX_CHUNK_CHARS as S,
|
|
307
|
+
parseDaemonMessage as T,
|
|
308
|
+
DaemonFrame as _,
|
|
309
|
+
CONTAINER_HEALTH_PATH as a,
|
|
310
|
+
HostMessage as b,
|
|
311
|
+
CONTAINER_TOKEN_HEADER as c,
|
|
312
|
+
ContainerInputPart as d,
|
|
313
|
+
ContainerMessage as f,
|
|
314
|
+
ContainerWhenBusy as g,
|
|
315
|
+
ContainerSettings as h,
|
|
316
|
+
CONTAINER_ENV as i,
|
|
317
|
+
ContainerEvent as l,
|
|
318
|
+
ContainerPart as m,
|
|
319
|
+
CLOSE_REPLACED as n,
|
|
320
|
+
CONTAINER_PROTOCOL_VERSION as o,
|
|
321
|
+
ContainerOutcome as p,
|
|
322
|
+
CLOSE_UNAUTHORIZED as r,
|
|
323
|
+
CONTAINER_SESSION_PATH as s,
|
|
324
|
+
AdapterInfo as t,
|
|
325
|
+
ContainerInput as u,
|
|
326
|
+
DaemonMessage as v,
|
|
327
|
+
inputText as w,
|
|
328
|
+
JsonValue as x,
|
|
329
|
+
DaemonOperation as y
|
|
330
|
+
};
|
|
331
|
+
//# sourceMappingURL=protocol-BEgrJYC5.d.ts.map
|