paseo-dsh 0.2.18 → 0.2.20
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/OVERVIEW.md +2 -0
- package/README.md +4 -0
- package/THIRD-PARTY-NOTICES.md +36 -0
- package/client/react-native.d.ts +4 -0
- package/client/settings-screen.tsx +144 -0
- package/client/timeline.tsx +1444 -0
- package/index.client.tsx +10 -1
- package/index.server.ts +57 -0
- package/lib/doctor.mjs +14 -2
- package/package.json +6 -2
- package/server/bridge-assets.ts +2 -1
- package/server/dsh-command.d.mts +7 -0
- package/server/dsh-command.mjs +40 -0
- package/server/dsh-process.ts +18 -11
- package/server/provider.ts +29 -9
- package/server/session.ts +48 -47
- package/server/timeline.ts +2 -0
- package/shared/image-preview.ts +28 -0
- package/shared/settings.ts +93 -0
|
@@ -0,0 +1,1444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact DSH timeline rows.
|
|
3
|
+
*
|
|
4
|
+
* The tool-row shape and the reasoning preview are adapted from Better Paseo
|
|
5
|
+
* (MIT, Copyright (c) 2026 ABorakati):
|
|
6
|
+
* https://github.com/RoundRedDot/better-paseo
|
|
7
|
+
*
|
|
8
|
+
* Only the pieces this provider needs are implemented: a one-line reasoning
|
|
9
|
+
* preview with a paced expanded body, and icon-led rows for the common DSH
|
|
10
|
+
* tool kinds. Semantic rows the host already owns (questions, plans, todos,
|
|
11
|
+
* subagents) are deliberately left to Paseo.
|
|
12
|
+
*/
|
|
13
|
+
import type {
|
|
14
|
+
PluginClientContext,
|
|
15
|
+
PluginTimelineItemProps,
|
|
16
|
+
} from "@getpaseo/plugin/client";
|
|
17
|
+
import { useAgent, useRpc, useSettings } from "@getpaseo/plugin/client";
|
|
18
|
+
import { Icon, copyText, useToast } from "@getpaseo/plugin/client/react-native";
|
|
19
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
20
|
+
import * as ReactNative from "react-native";
|
|
21
|
+
import { Modal, Platform, Pressable, ScrollView, Text, useWindowDimensions, View } from "react-native";
|
|
22
|
+
|
|
23
|
+
// The plugin SDK ships partial react-native types; the host runtime still
|
|
24
|
+
// provides Animated/Easing, so reach for them through the module object.
|
|
25
|
+
const RNAnimated = ReactNative as unknown as {
|
|
26
|
+
Animated: {
|
|
27
|
+
Value: new (value: number) => { interpolate(config: { inputRange: number[]; outputRange: number[] }): unknown };
|
|
28
|
+
View: import("react").ComponentType<{ style?: unknown; accessibilityLabel?: string; accessibilityRole?: string }>;
|
|
29
|
+
loop(animation: unknown): { start(): void; stop(): void };
|
|
30
|
+
sequence(animations: unknown[]): unknown;
|
|
31
|
+
timing(value: unknown, config: Record<string, unknown>): unknown;
|
|
32
|
+
};
|
|
33
|
+
Easing: { inOut(easing: unknown): unknown; ease: unknown };
|
|
34
|
+
StyleSheet: { create<T>(styles: T): T };
|
|
35
|
+
};
|
|
36
|
+
const AnimatedView = RNAnimated.Animated.View;
|
|
37
|
+
const ImageView = (ReactNative as unknown as {
|
|
38
|
+
Image: import("react").ComponentType<{
|
|
39
|
+
source: { uri: string };
|
|
40
|
+
resizeMode?: string;
|
|
41
|
+
style?: unknown;
|
|
42
|
+
accessibilityLabel?: string;
|
|
43
|
+
}>;
|
|
44
|
+
}).Image;
|
|
45
|
+
|
|
46
|
+
import { z } from "zod";
|
|
47
|
+
import { imagePreviewRpc } from "../shared/image-preview";
|
|
48
|
+
import { TIMELINE_STYLE_DEFAULTS, timelineStyleSettings, type TimelineStyleValues } from "../shared/settings";
|
|
49
|
+
|
|
50
|
+
type Phase = "streaming" | "complete";
|
|
51
|
+
type Theme = PluginTimelineItemProps<unknown>["theme"];
|
|
52
|
+
|
|
53
|
+
/** Live presentation settings, falling back to the schema defaults while loading. */
|
|
54
|
+
function useTimelineStyle(): TimelineStyleValues {
|
|
55
|
+
const state = useSettings(timelineStyleSettings);
|
|
56
|
+
return state.status === "ready" ? state.values : TIMELINE_STYLE_DEFAULTS;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const reasoningSchema = z.object({
|
|
60
|
+
text: z.string(),
|
|
61
|
+
phase: z.string().optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const toolDetailSchema = z.record(z.string(), z.unknown());
|
|
65
|
+
|
|
66
|
+
const toolSchema = z.object({
|
|
67
|
+
name: z.string(),
|
|
68
|
+
status: z.string(),
|
|
69
|
+
detail: toolDetailSchema.optional(),
|
|
70
|
+
callId: z.string().optional(),
|
|
71
|
+
error: z.string().optional(),
|
|
72
|
+
phase: z.string().optional(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
type ReasoningData = z.infer<typeof reasoningSchema>;
|
|
76
|
+
type ToolData = z.infer<typeof toolSchema>;
|
|
77
|
+
|
|
78
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
79
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type Json = boolean | null | number | string | Json[] | { [key: string]: Json };
|
|
83
|
+
|
|
84
|
+
function toJson(value: unknown): Json {
|
|
85
|
+
return JSON.parse(JSON.stringify(value)) as Json;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function stringField(source: Record<string, unknown> | undefined, key: string): string | undefined {
|
|
89
|
+
const value = source?.[key];
|
|
90
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Markdown down to the words a one-line preview can show. */
|
|
94
|
+
function plainInline(text: string): string {
|
|
95
|
+
return text
|
|
96
|
+
.replace(/```[^\n]*/g, " ")
|
|
97
|
+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
98
|
+
.replace(/(\*\*|__)(.+?)\1/g, "$2")
|
|
99
|
+
.replace(/`([^`]*)`/g, "$1")
|
|
100
|
+
.replace(/^\s{0,3}(?:#{1,6}\s+|>\s?|[-*+]\s+|\d+[.)]\s+)/gm, "")
|
|
101
|
+
.replace(/\s+/g, " ")
|
|
102
|
+
.trim();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function clip(text: string, max = 160): string {
|
|
106
|
+
return text.length > max ? `${text.slice(0, max - 1).trimEnd()}…` : text;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isTerminator(char: string): boolean {
|
|
110
|
+
return char === "." || char === "!" || char === "?" || char === "。" || char === "!" || char === "?";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function closersEnd(text: string, index: number): number {
|
|
114
|
+
let next = index + 1;
|
|
115
|
+
while (next < text.length && /["'\u201d\u2019)\]*_`]/.test(text.charAt(next))) next += 1;
|
|
116
|
+
return next;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function endsSentence(text: string, index: number): boolean {
|
|
120
|
+
if (!isTerminator(text.charAt(index))) return false;
|
|
121
|
+
const char = text.charAt(index);
|
|
122
|
+
if (char === "。" || char === "!" || char === "?") return true;
|
|
123
|
+
const next = closersEnd(text, index);
|
|
124
|
+
return next >= text.length || /\s/.test(text.charAt(next));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The newest complete sentence in the tail, so the preview changes per sentence. */
|
|
128
|
+
function lastSentence(text: string): string {
|
|
129
|
+
const window = text.length > 1200 ? text.slice(-1200) : text;
|
|
130
|
+
let end = -1;
|
|
131
|
+
for (let index = window.length - 1; index >= 0; index -= 1) {
|
|
132
|
+
if (endsSentence(window, index)) {
|
|
133
|
+
end = index;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (end < 0) return clip(plainInline(window));
|
|
138
|
+
let start = 0;
|
|
139
|
+
for (let index = end - 1; index >= 0; index -= 1) {
|
|
140
|
+
if (window.charAt(index) === "\n") {
|
|
141
|
+
start = index + 1;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (endsSentence(window, index)) {
|
|
145
|
+
start = closersEnd(window, index);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return clip(plainInline(window.slice(start, closersEnd(window, end))));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function firstSentence(text: string): string {
|
|
153
|
+
const plain = plainInline(text);
|
|
154
|
+
if (plain === "") return "";
|
|
155
|
+
for (let index = 0; index < plain.length; index += 1) {
|
|
156
|
+
if (endsSentence(plain, index)) {
|
|
157
|
+
return clip(plain.slice(0, closersEnd(plain, index)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return clip(plain);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Paseo's host may still export its reveal hook; newer hosts expose a
|
|
165
|
+
* component instead. A small local reveal keeps the expanded thought moving
|
|
166
|
+
* on every host without depending on either surface.
|
|
167
|
+
*/
|
|
168
|
+
function usePacedText(text: string, streaming: boolean): string {
|
|
169
|
+
const [count, setCount] = useState(() => (streaming ? 0 : text.length));
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!streaming) {
|
|
172
|
+
setCount(text.length);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
setCount((current) => Math.min(current, text.length));
|
|
176
|
+
const timer = setInterval(() => {
|
|
177
|
+
setCount((current) => {
|
|
178
|
+
if (current >= text.length) return current;
|
|
179
|
+
return Math.min(text.length, current + 12);
|
|
180
|
+
});
|
|
181
|
+
}, 45);
|
|
182
|
+
return () => clearInterval(timer);
|
|
183
|
+
}, [text, streaming]);
|
|
184
|
+
return text.slice(0, Math.min(count, text.length));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const MONO = Platform.OS === "ios" ? "Menlo" : "monospace";
|
|
188
|
+
|
|
189
|
+
/** The host's surface tokens may be translucent over a wallpaper; a sheet needs a solid one. */
|
|
190
|
+
function sheetBackground(theme: Theme): string {
|
|
191
|
+
const value = theme.colors.foreground.trim();
|
|
192
|
+
let r = 255;
|
|
193
|
+
let g = 255;
|
|
194
|
+
let b = 255;
|
|
195
|
+
const hex = /^#([0-9a-f]{6})$/i.exec(value);
|
|
196
|
+
if (hex !== null) {
|
|
197
|
+
const n = Number.parseInt(hex[1] ?? "", 16);
|
|
198
|
+
r = (n >> 16) & 255;
|
|
199
|
+
g = (n >> 8) & 255;
|
|
200
|
+
b = n & 255;
|
|
201
|
+
} else {
|
|
202
|
+
const rgb = /rgba?\(([^)]+)\)/i.exec(value);
|
|
203
|
+
if (rgb !== null) {
|
|
204
|
+
const parts = (rgb[1] ?? "").split(",").map((part) => Number.parseFloat(part.trim()));
|
|
205
|
+
if (parts.length >= 3 && parts.slice(0, 3).every(Number.isFinite)) {
|
|
206
|
+
[r, g, b] = [parts[0] ?? 255, parts[1] ?? 255, parts[2] ?? 255];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
211
|
+
return luminance < 0.5 ? "#FFFFFF" : "#1C1C1E";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const RUNNING_DOT = { size: 6, periodMs: 1200, minOpacity: 0.3, maxOpacity: 1 } as const;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* React Native Web compiles `animationKeyframes` into a real @keyframes rule
|
|
218
|
+
* through StyleSheet.create, so the pulse keeps running without a JS frame
|
|
219
|
+
* loop (and without re-rendering the row every frame).
|
|
220
|
+
*/
|
|
221
|
+
const runningDotPulse = Platform.OS === "web"
|
|
222
|
+
? RNAnimated.StyleSheet.create({
|
|
223
|
+
pulse: {
|
|
224
|
+
animationKeyframes: [
|
|
225
|
+
{ "0%": { opacity: RUNNING_DOT.maxOpacity }, "50%": { opacity: RUNNING_DOT.minOpacity }, "100%": { opacity: RUNNING_DOT.maxOpacity } },
|
|
226
|
+
],
|
|
227
|
+
animationDuration: `${RUNNING_DOT.periodMs}ms`,
|
|
228
|
+
animationIterationCount: "infinite",
|
|
229
|
+
animationTimingFunction: "ease-in-out",
|
|
230
|
+
} as unknown as Record<string, unknown>,
|
|
231
|
+
}).pulse
|
|
232
|
+
: null;
|
|
233
|
+
|
|
234
|
+
/** The breathing accent dot that stands in for a running tool's glyph. */
|
|
235
|
+
function RunningDot({ color }: { color: string }) {
|
|
236
|
+
const pulseRef = useRef<{ interpolate(config: { inputRange: number[]; outputRange: number[] }): unknown } | null>(null);
|
|
237
|
+
if (pulseRef.current === null) pulseRef.current = new RNAnimated.Animated.Value(0);
|
|
238
|
+
const pulse = pulseRef.current;
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (Platform.OS === "web") return;
|
|
241
|
+
const loop = RNAnimated.Animated.loop(
|
|
242
|
+
RNAnimated.Animated.timing(pulse, {
|
|
243
|
+
toValue: 1,
|
|
244
|
+
duration: RUNNING_DOT.periodMs,
|
|
245
|
+
easing: RNAnimated.Easing.inOut(RNAnimated.Easing.ease),
|
|
246
|
+
useNativeDriver: true,
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
loop.start();
|
|
250
|
+
return () => loop.stop();
|
|
251
|
+
}, [pulse]);
|
|
252
|
+
const opacity = pulse.interpolate({ inputRange: [0, 0.5, 1], outputRange: [1, RUNNING_DOT.minOpacity, 1] });
|
|
253
|
+
const shape = {
|
|
254
|
+
width: RUNNING_DOT.size,
|
|
255
|
+
height: RUNNING_DOT.size,
|
|
256
|
+
borderRadius: RUNNING_DOT.size / 2,
|
|
257
|
+
backgroundColor: color,
|
|
258
|
+
};
|
|
259
|
+
if (Platform.OS === "web") {
|
|
260
|
+
return (
|
|
261
|
+
<View accessibilityRole="progressbar" accessibilityLabel="运行中" style={[shape, runningDotPulse as never]} />
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return (
|
|
265
|
+
<AnimatedView accessibilityRole="progressbar" accessibilityLabel="运行中" style={[shape, { opacity }]} />
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The full command, on its own solid surface, capped so extreme lines scroll. */
|
|
270
|
+
function CommandBlock({ text, theme, maxHeight }: { text: string; theme: Theme; maxHeight?: number }) {
|
|
271
|
+
const background = sheetBackground(theme);
|
|
272
|
+
return (
|
|
273
|
+
<View
|
|
274
|
+
style={[
|
|
275
|
+
styles.commandBox,
|
|
276
|
+
{ borderColor: theme.colors.border },
|
|
277
|
+
Platform.OS === "web"
|
|
278
|
+
? ({ backgroundImage: `linear-gradient(${background}, ${background})` } as any)
|
|
279
|
+
: { backgroundColor: background },
|
|
280
|
+
]}
|
|
281
|
+
>
|
|
282
|
+
<ScrollView
|
|
283
|
+
style={maxHeight === undefined ? undefined : { maxHeight }}
|
|
284
|
+
contentContainerStyle={styles.commandContent}
|
|
285
|
+
showsVerticalScrollIndicator
|
|
286
|
+
>
|
|
287
|
+
<Text selectable style={[styles.commandText, styles.mono, { color: theme.colors.foreground }]}>
|
|
288
|
+
{text}
|
|
289
|
+
</Text>
|
|
290
|
+
</ScrollView>
|
|
291
|
+
</View>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Image preview for a read_image tool call; bytes come from the daemon RPC. */
|
|
296
|
+
function ImagePreview({ agentId, path, theme }: { agentId: string; path: string; theme: Theme }) {
|
|
297
|
+
const cwd = useAgent(agentId, (agent) => agent.cwd) ?? "";
|
|
298
|
+
const readImage = useRpc(imagePreviewRpc);
|
|
299
|
+
const window = useWindowDimensions();
|
|
300
|
+
const [state, setState] = useState<
|
|
301
|
+
| { status: "loading" }
|
|
302
|
+
| { status: "ready"; uri: string }
|
|
303
|
+
| { status: "tooLarge"; error: string }
|
|
304
|
+
| { status: "error"; error: string }
|
|
305
|
+
>({ status: "loading" });
|
|
306
|
+
|
|
307
|
+
const load = useCallback(
|
|
308
|
+
(allowLarge: boolean) => {
|
|
309
|
+
setState({ status: "loading" });
|
|
310
|
+
void readImage({ cwd, path, allowLarge })
|
|
311
|
+
.then((result) => {
|
|
312
|
+
if (result.dataUri !== null) {
|
|
313
|
+
setState({ status: "ready", uri: result.dataUri });
|
|
314
|
+
} else if (result.tooLarge) {
|
|
315
|
+
setState({ status: "tooLarge", error: result.error ?? "图片较大" });
|
|
316
|
+
} else {
|
|
317
|
+
setState({ status: "error", error: result.error ?? "无法读取图片" });
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
.catch((error: unknown) => {
|
|
321
|
+
setState({ status: "error", error: error instanceof Error ? error.message : String(error) });
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
[cwd, path, readImage],
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
load(false);
|
|
329
|
+
}, [load]);
|
|
330
|
+
|
|
331
|
+
if (state.status === "loading") {
|
|
332
|
+
return <Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>载入图片…</Text>;
|
|
333
|
+
}
|
|
334
|
+
if (state.status === "tooLarge") {
|
|
335
|
+
return (
|
|
336
|
+
<View style={styles.imageTooLarge}>
|
|
337
|
+
<Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>{state.error}</Text>
|
|
338
|
+
<Pressable onPress={() => load(true)} accessibilityLabel="仍要加载" hitSlop={6}>
|
|
339
|
+
<Text style={[styles.imageLoadAnyway, { color: theme.colors.accent }]}>仍要加载</Text>
|
|
340
|
+
</Pressable>
|
|
341
|
+
</View>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
if (state.status === "error") {
|
|
345
|
+
return <Text style={[styles.imageHint, { color: theme.colors.statusDanger }]}>{state.error}</Text>;
|
|
346
|
+
}
|
|
347
|
+
return (
|
|
348
|
+
<View
|
|
349
|
+
style={[
|
|
350
|
+
styles.imageFrame,
|
|
351
|
+
{ borderColor: theme.colors.border, height: Math.min(360, Math.max(180, Math.round(window.height * 0.32))) },
|
|
352
|
+
]}
|
|
353
|
+
>
|
|
354
|
+
<ImageView
|
|
355
|
+
source={{ uri: state.uri }}
|
|
356
|
+
resizeMode="contain"
|
|
357
|
+
accessibilityLabel="图片预览"
|
|
358
|
+
style={styles.image}
|
|
359
|
+
/>
|
|
360
|
+
</View>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function SheetPanel({
|
|
365
|
+
title,
|
|
366
|
+
subject,
|
|
367
|
+
subjectWrap = false,
|
|
368
|
+
icon,
|
|
369
|
+
theme,
|
|
370
|
+
onClose,
|
|
371
|
+
copyValue,
|
|
372
|
+
fullscreen = false,
|
|
373
|
+
onToggleFullscreen,
|
|
374
|
+
scrollable = true,
|
|
375
|
+
children,
|
|
376
|
+
}: {
|
|
377
|
+
title: string;
|
|
378
|
+
subject?: string;
|
|
379
|
+
subjectWrap?: boolean;
|
|
380
|
+
icon: string;
|
|
381
|
+
theme: Theme;
|
|
382
|
+
onClose: () => void;
|
|
383
|
+
copyValue?: string;
|
|
384
|
+
fullscreen?: boolean;
|
|
385
|
+
onToggleFullscreen?: () => void;
|
|
386
|
+
scrollable?: boolean;
|
|
387
|
+
children: ReactNode;
|
|
388
|
+
}) {
|
|
389
|
+
const toast = useToast();
|
|
390
|
+
const copy = useCallback(() => {
|
|
391
|
+
if (copyValue === undefined) return;
|
|
392
|
+
void copyText(copyValue)
|
|
393
|
+
.then(() => toast.show("已复制"))
|
|
394
|
+
.catch(() => toast.error("复制失败"));
|
|
395
|
+
}, [copyValue, toast]);
|
|
396
|
+
const window = useWindowDimensions();
|
|
397
|
+
const style = useTimelineStyle();
|
|
398
|
+
return (
|
|
399
|
+
<View style={styles.sheetPanel}>
|
|
400
|
+
<View style={[styles.handle, { backgroundColor: theme.colors.border }]} />
|
|
401
|
+
<View style={styles.sheetHeader}>
|
|
402
|
+
<Icon name={icon} size={16} color={theme.colors.foregroundMuted} />
|
|
403
|
+
<Text numberOfLines={1} style={[styles.sheetTitle, { color: theme.colors.foreground }]}>{title}</Text>
|
|
404
|
+
{copyValue === undefined ? null : (
|
|
405
|
+
<Pressable onPress={copy} accessibilityLabel="复制" hitSlop={8}>
|
|
406
|
+
<Icon name="Copy" size={16} color={theme.colors.foregroundMuted} />
|
|
407
|
+
</Pressable>
|
|
408
|
+
)}
|
|
409
|
+
{onToggleFullscreen === undefined ? null : (
|
|
410
|
+
<Pressable
|
|
411
|
+
onPress={onToggleFullscreen}
|
|
412
|
+
accessibilityLabel={fullscreen ? "退出全屏" : "全屏"}
|
|
413
|
+
hitSlop={8}
|
|
414
|
+
>
|
|
415
|
+
<Icon
|
|
416
|
+
name={fullscreen ? "Minimize2" : "Maximize2"}
|
|
417
|
+
size={16}
|
|
418
|
+
color={theme.colors.foregroundMuted}
|
|
419
|
+
/>
|
|
420
|
+
</Pressable>
|
|
421
|
+
)}
|
|
422
|
+
<Pressable onPress={onClose} accessibilityLabel="关闭" hitSlop={8}>
|
|
423
|
+
<Icon name="X" size={18} color={theme.colors.foregroundMuted} />
|
|
424
|
+
</Pressable>
|
|
425
|
+
</View>
|
|
426
|
+
{subject === undefined || subject === "" ? null : subjectWrap ? (
|
|
427
|
+
<CommandBlock
|
|
428
|
+
text={subject}
|
|
429
|
+
theme={theme}
|
|
430
|
+
maxHeight={Math.max(style.commandMinHeight, Math.round(window.height * style.commandMaxHeightRatio))}
|
|
431
|
+
/>
|
|
432
|
+
) : (
|
|
433
|
+
<Text numberOfLines={1} selectable style={[styles.sheetSubject, styles.mono, { color: theme.colors.foregroundMuted }]}>
|
|
434
|
+
{subject}
|
|
435
|
+
</Text>
|
|
436
|
+
)}
|
|
437
|
+
{scrollable ? (
|
|
438
|
+
<ScrollView style={styles.sheetScroll} contentContainerStyle={styles.sheetContent} showsVerticalScrollIndicator>
|
|
439
|
+
{children}
|
|
440
|
+
</ScrollView>
|
|
441
|
+
) : (
|
|
442
|
+
<View style={styles.sheetBody}>{children}</View>
|
|
443
|
+
)}
|
|
444
|
+
</View>
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function DetailSheet({
|
|
449
|
+
open,
|
|
450
|
+
onClose,
|
|
451
|
+
title,
|
|
452
|
+
subject,
|
|
453
|
+
subjectWrap,
|
|
454
|
+
icon,
|
|
455
|
+
theme,
|
|
456
|
+
copyValue,
|
|
457
|
+
scrollable,
|
|
458
|
+
children,
|
|
459
|
+
}: {
|
|
460
|
+
open: boolean;
|
|
461
|
+
onClose: () => void;
|
|
462
|
+
title: string;
|
|
463
|
+
subject?: string;
|
|
464
|
+
subjectWrap?: boolean;
|
|
465
|
+
icon: string;
|
|
466
|
+
theme: Theme;
|
|
467
|
+
copyValue?: string;
|
|
468
|
+
scrollable?: boolean;
|
|
469
|
+
children: ReactNode;
|
|
470
|
+
}) {
|
|
471
|
+
const [full, setFull] = useState(false);
|
|
472
|
+
useEffect(() => {
|
|
473
|
+
if (!open) setFull(false);
|
|
474
|
+
}, [open]);
|
|
475
|
+
const background = sheetBackground(theme);
|
|
476
|
+
return (
|
|
477
|
+
<Modal visible={open} transparent animationType={Platform.OS === "web" ? "none" : "slide"} onRequestClose={onClose} statusBarTranslucent>
|
|
478
|
+
<View style={styles.modalRoot}>
|
|
479
|
+
<Pressable style={styles.backdrop} onPress={onClose} accessibilityLabel="关闭" />
|
|
480
|
+
<View
|
|
481
|
+
style={[
|
|
482
|
+
styles.nativeSheet,
|
|
483
|
+
{ height: full ? "92%" : "50%", borderColor: theme.colors.border },
|
|
484
|
+
Platform.OS === "web"
|
|
485
|
+
? ({ backgroundImage: `linear-gradient(${background}, ${background})` } as any)
|
|
486
|
+
: { backgroundColor: background },
|
|
487
|
+
]}
|
|
488
|
+
>
|
|
489
|
+
<SheetPanel
|
|
490
|
+
title={title}
|
|
491
|
+
subject={subject}
|
|
492
|
+
subjectWrap={subjectWrap}
|
|
493
|
+
icon={icon}
|
|
494
|
+
theme={theme}
|
|
495
|
+
onClose={onClose}
|
|
496
|
+
copyValue={copyValue}
|
|
497
|
+
fullscreen={full}
|
|
498
|
+
onToggleFullscreen={() => setFull((value) => !value)}
|
|
499
|
+
scrollable={scrollable}
|
|
500
|
+
>
|
|
501
|
+
{children}
|
|
502
|
+
</SheetPanel>
|
|
503
|
+
</View>
|
|
504
|
+
</View>
|
|
505
|
+
</Modal>
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<ReasoningData>) {
|
|
510
|
+
const streaming = item.data.phase === "streaming";
|
|
511
|
+
const inline = layout.platform === "web";
|
|
512
|
+
const [open, setOpen] = useState(false);
|
|
513
|
+
const window = useWindowDimensions();
|
|
514
|
+
const text = item.data.text;
|
|
515
|
+
const preview = streaming ? lastSentence(text) || "思考中…" : firstSentence(text) || "已思考";
|
|
516
|
+
const revealed = usePacedText(text, streaming && open);
|
|
517
|
+
const spacing = useTimelineStyle();
|
|
518
|
+
// The live tail is laid out by the host with its own gap; a negative pull
|
|
519
|
+
// would overlap the row above it, so live rows never go negative.
|
|
520
|
+
const row = {
|
|
521
|
+
...styles.row,
|
|
522
|
+
marginTop: streaming ? spacing.liveReasoningRowMarginY : spacing.toolRowMarginY,
|
|
523
|
+
marginBottom: 0,
|
|
524
|
+
paddingVertical: spacing.toolRowPaddingY,
|
|
525
|
+
minHeight: spacing.toolRowMinHeight,
|
|
526
|
+
gap: spacing.toolRowGap,
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<View>
|
|
531
|
+
<Pressable
|
|
532
|
+
accessibilityRole="button"
|
|
533
|
+
accessibilityLabel={streaming ? "思考中" : "已思考"}
|
|
534
|
+
onPress={() => (inline ? setOpen((value) => !value) : setOpen(true))}
|
|
535
|
+
hitSlop={6}
|
|
536
|
+
style={({ pressed }: { pressed: boolean }) => [
|
|
537
|
+
row,
|
|
538
|
+
pressed ? { backgroundColor: theme.colors.surface1, borderRadius: 6 } : null,
|
|
539
|
+
]}
|
|
540
|
+
>
|
|
541
|
+
<View style={styles.lead}>
|
|
542
|
+
<Icon name="Brain" size={14} color={streaming ? theme.colors.accent : theme.colors.foregroundMuted} />
|
|
543
|
+
</View>
|
|
544
|
+
<Text style={[styles.verb, { color: theme.colors.foregroundMuted }]}>思考</Text>
|
|
545
|
+
<Text numberOfLines={1} style={[styles.target, { color: theme.colors.foregroundMuted }]}>
|
|
546
|
+
{preview}
|
|
547
|
+
</Text>
|
|
548
|
+
<View style={{ transform: [{ rotate: inline && open ? "90deg" : "0deg" }] }}>
|
|
549
|
+
<Icon name="ChevronRight" size={12} color={theme.colors.foregroundMuted} />
|
|
550
|
+
</View>
|
|
551
|
+
</Pressable>
|
|
552
|
+
{inline && open ? (
|
|
553
|
+
<View
|
|
554
|
+
style={[
|
|
555
|
+
styles.inlineReasoning,
|
|
556
|
+
{ borderColor: theme.colors.border },
|
|
557
|
+
Platform.OS === "web"
|
|
558
|
+
? ({ backgroundImage: `linear-gradient(${sheetBackground(theme)}, ${sheetBackground(theme)})` } as any)
|
|
559
|
+
: { backgroundColor: sheetBackground(theme) },
|
|
560
|
+
]}
|
|
561
|
+
>
|
|
562
|
+
<ScrollView
|
|
563
|
+
style={{ maxHeight: Math.max(160, Math.round(window.height * 0.35)) }}
|
|
564
|
+
contentContainerStyle={styles.inlineReasoningContent}
|
|
565
|
+
showsVerticalScrollIndicator
|
|
566
|
+
>
|
|
567
|
+
<Text selectable style={[styles.bodyText, { color: theme.colors.foreground }]}>{revealed}</Text>
|
|
568
|
+
</ScrollView>
|
|
569
|
+
</View>
|
|
570
|
+
) : null}
|
|
571
|
+
{inline ? null : (
|
|
572
|
+
<DetailSheet
|
|
573
|
+
open={open}
|
|
574
|
+
onClose={() => setOpen(false)}
|
|
575
|
+
title="思考"
|
|
576
|
+
icon="Brain"
|
|
577
|
+
theme={theme}
|
|
578
|
+
copyValue={revealed}
|
|
579
|
+
>
|
|
580
|
+
<Text selectable style={[styles.bodyText, { color: theme.colors.foreground }]}>{revealed}</Text>
|
|
581
|
+
</DetailSheet>
|
|
582
|
+
)}
|
|
583
|
+
</View>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
type ToolKind = "shell" | "read" | "write" | "edit" | "search" | "fetch" | "mcp" | "browser" | "code" | "other";
|
|
588
|
+
|
|
589
|
+
interface ToolLook {
|
|
590
|
+
icon: string;
|
|
591
|
+
verb: string;
|
|
592
|
+
target: string;
|
|
593
|
+
mark?: string;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/** A small program mark for the common shell programs Better Paseo brands. */
|
|
597
|
+
const PROGRAM_MARKS: Readonly<Record<string, string>> = {
|
|
598
|
+
git: "git",
|
|
599
|
+
gh: "gh",
|
|
600
|
+
npm: "npm",
|
|
601
|
+
npx: "npm",
|
|
602
|
+
pnpm: "pn",
|
|
603
|
+
pnpx: "pn",
|
|
604
|
+
yarn: "y",
|
|
605
|
+
node: "JS",
|
|
606
|
+
deno: "D",
|
|
607
|
+
bun: "bun",
|
|
608
|
+
python: "Py",
|
|
609
|
+
python3: "Py",
|
|
610
|
+
pip: "pip",
|
|
611
|
+
pip3: "pip",
|
|
612
|
+
uv: "uv",
|
|
613
|
+
pytest: "py",
|
|
614
|
+
tsc: "TS",
|
|
615
|
+
tsx: "TS",
|
|
616
|
+
cargo: "rs",
|
|
617
|
+
rustc: "rs",
|
|
618
|
+
go: "Go",
|
|
619
|
+
docker: "D",
|
|
620
|
+
"docker-compose": "D",
|
|
621
|
+
kubectl: "k8s",
|
|
622
|
+
helm: "h",
|
|
623
|
+
terraform: "tf",
|
|
624
|
+
aws: "aws",
|
|
625
|
+
gcloud: "G",
|
|
626
|
+
az: "az",
|
|
627
|
+
swift: "sw",
|
|
628
|
+
ruby: "rb",
|
|
629
|
+
php: "php",
|
|
630
|
+
java: "J",
|
|
631
|
+
gradle: "G",
|
|
632
|
+
mvn: "mvn",
|
|
633
|
+
dotnet: ".N",
|
|
634
|
+
flutter: "F",
|
|
635
|
+
code: "c",
|
|
636
|
+
cursor: "cur",
|
|
637
|
+
claude: "cl",
|
|
638
|
+
codex: "cx",
|
|
639
|
+
gemini: "G",
|
|
640
|
+
rg: "rg",
|
|
641
|
+
grep: "g",
|
|
642
|
+
find: "f",
|
|
643
|
+
curl: "c",
|
|
644
|
+
wget: "w",
|
|
645
|
+
make: "m",
|
|
646
|
+
brew: "b",
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
function shellProgram(command: string | undefined): string | undefined {
|
|
650
|
+
const first = command?.trim().split(/\s+/)[0];
|
|
651
|
+
if (first === undefined || first === "") return undefined;
|
|
652
|
+
const base = first.split(/[/\\]/).pop() ?? first;
|
|
653
|
+
return base.replace(/\.(?:exe|cmd|ps1)$/i, "").replace(/[0-9.]+$/, "");
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function mcpName(name: string): { server: string; tool: string } | undefined {
|
|
657
|
+
const match = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(name);
|
|
658
|
+
return match === null ? undefined : { server: match[1] ?? "", tool: match[2] ?? "" };
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function toolKindOf(name: string, detail: Record<string, unknown> | undefined): ToolKind {
|
|
662
|
+
const type = stringField(detail, "type");
|
|
663
|
+
if (type === "shell") return "shell";
|
|
664
|
+
if (type === "read") return "read";
|
|
665
|
+
if (type === "write") return "write";
|
|
666
|
+
if (type === "edit") return "edit";
|
|
667
|
+
if (type === "search") return "search";
|
|
668
|
+
if (type === "fetch") return "fetch";
|
|
669
|
+
if (name.startsWith("mcp__")) return "mcp";
|
|
670
|
+
if (name === "run_code") return "code";
|
|
671
|
+
if (/(?:^|_)browser_/.test(name)) return "browser";
|
|
672
|
+
// Older persisted rows kept `unknown` details; keep their rows recognizable
|
|
673
|
+
// instead of falling back to a bare tool name.
|
|
674
|
+
if (name === "read_image") return "read";
|
|
675
|
+
if (name === "web_fetch" || name === "webfetch") return "fetch";
|
|
676
|
+
if (name === "bash" || name === "pwsh") return "shell";
|
|
677
|
+
return "other";
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const BROWSER_VERBS: Readonly<Array<[RegExp, string]>> = [
|
|
681
|
+
[/^(?:navigate|open|goto|go|new_tab|open_url)$/, "打开网页"],
|
|
682
|
+
[/^(?:click|press|tap)$/, "点击"],
|
|
683
|
+
[/^(?:type|fill|input|press_key|key)$/, "输入"],
|
|
684
|
+
[/^(?:snapshot|screenshot|capture)$/, "截图"],
|
|
685
|
+
[/^(?:scroll)$/, "滚动"],
|
|
686
|
+
[/^(?:back|forward|reload)$/, "导航"],
|
|
687
|
+
[/^(?:wait)$/, "等待"],
|
|
688
|
+
[/^(?:close|close_tab)$/, "关闭"],
|
|
689
|
+
[/^(?:evaluate|run|run_code)$/, "执行"],
|
|
690
|
+
[/^(?:find|search)$/, "查找"],
|
|
691
|
+
];
|
|
692
|
+
|
|
693
|
+
/** Strip the server prefix and the `browser_` stem so verbs can match on the action. */
|
|
694
|
+
function browserAction(name: string): string {
|
|
695
|
+
const parsed = mcpName(name);
|
|
696
|
+
const bare = (parsed?.tool ?? name).replace(/^(?:paseo_)?browser_/, "");
|
|
697
|
+
return bare;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function browserVerb(action: string): string {
|
|
701
|
+
for (const [pattern, verb] of BROWSER_VERBS) {
|
|
702
|
+
if (pattern.test(action)) return verb;
|
|
703
|
+
}
|
|
704
|
+
return "浏览器";
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function firstLine(text: string | undefined): string | undefined {
|
|
708
|
+
const line = text?.split("\n").find((value) => value.trim() !== "");
|
|
709
|
+
return line === undefined ? undefined : line.trim();
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function hostOf(url: string): string {
|
|
713
|
+
const match = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]+)/i.exec(url.trim());
|
|
714
|
+
return match?.[1] ?? url.trim();
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function toolLook(data: ToolData): ToolLook {
|
|
718
|
+
const detail = data.detail;
|
|
719
|
+
const input = isRecord(detail?.input) ? detail.input : undefined;
|
|
720
|
+
const kind = toolKindOf(data.name, detail);
|
|
721
|
+
switch (kind) {
|
|
722
|
+
case "shell": {
|
|
723
|
+
const command = stringField(detail, "command") ?? stringField(input, "command");
|
|
724
|
+
const program = shellProgram(command);
|
|
725
|
+
const mark = program === undefined ? undefined : PROGRAM_MARKS[program];
|
|
726
|
+
return {
|
|
727
|
+
icon: "SquareTerminal",
|
|
728
|
+
verb: "命令",
|
|
729
|
+
target: firstLine(command) ?? data.name,
|
|
730
|
+
...(mark === undefined ? {} : { mark }),
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
case "read": {
|
|
734
|
+
const image = data.name === "read_image";
|
|
735
|
+
return {
|
|
736
|
+
icon: image ? "Image" : "FileText",
|
|
737
|
+
verb: image ? "看图" : "读取",
|
|
738
|
+
target: stringField(detail, "filePath")
|
|
739
|
+
?? stringField(input, "file_path")
|
|
740
|
+
?? stringField(input, "path")
|
|
741
|
+
?? data.name,
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
case "write":
|
|
745
|
+
return { icon: "Pencil", verb: "写入", target: stringField(detail, "filePath") ?? data.name };
|
|
746
|
+
case "edit":
|
|
747
|
+
return { icon: "Pencil", verb: "编辑", target: stringField(detail, "filePath") ?? data.name };
|
|
748
|
+
case "search": {
|
|
749
|
+
const query = stringField(detail, "query")
|
|
750
|
+
?? stringField(input, "query")
|
|
751
|
+
?? firstLine(stringField(input, "pattern"))
|
|
752
|
+
?? data.name;
|
|
753
|
+
return {
|
|
754
|
+
icon: "Search",
|
|
755
|
+
verb: stringField(detail, "toolName") === "web_search" ? "网页搜索" : "搜索",
|
|
756
|
+
target: query,
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
case "fetch":
|
|
760
|
+
return {
|
|
761
|
+
icon: "Globe",
|
|
762
|
+
verb: "抓取",
|
|
763
|
+
target: hostOf(stringField(detail, "url") ?? stringField(input, "url") ?? data.name),
|
|
764
|
+
};
|
|
765
|
+
case "mcp": {
|
|
766
|
+
const parsed = mcpName(data.name);
|
|
767
|
+
const browser = parsed !== undefined && parsed.tool.includes("browser_");
|
|
768
|
+
return {
|
|
769
|
+
icon: browser ? "Globe" : "Plug",
|
|
770
|
+
verb: browser ? "浏览器" : "MCP",
|
|
771
|
+
target: parsed === undefined ? data.name : `${parsed.server} / ${parsed.tool}`,
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
case "browser": {
|
|
775
|
+
const action = browserAction(data.name);
|
|
776
|
+
return {
|
|
777
|
+
icon: "Globe",
|
|
778
|
+
verb: browserVerb(action),
|
|
779
|
+
target: stringField(input, "url")
|
|
780
|
+
?? stringField(input, "title")
|
|
781
|
+
?? stringField(input, "selector")
|
|
782
|
+
?? stringField(input, "name")
|
|
783
|
+
?? action,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
case "code":
|
|
787
|
+
return {
|
|
788
|
+
icon: "Code",
|
|
789
|
+
verb: "运行代码",
|
|
790
|
+
target: stringField(input, "description") ?? firstLine(stringField(input, "code")) ?? "run_code",
|
|
791
|
+
};
|
|
792
|
+
default:
|
|
793
|
+
return {
|
|
794
|
+
icon: "Wrench",
|
|
795
|
+
verb: data.name,
|
|
796
|
+
target: stringField(input, "url")
|
|
797
|
+
?? stringField(input, "file_path")
|
|
798
|
+
?? stringField(input, "path")
|
|
799
|
+
?? stringField(input, "query")
|
|
800
|
+
?? stringField(input, "description")
|
|
801
|
+
?? firstLine(stringField(input, "command"))
|
|
802
|
+
?? "",
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function statusLabel(status: string): string {
|
|
808
|
+
if (status === "running") return "运行中";
|
|
809
|
+
if (status === "failed") return "失败";
|
|
810
|
+
if (status === "canceled") return "已取消";
|
|
811
|
+
return "完成";
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function statusColor(status: string, theme: Theme): string {
|
|
815
|
+
if (status === "failed") return theme.colors.statusDanger;
|
|
816
|
+
if (status === "running") return theme.colors.accent;
|
|
817
|
+
return theme.colors.foregroundMuted;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function readContent(content: string): string {
|
|
821
|
+
const match = /<content>\n?([\s\S]*?)\n?<\/content>/.exec(content);
|
|
822
|
+
const body = match?.[1] ?? content;
|
|
823
|
+
return body
|
|
824
|
+
.replace(/^\s*\d+:\s?/gm, "")
|
|
825
|
+
.replace(/\(End of file[^)]*\)\s*$/m, "")
|
|
826
|
+
.trim();
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
function toolContent(data: ToolData): string | undefined {
|
|
830
|
+
const detail = data.detail;
|
|
831
|
+
if (detail === undefined) return undefined;
|
|
832
|
+
const type = stringField(detail, "type");
|
|
833
|
+
const input = isRecord(detail.input) ? detail.input : undefined;
|
|
834
|
+
const parts: string[] = [];
|
|
835
|
+
switch (type) {
|
|
836
|
+
case "shell": {
|
|
837
|
+
const output = stringField(detail, "output");
|
|
838
|
+
if (output !== undefined) parts.push(output);
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
case "read": {
|
|
842
|
+
const content = stringField(detail, "content");
|
|
843
|
+
if (content !== undefined) parts.push(readContent(content));
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
case "write":
|
|
847
|
+
case "edit": {
|
|
848
|
+
const content = stringField(detail, "content") ?? stringField(detail, "newString");
|
|
849
|
+
if (content !== undefined) parts.push(content);
|
|
850
|
+
break;
|
|
851
|
+
}
|
|
852
|
+
case "search": {
|
|
853
|
+
const content = stringField(detail, "content");
|
|
854
|
+
if (content !== undefined) parts.push(content);
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
case "fetch": {
|
|
858
|
+
const result = stringField(detail, "result");
|
|
859
|
+
if (result !== undefined) parts.push(result);
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
default: {
|
|
863
|
+
const output = detail.output;
|
|
864
|
+
// Persisted rows from before these tools had a native detail type still
|
|
865
|
+
// carry `unknown`; keep their drawers readable instead of dumping JSON.
|
|
866
|
+
if (data.name === "read_image" || data.name === "read") {
|
|
867
|
+
if (typeof output === "string") parts.push(readContent(output));
|
|
868
|
+
} else if (
|
|
869
|
+
data.name === "web_fetch"
|
|
870
|
+
|| data.name === "webfetch"
|
|
871
|
+
|| data.name === "bash"
|
|
872
|
+
|| data.name === "pwsh"
|
|
873
|
+
) {
|
|
874
|
+
if (typeof output === "string") parts.push(output);
|
|
875
|
+
} else {
|
|
876
|
+
if (input !== undefined) parts.push(JSON.stringify(input, null, 2));
|
|
877
|
+
if (typeof output === "string") parts.push(output);
|
|
878
|
+
else if (output !== undefined) parts.push(JSON.stringify(output, null, 2));
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
const text = parts.join("\n\n").trim();
|
|
883
|
+
return text === "" ? undefined : text.length > 12000 ? `${text.slice(0, 12000)}\n…` : text;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function toolSubject(data: ToolData, look: ToolLook): string {
|
|
887
|
+
const detail = data.detail;
|
|
888
|
+
if (detail === undefined) return look.target;
|
|
889
|
+
const type = stringField(detail, "type");
|
|
890
|
+
switch (type) {
|
|
891
|
+
case "shell":
|
|
892
|
+
return stringField(detail, "command") ?? look.target;
|
|
893
|
+
case "read":
|
|
894
|
+
case "write":
|
|
895
|
+
case "edit":
|
|
896
|
+
return stringField(detail, "filePath") ?? look.target;
|
|
897
|
+
case "search":
|
|
898
|
+
return stringField(detail, "query") ?? look.target;
|
|
899
|
+
case "fetch":
|
|
900
|
+
return stringField(detail, "url") ?? look.target;
|
|
901
|
+
default:
|
|
902
|
+
return look.target;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
type Language = "plain" | "shell" | "json" | "diff" | "code" | "markdown";
|
|
907
|
+
|
|
908
|
+
type TokenKind = "plain" | "comment" | "string" | "number" | "keyword" | "key" | "added" | "removed" | "hunk";
|
|
909
|
+
|
|
910
|
+
interface Token {
|
|
911
|
+
text: string;
|
|
912
|
+
kind: TokenKind;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
const CODE_KEYWORDS = new Set([
|
|
916
|
+
"as", "async", "await", "break", "case", "catch", "class", "const", "continue", "declare", "default",
|
|
917
|
+
"delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "from", "function",
|
|
918
|
+
"if", "implements", "import", "in", "instanceof", "interface", "let", "namespace", "new", "null",
|
|
919
|
+
"of", "private", "protected", "public", "readonly", "return", "satisfies", "static", "super",
|
|
920
|
+
"switch", "this", "throw", "true", "try", "type", "typeof", "undefined", "var", "void", "while",
|
|
921
|
+
"yield", "and", "def", "elif", "except", "is", "lambda", "None", "not", "or", "pass", "raise",
|
|
922
|
+
"self", "True", "False", "with", "cd", "echo", "esac", "exit", "export", "fi", "local", "readonly",
|
|
923
|
+
"source", "then",
|
|
924
|
+
]);
|
|
925
|
+
|
|
926
|
+
const LANGUAGE_BY_EXTENSION: Readonly<Record<string, Language>> = {
|
|
927
|
+
bash: "shell", c: "code", cc: "code", cjs: "code", cpp: "code", cs: "code", css: "code",
|
|
928
|
+
diff: "diff", go: "code", h: "code", hpp: "code", html: "code", java: "code", js: "code",
|
|
929
|
+
json: "json", jsonc: "json", jsx: "code", kt: "code", markdown: "markdown", md: "markdown",
|
|
930
|
+
mjs: "code", patch: "diff", php: "code", py: "code", rb: "code", rs: "code", scss: "code",
|
|
931
|
+
sh: "shell", sql: "code", swift: "code", toml: "code", ts: "code", tsx: "code", yaml: "code",
|
|
932
|
+
yml: "code", zsh: "shell",
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
function languageFromPath(path: string | undefined): Language {
|
|
936
|
+
if (path === undefined) return "plain";
|
|
937
|
+
const extension = /\.([A-Za-z0-9]+)(?::\d+)?$/.exec(path)?.[1]?.toLowerCase();
|
|
938
|
+
return extension === undefined ? "plain" : LANGUAGE_BY_EXTENSION[extension] ?? "plain";
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
function toolLanguage(data: ToolData): Language {
|
|
942
|
+
const detail = data.detail;
|
|
943
|
+
if (detail === undefined) return "plain";
|
|
944
|
+
const type = stringField(detail, "type");
|
|
945
|
+
if (type === "shell") return "shell";
|
|
946
|
+
if (type === "read" || type === "write" || type === "edit") {
|
|
947
|
+
return languageFromPath(stringField(detail, "filePath"));
|
|
948
|
+
}
|
|
949
|
+
if (type === "fetch") return languageFromPath(stringField(detail, "url"));
|
|
950
|
+
const content = toolContent(data)?.trimStart() ?? "";
|
|
951
|
+
return content.startsWith("{") || content.startsWith("[") ? "json" : "plain";
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function tokenizeLine(line: string, language: Language): Token[] {
|
|
955
|
+
if (language === "diff") {
|
|
956
|
+
if (line.startsWith("+++") || line.startsWith("---")) return [{ text: line, kind: "plain" }];
|
|
957
|
+
if (line.startsWith("@@")) return [{ text: line, kind: "hunk" }];
|
|
958
|
+
if (line.startsWith("+")) return [{ text: line, kind: "added" }];
|
|
959
|
+
if (line.startsWith("-")) return [{ text: line, kind: "removed" }];
|
|
960
|
+
return [{ text: line, kind: "plain" }];
|
|
961
|
+
}
|
|
962
|
+
if (line === "") return [{ text: "", kind: "plain" }];
|
|
963
|
+
|
|
964
|
+
const tokens: Token[] = [];
|
|
965
|
+
const shell = language === "shell";
|
|
966
|
+
const json = language === "json";
|
|
967
|
+
const markdown = language === "markdown";
|
|
968
|
+
const syntax = language === "code" || shell || json;
|
|
969
|
+
let index = 0;
|
|
970
|
+
|
|
971
|
+
if (markdown) {
|
|
972
|
+
if (/^#{1,6}\s/.test(line)) return [{ text: line, kind: "keyword" }];
|
|
973
|
+
const bullet = /^(\s*)([-*+]|\d+[.)])(\s)/.exec(line);
|
|
974
|
+
if (bullet !== null) {
|
|
975
|
+
const indent = bullet[1] ?? "";
|
|
976
|
+
const marker = bullet[2] ?? "";
|
|
977
|
+
if (indent !== "") tokens.push({ text: indent, kind: "plain" });
|
|
978
|
+
tokens.push({ text: marker, kind: "keyword" });
|
|
979
|
+
index = indent.length + marker.length;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
while (index < line.length) {
|
|
984
|
+
const char = line.charAt(index);
|
|
985
|
+
const rest = line.slice(index);
|
|
986
|
+
|
|
987
|
+
if (/\s/.test(char)) {
|
|
988
|
+
let end = index + 1;
|
|
989
|
+
while (end < line.length && /\s/.test(line.charAt(end))) end += 1;
|
|
990
|
+
tokens.push({ text: line.slice(index, end), kind: "plain" });
|
|
991
|
+
index = end;
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (!json && rest.startsWith("/*")) {
|
|
996
|
+
const close = line.indexOf("*/", index + 2);
|
|
997
|
+
const end = close === -1 ? line.length : close + 2;
|
|
998
|
+
tokens.push({ text: line.slice(index, end), kind: "comment" });
|
|
999
|
+
index = end;
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (!json && !markdown && (shell ? char === "#" : rest.startsWith("//"))) {
|
|
1004
|
+
tokens.push({ text: rest, kind: "comment" });
|
|
1005
|
+
break;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
1009
|
+
if (!syntax && !(markdown && char === "`")) {
|
|
1010
|
+
tokens.push({ text: char, kind: "plain" });
|
|
1011
|
+
index += 1;
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
let end = index + 1;
|
|
1015
|
+
while (end < line.length) {
|
|
1016
|
+
const next = line.charAt(end);
|
|
1017
|
+
if (next === "\\") {
|
|
1018
|
+
end += 2;
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
end += 1;
|
|
1022
|
+
if (next === char) break;
|
|
1023
|
+
}
|
|
1024
|
+
const text = line.slice(index, end);
|
|
1025
|
+
if (json) {
|
|
1026
|
+
let after = end;
|
|
1027
|
+
while (after < line.length && /\s/.test(line.charAt(after))) after += 1;
|
|
1028
|
+
if (line.charAt(after) === ":") {
|
|
1029
|
+
tokens.push({ text, kind: "key" });
|
|
1030
|
+
index = end;
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
tokens.push({ text, kind: "string" });
|
|
1035
|
+
index = end;
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (syntax && /[0-9]/.test(char)) {
|
|
1040
|
+
let end = index + 1;
|
|
1041
|
+
while (end < line.length && /[0-9a-fA-FxX._]/.test(line.charAt(end))) end += 1;
|
|
1042
|
+
tokens.push({ text: line.slice(index, end), kind: "number" });
|
|
1043
|
+
index = end;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
if (/[A-Za-z_$]/.test(char)) {
|
|
1048
|
+
let end = index + 1;
|
|
1049
|
+
while (end < line.length && /[A-Za-z0-9_$]/.test(line.charAt(end))) end += 1;
|
|
1050
|
+
const word = line.slice(index, end);
|
|
1051
|
+
tokens.push({ text: word, kind: syntax && CODE_KEYWORDS.has(word) ? "keyword" : "plain" });
|
|
1052
|
+
index = end;
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
tokens.push({ text: char, kind: "plain" });
|
|
1057
|
+
index += 1;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
return tokens;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function tokenColor(kind: TokenKind, theme: Theme): string | undefined {
|
|
1064
|
+
switch (kind) {
|
|
1065
|
+
case "comment":
|
|
1066
|
+
return theme.colors.foregroundMuted;
|
|
1067
|
+
case "string":
|
|
1068
|
+
return theme.colors.statusSuccess;
|
|
1069
|
+
case "number":
|
|
1070
|
+
case "key":
|
|
1071
|
+
return theme.colors.statusWarning;
|
|
1072
|
+
case "keyword":
|
|
1073
|
+
return theme.colors.accent;
|
|
1074
|
+
case "added":
|
|
1075
|
+
return theme.colors.statusSuccess;
|
|
1076
|
+
case "removed":
|
|
1077
|
+
return theme.colors.statusDanger;
|
|
1078
|
+
case "hunk":
|
|
1079
|
+
return theme.colors.accent;
|
|
1080
|
+
default:
|
|
1081
|
+
return undefined;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
function HighlightedText({ text, language, theme, wrap = false }: { text: string; language: Language; theme: Theme; wrap?: boolean }) {
|
|
1086
|
+
const tokens = useMemo(() => {
|
|
1087
|
+
const lines = text.split("\n");
|
|
1088
|
+
const result: Token[] = [];
|
|
1089
|
+
lines.forEach((line, index) => {
|
|
1090
|
+
if (index > 0) result.push({ text: "\n", kind: "plain" });
|
|
1091
|
+
result.push(...tokenizeLine(line, language));
|
|
1092
|
+
});
|
|
1093
|
+
return result;
|
|
1094
|
+
}, [text, language]);
|
|
1095
|
+
return (
|
|
1096
|
+
<Text
|
|
1097
|
+
selectable
|
|
1098
|
+
style={[
|
|
1099
|
+
styles.codeText,
|
|
1100
|
+
styles.mono,
|
|
1101
|
+
{ color: theme.colors.foreground },
|
|
1102
|
+
Platform.OS === "web" ? ({ whiteSpace: wrap ? "pre-wrap" : "pre" } as any) : null,
|
|
1103
|
+
]}
|
|
1104
|
+
>
|
|
1105
|
+
{tokens.map((token, index) => {
|
|
1106
|
+
const color = tokenColor(token.kind, theme);
|
|
1107
|
+
return color === undefined
|
|
1108
|
+
? token.text
|
|
1109
|
+
: <Text key={index} style={{ color }}>{token.text}</Text>;
|
|
1110
|
+
})}
|
|
1111
|
+
</Text>
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/** Shared code surface: wrap toggle, copy, and both-axis scrolling. */
|
|
1116
|
+
function CodeSurface({
|
|
1117
|
+
text,
|
|
1118
|
+
language,
|
|
1119
|
+
theme,
|
|
1120
|
+
maxHeight,
|
|
1121
|
+
}: {
|
|
1122
|
+
text: string;
|
|
1123
|
+
language: Language;
|
|
1124
|
+
theme: Theme;
|
|
1125
|
+
maxHeight?: number;
|
|
1126
|
+
}) {
|
|
1127
|
+
const [wrap, setWrap] = useState(false);
|
|
1128
|
+
const toast = useToast();
|
|
1129
|
+
const background = sheetBackground(theme);
|
|
1130
|
+
const copy = useCallback(() => {
|
|
1131
|
+
void copyText(text)
|
|
1132
|
+
.then(() => toast.show("已复制"))
|
|
1133
|
+
.catch(() => toast.error("复制失败"));
|
|
1134
|
+
}, [text, toast]);
|
|
1135
|
+
return (
|
|
1136
|
+
<View
|
|
1137
|
+
style={[
|
|
1138
|
+
styles.codeBox,
|
|
1139
|
+
maxHeight === undefined ? { flex: 1 } : null,
|
|
1140
|
+
{ borderColor: theme.colors.border },
|
|
1141
|
+
Platform.OS === "web"
|
|
1142
|
+
? ({ backgroundImage: `linear-gradient(${background}, ${background})` } as any)
|
|
1143
|
+
: { backgroundColor: background },
|
|
1144
|
+
]}
|
|
1145
|
+
>
|
|
1146
|
+
<View style={[styles.codeToolbar, { borderBottomColor: theme.colors.border }]}>
|
|
1147
|
+
<Pressable onPress={() => setWrap((value) => !value)} accessibilityLabel={wrap ? "不换行" : "换行"} hitSlop={6}>
|
|
1148
|
+
<Text style={[styles.codeToolbarText, { color: theme.colors.foregroundMuted }]}>
|
|
1149
|
+
{wrap ? "不换行" : "换行"}
|
|
1150
|
+
</Text>
|
|
1151
|
+
</Pressable>
|
|
1152
|
+
<Pressable onPress={copy} accessibilityLabel="复制" hitSlop={6}>
|
|
1153
|
+
<Icon name="Copy" size={13} color={theme.colors.foregroundMuted} />
|
|
1154
|
+
</Pressable>
|
|
1155
|
+
</View>
|
|
1156
|
+
<ScrollView
|
|
1157
|
+
style={maxHeight === undefined ? styles.codeScroll : { maxHeight }}
|
|
1158
|
+
contentContainerStyle={styles.codeScrollContent}
|
|
1159
|
+
showsVerticalScrollIndicator
|
|
1160
|
+
>
|
|
1161
|
+
{wrap ? (
|
|
1162
|
+
<HighlightedText text={text} language={language} theme={theme} wrap />
|
|
1163
|
+
) : (
|
|
1164
|
+
<ScrollView horizontal showsHorizontalScrollIndicator contentContainerStyle={styles.codeRow}>
|
|
1165
|
+
<HighlightedText text={text} language={language} theme={theme} />
|
|
1166
|
+
</ScrollView>
|
|
1167
|
+
)}
|
|
1168
|
+
</ScrollView>
|
|
1169
|
+
</View>
|
|
1170
|
+
);
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolData>) {
|
|
1174
|
+
const [open, setOpen] = useState(false);
|
|
1175
|
+
const inline = layout.platform === "web";
|
|
1176
|
+
const window = useWindowDimensions();
|
|
1177
|
+
const data = item.data;
|
|
1178
|
+
const look = useMemo(() => toolLook(data), [data]);
|
|
1179
|
+
const content = useMemo(() => toolContent(data), [data]);
|
|
1180
|
+
const language = useMemo(() => toolLanguage(data), [data]);
|
|
1181
|
+
const subject = useMemo(() => toolSubject(data, look), [data, look]);
|
|
1182
|
+
const wrapSubject = stringField(data.detail, "type") === "shell";
|
|
1183
|
+
const detailInput = isRecord(data.detail?.input) ? data.detail.input : undefined;
|
|
1184
|
+
const imagePath = data.name === "read_image"
|
|
1185
|
+
? stringField(data.detail, "filePath") ?? stringField(detailInput, "file_path") ?? stringField(detailInput, "path")
|
|
1186
|
+
: undefined;
|
|
1187
|
+
const failed = data.status === "failed";
|
|
1188
|
+
const spacing = useTimelineStyle();
|
|
1189
|
+
const live = data.status === "running" || data.phase === "streaming";
|
|
1190
|
+
const row = {
|
|
1191
|
+
...styles.row,
|
|
1192
|
+
marginTop: spacing.toolRowMarginY,
|
|
1193
|
+
marginBottom: 0,
|
|
1194
|
+
paddingVertical: spacing.toolRowPaddingY,
|
|
1195
|
+
minHeight: spacing.toolRowMinHeight,
|
|
1196
|
+
gap: spacing.toolRowGap,
|
|
1197
|
+
};
|
|
1198
|
+
const openSheet = useCallback(() => {
|
|
1199
|
+
if (content === undefined) return;
|
|
1200
|
+
setOpen((value) => (inline ? !value : true));
|
|
1201
|
+
}, [content, inline]);
|
|
1202
|
+
return (
|
|
1203
|
+
<View>
|
|
1204
|
+
<Pressable
|
|
1205
|
+
accessibilityRole="button"
|
|
1206
|
+
accessibilityLabel={`${look.verb}${look.target === "" ? "" : ` ${look.target}`}`}
|
|
1207
|
+
onPress={openSheet}
|
|
1208
|
+
hitSlop={6}
|
|
1209
|
+
style={({ pressed }: { pressed: boolean }) => [
|
|
1210
|
+
row,
|
|
1211
|
+
pressed ? { backgroundColor: theme.colors.surface1, borderRadius: 6 } : null,
|
|
1212
|
+
]}
|
|
1213
|
+
>
|
|
1214
|
+
<View style={styles.lead}>
|
|
1215
|
+
{data.status === "running" ? (
|
|
1216
|
+
<RunningDot color={theme.colors.accent} />
|
|
1217
|
+
) : look.mark === undefined ? (
|
|
1218
|
+
<Icon name={look.icon} size={14} color={failed ? theme.colors.statusDanger : theme.colors.foregroundMuted} />
|
|
1219
|
+
) : (
|
|
1220
|
+
<View style={[styles.mark, { borderColor: theme.colors.border }]}>
|
|
1221
|
+
<Text style={[styles.markText, { color: theme.colors.foregroundMuted }]}>{look.mark}</Text>
|
|
1222
|
+
</View>
|
|
1223
|
+
)}
|
|
1224
|
+
</View>
|
|
1225
|
+
<Text style={[styles.verb, { color: failed ? theme.colors.statusDanger : theme.colors.foregroundMuted }]}>
|
|
1226
|
+
{look.verb}
|
|
1227
|
+
</Text>
|
|
1228
|
+
<Text numberOfLines={1} style={[styles.target, { color: theme.colors.foregroundMuted }]}>
|
|
1229
|
+
{look.target}
|
|
1230
|
+
</Text>
|
|
1231
|
+
{data.status === "running" || data.status === "completed" ? null : (
|
|
1232
|
+
<Text style={[styles.meta, { color: statusColor(data.status, theme) }]}>
|
|
1233
|
+
{statusLabel(data.status)}
|
|
1234
|
+
</Text>
|
|
1235
|
+
)}
|
|
1236
|
+
{content === undefined ? null : (
|
|
1237
|
+
<View style={{ transform: [{ rotate: inline && open ? "90deg" : "0deg" }] }}>
|
|
1238
|
+
<Icon name="ChevronRight" size={12} color={theme.colors.foregroundMuted} />
|
|
1239
|
+
</View>
|
|
1240
|
+
)}
|
|
1241
|
+
</Pressable>
|
|
1242
|
+
{inline && open && content !== undefined ? (
|
|
1243
|
+
<View style={styles.inlineTool}>
|
|
1244
|
+
{wrapSubject && subject !== "" ? (
|
|
1245
|
+
<CommandBlock
|
|
1246
|
+
text={subject}
|
|
1247
|
+
theme={theme}
|
|
1248
|
+
maxHeight={Math.max(120, Math.round(window.height * 0.25))}
|
|
1249
|
+
/>
|
|
1250
|
+
) : null}
|
|
1251
|
+
{imagePath === undefined ? (
|
|
1252
|
+
<CodeSurface
|
|
1253
|
+
text={content}
|
|
1254
|
+
language={language}
|
|
1255
|
+
theme={theme}
|
|
1256
|
+
maxHeight={Math.max(160, Math.round(window.height * 0.4))}
|
|
1257
|
+
/>
|
|
1258
|
+
) : (
|
|
1259
|
+
<View style={styles.imageBody}>
|
|
1260
|
+
<ImagePreview agentId={agentId} path={imagePath} theme={theme} />
|
|
1261
|
+
<Text style={[styles.imageCaption, { color: theme.colors.foregroundMuted }]}>{content}</Text>
|
|
1262
|
+
</View>
|
|
1263
|
+
)}
|
|
1264
|
+
</View>
|
|
1265
|
+
) : null}
|
|
1266
|
+
{inline ? null : (
|
|
1267
|
+
<DetailSheet
|
|
1268
|
+
open={open}
|
|
1269
|
+
onClose={() => setOpen(false)}
|
|
1270
|
+
title={look.verb}
|
|
1271
|
+
subject={subject}
|
|
1272
|
+
subjectWrap={wrapSubject}
|
|
1273
|
+
icon={look.icon}
|
|
1274
|
+
theme={theme}
|
|
1275
|
+
copyValue={content}
|
|
1276
|
+
scrollable={false}
|
|
1277
|
+
>
|
|
1278
|
+
{content === undefined ? null : imagePath === undefined ? (
|
|
1279
|
+
<CodeSurface text={content} language={language} theme={theme} />
|
|
1280
|
+
) : (
|
|
1281
|
+
<View style={styles.imageBody}>
|
|
1282
|
+
<ImagePreview agentId={agentId} path={imagePath} theme={theme} />
|
|
1283
|
+
<Text style={[styles.imageCaption, { color: theme.colors.foregroundMuted }]}>{content}</Text>
|
|
1284
|
+
</View>
|
|
1285
|
+
)}
|
|
1286
|
+
</DetailSheet>
|
|
1287
|
+
)}
|
|
1288
|
+
</View>
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
export function contributeTimeline(client: PluginClientContext): () => void {
|
|
1293
|
+
const cleanups = [
|
|
1294
|
+
client.addTimelineTransformer({
|
|
1295
|
+
id: "dsh-reasoning-row",
|
|
1296
|
+
query: { itemType: "reasoning" },
|
|
1297
|
+
transform({ item, phase }) {
|
|
1298
|
+
if (item.type !== "reasoning" || item.text.trim() === "") return undefined;
|
|
1299
|
+
return {
|
|
1300
|
+
items: [{
|
|
1301
|
+
type: "plugin" as const,
|
|
1302
|
+
kind: "dsh-reasoning",
|
|
1303
|
+
version: 1,
|
|
1304
|
+
data: { text: item.text, phase },
|
|
1305
|
+
}],
|
|
1306
|
+
};
|
|
1307
|
+
},
|
|
1308
|
+
}),
|
|
1309
|
+
client.addTimelineRenderer({
|
|
1310
|
+
kind: "dsh-reasoning",
|
|
1311
|
+
version: 1,
|
|
1312
|
+
schema: reasoningSchema,
|
|
1313
|
+
Component: ReasoningRow,
|
|
1314
|
+
}),
|
|
1315
|
+
client.addTimelineTransformer({
|
|
1316
|
+
id: "dsh-tool-row",
|
|
1317
|
+
query: { itemType: "tool_call" },
|
|
1318
|
+
transform({ item, phase }) {
|
|
1319
|
+
if (item.type !== "tool_call") return undefined;
|
|
1320
|
+
const detail = isRecord(item.detail) ? item.detail : undefined;
|
|
1321
|
+
const type = stringField(detail, "type");
|
|
1322
|
+
// Keep Paseo's richer cards for semantic helpers; every other tool gets
|
|
1323
|
+
// the shared row so a provider-specific name never shows up bare.
|
|
1324
|
+
const nativeCard = type === "sub_agent"
|
|
1325
|
+
|| type === "worktree_setup"
|
|
1326
|
+
|| type === "plain_text"
|
|
1327
|
+
|| type === "plan";
|
|
1328
|
+
if (nativeCard) return undefined;
|
|
1329
|
+
const error = item.error === null || item.error === undefined ? undefined : String(
|
|
1330
|
+
isRecord(item.error) && typeof item.error.message === "string" ? item.error.message : item.error,
|
|
1331
|
+
);
|
|
1332
|
+
return {
|
|
1333
|
+
items: [{
|
|
1334
|
+
type: "plugin" as const,
|
|
1335
|
+
kind: "dsh-tool",
|
|
1336
|
+
version: 1,
|
|
1337
|
+
data: {
|
|
1338
|
+
name: item.name,
|
|
1339
|
+
status: item.status,
|
|
1340
|
+
...(detail === undefined ? {} : { detail: toJson(detail) }),
|
|
1341
|
+
...(item.callId === undefined ? {} : { callId: item.callId }),
|
|
1342
|
+
...(error === undefined ? {} : { error }),
|
|
1343
|
+
phase,
|
|
1344
|
+
},
|
|
1345
|
+
}],
|
|
1346
|
+
};
|
|
1347
|
+
},
|
|
1348
|
+
}),
|
|
1349
|
+
client.addTimelineRenderer({
|
|
1350
|
+
kind: "dsh-tool",
|
|
1351
|
+
version: 1,
|
|
1352
|
+
schema: toolSchema,
|
|
1353
|
+
Component: ToolRow,
|
|
1354
|
+
}),
|
|
1355
|
+
];
|
|
1356
|
+
return () => {
|
|
1357
|
+
for (const cleanup of cleanups) cleanup();
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
const styles = {
|
|
1362
|
+
row: {
|
|
1363
|
+
flexDirection: "row",
|
|
1364
|
+
alignItems: "center",
|
|
1365
|
+
gap: 6,
|
|
1366
|
+
paddingVertical: 2,
|
|
1367
|
+
paddingHorizontal: 2,
|
|
1368
|
+
minHeight: 24,
|
|
1369
|
+
marginVertical: 0,
|
|
1370
|
+
},
|
|
1371
|
+
lead: { width: 17, height: 17, alignItems: "center", justifyContent: "center" },
|
|
1372
|
+
mark: { width: 17, height: 17, borderRadius: 4, borderWidth: 1, alignItems: "center", justifyContent: "center" },
|
|
1373
|
+
markText: { fontSize: 8, fontWeight: "700", lineHeight: 10 },
|
|
1374
|
+
verb: { fontSize: 12, fontWeight: "600", minWidth: 24 },
|
|
1375
|
+
target: { flex: 1, minWidth: 0, fontSize: 12 },
|
|
1376
|
+
meta: { fontSize: 11 },
|
|
1377
|
+
mono: { fontFamily: MONO },
|
|
1378
|
+
bodyText: { fontSize: 13, lineHeight: 20 },
|
|
1379
|
+
modalRoot: { flex: 1, justifyContent: "flex-end" },
|
|
1380
|
+
backdrop: {
|
|
1381
|
+
position: "absolute",
|
|
1382
|
+
top: 0,
|
|
1383
|
+
left: 0,
|
|
1384
|
+
right: 0,
|
|
1385
|
+
bottom: 0,
|
|
1386
|
+
zIndex: 0,
|
|
1387
|
+
backgroundColor: "rgba(0,0,0,0.45)",
|
|
1388
|
+
},
|
|
1389
|
+
nativeSheet: {
|
|
1390
|
+
position: "relative",
|
|
1391
|
+
zIndex: 1,
|
|
1392
|
+
width: "100%",
|
|
1393
|
+
maxWidth: 720,
|
|
1394
|
+
height: "50%",
|
|
1395
|
+
alignSelf: "center",
|
|
1396
|
+
borderTopWidth: 1,
|
|
1397
|
+
borderTopLeftRadius: 16,
|
|
1398
|
+
borderTopRightRadius: 16,
|
|
1399
|
+
overflow: "hidden",
|
|
1400
|
+
},
|
|
1401
|
+
sheetPanel: { flex: 1 },
|
|
1402
|
+
handle: { width: 36, height: 4, borderRadius: 2, alignSelf: "center", marginTop: 8, marginBottom: 4 },
|
|
1403
|
+
sheetHeader: { flexDirection: "row", alignItems: "center", gap: 8, paddingHorizontal: 16, paddingVertical: 10 },
|
|
1404
|
+
sheetTitle: { flex: 1, minWidth: 0, fontSize: 15, fontWeight: "600" },
|
|
1405
|
+
sheetSubject: { fontSize: 12, paddingHorizontal: 16, marginTop: -2, marginBottom: 8 },
|
|
1406
|
+
commandBox: {
|
|
1407
|
+
marginHorizontal: 16,
|
|
1408
|
+
marginBottom: 10,
|
|
1409
|
+
borderWidth: 1,
|
|
1410
|
+
borderRadius: 8,
|
|
1411
|
+
overflow: "hidden",
|
|
1412
|
+
},
|
|
1413
|
+
commandContent: { paddingHorizontal: 10, paddingVertical: 8 },
|
|
1414
|
+
commandText: { fontSize: 12, lineHeight: 18 },
|
|
1415
|
+
inlineTool: { marginTop: 6, marginBottom: 10, paddingHorizontal: 2, gap: 0 },
|
|
1416
|
+
imageBody: { flex: 1, gap: 8 },
|
|
1417
|
+
imageFrame: { borderWidth: 1, borderRadius: 8, overflow: "hidden", alignItems: "center", justifyContent: "center" },
|
|
1418
|
+
image: { width: "100%", height: "100%" },
|
|
1419
|
+
imageHint: { fontSize: 12, paddingVertical: 6 },
|
|
1420
|
+
imageTooLarge: { flexDirection: "row", alignItems: "center", gap: 10, flexWrap: "wrap" },
|
|
1421
|
+
imageLoadAnyway: { fontSize: 12, fontWeight: "600" },
|
|
1422
|
+
imageCaption: { fontSize: 12, lineHeight: 17 },
|
|
1423
|
+
inlineReasoning: { marginTop: 6, marginBottom: 10, borderWidth: 1, borderRadius: 8, overflow: "hidden" },
|
|
1424
|
+
inlineCodeBox: { borderWidth: 1, borderRadius: 10, overflow: "hidden" },
|
|
1425
|
+
inlineReasoningContent: { padding: 10 },
|
|
1426
|
+
sheetScroll: { flex: 1 },
|
|
1427
|
+
sheetContent: { paddingHorizontal: 16, paddingBottom: 32, paddingTop: 4 },
|
|
1428
|
+
sheetBody: { flex: 1, paddingHorizontal: 16, paddingBottom: 16, paddingTop: 4 },
|
|
1429
|
+
codeBox: { borderWidth: 1, borderRadius: 10, overflow: "hidden" },
|
|
1430
|
+
codeToolbar: {
|
|
1431
|
+
flexDirection: "row",
|
|
1432
|
+
alignItems: "center",
|
|
1433
|
+
justifyContent: "flex-end",
|
|
1434
|
+
gap: 14,
|
|
1435
|
+
paddingHorizontal: 10,
|
|
1436
|
+
paddingVertical: 6,
|
|
1437
|
+
borderBottomWidth: 1,
|
|
1438
|
+
},
|
|
1439
|
+
codeToolbarText: { fontSize: 11 },
|
|
1440
|
+
codeScroll: { flex: 1 },
|
|
1441
|
+
codeScrollContent: { padding: 12 },
|
|
1442
|
+
codeRow: { paddingRight: 12 },
|
|
1443
|
+
codeText: { fontSize: 12, lineHeight: 18 },
|
|
1444
|
+
} as const;
|