@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/index.js
CHANGED
|
@@ -6,9 +6,22 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
Image
|
|
8
8
|
} from "./chunk-WAKD3OO5.js";
|
|
9
|
+
import {
|
|
10
|
+
StreamEventType,
|
|
11
|
+
contentBlockStart,
|
|
12
|
+
contentBlockStop,
|
|
13
|
+
createStreamResult,
|
|
14
|
+
messageStart,
|
|
15
|
+
messageStop,
|
|
16
|
+
textDelta,
|
|
17
|
+
toolCallDelta,
|
|
18
|
+
toolExecutionEnd,
|
|
19
|
+
toolExecutionStart
|
|
20
|
+
} from "./chunk-73IIE3QT.js";
|
|
9
21
|
import {
|
|
10
22
|
AssistantMessage,
|
|
11
23
|
Message,
|
|
24
|
+
MessageRole,
|
|
12
25
|
ToolResultMessage,
|
|
13
26
|
UserMessage,
|
|
14
27
|
createProvider,
|
|
@@ -19,124 +32,65 @@ import {
|
|
|
19
32
|
resolveEmbeddingHandler,
|
|
20
33
|
resolveImageHandler,
|
|
21
34
|
resolveLLMHandler
|
|
22
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-MF5ETY5O.js";
|
|
23
36
|
import {
|
|
24
37
|
ExponentialBackoff,
|
|
25
38
|
LinearBackoff,
|
|
26
39
|
NoRetry,
|
|
27
40
|
RetryAfterStrategy,
|
|
28
41
|
TokenBucket
|
|
29
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-SBCATNHA.js";
|
|
30
43
|
import "./chunk-NWS5IKNR.js";
|
|
31
44
|
import {
|
|
32
45
|
DynamicKey,
|
|
33
46
|
RoundRobinKeys,
|
|
34
47
|
WeightedKeys
|
|
35
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-55X3W2MN.js";
|
|
36
49
|
import {
|
|
50
|
+
ErrorCode,
|
|
51
|
+
ModalityType,
|
|
37
52
|
UPPError,
|
|
38
53
|
toError
|
|
39
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-QNJO7DSD.js";
|
|
40
55
|
|
|
41
56
|
// src/types/content.ts
|
|
57
|
+
var ContentBlockType = {
|
|
58
|
+
/** Text content */
|
|
59
|
+
Text: "text",
|
|
60
|
+
/** Image content */
|
|
61
|
+
Image: "image",
|
|
62
|
+
/** Audio content */
|
|
63
|
+
Audio: "audio",
|
|
64
|
+
/** Video content */
|
|
65
|
+
Video: "video",
|
|
66
|
+
/** Binary/arbitrary data content */
|
|
67
|
+
Binary: "binary"
|
|
68
|
+
};
|
|
69
|
+
var ImageSourceType = {
|
|
70
|
+
/** Base64-encoded image data */
|
|
71
|
+
Base64: "base64",
|
|
72
|
+
/** URL reference to image */
|
|
73
|
+
Url: "url",
|
|
74
|
+
/** Raw bytes image data */
|
|
75
|
+
Bytes: "bytes"
|
|
76
|
+
};
|
|
42
77
|
function text(content) {
|
|
43
|
-
return { type:
|
|
78
|
+
return { type: ContentBlockType.Text, text: content };
|
|
44
79
|
}
|
|
45
80
|
function isTextBlock(block) {
|
|
46
|
-
return block.type ===
|
|
81
|
+
return block.type === ContentBlockType.Text;
|
|
47
82
|
}
|
|
48
83
|
function isImageBlock(block) {
|
|
49
|
-
return block.type ===
|
|
84
|
+
return block.type === ContentBlockType.Image;
|
|
50
85
|
}
|
|
51
86
|
function isAudioBlock(block) {
|
|
52
|
-
return block.type ===
|
|
87
|
+
return block.type === ContentBlockType.Audio;
|
|
53
88
|
}
|
|
54
89
|
function isVideoBlock(block) {
|
|
55
|
-
return block.type ===
|
|
90
|
+
return block.type === ContentBlockType.Video;
|
|
56
91
|
}
|
|
57
92
|
function isBinaryBlock(block) {
|
|
58
|
-
return block.type ===
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// src/types/stream.ts
|
|
62
|
-
function createStreamResult(generator, turnPromiseOrFactory, abortController) {
|
|
63
|
-
let cachedTurn = null;
|
|
64
|
-
const getTurn = () => {
|
|
65
|
-
if (typeof turnPromiseOrFactory === "function") {
|
|
66
|
-
if (!cachedTurn) {
|
|
67
|
-
cachedTurn = turnPromiseOrFactory();
|
|
68
|
-
}
|
|
69
|
-
return cachedTurn;
|
|
70
|
-
}
|
|
71
|
-
return turnPromiseOrFactory;
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
[Symbol.asyncIterator]() {
|
|
75
|
-
return generator;
|
|
76
|
-
},
|
|
77
|
-
get turn() {
|
|
78
|
-
return getTurn();
|
|
79
|
-
},
|
|
80
|
-
abort() {
|
|
81
|
-
abortController.abort();
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function textDelta(text2, index = 0) {
|
|
86
|
-
return {
|
|
87
|
-
type: "text_delta",
|
|
88
|
-
index,
|
|
89
|
-
delta: { text: text2 }
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function toolCallDelta(toolCallId, toolName, argumentsJson, index = 0) {
|
|
93
|
-
return {
|
|
94
|
-
type: "tool_call_delta",
|
|
95
|
-
index,
|
|
96
|
-
delta: { toolCallId, toolName, argumentsJson }
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function messageStart() {
|
|
100
|
-
return {
|
|
101
|
-
type: "message_start",
|
|
102
|
-
index: 0,
|
|
103
|
-
delta: {}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function messageStop() {
|
|
107
|
-
return {
|
|
108
|
-
type: "message_stop",
|
|
109
|
-
index: 0,
|
|
110
|
-
delta: {}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function contentBlockStart(index) {
|
|
114
|
-
return {
|
|
115
|
-
type: "content_block_start",
|
|
116
|
-
index,
|
|
117
|
-
delta: {}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function contentBlockStop(index) {
|
|
121
|
-
return {
|
|
122
|
-
type: "content_block_stop",
|
|
123
|
-
index,
|
|
124
|
-
delta: {}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function toolExecutionStart(toolCallId, toolName, timestamp, index = 0) {
|
|
128
|
-
return {
|
|
129
|
-
type: "tool_execution_start",
|
|
130
|
-
index,
|
|
131
|
-
delta: { toolCallId, toolName, timestamp }
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function toolExecutionEnd(toolCallId, toolName, result, isError, timestamp, index = 0) {
|
|
135
|
-
return {
|
|
136
|
-
type: "tool_execution_end",
|
|
137
|
-
index,
|
|
138
|
-
delta: { toolCallId, toolName, result, isError, timestamp }
|
|
139
|
-
};
|
|
93
|
+
return block.type === ContentBlockType.Binary;
|
|
140
94
|
}
|
|
141
95
|
|
|
142
96
|
// src/core/llm.ts
|
|
@@ -157,9 +111,9 @@ function llm(options) {
|
|
|
157
111
|
if (!llmHandler) {
|
|
158
112
|
throw new UPPError(
|
|
159
113
|
`Provider '${provider.name}' does not support LLM modality`,
|
|
160
|
-
|
|
114
|
+
ErrorCode.InvalidRequest,
|
|
161
115
|
provider.name,
|
|
162
|
-
|
|
116
|
+
ModalityType.LLM
|
|
163
117
|
);
|
|
164
118
|
}
|
|
165
119
|
const boundModel = llmHandler.bind(modelRef.modelId);
|
|
@@ -167,17 +121,17 @@ function llm(options) {
|
|
|
167
121
|
if (structure && !capabilities.structuredOutput) {
|
|
168
122
|
throw new UPPError(
|
|
169
123
|
`Provider '${provider.name}' does not support structured output`,
|
|
170
|
-
|
|
124
|
+
ErrorCode.InvalidRequest,
|
|
171
125
|
provider.name,
|
|
172
|
-
|
|
126
|
+
ModalityType.LLM
|
|
173
127
|
);
|
|
174
128
|
}
|
|
175
129
|
if (tools && tools.length > 0 && !capabilities.tools) {
|
|
176
130
|
throw new UPPError(
|
|
177
131
|
`Provider '${provider.name}' does not support tools`,
|
|
178
|
-
|
|
132
|
+
ErrorCode.InvalidRequest,
|
|
179
133
|
provider.name,
|
|
180
|
-
|
|
134
|
+
ModalityType.LLM
|
|
181
135
|
);
|
|
182
136
|
}
|
|
183
137
|
const instance = {
|
|
@@ -203,9 +157,9 @@ function llm(options) {
|
|
|
203
157
|
if (!capabilities.streaming) {
|
|
204
158
|
throw new UPPError(
|
|
205
159
|
`Provider '${provider.name}' does not support streaming`,
|
|
206
|
-
|
|
160
|
+
ErrorCode.InvalidRequest,
|
|
207
161
|
provider.name,
|
|
208
|
-
|
|
162
|
+
ModalityType.LLM
|
|
209
163
|
);
|
|
210
164
|
}
|
|
211
165
|
const { history, messages } = parseInputs(historyOrInput, inputs);
|
|
@@ -322,9 +276,9 @@ async function executeGenerate(model, config, system, params, tools, toolStrateg
|
|
|
322
276
|
await toolStrategy?.onMaxIterations?.(maxIterations);
|
|
323
277
|
throw new UPPError(
|
|
324
278
|
`Tool execution exceeded maximum iterations (${maxIterations})`,
|
|
325
|
-
|
|
279
|
+
ErrorCode.InvalidRequest,
|
|
326
280
|
model.provider.name,
|
|
327
|
-
|
|
281
|
+
ModalityType.LLM
|
|
328
282
|
);
|
|
329
283
|
}
|
|
330
284
|
const results = await executeTools(
|
|
@@ -385,14 +339,14 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
|
|
|
385
339
|
});
|
|
386
340
|
const maxIterations = toolStrategy?.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
387
341
|
const onAbort = () => {
|
|
388
|
-
const error = new UPPError("Stream cancelled",
|
|
342
|
+
const error = new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
|
|
389
343
|
generatorError = error;
|
|
390
344
|
rejectGenerator(error);
|
|
391
345
|
};
|
|
392
346
|
abortController.signal.addEventListener("abort", onAbort, { once: true });
|
|
393
347
|
const ensureNotAborted = () => {
|
|
394
348
|
if (abortController.signal.aborted) {
|
|
395
|
-
throw new UPPError("Stream cancelled",
|
|
349
|
+
throw new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
|
|
396
350
|
}
|
|
397
351
|
};
|
|
398
352
|
async function* generateStream() {
|
|
@@ -429,9 +383,9 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
|
|
|
429
383
|
await toolStrategy?.onMaxIterations?.(maxIterations);
|
|
430
384
|
throw new UPPError(
|
|
431
385
|
`Tool execution exceeded maximum iterations (${maxIterations})`,
|
|
432
|
-
|
|
386
|
+
ErrorCode.InvalidRequest,
|
|
433
387
|
model.provider.name,
|
|
434
|
-
|
|
388
|
+
ModalityType.LLM
|
|
435
389
|
);
|
|
436
390
|
}
|
|
437
391
|
const toolEvents = [];
|
|
@@ -461,7 +415,7 @@ function executeStream(model, config, system, params, tools, toolStrategy, struc
|
|
|
461
415
|
} finally {
|
|
462
416
|
abortController.signal.removeEventListener("abort", onAbort);
|
|
463
417
|
if (!generatorCompleted && !generatorSettled) {
|
|
464
|
-
const error = new UPPError("Stream cancelled",
|
|
418
|
+
const error = new UPPError("Stream cancelled", ErrorCode.Cancelled, model.provider.name, ModalityType.LLM);
|
|
465
419
|
generatorError = error;
|
|
466
420
|
if (!abortController.signal.aborted) {
|
|
467
421
|
abortController.abort();
|
|
@@ -630,25 +584,25 @@ function validateMediaCapabilities(messages, capabilities, providerName) {
|
|
|
630
584
|
if (block.type === "image" && !capabilities.imageInput) {
|
|
631
585
|
throw new UPPError(
|
|
632
586
|
`Provider '${providerName}' does not support image input`,
|
|
633
|
-
|
|
587
|
+
ErrorCode.InvalidRequest,
|
|
634
588
|
providerName,
|
|
635
|
-
|
|
589
|
+
ModalityType.LLM
|
|
636
590
|
);
|
|
637
591
|
}
|
|
638
592
|
if (block.type === "video" && !capabilities.videoInput) {
|
|
639
593
|
throw new UPPError(
|
|
640
594
|
`Provider '${providerName}' does not support video input`,
|
|
641
|
-
|
|
595
|
+
ErrorCode.InvalidRequest,
|
|
642
596
|
providerName,
|
|
643
|
-
|
|
597
|
+
ModalityType.LLM
|
|
644
598
|
);
|
|
645
599
|
}
|
|
646
600
|
if (block.type === "audio" && !capabilities.audioInput) {
|
|
647
601
|
throw new UPPError(
|
|
648
602
|
`Provider '${providerName}' does not support audio input`,
|
|
649
|
-
|
|
603
|
+
ErrorCode.InvalidRequest,
|
|
650
604
|
providerName,
|
|
651
|
-
|
|
605
|
+
ModalityType.LLM
|
|
652
606
|
);
|
|
653
607
|
}
|
|
654
608
|
}
|
|
@@ -672,9 +626,9 @@ function embedding(options) {
|
|
|
672
626
|
if (!handler) {
|
|
673
627
|
throw new UPPError(
|
|
674
628
|
`Provider '${provider.name}' does not support embedding modality`,
|
|
675
|
-
|
|
629
|
+
ErrorCode.InvalidRequest,
|
|
676
630
|
provider.name,
|
|
677
|
-
|
|
631
|
+
ModalityType.Embedding
|
|
678
632
|
);
|
|
679
633
|
}
|
|
680
634
|
const boundModel = handler.bind(modelRef.modelId);
|
|
@@ -735,9 +689,9 @@ function decodeBase64(b64, providerName) {
|
|
|
735
689
|
const cause = error instanceof Error ? error : new Error("Failed to decode base64 vector");
|
|
736
690
|
throw new UPPError(
|
|
737
691
|
"Invalid base64 embedding vector",
|
|
738
|
-
|
|
692
|
+
ErrorCode.InvalidResponse,
|
|
739
693
|
providerName,
|
|
740
|
-
|
|
694
|
+
ModalityType.Embedding,
|
|
741
695
|
void 0,
|
|
742
696
|
cause
|
|
743
697
|
);
|
|
@@ -766,9 +720,9 @@ function createChunkedStream(model, inputs, params, config, options) {
|
|
|
766
720
|
});
|
|
767
721
|
const cancelError = () => new UPPError(
|
|
768
722
|
"Embedding cancelled",
|
|
769
|
-
|
|
723
|
+
ErrorCode.Cancelled,
|
|
770
724
|
model.provider.name,
|
|
771
|
-
|
|
725
|
+
ModalityType.Embedding
|
|
772
726
|
);
|
|
773
727
|
const onAbort = () => {
|
|
774
728
|
rejectResult(cancelError());
|
|
@@ -875,9 +829,9 @@ function image(options) {
|
|
|
875
829
|
if (!imageHandler) {
|
|
876
830
|
throw new UPPError(
|
|
877
831
|
`Provider '${provider.name}' does not support image modality`,
|
|
878
|
-
|
|
832
|
+
ErrorCode.InvalidRequest,
|
|
879
833
|
provider.name,
|
|
880
|
-
|
|
834
|
+
ModalityType.Image
|
|
881
835
|
);
|
|
882
836
|
}
|
|
883
837
|
const boundModel = imageHandler.bind(modelRef.modelId);
|
|
@@ -887,7 +841,7 @@ function image(options) {
|
|
|
887
841
|
return error;
|
|
888
842
|
}
|
|
889
843
|
const err = toError(error);
|
|
890
|
-
return new UPPError(err.message,
|
|
844
|
+
return new UPPError(err.message, ErrorCode.ProviderError, provider.name, ModalityType.Image, void 0, err);
|
|
891
845
|
};
|
|
892
846
|
const instance = {
|
|
893
847
|
model: boundModel,
|
|
@@ -1240,14 +1194,20 @@ var ai = {
|
|
|
1240
1194
|
};
|
|
1241
1195
|
export {
|
|
1242
1196
|
AssistantMessage,
|
|
1197
|
+
ContentBlockType,
|
|
1243
1198
|
DynamicKey,
|
|
1199
|
+
ErrorCode,
|
|
1244
1200
|
ExponentialBackoff,
|
|
1245
1201
|
Image,
|
|
1202
|
+
ImageSourceType,
|
|
1246
1203
|
LinearBackoff,
|
|
1247
1204
|
Message,
|
|
1205
|
+
MessageRole,
|
|
1206
|
+
ModalityType,
|
|
1248
1207
|
NoRetry,
|
|
1249
1208
|
RetryAfterStrategy,
|
|
1250
1209
|
RoundRobinKeys,
|
|
1210
|
+
StreamEventType,
|
|
1251
1211
|
Thread,
|
|
1252
1212
|
TokenBucket,
|
|
1253
1213
|
ToolResultMessage,
|