@anvaka/vue-llm 0.4.1 → 0.4.2

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,99 +1,99 @@
1
- var h = (s) => {
1
+ var p = (s) => {
2
2
  throw TypeError(s);
3
3
  };
4
- var k = (s, o, t) => o.has(s) || h("Cannot " + t);
5
- var p = (s, o, t) => o.has(s) ? h("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(s) : o.set(s, t);
6
- var m = (s, o, t) => (k(s, o, "access private method"), t);
7
- import { BaseProvider as y } from "./BaseProvider.js";
8
- var u, _;
9
- class v extends y {
4
+ var y = (s, o, e) => o.has(s) || p("Cannot " + e);
5
+ var h = (s, o, e) => o.has(s) ? p("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(s) : o.set(s, e);
6
+ var m = (s, o, e) => (y(s, o, "access private method"), e);
7
+ import { BaseProvider as A } from "./BaseProvider.js";
8
+ import { isOpenAIReasoningModel as _ } from "./samplingPolicy.js";
9
+ var u, k;
10
+ class C extends A {
10
11
  constructor() {
11
12
  super(...arguments);
12
- p(this, u);
13
+ h(this, u);
13
14
  }
14
15
  async detectCapabilities() {
15
16
  if (!this.config.model) return;
16
- const t = this.config.model.toLowerCase();
17
- (t.startsWith("o1") || t.startsWith("o2") || t.startsWith("o3") || t.startsWith("o-") || t.includes("gpt-5") || t === "gpt5") && this.capabilities.add("thinking"), t.includes("gpt-4") && t.includes("vision") && this.capabilities.add("vision"), (t.includes("gpt-4") || t.includes("gpt-3.5") || t.includes("gpt-5")) && this.capabilities.add("tools");
17
+ const e = this.config.model.toLowerCase();
18
+ _(e) && this.capabilities.add("thinking"), e.includes("gpt-4") && e.includes("vision") && this.capabilities.add("vision"), (e.includes("gpt-4") || e.includes("gpt-3.5") || e.includes("gpt-5")) && this.capabilities.add("tools");
18
19
  }
19
- prepareRequest(t, e) {
20
- const n = e.model || this.config.model || "gpt-3.5-turbo", i = {
21
- model: n,
22
- messages: this.processMessages(t, e),
23
- temperature: e.temperature ?? 0.7,
24
- stream: e.stream || !1
20
+ prepareRequest(e, n) {
21
+ const t = n.model || this.config.model || "gpt-3.5-turbo", i = {
22
+ model: t,
23
+ messages: this.processMessages(e, n),
24
+ stream: n.stream || !1
25
25
  };
26
- return i.stream && (i.stream_options = { include_usage: !0 }), m(this, u, _).call(this, n) ? (i.max_completion_tokens = e.maxTokens || 1e3, i.temperature = 1) : i.max_tokens = e.maxTokens || 1e3, e.enableThinking && this.capabilities.has("thinking") && (i.reasoning_effort = e.reasoningEffort || "medium"), e.tools && this.capabilities.has("tools") && (i.tools = e.tools), i;
26
+ return i.stream && (i.stream_options = { include_usage: !0 }), m(this, u, k).call(this, t) ? i.max_completion_tokens = n.maxTokens || 1e3 : i.max_tokens = n.maxTokens || 1e3, this.applySamplingParams(i, n), n.enableThinking && this.capabilities.has("thinking") && (i.reasoning_effort = n.reasoningEffort || "medium"), n.tools && this.capabilities.has("tools") && (i.tools = n.tools), i;
27
27
  }
28
- processMessages(t, e) {
29
- const n = A(t);
30
- return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(n, e.images) : n;
28
+ processMessages(e, n) {
29
+ const t = b(e);
30
+ return n.images && this.capabilities.has("vision") ? this.addImagesToMessages(t, n.images) : t;
31
31
  }
32
- addImagesToMessages(t, e) {
33
- const n = t[t.length - 1];
34
- if (n && n.role === "user") {
35
- const i = [{ type: "text", text: n.content }];
36
- e.forEach((r) => {
32
+ addImagesToMessages(e, n) {
33
+ const t = e[e.length - 1];
34
+ if (t && t.role === "user") {
35
+ const i = [{ type: "text", text: t.content }];
36
+ n.forEach((a) => {
37
37
  i.push({
38
38
  type: "image_url",
39
- image_url: { url: typeof r == "string" ? r : r.url }
39
+ image_url: { url: typeof a == "string" ? a : a.url }
40
40
  });
41
- }), n.content = i;
41
+ }), t.content = i;
42
42
  }
43
- return t;
43
+ return e;
44
44
  }
45
- processResponse(t) {
46
- var i, r, l, a;
47
- const e = (r = (i = t.choices) == null ? void 0 : i[0]) == null ? void 0 : r.message, n = {
48
- content: (e == null ? void 0 : e.content) || "",
49
- usage: g(t.usage),
50
- finishReason: ((a = (l = t.choices) == null ? void 0 : l[0]) == null ? void 0 : a.finish_reason) || null
45
+ processResponse(e) {
46
+ var i, a, l, r;
47
+ const n = (a = (i = e.choices) == null ? void 0 : i[0]) == null ? void 0 : a.message, t = {
48
+ content: (n == null ? void 0 : n.content) || "",
49
+ usage: g(e.usage),
50
+ finishReason: ((r = (l = e.choices) == null ? void 0 : l[0]) == null ? void 0 : r.finish_reason) || null
51
51
  };
52
- return t.reasoning && (n.thinking = t.reasoning), Array.isArray(e == null ? void 0 : e.tool_calls) && (n.toolCalls = e.tool_calls.map((c) => {
52
+ return e.reasoning && (t.thinking = e.reasoning), Array.isArray(n == null ? void 0 : n.tool_calls) && (t.toolCalls = n.tool_calls.map((c) => {
53
53
  var d, f;
54
54
  return {
55
55
  id: c.id,
56
56
  name: (d = c.function) == null ? void 0 : d.name,
57
57
  args: T((f = c.function) == null ? void 0 : f.arguments)
58
58
  };
59
- })), n;
59
+ })), t;
60
60
  }
61
- parseStreamingLine(t) {
62
- if (!t.startsWith("data: ")) return null;
63
- const e = t.slice(6).trim();
64
- if (e === "[DONE]") return { done: !0 };
61
+ parseStreamingLine(e) {
62
+ if (!e.startsWith("data: ")) return null;
63
+ const n = e.slice(6).trim();
64
+ if (n === "[DONE]") return { done: !0 };
65
65
  try {
66
- return JSON.parse(e);
66
+ return JSON.parse(n);
67
67
  } catch {
68
68
  return null;
69
69
  }
70
70
  }
71
- extractStreamingContent(t) {
72
- var i, r, l;
73
- if (t.done) return { done: !0 };
74
- const e = (i = t.choices) == null ? void 0 : i[0], n = e == null ? void 0 : e.delta;
75
- if (n && Array.isArray(n.tool_calls) && n.tool_calls.length) {
76
- const a = n.tool_calls[0];
71
+ extractStreamingContent(e) {
72
+ var i, a, l;
73
+ if (e.done) return { done: !0 };
74
+ const n = (i = e.choices) == null ? void 0 : i[0], t = n == null ? void 0 : n.delta;
75
+ if (t && Array.isArray(t.tool_calls) && t.tool_calls.length) {
76
+ const r = t.tool_calls[0];
77
77
  return {
78
- content: n.content || "",
79
- thinking: n.reasoning || "",
78
+ content: t.content || "",
79
+ thinking: t.reasoning || "",
80
80
  done: !1,
81
- usage: g(t.usage),
82
- finishReason: (e == null ? void 0 : e.finish_reason) || null,
81
+ usage: g(e.usage),
82
+ finishReason: (n == null ? void 0 : n.finish_reason) || null,
83
83
  toolCallDelta: {
84
- index: a.index ?? 0,
85
- id: a.id || void 0,
86
- name: ((r = a.function) == null ? void 0 : r.name) || void 0,
87
- argsTextDelta: ((l = a.function) == null ? void 0 : l.arguments) || ""
84
+ index: r.index ?? 0,
85
+ id: r.id || void 0,
86
+ name: ((a = r.function) == null ? void 0 : a.name) || void 0,
87
+ argsTextDelta: ((l = r.function) == null ? void 0 : l.arguments) || ""
88
88
  }
89
89
  };
90
90
  }
91
91
  return {
92
- content: (n == null ? void 0 : n.content) || "",
93
- thinking: (n == null ? void 0 : n.reasoning) || "",
92
+ content: (t == null ? void 0 : t.content) || "",
93
+ thinking: (t == null ? void 0 : t.reasoning) || "",
94
94
  done: !1,
95
- usage: g(t.usage),
96
- finishReason: (e == null ? void 0 : e.finish_reason) || null
95
+ usage: g(e.usage),
96
+ finishReason: (n == null ? void 0 : n.finish_reason) || null
97
97
  };
98
98
  }
99
99
  getApiPath() {
@@ -105,17 +105,17 @@ class v extends y {
105
105
  getModelsEndpoint() {
106
106
  return `${this.config.baseUrl}/v1/models`;
107
107
  }
108
- parseModelsResponse(t) {
109
- var e;
110
- return ((e = t.data) == null ? void 0 : e.filter((n) => {
111
- const i = n.id.toLowerCase();
108
+ parseModelsResponse(e) {
109
+ var n;
110
+ return ((n = e.data) == null ? void 0 : n.filter((t) => {
111
+ const i = t.id.toLowerCase();
112
112
  return i.includes("gpt") || i.includes("chat");
113
- }).map((n) => n.id).sort()) || [];
113
+ }).map((t) => t.id).sort()) || [];
114
114
  }
115
115
  }
116
- u = new WeakSet(), _ = function(t) {
117
- const e = (t || "").toLowerCase();
118
- return e.startsWith("o1") || e.startsWith("o2") || e.startsWith("o3") || e.startsWith("o-") || e.includes("gpt-5") || e === "gpt5" || e.includes("reasoning") || this.capabilities.has("thinking");
116
+ u = new WeakSet(), k = function(e) {
117
+ const n = (e || "").toLowerCase();
118
+ return _(n) || n.includes("gpt-5") || this.capabilities.has("thinking");
119
119
  };
120
120
  function T(s) {
121
121
  if (!s) return {};
@@ -126,27 +126,27 @@ function T(s) {
126
126
  }
127
127
  }
128
128
  function g(s) {
129
- var l, a;
129
+ var l, r;
130
130
  if (!s) return null;
131
- const o = s.prompt_tokens ?? 0, t = s.completion_tokens ?? 0, e = s.total_tokens ?? o + t, n = (l = s.prompt_tokens_details) == null ? void 0 : l.cached_tokens, i = (a = s.completion_tokens_details) == null ? void 0 : a.reasoning_tokens, r = { inputTokens: o, outputTokens: t, totalTokens: e, raw: s };
132
- return n != null && (r.cachedInputTokens = n), i != null && (r.reasoningTokens = i), r;
131
+ const o = s.prompt_tokens ?? 0, e = s.completion_tokens ?? 0, n = s.total_tokens ?? o + e, t = (l = s.prompt_tokens_details) == null ? void 0 : l.cached_tokens, i = (r = s.completion_tokens_details) == null ? void 0 : r.reasoning_tokens, a = { inputTokens: o, outputTokens: e, totalTokens: n, raw: s };
132
+ return t != null && (a.cachedInputTokens = t), i != null && (a.reasoningTokens = i), a;
133
133
  }
134
- function A(s) {
134
+ function b(s) {
135
135
  return s.map((o) => o.role === "assistant" && Array.isArray(o.tool_calls) && o.tool_calls.length ? {
136
136
  role: "assistant",
137
137
  content: o.content ?? null,
138
- tool_calls: o.tool_calls.map((t) => ({
139
- id: t.id,
138
+ tool_calls: o.tool_calls.map((e) => ({
139
+ id: e.id,
140
140
  type: "function",
141
141
  function: {
142
- name: t.name,
143
- arguments: typeof t.args == "string" ? t.args : JSON.stringify(t.args || {})
142
+ name: e.name,
143
+ arguments: typeof e.args == "string" ? e.args : JSON.stringify(e.args || {})
144
144
  }
145
145
  }))
146
146
  } : o);
147
147
  }
148
148
  export {
149
- v as OpenAIProvider,
150
- A as convertMessagesToOpenAI,
149
+ C as OpenAIProvider,
150
+ b as convertMessagesToOpenAI,
151
151
  g as normalizeOpenAIUsage
152
152
  };
@@ -1,6 +1,6 @@
1
1
  import { BaseProvider as f } from "./BaseProvider.js";
2
2
  import { convertMessagesToOpenAI as g, normalizeOpenAIUsage as c } from "./OpenAIProvider.js";
3
- class y extends f {
3
+ class _ 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
  }
@@ -8,11 +8,10 @@ class y extends f {
8
8
  const t = {
9
9
  model: e.model || this.config.model,
10
10
  messages: this.processMessages(i, e),
11
- temperature: e.temperature ?? 0.7,
12
11
  max_tokens: e.maxTokens || 1e3,
13
12
  stream: e.stream || !1
14
13
  };
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;
14
+ return this.applySamplingParams(t, e), 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
15
  }
17
16
  processMessages(i, e) {
18
17
  const t = g(i);
@@ -110,5 +109,5 @@ function m(r) {
110
109
  }
111
110
  }
112
111
  export {
113
- y as OpenRouterProvider
112
+ _ as OpenRouterProvider
114
113
  };
@@ -0,0 +1,41 @@
1
+ const n = { PASS: "pass", OMIT: "omit", ONE: "one" }, r = /* @__PURE__ */ new Map();
2
+ function l(e, t) {
3
+ return `${e || ""}::${t || ""}`;
4
+ }
5
+ function c(e, t) {
6
+ e && (t === n.OMIT || t === n.ONE) && r.set(e, t);
7
+ }
8
+ function p(e, t) {
9
+ return r.get(e) || i(t);
10
+ }
11
+ function i(e) {
12
+ const t = String(e || "");
13
+ return s(t) ? n.OMIT : a(t) ? n.ONE : n.PASS;
14
+ }
15
+ function s(e) {
16
+ const t = e || "";
17
+ return /claude-opus-4[-.][789]/.test(t) || /claude-(sonnet|opus|haiku|fable)-5(?!\d)/.test(t);
18
+ }
19
+ function u(e) {
20
+ const t = String(e || "").toLowerCase();
21
+ return /(?:^|\/)o[1-9](?:[-.]|$)/.test(t) || t.includes("gpt-5") && !t.includes("gpt-5-chat") ? !0 : t === "gpt5" || t.includes("reasoning");
22
+ }
23
+ function a(e) {
24
+ const t = String(e || "").toLowerCase(), o = /kimi|moonshot/.test(t);
25
+ return u(t) || o;
26
+ }
27
+ function d(e) {
28
+ const t = String(e || "").toLowerCase();
29
+ return t.includes("temperature") ? /\bonly\s*1\b|\bmust be (?:exactly )?1\b|\bmust equal 1\b|\bequal to 1\b|\bset to 1\b/.test(t) ? n.ONE : /deprecat|unsupported|not support|no longer|isn'?t allowed|not allowed|not permitted|unexpected (?:parameter|field)|invalid parameter/.test(t) ? n.OMIT : null : null;
30
+ }
31
+ export {
32
+ n as SAMPLING_MODE,
33
+ d as classifyTemperatureError,
34
+ a as isFixedTemperatureModel,
35
+ u as isOpenAIReasoningModel,
36
+ c as recordSamplingConstraint,
37
+ l as samplingKey,
38
+ p as samplingModeFor,
39
+ s as samplingParamsRemoved,
40
+ i as staticSamplingMode
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvaka/vue-llm",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Browser-only LLM client with provider adapters and Vue 3 components",
5
5
  "type": "module",
6
6
  "license": "MIT",