@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
@@ -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,
@@ -322,7 +322,7 @@ export class Agent {
322
322
  this.toolkit.requireUserConfirm(toolCall.name) &&
323
323
  !this.confirmedToolCallIds.includes(toolCall.id)
324
324
  ) {
325
- toolCall.awaitUserConfirmation = true;
325
+ toolCall.state = 'asking';
326
326
  // Find the continuous tool calls that require user confirmation
327
327
  let i = index + 1;
328
328
  for (; i < pendingToolCalls.length; i++) {
@@ -332,7 +332,7 @@ export class Agent {
332
332
  this.confirmedToolCallIds.includes(nextToolCall.id)
333
333
  )
334
334
  break;
335
- nextToolCall.awaitUserConfirmation = true;
335
+ nextToolCall.state = 'asking';
336
336
  }
337
337
  return {
338
338
  awaitingType: EventType.REQUIRE_USER_CONFIRM,
@@ -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',
@@ -431,12 +431,20 @@ export class Agent {
431
431
  ]);
432
432
  }
433
433
  }
434
- // Remove the tool call from the awaiting state
435
- const processedToolCallIds = event.confirmResults.map(result => result.toolCall.id);
436
- // Set the awaitingUserConfirmation flag to undefined for UI update
434
+ // Update tool call states based on confirm results
435
+ const confirmedIds = new Set(
436
+ event.confirm_results.filter(r => r.confirmed).map(r => r.tool_call.id)
437
+ );
438
+ const deniedIds = new Set(
439
+ event.confirm_results.filter(r => !r.confirmed).map(r => r.tool_call.id)
440
+ );
437
441
  this.context.at(-1)?.content.forEach(content => {
438
- if (content.type === 'tool_call' && processedToolCallIds.includes(content.id)) {
439
- delete content.awaitUserConfirmation;
442
+ if (content.type === 'tool_call') {
443
+ if (confirmedIds.has(content.id)) {
444
+ content.state = 'allowed';
445
+ } else if (deniedIds.has(content.id)) {
446
+ content.state = 'finished';
447
+ }
440
448
  }
441
449
  });
442
450
  }
@@ -449,13 +457,13 @@ export class Agent {
449
457
  // Yield the run started event
450
458
  yield {
451
459
  id: crypto.randomUUID(),
452
- type: EventType.RUN_STARTED,
453
- createdAt: new Date().toISOString(),
454
- sessionId: '',
455
- replyId: this.replyId,
460
+ type: EventType.REPLY_START,
461
+ created_at: new Date().toISOString(),
462
+ session_id: '',
463
+ reply_id: this.replyId,
456
464
  name: this.name,
457
465
  role: 'assistant',
458
- } as RunStartedEvent;
466
+ } as ReplyStartEvent;
459
467
  }
460
468
 
461
469
  // Store the incoming message into memory
