agents 0.33.0 → 0.34.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 +1 -1
- package/dist/{agent-routing-vVMA7m8Y.d.ts → agent-routing-BSoZzNiP.d.ts} +537 -373
- package/dist/agent-routing.d.ts +1 -1
- package/dist/agent-tool-types.d.ts +1 -1
- package/dist/{agent-tools-gGXXkf1z.d.ts → agent-tools-Be-hpRpH.d.ts} +2 -2
- package/dist/agent-tools.d.ts +1 -1
- package/dist/{ai-sdk-Kon40i0q.js → ai-sdk-CRMlEBX7.js} +75 -44
- package/dist/ai-sdk-CRMlEBX7.js.map +1 -0
- package/dist/browser/ai.js +1 -1
- package/dist/browser/index.d.ts +7 -3
- package/dist/browser/index.js +2 -2
- package/dist/browser/tools/ai-sdk.d.ts +68 -3
- package/dist/browser/tools/pi.d.ts +2 -2
- package/dist/browser/tools/tanstack-ai.d.ts +2 -2
- package/dist/{browser-CI97khiJ.d.ts → browser-C9T74n4c.d.ts} +84 -5
- package/dist/{browser-tool-Cxtiwfua.d.ts → browser-tool-DxAYQY9T.d.ts} +2 -2
- package/dist/capability-DBAKc6UZ.js.map +1 -1
- package/dist/{capability-runner-BiVUtjqC.d.ts → capability-runner-uFOdSANC.d.ts} +3 -2
- package/dist/chat/index.d.ts +37 -6
- package/dist/chat/index.js +39 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/chat-sdk/index.js +1 -1
- package/dist/cli.js +64 -63
- package/dist/client-CkT8voRY.js +3740 -0
- package/dist/client-CkT8voRY.js.map +1 -0
- package/dist/{client-eSfgYvd3.d.ts → client-DqS6oequ.d.ts} +2 -2
- package/dist/client.d.ts +1 -1
- package/dist/{connector-Dl098To-.js → connector-Bphz6wIw.js} +16 -4
- package/dist/connector-Bphz6wIw.js.map +1 -0
- package/dist/{conversations-FjHDRZyD.d.ts → conversations-CoAYNW_q.d.ts} +4 -4
- package/dist/{current-agent-CKgT5d1O.d.ts → current-agent-DShbQHDO.d.ts} +24 -3
- package/dist/current-agent-DhoDkSnH.js.map +1 -1
- package/dist/{do-oauth-client-provider-DtNqv7oj.d.ts → do-oauth-client-provider-BsT8-vtd.d.ts} +22 -2
- package/dist/{durable-object-lifecycle-DOI_bzCH.d.ts → durable-object-lifecycle-CRCA6O0W.d.ts} +2 -2
- package/dist/experimental/channels/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.d.ts +2 -2
- package/dist/experimental/channels/web/index.js +1 -1
- package/dist/experimental/webmcp.js +1 -1
- package/dist/{gateway-BFO6vRDn.d.ts → gateway-Dz8zyZBJ.d.ts} +2 -2
- package/dist/harness/ai-sdk/index.d.ts +2 -2
- package/dist/harness/container/index.d.ts +2 -2
- package/dist/harness/container/index.js +1 -1
- package/dist/harness/container/index.js.map +1 -1
- package/dist/harness/opencode/index.d.ts +1 -1
- package/dist/harness/pi/index.d.ts +128 -12
- package/dist/harness/pi/index.js +128 -20
- package/dist/harness/pi/index.js.map +1 -1
- package/dist/harness/think/index.d.ts +2 -2
- package/dist/{images-CfuRCjwq.js → images-D4gtE06D.js} +119 -27
- package/dist/images-D4gtE06D.js.map +1 -0
- package/dist/{index-8k4qsX1T.d.ts → index-BXVgv6tp.d.ts} +4 -4
- package/dist/{index-BEL3ZV-s.d.ts → index-Cs7Ed9la.d.ts} +2 -2
- package/dist/{index-CBt8oRJt.d.ts → index-XiZxauMU.d.ts} +3 -3
- package/dist/index.d.ts +21 -21
- package/dist/index.js +2 -2
- package/dist/{input-schema-0uUu392-.js → input-schema-D6GilRXI.js} +2 -2
- package/dist/{input-schema-0uUu392-.js.map → input-schema-D6GilRXI.js.map} +1 -1
- package/dist/{input-schema-waggtYrH.js → input-schema-y8W5bOdM.js} +2 -2
- package/dist/{input-schema-waggtYrH.js.map → input-schema-y8W5bOdM.js.map} +1 -1
- package/dist/internal_context.d.ts +1 -1
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.js +1 -1
- package/dist/{lifecycle-v1rKHV2C.js → lifecycle-CB5Dmtrt.js} +126 -38
- package/dist/lifecycle-CB5Dmtrt.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 +45 -2
- package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
- package/dist/mcp/client/index.d.ts +42 -36
- package/dist/mcp/client/index.js +2 -2
- package/dist/mcp/client/x402.d.ts +8 -8
- package/dist/mcp/index.d.ts +17 -17
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/models/ai-sdk/index.d.ts +9 -5
- package/dist/models/ai-sdk/index.js +1 -1
- package/dist/models/opencode/index.d.ts +3 -3
- package/dist/models/opencode/index.js +2 -2
- package/dist/models/opencode/index.js.map +1 -1
- package/dist/models/pi-ai/index.d.ts +4 -4
- package/dist/models/pi-ai/index.js +53 -29
- package/dist/models/pi-ai/index.js.map +1 -1
- package/dist/{options-CiIsJHXR.d.ts → options-CiXaymmZ.d.ts} +2 -2
- package/dist/queue/index.d.ts +1 -1
- package/dist/queue/index.js +1 -1
- package/dist/{queue-CcIjVYTE.js → queue-B_wl6K0Z.js} +24 -5
- package/dist/queue-B_wl6K0Z.js.map +1 -0
- package/dist/react.d.ts +2 -2
- package/dist/routing/index.d.ts +2 -2
- package/dist/{scheduler-BCLESHSC.d.ts → scheduler-CTpR0Ct0.d.ts} +2 -2
- package/dist/{scheduler-FIHv2-kJ.js → scheduler-DGNEmxQR.js} +2 -1
- package/dist/scheduler-DGNEmxQR.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-CRY0bGiI.js.map +1 -1
- package/dist/sessions/index.d.ts +1 -1
- package/dist/{settings-Dk2il2Hf.js → settings-D2F_qONv.js} +11 -2
- package/dist/settings-D2F_qONv.js.map +1 -0
- package/dist/{src-DoGNJ4Ud.js → src-BO1FdLK1.js} +145 -86
- package/dist/src-BO1FdLK1.js.map +1 -0
- package/dist/state/index.d.ts +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{streams-vrCtbUIn.d.ts → streams-CAZxZBDg.d.ts} +2 -2
- package/dist/sub-routing.d.ts +12 -12
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/{tasks-BN_5AWqI.js → tasks-Cf_UfEO4.js} +2 -1
- package/dist/{tasks-BN_5AWqI.js.map → tasks-Cf_UfEO4.js.map} +1 -1
- package/dist/{tasks-E89KdwkS.d.ts → tasks-Cs8ilctE.d.ts} +2 -2
- package/dist/{tool-DkT_DJBm.js → tool-CmAGY6Fo.js} +24 -3
- package/dist/tool-CmAGY6Fo.js.map +1 -0
- package/dist/{tool-CxKsvxjm.js → tool-Kxcj8_22.js} +24 -4
- package/dist/tool-Kxcj8_22.js.map +1 -0
- package/dist/{transport-5moD2pW5.d.ts → transport-hV8AW4Bv.d.ts} +45 -12
- package/dist/voice/index.d.ts +2 -2
- package/dist/web/fetch/index.js +1 -1
- package/dist/web/fetch/tools/ai-sdk.js +2 -2
- package/dist/web/fetch/tools/pi.d.ts +5 -0
- package/dist/web/fetch/tools/pi.js +25 -2
- package/dist/web/fetch/tools/pi.js.map +1 -1
- package/dist/web/fetch/tools/tanstack-ai.js +2 -2
- package/dist/web/search/index.js +1 -1
- package/dist/web/search/tools/ai-sdk.js +2 -2
- package/dist/web/search/tools/pi.d.ts +4 -0
- package/dist/web/search/tools/pi.js +23 -2
- package/dist/web/search/tools/pi.js.map +1 -1
- package/dist/web/search/tools/tanstack-ai.js +2 -2
- package/dist/websockets/index.d.ts +2 -2
- package/dist/websockets/index.js +1 -1
- package/dist/{websockets-C6SJtWCJ.js → websockets-W4uhRg4-.js} +68 -5
- package/dist/websockets-W4uhRg4-.js.map +1 -0
- package/dist/workflow-types.d.ts +1 -1
- package/dist/workflows.d.ts +1 -1
- package/docs/agent-class.md +30 -4
- package/docs/browse-the-web.md +14 -0
- package/docs/chat-agents.md +13 -10
- package/docs/client-tools-continuation.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/configuration.md +6 -3
- package/docs/cross-domain-authentication.md +1 -1
- package/docs/fetch-the-web.md +20 -0
- package/docs/harnesses/pi.md +211 -22
- package/docs/harnesses/think.md +1 -1
- package/docs/http-websockets.md +40 -32
- package/docs/human-in-the-loop.md +2 -2
- package/docs/lifecycle.md +56 -0
- package/docs/mcp-client.md +104 -7
- package/docs/models-pi-ai.md +24 -10
- package/docs/models.md +42 -17
- package/docs/resumable-streaming.md +1 -1
- package/docs/retries.md +3 -6
- package/docs/search-the-web.md +10 -0
- package/docs/voice.md +1 -1
- package/package.json +13 -12
- package/dist/ai-sdk-CpuRsjP5.d.ts +0 -72
- package/dist/ai-sdk-Kon40i0q.js.map +0 -1
- package/dist/client-DMWujQJ1.js +0 -2325
- package/dist/client-DMWujQJ1.js.map +0 -1
- package/dist/connector-Dl098To-.js.map +0 -1
- package/dist/images-CfuRCjwq.js.map +0 -1
- package/dist/lifecycle-v1rKHV2C.js.map +0 -1
- package/dist/queue-CcIjVYTE.js.map +0 -1
- package/dist/scheduler-FIHv2-kJ.js.map +0 -1
- package/dist/settings-Dk2il2Hf.js.map +0 -1
- package/dist/src-DoGNJ4Ud.js.map +0 -1
- package/dist/tool-CxKsvxjm.js.map +0 -1
- package/dist/tool-DkT_DJBm.js.map +0 -1
- package/dist/websockets-C6SJtWCJ.js.map +0 -1
|
@@ -6,13 +6,77 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
T as BrowserSource,
|
|
8
8
|
b as BrowserNewTab
|
|
9
|
-
} from "../../browser-
|
|
9
|
+
} from "../../browser-C9T74n4c.js";
|
|
10
10
|
import {
|
|
11
11
|
n as BrowserToolOptions,
|
|
12
12
|
r as BrowserToolOutput,
|
|
13
13
|
t as BrowserToolInput
|
|
14
|
-
} from "../../browser-tool-
|
|
15
|
-
import {
|
|
14
|
+
} from "../../browser-tool-DxAYQY9T.js";
|
|
15
|
+
import { FlexibleSchema, JSONValue } from "ai";
|
|
16
|
+
|
|
17
|
+
//#region src/browser/tool-helpers.d.ts
|
|
18
|
+
/** What the model sees in place of a browser tool's output. */
|
|
19
|
+
type BrowserModelOutput =
|
|
20
|
+
| {
|
|
21
|
+
type: "text";
|
|
22
|
+
value: string;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: "json";
|
|
26
|
+
value: JSONValue;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/browser/tools/ai-sdk.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* The AI SDK tool {@link browserTool} returns. Assignable to the AI SDK's
|
|
32
|
+
* `Tool`, and `execute` / `toModelOutput` are always present.
|
|
33
|
+
*/
|
|
34
|
+
interface BrowserTool {
|
|
35
|
+
description: string;
|
|
36
|
+
inputSchema: FlexibleSchema<BrowserToolInput>;
|
|
37
|
+
execute(
|
|
38
|
+
input: BrowserToolInput,
|
|
39
|
+
options: unknown
|
|
40
|
+
): Promise<BrowserToolOutput>;
|
|
41
|
+
toModelOutput(options: { output: BrowserToolOutput }): BrowserModelOutput;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create an AI SDK tool that lets the model drive a persistent browser with
|
|
45
|
+
* JavaScript and the Chrome DevTools Protocol.
|
|
46
|
+
*
|
|
47
|
+
* The browser outlives each run: tabs, cookies, and logins carry over. The
|
|
48
|
+
* model never starts, closes, or resets it, and `sessionId: "active"`
|
|
49
|
+
* addresses the tab it last worked in. If the browser had to be replaced
|
|
50
|
+
* (it expired or was closed), the code still runs in the new browser and the
|
|
51
|
+
* result's `notice` says so.
|
|
52
|
+
*
|
|
53
|
+
* Browser Run only (Chromium). Guardrails, `keepAliveMs`, and recording are
|
|
54
|
+
* set on the `Browser`'s provider.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { Browser, browserRun } from "agents/browser";
|
|
59
|
+
* import { browserTool } from "agents/browser/ai-sdk";
|
|
60
|
+
*
|
|
61
|
+
* export class MyAgent extends Agent<Env> {
|
|
62
|
+
* browser = new Browser({ provider: browserRun(this.env.BROWSER) });
|
|
63
|
+
*
|
|
64
|
+
* constructor(ctx: AgentContext, env: Env) {
|
|
65
|
+
* super(ctx, env);
|
|
66
|
+
* this.lifecycle.use(this.browser);
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* async onChatMessage() {
|
|
70
|
+
* const tools = {
|
|
71
|
+
* browser: browserTool({ browser: this.browser, loader: this.env.LOADER })
|
|
72
|
+
* };
|
|
73
|
+
* // …pass `tools` to streamText / generateText
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
declare function browserTool(options: BrowserToolOptions): BrowserTool;
|
|
79
|
+
//#endregion
|
|
16
80
|
export {
|
|
17
81
|
type BrowserNewTab,
|
|
18
82
|
type BrowserSource,
|
|
@@ -25,3 +89,4 @@ export {
|
|
|
25
89
|
browserTool,
|
|
26
90
|
createQuickActionTools
|
|
27
91
|
};
|
|
92
|
+
//# sourceMappingURL=ai-sdk.d.ts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
T as BrowserSource,
|
|
3
3
|
b as BrowserNewTab
|
|
4
|
-
} from "../../browser-
|
|
4
|
+
} from "../../browser-C9T74n4c.js";
|
|
5
5
|
import {
|
|
6
6
|
n as BrowserToolOptions,
|
|
7
7
|
r as BrowserToolOutput,
|
|
8
8
|
t as BrowserToolInput
|
|
9
|
-
} from "../../browser-tool-
|
|
9
|
+
} from "../../browser-tool-DxAYQY9T.js";
|
|
10
10
|
import { ToolExecutionApi, ToolRegistration } from "@earendil-works/pi-durable";
|
|
11
11
|
|
|
12
12
|
//#region src/browser/tools/pi.d.ts
|
|
@@ -2,12 +2,12 @@ import { n as CreateBrowserToolsOptions } from "../../ai-CDn3Abax.js";
|
|
|
2
2
|
import {
|
|
3
3
|
T as BrowserSource,
|
|
4
4
|
b as BrowserNewTab
|
|
5
|
-
} from "../../browser-
|
|
5
|
+
} from "../../browser-C9T74n4c.js";
|
|
6
6
|
import {
|
|
7
7
|
n as BrowserToolOptions,
|
|
8
8
|
r as BrowserToolOutput,
|
|
9
9
|
t as BrowserToolInput
|
|
10
|
-
} from "../../browser-tool-
|
|
10
|
+
} from "../../browser-tool-DxAYQY9T.js";
|
|
11
11
|
import { SchemaInput, ServerTool } from "@tanstack/ai";
|
|
12
12
|
|
|
13
13
|
//#region src/browser/tanstack-ai.d.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
d as LifecycleRouteContext,
|
|
3
3
|
s as LifecycleCapability
|
|
4
|
-
} from "./capability-runner-
|
|
4
|
+
} from "./capability-runner-uFOdSANC.js";
|
|
5
5
|
import {
|
|
6
6
|
n as InternalHostInfo,
|
|
7
7
|
r as InternalHostMessage,
|
|
@@ -17,6 +17,70 @@ import {
|
|
|
17
17
|
} from "./session-store-B7Ca-u1t.js";
|
|
18
18
|
|
|
19
19
|
//#region src/browser/spec.d.ts
|
|
20
|
+
/** A parameter, return value, or type property in the raw protocol. */
|
|
21
|
+
interface RawCdpField {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
optional?: boolean;
|
|
25
|
+
experimental?: boolean;
|
|
26
|
+
deprecated?: boolean;
|
|
27
|
+
type?: string;
|
|
28
|
+
$ref?: string;
|
|
29
|
+
enum?: string[];
|
|
30
|
+
items?: {
|
|
31
|
+
type?: string;
|
|
32
|
+
$ref?: string;
|
|
33
|
+
enum?: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface RawCdpCommand {
|
|
37
|
+
name: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
experimental?: boolean;
|
|
40
|
+
deprecated?: boolean;
|
|
41
|
+
parameters?: RawCdpField[];
|
|
42
|
+
returns?: RawCdpField[];
|
|
43
|
+
}
|
|
44
|
+
interface RawCdpEvent {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
experimental?: boolean;
|
|
48
|
+
deprecated?: boolean;
|
|
49
|
+
parameters?: RawCdpField[];
|
|
50
|
+
}
|
|
51
|
+
interface RawCdpType {
|
|
52
|
+
id: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
experimental?: boolean;
|
|
55
|
+
deprecated?: boolean;
|
|
56
|
+
type?: string;
|
|
57
|
+
enum?: string[];
|
|
58
|
+
properties?: RawCdpField[];
|
|
59
|
+
items?: {
|
|
60
|
+
type?: string;
|
|
61
|
+
$ref?: string;
|
|
62
|
+
enum?: string[];
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Raw CDP protocol domain from `/json/protocol` */
|
|
66
|
+
interface RawCdpDomain {
|
|
67
|
+
domain: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
experimental?: boolean;
|
|
70
|
+
deprecated?: boolean;
|
|
71
|
+
commands?: RawCdpCommand[];
|
|
72
|
+
events?: RawCdpEvent[];
|
|
73
|
+
types?: RawCdpType[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The raw Chrome DevTools Protocol: the JSON Chrome serves at
|
|
77
|
+
* `/json/protocol` and publishes as `browser_protocol.json` and
|
|
78
|
+
* `js_protocol.json`. Other top-level fields, such as `version`, are allowed
|
|
79
|
+
* and ignored. `normalizeCdpSpec` turns it into a `SearchableCdpSpec`.
|
|
80
|
+
*/
|
|
81
|
+
interface RawCdpProtocol {
|
|
82
|
+
domains?: RawCdpDomain[];
|
|
83
|
+
}
|
|
20
84
|
/**
|
|
21
85
|
* The element type of an array field or type. `$ref` is always
|
|
22
86
|
* domain-qualified (`"Network.Cookie"`), matching a type's `name`.
|
|
@@ -91,6 +155,19 @@ interface CdpSpecSource {
|
|
|
91
155
|
*/
|
|
92
156
|
sessionId?: string;
|
|
93
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Normalize Chrome's raw protocol JSON into the spec a `BrowserSource`
|
|
160
|
+
* connection's `spec()` returns (a `SearchableCdpSpec`): every `$ref`
|
|
161
|
+
* domain-qualified (`"Page.FrameId"`), commands with `method`, events with
|
|
162
|
+
* `event`, types with `name`, and empty arrays where the protocol omits them.
|
|
163
|
+
*
|
|
164
|
+
* Use it for a source that has no `/json/protocol` endpoint or Browser Run
|
|
165
|
+
* binding for `loadCdpSpec`. Chrome publishes the protocol in two files,
|
|
166
|
+
* `browser_protocol.json` and `js_protocol.json`; merge their `domains` into
|
|
167
|
+
* one object before calling. Unlike `loadCdpSpec`, the spec is not cached, so
|
|
168
|
+
* keep it yourself (for example in a module-level constant).
|
|
169
|
+
*/
|
|
170
|
+
declare function normalizeCdpSpec(protocol: RawCdpProtocol): SearchableCdpSpec;
|
|
94
171
|
/** Load the (cached) searchable CDP spec for a browser source. */
|
|
95
172
|
declare function loadCdpSpec(source: CdpSpecSource): Promise<SearchableCdpSpec>;
|
|
96
173
|
//#endregion
|
|
@@ -112,7 +189,7 @@ interface BrowserSource {
|
|
|
112
189
|
* The browser's internal hostnames, when it has any. The docs list them,
|
|
113
190
|
* and {@link BrowserSession.functions} adds the hosts functions.
|
|
114
191
|
*/
|
|
115
|
-
readonly internalHosts?: BrowserInternalHosts;
|
|
192
|
+
readonly internalHosts?: BrowserInternalHosts | undefined;
|
|
116
193
|
}
|
|
117
194
|
interface BrowserSessionOptions {
|
|
118
195
|
/**
|
|
@@ -633,10 +710,11 @@ declare class Browser extends LifecycleCapability {
|
|
|
633
710
|
}
|
|
634
711
|
//#endregion
|
|
635
712
|
export {
|
|
636
|
-
|
|
713
|
+
SearchableCdpSpec as A,
|
|
637
714
|
BrowserSessionOptions as C,
|
|
638
715
|
CdpItems as D,
|
|
639
716
|
CdpField as E,
|
|
717
|
+
normalizeCdpSpec as M,
|
|
640
718
|
CdpSpecSource as O,
|
|
641
719
|
BrowserSession as S,
|
|
642
720
|
BrowserSource as T,
|
|
@@ -649,7 +727,8 @@ export {
|
|
|
649
727
|
ACTIVE_PAGE_SESSION as g,
|
|
650
728
|
BrowserFunctionDocs as h,
|
|
651
729
|
BrowserInternalHosts as i,
|
|
652
|
-
|
|
730
|
+
loadCdpSpec as j,
|
|
731
|
+
RawCdpProtocol as k,
|
|
653
732
|
DEFAULT_BROWSER_SCOPE as l,
|
|
654
733
|
BrowserFunction as m,
|
|
655
734
|
BrowserConnectOptions as n,
|
|
@@ -664,4 +743,4 @@ export {
|
|
|
664
743
|
BrowserSendInput as x,
|
|
665
744
|
BrowserLockOptions as y
|
|
666
745
|
};
|
|
667
|
-
//# sourceMappingURL=browser-
|
|
746
|
+
//# sourceMappingURL=browser-C9T74n4c.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as BrowserSource } from "./browser-
|
|
1
|
+
import { T as BrowserSource } from "./browser-C9T74n4c.js";
|
|
2
2
|
|
|
3
3
|
//#region src/browser/browser-tool.d.ts
|
|
4
4
|
interface BrowserToolOptions {
|
|
@@ -68,4 +68,4 @@ export {
|
|
|
68
68
|
BrowserToolOutput as r,
|
|
69
69
|
BrowserToolInput as t
|
|
70
70
|
};
|
|
71
|
-
//# sourceMappingURL=browser-tool-
|
|
71
|
+
//# sourceMappingURL=browser-tool-DxAYQY9T.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-DBAKc6UZ.js","names":[],"sources":["../src/lifecycle/capability.ts"],"sourcesContent":["import type {\n CapabilityStartContext,\n DurableObjectCapability\n} from \"./capability-runner\";\nimport type { Connection } from \"./types\";\nimport type { LifecycleJobs } from \"./job-queue\";\n\n/** Opaque address understood by a Lifecycle routing transport. */\nexport type LifecycleRouteAddress = {\n /** Stable equality and storage key. */\n readonly key: string;\n /** Transport-owned serialized address. */\n readonly data: string;\n};\n\n/** Context supplied with a routed capability message. */\nexport type LifecycleRouteContext = {\n /** Address of the sending Lifecycle, or undefined for an unrouted root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Capability-owned message payload. */\n readonly payload: unknown;\n};\n\n/** Startup state of a Lifecycle. */\nexport type LifecycleStatus = \"zero\" | \"starting\" | \"started\";\n\n/** Best-effort telemetry available to every Lifecycle capability. */\nexport type LifecycleEvents = {\n /** Publish an event under this capability's stable identity. */\n readonly emit: (type: string, payload: unknown) => void;\n};\n\n/** Routing available to every Lifecycle capability. */\nexport type LifecycleRoutes = {\n /** This Lifecycle's transport address, or undefined at the route root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Route a capability-owned message to the root Lifecycle. */\n readonly toRoot: (payload: unknown) => Promise<unknown>;\n /** Route a capability-owned message to another Lifecycle. */\n readonly to: (\n target: LifecycleRouteAddress,\n payload: unknown\n ) => Promise<unknown>;\n};\n\n/**\n * Ambient scope a capability supplies when entering host context on\n * behalf of a live connection or request.\n */\nexport type LifecycleHostContextScope = {\n /** The connection the callback runs on behalf of, when there is one. */\n readonly connection?: Connection;\n /** The request the callback runs on behalf of, when there is one. */\n readonly request?: Request;\n};\n\n/**\n * The platform's hibernatable-socket surface, exposed narrowly so a\n * capability that owns connections (e.g. WebSockets) can accept and\n * enumerate them without holding the whole `DurableObjectState`.\n * These are workerd API names, not Lifecycle modeling sockets.\n */\nexport type LifecycleSockets = {\n /** Accept a socket into hibernation under the given tags. */\n readonly accept: (ws: WebSocket, tags: string[]) => void;\n /** Every hibernated socket on the object, optionally by tag. */\n readonly get: (tag?: string) => WebSocket[];\n};\n\n/**\n * Standard services granted to every installed Lifecycle capability.\n */\nexport type LifecycleServices = {\n /** The host's Durable Object name; see `Lifecycle.name`. */\n readonly name: string;\n /** The host class name, as exported from the Worker. */\n readonly className: string;\n readonly storage: DurableObjectStorage;\n readonly sockets: LifecycleSockets;\n /**\n * Resolve once Lifecycle startup has finished, starting it if needed, and\n * reject if that startup fails. Calls made from inside startup resolve\n * immediately.\n *\n * Await it first in any operation that can run before startup and starts\n * work `onStart` also awaits, such as lazily opening a store. Native RPC\n * bypasses the automatic startup on fetch, alarm and WebSocket events, so\n * such an operation can begin that work outside startup. `onStart` then\n * awaits it while startup holds the input gate (`blockConcurrencyWhile`),\n * which holds back the work's timers and I/O, and startup times out after\n * 30 seconds and resets the object.\n */\n readonly ready: () => Promise<void>;\n /**\n * Startup state: `\"zero\"` before startup, `\"starting\"` while capability\n * and host startup hooks run, `\"started\"` once `ready()` resolves without\n * waiting.\n */\n readonly status: () => LifecycleStatus;\n /**\n * This capability's scoped access to the Lifecycle-owned work queue.\n * Pushed items are dispatched to `onJob` when due; every queue mutation\n * re-arms the physical alarm automatically.\n */\n readonly jobs: LifecycleJobs;\n /**\n * Keep work this capability hands off at a bounded `onJob` return inside\n * the current alarm's memory-limit breaker domain (#1825). Returns false,\n * tracking nothing, outside an alarm invocation.\n */\n readonly trackAlarmWork: (work: Promise<unknown>) => boolean;\n /**\n * Run a capability-held user callback inside the host invocation context.\n * Capability hooks run outside host context; this is the one boundary for\n * entering it, and a host composition root may substitute its own wrapper\n * (Agent adds tracing span scope). Pass `scope` to make a live\n * connection or request ambient for the callback.\n */\n readonly runInHostContext: (\n fn: () => unknown,\n scope?: LifecycleHostContextScope\n ) => Promise<unknown>;\n readonly events: LifecycleEvents;\n readonly routes: LifecycleRoutes;\n};\n\nconst installedServices = new WeakMap<object, LifecycleServices>();\n\n/**\n * Base class for capabilities that consume standard Lifecycle services.\n */\nexport abstract class LifecycleCapability<Props extends object = object> {\n readonly capabilityId: string;\n\n /** How this capability claims traffic; see {@link DurableObjectCapability.claims}. */\n readonly claims: \"selective\" | \"catch-all\" = \"selective\";\n\n protected constructor(capabilityId: string) {\n if (capabilityId.trim() === \"\") {\n throw new Error(\"Lifecycle capability IDs must be non-empty\");\n }\n this.capabilityId = capabilityId;\n }\n\n /** Default startup hook; capabilities override when they own startup work. */\n onStart(_context: CapabilityStartContext<Props>): void {}\n\n /** Standard services when installed, or undefined in isolated unit tests. */\n protected get lifecycleServices(): LifecycleServices | undefined {\n return installedServices.get(this);\n }\n\n /** Standard services supplied when Lifecycle installs this capability. */\n protected get lifecycle(): LifecycleServices {\n const services = this.lifecycleServices;\n if (!services) {\n throw new Error(\n `${this.constructor.name} must be installed with Lifecycle.use() before use`\n );\n }\n return services;\n }\n}\n\n/**\n * @internal Bind the standard service surface to one capability instance.\n * `Lifecycle.use()` calls this during installation. Test a capability by\n * installing it on a minimal Durable Object with a real Lifecycle rather\n * than binding fake services.\n */\nexport function bindLifecycleCapability(\n capability: LifecycleCapability,\n services: LifecycleServices\n): void {\n installedServices.set(capability, services);\n}\n\n/** @internal Read a capability ID without exposing installation internals. */\nexport function lifecycleCapabilityId(\n capability: DurableObjectCapability\n): string | undefined {\n return capability instanceof LifecycleCapability\n ? capability.capabilityId\n : undefined;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"capability-DBAKc6UZ.js","names":[],"sources":["../src/lifecycle/capability.ts"],"sourcesContent":["import type {\n CapabilityStartContext,\n DurableObjectCapability\n} from \"./capability-runner\";\nimport type { Connection } from \"./types\";\nimport type { LifecycleJobs } from \"./job-queue\";\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/** Opaque address understood by a Lifecycle routing transport. */\nexport type LifecycleRouteAddress = {\n /** Stable equality and storage key. */\n readonly key: string;\n /** Transport-owned serialized address. */\n readonly data: string;\n};\n\n/** Context supplied with a routed capability message. */\nexport type LifecycleRouteContext = {\n /** Address of the sending Lifecycle, or undefined for an unrouted root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Capability-owned message payload. */\n readonly payload: unknown;\n};\n\n/** Startup state of a Lifecycle. */\nexport type LifecycleStatus = \"zero\" | \"starting\" | \"started\";\n\n/** Best-effort telemetry available to every Lifecycle capability. */\nexport type LifecycleEvents = {\n /** Publish an event under this capability's stable identity. */\n readonly emit: (type: string, payload: unknown) => void;\n};\n\n/** Routing available to every Lifecycle capability. */\nexport type LifecycleRoutes = {\n /** This Lifecycle's transport address, or undefined at the route root. */\n readonly source: LifecycleRouteAddress | undefined;\n /** Route a capability-owned message to the root Lifecycle. */\n readonly toRoot: (payload: unknown) => Promise<unknown>;\n /** Route a capability-owned message to another Lifecycle. */\n readonly to: (\n target: LifecycleRouteAddress,\n payload: unknown\n ) => Promise<unknown>;\n};\n\n/**\n * Ambient scope a capability supplies when entering host context on\n * behalf of a live connection or request.\n */\nexport type LifecycleHostContextScope = {\n /** The connection the callback runs on behalf of, when there is one. */\n readonly connection?: Connection;\n /** The request the callback runs on behalf of, when there is one. */\n readonly request?: Request;\n};\n\n/**\n * The platform's hibernatable-socket surface, exposed narrowly so a\n * capability that owns connections (e.g. WebSockets) can accept and\n * enumerate them without holding the whole `DurableObjectState`.\n * These are workerd API names, not Lifecycle modeling sockets.\n */\nexport type LifecycleSockets = {\n /** Accept a socket into hibernation under the given tags. */\n readonly accept: (ws: WebSocket, tags: string[]) => void;\n /** Every hibernated socket on the object, optionally by tag. */\n readonly get: (tag?: string) => WebSocket[];\n};\n\n/**\n * Standard services granted to every installed Lifecycle capability.\n */\nexport type LifecycleServices = {\n /** The host's Durable Object name; see `Lifecycle.name`. */\n readonly name: string;\n /** The host class name, as exported from the Worker. */\n readonly className: string;\n readonly storage: DurableObjectStorage;\n readonly sockets: LifecycleSockets;\n /**\n * Resolve once Lifecycle startup has finished, starting it if needed, and\n * reject if that startup fails. Calls made from inside startup resolve\n * immediately.\n *\n * Await it first in any operation that can run before startup and starts\n * work `onStart` also awaits, such as lazily opening a store. Native RPC\n * bypasses the automatic startup on fetch, alarm and WebSocket events, so\n * such an operation can begin that work outside startup. `onStart` then\n * awaits it while startup holds the input gate (`blockConcurrencyWhile`),\n * which holds back the work's timers and I/O, and startup times out after\n * 30 seconds and resets the object.\n */\n readonly ready: () => Promise<void>;\n /**\n * Startup state: `\"zero\"` before startup, `\"starting\"` while capability\n * and host startup hooks run, `\"started\"` once `ready()` resolves without\n * waiting.\n */\n readonly status: () => LifecycleStatus;\n /**\n * This capability's scoped access to the Lifecycle-owned work queue.\n * Pushed items are dispatched to `onJob` when due; every queue mutation\n * re-arms the physical alarm automatically.\n */\n readonly jobs: LifecycleJobs;\n /**\n * Keep work this capability hands off at a bounded `onJob` return inside\n * the current alarm's memory-limit breaker domain (#1825). Returns false,\n * tracking nothing, outside an alarm invocation.\n */\n readonly trackAlarmWork: (work: Promise<unknown>) => boolean;\n /**\n * Run a capability-held user callback inside the host invocation context.\n * Capability hooks run outside host context; this is the one boundary for\n * entering it, and a host composition root may substitute its own wrapper\n * (Agent adds tracing span scope). Pass `scope` to make a live\n * connection or request ambient for the callback.\n */\n readonly runInHostContext: (\n fn: () => unknown,\n scope?: LifecycleHostContextScope\n ) => Promise<unknown>;\n readonly events: LifecycleEvents;\n readonly routes: LifecycleRoutes;\n};\n\nconst installedServices = new WeakMap<object, LifecycleServices>();\n\n/**\n * Base class for capabilities that consume standard Lifecycle services.\n */\nexport abstract class LifecycleCapability<Props extends object = object> {\n readonly capabilityId: string;\n\n /** How this capability claims traffic; see {@link DurableObjectCapability.claims}. */\n readonly claims: \"selective\" | \"catch-all\" = \"selective\";\n\n protected constructor(capabilityId: string) {\n if (capabilityId.trim() === \"\") {\n throw new Error(\"Lifecycle capability IDs must be non-empty\");\n }\n this.capabilityId = capabilityId;\n }\n\n /** Default startup hook; capabilities override when they own startup work. */\n onStart(_context: CapabilityStartContext<Props>): MaybePromise<void> {}\n\n /** Standard services when installed, or undefined in isolated unit tests. */\n protected get lifecycleServices(): LifecycleServices | undefined {\n return installedServices.get(this);\n }\n\n /** Standard services supplied when Lifecycle installs this capability. */\n protected get lifecycle(): LifecycleServices {\n const services = this.lifecycleServices;\n if (!services) {\n throw new Error(\n `${this.constructor.name} must be installed with Lifecycle.use() before use`\n );\n }\n return services;\n }\n}\n\n/**\n * @internal Bind the standard service surface to one capability instance.\n * `Lifecycle.use()` calls this during installation. Test a capability by\n * installing it on a minimal Durable Object with a real Lifecycle rather\n * than binding fake services.\n */\nexport function bindLifecycleCapability(\n capability: LifecycleCapability,\n services: LifecycleServices\n): void {\n installedServices.set(capability, services);\n}\n\n/** @internal Read a capability ID without exposing installation internals. */\nexport function lifecycleCapabilityId(\n capability: DurableObjectCapability\n): string | undefined {\n return capability instanceof LifecycleCapability\n ? capability.capabilityId\n : undefined;\n}\n"],"mappings":";AAgIA,MAAM,oCAAoB,IAAI,QAAmC;;;;AAKjE,IAAsB,sBAAtB,MAAyE;CAMvE,YAAsB,cAAsB;EAF5C,KAAS,SAAoC;EAG3C,IAAI,aAAa,KAAK,MAAM,IAC1B,MAAM,IAAI,MAAM,4CAA4C;EAE9D,KAAK,eAAe;CACtB;;CAGA,QAAQ,UAA6D,CAAC;;CAGtE,IAAc,oBAAmD;EAC/D,OAAO,kBAAkB,IAAI,IAAI;CACnC;;CAGA,IAAc,YAA+B;EAC3C,MAAM,WAAW,KAAK;EACtB,IAAI,CAAC,UACH,MAAM,IAAI,MACR,GAAG,KAAK,YAAY,KAAK,mDAC3B;EAEF,OAAO;CACT;AACF;;;;;;;AAQA,SAAgB,wBACd,YACA,UACM;CACN,kBAAkB,IAAI,YAAY,QAAQ;AAC5C;;AAGA,SAAgB,sBACd,YACoB;CACpB,OAAO,sBAAsB,sBACzB,WAAW,eACX,KAAA;AACN"}
|
|
@@ -162,6 +162,7 @@ type LifecycleJobs = {
|
|
|
162
162
|
};
|
|
163
163
|
//#endregion
|
|
164
164
|
//#region src/lifecycle/capability.d.ts
|
|
165
|
+
type MaybePromise$1<T> = T | Promise<T>;
|
|
165
166
|
/** Opaque address understood by a Lifecycle routing transport. */
|
|
166
167
|
type LifecycleRouteAddress = {
|
|
167
168
|
/** Stable equality and storage key. */ readonly key: string /** Transport-owned serialized address. */;
|
|
@@ -280,7 +281,7 @@ declare abstract class LifecycleCapability<Props extends object = object> {
|
|
|
280
281
|
readonly claims: "selective" | "catch-all";
|
|
281
282
|
protected constructor(capabilityId: string);
|
|
282
283
|
/** Default startup hook; capabilities override when they own startup work. */
|
|
283
|
-
onStart(_context: CapabilityStartContext<Props>): void
|
|
284
|
+
onStart(_context: CapabilityStartContext<Props>): MaybePromise$1<void>;
|
|
284
285
|
/** Standard services when installed, or undefined in isolated unit tests. */
|
|
285
286
|
protected get lifecycleServices(): LifecycleServices | undefined;
|
|
286
287
|
/** Standard services supplied when Lifecycle installs this capability. */
|
|
@@ -488,4 +489,4 @@ export {
|
|
|
488
489
|
Connection as x,
|
|
489
490
|
LifecycleJobPushOptions as y
|
|
490
491
|
};
|
|
491
|
-
//# sourceMappingURL=capability-runner-
|
|
492
|
+
//# sourceMappingURL=capability-runner-uFOdSANC.d.ts.map
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
_ as FiberRecoveryContext$1,
|
|
10
10
|
at as isPositionlessAgentToolChunk,
|
|
11
11
|
z as AgentToolEventState
|
|
12
|
-
} from "../agent-routing-
|
|
13
|
-
import { _ as TaskStep, m as TaskRunOptions } from "../tasks-
|
|
12
|
+
} from "../agent-routing-BSoZzNiP.js";
|
|
13
|
+
import { _ as TaskStep, m as TaskRunOptions } from "../tasks-Cs8ilctE.js";
|
|
14
14
|
import {
|
|
15
15
|
n as ClientToolSchema,
|
|
16
16
|
r as createToolsFromClientSchemas,
|
|
17
17
|
t as ClientToolExecutor
|
|
18
18
|
} from "../client-tools-aIBO0Fk7.js";
|
|
19
|
-
import { n as Streams } from "../streams-
|
|
19
|
+
import { n as Streams } from "../streams-CAZxZBDg.js";
|
|
20
20
|
import {
|
|
21
21
|
a as CHAT_MESSAGE_TYPES,
|
|
22
22
|
i as OutgoingMessage,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
r as AgentToolProgressEmitResult,
|
|
35
35
|
s as interceptAgentToolBroadcast,
|
|
36
36
|
t as AgentToolBroadcastHooks
|
|
37
|
-
} from "../agent-tools-
|
|
37
|
+
} from "../agent-tools-Be-hpRpH.js";
|
|
38
38
|
import { l as SessionMessage } from "../types-B7LojTe4.js";
|
|
39
39
|
import { ModelMessage, UIMessage } from "ai";
|
|
40
40
|
import { Connection, FiberRecoveryContext } from "agents";
|
|
@@ -354,9 +354,16 @@ declare class TurnQueue {
|
|
|
354
354
|
private _queue;
|
|
355
355
|
private _generation;
|
|
356
356
|
private _activeRequestId;
|
|
357
|
+
private _activeGeneration;
|
|
357
358
|
private _countsByGeneration;
|
|
358
359
|
get generation(): number;
|
|
359
360
|
get activeRequestId(): string | null;
|
|
361
|
+
/**
|
|
362
|
+
* The generation the active turn was admitted under, or `null` when no turn
|
|
363
|
+
* is active. A turn whose generation is older than {@link generation} was
|
|
364
|
+
* invalidated by a {@link reset} while it ran.
|
|
365
|
+
*/
|
|
366
|
+
get activeGeneration(): number | null;
|
|
360
367
|
get isActive(): boolean;
|
|
361
368
|
enqueue<T>(
|
|
362
369
|
requestId: string,
|
|
@@ -1020,6 +1027,7 @@ declare class ResumableStream {
|
|
|
1020
1027
|
options?: {
|
|
1021
1028
|
messageId?: string;
|
|
1022
1029
|
parentMessageId?: string;
|
|
1030
|
+
basePartCount?: number;
|
|
1023
1031
|
continuation?: boolean;
|
|
1024
1032
|
originMessageIds?: string[];
|
|
1025
1033
|
}
|
|
@@ -1033,6 +1041,11 @@ declare class ResumableStream {
|
|
|
1033
1041
|
* predates message-id tracking.
|
|
1034
1042
|
*/
|
|
1035
1043
|
getStreamMessageId(streamId: string): string | null;
|
|
1044
|
+
/**
|
|
1045
|
+
* How many parts the message an orphaned stream extends held when the
|
|
1046
|
+
* stream started, or null when the stream produces a message of its own.
|
|
1047
|
+
*/
|
|
1048
|
+
getStreamBasePartCount(streamId: string): number | null;
|
|
1036
1049
|
/**
|
|
1037
1050
|
* The message an orphaned stream's assistant message is a child of, or null
|
|
1038
1051
|
* when the stream appends to the latest leaf or predates parent tracking.
|
|
@@ -3402,9 +3415,27 @@ interface PersistReconstructedOrphanOptions<
|
|
|
3402
3415
|
/**
|
|
3403
3416
|
* Id for the reconstructed message when the stream carried no provider
|
|
3404
3417
|
* `start.messageId` to adopt. The accumulator still adopts a provider id when
|
|
3405
|
-
* present.
|
|
3418
|
+
* present. Unused when `continues` is set.
|
|
3406
3419
|
*/
|
|
3407
3420
|
fallbackId: string;
|
|
3421
|
+
/**
|
|
3422
|
+
* Set when the stream continued an existing message that held
|
|
3423
|
+
* `basePartCount` parts when the stream started. The chunks are replayed
|
|
3424
|
+
* onto that message's first `basePartCount` parts and its metadata in
|
|
3425
|
+
* continuation mode, as the live accumulator does: the result keeps
|
|
3426
|
+
* `messageId` (a provider `start.messageId` is ignored) and the earlier
|
|
3427
|
+
* parts, and persisting the same stream again rewrites the message rather
|
|
3428
|
+
* than appending a copy. When the message no longer exists it was deleted
|
|
3429
|
+
* (a continuation only starts from a stored message), so nothing is written:
|
|
3430
|
+
* the stream is not resurrected as a message of its own.
|
|
3431
|
+
*/
|
|
3432
|
+
continues?: {
|
|
3433
|
+
messageId: string;
|
|
3434
|
+
basePartCount: number /** Map each kept earlier part, e.g. close a part left streaming. */;
|
|
3435
|
+
settleBasePart?: (
|
|
3436
|
+
part: TMessage["parts"][number]
|
|
3437
|
+
) => TMessage["parts"][number];
|
|
3438
|
+
};
|
|
3408
3439
|
/**
|
|
3409
3440
|
* Finalize the reconstructed message before upsert — e.g. strip internal
|
|
3410
3441
|
* parts or resolve the persist-target id. Return `null` to skip persistence
|
|
@@ -3421,7 +3452,7 @@ interface PersistReconstructedOrphanOptions<
|
|
|
3421
3452
|
* Reconstruct a message from `chunks` and upsert it via the store. Returns
|
|
3422
3453
|
* `true` when a write happened (so a caller that broadcasts after — Think — can
|
|
3423
3454
|
* gate its broadcast on it), `false` when there was nothing to persist (no
|
|
3424
|
-
* parts,
|
|
3455
|
+
* parts, `prepare` returned `null`, or the message `continues` names is gone).
|
|
3425
3456
|
*/
|
|
3426
3457
|
declare function persistReconstructedOrphan<
|
|
3427
3458
|
TMessage extends UIMessage = UIMessage
|
package/dist/chat/index.js
CHANGED
|
@@ -198,6 +198,7 @@ var TurnQueue = class {
|
|
|
198
198
|
this._queue = Promise.resolve();
|
|
199
199
|
this._generation = 0;
|
|
200
200
|
this._activeRequestId = null;
|
|
201
|
+
this._activeGeneration = null;
|
|
201
202
|
this._countsByGeneration = /* @__PURE__ */ new Map();
|
|
202
203
|
}
|
|
203
204
|
get generation() {
|
|
@@ -206,6 +207,14 @@ var TurnQueue = class {
|
|
|
206
207
|
get activeRequestId() {
|
|
207
208
|
return this._activeRequestId;
|
|
208
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* The generation the active turn was admitted under, or `null` when no turn
|
|
212
|
+
* is active. A turn whose generation is older than {@link generation} was
|
|
213
|
+
* invalidated by a {@link reset} while it ran.
|
|
214
|
+
*/
|
|
215
|
+
get activeGeneration() {
|
|
216
|
+
return this._activeGeneration;
|
|
217
|
+
}
|
|
209
218
|
get isActive() {
|
|
210
219
|
return this._activeRequestId !== null;
|
|
211
220
|
}
|
|
@@ -224,6 +233,7 @@ var TurnQueue = class {
|
|
|
224
233
|
return { status: "stale" };
|
|
225
234
|
}
|
|
226
235
|
this._activeRequestId = requestId;
|
|
236
|
+
this._activeGeneration = capturedGeneration;
|
|
227
237
|
try {
|
|
228
238
|
return {
|
|
229
239
|
status: "completed",
|
|
@@ -231,6 +241,7 @@ var TurnQueue = class {
|
|
|
231
241
|
};
|
|
232
242
|
} finally {
|
|
233
243
|
this._activeRequestId = null;
|
|
244
|
+
this._activeGeneration = null;
|
|
234
245
|
this._decrementCount(capturedGeneration);
|
|
235
246
|
releaseTurn();
|
|
236
247
|
}
|
|
@@ -812,6 +823,7 @@ var ResumableStream = class {
|
|
|
812
823
|
const metadata = { cfChat: 1 };
|
|
813
824
|
if (options.messageId != null) metadata.messageId = options.messageId;
|
|
814
825
|
if (options.parentMessageId != null) metadata.parentMessageId = options.parentMessageId;
|
|
826
|
+
if (options.basePartCount != null) metadata.basePartCount = options.basePartCount;
|
|
815
827
|
if (this._activeIsContinuation) metadata.isContinuation = 1;
|
|
816
828
|
if (seqBase > 0) metadata.seqBase = seqBase;
|
|
817
829
|
if (options.originMessageIds?.length) metadata.originMessageIds = options.originMessageIds;
|
|
@@ -841,6 +853,15 @@ var ResumableStream = class {
|
|
|
841
853
|
return parseChatMetadata(row)?.messageId ?? null;
|
|
842
854
|
}
|
|
843
855
|
/**
|
|
856
|
+
* How many parts the message an orphaned stream extends held when the
|
|
857
|
+
* stream started, or null when the stream produces a message of its own.
|
|
858
|
+
*/
|
|
859
|
+
getStreamBasePartCount(streamId) {
|
|
860
|
+
const row = this.ops.getStream(streamId);
|
|
861
|
+
if (!row) return null;
|
|
862
|
+
return parseChatMetadata(row)?.basePartCount ?? null;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
844
865
|
* The message an orphaned stream's assistant message is a child of, or null
|
|
845
866
|
* when the stream appends to the latest leaf or predates parent tracking.
|
|
846
867
|
*/
|
|
@@ -2652,11 +2673,12 @@ function repairInterruptedToolParts(messages, options) {
|
|
|
2652
2673
|
* Reconstruct a message from `chunks` and upsert it via the store. Returns
|
|
2653
2674
|
* `true` when a write happened (so a caller that broadcasts after — Think — can
|
|
2654
2675
|
* gate its broadcast on it), `false` when there was nothing to persist (no
|
|
2655
|
-
* parts,
|
|
2676
|
+
* parts, `prepare` returned `null`, or the message `continues` names is gone).
|
|
2656
2677
|
*/
|
|
2657
2678
|
async function persistReconstructedOrphan(chunks, options) {
|
|
2658
2679
|
if (chunks.length === 0) return false;
|
|
2659
|
-
const accumulator =
|
|
2680
|
+
const accumulator = await createReconstructionAccumulator(options);
|
|
2681
|
+
if (accumulator === null) return false;
|
|
2660
2682
|
for (const chunk of chunks) try {
|
|
2661
2683
|
accumulator.applyChunk(JSON.parse(chunk.body));
|
|
2662
2684
|
} catch {}
|
|
@@ -2668,6 +2690,20 @@ async function persistReconstructedOrphan(chunks, options) {
|
|
|
2668
2690
|
else await options.store.appendMessage(prepared);
|
|
2669
2691
|
return true;
|
|
2670
2692
|
}
|
|
2693
|
+
async function createReconstructionAccumulator(options) {
|
|
2694
|
+
const { continues } = options;
|
|
2695
|
+
if (continues === void 0) return new StreamAccumulator({ messageId: options.fallbackId });
|
|
2696
|
+
const continued = await options.store.getMessage(continues.messageId);
|
|
2697
|
+
if (!continued) return null;
|
|
2698
|
+
const baseParts = continued.parts.slice(0, continues.basePartCount);
|
|
2699
|
+
const metadata = continued.metadata;
|
|
2700
|
+
return new StreamAccumulator({
|
|
2701
|
+
messageId: continues.messageId,
|
|
2702
|
+
continuation: true,
|
|
2703
|
+
existingParts: continues.settleBasePart ? baseParts.map(continues.settleBasePart) : baseParts,
|
|
2704
|
+
existingMetadata: metadata !== null && typeof metadata === "object" && !Array.isArray(metadata) ? metadata : void 0
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2671
2707
|
//#endregion
|
|
2672
2708
|
//#region src/chat/recovery.ts
|
|
2673
2709
|
function createChatFiberSnapshot({ kind, requestId, recoveryRootRequestId, continuation, messages, lastBody, lastClientTools, originMessageIds }) {
|
|
@@ -2877,7 +2913,7 @@ var ResumeHandshake = class {
|
|
|
2877
2913
|
/** Handle a client `STREAM_RESUME_ACK` for `requestId`. */
|
|
2878
2914
|
async handleResumeAck(connection, requestId) {
|
|
2879
2915
|
const { resumableStream, pendingResumeConnections, responseMessageType } = this.host;
|
|
2880
|
-
pendingResumeConnections.delete(connection.id);
|
|
2916
|
+
if (!resumableStream.hasActiveStream() || resumableStream.activeRequestId === requestId) pendingResumeConnections.delete(connection.id);
|
|
2881
2917
|
if (resumableStream.hasActiveStream() && resumableStream.activeRequestId === requestId) {
|
|
2882
2918
|
const orphanedStreamId = resumableStream.replayChunks(connection, resumableStream.activeRequestId);
|
|
2883
2919
|
if (orphanedStreamId) await this.host.persistOrphanedStream(orphanedStreamId);
|