@providerprotocol/ai 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic/index.d.ts +51 -15
- package/dist/anthropic/index.js +54 -19
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-SUNYWHTH.js → chunk-MOU4U3PO.js} +55 -3
- package/dist/chunk-MOU4U3PO.js.map +1 -0
- package/dist/{chunk-Y6Q7JCNP.js → chunk-MSR5P65T.js} +1 -1
- package/dist/chunk-MSR5P65T.js.map +1 -0
- package/dist/{chunk-W4BB4BG2.js → chunk-SVYROCLD.js} +31 -11
- package/dist/chunk-SVYROCLD.js.map +1 -0
- package/dist/chunk-U4JJC2YX.js +234 -0
- package/dist/chunk-U4JJC2YX.js.map +1 -0
- package/dist/{chunk-X5G4EHL7.js → chunk-Z7RBRCRN.js} +1 -1
- package/dist/chunk-Z7RBRCRN.js.map +1 -0
- package/dist/google/index.d.ts +376 -7
- package/dist/google/index.js +127 -15
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +222 -25
- package/dist/http/index.js +3 -3
- package/dist/index.d.ts +1482 -198
- package/dist/index.js +233 -49
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +92 -20
- package/dist/ollama/index.js +17 -7
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +340 -61
- package/dist/openai/index.js +57 -15
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +107 -51
- package/dist/openrouter/index.js +36 -8
- package/dist/openrouter/index.js.map +1 -1
- package/dist/provider-mKkz7Q9U.d.ts +488 -0
- package/dist/retry-Dh70lgr0.d.ts +508 -0
- package/dist/xai/index.d.ts +97 -22
- package/dist/xai/index.js +55 -19
- package/dist/xai/index.js.map +1 -1
- package/package.json +8 -12
- package/dist/chunk-CUCRF5W6.js +0 -136
- package/dist/chunk-CUCRF5W6.js.map +0 -1
- package/dist/chunk-SUNYWHTH.js.map +0 -1
- package/dist/chunk-W4BB4BG2.js.map +0 -1
- package/dist/chunk-X5G4EHL7.js.map +0 -1
- package/dist/chunk-Y6Q7JCNP.js.map +0 -1
- package/dist/provider-CUJWjgNl.d.ts +0 -192
- package/dist/retry-I2661_rv.d.ts +0 -118
- package/src/anthropic/index.ts +0 -3
- package/src/core/image.ts +0 -188
- package/src/core/llm.ts +0 -650
- package/src/core/provider.ts +0 -92
- package/src/google/index.ts +0 -3
- package/src/http/errors.ts +0 -112
- package/src/http/fetch.ts +0 -210
- package/src/http/index.ts +0 -31
- package/src/http/keys.ts +0 -136
- package/src/http/retry.ts +0 -205
- package/src/http/sse.ts +0 -136
- package/src/index.ts +0 -32
- package/src/ollama/index.ts +0 -3
- package/src/openai/index.ts +0 -39
- package/src/openrouter/index.ts +0 -11
- package/src/providers/anthropic/index.ts +0 -17
- package/src/providers/anthropic/llm.ts +0 -196
- package/src/providers/anthropic/transform.ts +0 -434
- package/src/providers/anthropic/types.ts +0 -213
- package/src/providers/google/index.ts +0 -17
- package/src/providers/google/llm.ts +0 -203
- package/src/providers/google/transform.ts +0 -447
- package/src/providers/google/types.ts +0 -214
- package/src/providers/ollama/index.ts +0 -43
- package/src/providers/ollama/llm.ts +0 -272
- package/src/providers/ollama/transform.ts +0 -434
- package/src/providers/ollama/types.ts +0 -260
- package/src/providers/openai/index.ts +0 -186
- package/src/providers/openai/llm.completions.ts +0 -201
- package/src/providers/openai/llm.responses.ts +0 -211
- package/src/providers/openai/transform.completions.ts +0 -561
- package/src/providers/openai/transform.responses.ts +0 -708
- package/src/providers/openai/types.ts +0 -1249
- package/src/providers/openrouter/index.ts +0 -177
- package/src/providers/openrouter/llm.completions.ts +0 -201
- package/src/providers/openrouter/llm.responses.ts +0 -211
- package/src/providers/openrouter/transform.completions.ts +0 -538
- package/src/providers/openrouter/transform.responses.ts +0 -742
- package/src/providers/openrouter/types.ts +0 -717
- package/src/providers/xai/index.ts +0 -223
- package/src/providers/xai/llm.completions.ts +0 -201
- package/src/providers/xai/llm.messages.ts +0 -195
- package/src/providers/xai/llm.responses.ts +0 -211
- package/src/providers/xai/transform.completions.ts +0 -565
- package/src/providers/xai/transform.messages.ts +0 -448
- package/src/providers/xai/transform.responses.ts +0 -678
- package/src/providers/xai/types.ts +0 -938
- package/src/types/content.ts +0 -133
- package/src/types/errors.ts +0 -85
- package/src/types/index.ts +0 -105
- package/src/types/llm.ts +0 -211
- package/src/types/messages.ts +0 -205
- package/src/types/provider.ts +0 -195
- package/src/types/schema.ts +0 -58
- package/src/types/stream.ts +0 -188
- package/src/types/thread.ts +0 -226
- package/src/types/tool.ts +0 -88
- package/src/types/turn.ts +0 -118
- package/src/utils/id.ts +0 -28
- package/src/xai/index.ts +0 -41
package/dist/openai/index.js
CHANGED
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
isAssistantMessage,
|
|
4
4
|
isToolResultMessage,
|
|
5
5
|
isUserMessage
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-SVYROCLD.js";
|
|
7
7
|
import {
|
|
8
8
|
parseSSEStream
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-Z7RBRCRN.js";
|
|
10
10
|
import {
|
|
11
11
|
UPPError,
|
|
12
12
|
doFetch,
|
|
13
13
|
doStreamFetch,
|
|
14
14
|
normalizeHttpError,
|
|
15
15
|
resolveApiKey
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-MOU4U3PO.js";
|
|
17
17
|
|
|
18
18
|
// src/providers/openai/transform.completions.ts
|
|
19
19
|
function transformRequest(request, modelId) {
|
|
@@ -48,12 +48,18 @@ function transformRequest(request, modelId) {
|
|
|
48
48
|
}
|
|
49
49
|
return openaiRequest;
|
|
50
50
|
}
|
|
51
|
+
function normalizeSystem(system) {
|
|
52
|
+
if (!system) return void 0;
|
|
53
|
+
if (typeof system === "string") return system;
|
|
54
|
+
return system.map((block) => block.text ?? "").filter((text) => text.length > 0).join("\n\n");
|
|
55
|
+
}
|
|
51
56
|
function transformMessages(messages, system) {
|
|
52
57
|
const result = [];
|
|
53
|
-
|
|
58
|
+
const normalizedSystem = normalizeSystem(system);
|
|
59
|
+
if (normalizedSystem) {
|
|
54
60
|
result.push({
|
|
55
61
|
role: "system",
|
|
56
|
-
content:
|
|
62
|
+
content: normalizedSystem
|
|
57
63
|
});
|
|
58
64
|
}
|
|
59
65
|
for (const message of messages) {
|
|
@@ -154,7 +160,12 @@ function transformContentBlock(block) {
|
|
|
154
160
|
throw new Error(`Unsupported content type: ${block.type}`);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
163
|
+
function extractToolOptions(tool) {
|
|
164
|
+
const openaiMeta = tool.metadata?.openai;
|
|
165
|
+
return { strict: openaiMeta?.strict };
|
|
166
|
+
}
|
|
157
167
|
function transformTool(tool) {
|
|
168
|
+
const { strict } = extractToolOptions(tool);
|
|
158
169
|
return {
|
|
159
170
|
type: "function",
|
|
160
171
|
function: {
|
|
@@ -165,7 +176,8 @@ function transformTool(tool) {
|
|
|
165
176
|
properties: tool.parameters.properties,
|
|
166
177
|
required: tool.parameters.required,
|
|
167
178
|
...tool.parameters.additionalProperties !== void 0 ? { additionalProperties: tool.parameters.additionalProperties } : {}
|
|
168
|
-
}
|
|
179
|
+
},
|
|
180
|
+
...strict !== void 0 ? { strict } : {}
|
|
169
181
|
}
|
|
170
182
|
};
|
|
171
183
|
}
|
|
@@ -221,7 +233,9 @@ function transformResponse(data) {
|
|
|
221
233
|
const usage = {
|
|
222
234
|
inputTokens: data.usage.prompt_tokens,
|
|
223
235
|
outputTokens: data.usage.completion_tokens,
|
|
224
|
-
totalTokens: data.usage.total_tokens
|
|
236
|
+
totalTokens: data.usage.total_tokens,
|
|
237
|
+
cacheReadTokens: data.usage.prompt_tokens_details?.cached_tokens ?? 0,
|
|
238
|
+
cacheWriteTokens: 0
|
|
225
239
|
};
|
|
226
240
|
let stopReason = "end_turn";
|
|
227
241
|
switch (choice.finish_reason) {
|
|
@@ -257,6 +271,7 @@ function createStreamState() {
|
|
|
257
271
|
finishReason: null,
|
|
258
272
|
inputTokens: 0,
|
|
259
273
|
outputTokens: 0,
|
|
274
|
+
cacheReadTokens: 0,
|
|
260
275
|
hadRefusal: false
|
|
261
276
|
};
|
|
262
277
|
}
|
|
@@ -324,6 +339,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
324
339
|
if (chunk.usage) {
|
|
325
340
|
state.inputTokens = chunk.usage.prompt_tokens;
|
|
326
341
|
state.outputTokens = chunk.usage.completion_tokens;
|
|
342
|
+
state.cacheReadTokens = chunk.usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
327
343
|
}
|
|
328
344
|
return events;
|
|
329
345
|
}
|
|
@@ -368,7 +384,9 @@ function buildResponseFromState(state) {
|
|
|
368
384
|
const usage = {
|
|
369
385
|
inputTokens: state.inputTokens,
|
|
370
386
|
outputTokens: state.outputTokens,
|
|
371
|
-
totalTokens: state.inputTokens + state.outputTokens
|
|
387
|
+
totalTokens: state.inputTokens + state.outputTokens,
|
|
388
|
+
cacheReadTokens: state.cacheReadTokens,
|
|
389
|
+
cacheWriteTokens: 0
|
|
372
390
|
};
|
|
373
391
|
let stopReason = "end_turn";
|
|
374
392
|
switch (state.finishReason) {
|
|
@@ -583,13 +601,19 @@ function transformRequest2(request, modelId) {
|
|
|
583
601
|
}
|
|
584
602
|
return openaiRequest;
|
|
585
603
|
}
|
|
604
|
+
function normalizeSystem2(system) {
|
|
605
|
+
if (!system) return void 0;
|
|
606
|
+
if (typeof system === "string") return system;
|
|
607
|
+
return system.map((block) => block.text ?? "").filter((text) => text.length > 0).join("\n\n");
|
|
608
|
+
}
|
|
586
609
|
function transformInputItems(messages, system) {
|
|
587
610
|
const result = [];
|
|
588
|
-
|
|
611
|
+
const normalizedSystem = normalizeSystem2(system);
|
|
612
|
+
if (normalizedSystem) {
|
|
589
613
|
result.push({
|
|
590
614
|
type: "message",
|
|
591
615
|
role: "system",
|
|
592
|
-
content:
|
|
616
|
+
content: normalizedSystem
|
|
593
617
|
});
|
|
594
618
|
}
|
|
595
619
|
for (const message of messages) {
|
|
@@ -708,7 +732,12 @@ function transformContentPart(block) {
|
|
|
708
732
|
throw new Error(`Unsupported content type: ${block.type}`);
|
|
709
733
|
}
|
|
710
734
|
}
|
|
735
|
+
function extractToolOptions2(tool) {
|
|
736
|
+
const openaiMeta = tool.metadata?.openai;
|
|
737
|
+
return { strict: openaiMeta?.strict };
|
|
738
|
+
}
|
|
711
739
|
function transformTool2(tool) {
|
|
740
|
+
const { strict } = extractToolOptions2(tool);
|
|
712
741
|
return {
|
|
713
742
|
type: "function",
|
|
714
743
|
name: tool.name,
|
|
@@ -718,7 +747,8 @@ function transformTool2(tool) {
|
|
|
718
747
|
properties: tool.parameters.properties,
|
|
719
748
|
required: tool.parameters.required,
|
|
720
749
|
...tool.parameters.additionalProperties !== void 0 ? { additionalProperties: tool.parameters.additionalProperties } : {}
|
|
721
|
-
}
|
|
750
|
+
},
|
|
751
|
+
...strict !== void 0 ? { strict } : {}
|
|
722
752
|
};
|
|
723
753
|
}
|
|
724
754
|
function transformResponse2(data) {
|
|
@@ -791,7 +821,9 @@ function transformResponse2(data) {
|
|
|
791
821
|
const usage = {
|
|
792
822
|
inputTokens: data.usage.input_tokens,
|
|
793
823
|
outputTokens: data.usage.output_tokens,
|
|
794
|
-
totalTokens: data.usage.total_tokens
|
|
824
|
+
totalTokens: data.usage.total_tokens,
|
|
825
|
+
cacheReadTokens: data.usage.input_tokens_details?.cached_tokens ?? 0,
|
|
826
|
+
cacheWriteTokens: 0
|
|
795
827
|
};
|
|
796
828
|
let stopReason = "end_turn";
|
|
797
829
|
if (data.status === "completed") {
|
|
@@ -821,6 +853,7 @@ function createStreamState2() {
|
|
|
821
853
|
status: "in_progress",
|
|
822
854
|
inputTokens: 0,
|
|
823
855
|
outputTokens: 0,
|
|
856
|
+
cacheReadTokens: 0,
|
|
824
857
|
hadRefusal: false
|
|
825
858
|
};
|
|
826
859
|
}
|
|
@@ -840,6 +873,7 @@ function transformStreamEvent2(event, state) {
|
|
|
840
873
|
if (event.response.usage) {
|
|
841
874
|
state.inputTokens = event.response.usage.input_tokens;
|
|
842
875
|
state.outputTokens = event.response.usage.output_tokens;
|
|
876
|
+
state.cacheReadTokens = event.response.usage.input_tokens_details?.cached_tokens ?? 0;
|
|
843
877
|
}
|
|
844
878
|
events.push({ type: "message_stop", index: 0, delta: {} });
|
|
845
879
|
break;
|
|
@@ -892,7 +926,7 @@ function transformStreamEvent2(event, state) {
|
|
|
892
926
|
delta: {}
|
|
893
927
|
});
|
|
894
928
|
break;
|
|
895
|
-
case "response.output_text.delta":
|
|
929
|
+
case "response.output_text.delta": {
|
|
896
930
|
const currentText = state.textByIndex.get(event.output_index) ?? "";
|
|
897
931
|
state.textByIndex.set(event.output_index, currentText + event.delta);
|
|
898
932
|
events.push({
|
|
@@ -901,6 +935,7 @@ function transformStreamEvent2(event, state) {
|
|
|
901
935
|
delta: { text: event.delta }
|
|
902
936
|
});
|
|
903
937
|
break;
|
|
938
|
+
}
|
|
904
939
|
case "response.output_text.done":
|
|
905
940
|
state.textByIndex.set(event.output_index, event.text);
|
|
906
941
|
break;
|
|
@@ -1023,7 +1058,6 @@ function buildResponseFromState2(state) {
|
|
|
1023
1058
|
openai: {
|
|
1024
1059
|
model: state.model,
|
|
1025
1060
|
status: state.status,
|
|
1026
|
-
// Store response_id for multi-turn tool calling
|
|
1027
1061
|
response_id: state.id,
|
|
1028
1062
|
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0
|
|
1029
1063
|
}
|
|
@@ -1033,7 +1067,9 @@ function buildResponseFromState2(state) {
|
|
|
1033
1067
|
const usage = {
|
|
1034
1068
|
inputTokens: state.inputTokens,
|
|
1035
1069
|
outputTokens: state.outputTokens,
|
|
1036
|
-
totalTokens: state.inputTokens + state.outputTokens
|
|
1070
|
+
totalTokens: state.inputTokens + state.outputTokens,
|
|
1071
|
+
cacheReadTokens: state.cacheReadTokens,
|
|
1072
|
+
cacheWriteTokens: 0
|
|
1037
1073
|
};
|
|
1038
1074
|
let stopReason = "end_turn";
|
|
1039
1075
|
if (state.status === "completed") {
|
|
@@ -1262,11 +1298,17 @@ function mcpTool(options) {
|
|
|
1262
1298
|
};
|
|
1263
1299
|
}
|
|
1264
1300
|
var tools = {
|
|
1301
|
+
/** Creates a web search tool configuration */
|
|
1265
1302
|
webSearch: webSearchTool,
|
|
1303
|
+
/** Creates a file search tool configuration */
|
|
1266
1304
|
fileSearch: fileSearchTool,
|
|
1305
|
+
/** Creates a code interpreter tool configuration */
|
|
1267
1306
|
codeInterpreter: codeInterpreterTool,
|
|
1307
|
+
/** Creates a computer tool configuration */
|
|
1268
1308
|
computer: computerTool,
|
|
1309
|
+
/** Creates an image generation tool configuration */
|
|
1269
1310
|
imageGeneration: imageGenerationTool,
|
|
1311
|
+
/** Creates an MCP tool configuration */
|
|
1270
1312
|
mcp: mcpTool
|
|
1271
1313
|
};
|
|
1272
1314
|
|