@aragon-agent/core 0.2.93 → 0.2.94
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/dist/engine/accept-steering.js +1 -15
- package/dist/engine/agent-loop.js +1 -533
- package/dist/engine/agent.js +1 -538
- package/dist/engine/compaction.js +1 -268
- package/dist/engine/context-manager.js +1 -13
- package/dist/engine/message-manager.js +1 -39
- package/dist/engine/steering.js +1 -72
- package/dist/engine/tool-result-content.js +1 -39
- package/dist/engine/watchdog.js +1 -73
- package/dist/index.js +1 -99
- package/dist/llm/context-window.js +1 -46
- package/dist/llm/image-tokens.js +1 -11
- package/dist/llm/model-discovery.js +1 -18
- package/dist/llm/model-registry.js +1 -370
- package/dist/llm/output-limit-recovery.js +1 -263
- package/dist/llm/output-limits.js +1 -283
- package/dist/llm/provider.js +1 -171
- package/dist/llm/providers/anthropic.js +1 -514
- package/dist/llm/providers/google.js +1 -464
- package/dist/llm/providers/index.js +1 -205
- package/dist/llm/providers/openai.js +1 -520
- package/dist/llm/providers/tool-result-images.js +1 -52
- package/dist/llm/retry.js +1 -948
- package/dist/llm/sse-parser.js +1 -103
- package/dist/llm/stream-utils.js +1 -118
- package/dist/llm/types.js +1 -17
- package/dist/sandbox/console-capture.js +1 -56
- package/dist/sandbox/http-bridge.js +1 -143
- package/dist/sandbox/isolated-vm-sandbox.js +1 -226
- package/dist/sandbox/tool-bridge.js +1 -98
- package/dist/sandbox/types.js +1 -8
- package/dist/skills/constants.js +1 -179
- package/dist/skills/disclosure.js +1 -788
- package/dist/skills/frontmatter.js +1 -177
- package/dist/skills/index.js +1 -18
- package/dist/skills/skill-find-tool.js +1 -117
- package/dist/skills/skill-registry.js +1 -208
- package/dist/skills/skill-tool.js +1 -96
- package/dist/skills/tool-policy.js +1 -272
- package/dist/skills/types.js +1 -8
- package/dist/skills/validate.js +1 -264
- package/dist/tools/executor.js +1 -281
- package/dist/tools/helpers.js +1 -87
- package/dist/tools/registry.js +1 -119
- package/dist/tools/types.js +1 -7
- package/dist/tools/validator.js +1 -210
- package/dist/types.js +1 -7
- package/package.json +3 -2
|
@@ -1,514 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anthropic Messages API adapter.
|
|
3
|
-
*
|
|
4
|
-
* Converts the universal LLM types to/from Anthropic's wire format and maps
|
|
5
|
-
* SSE events to the unified StreamEvent protocol.
|
|
6
|
-
*
|
|
7
|
-
* Supports:
|
|
8
|
-
* - Streaming via `POST /v1/messages` with `stream: true`
|
|
9
|
-
* - Extended thinking (thinking_start / thinking_delta)
|
|
10
|
-
* - Tool use (content_block_start type=tool_use → tool_call_*)
|
|
11
|
-
* - Multimodal user messages (text + image)
|
|
12
|
-
* - Model list via `GET /v1/models`
|
|
13
|
-
*/
|
|
14
|
-
import { reportedContextWindow } from '../context-window.js';
|
|
15
|
-
import { createModelDiscoverySignal } from '../model-discovery.js';
|
|
16
|
-
import { THINKING_BUDGET } from '../types.js';
|
|
17
|
-
import { LLMError, classifyHttpError, wrapFetchError } from '../provider.js';
|
|
18
|
-
import { DEFAULT_MAX_OUTPUT_TOKENS, resolveOutputTokens, staticCeilingFor, } from '../output-limits.js';
|
|
19
|
-
import { sendWithOutputLimitRecovery } from '../output-limit-recovery.js';
|
|
20
|
-
import { parseSSEStream } from '../stream-utils.js';
|
|
21
|
-
import { consumeStream } from '../stream-utils.js';
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// Constants
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
const DEFAULT_BASE_URL = 'https://api.anthropic.com';
|
|
26
|
-
const ANTHROPIC_VERSION = '2023-06-01';
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
// Anthropic provider
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
export class AnthropicProvider {
|
|
31
|
-
id = 'anthropic';
|
|
32
|
-
displayName = 'Anthropic';
|
|
33
|
-
defaultBaseUrl = DEFAULT_BASE_URL;
|
|
34
|
-
// -----------------------------------------------------------------------
|
|
35
|
-
// stream
|
|
36
|
-
// -----------------------------------------------------------------------
|
|
37
|
-
async *stream(request) {
|
|
38
|
-
if (request.signal?.aborted)
|
|
39
|
-
return;
|
|
40
|
-
const baseUrl = (request.baseUrl || this.defaultBaseUrl).replace(/\/+$/, '');
|
|
41
|
-
const url = `${baseUrl}/v1/messages`;
|
|
42
|
-
const body = buildRequestBody(request);
|
|
43
|
-
let response;
|
|
44
|
-
let errorBody = '';
|
|
45
|
-
try {
|
|
46
|
-
const attempt = await sendWithOutputLimitRecovery({
|
|
47
|
-
providerId: this.id,
|
|
48
|
-
modelId: request.model,
|
|
49
|
-
body,
|
|
50
|
-
tokenField: 'max_tokens',
|
|
51
|
-
send: (payload) => fetch(url, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: {
|
|
54
|
-
'Content-Type': 'application/json',
|
|
55
|
-
'x-api-key': request.apiKey,
|
|
56
|
-
'anthropic-version': ANTHROPIC_VERSION,
|
|
57
|
-
},
|
|
58
|
-
body: JSON.stringify(payload),
|
|
59
|
-
signal: request.signal,
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
response = attempt.response;
|
|
63
|
-
errorBody = attempt.bodyText;
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
if (request.signal?.aborted)
|
|
67
|
-
return;
|
|
68
|
-
yield { type: 'error', error: wrapFetchError(err, this.id) };
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (request.signal?.aborted)
|
|
72
|
-
return;
|
|
73
|
-
if (!response.ok) {
|
|
74
|
-
// `errorBody` is the ALREADY-CONSUMED body; re-reading it would throw.
|
|
75
|
-
// `response.headers` carries `Retry-After` / `anthropic-ratelimit-*-reset`
|
|
76
|
-
// out on `LLMError.retryAfterMs`; without it a 429 that stated a wait is
|
|
77
|
-
// retried on the plain ladder instead of when the server said to.
|
|
78
|
-
yield {
|
|
79
|
-
type: 'error',
|
|
80
|
-
error: classifyHttpError(response.status, errorBody, this.id, response.headers),
|
|
81
|
-
};
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (!response.body) {
|
|
85
|
-
yield { type: 'error', error: new LLMError('Response body is null', this.id, 'network_error', true) };
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
// -- Parse SSE events and map to StreamEvent --
|
|
89
|
-
const usage = { inputTokens: 0, outputTokens: 0 };
|
|
90
|
-
const contentBlocks = [];
|
|
91
|
-
let stopReason;
|
|
92
|
-
// Accumulator state per content block index
|
|
93
|
-
const blockAccumulators = new Map();
|
|
94
|
-
let currentBlockIndex = -1;
|
|
95
|
-
try {
|
|
96
|
-
// THE READ SIGNAL COVERS ONE ATTEMPT, not the request: it aborts on the caller's
|
|
97
|
-
// Esc (so Esc still means Esc) and on silence. Ending the read is what turns a
|
|
98
|
-
// stall into the `truncated before message_stop` failure below, which is
|
|
99
|
-
// `retryable` and therefore reaches the ladder (F1′).
|
|
100
|
-
const readSignal = request.readDeadline ?? request.signal;
|
|
101
|
-
for await (const sse of parseSSEStream(response.body, readSignal)) {
|
|
102
|
-
if (request.signal?.aborted)
|
|
103
|
-
return;
|
|
104
|
-
// LIVENESS, BEFORE ANY FILTERING: a `ping` is still a live connection.
|
|
105
|
-
request.onWireFrame?.();
|
|
106
|
-
// Anthropic uses the `event` field to distinguish event types
|
|
107
|
-
const eventType = sse.event;
|
|
108
|
-
if (!eventType || !sse.data)
|
|
109
|
-
continue;
|
|
110
|
-
let data;
|
|
111
|
-
try {
|
|
112
|
-
data = JSON.parse(sse.data);
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
continue; // skip malformed JSON
|
|
116
|
-
}
|
|
117
|
-
switch (eventType) {
|
|
118
|
-
case 'message_start': {
|
|
119
|
-
const msg = data.message;
|
|
120
|
-
if (msg?.usage) {
|
|
121
|
-
const u = msg.usage;
|
|
122
|
-
usage.inputTokens = u.input_tokens ?? 0;
|
|
123
|
-
usage.cacheReadTokens = u.cache_read_input_tokens;
|
|
124
|
-
usage.cacheWriteTokens = u.cache_creation_input_tokens;
|
|
125
|
-
}
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
case 'content_block_start': {
|
|
129
|
-
currentBlockIndex = data.index ?? currentBlockIndex + 1;
|
|
130
|
-
const block = data.content_block;
|
|
131
|
-
if (!block)
|
|
132
|
-
break;
|
|
133
|
-
const blockType = block.type;
|
|
134
|
-
if (blockType === 'thinking') {
|
|
135
|
-
blockAccumulators.set(currentBlockIndex, { type: 'thinking', text: '' });
|
|
136
|
-
yield { type: 'thinking_start' };
|
|
137
|
-
}
|
|
138
|
-
else if (blockType === 'tool_use') {
|
|
139
|
-
const toolCallId = block.id || '';
|
|
140
|
-
const toolName = block.name || '';
|
|
141
|
-
blockAccumulators.set(currentBlockIndex, {
|
|
142
|
-
type: 'tool_use',
|
|
143
|
-
toolCallId,
|
|
144
|
-
toolName,
|
|
145
|
-
argsJson: '',
|
|
146
|
-
});
|
|
147
|
-
yield { type: 'tool_call_start', toolCallId, toolName };
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
// text or redacted_thinking — treat as text
|
|
151
|
-
blockAccumulators.set(currentBlockIndex, { type: 'text', text: '' });
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
case 'content_block_delta': {
|
|
156
|
-
const idx = data.index ?? currentBlockIndex;
|
|
157
|
-
const delta = data.delta;
|
|
158
|
-
if (!delta)
|
|
159
|
-
break;
|
|
160
|
-
const deltaType = delta.type;
|
|
161
|
-
const acc = blockAccumulators.get(idx);
|
|
162
|
-
if (deltaType === 'text_delta') {
|
|
163
|
-
const text = delta.text || '';
|
|
164
|
-
if (acc && acc.type === 'text')
|
|
165
|
-
acc.text += text;
|
|
166
|
-
yield { type: 'text_delta', delta: text };
|
|
167
|
-
}
|
|
168
|
-
else if (deltaType === 'thinking_delta') {
|
|
169
|
-
const thinking = delta.thinking || '';
|
|
170
|
-
if (acc && acc.type === 'thinking')
|
|
171
|
-
acc.text += thinking;
|
|
172
|
-
yield { type: 'thinking_delta', delta: thinking };
|
|
173
|
-
}
|
|
174
|
-
else if (deltaType === 'input_json_delta') {
|
|
175
|
-
const partial = delta.partial_json || '';
|
|
176
|
-
if (acc && acc.type === 'tool_use') {
|
|
177
|
-
acc.argsJson += partial;
|
|
178
|
-
yield { type: 'tool_call_delta', toolCallId: acc.toolCallId, argsDelta: partial };
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case 'content_block_stop': {
|
|
184
|
-
const idx = data.index ?? currentBlockIndex;
|
|
185
|
-
const acc = blockAccumulators.get(idx);
|
|
186
|
-
if (!acc)
|
|
187
|
-
break;
|
|
188
|
-
// Extract signature from content_block_stop for thinking blocks
|
|
189
|
-
const stopBlock = data.content_block;
|
|
190
|
-
if (acc.type === 'text') {
|
|
191
|
-
contentBlocks.push({ type: 'text', text: acc.text });
|
|
192
|
-
}
|
|
193
|
-
else if (acc.type === 'thinking') {
|
|
194
|
-
const signature = stopBlock?.signature ?? acc.signature;
|
|
195
|
-
contentBlocks.push({ type: 'thinking', text: acc.text, signature });
|
|
196
|
-
}
|
|
197
|
-
else if (acc.type === 'tool_use') {
|
|
198
|
-
let args = {};
|
|
199
|
-
try {
|
|
200
|
-
args = acc.argsJson ? JSON.parse(acc.argsJson) : {};
|
|
201
|
-
}
|
|
202
|
-
catch {
|
|
203
|
-
// JSON is malformed — likely truncated due to max_tokens.
|
|
204
|
-
// Mark with __parse_error so the executor returns a clear error
|
|
205
|
-
// to the LLM instead of a confusing "missing required property" message.
|
|
206
|
-
console.warn(`[AnthropicProvider] Malformed tool call JSON for "${acc.toolName}" ` +
|
|
207
|
-
`(stopReason=${stopReason ?? 'unknown'}, ` +
|
|
208
|
-
`argsJson length=${acc.argsJson.length}): ` +
|
|
209
|
-
acc.argsJson.slice(0, 200));
|
|
210
|
-
args = { __parse_error: true, __raw: acc.argsJson };
|
|
211
|
-
}
|
|
212
|
-
contentBlocks.push({
|
|
213
|
-
type: 'tool_call',
|
|
214
|
-
toolCallId: acc.toolCallId,
|
|
215
|
-
toolName: acc.toolName,
|
|
216
|
-
args,
|
|
217
|
-
});
|
|
218
|
-
yield {
|
|
219
|
-
type: 'tool_call_end',
|
|
220
|
-
toolCallId: acc.toolCallId,
|
|
221
|
-
toolName: acc.toolName,
|
|
222
|
-
args,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
blockAccumulators.delete(idx);
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
case 'message_delta': {
|
|
229
|
-
const delta = data.delta;
|
|
230
|
-
if (delta?.stop_reason) {
|
|
231
|
-
stopReason = mapStopReason(delta.stop_reason);
|
|
232
|
-
}
|
|
233
|
-
const u = data.usage;
|
|
234
|
-
if (u) {
|
|
235
|
-
usage.outputTokens = u.output_tokens ?? usage.outputTokens;
|
|
236
|
-
// Anthropic-COMPATIBLE relays (context-usage-zero-input-tokens A)
|
|
237
|
-
// commonly disclose the real input token count only here, with
|
|
238
|
-
// `message_start` carrying 0 or nothing. FIRST-PARTY streams never
|
|
239
|
-
// put input-side fields in `message_delta`, so the takeover below is
|
|
240
|
-
// dead code on api.anthropic.com and official behaviour stays
|
|
241
|
-
// byte-identical; across several deltas the last non-zero wins.
|
|
242
|
-
const inputTokens = u.input_tokens ?? 0;
|
|
243
|
-
if (inputTokens > 0) {
|
|
244
|
-
// TAKE OVER, NEVER SUM. A delta that discloses input may report
|
|
245
|
-
// an INCLUSIVE total; keeping `message_start`'s additive cache
|
|
246
|
-
// fields on top of it double-counts the cached tokens and fires
|
|
247
|
-
// compaction early (P1-10). The input side is re-derived from
|
|
248
|
-
// this event alone: the delta's own cache terms when present,
|
|
249
|
-
// cleared when absent.
|
|
250
|
-
usage.inputTokens = inputTokens;
|
|
251
|
-
usage.cacheReadTokens = u.cache_read_input_tokens;
|
|
252
|
-
usage.cacheWriteTokens = u.cache_creation_input_tokens;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case 'message_stop': {
|
|
258
|
-
if (request.signal?.aborted)
|
|
259
|
-
return;
|
|
260
|
-
const message = {
|
|
261
|
-
role: 'assistant',
|
|
262
|
-
content: contentBlocks,
|
|
263
|
-
usage,
|
|
264
|
-
stopReason,
|
|
265
|
-
};
|
|
266
|
-
yield { type: 'done', message, usage };
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
case 'error': {
|
|
270
|
-
const errObj = data.error;
|
|
271
|
-
const errMsg = errObj?.message || 'Unknown Anthropic error';
|
|
272
|
-
const errType = errObj?.type || '';
|
|
273
|
-
// Map Anthropic error types to our classification
|
|
274
|
-
const llmErr = /overloaded/i.test(errType)
|
|
275
|
-
? new LLMError(errMsg, this.id, 'overloaded', true)
|
|
276
|
-
: /rate/i.test(errType)
|
|
277
|
-
? new LLMError(errMsg, this.id, 'rate_limit', true)
|
|
278
|
-
: /auth/i.test(errType)
|
|
279
|
-
? new LLMError(errMsg, this.id, 'auth_error', false)
|
|
280
|
-
: new LLMError(errMsg, this.id, 'server_error', true);
|
|
281
|
-
yield { type: 'error', error: llmErr };
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
default:
|
|
285
|
-
// ping, etc. — ignored
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
// A caller abort is silent; only an incomplete transport EOF is retried.
|
|
290
|
-
if (request.signal?.aborted)
|
|
291
|
-
return;
|
|
292
|
-
yield {
|
|
293
|
-
type: 'error',
|
|
294
|
-
error: new LLMError(`${this.id} stream truncated before message_stop`, this.id, 'network_error', true),
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
catch (err) {
|
|
298
|
-
if (request.signal?.aborted)
|
|
299
|
-
return;
|
|
300
|
-
yield { type: 'error', error: wrapFetchError(err, this.id) };
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
// -----------------------------------------------------------------------
|
|
304
|
-
// complete
|
|
305
|
-
// -----------------------------------------------------------------------
|
|
306
|
-
async complete(request) {
|
|
307
|
-
return consumeStream(this.stream(request));
|
|
308
|
-
}
|
|
309
|
-
// -----------------------------------------------------------------------
|
|
310
|
-
// listModels
|
|
311
|
-
// -----------------------------------------------------------------------
|
|
312
|
-
async listModels(apiKey, baseUrl, signal) {
|
|
313
|
-
const base = (baseUrl || this.defaultBaseUrl).replace(/\/+$/, '');
|
|
314
|
-
const url = `${base}/v1/models`;
|
|
315
|
-
const scope = createModelDiscoverySignal(signal);
|
|
316
|
-
try {
|
|
317
|
-
const models = [];
|
|
318
|
-
const seen = new Set();
|
|
319
|
-
let cursor;
|
|
320
|
-
for (let page = 0; page < 20 && !scope.signal.aborted; page++) {
|
|
321
|
-
try {
|
|
322
|
-
const pageUrl = cursor === undefined ? url : `${url}?after_id=${encodeURIComponent(cursor)}`;
|
|
323
|
-
const res = await fetch(pageUrl, {
|
|
324
|
-
method: 'GET',
|
|
325
|
-
headers: { 'x-api-key': apiKey, 'anthropic-version': ANTHROPIC_VERSION },
|
|
326
|
-
signal: scope.signal,
|
|
327
|
-
});
|
|
328
|
-
if (!res.ok)
|
|
329
|
-
break;
|
|
330
|
-
const data = await res.json();
|
|
331
|
-
if (!Array.isArray(data.data))
|
|
332
|
-
break;
|
|
333
|
-
models.push(...data.data);
|
|
334
|
-
const next = data.last_id;
|
|
335
|
-
if (data.has_more !== true || typeof next !== 'string' || next.length === 0 || seen.has(next))
|
|
336
|
-
break;
|
|
337
|
-
seen.add(next);
|
|
338
|
-
cursor = next;
|
|
339
|
-
}
|
|
340
|
-
catch {
|
|
341
|
-
break; // Preserve metadata from earlier pages when continuation fails.
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (signal?.aborted)
|
|
345
|
-
return [];
|
|
346
|
-
// The Anthropic models endpoint does NOT report an output ceiling, so this
|
|
347
|
-
// maps through the static table and deliberately does NOT call
|
|
348
|
-
// `learnModelCeiling`: asserting 64000 here is how `claude-3-5-haiku` ends
|
|
349
|
-
// up with a "discovered" ceiling that outranks its correct table entry.
|
|
350
|
-
return models.map((m) => ({
|
|
351
|
-
id: String(m.id || ''),
|
|
352
|
-
name: String(m.display_name || m.id || ''),
|
|
353
|
-
provider: this.id,
|
|
354
|
-
...reportedContextWindow(m),
|
|
355
|
-
maxOutputTokens: staticCeilingFor(this.id, String(m.id || '')) ?? DEFAULT_MAX_OUTPUT_TOKENS,
|
|
356
|
-
supportsThinking: /claude-(sonnet-4|opus-4)/i.test(String(m.id)),
|
|
357
|
-
supportsTools: true,
|
|
358
|
-
supportsImages: true,
|
|
359
|
-
cost: { input: 0, output: 0 },
|
|
360
|
-
}));
|
|
361
|
-
}
|
|
362
|
-
catch {
|
|
363
|
-
return [];
|
|
364
|
-
}
|
|
365
|
-
finally {
|
|
366
|
-
scope.dispose();
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
// ---------------------------------------------------------------------------
|
|
371
|
-
// Internal: request body builder
|
|
372
|
-
// ---------------------------------------------------------------------------
|
|
373
|
-
function buildRequestBody(request) {
|
|
374
|
-
// Requested thinking budget FIRST: the cap and the budget are resolved
|
|
375
|
-
// together because Anthropic requires `max_tokens > budget_tokens`, and
|
|
376
|
-
// `--thinking xhigh` (65536) against the 64000 default is otherwise a
|
|
377
|
-
// guaranteed 400 on every single request.
|
|
378
|
-
const requestedBudget = request.thinkingBudget
|
|
379
|
-
?? (request.thinkingLevel ? THINKING_BUDGET[request.thinkingLevel] : 0);
|
|
380
|
-
const resolution = resolveOutputTokens({
|
|
381
|
-
providerId: 'anthropic',
|
|
382
|
-
modelId: request.model,
|
|
383
|
-
...(request.maxTokens !== undefined ? { requested: request.maxTokens } : {}),
|
|
384
|
-
...(request.modelLimits ? { modelLimits: request.modelLimits } : {}),
|
|
385
|
-
thinkingBudget: requestedBudget,
|
|
386
|
-
});
|
|
387
|
-
const body = {
|
|
388
|
-
model: request.model,
|
|
389
|
-
messages: convertMessages(request.messages),
|
|
390
|
-
stream: true,
|
|
391
|
-
max_tokens: resolution.value,
|
|
392
|
-
};
|
|
393
|
-
if (request.systemPrompt) {
|
|
394
|
-
body.system = request.systemPrompt;
|
|
395
|
-
}
|
|
396
|
-
if (request.tools && request.tools.length > 0) {
|
|
397
|
-
body.tools = request.tools.map(convertToolDefinition);
|
|
398
|
-
}
|
|
399
|
-
if (request.temperature !== undefined) {
|
|
400
|
-
body.temperature = request.temperature;
|
|
401
|
-
}
|
|
402
|
-
if (request.stopSequences && request.stopSequences.length > 0) {
|
|
403
|
-
body.stop_sequences = request.stopSequences;
|
|
404
|
-
}
|
|
405
|
-
// Extended thinking. A resolved budget of 0 means the cap cannot legally house
|
|
406
|
-
// a `budget_tokens` at all, so the block is omitted entirely — and `temperature`
|
|
407
|
-
// is therefore NOT deleted, because nothing is enabled that forbids it.
|
|
408
|
-
const thinkingBudget = resolution.thinkingBudget ?? requestedBudget;
|
|
409
|
-
if (thinkingBudget > 0) {
|
|
410
|
-
body.thinking = {
|
|
411
|
-
type: 'enabled',
|
|
412
|
-
budget_tokens: thinkingBudget,
|
|
413
|
-
};
|
|
414
|
-
// When thinking is enabled, temperature must not be set (Anthropic requirement)
|
|
415
|
-
delete body.temperature;
|
|
416
|
-
}
|
|
417
|
-
return body;
|
|
418
|
-
}
|
|
419
|
-
// ---------------------------------------------------------------------------
|
|
420
|
-
// Internal: message format conversion
|
|
421
|
-
// ---------------------------------------------------------------------------
|
|
422
|
-
function convertMessages(messages) {
|
|
423
|
-
const result = [];
|
|
424
|
-
for (const msg of messages) {
|
|
425
|
-
switch (msg.role) {
|
|
426
|
-
case 'user':
|
|
427
|
-
result.push({
|
|
428
|
-
role: 'user',
|
|
429
|
-
content: typeof msg.content === 'string'
|
|
430
|
-
? msg.content
|
|
431
|
-
: convertContentParts(msg.content),
|
|
432
|
-
});
|
|
433
|
-
break;
|
|
434
|
-
case 'assistant':
|
|
435
|
-
result.push({
|
|
436
|
-
role: 'assistant',
|
|
437
|
-
content: convertAssistantContent(msg.content),
|
|
438
|
-
});
|
|
439
|
-
break;
|
|
440
|
-
case 'tool_result':
|
|
441
|
-
result.push({
|
|
442
|
-
role: 'user',
|
|
443
|
-
content: [
|
|
444
|
-
{
|
|
445
|
-
type: 'tool_result',
|
|
446
|
-
tool_use_id: msg.toolCallId,
|
|
447
|
-
content: typeof msg.content === 'string'
|
|
448
|
-
? msg.content
|
|
449
|
-
: convertContentParts(msg.content),
|
|
450
|
-
is_error: msg.isError || false,
|
|
451
|
-
},
|
|
452
|
-
],
|
|
453
|
-
});
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return result;
|
|
458
|
-
}
|
|
459
|
-
function convertContentParts(parts) {
|
|
460
|
-
return parts.map((part) => {
|
|
461
|
-
if (part.type === 'text') {
|
|
462
|
-
return { type: 'text', text: part.text };
|
|
463
|
-
}
|
|
464
|
-
// image
|
|
465
|
-
return {
|
|
466
|
-
type: 'image',
|
|
467
|
-
source: {
|
|
468
|
-
type: 'base64',
|
|
469
|
-
media_type: part.mediaType,
|
|
470
|
-
data: part.data,
|
|
471
|
-
},
|
|
472
|
-
};
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
function convertAssistantContent(blocks) {
|
|
476
|
-
return blocks.map((block) => {
|
|
477
|
-
switch (block.type) {
|
|
478
|
-
case 'text':
|
|
479
|
-
return { type: 'text', text: block.text };
|
|
480
|
-
case 'thinking':
|
|
481
|
-
return {
|
|
482
|
-
type: 'thinking',
|
|
483
|
-
thinking: block.text,
|
|
484
|
-
...(block.signature ? { signature: block.signature } : {}),
|
|
485
|
-
};
|
|
486
|
-
case 'tool_call':
|
|
487
|
-
return {
|
|
488
|
-
type: 'tool_use',
|
|
489
|
-
id: block.toolCallId,
|
|
490
|
-
name: block.toolName,
|
|
491
|
-
input: block.args,
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
function convertToolDefinition(tool) {
|
|
497
|
-
return {
|
|
498
|
-
name: tool.name,
|
|
499
|
-
description: tool.description,
|
|
500
|
-
input_schema: tool.parameters,
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
// ---------------------------------------------------------------------------
|
|
504
|
-
// Internal: helpers
|
|
505
|
-
// ---------------------------------------------------------------------------
|
|
506
|
-
function mapStopReason(reason) {
|
|
507
|
-
switch (reason) {
|
|
508
|
-
case 'end_turn': return 'end_turn';
|
|
509
|
-
case 'tool_use': return 'tool_use';
|
|
510
|
-
case 'max_tokens': return 'max_tokens';
|
|
511
|
-
case 'stop_sequence': return 'stop_sequence';
|
|
512
|
-
default: return 'end_turn';
|
|
513
|
-
}
|
|
514
|
-
}
|
|
1
|
+
const _0x1862e0=_0x45a3;(function(_0x1fc691,_0x2a09b1){const _0x57a857=_0x45a3,_0x8d739d=_0x1fc691();while(!![]){try{const _0x32d42a=parseInt(_0x57a857(0x140))/0x1+parseInt(_0x57a857(0x127))/0x2+parseInt(_0x57a857(0x176))/0x3+parseInt(_0x57a857(0x12d))/0x4+-parseInt(_0x57a857(0x139))/0x5*(-parseInt(_0x57a857(0x177))/0x6)+-parseInt(_0x57a857(0x12c))/0x7*(parseInt(_0x57a857(0x14c))/0x8)+-parseInt(_0x57a857(0x108))/0x9*(parseInt(_0x57a857(0x15b))/0xa);if(_0x32d42a===_0x2a09b1)break;else _0x8d739d['push'](_0x8d739d['shift']());}catch(_0x44f904){_0x8d739d['push'](_0x8d739d['shift']());}}}(_0x427d,0x1cfa8));import{reportedContextWindow}from'../context-window.js';import{createModelDiscoverySignal}from'../model-discovery.js';import{THINKING_BUDGET}from'../types.js';import{LLMError,classifyHttpError,wrapFetchError}from'../provider.js';import{DEFAULT_MAX_OUTPUT_TOKENS,resolveOutputTokens,staticCeilingFor}from'../output-limits.js';import{sendWithOutputLimitRecovery}from'../output-limit-recovery.js';import{parseSSEStream}from'../stream-utils.js';import{consumeStream}from'../stream-utils.js';const DEFAULT_BASE_URL=_0x1862e0(0x14a),ANTHROPIC_VERSION=_0x1862e0(0x141);export class AnthropicProvider{['id']=_0x1862e0(0x104);['displayName']=_0x1862e0(0x13a);[_0x1862e0(0x17a)]=DEFAULT_BASE_URL;async*[_0x1862e0(0x17b)](_0x1b2abb){const _0x1d0735=_0x1862e0;if(_0x1b2abb['signal']?.[_0x1d0735(0x119)])return;const _0x17b7d5=(_0x1b2abb['baseUrl']||this[_0x1d0735(0x17a)])[_0x1d0735(0x15c)](/\/+$/,''),_0x4e300d=''[_0x1d0735(0x110)](_0x17b7d5,_0x1d0735(0x169)),_0x2bc1cb=buildRequestBody(_0x1b2abb);let _0x2c0177,_0x119eb0='';try{const _0x59c81a=await sendWithOutputLimitRecovery({'providerId':this['id'],'modelId':_0x1b2abb['model'],'body':_0x2bc1cb,'tokenField':_0x1d0735(0x10c),'send':_0x78464a=>fetch(_0x4e300d,{'method':_0x1d0735(0x116),'headers':{'Content-Type':'application/json','x-api-key':_0x1b2abb[_0x1d0735(0x126)],'anthropic-version':ANTHROPIC_VERSION},'body':JSON[_0x1d0735(0x163)](_0x78464a),'signal':_0x1b2abb['signal']})});_0x2c0177=_0x59c81a[_0x1d0735(0x12b)],_0x119eb0=_0x59c81a['bodyText'];}catch(_0x31aac6){if(_0x1b2abb[_0x1d0735(0x14e)]?.[_0x1d0735(0x119)])return;yield{'type':_0x1d0735(0x16d),'error':wrapFetchError(_0x31aac6,this['id'])};return;}if(_0x1b2abb[_0x1d0735(0x14e)]?.[_0x1d0735(0x119)])return;if(!_0x2c0177['ok']){yield{'type':_0x1d0735(0x16d),'error':classifyHttpError(_0x2c0177[_0x1d0735(0x174)],_0x119eb0,this['id'],_0x2c0177[_0x1d0735(0x10a)])};return;}if(!_0x2c0177[_0x1d0735(0x158)]){yield{'type':'error','error':new LLMError('Response\x20body\x20is\x20null',this['id'],_0x1d0735(0x11c),!![])};return;}const _0x3dbc6e={'inputTokens':0x0,'outputTokens':0x0},_0x349bcc=[];let _0x28f3f1;const _0x639c0=new Map();let _0x32d68d=-0x1;try{const _0xa62f3f=_0x1b2abb[_0x1d0735(0x15a)]??_0x1b2abb['signal'];for await(const _0x134fa6 of parseSSEStream(_0x2c0177[_0x1d0735(0x158)],_0xa62f3f)){if(_0x1b2abb[_0x1d0735(0x14e)]?.['aborted'])return;_0x1b2abb['onWireFrame']?.();const _0x5909d3=_0x134fa6[_0x1d0735(0x131)];if(!_0x5909d3||!_0x134fa6[_0x1d0735(0x15e)])continue;let _0x4537bb;try{_0x4537bb=JSON[_0x1d0735(0x11b)](_0x134fa6[_0x1d0735(0x15e)]);}catch{continue;}switch(_0x5909d3){case _0x1d0735(0x145):{const _0xd2e720=_0x4537bb[_0x1d0735(0x134)];if(_0xd2e720?.[_0x1d0735(0x157)]){const _0xb6f047=_0xd2e720[_0x1d0735(0x157)];_0x3dbc6e[_0x1d0735(0x12f)]=_0xb6f047[_0x1d0735(0x128)]??0x0,_0x3dbc6e['cacheReadTokens']=_0xb6f047[_0x1d0735(0x154)],_0x3dbc6e[_0x1d0735(0x17c)]=_0xb6f047[_0x1d0735(0x120)];}break;}case _0x1d0735(0x13c):{_0x32d68d=_0x4537bb['index']??_0x32d68d+0x1;const _0x2a7083=_0x4537bb[_0x1d0735(0x14d)];if(!_0x2a7083)break;const _0x49cacf=_0x2a7083[_0x1d0735(0x16c)];if(_0x49cacf===_0x1d0735(0x112))_0x639c0['set'](_0x32d68d,{'type':'thinking','text':''}),yield{'type':_0x1d0735(0x171)};else{if(_0x49cacf===_0x1d0735(0x130)){const _0x5d2d4d=_0x2a7083['id']||'',_0x3b4a9b=_0x2a7083[_0x1d0735(0x12a)]||'';_0x639c0[_0x1d0735(0x10e)](_0x32d68d,{'type':_0x1d0735(0x130),'toolCallId':_0x5d2d4d,'toolName':_0x3b4a9b,'argsJson':''}),yield{'type':'tool_call_start','toolCallId':_0x5d2d4d,'toolName':_0x3b4a9b};}else _0x639c0['set'](_0x32d68d,{'type':_0x1d0735(0x115),'text':''});}break;}case _0x1d0735(0x152):{const _0x1f9abe=_0x4537bb[_0x1d0735(0x173)]??_0x32d68d,_0x5e5416=_0x4537bb[_0x1d0735(0x143)];if(!_0x5e5416)break;const _0x524a9b=_0x5e5416[_0x1d0735(0x16c)],_0x4bc231=_0x639c0[_0x1d0735(0x172)](_0x1f9abe);if(_0x524a9b===_0x1d0735(0x146)){const _0x2d98e5=_0x5e5416[_0x1d0735(0x115)]||'';if(_0x4bc231&&_0x4bc231[_0x1d0735(0x16c)]===_0x1d0735(0x115))_0x4bc231[_0x1d0735(0x115)]+=_0x2d98e5;yield{'type':_0x1d0735(0x146),'delta':_0x2d98e5};}else{if(_0x524a9b===_0x1d0735(0x159)){const _0x3cbc98=_0x5e5416[_0x1d0735(0x112)]||'';if(_0x4bc231&&_0x4bc231[_0x1d0735(0x16c)]===_0x1d0735(0x112))_0x4bc231[_0x1d0735(0x115)]+=_0x3cbc98;yield{'type':_0x1d0735(0x159),'delta':_0x3cbc98};}else{if(_0x524a9b==='input_json_delta'){const _0x4b39eb=_0x5e5416['partial_json']||'';_0x4bc231&&_0x4bc231['type']===_0x1d0735(0x130)&&(_0x4bc231['argsJson']+=_0x4b39eb,yield{'type':'tool_call_delta','toolCallId':_0x4bc231[_0x1d0735(0x13b)],'argsDelta':_0x4b39eb});}}}break;}case _0x1d0735(0x124):{const _0x3c6ae2=_0x4537bb[_0x1d0735(0x173)]??_0x32d68d,_0x1976dd=_0x639c0['get'](_0x3c6ae2);if(!_0x1976dd)break;const _0x3a74f7=_0x4537bb[_0x1d0735(0x14d)];if(_0x1976dd[_0x1d0735(0x16c)]==='text')_0x349bcc[_0x1d0735(0x106)]({'type':'text','text':_0x1976dd['text']});else{if(_0x1976dd[_0x1d0735(0x16c)]===_0x1d0735(0x112)){const _0x16f027=_0x3a74f7?.[_0x1d0735(0x10d)]??_0x1976dd[_0x1d0735(0x10d)];_0x349bcc[_0x1d0735(0x106)]({'type':_0x1d0735(0x112),'text':_0x1976dd['text'],'signature':_0x16f027});}else{if(_0x1976dd['type']===_0x1d0735(0x130)){let _0x4826bd={};try{_0x4826bd=_0x1976dd[_0x1d0735(0x148)]?JSON['parse'](_0x1976dd[_0x1d0735(0x148)]):{};}catch{console[_0x1d0735(0x117)](_0x1d0735(0x114)[_0x1d0735(0x110)](_0x1976dd['toolName'],'\x22\x20')+_0x1d0735(0x160)['concat'](_0x28f3f1??_0x1d0735(0x14b),',\x20')+_0x1d0735(0x16b)[_0x1d0735(0x110)](_0x1976dd[_0x1d0735(0x148)][_0x1d0735(0x155)],_0x1d0735(0x12e))+_0x1976dd[_0x1d0735(0x148)][_0x1d0735(0x14f)](0x0,0xc8)),_0x4826bd={'__parse_error':!![],'__raw':_0x1976dd['argsJson']};}_0x349bcc[_0x1d0735(0x106)]({'type':_0x1d0735(0x147),'toolCallId':_0x1976dd[_0x1d0735(0x13b)],'toolName':_0x1976dd[_0x1d0735(0x123)],'args':_0x4826bd}),yield{'type':_0x1d0735(0x151),'toolCallId':_0x1976dd[_0x1d0735(0x13b)],'toolName':_0x1976dd[_0x1d0735(0x123)],'args':_0x4826bd};}}}_0x639c0[_0x1d0735(0x179)](_0x3c6ae2);break;}case _0x1d0735(0x133):{const _0x4b6ba0=_0x4537bb[_0x1d0735(0x143)];_0x4b6ba0?.['stop_reason']&&(_0x28f3f1=mapStopReason(_0x4b6ba0['stop_reason']));const _0x2a5691=_0x4537bb[_0x1d0735(0x157)];if(_0x2a5691){_0x3dbc6e[_0x1d0735(0x118)]=_0x2a5691[_0x1d0735(0x10b)]??_0x3dbc6e[_0x1d0735(0x118)];const _0x3e2002=_0x2a5691[_0x1d0735(0x128)]??0x0;_0x3e2002>0x0&&(_0x3dbc6e[_0x1d0735(0x12f)]=_0x3e2002,_0x3dbc6e[_0x1d0735(0x144)]=_0x2a5691['cache_read_input_tokens'],_0x3dbc6e['cacheWriteTokens']=_0x2a5691[_0x1d0735(0x120)]);}break;}case _0x1d0735(0x13e):{if(_0x1b2abb['signal']?.[_0x1d0735(0x119)])return;const _0x5a9f63={'role':_0x1d0735(0x111),'content':_0x349bcc,'usage':_0x3dbc6e,'stopReason':_0x28f3f1};yield{'type':_0x1d0735(0x109),'message':_0x5a9f63,'usage':_0x3dbc6e};return;}case'error':{const _0x316f38=_0x4537bb[_0x1d0735(0x16d)],_0x505bf1=_0x316f38?.['message']||_0x1d0735(0x165),_0x1ded2a=_0x316f38?.['type']||'',_0x1df2ba=/overloaded/i[_0x1d0735(0x162)](_0x1ded2a)?new LLMError(_0x505bf1,this['id'],_0x1d0735(0x10f),!![]):/rate/i['test'](_0x1ded2a)?new LLMError(_0x505bf1,this['id'],'rate_limit',!![]):/auth/i[_0x1d0735(0x162)](_0x1ded2a)?new LLMError(_0x505bf1,this['id'],_0x1d0735(0x16e),![]):new LLMError(_0x505bf1,this['id'],'server_error',!![]);yield{'type':'error','error':_0x1df2ba};return;}default:break;}}if(_0x1b2abb[_0x1d0735(0x14e)]?.[_0x1d0735(0x119)])return;yield{'type':_0x1d0735(0x16d),'error':new LLMError(''[_0x1d0735(0x110)](this['id'],_0x1d0735(0x161)),this['id'],_0x1d0735(0x11c),!![])};}catch(_0x58fa93){if(_0x1b2abb[_0x1d0735(0x14e)]?.[_0x1d0735(0x119)])return;yield{'type':'error','error':wrapFetchError(_0x58fa93,this['id'])};}}async[_0x1862e0(0x138)](_0x31d61a){const _0x20a5fc=_0x1862e0;return consumeStream(this[_0x20a5fc(0x17b)](_0x31d61a));}async['listModels'](_0x4b66f0,_0x2b2ab2,_0x592f5a){const _0x2090ad=_0x1862e0,_0x471e36=(_0x2b2ab2||this[_0x2090ad(0x17a)])['replace'](/\/+$/,''),_0x28517c=''[_0x2090ad(0x110)](_0x471e36,_0x2090ad(0x15d)),_0x39b7e3=createModelDiscoverySignal(_0x592f5a);try{const _0x3c464d=[],_0x168519=new Set();let _0x329ab5;for(let _0x4c43b1=0x0;_0x4c43b1<0x14&&!_0x39b7e3[_0x2090ad(0x14e)]['aborted'];_0x4c43b1++){try{const _0x2124d4=_0x329ab5===undefined?_0x28517c:''['concat'](_0x28517c,_0x2090ad(0x122))[_0x2090ad(0x110)](encodeURIComponent(_0x329ab5)),_0x19a377=await fetch(_0x2124d4,{'method':_0x2090ad(0x156),'headers':{'x-api-key':_0x4b66f0,'anthropic-version':ANTHROPIC_VERSION},'signal':_0x39b7e3[_0x2090ad(0x14e)]});if(!_0x19a377['ok'])break;const _0x33bd70=await _0x19a377[_0x2090ad(0x105)]();if(!Array['isArray'](_0x33bd70[_0x2090ad(0x15e)]))break;_0x3c464d[_0x2090ad(0x106)](..._0x33bd70['data']);const _0x81b9eb=_0x33bd70['last_id'];if(_0x33bd70[_0x2090ad(0x11f)]!==!![]||typeof _0x81b9eb!==_0x2090ad(0x11a)||_0x81b9eb[_0x2090ad(0x155)]===0x0||_0x168519['has'](_0x81b9eb))break;_0x168519[_0x2090ad(0x164)](_0x81b9eb),_0x329ab5=_0x81b9eb;}catch{break;}}if(_0x592f5a?.[_0x2090ad(0x119)])return[];return _0x3c464d[_0x2090ad(0x13f)](_0x2ffe25=>({'id':String(_0x2ffe25['id']||''),'name':String(_0x2ffe25[_0x2090ad(0x150)]||_0x2ffe25['id']||''),'provider':this['id'],...reportedContextWindow(_0x2ffe25),'maxOutputTokens':staticCeilingFor(this['id'],String(_0x2ffe25['id']||''))??DEFAULT_MAX_OUTPUT_TOKENS,'supportsThinking':/claude-(sonnet-4|opus-4)/i[_0x2090ad(0x162)](String(_0x2ffe25['id'])),'supportsTools':!![],'supportsImages':!![],'cost':{'input':0x0,'output':0x0}}));}catch{return[];}finally{_0x39b7e3['dispose']();}}}function buildRequestBody(_0x239859){const _0x180768=_0x1862e0,_0x25d942=_0x239859[_0x180768(0x16f)]??(_0x239859[_0x180768(0x166)]?THINKING_BUDGET[_0x239859[_0x180768(0x166)]]:0x0),_0x3bc959=resolveOutputTokens({'providerId':_0x180768(0x104),'modelId':_0x239859[_0x180768(0x153)],..._0x239859[_0x180768(0x135)]!==undefined?{'requested':_0x239859[_0x180768(0x135)]}:{},..._0x239859[_0x180768(0x136)]?{'modelLimits':_0x239859[_0x180768(0x136)]}:{},'thinkingBudget':_0x25d942}),_0x2dda75={'model':_0x239859[_0x180768(0x153)],'messages':convertMessages(_0x239859[_0x180768(0x149)]),'stream':!![],'max_tokens':_0x3bc959[_0x180768(0x125)]};_0x239859['systemPrompt']&&(_0x2dda75[_0x180768(0x178)]=_0x239859[_0x180768(0x16a)]);_0x239859[_0x180768(0x142)]&&_0x239859['tools']['length']>0x0&&(_0x2dda75[_0x180768(0x142)]=_0x239859[_0x180768(0x142)][_0x180768(0x13f)](convertToolDefinition));_0x239859[_0x180768(0x113)]!==undefined&&(_0x2dda75['temperature']=_0x239859['temperature']);_0x239859[_0x180768(0x170)]&&_0x239859[_0x180768(0x170)]['length']>0x0&&(_0x2dda75[_0x180768(0x11e)]=_0x239859[_0x180768(0x170)]);const _0xcec549=_0x3bc959[_0x180768(0x16f)]??_0x25d942;return _0xcec549>0x0&&(_0x2dda75[_0x180768(0x112)]={'type':_0x180768(0x15f),'budget_tokens':_0xcec549},delete _0x2dda75[_0x180768(0x113)]),_0x2dda75;}function convertMessages(_0x32b4c0){const _0x37f652=_0x1862e0,_0x228fde=[];for(const _0x1929c2 of _0x32b4c0){switch(_0x1929c2['role']){case _0x37f652(0x121):_0x228fde['push']({'role':_0x37f652(0x121),'content':typeof _0x1929c2[_0x37f652(0x107)]===_0x37f652(0x11a)?_0x1929c2['content']:convertContentParts(_0x1929c2['content'])});break;case'assistant':_0x228fde[_0x37f652(0x106)]({'role':'assistant','content':convertAssistantContent(_0x1929c2['content'])});break;case _0x37f652(0x137):_0x228fde[_0x37f652(0x106)]({'role':_0x37f652(0x121),'content':[{'type':_0x37f652(0x137),'tool_use_id':_0x1929c2[_0x37f652(0x13b)],'content':typeof _0x1929c2[_0x37f652(0x107)]==='string'?_0x1929c2[_0x37f652(0x107)]:convertContentParts(_0x1929c2[_0x37f652(0x107)]),'is_error':_0x1929c2['isError']||![]}]});break;}}return _0x228fde;}function _0x427d(){const _0x1e424f=['ANnVBG','ChvZAa','y29UDgvUDa','mJe4ntKYovztDvLoEq','zg9Uzq','AgvHzgvYCW','B3v0Chv0x3rVA2vUCW','Bwf4x3rVA2vUCW','C2LNBMf0DxjL','C2v0','B3zLCMXVywrLza','y29Uy2f0','yxnZAxn0yw50','DgHPBMTPBMC','DgvTCgvYyxr1CMu','w0fUDgHYB3bPy1bYB3zPzgvYxsbnywXMB3jTzwqGDg9VBcbJywXSiePtt04GzM9Yici','Dgv4Da','ue9tva','D2fYBG','B3v0Chv0vg9Rzw5Z','ywjVCNrLza','C3rYAw5N','CgfYC2u','BMv0D29YA19LCNjVCG','zw5Kx3r1CM4','C3rVCf9Zzxf1zw5Jzxm','AgfZx21VCMu','y2fJAgvFy3jLyxrPB25FAw5WDxrFDg9Rzw5Z','DxnLCG','p2fMDgvYx2LKpq','Dg9VBe5HBwu','y29UDgvUDf9IBg9JA19ZDg9W','DMfSDwu','yxbPs2v5','nte0odHqEMHlrM0','Aw5WDxrFDg9Rzw5Z','yxjNCW','BMfTzq','CMvZCg9UC2u','ota0mZKZue5ZrLby','nJG0nta4uwj0v0je','ktOG','Aw5WDxruB2TLBNm','Dg9VBf91C2u','zxzLBNq','zgvZy3jPChrPB24','BwvZC2fNzv9KzwX0yq','BwvZC2fNzq','Bwf4vg9Rzw5Z','Bw9KzwXmAw1PDhm','Dg9VBf9Yzxn1Bhq','y29TCgXLDgu','mZe1AgDmqu1e','qw50AhjVCgLJ','Dg9VBenHBgXjza','y29UDgvUDf9IBg9JA19ZDgfYDa','CgfYyw1LDgvYCW','BwvZC2fNzv9ZDg9W','BwfW','mtC4oty2wfrXDKjl','mJaYmY0WnI0Wmq','Dg9VBhm','zgvSDge','y2fJAgvszwfKvg9Rzw5Z','BwvZC2fNzv9ZDgfYDa','Dgv4Df9KzwX0yq','Dg9VBf9JywXS','yxjNC0PZB24','BwvZC2fNzxm','Ahr0Chm6lY9HCgKUyw50AhjVCgLJlMnVBq','Dw5RBM93BG','ofjxC1bwza','y29UDgvUDf9IBg9JAW','C2LNBMfS','C2XPy2u','zgLZCgXHEv9Uyw1L','Dg9VBf9JywXSx2vUza','y29UDgvUDf9IBg9JA19KzwX0yq','Bw9KzwW','y2fJAgvFCMvHzf9PBNb1Df90B2TLBNm','BgvUz3rO','r0vu','DxnHz2u','yM9KEq','DgHPBMTPBMDFzgvSDge','CMvHzerLywrSAw5L','mJbNrhvdtNG','CMvWBgfJzq','l3yXl21VzgvSCW','zgf0yq','zw5HyMXLza','khn0B3bszwfZB249','ihn0CMvHBsb0CNvUy2f0zwqGyMvMB3jLig1LC3nHz2vFC3rVCa','DgvZDa','C3rYAw5NAwz5','ywrK','vw5RBM93BIbbBNrOCM9WAwmGzxjYB3i','DgHPBMTPBMDmzxzLBa','Aw1Hz2u','C3rVCf9Zzxf1zw5Jzq','l3yXl21LC3nHz2vZ','C3LZDgvTuhjVBxb0','yxjNC0PZB24GBgvUz3rOpq','DhLWzq','zxjYB3i','yxv0Af9LCNjVCG','DgHPBMTPBMDcDwrNzxq','C3rVCfnLCxvLBMnLCW','DgHPBMTPBMDFC3rHCNq','z2v0','Aw5KzxG','C3rHDhvZ','yMfZzty0','nti2nJGZu3nJD2fm','mtCZntHYv0XyAeG','C3LZDgvT','zgvSzxrL','zgvMyxvSDejHC2vvCMW','C3rYzwfT','y2fJAgvxCML0zvrVA2vUCW','yw50AhjVCgLJ'];_0x427d=function(){return _0x1e424f;};return _0x427d();}function convertContentParts(_0x3bb47c){const _0x3544b1=_0x1862e0;return _0x3bb47c[_0x3544b1(0x13f)](_0x45110b=>{const _0x28cc33=_0x3544b1;if(_0x45110b['type']==='text')return{'type':'text','text':_0x45110b['text']};return{'type':_0x28cc33(0x167),'source':{'type':_0x28cc33(0x175),'media_type':_0x45110b['mediaType'],'data':_0x45110b[_0x28cc33(0x15e)]}};});}function convertAssistantContent(_0x25aa29){const _0x557d1e=_0x1862e0;return _0x25aa29[_0x557d1e(0x13f)](_0x48dbaf=>{const _0x409dd0=_0x557d1e;switch(_0x48dbaf[_0x409dd0(0x16c)]){case _0x409dd0(0x115):return{'type':_0x409dd0(0x115),'text':_0x48dbaf[_0x409dd0(0x115)]};case _0x409dd0(0x112):return{'type':'thinking','thinking':_0x48dbaf[_0x409dd0(0x115)],..._0x48dbaf[_0x409dd0(0x10d)]?{'signature':_0x48dbaf[_0x409dd0(0x10d)]}:{}};case _0x409dd0(0x147):return{'type':_0x409dd0(0x130),'id':_0x48dbaf[_0x409dd0(0x13b)],'name':_0x48dbaf['toolName'],'input':_0x48dbaf[_0x409dd0(0x129)]};}});}function convertToolDefinition(_0x2ee908){const _0x89182c=_0x1862e0;return{'name':_0x2ee908[_0x89182c(0x12a)],'description':_0x2ee908[_0x89182c(0x132)],'input_schema':_0x2ee908[_0x89182c(0x13d)]};}function _0x45a3(_0x106990,_0x16e1ca){_0x106990=_0x106990-0x104;const _0x427d9=_0x427d();let _0x45a36c=_0x427d9[_0x106990];if(_0x45a3['jWCXrs']===undefined){var _0x4ef626=function(_0x3c5499){const _0x1160ab='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1de599='',_0x1b2abb='';for(let _0x17b7d5=0x0,_0x4e300d,_0x2bc1cb,_0x2c0177=0x0;_0x2bc1cb=_0x3c5499['charAt'](_0x2c0177++);~_0x2bc1cb&&(_0x4e300d=_0x17b7d5%0x4?_0x4e300d*0x40+_0x2bc1cb:_0x2bc1cb,_0x17b7d5++%0x4)?_0x1de599+=String['fromCharCode'](0xff&_0x4e300d>>(-0x2*_0x17b7d5&0x6)):0x0){_0x2bc1cb=_0x1160ab['indexOf'](_0x2bc1cb);}for(let _0x119eb0=0x0,_0x3dbc6e=_0x1de599['length'];_0x119eb0<_0x3dbc6e;_0x119eb0++){_0x1b2abb+='%'+('00'+_0x1de599['charCodeAt'](_0x119eb0)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x1b2abb);};_0x45a3['QwnKot']=_0x4ef626,_0x45a3['mGLVNm']={},_0x45a3['jWCXrs']=!![];}const _0x572e7d=_0x427d9[0x0];_0x45a3['zYicye']!==_0x572e7d&&(_0x45a3['mGLVNm']={},_0x45a3['zYicye']=_0x572e7d);const _0x32992f=_0x45a3['mGLVNm'][_0x106990];return _0x32992f===undefined?(_0x45a36c=_0x45a3['QwnKot'](_0x45a36c),_0x45a3['mGLVNm'][_0x106990]=_0x45a36c):_0x45a36c=_0x32992f,_0x45a36c;}function mapStopReason(_0x3b5995){const _0x3d26af=_0x1862e0;switch(_0x3b5995){case'end_turn':return _0x3d26af(0x11d);case'tool_use':return _0x3d26af(0x130);case _0x3d26af(0x10c):return _0x3d26af(0x10c);case _0x3d26af(0x168):return _0x3d26af(0x168);default:return _0x3d26af(0x11d);}}
|