@codeworksh/aikit 0.12.1 → 0.13.0-dev.20261102120654
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/cli.mjs +5 -5
- package/{codex-CLDBTrFm.mjs → codex-DvULd3EJ.mjs} +2 -56
- package/codex-DvULd3EJ.mjs.map +1 -0
- package/{copilot-DvUXC6Kx.mjs → copilot-D9T1jbpu.mjs} +13 -3
- package/copilot-D9T1jbpu.mjs.map +1 -0
- package/{copilot-headers-BLnBaJyp.mjs → copilot-headers-I-AOoDed.mjs} +2 -2
- package/{copilot-headers-BLnBaJyp.mjs.map → copilot-headers-I-AOoDed.mjs.map} +1 -1
- package/{failure-5Wjd-qFH.d.mts → failure-CCCRfhCf.d.mts} +6 -3
- package/{failure-DFQNKc-O.mjs → failure-D0qEqOsO.mjs} +37 -5
- package/failure-D0qEqOsO.mjs.map +1 -0
- package/github-copilot-C75m0xwW.mjs +3 -0
- package/{github-copilot-BcmOr0jd.mjs → github-copilot-CdkIxdQS.mjs} +31 -15
- package/github-copilot-CdkIxdQS.mjs.map +1 -0
- package/index.d.mts +540 -237
- package/index.mjs +566 -103
- package/index.mjs.map +1 -1
- package/interactive-c0deRdi7.mjs +115 -0
- package/interactive-c0deRdi7.mjs.map +1 -0
- package/llm/failure.d.mts +2 -2
- package/llm/failure.mjs +2 -2
- package/{model-Cjp-Dr8V.mjs → model-BZZZAySN.mjs} +564 -617
- package/{model-Cjp-Dr8V.mjs.map → model-BZZZAySN.mjs.map} +1 -1
- package/{model-D3wc9-u4.d.mts → model-Dgf7E5gc.d.mts} +20 -1
- package/{openai-codex-C1Yb02kM.mjs → model-av44O6GQ.mjs} +340 -355
- package/model-av44O6GQ.mjs.map +1 -0
- package/{modelgen-DXMmI80T.mjs → modelgen-f3yv7FiK.mjs} +50 -17
- package/modelgen-f3yv7FiK.mjs.map +1 -0
- package/modelgen.d.mts +1 -1
- package/modelgen.mjs +2 -2
- package/oauth/github/copilot.d.mts +10 -0
- package/oauth/github/copilot.mjs +2 -2
- package/oauth/interactive.d.mts +6 -1
- package/oauth/interactive.mjs +2 -2
- package/oauth/openai/codex.mjs +1 -1
- package/openai-codex-BGNrJzTb.mjs +2 -0
- package/openai-codex-DL0lqVuN.mjs +117 -0
- package/openai-codex-DL0lqVuN.mjs.map +1 -0
- package/package.json +1 -1
- package/{registry-u49t0S4S.mjs → registry-BULNTLAP.mjs} +10 -6
- package/{registry-u49t0S4S.mjs.map → registry-BULNTLAP.mjs.map} +1 -1
- package/codex-CLDBTrFm.mjs.map +0 -1
- package/copilot-DvUXC6Kx.mjs.map +0 -1
- package/failure-DFQNKc-O.mjs.map +0 -1
- package/github-copilot-BcmOr0jd.mjs.map +0 -1
- package/github-copilot-llyP2NK4.mjs +0 -3
- package/interactive-eoNnscGB.mjs +0 -57
- package/interactive-eoNnscGB.mjs.map +0 -1
- package/modelgen-DXMmI80T.mjs.map +0 -1
- package/openai-codex-C1Yb02kM.mjs.map +0 -1
- package/openai-codex-CHxShIN3.mjs +0 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { a as FailureSchema } from "./schema-rXSoWhic.mjs";
|
|
3
|
-
import { a as KnownProviderEnumSchema, c as ThinkingLevel, o as ProviderInfo } from "./model-
|
|
4
|
-
import { s as getOpenAICodexAccountId } from "./codex-CLDBTrFm.mjs";
|
|
3
|
+
import { a as KnownProviderEnumSchema, c as ThinkingLevel, o as ProviderInfo } from "./model-BZZZAySN.mjs";
|
|
5
4
|
import Type$1 from "typebox";
|
|
6
5
|
import { uuidv7 } from "uuidv7";
|
|
7
|
-
import { APICallError
|
|
6
|
+
import { APICallError } from "@ai-sdk/provider";
|
|
8
7
|
import { EventSourceParserStream } from "eventsource-parser/stream";
|
|
9
8
|
//#region src/message/message.ts
|
|
10
9
|
var message_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
AssistantMessageDiagnosticSchema: () => AssistantMessageDiagnosticSchema,
|
|
11
11
|
AssistantMessageSchema: () => AssistantMessageSchema,
|
|
12
12
|
ConstrainedSamplingSchema: () => ConstrainedSamplingSchema,
|
|
13
13
|
ContextSchema: () => ContextSchema,
|
|
@@ -15,6 +15,7 @@ var message_exports = /* @__PURE__ */ __exportAll({
|
|
|
15
15
|
ImageContentSchema: () => ImageContentSchema,
|
|
16
16
|
MessageSchema: () => MessageSchema,
|
|
17
17
|
StopReasonSchema: () => StopReasonSchema,
|
|
18
|
+
SystemMessageSchema: () => SystemMessageSchema,
|
|
18
19
|
TextContentSchema: () => TextContentSchema,
|
|
19
20
|
ThinkingContentSchema: () => ThinkingContentSchema,
|
|
20
21
|
ToolAbortedSchema: () => ToolAbortedSchema,
|
|
@@ -31,6 +32,7 @@ var message_exports = /* @__PURE__ */ __exportAll({
|
|
|
31
32
|
ToolCompletedSchema: () => ToolCompletedSchema,
|
|
32
33
|
ToolErrorResult: () => ToolErrorResult,
|
|
33
34
|
ToolErrorSchema: () => ToolErrorSchema,
|
|
35
|
+
ToolReferenceSchema: () => ToolReferenceSchema,
|
|
34
36
|
ToolRunningPartial: () => ToolRunningPartial,
|
|
35
37
|
ToolRunningSchema: () => ToolRunningSchema,
|
|
36
38
|
ToolSchema: () => ToolSchema,
|
|
@@ -41,8 +43,10 @@ var message_exports = /* @__PURE__ */ __exportAll({
|
|
|
41
43
|
UserMessageSchema: () => UserMessageSchema,
|
|
42
44
|
createAssistantMessage: () => createAssistantMessage,
|
|
43
45
|
createMessageId: () => createMessageId,
|
|
46
|
+
createSystemMessage: () => createSystemMessage,
|
|
44
47
|
createUserMessage: () => createUserMessage,
|
|
45
48
|
defineTool: () => defineTool,
|
|
49
|
+
omitImages: () => omitImages,
|
|
46
50
|
transformMessages: () => transformMessages
|
|
47
51
|
});
|
|
48
52
|
const TextContentSchema = Type$1.Object({
|
|
@@ -71,8 +75,6 @@ const ToolCallBaseSchema = Type$1.Object({
|
|
|
71
75
|
arguments: Type$1.Record(Type$1.String(), Type$1.Any()),
|
|
72
76
|
thoughtSignature: Type$1.Optional(Type$1.String()),
|
|
73
77
|
namespace: Type$1.Optional(Type$1.String()),
|
|
74
|
-
/** Names from Context.tools that became available after this tool result. */
|
|
75
|
-
addedToolNames: Type$1.Optional(Type$1.Array(Type$1.String())),
|
|
76
78
|
time: Type$1.Object({
|
|
77
79
|
start: Type$1.Number(),
|
|
78
80
|
end: Type$1.Number()
|
|
@@ -173,6 +175,18 @@ const UserMessageSchema = Type$1.Object({
|
|
|
173
175
|
time: Type$1.Object({ created: Type$1.Number() }),
|
|
174
176
|
parts: Type$1.Array(Type$1.Union([TextContentSchema, ImageContentSchema]))
|
|
175
177
|
});
|
|
178
|
+
/** Something aikit did on the caller's behalf while producing a message, such as a request retried in another shape. */
|
|
179
|
+
const AssistantMessageDiagnosticSchema = Type$1.Object({
|
|
180
|
+
type: Type$1.String(),
|
|
181
|
+
timestamp: Type$1.Number(),
|
|
182
|
+
error: Type$1.Optional(Type$1.Object({
|
|
183
|
+
name: Type$1.Optional(Type$1.String()),
|
|
184
|
+
message: Type$1.String(),
|
|
185
|
+
stack: Type$1.Optional(Type$1.String()),
|
|
186
|
+
code: Type$1.Optional(Type$1.Union([Type$1.String(), Type$1.Number()]))
|
|
187
|
+
})),
|
|
188
|
+
details: Type$1.Optional(Type$1.Record(Type$1.String(), Type$1.Unknown()))
|
|
189
|
+
});
|
|
176
190
|
const AssistantMessageSchema = Type$1.Object({
|
|
177
191
|
role: Type$1.Literal("assistant"),
|
|
178
192
|
protocol: KnownProviderEnumSchema,
|
|
@@ -191,6 +205,7 @@ const AssistantMessageSchema = Type$1.Object({
|
|
|
191
205
|
* Depends on ai-sdk
|
|
192
206
|
*/
|
|
193
207
|
failure: Type$1.Optional(FailureSchema),
|
|
208
|
+
diagnostics: Type$1.Optional(Type$1.Array(AssistantMessageDiagnosticSchema)),
|
|
194
209
|
time: Type$1.Object({
|
|
195
210
|
created: Type$1.Number(),
|
|
196
211
|
completed: Type$1.Number()
|
|
@@ -205,7 +220,6 @@ const AssistantMessageSchema = Type$1.Object({
|
|
|
205
220
|
responseModel: Type$1.Optional(Type$1.String()),
|
|
206
221
|
messageId: Type$1.String()
|
|
207
222
|
});
|
|
208
|
-
const MessageSchema = Type$1.Union([UserMessageSchema, AssistantMessageSchema]);
|
|
209
223
|
function createMessageId() {
|
|
210
224
|
return uuidv7();
|
|
211
225
|
}
|
|
@@ -258,10 +272,54 @@ const ToolSchema = Type$1.Object({
|
|
|
258
272
|
function defineTool(tool) {
|
|
259
273
|
return tool;
|
|
260
274
|
}
|
|
275
|
+
const ToolReferenceSchema = Type$1.Object({ name: Type$1.String() });
|
|
276
|
+
/**
|
|
277
|
+
* A change to the system prompt and tool set at one point in the transcript.
|
|
278
|
+
*
|
|
279
|
+
* `Context.systemPrompt` and `Context.tools` hold the prompt and tools at the start of the
|
|
280
|
+
* conversation; each system message changes them from its position on. Replaying them in
|
|
281
|
+
* order yields the current prompt and tools. A redefinition is a removal plus an addition of
|
|
282
|
+
* the same name.
|
|
283
|
+
*/
|
|
284
|
+
const SystemMessageSchema = Type$1.Object({
|
|
285
|
+
messageId: Type$1.String(),
|
|
286
|
+
role: Type$1.Literal("system"),
|
|
287
|
+
time: Type$1.Object({ created: Type$1.Number() }),
|
|
288
|
+
/** Instructions that apply from this point on, after the earlier ones. */
|
|
289
|
+
content: Type$1.Optional(Type$1.String()),
|
|
290
|
+
/**
|
|
291
|
+
* Named prompt sections rendered after the content. A later message replaces a section by
|
|
292
|
+
* name, and `null` removes it. Keep each section self-delimiting (a tag) so the model can
|
|
293
|
+
* relate an update to the original, and avoid integer-like names, which JSON reorders.
|
|
294
|
+
*/
|
|
295
|
+
sections: Type$1.Optional(Type$1.Record(Type$1.String(), Type$1.Union([Type$1.String(), Type$1.Null()]))),
|
|
296
|
+
/** Complete definitions of tools that become available at this point. */
|
|
297
|
+
toolsAdded: Type$1.Optional(Type$1.Array(ToolSchema)),
|
|
298
|
+
/** Tools that stop being available at this point. */
|
|
299
|
+
toolsRemoved: Type$1.Optional(Type$1.Array(ToolReferenceSchema)),
|
|
300
|
+
/** Caller data kept with the message; never sent to a provider. */
|
|
301
|
+
metadata: Type$1.Optional(Type$1.Record(Type$1.String(), Type$1.Unknown()))
|
|
302
|
+
});
|
|
303
|
+
const MessageSchema = Type$1.Union([
|
|
304
|
+
SystemMessageSchema,
|
|
305
|
+
UserMessageSchema,
|
|
306
|
+
AssistantMessageSchema
|
|
307
|
+
]);
|
|
308
|
+
function createSystemMessage(message) {
|
|
309
|
+
const { messageId = createMessageId(), time = { created: Date.now() }, ...rest } = message;
|
|
310
|
+
return {
|
|
311
|
+
messageId,
|
|
312
|
+
role: "system",
|
|
313
|
+
time,
|
|
314
|
+
...rest
|
|
315
|
+
};
|
|
316
|
+
}
|
|
261
317
|
const ContextSchema = Type$1.Object({
|
|
262
318
|
systemPrompt: Type$1.Optional(Type$1.String()),
|
|
263
319
|
messages: Type$1.Array(MessageSchema),
|
|
264
|
-
tools: Type$1.Optional(Type$1.Array(ToolSchema))
|
|
320
|
+
tools: Type$1.Optional(Type$1.Array(ToolSchema)),
|
|
321
|
+
/** Tools a later system message may add, for transports that must declare every tool up front. */
|
|
322
|
+
deferredTools: Type$1.Optional(Type$1.Array(ToolSchema))
|
|
265
323
|
});
|
|
266
324
|
function isUnresolvedToolCall(toolCall) {
|
|
267
325
|
return toolCall.status === ToolStatusEnum.pending || toolCall.status === ToolStatusEnum.running;
|
|
@@ -310,6 +368,10 @@ function transformMessages(messages, model, normalizeToolCallId) {
|
|
|
310
368
|
const supportsImages = model.input.includes("image");
|
|
311
369
|
const transformed = [];
|
|
312
370
|
for (const msg of messages) {
|
|
371
|
+
if (msg.role === "system") {
|
|
372
|
+
transformed.push(msg);
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
313
375
|
if (msg.role === "user") {
|
|
314
376
|
transformed.push(supportsImages ? msg : {
|
|
315
377
|
...msg,
|
|
@@ -321,13 +383,10 @@ function transformMessages(messages, model, normalizeToolCallId) {
|
|
|
321
383
|
const isSameModel = assistantMsg.provider.id === model.provider.id && assistantMsg.protocol === model.protocol && assistantMsg.model === model.id;
|
|
322
384
|
const parts = assistantMsg.parts.flatMap((block) => {
|
|
323
385
|
if (block.type === "thinking") {
|
|
324
|
-
if (isSameModel
|
|
386
|
+
if (!isSameModel) return [];
|
|
387
|
+
if (block.redacted || block.thinkingSignature) return block;
|
|
325
388
|
if (!block.thinking || block.thinking.trim() === "") return [];
|
|
326
|
-
|
|
327
|
-
return {
|
|
328
|
-
type: "text",
|
|
329
|
-
text: block.thinking
|
|
330
|
-
};
|
|
389
|
+
return block;
|
|
331
390
|
}
|
|
332
391
|
if (block.type === "text") {
|
|
333
392
|
if (isSameModel) return block;
|
|
@@ -374,8 +433,8 @@ function transformMessages(messages, model, normalizeToolCallId) {
|
|
|
374
433
|
return transformed;
|
|
375
434
|
}
|
|
376
435
|
//#endregion
|
|
377
|
-
//#region src/providers/
|
|
378
|
-
function
|
|
436
|
+
//#region src/providers/responses/tools.ts
|
|
437
|
+
function appendGrammarInputJsonDelta(buffer, inputProperty, nextInput, close) {
|
|
379
438
|
if (buffer.closed) {
|
|
380
439
|
if (close && nextInput === buffer.input) return void 0;
|
|
381
440
|
throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
|
|
@@ -405,7 +464,7 @@ function inferGrammarInputProperty(parameters) {
|
|
|
405
464
|
if (schema.properties[inputProperty]?.type !== "string") throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
|
|
406
465
|
return inputProperty;
|
|
407
466
|
}
|
|
408
|
-
function
|
|
467
|
+
function resolveToolGrammar(tool, compat) {
|
|
409
468
|
const config = tool.constrainedSampling;
|
|
410
469
|
if (!config || config.type !== "grammar") return void 0;
|
|
411
470
|
if (!(compat?.supportsOpenAIGrammarTools ?? false)) return void 0;
|
|
@@ -426,84 +485,73 @@ function resolveOpenAICodexToolConstraint(tool, compat) {
|
|
|
426
485
|
throw new Error(`tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
|
|
427
486
|
}
|
|
428
487
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
488
|
+
/** A function tool carries its grammar in `providerOptions[<provider>].grammar`. */
|
|
489
|
+
function toolGrammar(tool, provider) {
|
|
490
|
+
const grammar = (tool.providerOptions?.[provider])?.grammar;
|
|
491
|
+
return grammar?.type === "grammar" ? grammar : void 0;
|
|
492
|
+
}
|
|
493
|
+
function toResponsesTool(tool, provider) {
|
|
494
|
+
const grammar = toolGrammar(tool, provider);
|
|
495
|
+
return grammar ? {
|
|
496
|
+
type: "custom",
|
|
497
|
+
name: tool.name,
|
|
498
|
+
...tool.description !== void 0 && { description: tool.description },
|
|
499
|
+
format: {
|
|
435
500
|
type: "grammar",
|
|
436
|
-
|
|
501
|
+
syntax: grammar.format,
|
|
502
|
+
definition: grammar.definition
|
|
437
503
|
}
|
|
504
|
+
} : {
|
|
505
|
+
type: "function",
|
|
506
|
+
name: tool.name,
|
|
507
|
+
...tool.description !== void 0 && { description: tool.description },
|
|
508
|
+
parameters: tool.inputSchema,
|
|
509
|
+
strict: tool.strict ?? null
|
|
438
510
|
};
|
|
439
|
-
} };
|
|
440
|
-
function resolveOpenAICodexDeferredToolsMode(compat) {
|
|
441
|
-
if (compat?.supportsAdditionalTools ?? false) return "additional-tools";
|
|
442
|
-
return compat?.supportsToolSearch ?? false ? "tool-search" : void 0;
|
|
443
511
|
}
|
|
444
|
-
function
|
|
512
|
+
function prepareResponsesTools({ provider, tools, toolChoice, inPlaceToolNames }) {
|
|
445
513
|
const warnings = [];
|
|
446
|
-
const deferredCodexTools = /* @__PURE__ */ new Map();
|
|
447
514
|
const grammarToolInputProperties = /* @__PURE__ */ new Map();
|
|
448
515
|
if (!tools || tools.length === 0) return {
|
|
449
|
-
|
|
450
|
-
deferredCodexTools,
|
|
516
|
+
responsesTools: void 0,
|
|
451
517
|
grammarToolInputProperties,
|
|
452
|
-
|
|
518
|
+
toolChoiceValue: void 0,
|
|
453
519
|
warnings
|
|
454
520
|
};
|
|
455
|
-
const
|
|
521
|
+
const responsesTools = [];
|
|
456
522
|
for (const tool of tools) {
|
|
457
523
|
if (tool.type !== "function") {
|
|
458
524
|
warnings.push({
|
|
459
525
|
type: "unsupported",
|
|
460
526
|
feature: `tool type ${tool.type}`,
|
|
461
|
-
details: `
|
|
527
|
+
details: `Only function tools are supported; ignoring ${tool.name}.`
|
|
462
528
|
});
|
|
463
529
|
continue;
|
|
464
530
|
}
|
|
465
|
-
const grammar = (tool
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
name: tool.name,
|
|
469
|
-
...tool.description !== void 0 && { description: tool.description },
|
|
470
|
-
format: {
|
|
471
|
-
type: "grammar",
|
|
472
|
-
syntax: grammar.format,
|
|
473
|
-
definition: grammar.definition
|
|
474
|
-
}
|
|
475
|
-
} : {
|
|
476
|
-
type: "function",
|
|
477
|
-
name: tool.name,
|
|
478
|
-
...tool.description !== void 0 && { description: tool.description },
|
|
479
|
-
parameters: tool.inputSchema,
|
|
480
|
-
strict: tool.strict ?? null
|
|
481
|
-
};
|
|
482
|
-
if (grammar?.type === "grammar") grammarToolInputProperties.set(tool.name, grammar.inputProperty);
|
|
483
|
-
if (deferredToolNames?.has(tool.name)) deferredCodexTools.set(tool.name, codexTool);
|
|
484
|
-
else codexTools.push(codexTool);
|
|
531
|
+
const grammar = toolGrammar(tool, provider);
|
|
532
|
+
if (grammar) grammarToolInputProperties.set(tool.name, grammar.inputProperty);
|
|
533
|
+
if (!inPlaceToolNames?.has(tool.name)) responsesTools.push(toResponsesTool(tool, provider));
|
|
485
534
|
}
|
|
486
|
-
let
|
|
535
|
+
let toolChoiceValue;
|
|
487
536
|
switch (toolChoice?.type) {
|
|
488
537
|
case void 0: break;
|
|
489
538
|
case "auto":
|
|
490
539
|
case "none":
|
|
491
540
|
case "required":
|
|
492
|
-
|
|
541
|
+
toolChoiceValue = toolChoice.type;
|
|
493
542
|
break;
|
|
494
543
|
case "tool":
|
|
495
544
|
warnings.push({
|
|
496
545
|
type: "unsupported",
|
|
497
546
|
feature: "toolChoice tool name",
|
|
498
|
-
details: "
|
|
547
|
+
details: "Forcing a specific tool is not supported; using 'required' instead."
|
|
499
548
|
});
|
|
500
|
-
|
|
549
|
+
toolChoiceValue = "required";
|
|
501
550
|
}
|
|
502
551
|
return {
|
|
503
|
-
|
|
504
|
-
deferredCodexTools,
|
|
552
|
+
responsesTools: responsesTools.length > 0 ? responsesTools : void 0,
|
|
505
553
|
grammarToolInputProperties,
|
|
506
|
-
|
|
554
|
+
toolChoiceValue,
|
|
507
555
|
warnings
|
|
508
556
|
};
|
|
509
557
|
}
|
|
@@ -523,7 +571,7 @@ function shortHash(value) {
|
|
|
523
571
|
return (low >>> 0).toString(36) + (high >>> 0).toString(36);
|
|
524
572
|
}
|
|
525
573
|
//#endregion
|
|
526
|
-
//#region src/providers/
|
|
574
|
+
//#region src/providers/responses/error.ts
|
|
527
575
|
const asRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
528
576
|
const asString$1 = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
529
577
|
function normalizeErrorPayload(value) {
|
|
@@ -589,11 +637,12 @@ function retryAfterHeader(message) {
|
|
|
589
637
|
return { "retry-after": String(match[2]?.toLowerCase() === "ms" ? value / 1e3 : value) };
|
|
590
638
|
}
|
|
591
639
|
/**
|
|
592
|
-
* Turn a
|
|
640
|
+
* Turn a Responses error payload into a human-friendly message. Only terminal
|
|
593
641
|
* ChatGPT plan exhaustion is rewritten; transient 429s retain backend detail.
|
|
642
|
+
* `label` names the backend, e.g. "OpenAI Codex".
|
|
594
643
|
*/
|
|
595
|
-
function
|
|
596
|
-
let message = body || statusText ||
|
|
644
|
+
function responsesErrorMessage(label, body, statusText) {
|
|
645
|
+
let message = body || statusText || `${label} request failed`;
|
|
597
646
|
const error = parseErrorPayload(body)?.error;
|
|
598
647
|
if (isUsageLimitError(error)) {
|
|
599
648
|
const plan = error?.plan_type ? ` (${error.plan_type.toLowerCase()} plan)` : "";
|
|
@@ -603,7 +652,7 @@ function openAICodexErrorMessage(_status, body, statusText) {
|
|
|
603
652
|
if (error?.message) message = error.message;
|
|
604
653
|
return message;
|
|
605
654
|
}
|
|
606
|
-
async function
|
|
655
|
+
async function createResponsesAPICallError(args) {
|
|
607
656
|
const { response, url, requestBodyValues } = args;
|
|
608
657
|
const responseBody = await response.text().catch(() => "");
|
|
609
658
|
const responseHeaders = {};
|
|
@@ -612,7 +661,7 @@ async function createOpenAICodexAPICallError(args) {
|
|
|
612
661
|
});
|
|
613
662
|
const data = parseErrorPayload(responseBody);
|
|
614
663
|
return new APICallError({
|
|
615
|
-
message:
|
|
664
|
+
message: responsesErrorMessage(args.label, responseBody, response.statusText),
|
|
616
665
|
url,
|
|
617
666
|
requestBodyValues,
|
|
618
667
|
statusCode: response.status,
|
|
@@ -623,7 +672,7 @@ async function createOpenAICodexAPICallError(args) {
|
|
|
623
672
|
});
|
|
624
673
|
}
|
|
625
674
|
/** Map an error embedded in a successful SSE response to the same API error shape as HTTP failures. */
|
|
626
|
-
function
|
|
675
|
+
function createResponsesStreamError(args) {
|
|
627
676
|
const { error: value, url, requestBodyValues } = args;
|
|
628
677
|
const data = normalizeErrorPayload(value);
|
|
629
678
|
const error = data.error;
|
|
@@ -634,7 +683,7 @@ function createOpenAICodexStreamError(args) {
|
|
|
634
683
|
...retryAfterHeader(error?.message)
|
|
635
684
|
};
|
|
636
685
|
return new APICallError({
|
|
637
|
-
message:
|
|
686
|
+
message: responsesErrorMessage(args.label, responseBody),
|
|
638
687
|
url,
|
|
639
688
|
requestBodyValues,
|
|
640
689
|
statusCode,
|
|
@@ -645,9 +694,9 @@ function createOpenAICodexStreamError(args) {
|
|
|
645
694
|
});
|
|
646
695
|
}
|
|
647
696
|
/** A transport failure used when an SSE response ends without a terminal Responses event. */
|
|
648
|
-
function
|
|
697
|
+
function createResponsesPrematureCloseError(args) {
|
|
649
698
|
return new APICallError({
|
|
650
|
-
message:
|
|
699
|
+
message: `${args.label} stream closed before response.completed`,
|
|
651
700
|
url: args.url,
|
|
652
701
|
requestBodyValues: args.requestBodyValues,
|
|
653
702
|
...args.responseHeaders !== void 0 && { responseHeaders: args.responseHeaders },
|
|
@@ -659,7 +708,7 @@ function createOpenAICodexPrematureCloseError(args) {
|
|
|
659
708
|
* it the way AI SDK providers do, so it reads as a retryable transport failure that
|
|
660
709
|
* carries the request. Aborts pass through untouched.
|
|
661
710
|
*/
|
|
662
|
-
function
|
|
711
|
+
function responsesFetchError(error, url, requestBodyValues) {
|
|
663
712
|
if (error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError")) return error;
|
|
664
713
|
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error;
|
|
665
714
|
return new APICallError({
|
|
@@ -671,7 +720,7 @@ function openAICodexFetchError(error, url, requestBodyValues) {
|
|
|
671
720
|
});
|
|
672
721
|
}
|
|
673
722
|
//#endregion
|
|
674
|
-
//#region src/providers/
|
|
723
|
+
//#region src/providers/responses/prompt.ts
|
|
675
724
|
const DEFAULT_INSTRUCTIONS = "You are a helpful assistant.";
|
|
676
725
|
function splitToolCallId(toolCallId) {
|
|
677
726
|
const separator = toolCallId.indexOf("|");
|
|
@@ -762,16 +811,15 @@ function customToolOutput(output, supportsImages) {
|
|
|
762
811
|
const value = toolResultOutput(output, supportsImages);
|
|
763
812
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
764
813
|
}
|
|
765
|
-
function
|
|
766
|
-
const
|
|
767
|
-
return typeof
|
|
814
|
+
function providerMetadata(providerOptions, provider) {
|
|
815
|
+
const metadata = providerOptions?.[provider];
|
|
816
|
+
return typeof metadata === "object" && metadata !== null && !Array.isArray(metadata) ? metadata : void 0;
|
|
768
817
|
}
|
|
769
|
-
function
|
|
770
|
-
|
|
771
|
-
return Array.isArray(names) ? names.filter((name) => typeof name === "string") : [];
|
|
818
|
+
function toolChange(providerOptions, provider) {
|
|
819
|
+
return providerMetadata(providerOptions, provider)?.toolChange;
|
|
772
820
|
}
|
|
773
|
-
function reasoningItem(providerOptions) {
|
|
774
|
-
const value =
|
|
821
|
+
function reasoningItem(providerOptions, provider) {
|
|
822
|
+
const value = providerMetadata(providerOptions, provider)?.reasoningItem;
|
|
775
823
|
if (typeof value !== "string") return void 0;
|
|
776
824
|
try {
|
|
777
825
|
const parsed = JSON.parse(value);
|
|
@@ -782,67 +830,63 @@ function reasoningItem(providerOptions) {
|
|
|
782
830
|
return;
|
|
783
831
|
}
|
|
784
832
|
}
|
|
785
|
-
/**
|
|
786
|
-
function
|
|
787
|
-
const
|
|
788
|
-
const usedNames = /* @__PURE__ */ new Set();
|
|
833
|
+
/** Names of every tool declared in place by a system message's tool change. */
|
|
834
|
+
function collectInPlaceToolNames(prompt, provider) {
|
|
835
|
+
const names = /* @__PURE__ */ new Set();
|
|
789
836
|
for (const message of prompt) {
|
|
790
|
-
if (message.role
|
|
791
|
-
|
|
792
|
-
if (part.type === "tool-call") usedNames.add(part.toolName);
|
|
793
|
-
if (part.type === "tool-result") {
|
|
794
|
-
for (const name of addedToolNames(part.providerOptions)) if (!usedNames.has(name)) deferredNames.add(name);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
continue;
|
|
798
|
-
}
|
|
799
|
-
if (message.role !== "tool") continue;
|
|
800
|
-
for (const part of message.content) {
|
|
801
|
-
if (part.type !== "tool-result") continue;
|
|
802
|
-
for (const name of addedToolNames(part.providerOptions)) if (!usedNames.has(name)) deferredNames.add(name);
|
|
803
|
-
}
|
|
837
|
+
if (message.role !== "system") continue;
|
|
838
|
+
for (const tool of toolChange(message.providerOptions, provider)?.tools ?? []) names.add(tool.name);
|
|
804
839
|
}
|
|
805
|
-
return
|
|
840
|
+
return names;
|
|
841
|
+
}
|
|
842
|
+
function incrementalToolsNotice(unavailable) {
|
|
843
|
+
const notice = "This is an incremental tools update. Previously declared tools remain available unless explicitly marked unavailable. A tool declared again here is available again, and its latest definition replaces the earlier one.";
|
|
844
|
+
return unavailable.size > 0 ? `${notice}\nStill unavailable: ${[...unavailable].join(", ")}.` : notice;
|
|
806
845
|
}
|
|
807
|
-
function
|
|
808
|
-
return `
|
|
846
|
+
function toolRemovalNotice(names) {
|
|
847
|
+
return `The following tools are no longer available. Do not call them:\n${names.map((name) => `- ${name}`).join("\n")}`;
|
|
809
848
|
}
|
|
810
849
|
/**
|
|
811
|
-
* Convert an AI SDK V3 prompt into the
|
|
812
|
-
*
|
|
850
|
+
* Convert an AI SDK V3 prompt into the Responses request shape. The leading system
|
|
851
|
+
* message goes where `options.systemPrompt` says, later ones (prompt updates and tool
|
|
852
|
+
* changes) go in place, and everything else maps to `input` items.
|
|
813
853
|
*/
|
|
814
|
-
function
|
|
854
|
+
function convertToResponsesPrompt(prompt, options) {
|
|
855
|
+
const { provider } = options;
|
|
815
856
|
let instructions;
|
|
816
857
|
const input = [];
|
|
817
858
|
let syntheticMessageCounter = 0;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
if (tools.length ===
|
|
828
|
-
|
|
859
|
+
let toolChangeCounter = 0;
|
|
860
|
+
let declaredAdditionalTools = false;
|
|
861
|
+
/** Tools announced as removed and not declared again since. */
|
|
862
|
+
const unavailableTools = /* @__PURE__ */ new Set();
|
|
863
|
+
/** Declares the change's tools; returns the removal notice, which goes with the message's text. */
|
|
864
|
+
const appendToolChange = (change) => {
|
|
865
|
+
const seed = toolChangeCounter++;
|
|
866
|
+
const tools = change.tools.map((tool) => toResponsesTool(tool, provider));
|
|
867
|
+
for (const tool of tools) unavailableTools.delete(tool.name);
|
|
868
|
+
if (tools.length > 0 && change.mode === "changes") {
|
|
869
|
+
if (declaredAdditionalTools) input.push({
|
|
870
|
+
role: "developer",
|
|
871
|
+
content: incrementalToolsNotice(unavailableTools)
|
|
872
|
+
});
|
|
873
|
+
declaredAdditionalTools = true;
|
|
829
874
|
input.push({
|
|
830
875
|
type: "additional_tools",
|
|
831
876
|
role: "developer",
|
|
832
877
|
tools
|
|
833
878
|
});
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
const callId = deferredToolCallId(toolCallId, tools.map((tool) => tool.name));
|
|
879
|
+
} else if (tools.length > 0) {
|
|
880
|
+
const names = tools.map((tool) => tool.name);
|
|
881
|
+
const callId = `cdwrk_aikit_tool_${shortHash(`${seed}:${names.join(",")}`)}`;
|
|
838
882
|
input.push({
|
|
839
883
|
type: "tool_search_call",
|
|
840
884
|
call_id: callId,
|
|
841
885
|
execution: "client",
|
|
842
886
|
status: "completed",
|
|
843
887
|
arguments: {
|
|
844
|
-
query:
|
|
845
|
-
limit:
|
|
888
|
+
query: names.join(" "),
|
|
889
|
+
limit: names.length
|
|
846
890
|
}
|
|
847
891
|
});
|
|
848
892
|
input.push({
|
|
@@ -856,11 +900,27 @@ function convertToOpenAICodexPrompt(prompt, options) {
|
|
|
856
900
|
}))
|
|
857
901
|
});
|
|
858
902
|
}
|
|
903
|
+
const added = new Set(tools.map((tool) => tool.name));
|
|
904
|
+
const removed = change.removed.filter((name) => !added.has(name));
|
|
905
|
+
if (removed.length === 0) return;
|
|
906
|
+
for (const name of removed) unavailableTools.add(name);
|
|
907
|
+
return toolRemovalNotice(removed);
|
|
859
908
|
};
|
|
860
909
|
for (const message of prompt) switch (message.role) {
|
|
861
|
-
case "system":
|
|
862
|
-
|
|
910
|
+
case "system": {
|
|
911
|
+
const change = toolChange(message.providerOptions, provider);
|
|
912
|
+
if (!change && options.systemPrompt === "instructions" && instructions === void 0) {
|
|
913
|
+
instructions = message.content;
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
const removal = change ? appendToolChange(change) : void 0;
|
|
917
|
+
const text = [message.content, removal ?? ""].filter((part) => part.length > 0).join("\n\n");
|
|
918
|
+
if (text.length > 0) input.push({
|
|
919
|
+
role: "developer",
|
|
920
|
+
content: text
|
|
921
|
+
});
|
|
863
922
|
break;
|
|
923
|
+
}
|
|
864
924
|
case "user": {
|
|
865
925
|
const content = [];
|
|
866
926
|
for (const part of message.content) if (part.type === "text") content.push({
|
|
@@ -883,11 +943,11 @@ function convertToOpenAICodexPrompt(prompt, options) {
|
|
|
883
943
|
}
|
|
884
944
|
case "assistant":
|
|
885
945
|
for (const part of message.content) if (part.type === "reasoning") {
|
|
886
|
-
const item = reasoningItem(part.providerOptions);
|
|
946
|
+
const item = reasoningItem(part.providerOptions, provider);
|
|
887
947
|
if (item) input.push(item);
|
|
888
948
|
} else if (part.type === "text") {
|
|
889
949
|
syntheticMessageCounter++;
|
|
890
|
-
const messageId =
|
|
950
|
+
const messageId = providerMetadata(part.providerOptions, provider)?.messageId;
|
|
891
951
|
input.push({
|
|
892
952
|
type: "message",
|
|
893
953
|
role: "assistant",
|
|
@@ -901,9 +961,9 @@ function convertToOpenAICodexPrompt(prompt, options) {
|
|
|
901
961
|
});
|
|
902
962
|
} else if (part.type === "tool-call") {
|
|
903
963
|
const { callId, itemId } = splitToolCallId(part.toolCallId);
|
|
904
|
-
const metadata =
|
|
964
|
+
const metadata = providerMetadata(part.providerOptions, provider);
|
|
905
965
|
const namespace = metadata?.namespace;
|
|
906
|
-
const inputProperty = options
|
|
966
|
+
const inputProperty = options.grammarToolInputProperties?.get(part.toolName);
|
|
907
967
|
if (inputProperty) input.push({
|
|
908
968
|
type: "custom_tool_call",
|
|
909
969
|
...metadata?.omitItemId === true || !itemId.startsWith("ctc_") ? {} : { id: itemId },
|
|
@@ -925,28 +985,28 @@ function convertToOpenAICodexPrompt(prompt, options) {
|
|
|
925
985
|
case "tool": for (const part of message.content) {
|
|
926
986
|
if (part.type !== "tool-result") continue;
|
|
927
987
|
const { callId } = splitToolCallId(part.toolCallId);
|
|
928
|
-
if (options
|
|
988
|
+
if (options.grammarToolInputProperties?.has(part.toolName)) input.push({
|
|
929
989
|
type: "custom_tool_call_output",
|
|
930
990
|
call_id: callId,
|
|
931
|
-
output: customToolOutput(part.output, options
|
|
991
|
+
output: customToolOutput(part.output, options.supportsImages ?? true)
|
|
932
992
|
});
|
|
933
993
|
else input.push({
|
|
934
994
|
type: "function_call_output",
|
|
935
995
|
call_id: callId,
|
|
936
|
-
output: toolResultOutput(part.output, options
|
|
996
|
+
output: toolResultOutput(part.output, options.supportsImages ?? true)
|
|
937
997
|
});
|
|
938
|
-
appendDeferredTools(part.toolCallId, addedToolNames(part.providerOptions));
|
|
939
998
|
}
|
|
940
999
|
}
|
|
1000
|
+
if (options.systemPrompt === "developer") return { input };
|
|
941
1001
|
return {
|
|
942
1002
|
instructions: instructions || DEFAULT_INSTRUCTIONS,
|
|
943
1003
|
input
|
|
944
1004
|
};
|
|
945
1005
|
}
|
|
946
1006
|
//#endregion
|
|
947
|
-
//#region src/providers/
|
|
948
|
-
/** Parse standards-compliant event streams from
|
|
949
|
-
function
|
|
1007
|
+
//#region src/providers/responses/sse.ts
|
|
1008
|
+
/** Parse standards-compliant event streams from a Responses endpoint. */
|
|
1009
|
+
function parseResponsesSSEStream(body) {
|
|
950
1010
|
const decoder = new TextDecoder();
|
|
951
1011
|
return body.pipeThrough(new TransformStream({
|
|
952
1012
|
transform(chunk, controller) {
|
|
@@ -962,16 +1022,16 @@ function parseOpenAICodexSSEStream(body) {
|
|
|
962
1022
|
if (!data || data === "[DONE]") return;
|
|
963
1023
|
try {
|
|
964
1024
|
const parsed = JSON.parse(data);
|
|
965
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new TypeError("
|
|
1025
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new TypeError("Responses SSE data must be a JSON object");
|
|
966
1026
|
controller.enqueue(parsed);
|
|
967
1027
|
} catch (cause) {
|
|
968
|
-
controller.error(new Error(`invalid
|
|
1028
|
+
controller.error(new Error(`invalid Responses SSE JSON: ${data.slice(0, 200)}`, { cause }));
|
|
969
1029
|
}
|
|
970
1030
|
} }));
|
|
971
1031
|
}
|
|
972
1032
|
//#endregion
|
|
973
|
-
//#region src/providers/
|
|
974
|
-
function
|
|
1033
|
+
//#region src/providers/responses/usage.ts
|
|
1034
|
+
function convertResponsesUsage(usage) {
|
|
975
1035
|
const inputTotal = usage?.input_tokens;
|
|
976
1036
|
const cachedTokens = usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
977
1037
|
const cacheWriteTokens = usage?.input_tokens_details?.cache_write_tokens ?? 0;
|
|
@@ -992,7 +1052,7 @@ function convertOpenAICodexUsage(usage) {
|
|
|
992
1052
|
...usage ? { raw: usage } : {}
|
|
993
1053
|
};
|
|
994
1054
|
}
|
|
995
|
-
function
|
|
1055
|
+
function mapResponsesFinishReason(status, hasToolCalls, incompleteReason) {
|
|
996
1056
|
switch (status) {
|
|
997
1057
|
case "completed": return {
|
|
998
1058
|
unified: hasToolCalls ? "tool-calls" : "stop",
|
|
@@ -1020,11 +1080,9 @@ function mapOpenAICodexFinishReason(status, hasToolCalls, incompleteReason) {
|
|
|
1020
1080
|
};
|
|
1021
1081
|
}
|
|
1022
1082
|
}
|
|
1023
|
-
//#endregion
|
|
1024
|
-
//#region src/providers/openai-codex/codex-language-model.ts
|
|
1025
|
-
const OPENAI_CODEX_DEFAULT_BASE_URL = "https://chatgpt.com/backend-api";
|
|
1026
1083
|
const REQUEST_COMPRESSION_ZSTD_LEVEL = 3;
|
|
1027
|
-
|
|
1084
|
+
const MIN_OUTPUT_TOKENS = 16;
|
|
1085
|
+
function compressRequest(body) {
|
|
1028
1086
|
if (typeof process === "undefined" || !(process.versions?.node || process.versions?.bun)) return void 0;
|
|
1029
1087
|
const zlib = process.getBuiltinModule?.("node:zlib");
|
|
1030
1088
|
if (!zlib || typeof zlib.zstdCompressSync !== "function") return void 0;
|
|
@@ -1035,21 +1093,11 @@ function compressOpenAICodexRequest(body) {
|
|
|
1035
1093
|
return;
|
|
1036
1094
|
}
|
|
1037
1095
|
}
|
|
1038
|
-
function
|
|
1096
|
+
function clampPromptCacheKey(key) {
|
|
1039
1097
|
if (key === void 0) return void 0;
|
|
1040
1098
|
const characters = Array.from(key);
|
|
1041
1099
|
return characters.length <= 64 ? key : characters.slice(0, 64).join("");
|
|
1042
1100
|
}
|
|
1043
|
-
/**
|
|
1044
|
-
* Resolve the Codex responses endpoint from a base URL that may already
|
|
1045
|
-
* include the `/codex` or `/codex/responses` suffix.
|
|
1046
|
-
*/
|
|
1047
|
-
function resolveOpenAICodexUrl(baseUrl) {
|
|
1048
|
-
const normalized = (baseUrl?.trim() ? baseUrl : OPENAI_CODEX_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1049
|
-
if (normalized.endsWith("/codex/responses")) return normalized;
|
|
1050
|
-
if (normalized.endsWith("/codex")) return `${normalized}/responses`;
|
|
1051
|
-
return `${normalized}/codex/responses`;
|
|
1052
|
-
}
|
|
1053
1101
|
function asRecord(value) {
|
|
1054
1102
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1055
1103
|
}
|
|
@@ -1061,7 +1109,7 @@ function cleanHeaders(headers) {
|
|
|
1061
1109
|
for (const [key, value] of Object.entries(headers)) if (value !== void 0) result[key] = value;
|
|
1062
1110
|
return result;
|
|
1063
1111
|
}
|
|
1064
|
-
var
|
|
1112
|
+
var ResponsesLanguageModel = class {
|
|
1065
1113
|
specificationVersion = "v3";
|
|
1066
1114
|
modelId;
|
|
1067
1115
|
config;
|
|
@@ -1101,7 +1149,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1101
1149
|
type: "unsupported",
|
|
1102
1150
|
feature: "stopSequences"
|
|
1103
1151
|
});
|
|
1104
|
-
if (options.maxOutputTokens != null) warnings.push({
|
|
1152
|
+
if (options.maxOutputTokens != null && !this.config.request.maxOutputTokens) warnings.push({
|
|
1105
1153
|
type: "unsupported",
|
|
1106
1154
|
feature: "maxOutputTokens"
|
|
1107
1155
|
});
|
|
@@ -1109,47 +1157,51 @@ var OpenAICodexLanguageModel = class {
|
|
|
1109
1157
|
type: "unsupported",
|
|
1110
1158
|
feature: "responseFormat"
|
|
1111
1159
|
});
|
|
1112
|
-
const
|
|
1113
|
-
const
|
|
1114
|
-
const
|
|
1115
|
-
|
|
1160
|
+
const { provider, request } = this.config;
|
|
1161
|
+
const callOptions = options.providerOptions?.[provider] ?? {};
|
|
1162
|
+
const tools = prepareResponsesTools({
|
|
1163
|
+
provider,
|
|
1116
1164
|
tools: options.tools,
|
|
1117
1165
|
toolChoice: options.toolChoice,
|
|
1118
|
-
|
|
1166
|
+
inPlaceToolNames: collectInPlaceToolNames(options.prompt, provider)
|
|
1119
1167
|
});
|
|
1120
|
-
const { instructions, input } =
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
grammarToolInputProperties: tools.grammarToolInputProperties,
|
|
1168
|
+
const { instructions, input } = convertToResponsesPrompt(options.prompt, {
|
|
1169
|
+
provider,
|
|
1170
|
+
systemPrompt: request.systemPrompt,
|
|
1171
|
+
grammarToolInputProperties: new Map([...Object.entries(callOptions.grammarToolInputProperties ?? {}), ...tools.grammarToolInputProperties]),
|
|
1124
1172
|
supportsImages: this.config.compat?.supportsImages ?? false
|
|
1125
1173
|
});
|
|
1126
1174
|
warnings.push(...tools.warnings);
|
|
1127
|
-
const
|
|
1175
|
+
const verbosity = callOptions.textVerbosity ?? request.textVerbosity;
|
|
1176
|
+
const text = verbosity ? { verbosity } : {};
|
|
1128
1177
|
if (options.responseFormat?.type === "json" && options.responseFormat.schema !== void 0) text.format = {
|
|
1129
1178
|
type: "json_schema",
|
|
1130
1179
|
strict: true,
|
|
1131
1180
|
schema: options.responseFormat.schema,
|
|
1132
|
-
name: options.responseFormat.name ?? "
|
|
1181
|
+
name: options.responseFormat.name ?? "output_schema"
|
|
1133
1182
|
};
|
|
1134
1183
|
const args = {
|
|
1135
1184
|
model: this.modelId,
|
|
1136
1185
|
store: false,
|
|
1137
|
-
instructions,
|
|
1186
|
+
...instructions !== void 0 && { instructions },
|
|
1138
1187
|
input,
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1188
|
+
...request.toolDefaults ? {
|
|
1189
|
+
tool_choice: tools.toolChoiceValue ?? "auto",
|
|
1190
|
+
parallel_tool_calls: true
|
|
1191
|
+
} : tools.toolChoiceValue !== void 0 && { tool_choice: tools.toolChoiceValue },
|
|
1192
|
+
...(request.encryptedReasoning === "always" || callOptions.reasoningEffort) && { include: ["reasoning.encrypted_content"] },
|
|
1193
|
+
...Object.keys(text).length > 0 && { text }
|
|
1143
1194
|
};
|
|
1144
|
-
if (tools.
|
|
1195
|
+
if (tools.responsesTools) args.tools = tools.responsesTools;
|
|
1145
1196
|
if (options.temperature != null) args.temperature = options.temperature;
|
|
1146
|
-
|
|
1197
|
+
if (request.maxOutputTokens && options.maxOutputTokens != null) args.max_output_tokens = Math.max(options.maxOutputTokens, MIN_OUTPUT_TOKENS);
|
|
1198
|
+
const promptCacheKey = clampPromptCacheKey(this.config.promptCacheKey);
|
|
1147
1199
|
if (promptCacheKey) args.prompt_cache_key = promptCacheKey;
|
|
1148
|
-
const serviceTier =
|
|
1200
|
+
const serviceTier = callOptions.serviceTier ?? this.config.serviceTier;
|
|
1149
1201
|
if (serviceTier) args.service_tier = serviceTier;
|
|
1150
|
-
if (
|
|
1151
|
-
effort:
|
|
1152
|
-
summary:
|
|
1202
|
+
if (callOptions.reasoningEffort) args.reasoning = {
|
|
1203
|
+
effort: callOptions.reasoningEffort,
|
|
1204
|
+
summary: callOptions.reasoningSummary ?? "auto"
|
|
1153
1205
|
};
|
|
1154
1206
|
return {
|
|
1155
1207
|
args,
|
|
@@ -1167,7 +1219,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1167
1219
|
unified: "other",
|
|
1168
1220
|
raw: void 0
|
|
1169
1221
|
};
|
|
1170
|
-
let usage =
|
|
1222
|
+
let usage = convertResponsesUsage(void 0);
|
|
1171
1223
|
let responseId;
|
|
1172
1224
|
let responseModelId;
|
|
1173
1225
|
const reader = stream.getReader();
|
|
@@ -1249,13 +1301,13 @@ var OpenAICodexLanguageModel = class {
|
|
|
1249
1301
|
...args,
|
|
1250
1302
|
stream: true
|
|
1251
1303
|
};
|
|
1252
|
-
const url =
|
|
1304
|
+
const { url, label } = this.config;
|
|
1253
1305
|
const headers = cleanHeaders({
|
|
1254
1306
|
...await this.config.headers(),
|
|
1255
1307
|
...options.headers
|
|
1256
1308
|
});
|
|
1257
1309
|
const bodyJson = JSON.stringify(body);
|
|
1258
|
-
const compressedBody =
|
|
1310
|
+
const compressedBody = this.config.request.compress ? compressRequest(bodyJson) : void 0;
|
|
1259
1311
|
if (compressedBody) headers["content-encoding"] = "zstd";
|
|
1260
1312
|
const response = await (this.config.fetch ?? globalThis.fetch)(url, {
|
|
1261
1313
|
method: "POST",
|
|
@@ -1263,20 +1315,22 @@ var OpenAICodexLanguageModel = class {
|
|
|
1263
1315
|
body: compressedBody ?? bodyJson,
|
|
1264
1316
|
...options.abortSignal !== void 0 && { signal: options.abortSignal }
|
|
1265
1317
|
}).catch((error) => {
|
|
1266
|
-
throw
|
|
1318
|
+
throw responsesFetchError(error, url, body);
|
|
1267
1319
|
});
|
|
1268
|
-
if (!response.ok) throw await
|
|
1320
|
+
if (!response.ok) throw await createResponsesAPICallError({
|
|
1321
|
+
label,
|
|
1269
1322
|
response,
|
|
1270
1323
|
url,
|
|
1271
1324
|
requestBodyValues: body
|
|
1272
1325
|
});
|
|
1273
|
-
if (!response.body) throw new Error(
|
|
1326
|
+
if (!response.body) throw new Error(`${label} response has no body`);
|
|
1274
1327
|
const responseHeaders = {};
|
|
1275
1328
|
response.headers.forEach((value, key) => {
|
|
1276
1329
|
responseHeaders[key] = value;
|
|
1277
1330
|
});
|
|
1278
1331
|
return {
|
|
1279
|
-
stream:
|
|
1332
|
+
stream: parseResponsesSSEStream(response.body).pipeThrough(this.createTransformStream(warnings, options.includeRawChunks ?? false, grammarToolInputProperties, {
|
|
1333
|
+
label,
|
|
1280
1334
|
url,
|
|
1281
1335
|
requestBodyValues: body,
|
|
1282
1336
|
responseHeaders
|
|
@@ -1286,6 +1340,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1286
1340
|
};
|
|
1287
1341
|
}
|
|
1288
1342
|
createTransformStream(warnings, includeRawChunks, grammarToolInputProperties, request) {
|
|
1343
|
+
const { provider } = this.config;
|
|
1289
1344
|
let finishReason = {
|
|
1290
1345
|
unified: "other",
|
|
1291
1346
|
raw: void 0
|
|
@@ -1294,16 +1349,16 @@ var OpenAICodexLanguageModel = class {
|
|
|
1294
1349
|
let hasToolCalls = false;
|
|
1295
1350
|
let finished = false;
|
|
1296
1351
|
let servedServiceTier;
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1352
|
+
const slots = /* @__PURE__ */ new Map();
|
|
1353
|
+
const slotKey = (event, item) => typeof event.output_index === "number" ? `#${event.output_index}` : asString(event.item_id) ?? asString(item?.id);
|
|
1299
1354
|
const finish = (controller) => {
|
|
1300
1355
|
if (finished) return;
|
|
1301
1356
|
finished = true;
|
|
1302
1357
|
controller.enqueue({
|
|
1303
1358
|
type: "finish",
|
|
1304
1359
|
finishReason,
|
|
1305
|
-
usage:
|
|
1306
|
-
...servedServiceTier === void 0 ? {} : { providerMetadata: {
|
|
1360
|
+
usage: convertResponsesUsage(usage),
|
|
1361
|
+
...servedServiceTier === void 0 ? {} : { providerMetadata: { [provider]: { serviceTier: servedServiceTier } } }
|
|
1307
1362
|
});
|
|
1308
1363
|
};
|
|
1309
1364
|
const fail = (controller, error) => {
|
|
@@ -1315,100 +1370,114 @@ var OpenAICodexLanguageModel = class {
|
|
|
1315
1370
|
});
|
|
1316
1371
|
controller.terminate();
|
|
1317
1372
|
};
|
|
1318
|
-
const
|
|
1373
|
+
const startSlot = (key, item, controller) => {
|
|
1319
1374
|
const itemType = asString(item.type);
|
|
1320
1375
|
const itemId = asString(item.id);
|
|
1321
1376
|
if (!itemType || !itemId) return;
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1377
|
+
let slot;
|
|
1378
|
+
if (itemType === "message") {
|
|
1379
|
+
slot = {
|
|
1380
|
+
kind: "text",
|
|
1381
|
+
id: itemId
|
|
1382
|
+
};
|
|
1383
|
+
controller.enqueue({
|
|
1384
|
+
type: "text-start",
|
|
1385
|
+
id: itemId
|
|
1386
|
+
});
|
|
1387
|
+
} else if (itemType === "reasoning") {
|
|
1388
|
+
slot = {
|
|
1389
|
+
kind: "reasoning",
|
|
1390
|
+
id: itemId
|
|
1391
|
+
};
|
|
1392
|
+
controller.enqueue({
|
|
1393
|
+
type: "reasoning-start",
|
|
1394
|
+
id: itemId
|
|
1395
|
+
});
|
|
1396
|
+
} else if (itemType === "function_call") {
|
|
1397
|
+
const toolName = asString(item.name) ?? "";
|
|
1398
|
+
slot = {
|
|
1399
|
+
kind: "function",
|
|
1400
|
+
toolCallId: joinToolCallId(asString(item.call_id) ?? itemId, itemId),
|
|
1401
|
+
toolName
|
|
1402
|
+
};
|
|
1333
1403
|
hasToolCalls = true;
|
|
1334
1404
|
controller.enqueue({
|
|
1335
1405
|
type: "tool-input-start",
|
|
1336
|
-
id: toolCallId,
|
|
1337
|
-
toolName
|
|
1406
|
+
id: slot.toolCallId,
|
|
1407
|
+
toolName
|
|
1338
1408
|
});
|
|
1339
1409
|
} else if (itemType === "custom_tool_call") {
|
|
1340
1410
|
const toolName = asString(item.name) ?? "";
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
toolCallId,
|
|
1411
|
+
slot = {
|
|
1412
|
+
kind: "custom",
|
|
1413
|
+
toolCallId: joinToolCallId(asString(item.call_id) ?? itemId, itemId),
|
|
1345
1414
|
toolName,
|
|
1346
|
-
inputProperty,
|
|
1415
|
+
inputProperty: grammarToolInputProperties.get(toolName) ?? "input",
|
|
1347
1416
|
buffer: {
|
|
1348
1417
|
input: "",
|
|
1349
1418
|
started: false,
|
|
1350
1419
|
closed: false
|
|
1351
1420
|
}
|
|
1352
|
-
}
|
|
1421
|
+
};
|
|
1353
1422
|
hasToolCalls = true;
|
|
1354
1423
|
controller.enqueue({
|
|
1355
1424
|
type: "tool-input-start",
|
|
1356
|
-
id: toolCallId,
|
|
1425
|
+
id: slot.toolCallId,
|
|
1357
1426
|
toolName
|
|
1358
1427
|
});
|
|
1359
1428
|
}
|
|
1429
|
+
if (slot) slots.set(key, slot);
|
|
1430
|
+
return slot;
|
|
1360
1431
|
};
|
|
1361
|
-
const
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1432
|
+
const endSlot = (key, item, controller) => {
|
|
1433
|
+
const slot = slots.get(key) ?? startSlot(key, item, controller);
|
|
1434
|
+
if (!slot) return;
|
|
1435
|
+
slots.delete(key);
|
|
1436
|
+
const namespace = asString(item.namespace);
|
|
1437
|
+
const namespaceMetadata = namespace ? { providerMetadata: { [provider]: { namespace } } } : {};
|
|
1438
|
+
if (slot.kind === "text") {
|
|
1439
|
+
const messageId = asString(item.id) ?? slot.id;
|
|
1440
|
+
controller.enqueue({
|
|
1441
|
+
type: "text-end",
|
|
1442
|
+
id: slot.id,
|
|
1443
|
+
providerMetadata: { [provider]: { messageId } }
|
|
1444
|
+
});
|
|
1445
|
+
} else if (slot.kind === "reasoning") controller.enqueue({
|
|
1371
1446
|
type: "reasoning-end",
|
|
1372
|
-
id:
|
|
1373
|
-
providerMetadata: {
|
|
1447
|
+
id: slot.id,
|
|
1448
|
+
providerMetadata: { [provider]: { reasoningItem: JSON.stringify(item) } }
|
|
1374
1449
|
});
|
|
1375
|
-
else if (
|
|
1376
|
-
const toolCallId = toolCallIdsByItemId.get(itemId) ?? joinToolCallId(asString(item.call_id) ?? itemId, itemId);
|
|
1377
|
-
hasToolCalls = true;
|
|
1450
|
+
else if (slot.kind === "function") {
|
|
1378
1451
|
controller.enqueue({
|
|
1379
1452
|
type: "tool-input-end",
|
|
1380
|
-
id: toolCallId
|
|
1453
|
+
id: slot.toolCallId
|
|
1381
1454
|
});
|
|
1382
1455
|
controller.enqueue({
|
|
1383
1456
|
type: "tool-call",
|
|
1384
|
-
toolCallId,
|
|
1385
|
-
toolName: asString(item.name) ??
|
|
1457
|
+
toolCallId: slot.toolCallId,
|
|
1458
|
+
toolName: asString(item.name) ?? slot.toolName,
|
|
1386
1459
|
input: asString(item.arguments) ?? "",
|
|
1387
|
-
...
|
|
1460
|
+
...namespaceMetadata
|
|
1388
1461
|
});
|
|
1389
|
-
} else
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
const input = asString(item.input) ?? state.buffer.input;
|
|
1393
|
-
const delta = appendOpenAICodexGrammarInputJsonDelta(state.buffer, state.inputProperty, input, true);
|
|
1462
|
+
} else {
|
|
1463
|
+
const input = asString(item.input) ?? slot.buffer.input;
|
|
1464
|
+
const delta = appendGrammarInputJsonDelta(slot.buffer, slot.inputProperty, input, true);
|
|
1394
1465
|
if (delta) controller.enqueue({
|
|
1395
1466
|
type: "tool-input-delta",
|
|
1396
|
-
id:
|
|
1467
|
+
id: slot.toolCallId,
|
|
1397
1468
|
delta
|
|
1398
1469
|
});
|
|
1399
|
-
hasToolCalls = true;
|
|
1400
1470
|
controller.enqueue({
|
|
1401
1471
|
type: "tool-input-end",
|
|
1402
|
-
id:
|
|
1472
|
+
id: slot.toolCallId
|
|
1403
1473
|
});
|
|
1404
1474
|
controller.enqueue({
|
|
1405
1475
|
type: "tool-call",
|
|
1406
|
-
toolCallId:
|
|
1407
|
-
toolName:
|
|
1408
|
-
input: JSON.stringify({ [
|
|
1409
|
-
...
|
|
1476
|
+
toolCallId: slot.toolCallId,
|
|
1477
|
+
toolName: slot.toolName,
|
|
1478
|
+
input: JSON.stringify({ [slot.inputProperty]: input }),
|
|
1479
|
+
...namespaceMetadata
|
|
1410
1480
|
});
|
|
1411
|
-
customToolInputsByItemId.delete(itemId);
|
|
1412
1481
|
}
|
|
1413
1482
|
};
|
|
1414
1483
|
return new TransformStream({
|
|
@@ -1439,70 +1508,60 @@ var OpenAICodexLanguageModel = class {
|
|
|
1439
1508
|
}
|
|
1440
1509
|
case "response.output_item.added": {
|
|
1441
1510
|
const item = asRecord(event.item);
|
|
1442
|
-
|
|
1511
|
+
const key = item ? slotKey(event, item) : void 0;
|
|
1512
|
+
if (item && key) startSlot(key, item, controller);
|
|
1443
1513
|
break;
|
|
1444
1514
|
}
|
|
1445
1515
|
case "response.output_text.delta": {
|
|
1446
|
-
const
|
|
1516
|
+
const slot = slots.get(slotKey(event) ?? "");
|
|
1447
1517
|
const delta = asString(event.delta);
|
|
1448
|
-
if (
|
|
1518
|
+
if (slot?.kind === "text" && delta) controller.enqueue({
|
|
1449
1519
|
type: "text-delta",
|
|
1450
|
-
id:
|
|
1520
|
+
id: slot.id,
|
|
1451
1521
|
delta
|
|
1452
1522
|
});
|
|
1453
1523
|
break;
|
|
1454
1524
|
}
|
|
1455
1525
|
case "response.reasoning_text.delta":
|
|
1456
1526
|
case "response.reasoning_summary_text.delta": {
|
|
1457
|
-
const
|
|
1527
|
+
const slot = slots.get(slotKey(event) ?? "");
|
|
1458
1528
|
const delta = asString(event.delta);
|
|
1459
|
-
if (
|
|
1529
|
+
if (slot?.kind === "reasoning" && delta) controller.enqueue({
|
|
1460
1530
|
type: "reasoning-delta",
|
|
1461
|
-
id:
|
|
1531
|
+
id: slot.id,
|
|
1462
1532
|
delta
|
|
1463
1533
|
});
|
|
1464
1534
|
break;
|
|
1465
1535
|
}
|
|
1466
1536
|
case "response.function_call_arguments.delta": {
|
|
1467
|
-
const
|
|
1537
|
+
const slot = slots.get(slotKey(event) ?? "");
|
|
1468
1538
|
const delta = asString(event.delta);
|
|
1469
|
-
|
|
1470
|
-
if (toolCallId && delta) controller.enqueue({
|
|
1539
|
+
if (slot?.kind === "function" && delta) controller.enqueue({
|
|
1471
1540
|
type: "tool-input-delta",
|
|
1472
|
-
id: toolCallId,
|
|
1541
|
+
id: slot.toolCallId,
|
|
1473
1542
|
delta
|
|
1474
1543
|
});
|
|
1475
1544
|
break;
|
|
1476
1545
|
}
|
|
1477
|
-
case "response.custom_tool_call_input.delta":
|
|
1478
|
-
const itemId = asString(event.item_id);
|
|
1479
|
-
const delta = asString(event.delta);
|
|
1480
|
-
const state = itemId ? customToolInputsByItemId.get(itemId) : void 0;
|
|
1481
|
-
if (!state || delta === void 0) break;
|
|
1482
|
-
const jsonDelta = appendOpenAICodexGrammarInputJsonDelta(state.buffer, state.inputProperty, state.buffer.input + delta, false);
|
|
1483
|
-
if (jsonDelta) controller.enqueue({
|
|
1484
|
-
type: "tool-input-delta",
|
|
1485
|
-
id: state.toolCallId,
|
|
1486
|
-
delta: jsonDelta
|
|
1487
|
-
});
|
|
1488
|
-
break;
|
|
1489
|
-
}
|
|
1546
|
+
case "response.custom_tool_call_input.delta":
|
|
1490
1547
|
case "response.custom_tool_call_input.done": {
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1548
|
+
const slot = slots.get(slotKey(event) ?? "");
|
|
1549
|
+
if (slot?.kind !== "custom") break;
|
|
1550
|
+
const done = type === "response.custom_tool_call_input.done";
|
|
1551
|
+
const input = done ? asString(event.input) : slot.buffer.input + (asString(event.delta) ?? "");
|
|
1552
|
+
if (input === void 0) break;
|
|
1553
|
+
const jsonDelta = appendGrammarInputJsonDelta(slot.buffer, slot.inputProperty, input, done);
|
|
1496
1554
|
if (jsonDelta) controller.enqueue({
|
|
1497
1555
|
type: "tool-input-delta",
|
|
1498
|
-
id:
|
|
1556
|
+
id: slot.toolCallId,
|
|
1499
1557
|
delta: jsonDelta
|
|
1500
1558
|
});
|
|
1501
1559
|
break;
|
|
1502
1560
|
}
|
|
1503
1561
|
case "response.output_item.done": {
|
|
1504
1562
|
const item = asRecord(event.item);
|
|
1505
|
-
|
|
1563
|
+
const key = item ? slotKey(event, item) : void 0;
|
|
1564
|
+
if (item && key) endSlot(key, item, controller);
|
|
1506
1565
|
break;
|
|
1507
1566
|
}
|
|
1508
1567
|
case "response.completed":
|
|
@@ -1512,7 +1571,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1512
1571
|
servedServiceTier = asString(response?.service_tier) ?? servedServiceTier;
|
|
1513
1572
|
const status = asString(response?.status) ?? (type === "response.incomplete" ? "incomplete" : "completed");
|
|
1514
1573
|
const incompleteReason = asString(asRecord(response?.incomplete_details)?.reason);
|
|
1515
|
-
finishReason =
|
|
1574
|
+
finishReason = mapResponsesFinishReason(status, hasToolCalls, incompleteReason);
|
|
1516
1575
|
finish(controller);
|
|
1517
1576
|
controller.terminate();
|
|
1518
1577
|
break;
|
|
@@ -1523,8 +1582,8 @@ var OpenAICodexLanguageModel = class {
|
|
|
1523
1582
|
unified: "error",
|
|
1524
1583
|
raw: "failed"
|
|
1525
1584
|
};
|
|
1526
|
-
fail(controller,
|
|
1527
|
-
error: error ?? { message:
|
|
1585
|
+
fail(controller, createResponsesStreamError({
|
|
1586
|
+
error: error ?? { message: `${request.label} response failed` },
|
|
1528
1587
|
...request
|
|
1529
1588
|
}));
|
|
1530
1589
|
break;
|
|
@@ -1534,7 +1593,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1534
1593
|
unified: "error",
|
|
1535
1594
|
raw: asString(event.code) ?? "error"
|
|
1536
1595
|
};
|
|
1537
|
-
fail(controller,
|
|
1596
|
+
fail(controller, createResponsesStreamError({
|
|
1538
1597
|
error: event,
|
|
1539
1598
|
...request
|
|
1540
1599
|
}));
|
|
@@ -1545,7 +1604,7 @@ var OpenAICodexLanguageModel = class {
|
|
|
1545
1604
|
finished = true;
|
|
1546
1605
|
controller.enqueue({
|
|
1547
1606
|
type: "error",
|
|
1548
|
-
error:
|
|
1607
|
+
error: createResponsesPrematureCloseError(request)
|
|
1549
1608
|
});
|
|
1550
1609
|
}
|
|
1551
1610
|
}
|
|
@@ -1553,80 +1612,6 @@ var OpenAICodexLanguageModel = class {
|
|
|
1553
1612
|
}
|
|
1554
1613
|
};
|
|
1555
1614
|
//#endregion
|
|
1556
|
-
|
|
1557
|
-
const OPENAI_CODEX_API_KEY_ENV = "OPENAI_CODEX_API_KEY";
|
|
1558
|
-
const DEFAULT_ORIGINATOR = "codework";
|
|
1559
|
-
async function resolveApiKey(settings) {
|
|
1560
|
-
const apiKey = typeof settings.apiKey === "function" ? await settings.apiKey() : settings.apiKey ?? (typeof process === "undefined" ? void 0 : process.env["OPENAI_CODEX_API_KEY"]);
|
|
1561
|
-
if (!apiKey) throw new LoadAPIKeyError({ message: `OpenAI Codex API key is missing. Pass it using the 'apiKey' option or the ${OPENAI_CODEX_API_KEY_ENV} environment variable.` });
|
|
1562
|
-
return apiKey;
|
|
1563
|
-
}
|
|
1564
|
-
function resolveAccountId(settings, apiKey) {
|
|
1565
|
-
const accountId = settings.accountId ?? getOpenAICodexAccountId(apiKey);
|
|
1566
|
-
if (!accountId) throw new LoadAPIKeyError({ message: "Failed to extract the ChatGPT account id from the OpenAI Codex access token. Provide it using the 'accountId' option or pass a valid ChatGPT OAuth JWT as the API key." });
|
|
1567
|
-
return accountId;
|
|
1568
|
-
}
|
|
1569
|
-
function createOpenAICodex(options = {}) {
|
|
1570
|
-
const baseURL = options.baseURL?.replace(/\/+$/, "") || "https://chatgpt.com/backend-api";
|
|
1571
|
-
const sessionId = clampOpenAICodexPromptCacheKey(options.sessionId);
|
|
1572
|
-
const getHeaders = async () => {
|
|
1573
|
-
const apiKey = await resolveApiKey(options);
|
|
1574
|
-
const accountId = resolveAccountId(options, apiKey);
|
|
1575
|
-
return {
|
|
1576
|
-
Authorization: `Bearer ${apiKey}`,
|
|
1577
|
-
"chatgpt-account-id": accountId,
|
|
1578
|
-
"OpenAI-Beta": "responses=experimental",
|
|
1579
|
-
originator: options.originator ?? DEFAULT_ORIGINATOR,
|
|
1580
|
-
accept: "text/event-stream",
|
|
1581
|
-
"content-type": "application/json",
|
|
1582
|
-
...sessionId ? {
|
|
1583
|
-
"session-id": sessionId,
|
|
1584
|
-
"x-client-request-id": sessionId
|
|
1585
|
-
} : {},
|
|
1586
|
-
...options.headers
|
|
1587
|
-
};
|
|
1588
|
-
};
|
|
1589
|
-
const createLanguageModel = (modelId) => new OpenAICodexLanguageModel(modelId, {
|
|
1590
|
-
provider: "openai-codex",
|
|
1591
|
-
baseURL,
|
|
1592
|
-
headers: getHeaders,
|
|
1593
|
-
...options.fetch !== void 0 && { fetch: options.fetch },
|
|
1594
|
-
...sessionId !== void 0 && { sessionId },
|
|
1595
|
-
...options.serviceTier !== void 0 && { serviceTier: options.serviceTier },
|
|
1596
|
-
...options.compat !== void 0 && { compat: options.compat }
|
|
1597
|
-
});
|
|
1598
|
-
const provider = function(modelId) {
|
|
1599
|
-
if (new.target) throw new Error("openAI codex model function cannot be called with the new keyword.");
|
|
1600
|
-
return createLanguageModel(modelId);
|
|
1601
|
-
};
|
|
1602
|
-
provider.specificationVersion = "v3";
|
|
1603
|
-
provider.languageModel = createLanguageModel;
|
|
1604
|
-
provider.responses = createLanguageModel;
|
|
1605
|
-
provider.embeddingModel = (modelId) => {
|
|
1606
|
-
throw new NoSuchModelError({
|
|
1607
|
-
modelId,
|
|
1608
|
-
modelType: "embeddingModel"
|
|
1609
|
-
});
|
|
1610
|
-
};
|
|
1611
|
-
provider.textEmbeddingModel = (modelId) => {
|
|
1612
|
-
throw new NoSuchModelError({
|
|
1613
|
-
modelId,
|
|
1614
|
-
modelType: "embeddingModel"
|
|
1615
|
-
});
|
|
1616
|
-
};
|
|
1617
|
-
provider.imageModel = (modelId) => {
|
|
1618
|
-
throw new NoSuchModelError({
|
|
1619
|
-
modelId,
|
|
1620
|
-
modelType: "imageModel"
|
|
1621
|
-
});
|
|
1622
|
-
};
|
|
1623
|
-
return provider;
|
|
1624
|
-
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Default provider instance using `OPENAI_CODEX_API_KEY`.
|
|
1627
|
-
*/
|
|
1628
|
-
const openaiCodex = createOpenAICodex();
|
|
1629
|
-
//#endregion
|
|
1630
|
-
export { ToolCallSchema as C, transformMessages as E, AssistantMessageSchema as S, message_exports as T, appendOpenAICodexGrammarInputJsonDelta as _, OpenAICodexLanguageModel as a, resolveOpenAICodexDeferredToolsMode as b, convertOpenAICodexUsage as c, convertToOpenAICodexPrompt as d, joinToolCallId as f, shortHash as g, openAICodexErrorMessage as h, OPENAI_CODEX_DEFAULT_BASE_URL as i, mapOpenAICodexFinishReason as l, createOpenAICodexAPICallError as m, createOpenAICodex as n, clampOpenAICodexPromptCacheKey as o, splitToolCallId as p, openaiCodex as r, resolveOpenAICodexUrl as s, OPENAI_CODEX_API_KEY_ENV as t, collectOpenAICodexDeferredToolNames as u, openAICodexTools as v, createAssistantMessage as w, resolveOpenAICodexToolConstraint as x, prepareOpenAICodexTools as y };
|
|
1615
|
+
export { AssistantMessageSchema as a, message_exports as c, resolveToolGrammar as i, omitImages as l, clampPromptCacheKey as n, ToolCallSchema as o, shortHash as r, createAssistantMessage as s, ResponsesLanguageModel as t, transformMessages as u };
|
|
1631
1616
|
|
|
1632
|
-
//# sourceMappingURL=
|
|
1617
|
+
//# sourceMappingURL=model-av44O6GQ.mjs.map
|