@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.cjs
CHANGED
|
@@ -47,12 +47,14 @@ __export(index_exports, {
|
|
|
47
47
|
createModelRegistry: () => createModelRegistry,
|
|
48
48
|
defineTool: () => defineTool,
|
|
49
49
|
getDefaultSystemPromptPath: () => getDefaultSystemPromptPath,
|
|
50
|
+
isUsableModelSpec: () => isUsableModelSpec,
|
|
50
51
|
listModels: () => listModels,
|
|
51
52
|
registerModels: () => registerModels,
|
|
52
53
|
resolveModel: () => resolveModel,
|
|
53
54
|
resolveProviderModelId: () => resolveProviderModelId,
|
|
54
55
|
stringifyContent: () => stringifyContent,
|
|
55
|
-
stringifyContentParts: () => stringifyContentParts
|
|
56
|
+
stringifyContentParts: () => stringifyContentParts,
|
|
57
|
+
supportsFastMode: () => supportsFastMode
|
|
56
58
|
});
|
|
57
59
|
module.exports = __toCommonJS(index_exports);
|
|
58
60
|
|
|
@@ -69,12 +71,34 @@ var OPENAI_MODELS = [
|
|
|
69
71
|
provider: "openai",
|
|
70
72
|
aliases: ["default"]
|
|
71
73
|
},
|
|
74
|
+
{
|
|
75
|
+
id: "gpt-5.5",
|
|
76
|
+
provider: "openai",
|
|
77
|
+
contextWindow: 105e4,
|
|
78
|
+
maxInputTokens: 27e4,
|
|
79
|
+
maxOutputTokens: 13e4,
|
|
80
|
+
supportsFast: true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "gpt-5.5-1M",
|
|
84
|
+
provider: "openai",
|
|
85
|
+
providerModelId: "gpt-5.5",
|
|
86
|
+
aliases: ["gpt-5.5-1m", "gpt-5.5-full"],
|
|
87
|
+
contextWindow: 105e4,
|
|
88
|
+
maxInputTokens: 92e4,
|
|
89
|
+
maxOutputTokens: 13e4
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "gpt-5.5-pro",
|
|
93
|
+
provider: "openai"
|
|
94
|
+
},
|
|
72
95
|
{
|
|
73
96
|
id: "gpt-5.4",
|
|
74
97
|
provider: "openai",
|
|
75
98
|
contextWindow: 105e4,
|
|
76
99
|
maxInputTokens: GPT_5_4_CAPPED_INPUT_TOKENS,
|
|
77
|
-
maxOutputTokens: 128e3
|
|
100
|
+
maxOutputTokens: 128e3,
|
|
101
|
+
supportsFast: true
|
|
78
102
|
},
|
|
79
103
|
{
|
|
80
104
|
id: "gpt-5.4-1M",
|
|
@@ -96,11 +120,13 @@ var OPENAI_MODELS = [
|
|
|
96
120
|
},
|
|
97
121
|
{
|
|
98
122
|
id: "gpt-5.2-2025-12-11",
|
|
99
|
-
provider: "openai"
|
|
123
|
+
provider: "openai",
|
|
124
|
+
supportsFast: true
|
|
100
125
|
},
|
|
101
126
|
{
|
|
102
127
|
id: "gpt-5.2",
|
|
103
|
-
provider: "openai"
|
|
128
|
+
provider: "openai",
|
|
129
|
+
supportsFast: true
|
|
104
130
|
},
|
|
105
131
|
{
|
|
106
132
|
id: "gpt-5.2-pro",
|
|
@@ -112,23 +138,28 @@ var OPENAI_MODELS = [
|
|
|
112
138
|
},
|
|
113
139
|
{
|
|
114
140
|
id: "gpt-5.1",
|
|
115
|
-
provider: "openai"
|
|
141
|
+
provider: "openai",
|
|
142
|
+
supportsFast: true
|
|
116
143
|
},
|
|
117
144
|
{
|
|
118
145
|
id: "gpt-5.1-2025-11-13",
|
|
119
|
-
provider: "openai"
|
|
146
|
+
provider: "openai",
|
|
147
|
+
supportsFast: true
|
|
120
148
|
},
|
|
121
149
|
{
|
|
122
150
|
id: "gpt-5",
|
|
123
|
-
provider: "openai"
|
|
151
|
+
provider: "openai",
|
|
152
|
+
supportsFast: true
|
|
124
153
|
},
|
|
125
154
|
{
|
|
126
155
|
id: "gpt-5-mini",
|
|
127
|
-
provider: "openai"
|
|
156
|
+
provider: "openai",
|
|
157
|
+
supportsFast: true
|
|
128
158
|
},
|
|
129
159
|
{
|
|
130
160
|
id: "gpt-5-mini-2025-08-07",
|
|
131
|
-
provider: "openai"
|
|
161
|
+
provider: "openai",
|
|
162
|
+
supportsFast: true
|
|
132
163
|
},
|
|
133
164
|
{
|
|
134
165
|
id: "gpt-5-nano",
|
|
@@ -140,7 +171,8 @@ var OPENAI_MODELS = [
|
|
|
140
171
|
},
|
|
141
172
|
{
|
|
142
173
|
id: "gpt-5.1-codex",
|
|
143
|
-
provider: "openai"
|
|
174
|
+
provider: "openai",
|
|
175
|
+
supportsFast: true
|
|
144
176
|
},
|
|
145
177
|
{
|
|
146
178
|
id: "gpt-5.1-codex-max",
|
|
@@ -152,7 +184,8 @@ var OPENAI_MODELS = [
|
|
|
152
184
|
},
|
|
153
185
|
{
|
|
154
186
|
id: "gpt-5-codex",
|
|
155
|
-
provider: "openai"
|
|
187
|
+
provider: "openai",
|
|
188
|
+
supportsFast: true
|
|
156
189
|
},
|
|
157
190
|
{
|
|
158
191
|
id: "gpt-5-codex-mini",
|
|
@@ -268,9 +301,18 @@ var ANTHROPIC_MODELS = [
|
|
|
268
301
|
provider: "anthropic",
|
|
269
302
|
aliases: ["default"]
|
|
270
303
|
},
|
|
304
|
+
{
|
|
305
|
+
id: "claude-opus-4-7",
|
|
306
|
+
provider: "anthropic",
|
|
307
|
+
contextWindow: 1e6,
|
|
308
|
+
maxInputTokens: 1e6,
|
|
309
|
+
maxOutputTokens: 128e3,
|
|
310
|
+
supportsFast: true
|
|
311
|
+
},
|
|
271
312
|
{
|
|
272
313
|
id: "claude-opus-4-6",
|
|
273
|
-
provider: "anthropic"
|
|
314
|
+
provider: "anthropic",
|
|
315
|
+
supportsFast: true
|
|
274
316
|
},
|
|
275
317
|
{
|
|
276
318
|
id: "claude-opus-4-5",
|
|
@@ -365,10 +407,18 @@ function listModels(registry, provider) {
|
|
|
365
407
|
const all = Object.values(registry.modelsById);
|
|
366
408
|
return provider ? all.filter((model) => model.provider === provider) : all;
|
|
367
409
|
}
|
|
410
|
+
var isPositiveFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
411
|
+
function isUsableModelSpec(spec) {
|
|
412
|
+
return isPositiveFiniteNumber(spec?.maxInputTokens) || isPositiveFiniteNumber(spec?.contextWindow);
|
|
413
|
+
}
|
|
368
414
|
function resolveProviderModelId(registry, idOrAlias, provider) {
|
|
369
415
|
const spec = resolveModel(registry, idOrAlias, provider);
|
|
370
416
|
return spec ? spec.providerModelId ?? spec.id : void 0;
|
|
371
417
|
}
|
|
418
|
+
function supportsFastMode(registry, idOrAlias, provider) {
|
|
419
|
+
const spec = resolveModel(registry, idOrAlias, provider);
|
|
420
|
+
return spec?.supportsFast === true;
|
|
421
|
+
}
|
|
372
422
|
function cloneAliases(aliasesByProvider) {
|
|
373
423
|
return {
|
|
374
424
|
openai: { ...aliasesByProvider.openai },
|
|
@@ -2292,12 +2342,14 @@ var DEFAULT_CLIENT_TIMEOUT_MS = 20 * 60 * 1e3;
|
|
|
2292
2342
|
var DEFAULT_PROMPT_CACHE_CONTROL = {
|
|
2293
2343
|
type: "ephemeral"
|
|
2294
2344
|
};
|
|
2345
|
+
var FAST_MODE_BETA = "fast-mode-2026-02-01";
|
|
2295
2346
|
var ChatAnthropic = class {
|
|
2296
2347
|
provider = PROVIDER_NAME;
|
|
2297
2348
|
model;
|
|
2298
2349
|
client;
|
|
2299
2350
|
defaultMaxTokens;
|
|
2300
2351
|
defaultInvokeOptions;
|
|
2352
|
+
fastMode;
|
|
2301
2353
|
reasoningLevelMeta;
|
|
2302
2354
|
debugInvokeSeq = 0;
|
|
2303
2355
|
lastDebugRequestPayload = null;
|
|
@@ -2309,6 +2361,7 @@ var ChatAnthropic = class {
|
|
|
2309
2361
|
this.model = options.model ?? DEFAULT_MODEL;
|
|
2310
2362
|
this.defaultMaxTokens = options.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
2311
2363
|
this.defaultInvokeOptions = { ...options.invokeOptions ?? {} };
|
|
2364
|
+
this.fastMode = options.fastMode === true;
|
|
2312
2365
|
this.reasoningLevelMeta = {
|
|
2313
2366
|
requested: options.reasoningLevelRequested,
|
|
2314
2367
|
applied: options.reasoningLevelApplied,
|
|
@@ -2346,14 +2399,17 @@ var ChatAnthropic = class {
|
|
|
2346
2399
|
if (request.cache_control === void 0) {
|
|
2347
2400
|
request.cache_control = DEFAULT_PROMPT_CACHE_CONTROL;
|
|
2348
2401
|
}
|
|
2402
|
+
if (this.fastMode) {
|
|
2403
|
+
request.speed = "fast";
|
|
2404
|
+
request.betas = [...request.betas ?? [], FAST_MODE_BETA];
|
|
2405
|
+
}
|
|
2349
2406
|
const debugSeq = this.nextDebugInvokeSeq();
|
|
2350
2407
|
await this.debugRequestIfEnabled(request, debugSeq);
|
|
2351
|
-
const
|
|
2408
|
+
const requestOptions = signal ? { signal } : void 0;
|
|
2409
|
+
const response = this.fastMode ? await this.client.beta.messages.create(
|
|
2352
2410
|
request,
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
} : void 0
|
|
2356
|
-
);
|
|
2411
|
+
requestOptions
|
|
2412
|
+
) : await this.client.messages.create(request, requestOptions);
|
|
2357
2413
|
await this.debugResponseIfEnabled(response, debugSeq);
|
|
2358
2414
|
return toChatInvokeCompletion(response, {
|
|
2359
2415
|
reasoning_requested: this.reasoningLevelMeta.requested,
|
|
@@ -2448,25 +2504,6 @@ var ChatAnthropic = class {
|
|
|
2448
2504
|
var import_node_crypto2 = require("crypto");
|
|
2449
2505
|
var import_openai3 = __toESM(require("openai"), 1);
|
|
2450
2506
|
|
|
2451
|
-
// src/llm/openai/http-transport.ts
|
|
2452
|
-
var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader) => {
|
|
2453
|
-
const streamRequest = {
|
|
2454
|
-
...request,
|
|
2455
|
-
stream: true
|
|
2456
|
-
};
|
|
2457
|
-
return client.responses.stream(
|
|
2458
|
-
streamRequest,
|
|
2459
|
-
signal || sessionIdHeader ? {
|
|
2460
|
-
...signal ? { signal } : {},
|
|
2461
|
-
...sessionIdHeader ? {
|
|
2462
|
-
headers: {
|
|
2463
|
-
session_id: sessionIdHeader
|
|
2464
|
-
}
|
|
2465
|
-
} : {}
|
|
2466
|
-
} : void 0
|
|
2467
|
-
).finalResponse();
|
|
2468
|
-
};
|
|
2469
|
-
|
|
2470
2507
|
// src/llm/openai/response-utils.ts
|
|
2471
2508
|
var isRecord2 = (value) => typeof value === "object" && value !== null;
|
|
2472
2509
|
var stringifyUnknown3 = (value) => {
|
|
@@ -2508,6 +2545,107 @@ var extractOutputText = (items) => {
|
|
|
2508
2545
|
}
|
|
2509
2546
|
return texts.join("");
|
|
2510
2547
|
};
|
|
2548
|
+
var getRecordString = (record, key) => {
|
|
2549
|
+
const value = record[key];
|
|
2550
|
+
return typeof value === "string" ? value : void 0;
|
|
2551
|
+
};
|
|
2552
|
+
var getRecordNumber = (record, key) => {
|
|
2553
|
+
const value = record[key];
|
|
2554
|
+
return typeof value === "number" ? value : void 0;
|
|
2555
|
+
};
|
|
2556
|
+
var clipDebugText = (value, maxChars = 80) => value.length <= maxChars ? value : `${value.slice(0, maxChars)}...`;
|
|
2557
|
+
var getResponseStreamEventDebugPayload = (event) => {
|
|
2558
|
+
const payload = {
|
|
2559
|
+
type: event.type,
|
|
2560
|
+
sequence_number: typeof event.sequence_number === "number" ? event.sequence_number : null
|
|
2561
|
+
};
|
|
2562
|
+
const eventRecord = event;
|
|
2563
|
+
const outputIndex = getRecordNumber(eventRecord, "output_index");
|
|
2564
|
+
if (outputIndex !== void 0) {
|
|
2565
|
+
payload.output_index = outputIndex;
|
|
2566
|
+
}
|
|
2567
|
+
const contentIndex = getRecordNumber(eventRecord, "content_index");
|
|
2568
|
+
if (contentIndex !== void 0) {
|
|
2569
|
+
payload.content_index = contentIndex;
|
|
2570
|
+
}
|
|
2571
|
+
switch (event.type) {
|
|
2572
|
+
case "response.output_text.delta":
|
|
2573
|
+
case "response.reasoning_text.delta":
|
|
2574
|
+
case "response.function_call_arguments.delta": {
|
|
2575
|
+
const delta = getRecordString(eventRecord, "delta") ?? "";
|
|
2576
|
+
payload.delta_chars = delta.length;
|
|
2577
|
+
payload.delta_preview = clipDebugText(delta);
|
|
2578
|
+
break;
|
|
2579
|
+
}
|
|
2580
|
+
case "response.output_item.added":
|
|
2581
|
+
case "response.output_item.done": {
|
|
2582
|
+
const item = eventRecord.item;
|
|
2583
|
+
if (isRecord2(item)) {
|
|
2584
|
+
payload.item_type = getRecordString(item, "type");
|
|
2585
|
+
payload.item_role = getRecordString(item, "role");
|
|
2586
|
+
}
|
|
2587
|
+
break;
|
|
2588
|
+
}
|
|
2589
|
+
case "response.content_part.added": {
|
|
2590
|
+
const part = eventRecord.part;
|
|
2591
|
+
if (isRecord2(part)) {
|
|
2592
|
+
payload.part_type = getRecordString(part, "type");
|
|
2593
|
+
if (part.type === "output_text") {
|
|
2594
|
+
const text = getRecordString(part, "text") ?? "";
|
|
2595
|
+
payload.delta_chars = text.length;
|
|
2596
|
+
payload.delta_preview = clipDebugText(text);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
break;
|
|
2600
|
+
}
|
|
2601
|
+
case "response.completed": {
|
|
2602
|
+
const response = eventRecord.response;
|
|
2603
|
+
if (isRecord2(response)) {
|
|
2604
|
+
payload.response_id = getRecordString(response, "id");
|
|
2605
|
+
const status = response.status;
|
|
2606
|
+
payload.response_status = typeof status === "string" ? status : null;
|
|
2607
|
+
const output = response.output;
|
|
2608
|
+
if (Array.isArray(output)) {
|
|
2609
|
+
payload.response_output_items = output.length;
|
|
2610
|
+
}
|
|
2611
|
+
const outputText = response.output_text;
|
|
2612
|
+
payload.response_output_text = typeof outputText === "string" ? clipDebugText(outputText) : null;
|
|
2613
|
+
const usage = response.usage;
|
|
2614
|
+
if (isRecord2(usage)) {
|
|
2615
|
+
payload.response_output_tokens = getRecordNumber(
|
|
2616
|
+
usage,
|
|
2617
|
+
"output_tokens"
|
|
2618
|
+
);
|
|
2619
|
+
const outputDetails = usage.output_tokens_details;
|
|
2620
|
+
if (isRecord2(outputDetails)) {
|
|
2621
|
+
payload.response_reasoning_tokens = getRecordNumber(
|
|
2622
|
+
outputDetails,
|
|
2623
|
+
"reasoning_tokens"
|
|
2624
|
+
);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
break;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
return payload;
|
|
2632
|
+
};
|
|
2633
|
+
var getEmptyCompletionDebugPayload = (response, completion) => {
|
|
2634
|
+
if (completion.messages.length > 0) {
|
|
2635
|
+
return null;
|
|
2636
|
+
}
|
|
2637
|
+
const outputTokens = response.usage?.output_tokens;
|
|
2638
|
+
if (typeof outputTokens !== "number" || outputTokens <= 0) {
|
|
2639
|
+
return null;
|
|
2640
|
+
}
|
|
2641
|
+
return {
|
|
2642
|
+
id: response.id,
|
|
2643
|
+
status: response.status ?? null,
|
|
2644
|
+
output_text: typeof response.output_text === "string" ? response.output_text : null,
|
|
2645
|
+
output: Array.isArray(response.output) ? response.output : [],
|
|
2646
|
+
usage: response.usage ?? null
|
|
2647
|
+
};
|
|
2648
|
+
};
|
|
2511
2649
|
var toResponseInputContent = (part) => {
|
|
2512
2650
|
switch (part.type) {
|
|
2513
2651
|
case "text":
|
|
@@ -2549,6 +2687,411 @@ var toFunctionCallOutput = (content) => {
|
|
|
2549
2687
|
return content.map(toResponseInputContent);
|
|
2550
2688
|
};
|
|
2551
2689
|
|
|
2690
|
+
// src/llm/openai/response-accumulator.ts
|
|
2691
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null;
|
|
2692
|
+
var envTruthy2 = (value) => {
|
|
2693
|
+
if (!value) return false;
|
|
2694
|
+
const normalized = value.trim().toLowerCase();
|
|
2695
|
+
return normalized === "1" || normalized === "true";
|
|
2696
|
+
};
|
|
2697
|
+
var loggedUnhandledResponseEventTypes = /* @__PURE__ */ new Set();
|
|
2698
|
+
var cloneValue = (value) => {
|
|
2699
|
+
if (typeof structuredClone === "function") {
|
|
2700
|
+
return structuredClone(value);
|
|
2701
|
+
}
|
|
2702
|
+
return JSON.parse(JSON.stringify(value));
|
|
2703
|
+
};
|
|
2704
|
+
var cloneResponse = (response) => cloneValue(response);
|
|
2705
|
+
var cloneOutputItem = (item) => cloneValue(item);
|
|
2706
|
+
var ensureArrayIndex = (array, index) => {
|
|
2707
|
+
while (array.length <= index) {
|
|
2708
|
+
array.push(void 0);
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
var OpenAiResponseAccumulator = class {
|
|
2712
|
+
baseResponse = null;
|
|
2713
|
+
terminalResponse = null;
|
|
2714
|
+
outputItems = [];
|
|
2715
|
+
observeEvent(event) {
|
|
2716
|
+
switch (event.type) {
|
|
2717
|
+
case "response.created":
|
|
2718
|
+
case "response.queued":
|
|
2719
|
+
case "response.in_progress":
|
|
2720
|
+
case "response.incomplete": {
|
|
2721
|
+
this.seedBaseResponse(event.response);
|
|
2722
|
+
break;
|
|
2723
|
+
}
|
|
2724
|
+
case "response.output_item.added":
|
|
2725
|
+
case "response.output_item.done": {
|
|
2726
|
+
this.setOutputItem(event.output_index, event.item);
|
|
2727
|
+
break;
|
|
2728
|
+
}
|
|
2729
|
+
case "response.content_part.added": {
|
|
2730
|
+
this.addContentPart(
|
|
2731
|
+
event.output_index,
|
|
2732
|
+
event.content_index,
|
|
2733
|
+
event.part
|
|
2734
|
+
);
|
|
2735
|
+
break;
|
|
2736
|
+
}
|
|
2737
|
+
case "response.output_text.delta": {
|
|
2738
|
+
this.appendMessageText(
|
|
2739
|
+
event.output_index,
|
|
2740
|
+
event.content_index,
|
|
2741
|
+
event.delta
|
|
2742
|
+
);
|
|
2743
|
+
break;
|
|
2744
|
+
}
|
|
2745
|
+
case "response.output_text.done": {
|
|
2746
|
+
this.setMessageText(
|
|
2747
|
+
event.output_index,
|
|
2748
|
+
event.content_index,
|
|
2749
|
+
event.text
|
|
2750
|
+
);
|
|
2751
|
+
break;
|
|
2752
|
+
}
|
|
2753
|
+
case "response.refusal.delta": {
|
|
2754
|
+
this.appendRefusalText(
|
|
2755
|
+
event.output_index,
|
|
2756
|
+
event.content_index,
|
|
2757
|
+
event.delta
|
|
2758
|
+
);
|
|
2759
|
+
break;
|
|
2760
|
+
}
|
|
2761
|
+
case "response.refusal.done": {
|
|
2762
|
+
this.setRefusalText(
|
|
2763
|
+
event.output_index,
|
|
2764
|
+
event.content_index,
|
|
2765
|
+
event.refusal
|
|
2766
|
+
);
|
|
2767
|
+
break;
|
|
2768
|
+
}
|
|
2769
|
+
case "response.function_call_arguments.delta": {
|
|
2770
|
+
this.appendFunctionCallArguments(event.output_index, event.delta);
|
|
2771
|
+
break;
|
|
2772
|
+
}
|
|
2773
|
+
case "response.function_call_arguments.done": {
|
|
2774
|
+
this.setFunctionCallArguments(
|
|
2775
|
+
event.output_index,
|
|
2776
|
+
event.name,
|
|
2777
|
+
event.arguments
|
|
2778
|
+
);
|
|
2779
|
+
break;
|
|
2780
|
+
}
|
|
2781
|
+
case "response.reasoning_summary_part.added":
|
|
2782
|
+
case "response.reasoning_summary_part.done": {
|
|
2783
|
+
this.setReasoningSummaryPart(
|
|
2784
|
+
event.output_index,
|
|
2785
|
+
event.summary_index,
|
|
2786
|
+
event.part.text
|
|
2787
|
+
);
|
|
2788
|
+
break;
|
|
2789
|
+
}
|
|
2790
|
+
case "response.reasoning_summary_text.delta": {
|
|
2791
|
+
this.appendReasoningSummaryText(
|
|
2792
|
+
event.output_index,
|
|
2793
|
+
event.summary_index,
|
|
2794
|
+
event.delta
|
|
2795
|
+
);
|
|
2796
|
+
break;
|
|
2797
|
+
}
|
|
2798
|
+
case "response.reasoning_summary_text.done": {
|
|
2799
|
+
this.setReasoningSummaryText(
|
|
2800
|
+
event.output_index,
|
|
2801
|
+
event.summary_index,
|
|
2802
|
+
event.text
|
|
2803
|
+
);
|
|
2804
|
+
break;
|
|
2805
|
+
}
|
|
2806
|
+
case "response.reasoning_text.delta": {
|
|
2807
|
+
this.appendReasoningText(
|
|
2808
|
+
event.output_index,
|
|
2809
|
+
event.content_index,
|
|
2810
|
+
event.delta
|
|
2811
|
+
);
|
|
2812
|
+
break;
|
|
2813
|
+
}
|
|
2814
|
+
case "response.reasoning_text.done": {
|
|
2815
|
+
this.setReasoningText(
|
|
2816
|
+
event.output_index,
|
|
2817
|
+
event.content_index,
|
|
2818
|
+
event.text
|
|
2819
|
+
);
|
|
2820
|
+
break;
|
|
2821
|
+
}
|
|
2822
|
+
case "response.output_text.annotation.added": {
|
|
2823
|
+
this.addOutputTextAnnotation(
|
|
2824
|
+
event.output_index,
|
|
2825
|
+
event.content_index,
|
|
2826
|
+
event.annotation_index,
|
|
2827
|
+
event.annotation
|
|
2828
|
+
);
|
|
2829
|
+
break;
|
|
2830
|
+
}
|
|
2831
|
+
case "response.completed": {
|
|
2832
|
+
this.observeTerminalResponse(event.response);
|
|
2833
|
+
break;
|
|
2834
|
+
}
|
|
2835
|
+
default: {
|
|
2836
|
+
this.logUnhandledResponseEvent(event);
|
|
2837
|
+
break;
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
observeTerminalResponse(response) {
|
|
2842
|
+
if (!this.baseResponse) {
|
|
2843
|
+
this.seedBaseResponse(response);
|
|
2844
|
+
}
|
|
2845
|
+
this.terminalResponse = cloneResponse(response);
|
|
2846
|
+
}
|
|
2847
|
+
buildResponse(fallbackResponse) {
|
|
2848
|
+
const terminal = fallbackResponse ? cloneResponse(fallbackResponse) : this.terminalResponse ? cloneResponse(this.terminalResponse) : null;
|
|
2849
|
+
const base = terminal ?? this.baseResponse;
|
|
2850
|
+
if (!base) {
|
|
2851
|
+
throw new Error("openai response accumulator has no response snapshot");
|
|
2852
|
+
}
|
|
2853
|
+
const merged = cloneResponse(base);
|
|
2854
|
+
const accumulatedOutput = this.getAccumulatedOutputItems();
|
|
2855
|
+
if (accumulatedOutput.length > 0) {
|
|
2856
|
+
merged.output = accumulatedOutput;
|
|
2857
|
+
const accumulatedText = extractOutputText(accumulatedOutput);
|
|
2858
|
+
merged.output_text = accumulatedText;
|
|
2859
|
+
}
|
|
2860
|
+
return merged;
|
|
2861
|
+
}
|
|
2862
|
+
seedBaseResponse(response) {
|
|
2863
|
+
this.baseResponse = cloneResponse(response);
|
|
2864
|
+
if (this.outputItems.length === 0 && Array.isArray(response.output)) {
|
|
2865
|
+
for (const [index, item] of response.output.entries()) {
|
|
2866
|
+
this.outputItems[index] = cloneOutputItem(item);
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
getAccumulatedOutputItems() {
|
|
2871
|
+
return this.outputItems.filter(
|
|
2872
|
+
(item) => item !== void 0
|
|
2873
|
+
);
|
|
2874
|
+
}
|
|
2875
|
+
setOutputItem(index, item) {
|
|
2876
|
+
ensureArrayIndex(this.outputItems, index);
|
|
2877
|
+
this.outputItems[index] = cloneOutputItem(item);
|
|
2878
|
+
}
|
|
2879
|
+
getOutputItem(index) {
|
|
2880
|
+
return this.outputItems[index];
|
|
2881
|
+
}
|
|
2882
|
+
addContentPart(outputIndex, contentIndex, part) {
|
|
2883
|
+
const output = this.getOutputItem(outputIndex);
|
|
2884
|
+
if (!output || !isRecord3(part)) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
if (output.type === "message" && part.type !== "reasoning_text") {
|
|
2888
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
2889
|
+
output.content[contentIndex] = cloneValue(
|
|
2890
|
+
part
|
|
2891
|
+
);
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
if (output.type === "reasoning" && part.type === "reasoning_text") {
|
|
2895
|
+
const content = output.content ?? [];
|
|
2896
|
+
ensureArrayIndex(content, contentIndex);
|
|
2897
|
+
content[contentIndex] = cloneValue(
|
|
2898
|
+
part
|
|
2899
|
+
);
|
|
2900
|
+
output.content = content;
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
appendMessageText(outputIndex, contentIndex, delta) {
|
|
2904
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2905
|
+
if (!part) {
|
|
2906
|
+
return;
|
|
2907
|
+
}
|
|
2908
|
+
part.text += delta;
|
|
2909
|
+
}
|
|
2910
|
+
setMessageText(outputIndex, contentIndex, text) {
|
|
2911
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2912
|
+
if (!part) {
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2915
|
+
part.text = text;
|
|
2916
|
+
}
|
|
2917
|
+
appendRefusalText(outputIndex, contentIndex, delta) {
|
|
2918
|
+
const part = this.ensureMessageRefusalPart(outputIndex, contentIndex);
|
|
2919
|
+
if (!part) {
|
|
2920
|
+
return;
|
|
2921
|
+
}
|
|
2922
|
+
part.refusal += delta;
|
|
2923
|
+
}
|
|
2924
|
+
setRefusalText(outputIndex, contentIndex, refusal) {
|
|
2925
|
+
const part = this.ensureMessageRefusalPart(outputIndex, contentIndex);
|
|
2926
|
+
if (!part) {
|
|
2927
|
+
return;
|
|
2928
|
+
}
|
|
2929
|
+
part.refusal = refusal;
|
|
2930
|
+
}
|
|
2931
|
+
appendFunctionCallArguments(outputIndex, delta) {
|
|
2932
|
+
const output = this.getOutputItem(outputIndex);
|
|
2933
|
+
if (!output || output.type !== "function_call") {
|
|
2934
|
+
return;
|
|
2935
|
+
}
|
|
2936
|
+
output.arguments += delta;
|
|
2937
|
+
}
|
|
2938
|
+
setFunctionCallArguments(outputIndex, name, argumentsText) {
|
|
2939
|
+
const output = this.getOutputItem(outputIndex);
|
|
2940
|
+
if (!output || output.type !== "function_call") {
|
|
2941
|
+
return;
|
|
2942
|
+
}
|
|
2943
|
+
output.name = name;
|
|
2944
|
+
output.arguments = argumentsText;
|
|
2945
|
+
}
|
|
2946
|
+
setReasoningSummaryPart(outputIndex, summaryIndex, text) {
|
|
2947
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2948
|
+
if (!summary) {
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
summary.text = text;
|
|
2952
|
+
}
|
|
2953
|
+
appendReasoningSummaryText(outputIndex, summaryIndex, delta) {
|
|
2954
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2955
|
+
if (!summary) {
|
|
2956
|
+
return;
|
|
2957
|
+
}
|
|
2958
|
+
summary.text += delta;
|
|
2959
|
+
}
|
|
2960
|
+
setReasoningSummaryText(outputIndex, summaryIndex, text) {
|
|
2961
|
+
const summary = this.ensureReasoningSummaryPart(outputIndex, summaryIndex);
|
|
2962
|
+
if (!summary) {
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
summary.text = text;
|
|
2966
|
+
}
|
|
2967
|
+
appendReasoningText(outputIndex, contentIndex, delta) {
|
|
2968
|
+
const content = this.ensureReasoningContentPart(outputIndex, contentIndex);
|
|
2969
|
+
if (!content) {
|
|
2970
|
+
return;
|
|
2971
|
+
}
|
|
2972
|
+
content.text += delta;
|
|
2973
|
+
}
|
|
2974
|
+
setReasoningText(outputIndex, contentIndex, text) {
|
|
2975
|
+
const content = this.ensureReasoningContentPart(outputIndex, contentIndex);
|
|
2976
|
+
if (!content) {
|
|
2977
|
+
return;
|
|
2978
|
+
}
|
|
2979
|
+
content.text = text;
|
|
2980
|
+
}
|
|
2981
|
+
addOutputTextAnnotation(outputIndex, contentIndex, annotationIndex, annotation) {
|
|
2982
|
+
const part = this.ensureMessageTextPart(outputIndex, contentIndex);
|
|
2983
|
+
if (!part) {
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
ensureArrayIndex(part.annotations, annotationIndex);
|
|
2987
|
+
part.annotations[annotationIndex] = cloneValue(annotation);
|
|
2988
|
+
}
|
|
2989
|
+
ensureMessageTextPart(outputIndex, contentIndex) {
|
|
2990
|
+
const output = this.getOutputItem(outputIndex);
|
|
2991
|
+
if (!output || output.type !== "message") {
|
|
2992
|
+
return void 0;
|
|
2993
|
+
}
|
|
2994
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
2995
|
+
const current = output.content[contentIndex];
|
|
2996
|
+
if (!current || current.type !== "output_text") {
|
|
2997
|
+
output.content[contentIndex] = {
|
|
2998
|
+
type: "output_text",
|
|
2999
|
+
text: "",
|
|
3000
|
+
annotations: []
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
return output.content[contentIndex];
|
|
3004
|
+
}
|
|
3005
|
+
ensureMessageRefusalPart(outputIndex, contentIndex) {
|
|
3006
|
+
const output = this.getOutputItem(outputIndex);
|
|
3007
|
+
if (!output || output.type !== "message") {
|
|
3008
|
+
return void 0;
|
|
3009
|
+
}
|
|
3010
|
+
ensureArrayIndex(output.content, contentIndex);
|
|
3011
|
+
const current = output.content[contentIndex];
|
|
3012
|
+
if (!current || current.type !== "refusal") {
|
|
3013
|
+
output.content[contentIndex] = {
|
|
3014
|
+
type: "refusal",
|
|
3015
|
+
refusal: ""
|
|
3016
|
+
};
|
|
3017
|
+
}
|
|
3018
|
+
return output.content[contentIndex];
|
|
3019
|
+
}
|
|
3020
|
+
ensureReasoningSummaryPart(outputIndex, summaryIndex) {
|
|
3021
|
+
const output = this.getOutputItem(outputIndex);
|
|
3022
|
+
if (!output || output.type !== "reasoning") {
|
|
3023
|
+
return void 0;
|
|
3024
|
+
}
|
|
3025
|
+
ensureArrayIndex(output.summary, summaryIndex);
|
|
3026
|
+
if (!output.summary[summaryIndex]) {
|
|
3027
|
+
output.summary[summaryIndex] = {
|
|
3028
|
+
type: "summary_text",
|
|
3029
|
+
text: ""
|
|
3030
|
+
};
|
|
3031
|
+
}
|
|
3032
|
+
return output.summary[summaryIndex];
|
|
3033
|
+
}
|
|
3034
|
+
ensureReasoningContentPart(outputIndex, contentIndex) {
|
|
3035
|
+
const output = this.getOutputItem(outputIndex);
|
|
3036
|
+
if (!output || output.type !== "reasoning") {
|
|
3037
|
+
return void 0;
|
|
3038
|
+
}
|
|
3039
|
+
const content = output.content ?? [];
|
|
3040
|
+
ensureArrayIndex(content, contentIndex);
|
|
3041
|
+
if (!content[contentIndex]) {
|
|
3042
|
+
content[contentIndex] = {
|
|
3043
|
+
type: "reasoning_text",
|
|
3044
|
+
text: ""
|
|
3045
|
+
};
|
|
3046
|
+
}
|
|
3047
|
+
output.content = content;
|
|
3048
|
+
return content[contentIndex];
|
|
3049
|
+
}
|
|
3050
|
+
logUnhandledResponseEvent(event) {
|
|
3051
|
+
if (!envTruthy2(process.env.CODELIA_PROVIDER_LOG) && !envTruthy2(process.env.CODELIA_DEBUG)) {
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
3054
|
+
if (!event.type.startsWith("response.")) {
|
|
3055
|
+
return;
|
|
3056
|
+
}
|
|
3057
|
+
if (loggedUnhandledResponseEventTypes.has(event.type)) {
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3060
|
+
loggedUnhandledResponseEventTypes.add(event.type);
|
|
3061
|
+
const payload = getResponseStreamEventDebugPayload(event);
|
|
3062
|
+
console.error(`[openai.stream.unhandled] ${safeJsonStringify(payload)}`);
|
|
3063
|
+
}
|
|
3064
|
+
};
|
|
3065
|
+
|
|
3066
|
+
// src/llm/openai/http-transport.ts
|
|
3067
|
+
var invokeOpenAiHttp = async (client, request, signal, sessionIdHeader, onEvent) => {
|
|
3068
|
+
const streamRequest = {
|
|
3069
|
+
...request,
|
|
3070
|
+
stream: true
|
|
3071
|
+
};
|
|
3072
|
+
const stream = client.responses.stream(
|
|
3073
|
+
streamRequest,
|
|
3074
|
+
signal || sessionIdHeader ? {
|
|
3075
|
+
...signal ? { signal } : {},
|
|
3076
|
+
...sessionIdHeader ? {
|
|
3077
|
+
headers: {
|
|
3078
|
+
session_id: sessionIdHeader
|
|
3079
|
+
}
|
|
3080
|
+
} : {}
|
|
3081
|
+
} : void 0
|
|
3082
|
+
);
|
|
3083
|
+
if (typeof stream[Symbol.asyncIterator] === "function") {
|
|
3084
|
+
const accumulator = new OpenAiResponseAccumulator();
|
|
3085
|
+
for await (const event of stream) {
|
|
3086
|
+
accumulator.observeEvent(event);
|
|
3087
|
+
await onEvent?.(event);
|
|
3088
|
+
}
|
|
3089
|
+
const finalResponse = await stream.finalResponse();
|
|
3090
|
+
return accumulator.buildResponse(finalResponse);
|
|
3091
|
+
}
|
|
3092
|
+
return stream.finalResponse();
|
|
3093
|
+
};
|
|
3094
|
+
|
|
2552
3095
|
// src/llm/openai/serializer.ts
|
|
2553
3096
|
var toOpenAiOtherPart = (kind, payload) => ({
|
|
2554
3097
|
type: "other",
|
|
@@ -2948,12 +3491,12 @@ var resolveTimeoutMs = (value, fallbackMs) => {
|
|
|
2948
3491
|
}
|
|
2949
3492
|
return Math.floor(value);
|
|
2950
3493
|
};
|
|
2951
|
-
var
|
|
3494
|
+
var envTruthy3 = (value) => {
|
|
2952
3495
|
if (!value) return false;
|
|
2953
3496
|
const normalized = value.trim().toLowerCase();
|
|
2954
3497
|
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
2955
3498
|
};
|
|
2956
|
-
var WS_EVENT_TRACE_ENABLED =
|
|
3499
|
+
var WS_EVENT_TRACE_ENABLED = envTruthy3(process.env.CODELIA_DEBUG);
|
|
2957
3500
|
var WS_EVENT_TRACE_PROGRESS_LOG_INTERVAL_MS = 5e3;
|
|
2958
3501
|
var wsEventTraceStateBySource = /* @__PURE__ */ new Map();
|
|
2959
3502
|
var getWsEventTraceState = (source) => {
|
|
@@ -3075,6 +3618,7 @@ var OpenAiWsTransport = class {
|
|
|
3075
3618
|
let settled = false;
|
|
3076
3619
|
let rejectResponsePromise;
|
|
3077
3620
|
const responsePromise = new Promise((resolve, reject) => {
|
|
3621
|
+
const accumulator = new OpenAiResponseAccumulator();
|
|
3078
3622
|
let onAbort;
|
|
3079
3623
|
const nativeSocket = this.getNativeSocket(ws);
|
|
3080
3624
|
let removeNativeClose;
|
|
@@ -3130,7 +3674,7 @@ var OpenAiWsTransport = class {
|
|
|
3130
3674
|
if (settled || !terminalCompletedWithoutUsage) {
|
|
3131
3675
|
return;
|
|
3132
3676
|
}
|
|
3133
|
-
resolveOnce(terminalCompletedWithoutUsage);
|
|
3677
|
+
resolveOnce(accumulator.buildResponse(terminalCompletedWithoutUsage));
|
|
3134
3678
|
}, WS_TERMINAL_DONE_GRACE_MS);
|
|
3135
3679
|
};
|
|
3136
3680
|
const resetResponseTimeout = () => {
|
|
@@ -3141,7 +3685,9 @@ var OpenAiWsTransport = class {
|
|
|
3141
3685
|
timeout = setTimeout(() => {
|
|
3142
3686
|
if (settled) return;
|
|
3143
3687
|
if (terminalCompletedWithoutUsage) {
|
|
3144
|
-
resolveOnce(
|
|
3688
|
+
resolveOnce(
|
|
3689
|
+
accumulator.buildResponse(terminalCompletedWithoutUsage)
|
|
3690
|
+
);
|
|
3145
3691
|
return;
|
|
3146
3692
|
}
|
|
3147
3693
|
settled = true;
|
|
@@ -3156,18 +3702,19 @@ var OpenAiWsTransport = class {
|
|
|
3156
3702
|
const resolveFromTerminalEvent = (event, type) => {
|
|
3157
3703
|
const response = event?.response;
|
|
3158
3704
|
if (response && typeof response === "object") {
|
|
3705
|
+
accumulator.observeTerminalResponse(response);
|
|
3159
3706
|
if (type === "response.completed" && !this.hasUsageTotals(response)) {
|
|
3160
3707
|
terminalCompletedWithoutUsage = response;
|
|
3161
3708
|
scheduleDoneGraceTimer();
|
|
3162
3709
|
return;
|
|
3163
3710
|
}
|
|
3164
3711
|
clearDoneGraceTimer();
|
|
3165
|
-
resolveOnce(response);
|
|
3712
|
+
resolveOnce(accumulator.buildResponse(response));
|
|
3166
3713
|
return;
|
|
3167
3714
|
}
|
|
3168
3715
|
if (type === "response.done" && terminalCompletedWithoutUsage) {
|
|
3169
3716
|
clearDoneGraceTimer();
|
|
3170
|
-
resolveOnce(terminalCompletedWithoutUsage);
|
|
3717
|
+
resolveOnce(accumulator.buildResponse(terminalCompletedWithoutUsage));
|
|
3171
3718
|
return;
|
|
3172
3719
|
}
|
|
3173
3720
|
rejectOnce(
|
|
@@ -3179,6 +3726,9 @@ var OpenAiWsTransport = class {
|
|
|
3179
3726
|
if (!eventType) {
|
|
3180
3727
|
return;
|
|
3181
3728
|
}
|
|
3729
|
+
if (eventType !== "response.done") {
|
|
3730
|
+
accumulator.observeEvent(event);
|
|
3731
|
+
}
|
|
3182
3732
|
if (eventType === "response.failed") {
|
|
3183
3733
|
logWsEventTrace("sdk", eventType, false);
|
|
3184
3734
|
onResponseFailed(event);
|
|
@@ -3700,6 +4250,7 @@ var ChatOpenAI = class {
|
|
|
3700
4250
|
defaultReasoningEffort;
|
|
3701
4251
|
reasoningLevelMeta;
|
|
3702
4252
|
defaultTextVerbosity;
|
|
4253
|
+
defaultServiceTier;
|
|
3703
4254
|
websocketMode;
|
|
3704
4255
|
websocketApiVersion;
|
|
3705
4256
|
wsTransport;
|
|
@@ -3719,6 +4270,7 @@ var ChatOpenAI = class {
|
|
|
3719
4270
|
fallbackApplied: options.reasoningFallbackApplied
|
|
3720
4271
|
};
|
|
3721
4272
|
this.defaultTextVerbosity = options.textVerbosity;
|
|
4273
|
+
this.defaultServiceTier = options.serviceTier;
|
|
3722
4274
|
this.websocketMode = options.websocketMode ?? "off";
|
|
3723
4275
|
this.websocketApiVersion = options.websocketApiVersion ?? "v2";
|
|
3724
4276
|
this.wsTransport = new OpenAiWsTransport({
|
|
@@ -3742,7 +4294,7 @@ var ChatOpenAI = class {
|
|
|
3742
4294
|
const instructions = extractInstructions(messages);
|
|
3743
4295
|
const tools = toResponsesTools(toolDefs);
|
|
3744
4296
|
const tool_choice = toResponsesToolChoice(toolChoice);
|
|
3745
|
-
const { reasoningEffort, textVerbosity, ...rest } = options ?? {};
|
|
4297
|
+
const { reasoningEffort, textVerbosity, serviceTier, ...rest } = options ?? {};
|
|
3746
4298
|
const request = {
|
|
3747
4299
|
model: model ?? this.providerModel,
|
|
3748
4300
|
input: inputItems,
|
|
@@ -3774,6 +4326,10 @@ var ChatOpenAI = class {
|
|
|
3774
4326
|
verbosity
|
|
3775
4327
|
};
|
|
3776
4328
|
}
|
|
4329
|
+
const resolvedServiceTier = serviceTier ?? this.defaultServiceTier;
|
|
4330
|
+
if (resolvedServiceTier) {
|
|
4331
|
+
request.service_tier = resolvedServiceTier;
|
|
4332
|
+
}
|
|
3777
4333
|
if (context?.sessionKey && !request.prompt_cache_key) {
|
|
3778
4334
|
request.prompt_cache_key = context.sessionKey;
|
|
3779
4335
|
}
|
|
@@ -3797,7 +4353,7 @@ var ChatOpenAI = class {
|
|
|
3797
4353
|
debugSeq,
|
|
3798
4354
|
transportResult.transport
|
|
3799
4355
|
);
|
|
3800
|
-
|
|
4356
|
+
const completion = toChatInvokeCompletion2(transportResult.response, {
|
|
3801
4357
|
selected_model: model ?? this.model,
|
|
3802
4358
|
transport: transportResult.transport,
|
|
3803
4359
|
websocket_mode: this.websocketMode,
|
|
@@ -3809,6 +4365,13 @@ var ChatOpenAI = class {
|
|
|
3809
4365
|
reasoning_applied: this.reasoningLevelMeta.applied,
|
|
3810
4366
|
reasoning_fallback: this.reasoningLevelMeta.fallbackApplied
|
|
3811
4367
|
});
|
|
4368
|
+
await this.debugEmptyCompletionIfEnabled(
|
|
4369
|
+
transportResult.response,
|
|
4370
|
+
completion,
|
|
4371
|
+
debugSeq,
|
|
4372
|
+
transportResult.transport
|
|
4373
|
+
);
|
|
4374
|
+
return completion;
|
|
3812
4375
|
}
|
|
3813
4376
|
onHistoryCompacted(context) {
|
|
3814
4377
|
const sessionKey = context?.sessionKey;
|
|
@@ -4011,7 +4574,8 @@ var ChatOpenAI = class {
|
|
|
4011
4574
|
this.client,
|
|
4012
4575
|
args.request,
|
|
4013
4576
|
args.signal,
|
|
4014
|
-
args.sessionIdHeader
|
|
4577
|
+
args.sessionIdHeader,
|
|
4578
|
+
this.getHttpStreamDebugObserver(args.debugSeq)
|
|
4015
4579
|
);
|
|
4016
4580
|
return {
|
|
4017
4581
|
response,
|
|
@@ -4207,6 +4771,33 @@ var ChatOpenAI = class {
|
|
|
4207
4771
|
}
|
|
4208
4772
|
}
|
|
4209
4773
|
}
|
|
4774
|
+
async debugEmptyCompletionIfEnabled(response, completion, seq, transport) {
|
|
4775
|
+
const settings = getProviderLogSettings();
|
|
4776
|
+
if (!settings.enabled) {
|
|
4777
|
+
return;
|
|
4778
|
+
}
|
|
4779
|
+
const payload = getEmptyCompletionDebugPayload(response, completion);
|
|
4780
|
+
if (!payload) {
|
|
4781
|
+
return;
|
|
4782
|
+
}
|
|
4783
|
+
const outputTokens = payload.usage?.output_tokens ?? 0;
|
|
4784
|
+
console.error(
|
|
4785
|
+
`[openai.response.empty_completion] seq=${seq} transport=${transport} websocket_mode=${this.websocketMode} id=${payload.id} status=${payload.status ?? "unknown"} output_tokens=${outputTokens} messages=0`
|
|
4786
|
+
);
|
|
4787
|
+
console.error(safeJsonStringify(payload, 2));
|
|
4788
|
+
}
|
|
4789
|
+
getHttpStreamDebugObserver(seq) {
|
|
4790
|
+
const settings = getProviderLogSettings();
|
|
4791
|
+
if (!settings.enabled) {
|
|
4792
|
+
return void 0;
|
|
4793
|
+
}
|
|
4794
|
+
return (event) => {
|
|
4795
|
+
const payload = getResponseStreamEventDebugPayload(event);
|
|
4796
|
+
console.error(
|
|
4797
|
+
`[openai.stream.event] seq=${seq} transport=http_stream websocket_mode=${this.websocketMode} ${safeJsonStringify(payload)}`
|
|
4798
|
+
);
|
|
4799
|
+
};
|
|
4800
|
+
}
|
|
4210
4801
|
};
|
|
4211
4802
|
|
|
4212
4803
|
// src/llm/openrouter/chat.ts
|
|
@@ -4214,7 +4805,7 @@ var import_node_crypto3 = require("crypto");
|
|
|
4214
4805
|
var import_openai5 = __toESM(require("openai"), 1);
|
|
4215
4806
|
|
|
4216
4807
|
// src/llm/openrouter/response-utils.ts
|
|
4217
|
-
var
|
|
4808
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null;
|
|
4218
4809
|
var stringifyUnknown5 = (value) => {
|
|
4219
4810
|
if (value == null) return "";
|
|
4220
4811
|
if (typeof value === "string") return value;
|
|
@@ -4229,7 +4820,7 @@ var formatOtherPart4 = (part) => {
|
|
|
4229
4820
|
return payloadText ? `[other:${part.provider}/${part.kind}] ${payloadText}` : `[other:${part.provider}/${part.kind}]`;
|
|
4230
4821
|
};
|
|
4231
4822
|
var isResponsesApiInputContent = (value) => {
|
|
4232
|
-
if (!
|
|
4823
|
+
if (!isRecord4(value)) return false;
|
|
4233
4824
|
const type = value.type;
|
|
4234
4825
|
if (type === "input_text") {
|
|
4235
4826
|
return typeof value.text === "string";
|
|
@@ -4997,10 +5588,12 @@ function defineTool(toolOptions) {
|
|
|
4997
5588
|
createModelRegistry,
|
|
4998
5589
|
defineTool,
|
|
4999
5590
|
getDefaultSystemPromptPath,
|
|
5591
|
+
isUsableModelSpec,
|
|
5000
5592
|
listModels,
|
|
5001
5593
|
registerModels,
|
|
5002
5594
|
resolveModel,
|
|
5003
5595
|
resolveProviderModelId,
|
|
5004
5596
|
stringifyContent,
|
|
5005
|
-
stringifyContentParts
|
|
5597
|
+
stringifyContentParts,
|
|
5598
|
+
supportsFastMode
|
|
5006
5599
|
});
|