@anvaka/vue-llm 0.2.0 → 0.3.1

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.
@@ -1,46 +1,46 @@
1
- import { BaseProvider as h } from "./BaseProvider.js";
2
- import { convertMessagesToOpenAI as f } from "./OpenAIProvider.js";
3
- class y extends h {
1
+ import { BaseProvider as f } from "./BaseProvider.js";
2
+ import { convertMessagesToOpenAI as g, normalizeOpenAIUsage as c } from "./OpenAIProvider.js";
3
+ class y extends f {
4
4
  async detectCapabilities() {
5
5
  this.config.model && (this.capabilities.add("tools"), (this.config.model.includes("o1") || this.config.model.includes("thinking") || this.config.model.includes("reasoning")) && this.capabilities.add("thinking"), (this.config.model.includes("vision") || this.config.model.includes("gpt-4") || this.config.model.includes("claude") || this.config.model.includes("gemini")) && this.capabilities.add("vision"));
6
6
  }
7
- prepareRequest(n, e) {
7
+ prepareRequest(i, e) {
8
8
  const t = {
9
9
  model: e.model || this.config.model,
10
- messages: this.processMessages(n, e),
10
+ messages: this.processMessages(i, e),
11
11
  temperature: e.temperature ?? 0.7,
12
12
  max_tokens: e.maxTokens || 1e3,
13
13
  stream: e.stream || !1
14
14
  };
15
- return e.enableThinking && this.capabilities.has("thinking") && (t.reasoning = e.reasoning !== !1, e.reasoningEffort && (t.reasoning_effort = e.reasoningEffort)), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
15
+ return t.stream && (t.stream_options = { include_usage: !0 }), e.enableThinking && this.capabilities.has("thinking") && (t.reasoning = e.reasoning !== !1, e.reasoningEffort && (t.reasoning_effort = e.reasoningEffort)), e.tools && this.capabilities.has("tools") && (t.tools = e.tools, e.tool_choice && (t.tool_choice = e.tool_choice)), t;
16
16
  }
17
- processMessages(n, e) {
18
- const t = f(n);
17
+ processMessages(i, e) {
18
+ const t = g(i);
19
19
  return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(t, e.images) : t;
20
20
  }
21
- addImagesToMessages(n, e) {
22
- const t = n[n.length - 1];
23
- return t && t.role === "user" && (t.content = [{ type: "text", text: t.content }, ...e.map((i) => ({ type: "image_url", image_url: { url: i } }))]), n;
21
+ addImagesToMessages(i, e) {
22
+ const t = i[i.length - 1];
23
+ return t && t.role === "user" && (t.content = [{ type: "text", text: t.content }, ...e.map((n) => ({ type: "image_url", image_url: { url: n } }))]), i;
24
24
  }
25
25
  buildHeaders() {
26
- const n = { "Content-Type": "application/json" };
27
- return this.requiresAuth() && (n[this.getAuthHeaderName()] = this.getAuthHeaderValue()), this.config.siteUrl && (n["HTTP-Referer"] = this.config.siteUrl), this.config.siteName && (n["X-Title"] = this.config.siteName), n;
26
+ const i = { "Content-Type": "application/json" };
27
+ return this.requiresAuth() && (i[this.getAuthHeaderName()] = this.getAuthHeaderValue()), this.config.siteUrl && (i["HTTP-Referer"] = this.config.siteUrl), this.config.siteName && (i["X-Title"] = this.config.siteName), i;
28
28
  }
29
- processResponse(n) {
30
- var i, s, o, a;
31
- const e = (s = (i = n.choices) == null ? void 0 : i[0]) == null ? void 0 : s.message, t = { content: (e == null ? void 0 : e.content) || "", usage: n.usage || null, finishReason: c((a = (o = n.choices) == null ? void 0 : o[0]) == null ? void 0 : a.finish_reason) };
29
+ processResponse(i) {
30
+ var n, s, o, a;
31
+ const e = (s = (n = i.choices) == null ? void 0 : n[0]) == null ? void 0 : s.message, t = { content: (e == null ? void 0 : e.content) || "", usage: c(i.usage), finishReason: u((a = (o = i.choices) == null ? void 0 : o[0]) == null ? void 0 : a.finish_reason) };
32
32
  return e != null && e.reasoning && (t.thinking = e.reasoning), Array.isArray(e == null ? void 0 : e.tool_calls) && (t.toolCalls = e.tool_calls.map((l) => {
33
- var u, d;
33
+ var d, h;
34
34
  return {
35
35
  id: l.id,
36
- name: (u = l.function) == null ? void 0 : u.name,
37
- args: g((d = l.function) == null ? void 0 : d.arguments)
36
+ name: (d = l.function) == null ? void 0 : d.name,
37
+ args: m((h = l.function) == null ? void 0 : h.arguments)
38
38
  };
39
39
  })), t;
40
40
  }
41
- parseStreamingLine(n) {
42
- if (!n.startsWith("data: ")) return null;
43
- const e = n.slice(6).trim();
41
+ parseStreamingLine(i) {
42
+ if (!i.startsWith("data: ")) return null;
43
+ const e = i.slice(6).trim();
44
44
  if (e === "[DONE]") return { done: !0 };
45
45
  try {
46
46
  return JSON.parse(e);
@@ -48,18 +48,18 @@ class y extends h {
48
48
  return null;
49
49
  }
50
50
  }
51
- extractStreamingContent(n) {
52
- var i, s, o;
53
- if (n.done) return { done: !0 };
54
- const e = (i = n.choices) == null ? void 0 : i[0], t = e == null ? void 0 : e.delta;
51
+ extractStreamingContent(i) {
52
+ var n, s, o;
53
+ if (i.done) return { done: !0 };
54
+ const e = (n = i.choices) == null ? void 0 : n[0], t = e == null ? void 0 : e.delta;
55
55
  if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
56
56
  const a = t.tool_calls[0];
57
57
  return {
58
58
  content: t.content || "",
59
59
  thinking: t.reasoning || "",
60
60
  done: !1,
61
- usage: n.usage || null,
62
- finishReason: c(e == null ? void 0 : e.finish_reason),
61
+ usage: c(i.usage),
62
+ finishReason: u(e == null ? void 0 : e.finish_reason),
63
63
  toolCallDelta: {
64
64
  index: a.index ?? 0,
65
65
  id: a.id || void 0,
@@ -68,7 +68,7 @@ class y extends h {
68
68
  }
69
69
  };
70
70
  }
71
- return { content: (t == null ? void 0 : t.content) || "", thinking: (t == null ? void 0 : t.reasoning) || "", done: !1, usage: n.usage || null, finishReason: c(e == null ? void 0 : e.finish_reason) };
71
+ return { content: (t == null ? void 0 : t.content) || "", thinking: (t == null ? void 0 : t.reasoning) || "", done: !1, usage: c(i.usage), finishReason: u(e == null ? void 0 : e.finish_reason) };
72
72
  }
73
73
  getApiPath() {
74
74
  return "/v1/chat/completions";
@@ -79,29 +79,29 @@ class y extends h {
79
79
  getModelsEndpoint() {
80
80
  return `${this.config.baseUrl}/v1/models`;
81
81
  }
82
- parseModelsResponse(n) {
83
- return Array.isArray(n.data) ? n.data.filter((e) => {
84
- var i;
85
- const t = (i = e.architecture) == null ? void 0 : i.modality;
82
+ parseModelsResponse(i) {
83
+ return Array.isArray(i.data) ? i.data.filter((e) => {
84
+ var n;
85
+ const t = (n = e.architecture) == null ? void 0 : n.modality;
86
86
  return t && (t.includes("text->text") || t.includes("text+image->text"));
87
87
  }).map((e) => e.id).sort() : [];
88
88
  }
89
- async discoverModelsWithMetadata(n = 15e3) {
89
+ async discoverModelsWithMetadata(i = 15e3) {
90
90
  try {
91
- const e = this.buildHeaders(), t = new AbortController(), i = setTimeout(() => t.abort(), n), s = await fetch(this.getModelsEndpoint(), { method: "GET", headers: e, signal: t.signal });
92
- if (clearTimeout(i), !s.ok) throw new Error(`Failed to fetch models: ${s.status} ${s.statusText}`);
91
+ const e = this.buildHeaders(), t = new AbortController(), n = setTimeout(() => t.abort(), i), s = await fetch(this.getModelsEndpoint(), { method: "GET", headers: e, signal: t.signal });
92
+ if (clearTimeout(n), !s.ok) throw new Error(`Failed to fetch models: ${s.status} ${s.statusText}`);
93
93
  return (await s.json()).data || [];
94
94
  } catch (e) {
95
95
  throw e.name === "AbortError" ? new Error("Model discovery timeout - please check your connection") : e;
96
96
  }
97
97
  }
98
98
  }
99
- function c(r) {
99
+ function u(r) {
100
100
  if (!r) return null;
101
- const n = String(r).toLowerCase();
102
- return n === "length" || n === "max_tokens" ? "length" : n;
101
+ const i = String(r).toLowerCase();
102
+ return i === "length" || i === "max_tokens" ? "length" : i;
103
103
  }
104
- function g(r) {
104
+ function m(r) {
105
105
  if (!r) return {};
106
106
  try {
107
107
  return JSON.parse(r);
@@ -4,8 +4,9 @@ import { BedrockProvider as n } from "./BedrockProvider.js";
4
4
  import { GrokProvider as m } from "./GrokProvider.js";
5
5
  import { GeminiProvider as p } from "./GeminiProvider.js";
6
6
  import { OllamaProvider as u } from "./OllamaProvider.js";
7
- import { LlamaServerProvider as l } from "./LlamaServerProvider.js";
8
- import { OpenRouterProvider as A } from "./OpenRouterProvider.js";
7
+ import { LlamaServerProvider as E } from "./LlamaServerProvider.js";
8
+ import { OpenRouterProvider as l } from "./OpenRouterProvider.js";
9
+ import { DeepSeekProvider as A } from "./DeepSeekProvider.js";
9
10
  import { CustomProvider as O } from "./CustomProvider.js";
10
11
  const e = {
11
12
  OPENAI: "openai",
@@ -16,8 +17,9 @@ const e = {
16
17
  OLLAMA: "ollama",
17
18
  LLAMA_SERVER: "llama-server",
18
19
  OPENROUTER: "openrouter",
20
+ DEEPSEEK: "deepseek",
19
21
  CUSTOM: "custom"
20
- }, L = {
22
+ }, S = {
21
23
  [e.OPENAI]: { name: "OpenAI", baseUrl: "https://api.openai.com", requiresApiKey: !0 },
22
24
  [e.ANTHROPIC]: { name: "Anthropic", baseUrl: "https://api.anthropic.com", requiresApiKey: !0 },
23
25
  [e.BEDROCK]: { name: "AWS Bedrock", baseUrl: "https://bedrock-runtime.us-east-1.amazonaws.com", requiresApiKey: !0 },
@@ -26,6 +28,7 @@ const e = {
26
28
  [e.OLLAMA]: { name: "Ollama (Native)", baseUrl: "http://localhost:11434", requiresApiKey: !1 },
27
29
  [e.LLAMA_SERVER]: { name: "Local Llama Server", baseUrl: "http://localhost:8080", requiresApiKey: !1 },
28
30
  [e.OPENROUTER]: { name: "OpenRouter", baseUrl: "https://openrouter.ai/api", requiresApiKey: !0 },
31
+ [e.DEEPSEEK]: { name: "DeepSeek", baseUrl: "https://api.deepseek.com", requiresApiKey: !0 },
29
32
  [e.CUSTOM]: { name: "Custom OpenAI Compatible", baseUrl: "", requiresApiKey: !1 }
30
33
  };
31
34
  function c(t, r) {
@@ -43,8 +46,10 @@ function c(t, r) {
43
46
  case e.OLLAMA:
44
47
  return new u(r);
45
48
  case e.LLAMA_SERVER:
46
- return new l(r);
49
+ return new E(r);
47
50
  case e.OPENROUTER:
51
+ return new l(r);
52
+ case e.DEEPSEEK:
48
53
  return new A(r);
49
54
  case e.CUSTOM:
50
55
  return new O(r);
@@ -53,7 +58,7 @@ function c(t, r) {
53
58
  }
54
59
  }
55
60
  const a = /* @__PURE__ */ new Map();
56
- function K(t, r) {
61
+ function b(t, r) {
57
62
  if (typeof t != "string" || !r)
58
63
  throw new Error("registerProvider requires a type string and a class reference");
59
64
  a.set(t, r);
@@ -66,9 +71,9 @@ function N(t, r) {
66
71
  return c(t, r);
67
72
  }
68
73
  export {
69
- L as DEFAULT_CONFIGS,
74
+ S as DEFAULT_CONFIGS,
70
75
  e as PROVIDERS,
71
76
  c as createProvider,
72
77
  N as createProviderFlexible,
73
- K as registerProvider
78
+ b as registerProvider
74
79
  };
@@ -1,17 +1,19 @@
1
1
  import { BaseProvider as o } from "./BaseProvider.js";
2
2
  import { OpenAIProvider as t } from "./OpenAIProvider.js";
3
- import { AnthropicProvider as P } from "./AnthropicProvider.js";
3
+ import { AnthropicProvider as p } from "./AnthropicProvider.js";
4
4
  import { BEDROCK_CLAUDE_MODELS as v, BedrockProvider as x } from "./BedrockProvider.js";
5
- import { DEFAULT_CONFIGS as m, PROVIDERS as D, createProvider as E, createProviderFlexible as O, registerProvider as c } from "./factory.js";
5
+ import { DeepSeekProvider as m } from "./DeepSeekProvider.js";
6
+ import { DEFAULT_CONFIGS as E, PROVIDERS as O, createProvider as c, createProviderFlexible as A, registerProvider as S } from "./factory.js";
6
7
  export {
7
- P as AnthropicProvider,
8
+ p as AnthropicProvider,
8
9
  v as BEDROCK_CLAUDE_MODELS,
9
10
  o as BaseProvider,
10
11
  x as BedrockProvider,
11
- m as DEFAULT_CONFIGS,
12
+ E as DEFAULT_CONFIGS,
13
+ m as DeepSeekProvider,
12
14
  t as OpenAIProvider,
13
- D as PROVIDERS,
14
- E as createProvider,
15
- O as createProviderFlexible,
16
- c as registerProvider
15
+ O as PROVIDERS,
16
+ c as createProvider,
17
+ A as createProviderFlexible,
18
+ S as registerProvider
17
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvaka/vue-llm",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Browser-only LLM client with provider adapters and Vue 3 components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,7 +8,9 @@
8
8
  "module": "dist/index.js",
9
9
  "scripts": {
10
10
  "build": "vite build",
11
- "dev": "vite build --watch"
11
+ "dev": "vite build --watch",
12
+ "test:providers": "node test/providers.mjs",
13
+ "test:caching": "node test/caching.mjs"
12
14
  },
13
15
  "exports": {
14
16
  ".": {
@@ -23,6 +25,10 @@
23
25
  "import": "./dist/providers/index.js",
24
26
  "default": "./dist/providers/index.js"
25
27
  },
28
+ "./pricing": {
29
+ "import": "./dist/pricing/index.js",
30
+ "default": "./dist/pricing/index.js"
31
+ },
26
32
  "./styles/variables.css": "./src/styles/variables.css",
27
33
  "./styles/components.css": "./src/styles/components.css",
28
34
  "./dist/vue-llm.css": "./dist/vue-llm.css"