@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
@@ -8,10 +8,12 @@ function createMsg({
8
8
  role,
9
9
  metadata = {},
10
10
  id = crypto.randomUUID(),
11
- timestamp = (/* @__PURE__ */ new Date()).toISOString(),
11
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
12
+ finished_at,
12
13
  usage
13
14
  }) {
14
- return { id, name, role, content, metadata, timestamp, usage };
15
+ const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
16
+ return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
15
17
  }
16
18
  function getContentBlocks(msg, blockType) {
17
19
  if (!blockType) return msg.content;
@@ -670,7 +672,7 @@ var Agent = class {
670
672
  agentId: this.name,
671
673
  context: this.context,
672
674
  metadata: {
673
- replyId: this.replyId,
675
+ reply_id: this.replyId,
674
676
  curIter: this.curIter,
675
677
  curSummary: this.curSummary
676
678
  }
@@ -826,46 +828,46 @@ var Agent = class {
826
828
  }
827
829
  const event = options.event;
828
830
  if (event.type === "EXTERNAL_EXECUTION_RESULT" /* EXTERNAL_EXECUTION_RESULT */) {
829
- this._saveToContext(event.executionResults);
831
+ this._saveToContext(event.execution_results);
830
832
  } else if (event.type === "USER_CONFIRM_RESULT" /* USER_CONFIRM_RESULT */) {
831
- for (const result of event.confirmResults) {
833
+ for (const result of event.confirm_results) {
832
834
  if (result.confirmed) {
833
- this.confirmedToolCallIds.push(result.toolCall.id);
835
+ this.confirmedToolCallIds.push(result.tool_call.id);
834
836
  } else {
835
- const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.toolCall.name}"!</system-info>`;
837
+ const rejectionRes = `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`;
836
838
  yield {
837
839
  id: crypto.randomUUID(),
838
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
840
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
839
841
  type: "TOOL_RESULT_START" /* TOOL_RESULT_START */,
840
- replyId: this.replyId,
841
- toolCallId: result.toolCall.id
842
+ reply_id: this.replyId,
843
+ tool_call_id: result.tool_call.id
842
844
  };
843
845
  yield {
844
846
  id: crypto.randomUUID(),
845
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
847
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
846
848
  type: "TOOL_RESULT_TEXT_DELTA" /* TOOL_RESULT_TEXT_DELTA */,
847
- replyId: this.replyId,
848
- toolCallId: result.toolCall.id,
849
+ reply_id: this.replyId,
850
+ tool_call_id: result.tool_call.id,
849
851
  delta: rejectionRes
850
852
  };
851
853
  yield {
852
854
  id: crypto.randomUUID(),
853
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
855
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
854
856
  type: "TOOL_RESULT_END" /* TOOL_RESULT_END */,
855
- replyId: this.replyId,
856
- toolCallId: result.toolCall.id,
857
+ reply_id: this.replyId,
858
+ tool_call_id: result.tool_call.id,
857
859
  state: "interrupted"
858
860
  };
859
861
  this._saveToContext([
860
862
  {
861
863
  type: "tool_result",
862
- id: result.toolCall.id,
863
- name: result.toolCall.name,
864
+ id: result.tool_call.id,
865
+ name: result.tool_call.name,
864
866
  output: [
865
867
  {
866
868
  id: crypto.randomUUID(),
867
869
  type: "text",
868
- text: `<system-info>**Note** the user rejected the execution of tool "${result.toolCall.name}"!</system-info>`
870
+ text: `<system-info>**Note** the user rejected the execution of tool "${result.tool_call.name}"!</system-info>`
869
871
  }
870
872
  ],
871
873
  state: "interrupted"
@@ -873,7 +875,9 @@ var Agent = class {
873
875
  ]);
874
876
  }
875
877
  }
876
- const processedToolCallIds = event.confirmResults.map((result) => result.toolCall.id);
878
+ const processedToolCallIds = event.confirm_results.map(
879
+ (result) => result.tool_call.id
880
+ );
877
881
  this.context.at(-1)?.content.forEach((content) => {
878
882
  if (content.type === "tool_call" && processedToolCallIds.includes(content.id)) {
879
883
  delete content.awaitUserConfirmation;
@@ -886,10 +890,10 @@ var Agent = class {
886
890
  this.confirmedToolCallIds = [];
887
891
  yield {
888
892
  id: crypto.randomUUID(),
889
- type: "RUN_STARTED" /* RUN_STARTED */,
890
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
891
- sessionId: "",
892
- replyId: this.replyId,
893
+ type: "REPLY_START" /* REPLY_START */,
894
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
895
+ session_id: "",
896
+ reply_id: this.replyId,
893
897
  name: this.name,
894
898
  role: "assistant"
895
899
  };
@@ -917,10 +921,10 @@ var Agent = class {
917
921
  if (awaitingType) {
918
922
  yield {
919
923
  id: crypto.randomUUID(),
920
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
924
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
921
925
  type: awaitingType,
922
- replyId: this.replyId,
923
- toolCalls: awaitingToolCalls
926
+ reply_id: this.replyId,
927
+ tool_calls: awaitingToolCalls
924
928
  };
925
929
  return createMsg({
926
930
  name: this.name,
@@ -943,10 +947,10 @@ var Agent = class {
943
947
  }
944
948
  yield {
945
949
  id: crypto.randomUUID(),
946
- type: "RUN_FINISHED" /* RUN_FINISHED */,
947
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
948
- sessionId: "",
949
- replyId: this.replyId
950
+ type: "REPLY_END" /* REPLY_END */,
951
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
952
+ session_id: "",
953
+ reply_id: this.replyId
950
954
  };
951
955
  return createMsg({
952
956
  id: this.replyId,
@@ -968,10 +972,10 @@ var Agent = class {
968
972
  const tools = this.toolkit.getJSONSchemas();
969
973
  yield {
970
974
  id: crypto.randomUUID(),
971
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
972
- type: "MODEL_CALL_STARTED" /* MODEL_CALL_STARTED */,
973
- replyId: this.replyId,
974
- modelName: this.model.modelName
975
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
976
+ type: "MODEL_CALL_START" /* MODEL_CALL_START */,
977
+ reply_id: this.replyId,
978
+ model_name: this.model.modelName
975
979
  };
976
980
  const res = await this.model.call({
977
981
  messages: [
@@ -1017,39 +1021,39 @@ var Agent = class {
1017
1021
  if (blockIds.textBlockId) {
1018
1022
  yield {
1019
1023
  id: crypto.randomUUID(),
1020
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1024
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1021
1025
  type: "TEXT_BLOCK_END" /* TEXT_BLOCK_END */,
1022
- replyId: this.replyId,
1023
- blockId: blockIds.textBlockId
1026
+ reply_id: this.replyId,
1027
+ block_id: blockIds.textBlockId
1024
1028
  };
1025
1029
  }
1026
1030
  if (blockIds.thinkingBlockId) {
1027
1031
  yield {
1028
1032
  id: crypto.randomUUID(),
1029
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1033
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1030
1034
  type: "THINKING_BLOCK_END" /* THINKING_BLOCK_END */,
1031
- replyId: this.replyId,
1032
- blockId: blockIds.thinkingBlockId
1035
+ reply_id: this.replyId,
1036
+ block_id: blockIds.thinkingBlockId
1033
1037
  };
1034
1038
  }
1035
1039
  if (blockIds.toolCallIds.length > 0) {
1036
- for (const toolCallId of blockIds.toolCallIds) {
1040
+ for (const tool_call_id of blockIds.toolCallIds) {
1037
1041
  yield {
1038
1042
  id: crypto.randomUUID(),
1039
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1043
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1040
1044
  type: "TOOL_CALL_END" /* TOOL_CALL_END */,
1041
- replyId: this.replyId,
1042
- toolCallId
1045
+ reply_id: this.replyId,
1046
+ tool_call_id
1043
1047
  };
1044
1048
  }
1045
1049
  }
1046
1050
  yield {
1047
1051
  id: crypto.randomUUID(),
1048
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1049
- type: "MODEL_CALL_ENDED" /* MODEL_CALL_ENDED */,
1050
- replyId: this.replyId,
1051
- inputTokens: completedResponse.usage?.inputTokens || 0,
1052
- outputTokens: completedResponse.usage?.outputTokens || 0
1052
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1053
+ type: "MODEL_CALL_END" /* MODEL_CALL_END */,
1054
+ reply_id: this.replyId,
1055
+ input_tokens: completedResponse.usage?.inputTokens || 0,
1056
+ output_tokens: completedResponse.usage?.outputTokens || 0
1053
1057
  };
1054
1058
  return completedResponse;
1055
1059
  }
@@ -1065,10 +1069,10 @@ var Agent = class {
1065
1069
  yield {
1066
1070
  type: "TOOL_RESULT_START" /* TOOL_RESULT_START */,
1067
1071
  id: crypto.randomUUID(),
1068
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1069
- replyId: this.replyId,
1070
- toolCallId: options.toolCall.id,
1071
- toolCallName: options.toolCall.name
1072
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1073
+ reply_id: this.replyId,
1074
+ tool_call_id: options.toolCall.id,
1075
+ tool_call_name: options.toolCall.name
1072
1076
  };
1073
1077
  while (true) {
1074
1078
  const { value, done } = await res.next();
@@ -1120,18 +1124,18 @@ var Agent = class {
1120
1124
  responseId.textBlockId = crypto.randomUUID();
1121
1125
  yield {
1122
1126
  id: crypto.randomUUID(),
1123
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1127
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1124
1128
  type: "TEXT_BLOCK_START" /* TEXT_BLOCK_START */,
1125
- replyId: this.replyId,
1126
- blockId: responseId.textBlockId
1129
+ reply_id: this.replyId,
1130
+ block_id: responseId.textBlockId
1127
1131
  };
1128
1132
  }
1129
1133
  yield {
1130
1134
  id: crypto.randomUUID(),
1131
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1135
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1132
1136
  type: "TEXT_BLOCK_DELTA" /* TEXT_BLOCK_DELTA */,
1133
- replyId: this.replyId,
1134
- blockId: responseId.textBlockId,
1137
+ reply_id: this.replyId,
1138
+ block_id: responseId.textBlockId,
1135
1139
  delta: block.text
1136
1140
  };
1137
1141
  break;
@@ -1140,18 +1144,18 @@ var Agent = class {
1140
1144
  responseId.thinkingBlockId = crypto.randomUUID();
1141
1145
  yield {
1142
1146
  id: crypto.randomUUID(),
1143
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1147
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1144
1148
  type: "THINKING_BLOCK_START" /* THINKING_BLOCK_START */,
1145
- replyId: this.replyId,
1146
- blockId: responseId.thinkingBlockId
1149
+ reply_id: this.replyId,
1150
+ block_id: responseId.thinkingBlockId
1147
1151
  };
1148
1152
  }
1149
1153
  yield {
1150
1154
  id: crypto.randomUUID(),
1151
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1155
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1152
1156
  type: "THINKING_BLOCK_DELTA" /* THINKING_BLOCK_DELTA */,
1153
- replyId: this.replyId,
1154
- blockId: responseId.thinkingBlockId,
1157
+ reply_id: this.replyId,
1158
+ block_id: responseId.thinkingBlockId,
1155
1159
  delta: block.thinking
1156
1160
  };
1157
1161
  break;
@@ -1161,19 +1165,19 @@ var Agent = class {
1161
1165
  yield {
1162
1166
  id: crypto.randomUUID(),
1163
1167
  type: "TOOL_CALL_START" /* TOOL_CALL_START */,
1164
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1165
- replyId: this.replyId,
1166
- toolCallId: block.id,
1167
- toolCallName: block.name
1168
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1169
+ reply_id: this.replyId,
1170
+ tool_call_id: block.id,
1171
+ tool_call_name: block.name
1168
1172
  };
1169
1173
  }
1170
1174
  yield {
1171
1175
  id: crypto.randomUUID(),
1172
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1176
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1173
1177
  type: "TOOL_CALL_DELTA" /* TOOL_CALL_DELTA */,
1174
1178
  delta: block.input,
1175
- replyId: this.replyId,
1176
- toolCallId: block.id
1179
+ reply_id: this.replyId,
1180
+ tool_call_id: block.id
1177
1181
  };
1178
1182
  }
1179
1183
  }
@@ -1192,10 +1196,10 @@ var Agent = class {
1192
1196
  case "text":
1193
1197
  yield {
1194
1198
  id: crypto.randomUUID(),
1195
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1199
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1196
1200
  type: "TOOL_RESULT_TEXT_DELTA" /* TOOL_RESULT_TEXT_DELTA */,
1197
- replyId: this.replyId,
1198
- toolCallId: toolCall.id,
1201
+ reply_id: this.replyId,
1202
+ tool_call_id: toolCall.id,
1199
1203
  delta: block.text
1200
1204
  };
1201
1205
  break;
@@ -1203,21 +1207,21 @@ var Agent = class {
1203
1207
  if (block.source.type === "base64") {
1204
1208
  yield {
1205
1209
  id: crypto.randomUUID(),
1206
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1207
- type: "TOOL_RESULT_BINARY_DELTA" /* TOOL_RESULT_BINARY_DELTA */,
1208
- replyId: this.replyId,
1209
- toolCallId: toolCall.id,
1210
- mediaType: block.source.mediaType,
1210
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1211
+ type: "TOOL_RESULT_DATA_DELTA" /* TOOL_RESULT_DATA_DELTA */,
1212
+ reply_id: this.replyId,
1213
+ tool_call_id: toolCall.id,
1214
+ media_type: block.source.media_type,
1211
1215
  data: block.source.data
1212
1216
  };
1213
1217
  } else if (block.source.type === "url") {
1214
1218
  yield {
1215
1219
  id: crypto.randomUUID(),
1216
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1217
- type: "TOOL_RESULT_BINARY_DELTA" /* TOOL_RESULT_BINARY_DELTA */,
1218
- replyId: this.replyId,
1219
- toolCallId: toolCall.id,
1220
- mediaType: block.source.mediaType,
1220
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1221
+ type: "TOOL_RESULT_DATA_DELTA" /* TOOL_RESULT_DATA_DELTA */,
1222
+ reply_id: this.replyId,
1223
+ tool_call_id: toolCall.id,
1224
+ media_type: block.source.media_type,
1221
1225
  url: block.source.url
1222
1226
  };
1223
1227
  }
@@ -1226,10 +1230,10 @@ var Agent = class {
1226
1230
  }
1227
1231
  yield {
1228
1232
  id: crypto.randomUUID(),
1229
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1233
+ created_at: (/* @__PURE__ */ new Date()).toISOString(),
1230
1234
  type: "TOOL_RESULT_END" /* TOOL_RESULT_END */,
1231
- replyId: this.replyId,
1232
- toolCallId: toolCall.id,
1235
+ reply_id: this.replyId,
1236
+ tool_call_id: toolCall.id,
1233
1237
  state: toolRes.state
1234
1238
  };
1235
1239
  }
@@ -1239,7 +1243,7 @@ var Agent = class {
1239
1243
  */
1240
1244
  async toJSON() {
1241
1245
  return {
1242
- replyId: this.replyId,
1246
+ reply_id: this.replyId,
1243
1247
  confirmedToolCallIds: this.confirmedToolCallIds,
1244
1248
  curIter: this.curIter
1245
1249
  };