@agentscope-ai/agentscope 0.0.2 → 0.0.4

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 (90) 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 +104 -93
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/index.mjs +104 -93
  7. package/dist/agent/index.mjs.map +1 -1
  8. package/dist/{base-BOx3UzOl.d.mts → base-1YVBgB4n.d.mts} +2 -2
  9. package/dist/{base-DYlBMCy_.d.mts → base-B_MQMHWr.d.mts} +3 -3
  10. package/dist/{base-Cwi4bjze.d.ts → base-BherSLRs.d.ts} +3 -3
  11. package/dist/{base-NX-knWOv.d.ts → base-CY4DMBH1.d.ts} +1 -1
  12. package/dist/{base-BoIps2RL.d.ts → base-ChWjyzPL.d.ts} +2 -2
  13. package/dist/{base-C7jwyH4Z.d.mts → base-ClilytRZ.d.mts} +1 -1
  14. package/dist/{block-VsnHrllL.d.mts → block-B72uPF1H.d.mts} +7 -5
  15. package/dist/{block-VsnHrllL.d.ts → block-B72uPF1H.d.ts} +7 -5
  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 +4 -3
  23. package/dist/formatter/index.d.ts +4 -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-BcatlwXQ.d.ts → index-BNfyKbQN.d.ts} +1 -1
  29. package/dist/{index-BTJDlKvQ.d.mts → index-UQCwdfet.d.mts} +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 +3 -2
  37. package/dist/message/index.d.ts +3 -2
  38. package/dist/message/index.js +204 -5
  39. package/dist/message/index.js.map +1 -1
  40. package/dist/message/index.mjs +200 -5
  41. package/dist/message/index.mjs.map +1 -1
  42. package/dist/message-CPZd0NIc.d.ts +133 -0
  43. package/dist/message-DgpfAaHK.d.mts +133 -0
  44. package/dist/model/index.d.mts +6 -5
  45. package/dist/model/index.d.ts +6 -5
  46. package/dist/model/index.js +39 -28
  47. package/dist/model/index.js.map +1 -1
  48. package/dist/model/index.mjs +39 -28
  49. package/dist/model/index.mjs.map +1 -1
  50. package/dist/storage/index.d.mts +4 -3
  51. package/dist/storage/index.d.ts +4 -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-DeOlul5Y.d.ts} +2 -2
  59. package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-jwe7NmVJ.d.mts} +2 -2
  60. package/package.json +87 -87
  61. package/src/agent/agent.test.ts +104 -71
  62. package/src/agent/agent.ts +112 -104
  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 +11 -8
  67. package/src/formatter/dashscope-chat-formatter.ts +3 -3
  68. package/src/formatter/openai-chat-formatter.test.ts +13 -5
  69. package/src/formatter/openai-chat-formatter.ts +6 -6
  70. package/src/mcp/base.ts +1 -1
  71. package/src/mcp/http.test.ts +2 -0
  72. package/src/mcp/stdio.test.ts +1 -0
  73. package/src/message/append-event.test.ts +783 -0
  74. package/src/message/block.ts +8 -4
  75. package/src/message/index.ts +12 -1
  76. package/src/message/message.test.ts +3 -1
  77. package/src/message/message.ts +310 -47
  78. package/src/model/dashscope-model.test.ts +4 -0
  79. package/src/model/dashscope-model.ts +3 -0
  80. package/src/model/deepseek-model.test.ts +2 -0
  81. package/src/model/deepseek-model.ts +3 -0
  82. package/src/model/ollama-model.test.ts +1 -0
  83. package/src/model/ollama-model.ts +2 -0
  84. package/src/model/openai-model.ts +3 -0
  85. package/src/permission/index.ts +13 -0
  86. package/src/storage/file-system.test.ts +4 -3
  87. package/src/storage/file-system.ts +4 -4
  88. package/src/tool/toolkit.test.ts +12 -0
  89. package/dist/message-CkN21KaY.d.mts +0 -99
  90. package/dist/message-CzLeTlua.d.ts +0 -99
@@ -1,16 +1,29 @@
1
- import { b as ToolCallBlock, c as ToolResultBlock } from '../block-VsnHrllL.js';
1
+ import { b as ToolCallBlock, d as ToolResultBlock } from '../block-B72uPF1H.js';
2
+
3
+ declare enum PermissionBehavior {
4
+ ALLOW = "allow",
5
+ DENY = "deny",
6
+ ASK = "ask",
7
+ PASSTHROUGH = "passthrough"
8
+ }
9
+ interface PermissionRule {
10
+ tool_name: string;
11
+ rule_content: string | null;
12
+ behavior: PermissionBehavior;
13
+ source: string;
14
+ }
2
15
 
