@codelia/core 0.1.64 → 0.1.66
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 +641 -48
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +638 -47
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -11,12 +11,34 @@ var OPENAI_MODELS = [
|
|
|
11
11
|
provider: "openai",
|
|
12
12
|
aliases: ["default"]
|
|
13
13
|
},
|
|
14
|
+
{
|
|
15
|
+
id: "gpt-5.5",
|
|
16
|
+
provider: "openai",
|
|
17
|
+
contextWindow: 105e4,
|
|
18
|
+
maxInputTokens: 27e4,
|
|
19
|
+
maxOutputTokens: 13e4,
|
|
20
|
+
supportsFast: true
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "gpt-5.5-1M",
|
|
24
|
+
provider: "openai",
|
|
25
|
+
providerModelId: "gpt-5.5",
|
|
26
|
+
aliases: ["gpt-5.5-1m", "gpt-5.5-full"],
|
|
27
|
+
contextWindow: 105e4,
|
|
28
|
+
maxInputTokens: 92e4,
|
|
29
|
+
maxOutputTokens: 13e4
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "gpt-5.5-pro",
|
|
33
|
+
provider: "openai"
|
|
34
|
+
},
|
|
14
35
|
{
|
|
15
36
|
id: "gpt-5.4",
|
|
16
37
|
provider: "openai",
|
|
17
38
|
contextWindow: 105e4,
|
|
18
39
|
maxInputTokens: GPT_5_4_CAPPED_INPUT_TOKENS,
|
|
19
|
-
maxOutputTokens: 128e3
|
|
40
|
+
maxOutputTokens: 128e3,
|
|
41
|
+
supportsFast: true
|
|
20
42
|
},
|
|
21
43
|
{
|
|
22
44
|
id: "gpt-5.4-1M",
|
|
@@ -38,11 +60,13 @@ var OPENAI_MODELS = [
|
|
|
38
60
|
},
|
|
39
61
|
{
|
|
40
62
|
id: "gpt-5.2-2025-12-11",
|
|
41
|
-
provider: "openai"
|
|
63
|
+
provider: "openai",
|
|
64
|
+
supportsFast: true
|
|
42
65
|
},
|
|
43
66
|
{
|
|
44
67
|
id: "gpt-5.2",
|
|
45
|
-
provider: "openai"
|
|
68
|
+
provider: "openai",
|
|
69
|
+
supportsFast: true
|
|
46
70
|
},
|
|
47
71
|
{
|
|
48
72
|
id: "gpt-5.2-pro",
|
|
@@ -54,23 +78,28 @@ var OPENAI_MODELS = [
|
|
|
54
78
|
},
|
|
55
79
|
{
|
|
56
80
|
id: "gpt-5.1",
|
|
57
|
-
provider: "openai"
|
|
81
|
+
provider: "openai",
|
|
82
|
+
supportsFast: true
|
|
58
83
|
},
|
|
59
84
|
{
|
|
60
85
|
id: "gpt-5.1-2025-11-13",
|
|
61
|
-
provider: "openai"
|
|
86
|
+
provider: "openai",
|
|
87
|
+
supportsFast: true
|
|
62
88
|
},
|
|
63
89
|
{
|
|
64
90
|
id: "gpt-5",
|
|
65
|
-
provider: "openai"
|
|
91
|
+
provider: "openai",
|
|
92
|
+
supportsFast: true
|
|
66
93
|
},
|
|
67
94
|
{
|
|
68
95
|
id: "gpt-5-mini",
|
|
69
|
-
provider: "openai"
|
|
96
|
+
provider: "openai",
|
|
97
|
+
supportsFast: true
|
|
70
98
|
},
|
|
71
99
|
{
|
|
72
100
|
id: "gpt-5-mini-2025-08-07",
|
|
73
|
-
provider: "openai"
|
|
101
|
+
provider: "openai",
|
|
102
|
+
supportsFast: true
|
|
74
103
|
},
|
|
75
104
|
{
|
|
76
105
|
id: "gpt-5-nano",
|
|
@@ -82,7 +111,8 @@ var OPENAI_MODELS = [
|
|
|
82
111
|
},
|
|
83
112
|
{
|
|
84
113
|
id: "gpt-5.1-codex",
|
|
85
|
-
provider: "openai"
|
|
114
|
+
provider: "openai",
|
|
115
|
+
supportsFast: true
|
|
86
116
|
},
|
|
87
117
|
{
|
|
88
118
|
id: "gpt-5.1-codex-max",
|
|
@@ -94,7 +124,8 @@ var OPENAI_MODELS = [
|
|
|
94
124
|
},
|
|
95
125
|
{
|
|
96
126
|
id: "gpt-5-codex",
|
|
97
|
-
provider: "openai"
|
|
127
|
+
provider: "openai",
|
|
128
|
+
supportsFast: true
|
|
98
129
|
},
|
|
99
130
|
{
|
|
100
131
|
id: "gpt-5-codex-mini",
|
|
@@ -210,9 +241,18 @@ var ANTHROPIC_MODELS = [
|
|
|
210
241
|
provider: "anthropic",
|
|
211
242
|
aliases: ["default"]
|
|
212
243
|
},
|
|
244
|
+
{
|
|
245
|
+
id: "claude-opus-4-7",
|
|
246
|
+
provider: "anthropic",
|
|
247
|
+
contextWindow: 1e6,
|
|
248
|
+
maxInputTokens: 1e6,
|
|
249
|
+
maxOutputTokens: 128e3,
|
|
250
|
+
supportsFast: true
|
|
251
|
+
},
|
|
213
252
|
{
|
|
214
253
|
id: "claude-opus-4-6",
|
|
215
|
-
provider: "anthropic"
|
|
254
|
+
provider: "anthropic",
|
|
255
|
+
supportsFast: true
|
|
216
256
|
},
|
|
217
257
|
{
|
|
218
258
|
id: "claude-opus-4-5",
|
|
@@ -307,10 +347,18 @@ function listModels(registry, provider) {
|
|
|
307
347
|
const all = Object.values(registry.modelsById);
|
|
308
348
|
return provider ? all.filter((model) => model.provider === provider) : all;
|
|
309
349
|
}
|
|
350
|
+
var isPositiveFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
351
|
+
function isUsableModelSpec(spec) {
|
|
352
|
+
return isPositiveFiniteNumber(spec?.maxInputTokens) || isPositiveFiniteNumber(spec?.contextWindow);
|
|
353
|
+
}
|
|
310
354
|
function resolveProviderModelId(registry, idOrAlias, provider) {
|
|
311
355
|
const spec = resolveModel(registry, idOrAlias, provider);
|
|
312
356
|
return spec ? spec.providerModelId ?? spec.id : void 0;
|
|
313
357
|
}
|
|
358
|
+
function supportsFastMode(registry, idOrAlias, provider) {
|
|
359
|
+
const spec = resolveModel(registry, idOrAlias, provider);
|
|
360
|
+
return spec?.supportsFast === true;
|
|
361
|
+
}
|
|
314
362
|
function cloneAliases(aliasesByProvider) {
|
|
315
363
|
return {
|
|
316
364
|
openai: { ...aliasesByProvider.openai },
|
|
@@ -2234,12 +2282,14 @@ var DEFAULT_CLIENT_TIMEOUT_MS = 20 * 60 * 1e3;
|
|
|
2234
2282
|
var DEFAULT_PROMPT_CACHE_CONTROL = {
|
|
2235
2283
|
type: "ephemeral"
|
|
2236
2284
|
};
|
|
2285
|
+
var FAST_MODE_BETA = "fast-mode-2026-02-01";
|
|
2237
2286
|
var ChatAnthropic = class {
|
|
2238
2287
|
provider = PROVIDER_NAME;
|
|
2239
2288
|
model;
|
|
2240
2289
|
client;
|
|
2241
2290
|
defaultMaxTokens;
|
|
2242
2291
|
defaultInvokeOptions;
|
|
2292
|
+
fastMode;
|
|
2243
2293
|
reasoningLevelMeta;
|
|
2244
2294
|
debugInvokeSeq = 0;
|
|
2245
2295
|
lastDebugRequestPayload = null;
|
|
@@ -2251,6 +2301,7 @@ var ChatAnthropic = class {
|
|
|
2251
2301
|
this.model = options.model ?? DEFAULT_MODEL;
|
|
2252
2302
|
this.defaultMaxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
2253
2303
|
this.defaultInvokeOptions = { ...options.invokeOptions ?? {} };
|
|
2304
|
+
this.fastMode = options.fastMode === true;
|
|
2254
2305
|
this.reasoningLevelMeta = {
|
|
2255
2306
|
requested: options.reasoningLevelRequested,
|
|
2256
2307
|
applied: options.reasoningLevelApplied,
|
|
@@ -2288,14 +2339,17 @@ var ChatAnthropic = class {
|
|
|
2288
2339
|
if (request.cache_control === void 0) {
|
|
2289
2340
|
request.cache_control = DEFAULT_PROMPT_CACHE_CONTROL;
|
|
2290
2341
|
}
|
|
2342
|
+
if (this.fastMode) {
|
|
2343
|
+
request.speed = "fast";
|
|
2344
|
+
request.betas = [...request.betas ?? [], FAST_MODE_BETA];
|
|
2345
|
+
}
|
|
2291
2346
|
const debugSeq = this.nextDebugInvokeSeq();
|
|
2292
2347
|
await this.debugRequestIfEnabled(request, debugSeq);
|
|
2293
|
-
const
|
|
2348
|
+
const requestOptions = signal ? { signal } : void 0;
|
|
2349
|
+
const response = this.fastMode ? await this.client.beta.messages.create(
|
|
2294
2350
|
request,
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
} : void 0
|
|
2298
|
-
);
|
|
2351
|
+
requestOptions
|
|
2352
|
+
) : await this.client.messages.create(request, requestOptions);
|
|
2299
2353
|
await this.debugResponseIfEnabled(response, debugSeq);
|
|
2300
2354
|
return toChatInvokeCompletion(response, {
|
|
2301
2355
|
reasoning_requested: this.reasoningLevelMeta.requested,
|
|
@@ -2390,25 +2444,6 @@ var ChatAnthropic = class {
|
|
|
2390
2444
|
import { createHash as createHash2 } from "crypto";
|
|
2391
2445
|
import OpenAI from "openai";
|
|
2392
2446
|
|
|
2393
|
-
// src/llm/openai/http-transport.ts
|
|
2394
|
-
var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader) => {
|
|
2395
|
-
const streamRequest = {
|
|
2396
|
-
...request,
|
|
2397
|
-
stream: true
|
|
2398
|
-
};
|
|
2399
|
-
return client.responses.stream(
|
|
2400
|
-
streamRequest,
|
|
2401
|
-
signal || sessionIdHeader ? {
|
|
2402
|
-
...signal ? { signal } : {},
|
|
2403
|
-
...sessionIdHeader ? {
|
|
2404
|
-
headers: {
|
|
2405
|
-
session_id: sessionIdHeader
|
|
2406
|
-
}
|
|
2407
|
-
} : {}
|
|
2408
|
-
} : void 0
|
|
2409
|
-
).finalResponse();
|
|
2410
|
-
};
|
|
2411
|
-
|
|
2412
2447
|
// src/llm/openai/response-utils.ts
|
|
2413
2448
|
var isRecord2 = (value) => typeof value === "object" && value !== null;
|
|
2414
2449
|
var stringifyUnknown3 = (value) => {
|
|
@@ -2450,6 +2485,107 @@ var extractOutputText = (items) => {
|
|
|
2450
2485
|
}
|
|
2451
2486
|
return texts.join("");
|
|
2452
2487
|
};
|
|
2488
|
+
var getRecordString = (record, key) => {
|
|
2489
|
+
const value = record[key];
|
|
2490
|
+
return typeof value === "string" ? value : void 0;
|
|
2491
|
+
};
|
|
2492
|
+
var getRecordNumber = (record, key) => {
|
|
2493
|
+
const value = record[key];
|
|
2494
|
+
return typeof value === "number" ? value : void 0;
|
|
2495
|
+
};
|
|
2496
|
+
var clipDebugText = (value, maxChars = 80) => value.length <= maxChars ? value : `${value.slice(0, maxChars)}...`;
|
|
2497
|
+
var getResponseStreamEventDebugPayload = (event) => {
|
|
2498
|
+
const payload = {
|
|
2499
|
+
type: event.type,
|
|
2500
|
+
sequence_number: typeof event.sequence_number === "number" ? event.sequence_number : null
|
|
2501
|
+
};
|
|
2502
|
+
const eventRecord = event;
|
|
2503
|
+
const outputIndex = getRecordNumber(eventRecord, "output_index");
|
|
2504
|
+
if (outputIndex !== void 0) {
|
|
2505
|
+
payload.output_index = outputIndex;
|
|
2506
|
+
}
|
|
2507
|
+
const contentIndex = getRecordNumber(eventRecord, "content_index");
|
|
2508
|
+
if (contentIndex !== void 0) {
|
|
2509
|
+
payload.content_index = contentIndex;
|
|
2510
|
+
}
|
|
2511
|
+
switch (event.type) {
|
|
2512
|
+
case "response.output_text.delta":
|
|
2513
|
+
case "response.reasoning_text.delta":
|
|
2514
|
+
case "response.function_call_arguments.delta": {
|
|
2515
|
+
const delta = getRecordString(eventRecord, "delta") ?? "";
|
|
2516
|
+
payload.delta_chars = delta.length;
|
|
2517
|
+
payload.delta_preview = clipDebugText(delta);
|
|
2518
|
+
break;
|
|
2519
|
+
}
|
|
2520
|
+
case "response.output_item.added":
|
|
2521
|
+
case "response.output_item.done": {
|
|
2522
|
+
const item = eventRecord.item;
|
|
2523
|
+
if (isRecord2(item)) {
|
|
2524
|
+
payload.item_type = getRecordString(item, "type");
|
|
2525
|
+
payload.item_role = getRecordString(item, "role");
|
|
2526
|
+
}
|
|
2527
|
+
break;
|
|
2528
|
+
}
|
|
2529
|
+
case "response.content_part.added": {
|
|
2530
|
+
const part = eventRecord.part;
|
|
2531
|
+
if (isRecord2(part)) {
|
|
2532
|
+
payload.part_type = getRecordString(part, "type");
|
|
2533
|
+
if (part.type === "output_text") {
|
|
2534
|
+
const text = getRecordString(part, "text") ?? "";
|
|
2535
|
+
payload.delta_chars = text.length;
|
|
2536
|
+
payload.delta_preview = clipDebugText(text);
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
break;
|
|
2540
|
+
}
|
|
2541
|
+
case "response.completed": {
|
|
2542
|
+
const response = eventRecord.response;
|
|
2543
|
+
if (isRecord2(response)) {
|
|
2544
|
+
payload.response_id = getRecordString(response, "id");
|
|
2545
|
+
const status = response.status;
|
|
2546
|
+
payload.response_status = typeof status === "string" ? status : null;
|
|
2547
|
+
const output = response.output;
|
|
2548
|
+
if (Array.isArray(output)) {
|
|
2549
|
+
payload.response_output_items = output.length;
|
|
2550
|
+
}
|
|
2551
|
+
const outputText = response.output_text;
|
|
2552
|
+
payload.response_output_text = typeof outputText === "string" ? clipDebugText(outputText) : null;
|
|
2553
|
+
const usage = response.usage;
|
|
2554
|
+
if (isRecord2(usage)) {
|
|
2555
|
+
payload.response_output_tokens = getRecordNumber(
|
|
2556
|
+
usage,
|
|
2557
|
+
"output_tokens"
|
|
2558
|
+
);
|
|
2559
|
+
const outputDetails = usage.output_tokens_details;
|
|
2560
|
+
if (isRecord2(outputDetails)) {
|
|
2561
|
+
payload.response_reasoning_tokens = getRecordNumber(
|
|
2562
|
+
outputDetails,
|
|
2563
|
+
"reasoning_tokens"
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
break;
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
return payload;
|
|
2572
|
+
};
|
|
2573
|
+
var getEmptyCompletionDebugPayload = (response, completion) => {
|
|
2574
|
+
if (completion.messages.length > 0) {
|
|
2575
|
+
return null;
|
|
2576
|
+
}
|
|
2577
|
+
const outputTokens = response.usage?.output_tokens;
|
|
2578
|
+
if (typeof outputTokens !== "number" || outputTokens <= 0) {
|
|
2579
|
+
return null;
|
|
2580
|
+
}
|
|
2581
|
+
return {
|
|
2582
|
+
id: response.id,
|
|
2583
|
+
status: response.status ?? null,
|
|
2584
|
+
output_text: typeof response.output_text === "string" ? response.output_text : null,
|
|
2585
|
+
output: Array.isArray(response.output) ? response.output : [],
|
|
2586
|
+
usage: response.usage ?? null
|
|
2587
|
+
};
|
|
2588
|
+
};
|
|
2453
2589
|
var toResponseInputContent = (part) => {
|
|
2454
2590
|
switch (part.type) {
|
|
2455
2591
|
case "text":
|
|
@@ -2491,6 +2627,411 @@ var toFunctionCallOutput = (content) => {
|
|
|
2491
2627
|
return content.map(toResponseInputContent);
|
|
2492
2628
|
};
|
|
2493
2629
|
|
|
2630
|
+
// src/llm/openai/response-accumulator.ts
|
|
2631
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null;
|
|
2632
|
+
var envTruthy2 = (value) => {
|
|
2633
|
+
if (!value) return false;
|
|
2634
|
+
const normalized = value.trim().toLowerCase();
|
|
2635
|
+
return normalized === "1" || normalized === "true";
|
|
2636
|
+
};
|
|
2637
|
+
var loggedUnhandledResponseEventTypes = /* @__PURE__ */ new Set();
|
|
2638
|
+
var cloneValue = (value) => {
|
|
2639
|
+
if (typeof structuredClone === "function") {
|
|
2640
|
+
return structuredClone(value);
|
|
2641
|
+
}
|
|
2642
|
+
return JSON.parse(JSON.stringify(value));
|
|
2643
|
+
};
|
|
2644
|
+
var cloneResponse = (response) => cloneValue(response);
|
|
2645
|
+
var cloneOutputItem = (item) => cloneValue(item);
|
|
2646
|
+
var ensureArrayIndex = (array, index) => {
|
|
2647
|
+
while (array.length <= index) {
|
|
2648
|
+
array.push(void 0);
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
var OpenAiResponseAccumulator = class {
|
|
2652
|
+
baseResponse = null;
|
|
2653
|
+
terminalResponse = null;
|
|
2654
|
+
outputItems = [];
|
|
2655
|
+
observeEvent(event) {
|
|
2656
|
+
switch (event.type) {
|
|
2657
|
+
case "response.created":
|
|
2658
|
+
case "response.queued":
|
|
2659
|
+
case "response.in_progress":
|
|
2660
|
+
case "response.incomplete": {
|
|
2661
|
+
this.seedBaseResponse(event.response);
|
|
2662
|
+
break;
|
|
2663
|
+
}
|
|
2664
|
+
case "response.output_item.added":
|
|
2665
|
+
case "response.output_item.done": {
|
|
2666
|
+
this.setOutputItem(event.output_index, event.item);
|
|
2667
|
+
break;
|
|
2668
|
+
}
|
|
2669
|
+
case "response.content_part.added": {
|
|
2670
|
+
this.addContentPart(
|
|
2671
|
+
event.output_index,
|
|
2672
|
+
event.content_index,
|
|
2673
|
+
event.part
|
|
2674
|
+
);
|
|
2675
|
+
break;
|
|
2676
|
+
}
|
|
2677
|
+
case "response.output_text.delta": {
|
|
2678
|
+
this.appendMessageText(
|
|
2679
|
+
event.output_index,
|
|
2680
|
+
event.content_index,
|
|
2681
|
+
event.delta
|
|
2682
|
+
);
|
|
2683
|
+
break;
|
|
2684
|
+
}
|
|
2685
|
+
case "response.output_text.done": {
|
|
2686
|
+
this.setMessageText(
|
|
2687
|
+
event.output_index,
|
|
2688
|
+
event.content_index,
|
|
2689
|
+
event.text
|
|
2690
|
+
);
|
|
2691
|
+
break;
|
|
2692
|
+
}
|
|
2693
|
+
case "response.refusal.delta": {
|
|
2694
|
+
this.appendRefusalText(
|
|
2695
|
+
event.output_index,
|
|
2696
|
+
event.content_index,
|
|
2697
|
+
event.delta
|
|
2698
|
+
);
|
|
2699
|
+
break;
|
|
2700
|
+
}
|
|
2701
|
+
case "response.refusal.done": {
|
|
2702
|
+
this.setRefusalText(
|
|
2703
|
+
event.output_index,
|
|
2704
|
+
event.content_index,
|
|
2705
|
+
event.refusal
|
|
2706
|
+
);
|
|
2707
|
+
break;
|
|
2708
|
+
}
|
|
2709
|
+
case "response.function_call_arguments.delta": {
|
|
2710
|
+
this.appendFunctionCallArguments(event.output_index, event.delta);
|
|
2711
|
+
break;
|
|
2712
|
+
}
|
|
2713
|
+
case "response.function_call_arguments.done": {
|
|
2714
|
+
this.setFunctionCallArguments(
|
|
2715
|
+
event.output_index,
|
|
2716
|
+
event.name,
|
|
2717
|
+
event.arguments
|
|
2718
|
+
);
|
|
2719
|
+
break;
|
|
2720
|
+
}
|
|
2721
|
+
case "response.reasoning_summary_part.added":
|
|
2722
|
+
case "response.reasoning_summary_part.done": {
|
|
2723
|
+
this.setReasoningSummaryPart(
|
|
2724
|
+
event.output_index,
|
|
2725
|
+
event.summary_index,
|
|
2726
|
+
event.part.text
|
|
2727
|
+
);
|
|
2728
|
+
break;
|
|
2729
|
+
}
|
|
2730
|
+
case "response.reasoning_summary_text.delta": {
|
|
2731
|
+
this.appendReasoningSummaryText(
|
|
2732
|
+
event.output_index,
|
|
2733
|
+
event.summary_index,
|
|
2734
|
+
event.delta
|
|
2735
|
+
);
|
|
2736
|
+
break;
|
|
2737
|
+
}
|
|
2738
|
+
case "response.reasoning_summary_text.done": {
|
|
2739
|
+
this.setReasoningSummaryText(
|
|
2740
|
+
event.output_index,
|
|
2741
|
+
event.summary_index,
|
|
2742
|
+
event.text
|
|
2743
|
+
);
|
|
2744
|
+
break;
|
|
2745
|
+
}
|
|
2746
|
+
case "response.reasoning_text.delta": {
|
|
2747
|
+
this.appendReasoningText(
|
|
2748
|
+
event.output_index,
|
|
2749
|
+
event.content_index,
|
|
2750
|
+
event.delta
|
|
2751
|
+
);
|
|
2752
|
+
break;
|
|
2753
|
+
}
|
|
2754
|
+
case "response.reasoning_text.done": {
|
|
2755
|
+
this.setReasoningText(
|
|
2756
|
+
event.output_index,
|
|
2757
|
+
event.content_index,
|
|
2758
|
+
event.text
|
|
2759
|
+
);
|
|
2760
|
+
break;
|
|
2761
|
+
}
|
|
2762
|
+
case "response.output_text.annotation.added": {
|
|
2763
|
+
this.addOutputTextAnnotation(
|
|
2764
|
+
event.output_index,
|
|
2765
|
+
event.content_index,
|
|
2766
|
+
event.annotation_index,
|
|
2767
|
+
event.annotation
|
|
2768
|
+
);
|
|
2769
|
+
break;
|
|
2770
|
+
}
|
|
2771
|
+
case "response.completed": {
|
|
2772
|
+
this.observeTerminalResponse(event.response);
|
|
2773
|
+
break;
|
|
2774
|
+
}
|
|
2775
|
+
default: {
|
|
2776
|
+
this.logUnhandledResponseEvent(event);
|
|
2777
|
+
break;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
observeTerminalResponse(response) {
|
|
2782
|
+
if (!this.baseResponse) {
|
|
2783
|
+
this.seedBaseResponse(response);
|
|
2784
|
+
}
|
|
2785
|
+
this.terminalResponse = cloneResponse(response);
|
|
2786
|
+
}
|
|
2787
|
+
buildResponse(fallbackResponse) {
|
|
2788
|
+
const terminal = fallbackResponse ? cloneResponse(fallbackResponse) : this.terminalResponse ? cloneResponse(this.terminalResponse) : null;
|
|
2789
|
+
const base = terminal ?? this.baseResponse;
|
|
2790
|
+
if (!base) {
|
|
2791
|
+
throw new Error("openai response accumulator has no response snapshot");
|
|
2792
|
+
}
|
|
2793
|
+
const merged = cloneResponse(base);
|
|
2794
|
+
const accumulatedOutput = this.getAccumulatedOutputItems();
|
|
2795
|
+
if (accumulatedOutput.length > 0) {
|
|
2796
|
+
merged.output = accumulatedOutput;
|
|
2797
|
+
const accumulatedText = extractOutputText(accumulatedOutput);
|
|
2798
|
+
merged.output_text = accumulatedText;
|
|
2799
|
+
}
|
|
2800
|
+
return merged;
|
|
2801
|
+
}
|
|
2802
|
+
seedBaseResponse(response) {
|
|
2803
|
+
this.baseResponse = cloneResponse(response);
|
|
2804
|
+
if (this.outputItems.length === 0 && Array.isArray(response.output)) {
|
|
2805
|
+
for (const [index, item] of response.output.entries()) {
|
|
2806
|
+
this.outputItems[index] = cloneOutputItem(item);
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
getAccumulatedOutputItems() {
|
|
2811
|
+
return this.outputItems.filter(
|
|
2812
|
+
(item) => item !== void 0
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2815
|
+
setOutputItem(index, item) {
|
|
2816
|
+
ensureArrayIndex(this.outputItems, index);
|
|
2817
|
+
this.outputItems[index] = cloneOutputItem(item);
|
|
2818
|
+
}
|
|
2819
|
+
getOutputItem(index) {
|
|
2820
|
+
return this.outputItems[index];
|
|
2821
|
+
}
|
|
2822
|
+
addContentPart(outputIndex, contentIndex, part) {
|
|
2823
|
+
const output = this.getOutputItem(outputIndex);
|
|
2824
|
+
if (!output || !isRecord3(part)) {
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2827
|
+
if (output.type === "message" && part.type !== "reasoning_text") {
|
|
2828
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
2829
|
+
output.content[contentIndex] = cloneValue(
|
|
2830
|
+
part
|
|
2831
|
+
);
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
if (output.type === "reasoning" && part.type === "reasoning_text") {
|
|
2835
|
+
const content = output.content ?? [];
|
|
2836
|
+
ensureArrayIndex(content, contentIndex);
|
|
2837
|
+
content[contentIndex] = cloneValue(
|
|
2838
|
+
part
|
|
2839
|
+
);
|
|
2840
|
+
output.content = content;
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
appendMessageText(outputIndex, contentIndex, delta) {
|
|
2844
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2845
|
+
if (!part) {
|
|
2846
|
+
return;
|
|
2847
|
+
}
|
|
2848
|
+
part.text += delta;
|
|
2849
|
+
}
|
|
2850
|
+
setMessageText(outputIndex, contentIndex, text) {
|
|
2851
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2852
|
+
if (!part) {
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
part.text = text;
|
|
2856
|
+
}
|
|
2857
|
+
appendRefusalText(outputIndex, contentIndex, delta) {
|
|
2858
|
+
const part = this.ensureMessageRefusalPart(outputIndex, contentIndex);
|
|
2859
|
+
if (!part) {
|
|
2860
|
+
return;
|
|
2861
|
+
}
|
|
2862
|
+
part.refusal += delta;
|
|
2863
|
+
}
|
|
2864
|
+
setRefusalText(outputIndex, contentIndex, refusal) {
|
|
2865
|
+
const part = this.ensureMessageRefusalPart(outputIndex, contentIndex);
|
|
2866
|
+
if (!part) {
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
part.refusal = refusal;
|
|
2870
|
+
}
|
|
2871
|
+
appendFunctionCallArguments(outputIndex, delta) {
|
|
2872
|
+
const output = this.getOutputItem(outputIndex);
|
|
2873
|
+
if (!output || output.type !== "function_call") {
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2876
|
+
output.arguments += delta;
|
|
2877
|
+
}
|
|
2878
|
+
setFunctionCallArguments(outputIndex, name, argumentsText) {
|
|
2879
|
+
const output = this.getOutputItem(outputIndex);
|
|
2880
|
+
if (!output || output.type !== "function_call") {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
output.name = name;
|
|
2884
|
+
output.arguments = argumentsText;
|
|
2885
|
+
}
|
|
2886
|
+
setReasoningSummaryPart(outputIndex, summaryIndex, text) {
|
|
2887
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2888
|
+
if (!summary) {
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
summary.text = text;
|
|
2892
|
+
}
|
|
2893
|
+
appendReasoningSummaryText(outputIndex, summaryIndex, delta) {
|
|
2894
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2895
|
+
if (!summary) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
summary.text += delta;
|
|
2899
|
+
}
|
|
2900
|
+
setReasoningSummaryText(outputIndex, summaryIndex, text) {
|
|
2901
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2902
|
+
if (!summary) {
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
summary.text = text;
|
|
2906
|
+
}
|
|
2907
|
+
appendReasoningText(outputIndex, contentIndex, delta) {
|
|
2908
|
+
const content = this.ensureReasoningContentPart(outputIndex, contentIndex);
|
|
2909
|
+
if (!content) {
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
content.text += delta;
|
|
2913
|
+
}
|
|
2914
|
+
setReasoningText(outputIndex, contentIndex, text) {
|
|
2915
|
+
const content = this.ensureReasoningContentPart(outputIndex, contentIndex);
|
|
2916
|
+
if (!content) {
|
|
2917
|
+
return;
|
|
2918
|
+
}
|
|
2919
|
+
content.text = text;
|
|
2920
|
+
}
|
|
2921
|
+
addOutputTextAnnotation(outputIndex, contentIndex, annotationIndex, annotation) {
|
|
2922
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2923
|
+
if (!part) {
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2926
|
+
ensureArrayIndex(part.annotations, annotationIndex);
|
|
2927
|
+
part.annotations[annotationIndex] = cloneValue(annotation);
|
|
2928
|
+
}
|
|
2929
|
+
ensureMessageTextPart(outputIndex, contentIndex) {
|
|
2930
|
+
const output = this.getOutputItem(outputIndex);
|
|
2931
|
+
if (!output || output.type !== "message") {
|
|
2932
|
+
return void 0;
|
|
2933
|
+
}
|
|
2934
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
2935
|
+
const current = output.content[contentIndex];
|
|
2936
|
+
if (!current || current.type !== "output_text") {
|
|
2937
|
+
output.content[contentIndex] = {
|
|
2938
|
+
type: "output_text",
|
|
2939
|
+
text: "",
|
|
2940
|
+
annotations: []
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
return output.content[contentIndex];
|
|
2944
|
+
}
|
|
2945
|
+
ensureMessageRefusalPart(outputIndex, contentIndex) {
|
|
2946
|
+
const output = this.getOutputItem(outputIndex);
|
|
2947
|
+
if (!output || output.type !== "message") {
|
|
2948
|
+
return void 0;
|
|
2949
|
+
}
|
|
2950
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
2951
|
+
const current = output.content[contentIndex];
|
|
2952
|
+
if (!current || current.type !== "refusal") {
|
|
2953
|
+
output.content[contentIndex] = {
|
|
2954
|
+
type: "refusal",
|
|
2955
|
+
refusal: ""
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
return output.content[contentIndex];
|
|
2959
|
+
}
|
|
2960
|
+
ensureReasoningSummaryPart(outputIndex, summaryIndex) {
|
|
2961
|
+
const output = this.getOutputItem(outputIndex);
|
|
2962
|
+
if (!output || output.type !== "reasoning") {
|
|
2963
|
+
return void 0;
|
|
2964
|
+
}
|
|
2965
|
+
ensureArrayIndex(output.summary, summaryIndex);
|
|
2966
|
+
if (!output.summary[summaryIndex]) {
|
|
2967
|
+
output.summary[summaryIndex] = {
|
|
2968
|
+
type: "summary_text",
|
|
2969
|
+
text: ""
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
return output.summary[summaryIndex];
|
|
2973
|
+
}
|
|
2974
|
+
ensureReasoningContentPart(outputIndex, contentIndex) {
|
|
2975
|
+
const output = this.getOutputItem(outputIndex);
|
|
2976
|
+
if (!output || output.type !== "reasoning") {
|
|
2977
|
+
return void 0;
|
|
2978
|
+
}
|
|
2979
|
+
const content = output.content ?? [];
|
|
2980
|
+
ensureArrayIndex(content, contentIndex);
|
|
2981
|
+
if (!content[contentIndex]) {
|
|
2982
|
+
content[contentIndex] = {
|
|
2983
|
+
type: "reasoning_text",
|
|
2984
|
+
text: ""
|
|
2985
|
+
};
|
|
2986
|
+
}
|
|
2987
|
+
output.content = content;
|
|
2988
|
+
return content[contentIndex];
|
|
2989
|
+
}
|
|
2990
|
+
logUnhandledResponseEvent(event) {
|
|
2991
|
+
if (!envTruthy2(process.env.CODELIA_PROVIDER_LOG) && !envTruthy2(process.env.CODELIA_DEBUG)) {
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
if (!event.type.startsWith("response.")) {
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
if (loggedUnhandledResponseEventTypes.has(event.type)) {
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
loggedUnhandledResponseEventTypes.add(event.type);
|
|
3001
|
+
const payload = getResponseStreamEventDebugPayload(event);
|
|
3002
|
+
console.error(`[openai.stream.unhandled] ${safeJsonStringify(payload)}`);
|
|
3003
|
+
}
|
|
3004
|
+
};
|
|
3005
|
+
|
|
3006
|
+
// src/llm/openai/http-transport.ts
|
|
3007
|
+
var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader, onEvent) => {
|
|
3008
|
+
const streamRequest = {
|
|
3009
|
+
...request,
|
|
3010
|
+
stream: true
|
|
3011
|
+
};
|
|
3012
|
+
const stream = client.responses.stream(
|
|
3013
|
+
streamRequest,
|
|
3014
|
+
signal || sessionIdHeader ? {
|
|
3015
|
+
...signal ? { signal } : {},
|
|
3016
|
+
...sessionIdHeader ? {
|
|
3017
|
+
headers: {
|
|
3018
|
+
session_id: sessionIdHeader
|
|
3019
|
+
}
|
|
3020
|
+
} : {}
|
|
3021
|
+
} : void 0
|
|
3022
|
+
);
|
|
3023
|
+
if (typeof stream[Symbol.asyncIterator] === "function") {
|
|
3024
|
+
const accumulator = new OpenAiResponseAccumulator();
|
|
3025
|
+
for await (const event of stream) {
|
|
3026
|
+
accumulator.observeEvent(event);
|
|
3027
|
+
await onEvent?.(event);
|
|
3028
|
+
}
|
|
3029
|
+
const finalResponse = await stream.finalResponse();
|
|
3030
|
+
return accumulator.buildResponse(finalResponse);
|
|
3031
|
+
}
|
|
3032
|
+
return stream.finalResponse();
|
|
3033
|
+
};
|
|
3034
|
+
|
|
2494
3035
|
// src/llm/openai/serializer.ts
|
|
2495
3036
|
var toOpenAiOtherPart = (kind, payload) => ({
|
|
2496
3037
|
type: "other",
|
|
@@ -2890,12 +3431,12 @@ var resolveTimeoutMs = (value, fallbackMs) => {
|
|
|
2890
3431
|
}
|
|
2891
3432
|
return Math.floor(value);
|
|
2892
3433
|
};
|
|
2893
|
-
var
|
|
3434
|
+
var envTruthy3 = (value) => {
|
|
2894
3435
|
if (!value) return false;
|
|
2895
3436
|
const normalized = value.trim().toLowerCase();
|
|
2896
3437
|
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
2897
3438
|
};
|
|
2898
|
-
var WS_EVENT_TRACE_ENABLED =
|
|
3439
|
+
var WS_EVENT_TRACE_ENABLED = envTruthy3(process.env.CODELIA_DEBUG);
|
|
2899
3440
|
var WS_EVENT_TRACE_PROGRESS_LOG_INTERVAL_MS = 5e3;
|
|
2900
3441
|
var wsEventTraceStateBySource = /* @__PURE__ */ new Map();
|
|
2901
3442
|
var getWsEventTraceState = (source) => {
|
|
@@ -3017,6 +3558,7 @@ var OpenAiWsTransport = class {
|
|
|
3017
3558
|
let settled = false;
|
|
3018
3559
|
let rejectResponsePromise;
|
|
3019
3560
|
const responsePromise = new Promise((resolve, reject) => {
|
|
3561
|
+
const accumulator = new OpenAiResponseAccumulator();
|
|
3020
3562
|
let onAbort;
|
|
3021
3563
|
const nativeSocket = this.getNativeSocket(ws);
|
|
3022
3564
|
let removeNativeClose;
|
|
@@ -3072,7 +3614,7 @@ var OpenAiWsTransport = class {
|
|
|
3072
3614
|
if (settled || !terminalCompletedWithoutUsage) {
|
|
3073
3615
|
return;
|
|
3074
3616
|
}
|
|
3075
|
-
resolveOnce(terminalCompletedWithoutUsage);
|
|
3617
|
+
resolveOnce(accumulator.buildResponse(terminalCompletedWithoutUsage));
|
|
3076
3618
|
}, WS_TERMINAL_DONE_GRACE_MS);
|
|
3077
3619
|
};
|
|
3078
3620
|
const resetResponseTimeout = () => {
|
|
@@ -3083,7 +3625,9 @@ var OpenAiWsTransport = class {
|
|
|
3083
3625
|
timeout = setTimeout(() => {
|
|
3084
3626
|
if (settled) return;
|
|
3085
3627
|
if (terminalCompletedWithoutUsage) {
|
|
3086
|
-
resolveOnce(
|
|
3628
|
+
resolveOnce(
|
|
3629
|
+
accumulator.buildResponse(terminalCompletedWithoutUsage)
|
|
3630
|
+
);
|
|
3087
3631
|
return;
|
|
3088
3632
|
}
|
|
3089
3633
|
settled = true;
|
|
@@ -3098,18 +3642,19 @@ var OpenAiWsTransport = class {
|
|
|
3098
3642
|
const resolveFromTerminalEvent = (event, type) => {
|
|
3099
3643
|
const response = event?.response;
|
|
3100
3644
|
if (response && typeof response === "object") {
|
|
3645
|
+
accumulator.observeTerminalResponse(response);
|
|
3101
3646
|
if (type === "response.completed" && !this.hasUsageTotals(response)) {
|
|
3102
3647
|
terminalCompletedWithoutUsage = response;
|
|
3103
3648
|
scheduleDoneGraceTimer();
|
|
3104
3649
|
return;
|
|
3105
3650
|
}
|
|
3106
3651
|
clearDoneGraceTimer();
|
|
3107
|
-
resolveOnce(response);
|
|
3652
|
+
resolveOnce(accumulator.buildResponse(response));
|
|
3108
3653
|
return;
|
|
3109
3654
|
}
|
|
3110
3655
|
if (type === "response.done" && terminalCompletedWithoutUsage) {
|
|
3111
3656
|
clearDoneGraceTimer();
|
|
3112
|
-
resolveOnce(terminalCompletedWithoutUsage);
|
|
3657
|
+
resolveOnce(accumulator.buildResponse(terminalCompletedWithoutUsage));
|
|
3113
3658
|
return;
|
|
3114
3659
|
}
|
|
3115
3660
|
rejectOnce(
|
|
@@ -3121,6 +3666,9 @@ var OpenAiWsTransport = class {
|
|
|
3121
3666
|
if (!eventType) {
|
|
3122
3667
|
return;
|
|
3123
3668
|
}
|
|
3669
|
+
if (eventType !== "response.done") {
|
|
3670
|
+
accumulator.observeEvent(event);
|
|
3671
|
+
}
|
|
3124
3672
|
if (eventType === "response.failed") {
|
|
3125
3673
|
logWsEventTrace("sdk", eventType, false);
|
|
3126
3674
|
onResponseFailed(event);
|
|
@@ -3642,6 +4190,7 @@ var ChatOpenAI = class {
|
|
|
3642
4190
|
defaultReasoningEffort;
|
|
3643
4191
|
reasoningLevelMeta;
|
|
3644
4192
|
defaultTextVerbosity;
|
|
4193
|
+
defaultServiceTier;
|
|
3645
4194
|
websocketMode;
|
|
3646
4195
|
websocketApiVersion;
|
|
3647
4196
|
wsTransport;
|
|
@@ -3661,6 +4210,7 @@ var ChatOpenAI = class {
|
|
|
3661
4210
|
fallbackApplied: options.reasoningFallbackApplied
|
|
3662
4211
|
};
|
|
3663
4212
|
this.defaultTextVerbosity = options.textVerbosity;
|
|
4213
|
+
this.defaultServiceTier = options.serviceTier;
|
|
3664
4214
|
this.websocketMode = options.websocketMode ?? "off";
|
|
3665
4215
|
this.websocketApiVersion = options.websocketApiVersion ?? "v2";
|
|
3666
4216
|
this.wsTransport = new OpenAiWsTransport({
|
|
@@ -3684,7 +4234,7 @@ var ChatOpenAI = class {
|
|
|
3684
4234
|
const instructions = extractInstructions(messages);
|
|
3685
4235
|
const tools = toResponsesTools(toolDefs);
|
|
3686
4236
|
const tool_choice = toResponsesToolChoice(toolChoice);
|
|
3687
|
-
const { reasoningEffort, textVerbosity, ...rest } = options ?? {};
|
|
4237
|
+
const { reasoningEffort, textVerbosity, serviceTier, ...rest } = options ?? {};
|
|
3688
4238
|
const request = {
|
|
3689
4239
|
model: model ?? this.providerModel,
|
|
3690
4240
|
input: inputItems,
|
|
@@ -3716,6 +4266,10 @@ var ChatOpenAI = class {
|
|
|
3716
4266
|
verbosity
|
|
3717
4267
|
};
|
|
3718
4268
|
}
|
|
4269
|
+
const resolvedServiceTier = serviceTier ?? this.defaultServiceTier;
|
|
4270
|
+
if (resolvedServiceTier) {
|
|
4271
|
+
request.service_tier = resolvedServiceTier;
|
|
4272
|
+
}
|
|
3719
4273
|
if (context?.sessionKey && !request.prompt_cache_key) {
|
|
3720
4274
|
request.prompt_cache_key = context.sessionKey;
|
|
3721
4275
|
}
|
|
@@ -3739,7 +4293,7 @@ var ChatOpenAI = class {
|
|
|
3739
4293
|
debugSeq,
|
|
3740
4294
|
transportResult.transport
|
|
3741
4295
|
);
|
|
3742
|
-
|
|
4296
|
+
const completion = toChatInvokeCompletion2(transportResult.response, {
|
|
3743
4297
|
selected_model: model ?? this.model,
|
|
3744
4298
|
transport: transportResult.transport,
|
|
3745
4299
|
websocket_mode: this.websocketMode,
|
|
@@ -3751,6 +4305,13 @@ var ChatOpenAI = class {
|
|
|
3751
4305
|
reasoning_applied: this.reasoningLevelMeta.applied,
|
|
3752
4306
|
reasoning_fallback: this.reasoningLevelMeta.fallbackApplied
|
|
3753
4307
|
});
|
|
4308
|
+
await this.debugEmptyCompletionIfEnabled(
|
|
4309
|
+
transportResult.response,
|
|
4310
|
+
completion,
|
|
4311
|
+
debugSeq,
|
|
4312
|
+
transportResult.transport
|
|
4313
|
+
);
|
|
4314
|
+
return completion;
|
|
3754
4315
|
}
|
|
3755
4316
|
onHistoryCompacted(context) {
|
|
3756
4317
|
const sessionKey = context?.sessionKey;
|
|
@@ -3953,7 +4514,8 @@ var ChatOpenAI = class {
|
|
|
3953
4514
|
this.client,
|
|
3954
4515
|
args.request,
|
|
3955
4516
|
args.signal,
|
|
3956
|
-
args.sessionIdHeader
|
|
4517
|
+
args.sessionIdHeader,
|
|
4518
|
+
this.getHttpStreamDebugObserver(args.debugSeq)
|
|
3957
4519
|
);
|
|
3958
4520
|
return {
|
|
3959
4521
|
response,
|
|
@@ -4149,6 +4711,33 @@ var ChatOpenAI = class {
|
|
|
4149
4711
|
}
|
|
4150
4712
|
}
|
|
4151
4713
|
}
|
|
4714
|
+
async debugEmptyCompletionIfEnabled(response, completion, seq, transport) {
|
|
4715
|
+
const settings = getProviderLogSettings();
|
|
4716
|
+
if (!settings.enabled) {
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
4719
|
+
const payload = getEmptyCompletionDebugPayload(response, completion);
|
|
4720
|
+
if (!payload) {
|
|
4721
|
+
return;
|
|
4722
|
+
}
|
|
4723
|
+
const outputTokens = payload.usage?.output_tokens ?? 0;
|
|
4724
|
+
console.error(
|
|
4725
|
+
`[openai.response.empty_completion] seq=${seq} transport=${transport} websocket_mode=${this.websocketMode} id=${payload.id} status=${payload.status ?? "unknown"} output_tokens=${outputTokens} messages=0`
|
|
4726
|
+
);
|
|
4727
|
+
console.error(safeJsonStringify(payload, 2));
|
|
4728
|
+
}
|
|
4729
|
+
getHttpStreamDebugObserver(seq) {
|
|
4730
|
+
const settings = getProviderLogSettings();
|
|
4731
|
+
if (!settings.enabled) {
|
|
4732
|
+
return void 0;
|
|
4733
|
+
}
|
|
4734
|
+
return (event) => {
|
|
4735
|
+
const payload = getResponseStreamEventDebugPayload(event);
|
|
4736
|
+
console.error(
|
|
4737
|
+
`[openai.stream.event] seq=${seq} transport=http_stream websocket_mode=${this.websocketMode} ${safeJsonStringify(payload)}`
|
|
4738
|
+
);
|
|
4739
|
+
};
|
|
4740
|
+
}
|
|
4152
4741
|
};
|
|
4153
4742
|
|
|
4154
4743
|
// src/llm/openrouter/chat.ts
|
|
@@ -4156,7 +4745,7 @@ import { createHash as createHash3 } from "crypto";
|
|
|
4156
4745
|
import OpenAI2 from "openai";
|
|
4157
4746
|
|
|
4158
4747
|
// src/llm/openrouter/response-utils.ts
|
|
4159
|
-
var
|
|
4748
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null;
|
|
4160
4749
|
var stringifyUnknown5 = (value) => {
|
|
4161
4750
|
if (value == null) return "";
|
|
4162
4751
|
if (typeof value === "string") return value;
|
|
@@ -4171,7 +4760,7 @@ var formatOtherPart4 = (part) => {
|
|
|
4171
4760
|
return payloadText ? `[other:${part.provider}/${part.kind}] ${payloadText}` : `[other:${part.provider}/${part.kind}]`;
|
|
4172
4761
|
};
|
|
4173
4762
|
var isResponsesApiInputContent = (value) => {
|
|
4174
|
-
if (!
|
|
4763
|
+
if (!isRecord4(value)) return false;
|
|
4175
4764
|
const type = value.type;
|
|
4176
4765
|
if (type === "input_text") {
|
|
4177
4766
|
return typeof value.text === "string";
|
|
@@ -4937,10 +5526,12 @@ export {
|
|
|
4937
5526
|
createModelRegistry,
|
|
4938
5527
|
defineTool,
|
|
4939
5528
|
getDefaultSystemPromptPath,
|
|
5529
|
+
isUsableModelSpec,
|
|
4940
5530
|
listModels,
|
|
4941
5531
|
registerModels,
|
|
4942
5532
|
resolveModel,
|
|
4943
5533
|
resolveProviderModelId,
|
|
4944
5534
|
stringifyContent,
|
|
4945
|
-
stringifyContentParts
|
|
5535
|
+
stringifyContentParts,
|
|
5536
|
+
supportsFastMode
|
|
4946
5537
|
};
|