@agentscope-ai/agentscope 0.0.2 → 0.0.4
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 +202 -0
- package/dist/agent/index.d.mts +10 -10
- package/dist/agent/index.d.ts +10 -10
- package/dist/agent/index.js +104 -93
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +104 -93
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-BOx3UzOl.d.mts → base-1YVBgB4n.d.mts} +2 -2
- package/dist/{base-DYlBMCy_.d.mts → base-B_MQMHWr.d.mts} +3 -3
- package/dist/{base-Cwi4bjze.d.ts → base-BherSLRs.d.ts} +3 -3
- package/dist/{base-NX-knWOv.d.ts → base-CY4DMBH1.d.ts} +1 -1
- package/dist/{base-BoIps2RL.d.ts → base-ChWjyzPL.d.ts} +2 -2
- package/dist/{base-C7jwyH4Z.d.mts → base-ClilytRZ.d.mts} +1 -1
- package/dist/{block-VsnHrllL.d.mts → block-B72uPF1H.d.mts} +7 -5
- package/dist/{block-VsnHrllL.d.ts → block-B72uPF1H.d.ts} +7 -5
- package/dist/event/index.d.mts +105 -89
- package/dist/event/index.d.ts +105 -89
- package/dist/event/index.js +8 -8
- package/dist/event/index.js.map +1 -1
- package/dist/event/index.mjs +8 -8
- package/dist/event/index.mjs.map +1 -1
- package/dist/formatter/index.d.mts +4 -3
- package/dist/formatter/index.d.ts +4 -3
- package/dist/formatter/index.js +17 -17
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/index.mjs +17 -17
- package/dist/formatter/index.mjs.map +1 -1
- package/dist/{index-BcatlwXQ.d.ts → index-BNfyKbQN.d.ts} +1 -1
- package/dist/{index-BTJDlKvQ.d.mts → index-UQCwdfet.d.mts} +1 -1
- package/dist/mcp/index.d.mts +2 -2
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/index.mjs +1 -1
- package/dist/mcp/index.mjs.map +1 -1
- package/dist/message/index.d.mts +3 -2
- package/dist/message/index.d.ts +3 -2
- package/dist/message/index.js +204 -5
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +200 -5
- package/dist/message/index.mjs.map +1 -1
- package/dist/message-CPZd0NIc.d.ts +133 -0
- package/dist/message-DgpfAaHK.d.mts +133 -0
- package/dist/model/index.d.mts +6 -5
- package/dist/model/index.d.ts +6 -5
- package/dist/model/index.js +39 -28
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +39 -28
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +4 -3
- package/dist/storage/index.d.ts +4 -3
- package/dist/storage/index.js +4 -4
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +4 -4
- package/dist/storage/index.mjs.map +1 -1
- package/dist/tool/index.d.mts +4 -4
- package/dist/tool/index.d.ts +4 -4
- package/dist/{toolkit-CEpulFi0.d.ts → toolkit-DeOlul5Y.d.ts} +2 -2
- package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-jwe7NmVJ.d.mts} +2 -2
- package/package.json +87 -87
- package/src/agent/agent.test.ts +104 -71
- package/src/agent/agent.ts +112 -104
- package/src/agent/test-compression.ts +1 -1
- package/src/event/index.ts +96 -98
- package/src/formatter/base.ts +3 -3
- package/src/formatter/dashscope-chat-formatter.test.ts +11 -8
- package/src/formatter/dashscope-chat-formatter.ts +3 -3
- package/src/formatter/openai-chat-formatter.test.ts +13 -5
- package/src/formatter/openai-chat-formatter.ts +6 -6
- package/src/mcp/base.ts +1 -1
- package/src/mcp/http.test.ts +2 -0
- package/src/mcp/stdio.test.ts +1 -0
- package/src/message/append-event.test.ts +783 -0
- package/src/message/block.ts +8 -4
- package/src/message/index.ts +12 -1
- package/src/message/message.test.ts +3 -1
- package/src/message/message.ts +310 -47
- package/src/model/dashscope-model.test.ts +4 -0
- package/src/model/dashscope-model.ts +3 -0
- package/src/model/deepseek-model.test.ts +2 -0
- package/src/model/deepseek-model.ts +3 -0
- package/src/model/ollama-model.test.ts +1 -0
- package/src/model/ollama-model.ts +2 -0
- package/src/model/openai-model.ts +3 -0
- package/src/permission/index.ts +13 -0
- package/src/storage/file-system.test.ts +4 -3
- package/src/storage/file-system.ts +4 -4
- package/src/tool/toolkit.test.ts +12 -0
- package/dist/message-CkN21KaY.d.mts +0 -99
- package/dist/message-CzLeTlua.d.ts +0 -99
package/dist/event/index.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import { b as ToolCallBlock,
|
|
1
|
+
import { b as ToolCallBlock, d as ToolResultBlock } from '../block-B72uPF1H.js';
|
|
2
|
+
|
|
3
|
+
declare enum PermissionBehavior {
|
|
4
|
+
ALLOW = "allow",
|
|
5
|
+
DENY = "deny",
|
|
6
|
+
ASK = "ask",
|
|
7
|
+
PASSTHROUGH = "passthrough"
|
|
8
|
+
}
|
|
9
|
+
interface PermissionRule {
|
|
10
|
+
tool_name: string;
|
|
11
|
+
rule_content: string | null;
|
|
12
|
+
behavior: PermissionBehavior;
|
|
13
|
+
source: string;
|
|
14
|
+
}
|
|
2
15
|
|
|
3
16
|
declare enum EventType {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
REPLY_START = "REPLY_START",
|
|
18
|
+
REPLY_END = "REPLY_END",
|
|
19
|
+
MODEL_CALL_START = "MODEL_CALL_START",
|
|
20
|
+
MODEL_CALL_END = "MODEL_CALL_END",
|
|
8
21
|
TEXT_BLOCK_START = "TEXT_BLOCK_START",
|
|
9
22
|
TEXT_BLOCK_DELTA = "TEXT_BLOCK_DELTA",
|
|
10
23
|
TEXT_BLOCK_END = "TEXT_BLOCK_END",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
DATA_BLOCK_START = "DATA_BLOCK_START",
|
|
25
|
+
DATA_BLOCK_DELTA = "DATA_BLOCK_DELTA",
|
|
26
|
+
DATA_BLOCK_END = "DATA_BLOCK_END",
|
|
14
27
|
THINKING_BLOCK_START = "THINKING_BLOCK_START",
|
|
15
28
|
THINKING_BLOCK_DELTA = "THINKING_BLOCK_DELTA",
|
|
16
29
|
THINKING_BLOCK_END = "THINKING_BLOCK_END",
|
|
@@ -19,7 +32,7 @@ declare enum EventType {
|
|
|
19
32
|
TOOL_CALL_END = "TOOL_CALL_END",
|
|
20
33
|
TOOL_RESULT_START = "TOOL_RESULT_START",
|
|
21
34
|
TOOL_RESULT_TEXT_DELTA = "TOOL_RESULT_TEXT_DELTA",
|
|
22
|
-
|
|
35
|
+
TOOL_RESULT_DATA_DELTA = "TOOL_RESULT_DATA_DELTA",
|
|
23
36
|
TOOL_RESULT_END = "TOOL_RESULT_END",
|
|
24
37
|
EXCEED_MAX_ITERS = "EXCEED_MAX_ITERS",
|
|
25
38
|
REQUIRE_USER_CONFIRM = "REQUIRE_USER_CONFIRM",
|
|
@@ -29,153 +42,156 @@ declare enum EventType {
|
|
|
29
42
|
}
|
|
30
43
|
interface EventBase {
|
|
31
44
|
id: string;
|
|
32
|
-
|
|
45
|
+
created_at: string;
|
|
33
46
|
}
|
|
34
|
-
interface
|
|
35
|
-
type: EventType.
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
interface ReplyStartEvent extends EventBase {
|
|
48
|
+
type: EventType.REPLY_START;
|
|
49
|
+
session_id: string;
|
|
50
|
+
reply_id: string;
|
|
38
51
|
name: string;
|
|
39
52
|
role: 'user' | 'assistant' | 'system';
|
|
40
53
|
}
|
|
41
|
-
interface
|
|
42
|
-
type: EventType.
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
interface ReplyEndEvent extends EventBase {
|
|
55
|
+
type: EventType.REPLY_END;
|
|
56
|
+
session_id: string;
|
|
57
|
+
reply_id: string;
|
|
45
58
|
}
|
|
46
|
-
interface
|
|
47
|
-
type: EventType.
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
interface ModelCallStartEvent extends EventBase {
|
|
60
|
+
type: EventType.MODEL_CALL_START;
|
|
61
|
+
reply_id: string;
|
|
62
|
+
model_name: string;
|
|
50
63
|
}
|
|
51
|
-
interface
|
|
52
|
-
type: EventType.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
interface ModelCallEndEvent extends EventBase {
|
|
65
|
+
type: EventType.MODEL_CALL_END;
|
|
66
|
+
reply_id: string;
|
|
67
|
+
input_tokens: number;
|
|
68
|
+
output_tokens: number;
|
|
56
69
|
}
|
|
57
70
|
interface TextBlockStartEvent extends EventBase {
|
|
58
71
|
type: EventType.TEXT_BLOCK_START;
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
block_id: string;
|
|
73
|
+
reply_id: string;
|
|
61
74
|
}
|
|
62
75
|
interface TextBlockDeltaEvent extends EventBase {
|
|
63
76
|
type: EventType.TEXT_BLOCK_DELTA;
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
reply_id: string;
|
|
78
|
+
block_id: string;
|
|
66
79
|
delta: string;
|
|
67
80
|
}
|
|
68
81
|
interface TextBlockEndEvent extends EventBase {
|
|
69
82
|
type: EventType.TEXT_BLOCK_END;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
interface
|
|
74
|
-
type: EventType.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
interface
|
|
80
|
-
type: EventType.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
reply_id: string;
|
|
84
|
+
block_id: string;
|
|
85
|
+
}
|
|
86
|
+
interface DataBlockStartEvent extends EventBase {
|
|
87
|
+
type: EventType.DATA_BLOCK_START;
|
|
88
|
+
reply_id: string;
|
|
89
|
+
block_id: string;
|
|
90
|
+
media_type: string;
|
|
91
|
+
}
|
|
92
|
+
interface DataBlockDeltaEvent extends EventBase {
|
|
93
|
+
type: EventType.DATA_BLOCK_DELTA;
|
|
94
|
+
reply_id: string;
|
|
95
|
+
block_id: string;
|
|
83
96
|
data: string;
|
|
84
|
-
|
|
97
|
+
media_type: string;
|
|
85
98
|
}
|
|
86
|
-
interface
|
|
87
|
-
type: EventType.
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
interface DataBlockEndEvent extends EventBase {
|
|
100
|
+
type: EventType.DATA_BLOCK_END;
|
|
101
|
+
reply_id: string;
|
|
102
|
+
block_id: string;
|
|
90
103
|
}
|
|
91
104
|
interface ThinkingBlockStartEvent extends EventBase {
|
|
92
105
|
type: EventType.THINKING_BLOCK_START;
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
reply_id: string;
|
|
107
|
+
block_id: string;
|
|
95
108
|
}
|
|
96
109
|
interface ThinkingBlockDeltaEvent extends EventBase {
|
|
97
110
|
type: EventType.THINKING_BLOCK_DELTA;
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
reply_id: string;
|
|
112
|
+
block_id: string;
|
|
100
113
|
delta: string;
|
|
101
114
|
}
|
|
102
115
|
interface ThinkingBlockEndEvent extends EventBase {
|
|
103
116
|
type: EventType.THINKING_BLOCK_END;
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
reply_id: string;
|
|
118
|
+
block_id: string;
|
|
106
119
|
}
|
|
107
120
|
interface ToolCallStartEvent extends EventBase {
|
|
108
121
|
type: EventType.TOOL_CALL_START;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
reply_id: string;
|
|
123
|
+
tool_call_id: string;
|
|
124
|
+
tool_call_name: string;
|
|
112
125
|
}
|
|
113
126
|
interface ToolCallDeltaEvent extends EventBase {
|
|
114
127
|
type: EventType.TOOL_CALL_DELTA;
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
reply_id: string;
|
|
129
|
+
tool_call_id: string;
|
|
117
130
|
delta: string;
|
|
118
131
|
}
|
|
119
132
|
interface ToolCallEndEvent extends EventBase {
|
|
120
133
|
type: EventType.TOOL_CALL_END;
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
reply_id: string;
|
|
135
|
+
tool_call_id: string;
|
|
123
136
|
}
|
|
124
137
|
interface ToolResultStartEvent extends EventBase {
|
|
125
138
|
type: EventType.TOOL_RESULT_START;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
reply_id: string;
|
|
140
|
+
tool_call_id: string;
|
|
141
|
+
tool_call_name: string;
|
|
129
142
|
}
|
|
130
143
|
interface ToolResultTextDeltaEvent extends EventBase {
|
|
131
144
|
type: EventType.TOOL_RESULT_TEXT_DELTA;
|
|
132
|
-
|
|
133
|
-
|
|
145
|
+
reply_id: string;
|
|
146
|
+
tool_call_id: string;
|
|
147
|
+
block_id: string;
|
|
134
148
|
delta: string;
|
|
135
149
|
}
|
|
136
|
-
interface
|
|
137
|
-
type: EventType.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
150
|
+
interface ToolResultDataDeltaEvent extends EventBase {
|
|
151
|
+
type: EventType.TOOL_RESULT_DATA_DELTA;
|
|
152
|
+
reply_id: string;
|
|
153
|
+
tool_call_id: string;
|
|
154
|
+
block_id: string;
|
|
155
|
+
media_type: string;
|
|
141
156
|
data?: string;
|
|
142
157
|
url?: string;
|
|
143
158
|
}
|
|
144
159
|
interface ToolResultEndEvent extends EventBase {
|
|
145
160
|
type: EventType.TOOL_RESULT_END;
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
reply_id: string;
|
|
162
|
+
tool_call_id: string;
|
|
148
163
|
state: ToolResultBlock['state'];
|
|
149
164
|
}
|
|
150
165
|
interface ExceedMaxItersEvent extends EventBase {
|
|
151
166
|
type: EventType.EXCEED_MAX_ITERS;
|
|
152
|
-
|
|
153
|
-
agentId: string;
|
|
167
|
+
reply_id: string;
|
|
154
168
|
name: string;
|
|
155
169
|
}
|
|
156
170
|
interface RequireUserConfirmEvent extends EventBase {
|
|
157
171
|
type: EventType.REQUIRE_USER_CONFIRM;
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
reply_id: string;
|
|
173
|
+
tool_calls: ToolCallBlock[];
|
|
160
174
|
}
|
|
161
175
|
interface RequireExternalExecutionEvent extends EventBase {
|
|
162
176
|
type: EventType.REQUIRE_EXTERNAL_EXECUTION;
|
|
163
|
-
|
|
164
|
-
|
|
177
|
+
reply_id: string;
|
|
178
|
+
tool_calls: ToolCallBlock[];
|
|
179
|
+
}
|
|
180
|
+
interface ConfirmResult {
|
|
181
|
+
confirmed: boolean;
|
|
182
|
+
tool_call: ToolCallBlock;
|
|
183
|
+
rules?: PermissionRule[] | null;
|
|
165
184
|
}
|
|
166
185
|
interface UserConfirmResultEvent extends EventBase {
|
|
167
186
|
type: EventType.USER_CONFIRM_RESULT;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
confirmed: boolean;
|
|
171
|
-
toolCall: ToolCallBlock;
|
|
172
|
-
}[];
|
|
187
|
+
reply_id: string;
|
|
188
|
+
confirm_results: ConfirmResult[];
|
|
173
189
|
}
|
|
174
190
|
interface ExternalExecutionResultEvent extends EventBase {
|
|
175
191
|
type: EventType.EXTERNAL_EXECUTION_RESULT;
|
|
176
|
-
|
|
177
|
-
|
|
192
|
+
reply_id: string;
|
|
193
|
+
execution_results: ToolResultBlock[];
|
|
178
194
|
}
|
|
179
|
-
type AgentEvent =
|
|
195
|
+
type AgentEvent = ReplyStartEvent | ReplyEndEvent | ExceedMaxItersEvent | RequireUserConfirmEvent | RequireExternalExecutionEvent | ModelCallStartEvent | ModelCallEndEvent | TextBlockStartEvent | TextBlockDeltaEvent | TextBlockEndEvent | DataBlockStartEvent | DataBlockDeltaEvent | DataBlockEndEvent | ThinkingBlockStartEvent | ThinkingBlockDeltaEvent | ThinkingBlockEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultStartEvent | ToolResultTextDeltaEvent | ToolResultDataDeltaEvent | ToolResultEndEvent | UserConfirmResultEvent | ExternalExecutionResultEvent;
|
|
180
196
|
|
|
181
|
-
export { type AgentEvent, type
|
|
197
|
+
export { type AgentEvent, type ConfirmResult, type DataBlockDeltaEvent, type DataBlockEndEvent, type DataBlockStartEvent, type EventBase, EventType, type ExceedMaxItersEvent, type ExternalExecutionResultEvent, type ModelCallEndEvent, type ModelCallStartEvent, type ReplyEndEvent, type ReplyStartEvent, type RequireExternalExecutionEvent, type RequireUserConfirmEvent, type TextBlockDeltaEvent, type TextBlockEndEvent, type TextBlockStartEvent, type ThinkingBlockDeltaEvent, type ThinkingBlockEndEvent, type ThinkingBlockStartEvent, type ToolCallDeltaEvent, type ToolCallEndEvent, type ToolCallStartEvent, type ToolResultDataDeltaEvent, type ToolResultEndEvent, type ToolResultStartEvent, type ToolResultTextDeltaEvent, type UserConfirmResultEvent };
|
package/dist/event/index.js
CHANGED
|
@@ -24,16 +24,16 @@ __export(event_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(event_exports);
|
|
26
26
|
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
27
|
-
EventType2["
|
|
28
|
-
EventType2["
|
|
29
|
-
EventType2["
|
|
30
|
-
EventType2["
|
|
27
|
+
EventType2["REPLY_START"] = "REPLY_START";
|
|
28
|
+
EventType2["REPLY_END"] = "REPLY_END";
|
|
29
|
+
EventType2["MODEL_CALL_START"] = "MODEL_CALL_START";
|
|
30
|
+
EventType2["MODEL_CALL_END"] = "MODEL_CALL_END";
|
|
31
31
|
EventType2["TEXT_BLOCK_START"] = "TEXT_BLOCK_START";
|
|
32
32
|
EventType2["TEXT_BLOCK_DELTA"] = "TEXT_BLOCK_DELTA";
|
|
33
33
|
EventType2["TEXT_BLOCK_END"] = "TEXT_BLOCK_END";
|
|
34
|
-
EventType2["
|
|
35
|
-
EventType2["
|
|
36
|
-
EventType2["
|
|
34
|
+
EventType2["DATA_BLOCK_START"] = "DATA_BLOCK_START";
|
|
35
|
+
EventType2["DATA_BLOCK_DELTA"] = "DATA_BLOCK_DELTA";
|
|
36
|
+
EventType2["DATA_BLOCK_END"] = "DATA_BLOCK_END";
|
|
37
37
|
EventType2["THINKING_BLOCK_START"] = "THINKING_BLOCK_START";
|
|
38
38
|
EventType2["THINKING_BLOCK_DELTA"] = "THINKING_BLOCK_DELTA";
|
|
39
39
|
EventType2["THINKING_BLOCK_END"] = "THINKING_BLOCK_END";
|
|
@@ -42,7 +42,7 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
|
42
42
|
EventType2["TOOL_CALL_END"] = "TOOL_CALL_END";
|
|
43
43
|
EventType2["TOOL_RESULT_START"] = "TOOL_RESULT_START";
|
|
44
44
|
EventType2["TOOL_RESULT_TEXT_DELTA"] = "TOOL_RESULT_TEXT_DELTA";
|
|
45
|
-
EventType2["
|
|
45
|
+
EventType2["TOOL_RESULT_DATA_DELTA"] = "TOOL_RESULT_DATA_DELTA";
|
|
46
46
|
EventType2["TOOL_RESULT_END"] = "TOOL_RESULT_END";
|
|
47
47
|
EventType2["EXCEED_MAX_ITERS"] = "EXCEED_MAX_ITERS";
|
|
48
48
|
EventType2["REQUIRE_USER_CONFIRM"] = "REQUIRE_USER_CONFIRM";
|
package/dist/event/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\n\nexport enum EventType {\n
|
|
1
|
+
{"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\nimport { PermissionRule } from '../permission';\n\nexport enum EventType {\n REPLY_START = 'REPLY_START',\n REPLY_END = 'REPLY_END',\n\n MODEL_CALL_START = 'MODEL_CALL_START',\n MODEL_CALL_END = 'MODEL_CALL_END',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n DATA_BLOCK_START = 'DATA_BLOCK_START',\n DATA_BLOCK_DELTA = 'DATA_BLOCK_DELTA',\n DATA_BLOCK_END = 'DATA_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_DATA_DELTA = 'TOOL_RESULT_DATA_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n created_at: string;\n}\n\nexport interface ReplyStartEvent extends EventBase {\n type: EventType.REPLY_START;\n session_id: string;\n reply_id: string;\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface ReplyEndEvent extends EventBase {\n type: EventType.REPLY_END;\n session_id: string;\n reply_id: string;\n}\n\nexport interface ModelCallStartEvent extends EventBase {\n type: EventType.MODEL_CALL_START;\n reply_id: string;\n model_name: string;\n}\n\nexport interface ModelCallEndEvent extends EventBase {\n type: EventType.MODEL_CALL_END;\n reply_id: string;\n input_tokens: number;\n output_tokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n block_id: string;\n reply_id: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface DataBlockStartEvent extends EventBase {\n type: EventType.DATA_BLOCK_START;\n reply_id: string;\n block_id: string;\n media_type: string;\n}\n\nexport interface DataBlockDeltaEvent extends EventBase {\n type: EventType.DATA_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n data: string;\n media_type: string;\n}\n\nexport interface DataBlockEndEvent extends EventBase {\n type: EventType.DATA_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n reply_id: string;\n tool_call_id: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n reply_id: string;\n tool_call_id: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ToolResultDataDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_DATA_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n media_type: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n reply_id: string;\n tool_call_id: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n reply_id: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface ConfirmResult {\n confirmed: boolean;\n tool_call: ToolCallBlock;\n rules?: PermissionRule[] | null;\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n reply_id: string;\n confirm_results: ConfirmResult[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n reply_id: string;\n execution_results: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | ReplyStartEvent\n | ReplyEndEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartEvent\n | ModelCallEndEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | DataBlockStartEvent\n | DataBlockDeltaEvent\n | DataBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultDataDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AAEZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
|
package/dist/event/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/event/index.ts
|
|
2
2
|
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
3
|
-
EventType2["
|
|
4
|
-
EventType2["
|
|
5
|
-
EventType2["
|
|
6
|
-
EventType2["
|
|
3
|
+
EventType2["REPLY_START"] = "REPLY_START";
|
|
4
|
+
EventType2["REPLY_END"] = "REPLY_END";
|
|
5
|
+
EventType2["MODEL_CALL_START"] = "MODEL_CALL_START";
|
|
6
|
+
EventType2["MODEL_CALL_END"] = "MODEL_CALL_END";
|
|
7
7
|
EventType2["TEXT_BLOCK_START"] = "TEXT_BLOCK_START";
|
|
8
8
|
EventType2["TEXT_BLOCK_DELTA"] = "TEXT_BLOCK_DELTA";
|
|
9
9
|
EventType2["TEXT_BLOCK_END"] = "TEXT_BLOCK_END";
|
|
10
|
-
EventType2["
|
|
11
|
-
EventType2["
|
|
12
|
-
EventType2["
|
|
10
|
+
EventType2["DATA_BLOCK_START"] = "DATA_BLOCK_START";
|
|
11
|
+
EventType2["DATA_BLOCK_DELTA"] = "DATA_BLOCK_DELTA";
|
|
12
|
+
EventType2["DATA_BLOCK_END"] = "DATA_BLOCK_END";
|
|
13
13
|
EventType2["THINKING_BLOCK_START"] = "THINKING_BLOCK_START";
|
|
14
14
|
EventType2["THINKING_BLOCK_DELTA"] = "THINKING_BLOCK_DELTA";
|
|
15
15
|
EventType2["THINKING_BLOCK_END"] = "THINKING_BLOCK_END";
|
|
@@ -18,7 +18,7 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
|
18
18
|
EventType2["TOOL_CALL_END"] = "TOOL_CALL_END";
|
|
19
19
|
EventType2["TOOL_RESULT_START"] = "TOOL_RESULT_START";
|
|
20
20
|
EventType2["TOOL_RESULT_TEXT_DELTA"] = "TOOL_RESULT_TEXT_DELTA";
|
|
21
|
-
EventType2["
|
|
21
|
+
EventType2["TOOL_RESULT_DATA_DELTA"] = "TOOL_RESULT_DATA_DELTA";
|
|
22
22
|
EventType2["TOOL_RESULT_END"] = "TOOL_RESULT_END";
|
|
23
23
|
EventType2["EXCEED_MAX_ITERS"] = "EXCEED_MAX_ITERS";
|
|
24
24
|
EventType2["REQUIRE_USER_CONFIRM"] = "REQUIRE_USER_CONFIRM";
|
package/dist/event/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\n\nexport enum EventType {\n
|
|
1
|
+
{"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\nimport { PermissionRule } from '../permission';\n\nexport enum EventType {\n REPLY_START = 'REPLY_START',\n REPLY_END = 'REPLY_END',\n\n MODEL_CALL_START = 'MODEL_CALL_START',\n MODEL_CALL_END = 'MODEL_CALL_END',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n DATA_BLOCK_START = 'DATA_BLOCK_START',\n DATA_BLOCK_DELTA = 'DATA_BLOCK_DELTA',\n DATA_BLOCK_END = 'DATA_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_DATA_DELTA = 'TOOL_RESULT_DATA_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n created_at: string;\n}\n\nexport interface ReplyStartEvent extends EventBase {\n type: EventType.REPLY_START;\n session_id: string;\n reply_id: string;\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface ReplyEndEvent extends EventBase {\n type: EventType.REPLY_END;\n session_id: string;\n reply_id: string;\n}\n\nexport interface ModelCallStartEvent extends EventBase {\n type: EventType.MODEL_CALL_START;\n reply_id: string;\n model_name: string;\n}\n\nexport interface ModelCallEndEvent extends EventBase {\n type: EventType.MODEL_CALL_END;\n reply_id: string;\n input_tokens: number;\n output_tokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n block_id: string;\n reply_id: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface DataBlockStartEvent extends EventBase {\n type: EventType.DATA_BLOCK_START;\n reply_id: string;\n block_id: string;\n media_type: string;\n}\n\nexport interface DataBlockDeltaEvent extends EventBase {\n type: EventType.DATA_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n data: string;\n media_type: string;\n}\n\nexport interface DataBlockEndEvent extends EventBase {\n type: EventType.DATA_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n reply_id: string;\n tool_call_id: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n reply_id: string;\n tool_call_id: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ToolResultDataDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_DATA_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n media_type: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n reply_id: string;\n tool_call_id: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n reply_id: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface ConfirmResult {\n confirmed: boolean;\n tool_call: ToolCallBlock;\n rules?: PermissionRule[] | null;\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n reply_id: string;\n confirm_results: ConfirmResult[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n reply_id: string;\n execution_results: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | ReplyStartEvent\n | ReplyEndEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartEvent\n | ModelCallEndEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | DataBlockStartEvent\n | DataBlockDeltaEvent\n | DataBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultDataDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";AAGO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AAEZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { F as FormatterBase } from '../base-
|
|
2
|
-
import { M as Msg } from '../message-
|
|
3
|
-
import { T as TextBlock, D as DataBlock } from '../block-
|
|
1
|
+
import { F as FormatterBase } from '../base-1YVBgB4n.mjs';
|
|
2
|
+
import { M as Msg } from '../message-DgpfAaHK.mjs';
|
|
3
|
+
import { T as TextBlock, D as DataBlock } from '../block-B72uPF1H.mjs';
|
|
4
4
|
import '../index-CAxQAkiP.mjs';
|
|
5
|
+
import '../event/index.mjs';
|
|
5
6
|
|
|
6
7
|
interface DashScopeFormatterOptions {
|
|
7
8
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { F as FormatterBase } from '../base-
|
|
2
|
-
import { M as Msg } from '../message-
|
|
3
|
-
import { T as TextBlock, D as DataBlock } from '../block-
|
|
1
|
+
import { F as FormatterBase } from '../base-ChWjyzPL.js';
|
|
2
|
+
import { M as Msg } from '../message-CPZd0NIc.js';
|
|
3
|
+
import { T as TextBlock, D as DataBlock } from '../block-B72uPF1H.js';
|
|
4
4
|
import '../index-CAxQAkiP.js';
|
|
5
|
+
import '../event/index.js';
|
|
5
6
|
|
|
6
7
|
interface DashScopeFormatterOptions {
|
|
7
8
|
/**
|
package/dist/formatter/index.js
CHANGED
|
@@ -35,16 +35,16 @@ function createMsg({
|
|
|
35
35
|
role,
|
|
36
36
|
metadata = {},
|
|
37
37
|
id = crypto.randomUUID(),
|
|
38
|
-
|
|
38
|
+
created_at = (/* @__PURE__ */ new Date()).toISOString(),
|
|
39
|
+
finished_at,
|
|
39
40
|
usage
|
|
40
41
|
}) {
|
|
41
|
-
|
|
42
|
+
const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
|
|
43
|
+
return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
|
|
42
44
|
}
|
|
43
45
|
function getTextContent(msg, separator = "\n") {
|
|
44
46
|
const textBlocks = msg.content.filter((block) => block.type === "text");
|
|
45
|
-
if (textBlocks.length === 0)
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
47
|
+
if (textBlocks.length === 0) return null;
|
|
48
48
|
return textBlocks.map((block) => block.text).join(separator);
|
|
49
49
|
}
|
|
50
50
|
function getContentBlocks(msg, blockType) {
|
|
@@ -74,10 +74,10 @@ var FormatterBase = class {
|
|
|
74
74
|
textualOutput.push(block.text);
|
|
75
75
|
break;
|
|
76
76
|
default:
|
|
77
|
-
const type = block.source.
|
|
77
|
+
const type = block.source.media_type.split("/")[0];
|
|
78
78
|
if (type !== "image" && type !== "audio" && type !== "video") {
|
|
79
79
|
console.log(
|
|
80
|
-
`Unsupported media type '${block.source.
|
|
80
|
+
`Unsupported media type '${block.source.media_type}' in tool output. Only image, audio and video are supported.`
|
|
81
81
|
);
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
@@ -101,7 +101,7 @@ var FormatterBase = class {
|
|
|
101
101
|
}
|
|
102
102
|
const promotedBlocks = [];
|
|
103
103
|
promotedData.forEach(({ id, block }) => {
|
|
104
|
-
const type = block.source.
|
|
104
|
+
const type = block.source.media_type.split("/")[0];
|
|
105
105
|
promotedBlocks.push({
|
|
106
106
|
id: crypto.randomUUID(),
|
|
107
107
|
type: "text",
|
|
@@ -247,10 +247,10 @@ var DashScopeChatFormatter = class extends FormatterBase {
|
|
|
247
247
|
* @returns An object representing the formatted multimodal content.
|
|
248
248
|
*/
|
|
249
249
|
_formatMultimodalBlock(block) {
|
|
250
|
-
const type = block.source.
|
|
250
|
+
const type = block.source.media_type.split("/")[0];
|
|
251
251
|
if (!["image", "audio", "video"].includes(type)) {
|
|
252
252
|
console.log(
|
|
253
|
-
`Skip unsupported media type ${block.source.
|
|
253
|
+
`Skip unsupported media type ${block.source.media_type} in DashScopeChatFormatter. Only image, audio and video are supported.`
|
|
254
254
|
);
|
|
255
255
|
return [];
|
|
256
256
|
}
|
|
@@ -259,7 +259,7 @@ var DashScopeChatFormatter = class extends FormatterBase {
|
|
|
259
259
|
}
|
|
260
260
|
return [
|
|
261
261
|
{
|
|
262
|
-
[type]: `data:${block.source.
|
|
262
|
+
[type]: `data:${block.source.media_type};base64,${block.source.data}`
|
|
263
263
|
}
|
|
264
264
|
];
|
|
265
265
|
}
|
|
@@ -510,7 +510,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
510
510
|
block,
|
|
511
511
|
role
|
|
512
512
|
}) {
|
|
513
|
-
const type = block.source.
|
|
513
|
+
const type = block.source.media_type.split("/")[0];
|
|
514
514
|
if (type === "image") {
|
|
515
515
|
return [
|
|
516
516
|
{
|
|
@@ -533,7 +533,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
533
533
|
];
|
|
534
534
|
}
|
|
535
535
|
console.log(
|
|
536
|
-
`Skip unsupported media type ${block.source.
|
|
536
|
+
`Skip unsupported media type ${block.source.media_type} in OpenAIChatFormatter. Only image and audio are supported.`
|
|
537
537
|
);
|
|
538
538
|
return [];
|
|
539
539
|
}
|
|
@@ -544,7 +544,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
544
544
|
*/
|
|
545
545
|
async _toOpenAIImageURL(block) {
|
|
546
546
|
if (block.source.type === "base64") {
|
|
547
|
-
return `data:${block.source.
|
|
547
|
+
return `data:${block.source.media_type};base64,${block.source.data}`;
|
|
548
548
|
}
|
|
549
549
|
const sourceUrl = block.source.url;
|
|
550
550
|
if (sourceUrl.startsWith("http://") || sourceUrl.startsWith("https://")) {
|
|
@@ -565,7 +565,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
565
565
|
);
|
|
566
566
|
}
|
|
567
567
|
const file = await (0, import_promises.readFile)(localPath);
|
|
568
|
-
const mime = block.source.
|
|
568
|
+
const mime = block.source.media_type || `image/${ext.slice(1)}`;
|
|
569
569
|
return `data:${mime};base64,${file.toString("base64")}`;
|
|
570
570
|
}
|
|
571
571
|
/**
|
|
@@ -581,10 +581,10 @@ var OpenAIChatFormatter = class extends FormatterBase {
|
|
|
581
581
|
["audio/mpeg", "mp3"]
|
|
582
582
|
]);
|
|
583
583
|
if (block.source.type === "base64") {
|
|
584
|
-
const format2 = supportedMediaTypes.get(block.source.
|
|
584
|
+
const format2 = supportedMediaTypes.get(block.source.media_type);
|
|
585
585
|
if (!format2) {
|
|
586
586
|
throw new TypeError(
|
|
587
|
-
`Unsupported audio media type: ${block.source.
|
|
587
|
+
`Unsupported audio media type: ${block.source.media_type}, only audio/wav and audio/mp3 are supported.`
|
|
588
588
|
);
|
|
589
589
|
}
|
|
590
590
|
return { data: block.source.data, format: format2 };
|