@anvaka/vue-llm 0.2.0 → 0.3.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/README.md +64 -3
- package/dist/core/LLMClient.js +92 -63
- package/dist/index.js +37 -29
- package/dist/pricing/calculate.js +58 -0
- package/dist/pricing/index.js +10 -0
- package/dist/pricing/rates.js +80 -0
- package/dist/providers/AnthropicProvider.js +35 -26
- package/dist/providers/BaseProvider.js +84 -74
- package/dist/providers/CustomProvider.js +69 -28
- package/dist/providers/DeepSeekProvider.js +115 -0
- package/dist/providers/GeminiProvider.js +143 -111
- package/dist/providers/GrokProvider.js +75 -38
- package/dist/providers/LlamaServerProvider.js +72 -31
- package/dist/providers/OllamaProvider.js +117 -41
- package/dist/providers/OpenAIProvider.js +64 -57
- package/dist/providers/OpenRouterProvider.js +40 -40
- package/dist/providers/factory.js +12 -7
- package/dist/providers/index.js +10 -8
- package/package.json +7 -2
|
@@ -1,57 +1,86 @@
|
|
|
1
|
-
import { BaseProvider as
|
|
2
|
-
class
|
|
1
|
+
import { BaseProvider as m } from "./BaseProvider.js";
|
|
2
|
+
class k extends m {
|
|
3
3
|
async detectCapabilities() {
|
|
4
4
|
if (this.config.model)
|
|
5
5
|
try {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
} catch (
|
|
9
|
-
console.warn("Ollama capability detection failed:",
|
|
6
|
+
const e = (await this.fetchModelInfo()).capabilities || [];
|
|
7
|
+
e.includes("thinking") && this.capabilities.add("thinking"), e.includes("vision") && this.capabilities.add("vision"), e.includes("tools") && this.capabilities.add("tools");
|
|
8
|
+
} catch (t) {
|
|
9
|
+
console.warn("Ollama capability detection failed:", t);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
async fetchModelInfo() {
|
|
13
|
-
const
|
|
13
|
+
const t = await fetch(`${this.config.baseUrl}/api/show`, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
headers: { "Content-Type": "application/json" },
|
|
16
16
|
body: JSON.stringify({ name: this.config.model })
|
|
17
17
|
});
|
|
18
|
-
if (!
|
|
19
|
-
return
|
|
18
|
+
if (!t.ok) throw new Error(`Failed to fetch model info: ${t.status}`);
|
|
19
|
+
return t.json();
|
|
20
20
|
}
|
|
21
|
-
prepareRequest(
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
const
|
|
25
|
-
model:
|
|
26
|
-
messages: this.processMessages(
|
|
27
|
-
stream:
|
|
28
|
-
think:
|
|
29
|
-
options: { temperature:
|
|
21
|
+
prepareRequest(t, e) {
|
|
22
|
+
const s = e.model || this.config.model;
|
|
23
|
+
if (!s) throw new Error("Model must be specified for Ollama requests");
|
|
24
|
+
const i = {
|
|
25
|
+
model: s,
|
|
26
|
+
messages: this.processMessages(t, e),
|
|
27
|
+
stream: e.stream || !1,
|
|
28
|
+
think: e.enableThinking || !1,
|
|
29
|
+
options: { temperature: e.temperature ?? 0.7, num_predict: e.maxTokens || 1e3 }
|
|
30
30
|
};
|
|
31
|
-
return
|
|
31
|
+
return e.enableThinking && this.capabilities.has("thinking") && (i.options.enable_thinking = !0), e.tools && this.capabilities.has("tools") && (i.tools = e.tools), i;
|
|
32
32
|
}
|
|
33
|
-
processMessages(
|
|
34
|
-
|
|
33
|
+
processMessages(t, e) {
|
|
34
|
+
const s = p(t);
|
|
35
|
+
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(s, e.images) : s;
|
|
35
36
|
}
|
|
36
|
-
addImagesToMessages(
|
|
37
|
-
const
|
|
38
|
-
return
|
|
37
|
+
addImagesToMessages(t, e) {
|
|
38
|
+
const s = t[t.length - 1];
|
|
39
|
+
return s && s.role === "user" && (s.images = e.map((i) => typeof i == "string" && i.startsWith("data:") ? i.split(",")[1] : i)), t;
|
|
39
40
|
}
|
|
40
|
-
processResponse(
|
|
41
|
-
var i;
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
processResponse(t) {
|
|
42
|
+
var i, a;
|
|
43
|
+
const e = {
|
|
44
|
+
content: ((i = t.message) == null ? void 0 : i.content) || "",
|
|
45
|
+
usage: g(t),
|
|
46
|
+
finishReason: f(t.finish_reason)
|
|
47
|
+
};
|
|
48
|
+
t.thinking && (e.thinking = t.thinking);
|
|
49
|
+
const s = (a = t.message) == null ? void 0 : a.tool_calls;
|
|
50
|
+
return Array.isArray(s) && s.length && (e.toolCalls = s.map((r, c) => {
|
|
51
|
+
var o, l;
|
|
52
|
+
return {
|
|
53
|
+
id: h(c),
|
|
54
|
+
name: (o = r.function) == null ? void 0 : o.name,
|
|
55
|
+
args: d((l = r.function) == null ? void 0 : l.arguments)
|
|
56
|
+
};
|
|
57
|
+
})), e;
|
|
44
58
|
}
|
|
45
|
-
parseStreamingLine(
|
|
59
|
+
parseStreamingLine(t) {
|
|
46
60
|
try {
|
|
47
|
-
return JSON.parse(
|
|
61
|
+
return JSON.parse(t);
|
|
48
62
|
} catch {
|
|
49
63
|
return null;
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
|
-
extractStreamingContent(
|
|
53
|
-
var
|
|
54
|
-
|
|
66
|
+
extractStreamingContent(t) {
|
|
67
|
+
var i, a, r;
|
|
68
|
+
const e = {
|
|
69
|
+
content: ((i = t.message) == null ? void 0 : i.content) || "",
|
|
70
|
+
thinking: t.thinking || ((a = t.message) == null ? void 0 : a.thinking) || "",
|
|
71
|
+
done: t.done || !1,
|
|
72
|
+
usage: g(t),
|
|
73
|
+
finishReason: f(t.finish_reason)
|
|
74
|
+
}, s = (r = t.message) == null ? void 0 : r.tool_calls;
|
|
75
|
+
return Array.isArray(s) && s.length && (e.toolCallDeltas = s.map((c, o) => {
|
|
76
|
+
var l, u;
|
|
77
|
+
return {
|
|
78
|
+
index: o,
|
|
79
|
+
id: h(o),
|
|
80
|
+
name: ((l = c.function) == null ? void 0 : l.name) || "",
|
|
81
|
+
argsTextDelta: JSON.stringify(((u = c.function) == null ? void 0 : u.arguments) ?? {})
|
|
82
|
+
};
|
|
83
|
+
})), e;
|
|
55
84
|
}
|
|
56
85
|
getApiPath() {
|
|
57
86
|
return "/api/chat";
|
|
@@ -62,16 +91,63 @@ class l extends r {
|
|
|
62
91
|
getModelsEndpoint() {
|
|
63
92
|
return `${this.config.baseUrl}/api/tags`;
|
|
64
93
|
}
|
|
65
|
-
parseModelsResponse(
|
|
66
|
-
var
|
|
67
|
-
return ((
|
|
94
|
+
parseModelsResponse(t) {
|
|
95
|
+
var e;
|
|
96
|
+
return ((e = t.models) == null ? void 0 : e.map((s) => s.name)) || [];
|
|
68
97
|
}
|
|
69
98
|
}
|
|
70
|
-
function
|
|
71
|
-
if (!
|
|
72
|
-
const
|
|
73
|
-
return
|
|
99
|
+
function f(n) {
|
|
100
|
+
if (!n) return null;
|
|
101
|
+
const t = String(n).toLowerCase();
|
|
102
|
+
return t === "max_tokens" ? "length" : t;
|
|
103
|
+
}
|
|
104
|
+
function h(n) {
|
|
105
|
+
return `ollama_call_${n}`;
|
|
106
|
+
}
|
|
107
|
+
function g(n) {
|
|
108
|
+
if (!n || n.prompt_eval_count == null && n.eval_count == null) return null;
|
|
109
|
+
const t = n.prompt_eval_count ?? 0, e = n.eval_count ?? 0;
|
|
110
|
+
return { inputTokens: t, outputTokens: e, totalTokens: t + e, raw: n };
|
|
111
|
+
}
|
|
112
|
+
function d(n) {
|
|
113
|
+
if (n == null) return {};
|
|
114
|
+
if (typeof n == "string")
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(n);
|
|
117
|
+
} catch {
|
|
118
|
+
return { __parseError: !0, raw: n };
|
|
119
|
+
}
|
|
120
|
+
return n;
|
|
121
|
+
}
|
|
122
|
+
function p(n) {
|
|
123
|
+
return n.map((t) => {
|
|
124
|
+
if (t.role === "assistant" && Array.isArray(t.tool_calls) && t.tool_calls.length)
|
|
125
|
+
return {
|
|
126
|
+
role: "assistant",
|
|
127
|
+
content: t.content ?? "",
|
|
128
|
+
tool_calls: t.tool_calls.map((e) => ({
|
|
129
|
+
function: {
|
|
130
|
+
name: e.name,
|
|
131
|
+
arguments: typeof e.args == "string" ? _(e.args) : e.args || {}
|
|
132
|
+
}
|
|
133
|
+
}))
|
|
134
|
+
};
|
|
135
|
+
if (t.role === "tool") {
|
|
136
|
+
const { tool_call_id: e, ...s } = t;
|
|
137
|
+
return s;
|
|
138
|
+
}
|
|
139
|
+
return t;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function _(n) {
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(n);
|
|
145
|
+
} catch {
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
74
148
|
}
|
|
75
149
|
export {
|
|
76
|
-
|
|
150
|
+
k as OllamaProvider,
|
|
151
|
+
p as convertMessagesToOllama,
|
|
152
|
+
g as normalizeOllamaUsage
|
|
77
153
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var h = (s) => {
|
|
2
|
+
throw TypeError(s);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
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
7
|
import { BaseProvider as y } from "./BaseProvider.js";
|
|
8
|
-
var u,
|
|
8
|
+
var u, _;
|
|
9
9
|
class v extends y {
|
|
10
10
|
constructor() {
|
|
11
11
|
super(...arguments);
|
|
12
|
-
|
|
12
|
+
p(this, u);
|
|
13
13
|
}
|
|
14
14
|
async detectCapabilities() {
|
|
15
15
|
if (!this.config.model) return;
|
|
@@ -17,46 +17,46 @@ class v extends y {
|
|
|
17
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");
|
|
18
18
|
}
|
|
19
19
|
prepareRequest(t, e) {
|
|
20
|
-
const
|
|
21
|
-
model:
|
|
20
|
+
const n = e.model || this.config.model || "gpt-3.5-turbo", i = {
|
|
21
|
+
model: n,
|
|
22
22
|
messages: this.processMessages(t, e),
|
|
23
23
|
temperature: e.temperature ?? 0.7,
|
|
24
24
|
stream: e.stream || !1
|
|
25
25
|
};
|
|
26
|
-
return
|
|
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;
|
|
27
27
|
}
|
|
28
28
|
processMessages(t, e) {
|
|
29
|
-
const
|
|
30
|
-
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(
|
|
29
|
+
const n = A(t);
|
|
30
|
+
return e.images && this.capabilities.has("vision") ? this.addImagesToMessages(n, e.images) : n;
|
|
31
31
|
}
|
|
32
32
|
addImagesToMessages(t, e) {
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
e.forEach((
|
|
37
|
-
|
|
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) => {
|
|
37
|
+
i.push({
|
|
38
38
|
type: "image_url",
|
|
39
|
-
image_url: { url: typeof
|
|
39
|
+
image_url: { url: typeof r == "string" ? r : r.url }
|
|
40
40
|
});
|
|
41
|
-
}),
|
|
41
|
+
}), n.content = i;
|
|
42
42
|
}
|
|
43
43
|
return t;
|
|
44
44
|
}
|
|
45
45
|
processResponse(t) {
|
|
46
|
-
var
|
|
47
|
-
const e = (
|
|
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
48
|
content: (e == null ? void 0 : e.content) || "",
|
|
49
|
-
usage: t.usage
|
|
50
|
-
finishReason: ((
|
|
49
|
+
usage: g(t.usage),
|
|
50
|
+
finishReason: ((a = (l = t.choices) == null ? void 0 : l[0]) == null ? void 0 : a.finish_reason) || null
|
|
51
51
|
};
|
|
52
|
-
return t.reasoning && (
|
|
53
|
-
var
|
|
52
|
+
return t.reasoning && (n.thinking = t.reasoning), Array.isArray(e == null ? void 0 : e.tool_calls) && (n.toolCalls = e.tool_calls.map((c) => {
|
|
53
|
+
var d, f;
|
|
54
54
|
return {
|
|
55
55
|
id: c.id,
|
|
56
|
-
name: (
|
|
57
|
-
args:
|
|
56
|
+
name: (d = c.function) == null ? void 0 : d.name,
|
|
57
|
+
args: T((f = c.function) == null ? void 0 : f.arguments)
|
|
58
58
|
};
|
|
59
|
-
})),
|
|
59
|
+
})), n;
|
|
60
60
|
}
|
|
61
61
|
parseStreamingLine(t) {
|
|
62
62
|
if (!t.startsWith("data: ")) return null;
|
|
@@ -69,30 +69,30 @@ class v extends y {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
extractStreamingContent(t) {
|
|
72
|
-
var
|
|
72
|
+
var i, r, l;
|
|
73
73
|
if (t.done) return { done: !0 };
|
|
74
|
-
const e = (
|
|
75
|
-
if (
|
|
76
|
-
const
|
|
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];
|
|
77
77
|
return {
|
|
78
|
-
content:
|
|
79
|
-
thinking:
|
|
78
|
+
content: n.content || "",
|
|
79
|
+
thinking: n.reasoning || "",
|
|
80
80
|
done: !1,
|
|
81
|
-
usage: t.usage
|
|
81
|
+
usage: g(t.usage),
|
|
82
82
|
finishReason: (e == null ? void 0 : e.finish_reason) || null,
|
|
83
83
|
toolCallDelta: {
|
|
84
|
-
index:
|
|
85
|
-
id:
|
|
86
|
-
name: ((
|
|
87
|
-
argsTextDelta: ((l =
|
|
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) || ""
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
|
-
content: (
|
|
93
|
-
thinking: (
|
|
92
|
+
content: (n == null ? void 0 : n.content) || "",
|
|
93
|
+
thinking: (n == null ? void 0 : n.reasoning) || "",
|
|
94
94
|
done: !1,
|
|
95
|
-
usage: t.usage
|
|
95
|
+
usage: g(t.usage),
|
|
96
96
|
finishReason: (e == null ? void 0 : e.finish_reason) || null
|
|
97
97
|
};
|
|
98
98
|
}
|
|
@@ -107,29 +107,35 @@ class v extends y {
|
|
|
107
107
|
}
|
|
108
108
|
parseModelsResponse(t) {
|
|
109
109
|
var e;
|
|
110
|
-
return ((e = t.data) == null ? void 0 : e.filter((
|
|
111
|
-
const
|
|
112
|
-
return
|
|
113
|
-
}).map((
|
|
110
|
+
return ((e = t.data) == null ? void 0 : e.filter((n) => {
|
|
111
|
+
const i = n.id.toLowerCase();
|
|
112
|
+
return i.includes("gpt") || i.includes("chat");
|
|
113
|
+
}).map((n) => n.id).sort()) || [];
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
u = new WeakSet(),
|
|
116
|
+
u = new WeakSet(), _ = function(t) {
|
|
117
117
|
const e = (t || "").toLowerCase();
|
|
118
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");
|
|
119
119
|
};
|
|
120
|
-
function
|
|
121
|
-
if (!
|
|
120
|
+
function T(s) {
|
|
121
|
+
if (!s) return {};
|
|
122
122
|
try {
|
|
123
|
-
return JSON.parse(
|
|
123
|
+
return JSON.parse(s);
|
|
124
124
|
} catch {
|
|
125
|
-
return { __parseError: !0, raw:
|
|
125
|
+
return { __parseError: !0, raw: s };
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
128
|
+
function g(s) {
|
|
129
|
+
var l, a;
|
|
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;
|
|
133
|
+
}
|
|
134
|
+
function A(s) {
|
|
135
|
+
return s.map((o) => o.role === "assistant" && Array.isArray(o.tool_calls) && o.tool_calls.length ? {
|
|
130
136
|
role: "assistant",
|
|
131
|
-
content:
|
|
132
|
-
tool_calls:
|
|
137
|
+
content: o.content ?? null,
|
|
138
|
+
tool_calls: o.tool_calls.map((t) => ({
|
|
133
139
|
id: t.id,
|
|
134
140
|
type: "function",
|
|
135
141
|
function: {
|
|
@@ -137,9 +143,10 @@ function b(i) {
|
|
|
137
143
|
arguments: typeof t.args == "string" ? t.args : JSON.stringify(t.args || {})
|
|
138
144
|
}
|
|
139
145
|
}))
|
|
140
|
-
} :
|
|
146
|
+
} : o);
|
|
141
147
|
}
|
|
142
148
|
export {
|
|
143
149
|
v as OpenAIProvider,
|
|
144
|
-
|
|
150
|
+
A as convertMessagesToOpenAI,
|
|
151
|
+
g as normalizeOpenAIUsage
|
|
145
152
|
};
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { BaseProvider as
|
|
2
|
-
import { convertMessagesToOpenAI as
|
|
3
|
-
class y extends
|
|
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(
|
|
7
|
+
prepareRequest(i, e) {
|
|
8
8
|
const t = {
|
|
9
9
|
model: e.model || this.config.model,
|
|
10
|
-
messages: this.processMessages(
|
|
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(
|
|
18
|
-
const t =
|
|
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(
|
|
22
|
-
const t =
|
|
23
|
-
return t && t.role === "user" && (t.content = [{ type: "text", text: t.content }, ...e.map((
|
|
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
|
|
27
|
-
return this.requiresAuth() && (
|
|
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(
|
|
30
|
-
var
|
|
31
|
-
const e = (s = (
|
|
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
|
|
33
|
+
var d, h;
|
|
34
34
|
return {
|
|
35
35
|
id: l.id,
|
|
36
|
-
name: (
|
|
37
|
-
args:
|
|
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(
|
|
42
|
-
if (!
|
|
43
|
-
const e =
|
|
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(
|
|
52
|
-
var
|
|
53
|
-
if (
|
|
54
|
-
const e = (
|
|
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:
|
|
62
|
-
finishReason:
|
|
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:
|
|
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(
|
|
83
|
-
return Array.isArray(
|
|
84
|
-
var
|
|
85
|
-
const t = (
|
|
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(
|
|
89
|
+
async discoverModelsWithMetadata(i = 15e3) {
|
|
90
90
|
try {
|
|
91
|
-
const e = this.buildHeaders(), t = new AbortController(),
|
|
92
|
-
if (clearTimeout(
|
|
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
|
|
99
|
+
function u(r) {
|
|
100
100
|
if (!r) return null;
|
|
101
|
-
const
|
|
102
|
-
return
|
|
101
|
+
const i = String(r).toLowerCase();
|
|
102
|
+
return i === "length" || i === "max_tokens" ? "length" : i;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
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
|
|
8
|
-
import { OpenRouterProvider as
|
|
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
|
-
},
|
|
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
|
|
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
|
|
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
|
-
|
|
74
|
+
S as DEFAULT_CONFIGS,
|
|
70
75
|
e as PROVIDERS,
|
|
71
76
|
c as createProvider,
|
|
72
77
|
N as createProviderFlexible,
|
|
73
|
-
|
|
78
|
+
b as registerProvider
|
|
74
79
|
};
|
package/dist/providers/index.js
CHANGED
|
@@ -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
|
|
3
|
+
import { AnthropicProvider as p } from "./AnthropicProvider.js";
|
|
4
4
|
import { BEDROCK_CLAUDE_MODELS as v, BedrockProvider as x } from "./BedrockProvider.js";
|
|
5
|
-
import {
|
|
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
|
-
|
|
8
|
+
p as AnthropicProvider,
|
|
8
9
|
v as BEDROCK_CLAUDE_MODELS,
|
|
9
10
|
o as BaseProvider,
|
|
10
11
|
x as BedrockProvider,
|
|
11
|
-
|
|
12
|
+
E as DEFAULT_CONFIGS,
|
|
13
|
+
m as DeepSeekProvider,
|
|
12
14
|
t as OpenAIProvider,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
O as PROVIDERS,
|
|
16
|
+
c as createProvider,
|
|
17
|
+
A as createProviderFlexible,
|
|
18
|
+
S as registerProvider
|
|
17
19
|
};
|