3
16
  declare enum EventType {
4
- RUN_STARTED = "RUN_STARTED",
5
- RUN_FINISHED = "RUN_FINISHED",
6
- MODEL_CALL_STARTED = "MODEL_CALL_STARTED",
7
- MODEL_CALL_ENDED = "MODEL_CALL_ENDED",
17
+ REPLY_START = "REPLY_START",
18
+ REPLY_END = "REPLY_END",
19
+ MODEL_CALL_START = "MODEL_CALL_START",
20
+ MODEL_CALL_END = "MODEL_CALL_END",
8
21
  TEXT_BLOCK_START = "TEXT_BLOCK_START",
9
22
  TEXT_BLOCK_DELTA = "TEXT_BLOCK_DELTA",
10
23
  TEXT_BLOCK_END = "TEXT_BLOCK_END",
11
- BINARY_BLOCK_START = "BINARY_BLOCK_START",
12
- BINARY_BLOCK_DELTA = "BINARY_BLOCK_DELTA",
13
- BINARY_BLOCK_END = "BINARY_BLOCK_END",
24
+ DATA_BLOCK_START = "DATA_BLOCK_START",
25
+ DATA_BLOCK_DELTA = "DATA_BLOCK_DELTA",
26
+ DATA_BLOCK_END = "DATA_BLOCK_END",
14
27
  THINKING_BLOCK_START = "THINKING_BLOCK_START",
15
28
  THINKING_BLOCK_DELTA = "THINKING_BLOCK_DELTA",
16
29
  THINKING_BLOCK_END = "THINKING_BLOCK_END",
@@ -19,7 +32,7 @@ declare enum EventType {
19
32
  TOOL_CALL_END = "TOOL_CALL_END",
20
33
  TOOL_RESULT_START = "TOOL_RESULT_START",
21
34
  TOOL_RESULT_TEXT_DELTA = "TOOL_RESULT_TEXT_DELTA",
22
- TOOL_RESULT_BINARY_DELTA = "TOOL_RESULT_BINARY_DELTA",
35
+ TOOL_RESULT_DATA_DELTA = "TOOL_RESULT_DATA_DELTA",
23
36
  TOOL_RESULT_END = "TOOL_RESULT_END",
24
37
  EXCEED_MAX_ITERS = "EXCEED_MAX_ITERS",
25
38
  REQUIRE_USER_CONFIRM = "REQUIRE_USER_CONFIRM",
@@ -29,153 +42,156 @@ declare enum EventType {
29
42
  }
30
43
  interface EventBase {
31
44
  id: string;
32
- createdAt: string;
45
+ created_at: string;
33
46
  }
34
- interface RunStartedEvent extends EventBase {
35
- type: EventType.RUN_STARTED;
36
- sessionId: string;
37
- replyId: string;
47
+ interface ReplyStartEvent extends EventBase {
48
+ type: EventType.REPLY_START;
49
+ session_id: string;
50
+ reply_id: string;
38
51
  name: string;
39
52
  role: 'user' | 'assistant' | 'system';
40
53
  }
41
- interface RunFinishedEvent extends EventBase {
42
- type: EventType.RUN_FINISHED;
43
- sessionId: string;
44
- replyId: string;
54
+ interface ReplyEndEvent extends EventBase {
55
+ type: EventType.REPLY_END;
56
+ session_id: string;
57
+ reply_id: string;
45
58
  }
46
- interface ModelCallStartedEvent extends EventBase {
47
- type: EventType.MODEL_CALL_STARTED;
48
- replyId: string;
49
- modelName: string;
59
+ interface ModelCallStartEvent extends EventBase {
60
+ type: EventType.MODEL_CALL_START;
61
+ reply_id: string;
62
+ model_name: string;
50
63
  }
51
- interface ModelCallEndedEvent extends EventBase {
52
- type: EventType.MODEL_CALL_ENDED;
53
- replyId: string;
54
- inputTokens: number;
55
- outputTokens: number;
64
+ interface ModelCallEndEvent extends EventBase {
65
+ type: EventType.MODEL_CALL_END;
66
+ reply_id: string;
67
+ input_tokens: number;
68
+ output_tokens: number;
56
69
  }
57
70
  interface TextBlockStartEvent extends EventBase {
58
71
  type: EventType.TEXT_BLOCK_START;
59
- blockId: string;
60
- replyId: string;
72
+ block_id: string;
73
+ reply_id: string;
61
74
  }
62
75
  interface TextBlockDeltaEvent extends EventBase {
63
76
  type: EventType.TEXT_BLOCK_DELTA;
64
- replyId: string;
65
- blockId: string;
77
+ reply_id: string;
78
+ block_id: string;
66
79
  delta: string;
67
80
  }
68
81
  interface TextBlockEndEvent extends EventBase {
69
82
  type: EventType.TEXT_BLOCK_END;
70
- replyId: string;
71
- blockId: string;
72
- }
73
- interface BinaryBlockStartEvent extends EventBase {
74
- type: EventType.BINARY_BLOCK_START;
75
- replyId: string;
76
- blockId: string;
77
- mediaType: string;
78
- }
79
- interface BinaryBlockDeltaEvent extends EventBase {
80
- type: EventType.BINARY_BLOCK_DELTA;
81
- replyId: string;
82
- blockId: string;
83
+ reply_id: string;
84
+ block_id: string;
85
+ }
86
+ interface DataBlockStartEvent extends EventBase {
87
+ type: EventType.DATA_BLOCK_START;
88
+ reply_id: string;
89
+ block_id: string;
90
+ media_type: string;
91
+ }
92
+ interface DataBlockDeltaEvent extends EventBase {
93
+ type: EventType.DATA_BLOCK_DELTA;
94
+ reply_id: string;
95
+ block_id: string;
83
96
  data: string;
84
- mediaType: string;
97
+ media_type: string;
85
98
  }
86
- interface BinaryBlockEndEvent extends EventBase {
87
- type: EventType.BINARY_BLOCK_END;
88
- replyId: string;
89
- blockId: string;
99
+ interface DataBlockEndEvent extends EventBase {
100
+ type: EventType.DATA_BLOCK_END;
101
+ reply_id: string;
102
+ block_id: string;
90
103
  }
91
104
  interface ThinkingBlockStartEvent extends EventBase {
92
105
  type: EventType.THINKING_BLOCK_START;
93
- replyId: string;
94
- blockId: string;
106
+ reply_id: string;
107
+ block_id: string;
95
108
  }
96
109
  interface ThinkingBlockDeltaEvent extends EventBase {
97
110
  type: EventType.THINKING_BLOCK_DELTA;
98
- replyId: string;
99
- blockId: string;
111
+ reply_id: string;
112
+ block_id: string;
100
113
  delta: string;
101
114
  }
102
115
  interface ThinkingBlockEndEvent extends EventBase {
103
116
  type: EventType.THINKING_BLOCK_END;
104
- replyId: string;
105
- blockId: string;
117
+ reply_id: string;
118
+ block_id: string;
106
119
  }
107
120
  interface ToolCallStartEvent extends EventBase {
108
121
  type: EventType.TOOL_CALL_START;
109
- replyId: string;
110
- toolCallId: string;
111
- toolCallName: string;
122
+ reply_id: string;
123
+ tool_call_id: string;
124
+ tool_call_name: string;
112
125
  }
113
126
  interface ToolCallDeltaEvent extends EventBase {
114
127
  type: EventType.TOOL_CALL_DELTA;
115
- replyId: string;
116
- toolCallId: string;
128
+ reply_id: string;
129
+ tool_call_id: string;
117
130
  delta: string;
118
131
  }
119
132
  interface ToolCallEndEvent extends EventBase {
120
133
  type: EventType.TOOL_CALL_END;
121
- replyId: string;
122
- toolCallId: string;
134
+ reply_id: string;
135
+ tool_call_id: string;
123
136
  }
124
137
  interface ToolResultStartEvent extends EventBase {
125
138
  type: EventType.TOOL_RESULT_START;
126
- replyId: string;
127
- toolCallId: string;
128
- toolCallName: string;
139
+ reply_id: string;
140
+ tool_call_id: string;
141
+ tool_call_name: string;
129
142
  }
130
143
  interface ToolResultTextDeltaEvent extends EventBase {
131
144
  type: EventType.TOOL_RESULT_TEXT_DELTA;
132
- replyId: string;
133
- toolCallId: string;
145
+ reply_id: string;
146
+ tool_call_id: string;
147
+ block_id: string;
134
148
  delta: string;
135
149
  }
136
- interface ToolResultBinaryDeltaEvent extends EventBase {
137
- type: EventType.TOOL_RESULT_BINARY_DELTA;
138
- replyId: string;
139
- toolCallId: string;
140
- mediaType: string;
150
+ interface ToolResultDataDeltaEvent extends EventBase {
151
+ type: EventType.TOOL_RESULT_DATA_DELTA;
152
+ reply_id: string;
153
+ tool_call_id: string;
154
+ block_id: string;
155
+ media_type: string;
141
156
  data?: string;
142
157
  url?: string;
143
158
  }
144
159
  interface ToolResultEndEvent extends EventBase {
145
160
  type: EventType.TOOL_RESULT_END;
146
- replyId: string;
147
- toolCallId: string;
161
+ reply_id: string;
162
+ tool_call_id: string;
148
163
  state: ToolResultBlock['state'];
149
164
  }
150
165
  interface ExceedMaxItersEvent extends EventBase {
151
166
  type: EventType.EXCEED_MAX_ITERS;
152
- replyId: string;
153
- agentId: string;
167
+ reply_id: string;
154
168
  name: string;
155
169
  }
156
170
  interface RequireUserConfirmEvent extends EventBase {
157
171
  type: EventType.REQUIRE_USER_CONFIRM;
158
- replyId: string;
159
- toolCalls: ToolCallBlock[];
172
+ reply_id: string;
173
+ tool_calls: ToolCallBlock[];
160
174
  }
161
175
  interface RequireExternalExecutionEvent extends EventBase {
162
176
  type: EventType.REQUIRE_EXTERNAL_EXECUTION;
163
- replyId: string;
164
- toolCalls: ToolCallBlock[];
177
+ reply_id: string;
178
+ tool_calls: ToolCallBlock[];
179
+ }
180
+ interface ConfirmResult {
181
+ confirmed: boolean;
182
+ tool_call: ToolCallBlock;
183
+ rules?: PermissionRule[] | null;
165
184
  }
166
185
  interface UserConfirmResultEvent extends EventBase {
167
186
  type: EventType.USER_CONFIRM_RESULT;
168
- replyId: string;
169
- confirmResults: {
170
- confirmed: boolean;
171
- toolCall: ToolCallBlock;
172
- }[];
187
+ reply_id: string;
188
+ confirm_results: ConfirmResult[];
173
189
  }
174
190
  interface ExternalExecutionResultEvent extends EventBase {
175
191
  type: EventType.EXTERNAL_EXECUTION_RESULT;
176
- replyId: string;
177
- executionResults: ToolResultBlock[];
192
+ reply_id: string;
193
+ execution_results: ToolResultBlock[];
178
194
  }
179
- type AgentEvent = RunStartedEvent | RunFinishedEvent | ExceedMaxItersEvent | RequireUserConfirmEvent | RequireExternalExecutionEvent | ModelCallStartedEvent | ModelCallEndedEvent | TextBlockStartEvent | TextBlockDeltaEvent | TextBlockEndEvent | BinaryBlockStartEvent | BinaryBlockDeltaEvent | BinaryBlockEndEvent | ThinkingBlockStartEvent | ThinkingBlockDeltaEvent | ThinkingBlockEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultStartEvent | ToolResultTextDeltaEvent | ToolResultBinaryDeltaEvent | ToolResultEndEvent | UserConfirmResultEvent | ExternalExecutionResultEvent;
195
+ type AgentEvent = ReplyStartEvent | ReplyEndEvent | ExceedMaxItersEvent | RequireUserConfirmEvent | RequireExternalExecutionEvent | ModelCallStartEvent | ModelCallEndEvent | TextBlockStartEvent | TextBlockDeltaEvent | TextBlockEndEvent | DataBlockStartEvent | DataBlockDeltaEvent | DataBlockEndEvent | ThinkingBlockStartEvent | ThinkingBlockDeltaEvent | ThinkingBlockEndEvent | ToolCallStartEvent | ToolCallDeltaEvent | ToolCallEndEvent | ToolResultStartEvent | ToolResultTextDeltaEvent | ToolResultDataDeltaEvent | ToolResultEndEvent | UserConfirmResultEvent | ExternalExecutionResultEvent;
180
196
 
181
- export { type AgentEvent, type BinaryBlockDeltaEvent, type BinaryBlockEndEvent, type BinaryBlockStartEvent, type EventBase, EventType, type ExceedMaxItersEvent, type ExternalExecutionResultEvent, type ModelCallEndedEvent, type ModelCallStartedEvent, type RequireExternalExecutionEvent, type RequireUserConfirmEvent, type RunFinishedEvent, type RunStartedEvent, type TextBlockDeltaEvent, type TextBlockEndEvent, type TextBlockStartEvent, type ThinkingBlockDeltaEvent, type ThinkingBlockEndEvent, type ThinkingBlockStartEvent, type ToolCallDeltaEvent, type ToolCallEndEvent, type ToolCallStartEvent, type ToolResultBinaryDeltaEvent, type ToolResultEndEvent, type ToolResultStartEvent, type ToolResultTextDeltaEvent, type UserConfirmResultEvent };
197
+ export { type AgentEvent, type ConfirmResult, type DataBlockDeltaEvent, type DataBlockEndEvent, type DataBlockStartEvent, type EventBase, EventType, type ExceedMaxItersEvent, type ExternalExecutionResultEvent, type ModelCallEndEvent, type ModelCallStartEvent, type ReplyEndEvent, type ReplyStartEvent, type RequireExternalExecutionEvent, type RequireUserConfirmEvent, type TextBlockDeltaEvent, type TextBlockEndEvent, type TextBlockStartEvent, type ThinkingBlockDeltaEvent, type ThinkingBlockEndEvent, type ThinkingBlockStartEvent, type ToolCallDeltaEvent, type ToolCallEndEvent, type ToolCallStartEvent, type ToolResultDataDeltaEvent, type ToolResultEndEvent, type ToolResultStartEvent, type ToolResultTextDeltaEvent, type UserConfirmResultEvent };
@@ -24,16 +24,16 @@ __export(event_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(event_exports);
26
26
  var EventType = /* @__PURE__ */ ((EventType2) => {
27
- EventType2["RUN_STARTED"] = "RUN_STARTED";
28
- EventType2["RUN_FINISHED"] = "RUN_FINISHED";
29
- EventType2["MODEL_CALL_STARTED"] = "MODEL_CALL_STARTED";
30
- EventType2["MODEL_CALL_ENDED"] = "MODEL_CALL_ENDED";
27
+ EventType2["REPLY_START"] = "REPLY_START";
28
+ EventType2["REPLY_END"] = "REPLY_END";
29
+ EventType2["MODEL_CALL_START"] = "MODEL_CALL_START";
30
+ EventType2["MODEL_CALL_END"] = "MODEL_CALL_END";
31
31
  EventType2["TEXT_BLOCK_START"] = "TEXT_BLOCK_START";
32
32
  EventType2["TEXT_BLOCK_DELTA"] = "TEXT_BLOCK_DELTA";
33
33
  EventType2["TEXT_BLOCK_END"] = "TEXT_BLOCK_END";
34
- EventType2["BINARY_BLOCK_START"] = "BINARY_BLOCK_START";
35
- EventType2["BINARY_BLOCK_DELTA"] = "BINARY_BLOCK_DELTA";
36
- EventType2["BINARY_BLOCK_END"] = "BINARY_BLOCK_END";
34
+ EventType2["DATA_BLOCK_START"] = "DATA_BLOCK_START";
35
+ EventType2["DATA_BLOCK_DELTA"] = "DATA_BLOCK_DELTA";
36
+ EventType2["DATA_BLOCK_END"] = "DATA_BLOCK_END";
37
37
  EventType2["THINKING_BLOCK_START"] = "THINKING_BLOCK_START";
38
38
  EventType2["THINKING_BLOCK_DELTA"] = "THINKING_BLOCK_DELTA";
39
39
  EventType2["THINKING_BLOCK_END"] = "THINKING_BLOCK_END";
@@ -42,7 +42,7 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
42
42
  EventType2["TOOL_CALL_END"] = "TOOL_CALL_END";
43
43
  EventType2["TOOL_RESULT_START"] = "TOOL_RESULT_START";
44
44
  EventType2["TOOL_RESULT_TEXT_DELTA"] = "TOOL_RESULT_TEXT_DELTA";
45
- EventType2["TOOL_RESULT_BINARY_DELTA"] = "TOOL_RESULT_BINARY_DELTA";
45
+ EventType2["TOOL_RESULT_DATA_DELTA"] = "TOOL_RESULT_DATA_DELTA";
46
46
  EventType2["TOOL_RESULT_END"] = "TOOL_RESULT_END";
47
47
  EventType2["EXCEED_MAX_ITERS"] = "EXCEED_MAX_ITERS";
48
48
  EventType2["REQUIRE_USER_CONFIRM"] = "REQUIRE_USER_CONFIRM";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\n\nexport enum EventType {\n RUN_STARTED = 'RUN_STARTED',\n RUN_FINISHED = 'RUN_FINISHED',\n\n MODEL_CALL_STARTED = 'MODEL_CALL_STARTED',\n MODEL_CALL_ENDED = 'MODEL_CALL_ENDED',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n BINARY_BLOCK_START = 'BINARY_BLOCK_START',\n BINARY_BLOCK_DELTA = 'BINARY_BLOCK_DELTA',\n BINARY_BLOCK_END = 'BINARY_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_BINARY_DELTA = 'TOOL_RESULT_BINARY_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n createdAt: string;\n}\n\nexport interface RunStartedEvent extends EventBase {\n type: EventType.RUN_STARTED;\n sessionId: string;\n replyId: string;\n\n // Extra fields for AG-UI protocol\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface RunFinishedEvent extends EventBase {\n type: EventType.RUN_FINISHED;\n sessionId: string;\n replyId: string;\n}\n\nexport interface ModelCallStartedEvent extends EventBase {\n type: EventType.MODEL_CALL_STARTED;\n replyId: string;\n modelName: string;\n}\n\nexport interface ModelCallEndedEvent extends EventBase {\n type: EventType.MODEL_CALL_ENDED;\n replyId: string;\n inputTokens: number;\n outputTokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n blockId: string;\n replyId: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface BinaryBlockStartEvent extends EventBase {\n type: EventType.BINARY_BLOCK_START;\n replyId: string;\n blockId: string;\n mediaType: string;\n}\n\nexport interface BinaryBlockDeltaEvent extends EventBase {\n type: EventType.BINARY_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n data: string;\n mediaType: string;\n}\n\nexport interface BinaryBlockEndEvent extends EventBase {\n type: EventType.BINARY_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n replyId: string;\n blockId: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n replyId: string;\n toolCallId: string;\n toolCallName: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n replyId: string;\n toolCallId: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n replyId: string;\n toolCallId: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n replyId: string;\n toolCallId: string;\n toolCallName: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n replyId: string;\n toolCallId: string;\n delta: string;\n}\n\nexport interface ToolResultBinaryDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_BINARY_DELTA;\n replyId: string;\n toolCallId: string;\n mediaType: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n replyId: string;\n toolCallId: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n\n replyId: string;\n agentId: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n\n replyId: string;\n toolCalls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n\n replyId: string;\n toolCalls: ToolCallBlock[];\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n\n replyId: string;\n confirmResults: {\n confirmed: boolean;\n toolCall: ToolCallBlock;\n }[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n\n replyId: string;\n executionResults: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | RunStartedEvent\n | RunFinishedEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartedEvent\n | ModelCallEndedEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | BinaryBlockStartEvent\n | BinaryBlockDeltaEvent\n | BinaryBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultBinaryDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,kBAAe;AAEf,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,8BAA2B;AAC3B,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
1
+ {"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\nimport { PermissionRule } from '../permission';\n\nexport enum EventType {\n REPLY_START = 'REPLY_START',\n REPLY_END = 'REPLY_END',\n\n MODEL_CALL_START = 'MODEL_CALL_START',\n MODEL_CALL_END = 'MODEL_CALL_END',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n DATA_BLOCK_START = 'DATA_BLOCK_START',\n DATA_BLOCK_DELTA = 'DATA_BLOCK_DELTA',\n DATA_BLOCK_END = 'DATA_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_DATA_DELTA = 'TOOL_RESULT_DATA_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n created_at: string;\n}\n\nexport interface ReplyStartEvent extends EventBase {\n type: EventType.REPLY_START;\n session_id: string;\n reply_id: string;\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface ReplyEndEvent extends EventBase {\n type: EventType.REPLY_END;\n session_id: string;\n reply_id: string;\n}\n\nexport interface ModelCallStartEvent extends EventBase {\n type: EventType.MODEL_CALL_START;\n reply_id: string;\n model_name: string;\n}\n\nexport interface ModelCallEndEvent extends EventBase {\n type: EventType.MODEL_CALL_END;\n reply_id: string;\n input_tokens: number;\n output_tokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n block_id: string;\n reply_id: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface DataBlockStartEvent extends EventBase {\n type: EventType.DATA_BLOCK_START;\n reply_id: string;\n block_id: string;\n media_type: string;\n}\n\nexport interface DataBlockDeltaEvent extends EventBase {\n type: EventType.DATA_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n data: string;\n media_type: string;\n}\n\nexport interface DataBlockEndEvent extends EventBase {\n type: EventType.DATA_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n reply_id: string;\n tool_call_id: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n reply_id: string;\n tool_call_id: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ToolResultDataDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_DATA_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n media_type: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n reply_id: string;\n tool_call_id: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n reply_id: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface ConfirmResult {\n confirmed: boolean;\n tool_call: ToolCallBlock;\n rules?: PermissionRule[] | null;\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n reply_id: string;\n confirm_results: ConfirmResult[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n reply_id: string;\n execution_results: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | ReplyStartEvent\n | ReplyEndEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartEvent\n | ModelCallEndEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | DataBlockStartEvent\n | DataBlockDeltaEvent\n | DataBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultDataDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AAEZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
@@ -1,15 +1,15 @@
1
1
  // src/event/index.ts
2
2
  var EventType = /* @__PURE__ */ ((EventType2) => {
3
- EventType2["RUN_STARTED"] = "RUN_STARTED";
4
- EventType2["RUN_FINISHED"] = "RUN_FINISHED";
5
- EventType2["MODEL_CALL_STARTED"] = "MODEL_CALL_STARTED";
6
- EventType2["MODEL_CALL_ENDED"] = "MODEL_CALL_ENDED";
3
+ EventType2["REPLY_START"] = "REPLY_START";
4
+ EventType2["REPLY_END"] = "REPLY_END";
5
+ EventType2["MODEL_CALL_START"] = "MODEL_CALL_START";
6
+ EventType2["MODEL_CALL_END"] = "MODEL_CALL_END";
7
7
  EventType2["TEXT_BLOCK_START"] = "TEXT_BLOCK_START";
8
8
  EventType2["TEXT_BLOCK_DELTA"] = "TEXT_BLOCK_DELTA";
9
9
  EventType2["TEXT_BLOCK_END"] = "TEXT_BLOCK_END";
10
- EventType2["BINARY_BLOCK_START"] = "BINARY_BLOCK_START";
11
- EventType2["BINARY_BLOCK_DELTA"] = "BINARY_BLOCK_DELTA";
12
- EventType2["BINARY_BLOCK_END"] = "BINARY_BLOCK_END";
10
+ EventType2["DATA_BLOCK_START"] = "DATA_BLOCK_START";
11
+ EventType2["DATA_BLOCK_DELTA"] = "DATA_BLOCK_DELTA";
12
+ EventType2["DATA_BLOCK_END"] = "DATA_BLOCK_END";
13
13
  EventType2["THINKING_BLOCK_START"] = "THINKING_BLOCK_START";
14
14
  EventType2["THINKING_BLOCK_DELTA"] = "THINKING_BLOCK_DELTA";
15
15
  EventType2["THINKING_BLOCK_END"] = "THINKING_BLOCK_END";
@@ -18,7 +18,7 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
18
18
  EventType2["TOOL_CALL_END"] = "TOOL_CALL_END";
19
19
  EventType2["TOOL_RESULT_START"] = "TOOL_RESULT_START";
20
20
  EventType2["TOOL_RESULT_TEXT_DELTA"] = "TOOL_RESULT_TEXT_DELTA";
21
- EventType2["TOOL_RESULT_BINARY_DELTA"] = "TOOL_RESULT_BINARY_DELTA";
21
+ EventType2["TOOL_RESULT_DATA_DELTA"] = "TOOL_RESULT_DATA_DELTA";
22
22
  EventType2["TOOL_RESULT_END"] = "TOOL_RESULT_END";
23
23
  EventType2["EXCEED_MAX_ITERS"] = "EXCEED_MAX_ITERS";
24
24
  EventType2["REQUIRE_USER_CONFIRM"] = "REQUIRE_USER_CONFIRM";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\n\nexport enum EventType {\n RUN_STARTED = 'RUN_STARTED',\n RUN_FINISHED = 'RUN_FINISHED',\n\n MODEL_CALL_STARTED = 'MODEL_CALL_STARTED',\n MODEL_CALL_ENDED = 'MODEL_CALL_ENDED',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n BINARY_BLOCK_START = 'BINARY_BLOCK_START',\n BINARY_BLOCK_DELTA = 'BINARY_BLOCK_DELTA',\n BINARY_BLOCK_END = 'BINARY_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_BINARY_DELTA = 'TOOL_RESULT_BINARY_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n createdAt: string;\n}\n\nexport interface RunStartedEvent extends EventBase {\n type: EventType.RUN_STARTED;\n sessionId: string;\n replyId: string;\n\n // Extra fields for AG-UI protocol\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface RunFinishedEvent extends EventBase {\n type: EventType.RUN_FINISHED;\n sessionId: string;\n replyId: string;\n}\n\nexport interface ModelCallStartedEvent extends EventBase {\n type: EventType.MODEL_CALL_STARTED;\n replyId: string;\n modelName: string;\n}\n\nexport interface ModelCallEndedEvent extends EventBase {\n type: EventType.MODEL_CALL_ENDED;\n replyId: string;\n inputTokens: number;\n outputTokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n blockId: string;\n replyId: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface BinaryBlockStartEvent extends EventBase {\n type: EventType.BINARY_BLOCK_START;\n replyId: string;\n blockId: string;\n mediaType: string;\n}\n\nexport interface BinaryBlockDeltaEvent extends EventBase {\n type: EventType.BINARY_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n data: string;\n mediaType: string;\n}\n\nexport interface BinaryBlockEndEvent extends EventBase {\n type: EventType.BINARY_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n replyId: string;\n blockId: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n replyId: string;\n blockId: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n replyId: string;\n blockId: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n replyId: string;\n toolCallId: string;\n toolCallName: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n replyId: string;\n toolCallId: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n replyId: string;\n toolCallId: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n replyId: string;\n toolCallId: string;\n toolCallName: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n replyId: string;\n toolCallId: string;\n delta: string;\n}\n\nexport interface ToolResultBinaryDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_BINARY_DELTA;\n replyId: string;\n toolCallId: string;\n mediaType: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n replyId: string;\n toolCallId: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n\n replyId: string;\n agentId: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n\n replyId: string;\n toolCalls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n\n replyId: string;\n toolCalls: ToolCallBlock[];\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n\n replyId: string;\n confirmResults: {\n confirmed: boolean;\n toolCall: ToolCallBlock;\n }[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n\n replyId: string;\n executionResults: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | RunStartedEvent\n | RunFinishedEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartedEvent\n | ModelCallEndedEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | BinaryBlockStartEvent\n | BinaryBlockDeltaEvent\n | BinaryBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultBinaryDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";AAEO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,kBAAe;AAEf,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,wBAAqB;AACrB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,8BAA2B;AAC3B,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
1
+ {"version":3,"sources":["../../src/event/index.ts"],"sourcesContent":["import { ToolCallBlock, ToolResultBlock } from '../message';\nimport { PermissionRule } from '../permission';\n\nexport enum EventType {\n REPLY_START = 'REPLY_START',\n REPLY_END = 'REPLY_END',\n\n MODEL_CALL_START = 'MODEL_CALL_START',\n MODEL_CALL_END = 'MODEL_CALL_END',\n\n TEXT_BLOCK_START = 'TEXT_BLOCK_START',\n TEXT_BLOCK_DELTA = 'TEXT_BLOCK_DELTA',\n TEXT_BLOCK_END = 'TEXT_BLOCK_END',\n\n DATA_BLOCK_START = 'DATA_BLOCK_START',\n DATA_BLOCK_DELTA = 'DATA_BLOCK_DELTA',\n DATA_BLOCK_END = 'DATA_BLOCK_END',\n\n THINKING_BLOCK_START = 'THINKING_BLOCK_START',\n THINKING_BLOCK_DELTA = 'THINKING_BLOCK_DELTA',\n THINKING_BLOCK_END = 'THINKING_BLOCK_END',\n\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_DELTA = 'TOOL_CALL_DELTA',\n TOOL_CALL_END = 'TOOL_CALL_END',\n\n TOOL_RESULT_START = 'TOOL_RESULT_START',\n TOOL_RESULT_TEXT_DELTA = 'TOOL_RESULT_TEXT_DELTA',\n TOOL_RESULT_DATA_DELTA = 'TOOL_RESULT_DATA_DELTA',\n TOOL_RESULT_END = 'TOOL_RESULT_END',\n\n EXCEED_MAX_ITERS = 'EXCEED_MAX_ITERS',\n\n REQUIRE_USER_CONFIRM = 'REQUIRE_USER_CONFIRM',\n REQUIRE_EXTERNAL_EXECUTION = 'REQUIRE_EXTERNAL_EXECUTION',\n\n USER_CONFIRM_RESULT = 'USER_CONFIRM_RESULT',\n EXTERNAL_EXECUTION_RESULT = 'EXTERNAL_EXECUTION_RESULT',\n}\n\nexport interface EventBase {\n id: string;\n created_at: string;\n}\n\nexport interface ReplyStartEvent extends EventBase {\n type: EventType.REPLY_START;\n session_id: string;\n reply_id: string;\n name: string;\n role: 'user' | 'assistant' | 'system';\n}\n\nexport interface ReplyEndEvent extends EventBase {\n type: EventType.REPLY_END;\n session_id: string;\n reply_id: string;\n}\n\nexport interface ModelCallStartEvent extends EventBase {\n type: EventType.MODEL_CALL_START;\n reply_id: string;\n model_name: string;\n}\n\nexport interface ModelCallEndEvent extends EventBase {\n type: EventType.MODEL_CALL_END;\n reply_id: string;\n input_tokens: number;\n output_tokens: number;\n}\n\nexport interface TextBlockStartEvent extends EventBase {\n type: EventType.TEXT_BLOCK_START;\n block_id: string;\n reply_id: string;\n}\n\nexport interface TextBlockDeltaEvent extends EventBase {\n type: EventType.TEXT_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface TextBlockEndEvent extends EventBase {\n type: EventType.TEXT_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface DataBlockStartEvent extends EventBase {\n type: EventType.DATA_BLOCK_START;\n reply_id: string;\n block_id: string;\n media_type: string;\n}\n\nexport interface DataBlockDeltaEvent extends EventBase {\n type: EventType.DATA_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n data: string;\n media_type: string;\n}\n\nexport interface DataBlockEndEvent extends EventBase {\n type: EventType.DATA_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockStartEvent extends EventBase {\n type: EventType.THINKING_BLOCK_START;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ThinkingBlockDeltaEvent extends EventBase {\n type: EventType.THINKING_BLOCK_DELTA;\n reply_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ThinkingBlockEndEvent extends EventBase {\n type: EventType.THINKING_BLOCK_END;\n reply_id: string;\n block_id: string;\n}\n\nexport interface ToolCallStartEvent extends EventBase {\n type: EventType.TOOL_CALL_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolCallDeltaEvent extends EventBase {\n type: EventType.TOOL_CALL_DELTA;\n reply_id: string;\n tool_call_id: string;\n delta: string;\n}\n\nexport interface ToolCallEndEvent extends EventBase {\n type: EventType.TOOL_CALL_END;\n reply_id: string;\n tool_call_id: string;\n}\n\nexport interface ToolResultStartEvent extends EventBase {\n type: EventType.TOOL_RESULT_START;\n reply_id: string;\n tool_call_id: string;\n tool_call_name: string;\n}\n\nexport interface ToolResultTextDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_TEXT_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n delta: string;\n}\n\nexport interface ToolResultDataDeltaEvent extends EventBase {\n type: EventType.TOOL_RESULT_DATA_DELTA;\n reply_id: string;\n tool_call_id: string;\n block_id: string;\n media_type: string;\n data?: string;\n url?: string;\n}\n\nexport interface ToolResultEndEvent extends EventBase {\n type: EventType.TOOL_RESULT_END;\n reply_id: string;\n tool_call_id: string;\n state: ToolResultBlock['state'];\n}\n\nexport interface ExceedMaxItersEvent extends EventBase {\n type: EventType.EXCEED_MAX_ITERS;\n reply_id: string;\n name: string;\n}\n\nexport interface RequireUserConfirmEvent extends EventBase {\n type: EventType.REQUIRE_USER_CONFIRM;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface RequireExternalExecutionEvent extends EventBase {\n type: EventType.REQUIRE_EXTERNAL_EXECUTION;\n reply_id: string;\n tool_calls: ToolCallBlock[];\n}\n\nexport interface ConfirmResult {\n confirmed: boolean;\n tool_call: ToolCallBlock;\n rules?: PermissionRule[] | null;\n}\n\nexport interface UserConfirmResultEvent extends EventBase {\n type: EventType.USER_CONFIRM_RESULT;\n reply_id: string;\n confirm_results: ConfirmResult[];\n}\n\nexport interface ExternalExecutionResultEvent extends EventBase {\n type: EventType.EXTERNAL_EXECUTION_RESULT;\n reply_id: string;\n execution_results: ToolResultBlock[];\n}\n\nexport type AgentEvent =\n // The control events for the whole run\n | ReplyStartEvent\n | ReplyEndEvent\n | ExceedMaxItersEvent\n | RequireUserConfirmEvent\n | RequireExternalExecutionEvent\n | ModelCallStartEvent\n | ModelCallEndEvent\n // The data events for different block types\n | TextBlockStartEvent\n | TextBlockDeltaEvent\n | TextBlockEndEvent\n | DataBlockStartEvent\n | DataBlockDeltaEvent\n | DataBlockEndEvent\n | ThinkingBlockStartEvent\n | ThinkingBlockDeltaEvent\n | ThinkingBlockEndEvent\n | ToolCallStartEvent\n | ToolCallDeltaEvent\n | ToolCallEndEvent\n | ToolResultStartEvent\n | ToolResultTextDeltaEvent\n | ToolResultDataDeltaEvent\n | ToolResultEndEvent\n // The events from the external execution or user confirmation\n | UserConfirmResultEvent\n | ExternalExecutionResultEvent;\n"],"mappings":";AAGO,IAAK,YAAL,kBAAKA,eAAL;AACH,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,eAAY;AAEZ,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,oBAAiB;AAEjB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,wBAAqB;AAErB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,mBAAgB;AAEhB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,qBAAkB;AAElB,EAAAA,WAAA,sBAAmB;AAEnB,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,gCAA6B;AAE7B,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,+BAA4B;AAlCpB,SAAAA;AAAA,GAAA;","names":["EventType"]}
@@ -1,7 +1,8 @@
1
- import { F as FormatterBase } from '../base-BOx3UzOl.mjs';
2
- import { M as Msg } from '../message-CkN21KaY.mjs';
3
- import { T as TextBlock, D as DataBlock } from '../block-VsnHrllL.mjs';
1
+ import { F as FormatterBase } from '../base-1YVBgB4n.mjs';
2
+ import { M as Msg } from '../message-DgpfAaHK.mjs';
3
+ import { T as TextBlock, D as DataBlock } from '../block-B72uPF1H.mjs';
4
4
  import '../index-CAxQAkiP.mjs';
5
+ import '../event/index.mjs';
5
6
 
6
7
  interface DashScopeFormatterOptions {
7
8
  /**
@@ -1,7 +1,8 @@
1
- import { F as FormatterBase } from '../base-BoIps2RL.js';
2
- import { M as Msg } from '../message-CzLeTlua.js';
3
- import { T as TextBlock, D as DataBlock } from '../block-VsnHrllL.js';
1
+ import { F as FormatterBase } from '../base-ChWjyzPL.js';
2
+ import { M as Msg } from '../message-CPZd0NIc.js';
3
+ import { T as TextBlock, D as DataBlock } from '../block-B72uPF1H.js';
4
4
  import '../index-CAxQAkiP.js';
5
+ import '../event/index.js';
5
6
 
6
7
  interface DashScopeFormatterOptions {
7
8
  /**
@@ -35,16 +35,16 @@ function createMsg({
35
35
  role,
36
36
  metadata = {},
37
37
  id = crypto.randomUUID(),
38
- timestamp = (/* @__PURE__ */ new Date()).toISOString(),
38
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
39
+ finished_at,
39
40
  usage
40
41
  }) {
41
- return { id, name, role, content, metadata, timestamp, usage };
42
+ const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
43
+ return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
42
44
  }
43
45
  function getTextContent(msg, separator = "\n") {
44
46
  const textBlocks = msg.content.filter((block) => block.type === "text");
45
- if (textBlocks.length === 0) {
46
- return null;
47
- }
47
+ if (textBlocks.length === 0) return null;
48
48
  return textBlocks.map((block) => block.text).join(separator);
49
49
  }
50
50
  function getContentBlocks(msg, blockType) {
@@ -74,10 +74,10 @@ var FormatterBase = class {
74
74
  textualOutput.push(block.text);
75
75
  break;
76
76
  default:
77
- const type = block.source.mediaType.split("/")[0];
77
+ const type = block.source.media_type.split("/")[0];
78
78
  if (type !== "image" && type !== "audio" && type !== "video") {
79
79
  console.log(
80
- `Unsupported media type '${block.source.mediaType}' in tool output. Only image, audio and video are supported.`
80
+ `Unsupported media type '${block.source.media_type}' in tool output. Only image, audio and video are supported.`
81
81
  );
82
82
  break;
83
83
  }
@@ -101,7 +101,7 @@ var FormatterBase = class {
101
101
  }
102
102
  const promotedBlocks = [];
103
103
  promotedData.forEach(({ id, block }) => {
104
- const type = block.source.mediaType.split("/")[0];
104
+ const type = block.source.media_type.split("/")[0];
105
105
  promotedBlocks.push({
106
106
  id: crypto.randomUUID(),
107
107
  type: "text",
@@ -247,10 +247,10 @@ var DashScopeChatFormatter = class extends FormatterBase {
247
247
  * @returns An object representing the formatted multimodal content.
248
248
  */
249
249
  _formatMultimodalBlock(block) {
250
- const type = block.source.mediaType.split("/")[0];
250
+ const type = block.source.media_type.split("/")[0];
251
251
  if (!["image", "audio", "video"].includes(type)) {
252
252
  console.log(
253
- `Skip unsupported media type ${block.source.mediaType} in DashScopeChatFormatter. Only image, audio and video are supported.`
253
+ `Skip unsupported media type ${block.source.media_type} in DashScopeChatFormatter. Only image, audio and video are supported.`
254
254
  );
255
255
  return [];
256
256
  }
@@ -259,7 +259,7 @@ var DashScopeChatFormatter = class extends FormatterBase {
259
259
  }
260
260
  return [
261
261
  {
262
- [type]: `data:${block.source.mediaType};base64,${block.source.data}`
262
+ [type]: `data:${block.source.media_type};base64,${block.source.data}`
263
263
  }
264
264
  ];
265
265
  }
@@ -510,7 +510,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
510
510
  block,
511
511
  role
512
512
  }) {
513
- const type = block.source.mediaType.split("/")[0];
513
+ const type = block.source.media_type.split("/")[0];
514
514
  if (type === "image") {
515
515
  return [
516
516
  {
@@ -533,7 +533,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
533
533
  ];
534
534
  }
535
535
  console.log(
536
- `Skip unsupported media type ${block.source.mediaType} in OpenAIChatFormatter. Only image and audio are supported.`
536
+ `Skip unsupported media type ${block.source.media_type} in OpenAIChatFormatter. Only image and audio are supported.`
537
537
  );
538
538
  return [];
539
539
  }
@@ -544,7 +544,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
544
544
  */
545
545
  async _toOpenAIImageURL(block) {
546
546
  if (block.source.type === "base64") {
547
- return `data:${block.source.mediaType};base64,${block.source.data}`;
547
+ return `data:${block.source.media_type};base64,${block.source.data}`;
548
548
  }
549
549
  const sourceUrl = block.source.url;
550
550
  if (sourceUrl.startsWith("http://") || sourceUrl.startsWith("https://")) {
@@ -565,7 +565,7 @@ var OpenAIChatFormatter = class extends FormatterBase {
565
565
  );
566
566
  }
567
567
  const file = await (0, import_promises.readFile)(localPath);
568
- const mime = block.source.mediaType || `image/${ext.slice(1)}`;
568
+ const mime = block.source.media_type || `image/${ext.slice(1)}`;
569
569
  return `data:${mime};base64,${file.toString("base64")}`;
570
570
  }
571
571
  /**
@@ -581,10 +581,10 @@ var OpenAIChatFormatter = class extends FormatterBase {
581
581
  ["audio/mpeg", "mp3"]
582
582
  ]);
583
583
  if (block.source.type === "base64") {
584
- const format2 = supportedMediaTypes.get(block.source.mediaType);
584
+ const format2 = supportedMediaTypes.get(block.source.media_type);
585
585
  if (!format2) {
586
586
  throw new TypeError(
587
- `Unsupported audio media type: ${block.source.mediaType}, only audio/wav and audio/mp3 are supported.`
587
+ `Unsupported audio media type: ${block.source.media_type}, only audio/wav and audio/mp3 are supported.`
588
588
  );
589
589
  }
590
590
  return { data: block.source.data, format: format2 };