@agentscope-ai/agentscope 0.0.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/dist/agent/index.d.mts +234 -0
- package/dist/agent/index.d.ts +234 -0
- package/dist/agent/index.js +1412 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/index.mjs +1375 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/base-BOx3UzOl.d.mts +41 -0
- package/dist/base-BoIps2RL.d.ts +41 -0
- package/dist/base-C7jwyH4Z.d.mts +52 -0
- package/dist/base-Cwi4bjze.d.ts +127 -0
- package/dist/base-DYlBMCy_.d.mts +127 -0
- package/dist/base-NX-knWOv.d.ts +52 -0
- package/dist/block-VsnHrllL.d.mts +48 -0
- package/dist/block-VsnHrllL.d.ts +48 -0
- package/dist/event/index.d.mts +181 -0
- package/dist/event/index.d.ts +181 -0
- package/dist/event/index.js +58 -0
- package/dist/event/index.js.map +1 -0
- package/dist/event/index.mjs +33 -0
- package/dist/event/index.mjs.map +1 -0
- package/dist/formatter/index.d.mts +187 -0
- package/dist/formatter/index.d.ts +187 -0
- package/dist/formatter/index.js +647 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/index.mjs +616 -0
- package/dist/formatter/index.mjs.map +1 -0
- package/dist/index-BTJDlKvQ.d.mts +195 -0
- package/dist/index-BcatlwXQ.d.ts +195 -0
- package/dist/index-CAxQAkiP.d.mts +21 -0
- package/dist/index-CAxQAkiP.d.ts +21 -0
- package/dist/mcp/index.d.mts +9 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.js +432 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/index.mjs +408 -0
- package/dist/mcp/index.mjs.map +1 -0
- package/dist/message/index.d.mts +10 -0
- package/dist/message/index.d.ts +10 -0
- package/dist/message/index.js +67 -0
- package/dist/message/index.js.map +1 -0
- package/dist/message/index.mjs +37 -0
- package/dist/message/index.mjs.map +1 -0
- package/dist/message-CkN21KaY.d.mts +99 -0
- package/dist/message-CzLeTlua.d.ts +99 -0
- package/dist/model/index.d.mts +377 -0
- package/dist/model/index.d.ts +377 -0
- package/dist/model/index.js +1880 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/index.mjs +1849 -0
- package/dist/model/index.mjs.map +1 -0
- package/dist/storage/index.d.mts +68 -0
- package/dist/storage/index.d.ts +68 -0
- package/dist/storage/index.js +250 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.mjs +212 -0
- package/dist/storage/index.mjs.map +1 -0
- package/dist/tool/index.d.mts +311 -0
- package/dist/tool/index.d.ts +311 -0
- package/dist/tool/index.js +1494 -0
- package/dist/tool/index.js.map +1 -0
- package/dist/tool/index.mjs +1447 -0
- package/dist/tool/index.mjs.map +1 -0
- package/dist/toolkit-CEpulFi0.d.ts +99 -0
- package/dist/toolkit-CGEZSZPa.d.mts +99 -0
- package/jest.config.js +11 -0
- package/package.json +92 -0
- package/src/_utils/common.ts +104 -0
- package/src/_utils/index.ts +1 -0
- package/src/agent/agent-base.ts +0 -0
- package/src/agent/agent.test.ts +1028 -0
- package/src/agent/agent.ts +1032 -0
- package/src/agent/index.ts +2 -0
- package/src/agent/interfaces.ts +23 -0
- package/src/agent/test-compression.ts +72 -0
- package/src/event/index.ts +250 -0
- package/src/formatter/base.ts +133 -0
- package/src/formatter/dashscope-chat-formatter.test.ts +372 -0
- package/src/formatter/dashscope-chat-formatter.ts +163 -0
- package/src/formatter/deepseek-chat-formatter.ts +130 -0
- package/src/formatter/index.ts +5 -0
- package/src/formatter/ollama-chat-formatter.ts +67 -0
- package/src/formatter/openai-chat-formatter.test.ts +263 -0
- package/src/formatter/openai-chat-formatter.ts +301 -0
- package/src/formatter/openai.md +767 -0
- package/src/mcp/base.ts +114 -0
- package/src/mcp/http.test.ts +303 -0
- package/src/mcp/http.ts +224 -0
- package/src/mcp/index.ts +2 -0
- package/src/mcp/stdio.test.ts +91 -0
- package/src/mcp/stdio.ts +119 -0
- package/src/message/block.ts +60 -0
- package/src/message/enums.ts +4 -0
- package/src/message/index.ts +12 -0
- package/src/message/message.test.ts +80 -0
- package/src/message/message.ts +131 -0
- package/src/model/base.ts +226 -0
- package/src/model/dashscope-model.test.ts +335 -0
- package/src/model/dashscope-model.ts +441 -0
- package/src/model/deepseek-model.test.ts +279 -0
- package/src/model/deepseek-model.ts +401 -0
- package/src/model/index.ts +7 -0
- package/src/model/ollama-model.test.ts +307 -0
- package/src/model/ollama-model.ts +356 -0
- package/src/model/openai-model.ts +327 -0
- package/src/model/response.ts +22 -0
- package/src/model/usage.ts +12 -0
- package/src/storage/base.ts +52 -0
- package/src/storage/file-system.test.ts +587 -0
- package/src/storage/file-system.ts +269 -0
- package/src/storage/index.ts +2 -0
- package/src/tool/base.ts +23 -0
- package/src/tool/bash.test.ts +174 -0
- package/src/tool/bash.ts +152 -0
- package/src/tool/edit.test.ts +83 -0
- package/src/tool/edit.ts +95 -0
- package/src/tool/glob.test.ts +63 -0
- package/src/tool/glob.ts +166 -0
- package/src/tool/grep.test.ts +74 -0
- package/src/tool/grep.ts +256 -0
- package/src/tool/index.ts +10 -0
- package/src/tool/read.test.ts +77 -0
- package/src/tool/read.ts +117 -0
- package/src/tool/response.ts +82 -0
- package/src/tool/task.test.ts +299 -0
- package/src/tool/task.ts +399 -0
- package/src/tool/toolkit.test.ts +636 -0
- package/src/tool/toolkit.ts +601 -0
- package/src/tool/write.test.ts +52 -0
- package/src/tool/write.ts +57 -0
- package/src/type/index.ts +52 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.cjs.json +11 -0
- package/tsconfig.esm.json +10 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +20 -0
- package/typedoc.json +52 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { J as JSONSerializableObject } from './index-CAxQAkiP.mjs';
|
|
2
|
+
import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.mjs';
|
|
3
|
+
|
|
4
|
+
/** A chat message exchanged between agents or between an agent and a model. */
|
|
5
|
+
interface Msg {
|
|
6
|
+
/** Unique identifier for the message. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Display name of the message sender. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Conversation role of the sender. */
|
|
11
|
+
role: 'user' | 'assistant' | 'system';
|
|
12
|
+
/** Message body. */
|
|
13
|
+
content: ContentBlock[];
|
|
14
|
+
/** Arbitrary key-value metadata attached to the message. */
|
|
15
|
+
metadata: Record<string, JSONSerializableObject>;
|
|
16
|
+
/** ISO-8601 creation timestamp. */
|
|
17
|
+
timestamp: string;
|
|
18
|
+
/** Usage information for the message, such as token counts. */
|
|
19
|
+
usage?: {
|
|
20
|
+
inputTokens: number;
|
|
21
|
+
outputTokens: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
|
|
26
|
+
*
|
|
27
|
+
* @param root0
|
|
28
|
+
* @param root0.name
|
|
29
|
+
* @param root0.content
|
|
30
|
+
* @param root0.role
|
|
31
|
+
* @param root0.metadata
|
|
32
|
+
* @param root0.id
|
|
33
|
+
* @param root0.timestamp
|
|
34
|
+
* @param root0.usage
|
|
35
|
+
* @returns A fully-populated {@link Msg} object.
|
|
36
|
+
*/
|
|
37
|
+
declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
|
|
38
|
+
/**
|
|
39
|
+
* Extract the plain-text content from a message.
|
|
40
|
+
*
|
|
41
|
+
* When `content` is a string it is returned as-is. When it is an array of
|
|
42
|
+
* content blocks, all {@link TextBlock} texts are joined with `separator`.
|
|
43
|
+
*
|
|
44
|
+
* @param msg - The message to read.
|
|
45
|
+
* @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
|
|
46
|
+
* @returns The concatenated text, or `null` when no text blocks are present.
|
|
47
|
+
*/
|
|
48
|
+
declare function getTextContent(msg: Msg, separator?: string): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Return all content blocks from a message, regardless of type.
|
|
51
|
+
*
|
|
52
|
+
* When `content` is a plain string it is wrapped in a single {@link TextBlock}.
|
|
53
|
+
*
|
|
54
|
+
* @param msg - The message to read.
|
|
55
|
+
* @returns An array of all {@link ContentBlock} objects.
|
|
56
|
+
*/
|
|
57
|
+
declare function getContentBlocks(msg: Msg): ContentBlock[];
|
|
58
|
+
/**
|
|
59
|
+
* Return all {@link TextBlock} objects from a message.
|
|
60
|
+
*
|
|
61
|
+
* @param msg - The message to read.
|
|
62
|
+
* @param blockType - `'text'`
|
|
63
|
+
* @returns An array of {@link TextBlock} objects.
|
|
64
|
+
*/
|
|
65
|
+
declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
|
|
66
|
+
/**
|
|
67
|
+
* Return all {@link ThinkingBlock} objects from a message.
|
|
68
|
+
*
|
|
69
|
+
* @param msg - The message to read.
|
|
70
|
+
* @param blockType - `'thinking'`
|
|
71
|
+
* @returns An array of {@link ThinkingBlock} objects.
|
|
72
|
+
*/
|
|
73
|
+
declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
|
|
74
|
+
/**
|
|
75
|
+
* Return all {@link DataBlock} objects from a message.
|
|
76
|
+
*
|
|
77
|
+
* @param msg - The message to read.
|
|
78
|
+
* @param blockType - `'video'`
|
|
79
|
+
* @returns An array of {@link DataBlock} objects.
|
|
80
|
+
*/
|
|
81
|
+
declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
|
|
82
|
+
/**
|
|
83
|
+
* Return all {@link ToolCallBlock} objects from a message.
|
|
84
|
+
*
|
|
85
|
+
* @param msg - The message to read.
|
|
86
|
+
* @param blockType - `'tool_call'`
|
|
87
|
+
* @returns An array of {@link ToolCallBlock} objects.
|
|
88
|
+
*/
|
|
89
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
|
|
90
|
+
/**
|
|
91
|
+
* Return all {@link ToolResultBlock} objects from a message.
|
|
92
|
+
*
|
|
93
|
+
* @param msg - The message to read.
|
|
94
|
+
* @param blockType - `'tool_result'`
|
|
95
|
+
* @returns An array of {@link ToolResultBlock} objects.
|
|
96
|
+
*/
|
|
97
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
|
|
98
|
+
|
|
99
|
+
export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { J as JSONSerializableObject } from './index-CAxQAkiP.js';
|
|
2
|
+
import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.js';
|
|
3
|
+
|
|
4
|
+
/** A chat message exchanged between agents or between an agent and a model. */
|
|
5
|
+
interface Msg {
|
|
6
|
+
/** Unique identifier for the message. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Display name of the message sender. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Conversation role of the sender. */
|
|
11
|
+
role: 'user' | 'assistant' | 'system';
|
|
12
|
+
/** Message body. */
|
|
13
|
+
content: ContentBlock[];
|
|
14
|
+
/** Arbitrary key-value metadata attached to the message. */
|
|
15
|
+
metadata: Record<string, JSONSerializableObject>;
|
|
16
|
+
/** ISO-8601 creation timestamp. */
|
|
17
|
+
timestamp: string;
|
|
18
|
+
/** Usage information for the message, such as token counts. */
|
|
19
|
+
usage?: {
|
|
20
|
+
inputTokens: number;
|
|
21
|
+
outputTokens: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
|
|
26
|
+
*
|
|
27
|
+
* @param root0
|
|
28
|
+
* @param root0.name
|
|
29
|
+
* @param root0.content
|
|
30
|
+
* @param root0.role
|
|
31
|
+
* @param root0.metadata
|
|
32
|
+
* @param root0.id
|
|
33
|
+
* @param root0.timestamp
|
|
34
|
+
* @param root0.usage
|
|
35
|
+
* @returns A fully-populated {@link Msg} object.
|
|
36
|
+
*/
|
|
37
|
+
declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
|
|
38
|
+
/**
|
|
39
|
+
* Extract the plain-text content from a message.
|
|
40
|
+
*
|
|
41
|
+
* When `content` is a string it is returned as-is. When it is an array of
|
|
42
|
+
* content blocks, all {@link TextBlock} texts are joined with `separator`.
|
|
43
|
+
*
|
|
44
|
+
* @param msg - The message to read.
|
|
45
|
+
* @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
|
|
46
|
+
* @returns The concatenated text, or `null` when no text blocks are present.
|
|
47
|
+
*/
|
|
48
|
+
declare function getTextContent(msg: Msg, separator?: string): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Return all content blocks from a message, regardless of type.
|
|
51
|
+
*
|
|
52
|
+
* When `content` is a plain string it is wrapped in a single {@link TextBlock}.
|
|
53
|
+
*
|
|
54
|
+
* @param msg - The message to read.
|
|
55
|
+
* @returns An array of all {@link ContentBlock} objects.
|
|
56
|
+
*/
|
|
57
|
+
declare function getContentBlocks(msg: Msg): ContentBlock[];
|
|
58
|
+
/**
|
|
59
|
+
* Return all {@link TextBlock} objects from a message.
|
|
60
|
+
*
|
|
61
|
+
* @param msg - The message to read.
|
|
62
|
+
* @param blockType - `'text'`
|
|
63
|
+
* @returns An array of {@link TextBlock} objects.
|
|
64
|
+
*/
|
|
65
|
+
declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
|
|
66
|
+
/**
|
|
67
|
+
* Return all {@link ThinkingBlock} objects from a message.
|
|
68
|
+
*
|
|
69
|
+
* @param msg - The message to read.
|
|
70
|
+
* @param blockType - `'thinking'`
|
|
71
|
+
* @returns An array of {@link ThinkingBlock} objects.
|
|
72
|
+
*/
|
|
73
|
+
declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
|
|
74
|
+
/**
|
|
75
|
+
* Return all {@link DataBlock} objects from a message.
|
|
76
|
+
*
|
|
77
|
+
* @param msg - The message to read.
|
|
78
|
+
* @param blockType - `'video'`
|
|
79
|
+
* @returns An array of {@link DataBlock} objects.
|
|
80
|
+
*/
|
|
81
|
+
declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
|
|
82
|
+
/**
|
|
83
|
+
* Return all {@link ToolCallBlock} objects from a message.
|
|
84
|
+
*
|
|
85
|
+
* @param msg - The message to read.
|
|
86
|
+
* @param blockType - `'tool_call'`
|
|
87
|
+
* @returns An array of {@link ToolCallBlock} objects.
|
|
88
|
+
*/
|
|
89
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
|
|
90
|
+
/**
|
|
91
|
+
* Return all {@link ToolResultBlock} objects from a message.
|
|
92
|
+
*
|
|
93
|
+
* @param msg - The message to read.
|
|
94
|
+
* @param blockType - `'tool_result'`
|
|
95
|
+
* @returns An array of {@link ToolResultBlock} objects.
|
|
96
|
+
*/
|
|
97
|
+
declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
|
|
98
|
+
|
|
99
|
+
export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { C as ChatModelBase, c as ChatModelOptions, d as ChatModelRequestOptions, b as ChatResponse } from '../base-DYlBMCy_.mjs';
|
|
2
|
+
export { a as ChatUsage } from '../base-DYlBMCy_.mjs';
|
|
3
|
+
import { a as ToolChoice, T as ToolSchema } from '../index-CAxQAkiP.mjs';
|
|
4
|
+
import { b as ToolCallBlock, T as TextBlock, a as ThinkingBlock } from '../block-VsnHrllL.mjs';
|
|
5
|
+
import { Ollama, AbortableAsyncIterator, ChatResponse as ChatResponse$1 } from 'ollama';
|
|
6
|
+
import { OpenAI } from 'openai';
|
|
7
|
+
import { ChatCompletionMessageParam, ChatCompletionToolChoiceOption } from 'openai/resources/chat/completions';
|
|
8
|
+
import 'zod';
|
|
9
|
+
import '../base-BOx3UzOl.mjs';
|
|
10
|
+
import '../message-CkN21KaY.mjs';
|
|
11
|
+
|
|
12
|
+
interface DashScopeThinkingConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to enable thinking or not.
|
|
15
|
+
*/
|
|
16
|
+
enableThinking: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum tokens for reasoning (optional).
|
|
19
|
+
*/
|
|
20
|
+
thinkingBudget?: number;
|
|
21
|
+
}
|
|
22
|
+
interface DashScopeChatModelOptions extends ChatModelOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The API key for authenticating with DashScope API.
|
|
25
|
+
*/
|
|
26
|
+
apiKey: string;
|
|
27
|
+
/**
|
|
28
|
+
* Thinking configuration for DashScope models.
|
|
29
|
+
*/
|
|
30
|
+
thinkingConfig?: DashScopeThinkingConfig;
|
|
31
|
+
/**
|
|
32
|
+
* (Deprecated) Use thinkingConfig instead.
|
|
33
|
+
* Whether to enable the "thinking" feature in the model.
|
|
34
|
+
*/
|
|
35
|
+
enableThinking?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the model is multimodal or not, this will decide the default API endpoint.
|
|
38
|
+
*/
|
|
39
|
+
multimodal?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Preset generation parameters to include in each request.
|
|
42
|
+
* These parameters will be merged with the request-specific parameters.
|
|
43
|
+
*/
|
|
44
|
+
presetGenParams?: Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Preset headers that will be included in each request.
|
|
47
|
+
*/
|
|
48
|
+
presetHeaders?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The DashScope API chat model.
|
|
52
|
+
*/
|
|
53
|
+
declare class DashScopeChatModel extends ChatModelBase {
|
|
54
|
+
apiURL: string;
|
|
55
|
+
protected apiKey: string;
|
|
56
|
+
protected presetGenParams: Record<string, unknown> | undefined;
|
|
57
|
+
protected presetHeaders: Record<string, unknown> | undefined;
|
|
58
|
+
protected thinkingConfig?: DashScopeThinkingConfig;
|
|
59
|
+
/**
|
|
60
|
+
* Initializes a new instance of the DashScopeChatModel class.
|
|
61
|
+
*
|
|
62
|
+
* @param options - The DashScope chat model options.
|
|
63
|
+
* @param options.modelName - The name of the model to use.
|
|
64
|
+
* @param options.apiKey - The API key for authentication.
|
|
65
|
+
* @param options.stream - Whether to use streaming responses. Default is true.
|
|
66
|
+
* @param options.thinkingConfig - The thinking configuration for DashScope models, including whether to enable thinking and the thinking budget.
|
|
67
|
+
* @param options.maxRetries - The maximum number of retries for failed requests. Default is 3.
|
|
68
|
+
* @param options.fallbackModelName - The fallback model name to use if the primary model fails.
|
|
69
|
+
* @param options.presetGenParams - Preset generation parameters to include in each request.
|
|
70
|
+
* @param options.presetHeaders - Preset headers that will be included in each request.
|
|
71
|
+
* @param options.multimodal - Whether the model is multimodal or not, this will decide the default API endpoint. If not provided, it will be inferred from the model name.
|
|
72
|
+
* @param options.formatter - An optional custom formatter. If not provided, a default DashScopeChatFormatter will be used.
|
|
73
|
+
*/
|
|
74
|
+
constructor({ modelName, apiKey, stream, thinkingConfig, maxRetries, fallbackModelName, presetGenParams, presetHeaders, multimodal, formatter, }: DashScopeChatModelOptions);
|
|
75
|
+
/**
|
|
76
|
+
* Calls the DashScope API with the given parameters.
|
|
77
|
+
*
|
|
78
|
+
* @param modelName - The name of the model to use.
|
|
79
|
+
* @param options - The chat model options.
|
|
80
|
+
* @returns A promise that resolves to either a ChatResponse or an AsyncGenerator of ChatResponses.
|
|
81
|
+
*/
|
|
82
|
+
_callAPI(modelName: string, options: ChatModelRequestOptions<Record<string, unknown>>): Promise<ChatResponse | AsyncGenerator<ChatResponse, ChatResponse>>;
|
|
83
|
+
/**
|
|
84
|
+
* The method to format the tool choice parameter.
|
|
85
|
+
*
|
|
86
|
+
* @param toolChoice - The tool choice option.
|
|
87
|
+
* @returns The formatted tool choice.
|
|
88
|
+
*/
|
|
89
|
+
_formatToolChoice(toolChoice?: ToolChoice): 'auto' | 'none' | Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Parses a streamed response from DashScope API specifically for chat responses.
|
|
92
|
+
* An async generator that yields delta ChatResponse objects as they are received.
|
|
93
|
+
*
|
|
94
|
+
* @param response - The fetch response object.
|
|
95
|
+
* @param startTime - The start time of the request for usage calculation.
|
|
96
|
+
* @returns An async generator yielding delta ChatResponse objects, and returns the complete ChatResponse.
|
|
97
|
+
*/
|
|
98
|
+
_parseDashScopeStreamedResponse(response: Response, startTime: number): AsyncGenerator<ChatResponse, ChatResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Convert data into blocks
|
|
101
|
+
*
|
|
102
|
+
* @param text - The text response from the llm API
|
|
103
|
+
* @param thinking - The thinking response
|
|
104
|
+
* @param toolCalls - The tool calls
|
|
105
|
+
* @returns An array of blocks
|
|
106
|
+
*/
|
|
107
|
+
_dataToBlocks(text: string, thinking: string, toolCalls: Map<string, ToolCallBlock>): (TextBlock | ThinkingBlock | ToolCallBlock)[];
|
|
108
|
+
/**
|
|
109
|
+
* Format the tool schemas to the expected API format.
|
|
110
|
+
* @param tools
|
|
111
|
+
* @returns The formatted tool schemas.
|
|
112
|
+
*/
|
|
113
|
+
_formatToolSchemas(tools: ToolSchema[] | undefined): ToolSchema[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface DeepSeekThinkingConfig {
|
|
117
|
+
/**
|
|
118
|
+
* Whether to enable thinking or not.
|
|
119
|
+
*/
|
|
120
|
+
enableThinking: boolean;
|
|
121
|
+
}
|
|
122
|
+
interface DeepSeekChatModelOptions extends ChatModelOptions {
|
|
123
|
+
/**
|
|
124
|
+
* The API key for authenticating with DeepSeek API.
|
|
125
|
+
*/
|
|
126
|
+
apiKey: string;
|
|
127
|
+
/**
|
|
128
|
+
* Thinking configuration for DeepSeek models.
|
|
129
|
+
*/
|
|
130
|
+
thinkingConfig?: DeepSeekThinkingConfig;
|
|
131
|
+
/**
|
|
132
|
+
* Preset generation parameters to include in each request.
|
|
133
|
+
* These parameters will be merged with the request-specific parameters.
|
|
134
|
+
*/
|
|
135
|
+
presetGenParams?: Record<string, unknown>;
|
|
136
|
+
/**
|
|
137
|
+
* Preset headers that will be included in each request.
|
|
138
|
+
*/
|
|
139
|
+
presetHeaders?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The DeepSeek API chat model.
|
|
143
|
+
*/
|
|
144
|
+
declare class DeepSeekChatModel extends ChatModelBase {
|
|
145
|
+
apiURL: string;
|
|
146
|
+
protected apiKey: string;
|
|
147
|
+
protected presetGenParams: Record<string, unknown> | undefined;
|
|
148
|
+
protected presetHeaders: Record<string, unknown> | undefined;
|
|
149
|
+
protected thinkingConfig: DeepSeekThinkingConfig;
|
|
150
|
+
/**
|
|
151
|
+
* Initializes a new instance of the DeepSeekChatModel class.
|
|
152
|
+
*
|
|
153
|
+
* @param options - The DeepSeek chat model options.
|
|
154
|
+
* @param options.modelName - The name of the model to use.
|
|
155
|
+
* @param options.apiKey - The API key for authentication.
|
|
156
|
+
* @param options.stream - Whether to use streaming responses. Default is true.
|
|
157
|
+
* @param options.thinkingConfig - Thinking configuration.
|
|
158
|
+
* @param options.maxRetries - The maximum number of retries for failed requests. Default is 0.
|
|
159
|
+
* @param options.fallbackModelName - The fallback model name to use if the primary model fails.
|
|
160
|
+
* @param options.presetGenParams - Preset generation parameters to include in each request.
|
|
161
|
+
* @param options.presetHeaders - Preset headers that will be included in each request.
|
|
162
|
+
* @param options.formatter
|
|
163
|
+
*/
|
|
164
|
+
constructor({ modelName, apiKey, stream, thinkingConfig, maxRetries, fallbackModelName, presetGenParams, presetHeaders, formatter, }: DeepSeekChatModelOptions);
|
|
165
|
+
/**
|
|
166
|
+
* Calls the DeepSeek API with the given parameters.
|
|
167
|
+
*
|
|
168
|
+
* @param modelName - The name of the model to use.
|
|
169
|
+
* @param options - The chat model options.
|
|
170
|
+
* @returns A promise that resolves to either a ChatResponse or an AsyncGenerator of ChatResponses.
|
|
171
|
+
*/
|
|
172
|
+
_callAPI(modelName: string, options: ChatModelRequestOptions<Record<string, unknown>>): Promise<ChatResponse | AsyncGenerator<ChatResponse, ChatResponse>>;
|
|
173
|
+
/**
|
|
174
|
+
* The method to format the tool choice parameter.
|
|
175
|
+
*
|
|
176
|
+
* @param toolChoice - The tool choice option.
|
|
177
|
+
* @returns The formatted tool choice.
|
|
178
|
+
*/
|
|
179
|
+
_formatToolChoice(toolChoice?: ToolChoice): 'auto' | 'none' | 'required' | Record<string, unknown>;
|
|
180
|
+
/**
|
|
181
|
+
* Parses a streamed response from DeepSeek API specifically for chat responses.
|
|
182
|
+
* An async generator that yields delta ChatResponse objects as they are received.
|
|
183
|
+
*
|
|
184
|
+
* @param response - The fetch response object.
|
|
185
|
+
* @param startTime - The start time of the request for usage calculation.
|
|
186
|
+
* @returns An async generator yielding delta ChatResponse objects, and returns the complete ChatResponse.
|
|
187
|
+
*/
|
|
188
|
+
_parseDeepSeekStreamedResponse(response: Response, startTime: number): AsyncGenerator<ChatResponse, ChatResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Convert data into blocks
|
|
191
|
+
*
|
|
192
|
+
* @param text - The text response from the llm API
|
|
193
|
+
* @param thinking - The thinking response
|
|
194
|
+
* @param toolCalls - The tool calls
|
|
195
|
+
* @returns An array of blocks
|
|
196
|
+
*/
|
|
197
|
+
_accDataToBlocks(text: string, thinking: string, toolCalls: Map<string, ToolCallBlock>): (TextBlock | ThinkingBlock | ToolCallBlock)[];
|
|
198
|
+
/**
|
|
199
|
+
* Format the tool schemas to the expected API format for DeepSeek API.
|
|
200
|
+
* @param tools
|
|
201
|
+
* @returns The formatted tool schemas.
|
|
202
|
+
*/
|
|
203
|
+
_formatToolSchemas(tools: ToolSchema[] | undefined): ToolSchema[];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface OllamaThinkingConfig {
|
|
207
|
+
/**
|
|
208
|
+
* Whether to enable thinking or not.
|
|
209
|
+
*/
|
|
210
|
+
enableThinking: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Thinking level for Ollama models (high, medium, low).
|
|
213
|
+
* Only applicable when enableThinking is true.
|
|
214
|
+
*/
|
|
215
|
+
thinkingLevel?: 'high' | 'medium' | 'low';
|
|
216
|
+
}
|
|
217
|
+
interface OllamaChatModelOptions extends ChatModelOptions {
|
|
218
|
+
/**
|
|
219
|
+
* Additional parameters to pass to the Ollama API (e.g., temperature).
|
|
220
|
+
*/
|
|
221
|
+
options?: Record<string, unknown>;
|
|
222
|
+
/**
|
|
223
|
+
* Duration to keep the model loaded in memory (e.g., "5m", "1h").
|
|
224
|
+
*/
|
|
225
|
+
keepAlive?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Thinking configuration for Ollama models.
|
|
228
|
+
*/
|
|
229
|
+
thinkingConfig?: OllamaThinkingConfig;
|
|
230
|
+
/**
|
|
231
|
+
* The host address of the Ollama server.
|
|
232
|
+
*/
|
|
233
|
+
host?: string;
|
|
234
|
+
/**
|
|
235
|
+
* Extra keyword arguments to initialize the Ollama client.
|
|
236
|
+
*/
|
|
237
|
+
clientKwargs?: Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* Extra keyword arguments used in Ollama API generation.
|
|
240
|
+
*/
|
|
241
|
+
generateKwargs?: Record<string, unknown>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The Ollama chat model class in AgentScope.
|
|
245
|
+
*/
|
|
246
|
+
declare class OllamaChatModel extends ChatModelBase {
|
|
247
|
+
protected client: Ollama;
|
|
248
|
+
protected options?: Record<string, unknown>;
|
|
249
|
+
protected keepAlive: string;
|
|
250
|
+
protected thinkingConfig: OllamaThinkingConfig;
|
|
251
|
+
protected generateKwargs: Record<string, unknown>;
|
|
252
|
+
/**
|
|
253
|
+
* Initializes a new instance of the OllamaChatModel class.
|
|
254
|
+
* @param root0
|
|
255
|
+
* @param root0.modelName
|
|
256
|
+
* @param root0.stream
|
|
257
|
+
* @param root0.options
|
|
258
|
+
* @param root0.keepAlive
|
|
259
|
+
* @param root0.thinkingConfig
|
|
260
|
+
* @param root0.host
|
|
261
|
+
* @param root0.maxRetries
|
|
262
|
+
* @param root0.fallbackModelName
|
|
263
|
+
* @param root0.clientKwargs
|
|
264
|
+
* @param root0.generateKwargs
|
|
265
|
+
* @param root0.formatter
|
|
266
|
+
*/
|
|
267
|
+
constructor({ modelName, stream, options, keepAlive, thinkingConfig, host, maxRetries, fallbackModelName, clientKwargs, generateKwargs, formatter, }: OllamaChatModelOptions);
|
|
268
|
+
/**
|
|
269
|
+
* Calls the Ollama API with the given parameters.
|
|
270
|
+
* @param modelName
|
|
271
|
+
* @param options
|
|
272
|
+
* @returns A promise that resolves to either a ChatResponse or an AsyncGenerator of ChatResponses.
|
|
273
|
+
*/
|
|
274
|
+
_callAPI(modelName: string, options: ChatModelRequestOptions<Record<string, unknown>>): Promise<ChatResponse | AsyncGenerator<ChatResponse, ChatResponse>>;
|
|
275
|
+
/**
|
|
276
|
+
* Parse Ollama streaming response.
|
|
277
|
+
* @param stream
|
|
278
|
+
* @param startTime
|
|
279
|
+
* @returns An async generator that yields delta ChatResponse objects and returns the complete ChatResponse.
|
|
280
|
+
*/
|
|
281
|
+
_parseOllamaStreamResponse(stream: AbortableAsyncIterator<ChatResponse$1>, startTime: number): AsyncGenerator<ChatResponse, ChatResponse>;
|
|
282
|
+
/**
|
|
283
|
+
* Parse Ollama non-streaming response.
|
|
284
|
+
* @param response
|
|
285
|
+
* @param startTime
|
|
286
|
+
* @returns A ChatResponse object containing the content blocks and usage.
|
|
287
|
+
*/
|
|
288
|
+
_parseOllamaResponse(response: ChatResponse$1, startTime: number): ChatResponse;
|
|
289
|
+
/**
|
|
290
|
+
* Build content blocks from accumulated data.
|
|
291
|
+
* @param text
|
|
292
|
+
* @param thinking
|
|
293
|
+
* @param toolCalls
|
|
294
|
+
* @returns An array of content blocks.
|
|
295
|
+
*/
|
|
296
|
+
_buildContentBlocks(text: string, thinking: string, toolCalls: Map<string, ToolCallBlock>): Array<TextBlock | ThinkingBlock | ToolCallBlock>;
|
|
297
|
+
/**
|
|
298
|
+
* Format tool choice parameter (not supported by Ollama).
|
|
299
|
+
* @param _toolChoice
|
|
300
|
+
* @returns undefined as Ollama does not support tool choice.
|
|
301
|
+
*/
|
|
302
|
+
_formatToolChoice(_toolChoice?: ToolChoice): unknown;
|
|
303
|
+
/**
|
|
304
|
+
* Format tool schemas for Ollama API (no special formatting needed).
|
|
305
|
+
* @param tools
|
|
306
|
+
* @returns The same array of tool schemas, or an empty array if undefined.
|
|
307
|
+
*/
|
|
308
|
+
_formatToolSchemas(tools: ToolSchema[] | undefined): ToolSchema[];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
interface OpenAIChatModelOptions extends ChatModelOptions {
|
|
312
|
+
apiKey: string;
|
|
313
|
+
presetGenParams?: Record<string, unknown>;
|
|
314
|
+
baseURL?: string;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The OpenAI API chat model.
|
|
318
|
+
*/
|
|
319
|
+
declare class OpenAIChatModel extends ChatModelBase {
|
|
320
|
+
protected client: OpenAI;
|
|
321
|
+
protected presetGenParams: Record<string, unknown> | undefined;
|
|
322
|
+
/**
|
|
323
|
+
* Initializes a new instance of the OpenAIChatModel class.
|
|
324
|
+
* @param options
|
|
325
|
+
* @param options.modelName
|
|
326
|
+
* @param options.apiKey
|
|
327
|
+
* @param options.stream
|
|
328
|
+
* @param options.maxRetries
|
|
329
|
+
* @param options.fallbackModelName
|
|
330
|
+
* @param options.presetGenParams
|
|
331
|
+
* @param options.baseURL
|
|
332
|
+
* @param options.formatter
|
|
333
|
+
*/
|
|
334
|
+
constructor({ modelName, apiKey, stream, maxRetries, fallbackModelName, presetGenParams, baseURL, formatter, }: OpenAIChatModelOptions);
|
|
335
|
+
/**
|
|
336
|
+
* Calls the OpenAI API with the given parameters.
|
|
337
|
+
*
|
|
338
|
+
* @param modelName - The name of the model to use.
|
|
339
|
+
* @param options - The chat model options.
|
|
340
|
+
* @returns A promise that resolves to either a ChatResponse or an AsyncGenerator of ChatResponses.
|
|
341
|
+
*/
|
|
342
|
+
_callAPI(modelName: string, options: ChatModelRequestOptions<ChatCompletionMessageParam>): Promise<ChatResponse | AsyncGenerator<ChatResponse, ChatResponse>>;
|
|
343
|
+
/**
|
|
344
|
+
* Formats the tool choice for the API request.
|
|
345
|
+
*
|
|
346
|
+
* TODO: supports grouped tool choices.
|
|
347
|
+
*
|
|
348
|
+
* @param toolChoice - The tool choice option.
|
|
349
|
+
* @returns The formatted tool choice.
|
|
350
|
+
*/
|
|
351
|
+
_formatToolChoice(toolChoice?: ToolChoice): ChatCompletionToolChoiceOption;
|
|
352
|
+
/**
|
|
353
|
+
* Parses a streamed response from OpenAI API.
|
|
354
|
+
* An async generator that yields delta ChatResponse objects as they are received.
|
|
355
|
+
*
|
|
356
|
+
* @param stream - The OpenAI stream object.
|
|
357
|
+
* @param startTime - The start time of the request for usage calculation.
|
|
358
|
+
* @returns An async generator yielding delta ChatResponse objects, and returns the complete ChatResponse.
|
|
359
|
+
*/
|
|
360
|
+
_parseOpenAIStreamedResponse(stream: AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>, startTime: number): AsyncGenerator<ChatResponse, ChatResponse>;
|
|
361
|
+
/**
|
|
362
|
+
* Convert data into blocks
|
|
363
|
+
*
|
|
364
|
+
* @param text - The text response from the llm API
|
|
365
|
+
* @param toolCalls - The tool calls
|
|
366
|
+
* @returns An array of blocks
|
|
367
|
+
*/
|
|
368
|
+
_accDataToBlocks(text: string, toolCalls: Map<string, ToolCallBlock>): (TextBlock | ToolCallBlock)[];
|
|
369
|
+
/**
|
|
370
|
+
* Format the tool schemas to the expected API format.
|
|
371
|
+
* @param tools
|
|
372
|
+
* @returns The formatted tool schemas.
|
|
373
|
+
*/
|
|
374
|
+
_formatToolSchemas(tools: ToolSchema[] | undefined): ToolSchema[];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { ChatModelBase, ChatResponse, DashScopeChatModel, DeepSeekChatModel, OllamaChatModel, OpenAIChatModel };
|