@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.
Files changed (90) hide show
  1. package/LICENSE +202 -0
  2. package/dist/agent/index.d.mts +10 -10
  3. package/dist/agent/index.d.ts +10 -10
  4. package/dist/agent/index.js +104 -93
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/index.mjs +104 -93
  7. package/dist/agent/index.mjs.map +1 -1
  8. package/dist/{base-BOx3UzOl.d.mts → base-1YVBgB4n.d.mts} +2 -2
  9. package/dist/{base-DYlBMCy_.d.mts → base-B_MQMHWr.d.mts} +3 -3
  10. package/dist/{base-Cwi4bjze.d.ts → base-BherSLRs.d.ts} +3 -3
  11. package/dist/{base-NX-knWOv.d.ts → base-CY4DMBH1.d.ts} +1 -1
  12. package/dist/{base-BoIps2RL.d.ts → base-ChWjyzPL.d.ts} +2 -2
  13. package/dist/{base-C7jwyH4Z.d.mts → base-ClilytRZ.d.mts} +1 -1
  14. package/dist/{block-VsnHrllL.d.mts → block-B72uPF1H.d.mts} +7 -5
  15. package/dist/{block-VsnHrllL.d.ts → block-B72uPF1H.d.ts} +7 -5
  16. package/dist/event/index.d.mts +105 -89
  17. package/dist/event/index.d.ts +105 -89
  18. package/dist/event/index.js +8 -8
  19. package/dist/event/index.js.map +1 -1
  20. package/dist/event/index.mjs +8 -8
  21. package/dist/event/index.mjs.map +1 -1
  22. package/dist/formatter/index.d.mts +4 -3
  23. package/dist/formatter/index.d.ts +4 -3
  24. package/dist/formatter/index.js +17 -17
  25. package/dist/formatter/index.js.map +1 -1
  26. package/dist/formatter/index.mjs +17 -17
  27. package/dist/formatter/index.mjs.map +1 -1
  28. package/dist/{index-BcatlwXQ.d.ts → index-BNfyKbQN.d.ts} +1 -1
  29. package/dist/{index-BTJDlKvQ.d.mts → index-UQCwdfet.d.mts} +1 -1
  30. package/dist/mcp/index.d.mts +2 -2
  31. package/dist/mcp/index.d.ts +2 -2
  32. package/dist/mcp/index.js +1 -1
  33. package/dist/mcp/index.js.map +1 -1
  34. package/dist/mcp/index.mjs +1 -1
  35. package/dist/mcp/index.mjs.map +1 -1
  36. package/dist/message/index.d.mts +3 -2
  37. package/dist/message/index.d.ts +3 -2
  38. package/dist/message/index.js +204 -5
  39. package/dist/message/index.js.map +1 -1
  40. package/dist/message/index.mjs +200 -5
  41. package/dist/message/index.mjs.map +1 -1
  42. package/dist/message-CPZd0NIc.d.ts +133 -0
  43. package/dist/message-DgpfAaHK.d.mts +133 -0
  44. package/dist/model/index.d.mts +6 -5
  45. package/dist/model/index.d.ts +6 -5
  46. package/dist/model/index.js +39 -28
  47. package/dist/model/index.js.map +1 -1
  48. package/dist/model/index.mjs +39 -28
  49. package/dist/model/index.mjs.map +1 -1
  50. package/dist/storage/index.d.mts +4 -3
  51. package/dist/storage/index.d.ts +4 -3
  52. package/dist/storage/index.js +4 -4
  53. package/dist/storage/index.js.map +1 -1
  54. package/dist/storage/index.mjs +4 -4
  55. package/dist/storage/index.mjs.map +1 -1
  56. package/dist/tool/index.d.mts +4 -4
  57. package/dist/tool/index.d.ts +4 -4
  58. package/dist/{toolkit-CEpulFi0.d.ts → toolkit-DeOlul5Y.d.ts} +2 -2
  59. package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-jwe7NmVJ.d.mts} +2 -2
  60. package/package.json +87 -87
  61. package/src/agent/agent.test.ts +104 -71
  62. package/src/agent/agent.ts +112 -104
  63. package/src/agent/test-compression.ts +1 -1
  64. package/src/event/index.ts +96 -98
  65. package/src/formatter/base.ts +3 -3
  66. package/src/formatter/dashscope-chat-formatter.test.ts +11 -8
  67. package/src/formatter/dashscope-chat-formatter.ts +3 -3
  68. package/src/formatter/openai-chat-formatter.test.ts +13 -5
  69. package/src/formatter/openai-chat-formatter.ts +6 -6
  70. package/src/mcp/base.ts +1 -1
  71. package/src/mcp/http.test.ts +2 -0
  72. package/src/mcp/stdio.test.ts +1 -0
  73. package/src/message/append-event.test.ts +783 -0
  74. package/src/message/block.ts +8 -4
  75. package/src/message/index.ts +12 -1
  76. package/src/message/message.test.ts +3 -1
  77. package/src/message/message.ts +310 -47
  78. package/src/model/dashscope-model.test.ts +4 -0
  79. package/src/model/dashscope-model.ts +3 -0
  80. package/src/model/deepseek-model.test.ts +2 -0
  81. package/src/model/deepseek-model.ts +3 -0
  82. package/src/model/ollama-model.test.ts +1 -0
  83. package/src/model/ollama-model.ts +2 -0
  84. package/src/model/openai-model.ts +3 -0
  85. package/src/permission/index.ts +13 -0
  86. package/src/storage/file-system.test.ts +4 -3
  87. package/src/storage/file-system.ts +4 -4
  88. package/src/tool/toolkit.test.ts +12 -0
  89. package/dist/message-CkN21KaY.d.mts +0 -99
  90. package/dist/message-CzLeTlua.d.ts +0 -99
