@providerprotocol/ai 0.0.22 → 0.0.24
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 +95 -36
- 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-M4BMM5IB.js → chunk-6AZVUI6H.js} +20 -4
- package/dist/chunk-6AZVUI6H.js.map +1 -0
- package/dist/chunk-73IIE3QT.js +120 -0
- package/dist/chunk-73IIE3QT.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-NWS5IKNR.js → chunk-TOJCZMVU.js} +3 -12
- package/dist/chunk-TOJCZMVU.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 +36 -4
- package/dist/google/index.js +98 -53
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +4 -4
- package/dist/index.d.ts +8 -6
- package/dist/index.js +92 -122
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +5 -2
- package/dist/ollama/index.js +47 -36
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +117 -56
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +1 -1
- package/dist/openrouter/index.js +58 -53
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-DWEAzeM5.d.ts → provider-x4RocsnK.d.ts} +199 -54
- 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-DTfjXXPh.d.ts} +1 -1
- package/dist/{stream-DbkLOIbJ.d.ts → stream-ITNFNnO4.d.ts} +95 -38
- package/dist/xai/index.d.ts +1 -1
- package/dist/xai/index.js +221 -97
- 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-NWS5IKNR.js.map +0 -1
- package/dist/chunk-RFWLEFAB.js.map +0 -1
- package/dist/chunk-RS7C25LS.js.map +0 -1
package/dist/openai/index.js
CHANGED
|
@@ -3,7 +3,10 @@ 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,
|
|
@@ -11,20 +14,22 @@ import {
|
|
|
11
14
|
isAssistantMessage,
|
|
12
15
|
isToolResultMessage,
|
|
13
16
|
isUserMessage
|
|
14
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-6AZVUI6H.js";
|
|
15
18
|
import {
|
|
16
19
|
parseSSEStream
|
|
17
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-TOJCZMVU.js";
|
|
18
21
|
import {
|
|
19
22
|
resolveApiKey
|
|
20
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-55X3W2MN.js";
|
|
21
24
|
import {
|
|
25
|
+
ErrorCode,
|
|
26
|
+
ModalityType,
|
|
22
27
|
UPPError,
|
|
23
28
|
doFetch,
|
|
24
29
|
doStreamFetch,
|
|
25
30
|
normalizeHttpError,
|
|
26
31
|
toError
|
|
27
|
-
} from "../chunk-
|
|
32
|
+
} from "../chunk-QNJO7DSD.js";
|
|
28
33
|
|
|
29
34
|
// src/providers/openai/transform.completions.ts
|
|
30
35
|
function transformRequest(request, modelId) {
|
|
@@ -65,9 +70,9 @@ function normalizeSystem(system) {
|
|
|
65
70
|
if (!Array.isArray(system)) {
|
|
66
71
|
throw new UPPError(
|
|
67
72
|
"System prompt must be a string or an array of text blocks",
|
|
68
|
-
|
|
73
|
+
ErrorCode.InvalidRequest,
|
|
69
74
|
"openai",
|
|
70
|
-
|
|
75
|
+
ModalityType.LLM
|
|
71
76
|
);
|
|
72
77
|
}
|
|
73
78
|
const texts = [];
|
|
@@ -75,18 +80,18 @@ function normalizeSystem(system) {
|
|
|
75
80
|
if (!block || typeof block !== "object" || !("text" in block)) {
|
|
76
81
|
throw new UPPError(
|
|
77
82
|
"System prompt array must contain objects with a text field",
|
|
78
|
-
|
|
83
|
+
ErrorCode.InvalidRequest,
|
|
79
84
|
"openai",
|
|
80
|
-
|
|
85
|
+
ModalityType.LLM
|
|
81
86
|
);
|
|
82
87
|
}
|
|
83
88
|
const textValue = block.text;
|
|
84
89
|
if (typeof textValue !== "string") {
|
|
85
90
|
throw new UPPError(
|
|
86
91
|
"System prompt text must be a string",
|
|
87
|
-
|
|
92
|
+
ErrorCode.InvalidRequest,
|
|
88
93
|
"openai",
|
|
89
|
-
|
|
94
|
+
ModalityType.LLM
|
|
90
95
|
);
|
|
91
96
|
}
|
|
92
97
|
if (textValue.length > 0) {
|
|
@@ -321,7 +326,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
321
326
|
const events = [];
|
|
322
327
|
if (chunk.id && !state.id) {
|
|
323
328
|
state.id = chunk.id;
|
|
324
|
-
events.push({ type:
|
|
329
|
+
events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });
|
|
325
330
|
}
|
|
326
331
|
if (chunk.model) {
|
|
327
332
|
state.model = chunk.model;
|
|
@@ -331,7 +336,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
331
336
|
if (choice.delta.content) {
|
|
332
337
|
state.text += choice.delta.content;
|
|
333
338
|
events.push({
|
|
334
|
-
type:
|
|
339
|
+
type: StreamEventType.TextDelta,
|
|
335
340
|
index: 0,
|
|
336
341
|
delta: { text: choice.delta.content }
|
|
337
342
|
});
|
|
@@ -340,7 +345,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
340
345
|
state.hadRefusal = true;
|
|
341
346
|
state.text += choice.delta.refusal;
|
|
342
347
|
events.push({
|
|
343
|
-
type:
|
|
348
|
+
type: StreamEventType.TextDelta,
|
|
344
349
|
index: 0,
|
|
345
350
|
delta: { text: choice.delta.refusal }
|
|
346
351
|
});
|
|
@@ -362,7 +367,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
362
367
|
if (toolCallDelta.function?.arguments) {
|
|
363
368
|
toolCall.arguments += toolCallDelta.function.arguments;
|
|
364
369
|
events.push({
|
|
365
|
-
type:
|
|
370
|
+
type: StreamEventType.ToolCallDelta,
|
|
366
371
|
index,
|
|
367
372
|
delta: {
|
|
368
373
|
toolCallId: toolCall.id,
|
|
@@ -375,7 +380,7 @@ function transformStreamEvent(chunk, state) {
|
|
|
375
380
|
}
|
|
376
381
|
if (choice.finish_reason) {
|
|
377
382
|
state.finishReason = choice.finish_reason;
|
|
378
|
-
events.push({ type:
|
|
383
|
+
events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });
|
|
379
384
|
}
|
|
380
385
|
}
|
|
381
386
|
if (chunk.usage) {
|
|
@@ -477,9 +482,9 @@ function createCompletionsLLMHandler() {
|
|
|
477
482
|
if (!providerRef) {
|
|
478
483
|
throw new UPPError(
|
|
479
484
|
"Provider reference not set. Handler must be used with createProvider() or have _setProvider called.",
|
|
480
|
-
|
|
485
|
+
ErrorCode.InvalidRequest,
|
|
481
486
|
"openai",
|
|
482
|
-
|
|
487
|
+
ModalityType.LLM
|
|
483
488
|
);
|
|
484
489
|
}
|
|
485
490
|
const model = {
|
|
@@ -575,9 +580,9 @@ function createCompletionsLLMHandler() {
|
|
|
575
580
|
if (!response.body) {
|
|
576
581
|
const error = new UPPError(
|
|
577
582
|
"No response body for streaming request",
|
|
578
|
-
|
|
583
|
+
ErrorCode.ProviderError,
|
|
579
584
|
"openai",
|
|
580
|
-
|
|
585
|
+
ModalityType.LLM
|
|
581
586
|
);
|
|
582
587
|
responseReject(error);
|
|
583
588
|
throw error;
|
|
@@ -592,9 +597,9 @@ function createCompletionsLLMHandler() {
|
|
|
592
597
|
const errorData = chunk.error;
|
|
593
598
|
const error = new UPPError(
|
|
594
599
|
errorData.message ?? "Unknown error",
|
|
595
|
-
|
|
600
|
+
ErrorCode.ProviderError,
|
|
596
601
|
"openai",
|
|
597
|
-
|
|
602
|
+
ModalityType.LLM
|
|
598
603
|
);
|
|
599
604
|
responseReject(error);
|
|
600
605
|
throw error;
|
|
@@ -670,9 +675,9 @@ function normalizeSystem2(system) {
|
|
|
670
675
|
if (!Array.isArray(system)) {
|
|
671
676
|
throw new UPPError(
|
|
672
677
|
"System prompt must be a string or an array of text blocks",
|
|
673
|
-
|
|
678
|
+
ErrorCode.InvalidRequest,
|
|
674
679
|
"openai",
|
|
675
|
-
|
|
680
|
+
ModalityType.LLM
|
|
676
681
|
);
|
|
677
682
|
}
|
|
678
683
|
const texts = [];
|
|
@@ -680,18 +685,18 @@ function normalizeSystem2(system) {
|
|
|
680
685
|
if (!block || typeof block !== "object" || !("text" in block)) {
|
|
681
686
|
throw new UPPError(
|
|
682
687
|
"System prompt array must contain objects with a text field",
|
|
683
|
-
|
|
688
|
+
ErrorCode.InvalidRequest,
|
|
684
689
|
"openai",
|
|
685
|
-
|
|
690
|
+
ModalityType.LLM
|
|
686
691
|
);
|
|
687
692
|
}
|
|
688
693
|
const textValue = block.text;
|
|
689
694
|
if (typeof textValue !== "string") {
|
|
690
695
|
throw new UPPError(
|
|
691
696
|
"System prompt text must be a string",
|
|
692
|
-
|
|
697
|
+
ErrorCode.InvalidRequest,
|
|
693
698
|
"openai",
|
|
694
|
-
|
|
699
|
+
ModalityType.LLM
|
|
695
700
|
);
|
|
696
701
|
}
|
|
697
702
|
if (textValue.length > 0) {
|
|
@@ -761,6 +766,18 @@ function transformMessage2(message) {
|
|
|
761
766
|
}
|
|
762
767
|
const openaiMeta = message.metadata?.openai;
|
|
763
768
|
const functionCallItems = openaiMeta?.functionCallItems;
|
|
769
|
+
if (openaiMeta?.reasoningEncryptedContent) {
|
|
770
|
+
try {
|
|
771
|
+
const reasoningData = JSON.parse(openaiMeta.reasoningEncryptedContent);
|
|
772
|
+
items.push({
|
|
773
|
+
type: "reasoning",
|
|
774
|
+
id: reasoningData.id,
|
|
775
|
+
summary: reasoningData.summary,
|
|
776
|
+
encrypted_content: reasoningData.encrypted_content
|
|
777
|
+
});
|
|
778
|
+
} catch {
|
|
779
|
+
}
|
|
780
|
+
}
|
|
764
781
|
if (functionCallItems && functionCallItems.length > 0) {
|
|
765
782
|
for (const fc of functionCallItems) {
|
|
766
783
|
items.push({
|
|
@@ -851,6 +868,7 @@ function transformResponse2(data) {
|
|
|
851
868
|
const functionCallItems = [];
|
|
852
869
|
let hadRefusal = false;
|
|
853
870
|
let structuredData;
|
|
871
|
+
let reasoningEncryptedContent;
|
|
854
872
|
for (const item of data.output) {
|
|
855
873
|
if (item.type === "message") {
|
|
856
874
|
const messageItem = item;
|
|
@@ -896,6 +914,17 @@ function transformResponse2(data) {
|
|
|
896
914
|
source: { type: "base64", data: imageGen.result }
|
|
897
915
|
});
|
|
898
916
|
}
|
|
917
|
+
} else if (item.type === "reasoning") {
|
|
918
|
+
const reasoningItem = item;
|
|
919
|
+
const reasoningText = reasoningItem.summary.filter((s) => s.type === "summary_text").map((s) => s.text).join("");
|
|
920
|
+
if (reasoningText) {
|
|
921
|
+
content.push({ type: "reasoning", text: reasoningText });
|
|
922
|
+
}
|
|
923
|
+
reasoningEncryptedContent = JSON.stringify({
|
|
924
|
+
id: reasoningItem.id,
|
|
925
|
+
summary: reasoningItem.summary,
|
|
926
|
+
encrypted_content: reasoningItem.encrypted_content
|
|
927
|
+
});
|
|
899
928
|
}
|
|
900
929
|
}
|
|
901
930
|
const responseId = data.id || generateId();
|
|
@@ -909,7 +938,9 @@ function transformResponse2(data) {
|
|
|
909
938
|
model: data.model,
|
|
910
939
|
status: data.status,
|
|
911
940
|
response_id: responseId,
|
|
912
|
-
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0
|
|
941
|
+
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0,
|
|
942
|
+
// Store encrypted reasoning content for multi-turn context (stateless mode)
|
|
943
|
+
reasoningEncryptedContent
|
|
913
944
|
}
|
|
914
945
|
}
|
|
915
946
|
}
|
|
@@ -944,6 +975,7 @@ function createStreamState2() {
|
|
|
944
975
|
id: "",
|
|
945
976
|
model: "",
|
|
946
977
|
textByIndex: /* @__PURE__ */ new Map(),
|
|
978
|
+
reasoningByIndex: /* @__PURE__ */ new Map(),
|
|
947
979
|
toolCalls: /* @__PURE__ */ new Map(),
|
|
948
980
|
images: [],
|
|
949
981
|
status: "in_progress",
|
|
@@ -974,18 +1006,18 @@ function transformStreamEvent2(event, state) {
|
|
|
974
1006
|
switch (event.type) {
|
|
975
1007
|
case "response.created":
|
|
976
1008
|
updateFromResponse(event.response);
|
|
977
|
-
events.push({ type:
|
|
1009
|
+
events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });
|
|
978
1010
|
break;
|
|
979
1011
|
case "response.in_progress":
|
|
980
1012
|
updateFromResponse(event.response);
|
|
981
1013
|
break;
|
|
982
1014
|
case "response.completed":
|
|
983
1015
|
updateFromResponse(event.response);
|
|
984
|
-
events.push({ type:
|
|
1016
|
+
events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });
|
|
985
1017
|
break;
|
|
986
1018
|
case "response.failed":
|
|
987
1019
|
updateFromResponse(event.response);
|
|
988
|
-
events.push({ type:
|
|
1020
|
+
events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });
|
|
989
1021
|
break;
|
|
990
1022
|
case "response.output_item.added":
|
|
991
1023
|
if (event.item.type === "function_call") {
|
|
@@ -1002,7 +1034,7 @@ function transformStreamEvent2(event, state) {
|
|
|
1002
1034
|
state.toolCalls.set(event.output_index, existing);
|
|
1003
1035
|
}
|
|
1004
1036
|
events.push({
|
|
1005
|
-
type:
|
|
1037
|
+
type: StreamEventType.ContentBlockStart,
|
|
1006
1038
|
index: event.output_index,
|
|
1007
1039
|
delta: {}
|
|
1008
1040
|
});
|
|
@@ -1028,9 +1060,16 @@ function transformStreamEvent2(event, state) {
|
|
|
1028
1060
|
mimeType: imageGen.mime_type ?? "image/png"
|
|
1029
1061
|
});
|
|
1030
1062
|
}
|
|
1063
|
+
} else if (event.item.type === "reasoning") {
|
|
1064
|
+
const reasoningItem = event.item;
|
|
1065
|
+
state.reasoningEncryptedContent = JSON.stringify({
|
|
1066
|
+
id: reasoningItem.id,
|
|
1067
|
+
summary: reasoningItem.summary,
|
|
1068
|
+
encrypted_content: reasoningItem.encrypted_content
|
|
1069
|
+
});
|
|
1031
1070
|
}
|
|
1032
1071
|
events.push({
|
|
1033
|
-
type:
|
|
1072
|
+
type: StreamEventType.ContentBlockStop,
|
|
1034
1073
|
index: event.output_index,
|
|
1035
1074
|
delta: {}
|
|
1036
1075
|
});
|
|
@@ -1039,7 +1078,7 @@ function transformStreamEvent2(event, state) {
|
|
|
1039
1078
|
const currentText = state.textByIndex.get(event.output_index) ?? "";
|
|
1040
1079
|
state.textByIndex.set(event.output_index, currentText + event.delta);
|
|
1041
1080
|
events.push({
|
|
1042
|
-
type:
|
|
1081
|
+
type: StreamEventType.TextDelta,
|
|
1043
1082
|
index: event.output_index,
|
|
1044
1083
|
delta: { text: event.delta }
|
|
1045
1084
|
});
|
|
@@ -1053,7 +1092,7 @@ function transformStreamEvent2(event, state) {
|
|
|
1053
1092
|
const currentRefusal = state.textByIndex.get(event.output_index) ?? "";
|
|
1054
1093
|
state.textByIndex.set(event.output_index, currentRefusal + event.delta);
|
|
1055
1094
|
events.push({
|
|
1056
|
-
type:
|
|
1095
|
+
type: StreamEventType.TextDelta,
|
|
1057
1096
|
index: event.output_index,
|
|
1058
1097
|
delta: { text: event.delta }
|
|
1059
1098
|
});
|
|
@@ -1077,7 +1116,7 @@ function transformStreamEvent2(event, state) {
|
|
|
1077
1116
|
}
|
|
1078
1117
|
toolCall.arguments += event.delta;
|
|
1079
1118
|
events.push({
|
|
1080
|
-
type:
|
|
1119
|
+
type: StreamEventType.ToolCallDelta,
|
|
1081
1120
|
index: event.output_index,
|
|
1082
1121
|
delta: {
|
|
1083
1122
|
toolCallId: toolCall.callId ?? toolCall.itemId ?? "",
|
|
@@ -1103,6 +1142,19 @@ function transformStreamEvent2(event, state) {
|
|
|
1103
1142
|
toolCall.arguments = event.arguments;
|
|
1104
1143
|
break;
|
|
1105
1144
|
}
|
|
1145
|
+
case "response.reasoning_summary_text.delta": {
|
|
1146
|
+
const currentReasoning = state.reasoningByIndex.get(event.output_index) ?? "";
|
|
1147
|
+
state.reasoningByIndex.set(event.output_index, currentReasoning + event.delta);
|
|
1148
|
+
events.push({
|
|
1149
|
+
type: StreamEventType.ReasoningDelta,
|
|
1150
|
+
index: event.output_index,
|
|
1151
|
+
delta: { text: event.delta }
|
|
1152
|
+
});
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
case "response.reasoning_summary_text.done":
|
|
1156
|
+
state.reasoningByIndex.set(event.output_index, event.text);
|
|
1157
|
+
break;
|
|
1106
1158
|
case "error":
|
|
1107
1159
|
break;
|
|
1108
1160
|
default:
|
|
@@ -1113,6 +1165,14 @@ function transformStreamEvent2(event, state) {
|
|
|
1113
1165
|
function buildResponseFromState2(state) {
|
|
1114
1166
|
const content = [];
|
|
1115
1167
|
let structuredData;
|
|
1168
|
+
const orderedReasoningEntries = [...state.reasoningByIndex.entries()].sort(
|
|
1169
|
+
([leftIndex], [rightIndex]) => leftIndex - rightIndex
|
|
1170
|
+
);
|
|
1171
|
+
for (const [, reasoning] of orderedReasoningEntries) {
|
|
1172
|
+
if (reasoning) {
|
|
1173
|
+
content.push({ type: "reasoning", text: reasoning });
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1116
1176
|
const orderedTextEntries = [...state.textByIndex.entries()].sort(
|
|
1117
1177
|
([leftIndex], [rightIndex]) => leftIndex - rightIndex
|
|
1118
1178
|
);
|
|
@@ -1178,7 +1238,8 @@ function buildResponseFromState2(state) {
|
|
|
1178
1238
|
model: state.model,
|
|
1179
1239
|
status: state.status,
|
|
1180
1240
|
response_id: responseId,
|
|
1181
|
-
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0
|
|
1241
|
+
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0,
|
|
1242
|
+
reasoningEncryptedContent: state.reasoningEncryptedContent
|
|
1182
1243
|
}
|
|
1183
1244
|
}
|
|
1184
1245
|
}
|
|
@@ -1229,9 +1290,9 @@ function createResponsesLLMHandler() {
|
|
|
1229
1290
|
if (!providerRef) {
|
|
1230
1291
|
throw new UPPError(
|
|
1231
1292
|
"Provider reference not set. Handler must be used with createProvider() or have _setProvider called.",
|
|
1232
|
-
|
|
1293
|
+
ErrorCode.InvalidRequest,
|
|
1233
1294
|
"openai",
|
|
1234
|
-
|
|
1295
|
+
ModalityType.LLM
|
|
1235
1296
|
);
|
|
1236
1297
|
}
|
|
1237
1298
|
const model = {
|
|
@@ -1276,9 +1337,9 @@ function createResponsesLLMHandler() {
|
|
|
1276
1337
|
if (data.status === "failed" && data.error) {
|
|
1277
1338
|
throw new UPPError(
|
|
1278
1339
|
data.error.message,
|
|
1279
|
-
|
|
1340
|
+
ErrorCode.ProviderError,
|
|
1280
1341
|
"openai",
|
|
1281
|
-
|
|
1342
|
+
ModalityType.LLM
|
|
1282
1343
|
);
|
|
1283
1344
|
}
|
|
1284
1345
|
return transformResponse2(data);
|
|
@@ -1334,9 +1395,9 @@ function createResponsesLLMHandler() {
|
|
|
1334
1395
|
if (!response.body) {
|
|
1335
1396
|
const error = new UPPError(
|
|
1336
1397
|
"No response body for streaming request",
|
|
1337
|
-
|
|
1398
|
+
ErrorCode.ProviderError,
|
|
1338
1399
|
"openai",
|
|
1339
|
-
|
|
1400
|
+
ModalityType.LLM
|
|
1340
1401
|
);
|
|
1341
1402
|
responseReject(error);
|
|
1342
1403
|
throw error;
|
|
@@ -1351,9 +1412,9 @@ function createResponsesLLMHandler() {
|
|
|
1351
1412
|
const errorEvent = event;
|
|
1352
1413
|
const error = new UPPError(
|
|
1353
1414
|
errorEvent.error.message,
|
|
1354
|
-
|
|
1415
|
+
ErrorCode.ProviderError,
|
|
1355
1416
|
"openai",
|
|
1356
|
-
|
|
1417
|
+
ModalityType.LLM
|
|
1357
1418
|
);
|
|
1358
1419
|
responseReject(error);
|
|
1359
1420
|
throw error;
|
|
@@ -1406,9 +1467,9 @@ function createEmbeddingHandler() {
|
|
|
1406
1467
|
if (!providerRef) {
|
|
1407
1468
|
throw new UPPError(
|
|
1408
1469
|
"Provider reference not set. Handler must be used with createProvider().",
|
|
1409
|
-
|
|
1470
|
+
ErrorCode.InvalidRequest,
|
|
1410
1471
|
"openai",
|
|
1411
|
-
|
|
1472
|
+
ModalityType.Embedding
|
|
1412
1473
|
);
|
|
1413
1474
|
}
|
|
1414
1475
|
const model = {
|
|
@@ -1436,9 +1497,9 @@ function createEmbeddingHandler() {
|
|
|
1436
1497
|
}
|
|
1437
1498
|
throw new UPPError(
|
|
1438
1499
|
"OpenAI embeddings only support text input",
|
|
1439
|
-
|
|
1500
|
+
ErrorCode.InvalidRequest,
|
|
1440
1501
|
"openai",
|
|
1441
|
-
|
|
1502
|
+
ModalityType.Embedding
|
|
1442
1503
|
);
|
|
1443
1504
|
});
|
|
1444
1505
|
const body = {
|
|
@@ -1501,9 +1562,9 @@ function createImageHandler() {
|
|
|
1501
1562
|
if (!providerRef) {
|
|
1502
1563
|
throw new UPPError(
|
|
1503
1564
|
"Provider reference not set. Handler must be used with createProvider().",
|
|
1504
|
-
|
|
1565
|
+
ErrorCode.InvalidRequest,
|
|
1505
1566
|
"openai",
|
|
1506
|
-
|
|
1567
|
+
ModalityType.Image
|
|
1507
1568
|
);
|
|
1508
1569
|
}
|
|
1509
1570
|
const capabilities = getCapabilities(modelId);
|
|
@@ -1653,9 +1714,9 @@ function executeStream(modelId, request) {
|
|
|
1653
1714
|
if (!reader) {
|
|
1654
1715
|
throw new UPPError(
|
|
1655
1716
|
"No response body for streaming",
|
|
1656
|
-
|
|
1717
|
+
ErrorCode.ProviderError,
|
|
1657
1718
|
"openai",
|
|
1658
|
-
|
|
1719
|
+
ModalityType.Image
|
|
1659
1720
|
);
|
|
1660
1721
|
}
|
|
1661
1722
|
const decoder = new TextDecoder();
|
|
@@ -1772,9 +1833,9 @@ function transformResponse3(data) {
|
|
|
1772
1833
|
} else {
|
|
1773
1834
|
throw new UPPError(
|
|
1774
1835
|
"No image data in response",
|
|
1775
|
-
|
|
1836
|
+
ErrorCode.ProviderError,
|
|
1776
1837
|
"openai",
|
|
1777
|
-
|
|
1838
|
+
ModalityType.Image
|
|
1778
1839
|
);
|
|
1779
1840
|
}
|
|
1780
1841
|
return {
|