@buoy-gg/agent-core 7.0.34 → 7.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/lib/commonjs/blocks/receipts.js +83 -24
- package/lib/commonjs/blocks/receipts.js.map +1 -1
- package/lib/commonjs/blocks/runId.js +31 -0
- package/lib/commonjs/blocks/runId.js.map +1 -0
- package/lib/commonjs/blocks/types.js +23 -2
- package/lib/commonjs/blocks/types.js.map +1 -1
- package/lib/commonjs/blocks/uiTool.js +426 -12
- package/lib/commonjs/blocks/uiTool.js.map +1 -1
- package/lib/commonjs/catalog/catalog.g.js +121 -43
- package/lib/commonjs/catalog/catalog.g.js.map +1 -1
- package/lib/commonjs/catalog/catalog.source.json +121 -45
- package/lib/commonjs/catalog/catalog.types.g.js +44 -0
- package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
- package/lib/commonjs/catalog/normalizeParams.js +333 -0
- package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
- package/lib/commonjs/catalog/signature.js +68 -0
- package/lib/commonjs/catalog/signature.js.map +1 -0
- package/lib/commonjs/catalog/snapshotReads.js +13 -6
- package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
- package/lib/commonjs/catalog/toProviderTools.js +41 -5
- package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
- package/lib/commonjs/context/buildContextPack.js +367 -19
- package/lib/commonjs/context/buildContextPack.js.map +1 -1
- package/lib/commonjs/effects/digest.js +34 -0
- package/lib/commonjs/effects/digest.js.map +1 -0
- package/lib/commonjs/effects/ledger.js +85 -1
- package/lib/commonjs/effects/ledger.js.map +1 -1
- package/lib/commonjs/engine/askGate.js +287 -0
- package/lib/commonjs/engine/askGate.js.map +1 -0
- package/lib/commonjs/engine/effectFor.js +82 -1
- package/lib/commonjs/engine/effectFor.js.map +1 -1
- package/lib/commonjs/engine/historyBudget.js +260 -0
- package/lib/commonjs/engine/historyBudget.js.map +1 -0
- package/lib/commonjs/engine/runAgentTurn.js +958 -88
- package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
- package/lib/commonjs/engine/systemPrompt.js +72 -8
- package/lib/commonjs/engine/systemPrompt.js.map +1 -1
- package/lib/commonjs/engine/textToolCalls.js +276 -0
- package/lib/commonjs/engine/textToolCalls.js.map +1 -0
- package/lib/commonjs/index.js +81 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/policy/labels.js +19 -3
- package/lib/commonjs/policy/labels.js.map +1 -1
- package/lib/commonjs/policy/policy.js +6 -1
- package/lib/commonjs/policy/policy.js.map +1 -1
- package/lib/commonjs/policy/redact.js +42 -5
- package/lib/commonjs/policy/redact.js.map +1 -1
- package/lib/commonjs/providers/anthropic.js +340 -174
- package/lib/commonjs/providers/anthropic.js.map +1 -1
- package/lib/commonjs/providers/openai.js +229 -103
- package/lib/commonjs/providers/openai.js.map +1 -1
- package/lib/commonjs/providers/sse.js +164 -29
- package/lib/commonjs/providers/sse.js.map +1 -1
- package/lib/commonjs/providers/streamTimer.js +123 -0
- package/lib/commonjs/providers/streamTimer.js.map +1 -0
- package/lib/commonjs/providers/transport.js +107 -0
- package/lib/commonjs/providers/transport.js.map +1 -0
- package/lib/commonjs/providers/xhrStream.js +209 -0
- package/lib/commonjs/providers/xhrStream.js.map +1 -0
- package/lib/commonjs/session.js +245 -52
- package/lib/commonjs/session.js.map +1 -1
- package/lib/module/blocks/receipts.js +83 -24
- package/lib/module/blocks/receipts.js.map +1 -1
- package/lib/module/blocks/runId.js +26 -0
- package/lib/module/blocks/runId.js.map +1 -0
- package/lib/module/blocks/types.js +23 -2
- package/lib/module/blocks/types.js.map +1 -1
- package/lib/module/blocks/uiTool.js +424 -12
- package/lib/module/blocks/uiTool.js.map +1 -1
- package/lib/module/catalog/catalog.g.js +121 -43
- package/lib/module/catalog/catalog.g.js.map +1 -1
- package/lib/module/catalog/catalog.source.json +121 -45
- package/lib/module/catalog/catalog.types.g.js +40 -0
- package/lib/module/catalog/catalog.types.g.js.map +1 -0
- package/lib/module/catalog/normalizeParams.js +327 -0
- package/lib/module/catalog/normalizeParams.js.map +1 -0
- package/lib/module/catalog/signature.js +63 -0
- package/lib/module/catalog/signature.js.map +1 -0
- package/lib/module/catalog/snapshotReads.js +13 -6
- package/lib/module/catalog/snapshotReads.js.map +1 -1
- package/lib/module/catalog/toProviderTools.js +41 -5
- package/lib/module/catalog/toProviderTools.js.map +1 -1
- package/lib/module/context/buildContextPack.js +366 -19
- package/lib/module/context/buildContextPack.js.map +1 -1
- package/lib/module/effects/digest.js +29 -0
- package/lib/module/effects/digest.js.map +1 -0
- package/lib/module/effects/ledger.js +85 -1
- package/lib/module/effects/ledger.js.map +1 -1
- package/lib/module/engine/askGate.js +280 -0
- package/lib/module/engine/askGate.js.map +1 -0
- package/lib/module/engine/effectFor.js +83 -1
- package/lib/module/engine/effectFor.js.map +1 -1
- package/lib/module/engine/historyBudget.js +251 -0
- package/lib/module/engine/historyBudget.js.map +1 -0
- package/lib/module/engine/runAgentTurn.js +954 -88
- package/lib/module/engine/runAgentTurn.js.map +1 -1
- package/lib/module/engine/systemPrompt.js +71 -8
- package/lib/module/engine/systemPrompt.js.map +1 -1
- package/lib/module/engine/textToolCalls.js +270 -0
- package/lib/module/engine/textToolCalls.js.map +1 -0
- package/lib/module/index.js +7 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/policy/labels.js +19 -3
- package/lib/module/policy/labels.js.map +1 -1
- package/lib/module/policy/policy.js +6 -1
- package/lib/module/policy/policy.js.map +1 -1
- package/lib/module/policy/redact.js +42 -5
- package/lib/module/policy/redact.js.map +1 -1
- package/lib/module/providers/anthropic.js +341 -175
- package/lib/module/providers/anthropic.js.map +1 -1
- package/lib/module/providers/openai.js +230 -104
- package/lib/module/providers/openai.js.map +1 -1
- package/lib/module/providers/sse.js +160 -29
- package/lib/module/providers/sse.js.map +1 -1
- package/lib/module/providers/streamTimer.js +118 -0
- package/lib/module/providers/streamTimer.js.map +1 -0
- package/lib/module/providers/transport.js +103 -0
- package/lib/module/providers/transport.js.map +1 -0
- package/lib/module/providers/xhrStream.js +204 -0
- package/lib/module/providers/xhrStream.js.map +1 -0
- package/lib/module/session.js +228 -54
- package/lib/module/session.js.map +1 -1
- package/lib/typescript/blocks/receipts.d.ts +5 -10
- package/lib/typescript/blocks/receipts.d.ts.map +1 -1
- package/lib/typescript/blocks/runId.d.ts +20 -0
- package/lib/typescript/blocks/runId.d.ts.map +1 -0
- package/lib/typescript/blocks/types.d.ts +23 -2
- package/lib/typescript/blocks/types.d.ts.map +1 -1
- package/lib/typescript/blocks/uiTool.d.ts +11 -2
- package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
- package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
- package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
- package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
- package/lib/typescript/catalog/signature.d.ts +29 -0
- package/lib/typescript/catalog/signature.d.ts.map +1 -0
- package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
- package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
- package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
- package/lib/typescript/context/buildContextPack.d.ts +24 -2
- package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
- package/lib/typescript/effects/digest.d.ts +10 -0
- package/lib/typescript/effects/digest.d.ts.map +1 -0
- package/lib/typescript/effects/ledger.d.ts +55 -0
- package/lib/typescript/effects/ledger.d.ts.map +1 -1
- package/lib/typescript/engine/askGate.d.ts +29 -0
- package/lib/typescript/engine/askGate.d.ts.map +1 -0
- package/lib/typescript/engine/effectFor.d.ts +6 -1
- package/lib/typescript/engine/effectFor.d.ts.map +1 -1
- package/lib/typescript/engine/historyBudget.d.ts +92 -0
- package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
- package/lib/typescript/engine/runAgentTurn.d.ts +115 -1
- package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
- package/lib/typescript/engine/systemPrompt.d.ts +41 -0
- package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
- package/lib/typescript/engine/textToolCalls.d.ts +58 -0
- package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/policy/labels.d.ts.map +1 -1
- package/lib/typescript/policy/policy.d.ts.map +1 -1
- package/lib/typescript/policy/redact.d.ts.map +1 -1
- package/lib/typescript/providers/anthropic.d.ts +5 -0
- package/lib/typescript/providers/anthropic.d.ts.map +1 -1
- package/lib/typescript/providers/openai.d.ts +0 -16
- package/lib/typescript/providers/openai.d.ts.map +1 -1
- package/lib/typescript/providers/sse.d.ts +82 -1
- package/lib/typescript/providers/sse.d.ts.map +1 -1
- package/lib/typescript/providers/streamTimer.d.ts +59 -0
- package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
- package/lib/typescript/providers/transport.d.ts +40 -0
- package/lib/typescript/providers/transport.d.ts.map +1 -0
- package/lib/typescript/providers/types.d.ts +116 -3
- package/lib/typescript/providers/types.d.ts.map +1 -1
- package/lib/typescript/providers/xhrStream.d.ts +43 -0
- package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
- package/lib/typescript/session.d.ts +63 -2
- package/lib/typescript/session.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -24,6 +24,25 @@ export interface ToolResult {
|
|
|
24
24
|
content: string;
|
|
25
25
|
isError?: boolean;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* An Anthropic thinking block, kept verbatim.
|
|
29
|
+
*
|
|
30
|
+
* Every current Claude model thinks by DEFAULT, and the API requires the
|
|
31
|
+
* thinking blocks of the assistant turn that made a tool call to come back
|
|
32
|
+
* unchanged with the tool results — signature included. Drop them and the
|
|
33
|
+
* next request is a 400 ("Expected `thinking` or `redacted_thinking`"), which
|
|
34
|
+
* is every tool-using turn, i.e. all of them. So the adapter captures these
|
|
35
|
+
* and replays them; nothing else in the engine reads them, and the OpenAI
|
|
36
|
+
* adapter ignores the field.
|
|
37
|
+
*/
|
|
38
|
+
export type ThinkingBlock = {
|
|
39
|
+
type: "thinking";
|
|
40
|
+
thinking: string;
|
|
41
|
+
signature: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: "redacted_thinking";
|
|
44
|
+
data: string;
|
|
45
|
+
};
|
|
27
46
|
export type AgentMessage = {
|
|
28
47
|
role: "user";
|
|
29
48
|
text: string;
|
|
@@ -31,10 +50,40 @@ export type AgentMessage = {
|
|
|
31
50
|
role: "assistant";
|
|
32
51
|
text: string;
|
|
33
52
|
toolCalls?: ToolCall[];
|
|
53
|
+
thinking?: ThinkingBlock[];
|
|
34
54
|
} | {
|
|
35
55
|
role: "tool-results";
|
|
36
56
|
results: ToolResult[];
|
|
37
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";
|
|
38
87
|
/** Incremental output from a streaming turn. */
|
|
39
88
|
export type StreamEvent = {
|
|
40
89
|
type: "text";
|
|
@@ -43,14 +92,31 @@ export type StreamEvent = {
|
|
|
43
92
|
type: "tool-call";
|
|
44
93
|
call: ToolCall;
|
|
45
94
|
}
|
|
95
|
+
/** A completed thinking block, to be replayed on the next request. */
|
|
96
|
+
| {
|
|
97
|
+
type: "thinking";
|
|
98
|
+
block: ThinkingBlock;
|
|
99
|
+
}
|
|
46
100
|
/** Mid-stream provider error. Anthropic can emit these on a committed 200. */
|
|
47
101
|
| {
|
|
48
102
|
type: "error";
|
|
49
103
|
message: string;
|
|
50
|
-
|
|
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
|
+
| {
|
|
51
115
|
type: "done";
|
|
116
|
+
outcome: StreamOutcome;
|
|
52
117
|
stopReason?: string;
|
|
53
118
|
usage?: TokenUsage;
|
|
119
|
+
model?: string;
|
|
54
120
|
};
|
|
55
121
|
export interface TokenUsage {
|
|
56
122
|
input: number;
|
|
@@ -59,8 +125,10 @@ export interface TokenUsage {
|
|
|
59
125
|
* Anthropic's prompt-cache counters, when the provider reports them.
|
|
60
126
|
* `cacheRead` is the prefix that was served from cache at 0.1x — the whole
|
|
61
127
|
* point of caching — and `cacheWrite` is the prefix stored at 1.25x on the
|
|
62
|
-
* request that populated it.
|
|
63
|
-
*
|
|
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`
|
|
64
132
|
* rather than a smaller `input`; adding them is what gives the real total.
|
|
65
133
|
*/
|
|
66
134
|
cacheRead?: number;
|
|
@@ -69,6 +137,13 @@ export interface TokenUsage {
|
|
|
69
137
|
export interface ProviderRequest {
|
|
70
138
|
messages: AgentMessage[];
|
|
71
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;
|
|
72
147
|
tools: ProviderTool[];
|
|
73
148
|
model: string;
|
|
74
149
|
maxTokens: number;
|
|
@@ -107,6 +182,25 @@ export interface ProviderConfig {
|
|
|
107
182
|
* Set false for a gateway that rejects unknown `cache_control` fields.
|
|
108
183
|
*/
|
|
109
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;
|
|
110
204
|
/**
|
|
111
205
|
* Extra fields merged into every request BODY, last — `temperature`, a
|
|
112
206
|
* gateway's routing hints, whatever the endpoint demands that this config
|
|
@@ -115,6 +209,25 @@ export interface ProviderConfig {
|
|
|
115
209
|
* stream) win only if you don't override them, so use with care.
|
|
116
210
|
*/
|
|
117
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;
|
|
118
231
|
}
|
|
119
232
|
export interface Provider {
|
|
120
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,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;CAAE,
|
|
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;IA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;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,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"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type TurnEvent } from "./engine/runAgentTurn";
|
|
2
2
|
import { type ContextPack } from "./engine/systemPrompt";
|
|
3
3
|
import { EffectLedger } from "./effects/ledger";
|
|
4
|
-
import
|
|
4
|
+
import { compressConsumed, trimHistory, trimHistoryReport } from "./engine/historyBudget";
|
|
5
|
+
import type { AgentMessage, Provider, ProviderConfig } from "./providers/types";
|
|
5
6
|
import { type AskBuoyPolicy } from "./policy/policy";
|
|
6
7
|
import type { DispatchFn, SnapshotFn, ToolDescriptor } from "./types";
|
|
7
8
|
export interface AskBuoySessionConfig extends ProviderConfig {
|
|
@@ -26,6 +27,12 @@ export interface AskBuoySessionConfig extends ProviderConfig {
|
|
|
26
27
|
/** Override the built-in catalog. Tests and the desktop port use this. */
|
|
27
28
|
catalog?: ToolDescriptor[];
|
|
28
29
|
requestApproval?: RunApproval;
|
|
30
|
+
/**
|
|
31
|
+
* A ready-made provider, injected by tests and benches — a scripted one,
|
|
32
|
+
* or a real adapter wrapped for capture. Otherwise the session builds one
|
|
33
|
+
* from `protocol` and the ProviderConfig fields.
|
|
34
|
+
*/
|
|
35
|
+
provider?: Provider;
|
|
29
36
|
}
|
|
30
37
|
type RunApproval = (input: {
|
|
31
38
|
id: string;
|
|
@@ -34,10 +41,20 @@ type RunApproval = (input: {
|
|
|
34
41
|
label: string;
|
|
35
42
|
description: string;
|
|
36
43
|
reason: string;
|
|
44
|
+
/** The call itself — see `RunInput.requestApproval` for why it travels. */
|
|
45
|
+
params: Record<string, unknown>;
|
|
46
|
+
/** Fingerprint of the target at ask time — see `readTargetDigest`. */
|
|
47
|
+
targetDigest?: string;
|
|
37
48
|
}) => Promise<boolean>;
|
|
38
49
|
export interface AskBuoySession {
|
|
39
50
|
readonly ledger: EffectLedger;
|
|
40
51
|
readonly messages: AgentMessage[];
|
|
52
|
+
/**
|
|
53
|
+
* Reinstate a conversation from a previous run of the app, so the model
|
|
54
|
+
* remembers what was said before a reload or a crash. The history is
|
|
55
|
+
* sanitised first — see `resumableHistory`.
|
|
56
|
+
*/
|
|
57
|
+
restore(history: AgentMessage[]): void;
|
|
41
58
|
/** Probe the app for grounding. Safe to call more than once. */
|
|
42
59
|
prime(): Promise<void>;
|
|
43
60
|
/**
|
|
@@ -50,9 +67,53 @@ export interface AskBuoySession {
|
|
|
50
67
|
* separate store and kept rendering. Update in place instead.
|
|
51
68
|
*/
|
|
52
69
|
setAvailableActions(actions: Record<string, string[]>): void;
|
|
70
|
+
/**
|
|
71
|
+
* Turn this device's approval cards off, or back on.
|
|
72
|
+
*
|
|
73
|
+
* A DEVICE preference ("stop asking me"), not app policy — which is why it
|
|
74
|
+
* is a setter rather than a field on the config. The session is held across
|
|
75
|
+
* close and reopen so the conversation and the undo ledger survive, so a
|
|
76
|
+
* value captured when it was built could not be changed afterwards without
|
|
77
|
+
* throwing both away.
|
|
78
|
+
*
|
|
79
|
+
* It suppresses approval GATES only. `deny`, `allow`, `readOnly` and the
|
|
80
|
+
* release-build refusals are the app saying no, not the app asking a
|
|
81
|
+
* question, and a "stop asking" toggle must never widen what the agent can
|
|
82
|
+
* reach.
|
|
83
|
+
*/
|
|
84
|
+
setApprovalBypass(enabled: boolean): void;
|
|
85
|
+
/**
|
|
86
|
+
* The device's "look, don't touch" toggle.
|
|
87
|
+
*
|
|
88
|
+
* Effective policy is app read-only OR device read-only: this can only
|
|
89
|
+
* NARROW what the agent may do, never widen it — turning the device toggle
|
|
90
|
+
* off cannot switch off an app that configured `policy.readOnly`. Takes
|
|
91
|
+
* effect on the next call, including the remaining calls of a turn already
|
|
92
|
+
* running: the engine reads the policy object per call, and this mutates
|
|
93
|
+
* that object in place rather than handing the engine a new one at the next
|
|
94
|
+
* turn.
|
|
95
|
+
*/
|
|
96
|
+
setReadOnly(enabled: boolean): void;
|
|
53
97
|
send(text: string, signal?: AbortSignal): AsyncGenerator<TurnEvent, void, void>;
|
|
54
98
|
reset(): void;
|
|
55
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* A stored history, made safe to send as the start of a new request.
|
|
102
|
+
*
|
|
103
|
+
* Two things make a saved conversation unusable as-is.
|
|
104
|
+
*
|
|
105
|
+
* A history captured mid-turn ends with an assistant message whose `tool_use`
|
|
106
|
+
* blocks were never answered, or with the `tool_result`s and no reply after
|
|
107
|
+
* them. Every provider rejects both: the blocks must pair up. So this rewinds
|
|
108
|
+
* to the last COMPLETE round — an assistant message that made no tool calls,
|
|
109
|
+
* which is where a conversation is always safe to resume from.
|
|
110
|
+
*
|
|
111
|
+
* And thinking blocks are dropped. Anthropic needs them replayed only when the
|
|
112
|
+
* very next thing sent is that turn's `tool_result`s; a restored conversation
|
|
113
|
+
* always resumes with a fresh user message instead, so their signatures are
|
|
114
|
+
* dead weight at best and a stale-signature 400 at worst.
|
|
115
|
+
*/
|
|
116
|
+
export { compressConsumed, trimHistory, trimHistoryReport };
|
|
117
|
+
export declare function resumableHistory(history: AgentMessage[]): AgentMessage[];
|
|
56
118
|
export declare function createAskBuoySession(config: AskBuoySessionConfig): AskBuoySession;
|
|
57
|
-
export {};
|
|
58
119
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;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
|
4
4
|
"description": "Headless agent core for Ask Buoy - the tool catalog, BYO-model providers, turn loop and effect ledger that let an LLM drive Buoy devtools",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"bugs": {
|
|
44
44
|
"url": "https://github.com/LovesWorking/react-native-buoy/issues"
|
|
45
45
|
},
|
|
46
|
-
"homepage": "https://
|
|
46
|
+
"homepage": "https://buoy.gg/buoy/latest/docs/tools/ask-buoy",
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|
|
49
49
|
"tag": "latest"
|