@astack-tech/integrations 0.1.1-beta.5 → 0.2.0-beta.7
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/CHANGELOG.md +39 -0
- package/README.md +75 -1
- package/dist/index.cjs +180 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +180 -240
- package/dist/index.js.map +1 -1
- package/dist/model-provider/index.cjs +180 -240
- package/dist/model-provider/index.cjs.map +1 -1
- package/dist/model-provider/index.d.cts +146 -145
- package/dist/model-provider/index.d.ts +146 -145
- package/dist/model-provider/index.js +180 -240
- package/dist/model-provider/index.js.map +1 -1
- package/package.json +46 -27
- package/src/index.ts +1 -5
- package/src/model-provider/deepseek/index.ts +326 -476
- package/src/model-provider/index.ts +9 -2
|
@@ -1,195 +1,196 @@
|
|
|
1
|
-
import { Component } from '@astack-tech/core';
|
|
1
|
+
import { Component, Port } from '@astack-tech/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Options for the DeepSeek model provider.
|
|
5
5
|
*/
|
|
6
6
|
interface DeepseekConfig {
|
|
7
|
-
/**
|
|
8
|
-
* API 密钥
|
|
9
|
-
*/
|
|
7
|
+
/** DeepSeek API key. */
|
|
10
8
|
apiKey: string;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
name: string;
|
|
43
|
-
description: string;
|
|
44
|
-
parameters?: Record<string, unknown>;
|
|
45
|
-
}>;
|
|
46
|
-
/**
|
|
47
|
-
* API 格式的工具定义数组,与 rawTools 二选一
|
|
48
|
-
* 使用 OpenAI 兼容的工具定义格式
|
|
49
|
-
*/
|
|
50
|
-
tools?: unknown[];
|
|
51
|
-
/**
|
|
52
|
-
* dangerouslyAllowBrowser
|
|
53
|
-
* 是否允许在浏览器等非安全环境内运行
|
|
54
|
-
*/
|
|
55
|
-
dangerouslyAllowBrowser?: boolean;
|
|
9
|
+
/** Model name. Defaults to `deepseek-chat`. */
|
|
10
|
+
model?: string | undefined;
|
|
11
|
+
/** API base URL. Defaults to `https://api.deepseek.com/v1`. */
|
|
12
|
+
baseURL?: string | undefined;
|
|
13
|
+
/** Sampling temperature. Defaults to `0.7`. */
|
|
14
|
+
temperature?: number | undefined;
|
|
15
|
+
/** Maximum number of generated tokens. */
|
|
16
|
+
maxTokens?: number | undefined;
|
|
17
|
+
/** Nucleus sampling probability. */
|
|
18
|
+
topP?: number | undefined;
|
|
19
|
+
/** System prompt added before every request. */
|
|
20
|
+
systemPrompt?: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Tools given as `{ name, description, parameters }` objects.
|
|
23
|
+
* When this list is not empty, it takes precedence over `tools`.
|
|
24
|
+
*/
|
|
25
|
+
rawTools?: RawTool[] | undefined;
|
|
26
|
+
/** Tools in the OpenAI-compatible `{ type: 'function', function }` format. */
|
|
27
|
+
tools?: unknown[] | undefined;
|
|
28
|
+
/** Allows the OpenAI client to run in a browser. Defaults to `false`. */
|
|
29
|
+
dangerouslyAllowBrowser?: boolean | undefined;
|
|
30
|
+
/** Logs API errors to the console. Defaults to `false`. */
|
|
31
|
+
verbose?: boolean | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Tool description accepted by `rawTools` and `temporaryTools`.
|
|
35
|
+
*/
|
|
36
|
+
interface RawTool {
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
parameters?: Record<string, unknown> | undefined;
|
|
56
40
|
}
|
|
57
41
|
/**
|
|
58
|
-
*
|
|
42
|
+
* Role of a chat message.
|
|
59
43
|
*/
|
|
60
44
|
type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
61
45
|
/**
|
|
62
|
-
*
|
|
46
|
+
* Tool call in the internal format.
|
|
63
47
|
*/
|
|
64
48
|
interface ToolCall {
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
id?: string;
|
|
69
|
-
/**
|
|
70
|
-
* 工具名称
|
|
71
|
-
*/
|
|
49
|
+
/** Identifier assigned by the API. */
|
|
50
|
+
id?: string | undefined;
|
|
51
|
+
/** Name of the tool. */
|
|
72
52
|
tool_name: string;
|
|
73
|
-
/**
|
|
74
|
-
* 工具调用参数
|
|
75
|
-
*/
|
|
53
|
+
/** Parsed arguments. */
|
|
76
54
|
arguments: Record<string, unknown>;
|
|
77
55
|
}
|
|
78
56
|
/**
|
|
79
|
-
*
|
|
57
|
+
* Tool call returned by `chatCompletion`. It carries both the OpenAI shape
|
|
58
|
+
* (`type`, `function`) and the internal shape (`tool_name`, `arguments`).
|
|
59
|
+
*/
|
|
60
|
+
interface ResponseToolCall {
|
|
61
|
+
id: string;
|
|
62
|
+
type: 'function';
|
|
63
|
+
function: {
|
|
64
|
+
name: string;
|
|
65
|
+
arguments: string;
|
|
66
|
+
};
|
|
67
|
+
tool_name: string;
|
|
68
|
+
arguments: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Partial tool call emitted while streaming. `arguments` holds the raw JSON fragment.
|
|
72
|
+
*/
|
|
73
|
+
interface StreamToolCall {
|
|
74
|
+
id: string;
|
|
75
|
+
type: 'function';
|
|
76
|
+
function: {
|
|
77
|
+
name: string;
|
|
78
|
+
arguments: string;
|
|
79
|
+
};
|
|
80
|
+
tool_name: string;
|
|
81
|
+
arguments: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Token usage reported by the API.
|
|
80
85
|
*/
|
|
81
86
|
interface TokenUsage {
|
|
82
|
-
/**
|
|
83
|
-
* 完成部分的 token 数量
|
|
84
|
-
*/
|
|
85
87
|
completion_tokens: number;
|
|
86
|
-
/**
|
|
87
|
-
* 提示部分的 token 数量
|
|
88
|
-
*/
|
|
89
88
|
prompt_tokens: number;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
prompt_cache_hit_tokens?: number;
|
|
94
|
-
/**
|
|
95
|
-
* 提示缓存未命中的 token 数量(可选)
|
|
96
|
-
*/
|
|
97
|
-
prompt_cache_miss_tokens?: number;
|
|
98
|
-
/**
|
|
99
|
-
* 总 token 数量
|
|
100
|
-
*/
|
|
89
|
+
prompt_cache_hit_tokens?: number | undefined;
|
|
90
|
+
prompt_cache_miss_tokens?: number | undefined;
|
|
101
91
|
total_tokens: number;
|
|
102
92
|
}
|
|
103
93
|
/**
|
|
104
|
-
*
|
|
94
|
+
* Chat message accepted as input. It matches the agent message contract in
|
|
95
|
+
* `@astack-tech/components`, so agent histories can be passed directly.
|
|
105
96
|
*/
|
|
106
97
|
interface Message {
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 工具调用
|
|
117
|
-
*/
|
|
118
|
-
tool_calls?: ToolCall[];
|
|
119
|
-
/**
|
|
120
|
-
* 工具调用 ID,用于工具响应消息
|
|
121
|
-
*/
|
|
122
|
-
tool_call_id?: string;
|
|
123
|
-
/**
|
|
124
|
-
* Token 使用统计(可选)
|
|
125
|
-
*/
|
|
126
|
-
usage?: TokenUsage;
|
|
98
|
+
/** One of `system`, `user`, `assistant` or `tool` (see `MessageRole`). */
|
|
99
|
+
role: string;
|
|
100
|
+
content?: string | undefined;
|
|
101
|
+
/** Accepted for compatibility. Assistant tool calls are not forwarded to the API. */
|
|
102
|
+
tool_calls?: readonly unknown[] | undefined;
|
|
103
|
+
/** Identifier of the call that a `tool` message answers. */
|
|
104
|
+
tool_call_id?: string | undefined;
|
|
105
|
+
usage?: TokenUsage | undefined;
|
|
127
106
|
}
|
|
128
107
|
/**
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
108
|
+
* Assistant message returned by `chatCompletion`.
|
|
109
|
+
*/
|
|
110
|
+
interface AssistantMessage {
|
|
111
|
+
role: 'assistant';
|
|
112
|
+
content: string;
|
|
113
|
+
tool_calls?: ResponseToolCall[] | undefined;
|
|
114
|
+
usage?: TokenUsage | undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Chunk yielded by `streamChatCompletion`.
|
|
118
|
+
*/
|
|
119
|
+
interface StreamChunk {
|
|
120
|
+
role: 'assistant';
|
|
121
|
+
content: string;
|
|
122
|
+
tool_calls?: StreamToolCall[] | undefined;
|
|
123
|
+
usage?: TokenUsage | undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Per-call options.
|
|
127
|
+
*/
|
|
128
|
+
interface ChatCompletionOptions {
|
|
129
|
+
/** Tools for this call only. They replace the configured tools. */
|
|
130
|
+
temporaryTools?: unknown[] | undefined;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* DeepSeek model provider. It calls the DeepSeek API through the OpenAI-compatible client.
|
|
136
134
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
135
|
+
* Ports:
|
|
136
|
+
* - `prompt` (in): a text prompt. The answer is sent on `completion`.
|
|
137
|
+
* - `messages` (in): a list of chat messages. The reply is sent on `message`.
|
|
140
138
|
*/
|
|
141
139
|
declare class Deepseek extends Component {
|
|
142
|
-
private client;
|
|
143
|
-
private model;
|
|
144
|
-
private temperature;
|
|
145
|
-
private maxTokens
|
|
146
|
-
private topP
|
|
147
|
-
private systemPrompt
|
|
148
|
-
private tools
|
|
140
|
+
private readonly client;
|
|
141
|
+
private readonly model;
|
|
142
|
+
private readonly temperature;
|
|
143
|
+
private readonly maxTokens;
|
|
144
|
+
private readonly topP;
|
|
145
|
+
private readonly systemPrompt;
|
|
146
|
+
private readonly tools;
|
|
147
|
+
private readonly verbose;
|
|
149
148
|
constructor(config: DeepseekConfig);
|
|
150
149
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @returns
|
|
150
|
+
* Generates a completion for a single prompt.
|
|
151
|
+
*
|
|
152
|
+
* @returns The text answer, or the JSON-encoded assistant message when it contains tool calls.
|
|
154
153
|
*/
|
|
155
154
|
generateCompletion(prompt: string): Promise<string>;
|
|
156
155
|
/**
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
* Sends a conversation and returns the assistant reply.
|
|
157
|
+
*/
|
|
158
|
+
chatCompletion(messages: Message[], options?: ChatCompletionOptions): Promise<AssistantMessage>;
|
|
159
|
+
/**
|
|
160
|
+
* Streams the assistant reply. Each chunk holds a text delta, tool-call deltas, or usage.
|
|
161
161
|
*/
|
|
162
|
-
streamChatCompletion(messages: Message[], options?:
|
|
163
|
-
temporaryTools?: unknown[];
|
|
164
|
-
}): AsyncGenerator<Partial<Message>>;
|
|
162
|
+
streamChatCompletion(messages: Message[], options?: ChatCompletionOptions): AsyncGenerator<StreamChunk>;
|
|
165
163
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @param
|
|
169
|
-
* @returns 生成的响应消息
|
|
164
|
+
* Runs the model outside a pipeline.
|
|
165
|
+
*
|
|
166
|
+
* @param input A prompt string or a list of messages.
|
|
170
167
|
*/
|
|
171
|
-
|
|
172
|
-
temporaryTools?: unknown[];
|
|
173
|
-
}): Promise<Message>;
|
|
168
|
+
run(input: string | Message[]): Promise<string | AssistantMessage>;
|
|
174
169
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* @returns 生成的文本或响应消息
|
|
170
|
+
* Connects the `prompt` and `messages` input ports to the model.
|
|
171
|
+
* API errors produce a fallback value so the pipeline keeps flowing.
|
|
178
172
|
*/
|
|
179
|
-
|
|
173
|
+
_transform($i: Port, $o: Port): void;
|
|
174
|
+
private baseRequest;
|
|
175
|
+
private toolsParam;
|
|
176
|
+
private systemMessages;
|
|
180
177
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
178
|
+
* Converts input messages to API messages. Assistant `tool_calls` are not forwarded:
|
|
179
|
+
* agents send tool results back as user messages, and the API rejects assistant tool
|
|
180
|
+
* calls that are not followed by tool messages.
|
|
184
181
|
*/
|
|
185
|
-
|
|
182
|
+
private formatMessages;
|
|
183
|
+
private firstMessage;
|
|
184
|
+
private logError;
|
|
186
185
|
}
|
|
187
186
|
|
|
188
187
|
type index_Deepseek = Deepseek;
|
|
189
188
|
declare const index_Deepseek: typeof Deepseek;
|
|
190
189
|
type index_DeepseekConfig = DeepseekConfig;
|
|
191
190
|
declare namespace index {
|
|
192
|
-
export { index_Deepseek as Deepseek
|
|
191
|
+
export { index_Deepseek as Deepseek };
|
|
192
|
+
export type { AssistantMessage as DeepseekAssistantMessage, ChatCompletionOptions as DeepseekChatCompletionOptions, index_DeepseekConfig as DeepseekConfig, Message as DeepseekMessage, MessageRole as DeepseekMessageRole, RawTool as DeepseekRawTool, ResponseToolCall as DeepseekResponseToolCall, StreamChunk as DeepseekStreamChunk, StreamToolCall as DeepseekStreamToolCall, TokenUsage as DeepseekTokenUsage, ToolCall as DeepseekToolCall };
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
export { Deepseek,
|
|
195
|
+
export { Deepseek, index as i };
|
|
196
|
+
export type { AssistantMessage as DeepseekAssistantMessage, ChatCompletionOptions as DeepseekChatCompletionOptions, DeepseekConfig, Message as DeepseekMessage, MessageRole as DeepseekMessageRole, RawTool as DeepseekRawTool, ResponseToolCall as DeepseekResponseToolCall, StreamChunk as DeepseekStreamChunk, StreamToolCall as DeepseekStreamToolCall, TokenUsage as DeepseekTokenUsage, ToolCall as DeepseekToolCall };
|