@tdesign-react/chat 1.1.0-alpha.11 → 1.1.0-alpha.13
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/es/_chunks/dep-58d90dfe.js +438 -0
- package/es/_chunks/dep-58d90dfe.js.map +1 -0
- package/es/_chunks/dep-771678df.js +438 -0
- package/es/_chunks/dep-771678df.js.map +1 -0
- package/es/_chunks/dep-93283bbd.js +1247 -0
- package/es/_chunks/dep-93283bbd.js.map +1 -0
- package/es/_chunks/dep-dbdfe7d6.js +169 -0
- package/es/_chunks/dep-dbdfe7d6.js.map +1 -0
- package/es/_util/reactify.js +1 -1
- package/es/_util/useDynamicStyle.js +1 -1
- package/es/attachments/index.js +1 -1
- package/es/chat-actionbar/index.js +1 -1
- package/es/chat-engine/components/activity/index.js +2 -2
- package/es/chat-engine/components/activity/registry.js +1 -1
- package/es/chat-engine/components/activity/render.js +2 -2
- package/es/chat-engine/components/activity/types.js +1 -1
- package/es/chat-engine/components/index.js +17 -4
- package/es/chat-engine/components/index.js.map +1 -1
- package/es/chat-engine/components/json-render/catalog/atomic/button.js +1 -1
- package/es/chat-engine/components/json-render/catalog/atomic/card.js +1 -1
- package/es/chat-engine/components/json-render/catalog/atomic/input.js +17 -4
- package/es/chat-engine/components/json-render/catalog/atomic/input.js.map +1 -1
- package/es/chat-engine/components/json-render/catalog/atomic/layout.js +1 -1
- package/es/chat-engine/components/json-render/catalog/atomic/text.js +1 -1
- package/es/chat-engine/components/json-render/catalog/catalog-to-prompt.js +1 -1
- package/es/chat-engine/components/json-render/contexts/actions.js +2 -2
- package/es/chat-engine/components/json-render/contexts/data.js +2 -2
- package/es/chat-engine/components/json-render/contexts/index.js +2 -2
- package/es/chat-engine/components/json-render/contexts/store.js +1 -1
- package/es/chat-engine/components/json-render/contexts/tree.js +1 -1
- package/es/chat-engine/components/json-render/contexts/validation.js +2 -2
- package/es/chat-engine/components/json-render/contexts/visibility.js +2 -2
- package/es/chat-engine/components/json-render/index.js +17 -4
- package/es/chat-engine/components/json-render/index.js.map +1 -1
- package/es/chat-engine/components/json-render/registry/a2ui-binding.js +17 -4
- package/es/chat-engine/components/json-render/registry/a2ui-binding.js.map +1 -1
- package/es/chat-engine/components/json-render/registry/a2ui-registry.js +17 -4
- package/es/chat-engine/components/json-render/registry/a2ui-registry.js.map +1 -1
- package/es/chat-engine/components/json-render/registry/config.js +17 -4
- package/es/chat-engine/components/json-render/registry/config.js.map +1 -1
- package/es/chat-engine/components/json-render/registry/index.js +17 -4
- package/es/chat-engine/components/json-render/registry/index.js.map +1 -1
- package/es/chat-engine/components/json-render/renderer/A2UIJsonRenderActivityRenderer.js +16 -3
- package/es/chat-engine/components/json-render/renderer/A2UIJsonRenderActivityRenderer.js.map +1 -1
- package/es/chat-engine/components/json-render/renderer/JsonRenderActivityRenderer.js +3 -3
- package/es/chat-engine/components/json-render/renderer/JsonUIRenderer.js +2 -2
- package/es/chat-engine/components/json-render/renderer/_index.js +2 -2
- package/es/chat-engine/components/json-render/types.js +1 -1
- package/es/chat-engine/components/provider/agent-state.js +15 -2
- package/es/chat-engine/components/provider/agent-state.js.map +1 -1
- package/es/chat-engine/components/shared/ComponentErrorBoundary.js +1 -1
- package/es/chat-engine/components/shared/createRegistry.js +1 -1
- package/es/chat-engine/components/shared/index.js +1 -1
- package/es/chat-engine/components/shared/useRegistrationListener.js +1 -1
- package/es/chat-engine/components/toolcall/index.js +15 -2
- package/es/chat-engine/components/toolcall/index.js.map +1 -1
- package/es/chat-engine/components/toolcall/registry.js +1 -1
- package/es/chat-engine/components/toolcall/render.js +15 -2
- package/es/chat-engine/components/toolcall/render.js.map +1 -1
- package/es/chat-engine/components/toolcall/types.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/index.js +2 -1
- package/es/chat-engine/core/adapters/a2ui/index.js.map +1 -1
- package/es/chat-engine/core/adapters/a2ui/processor/A2uiMessageProcessor.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/processor/ComponentTree.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/processor/DataStore.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/processor/PathResolver.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/types/index.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/types/types.js +1 -1
- package/es/chat-engine/core/adapters/a2ui/utils/binding.js +2 -1631
- package/es/chat-engine/core/adapters/a2ui/utils/binding.js.map +1 -1
- package/es/chat-engine/core/adapters/a2ui/utils/index.js +2 -1
- package/es/chat-engine/core/adapters/a2ui/utils/index.js.map +1 -1
- package/es/chat-engine/core/adapters/a2ui/utils/validation.js +1 -1
- package/es/chat-engine/core/adapters/agui/ActivityManager.js +1 -1
- package/es/chat-engine/core/adapters/agui/StateManager.js +1 -1
- package/es/chat-engine/core/adapters/agui/event-mapper.js +1 -1
- package/es/chat-engine/core/adapters/agui/index.js +1 -1
- package/es/chat-engine/core/adapters/agui/types/events.js +1 -1
- package/es/chat-engine/core/adapters/agui/types/index.js +1 -1
- package/es/chat-engine/core/adapters/agui/utils.js +1 -1
- package/es/chat-engine/core/adapters/index.d.ts +2 -0
- package/es/chat-engine/core/adapters/index.js +27 -9
- package/es/chat-engine/core/adapters/index.js.map +1 -1
- package/es/chat-engine/core/adapters/json-render/SurfaceStateManager.js +1 -1
- package/es/chat-engine/core/adapters/json-render/a2ui-to-jsonrender.js +1 -1
- package/es/chat-engine/core/adapters/json-render/engine.js +1 -1
- package/es/chat-engine/core/adapters/json-render/index.js +1 -1
- package/es/chat-engine/core/adapters/json-render/types/a2ui.js +1 -1
- package/es/chat-engine/core/adapters/json-render/types/core.js +1 -1
- package/es/chat-engine/core/adapters/json-render/types/index.js +1 -1
- package/es/chat-engine/core/adapters/openclaw/event-mapper.d.ts +212 -0
- package/es/chat-engine/core/adapters/openclaw/event-mapper.js +606 -0
- package/es/chat-engine/core/adapters/openclaw/event-mapper.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/index.d.ts +158 -0
- package/es/chat-engine/core/adapters/openclaw/index.js +460 -0
- package/es/chat-engine/core/adapters/openclaw/index.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/rpc-handler.d.ts +114 -0
- package/es/chat-engine/core/adapters/openclaw/rpc-handler.js +263 -0
- package/es/chat-engine/core/adapters/openclaw/rpc-handler.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/types/config.d.ts +67 -0
- package/es/chat-engine/core/adapters/openclaw/types/config.js +35 -0
- package/es/chat-engine/core/adapters/openclaw/types/config.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/types/events.d.ts +121 -0
- package/es/chat-engine/core/adapters/openclaw/types/events.js +71 -0
- package/es/chat-engine/core/adapters/openclaw/types/events.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/types/index.d.ts +6 -0
- package/es/chat-engine/core/adapters/openclaw/types/index.js +11 -0
- package/es/chat-engine/core/adapters/openclaw/types/index.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/types/messages.d.ts +215 -0
- package/es/chat-engine/core/adapters/openclaw/types/messages.js +18 -0
- package/es/chat-engine/core/adapters/openclaw/types/messages.js.map +1 -0
- package/es/chat-engine/core/adapters/openclaw/utils.d.ts +49 -0
- package/es/chat-engine/core/adapters/openclaw/utils.js +109 -0
- package/es/chat-engine/core/adapters/openclaw/utils.js.map +1 -0
- package/es/chat-engine/core/adapters/shared/activity-manager.d.ts +11 -0
- package/es/chat-engine/core/adapters/shared/activity-manager.js +17 -0
- package/es/chat-engine/core/adapters/shared/activity-manager.js.map +1 -0
- package/es/chat-engine/core/adapters/shared/content-factory.d.ts +7 -0
- package/es/chat-engine/core/adapters/shared/content-factory.js +11 -0
- package/es/chat-engine/core/adapters/shared/content-factory.js.map +1 -0
- package/es/chat-engine/core/adapters/shared/index.d.ts +11 -0
- package/es/chat-engine/core/adapters/shared/index.js +21 -0
- package/es/chat-engine/core/adapters/shared/index.js.map +1 -0
- package/es/chat-engine/core/adapters/shared/merge-utils.d.ts +7 -0
- package/es/chat-engine/core/adapters/shared/merge-utils.js +11 -0
- package/es/chat-engine/core/adapters/shared/merge-utils.js.map +1 -0
- package/es/chat-engine/core/event-bus/ChatEventBus.js +1 -1
- package/es/chat-engine/core/event-bus/index.js +1 -1
- package/es/chat-engine/core/event-bus/types.js +1 -1
- package/es/chat-engine/core/index.d.ts +7 -0
- package/es/chat-engine/core/index.js +83 -8
- package/es/chat-engine/core/index.js.map +1 -1
- package/es/chat-engine/core/processor/index.js +1 -1
- package/es/chat-engine/core/server/batch-client.js +1 -1
- package/es/chat-engine/core/server/connection-manager.js +1 -1
- package/es/chat-engine/core/server/errors.js +1 -1
- package/es/chat-engine/core/server/index.d.ts +1 -0
- package/es/chat-engine/core/server/index.js +22 -1
- package/es/chat-engine/core/server/index.js.map +1 -1
- package/es/chat-engine/core/server/llm-service.d.ts +5 -0
- package/es/chat-engine/core/server/llm-service.js +140 -13
- package/es/chat-engine/core/server/llm-service.js.map +1 -1
- package/es/chat-engine/core/server/sse-client.js +1 -1
- package/es/chat-engine/core/server/sse-parser.js +1 -1
- package/es/chat-engine/core/server/types.js +1 -1
- package/es/chat-engine/core/server/websocket-client.d.ts +139 -0
- package/es/chat-engine/core/server/websocket-client.js +386 -0
- package/es/chat-engine/core/server/websocket-client.js.map +1 -0
- package/es/chat-engine/core/store/message.js +2 -2
- package/es/chat-engine/core/store/model.js +2 -2
- package/es/chat-engine/core/store/reactiveState.js +2 -2
- package/es/chat-engine/core/type.d.ts +7 -1
- package/es/chat-engine/core/type.js +1 -1
- package/es/chat-engine/core/utils/eventEmitter.d.ts +1 -0
- package/es/chat-engine/core/utils/eventEmitter.js +11 -1
- package/es/chat-engine/core/utils/eventEmitter.js.map +1 -1
- package/es/chat-engine/core/utils/immutable-patch.js +1 -1
- package/es/chat-engine/core/utils/index.js +1 -1
- package/es/chat-engine/core/utils/json-patch/helpers.js +1 -1
- package/es/chat-engine/core/utils/json-patch/index.js +1 -1
- package/es/chat-engine/core/utils/logger.js +1 -1
- package/es/chat-engine/core/utils/performance.js +1 -1
- package/es/chat-engine/hooks/index.js +15 -2
- package/es/chat-engine/hooks/index.js.map +1 -1
- package/es/chat-engine/hooks/useAgentActivity.js +1 -1
- package/es/chat-engine/hooks/useAgentState.js +15 -2
- package/es/chat-engine/hooks/useAgentState.js.map +1 -1
- package/es/chat-engine/hooks/useAgentToolcall.js +1 -1
- package/es/chat-engine/hooks/useChat.js +15 -2
- package/es/chat-engine/hooks/useChat.js.map +1 -1
- package/es/chat-engine/index.js +19 -6
- package/es/chat-engine/index.js.map +1 -1
- package/es/chat-filecard/index.js +1 -1
- package/es/chat-loading/index.js +1 -1
- package/es/chat-markdown/index.js +1 -1
- package/es/chat-message/index.js +1 -1
- package/es/chat-sender/index.js +1 -1
- package/es/chat-thinking/index.js +1 -1
- package/es/chatbot/index.js +1 -1
- package/es/index.js +19 -6
- package/es/index.js.map +1 -1
- package/es/style/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tdesign v1.1.0-alpha.12
|
|
3
|
+
* (c) 2026 tdesign
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
8
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
9
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
10
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
11
|
+
import { OpenClawEventType, ChatEventState, AgentStreamType, AgentDataType } from './types/events.js';
|
|
12
|
+
import '../shared/index.js';
|
|
13
|
+
import '../shared/activity-manager.js';
|
|
14
|
+
import { createToolCallContent, mergeStringContent, updateToolCall, handleSuggestionToolCall, createActivityContent } from '../agui/utils.js';
|
|
15
|
+
import { activityManager } from '../agui/ActivityManager.js';
|
|
16
|
+
import '../shared/content-factory.js';
|
|
17
|
+
import '../shared/merge-utils.js';
|
|
18
|
+
import '@babel/runtime/helpers/toConsumableArray';
|
|
19
|
+
import '../../utils/index.js';
|
|
20
|
+
import '../../utils/immutable-patch.js';
|
|
21
|
+
import '@babel/runtime/helpers/objectWithoutProperties';
|
|
22
|
+
import '@babel/runtime/helpers/toArray';
|
|
23
|
+
|
|
24
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
26
|
+
var OpenClawEventMapper = /*#__PURE__*/function () {
|
|
27
|
+
function OpenClawEventMapper() {
|
|
28
|
+
_classCallCheck(this, OpenClawEventMapper);
|
|
29
|
+
_defineProperty(this, "textBuffer", "");
|
|
30
|
+
_defineProperty(this, "currentRunId", null);
|
|
31
|
+
_defineProperty(this, "toolCallMap", {});
|
|
32
|
+
_defineProperty(this, "toolCallEnded", /* @__PURE__ */new Set());
|
|
33
|
+
}
|
|
34
|
+
return _createClass(OpenClawEventMapper, [{
|
|
35
|
+
key: "mapEvent",
|
|
36
|
+
value: function mapEvent(frame) {
|
|
37
|
+
var event = frame.event,
|
|
38
|
+
payload = frame.payload;
|
|
39
|
+
switch (event) {
|
|
40
|
+
case OpenClawEventType.CHAT:
|
|
41
|
+
return this.mapChatEvent(payload);
|
|
42
|
+
case OpenClawEventType.AGENT:
|
|
43
|
+
return this.mapAgentEvent(payload);
|
|
44
|
+
case OpenClawEventType.CONNECT_CHALLENGE:
|
|
45
|
+
return {
|
|
46
|
+
content: null,
|
|
47
|
+
isFinal: false,
|
|
48
|
+
hasError: false
|
|
49
|
+
};
|
|
50
|
+
default:
|
|
51
|
+
return this.mapGenericEvent(event, payload);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "mapChatEvent",
|
|
56
|
+
value: function mapChatEvent(payload) {
|
|
57
|
+
var state = payload.state,
|
|
58
|
+
message = payload.message,
|
|
59
|
+
runId = payload.runId,
|
|
60
|
+
errorMessage = payload.errorMessage;
|
|
61
|
+
this.currentRunId = runId || this.currentRunId;
|
|
62
|
+
switch (state) {
|
|
63
|
+
case ChatEventState.DELTA:
|
|
64
|
+
return this.handleChatDelta(message);
|
|
65
|
+
case ChatEventState.FINAL:
|
|
66
|
+
return this.handleChatFinal(message);
|
|
67
|
+
case ChatEventState.ERROR:
|
|
68
|
+
return {
|
|
69
|
+
content: this.createErrorContent(errorMessage || "Chat error"),
|
|
70
|
+
isFinal: true,
|
|
71
|
+
hasError: true,
|
|
72
|
+
errorMessage: errorMessage,
|
|
73
|
+
runId: this.currentRunId || void 0
|
|
74
|
+
};
|
|
75
|
+
case ChatEventState.ABORTED:
|
|
76
|
+
return {
|
|
77
|
+
content: null,
|
|
78
|
+
isFinal: true,
|
|
79
|
+
hasError: false,
|
|
80
|
+
runId: this.currentRunId || void 0
|
|
81
|
+
};
|
|
82
|
+
default:
|
|
83
|
+
return {
|
|
84
|
+
content: null,
|
|
85
|
+
isFinal: false,
|
|
86
|
+
hasError: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "handleChatDelta",
|
|
92
|
+
value: function handleChatDelta(message) {
|
|
93
|
+
if (!(message !== null && message !== void 0 && message.content)) {
|
|
94
|
+
return {
|
|
95
|
+
content: null,
|
|
96
|
+
isFinal: false,
|
|
97
|
+
hasError: false
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var text = this.extractTextFromContent(message.content);
|
|
101
|
+
if (text === null) {
|
|
102
|
+
return {
|
|
103
|
+
content: null,
|
|
104
|
+
isFinal: false,
|
|
105
|
+
hasError: false
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
var prevBuffer = this.textBuffer;
|
|
109
|
+
this.textBuffer = text;
|
|
110
|
+
var delta = text.startsWith(prevBuffer) ? text.slice(prevBuffer.length) : text;
|
|
111
|
+
if (!delta) {
|
|
112
|
+
return {
|
|
113
|
+
content: null,
|
|
114
|
+
isFinal: false,
|
|
115
|
+
hasError: false
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
var textContent = {
|
|
119
|
+
type: "text",
|
|
120
|
+
data: delta,
|
|
121
|
+
status: "streaming"
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
content: textContent,
|
|
125
|
+
isFinal: false,
|
|
126
|
+
hasError: false,
|
|
127
|
+
runId: this.currentRunId || void 0
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "handleChatFinal",
|
|
132
|
+
value: function handleChatFinal(_message) {
|
|
133
|
+
this.textBuffer = "";
|
|
134
|
+
var textContent = {
|
|
135
|
+
type: "text",
|
|
136
|
+
data: "",
|
|
137
|
+
status: "complete"
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
content: textContent,
|
|
141
|
+
isFinal: true,
|
|
142
|
+
hasError: false,
|
|
143
|
+
runId: this.currentRunId || void 0
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "mapAgentEvent",
|
|
148
|
+
value: function mapAgentEvent(payload) {
|
|
149
|
+
var stream = payload.stream,
|
|
150
|
+
data = payload.data,
|
|
151
|
+
runId = payload.runId;
|
|
152
|
+
this.currentRunId = runId || this.currentRunId;
|
|
153
|
+
switch (stream) {
|
|
154
|
+
case AgentStreamType.TOOL:
|
|
155
|
+
return this.handleToolStream(data);
|
|
156
|
+
case AgentStreamType.ACTIVITY:
|
|
157
|
+
return this.handleActivityStream(data);
|
|
158
|
+
case AgentStreamType.ASSISTANT:
|
|
159
|
+
case void 0:
|
|
160
|
+
default:
|
|
161
|
+
return this.handleAssistantStream(payload);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "handleAssistantStream",
|
|
166
|
+
value: function handleAssistantStream(payload) {
|
|
167
|
+
var type = payload.type,
|
|
168
|
+
data = payload.data;
|
|
169
|
+
if (data && typeof data.text === "string" && typeof data.delta === "string") {
|
|
170
|
+
return this.handleAgentTextSnapshot(data);
|
|
171
|
+
}
|
|
172
|
+
var eventType = type || (data === null || data === void 0 ? void 0 : data.type);
|
|
173
|
+
switch (eventType) {
|
|
174
|
+
case AgentDataType.TEXT_SNAPSHOT:
|
|
175
|
+
case "snapshot":
|
|
176
|
+
return this.handleAgentTextSnapshot(data);
|
|
177
|
+
case AgentDataType.TEXT_DELTA:
|
|
178
|
+
case "delta":
|
|
179
|
+
return this.handleAgentTextDelta(data);
|
|
180
|
+
case AgentDataType.DONE:
|
|
181
|
+
case "done":
|
|
182
|
+
case "complete":
|
|
183
|
+
case "final":
|
|
184
|
+
return this.handleAgentComplete();
|
|
185
|
+
case AgentDataType.ERROR:
|
|
186
|
+
case "error":
|
|
187
|
+
return {
|
|
188
|
+
content: this.createErrorContent((data === null || data === void 0 ? void 0 : data.text) || "Agent error"),
|
|
189
|
+
isFinal: true,
|
|
190
|
+
hasError: true,
|
|
191
|
+
errorMessage: data === null || data === void 0 ? void 0 : data.text,
|
|
192
|
+
runId: this.currentRunId || void 0
|
|
193
|
+
};
|
|
194
|
+
case AgentDataType.TOOL_CALL:
|
|
195
|
+
return this.handleToolCall(data);
|
|
196
|
+
case AgentDataType.TOOL_RESULT:
|
|
197
|
+
return this.handleToolResult(data);
|
|
198
|
+
default:
|
|
199
|
+
return this.handleAgentGenericData(data);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "handleAgentTextSnapshot",
|
|
204
|
+
value: function handleAgentTextSnapshot(data) {
|
|
205
|
+
var text = (data === null || data === void 0 ? void 0 : data.text) || "";
|
|
206
|
+
var delta = data === null || data === void 0 ? void 0 : data.delta;
|
|
207
|
+
if (!text && !delta) {
|
|
208
|
+
return {
|
|
209
|
+
content: null,
|
|
210
|
+
isFinal: false,
|
|
211
|
+
hasError: false
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
this.textBuffer = text;
|
|
215
|
+
var contentData = typeof delta === "string" ? delta : text;
|
|
216
|
+
if (!contentData) {
|
|
217
|
+
return {
|
|
218
|
+
content: null,
|
|
219
|
+
isFinal: false,
|
|
220
|
+
hasError: false
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
var textContent = {
|
|
224
|
+
type: "text",
|
|
225
|
+
data: contentData,
|
|
226
|
+
status: "streaming"
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
content: textContent,
|
|
230
|
+
isFinal: false,
|
|
231
|
+
hasError: false,
|
|
232
|
+
runId: this.currentRunId || void 0
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
key: "handleAgentTextDelta",
|
|
237
|
+
value: function handleAgentTextDelta(data) {
|
|
238
|
+
var delta = (data === null || data === void 0 ? void 0 : data.delta) || (data === null || data === void 0 ? void 0 : data.text) || "";
|
|
239
|
+
if (!delta) {
|
|
240
|
+
return {
|
|
241
|
+
content: null,
|
|
242
|
+
isFinal: false,
|
|
243
|
+
hasError: false
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
this.textBuffer += delta;
|
|
247
|
+
var textContent = {
|
|
248
|
+
type: "text",
|
|
249
|
+
data: delta,
|
|
250
|
+
status: "streaming"
|
|
251
|
+
};
|
|
252
|
+
return {
|
|
253
|
+
content: textContent,
|
|
254
|
+
isFinal: false,
|
|
255
|
+
hasError: false,
|
|
256
|
+
runId: this.currentRunId || void 0
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}, {
|
|
260
|
+
key: "handleAgentComplete",
|
|
261
|
+
value: function handleAgentComplete() {
|
|
262
|
+
var textContent = {
|
|
263
|
+
type: "text",
|
|
264
|
+
data: "",
|
|
265
|
+
status: "complete"
|
|
266
|
+
};
|
|
267
|
+
this.textBuffer = "";
|
|
268
|
+
return {
|
|
269
|
+
content: textContent,
|
|
270
|
+
isFinal: true,
|
|
271
|
+
hasError: false,
|
|
272
|
+
runId: this.currentRunId || void 0
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}, {
|
|
276
|
+
key: "handleAgentGenericData",
|
|
277
|
+
value: function handleAgentGenericData(data) {
|
|
278
|
+
var text = data === null || data === void 0 ? void 0 : data.text;
|
|
279
|
+
var delta = data === null || data === void 0 ? void 0 : data.delta;
|
|
280
|
+
if (typeof delta === "string" && delta) {
|
|
281
|
+
this.textBuffer += delta;
|
|
282
|
+
return {
|
|
283
|
+
content: {
|
|
284
|
+
type: "text",
|
|
285
|
+
data: delta,
|
|
286
|
+
status: "streaming"
|
|
287
|
+
},
|
|
288
|
+
isFinal: false,
|
|
289
|
+
hasError: false,
|
|
290
|
+
runId: this.currentRunId || void 0
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (typeof text === "string" && text) {
|
|
294
|
+
var prevBuffer = this.textBuffer;
|
|
295
|
+
this.textBuffer = text;
|
|
296
|
+
var contentData = text.startsWith(prevBuffer) ? text.slice(prevBuffer.length) : text;
|
|
297
|
+
if (!contentData) {
|
|
298
|
+
return {
|
|
299
|
+
content: null,
|
|
300
|
+
isFinal: false,
|
|
301
|
+
hasError: false
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
content: {
|
|
306
|
+
type: "text",
|
|
307
|
+
data: contentData,
|
|
308
|
+
status: "streaming"
|
|
309
|
+
},
|
|
310
|
+
isFinal: false,
|
|
311
|
+
hasError: false,
|
|
312
|
+
runId: this.currentRunId || void 0
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
content: null,
|
|
317
|
+
isFinal: false,
|
|
318
|
+
hasError: false
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}, {
|
|
322
|
+
key: "handleToolStream",
|
|
323
|
+
value: function handleToolStream(data) {
|
|
324
|
+
if (!(data !== null && data !== void 0 && data.toolCallId)) {
|
|
325
|
+
return {
|
|
326
|
+
content: null,
|
|
327
|
+
isFinal: false,
|
|
328
|
+
hasError: false
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
var toolCallId = data.toolCallId,
|
|
332
|
+
toolCallName = data.toolCallName,
|
|
333
|
+
state = data.state;
|
|
334
|
+
switch (state) {
|
|
335
|
+
case "start":
|
|
336
|
+
return this.handleToolCallStart(toolCallId, toolCallName, data);
|
|
337
|
+
case "args":
|
|
338
|
+
return this.handleToolCallArgs(toolCallId, data);
|
|
339
|
+
case "result":
|
|
340
|
+
return this.handleToolCallResult(toolCallId, data);
|
|
341
|
+
case "end":
|
|
342
|
+
return this.handleToolCallEnd(toolCallId);
|
|
343
|
+
default:
|
|
344
|
+
return this.handleToolCallGeneric(data);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}, {
|
|
348
|
+
key: "handleToolCallStart",
|
|
349
|
+
value: function handleToolCallStart(toolCallId, toolCallName, data) {
|
|
350
|
+
this.toolCallMap[toolCallId] = {
|
|
351
|
+
eventType: "TOOL_CALL_START",
|
|
352
|
+
toolCallId: toolCallId,
|
|
353
|
+
toolCallName: toolCallName || "unknown",
|
|
354
|
+
parentMessageId: (data === null || data === void 0 ? void 0 : data.parentMessageId) || "",
|
|
355
|
+
args: (data === null || data === void 0 ? void 0 : data.args) || (data === null || data === void 0 ? void 0 : data.delta) || ""
|
|
356
|
+
};
|
|
357
|
+
return {
|
|
358
|
+
content: createToolCallContent(this.toolCallMap[toolCallId], "pending", "append"),
|
|
359
|
+
isFinal: false,
|
|
360
|
+
hasError: false,
|
|
361
|
+
runId: this.currentRunId || void 0
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}, {
|
|
365
|
+
key: "handleToolCallArgs",
|
|
366
|
+
value: function handleToolCallArgs(toolCallId, data) {
|
|
367
|
+
if (!this.toolCallMap[toolCallId]) {
|
|
368
|
+
return {
|
|
369
|
+
content: null,
|
|
370
|
+
isFinal: false,
|
|
371
|
+
hasError: false
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
var currentArgs = this.toolCallMap[toolCallId].args || "";
|
|
375
|
+
var newArgs = mergeStringContent(currentArgs, (data === null || data === void 0 ? void 0 : data.delta) || "");
|
|
376
|
+
this.toolCallMap[toolCallId] = updateToolCall(this.toolCallMap[toolCallId], {
|
|
377
|
+
eventType: "TOOL_CALL_ARGS",
|
|
378
|
+
args: newArgs
|
|
379
|
+
});
|
|
380
|
+
return {
|
|
381
|
+
content: createToolCallContent(this.toolCallMap[toolCallId], "streaming", "merge"),
|
|
382
|
+
isFinal: false,
|
|
383
|
+
hasError: false,
|
|
384
|
+
runId: this.currentRunId || void 0
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}, {
|
|
388
|
+
key: "handleToolCallResult",
|
|
389
|
+
value: function handleToolCallResult(toolCallId, data) {
|
|
390
|
+
if (!this.toolCallMap[toolCallId]) {
|
|
391
|
+
return {
|
|
392
|
+
content: null,
|
|
393
|
+
isFinal: false,
|
|
394
|
+
hasError: false
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
var currentResult = this.toolCallMap[toolCallId].result || "";
|
|
398
|
+
var newResult = mergeStringContent(currentResult, (data === null || data === void 0 ? void 0 : data.content) || (data === null || data === void 0 ? void 0 : data.result) || "");
|
|
399
|
+
this.toolCallMap[toolCallId] = updateToolCall(this.toolCallMap[toolCallId], {
|
|
400
|
+
eventType: "TOOL_CALL_RESULT",
|
|
401
|
+
result: newResult
|
|
402
|
+
});
|
|
403
|
+
var suggestionContent = handleSuggestionToolCall(this.toolCallMap[toolCallId]);
|
|
404
|
+
if (suggestionContent) {
|
|
405
|
+
return {
|
|
406
|
+
content: suggestionContent,
|
|
407
|
+
isFinal: false,
|
|
408
|
+
hasError: false,
|
|
409
|
+
runId: this.currentRunId || void 0
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
content: createToolCallContent(this.toolCallMap[toolCallId], "complete", "merge"),
|
|
414
|
+
isFinal: false,
|
|
415
|
+
hasError: false,
|
|
416
|
+
runId: this.currentRunId || void 0
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
}, {
|
|
420
|
+
key: "handleToolCallEnd",
|
|
421
|
+
value: function handleToolCallEnd(toolCallId) {
|
|
422
|
+
this.toolCallEnded.add(toolCallId);
|
|
423
|
+
if (this.toolCallMap[toolCallId]) {
|
|
424
|
+
this.toolCallMap[toolCallId] = _objectSpread(_objectSpread({}, this.toolCallMap[toolCallId]), {}, {
|
|
425
|
+
eventType: "TOOL_CALL_END"
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
content: this.toolCallMap[toolCallId] ? createToolCallContent(this.toolCallMap[toolCallId], "complete", "merge") : null,
|
|
430
|
+
isFinal: false,
|
|
431
|
+
hasError: false,
|
|
432
|
+
runId: this.currentRunId || void 0
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
key: "handleToolCallGeneric",
|
|
437
|
+
value: function handleToolCallGeneric(data) {
|
|
438
|
+
if (!(data !== null && data !== void 0 && data.toolCallId)) {
|
|
439
|
+
return {
|
|
440
|
+
content: null,
|
|
441
|
+
isFinal: false,
|
|
442
|
+
hasError: false
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
var toolCallId = data.toolCallId;
|
|
446
|
+
var toolCallName = data.toolCallName;
|
|
447
|
+
if (!this.toolCallMap[toolCallId]) {
|
|
448
|
+
return this.handleToolCallStart(toolCallId, toolCallName, data);
|
|
449
|
+
}
|
|
450
|
+
if (data.delta || data.args) {
|
|
451
|
+
return this.handleToolCallArgs(toolCallId, data);
|
|
452
|
+
}
|
|
453
|
+
if (data.content || data.result) {
|
|
454
|
+
return this.handleToolCallResult(toolCallId, data);
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
content: null,
|
|
458
|
+
isFinal: false,
|
|
459
|
+
hasError: false
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "handleToolCall",
|
|
464
|
+
value: function handleToolCall(data) {
|
|
465
|
+
if (!(data !== null && data !== void 0 && data.toolCallId)) {
|
|
466
|
+
return {
|
|
467
|
+
content: null,
|
|
468
|
+
isFinal: false,
|
|
469
|
+
hasError: false
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
return this.handleToolCallStart(data.toolCallId, data.toolCallName || "unknown", data);
|
|
473
|
+
}
|
|
474
|
+
}, {
|
|
475
|
+
key: "handleToolResult",
|
|
476
|
+
value: function handleToolResult(data) {
|
|
477
|
+
if (!(data !== null && data !== void 0 && data.toolCallId)) {
|
|
478
|
+
return {
|
|
479
|
+
content: null,
|
|
480
|
+
isFinal: false,
|
|
481
|
+
hasError: false
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
return this.handleToolCallResult(data.toolCallId, data);
|
|
485
|
+
}
|
|
486
|
+
}, {
|
|
487
|
+
key: "handleActivityStream",
|
|
488
|
+
value: function handleActivityStream(data) {
|
|
489
|
+
if (!(data !== null && data !== void 0 && data.activityType)) {
|
|
490
|
+
return {
|
|
491
|
+
content: null,
|
|
492
|
+
isFinal: false,
|
|
493
|
+
hasError: false
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
var activityType = data.activityType;
|
|
497
|
+
var state = data.state;
|
|
498
|
+
var eventType = state === "snapshot" ? "ACTIVITY_SNAPSHOT" : "ACTIVITY_DELTA";
|
|
499
|
+
var activityData = activityManager.handleActivityEvent({
|
|
500
|
+
type: eventType,
|
|
501
|
+
activityType: activityType,
|
|
502
|
+
content: data.content,
|
|
503
|
+
patch: data.patch,
|
|
504
|
+
messageId: data.messageId
|
|
505
|
+
});
|
|
506
|
+
if (!activityData) {
|
|
507
|
+
return {
|
|
508
|
+
content: null,
|
|
509
|
+
isFinal: false,
|
|
510
|
+
hasError: false
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
var isSnapshot = state === "snapshot";
|
|
514
|
+
var existingActivity = activityManager.getActivity(activityType);
|
|
515
|
+
var isFirstEvent = isSnapshot || !existingActivity && state === "delta";
|
|
516
|
+
return {
|
|
517
|
+
content: createActivityContent(activityType, activityData.content, "streaming", isFirstEvent ? "append" : "merge", activityData.deltaInfo),
|
|
518
|
+
isFinal: false,
|
|
519
|
+
hasError: false,
|
|
520
|
+
runId: this.currentRunId || void 0
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
}, {
|
|
524
|
+
key: "mapGenericEvent",
|
|
525
|
+
value: function mapGenericEvent(_event, payload) {
|
|
526
|
+
if (_typeof(payload) === "object" && payload !== null) {
|
|
527
|
+
var p = payload;
|
|
528
|
+
var text = p.text || p.content || p.message;
|
|
529
|
+
if (typeof text === "string") {
|
|
530
|
+
return {
|
|
531
|
+
content: {
|
|
532
|
+
type: "text",
|
|
533
|
+
data: text,
|
|
534
|
+
status: "streaming"
|
|
535
|
+
},
|
|
536
|
+
isFinal: false,
|
|
537
|
+
hasError: false
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
content: null,
|
|
543
|
+
isFinal: false,
|
|
544
|
+
hasError: false
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
}, {
|
|
548
|
+
key: "extractTextFromContent",
|
|
549
|
+
value: function extractTextFromContent(content) {
|
|
550
|
+
if (!Array.isArray(content)) {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
return content.filter(function (c) {
|
|
554
|
+
return (c === null || c === void 0 ? void 0 : c.type) === "text" && (c === null || c === void 0 ? void 0 : c.text);
|
|
555
|
+
}).map(function (c) {
|
|
556
|
+
return c.text;
|
|
557
|
+
}).join("");
|
|
558
|
+
}
|
|
559
|
+
}, {
|
|
560
|
+
key: "createErrorContent",
|
|
561
|
+
value: function createErrorContent(message) {
|
|
562
|
+
return {
|
|
563
|
+
type: "text",
|
|
564
|
+
data: "Error: ".concat(message),
|
|
565
|
+
status: "error"
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
}, {
|
|
569
|
+
key: "getTextBuffer",
|
|
570
|
+
value: function getTextBuffer() {
|
|
571
|
+
return this.textBuffer;
|
|
572
|
+
}
|
|
573
|
+
}, {
|
|
574
|
+
key: "getCurrentRunId",
|
|
575
|
+
value: function getCurrentRunId() {
|
|
576
|
+
return this.currentRunId;
|
|
577
|
+
}
|
|
578
|
+
}, {
|
|
579
|
+
key: "getToolCall",
|
|
580
|
+
value: function getToolCall(toolCallId) {
|
|
581
|
+
return this.toolCallMap[toolCallId];
|
|
582
|
+
}
|
|
583
|
+
}, {
|
|
584
|
+
key: "getToolCalls",
|
|
585
|
+
value: function getToolCalls() {
|
|
586
|
+
return Object.values(this.toolCallMap);
|
|
587
|
+
}
|
|
588
|
+
}, {
|
|
589
|
+
key: "isToolCallEnded",
|
|
590
|
+
value: function isToolCallEnded(toolCallId) {
|
|
591
|
+
return this.toolCallEnded.has(toolCallId);
|
|
592
|
+
}
|
|
593
|
+
}, {
|
|
594
|
+
key: "reset",
|
|
595
|
+
value: function reset() {
|
|
596
|
+
this.textBuffer = "";
|
|
597
|
+
this.currentRunId = null;
|
|
598
|
+
this.toolCallMap = {};
|
|
599
|
+
this.toolCallEnded.clear();
|
|
600
|
+
activityManager.clear();
|
|
601
|
+
}
|
|
602
|
+
}]);
|
|
603
|
+
}();
|
|
604
|
+
|
|
605
|
+
export { OpenClawEventMapper };
|
|
606
|
+
//# sourceMappingURL=event-mapper.js.map
|