@agentscope-ai/agentscope 0.0.2 → 0.0.3
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 +94 -90
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +94 -90
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-BOx3UzOl.d.mts → base-Bo8TzBQq.d.mts} +2 -2
- package/dist/{base-NX-knWOv.d.ts → base-Co-MzdN5.d.ts} +1 -1
- package/dist/{base-DYlBMCy_.d.mts → base-D9uCcDjZ.d.mts} +3 -3
- package/dist/{base-C7jwyH4Z.d.mts → base-Dh5vEBQD.d.mts} +1 -1
- package/dist/{base-Cwi4bjze.d.ts → base-TYjCCv7T.d.ts} +3 -3
- package/dist/{base-BoIps2RL.d.ts → base-t7G4uaR_.d.ts} +2 -2
- package/dist/{block-VsnHrllL.d.mts → block-7fd6byyN.d.mts} +2 -2
- package/dist/{block-VsnHrllL.d.ts → block-7fd6byyN.d.ts} +2 -2
- 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 +3 -3
- package/dist/formatter/index.d.ts +3 -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-BTJDlKvQ.d.mts → index-BVNbIN62.d.mts} +1 -1
- package/dist/{index-BcatlwXQ.d.ts → index-DaopL-Vp.d.ts} +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 +2 -2
- package/dist/message/index.d.ts +2 -2
- package/dist/message/index.js +39 -5
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +36 -5
- package/dist/message/index.mjs.map +1 -1
- package/dist/{message-CkN21KaY.d.mts → message-CYnHiEVt.d.mts} +66 -43
- package/dist/{message-CzLeTlua.d.ts → message-DZN7LetB.d.ts} +66 -43
- package/dist/model/index.d.mts +5 -5
- package/dist/model/index.d.ts +5 -5
- package/dist/model/index.js +17 -17
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +17 -17
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +3 -3
- package/dist/storage/index.d.ts +3 -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-BuMTkbGg.d.ts} +2 -2
- package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-CH9qKAy9.d.mts} +2 -2
- package/package.json +87 -87
- package/src/agent/agent.test.ts +63 -63
- package/src/agent/agent.ts +101 -99
- 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 +8 -8
- package/src/formatter/dashscope-chat-formatter.ts +3 -3
- package/src/formatter/openai-chat-formatter.test.ts +4 -4
- package/src/formatter/openai-chat-formatter.ts +6 -6
- package/src/mcp/base.ts +1 -1
- package/src/message/block.ts +2 -2
- package/src/message/index.ts +9 -1
- package/src/message/message.test.ts +1 -1
- package/src/message/message.ts +101 -47
- package/src/permission/index.ts +13 -0
- package/src/storage/file-system.test.ts +3 -3
- package/src/storage/file-system.ts +4 -4
package/src/event/index.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ToolCallBlock, ToolResultBlock } from '../message';
|
|
2
|
+
import { PermissionRule } from '../permission';
|
|
2
3
|
|
|
3
4
|
export enum EventType {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
REPLY_START = 'REPLY_START',
|
|
6
|
+
REPLY_END = 'REPLY_END',
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
MODEL_CALL_START = 'MODEL_CALL_START',
|
|
9
|
+
MODEL_CALL_END = 'MODEL_CALL_END',
|
|
9
10
|
|
|
10
11
|
TEXT_BLOCK_START = 'TEXT_BLOCK_START',
|
|
11
12
|
TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',
|
|
12
13
|
TEXT_BLOCK_END = 'TEXT_BLOCK_END',
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
DATA_BLOCK_START = 'DATA_BLOCK_START',
|
|
16
|
+
DATA_BLOCK_DELTA = 'DATA_BLOCK_DELTA',
|
|
17
|
+
DATA_BLOCK_END = 'DATA_BLOCK_END',
|
|
17
18
|
|
|
18
19
|
THINKING_BLOCK_START = 'THINKING_BLOCK_START',
|
|
19
20
|
THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',
|
|
@@ -25,7 +26,7 @@ export enum EventType {
|
|
|
25
26
|
|
|
26
27
|
TOOL_RESULT_START = 'TOOL_RESULT_START',
|
|
27
28
|
TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',
|
|
28
|
-
|
|
29
|
+
TOOL_RESULT_DATA_DELTA = 'TOOL_RESULT_DATA_DELTA',
|
|
29
30
|
TOOL_RESULT_END = 'TOOL_RESULT_END',
|
|
30
31
|
|
|
31
32
|
EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',
|
|
@@ -39,202 +40,199 @@ export enum EventType {
|
|
|
39
40
|
|
|
40
41
|
export interface EventBase {
|
|
41
42
|
id: string;
|
|
42
|
-
|
|
43
|
+
created_at: string;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export interface
|
|
46
|
-
type: EventType.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Extra fields for AG-UI protocol
|
|
46
|
+
export interface ReplyStartEvent extends EventBase {
|
|
47
|
+
type: EventType.REPLY_START;
|
|
48
|
+
session_id: string;
|
|
49
|
+
reply_id: string;
|
|
51
50
|
name: string;
|
|
52
51
|
role: 'user' | 'assistant' | 'system';
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
export interface
|
|
56
|
-
type: EventType.
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
export interface ReplyEndEvent extends EventBase {
|
|
55
|
+
type: EventType.REPLY_END;
|
|
56
|
+
session_id: string;
|
|
57
|
+
reply_id: string;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export interface
|
|
62
|
-
type: EventType.
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
export interface ModelCallStartEvent extends EventBase {
|
|
61
|
+
type: EventType.MODEL_CALL_START;
|
|
62
|
+
reply_id: string;
|
|
63
|
+
model_name: string;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
export interface
|
|
68
|
-
type: EventType.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
export interface ModelCallEndEvent extends EventBase {
|
|
67
|
+
type: EventType.MODEL_CALL_END;
|
|
68
|
+
reply_id: string;
|
|
69
|
+
input_tokens: number;
|
|
70
|
+
output_tokens: number;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
export interface TextBlockStartEvent extends EventBase {
|
|
75
74
|
type: EventType.TEXT_BLOCK_START;
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
block_id: string;
|
|
76
|
+
reply_id: string;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export interface TextBlockDeltaEvent extends EventBase {
|
|
81
80
|
type: EventType.TEXT_BLOCK_DELTA;
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
reply_id: string;
|
|
82
|
+
block_id: string;
|
|
84
83
|
delta: string;
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
export interface TextBlockEndEvent extends EventBase {
|
|
88
87
|
type: EventType.TEXT_BLOCK_END;
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
reply_id: string;
|
|
89
|
+
block_id: string;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
export interface
|
|
94
|
-
type: EventType.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
export interface DataBlockStartEvent extends EventBase {
|
|
93
|
+
type: EventType.DATA_BLOCK_START;
|
|
94
|
+
reply_id: string;
|
|
95
|
+
block_id: string;
|
|
96
|
+
media_type: string;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
export interface
|
|
101
|
-
type: EventType.
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
export interface DataBlockDeltaEvent extends EventBase {
|
|
100
|
+
type: EventType.DATA_BLOCK_DELTA;
|
|
101
|
+
reply_id: string;
|
|
102
|
+
block_id: string;
|
|
104
103
|
data: string;
|
|
105
|
-
|
|
104
|
+
media_type: string;
|
|
106
105
|
}
|
|
107
106
|
|
|
108
|
-
export interface
|
|
109
|
-
type: EventType.
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
export interface DataBlockEndEvent extends EventBase {
|
|
108
|
+
type: EventType.DATA_BLOCK_END;
|
|
109
|
+
reply_id: string;
|
|
110
|
+
block_id: string;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
export interface ThinkingBlockStartEvent extends EventBase {
|
|
115
114
|
type: EventType.THINKING_BLOCK_START;
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
reply_id: string;
|
|
116
|
+
block_id: string;
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
export interface ThinkingBlockDeltaEvent extends EventBase {
|
|
121
120
|
type: EventType.THINKING_BLOCK_DELTA;
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
reply_id: string;
|
|
122
|
+
block_id: string;
|
|
124
123
|
delta: string;
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
export interface ThinkingBlockEndEvent extends EventBase {
|
|
128
127
|
type: EventType.THINKING_BLOCK_END;
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
reply_id: string;
|
|
129
|
+
block_id: string;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
export interface ToolCallStartEvent extends EventBase {
|
|
134
133
|
type: EventType.TOOL_CALL_START;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
reply_id: string;
|
|
135
|
+
tool_call_id: string;
|
|
136
|
+
tool_call_name: string;
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
export interface ToolCallDeltaEvent extends EventBase {
|
|
141
140
|
type: EventType.TOOL_CALL_DELTA;
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
reply_id: string;
|
|
142
|
+
tool_call_id: string;
|
|
144
143
|
delta: string;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
export interface ToolCallEndEvent extends EventBase {
|
|
148
147
|
type: EventType.TOOL_CALL_END;
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
reply_id: string;
|
|
149
|
+
tool_call_id: string;
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
export interface ToolResultStartEvent extends EventBase {
|
|
154
153
|
type: EventType.TOOL_RESULT_START;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
reply_id: string;
|
|
155
|
+
tool_call_id: string;
|
|
156
|
+
tool_call_name: string;
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
export interface ToolResultTextDeltaEvent extends EventBase {
|
|
161
160
|
type: EventType.TOOL_RESULT_TEXT_DELTA;
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
reply_id: string;
|
|
162
|
+
tool_call_id: string;
|
|
163
|
+
block_id: string;
|
|
164
164
|
delta: string;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
export interface
|
|
168
|
-
type: EventType.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
export interface ToolResultDataDeltaEvent extends EventBase {
|
|
168
|
+
type: EventType.TOOL_RESULT_DATA_DELTA;
|
|
169
|
+
reply_id: string;
|
|
170
|
+
tool_call_id: string;
|
|
171
|
+
block_id: string;
|
|
172
|
+
media_type: string;
|
|
172
173
|
data?: string;
|
|
173
174
|
url?: string;
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
export interface ToolResultEndEvent extends EventBase {
|
|
177
178
|
type: EventType.TOOL_RESULT_END;
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
reply_id: string;
|
|
180
|
+
tool_call_id: string;
|
|
180
181
|
state: ToolResultBlock['state'];
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
export interface ExceedMaxItersEvent extends EventBase {
|
|
184
185
|
type: EventType.EXCEED_MAX_ITERS;
|
|
185
|
-
|
|
186
|
-
replyId: string;
|
|
187
|
-
agentId: string;
|
|
186
|
+
reply_id: string;
|
|
188
187
|
name: string;
|
|
189
188
|
}
|
|
190
189
|
|
|
191
190
|
export interface RequireUserConfirmEvent extends EventBase {
|
|
192
191
|
type: EventType.REQUIRE_USER_CONFIRM;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
toolCalls: ToolCallBlock[];
|
|
192
|
+
reply_id: string;
|
|
193
|
+
tool_calls: ToolCallBlock[];
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
export interface RequireExternalExecutionEvent extends EventBase {
|
|
199
197
|
type: EventType.REQUIRE_EXTERNAL_EXECUTION;
|
|
198
|
+
reply_id: string;
|
|
199
|
+
tool_calls: ToolCallBlock[];
|
|
200
|
+
}
|
|
200
201
|
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
export interface ConfirmResult {
|
|
203
|
+
confirmed: boolean;
|
|
204
|
+
tool_call: ToolCallBlock;
|
|
205
|
+
rules?: PermissionRule[] | null;
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
export interface UserConfirmResultEvent extends EventBase {
|
|
206
209
|
type: EventType.USER_CONFIRM_RESULT;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
confirmResults: {
|
|
210
|
-
confirmed: boolean;
|
|
211
|
-
toolCall: ToolCallBlock;
|
|
212
|
-
}[];
|
|
210
|
+
reply_id: string;
|
|
211
|
+
confirm_results: ConfirmResult[];
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
export interface ExternalExecutionResultEvent extends EventBase {
|
|
216
215
|
type: EventType.EXTERNAL_EXECUTION_RESULT;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
executionResults: ToolResultBlock[];
|
|
216
|
+
reply_id: string;
|
|
217
|
+
execution_results: ToolResultBlock[];
|
|
220
218
|
}
|
|
221
219
|
|
|
222
220
|
export type AgentEvent =
|
|
223
221
|
// The control events for the whole run
|
|
224
|
-
|
|
|
225
|
-
|
|
|
222
|
+
| ReplyStartEvent
|
|
223
|
+
| ReplyEndEvent
|
|
226
224
|
| ExceedMaxItersEvent
|
|
227
225
|
| RequireUserConfirmEvent
|
|
228
226
|
| RequireExternalExecutionEvent
|
|
229
|
-
|
|
|
230
|
-
|
|
|
227
|
+
| ModelCallStartEvent
|
|
228
|
+
| ModelCallEndEvent
|
|
231
229
|
// The data events for different block types
|
|
232
230
|
| TextBlockStartEvent
|
|
233
231
|
| TextBlockDeltaEvent
|
|
234
232
|
| TextBlockEndEvent
|
|
235
|
-
|
|
|
236
|
-
|
|
|
237
|
-
|
|
|
233
|
+
| DataBlockStartEvent
|
|
234
|
+
| DataBlockDeltaEvent
|
|
235
|
+
| DataBlockEndEvent
|
|
238
236
|
| ThinkingBlockStartEvent
|
|
239
237
|
| ThinkingBlockDeltaEvent
|
|
240
238
|
| ThinkingBlockEndEvent
|
|
@@ -243,7 +241,7 @@ export type AgentEvent =
|
|
|
243
241
|
| ToolCallEndEvent
|
|
244
242
|
| ToolResultStartEvent
|
|
245
243
|
| ToolResultTextDeltaEvent
|
|
246
|
-
|
|
|
244
|
+
| ToolResultDataDeltaEvent
|
|
247
245
|
| ToolResultEndEvent
|
|
248
246
|
// The events from the external execution or user confirmation
|
|
249
247
|
| UserConfirmResultEvent
|
package/src/formatter/base.ts
CHANGED
|
@@ -39,10 +39,10 @@ export abstract class FormatterBase {
|
|
|
39
39
|
textualOutput.push(block.text);
|
|
40
40
|
break;
|
|
41
41
|
default:
|
|
42
|
-
const type = block.source.
|
|
42
|
+
const type = block.source.media_type.split('/')[0];
|
|
43
43
|
if (type !== 'image' && type !== 'audio' && type !== 'video') {
|
|
44
44
|
console.log(
|
|
45
|
-
`Unsupported media type '${block.source.
|
|
45
|
+
`Unsupported media type '${block.source.media_type}' in tool output. Only image, audio and video are supported.`
|
|
46
46
|
);
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
@@ -79,7 +79,7 @@ export abstract class FormatterBase {
|
|
|
79
79
|
// Attach prefix and suffix system-info tags if there are promoted blocks
|
|
80
80
|
const promotedBlocks: (TextBlock | DataBlock)[] = [];
|
|
81
81
|
promotedData.forEach(({ id, block }) => {
|
|
82
|
-
const type = block.source.
|
|
82
|
+
const type = block.source.media_type.split('/')[0];
|
|
83
83
|
promotedBlocks.push({
|
|
84
84
|
id: crypto.randomUUID(),
|
|
85
85
|
type: 'text',
|
|
@@ -157,7 +157,7 @@ describe('DashScopeChatFormatter', () => {
|
|
|
157
157
|
source: {
|
|
158
158
|
type: 'url',
|
|
159
159
|
url: 'https://example.com/image.png',
|
|
160
|
-
|
|
160
|
+
media_type: 'image/png',
|
|
161
161
|
},
|
|
162
162
|
},
|
|
163
163
|
],
|
|
@@ -180,7 +180,7 @@ describe('DashScopeChatFormatter', () => {
|
|
|
180
180
|
{
|
|
181
181
|
id: crypto.randomUUID(),
|
|
182
182
|
type: 'data',
|
|
183
|
-
source: { type: 'base64', data: 'xxx',
|
|
183
|
+
source: { type: 'base64', data: 'xxx', media_type: 'audio/mp3' },
|
|
184
184
|
},
|
|
185
185
|
{
|
|
186
186
|
id: crypto.randomUUID(),
|
|
@@ -188,7 +188,7 @@ describe('DashScopeChatFormatter', () => {
|
|
|
188
188
|
source: {
|
|
189
189
|
type: 'url',
|
|
190
190
|
url: 'file:///local/path/to/video.mp4',
|
|
191
|
-
|
|
191
|
+
media_type: 'video/mp4',
|
|
192
192
|
},
|
|
193
193
|
},
|
|
194
194
|
{
|
|
@@ -197,7 +197,7 @@ describe('DashScopeChatFormatter', () => {
|
|
|
197
197
|
source: {
|
|
198
198
|
type: 'url',
|
|
199
199
|
url: 'file:///C:/local/path/to/image.jpg',
|
|
200
|
-
|
|
200
|
+
media_type: 'image/jpg',
|
|
201
201
|
},
|
|
202
202
|
},
|
|
203
203
|
],
|
|
@@ -276,19 +276,19 @@ describe('DashScopeChatFormatter', () => {
|
|
|
276
276
|
source: {
|
|
277
277
|
type: 'url',
|
|
278
278
|
url: 'https://example.com/image1.png',
|
|
279
|
-
|
|
279
|
+
media_type: 'image/png',
|
|
280
280
|
},
|
|
281
281
|
},
|
|
282
282
|
{ id: crypto.randomUUID(), type: 'text', text: 'content 2' },
|
|
283
283
|
{
|
|
284
284
|
id: crypto.randomUUID(),
|
|
285
285
|
type: 'data',
|
|
286
|
-
source: { type: 'base64', data: 'xxx',
|
|
286
|
+
source: { type: 'base64', data: 'xxx', media_type: 'image/png' },
|
|
287
287
|
},
|
|
288
288
|
{
|
|
289
289
|
id: crypto.randomUUID(),
|
|
290
290
|
type: 'data',
|
|
291
|
-
source: { type: 'base64', data: 'yyy',
|
|
291
|
+
source: { type: 'base64', data: 'yyy', media_type: 'audio/mp3' },
|
|
292
292
|
},
|
|
293
293
|
{
|
|
294
294
|
id: crypto.randomUUID(),
|
|
@@ -296,7 +296,7 @@ describe('DashScopeChatFormatter', () => {
|
|
|
296
296
|
source: {
|
|
297
297
|
type: 'url',
|
|
298
298
|
url: '/local/path/to/video1.mp4',
|
|
299
|
-
|
|
299
|
+
media_type: 'video/mp4',
|
|
300
300
|
},
|
|
301
301
|
},
|
|
302
302
|
],
|
|
@@ -141,11 +141,11 @@ export class DashScopeChatFormatter extends FormatterBase {
|
|
|
141
141
|
* @returns An object representing the formatted multimodal content.
|
|
142
142
|
*/
|
|
143
143
|
_formatMultimodalBlock(block: DataBlock) {
|
|
144
|
-
const type = block.source.
|
|
144
|
+
const type = block.source.media_type.split('/')[0];
|
|
145
145
|
|
|
146
146
|
if (!['image', 'audio', 'video'].includes(type)) {
|
|
147
147
|
console.log(
|
|
148
|
-
`Skip unsupported media type ${block.source.
|
|
148
|
+
`Skip unsupported media type ${block.source.media_type} in DashScopeChatFormatter. Only image, audio and video are supported.`
|
|
149
149
|
);
|
|
150
150
|
return [];
|
|
151
151
|
}
|
|
@@ -156,7 +156,7 @@ export class DashScopeChatFormatter extends FormatterBase {
|
|
|
156
156
|
|
|
157
157
|
return [
|
|
158
158
|
{
|
|
159
|
-
[type]: `data:${block.source.
|
|
159
|
+
[type]: `data:${block.source.media_type};base64,${block.source.data}`,
|
|
160
160
|
},
|
|
161
161
|
];
|
|
162
162
|
}
|
|
@@ -133,13 +133,13 @@ describe('OpenAIChatFormatter', () => {
|
|
|
133
133
|
source: {
|
|
134
134
|
type: 'url',
|
|
135
135
|
url: 'https://example.com/image.png',
|
|
136
|
-
|
|
136
|
+
media_type: 'image/png',
|
|
137
137
|
},
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
id: crypto.randomUUID(),
|
|
141
141
|
type: 'data',
|
|
142
|
-
source: { type: 'base64', data: 'xxx',
|
|
142
|
+
source: { type: 'base64', data: 'xxx', media_type: 'audio/mp3' },
|
|
143
143
|
},
|
|
144
144
|
],
|
|
145
145
|
role: 'user',
|
|
@@ -153,7 +153,7 @@ describe('OpenAIChatFormatter', () => {
|
|
|
153
153
|
source: {
|
|
154
154
|
type: 'base64',
|
|
155
155
|
data: 'assistant-audio',
|
|
156
|
-
|
|
156
|
+
media_type: 'audio/mp3',
|
|
157
157
|
},
|
|
158
158
|
},
|
|
159
159
|
],
|
|
@@ -204,7 +204,7 @@ describe('OpenAIChatFormatter', () => {
|
|
|
204
204
|
{ type: 'text', text: 'content 1', id: crypto.randomUUID() },
|
|
205
205
|
{
|
|
206
206
|
type: 'data',
|
|
207
|
-
source: { type: 'base64', data: 'img64',
|
|
207
|
+
source: { type: 'base64', data: 'img64', media_type: 'image/png' },
|
|
208
208
|
id: crypto.randomUUID(),
|
|
209
209
|
},
|
|
210
210
|
],
|
|
@@ -156,7 +156,7 @@ export class OpenAIChatFormatter extends FormatterBase {
|
|
|
156
156
|
block: DataBlock;
|
|
157
157
|
role: Msg['role'];
|
|
158
158
|
}): Promise<Record<string, unknown>[]> {
|
|
159
|
-
const type = block.source.
|
|
159
|
+
const type = block.source.media_type.split('/')[0];
|
|
160
160
|
if (type === 'image') {
|
|
161
161
|
return [
|
|
162
162
|
{
|
|
@@ -182,7 +182,7 @@ export class OpenAIChatFormatter extends FormatterBase {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
console.log(
|
|
185
|
-
`Skip unsupported media type ${block.source.
|
|
185
|
+
`Skip unsupported media type ${block.source.media_type} in OpenAIChatFormatter. Only image and audio are supported.`
|
|
186
186
|
);
|
|
187
187
|
return [];
|
|
188
188
|
}
|
|
@@ -194,7 +194,7 @@ export class OpenAIChatFormatter extends FormatterBase {
|
|
|
194
194
|
*/
|
|
195
195
|
protected async _toOpenAIImageURL(block: DataBlock): Promise<string> {
|
|
196
196
|
if (block.source.type === 'base64') {
|
|
197
|
-
return `data:${block.source.
|
|
197
|
+
return `data:${block.source.media_type};base64,${block.source.data}`;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
const sourceUrl = block.source.url;
|
|
@@ -219,7 +219,7 @@ export class OpenAIChatFormatter extends FormatterBase {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
const file = await readFile(localPath);
|
|
222
|
-
const mime = block.source.
|
|
222
|
+
const mime = block.source.media_type || `image/${ext.slice(1)}`;
|
|
223
223
|
return `data:${mime};base64,${file.toString('base64')}`;
|
|
224
224
|
}
|
|
225
225
|
|
|
@@ -239,10 +239,10 @@ export class OpenAIChatFormatter extends FormatterBase {
|
|
|
239
239
|
]);
|
|
240
240
|
|
|
241
241
|
if (block.source.type === 'base64') {
|
|
242
|
-
const format = supportedMediaTypes.get(block.source.
|
|
242
|
+
const format = supportedMediaTypes.get(block.source.media_type);
|
|
243
243
|
if (!format) {
|
|
244
244
|
throw new TypeError(
|
|
245
|
-
`Unsupported audio media type: ${block.source.
|
|
245
|
+
`Unsupported audio media type: ${block.source.media_type}, only audio/wav and audio/mp3 are supported.`
|
|
246
246
|
);
|
|
247
247
|
}
|
|
248
248
|
return { data: block.source.data, format };
|
package/src/mcp/base.ts
CHANGED
|
@@ -87,7 +87,7 @@ export class MCPTool implements Tool {
|
|
|
87
87
|
content.push({
|
|
88
88
|
id: crypto.randomUUID(),
|
|
89
89
|
type: 'data',
|
|
90
|
-
source: { type: 'base64',
|
|
90
|
+
source: { type: 'base64', media_type: item.mimeType, data: item.data },
|
|
91
91
|
});
|
|
92
92
|
} else {
|
|
93
93
|
console.warn(
|
package/src/message/block.ts
CHANGED
|
@@ -35,13 +35,13 @@ export interface ToolResultBlock {
|
|
|
35
35
|
export interface Base64Source {
|
|
36
36
|
type: 'base64';
|
|
37
37
|
data: string;
|
|
38
|
-
|
|
38
|
+
media_type: string;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export interface URLSource {
|
|
42
42
|
type: 'url';
|
|
43
43
|
url: string;
|
|
44
|
-
|
|
44
|
+
media_type: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export interface DataBlock {
|
package/src/message/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ describe('Message', () => {
|
|
|
13
13
|
]);
|
|
14
14
|
expect(msg.role).toBe('user');
|
|
15
15
|
expect(msg.metadata).toEqual({});
|
|
16
|
-
expect(msg.
|
|
16
|
+
expect(msg.created_at).toBeDefined();
|
|
17
17
|
expect(msg.id).toBeDefined();
|
|
18
18
|
expect(getTextContent(msg)).toBe('Hello, world!');
|
|
19
19
|
|