@anvaka/vue-llm 0.3.1 → 0.3.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.
@@ -26,6 +26,7 @@ const t = {
26
26
  "gpt-5-codex": { input: 1.25, output: 10, cachedInput: 0.125 }
27
27
  },
28
28
  anthropic: {
29
+ "claude-opus-4-8": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
29
30
  "claude-opus-4-7": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
30
31
  "claude-opus-4-6": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
31
32
  "claude-sonnet-4-6": { input: 3, output: 15, cachedInput: 0.3, cacheCreation: 3.75 },
@@ -35,6 +36,7 @@ const t = {
35
36
  // Bedrock charges the same per-token rates as Anthropic direct for the
36
37
  // Claude inference profiles; the model IDs differ (us.anthropic.* prefix).
37
38
  bedrock: {
39
+ "us.anthropic.claude-opus-4-8": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
38
40
  "us.anthropic.claude-opus-4-7": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
39
41
  "us.anthropic.claude-opus-4-6": { input: 5, output: 25, cachedInput: 0.5, cacheCreation: 6.25 },
40
42
  "us.anthropic.claude-sonnet-4-6": { input: 3, output: 15, cachedInput: 0.3, cacheCreation: 3.75 },
@@ -1,19 +1,19 @@
1
1
  import { BaseProvider as g } from "./BaseProvider.js";
2
- class C extends g {
2
+ class b extends g {
3
3
  async detectCapabilities() {
4
4
  var t, e, o, s;
5
5
  ((t = this.config.model) != null && t.includes("claude-3") || (e = this.config.model) != null && e.includes("claude-sonnet") || (o = this.config.model) != null && o.includes("claude-opus") || (s = this.config.model) != null && s.includes("claude-haiku")) && (this.capabilities.add("vision"), this.capabilities.add("tools"));
6
6
  }
7
7
  prepareRequest(t, e) {
8
- const o = _(t), s = e.model || this.config.model || "claude-3-sonnet-20240229", r = {
8
+ const o = m(t), s = e.model || this.config.model || "claude-3-sonnet-20240229", r = {
9
9
  model: s,
10
10
  max_tokens: e.maxTokens || 1e3,
11
11
  messages: o,
12
12
  stream: e.stream || !1
13
13
  };
14
- s.includes("claude-opus-4-7") || (r.temperature = e.temperature ?? 0.7);
14
+ _(s) || (r.temperature = e.temperature ?? 0.7);
15
15
  const c = t.find((i) => i.role === "system");
16
- return c && (r.system = c.content), e.tools && this.capabilities.has("tools") && (r.tools = m(e.tools), e.tool_choice && (r.tool_choice = e.tool_choice)), this.promptCachingEnabled(e) && y(r, e), r;
16
+ return c && (r.system = c.content), e.tools && this.capabilities.has("tools") && (r.tools = y(e.tools), e.tool_choice && (r.tool_choice = e.tool_choice)), this.promptCachingEnabled(e) && k(r, e), r;
17
17
  }
18
18
  // Prompt caching is on by default for the Claude/Anthropic-family path
19
19
  // (Bedrock inherits this method) because it's strictly cheaper and degrades
@@ -106,6 +106,9 @@ class C extends g {
106
106
  return ((e = t.data) == null ? void 0 : e.map((o) => o.id)) || [];
107
107
  }
108
108
  }
109
+ function _(n) {
110
+ return /claude-opus-4-[789]/.test(n);
111
+ }
109
112
  function h(n) {
110
113
  if (!n) return null;
111
114
  const t = String(n).toLowerCase();
@@ -116,7 +119,7 @@ function f(n) {
116
119
  const t = n.input_tokens ?? 0, e = n.cache_read_input_tokens ?? 0, o = n.cache_creation_input_tokens ?? 0, r = n.input_tokens != null || n.cache_read_input_tokens != null || n.cache_creation_input_tokens != null ? t + e + o : 0, c = n.output_tokens ?? 0, i = { inputTokens: r, outputTokens: c, totalTokens: r + c, raw: n };
117
120
  return n.cache_read_input_tokens != null && (i.cachedInputTokens = e), n.cache_creation_input_tokens != null && (i.cacheCreationInputTokens = o), i;
118
121
  }
119
- function _(n) {
122
+ function m(n) {
120
123
  const t = [];
121
124
  for (const e of n)
122
125
  if (e.role !== "system") {
@@ -148,7 +151,7 @@ function _(n) {
148
151
  }
149
152
  return t;
150
153
  }
151
- function m(n) {
154
+ function y(n) {
152
155
  return n.map((t) => t.type === "function" && t.function ? {
153
156
  name: t.function.name,
154
157
  description: t.function.description,
@@ -156,9 +159,9 @@ function m(n) {
156
159
  } : t);
157
160
  }
158
161
  const l = { type: "ephemeral" };
159
- function y(n, t) {
162
+ function k(n, t) {
160
163
  if (n.system)
161
- n.system = k(n.system);
164
+ n.system = x(n.system);
162
165
  else if (Array.isArray(n.tools) && n.tools.length) {
163
166
  const e = n.tools.length - 1;
164
167
  n.tools[e] = { ...n.tools[e], cache_control: l };
@@ -167,12 +170,12 @@ function y(n, t) {
167
170
  const e = n.messages;
168
171
  if (Array.isArray(e) && e.length) {
169
172
  const o = e[e.length - 1];
170
- o.content = x(o.content);
173
+ o.content = A(o.content);
171
174
  }
172
175
  }
173
176
  return n;
174
177
  }
175
- function k(n) {
178
+ function x(n) {
176
179
  let t;
177
180
  if (typeof n == "string")
178
181
  t = [{ type: "text", text: n }];
@@ -182,7 +185,7 @@ function k(n) {
182
185
  return n;
183
186
  return t[t.length - 1] = { ...t[t.length - 1], cache_control: l }, t;
184
187
  }
185
- function x(n) {
188
+ function A(n) {
186
189
  if (typeof n == "string")
187
190
  return [{ type: "text", text: n, cache_control: l }];
188
191
  if (Array.isArray(n) && n.length) {
@@ -192,6 +195,7 @@ function x(n) {
192
195
  return n;
193
196
  }
194
197
  export {
195
- C as AnthropicProvider,
196
- f as normalizeAnthropicUsage
198
+ b as AnthropicProvider,
199
+ f as normalizeAnthropicUsage,
200
+ _ as samplingParamsRemoved
197
201
  };
@@ -1,6 +1,7 @@
1
1
  import { BaseProvider as y } from "./BaseProvider.js";
2
2
  import { AnthropicProvider as w } from "./AnthropicProvider.js";
3
- const g = [
3
+ const p = [
4
+ "us.anthropic.claude-opus-4-8",
4
5
  "us.anthropic.claude-opus-4-7",
5
6
  "us.anthropic.claude-sonnet-4-6",
6
7
  "us.anthropic.claude-haiku-4-5-20251001-v1:0",
@@ -9,10 +10,10 @@ const g = [
9
10
  "us.anthropic.claude-sonnet-4-5-20250929-v1:0",
10
11
  "us.anthropic.claude-opus-4-1-20250805-v1:0"
11
12
  ];
12
- class R extends w {
13
- prepareRequest(r, n) {
14
- const t = super.prepareRequest(r, n);
15
- return delete t.stream, t.anthropic_version = "bedrock-2023-05-31", t;
13
+ class A extends w {
14
+ prepareRequest(n, t) {
15
+ const r = super.prepareRequest(n, t);
16
+ return delete r.stream, r.anthropic_version = "bedrock-2023-05-31", r;
16
17
  }
17
18
  buildHeaders() {
18
19
  return y.prototype.buildHeaders.call(this);
@@ -26,147 +27,170 @@ class R extends w {
26
27
  requiresAuth() {
27
28
  return !!this.config.apiKey;
28
29
  }
29
- async makeRequest(r, n, t) {
30
- const e = r.model, d = { ...r };
30
+ async makeRequest(n, t, r) {
31
+ const e = n.model, d = { ...n };
31
32
  delete d.model;
32
- const c = `${this.config.baseUrl}/model/${encodeURIComponent(e)}/invoke`, u = n ? { signal: n } : new AbortController();
33
- n || (t = t || this.generateRequestId(), this.activeRequests.set(t, u));
33
+ const i = `${this.config.baseUrl}/model/${encodeURIComponent(e)}/invoke`, l = t ? { signal: t } : new AbortController();
34
+ t || (r = r || this.generateRequestId(), this.activeRequests.set(r, l));
34
35
  try {
35
- const s = await fetch(c, {
36
+ const o = await fetch(i, {
36
37
  method: "POST",
37
38
  headers: this.buildHeaders(),
38
39
  body: JSON.stringify(d),
39
- signal: u.signal || n
40
+ signal: l.signal || t
40
41
  });
41
- if (!s.ok) {
42
- const l = await s.text();
43
- throw new Error(`Bedrock API Error (${s.status}): ${l}`);
42
+ if (!o.ok) {
43
+ const h = await o.text();
44
+ throw new Error(`Bedrock API Error (${o.status}): ${h}`);
44
45
  }
45
- return s.json();
46
+ return o.json();
46
47
  } finally {
47
- !n && t && this.activeRequests.delete(t);
48
+ !t && r && this.activeRequests.delete(r);
48
49
  }
49
50
  }
50
- async makeStreamingRequest(r, n) {
51
- const t = r.model, e = { ...r };
51
+ async makeStreamingRequest(n, t) {
52
+ const r = n.model, e = { ...n };
52
53
  delete e.model;
53
- const d = `${this.config.baseUrl}/model/${encodeURIComponent(t)}/invoke-with-response-stream`, c = await fetch(d, {
54
+ const d = `${this.config.baseUrl}/model/${encodeURIComponent(r)}/invoke-with-response-stream`, i = await fetch(d, {
54
55
  method: "POST",
55
56
  headers: this.buildHeaders(),
56
57
  body: JSON.stringify(e),
57
- signal: n
58
+ signal: t
58
59
  });
59
- if (!c.ok) {
60
- const i = await c.text();
61
- throw new Error(`Bedrock API Error (${c.status}): ${i}`);
60
+ if (!i.ok) {
61
+ const c = await i.text();
62
+ throw new Error(`Bedrock API Error (${i.status}): ${c}`);
62
63
  }
63
- const u = c.body.getReader(), s = new v(), l = new TextEncoder(), f = new ReadableStream({
64
- async pull(i) {
64
+ const l = i.body.getReader(), o = new v(), h = new TextEncoder(), f = new ReadableStream({
65
+ async pull(c) {
65
66
  try {
66
- const { done: a, value: m } = await u.read();
67
+ const { done: a, value: g } = await l.read();
67
68
  if (a) {
68
- i.close();
69
+ c.close();
69
70
  return;
70
71
  }
71
- const p = s.feed(m);
72
- for (const h of p) {
73
- if (h.kind === "error") {
74
- i.error(new Error(h.message));
72
+ const m = o.feed(g);
73
+ for (const u of m) {
74
+ if (u.kind === "error") {
75
+ c.error(new Error(u.message));
75
76
  return;
76
77
  }
77
- i.enqueue(l.encode(`data: ${JSON.stringify(h.payload)}
78
+ c.enqueue(h.encode(`data: ${JSON.stringify(u.payload)}
78
79
  `));
79
80
  }
80
81
  } catch (a) {
81
- i.error(a);
82
+ c.error(a);
82
83
  }
83
84
  },
84
- cancel(i) {
85
+ cancel(c) {
85
86
  try {
86
- u.cancel(i);
87
+ l.cancel(c);
87
88
  } catch {
88
89
  }
89
90
  }
90
91
  });
91
92
  return new Response(f, { status: 200, headers: { "Content-Type": "text/event-stream" } });
92
93
  }
93
- // Bedrock control plane needs SigV4; Bearer auth can't list models.
94
- // Return the hardcoded list so the dropdown still populates.
95
- async discoverModels() {
96
- return g.slice();
94
+ // Live discovery is opt-in via config.liveModelDiscovery. A Bedrock API key
95
+ // authenticates against the control plane with Bearer auth (no SigV4), and
96
+ // the control-plane host returns permissive CORS headers, so a browser fetch
97
+ // works. When disabled (default) or on any failure, fall back to the static
98
+ // list — existing apps keep working with zero surprise network calls.
99
+ async discoverModels(n = 1e4) {
100
+ if (!this.config.liveModelDiscovery || !this.getModelsEndpoint())
101
+ return p.slice();
102
+ try {
103
+ const t = await super.discoverModels(n);
104
+ return t.length ? t : p.slice();
105
+ } catch {
106
+ return p.slice();
107
+ }
97
108
  }
109
+ // The control plane lives at the same host with the `-runtime` segment
110
+ // stripped: bedrock-runtime.{region}.amazonaws.com (invoke) ->
111
+ // bedrock.{region}.amazonaws.com (ListInferenceProfiles). Returns null when
112
+ // no distinct control-plane host can be derived (custom/relative baseUrl),
113
+ // which disables live discovery and leaves the static fallback in place.
98
114
  getModelsEndpoint() {
99
- return null;
115
+ const n = this.config.baseUrl || "", t = n.replace("bedrock-runtime.", "bedrock.");
116
+ return !t || t === n ? null : `${t}/inference-profiles`;
100
117
  }
101
- parseModelsResponse() {
102
- return g.slice();
118
+ // ListInferenceProfiles returns
119
+ // { inferenceProfileSummaries: [{ inferenceProfileId, ... }] }
120
+ // Keep only Anthropic Claude profiles (us.* and global.*) — those ids are
121
+ // exactly what InvokeModel expects in the URL path.
122
+ parseModelsResponse(n) {
123
+ const t = n == null ? void 0 : n.inferenceProfileSummaries;
124
+ if (!Array.isArray(t)) return p.slice();
125
+ const r = t.map((e) => e == null ? void 0 : e.inferenceProfileId).filter((e) => typeof e == "string" && e.includes("anthropic.claude"));
126
+ return r.length ? r : p.slice();
103
127
  }
104
128
  }
105
129
  class v {
106
130
  constructor() {
107
131
  this.buf = new Uint8Array(0), this.textDecoder = new TextDecoder();
108
132
  }
109
- feed(r) {
110
- if (r && r.length) {
111
- const t = new Uint8Array(this.buf.length + r.length);
112
- t.set(this.buf, 0), t.set(r, this.buf.length), this.buf = t;
133
+ feed(n) {
134
+ if (n && n.length) {
135
+ const r = new Uint8Array(this.buf.length + n.length);
136
+ r.set(this.buf, 0), r.set(n, this.buf.length), this.buf = r;
113
137
  }
114
- const n = [];
138
+ const t = [];
115
139
  for (; this.buf.length >= 12; ) {
116
- const t = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength), e = t.getUint32(0, !1), d = t.getUint32(4, !1);
140
+ const r = new DataView(this.buf.buffer, this.buf.byteOffset, this.buf.byteLength), e = r.getUint32(0, !1), d = r.getUint32(4, !1);
117
141
  if (e < 16 || e > 16 * 1024 * 1024)
118
142
  throw new Error(`Bedrock event stream: invalid frame length ${e}`);
119
143
  if (this.buf.length < e) break;
120
- const c = 12, u = c + d, s = u, l = e - 4, f = k(this.buf.subarray(c, u)), i = this.textDecoder.decode(this.buf.subarray(s, l));
144
+ const i = 12, l = i + d, o = l, h = e - 4, f = k(this.buf.subarray(i, l)), c = this.textDecoder.decode(this.buf.subarray(o, h));
121
145
  this.buf = this.buf.subarray(e);
122
146
  let a;
123
147
  try {
124
- a = JSON.parse(i);
148
+ a = JSON.parse(c);
125
149
  } catch {
126
150
  a = null;
127
151
  }
128
- const m = f[":message-type"], p = f[":exception-type"];
129
- if (m === "exception" || p) {
130
- const h = p || f[":event-type"] || "BedrockStreamException", b = (a == null ? void 0 : a.message) || i || "unknown error";
131
- n.push({ kind: "error", message: `${h}: ${b}` });
152
+ const g = f[":message-type"], m = f[":exception-type"];
153
+ if (g === "exception" || m) {
154
+ const u = m || f[":event-type"] || "BedrockStreamException", b = (a == null ? void 0 : a.message) || c || "unknown error";
155
+ t.push({ kind: "error", message: `${u}: ${b}` });
132
156
  continue;
133
157
  }
134
158
  if (a && typeof a.bytes == "string")
135
159
  try {
136
- const h = x(a.bytes), b = JSON.parse(h);
137
- n.push({ kind: "event", payload: b });
138
- } catch (h) {
139
- n.push({ kind: "error", message: `Bedrock event-stream decode failed: ${h.message}` });
160
+ const u = x(a.bytes), b = JSON.parse(u);
161
+ t.push({ kind: "event", payload: b });
162
+ } catch (u) {
163
+ t.push({ kind: "error", message: `Bedrock event-stream decode failed: ${u.message}` });
140
164
  }
141
165
  }
142
- return n;
166
+ return t;
143
167
  }
144
168
  }
145
- function k(o) {
146
- const r = {}, n = new DataView(o.buffer, o.byteOffset, o.byteLength), t = new TextDecoder();
169
+ function k(s) {
170
+ const n = {}, t = new DataView(s.buffer, s.byteOffset, s.byteLength), r = new TextDecoder();
147
171
  let e = 0;
148
- for (; e < o.length; ) {
149
- const d = o[e];
150
- if (e += 1, e + d > o.length) break;
151
- const c = t.decode(o.subarray(e, e + d));
152
- if (e += d, e >= o.length) break;
153
- const u = o[e];
154
- if (e += 1, u === 7) {
155
- if (e + 2 > o.length) break;
156
- const s = n.getUint16(e, !1);
157
- if (e += 2, e + s > o.length) break;
158
- r[c] = t.decode(o.subarray(e, e + s)), e += s;
172
+ for (; e < s.length; ) {
173
+ const d = s[e];
174
+ if (e += 1, e + d > s.length) break;
175
+ const i = r.decode(s.subarray(e, e + d));
176
+ if (e += d, e >= s.length) break;
177
+ const l = s[e];
178
+ if (e += 1, l === 7) {
179
+ if (e + 2 > s.length) break;
180
+ const o = t.getUint16(e, !1);
181
+ if (e += 2, e + o > s.length) break;
182
+ n[i] = r.decode(s.subarray(e, e + o)), e += o;
159
183
  } else
160
184
  break;
161
185
  }
162
- return r;
186
+ return n;
163
187
  }
164
- function x(o) {
165
- const r = atob(o), n = new Uint8Array(r.length);
166
- for (let t = 0; t < r.length; t++) n[t] = r.charCodeAt(t);
167
- return new TextDecoder().decode(n);
188
+ function x(s) {
189
+ const n = atob(s), t = new Uint8Array(n.length);
190
+ for (let r = 0; r < n.length; r++) t[r] = n.charCodeAt(r);
191
+ return new TextDecoder().decode(t);
168
192
  }
169
193
  export {
170
- g as BEDROCK_CLAUDE_MODELS,
171
- R as BedrockProvider
194
+ p as BEDROCK_CLAUDE_MODELS,
195
+ A as BedrockProvider
172
196
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvaka/vue-llm",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Browser-only LLM client with provider adapters and Vue 3 components",
5
5
  "type": "module",
6
6
  "license": "MIT",