@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
@@ -21,7 +21,9 @@ export interface Msg {
21
21
  /** Arbitrary key-value metadata attached to the message. */
22
22
  metadata: Record<string, JSONSerializableObject>;
23
23
  /** ISO-8601 creation timestamp. */
24
- timestamp: string;
24
+ created_at: string;
25
+ /** ISO-8601 finished timestamp. */
26
+ finished_at?: string | null;
25
27
  /** Usage information for the message, such as token counts. */
26
28
  usage?: {
27
29
  inputTokens: number;
@@ -30,17 +32,18 @@ export interface Msg {
30
32
  }
31
33
 
32
34
  /**
33
- * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
34
- *
35
+ * Create a new {@link Msg} object, filling in `id` and `created_at` when omitted.
36
+ * A plain string `content` is automatically wrapped in a single {@link TextBlock}.
35
37
  * @param root0
36
38
  * @param root0.name
37
39
  * @param root0.content
38
40
  * @param root0.role
39
41
  * @param root0.metadata
40
42
  * @param root0.id
41
- * @param root0.timestamp
43
+ * @param root0.created_at
44
+ * @param root0.finished_at
42
45
  * @param root0.usage
43
- * @returns A fully-populated {@link Msg} object.
46
+ * @returns A Msg object.
44
47
  */
45
48
  export function createMsg({
46
49
  name,
@@ -48,11 +51,99 @@ export function createMsg({
48
51
  role,
49
52
  metadata = {},
50
53
  id = crypto.randomUUID(),
51
- timestamp = new Date().toISOString(),
54
+ created_at = new Date().toISOString(),
55
+ finished_at,
52
56
  usage,
53
- }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> &
54
- Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg {
55
- return { id, name, role, content, metadata, timestamp, usage } as Msg;
57
+ }: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> &
58
+ Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {
59
+ content: string | ContentBlock[];
60
+ }): Msg {
61
+ const contentBlocks: ContentBlock[] =
62
+ typeof content === 'string'
63
+ ? [{ id: crypto.randomUUID(), type: 'text', text: content } as TextBlock]
64
+ : content;
65
+ return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
66
+ }
67
+
68
+ /**
69
+ * Create a user {@link Msg}.
70
+ * @param root0
71
+ * @param root0.name
72
+ * @param root0.content
73
+ * @param root0.metadata
74
+ * @param root0.id
75
+ * @param root0.created_at
76
+ * @returns A Msg object with role 'user'.
77
+ */
78
+ export function UserMsg({
79
+ name,
80
+ content,
81
+ metadata = {},
82
+ id = crypto.randomUUID(),
83
+ created_at = new Date().toISOString(),
84
+ }: {
85
+ name: string;
86
+ content: string | ContentBlock[];
87
+ metadata?: Record<string, JSONSerializableObject>;
88
+ id?: string;
89
+ created_at?: string;
90
+ }): Msg {
91
+ return createMsg({ name, content, role: 'user', metadata, id, created_at });
92
+ }
93
+
94
+ /**
95
+ * Create an assistant {@link Msg}.
96
+ * @param root0
97
+ * @param root0.name
98
+ * @param root0.content
99
+ * @param root0.metadata
100
+ * @param root0.id
101
+ * @param root0.created_at
102
+ * @param root0.usage
103
+ * @returns A Msg object with role 'assistant'.
104
+ */
105
+ export function AssistantMsg({
106
+ name,
107
+ content,
108
+ metadata = {},
109
+ id = crypto.randomUUID(),
110
+ created_at = new Date().toISOString(),
111
+ usage,
112
+ }: {
113
+ name: string;
114
+ content: string | ContentBlock[];
115
+ metadata?: Record<string, JSONSerializableObject>;
116
+ id?: string;
117
+ created_at?: string;
118
+ usage?: Msg['usage'];
119
+ }): Msg {
120
+ return createMsg({ name, content, role: 'assistant', metadata, id, created_at, usage });
121
+ }
122
+
123
+ /**
124
+ * Create a system {@link Msg}.
125
+ * @param root0
126
+ * @param root0.name
127
+ * @param root0.content
128
+ * @param root0.metadata
129
+ * @param root0.id
130
+ * @param root0.created_at
131
+ * @returns A Msg object with role 'system'.
132
+ */
133
+ export function SystemMsg({
134
+ name,
135
+ content,
136
+ metadata = {},
137
+ id = crypto.randomUUID(),
138
+ created_at = new Date().toISOString(),
139
+ }: {
140
+ name: string;
141
+ content: string | ContentBlock[];
142
+ metadata?: Record<string, JSONSerializableObject>;
143
+ id?: string;
144
+ created_at?: string;
145
+ }): Msg {
146
+ return createMsg({ name, content, role: 'system', metadata, id, created_at });
56
147
  }
57
148
 
58
149
  /**
@@ -67,9 +158,7 @@ export function createMsg({
67
158
  */
68
159
  export function getTextContent(msg: Msg, separator: string = '\n'): string | null {
69
160
  const textBlocks = msg.content.filter(block => block.type === 'text');
70
- if (textBlocks.length === 0) {
71
- return null;
72
- }
161
+ if (textBlocks.length === 0) return null;
73
162
  return textBlocks.map(block => (block as TextBlock).text).join(separator);
74
163
  }
75
164
 
@@ -82,45 +171,10 @@ export function getTextContent(msg: Msg, separator: string = '\n'): string | nul
82
171
  * @returns An array of all {@link ContentBlock} objects.
83
172
  */
84
173
  export function getContentBlocks(msg: Msg): ContentBlock[];
85
- /**
86
- * Return all {@link TextBlock} objects from a message.
87
- *
88
- * @param msg - The message to read.
89
- * @param blockType - `'text'`
90
- * @returns An array of {@link TextBlock} objects.
91
- */
92
174
  export function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
93
- /**
94
- * Return all {@link ThinkingBlock} objects from a message.
95
- *
96
- * @param msg - The message to read.
97
- * @param blockType - `'thinking'`
98
- * @returns An array of {@link ThinkingBlock} objects.
99
- */
100
175
  export function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
101
- /**
102
- * Return all {@link DataBlock} objects from a message.
103
- *
104
- * @param msg - The message to read.
105
- * @param blockType - `'video'`
106
- * @returns An array of {@link DataBlock} objects.
107
- */
108
176
  export function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
109
- /**
110
- * Return all {@link ToolCallBlock} objects from a message.
111
- *
112
- * @param msg - The message to read.
113
- * @param blockType - `'tool_call'`
114
- * @returns An array of {@link ToolCallBlock} objects.
115
- */
116
177
  export function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
117
- /**
118
- * Return all {@link ToolResultBlock} objects from a message.
119
- *
120
- * @param msg - The message to read.
121
- * @param blockType - `'tool_result'`
122
- * @returns An array of {@link ToolResultBlock} objects.
123
- */
124
178
  export function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
125
179
  export function getContentBlocks(
126
180
  msg: Msg,
@@ -0,0 +1,13 @@
1
+ export enum PermissionBehavior {
2
+ ALLOW = 'allow',
3
+ DENY = 'deny',
4
+ ASK = 'ask',
5
+ PASSTHROUGH = 'passthrough',
6
+ }
7
+
8
+ export interface PermissionRule {
9
+ tool_name: string;
10
+ rule_content: string | null;
11
+ behavior: PermissionBehavior;
12
+ source: string;
13
+ }
@@ -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
  ],
@@ -562,7 +562,7 @@ describe('LocalFileStorage', () => {
562
562
  source: {
563
563
  type: 'url',
564
564
  url: 'https://example.com/image.png',
565
- mediaType: 'image/png',
565
+ media_type: 'image/png',
566
566
  },
567
567
  },
568
568
  { 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;