@yourgpt/llm-sdk 2.6.0-beta.3 → 2.6.0
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/LICENSE +21 -0
- package/README.md +46 -10
- package/dist/adapters/index.d.mts +11 -13
- package/dist/adapters/index.d.ts +11 -13
- package/dist/adapters/index.js +327 -100
- package/dist/adapters/index.mjs +327 -100
- package/dist/audio-K-Z3-Bce.d.mts +191 -0
- package/dist/audio-K-Z3-Bce.d.ts +191 -0
- package/dist/{base-BICaQaRS.d.mts → base-6LzczuCg.d.ts} +8 -1
- package/dist/{base-CpRPB8u8.d.ts → base-DySbTP8C.d.mts} +8 -1
- package/dist/decisions-CJzOt87t.d.mts +137 -0
- package/dist/decisions-CJzOt87t.d.ts +137 -0
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/http-BQxUT5A9.d.mts +9 -0
- package/dist/http-BQxUT5A9.d.ts +9 -0
- package/dist/index.d.mts +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/index.js +599 -195
- package/dist/index.mjs +596 -196
- package/dist/providers/anthropic/index.d.mts +7 -4
- package/dist/providers/anthropic/index.d.ts +7 -4
- package/dist/providers/anthropic/index.js +383 -102
- package/dist/providers/anthropic/index.mjs +383 -102
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/cloudflare/index.d.mts +11 -0
- package/dist/providers/cloudflare/index.d.ts +11 -0
- package/dist/providers/cloudflare/index.js +743 -0
- package/dist/providers/cloudflare/index.mjs +741 -0
- package/dist/providers/fireworks/index.d.mts +3 -3
- package/dist/providers/fireworks/index.d.ts +3 -3
- package/dist/providers/fireworks/index.js +108 -59
- package/dist/providers/fireworks/index.mjs +108 -59
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +108 -59
- package/dist/providers/google/index.mjs +108 -59
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/openai/index.d.mts +38 -6
- package/dist/providers/openai/index.d.ts +38 -6
- package/dist/providers/openai/index.js +1378 -84
- package/dist/providers/openai/index.mjs +1376 -85
- package/dist/providers/openrouter/index.d.mts +21 -4
- package/dist/providers/openrouter/index.d.ts +21 -4
- package/dist/providers/openrouter/index.js +967 -130
- package/dist/providers/openrouter/index.mjs +967 -131
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +108 -59
- package/dist/providers/togetherai/index.mjs +108 -59
- package/dist/providers/typesafe/index.d.mts +8 -0
- package/dist/providers/typesafe/index.d.ts +8 -0
- package/dist/providers/typesafe/index.js +735 -0
- package/dist/providers/typesafe/index.mjs +733 -0
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +108 -59
- package/dist/providers/xai/index.mjs +108 -59
- package/dist/{types-DCFqkJAy.d.ts → types-B0y6VZSQ.d.ts} +1 -1
- package/dist/{types-DHQEMFHA.d.mts → types-BXQMtaCX.d.ts} +17 -3
- package/dist/{types-C3RgRbEC.d.mts → types-BY6BVhFg.d.mts} +1 -1
- package/dist/{types-Dikj3En4.d.ts → types-C7_qVSSd.d.mts} +17 -3
- package/dist/{types-Dg1Bcg1k.d.mts → types-D7lzMMLu.d.mts} +13 -1
- package/dist/{types-Dg1Bcg1k.d.ts → types-D7lzMMLu.d.ts} +13 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/docs/decisions.md +174 -0
- package/docs/media.md +201 -0
- package/docs/multimodal-and-audio.md +9 -2
- package/package.json +34 -12
- package/dist/audio-BBSwnjo8.d.mts +0 -92
- package/dist/audio-BBSwnjo8.d.ts +0 -92
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D7lzMMLu.mjs';
|
|
2
|
+
import { A as AIProvider } from '../../types-C7_qVSSd.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-DySbTP8C.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Fireworks Provider
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D7lzMMLu.js';
|
|
2
|
+
import { A as AIProvider } from '../../types-BXQMtaCX.js';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-6LzczuCg.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Fireworks Provider
|
|
@@ -113,6 +113,19 @@ function capabilities(model) {
|
|
|
113
113
|
const supportsNone = major === 5 && minor >= 1 && !chat || /^gpt-6-(?:sol|luna)(?:-\d{4}-\d{2}-\d{2})?$/i.test(model);
|
|
114
114
|
return { major, minor, reasoning, supportsNone };
|
|
115
115
|
}
|
|
116
|
+
function filterOpenAIResponseInclude(model, include, options = {}) {
|
|
117
|
+
const c = capabilities(model);
|
|
118
|
+
let result = include;
|
|
119
|
+
if (options.parameterPolicy !== "passthrough" && c.reasoning && !(options.reasoningEffort === "none" && c.supportsNone) && include.includes("message.output_text.logprobs")) {
|
|
120
|
+
result = include.filter(
|
|
121
|
+
(value) => value !== "message.output_text.logprobs"
|
|
122
|
+
);
|
|
123
|
+
(options.onWarning ?? console.warn)(
|
|
124
|
+
`[llm-sdk] ${model}: omitted message.output_text.logprobs because reasoning is enabled.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return result.length ? result : void 0;
|
|
128
|
+
}
|
|
116
129
|
function requiresOpenAIResponses(model, baseUrl, options = {}) {
|
|
117
130
|
if (options.parameterPolicy === "passthrough") return false;
|
|
118
131
|
const c = capabilities(model);
|
|
@@ -274,6 +287,7 @@ function toOpenAIResponseFormat(rf) {
|
|
|
274
287
|
};
|
|
275
288
|
}
|
|
276
289
|
function toOpenAIResponsesTextFormat(rf) {
|
|
290
|
+
if (rf?.type === "json_object") return { type: "json_object" };
|
|
277
291
|
if (!rf || rf.type !== "json_schema") return void 0;
|
|
278
292
|
return {
|
|
279
293
|
type: "json_schema",
|
|
@@ -588,6 +602,63 @@ function formatMessages(messages) {
|
|
|
588
602
|
});
|
|
589
603
|
}
|
|
590
604
|
|
|
605
|
+
// src/core/provider-error.ts
|
|
606
|
+
function invalidProviderResponse(message) {
|
|
607
|
+
return Object.assign(new Error(message), {
|
|
608
|
+
name: "InvalidProviderResponseError",
|
|
609
|
+
status: 502,
|
|
610
|
+
code: "INVALID_PROVIDER_RESPONSE"
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
function providerErrorEvent(error, code) {
|
|
614
|
+
const details = error ?? {};
|
|
615
|
+
const event = {
|
|
616
|
+
type: "error",
|
|
617
|
+
message: error instanceof Error ? error.message : String(error),
|
|
618
|
+
code,
|
|
619
|
+
...typeof details.status === "number" ? { status: details.status } : {},
|
|
620
|
+
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
621
|
+
...typeof details.param === "string" ? { param: details.param } : {},
|
|
622
|
+
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
623
|
+
};
|
|
624
|
+
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
625
|
+
return event;
|
|
626
|
+
}
|
|
627
|
+
function throwIfAborted(signal) {
|
|
628
|
+
if (!signal?.aborted) return;
|
|
629
|
+
const error = new Error("The operation was aborted");
|
|
630
|
+
error.name = "AbortError";
|
|
631
|
+
throw error;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/core/tool-validation.ts
|
|
635
|
+
function parseToolArguments(value) {
|
|
636
|
+
let args = value;
|
|
637
|
+
if (typeof value === "string") {
|
|
638
|
+
try {
|
|
639
|
+
args = JSON.parse(value || "{}");
|
|
640
|
+
} catch {
|
|
641
|
+
throw invalidProviderResponse("Tool arguments are not valid JSON");
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
645
|
+
throw invalidProviderResponse("Tool arguments must be a JSON object");
|
|
646
|
+
return args;
|
|
647
|
+
}
|
|
648
|
+
function validateToolCalls(calls) {
|
|
649
|
+
const ids = /* @__PURE__ */ new Set();
|
|
650
|
+
for (const call of calls) {
|
|
651
|
+
if (!call || typeof call.id !== "string" || !call.id || typeof call.name !== "string" || !call.name || ids.has(call.id))
|
|
652
|
+
throw invalidProviderResponse(
|
|
653
|
+
"Tool calls have missing or duplicate identities"
|
|
654
|
+
);
|
|
655
|
+
ids.add(call.id);
|
|
656
|
+
if (typeof call.args === "string")
|
|
657
|
+
throw invalidProviderResponse("Parsed tool arguments must be an object");
|
|
658
|
+
parseToolArguments(call.args);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
591
662
|
// src/core/openai-responses.ts
|
|
592
663
|
function resolveOpenAITransport(defaults, overrides) {
|
|
593
664
|
return {
|
|
@@ -694,35 +765,6 @@ function getResponseReplay(metadata) {
|
|
|
694
765
|
return responseReplayMetadata(metadata)?.openai?.response?.output;
|
|
695
766
|
}
|
|
696
767
|
|
|
697
|
-
// src/core/provider-error.ts
|
|
698
|
-
function invalidProviderResponse(message) {
|
|
699
|
-
return Object.assign(new Error(message), {
|
|
700
|
-
name: "InvalidProviderResponseError",
|
|
701
|
-
status: 502,
|
|
702
|
-
code: "INVALID_PROVIDER_RESPONSE"
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
function providerErrorEvent(error, code) {
|
|
706
|
-
const details = error ?? {};
|
|
707
|
-
const event = {
|
|
708
|
-
type: "error",
|
|
709
|
-
message: error instanceof Error ? error.message : String(error),
|
|
710
|
-
code,
|
|
711
|
-
...typeof details.status === "number" ? { status: details.status } : {},
|
|
712
|
-
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
713
|
-
...typeof details.param === "string" ? { param: details.param } : {},
|
|
714
|
-
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
715
|
-
};
|
|
716
|
-
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
717
|
-
return event;
|
|
718
|
-
}
|
|
719
|
-
function throwIfAborted(signal) {
|
|
720
|
-
if (!signal?.aborted) return;
|
|
721
|
-
const error = new Error("The operation was aborted");
|
|
722
|
-
error.name = "AbortError";
|
|
723
|
-
throw error;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
768
|
// src/core/utils.ts
|
|
727
769
|
function generateId(prefix = "id") {
|
|
728
770
|
return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
@@ -730,9 +772,6 @@ function generateId(prefix = "id") {
|
|
|
730
772
|
function generateMessageId() {
|
|
731
773
|
return generateId("msg");
|
|
732
774
|
}
|
|
733
|
-
function generateToolCallId() {
|
|
734
|
-
return generateId("call");
|
|
735
|
-
}
|
|
736
775
|
|
|
737
776
|
// src/adapters/openai.ts
|
|
738
777
|
var OpenAIAdapter = class _OpenAIAdapter {
|
|
@@ -756,6 +795,8 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
756
795
|
apiKey: this.config.apiKey,
|
|
757
796
|
baseURL: this.config.baseUrl,
|
|
758
797
|
organization: this.config.organization,
|
|
798
|
+
project: this.config.project,
|
|
799
|
+
timeout: this.config.timeout,
|
|
759
800
|
defaultHeaders: this.config.headers
|
|
760
801
|
});
|
|
761
802
|
}
|
|
@@ -1037,6 +1078,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1037
1078
|
request.config?.responseFormat
|
|
1038
1079
|
);
|
|
1039
1080
|
const modelIdForPayload = request.config?.model || this.model;
|
|
1081
|
+
const include = filterOpenAIResponseInclude(
|
|
1082
|
+
modelIdForPayload,
|
|
1083
|
+
[
|
|
1084
|
+
.../* @__PURE__ */ new Set([
|
|
1085
|
+
...options?.include ?? [],
|
|
1086
|
+
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1087
|
+
])
|
|
1088
|
+
],
|
|
1089
|
+
this.parameterOptions(request)
|
|
1090
|
+
);
|
|
1040
1091
|
const payload = {
|
|
1041
1092
|
model: modelIdForPayload,
|
|
1042
1093
|
instructions: request.systemPrompt,
|
|
@@ -1060,14 +1111,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1060
1111
|
...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {},
|
|
1061
1112
|
...options?.promptCacheOptions !== void 0 ? { prompt_cache_options: options.promptCacheOptions } : {},
|
|
1062
1113
|
...options?.promptCacheRetention !== void 0 ? { prompt_cache_retention: options.promptCacheRetention } : {},
|
|
1063
|
-
...
|
|
1064
|
-
include: [
|
|
1065
|
-
.../* @__PURE__ */ new Set([
|
|
1066
|
-
...options?.include ?? [],
|
|
1067
|
-
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1068
|
-
])
|
|
1069
|
-
]
|
|
1070
|
-
} : {},
|
|
1114
|
+
...include ? { include } : {},
|
|
1071
1115
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
1072
1116
|
stream
|
|
1073
1117
|
};
|
|
@@ -1438,15 +1482,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1438
1482
|
}
|
|
1439
1483
|
throwIfAborted(request.signal);
|
|
1440
1484
|
if (!finishReason)
|
|
1441
|
-
throw
|
|
1485
|
+
throw invalidProviderResponse(
|
|
1486
|
+
"OpenAI stream ended without a finish reason"
|
|
1487
|
+
);
|
|
1442
1488
|
if (toolCalls.size && !["tool_calls", "function_call"].includes(finishReason)) {
|
|
1443
|
-
throw
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
if (!call.id || !call.name)
|
|
1447
|
-
throw new Error("OpenAI stream contains an incomplete tool call");
|
|
1448
|
-
JSON.parse(call.arguments || "{}");
|
|
1489
|
+
throw invalidProviderResponse(
|
|
1490
|
+
"OpenAI stream ended with incomplete tool calls"
|
|
1491
|
+
);
|
|
1449
1492
|
}
|
|
1493
|
+
validateToolCalls(
|
|
1494
|
+
[...toolCalls.values()].map((call) => ({
|
|
1495
|
+
...call,
|
|
1496
|
+
args: parseToolArguments(call.arguments)
|
|
1497
|
+
}))
|
|
1498
|
+
);
|
|
1450
1499
|
for (const call of toolCalls.values()) {
|
|
1451
1500
|
yield {
|
|
1452
1501
|
type: "action:start",
|
|
@@ -1530,20 +1579,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1530
1579
|
logProviderPayload("openai", "response payload", response, request.debug);
|
|
1531
1580
|
const choice = response.choices?.[0];
|
|
1532
1581
|
const message = choice?.message;
|
|
1582
|
+
const toolCalls = (message?.tool_calls ?? []).map((toolCall) => ({
|
|
1583
|
+
id: toolCall.id,
|
|
1584
|
+
name: toolCall.function?.name,
|
|
1585
|
+
args: parseToolArguments(toolCall.function?.arguments ?? "{}"),
|
|
1586
|
+
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1587
|
+
}));
|
|
1588
|
+
validateToolCalls(toolCalls);
|
|
1589
|
+
if (toolCalls.length && choice?.finish_reason && !["tool_calls", "function_call"].includes(choice.finish_reason))
|
|
1590
|
+
throw invalidProviderResponse(
|
|
1591
|
+
"OpenAI response ended with incomplete tool calls"
|
|
1592
|
+
);
|
|
1533
1593
|
return {
|
|
1534
1594
|
content: message?.content ?? "",
|
|
1535
|
-
toolCalls
|
|
1536
|
-
id: toolCall.id ?? generateToolCallId(),
|
|
1537
|
-
name: toolCall.function?.name ?? "",
|
|
1538
|
-
args: (() => {
|
|
1539
|
-
try {
|
|
1540
|
-
return JSON.parse(toolCall.function?.arguments ?? "{}");
|
|
1541
|
-
} catch {
|
|
1542
|
-
return {};
|
|
1543
|
-
}
|
|
1544
|
-
})(),
|
|
1545
|
-
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1546
|
-
})) ?? [],
|
|
1595
|
+
toolCalls,
|
|
1547
1596
|
usage: response.usage ? {
|
|
1548
1597
|
promptTokens: response.usage.prompt_tokens,
|
|
1549
1598
|
completionTokens: response.usage.completion_tokens,
|
|
@@ -111,6 +111,19 @@ function capabilities(model) {
|
|
|
111
111
|
const supportsNone = major === 5 && minor >= 1 && !chat || /^gpt-6-(?:sol|luna)(?:-\d{4}-\d{2}-\d{2})?$/i.test(model);
|
|
112
112
|
return { major, minor, reasoning, supportsNone };
|
|
113
113
|
}
|
|
114
|
+
function filterOpenAIResponseInclude(model, include, options = {}) {
|
|
115
|
+
const c = capabilities(model);
|
|
116
|
+
let result = include;
|
|
117
|
+
if (options.parameterPolicy !== "passthrough" && c.reasoning && !(options.reasoningEffort === "none" && c.supportsNone) && include.includes("message.output_text.logprobs")) {
|
|
118
|
+
result = include.filter(
|
|
119
|
+
(value) => value !== "message.output_text.logprobs"
|
|
120
|
+
);
|
|
121
|
+
(options.onWarning ?? console.warn)(
|
|
122
|
+
`[llm-sdk] ${model}: omitted message.output_text.logprobs because reasoning is enabled.`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return result.length ? result : void 0;
|
|
126
|
+
}
|
|
114
127
|
function requiresOpenAIResponses(model, baseUrl, options = {}) {
|
|
115
128
|
if (options.parameterPolicy === "passthrough") return false;
|
|
116
129
|
const c = capabilities(model);
|
|
@@ -272,6 +285,7 @@ function toOpenAIResponseFormat(rf) {
|
|
|
272
285
|
};
|
|
273
286
|
}
|
|
274
287
|
function toOpenAIResponsesTextFormat(rf) {
|
|
288
|
+
if (rf?.type === "json_object") return { type: "json_object" };
|
|
275
289
|
if (!rf || rf.type !== "json_schema") return void 0;
|
|
276
290
|
return {
|
|
277
291
|
type: "json_schema",
|
|
@@ -586,6 +600,63 @@ function formatMessages(messages) {
|
|
|
586
600
|
});
|
|
587
601
|
}
|
|
588
602
|
|
|
603
|
+
// src/core/provider-error.ts
|
|
604
|
+
function invalidProviderResponse(message) {
|
|
605
|
+
return Object.assign(new Error(message), {
|
|
606
|
+
name: "InvalidProviderResponseError",
|
|
607
|
+
status: 502,
|
|
608
|
+
code: "INVALID_PROVIDER_RESPONSE"
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
function providerErrorEvent(error, code) {
|
|
612
|
+
const details = error ?? {};
|
|
613
|
+
const event = {
|
|
614
|
+
type: "error",
|
|
615
|
+
message: error instanceof Error ? error.message : String(error),
|
|
616
|
+
code,
|
|
617
|
+
...typeof details.status === "number" ? { status: details.status } : {},
|
|
618
|
+
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
619
|
+
...typeof details.param === "string" ? { param: details.param } : {},
|
|
620
|
+
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
621
|
+
};
|
|
622
|
+
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
623
|
+
return event;
|
|
624
|
+
}
|
|
625
|
+
function throwIfAborted(signal) {
|
|
626
|
+
if (!signal?.aborted) return;
|
|
627
|
+
const error = new Error("The operation was aborted");
|
|
628
|
+
error.name = "AbortError";
|
|
629
|
+
throw error;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/core/tool-validation.ts
|
|
633
|
+
function parseToolArguments(value) {
|
|
634
|
+
let args = value;
|
|
635
|
+
if (typeof value === "string") {
|
|
636
|
+
try {
|
|
637
|
+
args = JSON.parse(value || "{}");
|
|
638
|
+
} catch {
|
|
639
|
+
throw invalidProviderResponse("Tool arguments are not valid JSON");
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
643
|
+
throw invalidProviderResponse("Tool arguments must be a JSON object");
|
|
644
|
+
return args;
|
|
645
|
+
}
|
|
646
|
+
function validateToolCalls(calls) {
|
|
647
|
+
const ids = /* @__PURE__ */ new Set();
|
|
648
|
+
for (const call of calls) {
|
|
649
|
+
if (!call || typeof call.id !== "string" || !call.id || typeof call.name !== "string" || !call.name || ids.has(call.id))
|
|
650
|
+
throw invalidProviderResponse(
|
|
651
|
+
"Tool calls have missing or duplicate identities"
|
|
652
|
+
);
|
|
653
|
+
ids.add(call.id);
|
|
654
|
+
if (typeof call.args === "string")
|
|
655
|
+
throw invalidProviderResponse("Parsed tool arguments must be an object");
|
|
656
|
+
parseToolArguments(call.args);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
589
660
|
// src/core/openai-responses.ts
|
|
590
661
|
function resolveOpenAITransport(defaults, overrides) {
|
|
591
662
|
return {
|
|
@@ -692,35 +763,6 @@ function getResponseReplay(metadata) {
|
|
|
692
763
|
return responseReplayMetadata(metadata)?.openai?.response?.output;
|
|
693
764
|
}
|
|
694
765
|
|
|
695
|
-
// src/core/provider-error.ts
|
|
696
|
-
function invalidProviderResponse(message) {
|
|
697
|
-
return Object.assign(new Error(message), {
|
|
698
|
-
name: "InvalidProviderResponseError",
|
|
699
|
-
status: 502,
|
|
700
|
-
code: "INVALID_PROVIDER_RESPONSE"
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
function providerErrorEvent(error, code) {
|
|
704
|
-
const details = error ?? {};
|
|
705
|
-
const event = {
|
|
706
|
-
type: "error",
|
|
707
|
-
message: error instanceof Error ? error.message : String(error),
|
|
708
|
-
code,
|
|
709
|
-
...typeof details.status === "number" ? { status: details.status } : {},
|
|
710
|
-
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
711
|
-
...typeof details.param === "string" ? { param: details.param } : {},
|
|
712
|
-
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
713
|
-
};
|
|
714
|
-
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
715
|
-
return event;
|
|
716
|
-
}
|
|
717
|
-
function throwIfAborted(signal) {
|
|
718
|
-
if (!signal?.aborted) return;
|
|
719
|
-
const error = new Error("The operation was aborted");
|
|
720
|
-
error.name = "AbortError";
|
|
721
|
-
throw error;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
766
|
// src/core/utils.ts
|
|
725
767
|
function generateId(prefix = "id") {
|
|
726
768
|
return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
@@ -728,9 +770,6 @@ function generateId(prefix = "id") {
|
|
|
728
770
|
function generateMessageId() {
|
|
729
771
|
return generateId("msg");
|
|
730
772
|
}
|
|
731
|
-
function generateToolCallId() {
|
|
732
|
-
return generateId("call");
|
|
733
|
-
}
|
|
734
773
|
|
|
735
774
|
// src/adapters/openai.ts
|
|
736
775
|
var OpenAIAdapter = class _OpenAIAdapter {
|
|
@@ -754,6 +793,8 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
754
793
|
apiKey: this.config.apiKey,
|
|
755
794
|
baseURL: this.config.baseUrl,
|
|
756
795
|
organization: this.config.organization,
|
|
796
|
+
project: this.config.project,
|
|
797
|
+
timeout: this.config.timeout,
|
|
757
798
|
defaultHeaders: this.config.headers
|
|
758
799
|
});
|
|
759
800
|
}
|
|
@@ -1035,6 +1076,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1035
1076
|
request.config?.responseFormat
|
|
1036
1077
|
);
|
|
1037
1078
|
const modelIdForPayload = request.config?.model || this.model;
|
|
1079
|
+
const include = filterOpenAIResponseInclude(
|
|
1080
|
+
modelIdForPayload,
|
|
1081
|
+
[
|
|
1082
|
+
.../* @__PURE__ */ new Set([
|
|
1083
|
+
...options?.include ?? [],
|
|
1084
|
+
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1085
|
+
])
|
|
1086
|
+
],
|
|
1087
|
+
this.parameterOptions(request)
|
|
1088
|
+
);
|
|
1038
1089
|
const payload = {
|
|
1039
1090
|
model: modelIdForPayload,
|
|
1040
1091
|
instructions: request.systemPrompt,
|
|
@@ -1058,14 +1109,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1058
1109
|
...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {},
|
|
1059
1110
|
...options?.promptCacheOptions !== void 0 ? { prompt_cache_options: options.promptCacheOptions } : {},
|
|
1060
1111
|
...options?.promptCacheRetention !== void 0 ? { prompt_cache_retention: options.promptCacheRetention } : {},
|
|
1061
|
-
...
|
|
1062
|
-
include: [
|
|
1063
|
-
.../* @__PURE__ */ new Set([
|
|
1064
|
-
...options?.include ?? [],
|
|
1065
|
-
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1066
|
-
])
|
|
1067
|
-
]
|
|
1068
|
-
} : {},
|
|
1112
|
+
...include ? { include } : {},
|
|
1069
1113
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
1070
1114
|
stream
|
|
1071
1115
|
};
|
|
@@ -1436,15 +1480,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1436
1480
|
}
|
|
1437
1481
|
throwIfAborted(request.signal);
|
|
1438
1482
|
if (!finishReason)
|
|
1439
|
-
throw
|
|
1483
|
+
throw invalidProviderResponse(
|
|
1484
|
+
"OpenAI stream ended without a finish reason"
|
|
1485
|
+
);
|
|
1440
1486
|
if (toolCalls.size && !["tool_calls", "function_call"].includes(finishReason)) {
|
|
1441
|
-
throw
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (!call.id || !call.name)
|
|
1445
|
-
throw new Error("OpenAI stream contains an incomplete tool call");
|
|
1446
|
-
JSON.parse(call.arguments || "{}");
|
|
1487
|
+
throw invalidProviderResponse(
|
|
1488
|
+
"OpenAI stream ended with incomplete tool calls"
|
|
1489
|
+
);
|
|
1447
1490
|
}
|
|
1491
|
+
validateToolCalls(
|
|
1492
|
+
[...toolCalls.values()].map((call) => ({
|
|
1493
|
+
...call,
|
|
1494
|
+
args: parseToolArguments(call.arguments)
|
|
1495
|
+
}))
|
|
1496
|
+
);
|
|
1448
1497
|
for (const call of toolCalls.values()) {
|
|
1449
1498
|
yield {
|
|
1450
1499
|
type: "action:start",
|
|
@@ -1528,20 +1577,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1528
1577
|
logProviderPayload("openai", "response payload", response, request.debug);
|
|
1529
1578
|
const choice = response.choices?.[0];
|
|
1530
1579
|
const message = choice?.message;
|
|
1580
|
+
const toolCalls = (message?.tool_calls ?? []).map((toolCall) => ({
|
|
1581
|
+
id: toolCall.id,
|
|
1582
|
+
name: toolCall.function?.name,
|
|
1583
|
+
args: parseToolArguments(toolCall.function?.arguments ?? "{}"),
|
|
1584
|
+
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1585
|
+
}));
|
|
1586
|
+
validateToolCalls(toolCalls);
|
|
1587
|
+
if (toolCalls.length && choice?.finish_reason && !["tool_calls", "function_call"].includes(choice.finish_reason))
|
|
1588
|
+
throw invalidProviderResponse(
|
|
1589
|
+
"OpenAI response ended with incomplete tool calls"
|
|
1590
|
+
);
|
|
1531
1591
|
return {
|
|
1532
1592
|
content: message?.content ?? "",
|
|
1533
|
-
toolCalls
|
|
1534
|
-
id: toolCall.id ?? generateToolCallId(),
|
|
1535
|
-
name: toolCall.function?.name ?? "",
|
|
1536
|
-
args: (() => {
|
|
1537
|
-
try {
|
|
1538
|
-
return JSON.parse(toolCall.function?.arguments ?? "{}");
|
|
1539
|
-
} catch {
|
|
1540
|
-
return {};
|
|
1541
|
-
}
|
|
1542
|
-
})(),
|
|
1543
|
-
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1544
|
-
})) ?? [],
|
|
1593
|
+
toolCalls,
|
|
1545
1594
|
usage: response.usage ? {
|
|
1546
1595
|
promptTokens: response.usage.prompt_tokens,
|
|
1547
1596
|
completionTokens: response.usage.completion_tokens,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { G as GoogleProviderConfig, A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D7lzMMLu.mjs';
|
|
2
|
+
import { G as GoogleProviderConfig, A as AIProvider } from '../../types-C7_qVSSd.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-DySbTP8C.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Google Provider - OpenAI-Compatible
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { G as GoogleProviderConfig, A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D7lzMMLu.js';
|
|
2
|
+
import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BXQMtaCX.js';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-6LzczuCg.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Google Provider - OpenAI-Compatible
|