@buoy-gg/agent-core 7.0.35 → 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.
Files changed (174) hide show
  1. package/README.md +10 -7
  2. package/lib/commonjs/blocks/receipts.js +57 -1
  3. package/lib/commonjs/blocks/receipts.js.map +1 -1
  4. package/lib/commonjs/blocks/types.js +23 -2
  5. package/lib/commonjs/blocks/types.js.map +1 -1
  6. package/lib/commonjs/blocks/uiTool.js +423 -10
  7. package/lib/commonjs/blocks/uiTool.js.map +1 -1
  8. package/lib/commonjs/catalog/catalog.g.js +121 -43
  9. package/lib/commonjs/catalog/catalog.g.js.map +1 -1
  10. package/lib/commonjs/catalog/catalog.source.json +121 -45
  11. package/lib/commonjs/catalog/catalog.types.g.js +44 -0
  12. package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
  13. package/lib/commonjs/catalog/normalizeParams.js +333 -0
  14. package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
  15. package/lib/commonjs/catalog/signature.js +68 -0
  16. package/lib/commonjs/catalog/signature.js.map +1 -0
  17. package/lib/commonjs/catalog/snapshotReads.js +13 -6
  18. package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
  19. package/lib/commonjs/catalog/toProviderTools.js +41 -5
  20. package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
  21. package/lib/commonjs/context/buildContextPack.js +367 -19
  22. package/lib/commonjs/context/buildContextPack.js.map +1 -1
  23. package/lib/commonjs/effects/digest.js +34 -0
  24. package/lib/commonjs/effects/digest.js.map +1 -0
  25. package/lib/commonjs/effects/ledger.js +85 -1
  26. package/lib/commonjs/effects/ledger.js.map +1 -1
  27. package/lib/commonjs/engine/askGate.js +287 -0
  28. package/lib/commonjs/engine/askGate.js.map +1 -0
  29. package/lib/commonjs/engine/effectFor.js +82 -1
  30. package/lib/commonjs/engine/effectFor.js.map +1 -1
  31. package/lib/commonjs/engine/historyBudget.js +260 -0
  32. package/lib/commonjs/engine/historyBudget.js.map +1 -0
  33. package/lib/commonjs/engine/runAgentTurn.js +924 -83
  34. package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
  35. package/lib/commonjs/engine/systemPrompt.js +72 -8
  36. package/lib/commonjs/engine/systemPrompt.js.map +1 -1
  37. package/lib/commonjs/engine/textToolCalls.js +276 -0
  38. package/lib/commonjs/engine/textToolCalls.js.map +1 -0
  39. package/lib/commonjs/index.js +58 -0
  40. package/lib/commonjs/index.js.map +1 -1
  41. package/lib/commonjs/policy/labels.js +19 -3
  42. package/lib/commonjs/policy/labels.js.map +1 -1
  43. package/lib/commonjs/policy/policy.js +6 -1
  44. package/lib/commonjs/policy/policy.js.map +1 -1
  45. package/lib/commonjs/policy/redact.js +42 -5
  46. package/lib/commonjs/policy/redact.js.map +1 -1
  47. package/lib/commonjs/providers/anthropic.js +331 -208
  48. package/lib/commonjs/providers/anthropic.js.map +1 -1
  49. package/lib/commonjs/providers/openai.js +229 -103
  50. package/lib/commonjs/providers/openai.js.map +1 -1
  51. package/lib/commonjs/providers/sse.js +164 -29
  52. package/lib/commonjs/providers/sse.js.map +1 -1
  53. package/lib/commonjs/providers/streamTimer.js +123 -0
  54. package/lib/commonjs/providers/streamTimer.js.map +1 -0
  55. package/lib/commonjs/providers/transport.js +107 -0
  56. package/lib/commonjs/providers/transport.js.map +1 -0
  57. package/lib/commonjs/providers/xhrStream.js +209 -0
  58. package/lib/commonjs/providers/xhrStream.js.map +1 -0
  59. package/lib/commonjs/session.js +215 -58
  60. package/lib/commonjs/session.js.map +1 -1
  61. package/lib/module/blocks/receipts.js +57 -1
  62. package/lib/module/blocks/receipts.js.map +1 -1
  63. package/lib/module/blocks/types.js +23 -2
  64. package/lib/module/blocks/types.js.map +1 -1
  65. package/lib/module/blocks/uiTool.js +421 -10
  66. package/lib/module/blocks/uiTool.js.map +1 -1
  67. package/lib/module/catalog/catalog.g.js +121 -43
  68. package/lib/module/catalog/catalog.g.js.map +1 -1
  69. package/lib/module/catalog/catalog.source.json +121 -45
  70. package/lib/module/catalog/catalog.types.g.js +40 -0
  71. package/lib/module/catalog/catalog.types.g.js.map +1 -0
  72. package/lib/module/catalog/normalizeParams.js +327 -0
  73. package/lib/module/catalog/normalizeParams.js.map +1 -0
  74. package/lib/module/catalog/signature.js +63 -0
  75. package/lib/module/catalog/signature.js.map +1 -0
  76. package/lib/module/catalog/snapshotReads.js +13 -6
  77. package/lib/module/catalog/snapshotReads.js.map +1 -1
  78. package/lib/module/catalog/toProviderTools.js +41 -5
  79. package/lib/module/catalog/toProviderTools.js.map +1 -1
  80. package/lib/module/context/buildContextPack.js +366 -19
  81. package/lib/module/context/buildContextPack.js.map +1 -1
  82. package/lib/module/effects/digest.js +29 -0
  83. package/lib/module/effects/digest.js.map +1 -0
  84. package/lib/module/effects/ledger.js +85 -1
  85. package/lib/module/effects/ledger.js.map +1 -1
  86. package/lib/module/engine/askGate.js +280 -0
  87. package/lib/module/engine/askGate.js.map +1 -0
  88. package/lib/module/engine/effectFor.js +83 -1
  89. package/lib/module/engine/effectFor.js.map +1 -1
  90. package/lib/module/engine/historyBudget.js +251 -0
  91. package/lib/module/engine/historyBudget.js.map +1 -0
  92. package/lib/module/engine/runAgentTurn.js +920 -83
  93. package/lib/module/engine/runAgentTurn.js.map +1 -1
  94. package/lib/module/engine/systemPrompt.js +71 -8
  95. package/lib/module/engine/systemPrompt.js.map +1 -1
  96. package/lib/module/engine/textToolCalls.js +270 -0
  97. package/lib/module/engine/textToolCalls.js.map +1 -0
  98. package/lib/module/index.js +5 -3
  99. package/lib/module/index.js.map +1 -1
  100. package/lib/module/policy/labels.js +19 -3
  101. package/lib/module/policy/labels.js.map +1 -1
  102. package/lib/module/policy/policy.js +6 -1
  103. package/lib/module/policy/policy.js.map +1 -1
  104. package/lib/module/policy/redact.js +42 -5
  105. package/lib/module/policy/redact.js.map +1 -1
  106. package/lib/module/providers/anthropic.js +332 -209
  107. package/lib/module/providers/anthropic.js.map +1 -1
  108. package/lib/module/providers/openai.js +230 -104
  109. package/lib/module/providers/openai.js.map +1 -1
  110. package/lib/module/providers/sse.js +160 -29
  111. package/lib/module/providers/sse.js.map +1 -1
  112. package/lib/module/providers/streamTimer.js +118 -0
  113. package/lib/module/providers/streamTimer.js.map +1 -0
  114. package/lib/module/providers/transport.js +103 -0
  115. package/lib/module/providers/transport.js.map +1 -0
  116. package/lib/module/providers/xhrStream.js +204 -0
  117. package/lib/module/providers/xhrStream.js.map +1 -0
  118. package/lib/module/session.js +199 -60
  119. package/lib/module/session.js.map +1 -1
  120. package/lib/typescript/blocks/receipts.d.ts +5 -0
  121. package/lib/typescript/blocks/receipts.d.ts.map +1 -1
  122. package/lib/typescript/blocks/types.d.ts +23 -2
  123. package/lib/typescript/blocks/types.d.ts.map +1 -1
  124. package/lib/typescript/blocks/uiTool.d.ts +11 -2
  125. package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
  126. package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
  127. package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
  128. package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
  129. package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
  130. package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
  131. package/lib/typescript/catalog/signature.d.ts +29 -0
  132. package/lib/typescript/catalog/signature.d.ts.map +1 -0
  133. package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
  134. package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
  135. package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
  136. package/lib/typescript/context/buildContextPack.d.ts +24 -2
  137. package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
  138. package/lib/typescript/effects/digest.d.ts +10 -0
  139. package/lib/typescript/effects/digest.d.ts.map +1 -0
  140. package/lib/typescript/effects/ledger.d.ts +55 -0
  141. package/lib/typescript/effects/ledger.d.ts.map +1 -1
  142. package/lib/typescript/engine/askGate.d.ts +29 -0
  143. package/lib/typescript/engine/askGate.d.ts.map +1 -0
  144. package/lib/typescript/engine/effectFor.d.ts +6 -1
  145. package/lib/typescript/engine/effectFor.d.ts.map +1 -1
  146. package/lib/typescript/engine/historyBudget.d.ts +92 -0
  147. package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
  148. package/lib/typescript/engine/runAgentTurn.d.ts +83 -1
  149. package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
  150. package/lib/typescript/engine/systemPrompt.d.ts +41 -0
  151. package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
  152. package/lib/typescript/engine/textToolCalls.d.ts +58 -0
  153. package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
  154. package/lib/typescript/index.d.ts +5 -3
  155. package/lib/typescript/index.d.ts.map +1 -1
  156. package/lib/typescript/policy/labels.d.ts.map +1 -1
  157. package/lib/typescript/policy/policy.d.ts.map +1 -1
  158. package/lib/typescript/policy/redact.d.ts.map +1 -1
  159. package/lib/typescript/providers/anthropic.d.ts.map +1 -1
  160. package/lib/typescript/providers/openai.d.ts +0 -16
  161. package/lib/typescript/providers/openai.d.ts.map +1 -1
  162. package/lib/typescript/providers/sse.d.ts +82 -1
  163. package/lib/typescript/providers/sse.d.ts.map +1 -1
  164. package/lib/typescript/providers/streamTimer.d.ts +59 -0
  165. package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
  166. package/lib/typescript/providers/transport.d.ts +40 -0
  167. package/lib/typescript/providers/transport.d.ts.map +1 -0
  168. package/lib/typescript/providers/types.d.ts +91 -3
  169. package/lib/typescript/providers/types.d.ts.map +1 -1
  170. package/lib/typescript/providers/xhrStream.d.ts +43 -0
  171. package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
  172. package/lib/typescript/session.d.ts +40 -2
  173. package/lib/typescript/session.d.ts.map +1 -1
  174. package/package.json +2 -2
