@yourgpt/llm-sdk 2.6.0-beta.2 → 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 +87 -17
- package/dist/adapters/index.d.mts +11 -13
- package/dist/adapters/index.d.ts +11 -13
- package/dist/adapters/index.js +406 -114
- package/dist/adapters/index.mjs +406 -114
- 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 +17 -9
- package/dist/index.d.ts +17 -9
- package/dist/index.js +698 -205
- package/dist/index.mjs +695 -206
- package/dist/providers/anthropic/index.d.mts +7 -4
- package/dist/providers/anthropic/index.d.ts +7 -4
- package/dist/providers/anthropic/index.js +389 -115
- package/dist/providers/anthropic/index.mjs +389 -115
- 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 +181 -60
- package/dist/providers/fireworks/index.mjs +181 -60
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +181 -60
- package/dist/providers/google/index.mjs +181 -60
- 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 +1451 -85
- package/dist/providers/openai/index.mjs +1449 -86
- package/dist/providers/openrouter/index.d.mts +21 -4
- package/dist/providers/openrouter/index.d.ts +21 -4
- package/dist/providers/openrouter/index.js +1040 -131
- package/dist/providers/openrouter/index.mjs +1040 -132
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +181 -60
- package/dist/providers/togetherai/index.mjs +181 -60
- 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 +181 -60
- package/dist/providers/xai/index.mjs +181 -60
- 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
|
@@ -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",
|
|
@@ -615,6 +629,63 @@ function formatMessagesForXAI(messages) {
|
|
|
615
629
|
});
|
|
616
630
|
}
|
|
617
631
|
|
|
632
|
+
// src/core/provider-error.ts
|
|
633
|
+
function invalidProviderResponse(message) {
|
|
634
|
+
return Object.assign(new Error(message), {
|
|
635
|
+
name: "InvalidProviderResponseError",
|
|
636
|
+
status: 502,
|
|
637
|
+
code: "INVALID_PROVIDER_RESPONSE"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function providerErrorEvent(error, code) {
|
|
641
|
+
const details = error ?? {};
|
|
642
|
+
const event = {
|
|
643
|
+
type: "error",
|
|
644
|
+
message: error instanceof Error ? error.message : String(error),
|
|
645
|
+
code,
|
|
646
|
+
...typeof details.status === "number" ? { status: details.status } : {},
|
|
647
|
+
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
648
|
+
...typeof details.param === "string" ? { param: details.param } : {},
|
|
649
|
+
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
650
|
+
};
|
|
651
|
+
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
652
|
+
return event;
|
|
653
|
+
}
|
|
654
|
+
function throwIfAborted(signal) {
|
|
655
|
+
if (!signal?.aborted) return;
|
|
656
|
+
const error = new Error("The operation was aborted");
|
|
657
|
+
error.name = "AbortError";
|
|
658
|
+
throw error;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// src/core/tool-validation.ts
|
|
662
|
+
function parseToolArguments(value) {
|
|
663
|
+
let args = value;
|
|
664
|
+
if (typeof value === "string") {
|
|
665
|
+
try {
|
|
666
|
+
args = JSON.parse(value || "{}");
|
|
667
|
+
} catch {
|
|
668
|
+
throw invalidProviderResponse("Tool arguments are not valid JSON");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
672
|
+
throw invalidProviderResponse("Tool arguments must be a JSON object");
|
|
673
|
+
return args;
|
|
674
|
+
}
|
|
675
|
+
function validateToolCalls(calls) {
|
|
676
|
+
const ids = /* @__PURE__ */ new Set();
|
|
677
|
+
for (const call of calls) {
|
|
678
|
+
if (!call || typeof call.id !== "string" || !call.id || typeof call.name !== "string" || !call.name || ids.has(call.id))
|
|
679
|
+
throw invalidProviderResponse(
|
|
680
|
+
"Tool calls have missing or duplicate identities"
|
|
681
|
+
);
|
|
682
|
+
ids.add(call.id);
|
|
683
|
+
if (typeof call.args === "string")
|
|
684
|
+
throw invalidProviderResponse("Parsed tool arguments must be an object");
|
|
685
|
+
parseToolArguments(call.args);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
618
689
|
// src/core/openai-responses.ts
|
|
619
690
|
function resolveOpenAITransport(defaults, overrides) {
|
|
620
691
|
return {
|
|
@@ -662,6 +733,54 @@ function responseMetadata(response) {
|
|
|
662
733
|
}
|
|
663
734
|
};
|
|
664
735
|
}
|
|
736
|
+
function responseReplayMetadata(metadata) {
|
|
737
|
+
const response = metadata?.openai?.response;
|
|
738
|
+
if (!response) return metadata;
|
|
739
|
+
const output = response.output.map((item) => {
|
|
740
|
+
const fields = ["type", "id", "status"];
|
|
741
|
+
switch (item.type) {
|
|
742
|
+
case "reasoning":
|
|
743
|
+
fields.push("encrypted_content");
|
|
744
|
+
break;
|
|
745
|
+
case "message":
|
|
746
|
+
fields.push("role", "phase");
|
|
747
|
+
break;
|
|
748
|
+
case "function_call":
|
|
749
|
+
fields.push("call_id", "name", "namespace", "arguments");
|
|
750
|
+
break;
|
|
751
|
+
case "tool_search_call":
|
|
752
|
+
fields.push("call_id", "execution", "arguments");
|
|
753
|
+
break;
|
|
754
|
+
case "tool_search_output":
|
|
755
|
+
fields.push("call_id", "tools");
|
|
756
|
+
break;
|
|
757
|
+
case "web_search_call":
|
|
758
|
+
fields.push("action");
|
|
759
|
+
break;
|
|
760
|
+
default:
|
|
761
|
+
return stripItemDiagnostics(item);
|
|
762
|
+
}
|
|
763
|
+
const replay = Object.fromEntries(
|
|
764
|
+
fields.filter((key) => item[key] !== void 0).map((key) => [key, item[key]])
|
|
765
|
+
);
|
|
766
|
+
if (item.type === "reasoning") replay.summary = [];
|
|
767
|
+
if (item.type === "message")
|
|
768
|
+
replay.content = Array.isArray(item.content) ? item.content.flatMap(
|
|
769
|
+
(part) => part?.type === "output_text" && typeof part.text === "string" ? [{ type: "output_text", text: part.text, annotations: [] }] : part?.type === "refusal" && typeof part.refusal === "string" ? [{ type: "refusal", refusal: part.refusal }] : []
|
|
770
|
+
) : [];
|
|
771
|
+
return stripItemDiagnostics(replay);
|
|
772
|
+
});
|
|
773
|
+
return { openai: { response: { output, refusals: [] } } };
|
|
774
|
+
}
|
|
775
|
+
function stripItemDiagnostics(item) {
|
|
776
|
+
const {
|
|
777
|
+
usage: _usage,
|
|
778
|
+
logprobs: _logprobs,
|
|
779
|
+
metadata: _metadata,
|
|
780
|
+
...state
|
|
781
|
+
} = item;
|
|
782
|
+
return state;
|
|
783
|
+
}
|
|
665
784
|
function getResponseReplay(metadata) {
|
|
666
785
|
const response = metadata?.openai?.response;
|
|
667
786
|
if (response === void 0) return void 0;
|
|
@@ -670,29 +789,7 @@ function getResponseReplay(metadata) {
|
|
|
670
789
|
"Invalid OpenAI Responses replay metadata: output must contain typed items"
|
|
671
790
|
);
|
|
672
791
|
}
|
|
673
|
-
return response
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// src/core/provider-error.ts
|
|
677
|
-
function providerErrorEvent(error, code) {
|
|
678
|
-
const details = error ?? {};
|
|
679
|
-
const event = {
|
|
680
|
-
type: "error",
|
|
681
|
-
message: error instanceof Error ? error.message : String(error),
|
|
682
|
-
code,
|
|
683
|
-
...typeof details.status === "number" ? { status: details.status } : {},
|
|
684
|
-
...typeof details.code === "string" ? { providerCode: details.code } : {},
|
|
685
|
-
...typeof details.param === "string" ? { param: details.param } : {},
|
|
686
|
-
...typeof details.request_id === "string" ? { requestId: details.request_id } : {}
|
|
687
|
-
};
|
|
688
|
-
Object.defineProperty(event, "cause", { value: error, enumerable: false });
|
|
689
|
-
return event;
|
|
690
|
-
}
|
|
691
|
-
function throwIfAborted(signal) {
|
|
692
|
-
if (!signal?.aborted) return;
|
|
693
|
-
const error = new Error("The operation was aborted");
|
|
694
|
-
error.name = "AbortError";
|
|
695
|
-
throw error;
|
|
792
|
+
return responseReplayMetadata(metadata)?.openai?.response?.output;
|
|
696
793
|
}
|
|
697
794
|
|
|
698
795
|
// src/core/utils.ts
|
|
@@ -702,9 +799,6 @@ function generateId(prefix = "id") {
|
|
|
702
799
|
function generateMessageId() {
|
|
703
800
|
return generateId("msg");
|
|
704
801
|
}
|
|
705
|
-
function generateToolCallId() {
|
|
706
|
-
return generateId("call");
|
|
707
|
-
}
|
|
708
802
|
|
|
709
803
|
// src/adapters/openai.ts
|
|
710
804
|
var OpenAIAdapter = class _OpenAIAdapter {
|
|
@@ -728,6 +822,8 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
728
822
|
apiKey: this.config.apiKey,
|
|
729
823
|
baseURL: this.config.baseUrl,
|
|
730
824
|
organization: this.config.organization,
|
|
825
|
+
project: this.config.project,
|
|
826
|
+
timeout: this.config.timeout,
|
|
731
827
|
defaultHeaders: this.config.headers
|
|
732
828
|
});
|
|
733
829
|
}
|
|
@@ -850,7 +946,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
850
946
|
formatRawMessages(messages, preserveProviderMetadata = false) {
|
|
851
947
|
return messages.map((message) => {
|
|
852
948
|
const { attachments, providerMetadata, modelOutput, ...rest } = message;
|
|
853
|
-
let content = message.role === "tool" && !preserveProviderMetadata ? textToolOutput(modelOutput,
|
|
949
|
+
let content = message.role === "tool" && !preserveProviderMetadata && modelOutput !== void 0 ? textToolOutput(modelOutput, "") : message.content;
|
|
854
950
|
if (preserveProviderMetadata && modelOutput)
|
|
855
951
|
rest.modelOutput = modelOutput;
|
|
856
952
|
if (message.role === "assistant" && Array.isArray(message.tool_calls) && message.tool_calls.length > 0 && content === "") {
|
|
@@ -953,17 +1049,32 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
953
1049
|
const seenCallIds = /* @__PURE__ */ new Set();
|
|
954
1050
|
const toolCalls = Array.isArray(response?.output) ? response.output.filter((item) => item?.type === "function_call").map((item) => {
|
|
955
1051
|
if (typeof item.call_id !== "string" || !item.call_id || typeof item.name !== "string" || !item.name || typeof item.arguments !== "string" || item.status && item.status !== "completed") {
|
|
956
|
-
throw
|
|
1052
|
+
throw invalidProviderResponse(
|
|
1053
|
+
"Responses contains an incomplete function call"
|
|
1054
|
+
);
|
|
957
1055
|
}
|
|
958
1056
|
if (seenCallIds.has(item.call_id))
|
|
959
|
-
throw
|
|
1057
|
+
throw invalidProviderResponse(
|
|
1058
|
+
"Responses contains duplicate function call IDs"
|
|
1059
|
+
);
|
|
960
1060
|
seenCallIds.add(item.call_id);
|
|
961
|
-
|
|
1061
|
+
let args;
|
|
1062
|
+
try {
|
|
1063
|
+
args = JSON.parse(item.arguments);
|
|
1064
|
+
} catch {
|
|
1065
|
+
throw invalidProviderResponse(
|
|
1066
|
+
"Responses function arguments must be valid JSON"
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
962
1069
|
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
963
|
-
throw
|
|
1070
|
+
throw invalidProviderResponse(
|
|
964
1071
|
"Responses function arguments must be a JSON object"
|
|
965
1072
|
);
|
|
966
|
-
return {
|
|
1073
|
+
return {
|
|
1074
|
+
id: item.call_id,
|
|
1075
|
+
name: item.name,
|
|
1076
|
+
args
|
|
1077
|
+
};
|
|
967
1078
|
}) : [];
|
|
968
1079
|
return {
|
|
969
1080
|
content,
|
|
@@ -994,6 +1105,16 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
994
1105
|
request.config?.responseFormat
|
|
995
1106
|
);
|
|
996
1107
|
const modelIdForPayload = request.config?.model || this.model;
|
|
1108
|
+
const include = filterOpenAIResponseInclude(
|
|
1109
|
+
modelIdForPayload,
|
|
1110
|
+
[
|
|
1111
|
+
.../* @__PURE__ */ new Set([
|
|
1112
|
+
...options?.include ?? [],
|
|
1113
|
+
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1114
|
+
])
|
|
1115
|
+
],
|
|
1116
|
+
this.parameterOptions(request)
|
|
1117
|
+
);
|
|
997
1118
|
const payload = {
|
|
998
1119
|
model: modelIdForPayload,
|
|
999
1120
|
instructions: request.systemPrompt,
|
|
@@ -1017,14 +1138,7 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1017
1138
|
...options?.promptCacheKey !== void 0 ? { prompt_cache_key: options.promptCacheKey } : {},
|
|
1018
1139
|
...options?.promptCacheOptions !== void 0 ? { prompt_cache_options: options.promptCacheOptions } : {},
|
|
1019
1140
|
...options?.promptCacheRetention !== void 0 ? { prompt_cache_retention: options.promptCacheRetention } : {},
|
|
1020
|
-
...
|
|
1021
|
-
include: [
|
|
1022
|
-
.../* @__PURE__ */ new Set([
|
|
1023
|
-
...options?.include ?? [],
|
|
1024
|
-
...options?.store === false ? ["reasoning.encrypted_content"] : []
|
|
1025
|
-
])
|
|
1026
|
-
]
|
|
1027
|
-
} : {},
|
|
1141
|
+
...include ? { include } : {},
|
|
1028
1142
|
...responsesTextFormat ? { text: { format: responsesTextFormat } } : {},
|
|
1029
1143
|
stream
|
|
1030
1144
|
};
|
|
@@ -1206,7 +1320,9 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1206
1320
|
const uniqueCalls = /* @__PURE__ */ new Map();
|
|
1207
1321
|
for (const call of toolCalls.values()) {
|
|
1208
1322
|
if (!call.id || !call.name)
|
|
1209
|
-
throw
|
|
1323
|
+
throw invalidProviderResponse(
|
|
1324
|
+
"Responses stream contains an incomplete tool call"
|
|
1325
|
+
);
|
|
1210
1326
|
uniqueCalls.set(call.id, call);
|
|
1211
1327
|
}
|
|
1212
1328
|
toolCalls.clear();
|
|
@@ -1393,15 +1509,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1393
1509
|
}
|
|
1394
1510
|
throwIfAborted(request.signal);
|
|
1395
1511
|
if (!finishReason)
|
|
1396
|
-
throw
|
|
1512
|
+
throw invalidProviderResponse(
|
|
1513
|
+
"OpenAI stream ended without a finish reason"
|
|
1514
|
+
);
|
|
1397
1515
|
if (toolCalls.size && !["tool_calls", "function_call"].includes(finishReason)) {
|
|
1398
|
-
throw
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
if (!call.id || !call.name)
|
|
1402
|
-
throw new Error("OpenAI stream contains an incomplete tool call");
|
|
1403
|
-
JSON.parse(call.arguments || "{}");
|
|
1516
|
+
throw invalidProviderResponse(
|
|
1517
|
+
"OpenAI stream ended with incomplete tool calls"
|
|
1518
|
+
);
|
|
1404
1519
|
}
|
|
1520
|
+
validateToolCalls(
|
|
1521
|
+
[...toolCalls.values()].map((call) => ({
|
|
1522
|
+
...call,
|
|
1523
|
+
args: parseToolArguments(call.arguments)
|
|
1524
|
+
}))
|
|
1525
|
+
);
|
|
1405
1526
|
for (const call of toolCalls.values()) {
|
|
1406
1527
|
yield {
|
|
1407
1528
|
type: "action:start",
|
|
@@ -1485,20 +1606,20 @@ var OpenAIAdapter = class _OpenAIAdapter {
|
|
|
1485
1606
|
logProviderPayload("openai", "response payload", response, request.debug);
|
|
1486
1607
|
const choice = response.choices?.[0];
|
|
1487
1608
|
const message = choice?.message;
|
|
1609
|
+
const toolCalls = (message?.tool_calls ?? []).map((toolCall) => ({
|
|
1610
|
+
id: toolCall.id,
|
|
1611
|
+
name: toolCall.function?.name,
|
|
1612
|
+
args: parseToolArguments(toolCall.function?.arguments ?? "{}"),
|
|
1613
|
+
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1614
|
+
}));
|
|
1615
|
+
validateToolCalls(toolCalls);
|
|
1616
|
+
if (toolCalls.length && choice?.finish_reason && !["tool_calls", "function_call"].includes(choice.finish_reason))
|
|
1617
|
+
throw invalidProviderResponse(
|
|
1618
|
+
"OpenAI response ended with incomplete tool calls"
|
|
1619
|
+
);
|
|
1488
1620
|
return {
|
|
1489
1621
|
content: message?.content ?? "",
|
|
1490
|
-
toolCalls
|
|
1491
|
-
id: toolCall.id ?? generateToolCallId(),
|
|
1492
|
-
name: toolCall.function?.name ?? "",
|
|
1493
|
-
args: (() => {
|
|
1494
|
-
try {
|
|
1495
|
-
return JSON.parse(toolCall.function?.arguments ?? "{}");
|
|
1496
|
-
} catch {
|
|
1497
|
-
return {};
|
|
1498
|
-
}
|
|
1499
|
-
})(),
|
|
1500
|
-
...toolCall.extra_content ? { extra_content: toolCall.extra_content } : {}
|
|
1501
|
-
})) ?? [],
|
|
1622
|
+
toolCalls,
|
|
1502
1623
|
usage: response.usage ? {
|
|
1503
1624
|
promptTokens: response.usage.prompt_tokens,
|
|
1504
1625
|
completionTokens: response.usage.completion_tokens,
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-
|
|
2
|
-
import { L as LLMAdapter } from './base-
|
|
1
|
+
import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-D7lzMMLu.js';
|
|
2
|
+
import { L as LLMAdapter } from './base-6LzczuCg.js';
|
|
3
|
+
|
|
4
|
+
type AnthropicThinking = {
|
|
5
|
+
type: "enabled";
|
|
6
|
+
budgetTokens?: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: "adaptive";
|
|
9
|
+
display?: "summarized" | "omitted";
|
|
10
|
+
} | {
|
|
11
|
+
type: "disabled";
|
|
12
|
+
} | {
|
|
13
|
+
type: "between_tools";
|
|
14
|
+
};
|
|
3
15
|
|
|
4
16
|
/**
|
|
5
17
|
* Provider formatter interface
|
|
@@ -263,6 +275,8 @@ interface OpenAIProviderConfig extends BaseProviderConfig, OpenAIParameterOption
|
|
|
263
275
|
* Anthropic provider configuration
|
|
264
276
|
*/
|
|
265
277
|
interface AnthropicProviderConfig extends BaseProviderConfig {
|
|
278
|
+
thinking?: AnthropicThinking;
|
|
279
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
266
280
|
/** Extended thinking budget in tokens (minimum 1024) */
|
|
267
281
|
thinkingBudget?: number;
|
|
268
282
|
/** Enable prompt caching */
|
|
@@ -345,4 +359,4 @@ interface OllamaProviderConfig extends BaseProviderConfig {
|
|
|
345
359
|
options?: OllamaModelOptions;
|
|
346
360
|
}
|
|
347
361
|
|
|
348
|
-
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n };
|
|
362
|
+
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n, AnthropicThinking as o };
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-
|
|
2
|
-
import { L as LLMAdapter } from './base-
|
|
1
|
+
import { ae as OpenAIParameterOptions, O as OpenAITransportOptions, e as ToolDefinition, a1 as UnifiedToolCall, a2 as UnifiedToolResult } from './types-D7lzMMLu.mjs';
|
|
2
|
+
import { L as LLMAdapter } from './base-DySbTP8C.mjs';
|
|
3
|
+
|
|
4
|
+
type AnthropicThinking = {
|
|
5
|
+
type: "enabled";
|
|
6
|
+
budgetTokens?: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: "adaptive";
|
|
9
|
+
display?: "summarized" | "omitted";
|
|
10
|
+
} | {
|
|
11
|
+
type: "disabled";
|
|
12
|
+
} | {
|
|
13
|
+
type: "between_tools";
|
|
14
|
+
};
|
|
3
15
|
|
|
4
16
|
/**
|
|
5
17
|
* Provider formatter interface
|
|
@@ -263,6 +275,8 @@ interface OpenAIProviderConfig extends BaseProviderConfig, OpenAIParameterOption
|
|
|
263
275
|
* Anthropic provider configuration
|
|
264
276
|
*/
|
|
265
277
|
interface AnthropicProviderConfig extends BaseProviderConfig {
|
|
278
|
+
thinking?: AnthropicThinking;
|
|
279
|
+
effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
266
280
|
/** Extended thinking budget in tokens (minimum 1024) */
|
|
267
281
|
thinkingBudget?: number;
|
|
268
282
|
/** Enable prompt caching */
|
|
@@ -345,4 +359,4 @@ interface OllamaProviderConfig extends BaseProviderConfig {
|
|
|
345
359
|
options?: OllamaModelOptions;
|
|
346
360
|
}
|
|
347
361
|
|
|
348
|
-
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n };
|
|
362
|
+
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OpenAIProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AnthropicProviderConfig as a, AzureProviderConfig as b, OllamaProviderConfig as c, OllamaModelOptions as d, ProviderFormatter as e, AnthropicTool as f, AnthropicToolUse as g, AnthropicToolResult as h, OpenAITool as i, OpenAIToolCall as j, OpenAIToolResult as k, GeminiFunctionDeclaration as l, GeminiFunctionCall as m, GeminiFunctionResponse as n, AnthropicThinking as o };
|
|
@@ -812,6 +812,8 @@ interface DoGenerateParams {
|
|
|
812
812
|
* Result from model.doGenerate()
|
|
813
813
|
*/
|
|
814
814
|
interface DoGenerateResult {
|
|
815
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
816
|
+
reasoningText?: string;
|
|
815
817
|
/** Provider state retained for continuation and inspection. */
|
|
816
818
|
providerMetadata?: ProviderMetadata;
|
|
817
819
|
/** Generated text content */
|
|
@@ -840,7 +842,10 @@ interface TokenUsage {
|
|
|
840
842
|
/**
|
|
841
843
|
* Stream chunk from model.doStream()
|
|
842
844
|
*/
|
|
843
|
-
type StreamChunk = TextDeltaChunk |
|
|
845
|
+
type StreamChunk = TextDeltaChunk | {
|
|
846
|
+
type: "reasoning-delta";
|
|
847
|
+
text: string;
|
|
848
|
+
} | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
|
|
844
849
|
interface TextDeltaChunk {
|
|
845
850
|
type: "text-delta";
|
|
846
851
|
text: string;
|
|
@@ -899,6 +904,8 @@ interface GenerateTextParams {
|
|
|
899
904
|
* Result from generateText()
|
|
900
905
|
*/
|
|
901
906
|
interface GenerateTextResult {
|
|
907
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
908
|
+
reasoningText?: string;
|
|
902
909
|
/** Provider state retained for continuation and inspection. */
|
|
903
910
|
providerMetadata?: ProviderMetadata;
|
|
904
911
|
/** Final text output */
|
|
@@ -922,6 +929,8 @@ interface GenerateTextResult {
|
|
|
922
929
|
* A single step in the generation process
|
|
923
930
|
*/
|
|
924
931
|
interface GenerateStep {
|
|
932
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
933
|
+
reasoningText?: string;
|
|
925
934
|
/** Provider state retained for continuation and inspection. */
|
|
926
935
|
providerMetadata?: ProviderMetadata;
|
|
927
936
|
/** Text generated in this step */
|
|
@@ -967,6 +976,9 @@ interface StreamTextResult {
|
|
|
967
976
|
* Stream part for fullStream
|
|
968
977
|
*/
|
|
969
978
|
type StreamPart = {
|
|
979
|
+
type: "reasoning-delta";
|
|
980
|
+
text: string;
|
|
981
|
+
} | {
|
|
970
982
|
type: "text-delta";
|
|
971
983
|
text: string;
|
|
972
984
|
} | {
|
|
@@ -812,6 +812,8 @@ interface DoGenerateParams {
|
|
|
812
812
|
* Result from model.doGenerate()
|
|
813
813
|
*/
|
|
814
814
|
interface DoGenerateResult {
|
|
815
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
816
|
+
reasoningText?: string;
|
|
815
817
|
/** Provider state retained for continuation and inspection. */
|
|
816
818
|
providerMetadata?: ProviderMetadata;
|
|
817
819
|
/** Generated text content */
|
|
@@ -840,7 +842,10 @@ interface TokenUsage {
|
|
|
840
842
|
/**
|
|
841
843
|
* Stream chunk from model.doStream()
|
|
842
844
|
*/
|
|
843
|
-
type StreamChunk = TextDeltaChunk |
|
|
845
|
+
type StreamChunk = TextDeltaChunk | {
|
|
846
|
+
type: "reasoning-delta";
|
|
847
|
+
text: string;
|
|
848
|
+
} | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
|
|
844
849
|
interface TextDeltaChunk {
|
|
845
850
|
type: "text-delta";
|
|
846
851
|
text: string;
|
|
@@ -899,6 +904,8 @@ interface GenerateTextParams {
|
|
|
899
904
|
* Result from generateText()
|
|
900
905
|
*/
|
|
901
906
|
interface GenerateTextResult {
|
|
907
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
908
|
+
reasoningText?: string;
|
|
902
909
|
/** Provider state retained for continuation and inspection. */
|
|
903
910
|
providerMetadata?: ProviderMetadata;
|
|
904
911
|
/** Final text output */
|
|
@@ -922,6 +929,8 @@ interface GenerateTextResult {
|
|
|
922
929
|
* A single step in the generation process
|
|
923
930
|
*/
|
|
924
931
|
interface GenerateStep {
|
|
932
|
+
/** Provider-supplied reasoning text or summary, when available. */
|
|
933
|
+
reasoningText?: string;
|
|
925
934
|
/** Provider state retained for continuation and inspection. */
|
|
926
935
|
providerMetadata?: ProviderMetadata;
|
|
927
936
|
/** Text generated in this step */
|
|
@@ -967,6 +976,9 @@ interface StreamTextResult {
|
|
|
967
976
|
* Stream part for fullStream
|
|
968
977
|
*/
|
|
969
978
|
type StreamPart = {
|
|
979
|
+
type: "reasoning-delta";
|
|
980
|
+
text: string;
|
|
981
|
+
} | {
|
|
970
982
|
type: "text-delta";
|
|
971
983
|
text: string;
|
|
972
984
|
} | {
|
package/dist/yourgpt/index.d.mts
CHANGED
package/dist/yourgpt/index.d.ts
CHANGED