@alisio/plugin-deepseek 0.1.0-alpha.10
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 +21 -0
- package/README.md +54 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +89 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +322 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +28 -0
- package/package.json +39 -0
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,54 @@
|
|
|
1
|
+
# @alisio/plugin-deepseek
|
|
2
|
+
|
|
3
|
+
**The built-in DeepSeek model provider for [Alisio](https://github.com/GustavoGutierrez/alisio).**
|
|
4
|
+
Select it in `/connect`, discover models from the DeepSeek catalog, and talk to the Chat
|
|
5
|
+
Completions or Responses API.
|
|
6
|
+
|
|
7
|
+
## What it is
|
|
8
|
+
|
|
9
|
+
A `model-provider` plugin that registers the `deepseek` provider with the Alisio host. It ships as a
|
|
10
|
+
built-in of the `alisio` CLI and is enabled by default. Credentials are managed by Alisio and are
|
|
11
|
+
never persisted by this plugin: keys live in the global credentials store or an environment
|
|
12
|
+
variable.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Preinstalled in the `alisio` CLI. For an embedded host, register it through `createApplication`'s
|
|
17
|
+
`builtins` list.
|
|
18
|
+
|
|
19
|
+
## Using it: `/connect`
|
|
20
|
+
|
|
21
|
+
1. Run `alisio`, then `/connect` and choose **DeepSeek**.
|
|
22
|
+
2. Fields: **API key** (secret, required), **API key environment variable** (default
|
|
23
|
+
`DEEPSEEK_API_KEY`), **API mode** (`chat` or `responses`), **base URL** (default
|
|
24
|
+
`https://api.deepseek.com`; change only for a DeepSeek-compatible proxy).
|
|
25
|
+
3. Pick a model from the discovered catalog — for example `deepseek/deepseek-chat`.
|
|
26
|
+
|
|
27
|
+
The key is read from the stored credential first, then from `process.env[apiKeyEnv]` — usually:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
export DEEPSEEK_API_KEY=... # never put the key in config files, profiles or READMEs
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- Model discovery from the DeepSeek catalog (`GET /models`) with honest context windows.
|
|
36
|
+
- Chat Completions and Responses modes (default `chat`); bearer auth, `max_tokens` output budget.
|
|
37
|
+
- Provider-side usage reporting while streaming (`streamUsage: true`).
|
|
38
|
+
- Credentials never leave the Alisio credentials store or the named environment variable.
|
|
39
|
+
|
|
40
|
+
While registered, the provider also appears in `/model` and `alisio doctor`.
|
|
41
|
+
|
|
42
|
+
## Docs
|
|
43
|
+
|
|
44
|
+
[Configuration](https://gustavogutierrez.github.io/alisio/configuration) ·
|
|
45
|
+
[Plugins](https://gustavogutierrez.github.io/alisio/plugins).
|
|
46
|
+
|
|
47
|
+
## Requirements
|
|
48
|
+
|
|
49
|
+
Node.js **>= 22.16** or Bun **>= 1.4.2**.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT. Maintained by Gustavo Gutiérrez Mercado. Source: <https://github.com/GustavoGutierrez/alisio> ·
|
|
54
|
+
npm: <https://www.npmjs.com/settings/alisio/packages>.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { definePlugin } from "@alisio/sdk";
|
|
2
|
+
import { DeepSeekProvider } from "./provider.js";
|
|
3
|
+
import { loadVersion } from "./version.js";
|
|
4
|
+
const DEFAULT_BASE_URL = "https://api.deepseek.com";
|
|
5
|
+
const DEFAULT_API_KEY_ENV = "DEEPSEEK_API_KEY";
|
|
6
|
+
const profileString = (request, key, fallback) => typeof request.profile[key] === "string" && String(request.profile[key]).trim()
|
|
7
|
+
? String(request.profile[key]).trim()
|
|
8
|
+
: typeof request.legacy?.[key] === "string" && String(request.legacy[key]).trim()
|
|
9
|
+
? String(request.legacy[key]).trim()
|
|
10
|
+
: fallback;
|
|
11
|
+
export function createDeepSeekPlugin() {
|
|
12
|
+
return definePlugin({
|
|
13
|
+
id: "deepseek",
|
|
14
|
+
name: "DeepSeek",
|
|
15
|
+
description: "Dedicated DeepSeek Chat Completions and Responses provider",
|
|
16
|
+
categories: ["model-provider"],
|
|
17
|
+
version: loadVersion(import.meta.url),
|
|
18
|
+
apiVersion: 1,
|
|
19
|
+
setup(api) {
|
|
20
|
+
api.providers.register({
|
|
21
|
+
id: "deepseek",
|
|
22
|
+
name: "DeepSeek",
|
|
23
|
+
description: "DeepSeek Chat Completions and Responses APIs",
|
|
24
|
+
fields: [
|
|
25
|
+
{
|
|
26
|
+
key: "apiKey",
|
|
27
|
+
label: "API key",
|
|
28
|
+
kind: "secret",
|
|
29
|
+
required: true,
|
|
30
|
+
description: "Stored only in the global credentials file",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "apiKeyEnv",
|
|
34
|
+
label: "API key environment variable",
|
|
35
|
+
kind: "text",
|
|
36
|
+
required: false,
|
|
37
|
+
defaultValue: DEFAULT_API_KEY_ENV,
|
|
38
|
+
description: "Environment variable consulted when no stored API key exists; the connection remembers this name",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "apiMode",
|
|
42
|
+
label: "API mode",
|
|
43
|
+
kind: "select",
|
|
44
|
+
required: true,
|
|
45
|
+
defaultValue: "chat",
|
|
46
|
+
options: [
|
|
47
|
+
{ value: "chat", label: "Chat Completions" },
|
|
48
|
+
{ value: "responses", label: "Responses" },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "baseURL",
|
|
53
|
+
label: "DeepSeek API base URL",
|
|
54
|
+
kind: "url",
|
|
55
|
+
required: true,
|
|
56
|
+
defaultValue: DEFAULT_BASE_URL,
|
|
57
|
+
description: "Change only for a DeepSeek-compatible proxy",
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
create(request) {
|
|
61
|
+
const apiKey = request.credentials.apiKey;
|
|
62
|
+
const apiKeyEnv = profileString(request, "apiKeyEnv", DEFAULT_API_KEY_ENV);
|
|
63
|
+
if (!apiKey && !process.env[apiKeyEnv])
|
|
64
|
+
throw new Error(`DeepSeek API key is required (set it in /connect or export ${apiKeyEnv})`);
|
|
65
|
+
const baseURL = profileString(request, "baseURL", DEFAULT_BASE_URL);
|
|
66
|
+
const url = new URL(baseURL);
|
|
67
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
|
|
68
|
+
throw new Error("DeepSeek base URL must be HTTP(S) and must not contain credentials");
|
|
69
|
+
const apiMode = profileString(request, "apiMode", "chat");
|
|
70
|
+
if (apiMode !== "chat" && apiMode !== "responses")
|
|
71
|
+
throw new Error(`Unsupported DeepSeek API mode: ${apiMode}`);
|
|
72
|
+
const config = {
|
|
73
|
+
baseURL,
|
|
74
|
+
...(apiKey ? { apiKey } : {}),
|
|
75
|
+
apiKeyEnv,
|
|
76
|
+
model: profileString(request, "model", ""),
|
|
77
|
+
apiMode,
|
|
78
|
+
auth: "bearer",
|
|
79
|
+
tokenParameter: "max_tokens",
|
|
80
|
+
streamUsage: true,
|
|
81
|
+
};
|
|
82
|
+
return new DeepSeekProvider(config);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export { DeepSeekProvider } from "./provider.js";
|
|
89
|
+
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
|
+
}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
// `reasoning_effort` is provider-declared (DeepSeek's catalog `effort.supported_levels`); the
|
|
118
|
+
// SDK type is a fixed union, so the value is carried through the params type of `create`.
|
|
119
|
+
const reasoningEffort = request.reasoningEffort
|
|
120
|
+
? {
|
|
121
|
+
reasoning_effort: request.reasoningEffort,
|
|
122
|
+
}
|
|
123
|
+
: {};
|
|
124
|
+
const stream = await this.#client.chat.completions.create({
|
|
125
|
+
model: request.model || this.model,
|
|
126
|
+
messages,
|
|
127
|
+
stream: true,
|
|
128
|
+
...limit,
|
|
129
|
+
...(this.#config.streamUsage ? { stream_options: { include_usage: true } } : {}),
|
|
130
|
+
...reasoningEffort,
|
|
131
|
+
...(request.tools.length || request.nativeTools?.length
|
|
132
|
+
? {
|
|
133
|
+
tools: [
|
|
134
|
+
...request.tools.map((t) => ({
|
|
135
|
+
type: "function",
|
|
136
|
+
function: { name: t.name, description: t.description, parameters: t.inputSchema },
|
|
137
|
+
})),
|
|
138
|
+
...(request.nativeTools ?? []),
|
|
139
|
+
],
|
|
140
|
+
}
|
|
141
|
+
: {}),
|
|
142
|
+
}, { signal: request.signal });
|
|
143
|
+
let text = "", finish = null, usage;
|
|
144
|
+
const calls = new Map();
|
|
145
|
+
for await (const chunk of stream) {
|
|
146
|
+
if (chunk.usage) {
|
|
147
|
+
// DeepSeek reports prompt_cache_hit_tokens; OpenAI uses prompt_tokens_details.
|
|
148
|
+
const extra = chunk.usage;
|
|
149
|
+
const cached = chunk.usage.prompt_tokens_details?.cached_tokens ?? extra.prompt_cache_hit_tokens;
|
|
150
|
+
usage = {
|
|
151
|
+
input: chunk.usage.prompt_tokens,
|
|
152
|
+
output: chunk.usage.completion_tokens,
|
|
153
|
+
...(typeof cached === "number" ? { cachedInput: cached } : {}),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const choice = chunk.choices[0];
|
|
157
|
+
if (!choice)
|
|
158
|
+
continue;
|
|
159
|
+
const reasoning = choice.delta.reasoning_content;
|
|
160
|
+
if (typeof reasoning === "string" && reasoning)
|
|
161
|
+
yield { type: "reasoning_delta", delta: reasoning };
|
|
162
|
+
if (choice.delta.content) {
|
|
163
|
+
text += choice.delta.content;
|
|
164
|
+
yield { type: "text_delta", delta: choice.delta.content };
|
|
165
|
+
}
|
|
166
|
+
if (choice.delta.refusal)
|
|
167
|
+
throw new Error(`Provider refusal: ${choice.delta.refusal}`);
|
|
168
|
+
for (const part of choice.delta.tool_calls ?? []) {
|
|
169
|
+
const c = calls.get(part.index) ?? { id: "", name: "", arguments: "" };
|
|
170
|
+
if (part.id)
|
|
171
|
+
c.id = part.id;
|
|
172
|
+
if (part.function?.name)
|
|
173
|
+
c.name += part.function.name;
|
|
174
|
+
if (part.function?.arguments)
|
|
175
|
+
c.arguments += part.function.arguments;
|
|
176
|
+
calls.set(part.index, c);
|
|
177
|
+
}
|
|
178
|
+
if (choice.finish_reason)
|
|
179
|
+
finish = choice.finish_reason;
|
|
180
|
+
}
|
|
181
|
+
if (finish !== "stop" && finish !== "tool_calls" && finish !== "length")
|
|
182
|
+
throw new Error(`Provider response incomplete: ${finish ?? "stream ended"}`);
|
|
183
|
+
const completed = [...calls.entries()].sort(([a], [b]) => a - b).map(([, c]) => c);
|
|
184
|
+
if (completed.some((c) => !c.id || !c.name))
|
|
185
|
+
throw new Error("Incomplete tool call");
|
|
186
|
+
if (finish === "length" && !text.trim())
|
|
187
|
+
throw new Error("Provider response cut off by max output tokens before any usable content; raise limits.maxOutputTokens (/settings → Agent max output tokens)");
|
|
188
|
+
yield {
|
|
189
|
+
type: "completed",
|
|
190
|
+
message: {
|
|
191
|
+
role: "assistant",
|
|
192
|
+
text,
|
|
193
|
+
calls: completed,
|
|
194
|
+
...(finish === "length" ? { truncated: true } : {}),
|
|
195
|
+
},
|
|
196
|
+
usage,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
async *responses(request) {
|
|
200
|
+
const input = [];
|
|
201
|
+
for (const m of request.messages) {
|
|
202
|
+
if (m.role === "user") {
|
|
203
|
+
if (m.attachments?.length) {
|
|
204
|
+
const content = [];
|
|
205
|
+
if (m.text.trim())
|
|
206
|
+
content.push({ type: "input_text", text: m.text });
|
|
207
|
+
for (const a of m.attachments)
|
|
208
|
+
content.push({ type: "input_image", image_url: dataUrl(a), detail: "auto" });
|
|
209
|
+
input.push({ role: "user", content });
|
|
210
|
+
}
|
|
211
|
+
else
|
|
212
|
+
input.push({ role: "user", content: m.text });
|
|
213
|
+
}
|
|
214
|
+
else if (m.role === "tool")
|
|
215
|
+
input.push({
|
|
216
|
+
type: "function_call_output",
|
|
217
|
+
call_id: m.callId,
|
|
218
|
+
output: JSON.stringify(m.result),
|
|
219
|
+
});
|
|
220
|
+
else if (m.providerData)
|
|
221
|
+
input.push(...m.providerData);
|
|
222
|
+
else
|
|
223
|
+
throw new Error("Missing provider continuation data for Responses session");
|
|
224
|
+
}
|
|
225
|
+
const stream = await this.#client.responses.create({
|
|
226
|
+
model: request.model || this.model,
|
|
227
|
+
instructions: request.instructions,
|
|
228
|
+
input,
|
|
229
|
+
stream: true,
|
|
230
|
+
store: false,
|
|
231
|
+
include: ["reasoning.encrypted_content"],
|
|
232
|
+
max_output_tokens: request.maxOutputTokens,
|
|
233
|
+
...(request.reasoningEffort
|
|
234
|
+
? {
|
|
235
|
+
reasoning: {
|
|
236
|
+
effort: request.reasoningEffort,
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
: {}),
|
|
240
|
+
tools: [
|
|
241
|
+
...request.tools.map((t) => ({
|
|
242
|
+
type: "function",
|
|
243
|
+
name: t.name,
|
|
244
|
+
description: t.description,
|
|
245
|
+
parameters: t.inputSchema,
|
|
246
|
+
strict: false,
|
|
247
|
+
})),
|
|
248
|
+
...(request.nativeTools ?? []),
|
|
249
|
+
],
|
|
250
|
+
}, { signal: request.signal });
|
|
251
|
+
let complete = false;
|
|
252
|
+
for await (const event of stream) {
|
|
253
|
+
const officialEvent = event;
|
|
254
|
+
if (event.type === "response.output_text.delta")
|
|
255
|
+
yield { type: "text_delta", delta: event.delta };
|
|
256
|
+
if ((officialEvent.type === "response.reasoning_text.delta" ||
|
|
257
|
+
officialEvent.type === "response.reasoning_summary_text.delta") &&
|
|
258
|
+
typeof officialEvent.delta === "string")
|
|
259
|
+
yield { type: "reasoning_delta", delta: officialEvent.delta };
|
|
260
|
+
if (event.type === "response.failed" || event.type === "error")
|
|
261
|
+
throw new Error(`Provider response failed: ${event.type}`);
|
|
262
|
+
if (event.type === "response.incomplete") {
|
|
263
|
+
complete = true;
|
|
264
|
+
const r = event.response;
|
|
265
|
+
const calls = r.output
|
|
266
|
+
.filter((x) => x.type === "function_call")
|
|
267
|
+
.map((x) => ({ id: x.call_id, name: x.name, arguments: x.arguments }));
|
|
268
|
+
const text = r.output
|
|
269
|
+
.filter((x) => x.type === "message")
|
|
270
|
+
.flatMap((x) => x.content)
|
|
271
|
+
.filter((x) => x.type === "output_text")
|
|
272
|
+
.map((x) => x.text)
|
|
273
|
+
.join("");
|
|
274
|
+
if (!text.trim())
|
|
275
|
+
throw new Error("Provider response cut off by max output tokens before any usable content; raise limits.maxOutputTokens (/settings → Agent max output tokens)");
|
|
276
|
+
if (calls.some((c) => !c.id || !c.name))
|
|
277
|
+
throw new Error("Incomplete tool call");
|
|
278
|
+
yield {
|
|
279
|
+
type: "completed",
|
|
280
|
+
message: { role: "assistant", text, calls, providerData: r.output, truncated: true },
|
|
281
|
+
usage: r.usage
|
|
282
|
+
? {
|
|
283
|
+
input: r.usage.input_tokens,
|
|
284
|
+
output: r.usage.output_tokens,
|
|
285
|
+
...(typeof r.usage.input_tokens_details?.cached_tokens === "number"
|
|
286
|
+
? { cachedInput: r.usage.input_tokens_details.cached_tokens }
|
|
287
|
+
: {}),
|
|
288
|
+
}
|
|
289
|
+
: undefined,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
if (event.type === "response.completed") {
|
|
293
|
+
complete = true;
|
|
294
|
+
const r = event.response;
|
|
295
|
+
const calls = r.output
|
|
296
|
+
.filter((x) => x.type === "function_call")
|
|
297
|
+
.map((x) => ({ id: x.call_id, name: x.name, arguments: x.arguments }));
|
|
298
|
+
const text = r.output
|
|
299
|
+
.filter((x) => x.type === "message")
|
|
300
|
+
.flatMap((x) => x.content)
|
|
301
|
+
.filter((x) => x.type === "output_text")
|
|
302
|
+
.map((x) => x.text)
|
|
303
|
+
.join("");
|
|
304
|
+
yield {
|
|
305
|
+
type: "completed",
|
|
306
|
+
message: { role: "assistant", text, calls, providerData: r.output },
|
|
307
|
+
usage: r.usage
|
|
308
|
+
? {
|
|
309
|
+
input: r.usage.input_tokens,
|
|
310
|
+
output: r.usage.output_tokens,
|
|
311
|
+
...(typeof r.usage.input_tokens_details?.cached_tokens === "number"
|
|
312
|
+
? { cachedInput: r.usage.input_tokens_details.cached_tokens }
|
|
313
|
+
: {}),
|
|
314
|
+
}
|
|
315
|
+
: undefined,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (!complete)
|
|
320
|
+
throw new Error("Responses stream ended before completion");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
|
|
3
|
+
* reports stay in sync with the published package without a build-time constant to update.
|
|
4
|
+
* The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
|
|
5
|
+
* source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
|
|
6
|
+
* binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadVersion(fromHere: string): string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Fallback used when neither the build-time injection nor the package manifest is readable
|
|
6
|
+
* (e.g. an unpackaged embed). Keep it a development marker, never a publish literal, so it
|
|
7
|
+
* cannot silently desync from the published package.
|
|
8
|
+
*/
|
|
9
|
+
const FALLBACK = "dev";
|
|
10
|
+
/**
|
|
11
|
+
* Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
|
|
12
|
+
* reports stay in sync with the published package without a build-time constant to update.
|
|
13
|
+
* The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
|
|
14
|
+
* source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
|
|
15
|
+
* binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
|
|
16
|
+
*/
|
|
17
|
+
export function loadVersion(fromHere) {
|
|
18
|
+
if (process.env.ALISIO_PACKAGE_VERSION)
|
|
19
|
+
return process.env.ALISIO_PACKAGE_VERSION;
|
|
20
|
+
try {
|
|
21
|
+
const manifest = join(dirname(fileURLToPath(fromHere)), "..", "package.json");
|
|
22
|
+
const parsed = JSON.parse(readFileSync(manifest, "utf8"));
|
|
23
|
+
return typeof parsed.version === "string" && parsed.version ? parsed.version : FALLBACK;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return FALLBACK;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alisio/plugin-deepseek",
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
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.8"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@alisio/sdk": "0.1.0-alpha.8"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.com/"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json"
|
|
38
|
+
}
|
|
39
|
+
}
|