@@ -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,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AAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAClC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,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
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 { buildSystemPrompt, type ContextPack, type SystemPromptInput, } from "./engine/systemPrompt";
20
- export { buildContextDigest, type BuildContextInput } from "./context/buildContextPack";
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";
@@ -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;AAE3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,eAAe,EACf,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YA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AE,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":"AA+MA,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAgCD,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
+ {"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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appings":"AAAA;;;;;;;;;;;;;;;GAeG;AAqDH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAazD;AAQD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAQ3D;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
+ {"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;AAyCjB,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CA0MxE"}
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":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EAGf,MAAM,SAAS,CAAC;AA2CjB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CA+GrE"}
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 declare function readSse(response: Response): AsyncGenerator<SseEvent, void, void>;
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"],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YtF;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"}
@@ -55,6 +55,35 @@ export type AgentMessage = {
55
55
  role: "tool-results";
56
56
  results: ToolResult[];
57
57
  };
58
+ /**
59
+ * Why a stream ended, and whether what arrived can be acted on.
60
+ *
61
+ * `completed` is the ONLY value that admits tool calls for execution. The
62
+ * distinction exists because a truncated response is indistinguishable from a
63
+ * finished one by content alone: a connection cut after the model emitted
64
+ * `{"key":"cart","value":[]}` leaves valid JSON and a plausible plan, and the
65
+ * engine used to run it. See `StreamEvent.error.kind` for the other half.
66
+ */
67
+ export type StreamOutcome =
68
+ /** A terminal marker arrived: `message_stop` (Anthropic) or `[DONE]` (OpenAI). */
69
+ "completed"
70
+ /**
71
+ * Terminal marker arrived, but the model was cut off at `max_tokens` mid-plan.
72
+ * The text it managed is real; any tool calls in it are half a thought and
73
+ * are NOT executed.
74
+ */
75
+ | "output-limited";
76
+ /**
77
+ * Why a stream failed. `provider` is the model or gateway saying so; the other
78
+ * two are this side deciding the response cannot be trusted.
79
+ */
80
+ export type StreamErrorKind =
81
+ /** The provider reported it: HTTP error, or an `error` event on a 200. */
82
+ "provider"
83
+ /** The stream ended with no terminal marker. Bare EOF is never success. */
84
+ | "truncated"
85
+ /** No headers within `connectTimeoutMs`, or no bytes within `idleTimeoutMs`. */
86
+ | "timeout";
58
87
  /** Incremental output from a streaming turn. */
