@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
@@ -14,10 +14,10 @@ import { ActingOptions, ObserveOptions, ReasoningOptions, ReplyOptions } from '.
14
14
  import {
15
15
  AgentEvent,
16
16
  EventType,
17
- ModelCallEndedEvent,
18
- ModelCallStartedEvent,
19
- RunFinishedEvent,
20
- RunStartedEvent,
17
+ ModelCallEndEvent,
18
+ ModelCallStartEvent,
19
+ ReplyEndEvent,
20
+ ReplyStartEvent,
21
21
  TextBlockDeltaEvent,
22
22
  TextBlockEndEvent,
23
23
  TextBlockStartEvent,
@@ -27,7 +27,7 @@ import {
27
27
  ToolCallDeltaEvent,
28
28
  ToolCallEndEvent,
29
29
  ToolCallStartEvent,
30
- ToolResultBinaryDeltaEvent,
30
+ ToolResultDataDeltaEvent,
31
31
  ToolResultEndEvent,
32
32
  ToolResultStartEvent,
33
33
  ToolResultTextDeltaEvent,
@@ -194,7 +194,7 @@ export class Agent {
194
194
  agentId: this.name,
195
195
  context: this.context,
196
196
  metadata: {
197
- replyId: this.replyId,
197
+ reply_id: this.replyId,
198
198
  curIter: this.curIter,
199
199
  curSummary: this.curSummary,
200
200
  },
@@ -383,47 +383,47 @@ export class Agent {
383
383
  const event = options.event;
384
384
  if (event.type === EventType.EXTERNAL_EXECUTION_RESULT) {
385
385
  // Record the tool results into context and go on acting
386
- this._saveToContext(event.executionResults);
386
+ this._saveToContext(event.execution_results);
387
387
  } else if (event.type === EventType.USER_CONFIRM_RESULT) {
388
- for (const result of event.confirmResults) {
388
+ for (const result of event.confirm_results) {
389
389
  if (result.confirmed) {
390
- this.confirmedToolCallIds.push(result.toolCall.id);
390
+ this.confirmedToolCallIds.push(result.tool_call.id);
391
391
  } else {
392
392
  // If user rejected, add a rejection result and handle the pending tool calls
393
- const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.toolCall.name}"!</system-info>`;
393
+ const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`;
394
394
  yield {
395
395
  id: crypto.randomUUID(),
396
- createdAt: new Date().toISOString(),
396
+ created_at: new Date().toISOString(),
397
397
  type: EventType.TOOL_RESULT_START,
398
- replyId: this.replyId,
399
- toolCallId: result.toolCall.id,
398
+ reply_id: this.replyId,
399
+ tool_call_id: result.tool_call.id,
400
400
  } as ToolResultStartEvent;
401
401
  yield {
402
402
  id: crypto.randomUUID(),
403
- createdAt: new Date().toISOString(),
403
+ created_at: new Date().toISOString(),
404
404
  type: EventType.TOOL_RESULT_TEXT_DELTA,
405
- replyId: this.replyId,
406
- toolCallId: result.toolCall.id,
405
+ reply_id: this.replyId,
406
+ tool_call_id: result.tool_call.id,
407
407
  delta: rejectionRes,
408
408
  } as ToolResultTextDeltaEvent;
409
409
  yield {
410
410
  id: crypto.randomUUID(),
411
- createdAt: new Date().toISOString(),
411
+ created_at: new Date().toISOString(),
412
412
  type: EventType.TOOL_RESULT_END,
413
- replyId: this.replyId,
414
- toolCallId: result.toolCall.id,
413
+ reply_id: this.replyId,
414
+ tool_call_id: result.tool_call.id,
415
415
  state: 'interrupted',
416
416
  } as ToolResultEndEvent;
417
417
  this._saveToContext([
418
418
  {
419
419
  type: 'tool_result',
420
- id: result.toolCall.id,
421
- name: result.toolCall.name,
420
+ id: result.tool_call.id,
421
+ name: result.tool_call.name,
422
422
  output: [
423
423
  {
424
424
  id: crypto.randomUUID(),
425
425
  type: 'text',
426
- text: `<system-info>**Note** the user rejected the execution of tool "${result.toolCall.name}"!</system-info>`,
426
+ text: `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`,
427
427
  },
428
428
  ],
429
429
  state: 'interrupted',
@@ -432,7 +432,9 @@ export class Agent {
432
432
  }
433
433
  }
434
434
  // Remove the tool call from the awaiting state
435
- const processedToolCallIds = event.confirmResults.map(result => result.toolCall.id);
435
+ const processedToolCallIds = event.confirm_results.map(
436
+ result => result.tool_call.id
437
+ );
436
438
  // Set the awaitingUserConfirmation flag to undefined for UI update
437
439
  this.context.at(-1)?.content.forEach(content => {
438
440
  if (content.type === 'tool_call' && processedToolCallIds.includes(content.id)) {
@@ -449,13 +451,13 @@ export class Agent {
449
451
  // Yield the run started event
450
452
  yield {
451
453
  id: crypto.randomUUID(),
452
- type: EventType.RUN_STARTED,
453
- createdAt: new Date().toISOString(),
454
- sessionId: '',
455
- replyId: this.replyId,
454
+ type: EventType.REPLY_START,
455
+ created_at: new Date().toISOString(),
456
+ session_id: '',
457
+ reply_id: this.replyId,
456
458
  name: this.name,
457
459
  role: 'assistant',
458
- } as RunStartedEvent;
460
+ } as ReplyStartEvent;
459
461
  }
460
462
 
461
463
  // Store the incoming message into memory
@@ -490,10 +492,10 @@ export class Agent {
490
492
  if (awaitingType) {
491
493
  yield {
492
494
  id: crypto.randomUUID(),
493
- createdAt: new Date().toISOString(),
495
+ created_at: new Date().toISOString(),
494
496
  type: awaitingType,
495
- replyId: this.replyId,
496
- toolCalls: awaitingToolCalls,
497
+ reply_id: this.replyId,
498
+ tool_calls: awaitingToolCalls,
497
499
  };
498
500
 
499
501
  return createMsg({
@@ -528,11 +530,11 @@ export class Agent {
528
530
  // Yield the run finished event
529
531
  yield {
530
532
  id: crypto.randomUUID(),
531
- type: EventType.RUN_FINISHED,
532
- createdAt: new Date().toISOString(),
533
- sessionId: '',
534
- replyId: this.replyId,
535
- } as RunFinishedEvent;
533
+ type: EventType.REPLY_END,
534
+ created_at: new Date().toISOString(),
535
+ session_id: '',
536
+ reply_id: this.replyId,
537
+ } as ReplyEndEvent;
536
538
 
537
539
  return createMsg({
538
540
  id: this.replyId,
@@ -557,11 +559,11 @@ export class Agent {
557
559
  const tools = this.toolkit.getJSONSchemas();
558
560
  yield {
559
561
  id: crypto.randomUUID(),
560
- createdAt: new Date().toISOString(),
561
- type: EventType.MODEL_CALL_STARTED,
562
- replyId: this.replyId,
563
- modelName: this.model.modelName,
564
- } as ModelCallStartedEvent;
562
+ created_at: new Date().toISOString(),
563
+ type: EventType.MODEL_CALL_START,
564
+ reply_id: this.replyId,
565
+ model_name: this.model.modelName,
566
+ } as ModelCallStartEvent;
565
567
  const res = await this.model.call({
566
568
  messages: [
567
569
  createMsg({
@@ -620,41 +622,41 @@ export class Agent {
620
622
  if (blockIds.textBlockId) {
621
623
  yield {
622
624
  id: crypto.randomUUID(),
623
- createdAt: new Date().toISOString(),
625
+ created_at: new Date().toISOString(),
624
626
  type: EventType.TEXT_BLOCK_END,
625
- replyId: this.replyId,
626
- blockId: blockIds.textBlockId,
627
+ reply_id: this.replyId,
628
+ block_id: blockIds.textBlockId,
627
629
  } as TextBlockEndEvent;
628
630
  }
629
631
  if (blockIds.thinkingBlockId) {
630
632
  yield {
631
633
  id: crypto.randomUUID(),
632
- createdAt: new Date().toISOString(),
634
+ created_at: new Date().toISOString(),
633
635
  type: EventType.THINKING_BLOCK_END,
634
- replyId: this.replyId,
635
- blockId: blockIds.thinkingBlockId,
636
+ reply_id: this.replyId,
637
+ block_id: blockIds.thinkingBlockId,
636
638
  } as ThinkingBlockEndEvent;
637
639
  }
638
640
  if (blockIds.toolCallIds.length > 0) {
639
- for (const toolCallId of blockIds.toolCallIds) {
641
+ for (const tool_call_id of blockIds.toolCallIds) {
640
642
  yield {
641
643
  id: crypto.randomUUID(),
642
- createdAt: new Date().toISOString(),
644
+ created_at: new Date().toISOString(),
643
645
  type: EventType.TOOL_CALL_END,
644
- replyId: this.replyId,
645
- toolCallId,
646
+ reply_id: this.replyId,
647
+ tool_call_id,
646
648
  } as ToolCallEndEvent;
647
649
  }
648
650
  }
649
651
 
650
652
  yield {
651
653
  id: crypto.randomUUID(),
652
- createdAt: new Date().toISOString(),
653
- type: EventType.MODEL_CALL_ENDED,
654
- replyId: this.replyId,
655
- inputTokens: completedResponse.usage?.inputTokens || 0,
656
- outputTokens: completedResponse.usage?.outputTokens || 0,
657
- } as ModelCallEndedEvent;
654
+ created_at: new Date().toISOString(),
655
+ type: EventType.MODEL_CALL_END,
656
+ reply_id: this.replyId,
657
+ input_tokens: completedResponse.usage?.inputTokens || 0,
658
+ output_tokens: completedResponse.usage?.outputTokens || 0,
659
+ } as ModelCallEndEvent;
658
660
 
659
661
  return completedResponse;
660
662
  }
@@ -672,10 +674,10 @@ export class Agent {
672
674
  yield {
673
675
  type: EventType.TOOL_RESULT_START,
674
676
  id: crypto.randomUUID(),
675
- createdAt: new Date().toISOString(),
676
- replyId: this.replyId,
677
- toolCallId: options.toolCall.id,
678
- toolCallName: options.toolCall.name,
677
+ created_at: new Date().toISOString(),
678
+ reply_id: this.replyId,
679
+ tool_call_id: options.toolCall.id,
680
+ tool_call_name: options.toolCall.name,
679
681
  } as ToolResultStartEvent;
680
682
 
681
683
  while (true) {
@@ -741,18 +743,18 @@ export class Agent {
741
743
  responseId.textBlockId = crypto.randomUUID();
742
744
  yield {
743
745
  id: crypto.randomUUID(),
744
- createdAt: new Date().toISOString(),
746
+ created_at: new Date().toISOString(),
745
747
  type: EventType.TEXT_BLOCK_START,
746
- replyId: this.replyId,
747
- blockId: responseId.textBlockId,
748
+ reply_id: this.replyId,
749
+ block_id: responseId.textBlockId,
748
750
  } as TextBlockStartEvent;
749
751
  }
750
752
  yield {
751
753
  id: crypto.randomUUID(),
752
- createdAt: new Date().toISOString(),
754
+ created_at: new Date().toISOString(),
753
755
  type: EventType.TEXT_BLOCK_DELTA,
754
- replyId: this.replyId,
755
- blockId: responseId.textBlockId,
756
+ reply_id: this.replyId,
757
+ block_id: responseId.textBlockId,
756
758
  delta: block.text,
757
759
  } as TextBlockDeltaEvent;
758
760
  break;
@@ -762,18 +764,18 @@ export class Agent {
762
764
  responseId.thinkingBlockId = crypto.randomUUID();
763
765
  yield {
764
766
  id: crypto.randomUUID(),
765
- createdAt: new Date().toISOString(),
767
+ created_at: new Date().toISOString(),
766
768
  type: EventType.THINKING_BLOCK_START,
767
- replyId: this.replyId,
768
- blockId: responseId.thinkingBlockId,
769
+ reply_id: this.replyId,
770
+ block_id: responseId.thinkingBlockId,
769
771
  } as ThinkingBlockStartEvent;
770
772
  }
771
773
  yield {
772
774
  id: crypto.randomUUID(),
773
- createdAt: new Date().toISOString(),
775
+ created_at: new Date().toISOString(),
774
776
  type: EventType.THINKING_BLOCK_DELTA,
775
- replyId: this.replyId,
776
- blockId: responseId.thinkingBlockId,
777
+ reply_id: this.replyId,
778
+ block_id: responseId.thinkingBlockId,
777
779
  delta: block.thinking,
778
780
  } as ThinkingBlockDeltaEvent;
779
781
  break;
@@ -784,19 +786,19 @@ export class Agent {
784
786
  yield {
785
787
  id: crypto.randomUUID(),
786
788
  type: EventType.TOOL_CALL_START,
787
- createdAt: new Date().toISOString(),
788
- replyId: this.replyId,
789
- toolCallId: block.id,
790
- toolCallName: block.name,
789
+ created_at: new Date().toISOString(),
790
+ reply_id: this.replyId,
791
+ tool_call_id: block.id,
792
+ tool_call_name: block.name,
791
793
  } as ToolCallStartEvent;
792
794
  }
793
795
  yield {
794
796
  id: crypto.randomUUID(),
795
- createdAt: new Date().toISOString(),
797
+ created_at: new Date().toISOString(),
796
798
  type: EventType.TOOL_CALL_DELTA,
797
799
  delta: block.input,
798
- replyId: this.replyId,
799
- toolCallId: block.id,
800
+ reply_id: this.replyId,
801
+ tool_call_id: block.id,
800
802
  } as ToolCallDeltaEvent;
801
803
  }
802
804
  }
@@ -816,10 +818,10 @@ export class Agent {
816
818
  case 'text':
817
819
  yield {
818
820
  id: crypto.randomUUID(),
819
- createdAt: new Date().toISOString(),
821
+ created_at: new Date().toISOString(),
820
822
  type: EventType.TOOL_RESULT_TEXT_DELTA,
821
- replyId: this.replyId,
822
- toolCallId: toolCall.id,
823
+ reply_id: this.replyId,
824
+ tool_call_id: toolCall.id,
823
825
  delta: block.text,
824
826
  } as ToolResultTextDeltaEvent;
825
827
  break;
@@ -828,33 +830,33 @@ export class Agent {
828
830
  if (block.source.type === 'base64') {
829
831
  yield {
830
832
  id: crypto.randomUUID(),
831
- createdAt: new Date().toISOString(),
832
- type: EventType.TOOL_RESULT_BINARY_DELTA,
833
- replyId: this.replyId,
834
- toolCallId: toolCall.id,
835
- mediaType: block.source.mediaType,
833
+ created_at: new Date().toISOString(),
834
+ type: EventType.TOOL_RESULT_DATA_DELTA,
835
+ reply_id: this.replyId,
836
+ tool_call_id: toolCall.id,
837
+ media_type: block.source.media_type,
836
838
  data: block.source.data,
837
- } as ToolResultBinaryDeltaEvent;
839
+ } as ToolResultDataDeltaEvent;
838
840
  } else if (block.source.type === 'url') {
839
841
  yield {
840
842
  id: crypto.randomUUID(),
841
- createdAt: new Date().toISOString(),
842
- type: EventType.TOOL_RESULT_BINARY_DELTA,
843
- replyId: this.replyId,
844
- toolCallId: toolCall.id,
845
- mediaType: block.source.mediaType,
843
+ created_at: new Date().toISOString(),
844
+ type: EventType.TOOL_RESULT_DATA_DELTA,
845
+ reply_id: this.replyId,
846
+ tool_call_id: toolCall.id,
847
+ media_type: block.source.media_type,
846
848
  url: block.source.url,
847
- } as ToolResultBinaryDeltaEvent;
849
+ } as ToolResultDataDeltaEvent;
848
850
  }
849
851
  break;
850
852
  }
851
853
  }
852
854
  yield {
853
855
  id: crypto.randomUUID(),
854
- createdAt: new Date().toISOString(),
856
+ created_at: new Date().toISOString(),
855
857
  type: EventType.TOOL_RESULT_END,
856
- replyId: this.replyId,
857
- toolCallId: toolCall.id,
858
+ reply_id: this.replyId,
859
+ tool_call_id: toolCall.id,
858
860
  state: toolRes.state,
859
861
  } as ToolResultEndEvent;
860
862
  }
@@ -865,7 +867,7 @@ export class Agent {
865
867
  */
866
868
  public async toJSON() {
867
869
  return {
868
- replyId: this.replyId,
870
+ reply_id: this.replyId,
869
871
  confirmedToolCallIds: this.confirmedToolCallIds,
870
872
  curIter: this.curIter,
871
873
  };
@@ -39,7 +39,7 @@ const getUserInput = (): Promise<string> => {
39
39
  };
40
40
 
41
41
  /**
42
- *
42
+ * The main functions run a compression test for the agent.
43
43
  */
44
44
  async function main() {
45
45
  console.log('Compression test started. Type "exit" to quit.\n');