@providerprotocol/ai 0.0.22 → 0.0.23
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/README.md +188 -6
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +30 -25
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-7WYBJPJJ.js → chunk-55X3W2MN.js} +4 -3
- package/dist/chunk-55X3W2MN.js.map +1 -0
- package/dist/chunk-73IIE3QT.js +120 -0
- package/dist/chunk-73IIE3QT.js.map +1 -0
- package/dist/{chunk-M4BMM5IB.js → chunk-MF5ETY5O.js} +13 -4
- package/dist/chunk-MF5ETY5O.js.map +1 -0
- package/dist/{chunk-RFWLEFAB.js → chunk-QNJO7DSD.js} +61 -16
- package/dist/chunk-QNJO7DSD.js.map +1 -0
- package/dist/{chunk-RS7C25LS.js → chunk-SBCATNHA.js} +9 -5
- package/dist/chunk-SBCATNHA.js.map +1 -0
- package/dist/{chunk-I2VHCGQE.js → chunk-Z6DKC37J.js} +6 -5
- package/dist/chunk-Z6DKC37J.js.map +1 -0
- package/dist/google/index.d.ts +3 -2
- package/dist/google/index.js +38 -33
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +3 -3
- package/dist/index.d.ts +8 -6
- package/dist/index.js +81 -121
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +5 -2
- package/dist/ollama/index.js +34 -29
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +58 -53
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +1 -1
- package/dist/openrouter/index.js +57 -52
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-DWEAzeM5.d.ts → provider-DR1yins0.d.ts} +148 -52
- package/dist/proxy/index.d.ts +2 -2
- package/dist/proxy/index.js +11 -9
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DmPmqZL6.d.ts → retry-DJiqAslw.d.ts} +1 -1
- package/dist/{stream-DbkLOIbJ.d.ts → stream-BuTrqt_j.d.ts} +90 -38
- package/dist/xai/index.d.ts +1 -1
- package/dist/xai/index.js +71 -66
- package/dist/xai/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-7WYBJPJJ.js.map +0 -1
- package/dist/chunk-I2VHCGQE.js.map +0 -1
- package/dist/chunk-M4BMM5IB.js.map +0 -1
- package/dist/chunk-RFWLEFAB.js.map +0 -1
- package/dist/chunk-RS7C25LS.js.map +0 -1
package/dist/google/index.js
CHANGED
|
@@ -3,27 +3,32 @@ import {
|
|
|
3
3
|
} from "../chunk-WAKD3OO5.js";
|
|
4
4
|
import {
|
|
5
5
|
parseJsonResponse
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-Z6DKC37J.js";
|
|
7
|
+
import {
|
|
8
|
+
StreamEventType
|
|
9
|
+
} from "../chunk-73IIE3QT.js";
|
|
7
10
|
import {
|
|
8
11
|
AssistantMessage,
|
|
9
12
|
createProvider,
|
|
10
13
|
isAssistantMessage,
|
|
11
14
|
isToolResultMessage,
|
|
12
15
|
isUserMessage
|
|
13
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-MF5ETY5O.js";
|
|
14
17
|
import {
|
|
15
18
|
parseSSEStream
|
|
16
19
|
} from "../chunk-NWS5IKNR.js";
|
|
17
20
|
import {
|
|
18
21
|
resolveApiKey
|
|
19
|
-
} from "../chunk-
|
|
22
|
+
} from "../chunk-55X3W2MN.js";
|
|
20
23
|
import {
|
|
24
|
+
ErrorCode,
|
|
25
|
+
ModalityType,
|
|
21
26
|
UPPError,
|
|
22
27
|
doFetch,
|
|
23
28
|
doStreamFetch,
|
|
24
29
|
normalizeHttpError,
|
|
25
30
|
toError
|
|
26
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-QNJO7DSD.js";
|
|
27
32
|
|
|
28
33
|
// src/providers/google/transform.ts
|
|
29
34
|
function transformRequest(request, modelId) {
|
|
@@ -80,9 +85,9 @@ function normalizeSystem(system) {
|
|
|
80
85
|
if (!Array.isArray(system)) {
|
|
81
86
|
throw new UPPError(
|
|
82
87
|
"System prompt must be a string or an array of text parts",
|
|
83
|
-
|
|
88
|
+
ErrorCode.InvalidRequest,
|
|
84
89
|
"google",
|
|
85
|
-
|
|
90
|
+
ModalityType.LLM
|
|
86
91
|
);
|
|
87
92
|
}
|
|
88
93
|
const parts = [];
|
|
@@ -90,18 +95,18 @@ function normalizeSystem(system) {
|
|
|
90
95
|
if (!part || typeof part !== "object" || !("text" in part)) {
|
|
91
96
|
throw new UPPError(
|
|
92
97
|
"Google system prompt array must contain text parts",
|
|
93
|
-
|
|
98
|
+
ErrorCode.InvalidRequest,
|
|
94
99
|
"google",
|
|
95
|
-
|
|
100
|
+
ModalityType.LLM
|
|
96
101
|
);
|
|
97
102
|
}
|
|
98
103
|
const textValue = part.text;
|
|
99
104
|
if (typeof textValue !== "string") {
|
|
100
105
|
throw new UPPError(
|
|
101
106
|
"Google system prompt text must be a string",
|
|
102
|
-
|
|
107
|
+
ErrorCode.InvalidRequest,
|
|
103
108
|
"google",
|
|
104
|
-
|
|
109
|
+
ModalityType.LLM
|
|
105
110
|
);
|
|
106
111
|
}
|
|
107
112
|
parts.push(part);
|
|
@@ -308,7 +313,7 @@ function createStreamState() {
|
|
|
308
313
|
function transformStreamChunk(chunk, state) {
|
|
309
314
|
const events = [];
|
|
310
315
|
if (state.isFirstChunk) {
|
|
311
|
-
events.push({ type:
|
|
316
|
+
events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });
|
|
312
317
|
state.isFirstChunk = false;
|
|
313
318
|
}
|
|
314
319
|
if (chunk.usageMetadata) {
|
|
@@ -324,7 +329,7 @@ function transformStreamChunk(chunk, state) {
|
|
|
324
329
|
if ("text" in part) {
|
|
325
330
|
state.content += part.text;
|
|
326
331
|
events.push({
|
|
327
|
-
type:
|
|
332
|
+
type: StreamEventType.TextDelta,
|
|
328
333
|
index: 0,
|
|
329
334
|
delta: { text: part.text }
|
|
330
335
|
});
|
|
@@ -338,7 +343,7 @@ function transformStreamChunk(chunk, state) {
|
|
|
338
343
|
thoughtSignature: fc.thoughtSignature
|
|
339
344
|
});
|
|
340
345
|
events.push({
|
|
341
|
-
type:
|
|
346
|
+
type: StreamEventType.ToolCallDelta,
|
|
342
347
|
index: state.toolCalls.length - 1,
|
|
343
348
|
delta: {
|
|
344
349
|
toolCallId,
|
|
@@ -355,7 +360,7 @@ ${codeResult.codeExecutionResult.output}\`\`\`
|
|
|
355
360
|
`;
|
|
356
361
|
state.content += outputText;
|
|
357
362
|
events.push({
|
|
358
|
-
type:
|
|
363
|
+
type: StreamEventType.TextDelta,
|
|
359
364
|
index: 0,
|
|
360
365
|
delta: { text: outputText }
|
|
361
366
|
});
|
|
@@ -364,7 +369,7 @@ ${codeResult.codeExecutionResult.output}\`\`\`
|
|
|
364
369
|
}
|
|
365
370
|
if (candidate.finishReason) {
|
|
366
371
|
state.finishReason = candidate.finishReason;
|
|
367
|
-
events.push({ type:
|
|
372
|
+
events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });
|
|
368
373
|
}
|
|
369
374
|
return events;
|
|
370
375
|
}
|
|
@@ -458,9 +463,9 @@ function createLLMHandler() {
|
|
|
458
463
|
if (!providerRef) {
|
|
459
464
|
throw new UPPError(
|
|
460
465
|
"Provider reference not set. Handler must be used with createProvider().",
|
|
461
|
-
|
|
466
|
+
ErrorCode.InvalidRequest,
|
|
462
467
|
"google",
|
|
463
|
-
|
|
468
|
+
ModalityType.LLM
|
|
464
469
|
);
|
|
465
470
|
}
|
|
466
471
|
const model = {
|
|
@@ -554,9 +559,9 @@ function createLLMHandler() {
|
|
|
554
559
|
if (!response.body) {
|
|
555
560
|
const error = new UPPError(
|
|
556
561
|
"No response body for streaming request",
|
|
557
|
-
|
|
562
|
+
ErrorCode.ProviderError,
|
|
558
563
|
"google",
|
|
559
|
-
|
|
564
|
+
ModalityType.LLM
|
|
560
565
|
);
|
|
561
566
|
responseReject(error);
|
|
562
567
|
throw error;
|
|
@@ -567,9 +572,9 @@ function createLLMHandler() {
|
|
|
567
572
|
if (chunk.error) {
|
|
568
573
|
const error = new UPPError(
|
|
569
574
|
chunk.error.message,
|
|
570
|
-
|
|
575
|
+
ErrorCode.ProviderError,
|
|
571
576
|
"google",
|
|
572
|
-
|
|
577
|
+
ModalityType.LLM
|
|
573
578
|
);
|
|
574
579
|
responseReject(error);
|
|
575
580
|
throw error;
|
|
@@ -613,9 +618,9 @@ function createEmbeddingHandler() {
|
|
|
613
618
|
if (!providerRef) {
|
|
614
619
|
throw new UPPError(
|
|
615
620
|
"Provider reference not set. Handler must be used with createProvider().",
|
|
616
|
-
|
|
621
|
+
ErrorCode.InvalidRequest,
|
|
617
622
|
"google",
|
|
618
|
-
|
|
623
|
+
ModalityType.Embedding
|
|
619
624
|
);
|
|
620
625
|
}
|
|
621
626
|
const model = {
|
|
@@ -639,9 +644,9 @@ function createEmbeddingHandler() {
|
|
|
639
644
|
if (!text) {
|
|
640
645
|
throw new UPPError(
|
|
641
646
|
"Google embeddings only support text input",
|
|
642
|
-
|
|
647
|
+
ErrorCode.InvalidRequest,
|
|
643
648
|
"google",
|
|
644
|
-
|
|
649
|
+
ModalityType.Embedding
|
|
645
650
|
);
|
|
646
651
|
}
|
|
647
652
|
const embedRequest = {
|
|
@@ -713,9 +718,9 @@ function createImageHandler() {
|
|
|
713
718
|
if (!providerRef) {
|
|
714
719
|
throw new UPPError(
|
|
715
720
|
"Provider reference not set. Handler must be used with createProvider().",
|
|
716
|
-
|
|
721
|
+
ErrorCode.InvalidRequest,
|
|
717
722
|
"google",
|
|
718
|
-
|
|
723
|
+
ModalityType.Image
|
|
719
724
|
);
|
|
720
725
|
}
|
|
721
726
|
const capabilities = getCapabilities();
|
|
@@ -775,9 +780,9 @@ function transformResponse2(data) {
|
|
|
775
780
|
if (!data.predictions || data.predictions.length === 0) {
|
|
776
781
|
throw new UPPError(
|
|
777
782
|
"No images in response",
|
|
778
|
-
|
|
783
|
+
ErrorCode.ProviderError,
|
|
779
784
|
"google",
|
|
780
|
-
|
|
785
|
+
ModalityType.Image
|
|
781
786
|
);
|
|
782
787
|
}
|
|
783
788
|
const images = data.predictions.map((prediction) => {
|
|
@@ -922,9 +927,9 @@ async function update(name, updateRequest, apiKey, config, signal) {
|
|
|
922
927
|
if (updateRequest.expireTime && updateRequest.ttl) {
|
|
923
928
|
throw new UPPError(
|
|
924
929
|
"Provide either expireTime or ttl (not both)",
|
|
925
|
-
|
|
930
|
+
ErrorCode.InvalidRequest,
|
|
926
931
|
"google",
|
|
927
|
-
|
|
932
|
+
ModalityType.LLM
|
|
928
933
|
);
|
|
929
934
|
}
|
|
930
935
|
const updateMaskParts = [];
|
|
@@ -937,9 +942,9 @@ async function update(name, updateRequest, apiKey, config, signal) {
|
|
|
937
942
|
if (updateMaskParts.length === 0) {
|
|
938
943
|
throw new UPPError(
|
|
939
944
|
"Update request must include expireTime or ttl",
|
|
940
|
-
|
|
945
|
+
ErrorCode.InvalidRequest,
|
|
941
946
|
"google",
|
|
942
|
-
|
|
947
|
+
ModalityType.LLM
|
|
943
948
|
);
|
|
944
949
|
}
|
|
945
950
|
const cacheName = name.startsWith("cachedContents/") ? name : `cachedContents/${name}`;
|