@nexface/chat 0.1.1-alpha.1 → 0.1.1-alpha.3
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/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +3 -3
- package/dist/default-chat.js.map +1 -1
- package/dist/page-confirmation.d.ts +5 -2
- package/dist/page-confirmation.js.map +1 -1
- package/dist/react.d.ts +5 -2
- package/dist/react.js +62 -1
- package/dist/react.js.map +1 -1
- package/dist/storage.d.ts +18 -0
- package/dist/storage.js +108 -0
- package/dist/storage.js.map +1 -0
- package/dist/styles.css +5 -4
- package/dist/types.d.ts +2 -0
- package/package.json +3 -5
- package/dist/operation-surface.d.ts +0 -7
- package/dist/operation-surface.js +0 -79
- package/dist/operation-surface.js.map +0 -1
- package/dist/operation-types.d.ts +0 -17
- package/dist/operation-types.js +0 -2
- package/dist/operation-types.js.map +0 -1
- package/dist/operation-view.d.ts +0 -13
- package/dist/operation-view.js +0 -367
- package/dist/operation-view.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAaA,MAAM,kBAAkB,GAAG,2BAA2B,CAAC;AACvD,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;IACjE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QAAE,OA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AC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM;oBACzD,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACxG,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI;YAC1E,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa;gBAC1D,CAAC,CAAC,8BAA8B;gBAChC,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,IAAI,kBAAkB,EAAE,CAC9G,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/styles.css
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
--_surface: var(--nexface-chat-surface, #f6f6f8);
|
|
9
9
|
--_border: var(--nexface-chat-border, #e5e5eb);
|
|
10
10
|
color: var(--_text); font: 14px/1.65 var(--nexface-chat-font-family, "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
|
|
11
|
-
position: relative; min-width: 0; isolation: isolate;
|
|
11
|
+
position: relative; min-width: 0; isolation: isolate; box-sizing: border-box;
|
|
12
|
+
border: 1px solid var(--_border); border-radius: 12px;
|
|
12
13
|
}
|
|
13
14
|
.nexface-chat *, .nexface-chat *::before, .nexface-chat *::after { box-sizing: border-box; }
|
|
14
15
|
.nexface-chat button, .nexface-chat input, .nexface-chat textarea { font: inherit; color: inherit; }
|
|
@@ -18,13 +19,13 @@
|
|
|
18
19
|
.nexface-chat :focus-visible { outline: 2px solid var(--_accent); outline-offset: 3px; }
|
|
19
20
|
.nexface-chat[data-layout="floating"] { position: fixed; right: 24px; bottom: 24px; z-index: 10000; }
|
|
20
21
|
.nexface-chat[data-layout="floating"][data-side="left"] { left: 24px; right: auto; }
|
|
21
|
-
.nexface-chat[data-layout="floating"] .nexface-chat__panel { width: min(546px, calc(100vw - 32px)); height: min(760px, calc(100dvh - 48px)); box-shadow: 0 8px 40px #00000015;
|
|
22
|
+
.nexface-chat[data-layout="floating"] .nexface-chat__panel { width: min(546px, calc(100vw - 32px)); height: min(760px, calc(100dvh - 48px)); box-shadow: 0 8px 40px #00000015; }
|
|
22
23
|
.nexface-chat[data-layout="docked"] { position: fixed; inset: 0 0 0 auto; width: min(var(--nexface-chat-panel-width), 100vw); z-index: 1000; }
|
|
23
24
|
.nexface-chat[data-layout="docked"][data-side="left"] { inset: 0 auto 0 0; }
|
|
24
25
|
.nexface-chat[data-layout="inline"] { width: 100%; height: 100%; }
|
|
25
26
|
.nexface-chat[data-fullscreen][data-layout][data-side] { position: fixed; inset: 0; width: 100vw; height: 100dvh; z-index: 10001; }
|
|
26
27
|
.nexface-chat[data-fullscreen] .nexface-chat__panel { width: 100%; height: 100%; border-radius: 0; }
|
|
27
|
-
.nexface-chat__panel { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--_background); border-radius:
|
|
28
|
+
.nexface-chat__panel { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--_background); border-radius: inherit; position: relative; }
|
|
28
29
|
.nexface-chat__header { min-height: 64px; padding: 12px 20px; display: flex; align-items: center; gap: 12px; }
|
|
29
30
|
.nexface-chat__brand { display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1; white-space: nowrap; }
|
|
30
31
|
.nexface-chat__brand strong { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
|
|
@@ -68,7 +69,7 @@
|
|
|
68
69
|
.nexface-chat__thinking { color: #c8c8d0; letter-spacing: 3px; }
|
|
69
70
|
.nexface-chat__composer-area { position: relative; padding: 12px 18px 16px; background: var(--_background); }
|
|
70
71
|
.nexface-chat__composer { border: 1px solid var(--_border); box-shadow: 0 1px 3px #00000008; border-radius: 24px; padding: 14px 16px 12px; }
|
|
71
|
-
.nexface-chat__composer textarea { width: 100%; min-height: 48px; max-height: 180px; border: 0; resize: none; background: transparent; outline: none; line-height: 24px; padding: 0; }
|
|
72
|
+
.nexface-chat .nexface-chat__composer textarea { width: 100%; min-height: 48px; max-height: 180px; border: 0; resize: none; background: transparent; outline: none; line-height: 24px; padding: 0; }
|
|
72
73
|
.nexface-chat__composer textarea::placeholder { color: var(--_muted); }
|
|
73
74
|
.nexface-chat__composer-toolbar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
|
|
74
75
|
.nexface-chat__composer-toolbar > span { flex: 1; }
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentRunResult } from "@nexface/agent";
|
|
2
|
+
import type { CSSProperties } from "react";
|
|
2
3
|
export type ChatRunResult = Extract<AgentRunResult, {
|
|
3
4
|
status: "completed";
|
|
4
5
|
}>;
|
|
@@ -13,6 +14,7 @@ export interface ChatProps {
|
|
|
13
14
|
welcomeDescription?: string;
|
|
14
15
|
side?: "left" | "right";
|
|
15
16
|
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
16
18
|
attachments?: false | ChatAttachmentOptions;
|
|
17
19
|
title?: string;
|
|
18
20
|
welcomeMessage?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexface/chat",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.19.0"
|
|
@@ -16,21 +16,19 @@
|
|
|
16
16
|
"@ag-ui/core": "0.0.59",
|
|
17
17
|
"react-markdown": "10.1.0",
|
|
18
18
|
"remark-gfm": "4.0.1",
|
|
19
|
-
"@nexface/agent": "0.1.1-alpha.
|
|
19
|
+
"@nexface/agent": "0.1.1-alpha.3",
|
|
20
20
|
"@phosphor-icons/react": "^2.1.10"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@nexface/tools": "0.1.1-alpha.
|
|
23
|
+
"@nexface/tools": "0.1.1-alpha.3",
|
|
24
24
|
"react": ">=18",
|
|
25
25
|
"react-dom": ">=18"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
|
-
"gitHead": "d3cb178f7fb2c4b0ed71d2491aa6253cf275ad67",
|
|
31
30
|
"publishConfig": {
|
|
32
31
|
"access": "public",
|
|
33
|
-
"tag": "alpha",
|
|
34
32
|
"registry": "https://registry.npmjs.org"
|
|
35
33
|
}
|
|
36
34
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
import type { ToolRuntime } from "@nexface/tools";
|
|
3
|
-
export interface AgentOperationSurfaceProps {
|
|
4
|
-
toolRuntime: ToolRuntime;
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
}
|
|
7
|
-
export declare function AgentOperationSurface({ toolRuntime, children }: AgentOperationSurfaceProps): import("react").JSX.Element;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import { useChat } from "./react.js";
|
|
4
|
-
import { OperationOverlayView } from "./operation-view.js";
|
|
5
|
-
export function AgentOperationSurface({ toolRuntime, children }) {
|
|
6
|
-
const chat = useChat();
|
|
7
|
-
if (chat.toolRuntime !== toolRuntime)
|
|
8
|
-
throw new Error("AgentOperationSurface requires the NexfaceProvider Runtime.");
|
|
9
|
-
const element = useRef(null);
|
|
10
|
-
const owner = useRef({});
|
|
11
|
-
const [execution, setExecution] = useState();
|
|
12
|
-
const [history, setHistory] = useState([]);
|
|
13
|
-
const timer = useRef(undefined);
|
|
14
|
-
const userMessage = [...chat.messages].reverse().find((message) => message.role === "user");
|
|
15
|
-
const turn = `${chat.activeSessionId}:${userMessage?.id ?? ""}`;
|
|
16
|
-
const running = chat.status === "running" || chat.status === "cancelling";
|
|
17
|
-
const waiting = Boolean(chat.interrupt) && !running;
|
|
18
|
-
const clearTimer = () => {
|
|
19
|
-
if (timer.current !== undefined)
|
|
20
|
-
clearTimeout(timer.current);
|
|
21
|
-
timer.current = undefined;
|
|
22
|
-
};
|
|
23
|
-
useLayoutEffect(() => {
|
|
24
|
-
if (chat.operationSurface.current)
|
|
25
|
-
throw new Error("Only one AgentOperationSurface is supported per NexfaceProvider.");
|
|
26
|
-
chat.operationSurface.current = owner.current;
|
|
27
|
-
return () => { chat.operationSurface.current = null; };
|
|
28
|
-
}, [chat.operationSurface]);
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
clearTimer();
|
|
31
|
-
setExecution(undefined);
|
|
32
|
-
setHistory([]);
|
|
33
|
-
return clearTimer;
|
|
34
|
-
}, [turn]);
|
|
35
|
-
useLayoutEffect(() => toolRuntime.on("toolexecution", (event) => {
|
|
36
|
-
clearTimer();
|
|
37
|
-
setExecution(event);
|
|
38
|
-
setHistory((entries) => {
|
|
39
|
-
const entry = {
|
|
40
|
-
toolCallId: event.id,
|
|
41
|
-
progressLabel: `${event.name} · ${event.cancelled ? "已取消" : event.status === "running" ? "执行中" : event.status === "success" ? "已完成" : "失败"}`,
|
|
42
|
-
};
|
|
43
|
-
return entries.some((item) => item.toolCallId === event.id)
|
|
44
|
-
? entries.map((item) => item.toolCallId === event.id ? entry : item)
|
|
45
|
-
: [...entries, entry];
|
|
46
|
-
});
|
|
47
|
-
if (event.status !== "running") {
|
|
48
|
-
timer.current = setTimeout(() => setExecution(undefined), 720);
|
|
49
|
-
}
|
|
50
|
-
}), [toolRuntime]);
|
|
51
|
-
useLayoutEffect(() => {
|
|
52
|
-
if (!running) {
|
|
53
|
-
clearTimer();
|
|
54
|
-
setExecution(undefined);
|
|
55
|
-
}
|
|
56
|
-
}, [running, waiting]);
|
|
57
|
-
const resolveSurface = useCallback(() => element.current ?? undefined, []);
|
|
58
|
-
const resolveTarget = useCallback(() => {
|
|
59
|
-
if (!execution || execution.cancelled)
|
|
60
|
-
return undefined;
|
|
61
|
-
const target = toolRuntime.resolveTarget(execution.tool, execution.input);
|
|
62
|
-
return target && element.current?.contains(target) ? { element: target } : undefined;
|
|
63
|
-
}, [execution, toolRuntime]);
|
|
64
|
-
const operation = execution ? {
|
|
65
|
-
toolCallId: execution.id,
|
|
66
|
-
name: execution.name,
|
|
67
|
-
input: execution.input,
|
|
68
|
-
effect: execution.tool.definition.effect,
|
|
69
|
-
progressLabel: execution.name,
|
|
70
|
-
status: execution.cancelled ? "cancelled" : execution.status === "running" ? "running" : execution.status === "success" ? "completed" : "failed",
|
|
71
|
-
} : {
|
|
72
|
-
toolCallId: turn,
|
|
73
|
-
name: "agent",
|
|
74
|
-
progressLabel: waiting ? "等待你完成操作" : chat.error ? "任务失败" : "正在处理你的请求",
|
|
75
|
-
status: chat.error ? "failed" : running || waiting ? "running" : "completed",
|
|
76
|
-
};
|
|
77
|
-
return _jsxs(_Fragment, { children: [_jsx("div", { ref: element, className: "nexface-operation-surface", children: children }), _jsx(OperationOverlayView, { operation: operation, progressHistory: history, running: running, feedbackActive: Boolean(execution) && !waiting, humanHasControl: waiting, onCancel: chat.cancel, resolveSurface: resolveSurface, resolveTarget: resolveTarget }, chat.activeSessionId)] });
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=operation-surface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-surface.js","sourceRoot":"","sources":["../src/operation-surface.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAQ3D,MAAM,UAAU,qBAAqB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAA8B;IACzF,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,IAAI,IAAI,CAAC,WAAW,KAAK,WAAW;QAAE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACrH,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACzB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,EAA2B,CAAC;IACtE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgC,EAAE,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,MAAM,CAA4C,SAAS,CAAC,CAAC;IAC3E,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IAC5F,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,EAAE,IAAI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EAAE,OAAO,EAAE,SAAS,EAAC,2BAA2B,YAAE,QAAQ,GAAO,EACzE,KAAC,oBAAoB,IAEnB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,OAAO,EACxB,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAC9C,eAAe,EAAE,OAAO,EACxB,QAAQ,EAAE,IAAI,CAAC,MAAM,EACrB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,IARvB,IAAI,CAAC,eAAe,CASzB,IACD,CAAC;AACN,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AgentToolEffect } from "@nexface/tools";
|
|
2
|
-
export interface AgentOperation {
|
|
3
|
-
toolCallId: string;
|
|
4
|
-
name: string;
|
|
5
|
-
input?: unknown;
|
|
6
|
-
progressLabel?: string;
|
|
7
|
-
effect?: AgentToolEffect;
|
|
8
|
-
status: "running" | "completed" | "failed" | "cancelled";
|
|
9
|
-
}
|
|
10
|
-
export interface AgentOperationProgressEntry {
|
|
11
|
-
progressLabel: string;
|
|
12
|
-
toolCallId: string;
|
|
13
|
-
}
|
|
14
|
-
export interface AgentOperationTarget {
|
|
15
|
-
element: HTMLElement;
|
|
16
|
-
label?: string;
|
|
17
|
-
}
|
package/dist/operation-types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-types.js","sourceRoot":"","sources":["../src/operation-types.ts"],"names":[],"mappings":""}
|
package/dist/operation-view.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentOperation, AgentOperationProgressEntry, AgentOperationTarget } from "./operation-types.js";
|
|
2
|
-
export interface OperationOverlayViewProps {
|
|
3
|
-
feedbackActive?: boolean;
|
|
4
|
-
operation?: AgentOperation;
|
|
5
|
-
progressHistory?: readonly AgentOperationProgressEntry[];
|
|
6
|
-
running: boolean;
|
|
7
|
-
humanHasControl?: boolean;
|
|
8
|
-
taskLabel?: string;
|
|
9
|
-
onCancel?(): void;
|
|
10
|
-
resolveSurface?(): HTMLElement | undefined;
|
|
11
|
-
resolveTarget?(operation: AgentOperation): AgentOperationTarget | undefined;
|
|
12
|
-
}
|
|
13
|
-
export declare function OperationOverlayView({ operation, progressHistory, running, feedbackActive, humanHasControl, taskLabel, onCancel, resolveSurface, resolveTarget }: OperationOverlayViewProps): import("react").ReactPortal | null;
|
package/dist/operation-view.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CursorIcon as Cursor } from "@phosphor-icons/react/Cursor";
|
|
3
|
-
import { SparkleIcon as Sparkle } from "@phosphor-icons/react/Sparkle";
|
|
4
|
-
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
-
import { createPortal } from "react-dom";
|
|
6
|
-
const BROWSER_TOOL_NAMES = new Set(["getSnapshot", "executeCode"]);
|
|
7
|
-
const POINTER_EXIT_DURATION_MS = 120;
|
|
8
|
-
const POINTER_CLICK_FEEDBACK_DURATION_MS = 720;
|
|
9
|
-
const CONTROLLER_EXIT_DURATION_MS = 300;
|
|
10
|
-
function operationProgressLabel(operation) {
|
|
11
|
-
const progressLabel = operation.progressLabel?.trim().replace(/\s+/g, " ");
|
|
12
|
-
if (progressLabel)
|
|
13
|
-
return progressLabel.slice(0, 48);
|
|
14
|
-
return BROWSER_TOOL_NAMES.has(operation.name)
|
|
15
|
-
? "正在浏览网页"
|
|
16
|
-
: "正在处理你的请求";
|
|
17
|
-
}
|
|
18
|
-
function operationEffect(operation) {
|
|
19
|
-
if (operation.effect === "read" || operation.effect === "navigate")
|
|
20
|
-
return operation.effect;
|
|
21
|
-
return operation.name === "getSnapshot" ? "read" : "action";
|
|
22
|
-
}
|
|
23
|
-
function normalizedLabel(label) {
|
|
24
|
-
const normalized = label?.trim().replace(/\s+/g, " ");
|
|
25
|
-
return normalized || undefined;
|
|
26
|
-
}
|
|
27
|
-
function operationTargetLabel(operation, target) {
|
|
28
|
-
const label = target?.label;
|
|
29
|
-
if (!label || label === operation.name)
|
|
30
|
-
return undefined;
|
|
31
|
-
const rawNamePrefix = `${operation.name} · `;
|
|
32
|
-
return label.startsWith(rawNamePrefix) ? label.slice(rawNamePrefix.length) : label;
|
|
33
|
-
}
|
|
34
|
-
function pointerMoveDuration(from, to) {
|
|
35
|
-
const distance = Math.hypot(to.left - from.left, to.top - from.top);
|
|
36
|
-
if (distance < 2)
|
|
37
|
-
return 0;
|
|
38
|
-
return Math.round(Math.min(360, Math.max(180, 180 + distance * 0.18)));
|
|
39
|
-
}
|
|
40
|
-
function pointerReachedTarget(element, target) {
|
|
41
|
-
const rect = element.getBoundingClientRect();
|
|
42
|
-
return Math.hypot(rect.left - target.left, rect.top - target.top) < 2;
|
|
43
|
-
}
|
|
44
|
-
function AgentPointer({ active, initialPosition, label, operation, targetElement, targetPosition, visible }) {
|
|
45
|
-
const pointerRef = useRef(null);
|
|
46
|
-
const activeOperationRef = useRef(undefined);
|
|
47
|
-
const activeTargetRef = useRef(undefined);
|
|
48
|
-
const exitTimerRef = useRef(undefined);
|
|
49
|
-
const feedbackTimerRef = useRef(undefined);
|
|
50
|
-
const motionRevisionRef = useRef(0);
|
|
51
|
-
const latestActiveRef = useRef(active);
|
|
52
|
-
const latestOperationRef = useRef(operation);
|
|
53
|
-
const [motion, setMotion] = useState();
|
|
54
|
-
latestActiveRef.current = active;
|
|
55
|
-
latestOperationRef.current = operation;
|
|
56
|
-
const clearExitTimer = () => {
|
|
57
|
-
if (!exitTimerRef.current)
|
|
58
|
-
return;
|
|
59
|
-
clearTimeout(exitTimerRef.current);
|
|
60
|
-
exitTimerRef.current = undefined;
|
|
61
|
-
};
|
|
62
|
-
const clearFeedbackTimer = () => {
|
|
63
|
-
if (!feedbackTimerRef.current)
|
|
64
|
-
return;
|
|
65
|
-
clearTimeout(feedbackTimerRef.current);
|
|
66
|
-
feedbackTimerRef.current = undefined;
|
|
67
|
-
};
|
|
68
|
-
const scheduleResting = (revision, durationMs) => {
|
|
69
|
-
clearFeedbackTimer();
|
|
70
|
-
feedbackTimerRef.current = setTimeout(() => {
|
|
71
|
-
if (motionRevisionRef.current !== revision)
|
|
72
|
-
return;
|
|
73
|
-
setMotion((current) => current?.revision === revision
|
|
74
|
-
? { ...current, feedback: undefined, phase: "resting" }
|
|
75
|
-
: current);
|
|
76
|
-
}, durationMs);
|
|
77
|
-
};
|
|
78
|
-
const beginFeedback = (revision, toolCallId) => {
|
|
79
|
-
const latestOperation = latestOperationRef.current;
|
|
80
|
-
if (!latestActiveRef.current
|
|
81
|
-
|| motionRevisionRef.current !== revision
|
|
82
|
-
|| latestOperation.toolCallId !== toolCallId)
|
|
83
|
-
return;
|
|
84
|
-
const feedback = operationEffect(latestOperation) === "action"
|
|
85
|
-
&& latestOperation.status !== "failed"
|
|
86
|
-
&& latestOperation.status !== "cancelled"
|
|
87
|
-
? "click"
|
|
88
|
-
: undefined;
|
|
89
|
-
if (!feedback) {
|
|
90
|
-
setMotion((current) => current?.revision === revision
|
|
91
|
-
? { ...current, feedback: undefined, phase: "resting" }
|
|
92
|
-
: current);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
setMotion((current) => current?.revision === revision
|
|
96
|
-
? { ...current, feedback, phase: "arrived" }
|
|
97
|
-
: current);
|
|
98
|
-
scheduleResting(revision, POINTER_CLICK_FEEDBACK_DURATION_MS);
|
|
99
|
-
};
|
|
100
|
-
useEffect(() => () => {
|
|
101
|
-
clearExitTimer();
|
|
102
|
-
clearFeedbackTimer();
|
|
103
|
-
}, []);
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
if (!visible || !initialPosition) {
|
|
106
|
-
if (!motion || motion.phase === "hidden")
|
|
107
|
-
return;
|
|
108
|
-
activeOperationRef.current = undefined;
|
|
109
|
-
activeTargetRef.current = undefined;
|
|
110
|
-
clearFeedbackTimer();
|
|
111
|
-
const revision = ++motionRevisionRef.current;
|
|
112
|
-
setMotion((current) => current
|
|
113
|
-
? { ...current, durationMs: POINTER_EXIT_DURATION_MS, feedback: undefined, phase: "hidden", revision }
|
|
114
|
-
: current);
|
|
115
|
-
clearExitTimer();
|
|
116
|
-
exitTimerRef.current = setTimeout(() => {
|
|
117
|
-
if (motionRevisionRef.current === revision)
|
|
118
|
-
setMotion(undefined);
|
|
119
|
-
}, POINTER_EXIT_DURATION_MS);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
clearExitTimer();
|
|
123
|
-
if (!motion) {
|
|
124
|
-
activeOperationRef.current = operation.toolCallId;
|
|
125
|
-
activeTargetRef.current = undefined;
|
|
126
|
-
const revision = ++motionRevisionRef.current;
|
|
127
|
-
setMotion({
|
|
128
|
-
durationMs: 0,
|
|
129
|
-
feedback: undefined,
|
|
130
|
-
phase: "resting",
|
|
131
|
-
position: initialPosition,
|
|
132
|
-
revision,
|
|
133
|
-
toolCallId: operation.toolCallId,
|
|
134
|
-
});
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (!active) {
|
|
138
|
-
activeOperationRef.current = undefined;
|
|
139
|
-
activeTargetRef.current = undefined;
|
|
140
|
-
clearFeedbackTimer();
|
|
141
|
-
if (motion.phase !== "resting" || motion.feedback) {
|
|
142
|
-
const revision = ++motionRevisionRef.current;
|
|
143
|
-
setMotion((current) => current
|
|
144
|
-
? { ...current, feedback: undefined, phase: "resting", revision }
|
|
145
|
-
: current);
|
|
146
|
-
}
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const operationChanged = activeOperationRef.current !== operation.toolCallId;
|
|
150
|
-
if (operationChanged) {
|
|
151
|
-
activeOperationRef.current = operation.toolCallId;
|
|
152
|
-
activeTargetRef.current = undefined;
|
|
153
|
-
clearFeedbackTimer();
|
|
154
|
-
}
|
|
155
|
-
else if (motion.phase === "hidden") {
|
|
156
|
-
setMotion((current) => current
|
|
157
|
-
? { ...current, durationMs: 0, phase: "resting" }
|
|
158
|
-
: current);
|
|
159
|
-
}
|
|
160
|
-
if (!targetElement || !targetPosition) {
|
|
161
|
-
if (operationChanged || activeTargetRef.current) {
|
|
162
|
-
activeTargetRef.current = undefined;
|
|
163
|
-
clearFeedbackTimer();
|
|
164
|
-
const revision = ++motionRevisionRef.current;
|
|
165
|
-
const pointerRect = pointerRef.current?.getBoundingClientRect();
|
|
166
|
-
setMotion((current) => current
|
|
167
|
-
? {
|
|
168
|
-
...current,
|
|
169
|
-
durationMs: 0,
|
|
170
|
-
feedback: undefined,
|
|
171
|
-
phase: "resting",
|
|
172
|
-
position: pointerRect
|
|
173
|
-
? { left: pointerRect.left, top: pointerRect.top }
|
|
174
|
-
: current.position,
|
|
175
|
-
revision,
|
|
176
|
-
toolCallId: operation.toolCallId,
|
|
177
|
-
}
|
|
178
|
-
: current);
|
|
179
|
-
}
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const targetChanged = operationChanged || activeTargetRef.current !== targetElement;
|
|
183
|
-
if (!targetChanged) {
|
|
184
|
-
if (motion.position.left === targetPosition.left && motion.position.top === targetPosition.top)
|
|
185
|
-
return;
|
|
186
|
-
setMotion((current) => current
|
|
187
|
-
? { ...current, durationMs: 180, position: targetPosition }
|
|
188
|
-
: current);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
activeTargetRef.current = targetElement;
|
|
192
|
-
clearFeedbackTimer();
|
|
193
|
-
const revision = ++motionRevisionRef.current;
|
|
194
|
-
const pointerRect = pointerRef.current?.getBoundingClientRect();
|
|
195
|
-
const currentPosition = pointerRect
|
|
196
|
-
? { left: pointerRect.left, top: pointerRect.top }
|
|
197
|
-
: motion.position;
|
|
198
|
-
const prefersReducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
199
|
-
const durationMs = prefersReducedMotion ? 0 : pointerMoveDuration(currentPosition, targetPosition);
|
|
200
|
-
setMotion((current) => current
|
|
201
|
-
? {
|
|
202
|
-
...current,
|
|
203
|
-
durationMs,
|
|
204
|
-
feedback: undefined,
|
|
205
|
-
phase: "moving",
|
|
206
|
-
position: targetPosition,
|
|
207
|
-
revision,
|
|
208
|
-
toolCallId: operation.toolCallId,
|
|
209
|
-
}
|
|
210
|
-
: current);
|
|
211
|
-
if (durationMs === 0)
|
|
212
|
-
beginFeedback(revision, operation.toolCallId);
|
|
213
|
-
}, [
|
|
214
|
-
active,
|
|
215
|
-
initialPosition?.left,
|
|
216
|
-
initialPosition?.top,
|
|
217
|
-
motion,
|
|
218
|
-
operation.toolCallId,
|
|
219
|
-
targetElement,
|
|
220
|
-
targetPosition?.left,
|
|
221
|
-
targetPosition?.top,
|
|
222
|
-
visible,
|
|
223
|
-
]);
|
|
224
|
-
if (!motion)
|
|
225
|
-
return null;
|
|
226
|
-
const effect = operationEffect(operation);
|
|
227
|
-
const activeEffect = active ? effect : undefined;
|
|
228
|
-
return (_jsxs("div", { "aria-hidden": true, className: "agent-operation__pointer-effect", "data-active": active ? "true" : "false", "data-feedback": motion.feedback, "data-operation-effect": activeEffect, "data-phase": motion.phase, onTransitionEnd: (event) => {
|
|
229
|
-
if (event.currentTarget !== event.target
|
|
230
|
-
|| event.propertyName !== "transform"
|
|
231
|
-
|| motion.phase !== "moving"
|
|
232
|
-
|| !pointerReachedTarget(event.currentTarget, motion.position))
|
|
233
|
-
return;
|
|
234
|
-
beginFeedback(motion.revision, motion.toolCallId);
|
|
235
|
-
}, ref: pointerRef, style: {
|
|
236
|
-
"--agent-operation-pointer-duration": `${motion.durationMs}ms`,
|
|
237
|
-
"--agent-operation-pointer-x": `${motion.position.left}px`,
|
|
238
|
-
"--agent-operation-pointer-y": `${motion.position.top}px`,
|
|
239
|
-
"--agent-operation-ripple-duration": `${POINTER_CLICK_FEEDBACK_DURATION_MS}ms`,
|
|
240
|
-
}, children: [motion.phase === "arrived" && motion.feedback ? (_jsx("span", { className: "agent-operation__pointer-ripple agent-operation__pointer-ripple--primary" }, `primary-${motion.revision}`)) : null, _jsx("span", { className: "agent-operation__pointer-cursor", children: effect !== "read" && effect !== "navigate" ? (_jsx(Cursor, { className: "agent-operation__pointer", size: 24, weight: "fill" })) : null }), active && motion.phase !== "hidden" ? (_jsxs("span", { className: "agent-operation__pointer-label", "data-operation-effect": activeEffect, title: label, children: [activeEffect === "read" ? (_jsxs("span", { className: "agent-operation__pointer-read-scan", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : null, activeEffect === "navigate" ? _jsx("span", { className: "agent-operation__pointer-navigation-trail" }) : null, _jsx("span", { className: "agent-operation__pointer-label-text", children: label })] })) : null] }));
|
|
241
|
-
}
|
|
242
|
-
export function OperationOverlayView({ operation, progressHistory = [], running, feedbackActive = running, humanHasControl = false, taskLabel, onCancel, resolveSurface, resolveTarget }) {
|
|
243
|
-
const [, setFrame] = useState(0);
|
|
244
|
-
const [historyOpen, setHistoryOpen] = useState(false);
|
|
245
|
-
const historyId = useId();
|
|
246
|
-
const clearTimerRef = useRef(undefined);
|
|
247
|
-
const controllerTimerRef = useRef(undefined);
|
|
248
|
-
const [visibleOperation, setVisibleOperation] = useState(operation);
|
|
249
|
-
const [controllerMounted, setControllerMounted] = useState(Boolean(operation
|
|
250
|
-
&& operation.status !== "cancelled"
|
|
251
|
-
&& (running || humanHasControl || operation.status === "failed")));
|
|
252
|
-
const [controllerExiting, setControllerExiting] = useState(false);
|
|
253
|
-
useEffect(() => {
|
|
254
|
-
if (clearTimerRef.current)
|
|
255
|
-
clearTimeout(clearTimerRef.current);
|
|
256
|
-
if (operation)
|
|
257
|
-
setVisibleOperation(operation);
|
|
258
|
-
if (operation?.status === "cancelled") {
|
|
259
|
-
clearTimerRef.current = setTimeout(() => setVisibleOperation(undefined), 600);
|
|
260
|
-
}
|
|
261
|
-
return () => { if (clearTimerRef.current)
|
|
262
|
-
clearTimeout(clearTimerRef.current); };
|
|
263
|
-
}, [operation, running]);
|
|
264
|
-
useEffect(() => {
|
|
265
|
-
if ((!running && !feedbackActive && !humanHasControl) || !visibleOperation || visibleOperation.status === "cancelled")
|
|
266
|
-
return;
|
|
267
|
-
let frame = requestAnimationFrame(function update() { setFrame((current) => current + 1); frame = requestAnimationFrame(update); });
|
|
268
|
-
return () => cancelAnimationFrame(frame);
|
|
269
|
-
}, [visibleOperation?.toolCallId, visibleOperation?.status, running, feedbackActive, humanHasControl]);
|
|
270
|
-
useEffect(() => {
|
|
271
|
-
if (progressHistory.length === 0)
|
|
272
|
-
setHistoryOpen(false);
|
|
273
|
-
}, [progressHistory.length]);
|
|
274
|
-
const controllerShouldBeVisible = Boolean(visibleOperation
|
|
275
|
-
&& visibleOperation.status !== "cancelled"
|
|
276
|
-
&& (running || humanHasControl || visibleOperation.status === "failed"));
|
|
277
|
-
useEffect(() => {
|
|
278
|
-
if (controllerTimerRef.current)
|
|
279
|
-
clearTimeout(controllerTimerRef.current);
|
|
280
|
-
if (controllerShouldBeVisible) {
|
|
281
|
-
setControllerMounted(true);
|
|
282
|
-
setControllerExiting(false);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
if (!controllerMounted) {
|
|
286
|
-
setControllerExiting(false);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
setHistoryOpen(false);
|
|
290
|
-
setControllerExiting(true);
|
|
291
|
-
controllerTimerRef.current = setTimeout(() => {
|
|
292
|
-
setControllerMounted(false);
|
|
293
|
-
setControllerExiting(false);
|
|
294
|
-
}, CONTROLLER_EXIT_DURATION_MS);
|
|
295
|
-
return () => {
|
|
296
|
-
if (controllerTimerRef.current)
|
|
297
|
-
clearTimeout(controllerTimerRef.current);
|
|
298
|
-
};
|
|
299
|
-
}, [controllerMounted, controllerShouldBeVisible]);
|
|
300
|
-
useEffect(() => {
|
|
301
|
-
if (typeof document === "undefined")
|
|
302
|
-
return;
|
|
303
|
-
const surface = resolveSurface?.();
|
|
304
|
-
if (!surface)
|
|
305
|
-
return;
|
|
306
|
-
const previousInert = surface.inert;
|
|
307
|
-
const previousBusy = surface.getAttribute("aria-busy");
|
|
308
|
-
const locked = running && !humanHasControl;
|
|
309
|
-
surface.inert = locked;
|
|
310
|
-
if (locked)
|
|
311
|
-
surface.setAttribute("aria-busy", "true");
|
|
312
|
-
else
|
|
313
|
-
surface.removeAttribute("aria-busy");
|
|
314
|
-
return () => {
|
|
315
|
-
surface.inert = previousInert;
|
|
316
|
-
if (previousBusy === null)
|
|
317
|
-
surface.removeAttribute("aria-busy");
|
|
318
|
-
else
|
|
319
|
-
surface.setAttribute("aria-busy", previousBusy);
|
|
320
|
-
};
|
|
321
|
-
}, [humanHasControl, resolveSurface, running]);
|
|
322
|
-
if (!visibleOperation || typeof document === "undefined")
|
|
323
|
-
return null;
|
|
324
|
-
const resolvedTarget = resolveTarget?.(visibleOperation);
|
|
325
|
-
const surfaceElement = resolveSurface?.();
|
|
326
|
-
const target = resolvedTarget && (!surfaceElement || surfaceElement.contains(resolvedTarget.element))
|
|
327
|
-
? resolvedTarget
|
|
328
|
-
: undefined;
|
|
329
|
-
const progressLabel = operationProgressLabel(visibleOperation);
|
|
330
|
-
const effect = operationEffect(visibleOperation);
|
|
331
|
-
const targetLabel = operationTargetLabel(visibleOperation, target);
|
|
332
|
-
const pointerLabel = normalizedLabel(visibleOperation.progressLabel) ?? targetLabel ?? progressLabel;
|
|
333
|
-
const normalizedTaskLabel = normalizedLabel(taskLabel);
|
|
334
|
-
const controllerLabel = normalizedTaskLabel ?? (humanHasControl ? undefined : progressLabel);
|
|
335
|
-
const statusLabel = humanHasControl ? "等待你完成操作" : {
|
|
336
|
-
running: "Agent 正在控制",
|
|
337
|
-
completed: running ? "Agent 正在控制" : "操作已完成",
|
|
338
|
-
failed: running ? "Agent 正在处理错误" : "操作失败",
|
|
339
|
-
cancelled: "任务已终止",
|
|
340
|
-
}[visibleOperation.status];
|
|
341
|
-
const compactStatusLabel = humanHasControl
|
|
342
|
-
? "等待你完成操作"
|
|
343
|
-
: normalizedTaskLabel ?? progressLabel;
|
|
344
|
-
const rect = target?.element.isConnected ? target.element.getBoundingClientRect() : undefined;
|
|
345
|
-
const highlightedRect = effect === "navigate" ? undefined : rect;
|
|
346
|
-
const surfaceRect = surfaceElement?.isConnected ? surfaceElement.getBoundingClientRect() : undefined;
|
|
347
|
-
const agentControlsSurface = feedbackActive && !humanHasControl && visibleOperation.status !== "cancelled";
|
|
348
|
-
const operationFeedbackActive = feedbackActive && !humanHasControl && visibleOperation.status !== "cancelled";
|
|
349
|
-
const pointerVisible = Boolean(surfaceRect) && feedbackActive && !humanHasControl && visibleOperation.status !== "cancelled";
|
|
350
|
-
const pointerPosition = rect ? {
|
|
351
|
-
left: rect.left + rect.width / 2,
|
|
352
|
-
top: rect.top + rect.height / 2,
|
|
353
|
-
} : undefined;
|
|
354
|
-
const cancel = onCancel ? () => {
|
|
355
|
-
onCancel();
|
|
356
|
-
} : undefined;
|
|
357
|
-
return createPortal(_jsxs("div", { className: "agent-operation", "data-feedback-active": feedbackActive, "data-human-control": humanHasControl, "data-operation-effect": effect, "data-run-active": running, "data-status": visibleOperation.status, children: [agentControlsSurface && surfaceRect ? _jsx("div", { "aria-hidden": true, className: "agent-operation__surface", style: {
|
|
358
|
-
...(highlightedRect ? {
|
|
359
|
-
"--agent-operation-cutout-height": `${highlightedRect.height}px`,
|
|
360
|
-
"--agent-operation-cutout-left": `${highlightedRect.left - surfaceRect.left}px`,
|
|
361
|
-
"--agent-operation-cutout-top": `${highlightedRect.top - surfaceRect.top}px`,
|
|
362
|
-
"--agent-operation-cutout-width": `${highlightedRect.width}px`,
|
|
363
|
-
} : {}),
|
|
364
|
-
height: surfaceRect.height, left: surfaceRect.left, top: surfaceRect.top, width: surfaceRect.width,
|
|
365
|
-
} }) : null, operationFeedbackActive && highlightedRect ? _jsx("div", { "aria-hidden": true, className: "agent-operation__target", "data-operation-effect": effect, style: { height: highlightedRect.height, left: highlightedRect.left, top: highlightedRect.top, width: highlightedRect.width } }) : null, _jsx(AgentPointer, { active: operationFeedbackActive, initialPosition: surfaceRect ? { left: surfaceRect.left + surfaceRect.width / 2, top: surfaceRect.top + surfaceRect.height / 2 } : undefined, label: pointerLabel, operation: visibleOperation, targetElement: target?.element, targetPosition: pointerPosition, visible: pointerVisible }), controllerMounted ? _jsxs("section", { "aria-live": "polite", className: "agent-operation__controller", "data-visibility": controllerExiting ? "exiting" : "visible", style: surfaceRect ? { left: surfaceRect.left + surfaceRect.width / 2, maxWidth: Math.max(280, surfaceRect.width - 32) } : undefined, children: [historyOpen ? _jsxs("aside", { "aria-label": "\u672C\u6B21\u8FD0\u884C\u7684\u64CD\u4F5C\u8BB0\u5F55", className: "agent-operation__history", id: historyId, children: [_jsxs("header", { children: [_jsx("strong", { children: "\u64CD\u4F5C\u8BB0\u5F55" }), _jsx("span", { children: progressHistory.length })] }), _jsx("ol", { children: progressHistory.map(({ progressLabel: label, toolCallId }, index) => _jsxs("li", { children: [_jsx("span", { "aria-hidden": true, children: index + 1 }), _jsx("p", { children: label })] }, toolCallId)) })] }) : null, _jsx("span", { "aria-hidden": true, className: "agent-operation__edge-flow" }), _jsxs("span", { "aria-hidden": true, className: "agent-operation__pause-mark", children: [_jsx("i", {}), _jsx("i", {})] }), _jsxs("button", { "aria-controls": historyId, "aria-expanded": historyOpen, "aria-label": "\u67E5\u770B\u672C\u6B21\u8FD0\u884C\u7684\u64CD\u4F5C\u8BB0\u5F55", className: "agent-operation__activity", "data-open": historyOpen ? "true" : "false", disabled: progressHistory.length === 0, onClick: () => setHistoryOpen((current) => !current), title: progressHistory.length === 0 ? "暂无操作记录" : "查看本次运行的操作记录", type: "button", children: [_jsx(Sparkle, { className: "agent-operation__activity-icon", size: 16, weight: "fill" }), _jsx("i", {}), _jsx("b", { children: "\u2726" })] }), _jsxs("div", { children: [_jsx("span", { className: "agent-operation__heading", children: _jsx("strong", { children: controllerLabel }) }), statusLabel ? _jsx("small", { className: "agent-operation__description", children: _jsx("span", { className: "agent-operation__status", children: statusLabel }) }) : null] }), (running || humanHasControl) && visibleOperation.status !== "cancelled" ? _jsx("span", { className: "agent-operation__compact-status", title: compactStatusLabel, children: compactStatusLabel }) : null, cancel && running && visibleOperation.status !== "cancelled" ? _jsx("button", { className: "agent-operation__stop", type: "button", onClick: cancel, children: "\u7EC8\u6B62\u4EFB\u52A1" }) : null] }) : null] }), document.body);
|
|
366
|
-
}
|
|
367
|
-
//# sourceMappingURL=operation-view.js.map
|