@agentscope-ai/agentscope 0.0.5 → 0.0.6
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/dist/agent/index.d.mts +4 -4
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.js +34 -7
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +34 -7
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{base-qmU135_k.d.ts → base-13VLaOvY.d.ts} +2 -2
- package/dist/{base-BI5s2ksj.d.mts → base-Bc3GkNS7.d.mts} +1 -1
- package/dist/{base-DHtZCg94.d.ts → base-CJkm56kB.d.ts} +1 -1
- package/dist/{base-CFDeoJRe.d.ts → base-Dfizi3RB.d.ts} +1 -1
- package/dist/{base-BDyDUIhj.d.mts → base-L72wZVx8.d.mts} +2 -2
- package/dist/{base-BB9eTlit.d.mts → base-Ps8E0j1_.d.mts} +1 -1
- package/dist/event/index.d.mts +2 -2
- package/dist/event/index.d.ts +2 -2
- package/dist/event/index.js.map +1 -1
- package/dist/event/index.mjs.map +1 -1
- package/dist/formatter/index.d.mts +2 -2
- package/dist/formatter/index.d.ts +2 -2
- package/dist/formatter/index.js +16 -0
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/index.mjs +16 -0
- package/dist/formatter/index.mjs.map +1 -1
- package/dist/message/index.d.mts +1 -1
- package/dist/message/index.d.ts +1 -1
- package/dist/message/index.js +50 -14
- package/dist/message/index.js.map +1 -1
- package/dist/message/index.mjs +50 -14
- package/dist/message/index.mjs.map +1 -1
- package/dist/{message-D-LObC06.d.mts → message-COpNEf0G.d.mts} +10 -7
- package/dist/{message-DU0_qm3u.d.ts → message-DbCMy5tM.d.ts} +10 -7
- package/dist/model/index.d.mts +4 -4
- package/dist/model/index.d.ts +4 -4
- package/dist/model/index.js +16 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/index.mjs +16 -0
- package/dist/model/index.mjs.map +1 -1
- package/dist/storage/index.d.mts +2 -2
- package/dist/storage/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/agent/agent.ts +20 -7
- package/src/event/index.ts +2 -2
- package/src/message/append-event.test.ts +17 -11
- package/src/message/message.test.ts +2 -2
- package/src/message/message.ts +77 -14
package/dist/agent/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { M as Msg } from '../message-
|
|
2
|
+
import { M as Msg } from '../message-COpNEf0G.mjs';
|
|
3
3
|
import { b as ToolCallBlock, C as ContentBlock, d as ToolResultBlock } from '../block-BqWf-Qcb.mjs';
|
|
4
|
-
import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-
|
|
4
|
+
import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-L72wZVx8.mjs';
|
|
5
5
|
import { a as ToolResponse } from '../index-DpRGxYeT.mjs';
|
|
6
6
|
import { T as Toolkit } from '../toolkit-DvER4yhm.mjs';
|
|
7
7
|
import { UserConfirmResultEvent, ExternalExecutionResultEvent, AgentEvent, EventType, ToolResultTextDeltaEvent, ToolResultDataDeltaEvent, ToolResultEndEvent } from '../event/index.mjs';
|
|
8
8
|
import { a as ToolChoice } from '../index-CAxQAkiP.mjs';
|
|
9
|
-
import { S as StorageBase } from '../base-
|
|
10
|
-
import '../base-
|
|
9
|
+
import { S as StorageBase } from '../base-Ps8E0j1_.mjs';
|
|
10
|
+
import '../base-Bc3GkNS7.mjs';
|
|
11
11
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
12
12
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
13
13
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { M as Msg } from '../message-
|
|
2
|
+
import { M as Msg } from '../message-DbCMy5tM.js';
|
|
3
3
|
import { b as ToolCallBlock, C as ContentBlock, d as ToolResultBlock } from '../block-BqWf-Qcb.js';
|
|
4
|
-
import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-
|
|
4
|
+
import { C as ChatModelBase, a as ChatUsage, b as ChatResponse } from '../base-13VLaOvY.js';
|
|
5
5
|
import { a as ToolResponse } from '../index-9YC8onn7.js';
|
|
6
6
|
import { T as Toolkit } from '../toolkit-CLGa-xW0.js';
|
|
7
7
|
import { UserConfirmResultEvent, ExternalExecutionResultEvent, AgentEvent, EventType, ToolResultTextDeltaEvent, ToolResultDataDeltaEvent, ToolResultEndEvent } from '../event/index.js';
|
|
8
8
|
import { a as ToolChoice } from '../index-CAxQAkiP.js';
|
|
9
|
-
import { S as StorageBase } from '../base-
|
|
10
|
-
import '../base-
|
|
9
|
+
import { S as StorageBase } from '../base-CJkm56kB.js';
|
|
10
|
+
import '../base-Dfizi3RB.js';
|
|
11
11
|
import '@modelcontextprotocol/sdk/client/index.js';
|
|
12
12
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
13
13
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -38,6 +38,21 @@ module.exports = __toCommonJS(agent_exports);
|
|
|
38
38
|
var import_zod9 = require("zod");
|
|
39
39
|
|
|
40
40
|
// src/message/message.ts
|
|
41
|
+
function assertContentBlocksForRole(role, content) {
|
|
42
|
+
if (role === "user") {
|
|
43
|
+
for (const block of content) {
|
|
44
|
+
if (block.type !== "text" && block.type !== "data") {
|
|
45
|
+
throw new Error("User message can only contain text blocks or data blocks.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} else if (role === "system") {
|
|
49
|
+
for (const block of content) {
|
|
50
|
+
if (block.type !== "text") {
|
|
51
|
+
throw new Error("System message can only contain text blocks.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
41
56
|
function createMsg({
|
|
42
57
|
name,
|
|
43
58
|
content,
|
|
@@ -49,6 +64,7 @@ function createMsg({
|
|
|
49
64
|
usage
|
|
50
65
|
}) {
|
|
51
66
|
const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
|
|
67
|
+
assertContentBlocksForRole(role, contentBlocks);
|
|
52
68
|
return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
|
|
53
69
|
}
|
|
54
70
|
function getContentBlocks(msg, blockType) {
|
|
@@ -768,26 +784,37 @@ var Agent = class {
|
|
|
768
784
|
* @param usage
|
|
769
785
|
*/
|
|
770
786
|
_saveToContext(blocks, usage) {
|
|
787
|
+
const msgUsage = usage ? { input_tokens: usage.inputTokens, output_tokens: usage.outputTokens } : void 0;
|
|
771
788
|
const lastMsg = this.context.at(-1);
|
|
772
789
|
if (this.context.length === 0) {
|
|
773
790
|
this.context.push(
|
|
774
|
-
createMsg({
|
|
791
|
+
createMsg({
|
|
792
|
+
name: this.name,
|
|
793
|
+
content: blocks,
|
|
794
|
+
role: "assistant",
|
|
795
|
+
usage: msgUsage
|
|
796
|
+
})
|
|
775
797
|
);
|
|
776
798
|
} else if (lastMsg && lastMsg.role === "assistant" && lastMsg.name === this.name) {
|
|
777
799
|
lastMsg.content.push(...blocks);
|
|
778
|
-
if (
|
|
800
|
+
if (msgUsage) {
|
|
779
801
|
if (!lastMsg.usage) {
|
|
780
802
|
lastMsg.usage = {
|
|
781
|
-
|
|
782
|
-
|
|
803
|
+
input_tokens: 0,
|
|
804
|
+
output_tokens: 0
|
|
783
805
|
};
|
|
784
806
|
}
|
|
785
|
-
lastMsg.usage.
|
|
786
|
-
lastMsg.usage.
|
|
807
|
+
lastMsg.usage.input_tokens = lastMsg.usage.input_tokens + msgUsage.input_tokens;
|
|
808
|
+
lastMsg.usage.output_tokens = lastMsg.usage.output_tokens + msgUsage.output_tokens;
|
|
787
809
|
}
|
|
788
810
|
} else {
|
|
789
811
|
this.context.push(
|
|
790
|
-
createMsg({
|
|
812
|
+
createMsg({
|
|
813
|
+
name: this.name,
|
|
814
|
+
content: blocks,
|
|
815
|
+
role: "assistant",
|
|
816
|
+
usage: msgUsage
|
|
817
|
+
})
|
|
791
818
|
);
|
|
792
819
|
}
|
|
793
820
|
}
|