vue-llm 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/providers.js CHANGED
@@ -1,98 +1,106 @@
1
- import { S as N } from "./sse-DU5m1n6r.js";
2
- import { c as le } from "./sse-DU5m1n6r.js";
3
- import { r as x, i as O, d as I } from "./file-x_kW7BHa.js";
4
- import { c as S } from "./errors-B3A_zmVE.js";
5
- function te(t) {
1
+ import { S as $ } from "./sse-DU5m1n6r.js";
2
+ import { c as ye } from "./sse-DU5m1n6r.js";
3
+ import { r as x, i as S, d as A } from "./file-x_kW7BHa.js";
4
+ import { c as P } from "./errors-B3A_zmVE.js";
5
+ function M() {
6
+ return typeof window < "u" || typeof globalThis.importScripts == "function";
7
+ }
8
+ function le(t) {
6
9
  return {
7
10
  id: "openai",
8
11
  supportsStreaming: !0,
9
12
  validateConfig() {
10
13
  if (!t.apiKey)
11
14
  throw new Error('[vue-llm] OpenAI API key is required. Pass it via createOpenAI({ apiKey: "..." })');
12
- if (!t.dangerouslyAllowBrowser && typeof window < "u")
15
+ if (!t.dangerouslyAllowBrowser && M())
13
16
  throw new Error(
14
17
  "[vue-llm] API keys must not be used in the browser. Use a server proxy (/api/chat) to keep keys safe. If you understand the risk, set dangerouslyAllowBrowser: true."
15
18
  );
16
19
  },
17
20
  async chat(e) {
18
- const o = t.baseURL ?? "https://api.openai.com/v1/chat/completions", a = {
21
+ const o = t.baseURL ?? "https://api.openai.com/v1/chat/completions", n = {
19
22
  model: e.model,
20
- messages: L(e.messages),
23
+ messages: D(e.messages),
21
24
  stream: !0,
22
25
  stream_options: { include_usage: !0 }
23
26
  };
24
- e.providerOptions?.response_format && (a.response_format = e.providerOptions.response_format), e.tools?.length && (a.tools = e.tools.map((f) => ({
27
+ e.providerOptions?.response_format && (n.response_format = e.providerOptions.response_format), e.tools?.length && (n.tools = e.tools.map((y) => ({
25
28
  type: "function",
26
29
  function: {
27
- name: f.name,
28
- description: f.description,
29
- parameters: f.parameters
30
+ name: y.name,
31
+ description: y.description,
32
+ parameters: y.parameters
30
33
  }
31
34
  })));
32
- const i = await fetch(o, {
35
+ const c = await fetch(o, {
33
36
  method: "POST",
34
37
  headers: {
35
38
  Authorization: `Bearer ${t.apiKey}`,
36
39
  "Content-Type": "application/json",
37
40
  ...e.providerOptions?.headers
38
41
  },
39
- body: JSON.stringify(a),
42
+ body: JSON.stringify(n),
40
43
  signal: e.signal
41
44
  });
42
- if (!i.ok)
43
- throw await S("openai", "OpenAI API", i);
44
- if (!i.body)
45
+ if (!c.ok)
46
+ throw await P("openai", "OpenAI API", c);
47
+ if (!c.body)
45
48
  throw new Error("[vue-llm] No response body from OpenAI");
46
- let s;
47
- const n = new Promise((f) => {
48
- s = f;
49
- });
50
- return { stream: i.body.pipeThrough(new TextDecoderStream()).pipeThrough(new N()).pipeThrough(new TransformStream({
51
- transform(f, y) {
52
- if (f.data === "[DONE]") return;
53
- let m;
49
+ let p;
50
+ const r = new Promise((y) => {
51
+ p = y;
52
+ }), m = /* @__PURE__ */ new Map();
53
+ return { stream: c.body.pipeThrough(new TextDecoderStream()).pipeThrough(new $()).pipeThrough(new TransformStream({
54
+ transform(y, s) {
55
+ if (y.data === "[DONE]") return;
56
+ let l;
54
57
  try {
55
- m = JSON.parse(f.data);
58
+ l = JSON.parse(y.data);
56
59
  } catch {
57
60
  return;
58
61
  }
59
- const c = m.choices?.[0];
60
- if (!c) {
61
- m.usage && s({
62
+ const i = l.choices?.[0];
63
+ if (!i) {
64
+ l.usage && p({
62
65
  finishReason: "stop",
63
66
  usage: {
64
- promptTokens: m.usage.prompt_tokens,
65
- completionTokens: m.usage.completion_tokens,
66
- totalTokens: m.usage.total_tokens
67
+ promptTokens: l.usage.prompt_tokens,
68
+ completionTokens: l.usage.completion_tokens,
69
+ totalTokens: l.usage.total_tokens
67
70
  }
68
71
  });
69
72
  return;
70
73
  }
71
- const l = c.delta;
72
- if (l.content && y.enqueue({ type: "text-delta", text: l.content }), l.tool_calls)
73
- for (const p of l.tool_calls)
74
- p.id && y.enqueue({
75
- type: "tool-call-start",
76
- toolCallId: p.id,
77
- toolName: p.function?.name ?? ""
78
- }), p.function?.arguments && y.enqueue({
79
- type: "tool-call-delta",
80
- toolCallId: p.id ?? "",
81
- args: p.function.arguments
82
- });
83
- if (c.finish_reason) {
84
- const p = l.tool_calls?.filter((r) => r.id) ?? [];
85
- for (const r of p)
86
- r.id && y.enqueue({ type: "tool-call-end", toolCallId: r.id });
87
- const d = c.finish_reason === "tool_calls" ? "tool-calls" : c.finish_reason === "length" ? "length" : "stop";
88
- y.enqueue({ type: "finish", finishReason: d, usage: void 0 });
74
+ const u = i.delta;
75
+ if (u.content && s.enqueue({ type: "text-delta", text: u.content }), u.tool_calls)
76
+ for (const [f, a] of u.tool_calls.entries()) {
77
+ const w = a.index ?? f;
78
+ let d = m.get(w);
79
+ if (d || (d = { started: !1, pendingArguments: [] }, m.set(w, d)), a.id && (d.id = a.id), a.function?.name && (d.name = a.function.name), d.id && d.name && !d.started) {
80
+ s.enqueue({
81
+ type: "tool-call-start",
82
+ toolCallId: d.id,
83
+ toolName: d.name
84
+ }), d.started = !0;
85
+ for (const g of d.pendingArguments)
86
+ s.enqueue({ type: "tool-call-delta", toolCallId: d.id, args: g });
87
+ d.pendingArguments = [];
88
+ }
89
+ a.function?.arguments && (d.started && d.id ? s.enqueue({ type: "tool-call-delta", toolCallId: d.id, args: a.function.arguments }) : d.pendingArguments.push(a.function.arguments));
90
+ }
91
+ if (i.finish_reason) {
92
+ for (const a of m.values())
93
+ a.started && a.id && s.enqueue({ type: "tool-call-end", toolCallId: a.id });
94
+ m.clear();
95
+ const f = i.finish_reason === "tool_calls" ? "tool-calls" : i.finish_reason === "length" ? "length" : "stop";
96
+ s.enqueue({ type: "finish", finishReason: f, usage: void 0 });
89
97
  }
90
98
  }
91
- })), response: n };
99
+ })), response: r };
92
100
  }
93
101
  };
94
102
  }
95
- function L(t) {
103
+ function D(t) {
96
104
  return t.map((e) => e.role === "tool" ? {
97
105
  role: "tool",
98
106
  content: typeof e.content == "string" ? e.content : JSON.stringify(e.content),
@@ -110,10 +118,10 @@ function L(t) {
110
118
  }))
111
119
  } : {
112
120
  role: e.role,
113
- content: typeof e.content == "string" ? e.content : e.content.map(M)
121
+ content: typeof e.content == "string" ? e.content : e.content.map(G)
114
122
  });
115
123
  }
116
- function M(t) {
124
+ function G(t) {
117
125
  if (t.type === "text") return { type: "text", text: t.text };
118
126
  const e = x(t);
119
127
  if (e.mediaType.startsWith("image/"))
@@ -125,44 +133,44 @@ function M(t) {
125
133
  type: "file",
126
134
  file: { filename: e.filename ?? "document.pdf", file_data: e.url }
127
135
  };
128
- const o = J[e.mediaType];
136
+ const o = j[e.mediaType];
129
137
  if (o)
130
138
  return { type: "input_audio", input_audio: { data: e.base64, format: o } };
131
- if (O(e.mediaType))
132
- return { type: "text", text: I(e.base64) };
139
+ if (S(e.mediaType))
140
+ return { type: "text", text: A(e.base64) };
133
141
  throw new Error(`[vue-llm] OpenAI does not support ${e.mediaType} attachments`);
134
142
  }
135
- const J = {
143
+ const j = {
136
144
  "audio/wav": "wav",
137
145
  "audio/x-wav": "wav",
138
146
  "audio/mpeg": "mp3",
139
147
  "audio/mp3": "mp3"
140
148
  };
141
- function oe(t) {
149
+ function pe(t) {
142
150
  return {
143
151
  id: "anthropic",
144
152
  supportsStreaming: !0,
145
153
  validateConfig() {
146
154
  if (!t.apiKey)
147
155
  throw new Error('[vue-llm] Anthropic API key is required. Pass it via createAnthropic({ apiKey: "..." })');
148
- if (!t.dangerouslyAllowBrowser && typeof window < "u")
156
+ if (!t.dangerouslyAllowBrowser && M())
149
157
  throw new Error(
150
158
  "[vue-llm] API keys must not be used in the browser. Use a server proxy (/api/chat) to keep keys safe. If you understand the risk, set dangerouslyAllowBrowser: true."
151
159
  );
152
160
  },
153
161
  async chat(e) {
154
- const o = (t.baseURL ?? "https://api.anthropic.com") + "/v1/messages", a = e.messages.find((c) => c.role === "system"), i = e.messages.filter((c) => c.role !== "system"), s = {
162
+ const o = (t.baseURL ?? "https://api.anthropic.com") + "/v1/messages", n = e.messages.find((l) => l.role === "system"), c = e.messages.filter((l) => l.role !== "system"), p = {
155
163
  model: e.model,
156
- messages: U(i),
164
+ messages: K(c),
157
165
  max_tokens: e.providerOptions?.maxTokens ?? 4096,
158
166
  stream: !0
159
167
  };
160
- a && (s.system = typeof a.content == "string" ? a.content : a.content.map((c) => ({ type: "text", text: c.type === "text" ? c.text : "" }))), e.tools?.length && (s.tools = e.tools.map((c) => ({
161
- name: c.name,
162
- description: c.description,
163
- input_schema: c.parameters
168
+ n && (p.system = typeof n.content == "string" ? n.content : n.content.map((l) => ({ type: "text", text: l.type === "text" ? l.text : "" }))), e.tools?.length && (p.tools = e.tools.map((l) => ({
169
+ name: l.name,
170
+ description: l.description,
171
+ input_schema: l.parameters
164
172
  })));
165
- const n = await fetch(o, {
173
+ const r = await fetch(o, {
166
174
  method: "POST",
167
175
  headers: {
168
176
  "x-api-key": t.apiKey,
@@ -170,73 +178,73 @@ function oe(t) {
170
178
  "Content-Type": "application/json",
171
179
  ...e.providerOptions?.headers
172
180
  },
173
- body: JSON.stringify(s),
181
+ body: JSON.stringify(p),
174
182
  signal: e.signal
175
183
  });
176
- if (!n.ok)
177
- throw await S("anthropic", "Anthropic API", n);
178
- if (!n.body)
184
+ if (!r.ok)
185
+ throw await P("anthropic", "Anthropic API", r);
186
+ if (!r.body)
179
187
  throw new Error("[vue-llm] No response body from Anthropic");
180
- let u;
181
- const f = new Promise((c) => {
182
- u = c;
188
+ let m;
189
+ const _ = new Promise((l) => {
190
+ m = l;
183
191
  });
184
192
  let y = "";
185
- return { stream: n.body.pipeThrough(new TextDecoderStream()).pipeThrough(new N()).pipeThrough(new TransformStream({
186
- transform(c, l) {
187
- let p;
193
+ return { stream: r.body.pipeThrough(new TextDecoderStream()).pipeThrough(new $()).pipeThrough(new TransformStream({
194
+ transform(l, i) {
195
+ let u;
188
196
  try {
189
- p = JSON.parse(c.data);
197
+ u = JSON.parse(l.data);
190
198
  } catch {
191
199
  return;
192
200
  }
193
- switch (c.event ?? p.type) {
201
+ switch (l.event ?? u.type) {
194
202
  case "content_block_start": {
195
- const r = p.content_block;
196
- r?.type === "tool_use" && (y = r.id, l.enqueue({
203
+ const a = u.content_block;
204
+ a?.type === "tool_use" && (y = a.id, i.enqueue({
197
205
  type: "tool-call-start",
198
206
  toolCallId: y,
199
- toolName: r.name
207
+ toolName: a.name
200
208
  }));
201
209
  break;
202
210
  }
203
211
  case "content_block_delta": {
204
- const r = p.delta;
205
- r?.type === "text_delta" && r.text && l.enqueue({ type: "text-delta", text: r.text }), r?.type === "thinking_delta" && r.text && l.enqueue({ type: "reasoning-delta", text: r.text }), r?.type === "input_json_delta" && r.partial_json && l.enqueue({
212
+ const a = u.delta;
213
+ a?.type === "text_delta" && a.text && i.enqueue({ type: "text-delta", text: a.text }), a?.type === "thinking_delta" && a.text && i.enqueue({ type: "reasoning-delta", text: a.text }), a?.type === "input_json_delta" && a.partial_json && i.enqueue({
206
214
  type: "tool-call-delta",
207
215
  toolCallId: y,
208
- args: r.partial_json
216
+ args: a.partial_json
209
217
  });
210
218
  break;
211
219
  }
212
220
  case "content_block_stop": {
213
- y && (l.enqueue({ type: "tool-call-end", toolCallId: y }), y = "");
221
+ y && (i.enqueue({ type: "tool-call-end", toolCallId: y }), y = "");
214
222
  break;
215
223
  }
216
224
  case "message_delta": {
217
- const r = p.delta, w = p.usage, _ = r?.stop_reason === "tool_use" ? "tool-calls" : r?.stop_reason === "max_tokens" ? "length" : "stop";
218
- l.enqueue({
225
+ const a = u.delta, w = u.usage, d = a?.stop_reason === "tool_use" ? "tool-calls" : a?.stop_reason === "max_tokens" ? "length" : "stop";
226
+ i.enqueue({
219
227
  type: "finish",
220
- finishReason: _,
228
+ finishReason: d,
221
229
  usage: w ? { promptTokens: 0, completionTokens: w.output_tokens ?? 0, totalTokens: w.output_tokens ?? 0 } : void 0
222
- }), u({ finishReason: _, usage: void 0 });
230
+ }), m({ finishReason: d, usage: void 0 });
223
231
  break;
224
232
  }
225
233
  case "error": {
226
- const r = p.error;
227
- l.enqueue({
234
+ const a = u.error;
235
+ i.enqueue({
228
236
  type: "error",
229
- error: new Error(`[vue-llm] Anthropic stream error: ${r?.message ?? "unknown"}`)
237
+ error: new Error(`[vue-llm] Anthropic stream error: ${a?.message ?? "unknown"}`)
230
238
  });
231
239
  break;
232
240
  }
233
241
  }
234
242
  }
235
- })), response: f };
243
+ })), response: _ };
236
244
  }
237
245
  };
238
246
  }
239
- function U(t) {
247
+ function K(t) {
240
248
  return t.map((e) => {
241
249
  if (e.role === "tool")
242
250
  return {
@@ -250,133 +258,133 @@ function U(t) {
250
258
  if (e.role === "assistant" && e.toolCalls?.length) {
251
259
  const o = [];
252
260
  typeof e.content == "string" && e.content && o.push({ type: "text", text: e.content });
253
- for (const a of e.toolCalls)
261
+ for (const n of e.toolCalls)
254
262
  o.push({
255
263
  type: "tool_use",
256
- id: a.id,
257
- name: a.name,
258
- input: a.args
264
+ id: n.id,
265
+ name: n.name,
266
+ input: n.args
259
267
  });
260
268
  return { role: "assistant", content: o };
261
269
  }
262
270
  return {
263
271
  role: e.role,
264
- content: typeof e.content == "string" ? e.content : e.content.map($)
272
+ content: typeof e.content == "string" ? e.content : e.content.map(B)
265
273
  };
266
274
  });
267
275
  }
268
- function $(t) {
276
+ function B(t) {
269
277
  if (t.type === "text") return { type: "text", text: t.text };
270
278
  const e = x(t), o = e.base64 ? { type: "base64", media_type: e.mediaType, data: e.base64 } : { type: "url", url: e.url };
271
279
  if (e.mediaType.startsWith("image/"))
272
280
  return { type: "image", source: o };
273
281
  if (e.mediaType === "application/pdf")
274
282
  return { type: "document", source: o, ...e.filename ? { title: e.filename } : {} };
275
- if (O(e.mediaType) && e.base64)
283
+ if (S(e.mediaType) && e.base64)
276
284
  return {
277
285
  type: "document",
278
- source: { type: "text", media_type: "text/plain", data: I(e.base64) },
286
+ source: { type: "text", media_type: "text/plain", data: A(e.base64) },
279
287
  ...e.filename ? { title: e.filename } : {}
280
288
  };
281
289
  throw new Error(`[vue-llm] Anthropic does not support ${e.mediaType} attachments`);
282
290
  }
283
- function ne(t) {
291
+ function ce(t) {
284
292
  return {
285
293
  id: "google",
286
294
  supportsStreaming: !0,
287
295
  validateConfig() {
288
296
  if (!t.apiKey)
289
297
  throw new Error('[vue-llm] Google AI API key is required. Pass it via createGoogle({ apiKey: "..." })');
290
- if (!t.dangerouslyAllowBrowser && typeof window < "u")
298
+ if (!t.dangerouslyAllowBrowser && M())
291
299
  throw new Error(
292
300
  "[vue-llm] API keys must not be used in the browser. Use a server proxy to keep keys safe. If you understand the risk, set dangerouslyAllowBrowser: true."
293
301
  );
294
302
  },
295
303
  async chat(e) {
296
- const a = `${t.baseURL ?? "https://generativelanguage.googleapis.com/v1beta"}/models/${e.model}:streamGenerateContent?alt=sse&key=${t.apiKey}`, i = {
297
- contents: W(e.messages)
298
- }, s = e.messages.find((l) => l.role === "system");
299
- s && (i.systemInstruction = {
300
- parts: [{ text: typeof s.content == "string" ? s.content : "" }]
301
- }), e.tools?.length && (i.tools = [{
302
- functionDeclarations: e.tools.map((l) => ({
303
- name: l.name,
304
- description: l.description,
305
- parameters: l.parameters
304
+ const n = `${t.baseURL ?? "https://generativelanguage.googleapis.com/v1beta"}/models/${e.model}:streamGenerateContent?alt=sse&key=${t.apiKey}`, c = {
305
+ contents: q(e.messages)
306
+ }, p = e.messages.find((i) => i.role === "system");
307
+ p && (c.systemInstruction = {
308
+ parts: [{ text: typeof p.content == "string" ? p.content : "" }]
309
+ }), e.tools?.length && (c.tools = [{
310
+ functionDeclarations: e.tools.map((i) => ({
311
+ name: i.name,
312
+ description: i.description,
313
+ parameters: i.parameters
306
314
  }))
307
- }]), i.generationConfig = {
315
+ }]), c.generationConfig = {
308
316
  ...e.providerOptions?.response_format?.type === "json_object" ? { responseMimeType: "application/json" } : {}
309
317
  };
310
- const n = await fetch(a, {
318
+ const r = await fetch(n, {
311
319
  method: "POST",
312
320
  headers: {
313
321
  "Content-Type": "application/json",
314
322
  ...e.providerOptions?.headers
315
323
  },
316
- body: JSON.stringify(i),
324
+ body: JSON.stringify(c),
317
325
  signal: e.signal
318
326
  });
319
- if (!n.ok)
320
- throw await S("google", "Google AI API", n);
321
- if (!n.body)
327
+ if (!r.ok)
328
+ throw await P("google", "Google AI API", r);
329
+ if (!r.body)
322
330
  throw new Error("[vue-llm] No response body from Google AI");
323
- let u;
324
- const f = new Promise((l) => {
325
- u = l;
331
+ let m;
332
+ const _ = new Promise((i) => {
333
+ m = i;
326
334
  });
327
- let y = 0, m = !1;
328
- return { stream: n.body.pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
335
+ let y = 0, s = !1;
336
+ return { stream: r.body.pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
329
337
  buffer: "",
330
- transform(l, p) {
331
- this.buffer += l;
332
- const d = this.buffer.split(`
338
+ transform(i, u) {
339
+ this.buffer += i;
340
+ const f = this.buffer.split(`
333
341
  `);
334
- this.buffer = d.pop();
335
- for (const r of d)
336
- r.startsWith("data: ") && p.enqueue(r.slice(6));
342
+ this.buffer = f.pop();
343
+ for (const a of f)
344
+ a.startsWith("data: ") && u.enqueue(a.slice(6));
337
345
  },
338
- flush(l) {
339
- const p = this.buffer.trim();
340
- p.startsWith("data: ") && l.enqueue(p.slice(6));
346
+ flush(i) {
347
+ const u = this.buffer.trim();
348
+ u.startsWith("data: ") && i.enqueue(u.slice(6));
341
349
  }
342
350
  })).pipeThrough(new TransformStream({
343
- transform(l, p) {
344
- let d;
351
+ transform(i, u) {
352
+ let f;
345
353
  try {
346
- d = JSON.parse(l);
354
+ f = JSON.parse(i);
347
355
  } catch {
348
356
  return;
349
357
  }
350
- const r = d.candidates?.[0];
351
- if (!r) return;
352
- const w = r.content?.parts;
358
+ const a = f.candidates?.[0];
359
+ if (!a) return;
360
+ const w = a.content?.parts;
353
361
  if (w) {
354
- for (const _ of w)
355
- if (_.text !== void 0 && p.enqueue({ type: "text-delta", text: _.text }), _.functionCall) {
362
+ for (const d of w)
363
+ if (d.text !== void 0 && u.enqueue({ type: "text-delta", text: d.text }), d.functionCall) {
356
364
  const g = `tc_gemini_${++y}`;
357
- m = !0, p.enqueue({
365
+ s = !0, u.enqueue({
358
366
  type: "tool-call-start",
359
367
  toolCallId: g,
360
- toolName: _.functionCall.name
361
- }), p.enqueue({
368
+ toolName: d.functionCall.name
369
+ }), u.enqueue({
362
370
  type: "tool-call-delta",
363
371
  toolCallId: g,
364
- args: JSON.stringify(_.functionCall.args ?? {})
365
- }), p.enqueue({ type: "tool-call-end", toolCallId: g });
372
+ args: JSON.stringify(d.functionCall.args ?? {})
373
+ }), u.enqueue({ type: "tool-call-end", toolCallId: g });
366
374
  }
367
375
  }
368
- if (r.finishReason) {
369
- const _ = m ? "tool-calls" : r.finishReason === "MAX_TOKENS" ? "length" : "stop", g = d.usageMetadata;
370
- p.enqueue({
376
+ if (a.finishReason) {
377
+ const d = s ? "tool-calls" : a.finishReason === "MAX_TOKENS" ? "length" : "stop", g = f.usageMetadata;
378
+ u.enqueue({
371
379
  type: "finish",
372
- finishReason: _,
380
+ finishReason: d,
373
381
  usage: g ? {
374
382
  promptTokens: g.promptTokenCount ?? 0,
375
383
  completionTokens: g.candidatesTokenCount ?? 0,
376
384
  totalTokens: g.totalTokenCount ?? 0
377
385
  } : void 0
378
- }), u({
379
- finishReason: _,
386
+ }), m({
387
+ finishReason: d,
380
388
  usage: g ? {
381
389
  promptTokens: g.promptTokenCount ?? 0,
382
390
  completionTokens: g.candidatesTokenCount ?? 0,
@@ -385,49 +393,49 @@ function ne(t) {
385
393
  });
386
394
  }
387
395
  }
388
- })), response: f };
396
+ })), response: _ };
389
397
  }
390
398
  };
391
399
  }
392
- function W(t) {
400
+ function q(t) {
393
401
  const e = [], o = /* @__PURE__ */ new Map();
394
- for (const a of t) {
395
- if (a.role === "system") continue;
396
- if (a.role === "tool") {
397
- const n = {
402
+ for (const n of t) {
403
+ if (n.role === "system") continue;
404
+ if (n.role === "tool") {
405
+ const r = {
398
406
  functionResponse: {
399
- name: o.get(a.toolCallId ?? "") ?? a.toolCallId ?? "",
400
- response: { result: j(a.content) }
407
+ name: o.get(n.toolCallId ?? "") ?? n.toolCallId ?? "",
408
+ response: { result: F(n.content) }
401
409
  }
402
- }, u = e.at(-1);
403
- u?.role === "user" && u.parts.every((f) => f.functionResponse) ? u.parts.push(n) : e.push({ role: "user", parts: [n] });
410
+ }, m = e.at(-1);
411
+ m?.role === "user" && m.parts.every((_) => _.functionResponse) ? m.parts.push(r) : e.push({ role: "user", parts: [r] });
404
412
  continue;
405
413
  }
406
- for (const n of a.toolCalls ?? [])
407
- o.set(n.id, n.name);
408
- const i = a.role === "assistant" ? "model" : "user", s = [];
409
- if (typeof a.content == "string")
410
- a.content && s.push({ text: a.content });
411
- else if (Array.isArray(a.content)) {
412
- for (const n of a.content)
413
- if (n.type === "text" && s.push({ text: n.text }), n.type === "image" || n.type === "file") {
414
- const u = x(n);
415
- s.push(u.base64 ? { inlineData: { mimeType: u.mediaType, data: u.base64 } } : { fileData: { mimeType: u.mediaType, fileUri: u.url } });
414
+ for (const r of n.toolCalls ?? [])
415
+ o.set(r.id, r.name);
416
+ const c = n.role === "assistant" ? "model" : "user", p = [];
417
+ if (typeof n.content == "string")
418
+ n.content && p.push({ text: n.content });
419
+ else if (Array.isArray(n.content)) {
420
+ for (const r of n.content)
421
+ if (r.type === "text" && p.push({ text: r.text }), r.type === "image" || r.type === "file") {
422
+ const m = x(r);
423
+ p.push(m.base64 ? { inlineData: { mimeType: m.mediaType, data: m.base64 } } : { fileData: { mimeType: m.mediaType, fileUri: m.url } });
416
424
  }
417
425
  }
418
- if (a.toolCalls?.length)
419
- for (const n of a.toolCalls)
420
- s.push({
426
+ if (n.toolCalls?.length)
427
+ for (const r of n.toolCalls)
428
+ p.push({
421
429
  functionCall: {
422
- name: n.name,
423
- args: typeof n.args == "string" ? JSON.parse(n.args) : n.args
430
+ name: r.name,
431
+ args: typeof r.args == "string" ? JSON.parse(r.args) : r.args
424
432
  }
425
433
  });
426
- s.length > 0 && e.push({ role: i, parts: s });
434
+ p.length > 0 && e.push({ role: c, parts: p });
427
435
  }
428
436
  return e;
429
437
  }
430
- function j(t) {
438
+ function F(t) {
431
439
  if (typeof t != "string") return t;
432
440
  try {
433
441
  return JSON.parse(t);
@@ -435,90 +443,90 @@ function j(t) {
435
443
  return t;
436
444
  }
437
445
  }
438
- function ae(t) {
446
+ function ue(t) {
439
447
  return {
440
448
  id: "ollama",
441
449
  supportsStreaming: !0,
442
450
  validateConfig() {
443
451
  },
444
452
  async chat(e) {
445
- const o = (t?.baseURL ?? "http://localhost:11434") + "/api/chat", a = {
453
+ const o = (t?.baseURL ?? "http://localhost:11434") + "/api/chat", n = {
446
454
  model: e.model,
447
- messages: G(e.messages),
455
+ messages: H(e.messages),
448
456
  stream: !0
449
457
  };
450
- e.tools?.length && (a.tools = e.tools.map((m) => ({
458
+ e.tools?.length && (n.tools = e.tools.map((s) => ({
451
459
  type: "function",
452
460
  function: {
453
- name: m.name,
454
- description: m.description,
455
- parameters: m.parameters
461
+ name: s.name,
462
+ description: s.description,
463
+ parameters: s.parameters
456
464
  }
457
465
  })));
458
- const i = await fetch(o, {
466
+ const c = await fetch(o, {
459
467
  method: "POST",
460
468
  headers: {
461
469
  "Content-Type": "application/json",
462
470
  ...e.providerOptions?.headers
463
471
  },
464
- body: JSON.stringify(a),
472
+ body: JSON.stringify(n),
465
473
  signal: e.signal
466
474
  });
467
- if (!i.ok)
468
- throw await S("ollama", "Ollama API", i);
469
- if (!i.body)
475
+ if (!c.ok)
476
+ throw await P("ollama", "Ollama API", c);
477
+ if (!c.body)
470
478
  throw new Error("[vue-llm] No response body from Ollama");
471
- let s;
472
- const n = new Promise((m) => {
473
- s = m;
479
+ let p;
480
+ const r = new Promise((s) => {
481
+ p = s;
474
482
  });
475
- let u = "", f = !1;
476
- return { stream: i.body.pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
477
- transform(m, c) {
478
- u += m;
479
- const l = u.split(`
483
+ let m = "", _ = !1;
484
+ return { stream: c.body.pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({
485
+ transform(s, l) {
486
+ m += s;
487
+ const i = m.split(`
480
488
  `);
481
- u = l.pop() ?? "";
482
- for (const p of l) {
483
- if (!p.trim()) continue;
484
- let d;
489
+ m = i.pop() ?? "";
490
+ for (const u of i) {
491
+ if (!u.trim()) continue;
492
+ let f;
485
493
  try {
486
- d = JSON.parse(p);
494
+ f = JSON.parse(u);
487
495
  } catch {
488
496
  continue;
489
497
  }
490
- if (d.message?.content && c.enqueue({ type: "text-delta", text: d.message.content }), d.message?.tool_calls)
491
- for (const r of d.message.tool_calls) {
492
- f = !0;
498
+ if (f.message?.content && l.enqueue({ type: "text-delta", text: f.message.content }), f.message?.tool_calls)
499
+ for (const a of f.message.tool_calls) {
500
+ _ = !0;
493
501
  const w = `ollama-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
494
- c.enqueue({
502
+ l.enqueue({
495
503
  type: "tool-call-start",
496
504
  toolCallId: w,
497
- toolName: r.function.name
498
- }), c.enqueue({
505
+ toolName: a.function.name
506
+ }), l.enqueue({
499
507
  type: "tool-call-delta",
500
508
  toolCallId: w,
501
- args: JSON.stringify(r.function.arguments)
502
- }), c.enqueue({ type: "tool-call-end", toolCallId: w });
509
+ args: JSON.stringify(a.function.arguments)
510
+ }), l.enqueue({ type: "tool-call-end", toolCallId: w });
503
511
  }
504
- if (d.done) {
505
- const r = f ? "tool-calls" : "stop";
506
- c.enqueue({ type: "finish", finishReason: r }), s({
507
- finishReason: r,
508
- usage: d.eval_count ? {
509
- promptTokens: d.prompt_eval_count ?? 0,
510
- completionTokens: d.eval_count,
511
- totalTokens: (d.prompt_eval_count ?? 0) + d.eval_count
512
+ if (f.done) {
513
+ const a = _ ? "tool-calls" : "stop";
514
+ l.enqueue({ type: "finish", finishReason: a }), p({
515
+ finishReason: a,
516
+ usage: f.eval_count ? {
517
+ promptTokens: f.prompt_eval_count ?? 0,
518
+ completionTokens: f.eval_count,
519
+ totalTokens: (f.prompt_eval_count ?? 0) + f.eval_count
512
520
  } : void 0
513
521
  });
514
522
  }
515
523
  }
516
524
  }
517
- })), response: n };
525
+ })), response: r };
518
526
  }
519
527
  };
520
528
  }
521
- function G(t) {
529
+ function H(t) {
522
530
  const e = /* @__PURE__ */ new Map();
523
531
  return t.map((o) => {
524
532
  if (o.role === "tool")
@@ -528,172 +536,198 @@ function G(t) {
528
536
  tool_name: e.get(o.toolCallId ?? "")
529
537
  };
530
538
  if (o.role === "assistant" && o.toolCalls?.length) {
531
- for (const s of o.toolCalls) e.set(s.id, s.name);
539
+ for (const p of o.toolCalls) e.set(p.id, p.name);
532
540
  return {
533
541
  role: "assistant",
534
542
  content: typeof o.content == "string" ? o.content : "",
535
- tool_calls: o.toolCalls.map((s) => ({
543
+ tool_calls: o.toolCalls.map((p) => ({
536
544
  function: {
537
- name: s.name,
538
- arguments: typeof s.args == "string" ? JSON.parse(s.args) : s.args
545
+ name: p.name,
546
+ arguments: typeof p.args == "string" ? JSON.parse(p.args) : p.args
539
547
  }
540
548
  }))
541
549
  };
542
550
  }
543
551
  if (typeof o.content == "string")
544
552
  return { role: o.role, content: o.content };
545
- const a = [], i = [];
546
- for (const s of o.content) {
547
- if (s.type === "text") {
548
- a.push(s.text);
553
+ const n = [], c = [];
554
+ for (const p of o.content) {
555
+ if (p.type === "text") {
556
+ n.push(p.text);
549
557
  continue;
550
558
  }
551
- const n = x(s);
552
- if (!n.base64)
559
+ const r = x(p);
560
+ if (!r.base64)
553
561
  throw new Error("[vue-llm] Ollama requires attachments as data URLs, got a remote URL");
554
- if (n.mediaType.startsWith("image/"))
555
- i.push(n.base64);
556
- else if (O(n.mediaType))
557
- a.push(I(n.base64));
562
+ if (r.mediaType.startsWith("image/"))
563
+ c.push(r.base64);
564
+ else if (S(r.mediaType))
565
+ n.push(A(r.base64));
558
566
  else
559
- throw new Error(`[vue-llm] Ollama does not support ${n.mediaType} attachments`);
567
+ throw new Error(`[vue-llm] Ollama does not support ${r.mediaType} attachments`);
560
568
  }
561
569
  return {
562
570
  role: o.role,
563
- content: a.join(`
571
+ content: n.join(`
564
572
 
565
573
  `),
566
- ...i.length > 0 ? { images: i } : {}
574
+ ...c.length > 0 ? { images: c } : {}
567
575
  };
568
576
  });
569
577
  }
570
- function D() {
578
+ function z() {
571
579
  return typeof navigator < "u" && "gpu" in navigator && !!navigator.gpu;
572
580
  }
573
- function se(t) {
574
- let e, o, a;
575
- const i = (n) => t.onProgress?.(n);
576
- function s(n) {
577
- if (o === n && !a) return Promise.resolve();
578
- const f = (a ?? Promise.resolve()).catch(() => {
581
+ async function X() {
582
+ try {
583
+ const e = await navigator.gpu?.requestAdapter();
584
+ return e?.features.has("shader-f16") ? e.info?.vendor?.toLowerCase().includes("intel") ? "f32" : "f16" : "f32";
585
+ } catch {
586
+ return "f32";
587
+ }
588
+ }
589
+ const J = /-q(\d)f(16|32)(_\d+)?-/;
590
+ function fe(t) {
591
+ let e, o, n, c, p;
592
+ const r = (s) => t.onProgress?.(s);
593
+ async function m(s) {
594
+ const l = J.exec(s);
595
+ if (!l) return s;
596
+ const i = t.precision ?? "auto";
597
+ if (i === "auto" && l[2] === "32") return s;
598
+ const u = i === "auto" ? await (p ??= X()) : i;
599
+ return s.replace(J, `-q${l[1]}${u}${l[3] ?? ""}-`);
600
+ }
601
+ async function _(s) {
602
+ if (e)
603
+ await (await e).reload(s, t.chatOptions);
604
+ else {
605
+ e = t.createEngine(
606
+ s,
607
+ { ...t.engineConfig, initProgressCallback: r },
608
+ t.chatOptions
609
+ );
610
+ try {
611
+ await e;
612
+ } catch (l) {
613
+ throw e = void 0, l;
614
+ }
615
+ }
616
+ }
617
+ function y(s) {
618
+ if (o === s && !c) return Promise.resolve();
619
+ const i = (c ?? Promise.resolve()).catch(() => {
579
620
  }).then(async () => {
580
- if (o !== n) {
581
- if (e)
582
- o = void 0, await (await e).reload(n, t.chatOptions);
583
- else {
584
- e = t.createEngine(
585
- n,
586
- { ...t.engineConfig, initProgressCallback: i },
587
- t.chatOptions
588
- );
589
- try {
590
- await e;
591
- } catch (m) {
592
- throw e = void 0, m;
593
- }
594
- }
595
- o = n;
621
+ if (o === s) return;
622
+ o = void 0, n = void 0;
623
+ let f = await m(s);
624
+ try {
625
+ await _(f);
626
+ } catch (a) {
627
+ if (f === s || a?.name !== "ModelNotFoundError") throw a;
628
+ console.warn(`[vue-llm] ${f} is not available, loading ${s} instead`), f = s, await _(f);
596
629
  }
630
+ o = s, n = f;
597
631
  });
598
- a = f;
599
- const y = () => {
600
- a === f && (a = void 0);
632
+ c = i;
633
+ const u = () => {
634
+ c === i && (c = void 0);
601
635
  };
602
- return f.then(y, y), f;
636
+ return i.then(u, u), i;
603
637
  }
604
638
  return {
605
639
  id: "webllm",
606
640
  supportsStreaming: !0,
607
641
  get loadedModel() {
608
- return o;
642
+ return n;
609
643
  },
610
644
  validateConfig() {
611
645
  if (typeof t.createEngine != "function")
612
646
  throw new Error(
613
647
  "[vue-llm] createWebLLM requires an engine factory. Pass createWebLLM({ createEngine: CreateMLCEngine }) from @mlc-ai/web-llm"
614
648
  );
615
- if (!D())
649
+ if (!z())
616
650
  throw new Error("[vue-llm] In-browser models require WebGPU, which this browser does not support");
617
651
  },
618
- load: s,
652
+ load: y,
619
653
  async unload() {
620
- const n = e;
621
- e = void 0, o = void 0, n && await (await n).unload();
654
+ const s = e;
655
+ e = void 0, o = void 0, n = void 0, s && await (await s).unload();
622
656
  },
623
- async chat(n) {
624
- await s(n.model);
625
- const u = await e;
626
- if (n.signal?.aborted)
627
- throw n.signal.reason ?? new DOMException("Aborted", "AbortError");
628
- const f = {
629
- ...B(n.providerOptions),
630
- messages: F(n.messages),
657
+ async chat(s) {
658
+ await y(s.model);
659
+ const l = await e;
660
+ if (s.signal?.aborted)
661
+ throw s.signal.reason ?? new DOMException("Aborted", "AbortError");
662
+ const i = {
663
+ ...V(s.providerOptions),
664
+ messages: Y(s.messages),
631
665
  stream: !0,
632
666
  stream_options: { include_usage: !0 }
633
667
  };
634
- n.providerOptions?.response_format && (f.response_format = n.providerOptions.response_format), n.tools?.length && (f.tools = n.tools.map((h) => ({
668
+ s.providerOptions?.response_format && (i.response_format = s.providerOptions.response_format), s.tools?.length && (i.tools = s.tools.map((h) => ({
635
669
  type: "function",
636
670
  function: { name: h.name, description: h.description, parameters: h.parameters }
637
671
  })));
638
- const y = await u.chat.completions.create(f), m = () => {
639
- u.interruptGenerate();
672
+ const u = await l.chat.completions.create(i), f = () => {
673
+ l.interruptGenerate();
640
674
  };
641
- n.signal?.addEventListener("abort", m, { once: !0 });
642
- let c, l;
643
- const p = new Promise((h, T) => {
644
- c = h, l = T;
675
+ s.signal?.addEventListener("abort", f, { once: !0 });
676
+ let a, w;
677
+ const d = new Promise((h, b) => {
678
+ a = h, w = b;
645
679
  });
646
- p.catch(() => {
680
+ d.catch(() => {
647
681
  });
648
- const d = y[Symbol.asyncIterator](), r = q(), w = /* @__PURE__ */ new Map();
649
- let _ = "stop", g;
650
- const A = () => n.signal?.removeEventListener("abort", m), E = (h) => {
651
- h.usage && (g = {
682
+ const g = u[Symbol.asyncIterator](), L = oe(), C = /* @__PURE__ */ new Map();
683
+ let N = "stop", O;
684
+ const E = () => s.signal?.removeEventListener("abort", f), U = (h) => {
685
+ h.usage && (O = {
652
686
  promptTokens: h.usage.prompt_tokens,
653
687
  completionTokens: h.usage.completion_tokens,
654
688
  totalTokens: h.usage.total_tokens
655
689
  });
656
- const T = h.choices?.[0];
657
- if (!T) return [];
658
- const v = [];
659
- T.delta?.content && v.push(...r.push(T.delta.content));
660
- for (const [C, b] of (T.delta?.tool_calls ?? []).entries()) {
661
- const P = b.index ?? C;
662
- let k = w.get(P);
663
- if (k || (k = b.id ?? `webllm-call-${P}-${Date.now().toString(36)}`, w.set(P, k), v.push({ type: "tool-call-start", toolCallId: k, toolName: b.function?.name ?? "" })), b.function?.arguments) {
664
- const R = typeof b.function.arguments == "string" ? b.function.arguments : JSON.stringify(b.function.arguments);
665
- v.push({ type: "tool-call-delta", toolCallId: k, args: R });
690
+ const b = h.choices?.[0];
691
+ if (!b) return [];
692
+ const T = [];
693
+ b.delta?.content && T.push(...L.push(b.delta.content));
694
+ for (const [I, v] of (b.delta?.tool_calls ?? []).entries()) {
695
+ const R = v.index ?? I;
696
+ let k = C.get(R);
697
+ if (k || (k = v.id ?? `webllm-call-${R}-${Date.now().toString(36)}`, C.set(R, k), T.push({ type: "tool-call-start", toolCallId: k, toolName: v.function?.name ?? "" })), v.function?.arguments) {
698
+ const W = typeof v.function.arguments == "string" ? v.function.arguments : JSON.stringify(v.function.arguments);
699
+ T.push({ type: "tool-call-delta", toolCallId: k, args: W });
666
700
  }
667
701
  }
668
- return T.finish_reason && (_ = T.finish_reason === "tool_calls" ? "tool-calls" : T.finish_reason === "length" ? "length" : "stop"), v;
702
+ return b.finish_reason && (N = b.finish_reason === "tool_calls" ? "tool-calls" : b.finish_reason === "length" ? "length" : "stop"), T;
669
703
  };
670
704
  return { stream: new ReadableStream({
671
705
  async pull(h) {
672
706
  try {
673
707
  for (; ; ) {
674
- const { done: T, value: v } = await d.next();
675
- if (T) {
676
- for (const b of r.flush()) h.enqueue(b);
677
- for (const b of w.values()) h.enqueue({ type: "tool-call-end", toolCallId: b });
678
- w.clear(), h.enqueue({ type: "finish", finishReason: _, usage: g }), h.close(), A(), c({ finishReason: _, usage: g });
708
+ const { done: b, value: T } = await g.next();
709
+ if (b) {
710
+ for (const v of L.flush()) h.enqueue(v);
711
+ for (const v of C.values()) h.enqueue({ type: "tool-call-end", toolCallId: v });
712
+ C.clear(), h.enqueue({ type: "finish", finishReason: N, usage: O }), h.close(), E(), a({ finishReason: N, usage: O });
679
713
  return;
680
714
  }
681
- const C = E(v);
682
- for (const b of C) h.enqueue(b);
683
- if (C.length) return;
715
+ const I = U(T);
716
+ for (const v of I) h.enqueue(v);
717
+ if (I.length) return;
684
718
  }
685
- } catch (T) {
686
- A(), l(T), h.error(T);
719
+ } catch (b) {
720
+ E(), w(b), h.error(b);
687
721
  }
688
722
  },
689
723
  async cancel() {
690
- A(), await u.interruptGenerate(), await d.return?.(), c({ finishReason: "stop", usage: g });
724
+ E(), await l.interruptGenerate(), await g.return?.(), a({ finishReason: "stop", usage: O });
691
725
  }
692
- }), response: p };
726
+ }), response: d };
693
727
  }
694
728
  };
695
729
  }
696
- const K = [
730
+ const Q = [
697
731
  "temperature",
698
732
  "top_p",
699
733
  "max_tokens",
@@ -704,14 +738,14 @@ const K = [
704
738
  "logit_bias",
705
739
  "extra_body"
706
740
  ];
707
- function B(t) {
741
+ function V(t) {
708
742
  const e = {};
709
743
  if (!t) return e;
710
- for (const o of K)
744
+ for (const o of Q)
711
745
  t[o] !== void 0 && (e[o] = t[o]);
712
746
  return t.maxTokens !== void 0 && e.max_tokens === void 0 && (e.max_tokens = t.maxTokens), e;
713
747
  }
714
- function F(t) {
748
+ function Y(t) {
715
749
  return t.map((e) => {
716
750
  if (e.role === "tool")
717
751
  return {
@@ -723,73 +757,74 @@ function F(t) {
723
757
  return {
724
758
  role: "assistant",
725
759
  content: typeof e.content == "string" ? e.content : "",
726
- tool_calls: e.toolCalls.map((a) => ({
727
- id: a.id,
760
+ tool_calls: e.toolCalls.map((n) => ({
761
+ id: n.id,
728
762
  type: "function",
729
763
  function: {
730
- name: a.name,
731
- arguments: typeof a.args == "string" ? a.args : JSON.stringify(a.args)
764
+ name: n.name,
765
+ arguments: typeof n.args == "string" ? n.args : JSON.stringify(n.args)
732
766
  }
733
767
  }))
734
768
  };
735
769
  if (typeof e.content == "string")
736
770
  return { role: e.role, content: e.content };
737
- const o = e.content.map(H);
738
- return e.role !== "user" || o.every((a) => a.type === "text") ? { role: e.role, content: o.map((a) => a.type === "text" ? a.text : "").join(`
771
+ const o = e.content.map(Z);
772
+ return e.role !== "user" || o.every((n) => n.type === "text") ? { role: e.role, content: o.map((n) => n.type === "text" ? n.text : "").join(`
739
773
  `) } : { role: e.role, content: o };
740
774
  });
741
775
  }
742
- function H(t) {
776
+ function Z(t) {
743
777
  if (t.type === "text") return { type: "text", text: t.text };
744
778
  const e = x(t);
745
779
  if (e.mediaType.startsWith("image/"))
746
780
  return { type: "image_url", image_url: { url: e.url } };
747
- if (e.base64 && O(e.mediaType))
748
- return { type: "text", text: I(e.base64) };
781
+ if (e.base64 && S(e.mediaType))
782
+ return { type: "text", text: A(e.base64) };
749
783
  throw new Error(`[vue-llm] In-browser models do not support ${e.mediaType} attachments`);
750
784
  }
751
- const z = "<think>", X = "</think>";
752
- function q() {
785
+ const ee = "<think>", te = "</think>";
786
+ function oe() {
753
787
  let t = "", e = !1, o = !1;
754
- const a = (i, s) => {
755
- i && s.push(e ? { type: "reasoning-delta", text: i } : { type: "text-delta", text: i });
788
+ const n = (c, p) => {
789
+ c && p.push(e ? { type: "reasoning-delta", text: c } : { type: "text-delta", text: c });
756
790
  };
757
791
  return {
758
- push(i) {
759
- const s = [];
760
- for (t += i; t; ) {
792
+ push(c) {
793
+ const p = [];
794
+ for (t += c; t; ) {
761
795
  if (o) {
762
796
  if (t = t.replace(/^\s+/, ""), !t) break;
763
797
  o = !1;
764
798
  }
765
- const n = e ? X : z, u = t.indexOf(n);
766
- if (u !== -1) {
767
- a(t.slice(0, u), s), t = t.slice(u + n.length), e = !e, o = !0;
799
+ const r = e ? te : ee, m = t.indexOf(r);
800
+ if (m !== -1) {
801
+ n(t.slice(0, m), p), t = t.slice(m + r.length), e = !e, o = !0;
768
802
  continue;
769
803
  }
770
- const f = Q(t, n);
771
- a(t.slice(0, t.length - f), s), t = t.slice(t.length - f);
804
+ const _ = ne(t, r);
805
+ n(t.slice(0, t.length - _), p), t = t.slice(t.length - _);
772
806
  break;
773
807
  }
774
- return s;
808
+ return p;
775
809
  },
776
810
  flush() {
777
- const i = [];
778
- return a(t, i), t = "", i;
811
+ const c = [];
812
+ return n(t, c), t = "", c;
779
813
  }
780
814
  };
781
815
  }
782
- function Q(t, e) {
816
+ function ne(t, e) {
783
817
  for (let o = Math.min(e.length - 1, t.length); o > 0; o--)
784
818
  if (e.startsWith(t.slice(-o))) return o;
785
819
  return 0;
786
820
  }
787
821
  export {
788
- oe as createAnthropic,
789
- ne as createGoogle,
790
- ae as createOllama,
791
- te as createOpenAI,
792
- le as createSSEProvider,
793
- se as createWebLLM,
794
- D as isWebGPUSupported
822
+ pe as createAnthropic,
823
+ ce as createGoogle,
824
+ ue as createOllama,
825
+ le as createOpenAI,
826
+ ye as createSSEProvider,
827
+ fe as createWebLLM,
828
+ X as detectWebGPUPrecision,
829
+ z as isWebGPUSupported
795
830
  };