59
88
  export type StreamEvent = {
60
89
  type: "text";
@@ -72,10 +101,22 @@ export type StreamEvent = {
72
101
  | {
73
102
  type: "error";
74
103
  message: string;
75
- } | {
104
+ kind: StreamErrorKind;
105
+ }
106
+ /**
107
+ * The stream ended in a state worth acting on. A provider that cannot say
108
+ * this yields an `error` instead — there is no third way out.
109
+ *
110
+ * `model` is the id the provider actually SERVED — `message_start.message.model`
111
+ * on Anthropic, the chunk's `model` on OpenAI — which differs from the one
112
+ * requested whenever a gateway resolves an alias to a dated snapshot.
113
+ */
114
+ | {
76
115
  type: "done";
116
+ outcome: StreamOutcome;
77
117
  stopReason?: string;
78
118
  usage?: TokenUsage;
119
+ model?: string;
79
120
  };
80
121
  export interface TokenUsage {
81
122
  input: number;
@@ -84,8 +125,10 @@ export interface TokenUsage {
84
125
  * Anthropic's prompt-cache counters, when the provider reports them.
85
126
  * `cacheRead` is the prefix that was served from cache at 0.1x — the whole
86
127
  * point of caching — and `cacheWrite` is the prefix stored at 1.25x on the
87
- * request that populated it. Both are reported SEPARATELY from `input` by
88
- * the API, so a cached request shows a tiny `input` and a large `cacheRead`
128
+ * request that populated it. On Anthropic both are reported SEPARATELY from
129
+ * `input`, so a cached request shows a tiny `input` and a large `cacheRead`;
130
+ * on the OpenAI protocol `cacheRead` (from `prompt_tokens_details.cached_tokens`)
131
+ * is INCLUDED in `input` — never add the two there. Otherwise a cached request shows a tiny `input` and a large `cacheRead`
89
132
  * rather than a smaller `input`; adding them is what gives the real total.
90
133
  */
91
134
  cacheRead?: number;
@@ -94,6 +137,13 @@ export interface TokenUsage {
94
137
  export interface ProviderRequest {
95
138
  messages: AgentMessage[];
96
139
  system: string;
140
+ /**
141
+ * The part of the system prompt that changes every turn — the "right now"
142
+ * picture of the app (current route, mounted queries, recent requests).
143
+ * Kept apart from `system` so a provider that caches the stable prefix can
144
+ * append this AFTER its cache breakpoint instead of invalidating it.
145
+ */
146
+ systemVolatile?: string;
97
147
  tools: ProviderTool[];
98
148
  model: string;
99
149
  maxTokens: number;
@@ -132,6 +182,25 @@ export interface ProviderConfig {
132
182
  * Set false for a gateway that rejects unknown `cache_control` fields.
133
183
  */
134
184
  cache?: boolean;
185
+ /**
186
+ * How long to wait for response HEADERS before giving up. Default 30s.
187
+ *
188
+ * There was no clock here at all: a gateway that accepted the socket and
189
+ * never replied left the turn spinning until someone pressed Stop, with the
190
+ * thinking strip still animating. A timeout is not a retry — nothing is
191
+ * re-sent, because a request that may have reached the model is not safe to
192
+ * duplicate.
193
+ */
194
+ connectTimeoutMs?: number;
195
+ /**
196
+ * How long to wait between BYTES once the stream is open. Default 90s.
197
+ *
198
+ * Deliberately generous. Anthropic sends `ping` frames, but an OpenAI-protocol
199
+ * reasoning model can legitimately produce nothing for a long stretch while
200
+ * it thinks, and cutting that off looks exactly like a broken product. Only
201
+ * total silence counts — any frame, including a keepalive comment, resets it.
202
+ */
203
+ idleTimeoutMs?: number;
135
204
  /**
136
205
  * Extra fields merged into every request BODY, last — `temperature`, a
137
206
  * gateway's routing hints, whatever the endpoint demands that this config
@@ -140,6 +209,25 @@ export interface ProviderConfig {
140
209
  * stream) win only if you don't override them, so use with care.
141
210
  */
142
211
  requestOverrides?: Record<string, unknown>;
212
+ /**
213
+ * How to send the request: `fetch`, `xhr`, or `auto` (the default).
214
+ *
215
+ * `auto` starts with `fetch` and switches to XHR for the rest of the session
216
+ * if that first response turns out to have no readable body — which is React
217
+ * Native's own `fetch`, and every runtime without `expo/fetch` installed as
218
+ * the global. Pin it to `"xhr"` in a bare-RN app to stream from the very
219
+ * first reply instead of the second; pin it to `"fetch"` to rule XHR out.
220
+ * See providers/transport.ts for why the choice cannot be made later.
221
+ */
222
+ transport?: "fetch" | "xhr" | "auto";
223
+ /**
224
+ * The fetch to send requests with. Default: the global one. A harness
225
+ * passes its own so a network interceptor that wraps the global fetch
226
+ * stays off model traffic (it would otherwise capture — and could
227
+ * override — the agent's own requests), and so it can keep every request
228
+ * body it sent.
229
+ */
230
+ fetch?: typeof fetch;
143
231
  }
144
232
  export interface Provider {
145
233
  readonly protocol: "anthropic" | "openai";
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,oEAAoE;AACpE,MAAM,WAAW,QAAQ;IACvB,+DAA+D;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,MAAM,MAAM,YAAY,GACpB;IAAE,IA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CAAC,CAAC;IAC3C;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC1C;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,eAAe,GAAG,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;CACrE"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Streaming over `XMLHttpRequest`, for the runtimes where `fetch` cannot.
3
+ *
4
+ * React Native core still has no `response.body`: its `fetch` is the whatwg
5
+ * polyfill over XHR and resolves inside `xhr.onload`, i.e. after the ENTIRE
6
+ * body. Under Expo the global is `expo/fetch`, which does stream — but
7
+ * `EXPO_PUBLIC_USE_RN_FETCH=1` reverts that, and the bare-RN CLI, TV CLI and
8
+ * NativeScript lanes never had it at all. On those, every Ask Buoy answer
9
+ * appeared in one lump, however long the model took.
10
+ *
11
+ * XHR itself has streamed the whole time. `responseText` grows as bytes arrive
12
+ * and `onprogress` fires as it does, so slicing from the last offset gives the
13
+ * same incremental text a reader would. Two conditions, both easy to miss:
14
+ * the progress handler must be installed BEFORE `send()`, and `responseType`
15
+ * must stay text — anything else stops RN emitting progress at all.
16
+ *
17
+ * WHAT THIS IS NOT. It is not a second SSE parser: framing, the truncation
18
+ * rule and the terminal-marker contract all live in `sse.ts` and are shared
19
+ * verbatim. This file only produces text chunks.
20
+ */
21
+ import { type SseEvent, type SseReadOptions } from "./sse";
22
+ export interface XhrStreamRequest {
23
+ url: string;
24
+ headers: Record<string, string>;
25
+ body: string;
26
+ signal?: AbortSignal;
27
+ }
28
+ export interface XhrStreamResponse {
29
+ status: number;
30
+ ok: boolean;
31
+ contentType: string;
32
+ /** Whole body, for the non-2xx and not-a-stream paths. Reads what arrived. */
33
+ text(): Promise<string>;
34
+ frames(options?: SseReadOptions): AsyncGenerator<SseEvent, void, void>;
35
+ }
36
+ export declare function xhrAvailable(): boolean;
37
+ /**
38
+ * Send the request and resolve once the HEADERS are in, so the caller can
39
+ * check the status and content type before deciding to read a stream — the
40
+ * same shape `fetch` offers, and the reason this can slot in beside it.
41
+ */
42
+ export declare function xhrStream(req: XhrStreamRequest): Promise<XhrStreamResponse>;
43
+ //# sourceMappingURL=xhrStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhrStream.d.ts","sourceRoot":"","sources":["../../../src/providers/xhrStream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAc,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAKvE,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;CACxE;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA+K3E"}