@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.
- package/LICENSE +202 -0
- package/dist/agent/index.d.mts +10 -10
- package/dist/agent/index.d.ts +10 -10
- package/dist/agent/index.js +94 -90
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +94 -90
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-BOx3UzOl.d.mts → base-Bo8TzBQq.d.mts} +2 -2
- package/dist/{base-NX-knWOv.d.ts → base-Co-MzdN5.d.ts} +1 -1
- package/dist/{base-DYlBMCy_.d.mts → base-D9uCcDjZ.d.mts} +3 -3
- package/dist/{base-C7jwyH4Z.d.mts → base-Dh5vEBQD.d.mts} +1 -1
- package/dist/{base-Cwi4bjze.d.ts → base-TYjCCv7T.d.ts} +3 -3
- package/dist/{base-BoIps2RL.d.ts → base-t7G4uaR_.d.ts} +2 -2
- package/dist/{block-VsnHrllL.d.mts → block-7fd6byyN.d.mts} +2 -2
- package/dist/{block-VsnHrllL.d.ts → block-7fd6byyN.d.ts} +2 -2
- package/dist/event/index.d.mts +105 -89
- package/dist/event/index.d.ts +105 -89
- package/dist/event/index.js +8 -8
- package/dist/event/index.js.map +1 -1
- package/dist/event/index.mjs +8 -8
- package/dist/event/index.mjs.map +1 -1
- package/dist/formatter/index.d.mts +3 -3
- package/dist/formatter/index.d.ts +3 -3
- package/dist/formatter/index.js +17 -17
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/index.mjs +17 -17
- package/dist/formatter/index.mjs.map +1 -1
- package/dist/{index-BTJDlKvQ.d.mts → index-BVNbIN62.d.mts} +1 -1
- package/dist/{index-BcatlwXQ.d.ts → index-DaopL-Vp.d.ts} +1 -1
- package/dist/mcp/index.d.mts +2 -2
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/index.mjs +1 -1
- package/dist/mcp/index.mjs.map +1 -1
- package/dist/message/index.d.mts +2 -2
- package/dist/message/index.d.ts +2 -2
- package/dist/message/index.js +39 -5
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +36 -5
- package/dist/message/index.mjs.map +1 -1
- package/dist/{message-CkN21KaY.d.mts → message-CYnHiEVt.d.mts} +66 -43
- package/dist/{message-CzLeTlua.d.ts → message-DZN7LetB.d.ts} +66 -43
- package/dist/model/index.d.mts +5 -5
- package/dist/model/index.d.ts +5 -5
- package/dist/model/index.js +17 -17
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +17 -17
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +3 -3
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.js +4 -4
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +4 -4
- package/dist/storage/index.mjs.map +1 -1
- package/dist/tool/index.d.mts +4 -4
- package/dist/tool/index.d.ts +4 -4
- package/dist/{toolkit-CEpulFi0.d.ts → toolkit-BuMTkbGg.d.ts} +2 -2
- package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-CH9qKAy9.d.mts} +2 -2
- package/package.json +87 -87
- package/src/agent/agent.test.ts +63 -63
- package/src/agent/agent.ts +101 -99
- package/src/agent/test-compression.ts +1 -1
- package/src/event/index.ts +96 -98
- package/src/formatter/base.ts +3 -3
- package/src/formatter/dashscope-chat-formatter.test.ts +8 -8
- package/src/formatter/dashscope-chat-formatter.ts +3 -3
- package/src/formatter/openai-chat-formatter.test.ts +4 -4
- package/src/formatter/openai-chat-formatter.ts +6 -6
- package/src/mcp/base.ts +1 -1
- package/src/message/block.ts +2 -2
- package/src/message/index.ts +9 -1
- package/src/message/message.test.ts +1 -1
- package/src/message/message.ts +101 -47
- package/src/permission/index.ts +13 -0
- package/src/storage/file-system.test.ts +3 -3
- package/src/storage/file-system.ts +4 -4
package/dist/agent/index.mjs
CHANGED
|
@@ -8,10 +8,12 @@ function createMsg({
|
|
|
8
8
|
role,
|
|
9
9
|
metadata = {},
|
|
10
10
|
id = crypto.randomUUID(),
|
|
11
|
-
|
|
11
|
+
created_at = (/* @__PURE__ */ new Date()).toISOString(),
|
|
12
|
+
finished_at,
|
|
12
13
|
usage
|
|
13
14
|
}) {
|
|
14
|
-
|
|
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
|
-
|
|
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.
|
|
831
|
+
this._saveToContext(event.execution_results);
|
|
830
832
|
} else if (event.type === "USER_CONFIRM_RESULT" /* USER_CONFIRM_RESULT */) {
|
|
831
|
-
for (const result of event.
|
|
833
|
+
for (const result of event.confirm_results) {
|
|
832
834
|
if (result.confirmed) {
|
|
833
|
-
this.confirmedToolCallIds.push(result.
|
|
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.
|
|
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
|
-
|
|
840
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
839
841
|
type: "TOOL_RESULT_START" /* TOOL_RESULT_START */,
|
|
840
|
-
|
|
841
|
-
|
|
842
|
+
reply_id: this.replyId,
|
|
843
|
+
tool_call_id: result.tool_call.id
|
|
842
844
|
};
|
|
843
845
|
yield {
|
|
844
846
|
id: crypto.randomUUID(),
|
|
845
|
-
|
|
847
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
846
848
|
type: "TOOL_RESULT_TEXT_DELTA" /* TOOL_RESULT_TEXT_DELTA */,
|
|
847
|
-
|
|
848
|
-
|
|
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
|
-
|
|
855
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
854
856
|
type: "TOOL_RESULT_END" /* TOOL_RESULT_END */,
|
|
855
|
-
|
|
856
|
-
|
|
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.
|
|
863
|
-
name: result.
|
|
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.
|
|
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.
|
|
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: "
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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
|
-
|
|
924
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
921
925
|
type: awaitingType,
|
|
922
|
-
|
|
923
|
-
|
|
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: "
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
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
|
-
|
|
972
|
-
type: "
|
|
973
|
-
|
|
974
|
-
|
|
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
|
-
|
|
1024
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1021
1025
|
type: "TEXT_BLOCK_END" /* TEXT_BLOCK_END */,
|
|
1022
|
-
|
|
1023
|
-
|
|
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
|
-
|
|
1033
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1030
1034
|
type: "THINKING_BLOCK_END" /* THINKING_BLOCK_END */,
|
|
1031
|
-
|
|
1032
|
-
|
|
1035
|
+
reply_id: this.replyId,
|
|
1036
|
+
block_id: blockIds.thinkingBlockId
|
|
1033
1037
|
};
|
|
1034
1038
|
}
|
|
1035
1039
|
if (blockIds.toolCallIds.length > 0) {
|
|
1036
|
-
for (const
|
|
1040
|
+
for (const tool_call_id of blockIds.toolCallIds) {
|
|
1037
1041
|
yield {
|
|
1038
1042
|
id: crypto.randomUUID(),
|
|
1039
|
-
|
|
1043
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1040
1044
|
type: "TOOL_CALL_END" /* TOOL_CALL_END */,
|
|
1041
|
-
|
|
1042
|
-
|
|
1045
|
+
reply_id: this.replyId,
|
|
1046
|
+
tool_call_id
|
|
1043
1047
|
};
|
|
1044
1048
|
}
|
|
1045
1049
|
}
|
|
1046
1050
|
yield {
|
|
1047
1051
|
id: crypto.randomUUID(),
|
|
1048
|
-
|
|
1049
|
-
type: "
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
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
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
-
|
|
1127
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1124
1128
|
type: "TEXT_BLOCK_START" /* TEXT_BLOCK_START */,
|
|
1125
|
-
|
|
1126
|
-
|
|
1129
|
+
reply_id: this.replyId,
|
|
1130
|
+
block_id: responseId.textBlockId
|
|
1127
1131
|
};
|
|
1128
1132
|
}
|
|
1129
1133
|
yield {
|
|
1130
1134
|
id: crypto.randomUUID(),
|
|
1131
|
-
|
|
1135
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1132
1136
|
type: "TEXT_BLOCK_DELTA" /* TEXT_BLOCK_DELTA */,
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
-
|
|
1147
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1144
1148
|
type: "THINKING_BLOCK_START" /* THINKING_BLOCK_START */,
|
|
1145
|
-
|
|
1146
|
-
|
|
1149
|
+
reply_id: this.replyId,
|
|
1150
|
+
block_id: responseId.thinkingBlockId
|
|
1147
1151
|
};
|
|
1148
1152
|
}
|
|
1149
1153
|
yield {
|
|
1150
1154
|
id: crypto.randomUUID(),
|
|
1151
|
-
|
|
1155
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1152
1156
|
type: "THINKING_BLOCK_DELTA" /* THINKING_BLOCK_DELTA */,
|
|
1153
|
-
|
|
1154
|
-
|
|
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
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
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
|
-
|
|
1176
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1173
1177
|
type: "TOOL_CALL_DELTA" /* TOOL_CALL_DELTA */,
|
|
1174
1178
|
delta: block.input,
|
|
1175
|
-
|
|
1176
|
-
|
|
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
|
-
|
|
1199
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1196
1200
|
type: "TOOL_RESULT_TEXT_DELTA" /* TOOL_RESULT_TEXT_DELTA */,
|
|
1197
|
-
|
|
1198
|
-
|
|
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
|
-
|
|
1207
|
-
type: "
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
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
|
-
|
|
1217
|
-
type: "
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
-
|
|
1233
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1230
1234
|
type: "TOOL_RESULT_END" /* TOOL_RESULT_END */,
|
|
1231
|
-
|
|
1232
|
-
|
|
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
|
-
|
|
1246
|
+
reply_id: this.replyId,
|
|
1243
1247
|
confirmedToolCallIds: this.confirmedToolCallIds,
|
|
1244
1248
|
curIter: this.curIter
|
|
1245
1249
|
};
|