@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
@@ -444,7 +444,7 @@ describe('LocalFileStorage', () => {
444
444
  source: {
445
445
  type: 'url',
446
446
  url: 'https://example.com/image.png',
447
- mediaType: 'image/png',
447
+ media_type: 'image/png',
448
448
  },
449
449
  },
450
450
  ],
@@ -483,7 +483,7 @@ describe('LocalFileStorage', () => {
483
483
  source: {
484
484
  type: 'base64',
485
485
  data: base64Data,
486
- mediaType: 'text/plain',
486
+ media_type: 'text/plain',
487
487
  },
488
488
  },
489
489
  ],
@@ -529,6 +529,7 @@ describe('LocalFileStorage', () => {
529
529
  id: 'call-123',
530
530
  name: 'search',
531
531
  input: JSON.stringify({ query: 'test' }),
532
+ state: 'pending',
532
533
  },
533
534
  ],
534
535
  role: 'assistant',
@@ -562,7 +563,7 @@ describe('LocalFileStorage', () => {
562
563
  source: {
563
564
  type: 'url',
564
565
  url: 'https://example.com/image.png',
565
- mediaType: 'image/png',
566
+ media_type: 'image/png',
566
567
  },
567
568
  },
568
569
  { type: 'text', text: 'What do you see?', id: 'text-35' },
@@ -233,12 +233,12 @@ export class LocalFileStorage extends StorageBase {
233
233
  case 'data':
234
234
  if (block.source.type === 'url') {
235
235
  msgContent.push(
236
- `${msg.name}: <data src={${block.source.url}} type={${block.source.mediaType}} />`
236
+ `${msg.name}: <data src={${block.source.url}} type={${block.source.media_type}} />`
237
237
  );
238
238
  } else if (block.source.type === 'base64') {
239
239
  // Save the base64 data to a file and add a reference to the file in the offload content
240
- const mainType = block.source.mediaType.split('/')[0];
241
- const extension = mime.extension(block.source.mediaType) || 'bin';
240
+ const mainType = block.source.media_type.split('/')[0];
241
+ const extension = mime.extension(block.source.media_type) || 'bin';
242
242
  const filePath = path.join(
243
243
  offloadDataDir,
244
244
  `${mainType}-${Date.now()}.${extension}`
@@ -249,7 +249,7 @@ export class LocalFileStorage extends StorageBase {
249
249
  const buffer = Buffer.from(block.source.data, 'base64');
250
250
  fs.writeFileSync(filePath, buffer);
251
251
  msgContent.push(
252
- `${msg.name}: <data src={${filePath}} type={${block.source.mediaType}} />`
252
+ `${msg.name}: <data src={${filePath}} type={${block.source.media_type}} />`
253
253
  );
254
254
  }
255
255
  break;
@@ -92,6 +92,7 @@ describe('Toolkit', () => {
92
92
  type: 'tool_call',
93
93
  name: 'test_function',
94
94
  input: '{"a":"hello","b":5}',
95
+ state: 'pending',
95
96
  id: '1',
96
97
  });
97
98
 
@@ -162,6 +163,7 @@ describe('Toolkit', () => {
162
163
  type: 'tool_call',
163
164
  name: 'test_function',
164
165
  input: '{"a":"hello","b":5}',
166
+ state: 'pending',
165
167
  id: '1b',
166
168
  });
167
169
 
@@ -229,6 +231,7 @@ describe('Toolkit', () => {
229
231
  name: 'no_param_function',
230
232
  id: '2',
231
233
  input: '{}',
234
+ state: 'pending',
232
235
  });
233
236
 
234
237
  for await (const chunk of res) {
@@ -263,6 +266,7 @@ describe('Toolkit', () => {
263
266
  name: 'count_function',
264
267
  id: '3',
265
268
  input: '{"count":3}',
269
+ state: 'pending',
266
270
  });
267
271
 
268
272
  // Verify intermediate chunks
@@ -325,6 +329,7 @@ describe('Toolkit', () => {
325
329
  name: 'async_count_function',
326
330
  id: '4',
327
331
  input: '{"count":2}',
332
+ state: 'pending',
328
333
  });
329
334
 
330
335
  // Verify intermediate chunks
@@ -376,6 +381,7 @@ describe('Toolkit', () => {
376
381
  name: 'string_count_function',
377
382
  id: '8',
378
383
  input: '{"count":3}',
384
+ state: 'pending',
379
385
  });
380
386
 
381
387
  const chunks = [];
@@ -429,6 +435,7 @@ describe('Toolkit', () => {
429
435
  name: 'async_string_count_function',
430
436
  id: '9',
431
437
  input: '{"count":2}',
438
+ state: 'pending',
432
439
  });
433
440
 
434
441
  const chunks = [];
@@ -467,6 +474,7 @@ describe('Toolkit', () => {
467
474
  name: 'non_existent_function',
468
475
  id: '5',
469
476
  input: '{}',
477
+ state: 'pending',
470
478
  });
471
479
 
472
480
  for await (const chunk of res) {
@@ -495,6 +503,7 @@ describe('Toolkit', () => {
495
503
  name: 'test_function',
496
504
  id: '6',
497
505
  input: '{"a":"hello","b":20}',
506
+ state: 'pending',
498
507
  });
499
508
 
500
509
  for await (const chunk of res2) {
@@ -526,6 +535,7 @@ describe('Toolkit', () => {
526
535
  name: 'test_function',
527
536
  id: '7',
528
537
  input: '{"a":"hello","b":20}',
538
+ state: 'pending',
529
539
  });
530
540
 
531
541
  for await (const chunk of res3) {
@@ -582,6 +592,7 @@ This skill demonstrates how to use the Skill tool to retrieve skill content.`;
582
592
  type: 'tool_call',
583
593
  name: 'Skill',
584
594
  input: '{"name":"test_skill"}',
595
+ state: 'pending',
585
596
  id: 'skill_test_1',
586
597
  });
587
598
 
@@ -610,6 +621,7 @@ This skill demonstrates how to use the Skill tool to retrieve skill content.`;
610
621
  type: 'tool_call',
611
622
  name: 'Skill',
612
623
  input: '{"name":"non_existent_skill"}',
624
+ state: 'pending',
613
625
  id: 'skill_test_2',
614
626
  });
615
627
 
@@ -1,99 +0,0 @@
1
- import { J as JSONSerializableObject } from './index-CAxQAkiP.mjs';
2
- import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.mjs';
3
-
4
- /** A chat message exchanged between agents or between an agent and a model. */
5
- interface Msg {
6
- /** Unique identifier for the message. */
7
- id: string;
8
- /** Display name of the message sender. */
9
- name: string;
10
- /** Conversation role of the sender. */
11
- role: 'user' | 'assistant' | 'system';
12
- /** Message body. */
13
- content: ContentBlock[];
14
- /** Arbitrary key-value metadata attached to the message. */
15
- metadata: Record<string, JSONSerializableObject>;
16
- /** ISO-8601 creation timestamp. */
17
- timestamp: string;
18
- /** Usage information for the message, such as token counts. */
19
- usage?: {
20
- inputTokens: number;
21
- outputTokens: number;
22
- };
23
- }
24
- /**
25
- * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
26
- *
27
- * @param root0
28
- * @param root0.name
29
- * @param root0.content
30
- * @param root0.role
31
- * @param root0.metadata
32
- * @param root0.id
33
- * @param root0.timestamp
34
- * @param root0.usage
35
- * @returns A fully-populated {@link Msg} object.
36
- */
37
- declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
38
- /**
39
- * Extract the plain-text content from a message.
40
- *
41
- * When `content` is a string it is returned as-is. When it is an array of
42
- * content blocks, all {@link TextBlock} texts are joined with `separator`.
43
- *
44
- * @param msg - The message to read.
45
- * @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
46
- * @returns The concatenated text, or `null` when no text blocks are present.
47
- */
48
- declare function getTextContent(msg: Msg, separator?: string): string | null;
49
- /**
50
- * Return all content blocks from a message, regardless of type.
51
- *
52
- * When `content` is a plain string it is wrapped in a single {@link TextBlock}.
53
- *
54
- * @param msg - The message to read.
55
- * @returns An array of all {@link ContentBlock} objects.
56
- */
57
- declare function getContentBlocks(msg: Msg): ContentBlock[];
58
- /**
59
- * Return all {@link TextBlock} objects from a message.
60
- *
61
- * @param msg - The message to read.
62
- * @param blockType - `'text'`
63
- * @returns An array of {@link TextBlock} objects.
64
- */
65
- declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
66
- /**
67
- * Return all {@link ThinkingBlock} objects from a message.
68
- *
69
- * @param msg - The message to read.
70
- * @param blockType - `'thinking'`
71
- * @returns An array of {@link ThinkingBlock} objects.
72
- */
73
- declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
74
- /**
75
- * Return all {@link DataBlock} objects from a message.
76
- *
77
- * @param msg - The message to read.
78
- * @param blockType - `'video'`
79
- * @returns An array of {@link DataBlock} objects.
80
- */
81
- declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
82
- /**
83
- * Return all {@link ToolCallBlock} objects from a message.
84
- *
85
- * @param msg - The message to read.
86
- * @param blockType - `'tool_call'`
87
- * @returns An array of {@link ToolCallBlock} objects.
88
- */
89
- declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
90
- /**
91
- * Return all {@link ToolResultBlock} objects from a message.
92
- *
93
- * @param msg - The message to read.
94
- * @param blockType - `'tool_result'`
95
- * @returns An array of {@link ToolResultBlock} objects.
96
- */
97
- declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
98
-
99
- export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };
@@ -1,99 +0,0 @@
1
- import { J as JSONSerializableObject } from './index-CAxQAkiP.js';
2
- import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.js';
3
-
4
- /** A chat message exchanged between agents or between an agent and a model. */
5
- interface Msg {
6
- /** Unique identifier for the message. */
7
- id: string;
8
- /** Display name of the message sender. */
9
- name: string;
10
- /** Conversation role of the sender. */
11
- role: 'user' | 'assistant' | 'system';
12
- /** Message body. */
13
- content: ContentBlock[];
14
- /** Arbitrary key-value metadata attached to the message. */
15
- metadata: Record<string, JSONSerializableObject>;
16
- /** ISO-8601 creation timestamp. */
17
- timestamp: string;
18
- /** Usage information for the message, such as token counts. */
19
- usage?: {
20
- inputTokens: number;
21
- outputTokens: number;
22
- };
23
- }
24
- /**
25
- * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
26
- *
27
- * @param root0
28
- * @param root0.name
29
- * @param root0.content
30
- * @param root0.role
31
- * @param root0.metadata
32
- * @param root0.id
33
- * @param root0.timestamp
34
- * @param root0.usage
35
- * @returns A fully-populated {@link Msg} object.
36
- */
37
- declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
38
- /**
39
- * Extract the plain-text content from a message.
40
- *
41
- * When `content` is a string it is returned as-is. When it is an array of
42
- * content blocks, all {@link TextBlock} texts are joined with `separator`.
43
- *
44
- * @param msg - The message to read.
45
- * @param separator - String inserted between consecutive text blocks. Defaults to `'\n'`.
46
- * @returns The concatenated text, or `null` when no text blocks are present.
47
- */
48
- declare function getTextContent(msg: Msg, separator?: string): string | null;
49
- /**
50
- * Return all content blocks from a message, regardless of type.
51
- *
52
- * When `content` is a plain string it is wrapped in a single {@link TextBlock}.
53
- *
54
- * @param msg - The message to read.
55
- * @returns An array of all {@link ContentBlock} objects.
56
- */
57
- declare function getContentBlocks(msg: Msg): ContentBlock[];
58
- /**
59
- * Return all {@link TextBlock} objects from a message.
60
- *
61
- * @param msg - The message to read.
62
- * @param blockType - `'text'`
63
- * @returns An array of {@link TextBlock} objects.
64
- */
65
- declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
66
- /**
67
- * Return all {@link ThinkingBlock} objects from a message.
68
- *
69
- * @param msg - The message to read.
70
- * @param blockType - `'thinking'`
71
- * @returns An array of {@link ThinkingBlock} objects.
72
- */
73
- declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
74
- /**
75
- * Return all {@link DataBlock} objects from a message.
76
- *
77
- * @param msg - The message to read.
78
- * @param blockType - `'video'`
79
- * @returns An array of {@link DataBlock} objects.
80
- */
81
- declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
82
- /**
83
- * Return all {@link ToolCallBlock} objects from a message.
84
- *
85
- * @param msg - The message to read.
86
- * @param blockType - `'tool_call'`
87
- * @returns An array of {@link ToolCallBlock} objects.
88
- */
89
- declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
90
- /**
91
- * Return all {@link ToolResultBlock} objects from a message.
92
- *
93
- * @param msg - The message to read.
94
- * @param blockType - `'tool_result'`
95
- * @returns An array of {@link ToolResultBlock} objects.
96
- */
97
- declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
98
-
99
- export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };