@roomle/embedding-lib 0.0.0-dev-1bd05f2 → 0.0.0-dev-7e3cd4b
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/THIRD-PARTY-NOTICES.txt +554 -2
- package/coerce-CqJod_GZ.mjs +8 -0
- package/coerce-CsI42_k0.mjs +6 -0
- package/configurator.d.ts +2 -0
- package/configurator.js +29 -0
- package/configurator.min.js +27 -0
- package/dist-5jYYtT4q.mjs +8216 -0
- package/dist-B9yy8ym8.mjs +5512 -0
- package/dist-BV-32IEX.mjs +8128 -0
- package/dist-Bb2L1Zel.mjs +6045 -0
- package/dist-Bo3WzRdf.mjs +6223 -0
- package/dist-Bt1FopV4.mjs +7594 -0
- package/dist-C5fKJXpB.mjs +5598 -0
- package/dist-COgAdYY1.mjs +7554 -0
- package/dist-CXemOs84.mjs +849 -0
- package/dist-CqP0aX0A.mjs +866 -0
- package/dist-CqpDM10w.mjs +1179 -0
- package/dist-D0kh4WfT.mjs +7721 -0
- package/dist-D5HdKuwj.mjs +1221 -0
- package/dist-DJtonrDM.mjs +16906 -0
- package/dist-GTk8ppiK.mjs +8380 -0
- package/dist-XEy6Tk_Y.mjs +17341 -0
- package/{drag-ghost-DRJqglR4.mjs → drag-ghost-D7FnWbO4.mjs} +1 -1
- package/{drag-ghost-DvNl926o.mjs → drag-ghost-yXe7c8jA.mjs} +1 -1
- package/{drag-in-O6toxxkY.mjs → drag-in-BiEe2Lgv.mjs} +14 -20
- package/{drag-in-D_heMFxk.mjs → drag-in-t7T6Pqwc.mjs} +9 -15
- package/embedding-plugins.js +1 -1
- package/embedding-plugins.min.js +1 -1
- package/experimental-evaluation-BgWFolud.mjs +1074 -0
- package/experimental-evaluation-D56MbtjO.mjs +970 -0
- package/{from-custom-view-CnUFpf6f.mjs → from-custom-view-CTBapIc6.mjs} +30 -30
- package/{from-custom-view-DsDwSZTY.mjs → from-custom-view-xbjgsLll.mjs} +31 -31
- package/{from-website-bTi4qNXt.mjs → from-website-DUPMQPl6.mjs} +23 -23
- package/{from-website-Csj57D58.mjs → from-website-JwG7Ic_U.mjs} +23 -23
- package/hi.js +128 -295
- package/hi.min.js +118 -261
- package/mcp-tools-Cnhgobge.mjs +153 -0
- package/mcp-tools-D3Ei3Apu.mjs +151 -0
- package/package.json +12 -1
- package/packages/embedding-lib/src/configurator-agent/configurator-mcp-tools.d.ts +4 -0
- package/packages/embedding-lib/src/configurator-agent/configurator-planning-assistant.d.ts +13 -0
- package/packages/embedding-lib/src/configurator.d.ts +3 -0
- package/packages/embedding-lib/src/homag-intelligence/hi-mcp-tools.d.ts +4 -61
- package/packages/embedding-lib/src/homag-intelligence/hi-planning-assistant.d.ts +2 -48
- package/packages/embedding-lib/src/planning-assistant/chat-model.d.ts +1 -0
- package/packages/embedding-lib/src/planning-assistant/mcp-tools.d.ts +2 -0
- package/packages/web-sdk/packages/assistant.d.ts +3 -0
- package/packages/web-sdk/packages/common-core/src/agent-tools/mcp-tool-types.d.ts +30 -0
- package/packages/web-sdk/packages/common-core/src/planning-assistant/chat-model.d.ts +8 -0
- package/packages/web-sdk/packages/common-core/src/planning-assistant/mcp-tools.d.ts +52 -0
- package/packages/web-sdk/packages/common-core/src/planning-assistant/types.d.ts +35 -0
- package/roomle-embedding-lib.js +42 -45
- package/roomle-embedding-lib.min.js +38 -41
- package/sbom.cdx.json +363 -5
- /package/{browser-BjtSrqbu.mjs → browser-D6As4Zxr.mjs} +0 -0
- /package/{browser-D6M-d6y5.mjs → browser-zrjtYpL8.mjs} +0 -0
- /package/{comlink-CR7SvKHo.mjs → comlink-Cmiqa2s0.mjs} +0 -0
- /package/{comlink-BwWPcVOp.mjs → comlink-Dc3LZUoi.mjs} +0 -0
- /package/{utils-BoELtcEK.mjs → utils-CAAGdgk8.mjs} +0 -0
- /package/{utils-BwWn6Fw4.mjs → utils-WeolMfC5.mjs} +0 -0
|
@@ -0,0 +1,1221 @@
|
|
|
1
|
+
|
|
2
|
+
import { D as e, E as t, H as n, Ht as r, Jt as i, K as a, L as o, O as s, Rt as c, S as l, Sn as u, Tt as d, Vt as f, Wt as p, X as m, Yt as h, _ as g, _t as _, an as v, bt as y, dn as b, f as x, h as S, in as C, jn as w, jt as T, kn as ee, ln as E, nn as D, o as O, qt as k, sn as A, tn as te, v as ne, w as j, xn as M, yt as re, zt as ie } from "./dist-BV-32IEX.mjs";
|
|
3
|
+
//#region node_modules/@ai-sdk/openai-compatible/dist/index.js
|
|
4
|
+
function N(e) {
|
|
5
|
+
return e.replace(/[_-]([a-z])/g, (e) => e[1].toUpperCase());
|
|
6
|
+
}
|
|
7
|
+
function P(e, t) {
|
|
8
|
+
let n = N(e);
|
|
9
|
+
return n !== e && t?.[n] != null ? n : e;
|
|
10
|
+
}
|
|
11
|
+
function F({ rawName: e, providerOptions: t, warnings: n }) {
|
|
12
|
+
let r = N(e);
|
|
13
|
+
r !== e && t?.[e] != null && n.push({
|
|
14
|
+
type: "deprecated",
|
|
15
|
+
setting: `providerOptions key '${e}'`,
|
|
16
|
+
message: `Use '${r}' instead.`
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
var I = {
|
|
20
|
+
errorSchema: v({ error: v({
|
|
21
|
+
message: E(),
|
|
22
|
+
type: E().nullish(),
|
|
23
|
+
param: k().nullish(),
|
|
24
|
+
code: b([E(), C()]).nullish()
|
|
25
|
+
}) }),
|
|
26
|
+
errorToMessage: (e) => e.error.message
|
|
27
|
+
};
|
|
28
|
+
function ae(e) {
|
|
29
|
+
if (e == null) return s();
|
|
30
|
+
let t = e.prompt_tokens ?? 0, n = e.completion_tokens ?? 0, r = e.prompt_tokens_details?.cached_tokens ?? 0, i = e.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
31
|
+
return {
|
|
32
|
+
inputTokens: {
|
|
33
|
+
total: t,
|
|
34
|
+
noCache: t - r,
|
|
35
|
+
cacheRead: r,
|
|
36
|
+
cacheWrite: void 0
|
|
37
|
+
},
|
|
38
|
+
outputTokens: {
|
|
39
|
+
total: n,
|
|
40
|
+
text: Math.max(0, n - i),
|
|
41
|
+
reasoning: i
|
|
42
|
+
},
|
|
43
|
+
raw: e
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function L(e) {
|
|
47
|
+
return e?.providerOptions?.openaiCompatible ?? {};
|
|
48
|
+
}
|
|
49
|
+
function oe(e) {
|
|
50
|
+
switch (e) {
|
|
51
|
+
case "audio/wav": return "wav";
|
|
52
|
+
case "audio/mp3":
|
|
53
|
+
case "audio/mpeg": return "mp3";
|
|
54
|
+
default: return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function se(e, { providerOptionsKey: t = "google" } = {}) {
|
|
58
|
+
let n = [];
|
|
59
|
+
for (let { role: r, content: i, ...o } of e) {
|
|
60
|
+
let e = L({ ...o });
|
|
61
|
+
switch (r) {
|
|
62
|
+
case "system":
|
|
63
|
+
n.push({
|
|
64
|
+
role: "system",
|
|
65
|
+
content: i,
|
|
66
|
+
...e
|
|
67
|
+
});
|
|
68
|
+
break;
|
|
69
|
+
case "user":
|
|
70
|
+
if (i.length === 1 && i[0].type === "text") {
|
|
71
|
+
n.push({
|
|
72
|
+
role: "user",
|
|
73
|
+
content: i[0].text,
|
|
74
|
+
...L(i[0])
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
n.push({
|
|
79
|
+
role: "user",
|
|
80
|
+
content: i.map((e) => {
|
|
81
|
+
let t = L(e);
|
|
82
|
+
switch (e.type) {
|
|
83
|
+
case "text": return {
|
|
84
|
+
type: "text",
|
|
85
|
+
text: e.text,
|
|
86
|
+
...t
|
|
87
|
+
};
|
|
88
|
+
case "file": switch (e.data.type) {
|
|
89
|
+
case "reference": throw new w({ functionality: "file parts with provider references" });
|
|
90
|
+
case "text": throw new w({ functionality: "text file parts" });
|
|
91
|
+
case "url":
|
|
92
|
+
case "data": {
|
|
93
|
+
let n = a(e.mediaType);
|
|
94
|
+
if (n === "image") return {
|
|
95
|
+
type: "image_url",
|
|
96
|
+
image_url: { url: e.data.type === "url" ? e.data.url.toString() : `data:${d({ part: e })};base64,${g(e.data.data)}` },
|
|
97
|
+
...t
|
|
98
|
+
};
|
|
99
|
+
if (n === "video") return {
|
|
100
|
+
type: "video_url",
|
|
101
|
+
video_url: { url: e.data.type === "url" ? e.data.url.toString() : `data:${d({ part: e })};base64,${g(e.data.data)}` },
|
|
102
|
+
...t
|
|
103
|
+
};
|
|
104
|
+
if (n === "audio") {
|
|
105
|
+
if (e.data.type === "url") throw new w({ functionality: "audio file parts with URLs" });
|
|
106
|
+
let n = d({ part: e }), r = oe(n);
|
|
107
|
+
if (r === null) throw new w({ functionality: `audio media type ${n}` });
|
|
108
|
+
return {
|
|
109
|
+
type: "input_audio",
|
|
110
|
+
input_audio: {
|
|
111
|
+
data: g(e.data.data),
|
|
112
|
+
format: r
|
|
113
|
+
},
|
|
114
|
+
...t
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (n === "application") {
|
|
118
|
+
if (e.data.type === "url") throw new w({ functionality: "PDF file parts with URLs" });
|
|
119
|
+
let n = d({ part: e });
|
|
120
|
+
if (n !== "application/pdf") throw new w({ functionality: `file part media type ${n}` });
|
|
121
|
+
return {
|
|
122
|
+
type: "file",
|
|
123
|
+
file: {
|
|
124
|
+
filename: e.filename ?? "document.pdf",
|
|
125
|
+
file_data: `data:application/pdf;base64,${g(e.data.data)}`
|
|
126
|
+
},
|
|
127
|
+
...t
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (n === "text") return {
|
|
131
|
+
type: "text",
|
|
132
|
+
text: e.data.type === "url" ? e.data.url.toString() : typeof e.data.data == "string" ? new TextDecoder().decode(S(e.data.data)) : new TextDecoder().decode(e.data.data),
|
|
133
|
+
...t
|
|
134
|
+
};
|
|
135
|
+
throw new w({ functionality: `file part media type ${e.mediaType}` });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}),
|
|
140
|
+
...e
|
|
141
|
+
});
|
|
142
|
+
break;
|
|
143
|
+
case "assistant": {
|
|
144
|
+
let r = "", a = "", o = [];
|
|
145
|
+
for (let e of i) {
|
|
146
|
+
let n = L(e);
|
|
147
|
+
switch (e.type) {
|
|
148
|
+
case "text":
|
|
149
|
+
r += e.text;
|
|
150
|
+
break;
|
|
151
|
+
case "reasoning":
|
|
152
|
+
a += e.text;
|
|
153
|
+
break;
|
|
154
|
+
case "tool-call": {
|
|
155
|
+
let r = e.providerOptions?.[t]?.thoughtSignature ?? e.providerOptions?.google?.thoughtSignature;
|
|
156
|
+
o.push({
|
|
157
|
+
id: e.toolCallId,
|
|
158
|
+
type: "function",
|
|
159
|
+
function: {
|
|
160
|
+
name: e.toolName,
|
|
161
|
+
arguments: JSON.stringify(e.input)
|
|
162
|
+
},
|
|
163
|
+
...n,
|
|
164
|
+
...r ? { extra_content: { google: { thought_signature: String(r) } } } : {}
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
n.push({
|
|
171
|
+
role: "assistant",
|
|
172
|
+
content: o.length > 0 ? r || null : r,
|
|
173
|
+
...a.length > 0 ? { reasoning_content: a } : {},
|
|
174
|
+
tool_calls: o.length > 0 ? o : void 0,
|
|
175
|
+
...e
|
|
176
|
+
});
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case "tool":
|
|
180
|
+
for (let e of i) {
|
|
181
|
+
if (e.type === "tool-approval-response") continue;
|
|
182
|
+
let t = e.output, r;
|
|
183
|
+
switch (t.type) {
|
|
184
|
+
case "text":
|
|
185
|
+
case "error-text":
|
|
186
|
+
r = t.value;
|
|
187
|
+
break;
|
|
188
|
+
case "execution-denied":
|
|
189
|
+
r = t.reason ?? "Tool call execution denied.";
|
|
190
|
+
break;
|
|
191
|
+
case "content":
|
|
192
|
+
case "json":
|
|
193
|
+
case "error-json":
|
|
194
|
+
r = JSON.stringify(t.value);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
let i = L(e);
|
|
198
|
+
n.push({
|
|
199
|
+
role: "tool",
|
|
200
|
+
tool_call_id: e.toolCallId,
|
|
201
|
+
content: r,
|
|
202
|
+
...i
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
default: throw Error(`Unsupported role: ${r}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return n;
|
|
210
|
+
}
|
|
211
|
+
function R({ id: t, model: n, created: r }) {
|
|
212
|
+
return e({
|
|
213
|
+
id: t,
|
|
214
|
+
model: n,
|
|
215
|
+
created: r || void 0
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function z(e) {
|
|
219
|
+
switch (e) {
|
|
220
|
+
case "stop": return "stop";
|
|
221
|
+
case "length": return "length";
|
|
222
|
+
case "content_filter": return "content-filter";
|
|
223
|
+
case "function_call":
|
|
224
|
+
case "tool_calls": return "tool-calls";
|
|
225
|
+
default: return "other";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
var B = v({
|
|
229
|
+
user: E().optional(),
|
|
230
|
+
reasoningEffort: E().optional(),
|
|
231
|
+
textVerbosity: E().optional(),
|
|
232
|
+
strictJsonSchema: h().optional()
|
|
233
|
+
});
|
|
234
|
+
function ce({ tools: e, toolChoice: t }) {
|
|
235
|
+
e = e?.length ? e : void 0;
|
|
236
|
+
let n = [];
|
|
237
|
+
if (e == null) return {
|
|
238
|
+
tools: void 0,
|
|
239
|
+
toolChoice: void 0,
|
|
240
|
+
toolWarnings: n
|
|
241
|
+
};
|
|
242
|
+
let r = [];
|
|
243
|
+
for (let t of e) t.type === "provider" ? n.push({
|
|
244
|
+
type: "unsupported",
|
|
245
|
+
feature: `provider-defined tool ${t.id}`
|
|
246
|
+
}) : r.push({
|
|
247
|
+
type: "function",
|
|
248
|
+
function: {
|
|
249
|
+
name: t.name,
|
|
250
|
+
description: t.description,
|
|
251
|
+
parameters: t.inputSchema,
|
|
252
|
+
...t.strict == null ? {} : { strict: t.strict }
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
if (t == null) return {
|
|
256
|
+
tools: r,
|
|
257
|
+
toolChoice: void 0,
|
|
258
|
+
toolWarnings: n
|
|
259
|
+
};
|
|
260
|
+
let i = t.type;
|
|
261
|
+
switch (i) {
|
|
262
|
+
case "auto":
|
|
263
|
+
case "none":
|
|
264
|
+
case "required": return {
|
|
265
|
+
tools: r,
|
|
266
|
+
toolChoice: i,
|
|
267
|
+
toolWarnings: n
|
|
268
|
+
};
|
|
269
|
+
case "tool": return {
|
|
270
|
+
tools: r,
|
|
271
|
+
toolChoice: {
|
|
272
|
+
type: "function",
|
|
273
|
+
function: { name: t.toolName }
|
|
274
|
+
},
|
|
275
|
+
toolWarnings: n
|
|
276
|
+
};
|
|
277
|
+
default: throw new w({ functionality: `tool choice type: ${i}` });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
var V = class e {
|
|
281
|
+
constructor(e, t) {
|
|
282
|
+
this.specificationVersion = "v4", this.modelId = e, this.config = t;
|
|
283
|
+
let n = t.errorStructure ?? I;
|
|
284
|
+
this.chunkSchema = de(n.errorSchema), this.failedResponseHandler = j(n), this.supportsStructuredOutputs = t.supportsStructuredOutputs ?? !1;
|
|
285
|
+
}
|
|
286
|
+
static [r](e) {
|
|
287
|
+
return T({
|
|
288
|
+
modelId: e.modelId,
|
|
289
|
+
config: e.config
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
static [f](t) {
|
|
293
|
+
return new e(t.modelId, t.config);
|
|
294
|
+
}
|
|
295
|
+
get provider() {
|
|
296
|
+
return this.config.provider;
|
|
297
|
+
}
|
|
298
|
+
get providerOptionsName() {
|
|
299
|
+
return this.config.provider.split(".")[0].trim();
|
|
300
|
+
}
|
|
301
|
+
get supportedUrls() {
|
|
302
|
+
return this.config.supportedUrls?.() ?? {};
|
|
303
|
+
}
|
|
304
|
+
transformRequestBody(e) {
|
|
305
|
+
return this.config.transformRequestBody?.(e) ?? e;
|
|
306
|
+
}
|
|
307
|
+
convertUsage(e) {
|
|
308
|
+
return this.config.convertUsage?.(e) ?? ae(e);
|
|
309
|
+
}
|
|
310
|
+
async getArgs({ prompt: e, maxOutputTokens: t, temperature: n, topP: r, topK: i, frequencyPenalty: a, presencePenalty: o, reasoning: s, providerOptions: c, stopSequences: l, responseFormat: u, seed: d, toolChoice: f, tools: p }) {
|
|
311
|
+
let h = [], g = await _({
|
|
312
|
+
provider: "openai-compatible",
|
|
313
|
+
providerOptions: c,
|
|
314
|
+
schema: B
|
|
315
|
+
});
|
|
316
|
+
g != null && h.push({
|
|
317
|
+
type: "deprecated",
|
|
318
|
+
setting: "providerOptions key 'openai-compatible'",
|
|
319
|
+
message: "Use 'openaiCompatible' instead."
|
|
320
|
+
}), F({
|
|
321
|
+
rawName: this.providerOptionsName,
|
|
322
|
+
providerOptions: c,
|
|
323
|
+
warnings: h
|
|
324
|
+
});
|
|
325
|
+
let v = Object.assign(g ?? {}, await _({
|
|
326
|
+
provider: "openaiCompatible",
|
|
327
|
+
providerOptions: c,
|
|
328
|
+
schema: B
|
|
329
|
+
}) ?? {}, await _({
|
|
330
|
+
provider: this.providerOptionsName,
|
|
331
|
+
providerOptions: c,
|
|
332
|
+
schema: B
|
|
333
|
+
}) ?? {}, await _({
|
|
334
|
+
provider: N(this.providerOptionsName),
|
|
335
|
+
providerOptions: c,
|
|
336
|
+
schema: B
|
|
337
|
+
}) ?? {}), y = v?.strictJsonSchema ?? !0;
|
|
338
|
+
i != null && h.push({
|
|
339
|
+
type: "unsupported",
|
|
340
|
+
feature: "topK"
|
|
341
|
+
}), u?.type === "json" && u.schema != null && !this.supportsStructuredOutputs && h.push({
|
|
342
|
+
type: "unsupported",
|
|
343
|
+
feature: "responseFormat",
|
|
344
|
+
details: "JSON response format schema is only supported with structuredOutputs"
|
|
345
|
+
});
|
|
346
|
+
let { tools: b, toolChoice: x, toolWarnings: S } = ce({
|
|
347
|
+
tools: p,
|
|
348
|
+
toolChoice: f
|
|
349
|
+
}), C = P(this.providerOptionsName, c);
|
|
350
|
+
return {
|
|
351
|
+
metadataKey: C,
|
|
352
|
+
args: {
|
|
353
|
+
model: this.modelId,
|
|
354
|
+
user: v.user,
|
|
355
|
+
max_tokens: t,
|
|
356
|
+
temperature: n,
|
|
357
|
+
top_p: r,
|
|
358
|
+
frequency_penalty: a,
|
|
359
|
+
presence_penalty: o,
|
|
360
|
+
response_format: u?.type === "json" ? this.supportsStructuredOutputs === !0 && u.schema != null ? {
|
|
361
|
+
type: "json_schema",
|
|
362
|
+
json_schema: {
|
|
363
|
+
schema: u.schema,
|
|
364
|
+
strict: y,
|
|
365
|
+
name: u.name ?? "response",
|
|
366
|
+
description: u.description
|
|
367
|
+
}
|
|
368
|
+
} : { type: "json_object" } : void 0,
|
|
369
|
+
stop: l,
|
|
370
|
+
seed: d,
|
|
371
|
+
...Object.fromEntries(Object.entries({
|
|
372
|
+
...c?.[this.providerOptionsName],
|
|
373
|
+
...c?.[N(this.providerOptionsName)]
|
|
374
|
+
}).filter(([e]) => !Object.keys(B.shape).includes(e))),
|
|
375
|
+
reasoning_effort: v.reasoningEffort ?? (m(s) ? s : void 0),
|
|
376
|
+
verbosity: v.textVerbosity,
|
|
377
|
+
messages: se(e, { providerOptionsKey: C }),
|
|
378
|
+
tools: b,
|
|
379
|
+
tool_choice: x
|
|
380
|
+
},
|
|
381
|
+
warnings: [...h, ...S]
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
async doGenerate(e) {
|
|
385
|
+
let { args: r, warnings: i, metadataKey: a } = await this.getArgs({ ...e }), o = this.transformRequestBody(r), s = JSON.stringify(o), { responseHeaders: c, value: l, rawValue: d } = await y({
|
|
386
|
+
url: this.config.url({
|
|
387
|
+
path: "/chat/completions",
|
|
388
|
+
modelId: this.modelId
|
|
389
|
+
}),
|
|
390
|
+
headers: x(this.config.headers?.(), e.headers),
|
|
391
|
+
body: o,
|
|
392
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
393
|
+
successfulResponseHandler: t(le),
|
|
394
|
+
abortSignal: e.abortSignal,
|
|
395
|
+
fetch: this.config.fetch
|
|
396
|
+
}), f = l.choices[0];
|
|
397
|
+
if (f == null) throw new u({
|
|
398
|
+
data: d,
|
|
399
|
+
message: "Response did not contain any choices."
|
|
400
|
+
});
|
|
401
|
+
let p = [];
|
|
402
|
+
p.push(...W(f.message.content));
|
|
403
|
+
let m = f.message.reasoning_content ?? f.message.reasoning;
|
|
404
|
+
if (m != null && m.length > 0 && p.push({
|
|
405
|
+
type: "reasoning",
|
|
406
|
+
text: m
|
|
407
|
+
}), f.message.tool_calls != null) for (let e of f.message.tool_calls) {
|
|
408
|
+
let t = e.extra_content?.google?.thought_signature;
|
|
409
|
+
p.push({
|
|
410
|
+
type: "tool-call",
|
|
411
|
+
toolCallId: e.id || n(),
|
|
412
|
+
toolName: e.function.name,
|
|
413
|
+
input: e.function.arguments,
|
|
414
|
+
...t ? { providerMetadata: { [a]: { thoughtSignature: t } } } : {}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
let h = {
|
|
418
|
+
[a]: {},
|
|
419
|
+
...await this.config.metadataExtractor?.extractMetadata?.({ parsedBody: d })
|
|
420
|
+
}, g = l.usage?.completion_tokens_details;
|
|
421
|
+
return g?.accepted_prediction_tokens != null && (h[a].acceptedPredictionTokens = g?.accepted_prediction_tokens), g?.rejected_prediction_tokens != null && (h[a].rejectedPredictionTokens = g?.rejected_prediction_tokens), {
|
|
422
|
+
content: p,
|
|
423
|
+
finishReason: {
|
|
424
|
+
unified: z(f.finish_reason),
|
|
425
|
+
raw: f.finish_reason ?? void 0
|
|
426
|
+
},
|
|
427
|
+
usage: this.convertUsage(l.usage),
|
|
428
|
+
providerMetadata: h,
|
|
429
|
+
request: { body: s },
|
|
430
|
+
response: {
|
|
431
|
+
...R(l),
|
|
432
|
+
headers: c,
|
|
433
|
+
body: d
|
|
434
|
+
},
|
|
435
|
+
warnings: i
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
async doStream(e) {
|
|
439
|
+
let { args: t, warnings: r, metadataKey: i } = await this.getArgs({ ...e }), a = this.transformRequestBody({
|
|
440
|
+
...t,
|
|
441
|
+
stream: !0,
|
|
442
|
+
stream_options: this.config.includeUsage ? { include_usage: !0 } : void 0
|
|
443
|
+
}), o = this.config.metadataExtractor?.createStreamExtractor(), { responseHeaders: s, value: c } = await y({
|
|
444
|
+
url: this.config.url({
|
|
445
|
+
path: "/chat/completions",
|
|
446
|
+
modelId: this.modelId
|
|
447
|
+
}),
|
|
448
|
+
headers: x(this.config.headers?.(), e.headers),
|
|
449
|
+
body: a,
|
|
450
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
451
|
+
successfulResponseHandler: l(this.chunkSchema),
|
|
452
|
+
abortSignal: e.abortSignal,
|
|
453
|
+
fetch: this.config.fetch
|
|
454
|
+
}), d = i, f, p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set(), h = (e) => {
|
|
455
|
+
let t = e.index;
|
|
456
|
+
if (t == null || m.has(t)) {
|
|
457
|
+
f.processDelta(e);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
let n = p.get(t);
|
|
461
|
+
n == null ? (n = {
|
|
462
|
+
id: e.id ?? null,
|
|
463
|
+
bufferedArguments: "",
|
|
464
|
+
extraContent: e.extra_content ?? null
|
|
465
|
+
}, p.set(t, n)) : (n.id == null && e.id != null && (n.id = e.id), n.extraContent == null && e.extra_content != null && (n.extraContent = e.extra_content));
|
|
466
|
+
let r = e.function?.arguments;
|
|
467
|
+
r != null && (n.bufferedArguments += r);
|
|
468
|
+
let i = e.function?.name;
|
|
469
|
+
if (i != null) {
|
|
470
|
+
let e = {
|
|
471
|
+
index: t,
|
|
472
|
+
id: n.id,
|
|
473
|
+
function: {
|
|
474
|
+
name: i,
|
|
475
|
+
arguments: n.bufferedArguments
|
|
476
|
+
},
|
|
477
|
+
extra_content: n.extraContent ?? void 0
|
|
478
|
+
};
|
|
479
|
+
f.processDelta(e), p.delete(t), m.add(t);
|
|
480
|
+
}
|
|
481
|
+
}, g, _, v = !1, b = !1, S = !1, C = (e) => this.convertUsage(e);
|
|
482
|
+
return {
|
|
483
|
+
stream: c.pipeThrough(new TransformStream({
|
|
484
|
+
start(e) {
|
|
485
|
+
f = new O(e, {
|
|
486
|
+
generateId: n,
|
|
487
|
+
extractMetadata: (e) => {
|
|
488
|
+
let t = e.extra_content?.google?.thought_signature;
|
|
489
|
+
return t ? { [d]: { thoughtSignature: t } } : void 0;
|
|
490
|
+
},
|
|
491
|
+
buildToolCallProviderMetadata: (e) => e
|
|
492
|
+
}), e.enqueue({
|
|
493
|
+
type: "stream-start",
|
|
494
|
+
warnings: r
|
|
495
|
+
});
|
|
496
|
+
},
|
|
497
|
+
transform(t, n) {
|
|
498
|
+
if (e.includeRawChunks && n.enqueue({
|
|
499
|
+
type: "raw",
|
|
500
|
+
rawValue: t.rawValue
|
|
501
|
+
}), !t.success) {
|
|
502
|
+
g = {
|
|
503
|
+
unified: "error",
|
|
504
|
+
raw: void 0
|
|
505
|
+
}, n.enqueue({
|
|
506
|
+
type: "error",
|
|
507
|
+
error: t.error
|
|
508
|
+
});
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
if (o?.processChunk(t.rawValue), "error" in t.value) {
|
|
512
|
+
g = {
|
|
513
|
+
unified: "error",
|
|
514
|
+
raw: void 0
|
|
515
|
+
}, n.enqueue({
|
|
516
|
+
type: "error",
|
|
517
|
+
error: t.value.error
|
|
518
|
+
});
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
let r = t.value;
|
|
522
|
+
if (!v) {
|
|
523
|
+
let e = R(r);
|
|
524
|
+
Object.values(e).some(Boolean) && (v = !0, n.enqueue({
|
|
525
|
+
type: "response-metadata",
|
|
526
|
+
...e
|
|
527
|
+
}));
|
|
528
|
+
}
|
|
529
|
+
r.usage != null && (_ = r.usage);
|
|
530
|
+
let i = r.choices[0];
|
|
531
|
+
if (i?.finish_reason != null && (g = {
|
|
532
|
+
unified: z(i.finish_reason),
|
|
533
|
+
raw: i.finish_reason ?? void 0
|
|
534
|
+
}), i?.delta == null) return;
|
|
535
|
+
let a = i.delta, s = (e) => {
|
|
536
|
+
S &&= (n.enqueue({
|
|
537
|
+
type: "text-end",
|
|
538
|
+
id: "txt-0"
|
|
539
|
+
}), !1), b ||= (n.enqueue({
|
|
540
|
+
type: "reasoning-start",
|
|
541
|
+
id: "reasoning-0"
|
|
542
|
+
}), !0), n.enqueue({
|
|
543
|
+
type: "reasoning-delta",
|
|
544
|
+
id: "reasoning-0",
|
|
545
|
+
delta: e
|
|
546
|
+
});
|
|
547
|
+
}, c = (e) => {
|
|
548
|
+
b &&= (n.enqueue({
|
|
549
|
+
type: "reasoning-end",
|
|
550
|
+
id: "reasoning-0"
|
|
551
|
+
}), !1), S ||= (n.enqueue({
|
|
552
|
+
type: "text-start",
|
|
553
|
+
id: "txt-0"
|
|
554
|
+
}), !0), n.enqueue({
|
|
555
|
+
type: "text-delta",
|
|
556
|
+
id: "txt-0",
|
|
557
|
+
delta: e
|
|
558
|
+
});
|
|
559
|
+
}, l = a.reasoning_content ?? a.reasoning;
|
|
560
|
+
l && s(l);
|
|
561
|
+
for (let e of W(a.content)) e.type === "reasoning" ? s(e.text) : c(e.text);
|
|
562
|
+
if (a.tool_calls != null && a.tool_calls.length > 0) {
|
|
563
|
+
b &&= (n.enqueue({
|
|
564
|
+
type: "reasoning-end",
|
|
565
|
+
id: "reasoning-0"
|
|
566
|
+
}), !1);
|
|
567
|
+
for (let e of a.tool_calls) h(e);
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
flush(e) {
|
|
571
|
+
b && e.enqueue({
|
|
572
|
+
type: "reasoning-end",
|
|
573
|
+
id: "reasoning-0"
|
|
574
|
+
}), S && e.enqueue({
|
|
575
|
+
type: "text-end",
|
|
576
|
+
id: "txt-0"
|
|
577
|
+
});
|
|
578
|
+
for (let [e, t] of p) f.processDelta({
|
|
579
|
+
index: e,
|
|
580
|
+
id: t.id,
|
|
581
|
+
function: { arguments: t.bufferedArguments }
|
|
582
|
+
});
|
|
583
|
+
p.clear(), f.flush(), g ?? (g = {
|
|
584
|
+
unified: "error",
|
|
585
|
+
raw: void 0
|
|
586
|
+
}, e.enqueue({
|
|
587
|
+
type: "error",
|
|
588
|
+
error: new u({
|
|
589
|
+
data: void 0,
|
|
590
|
+
message: "Response stream ended without a finish reason."
|
|
591
|
+
})
|
|
592
|
+
}));
|
|
593
|
+
let t = {
|
|
594
|
+
[d]: {},
|
|
595
|
+
...o?.buildMetadata()
|
|
596
|
+
};
|
|
597
|
+
_?.completion_tokens_details?.accepted_prediction_tokens != null && (t[d].acceptedPredictionTokens = _?.completion_tokens_details?.accepted_prediction_tokens), _?.completion_tokens_details?.rejected_prediction_tokens != null && (t[d].rejectedPredictionTokens = _?.completion_tokens_details?.rejected_prediction_tokens), e.enqueue({
|
|
598
|
+
type: "finish",
|
|
599
|
+
finishReason: g,
|
|
600
|
+
usage: C(_),
|
|
601
|
+
providerMetadata: t
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
})),
|
|
605
|
+
request: { body: a },
|
|
606
|
+
response: { headers: s }
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
}, H = D({
|
|
610
|
+
prompt_tokens: C().nullish(),
|
|
611
|
+
completion_tokens: C().nullish(),
|
|
612
|
+
total_tokens: C().nullish(),
|
|
613
|
+
prompt_tokens_details: D({ cached_tokens: C().nullish() }).nullish(),
|
|
614
|
+
completion_tokens_details: D({
|
|
615
|
+
reasoning_tokens: C().nullish(),
|
|
616
|
+
accepted_prediction_tokens: C().nullish(),
|
|
617
|
+
rejected_prediction_tokens: C().nullish()
|
|
618
|
+
}).nullish()
|
|
619
|
+
}).nullish(), U = b([E(), i(D({ type: E() }))]).nullish();
|
|
620
|
+
function W(e) {
|
|
621
|
+
if (e == null) return [];
|
|
622
|
+
if (typeof e == "string") return e.length > 0 ? [{
|
|
623
|
+
type: "text",
|
|
624
|
+
text: e
|
|
625
|
+
}] : [];
|
|
626
|
+
let t = [];
|
|
627
|
+
for (let n of e) if (n.type === "text" && typeof n.text == "string") n.text.length > 0 && t.push({
|
|
628
|
+
type: "text",
|
|
629
|
+
text: n.text
|
|
630
|
+
});
|
|
631
|
+
else if (n.type === "thinking" && Array.isArray(n.thinking)) {
|
|
632
|
+
let e = n.thinking.filter((e) => typeof e == "object" && !!e && "type" in e && e.type === "text" && "text" in e && typeof e.text == "string").map((e) => e.text).join("");
|
|
633
|
+
e.length > 0 && t.push({
|
|
634
|
+
type: "reasoning",
|
|
635
|
+
text: e
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
return t;
|
|
639
|
+
}
|
|
640
|
+
var le = D({
|
|
641
|
+
id: E().nullish(),
|
|
642
|
+
created: C().nullish(),
|
|
643
|
+
model: E().nullish(),
|
|
644
|
+
choices: i(v({
|
|
645
|
+
message: v({
|
|
646
|
+
role: te("assistant").nullish(),
|
|
647
|
+
content: U,
|
|
648
|
+
reasoning_content: E().nullish(),
|
|
649
|
+
reasoning: E().nullish(),
|
|
650
|
+
tool_calls: i(v({
|
|
651
|
+
id: E().nullish(),
|
|
652
|
+
function: v({
|
|
653
|
+
name: E(),
|
|
654
|
+
arguments: E()
|
|
655
|
+
}),
|
|
656
|
+
extra_content: v({ google: v({ thought_signature: E().nullish() }).nullish() }).nullish()
|
|
657
|
+
})).nullish()
|
|
658
|
+
}),
|
|
659
|
+
finish_reason: E().nullish()
|
|
660
|
+
})),
|
|
661
|
+
usage: H
|
|
662
|
+
}), ue = D({
|
|
663
|
+
id: E().nullish(),
|
|
664
|
+
created: C().nullish(),
|
|
665
|
+
model: E().nullish(),
|
|
666
|
+
choices: i(v({
|
|
667
|
+
delta: v({
|
|
668
|
+
role: p(["assistant", ""]).nullish(),
|
|
669
|
+
content: U,
|
|
670
|
+
reasoning_content: E().nullish(),
|
|
671
|
+
reasoning: E().nullish(),
|
|
672
|
+
tool_calls: i(v({
|
|
673
|
+
index: C().nullish(),
|
|
674
|
+
id: E().nullish(),
|
|
675
|
+
function: v({
|
|
676
|
+
name: E().nullish(),
|
|
677
|
+
arguments: E().nullish()
|
|
678
|
+
}),
|
|
679
|
+
extra_content: v({ google: v({ thought_signature: E().nullish() }).nullish() }).nullish()
|
|
680
|
+
})).nullish()
|
|
681
|
+
}).nullish(),
|
|
682
|
+
finish_reason: E().nullish()
|
|
683
|
+
})),
|
|
684
|
+
usage: H
|
|
685
|
+
}), de = (e) => b([ue, e]);
|
|
686
|
+
function G(e) {
|
|
687
|
+
if (e == null) return s();
|
|
688
|
+
let t = e.prompt_tokens ?? 0, n = e.completion_tokens ?? 0;
|
|
689
|
+
return {
|
|
690
|
+
inputTokens: {
|
|
691
|
+
total: t,
|
|
692
|
+
noCache: t,
|
|
693
|
+
cacheRead: void 0,
|
|
694
|
+
cacheWrite: void 0
|
|
695
|
+
},
|
|
696
|
+
outputTokens: {
|
|
697
|
+
total: n,
|
|
698
|
+
text: n,
|
|
699
|
+
reasoning: void 0
|
|
700
|
+
},
|
|
701
|
+
raw: e
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function fe({ prompt: e, user: t = "user", assistant: n = "assistant" }) {
|
|
705
|
+
let r = "";
|
|
706
|
+
e[0].role === "system" && (r += `${e[0].content}
|
|
707
|
+
|
|
708
|
+
`, e = e.slice(1));
|
|
709
|
+
for (let { role: i, content: a } of e) switch (i) {
|
|
710
|
+
case "system": throw new M({
|
|
711
|
+
message: "Unexpected system message in prompt: ${content}",
|
|
712
|
+
prompt: e
|
|
713
|
+
});
|
|
714
|
+
case "user": {
|
|
715
|
+
let e = a.map((e) => {
|
|
716
|
+
switch (e.type) {
|
|
717
|
+
case "text": return e.text;
|
|
718
|
+
}
|
|
719
|
+
}).filter(Boolean).join("");
|
|
720
|
+
r += `${t}:
|
|
721
|
+
${e}
|
|
722
|
+
|
|
723
|
+
`;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
case "assistant": {
|
|
727
|
+
let e = a.map((e) => {
|
|
728
|
+
switch (e.type) {
|
|
729
|
+
case "text": return e.text;
|
|
730
|
+
case "tool-call": throw new w({ functionality: "tool-call messages" });
|
|
731
|
+
}
|
|
732
|
+
}).join("");
|
|
733
|
+
r += `${n}:
|
|
734
|
+
${e}
|
|
735
|
+
|
|
736
|
+
`;
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
case "tool": throw new w({ functionality: "tool messages" });
|
|
740
|
+
default: throw Error(`Unsupported role: ${i}`);
|
|
741
|
+
}
|
|
742
|
+
return r += `${n}:
|
|
743
|
+
`, {
|
|
744
|
+
prompt: r,
|
|
745
|
+
stopSequences: [`
|
|
746
|
+
${t}:`]
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function K(e) {
|
|
750
|
+
switch (e) {
|
|
751
|
+
case "stop": return "stop";
|
|
752
|
+
case "length": return "length";
|
|
753
|
+
case "content_filter": return "content-filter";
|
|
754
|
+
case "function_call":
|
|
755
|
+
case "tool_calls": return "tool-calls";
|
|
756
|
+
default: return "other";
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
var q = v({
|
|
760
|
+
echo: h().optional(),
|
|
761
|
+
logitBias: A(E(), C()).optional(),
|
|
762
|
+
suffix: E().optional(),
|
|
763
|
+
user: E().optional()
|
|
764
|
+
}), pe = class n {
|
|
765
|
+
constructor(e, t) {
|
|
766
|
+
this.specificationVersion = "v4", this.modelId = e, this.config = t;
|
|
767
|
+
let n = t.errorStructure ?? I;
|
|
768
|
+
this.chunkSchema = he(n.errorSchema), this.failedResponseHandler = j(n);
|
|
769
|
+
}
|
|
770
|
+
static [r](e) {
|
|
771
|
+
return T({
|
|
772
|
+
modelId: e.modelId,
|
|
773
|
+
config: e.config
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
static [f](e) {
|
|
777
|
+
return new n(e.modelId, e.config);
|
|
778
|
+
}
|
|
779
|
+
get provider() {
|
|
780
|
+
return this.config.provider;
|
|
781
|
+
}
|
|
782
|
+
get providerOptionsName() {
|
|
783
|
+
return this.config.provider.split(".")[0].trim();
|
|
784
|
+
}
|
|
785
|
+
get supportedUrls() {
|
|
786
|
+
return this.config.supportedUrls?.() ?? {};
|
|
787
|
+
}
|
|
788
|
+
async getArgs({ prompt: e, maxOutputTokens: t, temperature: n, topP: r, topK: i, frequencyPenalty: a, presencePenalty: o, stopSequences: s, responseFormat: c, seed: l, providerOptions: u, tools: d, toolChoice: f }) {
|
|
789
|
+
let p = [];
|
|
790
|
+
F({
|
|
791
|
+
rawName: this.providerOptionsName,
|
|
792
|
+
providerOptions: u,
|
|
793
|
+
warnings: p
|
|
794
|
+
});
|
|
795
|
+
let m = Object.assign(await _({
|
|
796
|
+
provider: this.providerOptionsName,
|
|
797
|
+
providerOptions: u,
|
|
798
|
+
schema: q
|
|
799
|
+
}) ?? {}, await _({
|
|
800
|
+
provider: N(this.providerOptionsName),
|
|
801
|
+
providerOptions: u,
|
|
802
|
+
schema: q
|
|
803
|
+
}) ?? {});
|
|
804
|
+
i != null && p.push({
|
|
805
|
+
type: "unsupported",
|
|
806
|
+
feature: "topK"
|
|
807
|
+
}), d?.length && p.push({
|
|
808
|
+
type: "unsupported",
|
|
809
|
+
feature: "tools"
|
|
810
|
+
}), f != null && p.push({
|
|
811
|
+
type: "unsupported",
|
|
812
|
+
feature: "toolChoice"
|
|
813
|
+
}), c != null && c.type !== "text" && p.push({
|
|
814
|
+
type: "unsupported",
|
|
815
|
+
feature: "responseFormat",
|
|
816
|
+
details: "JSON response format is not supported."
|
|
817
|
+
});
|
|
818
|
+
let { prompt: h, stopSequences: g } = fe({ prompt: e }), v = [...g ?? [], ...s ?? []];
|
|
819
|
+
return {
|
|
820
|
+
args: {
|
|
821
|
+
model: this.modelId,
|
|
822
|
+
echo: m.echo,
|
|
823
|
+
logit_bias: m.logitBias,
|
|
824
|
+
suffix: m.suffix,
|
|
825
|
+
user: m.user,
|
|
826
|
+
max_tokens: t,
|
|
827
|
+
temperature: n,
|
|
828
|
+
top_p: r,
|
|
829
|
+
frequency_penalty: a,
|
|
830
|
+
presence_penalty: o,
|
|
831
|
+
seed: l,
|
|
832
|
+
...u?.[this.providerOptionsName],
|
|
833
|
+
...u?.[N(this.providerOptionsName)],
|
|
834
|
+
prompt: h,
|
|
835
|
+
stop: v.length > 0 ? v : void 0
|
|
836
|
+
},
|
|
837
|
+
warnings: p
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
async doGenerate(n) {
|
|
841
|
+
let { args: r, warnings: i } = await this.getArgs(n), { responseHeaders: a, value: o, rawValue: s } = await y({
|
|
842
|
+
url: this.config.url({
|
|
843
|
+
path: "/completions",
|
|
844
|
+
modelId: this.modelId
|
|
845
|
+
}),
|
|
846
|
+
headers: x(this.config.headers?.(), n.headers),
|
|
847
|
+
body: r,
|
|
848
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
849
|
+
successfulResponseHandler: t(me),
|
|
850
|
+
abortSignal: n.abortSignal,
|
|
851
|
+
fetch: this.config.fetch
|
|
852
|
+
}), c = o.choices[0], l = [];
|
|
853
|
+
return c.text != null && c.text.length > 0 && l.push({
|
|
854
|
+
type: "text",
|
|
855
|
+
text: c.text
|
|
856
|
+
}), {
|
|
857
|
+
content: l,
|
|
858
|
+
usage: G(o.usage),
|
|
859
|
+
finishReason: {
|
|
860
|
+
unified: K(c.finish_reason),
|
|
861
|
+
raw: c.finish_reason
|
|
862
|
+
},
|
|
863
|
+
request: { body: r },
|
|
864
|
+
response: {
|
|
865
|
+
...e(o),
|
|
866
|
+
headers: a,
|
|
867
|
+
body: s
|
|
868
|
+
},
|
|
869
|
+
warnings: i
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
async doStream(t) {
|
|
873
|
+
let { args: n, warnings: r } = await this.getArgs(t), i = {
|
|
874
|
+
...n,
|
|
875
|
+
stream: !0,
|
|
876
|
+
stream_options: this.config.includeUsage ? { include_usage: !0 } : void 0
|
|
877
|
+
}, { responseHeaders: a, value: o } = await y({
|
|
878
|
+
url: this.config.url({
|
|
879
|
+
path: "/completions",
|
|
880
|
+
modelId: this.modelId
|
|
881
|
+
}),
|
|
882
|
+
headers: x(this.config.headers?.(), t.headers),
|
|
883
|
+
body: i,
|
|
884
|
+
failedResponseHandler: this.failedResponseHandler,
|
|
885
|
+
successfulResponseHandler: l(this.chunkSchema),
|
|
886
|
+
abortSignal: t.abortSignal,
|
|
887
|
+
fetch: this.config.fetch
|
|
888
|
+
}), s = {
|
|
889
|
+
unified: "other",
|
|
890
|
+
raw: void 0
|
|
891
|
+
}, c, u = !0;
|
|
892
|
+
return {
|
|
893
|
+
stream: o.pipeThrough(new TransformStream({
|
|
894
|
+
start(e) {
|
|
895
|
+
e.enqueue({
|
|
896
|
+
type: "stream-start",
|
|
897
|
+
warnings: r
|
|
898
|
+
});
|
|
899
|
+
},
|
|
900
|
+
transform(n, r) {
|
|
901
|
+
if (t.includeRawChunks && r.enqueue({
|
|
902
|
+
type: "raw",
|
|
903
|
+
rawValue: n.rawValue
|
|
904
|
+
}), !n.success) {
|
|
905
|
+
s = {
|
|
906
|
+
unified: "error",
|
|
907
|
+
raw: void 0
|
|
908
|
+
}, r.enqueue({
|
|
909
|
+
type: "error",
|
|
910
|
+
error: n.error
|
|
911
|
+
});
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
let i = n.value;
|
|
915
|
+
if ("error" in i) {
|
|
916
|
+
s = {
|
|
917
|
+
unified: "error",
|
|
918
|
+
raw: void 0
|
|
919
|
+
}, r.enqueue({
|
|
920
|
+
type: "error",
|
|
921
|
+
error: i.error
|
|
922
|
+
});
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
u && (u = !1, r.enqueue({
|
|
926
|
+
type: "response-metadata",
|
|
927
|
+
...e(i)
|
|
928
|
+
}), r.enqueue({
|
|
929
|
+
type: "text-start",
|
|
930
|
+
id: "0"
|
|
931
|
+
})), i.usage != null && (c = i.usage);
|
|
932
|
+
let a = i.choices[0];
|
|
933
|
+
a?.finish_reason != null && (s = {
|
|
934
|
+
unified: K(a.finish_reason),
|
|
935
|
+
raw: a.finish_reason ?? void 0
|
|
936
|
+
}), a?.text != null && r.enqueue({
|
|
937
|
+
type: "text-delta",
|
|
938
|
+
id: "0",
|
|
939
|
+
delta: a.text
|
|
940
|
+
});
|
|
941
|
+
},
|
|
942
|
+
flush(e) {
|
|
943
|
+
u || e.enqueue({
|
|
944
|
+
type: "text-end",
|
|
945
|
+
id: "0"
|
|
946
|
+
}), e.enqueue({
|
|
947
|
+
type: "finish",
|
|
948
|
+
finishReason: s,
|
|
949
|
+
usage: G(c)
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
})),
|
|
953
|
+
request: { body: i },
|
|
954
|
+
response: { headers: a }
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
}, J = D({
|
|
958
|
+
prompt_tokens: C(),
|
|
959
|
+
completion_tokens: C(),
|
|
960
|
+
total_tokens: C()
|
|
961
|
+
}), me = v({
|
|
962
|
+
id: E().nullish(),
|
|
963
|
+
created: C().nullish(),
|
|
964
|
+
model: E().nullish(),
|
|
965
|
+
choices: i(v({
|
|
966
|
+
text: E(),
|
|
967
|
+
finish_reason: E()
|
|
968
|
+
})),
|
|
969
|
+
usage: J.nullish()
|
|
970
|
+
}), he = (e) => b([v({
|
|
971
|
+
id: E().nullish(),
|
|
972
|
+
created: C().nullish(),
|
|
973
|
+
model: E().nullish(),
|
|
974
|
+
choices: i(v({
|
|
975
|
+
text: E(),
|
|
976
|
+
finish_reason: E().nullish(),
|
|
977
|
+
index: C()
|
|
978
|
+
})),
|
|
979
|
+
usage: J.nullish()
|
|
980
|
+
}), e]), Y = v({
|
|
981
|
+
dimensions: C().optional(),
|
|
982
|
+
user: E().optional()
|
|
983
|
+
}), ge = class e {
|
|
984
|
+
constructor(e, t) {
|
|
985
|
+
this.specificationVersion = "v4", this.modelId = e, this.config = t;
|
|
986
|
+
}
|
|
987
|
+
get provider() {
|
|
988
|
+
return this.config.provider;
|
|
989
|
+
}
|
|
990
|
+
get maxEmbeddingsPerCall() {
|
|
991
|
+
return this.config.maxEmbeddingsPerCall ?? 2048;
|
|
992
|
+
}
|
|
993
|
+
get supportsParallelCalls() {
|
|
994
|
+
return this.config.supportsParallelCalls ?? !0;
|
|
995
|
+
}
|
|
996
|
+
static [r](e) {
|
|
997
|
+
return T({
|
|
998
|
+
modelId: e.modelId,
|
|
999
|
+
config: e.config
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
static [f](t) {
|
|
1003
|
+
return new e(t.modelId, t.config);
|
|
1004
|
+
}
|
|
1005
|
+
get providerOptionsName() {
|
|
1006
|
+
return this.config.provider.split(".")[0].trim();
|
|
1007
|
+
}
|
|
1008
|
+
async doEmbed({ values: e, headers: n, abortSignal: r, providerOptions: i }) {
|
|
1009
|
+
let a = [], o = await _({
|
|
1010
|
+
provider: "openai-compatible",
|
|
1011
|
+
providerOptions: i,
|
|
1012
|
+
schema: Y
|
|
1013
|
+
});
|
|
1014
|
+
o != null && a.push({
|
|
1015
|
+
type: "deprecated",
|
|
1016
|
+
setting: "providerOptions key 'openai-compatible'",
|
|
1017
|
+
message: "Use 'openaiCompatible' instead."
|
|
1018
|
+
}), F({
|
|
1019
|
+
rawName: this.providerOptionsName,
|
|
1020
|
+
providerOptions: i,
|
|
1021
|
+
warnings: a
|
|
1022
|
+
});
|
|
1023
|
+
let s = Object.assign(o ?? {}, await _({
|
|
1024
|
+
provider: "openaiCompatible",
|
|
1025
|
+
providerOptions: i,
|
|
1026
|
+
schema: Y
|
|
1027
|
+
}) ?? {}, await _({
|
|
1028
|
+
provider: this.providerOptionsName,
|
|
1029
|
+
providerOptions: i,
|
|
1030
|
+
schema: Y
|
|
1031
|
+
}) ?? {});
|
|
1032
|
+
if (e.length > this.maxEmbeddingsPerCall) throw new ee({
|
|
1033
|
+
provider: this.provider,
|
|
1034
|
+
modelId: this.modelId,
|
|
1035
|
+
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
1036
|
+
values: e
|
|
1037
|
+
});
|
|
1038
|
+
let { responseHeaders: c, value: l, rawValue: u } = await y({
|
|
1039
|
+
url: this.config.url({
|
|
1040
|
+
path: "/embeddings",
|
|
1041
|
+
modelId: this.modelId
|
|
1042
|
+
}),
|
|
1043
|
+
headers: x(this.config.headers?.(), n),
|
|
1044
|
+
body: {
|
|
1045
|
+
model: this.modelId,
|
|
1046
|
+
input: e,
|
|
1047
|
+
encoding_format: "float",
|
|
1048
|
+
dimensions: s.dimensions,
|
|
1049
|
+
user: s.user
|
|
1050
|
+
},
|
|
1051
|
+
failedResponseHandler: j(this.config.errorStructure ?? I),
|
|
1052
|
+
successfulResponseHandler: t(_e),
|
|
1053
|
+
abortSignal: r,
|
|
1054
|
+
fetch: this.config.fetch
|
|
1055
|
+
});
|
|
1056
|
+
return {
|
|
1057
|
+
warnings: a,
|
|
1058
|
+
embeddings: l.data.map((e) => e.embedding),
|
|
1059
|
+
usage: l.usage ? { tokens: l.usage.prompt_tokens } : void 0,
|
|
1060
|
+
providerMetadata: l.providerMetadata,
|
|
1061
|
+
response: {
|
|
1062
|
+
headers: c,
|
|
1063
|
+
body: u
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
}, _e = v({
|
|
1068
|
+
data: i(v({ embedding: i(C()) })),
|
|
1069
|
+
usage: v({ prompt_tokens: C() }).nullish(),
|
|
1070
|
+
providerMetadata: A(E(), A(E(), k())).optional()
|
|
1071
|
+
}), X = class e {
|
|
1072
|
+
constructor(e, t) {
|
|
1073
|
+
this.modelId = e, this.config = t, this.specificationVersion = "v4", this.maxImagesPerCall = 10, this.supportsFileInputs = void 0, this.supportsMaskInputs = void 0;
|
|
1074
|
+
}
|
|
1075
|
+
get provider() {
|
|
1076
|
+
return this.config.provider;
|
|
1077
|
+
}
|
|
1078
|
+
get providerOptionsKey() {
|
|
1079
|
+
return this.config.provider.split(".")[0].trim();
|
|
1080
|
+
}
|
|
1081
|
+
static [r](e) {
|
|
1082
|
+
return T({
|
|
1083
|
+
modelId: e.modelId,
|
|
1084
|
+
config: e.config
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
static [f](t) {
|
|
1088
|
+
return new e(t.modelId, t.config);
|
|
1089
|
+
}
|
|
1090
|
+
getArgs(e, t) {
|
|
1091
|
+
return F({
|
|
1092
|
+
rawName: this.providerOptionsKey,
|
|
1093
|
+
providerOptions: e,
|
|
1094
|
+
warnings: t
|
|
1095
|
+
}), {
|
|
1096
|
+
...e[this.providerOptionsKey],
|
|
1097
|
+
...e[N(this.providerOptionsKey)]
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
async doGenerate({ prompt: e, n, size: r, aspectRatio: i, seed: a, providerOptions: o, headers: s, abortSignal: c, files: l, mask: u }) {
|
|
1101
|
+
let d = [];
|
|
1102
|
+
i != null && d.push({
|
|
1103
|
+
type: "unsupported",
|
|
1104
|
+
feature: "aspectRatio",
|
|
1105
|
+
details: "This model does not support aspect ratio. Use `size` instead."
|
|
1106
|
+
}), a != null && d.push({
|
|
1107
|
+
type: "unsupported",
|
|
1108
|
+
feature: "seed"
|
|
1109
|
+
});
|
|
1110
|
+
let f = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date(), p = this.getArgs(o, d);
|
|
1111
|
+
if (l != null && l.length > 0) {
|
|
1112
|
+
let { value: i, responseHeaders: a } = await re({
|
|
1113
|
+
url: this.config.url({
|
|
1114
|
+
path: "/images/edits",
|
|
1115
|
+
modelId: this.modelId
|
|
1116
|
+
}),
|
|
1117
|
+
headers: x(this.config.headers?.(), s),
|
|
1118
|
+
formData: ne({
|
|
1119
|
+
model: this.modelId,
|
|
1120
|
+
prompt: e,
|
|
1121
|
+
image: await Promise.all(l.map((e) => $(e))),
|
|
1122
|
+
mask: u == null ? void 0 : await $(u),
|
|
1123
|
+
n,
|
|
1124
|
+
size: r,
|
|
1125
|
+
...p
|
|
1126
|
+
}),
|
|
1127
|
+
failedResponseHandler: j(this.config.errorStructure ?? I),
|
|
1128
|
+
successfulResponseHandler: t(Q),
|
|
1129
|
+
abortSignal: c,
|
|
1130
|
+
fetch: this.config.fetch
|
|
1131
|
+
});
|
|
1132
|
+
return {
|
|
1133
|
+
images: i.data.map((e) => e.b64_json),
|
|
1134
|
+
warnings: d,
|
|
1135
|
+
usage: Z(i.usage),
|
|
1136
|
+
response: {
|
|
1137
|
+
timestamp: f,
|
|
1138
|
+
modelId: this.modelId,
|
|
1139
|
+
headers: a
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
let { value: m, responseHeaders: h } = await y({
|
|
1144
|
+
url: this.config.url({
|
|
1145
|
+
path: "/images/generations",
|
|
1146
|
+
modelId: this.modelId
|
|
1147
|
+
}),
|
|
1148
|
+
headers: x(this.config.headers?.(), s),
|
|
1149
|
+
body: {
|
|
1150
|
+
model: this.modelId,
|
|
1151
|
+
prompt: e,
|
|
1152
|
+
n,
|
|
1153
|
+
size: r,
|
|
1154
|
+
...p
|
|
1155
|
+
},
|
|
1156
|
+
failedResponseHandler: j(this.config.errorStructure ?? I),
|
|
1157
|
+
successfulResponseHandler: t(Q),
|
|
1158
|
+
abortSignal: c,
|
|
1159
|
+
fetch: this.config.fetch
|
|
1160
|
+
});
|
|
1161
|
+
return {
|
|
1162
|
+
images: m.data.map((e) => e.b64_json),
|
|
1163
|
+
warnings: d,
|
|
1164
|
+
usage: Z(m.usage),
|
|
1165
|
+
response: {
|
|
1166
|
+
timestamp: f,
|
|
1167
|
+
modelId: this.modelId,
|
|
1168
|
+
headers: h
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
function Z(e) {
|
|
1174
|
+
return e == null ? void 0 : {
|
|
1175
|
+
inputTokens: e.input_tokens ?? void 0,
|
|
1176
|
+
outputTokens: e.output_tokens ?? void 0,
|
|
1177
|
+
totalTokens: e.total_tokens ?? void 0
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
var Q = v({
|
|
1181
|
+
data: i(v({ b64_json: E() })),
|
|
1182
|
+
usage: v({
|
|
1183
|
+
input_tokens: C().nullish(),
|
|
1184
|
+
output_tokens: C().nullish(),
|
|
1185
|
+
total_tokens: C().nullish()
|
|
1186
|
+
}).nullish()
|
|
1187
|
+
});
|
|
1188
|
+
async function $(e) {
|
|
1189
|
+
if (e.type === "url") return o(e.url);
|
|
1190
|
+
let t = e.data instanceof Uint8Array ? e.data : S(e.data);
|
|
1191
|
+
return new Blob([t], { type: e.mediaType });
|
|
1192
|
+
}
|
|
1193
|
+
var ve = "3.0.59";
|
|
1194
|
+
function ye(e) {
|
|
1195
|
+
let t = ie(e.baseURL), n = e.name, r = {
|
|
1196
|
+
...e.apiKey && { Authorization: `Bearer ${e.apiKey}` },
|
|
1197
|
+
...e.headers
|
|
1198
|
+
}, i = () => c(r, `ai-sdk-openai-compatible/${ve}`), a = (r) => ({
|
|
1199
|
+
provider: `${n}.${r}`,
|
|
1200
|
+
url: ({ path: n }) => {
|
|
1201
|
+
let r = new URL(`${t}${n}`);
|
|
1202
|
+
return e.queryParams && (r.search = new URLSearchParams(e.queryParams).toString()), r.toString();
|
|
1203
|
+
},
|
|
1204
|
+
headers: i,
|
|
1205
|
+
fetch: e.fetch
|
|
1206
|
+
}), o = (e) => s(e), s = (t) => new V(t, {
|
|
1207
|
+
...a("chat"),
|
|
1208
|
+
includeUsage: e.includeUsage,
|
|
1209
|
+
supportsStructuredOutputs: e.supportsStructuredOutputs,
|
|
1210
|
+
supportedUrls: e.supportedUrls,
|
|
1211
|
+
transformRequestBody: e.transformRequestBody,
|
|
1212
|
+
metadataExtractor: e.metadataExtractor,
|
|
1213
|
+
convertUsage: e.convertUsage
|
|
1214
|
+
}), l = (t) => new pe(t, {
|
|
1215
|
+
...a("completion"),
|
|
1216
|
+
includeUsage: e.includeUsage
|
|
1217
|
+
}), u = (e) => new ge(e, { ...a("embedding") }), d = (e) => new X(e, a("image")), f = (e) => o(e);
|
|
1218
|
+
return f.specificationVersion = "v4", f.languageModel = o, f.chatModel = s, f.completionModel = l, f.embeddingModel = u, f.textEmbeddingModel = u, f.imageModel = d, f;
|
|
1219
|
+
}
|
|
1220
|
+
//#endregion
|
|
1221
|
+
export { ye as createOpenAICompatible };
|