@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.
Files changed (44) hide show
  1. package/dist/agent/index.d.mts +4 -4
  2. package/dist/agent/index.d.ts +4 -4
  3. package/dist/agent/index.js +34 -7
  4. package/dist/agent/index.js.map +1 -1
  5. package/dist/agent/index.mjs +34 -7
  6. package/dist/agent/index.mjs.map +1 -1
  7. package/dist/{base-qmU135_k.d.ts → base-13VLaOvY.d.ts} +2 -2
  8. package/dist/{base-BI5s2ksj.d.mts → base-Bc3GkNS7.d.mts} +1 -1
  9. package/dist/{base-DHtZCg94.d.ts → base-CJkm56kB.d.ts} +1 -1
  10. package/dist/{base-CFDeoJRe.d.ts → base-Dfizi3RB.d.ts} +1 -1
  11. package/dist/{base-BDyDUIhj.d.mts → base-L72wZVx8.d.mts} +2 -2
  12. package/dist/{base-BB9eTlit.d.mts → base-Ps8E0j1_.d.mts} +1 -1
  13. package/dist/event/index.d.mts +2 -2
  14. package/dist/event/index.d.ts +2 -2
  15. package/dist/event/index.js.map +1 -1
  16. package/dist/event/index.mjs.map +1 -1
  17. package/dist/formatter/index.d.mts +2 -2
  18. package/dist/formatter/index.d.ts +2 -2
  19. package/dist/formatter/index.js +16 -0
  20. package/dist/formatter/index.js.map +1 -1
  21. package/dist/formatter/index.mjs +16 -0
  22. package/dist/formatter/index.mjs.map +1 -1
  23. package/dist/message/index.d.mts +1 -1
  24. package/dist/message/index.d.ts +1 -1
  25. package/dist/message/index.js +50 -14
  26. package/dist/message/index.js.map +1 -1
  27. package/dist/message/index.mjs +50 -14
  28. package/dist/message/index.mjs.map +1 -1
  29. package/dist/{message-D-LObC06.d.mts → message-COpNEf0G.d.mts} +10 -7
  30. package/dist/{message-DU0_qm3u.d.ts → message-DbCMy5tM.d.ts} +10 -7
  31. package/dist/model/index.d.mts +4 -4
  32. package/dist/model/index.d.ts +4 -4
  33. package/dist/model/index.js +16 -0
  34. package/dist/model/index.js.map +1 -1
  35. package/dist/model/index.mjs +16 -0
  36. package/dist/model/index.mjs.map +1 -1
  37. package/dist/storage/index.d.mts +2 -2
  38. package/dist/storage/index.d.ts +2 -2
  39. package/package.json +1 -1
  40. package/src/agent/agent.ts +20 -7
  41. package/src/event/index.ts +2 -2
  42. package/src/message/append-event.test.ts +17 -11
  43. package/src/message/message.test.ts +2 -2
  44. package/src/message/message.ts +77 -14
@@ -1,13 +1,13 @@
1
1
  import { z } from 'zod';
2
- import { M as Msg } from '../message-D-LObC06.mjs';
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-BDyDUIhj.mjs';
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-BB9eTlit.mjs';
10
- import '../base-BI5s2ksj.mjs';
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';
@@ -1,13 +1,13 @@
1
1
  import { z } from 'zod';
2
- import { M as Msg } from '../message-DU0_qm3u.js';
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-qmU135_k.js';
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-DHtZCg94.js';
10
- import '../base-CFDeoJRe.js';
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';
@@ -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({ name: this.name, content: blocks, role: "assistant", usage })
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 (usage) {
800
+ if (msgUsage) {
779
801
  if (!lastMsg.usage) {
780
802
  lastMsg.usage = {
781
- inputTokens: 0,
782
- outputTokens: 0
803
+ input_tokens: 0,
804
+ output_tokens: 0
783
805
  };
784
806
  }
785
- lastMsg.usage.inputTokens = lastMsg.usage.inputTokens + usage.inputTokens;
786
- lastMsg.usage.outputTokens = lastMsg.usage.outputTokens + usage.outputTokens;
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({ name: this.name, content: blocks, role: "assistant", usage })
812
+ createMsg({
813
+ name: this.name,
814
+ content: blocks,
815
+ role: "assistant",
816
+ usage: msgUsage
817
+ })
791
818
  );
792
819
  }
793
820
  }