@@ -490,10 +498,10 @@ export class Agent {
490
498
  if (awaitingType) {
491
499
  yield {
492
500
  id: crypto.randomUUID(),
493
- createdAt: new Date().toISOString(),
501
+ created_at: new Date().toISOString(),
494
502
  type: awaitingType,
495
- replyId: this.replyId,
496
- toolCalls: awaitingToolCalls,
503
+ reply_id: this.replyId,
504
+ tool_calls: awaitingToolCalls,
497
505
  };
498
506
 
499
507
  return createMsg({
@@ -528,11 +536,11 @@ export class Agent {
528
536
  // Yield the run finished event
529
537
  yield {
530
538
  id: crypto.randomUUID(),
531
- type: EventType.RUN_FINISHED,
532
- createdAt: new Date().toISOString(),
533
- sessionId: '',
534
- replyId: this.replyId,
535
- } as RunFinishedEvent;
539
+ type: EventType.REPLY_END,
540
+ created_at: new Date().toISOString(),
541
+ session_id: '',
542
+ reply_id: this.replyId,
543
+ } as ReplyEndEvent;
536
544
 
537
545
  return createMsg({
538
546
  id: this.replyId,
@@ -557,11 +565,11 @@ export class Agent {
557
565
  const tools = this.toolkit.getJSONSchemas();
558
566
  yield {
559
567
  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;
568
+ created_at: new Date().toISOString(),
569
+ type: EventType.MODEL_CALL_START,
570
+ reply_id: this.replyId,
571
+ model_name: this.model.modelName,
572
+ } as ModelCallStartEvent;
565
573
  const res = await this.model.call({
566
574
  messages: [
567
575
  createMsg({
@@ -620,41 +628,41 @@ export class Agent {
620
628
  if (blockIds.textBlockId) {
621
629
  yield {
622
630
  id: crypto.randomUUID(),
623
- createdAt: new Date().toISOString(),
631
+ created_at: new Date().toISOString(),
624
632
  type: EventType.TEXT_BLOCK_END,
625
- replyId: this.replyId,
626
- blockId: blockIds.textBlockId,
633
+ reply_id: this.replyId,
634
+ block_id: blockIds.textBlockId,
627
635
  } as TextBlockEndEvent;
628
636
  }
629
637
  if (blockIds.thinkingBlockId) {
630
638
  yield {
631
639
  id: crypto.randomUUID(),
632
- createdAt: new Date().toISOString(),
640
+ created_at: new Date().toISOString(),
633
641
  type: EventType.THINKING_BLOCK_END,
634
- replyId: this.replyId,
635
- blockId: blockIds.thinkingBlockId,
642
+ reply_id: this.replyId,
643
+ block_id: blockIds.thinkingBlockId,
636
644
  } as ThinkingBlockEndEvent;
637
645
  }
638
646
  if (blockIds.toolCallIds.length > 0) {
639
- for (const toolCallId of blockIds.toolCallIds) {
647
+ for (const tool_call_id of blockIds.toolCallIds) {
640
648
  yield {
641
649
  id: crypto.randomUUID(),
642
- createdAt: new Date().toISOString(),
650
+ created_at: new Date().toISOString(),
643
651
  type: EventType.TOOL_CALL_END,
644
- replyId: this.replyId,
645
- toolCallId,
652
+ reply_id: this.replyId,
653
+ tool_call_id,
646
654
  } as ToolCallEndEvent;
647
655
  }
648
656
  }
649
657
 
650
658
  yield {
651
659
  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;
660
+ created_at: new Date().toISOString(),
661
+ type: EventType.MODEL_CALL_END,
662
+ reply_id: this.replyId,
663
+ input_tokens: completedResponse.usage?.inputTokens || 0,
664
+ output_tokens: completedResponse.usage?.outputTokens || 0,
665
+ } as ModelCallEndEvent;
658
666
 
659
667
  return completedResponse;
660
668
  }
@@ -672,10 +680,10 @@ export class Agent {
672
680
  yield {
673
681
  type: EventType.TOOL_RESULT_START,
674
682
  id: crypto.randomUUID(),
675
- createdAt: new Date().toISOString(),
676
- replyId: this.replyId,
677
- toolCallId: options.toolCall.id,
678
- toolCallName: options.toolCall.name,
683
+ created_at: new Date().toISOString(),
684
+ reply_id: this.replyId,
685
+ tool_call_id: options.toolCall.id,
686
+ tool_call_name: options.toolCall.name,
679
687
  } as ToolResultStartEvent;
680
688
 
681
689
  while (true) {
@@ -741,18 +749,18 @@ export class Agent {
741
749
  responseId.textBlockId = crypto.randomUUID();
742
750
  yield {
743
751
  id: crypto.randomUUID(),
744
- createdAt: new Date().toISOString(),
752
+ created_at: new Date().toISOString(),
745
753
  type: EventType.TEXT_BLOCK_START,
746
- replyId: this.replyId,
747
- blockId: responseId.textBlockId,
754
+ reply_id: this.replyId,
755
+ block_id: responseId.textBlockId,
748
756
  } as TextBlockStartEvent;
749
757
  }
750
758
  yield {
751
759
  id: crypto.randomUUID(),
752
- createdAt: new Date().toISOString(),
760
+ created_at: new Date().toISOString(),
753
761
  type: EventType.TEXT_BLOCK_DELTA,
754
- replyId: this.replyId,
755
- blockId: responseId.textBlockId,
762
+ reply_id: this.replyId,
763
+ block_id: responseId.textBlockId,
756
764
  delta: block.text,
757
765
  } as TextBlockDeltaEvent;
758
766
  break;
@@ -762,18 +770,18 @@ export class Agent {
762
770
  responseId.thinkingBlockId = crypto.randomUUID();
763
771
  yield {
764
772
  id: crypto.randomUUID(),
765
- createdAt: new Date().toISOString(),
773
+ created_at: new Date().toISOString(),
766
774
  type: EventType.THINKING_BLOCK_START,
767
- replyId: this.replyId,
768
- blockId: responseId.thinkingBlockId,
775
+ reply_id: this.replyId,
776
+ block_id: responseId.thinkingBlockId,
769
777
  } as ThinkingBlockStartEvent;
770
778
  }
771
779
  yield {
772
780
  id: crypto.randomUUID(),
773
- createdAt: new Date().toISOString(),
781
+ created_at: new Date().toISOString(),
774
782
  type: EventType.THINKING_BLOCK_DELTA,
775
- replyId: this.replyId,
776
- blockId: responseId.thinkingBlockId,
783
+ reply_id: this.replyId,
784
+ block_id: responseId.thinkingBlockId,
777
785
  delta: block.thinking,
778
786
  } as ThinkingBlockDeltaEvent;
779
787
  break;
@@ -784,19 +792,19 @@ export class Agent {
784
792
  yield {
785
793
  id: crypto.randomUUID(),
786
794
  type: EventType.TOOL_CALL_START,
787
- createdAt: new Date().toISOString(),
788
- replyId: this.replyId,
789
- toolCallId: block.id,
790
- toolCallName: block.name,
795
+ created_at: new Date().toISOString(),
796
+ reply_id: this.replyId,
797
+ tool_call_id: block.id,
798
+ tool_call_name: block.name,
791
799
  } as ToolCallStartEvent;
792
800
  }
793
801
  yield {
794
802
  id: crypto.randomUUID(),
795
- createdAt: new Date().toISOString(),
803
+ created_at: new Date().toISOString(),
796
804
  type: EventType.TOOL_CALL_DELTA,
797
805
  delta: block.input,
798
- replyId: this.replyId,
799
- toolCallId: block.id,
806
+ reply_id: this.replyId,
807
+ tool_call_id: block.id,
800
808
  } as ToolCallDeltaEvent;
801
809
  }
802
810
  }
@@ -816,10 +824,10 @@ export class Agent {
816
824
  case 'text':
817
825
  yield {
818
826
  id: crypto.randomUUID(),
819
- createdAt: new Date().toISOString(),
827
+ created_at: new Date().toISOString(),
820
828
  type: EventType.TOOL_RESULT_TEXT_DELTA,
821
- replyId: this.replyId,
822
- toolCallId: toolCall.id,
829
+ reply_id: this.replyId,
830
+ tool_call_id: toolCall.id,
823
831
  delta: block.text,
824
832
  } as ToolResultTextDeltaEvent;
825
833
  break;
@@ -828,33 +836,33 @@ export class Agent {
828
836
  if (block.source.type === 'base64') {
829
837
  yield {
830
838
  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,
839
+ created_at: new Date().toISOString(),
840
+ type: EventType.TOOL_RESULT_DATA_DELTA,
841
+ reply_id: this.replyId,
842
+ tool_call_id: toolCall.id,
843
+ media_type: block.source.media_type,
836
844
  data: block.source.data,
837
- } as ToolResultBinaryDeltaEvent;
845
+ } as ToolResultDataDeltaEvent;
838
846
  } else if (block.source.type === 'url') {
839
847
  yield {
840
848
  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,
849
+ created_at: new Date().toISOString(),
850
+ type: EventType.TOOL_RESULT_DATA_DELTA,
851
+ reply_id: this.replyId,
852
+ tool_call_id: toolCall.id,
853
+ media_type: block.source.media_type,
846
854
  url: block.source.url,
847
- } as ToolResultBinaryDeltaEvent;
855
+ } as ToolResultDataDeltaEvent;
848
856
  }
849
857
  break;
850
858
  }
851
859
  }
852
860
  yield {
853
861
  id: crypto.randomUUID(),
854
- createdAt: new Date().toISOString(),
862
+ created_at: new Date().toISOString(),
855
863
  type: EventType.TOOL_RESULT_END,
856
- replyId: this.replyId,
857
- toolCallId: toolCall.id,
864
+ reply_id: this.replyId,
865
+ tool_call_id: toolCall.id,
858
866
  state: toolRes.state,
859
867
  } as ToolResultEndEvent;
860
868
  }
@@ -865,7 +873,7 @@ export class Agent {
865
873
  */
866
874
  public async toJSON() {
867
875
  return {
868
- replyId: this.replyId,
876
+ reply_id: this.replyId,
869
877
  confirmedToolCallIds: this.confirmedToolCallIds,
870
878
  curIter: this.curIter,
871
879
  };
@@ -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');