@blade-hq/agent-react 2612.0.0-beta.97 → 2612.0.0-beta.99
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/README.md +3 -2
- package/dist/McpAppCard-ADVDKC2C.js +171 -0
- package/dist/McpAppCard-ADVDKC2C.js.map +1 -0
- package/dist/McpAppFrame-VEOUJL5E.js +9 -0
- package/dist/PlanGraph-3D5PCSIJ.js +189 -0
- package/dist/PlanGraph-3D5PCSIJ.js.map +1 -0
- package/dist/{chunk-FTBMG7TK.js → SessionPluginConfigForm-DWVDFK6A.js} +2 -3
- package/dist/chat/AskUserQuestionBlock.d.ts +2 -1
- package/dist/chat/ChatPanel.d.ts +3 -1
- package/dist/chat/CurrentPlanPanel.d.ts +2 -1
- package/dist/chat/LightComposer.d.ts +1 -1
- package/dist/chat/LiteMessageList.d.ts +9 -0
- package/dist/chat/RelatedWork.d.ts +24 -0
- package/dist/chat/index.d.ts +1 -0
- package/dist/chat/plan/PlanGraph.d.ts +26 -0
- package/dist/chat/plan/PlanSurface.d.ts +9 -0
- package/dist/chat/plan/presentation.d.ts +18 -0
- package/dist/chat/runtime/actions.d.ts +1 -0
- package/dist/chat/runtime/environment.d.ts +5 -0
- package/dist/chat/runtime/session-source.d.ts +2 -0
- package/dist/chat.css +181 -0
- package/dist/{chunk-CJQINCIP.js → chunk-3RFYXI6V.js} +51 -71
- package/dist/chunk-3RFYXI6V.js.map +1 -0
- package/dist/chunk-5JAFIDDP.js +1386 -0
- package/dist/chunk-5JAFIDDP.js.map +1 -0
- package/dist/{chunk-RULD2XDA.js → chunk-67JW6ASD.js} +1561 -1199
- package/dist/chunk-67JW6ASD.js.map +1 -0
- package/dist/chunk-7WR2KG5O.js +50 -0
- package/dist/chunk-7WR2KG5O.js.map +1 -0
- package/dist/chunk-FR3ON5R4.js +30 -0
- package/dist/chunk-FR3ON5R4.js.map +1 -0
- package/dist/chunk-GRUDJLWG.js +8 -0
- package/dist/chunk-GRUDJLWG.js.map +1 -0
- package/dist/{chunk-EM7X2QZ2.js → chunk-GZHQQXYI.js} +19 -16
- package/dist/chunk-GZHQQXYI.js.map +1 -0
- package/dist/{chunk-RHUJ77ZZ.js → chunk-IOIKCFRO.js} +36 -1566
- package/dist/chunk-IOIKCFRO.js.map +1 -0
- package/dist/{chunk-IOKIQSWP.js → chunk-J6BSKVVK.js} +37 -19
- package/dist/chunk-J6BSKVVK.js.map +1 -0
- package/dist/{chunk-4VBPNAAT.js → chunk-MG4RF573.js} +33 -15
- package/dist/chunk-MG4RF573.js.map +1 -0
- package/dist/{chunk-KJDDAZZY.js → chunk-SVCTJ4VS.js} +145 -25
- package/dist/chunk-SVCTJ4VS.js.map +1 -0
- package/dist/{chunk-FXTAY3LE.js → chunk-WEOW475M.js} +17 -17
- package/dist/{chunk-FXTAY3LE.js.map → chunk-WEOW475M.js.map} +1 -1
- package/dist/{chunk-6Z7T6BOB.js → chunk-YBTELD7P.js} +7 -5
- package/dist/{chunk-6Z7T6BOB.js.map → chunk-YBTELD7P.js.map} +1 -1
- package/dist/components/AgentChat.d.ts +3 -0
- package/dist/components/McpAppCard.d.ts +1 -7
- package/dist/components/ReplayBar.d.ts +7 -1
- package/dist/components/lazy-mcp-app-card.d.ts +1 -0
- package/dist/components/lazy-mcp-app-frame.d.ts +1 -0
- package/dist/components/lazy-session-plugin-config-form.d.ts +1 -0
- package/dist/components/mcp-app-context.d.ts +7 -0
- package/dist/connectors.js +3 -3
- package/dist/embed/entry.d.ts +4 -0
- package/dist/embed/load-plan-graph.d.ts +2 -0
- package/dist/embed/plan-graph-chunk.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -9
- package/dist/internal.d.ts +4 -4
- package/dist/internal.js +29 -17
- package/dist/internal.js.map +1 -1
- package/dist/questions.js +5 -4
- package/dist/questions.js.map +1 -1
- package/dist/rich-input/ChatInput.d.ts +3 -1
- package/dist/rich-input/ComposerControls.d.ts +21 -0
- package/dist/rich-input/index.d.ts +1 -0
- package/dist/rich-input/model/resolve-model.d.ts +8 -2
- package/dist/rich-input.js +341 -267
- package/dist/rich-input.js.map +1 -1
- package/dist/style.full.css +182 -1
- package/dist/tool-details.js +6 -5
- package/dist/tool-details.js.map +1 -1
- package/package.json +2 -2
- package/public-api.md +31 -2
- package/dist/SessionPluginConfigForm-DWLJEYBY.js +0 -9
- package/dist/chunk-4VBPNAAT.js.map +0 -1
- package/dist/chunk-CJQINCIP.js.map +0 -1
- package/dist/chunk-EM7X2QZ2.js.map +0 -1
- package/dist/chunk-IOKIQSWP.js.map +0 -1
- package/dist/chunk-KJDDAZZY.js.map +0 -1
- package/dist/chunk-RHUJ77ZZ.js.map +0 -1
- package/dist/chunk-RULD2XDA.js.map +0 -1
- /package/dist/{SessionPluginConfigForm-DWLJEYBY.js.map → McpAppFrame-VEOUJL5E.js.map} +0 -0
- /package/dist/{chunk-FTBMG7TK.js.map → SessionPluginConfigForm-DWVDFK6A.js.map} +0 -0
|
@@ -0,0 +1,1386 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MarkdownContent
|
|
3
|
+
} from "./chunk-YBTELD7P.js";
|
|
4
|
+
import {
|
|
5
|
+
cn,
|
|
6
|
+
extractToolFilePath,
|
|
7
|
+
formatToolFileName,
|
|
8
|
+
formatToolName,
|
|
9
|
+
useHighlightedCode
|
|
10
|
+
} from "./chunk-3RFYXI6V.js";
|
|
11
|
+
import {
|
|
12
|
+
useBladeClient,
|
|
13
|
+
useOptionalBladeClient
|
|
14
|
+
} from "./chunk-FR3ON5R4.js";
|
|
15
|
+
import {
|
|
16
|
+
dist_exports2 as dist_exports
|
|
17
|
+
} from "./chunk-WEOW475M.js";
|
|
18
|
+
import {
|
|
19
|
+
ChevronLeft,
|
|
20
|
+
ChevronRight,
|
|
21
|
+
CircleAlert,
|
|
22
|
+
CircleCheck,
|
|
23
|
+
Download,
|
|
24
|
+
Earth,
|
|
25
|
+
ExternalLink,
|
|
26
|
+
FileText,
|
|
27
|
+
Folder,
|
|
28
|
+
Minus,
|
|
29
|
+
Plus,
|
|
30
|
+
RotateCcw,
|
|
31
|
+
X
|
|
32
|
+
} from "./chunk-J6BSKVVK.js";
|
|
33
|
+
|
|
34
|
+
// src/components/MessageImage.tsx
|
|
35
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
36
|
+
import { jsx } from "react/jsx-runtime";
|
|
37
|
+
var assetPattern = /^\/api\/(sessions|share)\/([^/]+)\/media\/([a-f0-9]{64})$/;
|
|
38
|
+
var MessageImage = forwardRef(function MessageImage2({ client: suppliedClient, src, original = false, alt, style, ...props }, ref) {
|
|
39
|
+
const contextClient = useOptionalBladeClient();
|
|
40
|
+
const client = suppliedClient ?? contextClient;
|
|
41
|
+
const element = useRef(null);
|
|
42
|
+
useImperativeHandle(ref, () => element.current);
|
|
43
|
+
const [visible, setVisible] = useState(false);
|
|
44
|
+
const [result, setResult] = useState(null);
|
|
45
|
+
const match = src?.match(assetPattern);
|
|
46
|
+
const scope = match?.[1];
|
|
47
|
+
const sessionId = match?.[2];
|
|
48
|
+
const assetId = match?.[3];
|
|
49
|
+
const identity = assetId && client ? client.buildAuthedUrl(src) : "";
|
|
50
|
+
const source = `${src}:${original}:${identity}`;
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const node = element.current;
|
|
53
|
+
if (!node || !assetId) return;
|
|
54
|
+
if (original || typeof IntersectionObserver === "undefined") {
|
|
55
|
+
setVisible(true);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const observer = new IntersectionObserver((entries) => {
|
|
59
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
60
|
+
setVisible(true);
|
|
61
|
+
observer.disconnect();
|
|
62
|
+
}
|
|
63
|
+
}, { rootMargin: "200px" });
|
|
64
|
+
observer.observe(node);
|
|
65
|
+
return () => observer.disconnect();
|
|
66
|
+
}, [assetId, original]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!visible || !client || !sessionId || !assetId) return;
|
|
69
|
+
let alive = true;
|
|
70
|
+
let objectUrl = null;
|
|
71
|
+
const pending = scope === "share" ? client.sessions.fetchSharedImage(sessionId, assetId, !original) : client.sessions.fetchImage(sessionId, assetId, !original);
|
|
72
|
+
void pending.then((blob) => {
|
|
73
|
+
if (!alive) return;
|
|
74
|
+
objectUrl = URL.createObjectURL(blob);
|
|
75
|
+
setResult({ source, client, url: objectUrl });
|
|
76
|
+
}).catch(() => {
|
|
77
|
+
if (alive) setResult({ source, client, url: null });
|
|
78
|
+
});
|
|
79
|
+
return () => {
|
|
80
|
+
alive = false;
|
|
81
|
+
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
|
82
|
+
};
|
|
83
|
+
}, [visible, client, scope, sessionId, assetId, original, source]);
|
|
84
|
+
const current = result?.source === source && result.client === client ? result : null;
|
|
85
|
+
const imageStyle = { aspectRatio: props.width && props.height ? `${props.width}/${props.height}` : void 0, ...style };
|
|
86
|
+
return /* @__PURE__ */ jsx(
|
|
87
|
+
"img",
|
|
88
|
+
{
|
|
89
|
+
...props,
|
|
90
|
+
ref: element,
|
|
91
|
+
src: assetId ? current?.url ?? void 0 : src,
|
|
92
|
+
alt: assetId && current?.url === null ? "\u56FE\u7247\u52A0\u8F7D\u5931\u8D25" : alt,
|
|
93
|
+
loading: original ? "eager" : "lazy",
|
|
94
|
+
style: assetId && !current?.url && !props.height ? { minHeight: 64, ...imageStyle } : imageStyle
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// src/components/lazy-mcp-app-card.ts
|
|
100
|
+
import { lazy } from "react";
|
|
101
|
+
var McpAppCard = lazy(async () => ({
|
|
102
|
+
default: (await import("./McpAppCard-ADVDKC2C.js")).McpAppCard
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
// src/components/ToolUiCardView.tsx
|
|
106
|
+
import { resolveToolUiCardContent } from "@blade-hq/agent-client/internal";
|
|
107
|
+
import { Suspense, useEffect as useEffect2, useState as useState2 } from "react";
|
|
108
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
109
|
+
function ToolUiCardView({ card, sessionId }) {
|
|
110
|
+
if (card.mcpApp) return sessionId ? /* @__PURE__ */ jsx2(Suspense, { fallback: null, children: /* @__PURE__ */ jsx2(McpAppCard, { sessionId, sourceId: card.mcpApp.sourceId }) }) : null;
|
|
111
|
+
const resolved = resolveToolUiCardContent(card);
|
|
112
|
+
if (!resolved) return null;
|
|
113
|
+
if (resolved.type === "resource-file") {
|
|
114
|
+
return sessionId ? /* @__PURE__ */ jsx2(FileCard, { card, sessionId, path: resolved.content }, `${sessionId}:${resolved.content}`) : null;
|
|
115
|
+
}
|
|
116
|
+
const sandbox = resolved.type === "resource-uri" ? "allow-scripts allow-same-origin" : "allow-scripts";
|
|
117
|
+
return /* @__PURE__ */ jsx2(
|
|
118
|
+
"iframe",
|
|
119
|
+
{
|
|
120
|
+
title: card.title ?? "\u5DE5\u5177\u754C\u9762",
|
|
121
|
+
src: resolved.type === "resource-uri" ? resolved.content : void 0,
|
|
122
|
+
srcDoc: resolved.type === "resource-html" ? injectBaseTag(resolved.content) : void 0,
|
|
123
|
+
sandbox,
|
|
124
|
+
loading: "lazy",
|
|
125
|
+
scrolling: "no",
|
|
126
|
+
className: "w-full rounded-xl border border-[hsl(var(--border))] bg-white",
|
|
127
|
+
referrerPolicy: "no-referrer",
|
|
128
|
+
style: { height: card.height }
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
function FileCard({ card, sessionId, path }) {
|
|
133
|
+
const client = useBladeClient();
|
|
134
|
+
const [html, setHtml] = useState2(null);
|
|
135
|
+
const [failed, setFailed] = useState2(false);
|
|
136
|
+
const [refreshVersion, setRefreshVersion] = useState2(0);
|
|
137
|
+
useEffect2(() => {
|
|
138
|
+
const abort = new AbortController();
|
|
139
|
+
setHtml(null);
|
|
140
|
+
setFailed(false);
|
|
141
|
+
void client.textFromInit(
|
|
142
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/files/${encodeURIComponent(path)}`,
|
|
143
|
+
{ signal: abort.signal }
|
|
144
|
+
).then((content) => {
|
|
145
|
+
if (!abort.signal.aborted) setHtml(content);
|
|
146
|
+
}).catch(() => {
|
|
147
|
+
if (!abort.signal.aborted) setFailed(true);
|
|
148
|
+
});
|
|
149
|
+
return () => abort.abort();
|
|
150
|
+
}, [client, sessionId, path, refreshVersion]);
|
|
151
|
+
const filePath = path.split("/").map(encodeURIComponent).join("/").replace(/^\//, "%2F");
|
|
152
|
+
const baseUrl = new URL(
|
|
153
|
+
`api/sessions/${encodeURIComponent(sessionId)}/serve/${filePath}`,
|
|
154
|
+
`${client.options.baseUrl.replace(/\/$/, "")}/`
|
|
155
|
+
).href;
|
|
156
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
157
|
+
/* @__PURE__ */ jsx2("div", { className: "flex justify-end py-2", children: /* @__PURE__ */ jsx2(
|
|
158
|
+
"button",
|
|
159
|
+
{
|
|
160
|
+
type: "button",
|
|
161
|
+
disabled: html === null && !failed,
|
|
162
|
+
onClick: () => setRefreshVersion((value) => value + 1),
|
|
163
|
+
className: "rounded-md bg-[hsl(var(--primary))] px-3 py-1 text-sm text-[hsl(var(--primary-foreground))]",
|
|
164
|
+
children: "\u5237\u65B0"
|
|
165
|
+
}
|
|
166
|
+
) }),
|
|
167
|
+
failed ? /* @__PURE__ */ jsx2("p", { role: "alert", children: "\u65E0\u6CD5\u6253\u5F00\u6587\u4EF6\uFF0C\u6587\u4EF6\u53EF\u80FD\u5DF2\u79FB\u52A8\u6216\u5220\u9664\u3002" }) : html === null ? /* @__PURE__ */ jsx2("p", { children: "\u6B63\u5728\u6253\u5F00\u6587\u4EF6\u2026" }) : /* @__PURE__ */ jsx2(
|
|
168
|
+
"iframe",
|
|
169
|
+
{
|
|
170
|
+
title: card.title ?? "\u6587\u4EF6\u9884\u89C8",
|
|
171
|
+
srcDoc: injectBaseTag(html, baseUrl),
|
|
172
|
+
sandbox: "allow-scripts",
|
|
173
|
+
loading: "lazy",
|
|
174
|
+
referrerPolicy: "no-referrer",
|
|
175
|
+
className: "w-full rounded-xl border border-[hsl(var(--border))] bg-white",
|
|
176
|
+
style: { height: card.height }
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
] });
|
|
180
|
+
}
|
|
181
|
+
function injectBaseTag(html, baseUrl = `${window.location.origin}/`) {
|
|
182
|
+
const base = `<base href="${baseUrl.replaceAll("&", "&").replaceAll('"', """)}">`;
|
|
183
|
+
const headIdx = html.toLowerCase().indexOf("<head");
|
|
184
|
+
if (headIdx >= 0) {
|
|
185
|
+
const closeIdx = html.indexOf(">", headIdx);
|
|
186
|
+
if (closeIdx >= 0) {
|
|
187
|
+
return `${html.slice(0, closeIdx + 1)}
|
|
188
|
+
${base}
|
|
189
|
+
${html.slice(closeIdx + 1)}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return `${base}
|
|
193
|
+
${html}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/chat/lib/code-language.ts
|
|
197
|
+
var SUPPORTED_LANGUAGES = [
|
|
198
|
+
"python",
|
|
199
|
+
"javascript",
|
|
200
|
+
"typescript",
|
|
201
|
+
"tsx",
|
|
202
|
+
"jsx",
|
|
203
|
+
"yaml",
|
|
204
|
+
"markdown",
|
|
205
|
+
"bash",
|
|
206
|
+
"json",
|
|
207
|
+
"go",
|
|
208
|
+
"rust",
|
|
209
|
+
"css",
|
|
210
|
+
"html"
|
|
211
|
+
];
|
|
212
|
+
var LANGUAGE_ALIASES = {
|
|
213
|
+
bash: "bash",
|
|
214
|
+
css: "css",
|
|
215
|
+
go: "go",
|
|
216
|
+
golang: "go",
|
|
217
|
+
htm: "html",
|
|
218
|
+
html: "html",
|
|
219
|
+
javascript: "javascript",
|
|
220
|
+
js: "javascript",
|
|
221
|
+
json: "json",
|
|
222
|
+
jsonc: "json",
|
|
223
|
+
jsx: "jsx",
|
|
224
|
+
markdown: "markdown",
|
|
225
|
+
md: "markdown",
|
|
226
|
+
py: "python",
|
|
227
|
+
python: "python",
|
|
228
|
+
rs: "rust",
|
|
229
|
+
rust: "rust",
|
|
230
|
+
scss: "css",
|
|
231
|
+
sh: "bash",
|
|
232
|
+
shell: "bash",
|
|
233
|
+
ts: "typescript",
|
|
234
|
+
tsx: "tsx",
|
|
235
|
+
typescript: "typescript",
|
|
236
|
+
yaml: "yaml",
|
|
237
|
+
yml: "yaml",
|
|
238
|
+
zsh: "bash"
|
|
239
|
+
};
|
|
240
|
+
var FILE_EXTENSION_ALIASES = {
|
|
241
|
+
".bash": "bash",
|
|
242
|
+
".css": "css",
|
|
243
|
+
".go": "go",
|
|
244
|
+
".htm": "html",
|
|
245
|
+
".html": "html",
|
|
246
|
+
".js": "javascript",
|
|
247
|
+
".json": "json",
|
|
248
|
+
".jsonc": "json",
|
|
249
|
+
".jsx": "jsx",
|
|
250
|
+
".md": "markdown",
|
|
251
|
+
".mdx": "markdown",
|
|
252
|
+
".py": "python",
|
|
253
|
+
".rs": "rust",
|
|
254
|
+
".scss": "css",
|
|
255
|
+
".sh": "bash",
|
|
256
|
+
".ts": "typescript",
|
|
257
|
+
".tsx": "tsx",
|
|
258
|
+
".yaml": "yaml",
|
|
259
|
+
".yml": "yaml",
|
|
260
|
+
".zsh": "bash"
|
|
261
|
+
};
|
|
262
|
+
function normalizeCodeLanguage(language) {
|
|
263
|
+
if (!language) return null;
|
|
264
|
+
return LANGUAGE_ALIASES[language.trim().toLowerCase()] ?? null;
|
|
265
|
+
}
|
|
266
|
+
function getCodeLanguageFromFilename(filePath) {
|
|
267
|
+
if (!filePath) return null;
|
|
268
|
+
const dotIndex = filePath.lastIndexOf(".");
|
|
269
|
+
if (dotIndex < 0) return null;
|
|
270
|
+
return FILE_EXTENSION_ALIASES[filePath.slice(dotIndex).toLowerCase()] ?? null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// src/chat/tool-renderers/shared.tsx
|
|
274
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
275
|
+
function getResultText(result) {
|
|
276
|
+
if (typeof result === "string") return result;
|
|
277
|
+
if (Array.isArray(result)) {
|
|
278
|
+
const texts = result.filter(
|
|
279
|
+
(p) => typeof p === "object" && p !== null && p.type === "text" && typeof p.text === "string"
|
|
280
|
+
).map((p) => p.text);
|
|
281
|
+
return texts.length > 0 ? texts.join("\n") : null;
|
|
282
|
+
}
|
|
283
|
+
return result != null ? String(result) : null;
|
|
284
|
+
}
|
|
285
|
+
function getResultImages(result) {
|
|
286
|
+
if (!Array.isArray(result)) return [];
|
|
287
|
+
return result.filter(
|
|
288
|
+
(p) => typeof p === "object" && p !== null && p.type === "image_url" && typeof p.image_url?.url === "string"
|
|
289
|
+
).map((p) => p.image_url);
|
|
290
|
+
}
|
|
291
|
+
function parseJsonValue(value) {
|
|
292
|
+
if (!value) return null;
|
|
293
|
+
try {
|
|
294
|
+
return JSON.parse(value);
|
|
295
|
+
} catch {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function isPlainObject(value) {
|
|
300
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
301
|
+
}
|
|
302
|
+
function getStringValue(data, key) {
|
|
303
|
+
const value = data?.[key];
|
|
304
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
305
|
+
}
|
|
306
|
+
function getNumberValue(data, key) {
|
|
307
|
+
const value = data?.[key];
|
|
308
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
309
|
+
}
|
|
310
|
+
function getBooleanValue(data, key) {
|
|
311
|
+
return data?.[key] === true;
|
|
312
|
+
}
|
|
313
|
+
function extractErrorMessage(value) {
|
|
314
|
+
const text = typeof value === "string" ? value : getResultText(value);
|
|
315
|
+
if (!text?.trim()) return null;
|
|
316
|
+
const parsed = parseJsonValue(text);
|
|
317
|
+
if (!isPlainObject(parsed)) return null;
|
|
318
|
+
return typeof parsed.error === "string" && parsed.error.trim() ? parsed.error.trim() : null;
|
|
319
|
+
}
|
|
320
|
+
function getFileName(filePath) {
|
|
321
|
+
if (!filePath) return "\u672A\u547D\u540D\u6587\u4EF6";
|
|
322
|
+
return filePath.split(/[\\/]/).pop() ?? filePath;
|
|
323
|
+
}
|
|
324
|
+
function getCodeLanguage(filePath) {
|
|
325
|
+
return getCodeLanguageFromFilename(filePath);
|
|
326
|
+
}
|
|
327
|
+
function formatBytes(size) {
|
|
328
|
+
if (typeof size !== "number" || !Number.isFinite(size) || size < 0) return null;
|
|
329
|
+
if (size < 1024) return `${size} B`;
|
|
330
|
+
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
|
|
331
|
+
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
|
|
332
|
+
}
|
|
333
|
+
function CodePreview({
|
|
334
|
+
content,
|
|
335
|
+
filePath,
|
|
336
|
+
emptyLabel = "\uFF08\u6682\u65E0\u5185\u5BB9\uFF09",
|
|
337
|
+
className
|
|
338
|
+
}) {
|
|
339
|
+
const { highlightedHtml } = useHighlightedCode(content, getCodeLanguage(filePath));
|
|
340
|
+
if (!content.trim()) {
|
|
341
|
+
return /* @__PURE__ */ jsx3(
|
|
342
|
+
"pre",
|
|
343
|
+
{
|
|
344
|
+
className: cn(
|
|
345
|
+
"overflow-auto rounded-lg border border-[hsl(var(--border))]",
|
|
346
|
+
"bg-[hsl(var(--muted))]/35 p-3 font-mono text-[11px] text-[hsl(var(--muted-foreground))]",
|
|
347
|
+
className
|
|
348
|
+
),
|
|
349
|
+
children: /* @__PURE__ */ jsx3("code", { children: emptyLabel })
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
return /* @__PURE__ */ jsx3(
|
|
354
|
+
"pre",
|
|
355
|
+
{
|
|
356
|
+
className: cn(
|
|
357
|
+
"overflow-auto rounded-lg border border-[hsl(var(--border))]",
|
|
358
|
+
"bg-[hsl(var(--muted))]/35 p-3 text-[11px]",
|
|
359
|
+
className
|
|
360
|
+
),
|
|
361
|
+
children: highlightedHtml ? /* @__PURE__ */ jsx3(
|
|
362
|
+
"code",
|
|
363
|
+
{
|
|
364
|
+
className: "font-mono",
|
|
365
|
+
dangerouslySetInnerHTML: { __html: highlightedHtml }
|
|
366
|
+
}
|
|
367
|
+
) : /* @__PURE__ */ jsx3("code", { className: "whitespace-pre-wrap break-words font-mono text-[hsl(var(--foreground))]", children: content })
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/chat/tool-renderers/BashRenderer.tsx
|
|
373
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
374
|
+
function pickOutputField(data) {
|
|
375
|
+
if (!data) return null;
|
|
376
|
+
for (const key of ["output", "stdout", "stderr"]) {
|
|
377
|
+
const value = data[key];
|
|
378
|
+
if (typeof value === "string") return value;
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
function MetaPill({ label }) {
|
|
383
|
+
return /* @__PURE__ */ jsx4("span", { className: "rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] text-secondary-foreground", children: label });
|
|
384
|
+
}
|
|
385
|
+
function BashRenderer({ toolCall }) {
|
|
386
|
+
const argsValue = parseJsonValue(toolCall.arguments);
|
|
387
|
+
const rawText = getResultText(toolCall.result);
|
|
388
|
+
const resultStr = typeof rawText === "string" && rawText.trim().length > 0 ? rawText : null;
|
|
389
|
+
const resultValue = parseJsonValue(resultStr);
|
|
390
|
+
const args = isPlainObject(argsValue) ? argsValue : null;
|
|
391
|
+
const result = isPlainObject(resultValue) ? resultValue : null;
|
|
392
|
+
const normalizedName = formatToolName(toolCall.name);
|
|
393
|
+
const command = getStringValue(result, "command") ?? getStringValue(args, "command") ?? "";
|
|
394
|
+
const taskId = getStringValue(result, "task_id");
|
|
395
|
+
const exitCode = getNumberValue(result, "exit_code");
|
|
396
|
+
const timedOut = getBooleanValue(result, "timed_out");
|
|
397
|
+
const truncated = getBooleanValue(result, "truncated");
|
|
398
|
+
const cwdResetNote = getStringValue(result, "cwd_reset_note");
|
|
399
|
+
const errorMessage = extractErrorMessage(toolCall.result) ?? (toolCall.status === "error" ? resultStr?.trim() ?? null : null);
|
|
400
|
+
const structuredOutput = pickOutputField(result);
|
|
401
|
+
const rawFallbackOutput = result === null && typeof resultStr === "string" && resultStr.trim().length > 0 ? resultStr : null;
|
|
402
|
+
const output = structuredOutput !== null ? structuredOutput : errorMessage ?? rawFallbackOutput ?? (normalizedName === "BgBash" ? "" : null);
|
|
403
|
+
const hasFailure = toolCall.status === "error" || timedOut || exitCode !== null && exitCode !== 0;
|
|
404
|
+
return /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
|
|
405
|
+
/* @__PURE__ */ jsxs2("div", { className: "overflow-hidden rounded-lg border border-border bg-card", children: [
|
|
406
|
+
/* @__PURE__ */ jsx4("div", { className: "border-b border-border px-3 py-2 text-[10px] uppercase tracking-[0.16em] text-muted-foreground", children: "\u547D\u4EE4" }),
|
|
407
|
+
/* @__PURE__ */ jsx4("pre", { className: "overflow-x-auto px-3 py-3 font-mono text-[11px] leading-5 text-foreground", children: /* @__PURE__ */ jsx4("code", { children: `$ ${command || "\uFF08\u672A\u63D0\u4F9B\u547D\u4EE4\uFF09"}` }) })
|
|
408
|
+
] }),
|
|
409
|
+
/* @__PURE__ */ jsxs2(
|
|
410
|
+
"div",
|
|
411
|
+
{
|
|
412
|
+
className: cn(
|
|
413
|
+
"overflow-hidden rounded-lg border bg-muted/50",
|
|
414
|
+
hasFailure ? "border-[hsl(var(--swf-danger)/0.5)]" : "border-border"
|
|
415
|
+
),
|
|
416
|
+
children: [
|
|
417
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2", children: [
|
|
418
|
+
/* @__PURE__ */ jsx4("div", { className: "text-[10px] uppercase tracking-[0.16em] text-muted-foreground", children: "\u8F93\u51FA" }),
|
|
419
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap items-center gap-1.5", children: [
|
|
420
|
+
taskId ? /* @__PURE__ */ jsx4(MetaPill, { label: `\u4EFB\u52A1 ${taskId}` }) : null,
|
|
421
|
+
exitCode !== null ? /* @__PURE__ */ jsx4(MetaPill, { label: `\u9000\u51FA\u7801 ${exitCode}` }) : null,
|
|
422
|
+
timedOut ? /* @__PURE__ */ jsx4(MetaPill, { label: "\u5DF2\u8D85\u65F6" }) : null,
|
|
423
|
+
truncated ? /* @__PURE__ */ jsx4(MetaPill, { label: "\u8F93\u51FA\u5DF2\u622A\u65AD" }) : null,
|
|
424
|
+
normalizedName === "BgBash" && !taskId ? /* @__PURE__ */ jsx4(MetaPill, { label: "\u540E\u53F0\u4EFB\u52A1" }) : null
|
|
425
|
+
] })
|
|
426
|
+
] }),
|
|
427
|
+
/* @__PURE__ */ jsx4("pre", { className: "max-h-[280px] overflow-auto px-3 py-3 font-mono text-[11px] leading-5 text-foreground", children: /* @__PURE__ */ jsx4("code", { className: "whitespace-pre-wrap break-words", children: output !== null && output.trim().length > 0 ? output : normalizedName === "BgBash" ? "\u4EFB\u52A1\u5DF2\u8FDB\u5165\u540E\u53F0\u6267\u884C\uFF0C\u8F93\u51FA\u4F1A\u5728\u540E\u53F0\u4EFB\u52A1\u9762\u677F\u4E2D\u7EE7\u7EED\u66F4\u65B0\u3002" : output !== null && output.trim().length === 0 && hasFailure ? "\u547D\u4EE4\u5DF2\u7ED3\u675F\uFF0C\u4F46\u672A\u6355\u83B7\u5230\u7EC8\u7AEF\u8F93\u51FA\uFF08\u8BF7\u67E5\u770B\u9000\u51FA\u7801\uFF09\u3002" : "\u547D\u4EE4\u672A\u8FD4\u56DE\u8F93\u51FA\u3002" }) })
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
),
|
|
431
|
+
cwdResetNote ? /* @__PURE__ */ jsx4("div", { className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/35 px-3 py-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: cwdResetNote }) : null
|
|
432
|
+
] });
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/chat/tool-renderers/write-preview-scroll.ts
|
|
436
|
+
function shouldFollowWritePreview(toolName, status) {
|
|
437
|
+
return toolName === "Write" && status === "pending";
|
|
438
|
+
}
|
|
439
|
+
function scrollWritePreviewToLatest(preview) {
|
|
440
|
+
preview.scrollTop = preview.scrollHeight;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/chat/tool-renderers/FileEditRenderer.tsx
|
|
444
|
+
import { useLayoutEffect, useRef as useRef2 } from "react";
|
|
445
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
446
|
+
var MAX_DIFF_LINES = 200;
|
|
447
|
+
var FILE_PATH_FIELDS = ["file_path", "path"];
|
|
448
|
+
function computeDiff(oldText, newText) {
|
|
449
|
+
const oldLines = oldText.split("\n");
|
|
450
|
+
const newLines = newText.split("\n");
|
|
451
|
+
if (oldLines.length > MAX_DIFF_LINES || newLines.length > MAX_DIFF_LINES) {
|
|
452
|
+
return [
|
|
453
|
+
...oldLines.slice(0, MAX_DIFF_LINES).map((line) => ({
|
|
454
|
+
type: "removed",
|
|
455
|
+
value: line,
|
|
456
|
+
line: null
|
|
457
|
+
})),
|
|
458
|
+
...newLines.slice(0, MAX_DIFF_LINES).map((line, i) => ({
|
|
459
|
+
type: "added",
|
|
460
|
+
value: line,
|
|
461
|
+
line: i + 1
|
|
462
|
+
}))
|
|
463
|
+
];
|
|
464
|
+
}
|
|
465
|
+
const rows = oldLines.length;
|
|
466
|
+
const cols = newLines.length;
|
|
467
|
+
const lcs = Array.from({ length: rows + 1 }, () => Array(cols + 1).fill(0));
|
|
468
|
+
for (let row2 = 1; row2 <= rows; row2 += 1) {
|
|
469
|
+
for (let col2 = 1; col2 <= cols; col2 += 1) {
|
|
470
|
+
lcs[row2][col2] = oldLines[row2 - 1] === newLines[col2 - 1] ? lcs[row2 - 1][col2 - 1] + 1 : Math.max(lcs[row2 - 1][col2], lcs[row2][col2 - 1]);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const diff = [];
|
|
474
|
+
let row = rows;
|
|
475
|
+
let col = cols;
|
|
476
|
+
while (row > 0 || col > 0) {
|
|
477
|
+
if (row > 0 && col > 0 && oldLines[row - 1] === newLines[col - 1]) {
|
|
478
|
+
diff.push({ type: "unchanged", value: oldLines[row - 1] });
|
|
479
|
+
row -= 1;
|
|
480
|
+
col -= 1;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (col > 0 && (row === 0 || lcs[row][col - 1] >= lcs[row - 1][col])) {
|
|
484
|
+
diff.push({ type: "added", value: newLines[col - 1] });
|
|
485
|
+
col -= 1;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (row > 0) {
|
|
489
|
+
diff.push({ type: "removed", value: oldLines[row - 1] });
|
|
490
|
+
row -= 1;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const numbered = [];
|
|
494
|
+
let lineNumber = 0;
|
|
495
|
+
for (const line of diff.reverse()) {
|
|
496
|
+
if (line.type === "removed") {
|
|
497
|
+
numbered.push({ ...line, line: null });
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
lineNumber += 1;
|
|
501
|
+
numbered.push({ ...line, line: lineNumber });
|
|
502
|
+
}
|
|
503
|
+
return numbered;
|
|
504
|
+
}
|
|
505
|
+
function buildWritePreview(content) {
|
|
506
|
+
return content.split("\n").map((line, index) => ({
|
|
507
|
+
type: "added",
|
|
508
|
+
value: line,
|
|
509
|
+
line: index + 1
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
function buildEditPreview(args, rawArguments) {
|
|
513
|
+
const edits = Array.isArray(args?.edits) ? args.edits : null;
|
|
514
|
+
if (edits) {
|
|
515
|
+
return edits.flatMap((rawEdit, index) => {
|
|
516
|
+
if (!isPlainObject(rawEdit)) {
|
|
517
|
+
return [];
|
|
518
|
+
}
|
|
519
|
+
const oldText = getStringValue(rawEdit, "old_text") ?? "";
|
|
520
|
+
const newText = getStringValue(rawEdit, "new_text") ?? "";
|
|
521
|
+
const lines = computeDiff(oldText, newText);
|
|
522
|
+
return index === 0 ? lines : [
|
|
523
|
+
{ type: "unchanged", value: "", line: null },
|
|
524
|
+
...lines
|
|
525
|
+
];
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
const oldString = getStringValue(args, "old_string") ?? "";
|
|
529
|
+
const newString = getStringValue(args, "new_string") ?? "";
|
|
530
|
+
if (!oldString && !newString && !args) {
|
|
531
|
+
return buildPartialEditPreview(rawArguments);
|
|
532
|
+
}
|
|
533
|
+
return computeDiff(oldString, newString);
|
|
534
|
+
}
|
|
535
|
+
function buildPartialEditPreview(rawArguments) {
|
|
536
|
+
const oldValues = extractAllJsonStringFieldPartials(rawArguments, "old_text");
|
|
537
|
+
const newValues = extractAllJsonStringFieldPartials(rawArguments, "new_text");
|
|
538
|
+
if (!oldValues.length && !newValues.length) return [];
|
|
539
|
+
const rows = [];
|
|
540
|
+
for (let index = 0; index < Math.max(oldValues.length, newValues.length); index += 1) {
|
|
541
|
+
if (index > 0) {
|
|
542
|
+
rows.push({ type: "unchanged", value: "", line: null });
|
|
543
|
+
}
|
|
544
|
+
const oldText = oldValues[index] ?? "";
|
|
545
|
+
const newText = newValues[index] ?? "";
|
|
546
|
+
rows.push(...computeDiff(oldText, newText));
|
|
547
|
+
}
|
|
548
|
+
return rows;
|
|
549
|
+
}
|
|
550
|
+
function extractChecksum(result) {
|
|
551
|
+
const text = typeof result === "string" ? result : null;
|
|
552
|
+
const match = text?.match(/\[checksum:\s*([^\]]+)\]/);
|
|
553
|
+
return match?.[1]?.trim() ?? null;
|
|
554
|
+
}
|
|
555
|
+
function getRawStringValue(data, key) {
|
|
556
|
+
const value = data?.[key];
|
|
557
|
+
return typeof value === "string" ? value : null;
|
|
558
|
+
}
|
|
559
|
+
function extractJsonStringFieldPartial(raw, names) {
|
|
560
|
+
for (const name of names) {
|
|
561
|
+
const values = extractAllJsonStringFieldPartials(raw, name);
|
|
562
|
+
if (values.length > 0) return values[values.length - 1] ?? "";
|
|
563
|
+
}
|
|
564
|
+
return "";
|
|
565
|
+
}
|
|
566
|
+
function extractAllJsonStringFieldPartials(raw, name) {
|
|
567
|
+
return extractAllJsonStringFields(raw, name, false);
|
|
568
|
+
}
|
|
569
|
+
function extractAllJsonStringFields(raw, name, requireClosed) {
|
|
570
|
+
const marker = `"${name}"`;
|
|
571
|
+
const values = [];
|
|
572
|
+
let searchFrom = 0;
|
|
573
|
+
while (true) {
|
|
574
|
+
const markerIndex = raw.indexOf(marker, searchFrom);
|
|
575
|
+
if (markerIndex < 0) return values;
|
|
576
|
+
const colonIndex = raw.indexOf(":", markerIndex + marker.length);
|
|
577
|
+
if (colonIndex < 0) return values;
|
|
578
|
+
const quoteIndex = raw.indexOf('"', colonIndex + 1);
|
|
579
|
+
if (quoteIndex < 0) return values;
|
|
580
|
+
const { value, closed } = readJsonString(raw, quoteIndex + 1);
|
|
581
|
+
if (closed || !requireClosed) {
|
|
582
|
+
values.push(value);
|
|
583
|
+
}
|
|
584
|
+
searchFrom = quoteIndex + 1;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function readJsonString(raw, start) {
|
|
588
|
+
const chars = [];
|
|
589
|
+
let index = start;
|
|
590
|
+
while (index < raw.length) {
|
|
591
|
+
const char = raw[index];
|
|
592
|
+
if (char === '"') {
|
|
593
|
+
return { value: chars.join(""), closed: true };
|
|
594
|
+
}
|
|
595
|
+
if (char !== "\\") {
|
|
596
|
+
chars.push(char);
|
|
597
|
+
index += 1;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (index + 1 >= raw.length) {
|
|
601
|
+
return { value: chars.join(""), closed: false };
|
|
602
|
+
}
|
|
603
|
+
const escaped = raw[index + 1];
|
|
604
|
+
if (escaped === "n") {
|
|
605
|
+
chars.push("\n");
|
|
606
|
+
} else if (escaped === "r") {
|
|
607
|
+
chars.push("\r");
|
|
608
|
+
} else if (escaped === "t") {
|
|
609
|
+
chars.push(" ");
|
|
610
|
+
} else if (escaped === '"' || escaped === "\\" || escaped === "/") {
|
|
611
|
+
chars.push(escaped);
|
|
612
|
+
} else if (escaped === "u" && index + 5 < raw.length) {
|
|
613
|
+
const code = raw.slice(index + 2, index + 6);
|
|
614
|
+
const parsed = Number.parseInt(code, 16);
|
|
615
|
+
if (Number.isFinite(parsed)) {
|
|
616
|
+
chars.push(String.fromCharCode(parsed));
|
|
617
|
+
}
|
|
618
|
+
index += 4;
|
|
619
|
+
} else {
|
|
620
|
+
chars.push(escaped ?? "");
|
|
621
|
+
}
|
|
622
|
+
index += 2;
|
|
623
|
+
}
|
|
624
|
+
return { value: chars.join(""), closed: false };
|
|
625
|
+
}
|
|
626
|
+
function FileEditRenderer({ toolCall }) {
|
|
627
|
+
const previewRef = useRef2(null);
|
|
628
|
+
const rawArguments = toolCall.arguments ?? "";
|
|
629
|
+
const argsValue = parseJsonValue(toolCall.arguments);
|
|
630
|
+
const args = isPlainObject(argsValue) ? argsValue : null;
|
|
631
|
+
const normalizedName = formatToolName(toolCall.name);
|
|
632
|
+
const partialFilePath = extractJsonStringFieldPartial(rawArguments, FILE_PATH_FIELDS);
|
|
633
|
+
const filePath = extractToolFilePath(toolCall) ?? partialFilePath;
|
|
634
|
+
const fileName = getFileName(filePath);
|
|
635
|
+
const errorMessage = extractErrorMessage(toolCall.result);
|
|
636
|
+
const displayErrorMessage = errorMessage ? "\u6587\u4EF6\u64CD\u4F5C\u5931\u8D25" : null;
|
|
637
|
+
const checksum = extractChecksum(toolCall.result);
|
|
638
|
+
const description = getStringValue(args, "description") ?? extractJsonStringFieldPartial(rawArguments, ["description"]);
|
|
639
|
+
const writeContent = getRawStringValue(args, "content") ?? extractJsonStringFieldPartial(rawArguments, ["content"]);
|
|
640
|
+
const diffLines = normalizedName === "Write" ? buildWritePreview(writeContent) : buildEditPreview(args, rawArguments);
|
|
641
|
+
const resultStr = typeof toolCall.result === "string" ? toolCall.result : null;
|
|
642
|
+
const summaryText = resultStr?.trim() && !errorMessage ? resultStr.trim() : null;
|
|
643
|
+
const displaySummaryText = summaryText && toolCall.status !== "error" && toolCall.status !== "cancelled" ? normalizedName === "Write" ? "\u6587\u4EF6\u5DF2\u5199\u5165" : "\u6587\u4EF6\u5DF2\u66F4\u65B0" : null;
|
|
644
|
+
const followLatest = shouldFollowWritePreview(normalizedName, toolCall.status);
|
|
645
|
+
useLayoutEffect(() => {
|
|
646
|
+
const preview = previewRef.current;
|
|
647
|
+
if (!preview || !followLatest || writeContent.length === 0) return;
|
|
648
|
+
scrollWritePreviewToLatest(preview);
|
|
649
|
+
}, [followLatest, writeContent]);
|
|
650
|
+
return /* @__PURE__ */ jsxs3("div", { className: "space-y-3", children: [
|
|
651
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-start justify-between gap-3", children: [
|
|
652
|
+
/* @__PURE__ */ jsxs3("div", { className: "min-w-0", children: [
|
|
653
|
+
/* @__PURE__ */ jsx5("div", { className: "text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--muted-foreground))]", children: normalizedName === "Write" ? "\u5199\u5165\u6587\u4EF6" : "\u7F16\u8F91\u6587\u4EF6" }),
|
|
654
|
+
/* @__PURE__ */ jsx5("div", { className: "truncate font-mono text-[11px] text-[hsl(var(--foreground))]", children: fileName })
|
|
655
|
+
] }),
|
|
656
|
+
checksum ? /* @__PURE__ */ jsx5("span", { className: "rounded-full border border-[hsl(var(--border))] bg-[hsl(var(--muted))] px-2 py-0.5 font-mono text-[10px] text-[hsl(var(--muted-foreground))]", children: checksum }) : null
|
|
657
|
+
] }),
|
|
658
|
+
description ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/35 px-3 py-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: description }) : null,
|
|
659
|
+
displayErrorMessage ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-[hsl(var(--swf-danger)/0.3)] bg-[hsl(var(--swf-danger-soft))] px-3 py-2 text-[11px] text-[hsl(var(--swf-danger))]", children: displayErrorMessage }) : null,
|
|
660
|
+
/* @__PURE__ */ jsxs3("div", { className: "file-edit-preview overflow-hidden rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20", children: [
|
|
661
|
+
/* @__PURE__ */ jsx5("div", { className: "border-b border-[hsl(var(--border))] px-3 py-2 text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--muted-foreground))]", children: normalizedName === "Write" ? "\u5185\u5BB9\u9884\u89C8" : "\u53D8\u66F4\u9884\u89C8" }),
|
|
662
|
+
/* @__PURE__ */ jsx5(
|
|
663
|
+
"pre",
|
|
664
|
+
{
|
|
665
|
+
ref: previewRef,
|
|
666
|
+
className: "max-h-[320px] overflow-auto p-0 font-mono text-[11px] leading-5",
|
|
667
|
+
children: diffLines.length > 0 ? diffLines.map((line, index) => {
|
|
668
|
+
const prefix = line.type === "added" ? "+ " : line.type === "removed" ? "- " : " ";
|
|
669
|
+
return /* @__PURE__ */ jsxs3(
|
|
670
|
+
"div",
|
|
671
|
+
{
|
|
672
|
+
className: cn(
|
|
673
|
+
"grid grid-cols-[2.25rem_minmax(0,1fr)] gap-0 px-2",
|
|
674
|
+
line.type === "added" && "bg-[hsl(var(--swf-success-soft))] text-[hsl(var(--swf-success))]",
|
|
675
|
+
line.type === "removed" && "bg-[hsl(var(--swf-danger-soft))] text-[hsl(var(--swf-danger))]",
|
|
676
|
+
line.type === "unchanged" && "text-[hsl(var(--foreground))]"
|
|
677
|
+
),
|
|
678
|
+
children: [
|
|
679
|
+
/* @__PURE__ */ jsx5("span", { className: "select-none py-0.5 text-right text-[10px] text-[hsl(var(--muted-foreground))]", children: line.line ?? "" }),
|
|
680
|
+
/* @__PURE__ */ jsxs3("span", { className: "min-w-0 whitespace-pre-wrap break-words py-0.5", children: [
|
|
681
|
+
prefix,
|
|
682
|
+
line.value
|
|
683
|
+
] })
|
|
684
|
+
]
|
|
685
|
+
},
|
|
686
|
+
`${line.type}-${line.line}-${index}`
|
|
687
|
+
);
|
|
688
|
+
}) : /* @__PURE__ */ jsx5("div", { className: "px-3 py-4 text-[11px] text-[hsl(var(--muted-foreground))]", children: "\u672A\u68C0\u6D4B\u5230\u53EF\u9884\u89C8\u7684\u53D8\u66F4\u3002" })
|
|
689
|
+
}
|
|
690
|
+
)
|
|
691
|
+
] }),
|
|
692
|
+
displaySummaryText ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/35 px-3 py-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: displaySummaryText }) : null
|
|
693
|
+
] });
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// src/chat/ImageLightbox.tsx
|
|
697
|
+
import { useCallback, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
698
|
+
import { Fragment, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
699
|
+
function ImageLightbox({ open, onOpenChange, images, initialIndex = 0 }) {
|
|
700
|
+
const [currentIndex, setCurrentIndex] = useState3(initialIndex);
|
|
701
|
+
const [scale, setScale] = useState3(1);
|
|
702
|
+
const [translate, setTranslate] = useState3({ x: 0, y: 0 });
|
|
703
|
+
const dragging = useRef3(false);
|
|
704
|
+
const dragStart = useRef3({ x: 0, y: 0 });
|
|
705
|
+
const translateStart = useRef3({ x: 0, y: 0 });
|
|
706
|
+
const imgRef = useRef3(null);
|
|
707
|
+
const [loadedSource, setLoadedSource] = useState3(null);
|
|
708
|
+
const reset = useCallback(() => {
|
|
709
|
+
setScale(1);
|
|
710
|
+
setTranslate({ x: 0, y: 0 });
|
|
711
|
+
}, []);
|
|
712
|
+
const close = useCallback(() => {
|
|
713
|
+
reset();
|
|
714
|
+
onOpenChange(false);
|
|
715
|
+
}, [onOpenChange, reset]);
|
|
716
|
+
const zoomIn = useCallback(() => setScale((s) => Math.min(s + 0.5, 5)), []);
|
|
717
|
+
const zoomOut = useCallback(() => setScale((s) => Math.max(s - 0.5, 0.5)), []);
|
|
718
|
+
const goPrev = useCallback(() => {
|
|
719
|
+
setLoadedSource(null);
|
|
720
|
+
setCurrentIndex((i) => Math.max(0, i - 1));
|
|
721
|
+
reset();
|
|
722
|
+
}, [reset]);
|
|
723
|
+
const goNext = useCallback(() => {
|
|
724
|
+
setLoadedSource(null);
|
|
725
|
+
setCurrentIndex((i) => Math.min(images.length - 1, i + 1));
|
|
726
|
+
reset();
|
|
727
|
+
}, [images.length, reset]);
|
|
728
|
+
const prevOpenRef = useRef3(false);
|
|
729
|
+
useEffect3(() => {
|
|
730
|
+
if (open && !prevOpenRef.current) {
|
|
731
|
+
setLoadedSource(null);
|
|
732
|
+
setCurrentIndex(initialIndex);
|
|
733
|
+
reset();
|
|
734
|
+
}
|
|
735
|
+
prevOpenRef.current = open;
|
|
736
|
+
}, [open, initialIndex, reset]);
|
|
737
|
+
const handleWheel = useCallback((e) => {
|
|
738
|
+
e.preventDefault();
|
|
739
|
+
setScale((s) => {
|
|
740
|
+
const delta = e.deltaY > 0 ? -0.2 : 0.2;
|
|
741
|
+
return Math.min(Math.max(s + delta, 0.5), 5);
|
|
742
|
+
});
|
|
743
|
+
}, []);
|
|
744
|
+
const handleMouseDown = useCallback(
|
|
745
|
+
(e) => {
|
|
746
|
+
if (scale <= 1) return;
|
|
747
|
+
e.preventDefault();
|
|
748
|
+
dragging.current = true;
|
|
749
|
+
dragStart.current = { x: e.clientX, y: e.clientY };
|
|
750
|
+
translateStart.current = { ...translate };
|
|
751
|
+
},
|
|
752
|
+
[scale, translate]
|
|
753
|
+
);
|
|
754
|
+
const handleMouseMove = useCallback((e) => {
|
|
755
|
+
if (!dragging.current) return;
|
|
756
|
+
setTranslate({
|
|
757
|
+
x: translateStart.current.x + e.clientX - dragStart.current.x,
|
|
758
|
+
y: translateStart.current.y + e.clientY - dragStart.current.y
|
|
759
|
+
});
|
|
760
|
+
}, []);
|
|
761
|
+
const handleMouseUp = useCallback(() => {
|
|
762
|
+
dragging.current = false;
|
|
763
|
+
}, []);
|
|
764
|
+
const handleDoubleClick = useCallback(() => {
|
|
765
|
+
reset();
|
|
766
|
+
}, [reset]);
|
|
767
|
+
const handleAreaClick = useCallback(
|
|
768
|
+
(e) => {
|
|
769
|
+
if (imgRef.current && !imgRef.current.contains(e.target)) {
|
|
770
|
+
close();
|
|
771
|
+
}
|
|
772
|
+
},
|
|
773
|
+
[close]
|
|
774
|
+
);
|
|
775
|
+
const handleDownload = useCallback(() => {
|
|
776
|
+
const img = images[currentIndex] ?? images[0];
|
|
777
|
+
const source = imgRef.current?.getAttribute("src");
|
|
778
|
+
if (!img || !source) return;
|
|
779
|
+
const a = document.createElement("a");
|
|
780
|
+
a.href = source;
|
|
781
|
+
a.download = img.alt || "image.png";
|
|
782
|
+
a.click();
|
|
783
|
+
}, [images, currentIndex]);
|
|
784
|
+
const handleOpenInNewTab = useCallback(() => {
|
|
785
|
+
const source = imgRef.current?.getAttribute("src");
|
|
786
|
+
if (source) window.open(source, "_blank", "noopener,noreferrer");
|
|
787
|
+
}, []);
|
|
788
|
+
if (!open) return null;
|
|
789
|
+
if (images.length === 0) {
|
|
790
|
+
return /* @__PURE__ */ jsxs4(
|
|
791
|
+
LightboxDialog,
|
|
792
|
+
{
|
|
793
|
+
onClose: close,
|
|
794
|
+
className: "fixed inset-0 z-50 flex animate-in items-center justify-center bg-black/80 fade-in-0 duration-(--motion-duration-fast)",
|
|
795
|
+
onClick: close,
|
|
796
|
+
children: [
|
|
797
|
+
/* @__PURE__ */ jsx6(
|
|
798
|
+
"button",
|
|
799
|
+
{
|
|
800
|
+
type: "button",
|
|
801
|
+
onClick: close,
|
|
802
|
+
"aria-label": "\u5173\u95ED\u56FE\u7247\u9884\u89C8",
|
|
803
|
+
className: "absolute right-4 top-4 z-10 rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
804
|
+
children: /* @__PURE__ */ jsx6(X, { size: 20 })
|
|
805
|
+
}
|
|
806
|
+
),
|
|
807
|
+
/* @__PURE__ */ jsx6("span", { className: "text-sm text-white/60", children: "\u52A0\u8F7D\u4E2D..." })
|
|
808
|
+
]
|
|
809
|
+
}
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
const current = images[currentIndex] ?? images[0];
|
|
813
|
+
const showNav = images.length > 1;
|
|
814
|
+
return /* @__PURE__ */ jsxs4(
|
|
815
|
+
LightboxDialog,
|
|
816
|
+
{
|
|
817
|
+
onClose: close,
|
|
818
|
+
onKeyDown: (event) => {
|
|
819
|
+
if (images.length > 1) {
|
|
820
|
+
if (event.key === "ArrowLeft") goPrev();
|
|
821
|
+
if (event.key === "ArrowRight") goNext();
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
className: "fixed inset-0 z-50 animate-in bg-black/80 fade-in-0 duration-(--motion-duration-fast)",
|
|
825
|
+
onClick: handleAreaClick,
|
|
826
|
+
children: [
|
|
827
|
+
/* @__PURE__ */ jsxs4(
|
|
828
|
+
"div",
|
|
829
|
+
{
|
|
830
|
+
className: "absolute right-4 top-4 z-10 flex items-center gap-1.5",
|
|
831
|
+
onClick: (e) => e.stopPropagation(),
|
|
832
|
+
children: [
|
|
833
|
+
/* @__PURE__ */ jsx6(
|
|
834
|
+
"button",
|
|
835
|
+
{
|
|
836
|
+
type: "button",
|
|
837
|
+
onClick: handleDownload,
|
|
838
|
+
disabled: loadedSource !== current.src,
|
|
839
|
+
title: loadedSource === current.src ? "\u4E0B\u8F7D\u56FE\u7247" : "\u539F\u56FE\u52A0\u8F7D\u4E2D",
|
|
840
|
+
className: "rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
841
|
+
children: /* @__PURE__ */ jsx6(Download, { size: 18 })
|
|
842
|
+
}
|
|
843
|
+
),
|
|
844
|
+
/* @__PURE__ */ jsx6(
|
|
845
|
+
"button",
|
|
846
|
+
{
|
|
847
|
+
type: "button",
|
|
848
|
+
onClick: handleOpenInNewTab,
|
|
849
|
+
disabled: loadedSource !== current.src,
|
|
850
|
+
title: loadedSource === current.src ? "\u65B0\u6807\u7B7E\u9875\u6253\u5F00" : "\u539F\u56FE\u52A0\u8F7D\u4E2D",
|
|
851
|
+
className: "rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
852
|
+
children: /* @__PURE__ */ jsx6(ExternalLink, { size: 18 })
|
|
853
|
+
}
|
|
854
|
+
),
|
|
855
|
+
/* @__PURE__ */ jsx6(
|
|
856
|
+
"button",
|
|
857
|
+
{
|
|
858
|
+
type: "button",
|
|
859
|
+
onClick: close,
|
|
860
|
+
"aria-label": "\u5173\u95ED\u56FE\u7247\u9884\u89C8",
|
|
861
|
+
className: "rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
862
|
+
children: /* @__PURE__ */ jsx6(X, { size: 20 })
|
|
863
|
+
}
|
|
864
|
+
)
|
|
865
|
+
]
|
|
866
|
+
}
|
|
867
|
+
),
|
|
868
|
+
showNav && currentIndex > 0 && /* @__PURE__ */ jsx6(
|
|
869
|
+
"button",
|
|
870
|
+
{
|
|
871
|
+
type: "button",
|
|
872
|
+
onClick: (e) => {
|
|
873
|
+
e.stopPropagation();
|
|
874
|
+
goPrev();
|
|
875
|
+
},
|
|
876
|
+
className: "absolute left-4 top-1/2 z-10 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
877
|
+
children: /* @__PURE__ */ jsx6(ChevronLeft, { size: 24 })
|
|
878
|
+
}
|
|
879
|
+
),
|
|
880
|
+
showNav && currentIndex < images.length - 1 && /* @__PURE__ */ jsx6(
|
|
881
|
+
"button",
|
|
882
|
+
{
|
|
883
|
+
type: "button",
|
|
884
|
+
onClick: (e) => {
|
|
885
|
+
e.stopPropagation();
|
|
886
|
+
goNext();
|
|
887
|
+
},
|
|
888
|
+
className: "absolute right-4 top-1/2 z-10 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white/80 transition-colors hover:bg-black/70 hover:text-white",
|
|
889
|
+
children: /* @__PURE__ */ jsx6(ChevronRight, { size: 24 })
|
|
890
|
+
}
|
|
891
|
+
),
|
|
892
|
+
/* @__PURE__ */ jsxs4("div", { className: "absolute bottom-6 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1 rounded-full bg-black/50 px-2 py-1", onClick: (event) => event.stopPropagation(), children: [
|
|
893
|
+
/* @__PURE__ */ jsx6(
|
|
894
|
+
"button",
|
|
895
|
+
{
|
|
896
|
+
type: "button",
|
|
897
|
+
onClick: zoomOut,
|
|
898
|
+
"aria-label": "\u7F29\u5C0F\u56FE\u7247",
|
|
899
|
+
className: "rounded-full p-1.5 text-white/80 transition-colors hover:bg-white/10 hover:text-white",
|
|
900
|
+
children: /* @__PURE__ */ jsx6(Minus, { size: 16 })
|
|
901
|
+
}
|
|
902
|
+
),
|
|
903
|
+
/* @__PURE__ */ jsxs4("span", { className: "min-w-[3rem] text-center text-xs text-white/80", children: [
|
|
904
|
+
Math.round(scale * 100),
|
|
905
|
+
"%"
|
|
906
|
+
] }),
|
|
907
|
+
/* @__PURE__ */ jsx6(
|
|
908
|
+
"button",
|
|
909
|
+
{
|
|
910
|
+
type: "button",
|
|
911
|
+
onClick: zoomIn,
|
|
912
|
+
"aria-label": "\u653E\u5927\u56FE\u7247",
|
|
913
|
+
className: "rounded-full p-1.5 text-white/80 transition-colors hover:bg-white/10 hover:text-white",
|
|
914
|
+
children: /* @__PURE__ */ jsx6(Plus, { size: 16 })
|
|
915
|
+
}
|
|
916
|
+
),
|
|
917
|
+
/* @__PURE__ */ jsx6(
|
|
918
|
+
"button",
|
|
919
|
+
{
|
|
920
|
+
type: "button",
|
|
921
|
+
onClick: reset,
|
|
922
|
+
"aria-label": "\u6062\u590D\u56FE\u7247\u5927\u5C0F",
|
|
923
|
+
className: "rounded-full p-1.5 text-white/80 transition-colors hover:bg-white/10 hover:text-white",
|
|
924
|
+
children: /* @__PURE__ */ jsx6(RotateCcw, { size: 16 })
|
|
925
|
+
}
|
|
926
|
+
),
|
|
927
|
+
showNav && /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
928
|
+
/* @__PURE__ */ jsx6("div", { className: "mx-1 h-4 w-px bg-white/20" }),
|
|
929
|
+
/* @__PURE__ */ jsxs4("span", { className: "min-w-[3rem] text-center text-xs text-white/80", children: [
|
|
930
|
+
currentIndex + 1,
|
|
931
|
+
" / ",
|
|
932
|
+
images.length
|
|
933
|
+
] })
|
|
934
|
+
] })
|
|
935
|
+
] }),
|
|
936
|
+
/* @__PURE__ */ jsx6(
|
|
937
|
+
"div",
|
|
938
|
+
{
|
|
939
|
+
className: "flex h-full w-full items-center justify-center overflow-hidden p-12",
|
|
940
|
+
style: { cursor: scale > 1 ? "grab" : "default" },
|
|
941
|
+
onWheel: handleWheel,
|
|
942
|
+
onMouseDown: handleMouseDown,
|
|
943
|
+
onMouseMove: handleMouseMove,
|
|
944
|
+
onMouseUp: handleMouseUp,
|
|
945
|
+
onMouseLeave: handleMouseUp,
|
|
946
|
+
onDoubleClick: handleDoubleClick,
|
|
947
|
+
children: /* @__PURE__ */ jsx6(
|
|
948
|
+
MessageImage,
|
|
949
|
+
{
|
|
950
|
+
original: true,
|
|
951
|
+
ref: imgRef,
|
|
952
|
+
src: current.src,
|
|
953
|
+
onLoad: () => setLoadedSource(current.src),
|
|
954
|
+
alt: current.alt,
|
|
955
|
+
draggable: false,
|
|
956
|
+
className: "max-h-full max-w-full select-none object-contain",
|
|
957
|
+
style: {
|
|
958
|
+
transform: `scale(${scale}) translate(${translate.x / scale}px, ${translate.y / scale}px)`,
|
|
959
|
+
transition: dragging.current ? "none" : "transform 0.2s ease"
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
)
|
|
963
|
+
}
|
|
964
|
+
)
|
|
965
|
+
]
|
|
966
|
+
}
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
function LightboxDialog({ children, className, onClose, onClick, onKeyDown }) {
|
|
970
|
+
const [opener] = useState3(() => document.activeElement);
|
|
971
|
+
return /* @__PURE__ */ jsx6(dist_exports.Root, { open: true, onOpenChange: (open) => {
|
|
972
|
+
if (!open) onClose();
|
|
973
|
+
}, children: /* @__PURE__ */ jsxs4(dist_exports.Portal, { children: [
|
|
974
|
+
/* @__PURE__ */ jsx6(dist_exports.Overlay, { className: "fixed inset-0 z-50" }),
|
|
975
|
+
/* @__PURE__ */ jsxs4(
|
|
976
|
+
dist_exports.Content,
|
|
977
|
+
{
|
|
978
|
+
className,
|
|
979
|
+
"aria-describedby": void 0,
|
|
980
|
+
onClick,
|
|
981
|
+
onKeyDown,
|
|
982
|
+
onCloseAutoFocus: (event) => {
|
|
983
|
+
event.preventDefault();
|
|
984
|
+
if (opener?.isConnected) opener.focus({ preventScroll: true });
|
|
985
|
+
},
|
|
986
|
+
children: [
|
|
987
|
+
/* @__PURE__ */ jsx6(dist_exports.Title, { className: "sr-only", children: "\u56FE\u7247\u9884\u89C8" }),
|
|
988
|
+
children
|
|
989
|
+
]
|
|
990
|
+
}
|
|
991
|
+
)
|
|
992
|
+
] }) });
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// src/chat/tool-renderers/FileReadRenderer.tsx
|
|
996
|
+
import { useState as useState4 } from "react";
|
|
997
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
998
|
+
var NUMBERED_LINE_RE = /^(\s*\d+)\t([\s\S]*)$/;
|
|
999
|
+
function parseReadResult(result) {
|
|
1000
|
+
if (!result) {
|
|
1001
|
+
return {
|
|
1002
|
+
checksum: null,
|
|
1003
|
+
content: "",
|
|
1004
|
+
endLine: null,
|
|
1005
|
+
note: null,
|
|
1006
|
+
startLine: null
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
let body = result.trimEnd();
|
|
1010
|
+
const checksumMatch = body.match(/\n\n\[checksum:\s*([^\]]+)\]\s*$/);
|
|
1011
|
+
const checksum = checksumMatch?.[1]?.trim() ?? null;
|
|
1012
|
+
if (checksumMatch?.index !== void 0) {
|
|
1013
|
+
body = body.slice(0, checksumMatch.index).trimEnd();
|
|
1014
|
+
}
|
|
1015
|
+
const noteMatch = body.match(/\n\n(文件共[\s\S]*?)\s*$/);
|
|
1016
|
+
const note = noteMatch?.[0]?.trim() ?? null;
|
|
1017
|
+
if (noteMatch?.index !== void 0) {
|
|
1018
|
+
body = body.slice(0, noteMatch.index).trimEnd();
|
|
1019
|
+
}
|
|
1020
|
+
const numberedLines = body.split("\n").map((line) => {
|
|
1021
|
+
const match = line.match(NUMBERED_LINE_RE);
|
|
1022
|
+
if (!match) return null;
|
|
1023
|
+
return {
|
|
1024
|
+
number: Number(match[1].trim()),
|
|
1025
|
+
text: match[2]
|
|
1026
|
+
};
|
|
1027
|
+
}).filter((line) => Boolean(line));
|
|
1028
|
+
return {
|
|
1029
|
+
checksum,
|
|
1030
|
+
content: numberedLines.length > 0 ? numberedLines.map((line) => line.text).join("\n") : body,
|
|
1031
|
+
endLine: numberedLines.length > 0 ? numberedLines[numberedLines.length - 1].number : null,
|
|
1032
|
+
note,
|
|
1033
|
+
startLine: numberedLines.length > 0 ? numberedLines[0].number : null
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
function formatLineRange(startLine, endLine) {
|
|
1037
|
+
if (startLine === null || endLine === null) return null;
|
|
1038
|
+
return startLine === endLine ? `\u7B2C ${startLine} \u884C` : `\u7B2C ${startLine}-${endLine} \u884C`;
|
|
1039
|
+
}
|
|
1040
|
+
function FileReadRenderer({ toolCall }) {
|
|
1041
|
+
const [lightboxIndex, setLightboxIndex] = useState4(null);
|
|
1042
|
+
const argsValue = parseJsonValue(toolCall.arguments);
|
|
1043
|
+
const args = isPlainObject(argsValue) ? argsValue : null;
|
|
1044
|
+
const filePath = extractToolFilePath(toolCall);
|
|
1045
|
+
const fileName = getFileName(filePath);
|
|
1046
|
+
const displayName = filePath ? formatToolFileName(filePath) : fileName;
|
|
1047
|
+
const description = getStringValue(args, "description");
|
|
1048
|
+
const resultText = getResultText(toolCall.result);
|
|
1049
|
+
const images = getResultImages(toolCall.result);
|
|
1050
|
+
const imageUrls = images.map((image) => image.url);
|
|
1051
|
+
const isImageResult = imageUrls.length > 0;
|
|
1052
|
+
const errorMessage = extractErrorMessage(resultText);
|
|
1053
|
+
const { checksum, content, note, startLine, endLine } = parseReadResult(resultText);
|
|
1054
|
+
const fallbackStart = getNumberValue(args, "offset") ?? 1;
|
|
1055
|
+
const lineCount = content ? content.split("\n").length : 0;
|
|
1056
|
+
const resolvedStartLine = startLine ?? (lineCount > 0 ? fallbackStart : null);
|
|
1057
|
+
const resolvedEndLine = endLine ?? (resolvedStartLine !== null && lineCount > 0 ? resolvedStartLine + lineCount - 1 : null);
|
|
1058
|
+
const lineRange = formatLineRange(resolvedStartLine, resolvedEndLine);
|
|
1059
|
+
return /* @__PURE__ */ jsxs5("div", { className: "space-y-3", children: [
|
|
1060
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex items-start justify-between gap-3", children: [
|
|
1061
|
+
/* @__PURE__ */ jsxs5("div", { className: "min-w-0", children: [
|
|
1062
|
+
/* @__PURE__ */ jsx7("div", { className: "truncate font-mono text-[11px] text-[hsl(var(--foreground))]", children: displayName }),
|
|
1063
|
+
filePath ? /* @__PURE__ */ jsx7("div", { className: "truncate text-[10px] text-[hsl(var(--muted-foreground))]", children: filePath }) : null
|
|
1064
|
+
] }),
|
|
1065
|
+
/* @__PURE__ */ jsxs5("div", { className: "flex flex-wrap items-center justify-end gap-1.5", children: [
|
|
1066
|
+
lineRange ? /* @__PURE__ */ jsx7("span", { className: "rounded-full border border-[hsl(var(--border))] bg-[hsl(var(--muted))] px-2 py-0.5 text-[10px] text-[hsl(var(--muted-foreground))]", children: lineRange }) : null,
|
|
1067
|
+
checksum ? /* @__PURE__ */ jsx7("span", { className: "rounded-full border border-[hsl(var(--border))] bg-[hsl(var(--muted))] px-2 py-0.5 font-mono text-[10px] text-[hsl(var(--muted-foreground))]", children: checksum }) : null
|
|
1068
|
+
] })
|
|
1069
|
+
] }),
|
|
1070
|
+
description ? /* @__PURE__ */ jsx7("div", { className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/35 px-3 py-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: description }) : null,
|
|
1071
|
+
errorMessage ? /* @__PURE__ */ jsx7("div", { className: "rounded-lg border border-[hsl(var(--swf-danger)/0.3)] bg-[hsl(var(--swf-danger-soft))] px-3 py-2 text-[11px] text-[hsl(var(--swf-danger))]", children: errorMessage }) : null,
|
|
1072
|
+
isImageResult ? /* @__PURE__ */ jsxs5("div", { className: "grid gap-2", children: [
|
|
1073
|
+
imageUrls.map((url, idx) => /* @__PURE__ */ jsx7(
|
|
1074
|
+
"button",
|
|
1075
|
+
{
|
|
1076
|
+
type: "button",
|
|
1077
|
+
onClick: () => setLightboxIndex(idx),
|
|
1078
|
+
className: "cursor-zoom-in",
|
|
1079
|
+
title: "\u67E5\u770B\u5927\u56FE",
|
|
1080
|
+
children: /* @__PURE__ */ jsx7(
|
|
1081
|
+
MessageImage,
|
|
1082
|
+
{
|
|
1083
|
+
src: url,
|
|
1084
|
+
width: images[idx].width,
|
|
1085
|
+
height: images[idx].height,
|
|
1086
|
+
alt: fileName,
|
|
1087
|
+
className: "max-h-64 rounded-lg border border-[hsl(var(--border))] object-contain"
|
|
1088
|
+
}
|
|
1089
|
+
)
|
|
1090
|
+
},
|
|
1091
|
+
url.slice(0, 64)
|
|
1092
|
+
)),
|
|
1093
|
+
/* @__PURE__ */ jsx7(
|
|
1094
|
+
ImageLightbox,
|
|
1095
|
+
{
|
|
1096
|
+
open: lightboxIndex != null,
|
|
1097
|
+
onOpenChange: (open) => {
|
|
1098
|
+
if (!open) setLightboxIndex(null);
|
|
1099
|
+
},
|
|
1100
|
+
images: imageUrls.map((url) => ({ src: url, alt: fileName })),
|
|
1101
|
+
initialIndex: lightboxIndex ?? 0
|
|
1102
|
+
}
|
|
1103
|
+
),
|
|
1104
|
+
content ? /* @__PURE__ */ jsx7("div", { className: "text-[11px] text-[hsl(var(--muted-foreground))]", children: content }) : null
|
|
1105
|
+
] }) : !errorMessage ? /* @__PURE__ */ jsx7(CodePreview, { content, filePath, className: "max-h-[360px]" }) : null,
|
|
1106
|
+
note ? /* @__PURE__ */ jsx7("div", { className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/35 px-3 py-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: note }) : null
|
|
1107
|
+
] });
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// src/chat/tool-renderers/SearchRenderer.tsx
|
|
1111
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1112
|
+
function toRecordArray(value) {
|
|
1113
|
+
return Array.isArray(value) ? value.filter(isPlainObject) : [];
|
|
1114
|
+
}
|
|
1115
|
+
function parseDirectoryItems(result) {
|
|
1116
|
+
const value = parseJsonValue(result);
|
|
1117
|
+
if (!Array.isArray(value)) {
|
|
1118
|
+
return [];
|
|
1119
|
+
}
|
|
1120
|
+
return value.map((item) => {
|
|
1121
|
+
if (typeof item === "string") {
|
|
1122
|
+
return {
|
|
1123
|
+
isDir: item.endsWith("/"),
|
|
1124
|
+
name: item,
|
|
1125
|
+
size: null
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
if (!isPlainObject(item)) {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
return {
|
|
1132
|
+
isDir: item.is_dir === true,
|
|
1133
|
+
name: typeof item.name === "string" ? item.name : "\u672A\u547D\u540D",
|
|
1134
|
+
size: typeof item.size === "number" ? item.size : null
|
|
1135
|
+
};
|
|
1136
|
+
}).filter((item) => Boolean(item));
|
|
1137
|
+
}
|
|
1138
|
+
function parseGrepResult(result) {
|
|
1139
|
+
if (!result?.trim()) {
|
|
1140
|
+
return { matches: [], searchPath: null };
|
|
1141
|
+
}
|
|
1142
|
+
const [header, ...rest] = result.split("\n");
|
|
1143
|
+
const searchPath = header.startsWith("\u641C\u7D22\u8DEF\u5F84:") ? header.replace("\u641C\u7D22\u8DEF\u5F84:", "").trim() : null;
|
|
1144
|
+
const matches = toRecordArray(parseJsonValue(rest.join("\n"))).map((item) => ({
|
|
1145
|
+
line: typeof item.line === "string" ? item.line : "",
|
|
1146
|
+
lineNumber: typeof item.line_number === "number" ? item.line_number : null,
|
|
1147
|
+
path: typeof item.path === "string" ? item.path : "\u672A\u77E5\u8DEF\u5F84"
|
|
1148
|
+
}));
|
|
1149
|
+
return { matches, searchPath };
|
|
1150
|
+
}
|
|
1151
|
+
function parseWebResults(result) {
|
|
1152
|
+
const value = parseJsonValue(result);
|
|
1153
|
+
const items = isPlainObject(value) ? toRecordArray(value.results) : toRecordArray(value);
|
|
1154
|
+
return items.map((item) => ({
|
|
1155
|
+
description: typeof item.text === "string" ? item.text : typeof item.description === "string" ? item.description : null,
|
|
1156
|
+
publishedDate: typeof item.published_date === "string" ? item.published_date : null,
|
|
1157
|
+
title: typeof item.title === "string" ? item.title : null,
|
|
1158
|
+
url: typeof item.url === "string" ? item.url : null
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1161
|
+
function renderEmptyState(label) {
|
|
1162
|
+
return /* @__PURE__ */ jsx8("div", { className: "rounded-lg border border-dashed border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20 px-3 py-4 text-[11px] text-[hsl(var(--muted-foreground))]", children: label });
|
|
1163
|
+
}
|
|
1164
|
+
function SearchRenderer({ toolCall }) {
|
|
1165
|
+
const normalizedName = formatToolName(toolCall.name);
|
|
1166
|
+
const argsValue = parseJsonValue(toolCall.arguments);
|
|
1167
|
+
const args = isPlainObject(argsValue) ? argsValue : null;
|
|
1168
|
+
const resultStr = getResultText(toolCall.result);
|
|
1169
|
+
const errorMessage = extractErrorMessage(resultStr);
|
|
1170
|
+
if (errorMessage) {
|
|
1171
|
+
return /* @__PURE__ */ jsx8("div", { className: "rounded-lg border border-[hsl(var(--swf-danger)/0.3)] bg-[hsl(var(--swf-danger-soft))] px-3 py-2 text-[11px] text-[hsl(var(--swf-danger))]", children: errorMessage });
|
|
1172
|
+
}
|
|
1173
|
+
if (normalizedName === "Ls" || normalizedName === "Glob") {
|
|
1174
|
+
const items = parseDirectoryItems(resultStr);
|
|
1175
|
+
const path = getStringValue(args, "path");
|
|
1176
|
+
return /* @__PURE__ */ jsxs6("div", { className: "space-y-3", children: [
|
|
1177
|
+
path ? /* @__PURE__ */ jsxs6("div", { className: "text-[11px] text-[hsl(var(--muted-foreground))]", children: [
|
|
1178
|
+
"\u76EE\u5F55\uFF1A",
|
|
1179
|
+
path
|
|
1180
|
+
] }) : null,
|
|
1181
|
+
items.length > 0 ? /* @__PURE__ */ jsx8("div", { className: "grid gap-2", children: items.map((item) => /* @__PURE__ */ jsxs6(
|
|
1182
|
+
"div",
|
|
1183
|
+
{
|
|
1184
|
+
className: "flex items-center justify-between gap-3 rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20 px-3 py-2",
|
|
1185
|
+
children: [
|
|
1186
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
1187
|
+
item.isDir ? /* @__PURE__ */ jsx8(Folder, { size: 14, className: "shrink-0 text-[hsl(var(--muted-foreground))]" }) : /* @__PURE__ */ jsx8(FileText, { size: 14, className: "shrink-0 text-[hsl(var(--muted-foreground))]" }),
|
|
1188
|
+
/* @__PURE__ */ jsx8("span", { className: "truncate font-mono text-[11px] text-[hsl(var(--foreground))]", children: item.name })
|
|
1189
|
+
] }),
|
|
1190
|
+
/* @__PURE__ */ jsx8("span", { className: "shrink-0 text-[10px] text-[hsl(var(--muted-foreground))]", children: item.isDir ? "\u76EE\u5F55" : formatBytes(item.size) ?? "\u6587\u4EF6" })
|
|
1191
|
+
]
|
|
1192
|
+
},
|
|
1193
|
+
`${item.name}-${item.size}-${item.isDir}`
|
|
1194
|
+
)) }) : renderEmptyState("\u6CA1\u6709\u53EF\u5C55\u793A\u7684\u6587\u4EF6\u7ED3\u679C\u3002")
|
|
1195
|
+
] });
|
|
1196
|
+
}
|
|
1197
|
+
if (normalizedName === "Grep") {
|
|
1198
|
+
const { matches, searchPath } = parseGrepResult(resultStr);
|
|
1199
|
+
const pattern = getStringValue(args, "pattern");
|
|
1200
|
+
return /* @__PURE__ */ jsxs6("div", { className: "space-y-3", children: [
|
|
1201
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex flex-wrap items-center gap-2 text-[11px] text-[hsl(var(--muted-foreground))]", children: [
|
|
1202
|
+
pattern ? /* @__PURE__ */ jsx8("span", { className: "rounded-full bg-[hsl(var(--muted))] px-2 py-0.5 font-mono", children: pattern }) : null,
|
|
1203
|
+
searchPath ? /* @__PURE__ */ jsxs6("span", { children: [
|
|
1204
|
+
"\u8303\u56F4\uFF1A",
|
|
1205
|
+
searchPath
|
|
1206
|
+
] }) : null
|
|
1207
|
+
] }),
|
|
1208
|
+
matches.length > 0 ? /* @__PURE__ */ jsx8("div", { className: "grid gap-2", children: matches.map((match) => /* @__PURE__ */ jsxs6(
|
|
1209
|
+
"div",
|
|
1210
|
+
{
|
|
1211
|
+
className: "rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20 px-3 py-2",
|
|
1212
|
+
children: [
|
|
1213
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between gap-3", children: [
|
|
1214
|
+
/* @__PURE__ */ jsx8("span", { className: "truncate font-mono text-[11px] text-[hsl(var(--foreground))]", children: match.path }),
|
|
1215
|
+
match.lineNumber !== null ? /* @__PURE__ */ jsxs6("span", { className: "shrink-0 text-[10px] text-[hsl(var(--muted-foreground))]", children: [
|
|
1216
|
+
"\u7B2C ",
|
|
1217
|
+
match.lineNumber,
|
|
1218
|
+
" \u884C"
|
|
1219
|
+
] }) : null
|
|
1220
|
+
] }),
|
|
1221
|
+
/* @__PURE__ */ jsx8("pre", { className: "mt-2 overflow-x-auto whitespace-pre-wrap font-mono text-[11px] text-[hsl(var(--muted-foreground))]", children: /* @__PURE__ */ jsx8("code", { children: match.line }) })
|
|
1222
|
+
]
|
|
1223
|
+
},
|
|
1224
|
+
`${match.path}-${match.lineNumber}-${match.line}`
|
|
1225
|
+
)) }) : renderEmptyState("\u6CA1\u6709\u627E\u5230\u5339\u914D\u7ED3\u679C\u3002")
|
|
1226
|
+
] });
|
|
1227
|
+
}
|
|
1228
|
+
if (normalizedName === "WebFetch") {
|
|
1229
|
+
const url = getStringValue(args, "url");
|
|
1230
|
+
const text = resultStr?.trim();
|
|
1231
|
+
return /* @__PURE__ */ jsxs6("div", { className: "space-y-3", children: [
|
|
1232
|
+
url ? /* @__PURE__ */ jsxs6(
|
|
1233
|
+
"a",
|
|
1234
|
+
{
|
|
1235
|
+
href: url,
|
|
1236
|
+
target: "_blank",
|
|
1237
|
+
rel: "noreferrer",
|
|
1238
|
+
className: "flex items-center gap-2 truncate font-mono text-[10px] text-[hsl(var(--muted-foreground))] hover:text-[hsl(var(--foreground))]",
|
|
1239
|
+
children: [
|
|
1240
|
+
/* @__PURE__ */ jsx8(Earth, { size: 12, className: "shrink-0" }),
|
|
1241
|
+
/* @__PURE__ */ jsx8("span", { className: "truncate", children: url }),
|
|
1242
|
+
/* @__PURE__ */ jsx8(ExternalLink, { size: 11, className: "shrink-0" })
|
|
1243
|
+
]
|
|
1244
|
+
}
|
|
1245
|
+
) : null,
|
|
1246
|
+
text ? /* @__PURE__ */ jsx8("div", { className: "max-h-80 overflow-y-auto rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20 px-3 py-3", children: /* @__PURE__ */ jsx8("p", { className: "whitespace-pre-wrap text-[11px] leading-5 text-[hsl(var(--foreground))]", children: text }) }) : renderEmptyState("\u8FD9\u4E2A\u7F51\u9875\u6CA1\u6709\u53EF\u5C55\u793A\u7684\u6B63\u6587\u3002")
|
|
1247
|
+
] });
|
|
1248
|
+
}
|
|
1249
|
+
const results = parseWebResults(resultStr);
|
|
1250
|
+
const query = getStringValue(args, "query");
|
|
1251
|
+
return /* @__PURE__ */ jsxs6("div", { className: "space-y-3", children: [
|
|
1252
|
+
query ? /* @__PURE__ */ jsxs6("div", { className: "text-[11px] text-[hsl(var(--muted-foreground))]", children: [
|
|
1253
|
+
"\u67E5\u8BE2\uFF1A",
|
|
1254
|
+
query
|
|
1255
|
+
] }) : null,
|
|
1256
|
+
results.length > 0 ? /* @__PURE__ */ jsx8("div", { className: "grid gap-2", children: results.map((item, index) => /* @__PURE__ */ jsx8(
|
|
1257
|
+
"a",
|
|
1258
|
+
{
|
|
1259
|
+
href: item.url ?? void 0,
|
|
1260
|
+
target: "_blank",
|
|
1261
|
+
rel: "noreferrer",
|
|
1262
|
+
className: cn(
|
|
1263
|
+
"rounded-lg border border-[hsl(var(--border))] bg-[hsl(var(--muted))]/20 px-3 py-3 transition-colors",
|
|
1264
|
+
item.url && "hover:border-[hsl(var(--ring))] hover:bg-[hsl(var(--muted))]/35"
|
|
1265
|
+
),
|
|
1266
|
+
children: /* @__PURE__ */ jsxs6("div", { className: "flex items-start gap-3", children: [
|
|
1267
|
+
/* @__PURE__ */ jsx8(Earth, { size: 16, className: "mt-0.5 shrink-0 text-[hsl(var(--muted-foreground))]" }),
|
|
1268
|
+
/* @__PURE__ */ jsxs6("div", { className: "min-w-0 flex-1", children: [
|
|
1269
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-start justify-between gap-3", children: [
|
|
1270
|
+
/* @__PURE__ */ jsx8("span", { className: "line-clamp-2 text-[11px] font-medium text-[hsl(var(--foreground))]", children: item.title ?? item.url ?? "\u672A\u547D\u540D\u7ED3\u679C" }),
|
|
1271
|
+
item.url ? /* @__PURE__ */ jsx8(
|
|
1272
|
+
ExternalLink,
|
|
1273
|
+
{
|
|
1274
|
+
size: 12,
|
|
1275
|
+
className: "mt-0.5 shrink-0 text-[hsl(var(--muted-foreground))]"
|
|
1276
|
+
}
|
|
1277
|
+
) : null
|
|
1278
|
+
] }),
|
|
1279
|
+
item.url ? /* @__PURE__ */ jsx8("div", { className: "mt-1 truncate font-mono text-[10px] text-[hsl(var(--muted-foreground))]", children: item.url }) : null,
|
|
1280
|
+
item.publishedDate ? /* @__PURE__ */ jsxs6("div", { className: "mt-1 text-[10px] text-[hsl(var(--muted-foreground))]", children: [
|
|
1281
|
+
"\u53D1\u5E03\u4E8E ",
|
|
1282
|
+
item.publishedDate.slice(0, 10)
|
|
1283
|
+
] }) : null,
|
|
1284
|
+
item.description ? /* @__PURE__ */ jsx8("p", { className: "mt-2 line-clamp-3 text-[11px] leading-5 text-[hsl(var(--muted-foreground))]", children: item.description }) : null
|
|
1285
|
+
] })
|
|
1286
|
+
] })
|
|
1287
|
+
},
|
|
1288
|
+
`${item.url ?? item.title ?? "result"}-${index}`
|
|
1289
|
+
)) }) : renderEmptyState("\u6CA1\u6709\u53EF\u5C55\u793A\u7684\u641C\u7D22\u7ED3\u679C\u3002")
|
|
1290
|
+
] });
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// src/chat/tool-renderers/SubmitResultRenderer.tsx
|
|
1294
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1295
|
+
function extractText(value, key) {
|
|
1296
|
+
if (!isPlainObject(value)) return null;
|
|
1297
|
+
const field = value[key];
|
|
1298
|
+
return typeof field === "string" && field.trim() ? field.trim() : null;
|
|
1299
|
+
}
|
|
1300
|
+
function parsePayload(toolCall) {
|
|
1301
|
+
const resultText = getResultText(toolCall.result);
|
|
1302
|
+
const parsedResult = parseJsonValue(resultText);
|
|
1303
|
+
const parsedArgs = parseJsonValue(toolCall.arguments);
|
|
1304
|
+
const description = extractText(parsedArgs, "description") ?? extractText(parsedResult, "description");
|
|
1305
|
+
const result = extractText(parsedArgs, "result") ?? extractText(parsedResult, "result") ?? (!isPlainObject(parsedResult) ? resultText?.trim() ?? null : null);
|
|
1306
|
+
const error = extractText(parsedArgs, "err_msg") ?? extractText(parsedResult, "err_msg") ?? extractText(parsedResult, "error");
|
|
1307
|
+
const rawStatus = extractText(parsedResult, "status");
|
|
1308
|
+
const status = rawStatus === "submitted" ? null : rawStatus;
|
|
1309
|
+
return { description, result, error, status };
|
|
1310
|
+
}
|
|
1311
|
+
function SubmitResultRenderer({ toolCall }) {
|
|
1312
|
+
const { description, result, error, status } = parsePayload(toolCall);
|
|
1313
|
+
const isError = toolCall.status === "error" || Boolean(error);
|
|
1314
|
+
const Icon = isError ? CircleAlert : CircleCheck;
|
|
1315
|
+
return /* @__PURE__ */ jsxs7("div", { className: "overflow-hidden rounded-2xl border border-[hsl(var(--border))] bg-[hsl(var(--card))]", children: [
|
|
1316
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-3 border-b border-[hsl(var(--border))] bg-[hsl(var(--muted))]/25 px-4 py-3", children: [
|
|
1317
|
+
/* @__PURE__ */ jsx9("div", { className: isError ? "text-[hsl(var(--swf-danger))]" : "text-[hsl(var(--swf-success))]", children: /* @__PURE__ */ jsx9(Icon, { size: 18 }) }),
|
|
1318
|
+
/* @__PURE__ */ jsxs7("div", { className: "min-w-0 flex-1", children: [
|
|
1319
|
+
/* @__PURE__ */ jsx9("div", { className: "font-medium text-[hsl(var(--foreground))]", children: description || (isError ? "\u4EFB\u52A1\u672A\u5B8C\u6210" : "\u4EFB\u52A1\u7ED3\u679C\u5DF2\u63D0\u4EA4") }),
|
|
1320
|
+
description ? /* @__PURE__ */ jsx9("div", { className: "mt-0.5 text-xs text-[hsl(var(--muted-foreground))]", children: isError ? "\u4EFB\u52A1\u672A\u5B8C\u6210" : "\u4EFB\u52A1\u7ED3\u679C\u5DF2\u63D0\u4EA4" }) : null,
|
|
1321
|
+
status ? /* @__PURE__ */ jsxs7("div", { className: "mt-0.5 text-xs text-[hsl(var(--muted-foreground))]", children: [
|
|
1322
|
+
"\u72B6\u6001\uFF1A",
|
|
1323
|
+
status
|
|
1324
|
+
] }) : null
|
|
1325
|
+
] })
|
|
1326
|
+
] }),
|
|
1327
|
+
/* @__PURE__ */ jsxs7("div", { className: "space-y-3 px-4 py-4 text-sm leading-6 text-[hsl(var(--foreground))]", children: [
|
|
1328
|
+
result ? /* @__PURE__ */ jsx9(MarkdownContent, { mode: "static", children: result }) : null,
|
|
1329
|
+
error ? /* @__PURE__ */ jsxs7("div", { className: "rounded-xl border border-[hsl(var(--swf-danger)/0.3)] bg-[hsl(var(--swf-danger-soft))] px-3 py-2 text-sm text-[hsl(var(--swf-danger))]", children: [
|
|
1330
|
+
/* @__PURE__ */ jsx9("div", { className: "mb-1 font-medium", children: "\u672A\u5B8C\u6210\u539F\u56E0" }),
|
|
1331
|
+
/* @__PURE__ */ jsx9("div", { className: "whitespace-pre-wrap", children: error })
|
|
1332
|
+
] }) : null,
|
|
1333
|
+
!result && !error ? /* @__PURE__ */ jsx9("p", { className: "text-[hsl(var(--muted-foreground))]", children: "\u667A\u80FD\u4F53\u5DF2\u7ED3\u675F\u672C\u8F6E\u4EFB\u52A1\u3002" }) : null
|
|
1334
|
+
] })
|
|
1335
|
+
] });
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// src/chat/tool-renderers/registry.ts
|
|
1339
|
+
var RENDERERS = /* @__PURE__ */ new Map([
|
|
1340
|
+
["Bash", BashRenderer],
|
|
1341
|
+
["BgBash", BashRenderer],
|
|
1342
|
+
["Edit", FileEditRenderer],
|
|
1343
|
+
["MultiEdit", FileEditRenderer],
|
|
1344
|
+
["Grep", SearchRenderer],
|
|
1345
|
+
["Glob", SearchRenderer],
|
|
1346
|
+
["Ls", SearchRenderer],
|
|
1347
|
+
["Read", FileReadRenderer],
|
|
1348
|
+
["WebFetch", SearchRenderer],
|
|
1349
|
+
["WebSearch", SearchRenderer],
|
|
1350
|
+
["Write", FileEditRenderer],
|
|
1351
|
+
["submit_result", SubmitResultRenderer]
|
|
1352
|
+
]);
|
|
1353
|
+
function getRenderer(toolName) {
|
|
1354
|
+
return RENDERERS.get(formatToolName(toolName)) ?? null;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
export {
|
|
1358
|
+
MessageImage,
|
|
1359
|
+
McpAppCard,
|
|
1360
|
+
ToolUiCardView,
|
|
1361
|
+
SUPPORTED_LANGUAGES,
|
|
1362
|
+
normalizeCodeLanguage,
|
|
1363
|
+
getCodeLanguageFromFilename,
|
|
1364
|
+
getResultText,
|
|
1365
|
+
getResultImages,
|
|
1366
|
+
parseJsonValue,
|
|
1367
|
+
isPlainObject,
|
|
1368
|
+
getStringValue,
|
|
1369
|
+
getNumberValue,
|
|
1370
|
+
getBooleanValue,
|
|
1371
|
+
extractErrorMessage,
|
|
1372
|
+
getFileName,
|
|
1373
|
+
getCodeLanguage,
|
|
1374
|
+
formatBytes,
|
|
1375
|
+
CodePreview,
|
|
1376
|
+
BashRenderer,
|
|
1377
|
+
shouldFollowWritePreview,
|
|
1378
|
+
scrollWritePreviewToLatest,
|
|
1379
|
+
FileEditRenderer,
|
|
1380
|
+
ImageLightbox,
|
|
1381
|
+
FileReadRenderer,
|
|
1382
|
+
SearchRenderer,
|
|
1383
|
+
SubmitResultRenderer,
|
|
1384
|
+
getRenderer
|
|
1385
|
+
};
|
|
1386
|
+
//# sourceMappingURL=chunk-5JAFIDDP.js.map
|