@buoy-gg/agent-core 7.0.35 → 7.0.38
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 +21 -14
- package/lib/commonjs/blocks/receipts.js +57 -1
- package/lib/commonjs/blocks/receipts.js.map +1 -1
- package/lib/commonjs/blocks/types.js +23 -2
- package/lib/commonjs/blocks/types.js.map +1 -1
- package/lib/commonjs/blocks/uiTool.js +423 -10
- package/lib/commonjs/blocks/uiTool.js.map +1 -1
- package/lib/commonjs/catalog/catalog.g.js +213 -48
- package/lib/commonjs/catalog/catalog.g.js.map +1 -1
- package/lib/commonjs/catalog/catalog.source.json +226 -48
- 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 +44 -6
- 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 +98 -2
- 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/evidence.js +113 -0
- package/lib/commonjs/engine/evidence.js.map +1 -0
- package/lib/commonjs/engine/historyBudget.js +363 -0
- package/lib/commonjs/engine/historyBudget.js.map +1 -0
- package/lib/commonjs/engine/retrieve.js +214 -0
- package/lib/commonjs/engine/retrieve.js.map +1 -0
- package/lib/commonjs/engine/runAgentTurn.js +1231 -120
- package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
- package/lib/commonjs/engine/systemPrompt.js +103 -9
- 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/engine/tokenCalibration.js +81 -0
- package/lib/commonjs/engine/tokenCalibration.js.map +1 -0
- package/lib/commonjs/engine/verify.js +300 -0
- package/lib/commonjs/engine/verify.js.map +1 -0
- package/lib/commonjs/index.js +74 -0
- 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 -208
- package/lib/commonjs/providers/anthropic.js.map +1 -1
- package/lib/commonjs/providers/openai.js +237 -103
- package/lib/commonjs/providers/openai.js.map +1 -1
- package/lib/commonjs/providers/problem.js +98 -0
- package/lib/commonjs/providers/problem.js.map +1 -0
- package/lib/commonjs/providers/sse.js +170 -34
- 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 +123 -0
- package/lib/commonjs/providers/transport.js.map +1 -0
- package/lib/commonjs/providers/xhrStream.js +212 -0
- package/lib/commonjs/providers/xhrStream.js.map +1 -0
- package/lib/commonjs/session.js +242 -58
- package/lib/commonjs/session.js.map +1 -1
- package/lib/module/blocks/receipts.js +57 -1
- package/lib/module/blocks/receipts.js.map +1 -1
- package/lib/module/blocks/types.js +23 -2
- package/lib/module/blocks/types.js.map +1 -1
- package/lib/module/blocks/uiTool.js +421 -10
- package/lib/module/blocks/uiTool.js.map +1 -1
- package/lib/module/catalog/catalog.g.js +213 -48
- package/lib/module/catalog/catalog.g.js.map +1 -1
- package/lib/module/catalog/catalog.source.json +226 -48
- 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 +44 -6
- 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 +98 -2
- 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/evidence.js +107 -0
- package/lib/module/engine/evidence.js.map +1 -0
- package/lib/module/engine/historyBudget.js +355 -0
- package/lib/module/engine/historyBudget.js.map +1 -0
- package/lib/module/engine/retrieve.js +210 -0
- package/lib/module/engine/retrieve.js.map +1 -0
- package/lib/module/engine/runAgentTurn.js +1227 -121
- package/lib/module/engine/runAgentTurn.js.map +1 -1
- package/lib/module/engine/systemPrompt.js +101 -9
- 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/engine/tokenCalibration.js +75 -0
- package/lib/module/engine/tokenCalibration.js.map +1 -0
- package/lib/module/engine/verify.js +292 -0
- package/lib/module/engine/verify.js.map +1 -0
- package/lib/module/index.js +7 -3
- 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 -209
- package/lib/module/providers/anthropic.js.map +1 -1
- package/lib/module/providers/openai.js +238 -104
- package/lib/module/providers/openai.js.map +1 -1
- package/lib/module/providers/problem.js +92 -0
- package/lib/module/providers/problem.js.map +1 -0
- package/lib/module/providers/sse.js +166 -34
- 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 +119 -0
- package/lib/module/providers/transport.js.map +1 -0
- package/lib/module/providers/xhrStream.js +207 -0
- package/lib/module/providers/xhrStream.js.map +1 -0
- package/lib/module/session.js +226 -60
- package/lib/module/session.js.map +1 -1
- package/lib/typescript/blocks/receipts.d.ts +5 -0
- package/lib/typescript/blocks/receipts.d.ts.map +1 -1
- 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 +2 -2
- 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 +73 -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/evidence.d.ts +67 -0
- package/lib/typescript/engine/evidence.d.ts.map +1 -0
- package/lib/typescript/engine/historyBudget.d.ts +115 -0
- package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
- package/lib/typescript/engine/retrieve.d.ts +32 -0
- package/lib/typescript/engine/retrieve.d.ts.map +1 -0
- package/lib/typescript/engine/runAgentTurn.d.ts +179 -3
- package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
- package/lib/typescript/engine/systemPrompt.d.ts +80 -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/engine/tokenCalibration.d.ts +46 -0
- package/lib/typescript/engine/tokenCalibration.d.ts.map +1 -0
- package/lib/typescript/engine/verify.d.ts +67 -0
- package/lib/typescript/engine/verify.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -3
- 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.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/problem.d.ts +50 -0
- package/lib/typescript/providers/problem.d.ts.map +1 -0
- package/lib/typescript/providers/sse.d.ts +86 -2
- 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 +48 -0
- package/lib/typescript/providers/transport.d.ts.map +1 -0
- package/lib/typescript/providers/types.d.ts +105 -3
- package/lib/typescript/providers/types.d.ts.map +1 -1
- package/lib/typescript/providers/xhrStream.d.ts +45 -0
- package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
- package/lib/typescript/session.d.ts +55 -4
- package/lib/typescript/session.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +6 -0
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +10 -10
- package/LICENSE +0 -58
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many characters make a token — measured, not assumed.
|
|
3
|
+
*
|
|
4
|
+
* Every budget in this engine is kept in characters because that is what a
|
|
5
|
+
* string has, but every LIMIT that matters is in tokens: the provider's
|
|
6
|
+
* context window, the reply room, the cost. The conversion was a constant
|
|
7
|
+
* (4) everywhere. English prose does run near 4; the tool results this agent
|
|
8
|
+
* actually sends are JSON, which tokenizes nearer 3 — so a request the budget
|
|
9
|
+
* called 100k tokens could be 130k, on a gateway whose window is 128k. The
|
|
10
|
+
* proactive budget was optimistic in exactly the sessions it exists for.
|
|
11
|
+
*
|
|
12
|
+
* The provider tells us the truth after every request: its usage report
|
|
13
|
+
* carries the prompt's token count, and the engine knows how many characters
|
|
14
|
+
* it sent. One division gives the ratio for THIS conversation on THIS
|
|
15
|
+
* tokenizer; an exponential average smooths a single odd request (a round
|
|
16
|
+
* that was all prose, or all ids). Strands' design 0008 does the same in
|
|
17
|
+
* reverse — a known token baseline plus an estimate of the delta — and its
|
|
18
|
+
* decision record says why: public limits should be in LLM-native units.
|
|
19
|
+
*
|
|
20
|
+
* Clamped, because a wrong sample must not be able to blow the budget wide
|
|
21
|
+
* open (a gateway that reports nonsense usage) or shrink it to nothing.
|
|
22
|
+
*/
|
|
23
|
+
import type { TokenUsage } from "../providers/types";
|
|
24
|
+
export declare const DEFAULT_CHARS_PER_TOKEN = 4;
|
|
25
|
+
export declare class TokenCalibration {
|
|
26
|
+
private ratio;
|
|
27
|
+
private samples;
|
|
28
|
+
/** Characters per token, as currently believed. */
|
|
29
|
+
get charsPerToken(): number;
|
|
30
|
+
get sampleCount(): number;
|
|
31
|
+
/** Fold in one request: what was sent, and what the provider counted. */
|
|
32
|
+
observe(requestChars: number, promptTokens: number): void;
|
|
33
|
+
/** Characters a token budget allows, at the believed ratio. */
|
|
34
|
+
chars(tokens: number): number;
|
|
35
|
+
reset(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The whole prompt's token count from a usage report.
|
|
39
|
+
*
|
|
40
|
+
* Anthropic reports the cached and freshly-written prefix SEPARATELY from
|
|
41
|
+
* `input`; OpenAI-shaped providers fold `cached_tokens` INTO `prompt_tokens`.
|
|
42
|
+
* See TokenUsage. Adding on the wrong protocol double-counts the cache and
|
|
43
|
+
* halves the believed ratio.
|
|
44
|
+
*/
|
|
45
|
+
export declare function promptTokensOf(usage: TokenUsage, protocol: "anthropic" | "openai"): number;
|
|
46
|
+
//# sourceMappingURL=tokenCalibration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenCalibration.d.ts","sourceRoot":"","sources":["../../../src/engine/tokenCalibration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAQzC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,OAAO,CAAK;IAEpB,mDAAmD;IACnD,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,yEAAyE;IACzE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAOzD,+DAA+D;IAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI7B,KAAK,IAAI,IAAI;CAId;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,MAAM,CAG1F"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outcome verification: after a write lands, check that what the user asked
|
|
3
|
+
* for actually happened — not just that the adapter said ok.
|
|
4
|
+
*
|
|
5
|
+
* "Install override → `{ok:true}`" was reported as done. But installed ≠ a
|
|
6
|
+
* request has used it ≠ the cart shows it, and each step can succeed while
|
|
7
|
+
* the outcome fails: the app had the old response cached, the screen kept
|
|
8
|
+
* saying In Stock, and the reply said "the item is now sold out". Strands'
|
|
9
|
+
* GoalLoop frames this as a completion criterion with bounded correction; the
|
|
10
|
+
* criterion borrowed here is DETERMINISTIC — a read-back the engine performs
|
|
11
|
+
* with the same tools the model has — not a second model judging the reply.
|
|
12
|
+
*
|
|
13
|
+
* Three outcomes, each honest about what it is:
|
|
14
|
+
*
|
|
15
|
+
* - `verified` — the read-back shows the requested state.
|
|
16
|
+
* - `unverified` — the write landed but the read-back cannot yet show the
|
|
17
|
+
* outcome (an override is installed but no request has
|
|
18
|
+
* matched it). Reported as exactly that, never as proof.
|
|
19
|
+
* - `failed` — the read-back contradicts the write. The model is told
|
|
20
|
+
* what was found and asked for ONE correction through the
|
|
21
|
+
* same policy and ledger path; never to repeat the write.
|
|
22
|
+
*
|
|
23
|
+
* Bounded by construction: each verifier makes a few reads, polls for at most
|
|
24
|
+
* `waitMs` (small, per action), and stops on the turn's abort signal. It never
|
|
25
|
+
* dispatches a write, and its reads are not stashed as evidence. Undefined
|
|
26
|
+
* means "no opinion" — nothing is appended, which is what every action
|
|
27
|
+
* without a verifier gets.
|
|
28
|
+
*/
|
|
29
|
+
import type { DispatchFn } from "../types";
|
|
30
|
+
export type VerificationStatus = "verified" | "unverified" | "failed";
|
|
31
|
+
export interface Verification {
|
|
32
|
+
status: VerificationStatus;
|
|
33
|
+
/** One plain sentence for the row and the model. */
|
|
34
|
+
detail: string;
|
|
35
|
+
}
|
|
36
|
+
export interface VerifyInput {
|
|
37
|
+
toolId: string;
|
|
38
|
+
action: string;
|
|
39
|
+
params: Record<string, unknown>;
|
|
40
|
+
result: unknown;
|
|
41
|
+
dispatch: DispatchFn;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
/**
|
|
44
|
+
* The store / cache read the engine already took after the write for the
|
|
45
|
+
* receipt (`captureStoreState`), so the zustand and query verifiers do not
|
|
46
|
+
* read the same thing twice. Absent → the verifier reads it itself.
|
|
47
|
+
*/
|
|
48
|
+
after?: unknown;
|
|
49
|
+
}
|
|
50
|
+
type Verifier = (input: VerifyInput) => Promise<Verification | undefined>;
|
|
51
|
+
/** Every key in `want` present in `have` with an equal (deep) value. Arrays compare whole. */
|
|
52
|
+
export declare function isSubset(want: unknown, have: unknown): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* The adapters' path grammar — dotted keys, `[0]`, and the id-addressed
|
|
55
|
+
* `[field=value]` the prompt recommends for list edits ("lines[lineId=seed-1].qty").
|
|
56
|
+
* A mirror of shared/sync/valuePath.ts, kept here because agent-core imports
|
|
57
|
+
* nothing. The first live run wrote exactly that form and this resolver, then
|
|
58
|
+
* dotted-only, reported a landed edit as "did not take".
|
|
59
|
+
*/
|
|
60
|
+
export declare function atPath(root: unknown, path: string): unknown;
|
|
61
|
+
export declare const VERIFIERS: Readonly<Record<string, Verifier>>;
|
|
62
|
+
/** Run the verifier for this action, if there is one. Never throws: a read that blows up is "no opinion". */
|
|
63
|
+
export declare function verifyOutcome(input: VerifyInput): Promise<Verification | undefined>;
|
|
64
|
+
/** The trailer the model reads. Kept in the `[Buoy] ` trailer form the bench's parser splits on. */
|
|
65
|
+
export declare function verificationTrailer(v: Verification): string;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/engine/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEtE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;AA6B1E,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAS9D;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAqB3D;AAiFD,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAMxD,CAAC;AAEF,6GAA6G;AAC7G,wBAAsB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAQzF;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,CAS3D"}
|
|
@@ -9,15 +9,19 @@
|
|
|
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
19
|
export type { AgentMessage, Provider, ProviderConfig, ProviderRequest, StreamEvent, ThinkingBlock, TokenUsage, ToolCall, ToolResult, } from "./providers/types";
|
|
18
|
-
export { runAgentTurn, runGatedAction, type GatedActionInput, type GatedActionOutcome, type RunTurnInput, type TurnEvent, } from "./engine/runAgentTurn";
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
20
|
+
export { runAgentTurn, runGatedAction, readTargetDigest, digestOf, type GatedActionInput, type GatedActionOutcome, type RunTurnInput, type TurnEvent, type ApprovalAnswer, type StopReason, } from "./engine/runAgentTurn";
|
|
21
|
+
export { EvidenceStore, type EvidenceEntry } from "./engine/evidence";
|
|
22
|
+
export { TokenCalibration } from "./engine/tokenCalibration";
|
|
23
|
+
export { buildLiveBlock, buildSystemPrompt, type ContextPack, type Procedure, type SystemPromptInput, } from "./engine/systemPrompt";
|
|
24
|
+
export { buildContextDigest, buildLiveContext, type BuildContextInput, } from "./context/buildContextPack";
|
|
21
25
|
export { EffectLedger, isReversible, type AppliedEffect, type LedgerEntry, type RevertOutcome, } from "./effects/ledger";
|
|
22
26
|
export { humanise, titleCall, toolTitle } from "./policy/labels";
|
|
23
27
|
export * from "./blocks/types";
|
|
@@ -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,qBA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OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjE,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EACL,MAAM,EACN,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,iBAAiB,CAAC;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,CAA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M,CAAC;CACnB;AAED,wGAAwG;AACxG,eAAO,MAAM,wBAAwB,EAAE,YAAY,EAAoB,CAAC;AAExE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,EAAE,CAE5E;AAED,MAAM,MAAM,QAAQ,GAChB;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GACpB;IAAE,OAAO,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,gBAAgB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,2CAA2C;IAC3C,SAAS,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"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA2EjB,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAySxE"}
|
|
@@ -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;AA8DjB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAkNrE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What kind of failure a provider reported — decided once, from the status,
|
|
3
|
+
* the error type and the message, so the engine can act on the KIND rather
|
|
4
|
+
* than grep a string.
|
|
5
|
+
*
|
|
6
|
+
* Only two kinds are acted on, and both only when nothing has been generated:
|
|
7
|
+
*
|
|
8
|
+
* - `throttled` — 429 / 529 / 503, a `rate_limit_error` or `overloaded_error`
|
|
9
|
+
* frame, or a body that says so. Waiting and asking again is the right move;
|
|
10
|
+
* the request never reached a model.
|
|
11
|
+
* - `overflow` — the provider refused the request as too big. Trimming older
|
|
12
|
+
* history and asking once more is the right move; the proactive budget is
|
|
13
|
+
* an estimate (chars ÷ 4) and JSON tokenizes worse than prose.
|
|
14
|
+
*
|
|
15
|
+
* Everything else — auth, a bad schema, an unknown model, a mid-answer
|
|
16
|
+
* `api_error` — is reported and NOT retried. The phrase lists are the union
|
|
17
|
+
* observed across provider responses by the Strands SDK (harness-sdk
|
|
18
|
+
* `381ab48`, `models/anthropic.ts` + `models/openai/errors.ts`, Apache-2.0),
|
|
19
|
+
* matched case-insensitively on the lowered message.
|
|
20
|
+
*/
|
|
21
|
+
export type ProblemKind = "throttled" | "overflow" | "auth" | "other";
|
|
22
|
+
export interface StreamProblem {
|
|
23
|
+
kind: ProblemKind;
|
|
24
|
+
/** HTTP status, when the failure was an HTTP response. */
|
|
25
|
+
status?: number;
|
|
26
|
+
/** A `Retry-After` the endpoint sent, in ms — honoured over the backoff. */
|
|
27
|
+
retryAfterMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface ClassifyInput {
|
|
30
|
+
status?: number;
|
|
31
|
+
/** The provider's error `type` (or OpenAI `code`), when the body was parsed. */
|
|
32
|
+
type?: string;
|
|
33
|
+
message: string;
|
|
34
|
+
/** Raw `Retry-After` header value — seconds, or an HTTP date. */
|
|
35
|
+
retryAfter?: string | null;
|
|
36
|
+
}
|
|
37
|
+
export declare function classifyProblem(input: ClassifyInput): StreamProblem;
|
|
38
|
+
/**
|
|
39
|
+
* `Retry-After` is either delay-seconds or an HTTP-date. Anything unparseable
|
|
40
|
+
* or in the past is undefined, so the caller falls back to its own backoff.
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseRetryAfter(value: string | null | undefined): number | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Pull the provider's error `type` out of an error body, for the HTTP path
|
|
45
|
+
* where the body is JSON like `{"error":{"type":"overloaded_error",…}}` or
|
|
46
|
+
* `{"error":{"code":"context_length_exceeded",…}}`. Returns undefined for
|
|
47
|
+
* anything that is not that shape; the message phrases still apply.
|
|
48
|
+
*/
|
|
49
|
+
export declare function errorTypeOf(body: string): string | undefined;
|
|
50
|
+
//# sourceMappingURL=problem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.d.ts","sourceRoot":"","sources":["../../../src/providers/problem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAEtE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA8BD,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAoBnE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAQpF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAS5D"}
|
|
@@ -7,12 +7,96 @@
|
|
|
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
|
|
16
|
-
/**
|
|
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>;
|
|
81
|
+
/**
|
|
82
|
+
* Body text for a failed response, trimmed to something a user can read.
|
|
83
|
+
* The detail alone — the transport prefixes the status and classifies it.
|
|
84
|
+
*/
|
|
17
85
|
export declare function errorBody(response: Response): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* The message for a stream that stopped before the provider said it was done.
|
|
88
|
+
*
|
|
89
|
+
* `truncated` distinguishes the two shapes: cut mid-frame (a dropped
|
|
90
|
+
* connection) versus a clean frame boundary with no terminal marker (a gateway
|
|
91
|
+
* that closes the socket instead of sending one). The second is a
|
|
92
|
+
* compatibility problem worth naming, because retrying it will not help.
|
|
93
|
+
*/
|
|
94
|
+
export declare function truncatedMessage(truncated: boolean): string;
|
|
95
|
+
/**
|
|
96
|
+
* The message for arguments that would not parse, with enough in it to act on.
|
|
97
|
+
* `stopReason` "length" is the common cause — a reasoning model spends its
|
|
98
|
+
* budget thinking and the tool call is truncated mid-JSON — and the tail of
|
|
99
|
+
* the raw arguments says immediately whether that is what happened.
|
|
100
|
+
*/
|
|
101
|
+
export declare function unparseableMessage(name: string, args: string, stopReason?: string): string;
|
|
18
102
|
//# 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;;;GAGG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAMnE;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,48 @@
|
|
|
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
|
+
import { type StreamProblem } from "./problem";
|
|
22
|
+
export type TransportKind = "fetch" | "xhr" | "auto";
|
|
23
|
+
export interface OpenStreamRequest {
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
body: string;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}
|
|
28
|
+
export interface OpenStreamResult {
|
|
29
|
+
/** A message when the request failed or is not a stream; frames are empty. */
|
|
30
|
+
problem?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The failure, classified — see providers/problem.ts. Present whenever
|
|
33
|
+
* `problem` is an HTTP failure; a not-a-stream body is `other`. The engine
|
|
34
|
+
* retries `throttled` and `overflow` when nothing was generated, and this
|
|
35
|
+
* is the only place the status and `Retry-After` header are still in hand.
|
|
36
|
+
*/
|
|
37
|
+
problemInfo?: StreamProblem;
|
|
38
|
+
frames(options?: SseReadOptions): AsyncGenerator<SseEvent, void, void>;
|
|
39
|
+
}
|
|
40
|
+
export interface Transport {
|
|
41
|
+
open(req: OpenStreamRequest): Promise<OpenStreamResult>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* One transport per provider instance, because the `auto` decision is worth
|
|
45
|
+
* remembering: re-learning it would buffer the first reply of every turn.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createTransport(config: ProviderConfig): Transport;
|
|
48
|
+
//# 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;AAEf,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE7E,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;;;;;OAKG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,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,CAmFjE"}
|