@codelia/core 0.1.70 → 0.1.71
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/index.cjs +81 -53
- package/dist/index.js +81 -53
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -384,6 +384,13 @@ var ANTHROPIC_MODELS = [
|
|
|
384
384
|
provider: "anthropic",
|
|
385
385
|
aliases: ["default"]
|
|
386
386
|
},
|
|
387
|
+
{
|
|
388
|
+
id: "claude-fable-5",
|
|
389
|
+
provider: "anthropic",
|
|
390
|
+
contextWindow: 1e6,
|
|
391
|
+
maxInputTokens: 1e6,
|
|
392
|
+
maxOutputTokens: 128e3
|
|
393
|
+
},
|
|
387
394
|
{
|
|
388
395
|
id: "claude-opus-4-8",
|
|
389
396
|
provider: "anthropic",
|
|
@@ -1302,6 +1309,9 @@ var collectModelOutput = (messages) => {
|
|
|
1302
1309
|
assistantTexts.push(text);
|
|
1303
1310
|
}
|
|
1304
1311
|
}
|
|
1312
|
+
if (message.refusal) {
|
|
1313
|
+
assistantTexts.push(message.refusal);
|
|
1314
|
+
}
|
|
1305
1315
|
if (message.tool_calls?.length) {
|
|
1306
1316
|
toolCalls.push(...message.tool_calls);
|
|
1307
1317
|
}
|
|
@@ -2356,6 +2366,12 @@ var toAnthropicMessages = (messages) => {
|
|
|
2356
2366
|
return { system, messages: dropOrphanToolUseBlocks(output) };
|
|
2357
2367
|
};
|
|
2358
2368
|
var extractText = (blocks) => blocks.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
2369
|
+
var DEFAULT_REFUSAL_MESSAGE = "This request was declined by Anthropic's safety classifier.";
|
|
2370
|
+
var extractRefusal = (response) => {
|
|
2371
|
+
if (response.stop_reason !== "refusal") return null;
|
|
2372
|
+
const explanation = response.stop_details?.explanation?.trim();
|
|
2373
|
+
return explanation || DEFAULT_REFUSAL_MESSAGE;
|
|
2374
|
+
};
|
|
2359
2375
|
var toUsage = (response) => {
|
|
2360
2376
|
if (!response.usage) return null;
|
|
2361
2377
|
const baseInputTokens = response.usage.input_tokens ?? 0;
|
|
@@ -2375,58 +2391,63 @@ var toUsage = (response) => {
|
|
|
2375
2391
|
var toChatInvokeCompletion = (response, meta) => {
|
|
2376
2392
|
const blocks = response.content ?? [];
|
|
2377
2393
|
const messages = [];
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2394
|
+
const refusal = extractRefusal(response);
|
|
2395
|
+
if (refusal) {
|
|
2396
|
+
messages.push({ role: "assistant", content: null, refusal });
|
|
2397
|
+
} else {
|
|
2398
|
+
for (const block of blocks) {
|
|
2399
|
+
switch (block.type) {
|
|
2400
|
+
case "text":
|
|
2401
|
+
messages.push({
|
|
2402
|
+
role: "assistant",
|
|
2403
|
+
content: block.text
|
|
2404
|
+
});
|
|
2405
|
+
break;
|
|
2406
|
+
case "tool_use":
|
|
2407
|
+
messages.push({
|
|
2408
|
+
role: "assistant",
|
|
2409
|
+
content: null,
|
|
2410
|
+
tool_calls: [
|
|
2411
|
+
{
|
|
2412
|
+
id: block.id,
|
|
2413
|
+
type: "function",
|
|
2414
|
+
function: {
|
|
2415
|
+
name: block.name,
|
|
2416
|
+
arguments: isRecord(block.input) ? JSON.stringify(block.input) : JSON.stringify({ value: block.input })
|
|
2417
|
+
},
|
|
2418
|
+
provider_meta: block
|
|
2419
|
+
}
|
|
2420
|
+
]
|
|
2421
|
+
});
|
|
2422
|
+
break;
|
|
2423
|
+
case "thinking":
|
|
2424
|
+
messages.push({
|
|
2425
|
+
role: "reasoning",
|
|
2426
|
+
content: block.thinking,
|
|
2427
|
+
raw_item: block
|
|
2428
|
+
});
|
|
2429
|
+
break;
|
|
2430
|
+
case "redacted_thinking":
|
|
2431
|
+
messages.push({
|
|
2432
|
+
role: "reasoning",
|
|
2433
|
+
content: "[redacted]",
|
|
2434
|
+
raw_item: block
|
|
2435
|
+
});
|
|
2436
|
+
break;
|
|
2437
|
+
default:
|
|
2438
|
+
messages.push({
|
|
2439
|
+
role: "assistant",
|
|
2440
|
+
content: [
|
|
2441
|
+
{
|
|
2442
|
+
type: "other",
|
|
2443
|
+
provider: "anthropic",
|
|
2444
|
+
kind: block.type,
|
|
2445
|
+
payload: block
|
|
2446
|
+
}
|
|
2447
|
+
]
|
|
2448
|
+
});
|
|
2449
|
+
break;
|
|
2450
|
+
}
|
|
2430
2451
|
}
|
|
2431
2452
|
}
|
|
2432
2453
|
if (messages.length === 0) {
|
|
@@ -2442,7 +2463,14 @@ var toChatInvokeCompletion = (response, meta) => {
|
|
|
2442
2463
|
provider_meta: {
|
|
2443
2464
|
response_id: response.id,
|
|
2444
2465
|
model: response.model,
|
|
2445
|
-
raw_output_text: stringifyUnknown2(extractText(blocks)),
|
|
2466
|
+
raw_output_text: stringifyUnknown2(refusal ? "" : extractText(blocks)),
|
|
2467
|
+
...response.stop_details?.type === "refusal" ? {
|
|
2468
|
+
stop_details: {
|
|
2469
|
+
type: "refusal",
|
|
2470
|
+
category: response.stop_details.category,
|
|
2471
|
+
explanation: response.stop_details.explanation
|
|
2472
|
+
}
|
|
2473
|
+
} : {},
|
|
2446
2474
|
...typeof meta?.reasoning_requested === "string" ? { reasoning_requested: meta.reasoning_requested } : {},
|
|
2447
2475
|
...typeof meta?.reasoning_applied === "string" ? { reasoning_applied: meta.reasoning_applied } : {},
|
|
2448
2476
|
...typeof meta?.reasoning_fallback === "boolean" ? { reasoning_fallback: meta.reasoning_fallback } : {},
|
package/dist/index.js
CHANGED
|
@@ -320,6 +320,13 @@ var ANTHROPIC_MODELS = [
|
|
|
320
320
|
provider: "anthropic",
|
|
321
321
|
aliases: ["default"]
|
|
322
322
|
},
|
|
323
|
+
{
|
|
324
|
+
id: "claude-fable-5",
|
|
325
|
+
provider: "anthropic",
|
|
326
|
+
contextWindow: 1e6,
|
|
327
|
+
maxInputTokens: 1e6,
|
|
328
|
+
maxOutputTokens: 128e3
|
|
329
|
+
},
|
|
323
330
|
{
|
|
324
331
|
id: "claude-opus-4-8",
|
|
325
332
|
provider: "anthropic",
|
|
@@ -1238,6 +1245,9 @@ var collectModelOutput = (messages) => {
|
|
|
1238
1245
|
assistantTexts.push(text);
|
|
1239
1246
|
}
|
|
1240
1247
|
}
|
|
1248
|
+
if (message.refusal) {
|
|
1249
|
+
assistantTexts.push(message.refusal);
|
|
1250
|
+
}
|
|
1241
1251
|
if (message.tool_calls?.length) {
|
|
1242
1252
|
toolCalls.push(...message.tool_calls);
|
|
1243
1253
|
}
|
|
@@ -2292,6 +2302,12 @@ var toAnthropicMessages = (messages) => {
|
|
|
2292
2302
|
return { system, messages: dropOrphanToolUseBlocks(output) };
|
|
2293
2303
|
};
|
|
2294
2304
|
var extractText = (blocks) => blocks.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
2305
|
+
var DEFAULT_REFUSAL_MESSAGE = "This request was declined by Anthropic's safety classifier.";
|
|
2306
|
+
var extractRefusal = (response) => {
|
|
2307
|
+
if (response.stop_reason !== "refusal") return null;
|
|
2308
|
+
const explanation = response.stop_details?.explanation?.trim();
|
|
2309
|
+
return explanation || DEFAULT_REFUSAL_MESSAGE;
|
|
2310
|
+
};
|
|
2295
2311
|
var toUsage = (response) => {
|
|
2296
2312
|
if (!response.usage) return null;
|
|
2297
2313
|
const baseInputTokens = response.usage.input_tokens ?? 0;
|
|
@@ -2311,58 +2327,63 @@ var toUsage = (response) => {
|
|
|
2311
2327
|
var toChatInvokeCompletion = (response, meta) => {
|
|
2312
2328
|
const blocks = response.content ?? [];
|
|
2313
2329
|
const messages = [];
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2330
|
+
const refusal = extractRefusal(response);
|
|
2331
|
+
if (refusal) {
|
|
2332
|
+
messages.push({ role: "assistant", content: null, refusal });
|
|
2333
|
+
} else {
|
|
2334
|
+
for (const block of blocks) {
|
|
2335
|
+
switch (block.type) {
|
|
2336
|
+
case "text":
|
|
2337
|
+
messages.push({
|
|
2338
|
+
role: "assistant",
|
|
2339
|
+
content: block.text
|
|
2340
|
+
});
|
|
2341
|
+
break;
|
|
2342
|
+
case "tool_use":
|
|
2343
|
+
messages.push({
|
|
2344
|
+
role: "assistant",
|
|
2345
|
+
content: null,
|
|
2346
|
+
tool_calls: [
|
|
2347
|
+
{
|
|
2348
|
+
id: block.id,
|
|
2349
|
+
type: "function",
|
|
2350
|
+
function: {
|
|
2351
|
+
name: block.name,
|
|
2352
|
+
arguments: isRecord(block.input) ? JSON.stringify(block.input) : JSON.stringify({ value: block.input })
|
|
2353
|
+
},
|
|
2354
|
+
provider_meta: block
|
|
2355
|
+
}
|
|
2356
|
+
]
|
|
2357
|
+
});
|
|
2358
|
+
break;
|
|
2359
|
+
case "thinking":
|
|
2360
|
+
messages.push({
|
|
2361
|
+
role: "reasoning",
|
|
2362
|
+
content: block.thinking,
|
|
2363
|
+
raw_item: block
|
|
2364
|
+
});
|
|
2365
|
+
break;
|
|
2366
|
+
case "redacted_thinking":
|
|
2367
|
+
messages.push({
|
|
2368
|
+
role: "reasoning",
|
|
2369
|
+
content: "[redacted]",
|
|
2370
|
+
raw_item: block
|
|
2371
|
+
});
|
|
2372
|
+
break;
|
|
2373
|
+
default:
|
|
2374
|
+
messages.push({
|
|
2375
|
+
role: "assistant",
|
|
2376
|
+
content: [
|
|
2377
|
+
{
|
|
2378
|
+
type: "other",
|
|
2379
|
+
provider: "anthropic",
|
|
2380
|
+
kind: block.type,
|
|
2381
|
+
payload: block
|
|
2382
|
+
}
|
|
2383
|
+
]
|
|
2384
|
+
});
|
|
2385
|
+
break;
|
|
2386
|
+
}
|
|
2366
2387
|
}
|
|
2367
2388
|
}
|
|
2368
2389
|
if (messages.length === 0) {
|
|
@@ -2378,7 +2399,14 @@ var toChatInvokeCompletion = (response, meta) => {
|
|
|
2378
2399
|
provider_meta: {
|
|
2379
2400
|
response_id: response.id,
|
|
2380
2401
|
model: response.model,
|
|
2381
|
-
raw_output_text: stringifyUnknown2(extractText(blocks)),
|
|
2402
|
+
raw_output_text: stringifyUnknown2(refusal ? "" : extractText(blocks)),
|
|
2403
|
+
...response.stop_details?.type === "refusal" ? {
|
|
2404
|
+
stop_details: {
|
|
2405
|
+
type: "refusal",
|
|
2406
|
+
category: response.stop_details.category,
|
|
2407
|
+
explanation: response.stop_details.explanation
|
|
2408
|
+
}
|
|
2409
|
+
} : {},
|
|
2382
2410
|
...typeof meta?.reasoning_requested === "string" ? { reasoning_requested: meta.reasoning_requested } : {},
|
|
2383
2411
|
...typeof meta?.reasoning_applied === "string" ? { reasoning_applied: meta.reasoning_applied } : {},
|
|
2384
2412
|
...typeof meta?.reasoning_fallback === "boolean" ? { reasoning_fallback: meta.reasoning_fallback } : {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
28
|
-
"@codelia/config": "0.1.
|
|
29
|
-
"@codelia/shared-types": "0.1.
|
|
28
|
+
"@codelia/config": "0.1.71",
|
|
29
|
+
"@codelia/shared-types": "0.1.71",
|
|
30
30
|
"@google-cloud/vertexai": "^1.10.0",
|
|
31
31
|
"@google/genai": "^1.43.0",
|
|
32
32
|
"json-schema": "^0.4.0",
|