@buoy-gg/agent-core 7.0.34 → 7.0.36
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 +10 -7
- package/lib/commonjs/blocks/receipts.js +83 -24
- package/lib/commonjs/blocks/receipts.js.map +1 -1
- package/lib/commonjs/blocks/runId.js +31 -0
- package/lib/commonjs/blocks/runId.js.map +1 -0
- package/lib/commonjs/blocks/types.js +23 -2
- package/lib/commonjs/blocks/types.js.map +1 -1
- package/lib/commonjs/blocks/uiTool.js +426 -12
- package/lib/commonjs/blocks/uiTool.js.map +1 -1
- package/lib/commonjs/catalog/catalog.g.js +121 -43
- package/lib/commonjs/catalog/catalog.g.js.map +1 -1
- package/lib/commonjs/catalog/catalog.source.json +121 -45
- package/lib/commonjs/catalog/catalog.types.g.js +44 -0
- package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
- package/lib/commonjs/catalog/normalizeParams.js +333 -0
- package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
- package/lib/commonjs/catalog/signature.js +68 -0
- package/lib/commonjs/catalog/signature.js.map +1 -0
- package/lib/commonjs/catalog/snapshotReads.js +13 -6
- package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
- package/lib/commonjs/catalog/toProviderTools.js +41 -5
- package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
- package/lib/commonjs/context/buildContextPack.js +367 -19
- package/lib/commonjs/context/buildContextPack.js.map +1 -1
- package/lib/commonjs/effects/digest.js +34 -0
- package/lib/commonjs/effects/digest.js.map +1 -0
- package/lib/commonjs/effects/ledger.js +85 -1
- package/lib/commonjs/effects/ledger.js.map +1 -1
- package/lib/commonjs/engine/askGate.js +287 -0
- package/lib/commonjs/engine/askGate.js.map +1 -0
- package/lib/commonjs/engine/effectFor.js +82 -1
- package/lib/commonjs/engine/effectFor.js.map +1 -1
- package/lib/commonjs/engine/historyBudget.js +260 -0
- package/lib/commonjs/engine/historyBudget.js.map +1 -0
- package/lib/commonjs/engine/runAgentTurn.js +958 -88
- package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
- package/lib/commonjs/engine/systemPrompt.js +72 -8
- package/lib/commonjs/engine/systemPrompt.js.map +1 -1
- package/lib/commonjs/engine/textToolCalls.js +276 -0
- package/lib/commonjs/engine/textToolCalls.js.map +1 -0
- package/lib/commonjs/index.js +81 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/policy/labels.js +19 -3
- package/lib/commonjs/policy/labels.js.map +1 -1
- package/lib/commonjs/policy/policy.js +6 -1
- package/lib/commonjs/policy/policy.js.map +1 -1
- package/lib/commonjs/policy/redact.js +42 -5
- package/lib/commonjs/policy/redact.js.map +1 -1
- package/lib/commonjs/providers/anthropic.js +340 -174
- package/lib/commonjs/providers/anthropic.js.map +1 -1
- package/lib/commonjs/providers/openai.js +229 -103
- package/lib/commonjs/providers/openai.js.map +1 -1
- package/lib/commonjs/providers/sse.js +164 -29
- package/lib/commonjs/providers/sse.js.map +1 -1
- package/lib/commonjs/providers/streamTimer.js +123 -0
- package/lib/commonjs/providers/streamTimer.js.map +1 -0
- package/lib/commonjs/providers/transport.js +107 -0
- package/lib/commonjs/providers/transport.js.map +1 -0
- package/lib/commonjs/providers/xhrStream.js +209 -0
- package/lib/commonjs/providers/xhrStream.js.map +1 -0
- package/lib/commonjs/session.js +245 -52
- package/lib/commonjs/session.js.map +1 -1
- package/lib/module/blocks/receipts.js +83 -24
- package/lib/module/blocks/receipts.js.map +1 -1
- package/lib/module/blocks/runId.js +26 -0
- package/lib/module/blocks/runId.js.map +1 -0
- package/lib/module/blocks/types.js +23 -2
- package/lib/module/blocks/types.js.map +1 -1
- package/lib/module/blocks/uiTool.js +424 -12
- package/lib/module/blocks/uiTool.js.map +1 -1
- package/lib/module/catalog/catalog.g.js +121 -43
- package/lib/module/catalog/catalog.g.js.map +1 -1
- package/lib/module/catalog/catalog.source.json +121 -45
- package/lib/module/catalog/catalog.types.g.js +40 -0
- package/lib/module/catalog/catalog.types.g.js.map +1 -0
- package/lib/module/catalog/normalizeParams.js +327 -0
- package/lib/module/catalog/normalizeParams.js.map +1 -0
- package/lib/module/catalog/signature.js +63 -0
- package/lib/module/catalog/signature.js.map +1 -0
- package/lib/module/catalog/snapshotReads.js +13 -6
- package/lib/module/catalog/snapshotReads.js.map +1 -1
- package/lib/module/catalog/toProviderTools.js +41 -5
- package/lib/module/catalog/toProviderTools.js.map +1 -1
- package/lib/module/context/buildContextPack.js +366 -19
- package/lib/module/context/buildContextPack.js.map +1 -1
- package/lib/module/effects/digest.js +29 -0
- package/lib/module/effects/digest.js.map +1 -0
- package/lib/module/effects/ledger.js +85 -1
- package/lib/module/effects/ledger.js.map +1 -1
- package/lib/module/engine/askGate.js +280 -0
- package/lib/module/engine/askGate.js.map +1 -0
- package/lib/module/engine/effectFor.js +83 -1
- package/lib/module/engine/effectFor.js.map +1 -1
- package/lib/module/engine/historyBudget.js +251 -0
- package/lib/module/engine/historyBudget.js.map +1 -0
- package/lib/module/engine/runAgentTurn.js +954 -88
- package/lib/module/engine/runAgentTurn.js.map +1 -1
- package/lib/module/engine/systemPrompt.js +71 -8
- package/lib/module/engine/systemPrompt.js.map +1 -1
- package/lib/module/engine/textToolCalls.js +270 -0
- package/lib/module/engine/textToolCalls.js.map +1 -0
- package/lib/module/index.js +7 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/policy/labels.js +19 -3
- package/lib/module/policy/labels.js.map +1 -1
- package/lib/module/policy/policy.js +6 -1
- package/lib/module/policy/policy.js.map +1 -1
- package/lib/module/policy/redact.js +42 -5
- package/lib/module/policy/redact.js.map +1 -1
- package/lib/module/providers/anthropic.js +341 -175
- package/lib/module/providers/anthropic.js.map +1 -1
- package/lib/module/providers/openai.js +230 -104
- package/lib/module/providers/openai.js.map +1 -1
- package/lib/module/providers/sse.js +160 -29
- package/lib/module/providers/sse.js.map +1 -1
- package/lib/module/providers/streamTimer.js +118 -0
- package/lib/module/providers/streamTimer.js.map +1 -0
- package/lib/module/providers/transport.js +103 -0
- package/lib/module/providers/transport.js.map +1 -0
- package/lib/module/providers/xhrStream.js +204 -0
- package/lib/module/providers/xhrStream.js.map +1 -0
- package/lib/module/session.js +228 -54
- package/lib/module/session.js.map +1 -1
- package/lib/typescript/blocks/receipts.d.ts +5 -10
- package/lib/typescript/blocks/receipts.d.ts.map +1 -1
- package/lib/typescript/blocks/runId.d.ts +20 -0
- package/lib/typescript/blocks/runId.d.ts.map +1 -0
- package/lib/typescript/blocks/types.d.ts +23 -2
- package/lib/typescript/blocks/types.d.ts.map +1 -1
- package/lib/typescript/blocks/uiTool.d.ts +11 -2
- package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
- package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
- package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
- package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
- package/lib/typescript/catalog/signature.d.ts +29 -0
- package/lib/typescript/catalog/signature.d.ts.map +1 -0
- package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
- package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
- package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
- package/lib/typescript/context/buildContextPack.d.ts +24 -2
- package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
- package/lib/typescript/effects/digest.d.ts +10 -0
- package/lib/typescript/effects/digest.d.ts.map +1 -0
- package/lib/typescript/effects/ledger.d.ts +55 -0
- package/lib/typescript/effects/ledger.d.ts.map +1 -1
- package/lib/typescript/engine/askGate.d.ts +29 -0
- package/lib/typescript/engine/askGate.d.ts.map +1 -0
- package/lib/typescript/engine/effectFor.d.ts +6 -1
- package/lib/typescript/engine/effectFor.d.ts.map +1 -1
- package/lib/typescript/engine/historyBudget.d.ts +92 -0
- package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
- package/lib/typescript/engine/runAgentTurn.d.ts +115 -1
- package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
- package/lib/typescript/engine/systemPrompt.d.ts +41 -0
- package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
- package/lib/typescript/engine/textToolCalls.d.ts +58 -0
- package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/policy/labels.d.ts.map +1 -1
- package/lib/typescript/policy/policy.d.ts.map +1 -1
- package/lib/typescript/policy/redact.d.ts.map +1 -1
- package/lib/typescript/providers/anthropic.d.ts +5 -0
- package/lib/typescript/providers/anthropic.d.ts.map +1 -1
- package/lib/typescript/providers/openai.d.ts +0 -16
- package/lib/typescript/providers/openai.d.ts.map +1 -1
- package/lib/typescript/providers/sse.d.ts +82 -1
- package/lib/typescript/providers/sse.d.ts.map +1 -1
- package/lib/typescript/providers/streamTimer.d.ts +59 -0
- package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
- package/lib/typescript/providers/transport.d.ts +40 -0
- package/lib/typescript/providers/transport.d.ts.map +1 -0
- package/lib/typescript/providers/types.d.ts +116 -3
- package/lib/typescript/providers/types.d.ts.map +1 -1
- package/lib/typescript/providers/xhrStream.d.ts +43 -0
- package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
- package/lib/typescript/session.d.ts +63 -2
- package/lib/typescript/session.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -20,10 +20,46 @@ import type { DispatchFn, SnapshotFn, ToolDescriptor } from "../types";
|
|
|
20
20
|
import type { AgentMessage, Provider } from "../providers/types";
|
|
21
21
|
import { EffectLedger } from "../effects/ledger";
|
|
22
22
|
import { type AskBuoyPolicy } from "../policy/policy";
|
|
23
|
+
import { digestOf } from "../effects/digest";
|
|
23
24
|
import { type Block } from "../blocks/types";
|
|
24
25
|
export type TurnEvent = {
|
|
25
26
|
type: "text";
|
|
26
27
|
delta: string;
|
|
28
|
+
/**
|
|
29
|
+
* This delta opens a new round of the same answer.
|
|
30
|
+
*
|
|
31
|
+
* One assistant bubble spans every round of a multi-step run, so without
|
|
32
|
+
* a marker the last sentence of one round and the first of the next are
|
|
33
|
+
* concatenated — "…resets every launch.Here's the full picture…". The
|
|
34
|
+
* ENGINE is the only layer that knows where a round ends: the UI sees a
|
|
35
|
+
* flat stream of deltas, and the tool events it used to infer the
|
|
36
|
+
* boundary from are not always there (a declined approval runs no tool).
|
|
37
|
+
*/
|
|
38
|
+
breakBefore?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The model's own reasoning for this turn, when the provider reports any.
|
|
42
|
+
*
|
|
43
|
+
* Only some models produce it: Claude emits thinking blocks by default, and
|
|
44
|
+
* an OpenAI reasoning model reports a summary; gpt-4.1 and friends produce
|
|
45
|
+
* nothing here at all. So a UI showing this must be honest about it being
|
|
46
|
+
* absent rather than looking broken.
|
|
47
|
+
*/
|
|
48
|
+
| {
|
|
49
|
+
type: "reasoning";
|
|
50
|
+
text: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whole rounds were dropped from the model's memory before this turn.
|
|
54
|
+
*
|
|
55
|
+
* Yielded by the SESSION (which owns trimming), never by the engine. The
|
|
56
|
+
* screen still shows those rounds, so without this the transcript and the
|
|
57
|
+
* model silently disagree — the user asks "turn off that override" and the
|
|
58
|
+
* model, having lost the round that armed it, asks which one.
|
|
59
|
+
*/
|
|
60
|
+
| {
|
|
61
|
+
type: "history-trimmed";
|
|
62
|
+
droppedRounds: number;
|
|
27
63
|
} | {
|
|
28
64
|
type: "tool-start";
|
|
29
65
|
id: string;
|
|
@@ -33,11 +69,31 @@ export type TurnEvent = {
|
|
|
33
69
|
label: string;
|
|
34
70
|
/** The catalog sentence, for a row the user expands. */
|
|
35
71
|
description: string;
|
|
72
|
+
/**
|
|
73
|
+
* What the model actually asked for, post-validation. The label says
|
|
74
|
+
* "Open /bag"; this says which path, which key, which value — the
|
|
75
|
+
* difference between "a step ran" and "here is what it did".
|
|
76
|
+
*/
|
|
77
|
+
params: Record<string, unknown>;
|
|
78
|
+
/** read / write / destructive, from the catalog. */
|
|
79
|
+
effect: "read" | "write" | "destructive";
|
|
36
80
|
} | {
|
|
37
81
|
type: "tool-end";
|
|
38
82
|
id: string;
|
|
39
83
|
ok: boolean;
|
|
40
84
|
summary: string;
|
|
85
|
+
/** Wall time for the dispatch, so a slow step is findable. */
|
|
86
|
+
durationMs: number;
|
|
87
|
+
/**
|
|
88
|
+
* The redacted result the MODEL was given, capped. Present only for a
|
|
89
|
+
* step that succeeded.
|
|
90
|
+
*
|
|
91
|
+
* This is what turns a trace into a debugging artefact: "the write
|
|
92
|
+
* succeeded" and "the write returned `{ok:false}`" look identical
|
|
93
|
+
* without it, and the second is usually the bug. It is the same
|
|
94
|
+
* redacted string the receipt is built from — never the raw value.
|
|
95
|
+
*/
|
|
96
|
+
result?: string;
|
|
41
97
|
}
|
|
42
98
|
/** A block to render — a receipt from a tool result, or a model-authored block. */
|
|
43
99
|
| {
|
|
@@ -61,11 +117,20 @@ export type TurnEvent = {
|
|
|
61
117
|
type: "error";
|
|
62
118
|
message: string;
|
|
63
119
|
}
|
|
64
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Token usage for one provider request, when the provider reports it.
|
|
122
|
+
* `cacheRead`/`cacheWrite` are the prompt-cache counters (see TokenUsage —
|
|
123
|
+
* without them a cached Claude request looks nearly free) and `model` is
|
|
124
|
+
* the id the provider actually SERVED, which is what a cost table or a
|
|
125
|
+
* benchmark needs when a gateway alias drifts to a new snapshot.
|
|
126
|
+
*/
|
|
65
127
|
| {
|
|
66
128
|
type: "usage";
|
|
67
129
|
input: number;
|
|
68
130
|
output: number;
|
|
131
|
+
cacheRead?: number;
|
|
132
|
+
cacheWrite?: number;
|
|
133
|
+
model?: string;
|
|
69
134
|
} | {
|
|
70
135
|
type: "done";
|
|
71
136
|
};
|
|
@@ -74,6 +139,8 @@ export interface RunTurnInput {
|
|
|
74
139
|
catalog: ToolDescriptor[];
|
|
75
140
|
messages: AgentMessage[];
|
|
76
141
|
system: string;
|
|
142
|
+
/** Per-turn "right now" block. See ProviderRequest.systemVolatile. */
|
|
143
|
+
systemVolatile?: string;
|
|
77
144
|
model: string;
|
|
78
145
|
maxTokens: number;
|
|
79
146
|
dispatch: DispatchFn;
|
|
@@ -99,10 +166,57 @@ export interface RunTurnInput {
|
|
|
99
166
|
label: string;
|
|
100
167
|
description: string;
|
|
101
168
|
reason: string;
|
|
169
|
+
/**
|
|
170
|
+
* The exact call being asked about.
|
|
171
|
+
*
|
|
172
|
+
* The UI does not render it — an approval prompt shows the effect, not the
|
|
173
|
+
* payload. It travels so a card that OUTLIVES this turn can still run it:
|
|
174
|
+
* the sheet persists an unanswered approval, and after a reload the
|
|
175
|
+
* generator holding this promise no longer exists, so Allow has to
|
|
176
|
+
* re-dispatch the call itself.
|
|
177
|
+
*/
|
|
178
|
+
params: Record<string, unknown>;
|
|
179
|
+
/**
|
|
180
|
+
* A fingerprint of the value this call is about to overwrite, read at the
|
|
181
|
+
* moment the question was asked — see `readTargetDigest`. A card that comes
|
|
182
|
+
* back after a restart re-reads and compares before it writes; a card
|
|
183
|
+
* answered live never needs it. Absent when the target cannot be read.
|
|
184
|
+
*/
|
|
185
|
+
targetDigest?: string;
|
|
102
186
|
}) => Promise<boolean>;
|
|
103
187
|
signal?: AbortSignal;
|
|
188
|
+
/**
|
|
189
|
+
* Every http(s) URL this CONVERSATION has read out of a tool result. Owned
|
|
190
|
+
* by the session so it outlives one turn: "now show me those as pictures"
|
|
191
|
+
* is a normal second message, and a per-turn set answered it by silently
|
|
192
|
+
* stripping every image — the model then described artwork the user could
|
|
193
|
+
* not see. Provenance is still enforced, just over the whole conversation
|
|
194
|
+
* rather than one turn of it. Omitted (tests, one-shot callers) means a
|
|
195
|
+
* fresh per-turn set.
|
|
196
|
+
*/
|
|
197
|
+
seenUrls?: Set<string>;
|
|
104
198
|
}
|
|
105
199
|
export declare function runAgentTurn(input: RunTurnInput): AsyncGenerator<TurnEvent, AgentMessage[], void>;
|
|
200
|
+
export { digestOf };
|
|
201
|
+
/**
|
|
202
|
+
* Fingerprint the value a write is about to replace.
|
|
203
|
+
*
|
|
204
|
+
* Built for the approval card that outlives its turn: the app crashed with
|
|
205
|
+
* "Set bag line L-01 qty to 14" still asking, relaunched, and the card came
|
|
206
|
+
* back — and Allow wrote qty 14 against whatever the bag was NOW, maybe a
|
|
207
|
+
* different account, maybe a line that no longer existed. A hash of the
|
|
208
|
+
* params alone would not catch that (same label, same params, different
|
|
209
|
+
* world). So the card carries a digest of the TARGET at ask time, and a
|
|
210
|
+
* restored Allow re-reads and compares before it writes. Undefined when the
|
|
211
|
+
* target cannot be read — then the card can only warn, not check.
|
|
212
|
+
*/
|
|
213
|
+
export declare function readTargetDigest(input: {
|
|
214
|
+
toolId: string;
|
|
215
|
+
action: string;
|
|
216
|
+
params: Record<string, unknown>;
|
|
217
|
+
dispatch: DispatchFn;
|
|
218
|
+
catalog?: ToolDescriptor[];
|
|
219
|
+
}): Promise<string | undefined>;
|
|
106
220
|
export interface GatedActionInput {
|
|
107
221
|
toolId: string;
|
|
108
222
|
action: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runAgentTurn.d.ts","sourceRoot":"","sources":["../../../src/engine/runAgentTurn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAoB,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"runAgentTurn.d.ts","sourceRoot":"","sources":["../../../src/engine/runAgentTurn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAoB,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAOzF,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EAKT,MAA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,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;CAC5B;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAC7B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAmEzF"}
|
|
@@ -41,9 +41,50 @@ export interface SystemPromptInput {
|
|
|
41
41
|
context?: ContextPack;
|
|
42
42
|
isRelease: boolean;
|
|
43
43
|
readOnly: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Who turned read-only on. The APP configuring it is a rule the user cannot
|
|
46
|
+
* change; the DEVICE toggle is the person in front of the phone choosing to
|
|
47
|
+
* look without touching — and the model should tell them where to turn it
|
|
48
|
+
* off rather than send them to a developer.
|
|
49
|
+
*/
|
|
50
|
+
readOnlySource?: "app" | "device";
|
|
44
51
|
requireApproval: string[];
|
|
52
|
+
/**
|
|
53
|
+
* The user turned approval cards off on this device. Distinct from an empty
|
|
54
|
+
* `requireApproval`, which is the APP choosing full auto-run: here a gate
|
|
55
|
+
* exists and the person in front of the phone waived it, so the model is
|
|
56
|
+
* told plainly that nothing will stop a destructive call.
|
|
57
|
+
*/
|
|
58
|
+
approvalsBypassed?: boolean;
|
|
45
59
|
appName?: string;
|
|
46
60
|
platform?: string;
|
|
47
61
|
}
|
|
48
62
|
export declare function buildSystemPrompt(input: SystemPromptInput): string;
|
|
63
|
+
/**
|
|
64
|
+
* The per-turn block: what the app is showing at the moment the user typed.
|
|
65
|
+
* Rendered AFTER the cached prompt (see ProviderRequest.systemVolatile), so it
|
|
66
|
+
* can change on every message without invalidating anything.
|
|
67
|
+
*
|
|
68
|
+
* Returns undefined when nothing was readable — the prompt then says so, so the
|
|
69
|
+
* model knows to read for itself rather than assume the block was empty
|
|
70
|
+
* because the app is.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildLiveBlock(live: Record<string, unknown> | undefined,
|
|
73
|
+
/**
|
|
74
|
+
* What this conversation has already changed, newest last.
|
|
75
|
+
*
|
|
76
|
+
* The ledger existed from the start and the model could never see it. Two
|
|
77
|
+
* failures came out of that. Asked "what have you changed?" it answered from
|
|
78
|
+
* memory of its own sentences, which drifts and cannot survive a reload. And
|
|
79
|
+
* reading a value it had itself overwritten three turns earlier, it reported
|
|
80
|
+
* the number as the app's own — the same "never fake the answer" problem as
|
|
81
|
+
* a network override, with the model as the one deceived.
|
|
82
|
+
*
|
|
83
|
+
* Short by construction: tool, action and a label per entry, capped. It is a
|
|
84
|
+
* reminder of what happened, not a replay of it.
|
|
85
|
+
*/
|
|
86
|
+
changes?: {
|
|
87
|
+
label: string;
|
|
88
|
+
undone: boolean;
|
|
89
|
+
}[]): string;
|
|
49
90
|
//# sourceMappingURL=systemPrompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemPrompt.d.ts","sourceRoot":"","sources":["../../../src/engine/systemPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAA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E,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CA2HlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;AACzC;;;;;;;;;;;;GAYG;AACH,OAAO,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,EAAE,GAC7C,MAAM,CAgBR"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recovering a tool call a model wrote as TEXT instead of calling.
|
|
3
|
+
*
|
|
4
|
+
* Every provider here is sent real tool definitions, and most models use them.
|
|
5
|
+
* Some don't — under a gateway, after a clarifying question, or just on the
|
|
6
|
+
* wrong roll, a model answers with the call spelled out as JSON:
|
|
7
|
+
*
|
|
8
|
+
* ```json
|
|
9
|
+
* {"calls":[{"tool":"buoy_zustand","action":"setState","params":{…}}],
|
|
10
|
+
* "reply":"Done — I added one Jigglypuff to your bag."}
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Left alone this is the worst outcome the product has: the user said "yes,
|
|
14
|
+
* go ahead", nothing happened, and what they got back was a wall of JSON
|
|
15
|
+
* claiming it did. The same class of problem as the parameter aliases in
|
|
16
|
+
* normalizeParams — models reach for a convention they know, and meeting them
|
|
17
|
+
* costs one parse.
|
|
18
|
+
*
|
|
19
|
+
* Two halves, and the first is why this file exists at all:
|
|
20
|
+
*
|
|
21
|
+
* 1. {@link couldBeToolCallEnvelope} runs on every delta, because the decision
|
|
22
|
+
* has to be made BEFORE the text reaches the screen. Streamed text cannot
|
|
23
|
+
* be taken back. It withholds only what could still be an envelope and
|
|
24
|
+
* releases the moment it can't be.
|
|
25
|
+
* 2. {@link parseTextToolCalls} turns the finished blob into ordinary calls,
|
|
26
|
+
* which then go through validation, the policy, and approval exactly like a
|
|
27
|
+
* native one. Nothing here decides that a call is allowed to run — a
|
|
28
|
+
* recovered destructive call still stops at the same approval sheet.
|
|
29
|
+
*/
|
|
30
|
+
import type { ToolCall } from "../providers/types";
|
|
31
|
+
import type { ToolDescriptor } from "../types";
|
|
32
|
+
/**
|
|
33
|
+
* Could the text so far still turn out to be a tool-call envelope?
|
|
34
|
+
*
|
|
35
|
+
* False the instant it can't be, so an ordinary answer streams exactly as it
|
|
36
|
+
* did before — the window this holds is one opening brace plus a key name.
|
|
37
|
+
*/
|
|
38
|
+
export declare function couldBeToolCallEnvelope(text: string): boolean;
|
|
39
|
+
export interface SalvagedCalls {
|
|
40
|
+
calls: ToolCall[];
|
|
41
|
+
/** The prose the envelope carried, if any. The JSON itself is never shown. */
|
|
42
|
+
reply: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read a text envelope as tool calls, or nothing if that is not what it is.
|
|
46
|
+
*
|
|
47
|
+
* Deliberately strict about the SHAPE and loose about the spelling: it will
|
|
48
|
+
* not turn arbitrary JSON into calls (a model showing the user a response body
|
|
49
|
+
* must still be shown), but it accepts every naming convention a model might
|
|
50
|
+
* carry over — `tool`/`name`, `params`/`input`/`arguments`, one call or many.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseTextToolCalls(text: string, catalog: ToolDescriptor[]): SalvagedCalls | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Appended to a recovered call's result, so the model corrects itself for the
|
|
55
|
+
* rest of the conversation instead of writing the next one as text too.
|
|
56
|
+
*/
|
|
57
|
+
export declare const SALVAGE_NOTE = "\n\n[You wrote this call as JSON in your reply instead of calling the tool. It was recovered and run this time. Call tools through the tool interface \u2014 text is shown to the user as-is, and a call written there does not run.]";
|
|
58
|
+
//# sourceMappingURL=textToolCalls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textToolCalls.d.ts","sourceRoot":"","sources":["../../../src/engine/textToolCalls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA0B/C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQ7D;AA+JD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc,EAAE,GACxB,aAAa,GAAG,SAAS,CA+B3B;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,0OAC2M,CAAC"}
|
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export type { ActionDescriptor, ActionEffect, DispatchFn, JsonSchema, ReleaseBehavior, SnapshotFn, ToolDescriptor, UndoSpec, } from "./types";
|
|
11
11
|
export { CATALOG, CATALOG_ACTION_COUNT, CATALOG_TOOL_COUNT } from "./catalog/catalog.g";
|
|
12
|
+
export { CATALOG_ACTIONS, type CatalogAction, type CatalogActionMap, type CatalogToolId, } from "./catalog/catalog.types.g";
|
|
12
13
|
export { fromProviderToolName, toProviderToolName, toProviderTools, type ProviderTool, type ToProviderToolsOptions, } from "./catalog/toProviderTools";
|
|
13
14
|
export { applyDefaults, validateParams, type ValidationResult, } from "./catalog/validateParams";
|
|
14
15
|
export { projectSnapshot, SNAPSHOT_ACTION } from "./catalog/snapshotReads";
|
|
16
|
+
export { normalizeParams, aliasNote, hashQueryKey } from "./catalog/normalizeParams";
|
|
15
17
|
export { createAnthropicProvider } from "./providers/anthropic";
|
|
16
18
|
export { createOpenAIProvider } from "./providers/openai";
|
|
17
|
-
export type { AgentMessage, Provider, ProviderConfig, ProviderRequest, StreamEvent, TokenUsage, ToolCall, ToolResult, } from "./providers/types";
|
|
18
|
-
export { runAgentTurn, runGatedAction, type GatedActionInput, type GatedActionOutcome, type RunTurnInput, type TurnEvent, } from "./engine/runAgentTurn";
|
|
19
|
-
export { buildSystemPrompt, type ContextPack, type SystemPromptInput, } from "./engine/systemPrompt";
|
|
20
|
-
export { buildContextDigest, type BuildContextInput } from "./context/buildContextPack";
|
|
19
|
+
export type { AgentMessage, Provider, ProviderConfig, ProviderRequest, StreamEvent, ThinkingBlock, TokenUsage, ToolCall, ToolResult, } from "./providers/types";
|
|
20
|
+
export { runAgentTurn, runGatedAction, readTargetDigest, digestOf, type GatedActionInput, type GatedActionOutcome, type RunTurnInput, type TurnEvent, } from "./engine/runAgentTurn";
|
|
21
|
+
export { buildLiveBlock, buildSystemPrompt, type ContextPack, type SystemPromptInput, } from "./engine/systemPrompt";
|
|
22
|
+
export { buildContextDigest, buildLiveContext, type BuildContextInput, } from "./context/buildContextPack";
|
|
21
23
|
export { EffectLedger, isReversible, type AppliedEffect, type LedgerEntry, type RevertOutcome, } from "./effects/ledger";
|
|
22
24
|
export { humanise, titleCall, toolTitle } from "./policy/labels";
|
|
23
25
|
export * from "./blocks/types";
|
|
@@ -25,5 +27,6 @@ export { UI_TOOL_NAME, UI_PARAMS, uiProviderTool, buildUiBlock } from "./blocks/
|
|
|
25
27
|
export { projectReceipt, shallowDiff, type ReceiptInput } from "./blocks/receipts";
|
|
26
28
|
export { decide, describeCall, DEFAULT_REQUIRE_APPROVAL, resolveRequireApproval, type AllowRule, type AskBuoyPolicy, type Decision, } from "./policy/policy";
|
|
27
29
|
export { redact, registerSelfEndpoint, isSelfTraffic, stripSelfTraffic, } from "./policy/redact";
|
|
28
|
-
export {
|
|
30
|
+
export { idFactory, RUN_ID } from "./blocks/runId";
|
|
31
|
+
export { createAskBuoySession, resumableHistory, type AskBuoySession, type AskBuoySessionConfig, } from "./session";
|
|
29
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,QAAQ,GACT,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,EACb,cAAc,EACd,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,cAAc,EACd,QAAQ,GACT,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,EACb,cAAc,EACd,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,eA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AC;AACzB,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../../src/policy/labels.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../../src/policy/labels.ts"],"names":[],"mappings":"AAwNA,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAuCD,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO/C;AAaD;;;GAGG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAoBR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/policy/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG/D;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;IACjC;;;;OAIG;IACH,kBAAkB,CA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EAAE,OAAO,CAAC;CACpB;AAKD,wBAAgB,MAAM,CAAC,EACrB,UAAU,EACV,MAAM,EACN,MAAM,EACN,SAAS,GACV,EAAE,WAAW,GAAG,QAAQ,CA2ExB;AAoBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,gBAAgB,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAER"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../../src/policy/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../../src/policy/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAoEH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAazD;AAuBD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAgB3D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAOnD;AAQD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAYnE"}
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* user content array with any text after, and that user message must
|
|
17
17
|
* immediately follow the assistant turn. "Here are the results:" placed
|
|
18
18
|
* before the blocks is an instant 400.
|
|
19
|
+
* 5. Every current Claude model thinks by DEFAULT, and a `thinking` block must
|
|
20
|
+
* be replayed VERBATIM (signature and all) at the FRONT of the assistant
|
|
21
|
+
* turn it came from whenever that turn's tool results are sent back. An
|
|
22
|
+
* adapter that keeps only text and tool_use 400s on the second request of
|
|
23
|
+
* every tool-using turn — which is every turn Ask Buoy actually makes.
|
|
19
24
|
*/
|
|
20
25
|
import type { Provider, ProviderConfig } from "./types";
|
|
21
26
|
export declare function createAnthropicProvider(config: ProviderConfig): Provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EAMf,MAAM,SAAS,CAAC;AA0EjB,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAqSxE"}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI chat-completions protocol.
|
|
3
|
-
*
|
|
4
|
-
* The differences from Anthropic that actually matter to the code:
|
|
5
|
-
* - Tool results are their own `{role:"tool", tool_call_id, content}` MESSAGE,
|
|
6
|
-
* not blocks inside a user message.
|
|
7
|
-
* - Tool arguments arrive as a JSON STRING, streamed in fragments, and are
|
|
8
|
-
* keyed by an `index` that is stable across deltas while `id`/`name` only
|
|
9
|
-
* appear on the first fragment.
|
|
10
|
-
* - The stream DOES have a `data: [DONE]` sentinel, unlike Anthropic's.
|
|
11
|
-
*
|
|
12
|
-
* This adapter also serves Azure and any OpenAI-compatible org gateway, which
|
|
13
|
-
* is the common shape for an internal LLM proxy. Note Anthropic's own
|
|
14
|
-
* OpenAI-compatibility endpoint is explicitly not production-ready and silently
|
|
15
|
-
* ignores several fields — use the native Anthropic adapter for Anthropic.
|
|
16
|
-
*/
|
|
17
1
|
import type { Provider, ProviderConfig } from "./types";
|
|
18
2
|
export declare function createOpenAIProvider(config: ProviderConfig): Provider;
|
|
19
3
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/providers/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/providers/openai.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EAIf,MAAM,SAAS,CAAC;AA6DjB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CA+MrE"}
|
|
@@ -7,12 +7,93 @@
|
|
|
7
7
|
* TV-CLI lanes never had it. So `readSse` degrades to reading the whole body
|
|
8
8
|
* and replaying it as events rather than failing: a non-streaming answer is a
|
|
9
9
|
* slower chat, while a hard failure is no chat at all.
|
|
10
|
+
*
|
|
11
|
+
* THE TWO PATHS MUST AGREE. They did not. The buffered path appended "\n\n" to
|
|
12
|
+
* the body before parsing, which turns an unterminated final frame — the exact
|
|
13
|
+
* signature of a cut connection — into a well-formed event. The streaming path
|
|
14
|
+
* discarded that same frame, as the SSE spec requires. So one lane invented a
|
|
15
|
+
* complete answer where the other saw a broken one. Now both discard it and
|
|
16
|
+
* both RECORD it (`SseReadStatus.truncated`), because "was this reply whole?"
|
|
17
|
+
* is a question the engine has to answer before it runs anything.
|
|
10
18
|
*/
|
|
11
19
|
export interface SseEvent {
|
|
12
20
|
event?: string;
|
|
13
21
|
data: string;
|
|
14
22
|
}
|
|
15
|
-
export
|
|
23
|
+
export interface SseReadStatus {
|
|
24
|
+
/**
|
|
25
|
+
* Non-blank bytes were left over at EOF: the stream stopped mid-frame.
|
|
26
|
+
*
|
|
27
|
+
* Discarding the partial frame is correct (SSE spec); pretending the stream
|
|
28
|
+
* ended cleanly is not. Providers pair this with their own terminal-marker
|
|
29
|
+
* check — a clean frame boundary with no `message_stop`/`[DONE]` is equally
|
|
30
|
+
* truncated, just tidier about it.
|
|
31
|
+
*/
|
|
32
|
+
truncated: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface SseReadOptions {
|
|
35
|
+
status?: SseReadStatus;
|
|
36
|
+
/**
|
|
37
|
+
* Aborts the READ itself, not just the request.
|
|
38
|
+
*
|
|
39
|
+
* Normally redundant: a real `fetch` errors its response body when its
|
|
40
|
+
* signal aborts, so `reader.read()` rejects on its own. But Ask Buoy takes a
|
|
41
|
+
* host-supplied `fetch` (`ProviderConfig.fetch`), and a wrapper that returns
|
|
42
|
+
* a body it built itself — an interceptor, a replay harness, a polyfill —
|
|
43
|
+
* severs that link. Without this the idle timeout fires, aborts a signal
|
|
44
|
+
* nothing is listening to, and the turn parks on a read that never settles:
|
|
45
|
+
* exactly the hang the clock was added to end.
|
|
46
|
+
*/
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
/**
|
|
49
|
+
* Called once per COMPLETE frame, including ones that yield nothing.
|
|
50
|
+
*
|
|
51
|
+
* The idle timeout hangs off this. A comment-only frame — `: OPENROUTER
|
|
52
|
+
* PROCESSING`, which is exactly what arrives during a long silence — is
|
|
53
|
+
* skipped by the parser and would otherwise look identical to a dead socket.
|
|
54
|
+
*/
|
|
55
|
+
onFrame?: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Turn a stream of TEXT chunks into SSE frames.
|
|
59
|
+
*
|
|
60
|
+
* The one place framing happens, whatever produced the bytes: a `fetch` body
|
|
61
|
+
* reader, an `XMLHttpRequest` progress slice, or a whole body read at once on
|
|
62
|
+
* a runtime that cannot stream. Splitting it out is what lets the XHR
|
|
63
|
+
* transport exist without a second parser to keep in step with this one.
|
|
64
|
+
*/
|
|
65
|
+
export declare function framesFrom(chunks: AsyncIterable<string>, options?: SseReadOptions): AsyncGenerator<SseEvent, void, void>;
|
|
66
|
+
export declare function readSse(response: Response, options?: SseReadOptions): AsyncGenerator<SseEvent, void, void>;
|
|
67
|
+
/**
|
|
68
|
+
* A 200 that is not a stream at all.
|
|
69
|
+
*
|
|
70
|
+
* Gateways in front of a model do this: an auth proxy that has lost its
|
|
71
|
+
* upstream serves an HTML error page, a misrouted path serves an SPA shell,
|
|
72
|
+
* and a gateway that ignored `stream: true` serves one JSON object. Every one
|
|
73
|
+
* of those parses to zero SSE frames, so the old code read it as a model that
|
|
74
|
+
* had nothing to say and ended the turn with a blank bubble.
|
|
75
|
+
*
|
|
76
|
+
* Returns a message when the body should be treated as an error, and undefined
|
|
77
|
+
* when it looks like something the SSE reader can work with. Consumes the body
|
|
78
|
+
* only in the failing case.
|
|
79
|
+
*/
|
|
80
|
+
export declare function nonStreamProblem(response: Response): Promise<string | undefined>;
|
|
16
81
|
/** Body text for a failed response, trimmed to something a user can read. */
|
|
17
82
|
export declare function errorBody(response: Response): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* The message for a stream that stopped before the provider said it was done.
|
|
85
|
+
*
|
|
86
|
+
* `truncated` distinguishes the two shapes: cut mid-frame (a dropped
|
|
87
|
+
* connection) versus a clean frame boundary with no terminal marker (a gateway
|
|
88
|
+
* that closes the socket instead of sending one). The second is a
|
|
89
|
+
* compatibility problem worth naming, because retrying it will not help.
|
|
90
|
+
*/
|
|
91
|
+
export declare function truncatedMessage(truncated: boolean): string;
|
|
92
|
+
/**
|
|
93
|
+
* The message for arguments that would not parse, with enough in it to act on.
|
|
94
|
+
* `stopReason` "length" is the common cause — a reasoning model spends its
|
|
95
|
+
* budget thinking and the tool call is truncated mid-JSON — and the tail of
|
|
96
|
+
* the raw arguments says immediately whether that is what happened.
|
|
97
|
+
*/
|
|
98
|
+
export declare function unparseableMessage(name: string, args: string, stopReason?: string): string;
|
|
18
99
|
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/providers/sse.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/providers/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;;OAOG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AA6CD;;;;;;;GAOG;AACH,wBAAuB,UAAU,CAC/B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,OAAO,GAAE,cAAmB,GAC3B,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAUtC;AAED,wBAAuB,OAAO,CAC5B,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,cAAmB,GAC3B,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CA6EtC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAYtF;AAED,6EAA6E;AAC7E,wBAAsB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAQnE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAI3D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ1F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The clock on a model request.
|
|
3
|
+
*
|
|
4
|
+
* There was none. A gateway that accepted the socket and then said nothing —
|
|
5
|
+
* an overloaded proxy, a dropped VPN, a laptop that slept mid-answer — left
|
|
6
|
+
* the turn running with the thinking strip animating until a person pressed
|
|
7
|
+
* Stop. The 180s turn deadline did not help: it is read at the TOP of a step
|
|
8
|
+
* (`runAgentTurn`), and a step parked inside `await fetch(...)` never reaches
|
|
9
|
+
* the next one.
|
|
10
|
+
*
|
|
11
|
+
* Two clocks, because the two silences mean different things:
|
|
12
|
+
*
|
|
13
|
+
* - CONNECT covers "no headers yet". Nothing has been generated, so nothing is
|
|
14
|
+
* lost by giving up; 30s is already long for a gateway to acknowledge a POST.
|
|
15
|
+
* - IDLE covers "headers arrived, then nothing". This one has to be generous.
|
|
16
|
+
* Anthropic sends `ping` frames, but an OpenAI-protocol reasoning model can
|
|
17
|
+
* legitimately emit nothing for a long stretch while it thinks, and cutting
|
|
18
|
+
* that off would look like a broken product. Any frame at all — a keepalive
|
|
19
|
+
* comment included — resets it, so only total silence trips it.
|
|
20
|
+
*
|
|
21
|
+
* A timeout is NOT a retry. Nothing is re-sent: the request may have reached
|
|
22
|
+
* the model, and a duplicate turn is a duplicate bill and possibly duplicate
|
|
23
|
+
* writes. The turn ends with an honest notice and a Continue button.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_CONNECT_TIMEOUT_MS = 30000;
|
|
26
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS = 90000;
|
|
27
|
+
export interface StreamTimerOptions {
|
|
28
|
+
connectTimeoutMs?: number;
|
|
29
|
+
idleTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface StreamTimer {
|
|
32
|
+
/**
|
|
33
|
+
* The signal to hand to `fetch`. Aborts when the caller's signal aborts OR
|
|
34
|
+
* when either clock runs out, so one signal covers all three.
|
|
35
|
+
*/
|
|
36
|
+
readonly signal: AbortSignal | undefined;
|
|
37
|
+
/** Headers arrived: stop the connect clock, start the idle one. */
|
|
38
|
+
connected(): void;
|
|
39
|
+
/** A frame arrived: restart the idle clock. */
|
|
40
|
+
activity(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Which clock fired, if either. Read in the provider's catch: an abort with
|
|
43
|
+
* a reason here is a timeout, an abort without one is the user's Stop.
|
|
44
|
+
*/
|
|
45
|
+
readonly expired: "connect" | "idle" | undefined;
|
|
46
|
+
/** Message for the expired clock, or undefined if neither fired. */
|
|
47
|
+
message(): string | undefined;
|
|
48
|
+
/** Always call this — a live timer keeps the JS runtime awake. */
|
|
49
|
+
dispose(): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A timer over an optional caller signal.
|
|
53
|
+
*
|
|
54
|
+
* When no `AbortController` exists (a runtime old enough to lack it) this
|
|
55
|
+
* degrades to passing the caller's signal straight through with no clocks,
|
|
56
|
+
* rather than failing to send anything at all.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createStreamTimer(callerSignal: AbortSignal | undefined, options?: StreamTimerOptions): StreamTimer;
|
|
59
|
+
//# sourceMappingURL=streamTimer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamTimer.d.ts","sourceRoot":"","sources":["../../../src/providers/streamTimer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,eAAO,MAAM,0BAA0B,QAAS,CAAC;AACjD,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IACzC,mEAAmE;IACnE,SAAS,IAAI,IAAI,CAAC;IAClB,+CAA+C;IAC/C,QAAQ,IAAI,IAAI,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACjD,oEAAoE;IACpE,OAAO,IAAI,MAAM,GAAG,SAAS,CAAC;IAC9B,kEAAkE;IAClE,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,WAAW,GAAG,SAAS,EACrC,OAAO,GAAE,kBAAuB,GAC/B,WAAW,CAyFb"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a request is SENT, decided before it is sent.
|
|
3
|
+
*
|
|
4
|
+
* The obvious place to add XHR was inside `readSse`, once a missing
|
|
5
|
+
* `response.body` had already proved that `fetch` could not stream. That is
|
|
6
|
+
* the wrong boundary and would have been a real bug: the POST has already
|
|
7
|
+
* happened by then, the reader has neither the URL nor the headers nor the
|
|
8
|
+
* body to repeat it, and issuing a second one would ask the model to generate
|
|
9
|
+
* the same answer twice — billed twice, and for a turn that writes, acted on
|
|
10
|
+
* twice. Transport is chosen up front; a response that has started is consumed
|
|
11
|
+
* exactly once, whatever it turns out to be.
|
|
12
|
+
*
|
|
13
|
+
* `auto` therefore learns rather than probes. The first request goes through
|
|
14
|
+
* `fetch`; if that response has no reader, the answer is buffered (as it
|
|
15
|
+
* always was on that runtime) and the SESSION remembers, so every later
|
|
16
|
+
* request uses XHR and streams. One buffered reply at the start of a bare-RN
|
|
17
|
+
* session, and nothing to configure.
|
|
18
|
+
*/
|
|
19
|
+
import type { ProviderConfig } from "./types";
|
|
20
|
+
import { type SseEvent, type SseReadOptions } from "./sse";
|
|
21
|
+
export type TransportKind = "fetch" | "xhr" | "auto";
|
|
22
|
+
export interface OpenStreamRequest {
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
body: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}
|
|
27
|
+
export interface OpenStreamResult {
|
|
28
|
+
/** A message when the request failed or is not a stream; frames are empty. */
|
|
29
|
+
problem?: string;
|
|
30
|
+
frames(options?: SseReadOptions): AsyncGenerator<SseEvent, void, void>;
|
|
31
|
+
}
|
|
32
|
+
export interface Transport {
|
|
33
|
+
open(req: OpenStreamRequest): Promise<OpenStreamResult>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One transport per provider instance, because the `auto` decision is worth
|
|
37
|
+
* remembering: re-learning it would buffer the first reply of every turn.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createTransport(config: ProviderConfig): Transport;
|
|
40
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/providers/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;CACxE;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACzD;AAID;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAsEjE"}
|