@@ -1,19 +1,20 @@
1
1
  import { ToolCallBlock, ToolResultBlock } from '../message';
2
+ import { PermissionRule } from '../permission';
2
3
 
3
4
  export enum EventType {
4
- RUN_STARTED = 'RUN_STARTED',
5
- RUN_FINISHED = 'RUN_FINISHED',
5
+ REPLY_START = 'REPLY_START',
6
+ REPLY_END = 'REPLY_END',
6
7
 
7
- MODEL_CALL_STARTED = 'MODEL_CALL_STARTED',
8
- MODEL_CALL_ENDED = 'MODEL_CALL_ENDED',
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
- BINARY_BLOCK_START = 'BINARY_BLOCK_START',
15
- BINARY_BLOCK_DELTA = 'BINARY_BLOCK_DELTA',
16
- BINARY_BLOCK_END = 'BINARY_BLOCK_END',
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
- TOOL_RESULT_BINARY_DELTA = 'TOOL_RESULT_BINARY_DELTA',
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
- createdAt: string;
43
+ created_at: string;
43
44
  }
44
45
 
45
- export interface RunStartedEvent extends EventBase {
46
- type: EventType.RUN_STARTED;
47
- sessionId: string;
48
- replyId: string;
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 RunFinishedEvent extends EventBase {
56
- type: EventType.RUN_FINISHED;
57
- sessionId: string;
58
- replyId: string;
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 ModelCallStartedEvent extends EventBase {
62
- type: EventType.MODEL_CALL_STARTED;
63
- replyId: string;
64
- modelName: string;
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 ModelCallEndedEvent extends EventBase {
68
- type: EventType.MODEL_CALL_ENDED;
69
- replyId: string;
70
- inputTokens: number;
71
- outputTokens: number;
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
- blockId: string;
77
- replyId: string;
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
- replyId: string;
83
- blockId: string;
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
- replyId: string;
90
- blockId: string;
88
+ reply_id: string;
89
+ block_id: string;
91
90
  }
92
91
 
93
- export interface BinaryBlockStartEvent extends EventBase {
94
- type: EventType.BINARY_BLOCK_START;
95
- replyId: string;
96
- blockId: string;
97
- mediaType: string;
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 BinaryBlockDeltaEvent extends EventBase {
101
- type: EventType.BINARY_BLOCK_DELTA;
102
- replyId: string;
103
- blockId: string;
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
- mediaType: string;
104
+ media_type: string;
106
105
  }
107
106
 
108
- export interface BinaryBlockEndEvent extends EventBase {
109
- type: EventType.BINARY_BLOCK_END;
110
- replyId: string;
111
- blockId: string;
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
- replyId: string;
117
- blockId: string;
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
- replyId: string;
123
- blockId: string;
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
- replyId: string;
130
- blockId: string;
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
- replyId: string;
136
- toolCallId: string;
137
- toolCallName: string;
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
- replyId: string;
143
- toolCallId: string;
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
- replyId: string;
150
- toolCallId: string;
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
- replyId: string;
156
- toolCallId: string;
157
- toolCallName: string;
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
- replyId: string;
163
- toolCallId: string;
161
+ reply_id: string;
162
+ tool_call_id: string;
163
+ block_id: string;
164
164
  delta: string;
165
165
  }
166
166
 
167
- export interface ToolResultBinaryDeltaEvent extends EventBase {
168
- type: EventType.TOOL_RESULT_BINARY_DELTA;
169
- replyId: string;
170
- toolCallId: string;
171
- mediaType: string;
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
- replyId: string;
179
- toolCallId: string;
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
- replyId: string;
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
- replyId: string;
202
- toolCalls: ToolCallBlock[];
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
- replyId: string;
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
- replyId: string;
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
- | RunStartedEvent
225
- | RunFinishedEvent
222
+ | ReplyStartEvent
223
+ | ReplyEndEvent
226
224
  | ExceedMaxItersEvent
227
225
  | RequireUserConfirmEvent
228
226
  | RequireExternalExecutionEvent
229
- | ModelCallStartedEvent
230
- | ModelCallEndedEvent
227
+ | ModelCallStartEvent
228
+ | ModelCallEndEvent
231
229
  // The data events for different block types
232
230
  | TextBlockStartEvent
233
231
  | TextBlockDeltaEvent
234
232
  | TextBlockEndEvent
235
- | BinaryBlockStartEvent
236
- | BinaryBlockDeltaEvent
237
- | BinaryBlockEndEvent
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
- | ToolResultBinaryDeltaEvent
244
+ | ToolResultDataDeltaEvent
247
245
  | ToolResultEndEvent
248
246
  // The events from the external execution or user confirmation
249
247
  | UserConfirmResultEvent
@@ -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.mediaType.split('/')[0];
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.mediaType}' in tool output. Only image, audio and video are supported.`
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.mediaType.split('/')[0];
82
+ const type = block.source.media_type.split('/')[0];
83
83
  promotedBlocks.push({
84
84
  id: crypto.randomUUID(),
85
85
  type: 'text',
@@ -63,12 +63,14 @@ describe('DashScopeChatFormatter', () => {
63
63
  id: '1',
64
64
  name: 'google_search',
65
65
  input: '{"query": "example1"}',
66
+ state: 'pending',
66
67
  },
67
68
  {
68
69
  type: 'tool_call',
69
70
  id: '2',
70
71
  name: 'bing_search',
71
72
  input: '{"query": "example2"}',
73
+ state: 'pending',
72
74
  },
73
75
  {
74
76
  type: 'tool_result',
@@ -157,7 +159,7 @@ describe('DashScopeChatFormatter', () => {
157
159
  source: {
158
160
  type: 'url',
159
161
  url: 'https://example.com/image.png',
160
- mediaType: 'image/png',
162
+ media_type: 'image/png',
161
163
  },
162
164
  },
163
165
  ],
@@ -180,7 +182,7 @@ describe('DashScopeChatFormatter', () => {
180
182
  {
181
183
  id: crypto.randomUUID(),
182
184
  type: 'data',
183
- source: { type: 'base64', data: 'xxx', mediaType: 'audio/mp3' },
185
+ source: { type: 'base64', data: 'xxx', media_type: 'audio/mp3' },
184
186
  },
185
187
  {
186
188
  id: crypto.randomUUID(),
@@ -188,7 +190,7 @@ describe('DashScopeChatFormatter', () => {
188
190
  source: {
189
191
  type: 'url',
190
192
  url: 'file:///local/path/to/video.mp4',
191
- mediaType: 'video/mp4',
193
+ media_type: 'video/mp4',
192
194
  },
193
195
  },
194
196
  {
@@ -197,7 +199,7 @@ describe('DashScopeChatFormatter', () => {
197
199
  source: {
198
200
  type: 'url',
199
201
  url: 'file:///C:/local/path/to/image.jpg',
200
- mediaType: 'image/jpg',
202
+ media_type: 'image/jpg',
201
203
  },
202
204
  },
203
205
  ],
@@ -263,6 +265,7 @@ describe('DashScopeChatFormatter', () => {
263
265
  id: '1',
264
266
  name: 'google_search',
265
267
  input: '{\"query\": \"example1\"}',
268
+ state: 'pending',
266
269
  },
267
270
  {
268
271
  type: 'tool_result',
@@ -276,19 +279,19 @@ describe('DashScopeChatFormatter', () => {
276
279
  source: {
277
280
  type: 'url',
278
281
  url: 'https://example.com/image1.png',
279
- mediaType: 'image/png',
282
+ media_type: 'image/png',
280
283
  },
281
284
  },
282
285
  { id: crypto.randomUUID(), type: 'text', text: 'content 2' },
283
286
  {
284
287
  id: crypto.randomUUID(),
285
288
  type: 'data',
286
- source: { type: 'base64', data: 'xxx', mediaType: 'image/png' },
289
+ source: { type: 'base64', data: 'xxx', media_type: 'image/png' },
287
290
  },
288
291
  {
289
292
  id: crypto.randomUUID(),
290
293
  type: 'data',
291
- source: { type: 'base64', data: 'yyy', mediaType: 'audio/mp3' },
294
+ source: { type: 'base64', data: 'yyy', media_type: 'audio/mp3' },
292
295
  },
293
296
  {
294
297
  id: crypto.randomUUID(),
@@ -296,7 +299,7 @@ describe('DashScopeChatFormatter', () => {
296
299
  source: {
297
300
  type: 'url',
298
301
  url: '/local/path/to/video1.mp4',
299
- mediaType: 'video/mp4',
302
+ media_type: 'video/mp4',
300
303
  },
301
304
  },
302
305
  ],
@@ -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.mediaType.split('/')[0];
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.mediaType} in DashScopeChatFormatter. Only image, audio and video are supported.`
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.mediaType};base64,${block.source.data}`,
159
+ [type]: `data:${block.source.media_type};base64,${block.source.data}`,
160
160
  },
161
161
  ];
162
162
  }
@@ -54,12 +54,14 @@ describe('OpenAIChatFormatter', () => {
54
54
  id: '1',
55
55
  name: 'google_search',
56
56
  input: '{"query": "example1"}',
57
+ state: 'pending',
57
58
  },
58
59
  {
59
60
  type: 'tool_call',
60
61
  id: '2',
61
62
  name: 'bing_search',
62
63
  input: '{"query": "example2"}',
64
+ state: 'pending',
63
65
  },
64
66
  {
65
67
  type: 'tool_result',
@@ -133,13 +135,13 @@ describe('OpenAIChatFormatter', () => {
133
135
  source: {
134
136
  type: 'url',
135
137
  url: 'https://example.com/image.png',
136
- mediaType: 'image/png',
138
+ media_type: 'image/png',
137
139
  },
138
140
  },
139
141
  {
140
142
  id: crypto.randomUUID(),
141
143
  type: 'data',
142
- source: { type: 'base64', data: 'xxx', mediaType: 'audio/mp3' },
144
+ source: { type: 'base64', data: 'xxx', media_type: 'audio/mp3' },
143
145
  },
144
146
  ],
145
147
  role: 'user',
@@ -153,7 +155,7 @@ describe('OpenAIChatFormatter', () => {
153
155
  source: {
154
156
  type: 'base64',
155
157
  data: 'assistant-audio',
156
- mediaType: 'audio/mp3',
158
+ media_type: 'audio/mp3',
157
159
  },
158
160
  },
159
161
  ],
@@ -195,7 +197,13 @@ describe('OpenAIChatFormatter', () => {
195
197
  createMsg({
196
198
  name: 'assistant',
197
199
  content: [
198
- { type: 'tool_call', id: '1', name: 'google_search', input: '{"query": "A"}' },
200
+ {
201
+ type: 'tool_call',
202
+ id: '1',
203
+ name: 'google_search',
204
+ input: '{"query": "A"}',
205
+ state: 'pending',
206
+ },
199
207
  {
200
208
  type: 'tool_result',
201
209
  id: '1',
@@ -204,7 +212,7 @@ describe('OpenAIChatFormatter', () => {
204
212
  { type: 'text', text: 'content 1', id: crypto.randomUUID() },
205
213
  {
206
214
  type: 'data',
207
- source: { type: 'base64', data: 'img64', mediaType: 'image/png' },
215
+ source: { type: 'base64', data: 'img64', media_type: 'image/png' },
208
216
  id: crypto.randomUUID(),
209
217
  },
210
218
  ],
@@ -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.mediaType.split('/')[0];
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.mediaType} in OpenAIChatFormatter. Only image and audio are supported.`
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.mediaType};base64,${block.source.data}`;
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.mediaType || `image/${ext.slice(1)}`;
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.mediaType);
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.mediaType}, only audio/wav and audio/mp3 are supported.`
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', mediaType: item.mimeType, data: item.data },
90
+ source: { type: 'base64', media_type: item.mimeType, data: item.data },
91
91
  });
92
92
  } else {
93
93
  console.warn(
@@ -215,6 +215,7 @@ describe('HTTPStatefulMCPClient', () => {
215
215
  name: 'add',
216
216
  type: 'tool_call',
217
217
  input: `{"a": 10, "b": 20}`,
218
+ state: 'pending',
218
219
  });
219
220
  for await (const item of res) {
220
221
  expect(item.content.length).toBeGreaterThan(0);
@@ -288,6 +289,7 @@ describe('HTTPStatelessMCPClient', () => {
288
289
  name: 'add',
289
290
  type: 'tool_call',
290
291
  input: `{"a": 15, "b": 25}`,
292
+ state: 'pending',
291
293
  });
292
294
  const collectedRes: ToolResponse[] = [];
293
295
  for await (const item of res) {
@@ -77,6 +77,7 @@ describeUnlessWindows('StdIOMCPClient', () => {
77
77
  name: 'read_file',
78
78
  type: 'tool_call',
79
79
  input: `{"path": "${testFilePath}"}`,
80
+ state: 'pending',
80
81
  });
81
82
  for await (const item of res) {
82
83
  expect(item.content.length).toBeGreaterThan(0);