@alisio/plugin-deepseek 0.1.0-alpha.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gustavo Gutiérrez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @alisio/plugin-deepseek
2
+
3
+ Built-in DeepSeek provider for Alisio. It supports model discovery plus the documented Chat
4
+ Completions and Responses APIs. Credentials are supplied by Alisio and are never persisted here.
@@ -0,0 +1,6 @@
1
+ import { type Plugin } from "@alisio/sdk";
2
+ export declare function createDeepSeekPlugin(): Plugin;
3
+ export type { DeepSeekConfig } from "./provider.ts";
4
+ export { DeepSeekProvider } from "./provider.ts";
5
+ declare const _default: Plugin;
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ import { definePlugin } from "@alisio/sdk";
2
+ import { DeepSeekProvider } from "./provider.js";
3
+ const DEFAULT_BASE_URL = "https://api.deepseek.com";
4
+ const profileString = (request, key, fallback) => typeof request.profile[key] === "string" ? String(request.profile[key]) : fallback;
5
+ export function createDeepSeekPlugin() {
6
+ return definePlugin({
7
+ id: "deepseek",
8
+ name: "DeepSeek",
9
+ description: "Dedicated DeepSeek Chat Completions and Responses provider",
10
+ categories: ["model-provider"],
11
+ version: "0.1.0-alpha.1",
12
+ apiVersion: 1,
13
+ setup(api) {
14
+ api.providers.register({
15
+ id: "deepseek",
16
+ name: "DeepSeek",
17
+ description: "DeepSeek Chat Completions and Responses APIs",
18
+ fields: [
19
+ {
20
+ key: "apiKey",
21
+ label: "API key",
22
+ kind: "secret",
23
+ required: true,
24
+ description: "Stored only in the global credentials file",
25
+ },
26
+ {
27
+ key: "apiMode",
28
+ label: "API mode",
29
+ kind: "select",
30
+ required: true,
31
+ defaultValue: "chat",
32
+ options: [
33
+ { value: "chat", label: "Chat Completions" },
34
+ { value: "responses", label: "Responses" },
35
+ ],
36
+ },
37
+ {
38
+ key: "baseURL",
39
+ label: "DeepSeek API base URL",
40
+ kind: "url",
41
+ required: true,
42
+ defaultValue: DEFAULT_BASE_URL,
43
+ description: "Change only for a DeepSeek-compatible proxy",
44
+ },
45
+ ],
46
+ create(request) {
47
+ const apiKey = request.credentials.apiKey;
48
+ if (!apiKey)
49
+ throw new Error("DeepSeek API key is required");
50
+ const baseURL = profileString(request, "baseURL", DEFAULT_BASE_URL);
51
+ const url = new URL(baseURL);
52
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
53
+ throw new Error("DeepSeek base URL must be HTTP(S) and must not contain credentials");
54
+ const apiMode = profileString(request, "apiMode", "chat");
55
+ if (apiMode !== "chat" && apiMode !== "responses")
56
+ throw new Error(`Unsupported DeepSeek API mode: ${apiMode}`);
57
+ const config = {
58
+ baseURL,
59
+ apiKey,
60
+ apiKeyEnv: "DEEPSEEK_API_KEY",
61
+ model: profileString(request, "model", ""),
62
+ apiMode,
63
+ auth: "bearer",
64
+ tokenParameter: "max_tokens",
65
+ streamUsage: true,
66
+ };
67
+ return new DeepSeekProvider(config);
68
+ },
69
+ });
70
+ },
71
+ });
72
+ }
73
+ export { DeepSeekProvider } from "./provider.js";
74
+ export default createDeepSeekPlugin();
@@ -0,0 +1,23 @@
1
+ import type { ModelInfo, ModelProvider, ProviderEvent } from "@alisio/sdk";
2
+ import OpenAI from "openai";
3
+ export interface DeepSeekConfig {
4
+ baseURL: string;
5
+ apiKey?: string;
6
+ apiKeyEnv: string;
7
+ model: string;
8
+ apiMode: "chat" | "responses";
9
+ auth: "bearer" | "none";
10
+ tokenParameter: "max_tokens" | "max_completion_tokens" | "omit";
11
+ streamUsage: boolean;
12
+ contextWindow?: number;
13
+ }
14
+ export declare class DeepSeekProvider implements ModelProvider {
15
+ #private;
16
+ readonly id: string;
17
+ readonly model: string;
18
+ constructor(config: DeepSeekConfig, client?: OpenAI);
19
+ /** Lists models using DeepSeek's official GET /models response fields. */
20
+ listModels(signal: AbortSignal): Promise<ModelInfo[]>;
21
+ stream(request: Parameters<ModelProvider["stream"]>[0]): AsyncIterable<ProviderEvent>;
22
+ private responses;
23
+ }
@@ -0,0 +1,268 @@
1
+ import OpenAI from "openai";
2
+ const dataUrl = (a) => `data:${a.mimeType};base64,${a.data}`;
3
+ export class DeepSeekProvider {
4
+ id;
5
+ model;
6
+ #client;
7
+ #config;
8
+ constructor(config, client) {
9
+ this.model = config.model;
10
+ const { apiKey: _apiKey, ...safeConfig } = config;
11
+ this.#config = safeConfig;
12
+ const key = config.auth === "none" ? "unused" : (config.apiKey ?? process.env[config.apiKeyEnv]);
13
+ if (!client && !key)
14
+ throw new Error(`Missing API key environment variable: ${config.apiKeyEnv}`);
15
+ this.id = `deepseek:${config.apiMode}:${config.baseURL.replace(/\/$/, "")}`;
16
+ this.#client =
17
+ client ??
18
+ new OpenAI({
19
+ baseURL: config.baseURL,
20
+ apiKey: key,
21
+ maxRetries: 0,
22
+ timeout: 120_000,
23
+ ...(config.auth === "none" ? { defaultHeaders: { Authorization: null } } : {}),
24
+ });
25
+ }
26
+ /** Lists models using DeepSeek's official GET /models response fields. */
27
+ async listModels(signal) {
28
+ const models = [];
29
+ for await (const m of this.#client.models.list({ signal })) {
30
+ const extra = m;
31
+ const window = extra.context_window;
32
+ const maxOutput = extra.max_output_tokens;
33
+ const inputModalities = Array.isArray(extra.input_modalities)
34
+ ? extra.input_modalities.filter((v) => typeof v === "string")
35
+ : undefined;
36
+ const outputModalities = Array.isArray(extra.output_modalities)
37
+ ? extra.output_modalities.filter((v) => typeof v === "string")
38
+ : undefined;
39
+ const apiCapabilities = extra.api_capabilities &&
40
+ typeof extra.api_capabilities === "object" &&
41
+ !Array.isArray(extra.api_capabilities)
42
+ ? structuredClone(extra.api_capabilities)
43
+ : undefined;
44
+ const effortSource = extra.effort && typeof extra.effort === "object"
45
+ ? extra.effort
46
+ : undefined;
47
+ const supportedLevels = Array.isArray(effortSource?.supported_levels)
48
+ ? effortSource.supported_levels.filter((v) => typeof v === "string")
49
+ : [];
50
+ const defaultLevel = effortSource?.default_level;
51
+ models.push({
52
+ id: m.id,
53
+ ...(typeof extra.owned_by === "string" ? { ownedBy: extra.owned_by } : {}),
54
+ ...(typeof extra.name === "string" ? { name: extra.name } : {}),
55
+ ...(typeof window === "number" && Number.isFinite(window) && window > 0
56
+ ? { contextWindow: window }
57
+ : {}),
58
+ ...(typeof maxOutput === "number" && maxOutput > 0 ? { maxOutputTokens: maxOutput } : {}),
59
+ ...(inputModalities?.length ? { inputModalities } : {}),
60
+ ...(outputModalities?.length ? { outputModalities } : {}),
61
+ ...(apiCapabilities ? { apiCapabilities } : {}),
62
+ ...(supportedLevels.length
63
+ ? {
64
+ effort: {
65
+ supportedLevels,
66
+ ...(typeof defaultLevel === "string" ? { defaultLevel } : {}),
67
+ },
68
+ }
69
+ : {}),
70
+ });
71
+ if (models.length >= 1000)
72
+ break;
73
+ }
74
+ return models;
75
+ }
76
+ async *stream(request) {
77
+ if (this.#config.apiMode === "responses") {
78
+ yield* this.responses(request);
79
+ return;
80
+ }
81
+ const messages = [
82
+ { role: "system", content: request.instructions },
83
+ ];
84
+ for (const m of request.messages) {
85
+ if (m.role === "user") {
86
+ if (m.attachments?.length) {
87
+ const parts = [];
88
+ if (m.text.trim())
89
+ parts.push({ type: "text", text: m.text });
90
+ for (const a of m.attachments)
91
+ parts.push({ type: "image_url", image_url: { url: dataUrl(a) } });
92
+ messages.push({ role: "user", content: parts });
93
+ }
94
+ else
95
+ messages.push({ role: "user", content: m.text });
96
+ }
97
+ else if (m.role === "tool")
98
+ messages.push({ role: "tool", tool_call_id: m.callId, content: JSON.stringify(m.result) });
99
+ else
100
+ messages.push({
101
+ role: "assistant",
102
+ content: m.text || null,
103
+ ...(m.calls.length
104
+ ? {
105
+ tool_calls: m.calls.map((c) => ({
106
+ id: c.id,
107
+ type: "function",
108
+ function: { name: c.name, arguments: c.arguments },
109
+ })),
110
+ }
111
+ : {}),
112
+ });
113
+ }
114
+ const limit = this.#config.tokenParameter === "omit"
115
+ ? {}
116
+ : { [this.#config.tokenParameter]: request.maxOutputTokens };
117
+ const stream = await this.#client.chat.completions.create({
118
+ model: request.model || this.model,
119
+ messages,
120
+ stream: true,
121
+ ...limit,
122
+ ...(this.#config.streamUsage ? { stream_options: { include_usage: true } } : {}),
123
+ ...(request.tools.length || request.nativeTools?.length
124
+ ? {
125
+ tools: [
126
+ ...request.tools.map((t) => ({
127
+ type: "function",
128
+ function: { name: t.name, description: t.description, parameters: t.inputSchema },
129
+ })),
130
+ ...(request.nativeTools ?? []),
131
+ ],
132
+ }
133
+ : {}),
134
+ }, { signal: request.signal });
135
+ let text = "", finish = null, usage;
136
+ const calls = new Map();
137
+ for await (const chunk of stream) {
138
+ if (chunk.usage) {
139
+ // DeepSeek reports prompt_cache_hit_tokens; OpenAI uses prompt_tokens_details.
140
+ const extra = chunk.usage;
141
+ const cached = chunk.usage.prompt_tokens_details?.cached_tokens ?? extra.prompt_cache_hit_tokens;
142
+ usage = {
143
+ input: chunk.usage.prompt_tokens,
144
+ output: chunk.usage.completion_tokens,
145
+ ...(typeof cached === "number" ? { cachedInput: cached } : {}),
146
+ };
147
+ }
148
+ const choice = chunk.choices[0];
149
+ if (!choice)
150
+ continue;
151
+ const reasoning = choice.delta.reasoning_content;
152
+ if (typeof reasoning === "string" && reasoning)
153
+ yield { type: "reasoning_delta", delta: reasoning };
154
+ if (choice.delta.content) {
155
+ text += choice.delta.content;
156
+ yield { type: "text_delta", delta: choice.delta.content };
157
+ }
158
+ if (choice.delta.refusal)
159
+ throw new Error(`Provider refusal: ${choice.delta.refusal}`);
160
+ for (const part of choice.delta.tool_calls ?? []) {
161
+ const c = calls.get(part.index) ?? { id: "", name: "", arguments: "" };
162
+ if (part.id)
163
+ c.id = part.id;
164
+ if (part.function?.name)
165
+ c.name += part.function.name;
166
+ if (part.function?.arguments)
167
+ c.arguments += part.function.arguments;
168
+ calls.set(part.index, c);
169
+ }
170
+ if (choice.finish_reason)
171
+ finish = choice.finish_reason;
172
+ }
173
+ if (finish !== "stop" && finish !== "tool_calls")
174
+ throw new Error(`Provider response incomplete: ${finish ?? "stream ended"}`);
175
+ const completed = [...calls.entries()].sort(([a], [b]) => a - b).map(([, c]) => c);
176
+ if (completed.some((c) => !c.id || !c.name))
177
+ throw new Error("Incomplete tool call");
178
+ yield { type: "completed", message: { role: "assistant", text, calls: completed }, usage };
179
+ }
180
+ async *responses(request) {
181
+ const input = [];
182
+ for (const m of request.messages) {
183
+ if (m.role === "user") {
184
+ if (m.attachments?.length) {
185
+ const content = [];
186
+ if (m.text.trim())
187
+ content.push({ type: "input_text", text: m.text });
188
+ for (const a of m.attachments)
189
+ content.push({ type: "input_image", image_url: dataUrl(a), detail: "auto" });
190
+ input.push({ role: "user", content });
191
+ }
192
+ else
193
+ input.push({ role: "user", content: m.text });
194
+ }
195
+ else if (m.role === "tool")
196
+ input.push({
197
+ type: "function_call_output",
198
+ call_id: m.callId,
199
+ output: JSON.stringify(m.result),
200
+ });
201
+ else if (m.providerData)
202
+ input.push(...m.providerData);
203
+ else
204
+ throw new Error("Missing provider continuation data for Responses session");
205
+ }
206
+ const stream = await this.#client.responses.create({
207
+ model: request.model || this.model,
208
+ instructions: request.instructions,
209
+ input,
210
+ stream: true,
211
+ store: false,
212
+ include: ["reasoning.encrypted_content"],
213
+ max_output_tokens: request.maxOutputTokens,
214
+ tools: [
215
+ ...request.tools.map((t) => ({
216
+ type: "function",
217
+ name: t.name,
218
+ description: t.description,
219
+ parameters: t.inputSchema,
220
+ strict: false,
221
+ })),
222
+ ...(request.nativeTools ?? []),
223
+ ],
224
+ }, { signal: request.signal });
225
+ let complete = false;
226
+ for await (const event of stream) {
227
+ const officialEvent = event;
228
+ if (event.type === "response.output_text.delta")
229
+ yield { type: "text_delta", delta: event.delta };
230
+ if ((officialEvent.type === "response.reasoning_text.delta" ||
231
+ officialEvent.type === "response.reasoning_summary_text.delta") &&
232
+ typeof officialEvent.delta === "string")
233
+ yield { type: "reasoning_delta", delta: officialEvent.delta };
234
+ if (event.type === "response.failed" ||
235
+ event.type === "response.incomplete" ||
236
+ event.type === "error")
237
+ throw new Error(`Provider response failed: ${event.type}`);
238
+ if (event.type === "response.completed") {
239
+ complete = true;
240
+ const r = event.response;
241
+ const calls = r.output
242
+ .filter((x) => x.type === "function_call")
243
+ .map((x) => ({ id: x.call_id, name: x.name, arguments: x.arguments }));
244
+ const text = r.output
245
+ .filter((x) => x.type === "message")
246
+ .flatMap((x) => x.content)
247
+ .filter((x) => x.type === "output_text")
248
+ .map((x) => x.text)
249
+ .join("");
250
+ yield {
251
+ type: "completed",
252
+ message: { role: "assistant", text, calls, providerData: r.output },
253
+ usage: r.usage
254
+ ? {
255
+ input: r.usage.input_tokens,
256
+ output: r.usage.output_tokens,
257
+ ...(typeof r.usage.input_tokens_details?.cached_tokens === "number"
258
+ ? { cachedInput: r.usage.input_tokens_details.cached_tokens }
259
+ : {}),
260
+ }
261
+ : undefined,
262
+ };
263
+ }
264
+ }
265
+ if (!complete)
266
+ throw new Error("Responses stream ended before completion");
267
+ }
268
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@alisio/plugin-deepseek",
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "Built-in DeepSeek model provider for Alisio.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=22.16"
22
+ },
23
+ "dependencies": {
24
+ "openai": "7.23.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@alisio/sdk": "^0.1.0-alpha.2"
28
+ },
29
+ "devDependencies": {
30
+ "@alisio/sdk": "0.1.0-alpha.2"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "registry": "https://registry.npmjs.com/"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.build.json"
38
+ }
39
+ }