@rarebit-one/harness-kernel 0.10.0 → 0.11.0-next.1
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 +160 -6
- package/dist/agent.d.ts +117 -8
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +332 -25
- package/dist/agent.js.map +1 -1
- package/dist/engines/native.d.ts +5 -0
- package/dist/engines/native.d.ts.map +1 -1
- package/dist/engines/native.js +30 -10
- package/dist/engines/native.js.map +1 -1
- package/dist/engines/types.d.ts +31 -1
- package/dist/engines/types.d.ts.map +1 -1
- package/dist/events.d.ts +30 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +18 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/loop.d.ts +60 -11
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +7 -5
- package/dist/loop.js.map +1 -1
- package/dist/models/chat.d.ts +2 -1
- package/dist/models/chat.d.ts.map +1 -1
- package/dist/models/chat.js +20 -4
- package/dist/models/chat.js.map +1 -1
- package/dist/models/types.d.ts +16 -0
- package/dist/models/types.d.ts.map +1 -1
- package/dist/models/types.js.map +1 -1
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +29 -1
- package/dist/private.js.map +1 -1
- package/dist/providers/anthropic.d.ts +30 -4
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +130 -29
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/index.d.ts +42 -6
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +132 -48
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/mock.d.ts +6 -3
- package/dist/providers/mock.d.ts.map +1 -1
- package/dist/providers/mock.js +9 -4
- package/dist/providers/mock.js.map +1 -1
- package/dist/providers/openai.d.ts +54 -8
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +164 -32
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/options.d.ts +177 -0
- package/dist/providers/options.d.ts.map +1 -0
- package/dist/providers/options.js +67 -0
- package/dist/providers/options.js.map +1 -0
- package/dist/providers/scripted.d.ts +49 -0
- package/dist/providers/scripted.d.ts.map +1 -0
- package/dist/providers/scripted.js +90 -0
- package/dist/providers/scripted.js.map +1 -0
- package/dist/providers/types.d.ts +60 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/tools/metadata.d.ts +24 -0
- package/dist/tools/metadata.d.ts.map +1 -1
- package/dist/tools/metadata.js +8 -0
- package/dist/tools/metadata.js.map +1 -1
- package/dist/tools/registry.d.ts +10 -3
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +9 -4
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/terminal.d.ts +33 -0
- package/dist/tools/terminal.d.ts.map +1 -0
- package/dist/tools/terminal.js +32 -0
- package/dist/tools/terminal.js.map +1 -0
- package/package.json +4 -3
package/dist/providers/openai.js
CHANGED
|
@@ -1,33 +1,55 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
2
|
import { maxTokens, providerMaxRetries, providerTimeoutMs } from "./clientOptions.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { rejectOption, resolveMaxRetries, resolveMaxTokens, resolvePromptCache, } from "./options.js";
|
|
4
|
+
function cachedPart(text, ttl) {
|
|
5
|
+
return { type: "text", text, cache_control: { type: "ephemeral", ...(ttl ? { ttl } : {}) } };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Map provider-neutral messages to OpenAI chat messages (pure; tested).
|
|
9
|
+
*
|
|
10
|
+
* With `cache` set (OpenRouter), the trailing N messages are sent as content
|
|
11
|
+
* parts with a `cache_control` breakpoint on their text. An assistant message
|
|
12
|
+
* with no prose has nowhere to put one and is left as it was; a tool message
|
|
13
|
+
* puts it on its last result. Messages outside the window keep the plain
|
|
14
|
+
* string form.
|
|
15
|
+
*/
|
|
16
|
+
export function toOpenAIMessages(messages, cache) {
|
|
5
17
|
const out = [];
|
|
6
|
-
|
|
18
|
+
const firstCached = cache ? Math.max(0, messages.length - cache.trailingMessages) : Infinity;
|
|
19
|
+
messages.forEach((m, index) => {
|
|
20
|
+
const mark = cache !== undefined && index >= firstCached;
|
|
7
21
|
if (m.role === "user") {
|
|
8
|
-
out.push({ role: "user", content: m.text });
|
|
22
|
+
out.push({ role: "user", content: mark ? [cachedPart(m.text, cache.ttl)] : m.text });
|
|
9
23
|
}
|
|
10
24
|
else if (m.role === "assistant") {
|
|
11
25
|
const msg = {
|
|
12
26
|
role: "assistant",
|
|
13
|
-
content: m.text,
|
|
27
|
+
content: mark && m.text ? [cachedPart(m.text, cache.ttl)] : m.text,
|
|
14
28
|
};
|
|
15
29
|
if (m.toolCalls.length > 0) {
|
|
16
30
|
msg.tool_calls = m.toolCalls.map((tc) => ({
|
|
17
31
|
id: tc.id,
|
|
18
32
|
type: "function",
|
|
19
|
-
|
|
33
|
+
// The model's own bytes when we have them, so a replayed call is
|
|
34
|
+
// verbatim; the parsed object re-serialised otherwise.
|
|
35
|
+
function: { name: tc.name, arguments: tc.argumentsText ?? JSON.stringify(tc.input) },
|
|
20
36
|
}));
|
|
21
37
|
}
|
|
22
38
|
out.push(msg);
|
|
23
39
|
}
|
|
24
40
|
else {
|
|
25
|
-
// Each tool result becomes its own `tool` message keyed by the call id
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
// Each tool result becomes its own `tool` message keyed by the call id;
|
|
42
|
+
// the breakpoint goes on the last one so the whole batch sits inside it.
|
|
43
|
+
m.results.forEach((r, i) => {
|
|
44
|
+
const last = i === m.results.length - 1;
|
|
45
|
+
out.push({
|
|
46
|
+
role: "tool",
|
|
47
|
+
tool_call_id: r.toolCallId,
|
|
48
|
+
content: mark && last ? [cachedPart(r.content, cache.ttl)] : r.content,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
29
51
|
}
|
|
30
|
-
}
|
|
52
|
+
});
|
|
31
53
|
return out;
|
|
32
54
|
}
|
|
33
55
|
/** Reduce an OpenAI response message to text + tool calls (pure; tested). */
|
|
@@ -43,25 +65,59 @@ export function parseOpenAIMessage(message) {
|
|
|
43
65
|
id: tc.id,
|
|
44
66
|
name: tc.function.name,
|
|
45
67
|
input: parseArguments(tc.function.arguments),
|
|
68
|
+
argumentsText: tc.function.arguments,
|
|
46
69
|
});
|
|
47
70
|
}
|
|
48
71
|
return { text, toolCalls };
|
|
49
72
|
}
|
|
73
|
+
/** Map the OpenAI dialect's `finish_reason` onto the neutral vocabulary (pure; tested). */
|
|
74
|
+
export function openAIFinishReason(finishReason) {
|
|
75
|
+
switch (finishReason) {
|
|
76
|
+
case "stop":
|
|
77
|
+
return "stop";
|
|
78
|
+
case "tool_calls":
|
|
79
|
+
case "function_call":
|
|
80
|
+
return "tool_calls";
|
|
81
|
+
case "length":
|
|
82
|
+
return "length";
|
|
83
|
+
case "content_filter":
|
|
84
|
+
return "content_filter";
|
|
85
|
+
default:
|
|
86
|
+
return "unknown";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** The dialect's `tool_choice` for a neutral {@link ToolChoice}. */
|
|
90
|
+
function openAIToolChoice(choice) {
|
|
91
|
+
if (typeof choice === "string")
|
|
92
|
+
return choice;
|
|
93
|
+
return { type: "function", function: { name: choice.name } };
|
|
94
|
+
}
|
|
50
95
|
/**
|
|
51
|
-
* Map an OpenAI `usage` block to the kernel's token accounting (pure;
|
|
52
|
-
* `prompt_tokens` already includes cached input, so it maps to
|
|
53
|
-
* as-is and `cached_tokens` is the cache-read breakdown. OpenAI
|
|
54
|
-
*
|
|
96
|
+
* Map an OpenAI-dialect `usage` block to the kernel's token accounting (pure;
|
|
97
|
+
* tested). `prompt_tokens` already includes cached input, so it maps to
|
|
98
|
+
* `inputTokens` as-is and `cached_tokens` is the cache-read breakdown. OpenAI
|
|
99
|
+
* reports no write count; OpenRouter does (`cache_write_tokens`), and prices
|
|
100
|
+
* the call (`cost`), so both are carried when present. Reasoning tokens are
|
|
101
|
+
* the `completion_tokens_details` breakdown either side reports.
|
|
55
102
|
*/
|
|
56
103
|
export function openAIUsage(usage) {
|
|
57
104
|
if (!usage)
|
|
58
105
|
return undefined;
|
|
106
|
+
const extended = usage;
|
|
59
107
|
const cached = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
108
|
+
const written = extended.prompt_tokens_details?.cache_write_tokens ?? 0;
|
|
109
|
+
const reasoning = usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
110
|
+
const cost = extended.cost;
|
|
60
111
|
return {
|
|
61
112
|
inputTokens: usage.prompt_tokens,
|
|
62
113
|
outputTokens: usage.completion_tokens,
|
|
63
114
|
totalTokens: usage.total_tokens,
|
|
64
115
|
...(cached > 0 ? { cacheReadTokens: cached } : {}),
|
|
116
|
+
...(written > 0 ? { cacheWriteTokens: written } : {}),
|
|
117
|
+
...(reasoning > 0 ? { reasoningTokens: reasoning } : {}),
|
|
118
|
+
...(typeof cost === "number" && Number.isFinite(cost)
|
|
119
|
+
? { reportedCost: { amount: cost, currency: "USD" } }
|
|
120
|
+
: {}),
|
|
65
121
|
};
|
|
66
122
|
}
|
|
67
123
|
/** Parse a tool-call arguments JSON string, tolerating empty/invalid input. */
|
|
@@ -76,6 +132,70 @@ function parseArguments(raw) {
|
|
|
76
132
|
return {};
|
|
77
133
|
}
|
|
78
134
|
}
|
|
135
|
+
/** The adapter names whose dialect differences this core knows about. */
|
|
136
|
+
export const OPENAI_ADAPTER = "openai";
|
|
137
|
+
export const OPENROUTER_ADAPTER = "openrouter";
|
|
138
|
+
/**
|
|
139
|
+
* Build the chat.completions request for one conversation step (pure; tested).
|
|
140
|
+
*
|
|
141
|
+
* `name` selects the dialect: `openrouter` accepts the `openrouter` options
|
|
142
|
+
* block and places prompt-cache breakpoints as content parts; `openai` maps
|
|
143
|
+
* `promptCache.key` onto `prompt_cache_key` (its caching is otherwise
|
|
144
|
+
* automatic, so breakpoints have nothing to attach to); any other name (local
|
|
145
|
+
* servers, custom endpoints) gets the plain dialect and rejects the
|
|
146
|
+
* OpenRouter block.
|
|
147
|
+
*/
|
|
148
|
+
export function openAICompatibleRequestBody(name, model, req, fallbackMaxTokens = maxTokens()) {
|
|
149
|
+
const options = req.providerOptions;
|
|
150
|
+
const isOpenRouter = name === OPENROUTER_ADAPTER;
|
|
151
|
+
if (!isOpenRouter)
|
|
152
|
+
rejectOption(name, options, "openrouter");
|
|
153
|
+
const cache = options?.promptCache
|
|
154
|
+
? resolvePromptCache(options.promptCache)
|
|
155
|
+
: undefined;
|
|
156
|
+
const ttl = cache?.ttl;
|
|
157
|
+
const tools = req.tools.map((t) => ({
|
|
158
|
+
type: "function",
|
|
159
|
+
function: { name: t.name, description: t.description, parameters: t.inputSchema },
|
|
160
|
+
}));
|
|
161
|
+
const system = isOpenRouter && cache?.system && req.system
|
|
162
|
+
? { role: "system", content: [cachedPart(req.system, ttl)] }
|
|
163
|
+
: { role: "system", content: req.system };
|
|
164
|
+
const messageCache = isOpenRouter && cache && cache.trailingMessages > 0
|
|
165
|
+
? { trailingMessages: cache.trailingMessages, ...(ttl ? { ttl } : {}) }
|
|
166
|
+
: undefined;
|
|
167
|
+
// OpenAI retired `max_tokens` in favour of `max_completion_tokens` (its
|
|
168
|
+
// reasoning models reject the old name); OpenRouter and the local servers
|
|
169
|
+
// document `max_tokens`, so each dialect gets the field it names.
|
|
170
|
+
const cap = resolveMaxTokens(options, fallbackMaxTokens);
|
|
171
|
+
const body = {
|
|
172
|
+
model,
|
|
173
|
+
...(name === OPENAI_ADAPTER ? { max_completion_tokens: cap } : { max_tokens: cap }),
|
|
174
|
+
messages: [system, ...toOpenAIMessages(req.messages, messageCache)],
|
|
175
|
+
...(tools.length > 0 ? { tools } : {}),
|
|
176
|
+
// Omitted on a tools-free request: the budget summary call sends the same
|
|
177
|
+
// options with no tools, and a forced choice there is an API error.
|
|
178
|
+
...(tools.length > 0 && options?.toolChoice !== undefined
|
|
179
|
+
? { tool_choice: openAIToolChoice(options.toolChoice) }
|
|
180
|
+
: {}),
|
|
181
|
+
...(typeof options?.temperature === "number" ? { temperature: options.temperature } : {}),
|
|
182
|
+
...(options?.responseFormat ? { response_format: options.responseFormat } : {}),
|
|
183
|
+
};
|
|
184
|
+
if (name === OPENAI_ADAPTER && cache?.key)
|
|
185
|
+
body.prompt_cache_key = cache.key;
|
|
186
|
+
if (isOpenRouter && options?.openrouter) {
|
|
187
|
+
const or = options.openrouter;
|
|
188
|
+
if (or.models)
|
|
189
|
+
body.models = or.models;
|
|
190
|
+
if (or.provider)
|
|
191
|
+
body.provider = { ...or.provider };
|
|
192
|
+
if (or.usage)
|
|
193
|
+
body.usage = or.usage;
|
|
194
|
+
if (or.transforms)
|
|
195
|
+
body.transforms = or.transforms;
|
|
196
|
+
}
|
|
197
|
+
return body;
|
|
198
|
+
}
|
|
79
199
|
/**
|
|
80
200
|
* Shared core for providers speaking the OpenAI chat.completions dialect
|
|
81
201
|
* (including tools). OpenAI proper and OpenRouter both instantiate this —
|
|
@@ -84,8 +204,8 @@ function parseArguments(raw) {
|
|
|
84
204
|
export class OpenAICompatibleProvider {
|
|
85
205
|
name;
|
|
86
206
|
reportsUsage = true;
|
|
87
|
-
client;
|
|
88
207
|
model;
|
|
208
|
+
client;
|
|
89
209
|
constructor(name, opts) {
|
|
90
210
|
// The SDK retries transient 429/5xx/network errors with exponential backoff
|
|
91
211
|
// internally, so a blip doesn't fail the whole run; `timeout` bounds each
|
|
@@ -103,7 +223,10 @@ export class OpenAICompatibleProvider {
|
|
|
103
223
|
async complete(req) {
|
|
104
224
|
const completion = await this.client.chat.completions.create({
|
|
105
225
|
model: this.model,
|
|
106
|
-
|
|
226
|
+
// Same field rule as `converse`: OpenAI's current name, the documented one elsewhere.
|
|
227
|
+
...(this.name === OPENAI_ADAPTER
|
|
228
|
+
? { max_completion_tokens: maxTokens() }
|
|
229
|
+
: { max_tokens: maxTokens() }),
|
|
107
230
|
messages: [
|
|
108
231
|
{ role: "system", content: req.system },
|
|
109
232
|
{ role: "user", content: req.prompt },
|
|
@@ -112,27 +235,36 @@ export class OpenAICompatibleProvider {
|
|
|
112
235
|
return completion.choices[0]?.message?.content ?? "";
|
|
113
236
|
}
|
|
114
237
|
async converse(req, opts) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
messages: [{ role: "system", content: req.system }, ...toOpenAIMessages(req.messages)],
|
|
123
|
-
...(tools.length > 0 ? { tools } : {}),
|
|
124
|
-
},
|
|
125
|
-
// Per-request, so an abort cancels THIS call (retries included).
|
|
126
|
-
opts?.signal ? { signal: opts.signal } : undefined);
|
|
238
|
+
// Per-request options, so an abort cancels THIS call (retries included)
|
|
239
|
+
// and a per-call retry count leaves the shared client untouched.
|
|
240
|
+
const retries = resolveMaxRetries(req.providerOptions);
|
|
241
|
+
const completion = await this.client.chat.completions.create(openAICompatibleRequestBody(this.name, this.model, req), {
|
|
242
|
+
...(opts?.signal ? { signal: opts.signal } : {}),
|
|
243
|
+
...(retries !== undefined ? { maxRetries: retries } : {}),
|
|
244
|
+
});
|
|
127
245
|
const usage = openAIUsage(completion.usage);
|
|
128
|
-
const
|
|
246
|
+
const choice = completion.choices[0];
|
|
247
|
+
const message = choice?.message;
|
|
129
248
|
const parsed = message ? parseOpenAIMessage(message) : { text: "", toolCalls: [] };
|
|
130
|
-
|
|
249
|
+
const finishReason = openAIFinishReason(choice?.finish_reason);
|
|
250
|
+
// OpenRouter adds a top-level `provider` naming the upstream that served
|
|
251
|
+
// the request; the SDK's response type does not know it, so read it loosely.
|
|
252
|
+
const upstream = this.name === OPENROUTER_ADAPTER ? completion.provider : undefined;
|
|
253
|
+
return {
|
|
254
|
+
...parsed,
|
|
255
|
+
...(usage ? { usage } : {}),
|
|
256
|
+
finishReason,
|
|
257
|
+
...(typeof completion.model === "string" && completion.model
|
|
258
|
+
? { model: completion.model }
|
|
259
|
+
: {}),
|
|
260
|
+
...(typeof completion.id === "string" && completion.id ? { responseId: completion.id } : {}),
|
|
261
|
+
...(typeof upstream === "string" && upstream ? { upstream } : {}),
|
|
262
|
+
};
|
|
131
263
|
}
|
|
132
264
|
}
|
|
133
265
|
export class OpenAIProvider extends OpenAICompatibleProvider {
|
|
134
266
|
constructor(apiKey, model = process.env.OPENAI_MODEL ?? "gpt-4.1") {
|
|
135
|
-
super(
|
|
267
|
+
super(OPENAI_ADAPTER, { apiKey, model });
|
|
136
268
|
}
|
|
137
269
|
}
|
|
138
270
|
//# sourceMappingURL=openai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAWrF,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAC9B,QAAwB;IAExB,MAAM,GAAG,GAAyD,EAAE,CAAA;IACpE,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC7C,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,GAAG,GAAgE;gBACvE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,CAAC,CAAC,IAAI;aAChB,CAAA;YACD,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC3B,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,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AAC,EAAE,CAAC;YAC3B,YAAY;YACZ,GAAG,CAAC,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ,IAAI,UAAU,CAAC,KAAK;gBAC1D,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE;gBAC7B,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,UAAU,CAAC,EAAE,KAAK,QAAQ,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5F,GAAG,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClE,CAAA;IACH,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,wBAAwB;IAC1D,YAAY,MAAc,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,SAAS;QACvE,KAAK,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1C,CAAC;CACF"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call provider options: the typed passthrough from a caller to the adapter
|
|
3
|
+
* that makes the HTTP request.
|
|
4
|
+
*
|
|
5
|
+
* Two kinds of thing live here, and the split is deliberate:
|
|
6
|
+
*
|
|
7
|
+
* - **Neutral options** (`maxTokens`, `promptCache`, `responseFormat`) name an
|
|
8
|
+
* intent, and each adapter maps it onto its own wire format as well as it
|
|
9
|
+
* can. Prompt caching is the clearest case: Anthropic wants explicit
|
|
10
|
+
* `cache_control` breakpoints, OpenRouter wants them inside content parts,
|
|
11
|
+
* OpenAI caches prefixes automatically and only takes a routing key.
|
|
12
|
+
* - **Adapter-addressed options** (`openrouter`) carry one API's own
|
|
13
|
+
* vocabulary verbatim, snake_case and all, because translating them would
|
|
14
|
+
* only add a place for the two to drift.
|
|
15
|
+
*
|
|
16
|
+
* Either way, an option an adapter cannot honour is an error, never a silent
|
|
17
|
+
* drop: a caller that asked for zero-data-retention routing and got a request
|
|
18
|
+
* that said nothing about it would have no way to notice.
|
|
19
|
+
*/
|
|
20
|
+
/** How long a cache breakpoint keeps its entry alive (Anthropic and OpenRouter). */
|
|
21
|
+
export type CacheTtl = "5m" | "1h";
|
|
22
|
+
/**
|
|
23
|
+
* Where to place prompt-cache breakpoints. Every field is optional; passing
|
|
24
|
+
* `promptCache: {}` means "cache this prompt the usual way": the system prompt,
|
|
25
|
+
* the tool definitions and the last message, so the next call in the same
|
|
26
|
+
* conversation reads the whole prefix from cache.
|
|
27
|
+
*
|
|
28
|
+
* Breakpoints exist on Anthropic (`cache_control`) and OpenRouter (content
|
|
29
|
+
* parts). The `openai` adapter has no breakpoints to place (its caching is
|
|
30
|
+
* automatic over the prefix) and honours only `key`; the `local` adapter and
|
|
31
|
+
* any custom OpenAI-compatible endpoint accept the option and leave caching to
|
|
32
|
+
* the server's own prefix cache. Those two are best effort by design rather
|
|
33
|
+
* than an error: "cache this prompt" is an intent every adapter can honour as
|
|
34
|
+
* well as its API allows, unlike an option addressed to a different API.
|
|
35
|
+
*/
|
|
36
|
+
export interface PromptCacheOptions {
|
|
37
|
+
/** Breakpoint after the system prompt. Default `true`. */
|
|
38
|
+
system?: boolean;
|
|
39
|
+
/** Breakpoint after the tool definitions (Anthropic only). Default `true`. */
|
|
40
|
+
tools?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* How many trailing messages get a breakpoint on their last content block.
|
|
43
|
+
* Default 1; clamped to {@link MAX_TRAILING_CACHE_MESSAGES} because Anthropic
|
|
44
|
+
* allows four breakpoints per request and two are spent on system and tools.
|
|
45
|
+
*/
|
|
46
|
+
trailingMessages?: number;
|
|
47
|
+
/** Cache lifetime for every breakpoint this call places. Default is the provider's (`5m`). */
|
|
48
|
+
ttl?: CacheTtl;
|
|
49
|
+
/** OpenAI `prompt_cache_key`: routes requests sharing a prefix to the same cache. */
|
|
50
|
+
key?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Anthropic's breakpoint ceiling is four; two go to system and tools. */
|
|
53
|
+
export declare const MAX_TRAILING_CACHE_MESSAGES = 2;
|
|
54
|
+
/** The resolved form of {@link PromptCacheOptions}: every default applied. */
|
|
55
|
+
export interface ResolvedPromptCache {
|
|
56
|
+
system: boolean;
|
|
57
|
+
tools: boolean;
|
|
58
|
+
trailingMessages: number;
|
|
59
|
+
ttl?: CacheTtl;
|
|
60
|
+
key?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Apply the defaults and the clamp. */
|
|
63
|
+
export declare function resolvePromptCache(options: PromptCacheOptions): ResolvedPromptCache;
|
|
64
|
+
/**
|
|
65
|
+
* The OpenAI chat.completions `response_format` shape, which OpenRouter and most
|
|
66
|
+
* OpenAI-compatible servers accept as-is. The Anthropic adapter rejects it: the
|
|
67
|
+
* Messages API has no equivalent field, and a structured answer there is a
|
|
68
|
+
* terminal tool with a schema.
|
|
69
|
+
*/
|
|
70
|
+
export type ResponseFormat = {
|
|
71
|
+
type: "text";
|
|
72
|
+
} | {
|
|
73
|
+
type: "json_object";
|
|
74
|
+
} | {
|
|
75
|
+
type: "json_schema";
|
|
76
|
+
json_schema: {
|
|
77
|
+
name: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
schema?: Record<string, unknown>;
|
|
80
|
+
strict?: boolean | null;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* OpenRouter's `provider` routing preferences, passed through verbatim (hence
|
|
85
|
+
* snake_case: these are OpenRouter's own field names). `data_collection: "deny"`
|
|
86
|
+
* and `zdr: true` are the data-policy knobs: the first excludes upstreams that
|
|
87
|
+
* may store or train on prompts, the second restricts routing to upstreams
|
|
88
|
+
* with a zero-data-retention policy.
|
|
89
|
+
*/
|
|
90
|
+
export interface OpenRouterProviderPreferences {
|
|
91
|
+
/** Upstreams to try, in order. */
|
|
92
|
+
order?: string[];
|
|
93
|
+
/** Only these upstreams may serve the request. */
|
|
94
|
+
only?: string[];
|
|
95
|
+
/** Never route to these upstreams. */
|
|
96
|
+
ignore?: string[];
|
|
97
|
+
/** Whether to fall back past `order` when those upstreams fail. */
|
|
98
|
+
allow_fallbacks?: boolean;
|
|
99
|
+
/** Only route to upstreams that support every parameter in the request. */
|
|
100
|
+
require_parameters?: boolean;
|
|
101
|
+
/** `deny` excludes upstreams that may store or train on the prompt. */
|
|
102
|
+
data_collection?: "allow" | "deny";
|
|
103
|
+
/** Restrict routing to upstreams with a zero-data-retention policy. */
|
|
104
|
+
zdr?: boolean;
|
|
105
|
+
/** Routing priority when several upstreams qualify. */
|
|
106
|
+
sort?: "price" | "throughput" | "latency" | (string & {});
|
|
107
|
+
/** Acceptable quantization levels, e.g. `["fp16", "bf16"]`. */
|
|
108
|
+
quantizations?: string[];
|
|
109
|
+
/** Price ceilings per million tokens, in OpenRouter's own keys (`prompt`, `completion`, …). */
|
|
110
|
+
max_price?: Record<string, number>;
|
|
111
|
+
}
|
|
112
|
+
/** Options only the OpenRouter adapter can honour. */
|
|
113
|
+
export interface OpenRouterOptions {
|
|
114
|
+
/** Fallback model ids, tried in order when the primary model fails or is unavailable. */
|
|
115
|
+
models?: string[];
|
|
116
|
+
/** Upstream routing and data-policy preferences. */
|
|
117
|
+
provider?: OpenRouterProviderPreferences;
|
|
118
|
+
/** `{ include: true }` asks for token accounting (incl. cache reads) in the response. */
|
|
119
|
+
usage?: {
|
|
120
|
+
include: boolean;
|
|
121
|
+
};
|
|
122
|
+
/** OpenRouter prompt transforms, e.g. `["middle-out"]`. */
|
|
123
|
+
transforms?: string[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Which tool the model must call. `auto` lets it choose (the provider
|
|
127
|
+
* default), `required` forces some tool, `none` forbids tools, `{ name }`
|
|
128
|
+
* forces that one (the last step of a terminal-tool flow). Every adapter
|
|
129
|
+
* omits the setting on a request that carries no tools, which is what the
|
|
130
|
+
* loop's budget-summary call sends, so a forced choice never reaches a call
|
|
131
|
+
* that has nothing to choose from.
|
|
132
|
+
*/
|
|
133
|
+
export type ToolChoice = "auto" | "required" | "none" | {
|
|
134
|
+
name: string;
|
|
135
|
+
};
|
|
136
|
+
/** Everything a caller may hand an adapter for one request. */
|
|
137
|
+
export interface ProviderOptions {
|
|
138
|
+
/** Sampling temperature, passed through as given. */
|
|
139
|
+
temperature?: number;
|
|
140
|
+
/** Which tool the model must call; see {@link ToolChoice}. */
|
|
141
|
+
toolChoice?: ToolChoice;
|
|
142
|
+
/** Completion token cap for this call; overrides `RUNNER_MAX_TOKENS`. */
|
|
143
|
+
maxTokens?: number;
|
|
144
|
+
/**
|
|
145
|
+
* SDK retry count for this call; overrides `RUNNER_PROVIDER_MAX_RETRIES`.
|
|
146
|
+
* Set `0` when the request carries its own fallback chain (OpenRouter
|
|
147
|
+
* `models`), so a transient upstream failure is not retried by the SDK and
|
|
148
|
+
* then again by the router.
|
|
149
|
+
*/
|
|
150
|
+
maxRetries?: number;
|
|
151
|
+
/** Prompt caching. Each adapter maps it onto its own mechanism. */
|
|
152
|
+
promptCache?: PromptCacheOptions;
|
|
153
|
+
/** Structured-output format (OpenAI-compatible adapters only). */
|
|
154
|
+
responseFormat?: ResponseFormat;
|
|
155
|
+
/** OpenRouter-only routing options; any other adapter rejects them. */
|
|
156
|
+
openrouter?: OpenRouterOptions;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Thrown when an option is addressed to an adapter that cannot honour it. The
|
|
160
|
+
* kernel never drops an option on the floor: silence here is how a request
|
|
161
|
+
* meant for a zero-data-retention route ends up somewhere else.
|
|
162
|
+
*/
|
|
163
|
+
export declare class ProviderOptionsError extends Error {
|
|
164
|
+
readonly adapter: string;
|
|
165
|
+
readonly option: keyof ProviderOptions;
|
|
166
|
+
constructor(adapter: string, option: keyof ProviderOptions, detail?: string);
|
|
167
|
+
}
|
|
168
|
+
/** Throw if `options` carries `option`, for an adapter that cannot honour it. */
|
|
169
|
+
export declare function rejectOption(adapter: string, options: ProviderOptions | undefined, option: keyof ProviderOptions, detail?: string): void;
|
|
170
|
+
/** The per-call retry count when given and non-negative, else undefined (the client's default). */
|
|
171
|
+
export declare function resolveMaxRetries(options: ProviderOptions | undefined): number | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* The per-call completion cap: the option when given and positive, else the
|
|
174
|
+
* caller's fallback (normally the env-resolved `RUNNER_MAX_TOKENS`).
|
|
175
|
+
*/
|
|
176
|
+
export declare function resolveMaxTokens(options: ProviderOptions | undefined, fallback: number): number;
|
|
177
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/providers/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oFAAoF;AACpF,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAA;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,8FAA8F;IAC9F,GAAG,CAAC,EAAE,QAAQ,CAAA;IACd,qFAAqF;IACrF,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,IAAI,CAAA;AAE5C,8EAA8E;AAC9E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,OAAO,CAAA;IACd,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,CAAC,EAAE,QAAQ,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,wCAAwC;AACxC,wBA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G1F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/F"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call provider options: the typed passthrough from a caller to the adapter
|
|
3
|
+
* that makes the HTTP request.
|
|
4
|
+
*
|
|
5
|
+
* Two kinds of thing live here, and the split is deliberate:
|
|
6
|
+
*
|
|
7
|
+
* - **Neutral options** (`maxTokens`, `promptCache`, `responseFormat`) name an
|
|
8
|
+
* intent, and each adapter maps it onto its own wire format as well as it
|
|
9
|
+
* can. Prompt caching is the clearest case: Anthropic wants explicit
|
|
10
|
+
* `cache_control` breakpoints, OpenRouter wants them inside content parts,
|
|
11
|
+
* OpenAI caches prefixes automatically and only takes a routing key.
|
|
12
|
+
* - **Adapter-addressed options** (`openrouter`) carry one API's own
|
|
13
|
+
* vocabulary verbatim, snake_case and all, because translating them would
|
|
14
|
+
* only add a place for the two to drift.
|
|
15
|
+
*
|
|
16
|
+
* Either way, an option an adapter cannot honour is an error, never a silent
|
|
17
|
+
* drop: a caller that asked for zero-data-retention routing and got a request
|
|
18
|
+
* that said nothing about it would have no way to notice.
|
|
19
|
+
*/
|
|
20
|
+
/** Anthropic's breakpoint ceiling is four; two go to system and tools. */
|
|
21
|
+
export const MAX_TRAILING_CACHE_MESSAGES = 2;
|
|
22
|
+
/** Apply the defaults and the clamp. */
|
|
23
|
+
export function resolvePromptCache(options) {
|
|
24
|
+
const requested = options.trailingMessages ?? 1;
|
|
25
|
+
const trailingMessages = Math.max(0, Math.min(MAX_TRAILING_CACHE_MESSAGES, Number.isFinite(requested) ? Math.floor(requested) : 1));
|
|
26
|
+
return {
|
|
27
|
+
system: options.system ?? true,
|
|
28
|
+
tools: options.tools ?? true,
|
|
29
|
+
trailingMessages,
|
|
30
|
+
...(options.ttl !== undefined ? { ttl: options.ttl } : {}),
|
|
31
|
+
...(options.key !== undefined ? { key: options.key } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when an option is addressed to an adapter that cannot honour it. The
|
|
36
|
+
* kernel never drops an option on the floor: silence here is how a request
|
|
37
|
+
* meant for a zero-data-retention route ends up somewhere else.
|
|
38
|
+
*/
|
|
39
|
+
export class ProviderOptionsError extends Error {
|
|
40
|
+
adapter;
|
|
41
|
+
option;
|
|
42
|
+
constructor(adapter, option, detail) {
|
|
43
|
+
super(`provider "${adapter}" does not support providerOptions.${option}${detail ? ` (${detail})` : ""}`);
|
|
44
|
+
this.name = "ProviderOptionsError";
|
|
45
|
+
this.adapter = adapter;
|
|
46
|
+
this.option = option;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Throw if `options` carries `option`, for an adapter that cannot honour it. */
|
|
50
|
+
export function rejectOption(adapter, options, option, detail) {
|
|
51
|
+
if (options?.[option] !== undefined)
|
|
52
|
+
throw new ProviderOptionsError(adapter, option, detail);
|
|
53
|
+
}
|
|
54
|
+
/** The per-call retry count when given and non-negative, else undefined (the client's default). */
|
|
55
|
+
export function resolveMaxRetries(options) {
|
|
56
|
+
const n = options?.maxRetries;
|
|
57
|
+
return typeof n === "number" && Number.isFinite(n) && n >= 0 ? Math.floor(n) : undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The per-call completion cap: the option when given and positive, else the
|
|
61
|
+
* caller's fallback (normally the env-resolved `RUNNER_MAX_TOKENS`).
|
|
62
|
+
*/
|
|
63
|
+
export function resolveMaxTokens(options, fallback) {
|
|
64
|
+
const n = options?.maxTokens;
|
|
65
|
+
return typeof n === "number" && Number.isFinite(n) && n > 0 ? Math.floor(n) : fallback;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/providers/options.ts"],"names":[],"mappings":"AAAA;;;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tB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,OAAoC,EACpC,MAA6B,EAC7B,MAAe;IAEf,IAAI,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAC9F,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,iBAAiB,CAAC,OAAoC;IACpE,MAAM,CAAC,GAAG,OAAO,EAAE,UAAU,CAAA;IAC7B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAoC,EAAE,QAAgB;IACrF,MAAM,CAAC,GAAG,OAAO,EAAE,SAAS,CAAA;IAC5B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AACxF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { CompletionRequest, ConverseOptions, ConverseRequest, ConverseResult, Provider } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* One scripted model turn: a fixed result, or a function of the request it
|
|
4
|
+
* answers (and its zero-based index in the script) for a script that needs to
|
|
5
|
+
* inspect what the loop sent before deciding.
|
|
6
|
+
*/
|
|
7
|
+
export type ScriptedTurn = ConverseResult | ((req: ConverseRequest, index: number) => ConverseResult | Promise<ConverseResult>);
|
|
8
|
+
export interface ScriptedProviderOptions {
|
|
9
|
+
/** Reported as `Provider.name`; shows up as the run's `provider`. Default `"scripted"`. */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Reported as `Provider.model` and stamped on every result that names none. */
|
|
12
|
+
model?: string;
|
|
13
|
+
/** Declare usage reporting when the script's turns carry `usage`. Default `false`. */
|
|
14
|
+
reportsUsage?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Thrown when the loop asks for a turn the script does not have. */
|
|
17
|
+
export declare class ScriptExhaustedError extends Error {
|
|
18
|
+
readonly played: number;
|
|
19
|
+
constructor(played: number);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A deterministic provider that plays back a recorded script of model turns.
|
|
23
|
+
*
|
|
24
|
+
* It exists for evals and tests that need the whole loop to run — tools
|
|
25
|
+
* executed, results fed back, terminal tools honoured — without a model or a
|
|
26
|
+
* network, and with every request the loop built available afterwards for
|
|
27
|
+
* assertions. It fails loud in both directions: a script that runs out throws
|
|
28
|
+
* rather than inventing a turn, and `remaining` lets a test assert that every
|
|
29
|
+
* recorded turn was consumed.
|
|
30
|
+
*
|
|
31
|
+
* It honours `signal` the way a real adapter does, so cancellation tests can
|
|
32
|
+
* run against it too.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ScriptedProvider implements Provider {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly model?: string;
|
|
37
|
+
readonly reportsUsage: boolean;
|
|
38
|
+
/** Every request received, in order, as detached copies. */
|
|
39
|
+
readonly requests: ConverseRequest[];
|
|
40
|
+
private readonly script;
|
|
41
|
+
private played;
|
|
42
|
+
constructor(script: readonly ScriptedTurn[], options?: ScriptedProviderOptions);
|
|
43
|
+
/** Turns not yet played. Zero after a conversation consumed the whole script. */
|
|
44
|
+
get remaining(): number;
|
|
45
|
+
converse(req: ConverseRequest, opts?: ConverseOptions): Promise<ConverseResult>;
|
|
46
|
+
/** Play the next turn as a one-shot completion and return its text. */
|
|
47
|
+
complete(req: CompletionRequest): Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=scripted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripted.d.ts","sourceRoot":"","sources":["../../src/providers/scripted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,cAAc,EACd,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,MAAM,MAAM,YAAY,GACpB,cAAc,GACd,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,KAAK,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;AAEvF,MAAM,WAAW,uBAAuB;IACtC,2FAA2F;IAC3F,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sFAAsF;IACtF,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,qEAAqE;AACrE,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;gBAEX,MAAM,EAAE,MAAM;CAQ3B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAK;IAEzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,GAAE,uBAA4B;IAOlF,iFAAiF;IACjF,IAAI,SAAS,IAAI,MAAM,CAEtB;IAEK,QAAQ,CAAC,GAAG,E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