@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.
Files changed (77) 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 +94 -90
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/index.mjs +94 -90
  7. package/dist/agent/index.mjs.map +1 -1
  8. package/dist/{base-BOx3UzOl.d.mts → base-Bo8TzBQq.d.mts} +2 -2
  9. package/dist/{base-NX-knWOv.d.ts → base-Co-MzdN5.d.ts} +1 -1
  10. package/dist/{base-DYlBMCy_.d.mts → base-D9uCcDjZ.d.mts} +3 -3
  11. package/dist/{base-C7jwyH4Z.d.mts → base-Dh5vEBQD.d.mts} +1 -1
  12. package/dist/{base-Cwi4bjze.d.ts → base-TYjCCv7T.d.ts} +3 -3
  13. package/dist/{base-BoIps2RL.d.ts → base-t7G4uaR_.d.ts} +2 -2
  14. package/dist/{block-VsnHrllL.d.mts → block-7fd6byyN.d.mts} +2 -2
  15. package/dist/{block-VsnHrllL.d.ts → block-7fd6byyN.d.ts} +2 -2
  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 +3 -3
  23. package/dist/formatter/index.d.ts +3 -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-BTJDlKvQ.d.mts → index-BVNbIN62.d.mts} +1 -1
  29. package/dist/{index-BcatlwXQ.d.ts → index-DaopL-Vp.d.ts} +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 +2 -2
  37. package/dist/message/index.d.ts +2 -2
  38. package/dist/message/index.js +39 -5
  39. package/dist/message/index.js.map +1 -1
  40. package/dist/message/index.mjs +36 -5
  41. package/dist/message/index.mjs.map +1 -1
  42. package/dist/{message-CkN21KaY.d.mts → message-CYnHiEVt.d.mts} +66 -43
  43. package/dist/{message-CzLeTlua.d.ts → message-DZN7LetB.d.ts} +66 -43
  44. package/dist/model/index.d.mts +5 -5
  45. package/dist/model/index.d.ts +5 -5
  46. package/dist/model/index.js +17 -17
  47. package/dist/model/index.js.map +1 -1
  48. package/dist/model/index.mjs +17 -17
  49. package/dist/model/index.mjs.map +1 -1
  50. package/dist/storage/index.d.mts +3 -3
  51. package/dist/storage/index.d.ts +3 -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-BuMTkbGg.d.ts} +2 -2
  59. package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-CH9qKAy9.d.mts} +2 -2
  60. package/package.json +87 -87
  61. package/src/agent/agent.test.ts +63 -63
  62. package/src/agent/agent.ts +101 -99
  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 +8 -8
  67. package/src/formatter/dashscope-chat-formatter.ts +3 -3
  68. package/src/formatter/openai-chat-formatter.test.ts +4 -4
  69. package/src/formatter/openai-chat-formatter.ts +6 -6
  70. package/src/mcp/base.ts +1 -1
  71. package/src/message/block.ts +2 -2
  72. package/src/message/index.ts +9 -1
  73. package/src/message/message.test.ts +1 -1
  74. package/src/message/message.ts +101 -47
  75. package/src/permission/index.ts +13 -0
  76. package/src/storage/file-system.test.ts +3 -3
  77. package/src/storage/file-system.ts +4 -4
@@ -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',
@@ -157,7 +157,7 @@ describe('DashScopeChatFormatter', () => {
157
157
  source: {
158
158
  type: 'url',
159
159
  url: 'https://example.com/image.png',
160
- mediaType: 'image/png',
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', mediaType: 'audio/mp3' },
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
- mediaType: 'video/mp4',
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
- mediaType: 'image/jpg',
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
- mediaType: 'image/png',
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', mediaType: 'image/png' },
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', mediaType: 'audio/mp3' },
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
- mediaType: 'video/mp4',
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.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
  }
@@ -133,13 +133,13 @@ describe('OpenAIChatFormatter', () => {
133
133
  source: {
134
134
  type: 'url',
135
135
  url: 'https://example.com/image.png',
136
- mediaType: 'image/png',
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', mediaType: 'audio/mp3' },
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
- mediaType: 'audio/mp3',
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', mediaType: 'image/png' },
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.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(
@@ -35,13 +35,13 @@ export interface ToolResultBlock {
35
35
  export interface Base64Source {
36
36
  type: 'base64';
37
37
  data: string;
38
- mediaType: string;
38
+ media_type: string;
39
39
  }
40
40
 
41
41
  export interface URLSource {
42
42
  type: 'url';
43
43
  url: string;
44
- mediaType: string;
44
+ media_type: string;
45
45
  }
46
46
 
47
47
  export interface DataBlock {
@@ -1,4 +1,12 @@
1
- export { Msg, createMsg, getTextContent, getContentBlocks } from './message';
1
+ export {
2
+ Msg,
3
+ createMsg,
4
+ UserMsg,
5
+ AssistantMsg,
6
+ SystemMsg,
7
+ getTextContent,
8
+ getContentBlocks,
9
+ } from './message';
2
10
  export {
3
11
  TextBlock,
4
12
  ThinkingBlock,
@@ -13,7 +13,7 @@ describe('Message', () => {
13
13
  ]);
14
14
  expect(msg.role).toBe('user');
15
15
  expect(msg.metadata).toEqual({});
16
- expect(msg.timestamp).toBeDefined();
16
+ expect(msg.created_at).toBeDefined();
17
17
  expect(msg.id).toBeDefined();
18
18
  expect(getTextContent(msg)).toBe('Hello, world!');
19
19