@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,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { J as JSONSerializableObject, T as ToolSchema, a as ToolChoice } from './index-CAxQAkiP.js';
|
|
3
|
+
import { T as TextBlock, b as ToolCallBlock, a as ThinkingBlock, D as DataBlock } from './block-VsnHrllL.js';
|
|
4
|
+
import { F as FormatterBase } from './base-BoIps2RL.js';
|
|
5
|
+
import { M as Msg } from './message-CzLeTlua.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The usage structure for chat models.
|
|
9
|
+
*/
|
|
10
|
+
interface ChatUsage {
|
|
11
|
+
type: 'chat_usage';
|
|
12
|
+
inputTokens: number;
|
|
13
|
+
outputTokens: number;
|
|
14
|
+
time: number;
|
|
15
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
type: 'chat';
|
|
20
|
+
id: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
content: Array<TextBlock | ToolCallBlock | ThinkingBlock | DataBlock>;
|
|
23
|
+
usage?: ChatUsage;
|
|
24
|
+
structuredContent?: Record<string, JSONSerializableObject>;
|
|
25
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
26
|
+
}
|
|
27
|
+
interface StructuredResponse {
|
|
28
|
+
type: 'structured';
|
|
29
|
+
id: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
content: Record<string, JSONSerializableObject>;
|
|
32
|
+
usage?: ChatUsage;
|
|
33
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ChatModelOptions {
|
|
37
|
+
modelName: string;
|
|
38
|
+
stream?: boolean;
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
fallbackModelName?: string;
|
|
41
|
+
formatter?: FormatterBase;
|
|
42
|
+
}
|
|
43
|
+
interface ChatModelCallOptions {
|
|
44
|
+
messages: Msg[];
|
|
45
|
+
tools?: ToolSchema[];
|
|
46
|
+
toolChoice?: ToolChoice;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
interface ChatModelCallStructuredOptions {
|
|
50
|
+
messages: Msg[];
|
|
51
|
+
schema: z.ZodObject;
|
|
52
|
+
}
|
|
53
|
+
interface ChatModelRequestOptions<T> {
|
|
54
|
+
messages: T[];
|
|
55
|
+
tools?: ToolSchema[];
|
|
56
|
+
toolChoice?: ToolChoice;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The base class for chat models.
|
|
61
|
+
*/
|
|
62
|
+
declare abstract class ChatModelBase {
|
|
63
|
+
modelName: string;
|
|
64
|
+
stream: boolean;
|
|
65
|
+
maxRetries: number;
|
|
66
|
+
fallbackModelName?: string;
|
|
67
|
+
formatter?: FormatterBase;
|
|
68
|
+
/**
|
|
69
|
+
* Initializes a new instance of the ChatModelBase class.
|
|
70
|
+
*
|
|
71
|
+
* @param options - The chat model options, including model name, streaming option, max retries, fallback
|
|
72
|
+
* model name, and formatter.
|
|
73
|
+
*
|
|
74
|
+
* @param options.modelName
|
|
75
|
+
* @param options.stream
|
|
76
|
+
* @param options.maxRetries
|
|
77
|
+
* @param options.fallbackModelName
|
|
78
|
+
* @param options.formatter
|
|
79
|
+
*/
|
|
80
|
+
protected constructor({ modelName, stream, maxRetries, fallbackModelName, formatter, }: ChatModelOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Calls the chat model with the given messages.
|
|
83
|
+
* This is the main method to interact with the model.
|
|
84
|
+
*
|
|
85
|
+
* @param options - The chat model call options.
|
|
86
|
+
* @returns A promise that resolves to the model's response.
|
|
87
|
+
*/
|
|
88
|
+
call(options: ChatModelCallOptions): Promise<ChatResponse | AsyncGenerator<ChatResponse>>;
|
|
89
|
+
/**
|
|
90
|
+
* Abstract method to call the underlying API with the given parameters.
|
|
91
|
+
*/
|
|
92
|
+
protected abstract _callAPI(modelName: string, options: ChatModelRequestOptions<unknown>): Promise<ChatResponse | AsyncGenerator<ChatResponse>>;
|
|
93
|
+
/**
|
|
94
|
+
* Format the AgentScope tool choice parameter to the expected API format.
|
|
95
|
+
*
|
|
96
|
+
* @param toolChoice - The tool choice option.
|
|
97
|
+
* @returns The formatted tool choice.
|
|
98
|
+
*/
|
|
99
|
+
abstract _formatToolChoice(toolChoice: ToolChoice): unknown;
|
|
100
|
+
/**
|
|
101
|
+
* A heuristic method to count the number of the tokens
|
|
102
|
+
* Note the multimodal content is ignored in the token counting
|
|
103
|
+
* @param options
|
|
104
|
+
* @param options.messages
|
|
105
|
+
* @param options.tools
|
|
106
|
+
* @returns The estimated number of tokens in the input messages and tools.
|
|
107
|
+
*/
|
|
108
|
+
countTokens(options: {
|
|
109
|
+
messages: Msg[];
|
|
110
|
+
tools?: ToolSchema[];
|
|
111
|
+
}): Promise<number>;
|
|
112
|
+
/**
|
|
113
|
+
* Format the tool schemas to the expected API format.
|
|
114
|
+
* @param tools
|
|
115
|
+
* @returns The formatted tool schemas.
|
|
116
|
+
*/
|
|
117
|
+
abstract _formatToolSchemas(tools: ToolSchema[]): unknown[];
|
|
118
|
+
/**
|
|
119
|
+
* A default implementation of the structured call method. For those supporting structured output, the model should
|
|
120
|
+
* override this method.
|
|
121
|
+
* @param options
|
|
122
|
+
* @returns The structured response from the model, which should conform to the provided Zod schema.
|
|
123
|
+
*/
|
|
124
|
+
callStructured(options: ChatModelCallStructuredOptions): Promise<StructuredResponse>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { ChatModelBase as C, type ChatUsage as a, type ChatResponse as b, type ChatModelOptions as c, type ChatModelRequestOptions as d };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { J as JSONSerializableObject, T as ToolSchema, a as ToolChoice } from './index-CAxQAkiP.mjs';
|
|
3
|
+
import { T as TextBlock, b as ToolCallBlock, a as ThinkingBlock, D as DataBlock } from './block-VsnHrllL.mjs';
|
|
4
|
+
import { F as FormatterBase } from './base-BOx3UzOl.mjs';
|
|
5
|
+
import { M as Msg } from './message-CkN21KaY.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The usage structure for chat models.
|
|
9
|
+
*/
|
|
10
|
+
interface ChatUsage {
|
|
11
|
+
type: 'chat_usage';
|
|
12
|
+
inputTokens: number;
|
|
13
|
+
outputTokens: number;
|
|
14
|
+
time: number;
|
|
15
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
type: 'chat';
|
|
20
|
+
id: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
content: Array<TextBlock | ToolCallBlock | ThinkingBlock | DataBlock>;
|
|
23
|
+
usage?: ChatUsage;
|
|
24
|
+
structuredContent?: Record<string, JSONSerializableObject>;
|
|
25
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
26
|
+
}
|
|
27
|
+
interface StructuredResponse {
|
|
28
|
+
type: 'structured';
|
|
29
|
+
id: string;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
content: Record<string, JSONSerializableObject>;
|
|
32
|
+
usage?: ChatUsage;
|
|
33
|
+
metadata?: Record<string, JSONSerializableObject>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ChatModelOptions {
|
|
37
|
+
modelName: string;
|
|
38
|
+
stream?: boolean;
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
fallbackModelName?: string;
|
|
41
|
+
formatter?: FormatterBase;
|
|
42
|
+
}
|
|
43
|
+
interface ChatModelCallOptions {
|
|
44
|
+
messages: Msg[];
|
|
45
|
+
tools?: ToolSchema[];
|
|
46
|
+
toolChoice?: ToolChoice;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
interface ChatModelCallStructuredOptions {
|
|
50
|
+
messages: Msg[];
|
|
51
|
+
schema: z.ZodObject;
|
|
52
|
+
}
|
|
53
|
+
interface ChatModelRequestOptions<T> {
|
|
54
|
+
messages: T[];
|
|
55
|
+
tools?: ToolSchema[];
|
|
56
|
+
toolChoice?: ToolChoice;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The base class for chat models.
|
|
61
|
+
*/
|
|
62
|
+
declare abstract class ChatModelBase {
|
|
63
|
+
modelName: string;
|
|
64
|
+
stream: boolean;
|
|
65
|
+
maxRetries: number;
|
|
66
|
+
fallbackModelName?: string;
|
|
67
|
+
formatter?: FormatterBase;
|
|
68
|
+
/**
|
|
69
|
+
* Initializes a new instance of the ChatModelBase class.
|
|
70
|
+
*
|
|
71
|
+
* @param options - The chat model options, including model name, streaming option, max retries, fallback
|
|
72
|
+
* model name, and formatter.
|
|
73
|
+
*
|
|
74
|
+
* @param options.modelName
|
|
75
|
+
* @param options.stream
|
|
76
|
+
* @param options.maxRetries
|
|
77
|
+
* @param options.fallbackModelName
|
|
78
|
+
* @param options.formatter
|
|
79
|
+
*/
|
|
80
|
+
protected constructor({ modelName, stream, maxRetries, fallbackModelName, formatter, }: ChatModelOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Calls the chat model with the given messages.
|
|
83
|
+
* This is the main method to interact with the model.
|
|
84
|
+
*
|
|
85
|
+
* @param options - The chat model call options.
|
|
86
|
+
* @returns A promise that resolves to the model's response.
|
|
87
|
+
*/
|
|
88
|
+
call(options: ChatModelCallOptions): Promise<ChatResponse | AsyncGenerator<ChatResponse>>;
|
|
89
|
+
/**
|
|
90
|
+
* Abstract method to call the underlying API with the given parameters.
|
|
91
|
+
*/
|
|
92
|
+
protected abstract _callAPI(modelName: string, options: ChatModelRequestOptions<unknown>): Promise<ChatResponse | AsyncGenerator<ChatResponse>>;
|
|
93
|
+
/**
|
|
94
|
+
* Format the AgentScope tool choice parameter to the expected API format.
|
|
95
|
+
*
|
|
96
|
+
* @param toolChoice - The tool choice option.
|
|
97
|
+
* @returns The formatted tool choice.
|
|
98
|
+
*/
|
|
99
|
+
abstract _formatToolChoice(toolChoice: ToolChoice): unknown;
|
|
100
|
+
/**
|
|
101
|
+
* A heuristic method to count the number of the tokens
|
|
102
|
+
* Note the multimodal content is ignored in the token counting
|
|
103
|
+
* @param options
|
|
104
|
+
* @param options.messages
|
|
105
|
+
* @param options.tools
|
|
106
|
+
* @returns The estimated number of tokens in the input messages and tools.
|
|
107
|
+
*/
|
|
108
|
+
countTokens(options: {
|
|
109
|
+
messages: Msg[];
|
|
110
|
+
tools?: ToolSchema[];
|
|
111
|
+
}): Promise<number>;
|
|
112
|
+
/**
|
|
113
|
+
* Format the tool schemas to the expected API format.
|
|
114
|
+
* @param tools
|
|
115
|
+
* @returns The formatted tool schemas.
|
|
116
|
+
*/
|
|
117
|
+
abstract _formatToolSchemas(tools: ToolSchema[]): unknown[];
|
|
118
|
+
/**
|
|
119
|
+
* A default implementation of the structured call method. For those supporting structured output, the model should
|
|
120
|
+
* override this method.
|
|
121
|
+
* @param options
|
|
122
|
+
* @returns The structured response from the model, which should conform to the provided Zod schema.
|
|
123
|
+
*/
|
|
124
|
+
callStructured(options: ChatModelCallStructuredOptions): Promise<StructuredResponse>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { ChatModelBase as C, type ChatUsage as a, type ChatResponse as b, type ChatModelOptions as c, type ChatModelRequestOptions as d };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { M as Msg } from './message-CzLeTlua.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The complete agent state including both conversation context and metadata.
|
|
5
|
+
*/
|
|
6
|
+
interface AgentState {
|
|
7
|
+
/**
|
|
8
|
+
* The conversation context (message history).
|
|
9
|
+
*/
|
|
10
|
+
context: Msg[];
|
|
11
|
+
/**
|
|
12
|
+
* Agent metadata (replyId, curIter, curSummary, etc.).
|
|
13
|
+
*/
|
|
14
|
+
metadata: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The base storage class that responsible for
|
|
18
|
+
* - loading/saving agent context and state, and
|
|
19
|
+
* - offloading compressed context to external storage for agentic search if needed
|
|
20
|
+
*/
|
|
21
|
+
declare abstract class StorageBase {
|
|
22
|
+
/**
|
|
23
|
+
* Load the complete agent state including context and metadata.
|
|
24
|
+
* @param options.agentId - The agent identifier
|
|
25
|
+
* @returns The agent state with context and metadata
|
|
26
|
+
*/
|
|
27
|
+
abstract loadAgentState(options?: {
|
|
28
|
+
agentId?: string;
|
|
29
|
+
}): Promise<AgentState>;
|
|
30
|
+
/**
|
|
31
|
+
* Save the complete agent state including context and metadata.
|
|
32
|
+
* @param options.agentId - The agent identifier
|
|
33
|
+
* @param options.context - The conversation context to save
|
|
34
|
+
* @param options.metadata - The agent metadata to save
|
|
35
|
+
*/
|
|
36
|
+
abstract saveAgentState(options: {
|
|
37
|
+
agentId?: string;
|
|
38
|
+
context: Msg[];
|
|
39
|
+
metadata: Record<string, unknown>;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Offload the compressed context to external storage for agentic search if needed.
|
|
43
|
+
* @param _options.msgs
|
|
44
|
+
* @param _options
|
|
45
|
+
* @returns The identifier or URL of the offloaded context, or undefined if offloading is not implemented or not needed
|
|
46
|
+
*/
|
|
47
|
+
offloadContext(_options: {
|
|
48
|
+
msgs: Msg[];
|
|
49
|
+
}): Promise<string | undefined>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { type AgentState as A, StorageBase as S };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface TextBlock {
|
|
2
|
+
type: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
interface ThinkingBlock {
|
|
7
|
+
type: 'thinking';
|
|
8
|
+
thinking: string;
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
interface HintBlock {
|
|
12
|
+
type: 'hint';
|
|
13
|
+
hint: string;
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
interface ToolCallBlock {
|
|
17
|
+
type: 'tool_call';
|
|
18
|
+
name: string;
|
|
19
|
+
id: string;
|
|
20
|
+
input: string;
|
|
21
|
+
awaitUserConfirmation?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ToolResultBlock {
|
|
24
|
+
type: 'tool_result';
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
output: string | (TextBlock | DataBlock)[];
|
|
28
|
+
state: 'success' | 'error' | 'interrupted' | 'running';
|
|
29
|
+
}
|
|
30
|
+
interface Base64Source {
|
|
31
|
+
type: 'base64';
|
|
32
|
+
data: string;
|
|
33
|
+
mediaType: string;
|
|
34
|
+
}
|
|
35
|
+
interface URLSource {
|
|
36
|
+
type: 'url';
|
|
37
|
+
url: string;
|
|
38
|
+
mediaType: string;
|
|
39
|
+
}
|
|
40
|
+
interface DataBlock {
|
|
41
|
+
type: 'data';
|
|
42
|
+
source: Base64Source | URLSource;
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
}
|
|
46
|
+
type ContentBlock = TextBlock | ThinkingBlock | HintBlock | ToolCallBlock | ToolResultBlock | DataBlock;
|
|
47
|
+
|
|
48
|
+
export type { Base64Source as B, ContentBlock as C, DataBlock as D, TextBlock as T, URLSource as U, ThinkingBlock as a, ToolCallBlock as b, ToolResultBlock as c };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface TextBlock {
|
|
2
|
+
type: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
interface ThinkingBlock {
|
|
7
|
+
type: 'thinking';
|
|
8
|
+
thinking: string;
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
interface HintBlock {
|
|
12
|
+
type: 'hint';
|
|
13
|
+
hint: string;
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
interface ToolCallBlock {
|
|
17
|
+
type: 'tool_call';
|
|
18
|
+
name: string;
|
|
19
|
+
id: string;
|
|
20
|
+
input: string;
|
|
21
|
+
awaitUserConfirmation?: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface ToolResultBlock {
|
|
24
|
+
type: 'tool_result';
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
output: string | (TextBlock | DataBlock)[];
|
|
28
|
+
state: 'success' | 'error' | 'interrupted' | 'running';
|
|
29
|
+
}
|
|
30
|
+
interface Base64Source {
|
|
31
|
+
type: 'base64';
|
|
32
|
+
data: string;
|
|
33
|
+
mediaType: string;
|
|
34
|
+
}
|
|
35
|
+
interface URLSource {
|
|
36
|
+
type: 'url';
|
|
37
|
+
url: string;
|
|
38
|
+
mediaType: string;
|
|
39
|
+
}
|
|
40
|
+
interface DataBlock {
|
|
41
|
+
type: 'data';
|
|
42
|
+
source: Base64Source | URLSource;
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
}
|
|
46
|
+
type ContentBlock = TextBlock | ThinkingBlock | HintBlock | ToolCallBlock | ToolResultBlock | DataBlock;
|
|
47
|
+
|
|
48
|
+
export type { Base64Source as B, ContentBlock as C, DataBlock as D, TextBlock as T, URLSource as U, ThinkingBlock as a, ToolCallBlock as b, ToolResultBlock as c };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { b as ToolCallBlock, c as ToolResultBlock } from '../block-VsnHrllL.mjs';
|
|
2
|
+
|
|
3
|
+
declare enum EventType {
|
|
4
|
+
RUN_STARTED = "RUN_STARTED",
|
|
5
|
+
RUN_FINISHED = "RUN_FINISHED",
|
|
6
|
+
MODEL_CALL_STARTED = "MODEL_CALL_STARTED",
|
|
7
|
+
MODEL_CALL_ENDED = "MODEL_CALL_ENDED",
|
|
8
|
+
TEXT_BLOCK_START = "TEXT_BLOCK_START",
|
|
9
|
+
TEXT_BLOCK_DELTA = "TEXT_BLOCK_DELTA",
|
|
10
|
+
TEXT_BLOCK_END = "TEXT_BLOCK_END",
|
|
11
|
+
BINARY_BLOCK_START = "BINARY_BLOCK_START",
|
|
12
|
+
BINARY_BLOCK_DELTA = "BINARY_BLOCK_DELTA",
|
|
13
|
+
BINARY_BLOCK_END = "BINARY_BLOCK_END",
|
|
14
|
+
THINKING_BLOCK_START = "THINKING_BLOCK_START",
|
|
15
|
+
THINKING_BLOCK_DELTA = "THINKING_BLOCK_DELTA",
|
|
16
|
+
THINKING_BLOCK_END = "THINKING_BLOCK_END",
|
|
17
|
+
TOOL_CALL_START = "TOOL_CALL_START",
|
|
18
|
+
TOOL_CALL_DELTA = "TOOL_CALL_DELTA",
|
|
19
|
+
TOOL_CALL_END = "TOOL_CALL_END",
|
|
20
|
+
TOOL_RESULT_START = "TOOL_RESULT_START",
|
|
21
|
+
TOOL_RESULT_TEXT_DELTA = "TOOL_RESULT_TEXT_DELTA",
|
|
22
|
+
TOOL_RESULT_BINARY_DELTA = "TOOL_RESULT_BINARY_DELTA",
|
|
23
|
+
TOOL_RESULT_END = "TOOL_RESULT_END",
|
|
24
|
+
EXCEED_MAX_ITERS = "EXCEED_MAX_ITERS",
|
|
25
|
+
REQUIRE_USER_CONFIRM = "REQUIRE_USER_CONFIRM",
|
|
26
|
+
REQUIRE_EXTERNAL_EXECUTION = "REQUIRE_EXTERNAL_EXECUTION",
|
|
27
|
+
USER_CONFIRM_RESULT = "USER_CONFIRM_RESULT",
|
|
28
|
+
EXTERNAL_EXECUTION_RESULT = "EXTERNAL_EXECUTION_RESULT"
|
|
29
|
+
}
|
|
30
|
+
interface EventBase {
|
|
31
|
+
id: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
}
|
|
34
|
+
interface RunStartedEvent extends EventBase {
|
|
35
|
+
type: EventType.RUN_STARTED;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
replyId: string;
|
|
38
|
+
name: string;
|
|
39
|
+
role: 'user' | 'assistant' | 'system';
|
|
40
|
+
}
|
|
41
|
+
interface RunFinishedEvent extends EventBase {
|
|
42
|
+
type: EventType.RUN_FINISHED;
|
|
43
|
+
sessionId: string;
|
|
44
|
+
replyId: string;
|
|
45
|
+
}
|
|
46
|
+
interface ModelCallStartedEvent extends EventBase {
|
|
47
|
+
type: EventType.MODEL_CALL_STARTED;
|
|
48
|
+
replyId: string;
|
|
49
|
+
modelName: string;
|
|
50
|
+
}
|
|
51
|
+
interface ModelCallEndedEvent extends EventBase {
|
|
52
|
+
type: EventType.MODEL_CALL_ENDED;
|
|
53
|
+
replyId: string;
|
|
54
|
+
inputTokens: number;
|
|
55
|
+
outputTokens: number;
|
|
56
|
+
}
|
|
57
|
+
interface TextBlockStartEvent extends EventBase {
|
|
58
|
+
type: EventType.TEXT_BLOCK_START;
|
|
59
|
+
blockId: string;
|
|
60
|
+
replyId: string;
|
|
61
|
+
}
|
|
62
|
+
interface TextBlockDeltaEvent extends EventBase {
|
|
63
|
+
type: EventType.TEXT_BLOCK_DELTA;
|
|
64
|
+
replyId: string;
|
|
65
|
+
blockId: string;
|
|
66
|
+
delta: string;
|
|
67
|
+
}
|
|
68
|
+
interface TextBlockEndEvent extends EventBase {
|
|
69
|
+
type: EventType.TEXT_BLOCK_END;
|
|
70
|
+
replyId: string;
|
|
71
|
+
blockId: string;
|
|
72
|
+
}
|
|
73
|
+
interface BinaryBlockStartEvent extends EventBase {
|
|
74
|
+
type: EventType.BINARY_BLOCK_START;
|
|
75
|
+
replyId: string;
|
|
76
|
+
blockId: string;
|
|
77
|
+
mediaType: string;
|
|
78
|
+
}
|
|
79
|
+
interface BinaryBlockDeltaEvent extends EventBase {
|
|
80
|
+
type: EventType.BINARY_BLOCK_DELTA;
|
|
81
|
+
replyId: string;
|
|
82
|
+
blockId: string;
|
|
83
|
+
data: string;
|
|
84
|
+
mediaType: string;
|
|
85
|
+
}
|
|
86
|
+
interface BinaryBlockEndEvent extends EventBase {
|
|
87
|
+
type: EventType.BINARY_BLOCK_END;
|
|
88
|
+
replyId: string;
|
|
89
|
+
blockId: string;
|
|
90
|
+
}
|
|
91
|
+
interface ThinkingBlockStartEvent extends EventBase {
|
|
92
|
+
type: EventType.THINKING_BLOCK_START;
|
|
93
|
+
replyId: string;
|
|
94
|
+
blockId: string;
|
|
95
|
+
}
|
|
96
|
+
interface ThinkingBlockDeltaEvent extends EventBase {
|
|
97
|
+
type: EventType.THINKING_BLOCK_DELTA;
|
|
98
|
+
replyId: string;
|
|
99
|
+
blockId: string;
|
|
100
|
+
delta: string;
|
|
101
|
+
}
|
|
102
|
+
interface ThinkingBlockEndEvent extends EventBase {
|
|
103
|
+
type: EventType.THINKING_BLOCK_END;
|
|
104
|
+
replyId: string;
|
|
105
|
+
blockId: string;
|
|
106
|
+
}
|
|
107
|
+
interface ToolCallStartEvent extends EventBase {
|
|
108
|
+
type: EventType.TOOL_CALL_START;
|
|
109
|
+
replyId: string;
|
|
110
|
+
toolCallId: string;
|
|
111
|
+
toolCallName: string;
|
|
112
|
+
}
|
|
113
|
+
interface ToolCallDeltaEvent extends EventBase {
|
|
114
|
+
type: EventType.TOOL_CALL_DELTA;
|
|
115
|
+
replyId: string;
|
|
116
|
+
toolCallId: string;
|
|
117
|
+
delta: string;
|
|
118
|
+
}
|
|
119
|
+
interface ToolCallEndEvent extends EventBase {
|
|
120
|
+
type: EventType.TOOL_CALL_END;
|
|
121
|
+
replyId: string;
|
|
122
|
+
toolCallId: string;
|
|
123
|
+
}
|
|
124
|
+
interface ToolResultStartEvent extends EventBase {
|
|
125
|
+
type: EventType.TOOL_RESULT_START;
|
|
126
|
+
replyId: string;
|
|
127
|
+
toolCallId: string;
|
|
128
|
+
toolCallName: string;
|
|
129
|
+
}
|
|
130
|
+
interface ToolResultTextDeltaEvent extends EventBase {
|
|
131
|
+
type: EventType.TOOL_RESULT_TEXT_DELTA;
|
|
132
|
+
replyId: string;
|
|
133
|
+
toolCallId: string;
|
|
134
|
+
delta: string;
|
|
135
|
+
}
|
|
136
|
+
interface ToolResultBinaryDeltaEvent extends EventBase {
|
|
137
|
+
type: EventType.TOOL_RESULT_BINARY_DELTA;
|
|
138
|
+
replyId: string;
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
mediaType: string;
|
|
141
|
+
data?: string;
|
|
142
|
+
url?: string;
|
|
143
|
+
}
|
|
144
|
+
interface ToolResultEndEvent extends EventBase {
|
|
145
|
+
type: EventType.TOOL_RESULT_END;
|
|
146
|
+
replyId: string;
|
|
147
|
+
toolCallId: string;
|
|
148
|
+
state: ToolResultBlock['state'];
|
|
149
|
+
}
|
|
150
|
+
interface ExceedMaxItersEvent extends EventBase {
|
|
151
|
+
type: EventType.EXCEED_MAX_ITERS;
|
|
152
|
+
replyId: string;
|
|
153
|
+
agentId: string;
|
|
154
|
+
name: string;
|
|
155
|
+
}
|
|
156
|
+
interface RequireUserConfirmEvent extends EventBase {
|
|
157
|
+
type: EventType.REQUIRE_USER_CONFIRM;
|
|
158
|
+
replyId: string;
|
|
159
|
+
toolCalls: ToolCallBlock[];
|
|
160
|
+
}
|
|
161
|
+
interface RequireExternalExecutionEvent extends EventBase {
|
|
162
|
+
type: EventType.REQUIRE_EXTERNAL_EXECUTION;
|
|
163
|
+
replyId: string;
|
|
164
|
+
toolCalls: ToolCallBlock[];
|
|
165
|
+
}
|
|
166
|
+
interface UserConfirmResultEvent extends EventBase {
|
|
167
|
+
type: EventType.USER_CONFIRM_RESULT;
|
|
168
|
+
replyId: string;
|
|
169
|
+
confirmResults: {
|
|
170
|
+
confirmed: boolean;
|
|
171
|
+
toolCall: ToolCallBlock;
|
|
172
|
+
}[];
|
|
173
|
+
}
|
|
174
|
+
interface ExternalExecutionResultEvent extends EventBase {
|
|
175
|
+
type: EventType.EXTERNAL_EXECUTION_RESULT;
|
|
176
|
+
replyId: string;
|
|
177
|
+
executionResults: ToolResultBlock[];
|
|
178
|
+
}
|
|
179
|
+
type AgentEvent = RunStartedEvent | RunFinishedEvent | ExceedMaxItersEvent | RequireUserConfirmEvent | RequireExternalExecutionEvent | ModelCallStartedEvent | ModelCallEndedEvent | TextBlockStartEvent | TextBlockDeltaEvent | TextBlockEndEvent | BinaryBlockStartEvent | BinaryBlockDeltaEvent | BinaryBlockEndEvent | ThinkingBlockStartEvent | ThinkingBlockDeltaEvent | ThinkingBlockEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultStartEvent | ToolResultTextDeltaEvent | ToolResultBinaryDeltaEvent | ToolResultEndEvent | UserConfirmResultEvent | ExternalExecutionResultEvent;
|
|
180
|
+
|
|
181
|
+
export { type AgentEvent, type BinaryBlockDeltaEvent, type BinaryBlockEndEvent, type BinaryBlockStartEvent, type EventBase, EventType, type ExceedMaxItersEvent, type ExternalExecutionResultEvent, type ModelCallEndedEvent, type ModelCallStartedEvent, type RequireExternalExecutionEvent, type RequireUserConfirmEvent, type RunFinishedEvent, type RunStartedEvent, type TextBlockDeltaEvent, type TextBlockEndEvent, type TextBlockStartEvent, type ThinkingBlockDeltaEvent, type ThinkingBlockEndEvent, type ThinkingBlockStartEvent, type ToolCallDeltaEvent, type ToolCallEndEvent, type ToolCallStartEvent, type ToolResultBinaryDeltaEvent, type ToolResultEndEvent, type ToolResultStartEvent, type ToolResultTextDeltaEvent, type UserConfirmResultEvent };
|