@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
@@ -2,6 +2,21 @@
2
2
  import { z as z9 } from "zod";
3
3
 
4
4
  // src/message/message.ts
5
+ function assertContentBlocksForRole(role, content) {
6
+ if (role === "user") {
7
+ for (const block of content) {
8
+ if (block.type !== "text" && block.type !== "data") {
9
+ throw new Error("User message can only contain text blocks or data blocks.");
10
+ }
11
+ }
12
+ } else if (role === "system") {
13
+ for (const block of content) {
14
+ if (block.type !== "text") {
15
+ throw new Error("System message can only contain text blocks.");
16
+ }
17
+ }
18
+ }
19
+ }
5
20
  function createMsg({
6
21
  name,
7
22
  content,
@@ -13,6 +28,7 @@ function createMsg({
13
28
  usage
14
29
  }) {
15
30
  const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
31
+ assertContentBlocksForRole(role, contentBlocks);
16
32
  return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
17
33
  }
18
34
  function getContentBlocks(msg, blockType) {
@@ -732,26 +748,37 @@ var Agent = class {
732
748
  * @param usage
733
749
  */
734
750
  _saveToContext(blocks, usage) {
751
+ const msgUsage = usage ? { input_tokens: usage.inputTokens, output_tokens: usage.outputTokens } : void 0;
735
752
  const lastMsg = this.context.at(-1);
736
753
  if (this.context.length === 0) {
737
754
  this.context.push(
738
- createMsg({ name: this.name, content: blocks, role: "assistant", usage })
755
+ createMsg({
756
+ name: this.name,
757
+ content: blocks,
758
+ role: "assistant",
759
+ usage: msgUsage
760
+ })
739
761
  );
740
762
  } else if (lastMsg && lastMsg.role === "assistant" && lastMsg.name === this.name) {
741
763
  lastMsg.content.push(...blocks);
742
- if (usage) {
764
+ if (msgUsage) {
743
765
  if (!lastMsg.usage) {
744
766
  lastMsg.usage = {
745
- inputTokens: 0,
746
- outputTokens: 0
767
+ input_tokens: 0,
768
+ output_tokens: 0
747
769
  };
748
770
  }
749
- lastMsg.usage.inputTokens = lastMsg.usage.inputTokens + usage.inputTokens;
750
- lastMsg.usage.outputTokens = lastMsg.usage.outputTokens + usage.outputTokens;
771
+ lastMsg.usage.input_tokens = lastMsg.usage.input_tokens + msgUsage.input_tokens;
772
+ lastMsg.usage.output_tokens = lastMsg.usage.output_tokens + msgUsage.output_tokens;
751
773
  }
752
774
  } else {
753
775
  this.context.push(
754
- createMsg({ name: this.name, content: blocks, role: "assistant", usage })
776
+ createMsg({
777
+ name: this.name,
778
+ content: blocks,
779
+ role: "assistant",
780
+ usage: msgUsage
781
+ })
755
782
  );
756
783
  }
757
784
  }