@astack-tech/integrations 0.1.1-beta.6 → 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.
@@ -1,195 +1,196 @@
1
- import { Component } from '@astack-tech/core';
1
+ import { Component, Port } from '@astack-tech/core';
2
2
 
3
3
  /**
4
- * Deepseek 模型提供者配置
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
- * 默认为 'deepseek-chat'
14
- */
15
- model?: string;
16
- /**
17
- * 自定义 API 基础 URL
18
- * 默认为 Deepseek 官方 API 地址
19
- */
20
- baseURL?: string;
21
- /**
22
- * 温度参数,控制输出的随机性
23
- */
24
- temperature?: number;
25
- /**
26
- * 最大生成的 token 数
27
- */
28
- maxTokens?: number;
29
- /**
30
- * 采样概率
31
- */
32
- topP?: number;
33
- /**
34
- * 系统提示消息
35
- */
36
- systemPrompt?: string;
37
- /**
38
- * 工具实例数组,直接传递工具实例
39
- * 每个工具应具有 name、description 和 parameters 属性
40
- */
41
- rawTools?: Array<{
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
- * 工具调用 ID
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
- * Token 使用统计
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
- * 提示缓存命中的 token 数量(可选)
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
- role: MessageRole;
111
- /**
112
- * 消息内容
113
- */
114
- content?: string;
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
- * Deepseek 组件
130
- *
131
- * 使用 OpenAI 兼容接口调用 Deepseek 模型
132
- *
133
- * 输入:
134
- * - prompt: 文本提示
135
- * - messages: 对话消息数组
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
- * - completion: 生成的文本完成
139
- * - message: 生成的响应消息
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
- * @param prompt 提示文本
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
- * @param messages 对话消息数组
159
- * @param options 可选的调用选项,包含临时工具列表
160
- * @returns 生成的流式响应消息异步生成器
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
- * @param messages 对话消息数组
168
- * @param options 可选的调用选项,包含临时工具列表
169
- * @returns 生成的响应消息
164
+ * Runs the model outside a pipeline.
165
+ *
166
+ * @param input A prompt string or a list of messages.
170
167
  */
171
- chatCompletion(messages: Message[], options?: {
172
- temporaryTools?: unknown[];
173
- }): Promise<Message>;
168
+ run(input: string | Message[]): Promise<string | AssistantMessage>;
174
169
  /**
175
- * 在独立模式下运行组件
176
- * @param input 输入参数,可以是提示文本或对话消息数组
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
- run(input: string | Message[]): Promise<string | Message>;
173
+ _transform($i: Port, $o: Port): void;
174
+ private baseRequest;
175
+ private toolsParam;
176
+ private systemMessages;
180
177
  /**
181
- * 在流水线中运行组件
182
- * @param $i 输入端口
183
- * @param $o 输出端口
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
- _transform($i: any, $o: any): void;
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, type index_DeepseekConfig as DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall };
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, type DeepseekConfig, type Message as DeepseekMessage, type MessageRole as DeepseekMessageRole, type ToolCall as DeepseekToolCall, index as i };
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 };