@nexface/tools 0.1.14 → 0.1.15-alpha.1
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/browser/actions.js +10 -34
- package/dist/browser/actions.js.map +1 -0
- package/dist/browser/controller.js +74 -53
- package/dist/browser/controller.js.map +1 -0
- package/dist/browser/diagnostics.js +3 -8
- package/dist/browser/diagnostics.js.map +1 -0
- package/dist/browser/dom.js +28 -12
- package/dist/browser/dom.js.map +1 -0
- package/dist/browser/feedback.js +5 -6
- package/dist/browser/feedback.js.map +1 -0
- package/dist/browser/focus.js +1 -0
- package/dist/browser/focus.js.map +1 -0
- package/dist/browser/locator.js +9 -3
- package/dist/browser/locator.js.map +1 -0
- package/dist/browser/prompt.generated.js +1 -0
- package/dist/browser/prompt.generated.js.map +1 -0
- package/dist/browser/prompt.js +1 -0
- package/dist/browser/prompt.js.map +1 -0
- package/dist/browser/snapshot.js +22 -10
- package/dist/browser/snapshot.js.map +1 -0
- package/dist/browser/toolset.js +36 -42
- package/dist/browser/toolset.js.map +1 -0
- package/dist/browser/types.d.ts +1 -1
- package/dist/browser/types.js +1 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/browser/worker-runner.js +1 -0
- package/dist/browser/worker-runner.js.map +1 -0
- package/dist/definition.d.ts +3 -1
- package/dist/definition.js +2 -2
- package/dist/definition.js.map +1 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-react.d.ts +1 -1
- package/dist/internal-react.js +4 -3
- package/dist/internal-react.js.map +1 -0
- package/dist/internal-types.js +1 -0
- package/dist/internal-types.js.map +1 -0
- package/dist/navigation.js +1 -0
- package/dist/navigation.js.map +1 -0
- package/dist/operation-lock.js +2 -36
- package/dist/operation-lock.js.map +1 -0
- package/dist/operation-runtime.js +13 -41
- package/dist/operation-runtime.js.map +1 -0
- package/dist/operation-surface.js +41 -118
- package/dist/operation-surface.js.map +1 -0
- package/dist/operation-types.js +1 -0
- package/dist/operation-types.js.map +1 -0
- package/dist/operation-view.d.ts +1 -1
- package/dist/operation-view.js +60 -120
- package/dist/operation-view.js.map +1 -0
- package/dist/react.js +12 -9
- package/dist/react.js.map +1 -0
- package/dist/registration.d.ts +3 -0
- package/dist/registration.js +7 -5
- package/dist/registration.js.map +1 -0
- package/dist/runtime.d.ts +17 -6
- package/dist/runtime.js +59 -105
- package/dist/runtime.js.map +1 -0
- package/dist/shared/definition.js +1 -0
- package/dist/shared/definition.js.map +1 -0
- package/dist/shared/errors.d.ts +1 -1
- package/dist/shared/errors.js +1 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/page-protocol.js +1 -0
- package/dist/shared/page-protocol.js.map +1 -0
- package/dist/shared/page-tools.js +1 -0
- package/dist/shared/page-tools.js.map +1 -0
- package/dist/shared/runtime-controller.d.ts +0 -1
- package/dist/shared/runtime-controller.js +1 -0
- package/dist/shared/runtime-controller.js.map +1 -0
- package/dist/shared/runtime-execution.js +1 -0
- package/dist/shared/runtime-execution.js.map +1 -0
- package/dist/shared/schema.js +19 -45
- package/dist/shared/schema.js.map +1 -0
- package/dist/styles.css +109 -879
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/webmcp.js +12 -38
- package/dist/webmcp.js.map +1 -0
- package/package.json +2 -6
- package/dist/tool-search.d.ts +0 -11
- package/dist/tool-search.js +0 -117
|
@@ -4,24 +4,17 @@ export class OperationTracker {
|
|
|
4
4
|
#unscoped = 0;
|
|
5
5
|
#executions = new Map();
|
|
6
6
|
#listeners = new Set();
|
|
7
|
-
#snapshot = Object.freeze({
|
|
8
|
-
operation: null,
|
|
9
|
-
executions: Object.freeze([]),
|
|
10
|
-
});
|
|
7
|
+
#snapshot = Object.freeze({ operation: null, executions: Object.freeze([]) });
|
|
11
8
|
getSnapshot = () => this.#snapshot;
|
|
12
9
|
subscribe = (listener) => {
|
|
13
10
|
this.#listeners.add(listener);
|
|
14
|
-
return () => {
|
|
15
|
-
this.#listeners.delete(listener);
|
|
16
|
-
};
|
|
11
|
+
return () => { this.#listeners.delete(listener); };
|
|
17
12
|
};
|
|
18
13
|
begin(options = {}) {
|
|
19
14
|
options.signal?.throwIfAborted();
|
|
20
15
|
const previous = this.#operation;
|
|
21
|
-
const replacing = previous &&
|
|
22
|
-
previous.
|
|
23
|
-
previous.snapshot.status === "waiting" &&
|
|
24
|
-
previous.pending === 0;
|
|
16
|
+
const replacing = previous && previous.handle === options.replaceWaiting
|
|
17
|
+
&& previous.snapshot.status === "waiting" && previous.pending === 0;
|
|
25
18
|
if (this.#unscoped || (previous && !replacing)) {
|
|
26
19
|
throw new AgentToolError("OPERATION_BUSY", "The Runtime already has an operation or outstanding tool calls.");
|
|
27
20
|
}
|
|
@@ -30,22 +23,11 @@ export class OperationTracker {
|
|
|
30
23
|
previous.resolveEnd();
|
|
31
24
|
}
|
|
32
25
|
let resolveEnd;
|
|
33
|
-
const endPromise = new Promise((resolve) => {
|
|
34
|
-
resolveEnd = resolve;
|
|
35
|
-
});
|
|
26
|
+
const endPromise = new Promise((resolve) => { resolveEnd = resolve; });
|
|
36
27
|
const id = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
37
28
|
const operation = {
|
|
38
|
-
snapshot: Object.freeze({
|
|
39
|
-
|
|
40
|
-
source: options.source ?? "host",
|
|
41
|
-
status: "running",
|
|
42
|
-
hasExecuted: false,
|
|
43
|
-
canCancel: Boolean(options.onCancel),
|
|
44
|
-
...(options.taskProgress ? { taskProgress: Object.freeze(options.taskProgress) } : {}),
|
|
45
|
-
}),
|
|
46
|
-
handle: undefined,
|
|
47
|
-
pending: 0,
|
|
48
|
-
resolveEnd,
|
|
29
|
+
snapshot: Object.freeze({ id, source: options.source ?? "host", status: "running", hasExecuted: false, canCancel: Boolean(options.onCancel), ...(options.taskProgress ? { taskProgress: Object.freeze(options.taskProgress) } : {}) }),
|
|
30
|
+
handle: undefined, pending: 0, resolveEnd,
|
|
49
31
|
...(options.onCancel ? { onCancel: options.onCancel } : {}),
|
|
50
32
|
removeAbort: () => options.signal?.removeEventListener("abort", onAbort),
|
|
51
33
|
};
|
|
@@ -60,11 +42,7 @@ export class OperationTracker {
|
|
|
60
42
|
if (this.#operation !== operation || operation.snapshot.status === "ending")
|
|
61
43
|
return endPromise;
|
|
62
44
|
operation.removeAbort();
|
|
63
|
-
operation.snapshot = Object.freeze({
|
|
64
|
-
...operation.snapshot,
|
|
65
|
-
status: "ending",
|
|
66
|
-
outcome: endOptions?.outcome ?? "completed",
|
|
67
|
-
});
|
|
45
|
+
operation.snapshot = Object.freeze({ ...operation.snapshot, status: "ending", outcome: endOptions?.outcome ?? "completed" });
|
|
68
46
|
this.#publish();
|
|
69
47
|
if (this.#finish(operation))
|
|
70
48
|
this.#publish();
|
|
@@ -99,11 +77,8 @@ export class OperationTracker {
|
|
|
99
77
|
}
|
|
100
78
|
requestCancel(id) {
|
|
101
79
|
const operation = this.#operation;
|
|
102
|
-
if (!operation ||
|
|
103
|
-
operation.snapshot.
|
|
104
|
-
!operation.onCancel ||
|
|
105
|
-
operation.snapshot.status === "ending" ||
|
|
106
|
-
operation.snapshot.status === "cancelling")
|
|
80
|
+
if (!operation || operation.snapshot.id !== id || !operation.onCancel
|
|
81
|
+
|| operation.snapshot.status === "ending" || operation.snapshot.status === "cancelling")
|
|
107
82
|
return;
|
|
108
83
|
const previous = operation.snapshot.status;
|
|
109
84
|
this.#update(operation, { status: "cancelling" });
|
|
@@ -148,9 +123,7 @@ export class OperationTracker {
|
|
|
148
123
|
if (event.status === "running") {
|
|
149
124
|
this.#executions.set(event.id, event);
|
|
150
125
|
const operation = this.#operation;
|
|
151
|
-
if (operation &&
|
|
152
|
-
event.operationId === operation.snapshot.id &&
|
|
153
|
-
!operation.snapshot.hasExecuted) {
|
|
126
|
+
if (operation && event.operationId === operation.snapshot.id && !operation.snapshot.hasExecuted) {
|
|
154
127
|
operation.snapshot = Object.freeze({ ...operation.snapshot, hasExecuted: true });
|
|
155
128
|
}
|
|
156
129
|
}
|
|
@@ -159,9 +132,7 @@ export class OperationTracker {
|
|
|
159
132
|
this.#publish();
|
|
160
133
|
}
|
|
161
134
|
#finish(operation) {
|
|
162
|
-
if (operation.pending ||
|
|
163
|
-
operation.snapshot.status !== "ending" ||
|
|
164
|
-
this.#operation !== operation)
|
|
135
|
+
if (operation.pending || operation.snapshot.status !== "ending" || this.#operation !== operation)
|
|
165
136
|
return false;
|
|
166
137
|
this.#operation = undefined;
|
|
167
138
|
operation.resolveEnd();
|
|
@@ -180,3 +151,4 @@ export class OperationTracker {
|
|
|
180
151
|
listener();
|
|
181
152
|
}
|
|
182
153
|
}
|
|
154
|
+
//# sourceMappingURL=operation-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-runtime.js","sourceRoot":"","sources":["../src/operation-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AA+BpD,MAAM,OAAO,gBAAgB;IAC3B,UAAU,CAAwB;IAClC,SAAS,GAAG,CAAC,CAAC;IACd,WAAW,GAAG,IAAI,GAAG,EAAmC,CAAC;IACzD,UAAU,GAAG,IAAI,GAAG,EAAc,CAAC;IACnC,SAAS,GAA4B,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAEvG,WAAW,GAAG,GAA4B,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;IAC5D,SAAS,GAAG,CAAC,QAAoB,EAAgB,EAAE;QACjD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC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AAK,QAAQ,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QAC/G,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,SAAoB,EAAE,KAAiC;QAC7D,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7B,SAAS,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,IAAI,IAAI;YAC5C,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;SAC1D,CAAC,CAAC;QACH,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU;YAAE,QAAQ,EAAE,CAAC;IACrD,CAAC;CACF","sourcesContent":["import type { AgentToolExecutionEvent } from \"./internal-types.js\";\nimport { AgentToolError } from \"./shared/errors.js\";\nimport type { ToolOperation } from \"./runtime.js\";\n\nimport type { TaskProgress } from \"./shared/runtime-controller.js\";\nexport type { TaskProgress } from \"./shared/runtime-controller.js\";\n\nexport interface OperationSnapshot {\n readonly taskProgress?: TaskProgress;\n readonly id: string;\n readonly source: \"host\" | \"webmcp\";\n readonly status: \"running\" | \"waiting\" | \"cancelling\" | \"ending\";\n readonly hasExecuted: boolean;\n readonly outcome?: \"completed\" | \"failed\" | \"cancelled\";\n readonly reason?: \"bridge_disposed\";\n readonly canCancel: boolean;\n}\n\nexport interface RuntimeActivitySnapshot {\n readonly operation: OperationSnapshot | null;\n readonly executions: readonly AgentToolExecutionEvent[];\n}\n\ntype Operation = {\n snapshot: OperationSnapshot;\n handle: ToolOperation;\n pending: number;\n onCancel?: () => void;\n removeAbort(): void;\n resolveEnd(): void;\n};\n\nexport class OperationTracker {\n #operation: Operation | undefined;\n #unscoped = 0;\n #executions = new Map<string, AgentToolExecutionEvent>();\n #listeners = new Set<() => void>();\n #snapshot: RuntimeActivitySnapshot = Object.freeze({ operation: null, executions: Object.freeze([]) });\n\n getSnapshot = (): RuntimeActivitySnapshot => this.#snapshot;\n subscribe = (listener: () => void): (() => void) => {\n this.#listeners.add(listener);\n return () => { this.#listeners.delete(listener); };\n };\n\n begin(options: {\n signal?: AbortSignal;\n onCancel?: () => void;\n source?: \"host\" | \"webmcp\";\n replaceWaiting?: ToolOperation;\n taskProgress?: TaskProgress;\n } = {}): ToolOperation {\n options.signal?.throwIfAborted();\n const previous = this.#operation;\n const replacing = previous && previous.handle === options.replaceWaiting\n && previous.snapshot.status === \"waiting\" && previous.pending === 0;\n if (this.#unscoped || (previous && !replacing)) {\n throw new AgentToolError(\"OPERATION_BUSY\", \"The Runtime already has an operation or outstanding tool calls.\");\n }\n if (replacing) {\n previous.removeAbort();\n previous.resolveEnd();\n }\n let resolveEnd!: () => void;\n const endPromise = new Promise<void>((resolve) => { resolveEnd = resolve; });\n const id = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;\n const operation: Operation = {\n snapshot: Object.freeze({ id, source: options.source ?? \"host\", status: \"running\", hasExecuted: false, canCancel: Boolean(options.onCancel), ...(options.taskProgress ? { taskProgress: Object.freeze(options.taskProgress) } : {}) }),\n handle: undefined!, pending: 0, resolveEnd,\n ...(options.onCancel ? { onCancel: options.onCancel } : {}),\n removeAbort: () => options.signal?.removeEventListener(\"abort\", onAbort),\n };\n const onAbort = () => {\n if (this.#operation !== operation || operation.snapshot.status === \"ending\") return;\n this.#update(operation, { status: \"cancelling\" });\n };\n const handle: ToolOperation = Object.freeze({\n id,\n end: (endOptions?: { outcome?: \"completed\" | \"failed\" | \"cancelled\" }) => {\n if (this.#operation !== operation || operation.snapshot.status === \"ending\") return endPromise;\n operation.removeAbort();\n operation.snapshot = Object.freeze({ ...operation.snapshot, status: \"ending\", outcome: endOptions?.outcome ?? \"completed\" });\n this.#publish();\n if (this.#finish(operation)) this.#publish();\n return endPromise;\n },\n });\n operation.handle = handle;\n this.#operation = operation;\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n this.#publish();\n return handle;\n }\n\n setWaitingForUser(handle: ToolOperation, waiting: boolean): void {\n const operation = this.#operation;\n if (operation?.handle !== handle || ![\"running\", \"waiting\"].includes(operation.snapshot.status)) return;\n const status = waiting ? \"waiting\" : \"running\";\n if (status !== operation.snapshot.status) this.#update(operation, { status });\n }\n\n setTaskProgress(handle: ToolOperation, progress: TaskProgress): void {\n const operation = this.#operation;\n if (operation?.handle !== handle || operation.snapshot.status === \"ending\") return;\n this.#update(operation, { taskProgress: Object.freeze(progress) });\n }\n\n disposeBridge(handle: ToolOperation): Promise<void> {\n const operation = this.#operation;\n if (operation?.handle === handle) operation.snapshot = Object.freeze({ ...operation.snapshot, reason: \"bridge_disposed\" });\n return handle.end();\n }\n\n requestCancel(id: string): void {\n const operation = this.#operation;\n if (!operation || operation.snapshot.id !== id || !operation.onCancel\n || operation.snapshot.status === \"ending\" || operation.snapshot.status === \"cancelling\") return;\n const previous = operation.snapshot.status;\n this.#update(operation, { status: \"cancelling\" });\n try {\n operation.onCancel();\n } catch (error) {\n if (this.#operation === operation && this.#snapshot.operation?.status === \"cancelling\") {\n this.#update(operation, { status: previous });\n }\n throw error;\n }\n }\n\n // Admission is captured before execution and released exactly once, including queued aborts.\n admit(): { operationId?: string; release(): void } {\n const operation = this.#operation;\n if (operation?.snapshot.status === \"ending\") {\n throw new AgentToolError(\"OPERATION_BUSY\", \"The Runtime operation is ending; wait for end() before submitting more calls.\");\n }\n if (operation) operation.pending += 1;\n else this.#unscoped += 1;\n let released = false;\n return {\n ...(operation ? { operationId: operation.snapshot.id } : {}),\n release: () => {\n if (released) return;\n released = true;\n if (operation) {\n operation.pending -= 1;\n if (this.#finish(operation)) this.#publish();\n } else this.#unscoped -= 1;\n },\n };\n }\n\n observe(event: AgentToolExecutionEvent): void {\n if (event.status === \"running\") {\n this.#executions.set(event.id, event);\n const operation = this.#operation;\n if (operation && event.operationId === operation.snapshot.id && !operation.snapshot.hasExecuted) {\n operation.snapshot = Object.freeze({ ...operation.snapshot, hasExecuted: true });\n }\n } else this.#executions.delete(event.id);\n this.#publish();\n }\n\n #finish(operation: Operation): boolean {\n if (operation.pending || operation.snapshot.status !== \"ending\" || this.#operation !== operation) return false;\n this.#operation = undefined;\n operation.resolveEnd();\n return true;\n }\n\n #update(operation: Operation, patch: Partial<OperationSnapshot>): void {\n operation.snapshot = Object.freeze({ ...operation.snapshot, ...patch });\n this.#publish();\n }\n\n #publish(): void {\n this.#snapshot = Object.freeze({\n operation: this.#operation?.snapshot ?? null,\n executions: Object.freeze([...this.#executions.values()]),\n });\n for (const listener of this.#listeners) listener();\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { flushSync } from "react-dom";
|
|
3
|
-
import { useCallback, useLayoutEffect, useRef, useState
|
|
3
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
4
4
|
import { useSyncExternalStore } from "use-sync-external-store/shim";
|
|
5
5
|
import { PageCommandError } from "./browser/locator.js";
|
|
6
6
|
import { getInternalToolRuntime } from "./runtime.js";
|
|
@@ -9,8 +9,7 @@ import { isAgentActivation } from "./browser/focus.js";
|
|
|
9
9
|
import { OperationOverlayView } from "./operation-view.js";
|
|
10
10
|
const BROWSER_TOOL_NAMES = new Set(["nxf_getSnapshot", "nxf_executeAction", "nxf_applyAction"]);
|
|
11
11
|
const belongsToOperation = (event, operation) => !operation || event.operationId === operation.id;
|
|
12
|
-
const canPresentInOperation = (event, operation) => belongsToOperation(event, operation) &&
|
|
13
|
-
(!operation || operation.status === "running" || operation.status === "ending");
|
|
12
|
+
const canPresentInOperation = (event, operation) => belongsToOperation(event, operation) && (!operation || operation.status === "running" || operation.status === "ending");
|
|
14
13
|
const surfaces = new WeakSet();
|
|
15
14
|
export function AgentOperationSurface(props) {
|
|
16
15
|
const element = useRef(null);
|
|
@@ -22,34 +21,28 @@ export function AgentOperationSurface(props) {
|
|
|
22
21
|
if (surfaces.has(props.toolRuntime))
|
|
23
22
|
throw new Error("Only one AgentOperationSurface is supported per Runtime.");
|
|
24
23
|
surfaces.add(props.toolRuntime);
|
|
25
|
-
return () => {
|
|
26
|
-
surfaces.delete(props.toolRuntime);
|
|
27
|
-
};
|
|
24
|
+
return () => { surfaces.delete(props.toolRuntime); };
|
|
28
25
|
}, [props.toolRuntime]);
|
|
29
26
|
const blockUserInput = useCallback((event) => {
|
|
30
27
|
if ((event.type === "submit" || event.type === "reset") && isAgentActivation())
|
|
31
28
|
return;
|
|
32
|
-
if (!element.current ||
|
|
33
|
-
!isOperationSurfaceLocked(element.current) ||
|
|
34
|
-
!event.nativeEvent.isTrusted)
|
|
29
|
+
if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted)
|
|
35
30
|
return;
|
|
36
31
|
event.preventDefault();
|
|
37
32
|
event.stopPropagation();
|
|
38
33
|
}, []);
|
|
39
34
|
const blockPassiveUserInput = useCallback((event) => {
|
|
40
|
-
if (!element.current ||
|
|
41
|
-
!isOperationSurfaceLocked(element.current) ||
|
|
42
|
-
!event.nativeEvent.isTrusted)
|
|
35
|
+
if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted)
|
|
43
36
|
return;
|
|
44
37
|
// Stop React's capture dispatch, but let the native event reach our non-passive
|
|
45
38
|
// surface listener. React's passive root listener cannot prevent scrolling.
|
|
46
39
|
event.isPropagationStopped = () => true;
|
|
47
40
|
}, []);
|
|
48
|
-
return
|
|
41
|
+
return React.createElement(React.Fragment, null,
|
|
49
42
|
React.createElement("div", { ref: element, className: "nexface-operation-surface", onClickCapture: blockUserInput, onDoubleClickCapture: blockUserInput, onAuxClickCapture: blockUserInput, onPointerDownCapture: blockUserInput, onPointerUpCapture: blockUserInput, onPointerMoveCapture: blockUserInput, onPointerOverCapture: blockUserInput, onPointerOutCapture: blockUserInput, onMouseDownCapture: blockUserInput, onMouseUpCapture: blockUserInput, onContextMenuCapture: blockUserInput, onMouseMoveCapture: blockUserInput, onMouseOverCapture: blockUserInput, onMouseOutCapture: blockUserInput, onWheelCapture: blockPassiveUserInput, onTouchStartCapture: blockPassiveUserInput, onTouchMoveCapture: blockPassiveUserInput, onTouchEndCapture: blockUserInput, onTouchCancelCapture: blockUserInput, onKeyDownCapture: blockUserInput, onKeyUpCapture: blockUserInput, onKeyPressCapture: blockUserInput, onBeforeInputCapture: blockUserInput, onPasteCapture: blockUserInput, onCutCapture: blockUserInput, onDropCapture: blockUserInput, onDragStartCapture: blockUserInput, onSubmitCapture: blockUserInput, onResetCapture: blockUserInput }, props.children),
|
|
50
|
-
React.createElement(OperationSurfaceContent, { ...props, element: element }))
|
|
43
|
+
React.createElement(OperationSurfaceContent, { ...props, element: element }));
|
|
51
44
|
}
|
|
52
|
-
function OperationSurfaceContent({ toolRuntime, element
|
|
45
|
+
function OperationSurfaceContent({ toolRuntime, element }) {
|
|
53
46
|
const runtime = getInternalToolRuntime(toolRuntime);
|
|
54
47
|
const activity = useSyncExternalStore(runtime.subscribeActivity, runtime.getActivitySnapshot, runtime.getActivitySnapshot);
|
|
55
48
|
const cycle = activity.operation;
|
|
@@ -65,24 +58,15 @@ function OperationSurfaceContent({ toolRuntime, element, }) {
|
|
|
65
58
|
useLayoutEffect(() => runtime.setPageActionFeedback((event, feedback, signal) => {
|
|
66
59
|
const operation = runtime.getActivitySnapshot().operation;
|
|
67
60
|
if (signal?.aborted || !canPresentInOperation(event, operation))
|
|
68
|
-
throw new PageCommandError({
|
|
69
|
-
code: "EXECUTION_CANCELLED",
|
|
70
|
-
message: "Page action presentation was interrupted.",
|
|
71
|
-
});
|
|
61
|
+
throw new PageCommandError({ code: "EXECUTION_CANCELLED", message: "Page action presentation was interrupted." });
|
|
72
62
|
const target = feedback.target;
|
|
73
|
-
if (!feedback.effect ||
|
|
74
|
-
(feedback.effect === "action" &&
|
|
75
|
-
(!target?.isConnected || !element.current?.contains(target)))) {
|
|
63
|
+
if (!feedback.effect || (feedback.effect === "action" && (!target?.isConnected || !element.current?.contains(target)))) {
|
|
76
64
|
setVisual(undefined);
|
|
77
65
|
return;
|
|
78
66
|
}
|
|
79
67
|
const next = {
|
|
80
|
-
id: crypto.randomUUID(),
|
|
81
|
-
effect: feedback.effect,
|
|
82
|
-
label: label(event),
|
|
83
|
-
centered: feedback.effect === "read",
|
|
84
|
-
persistentCursor: true,
|
|
85
|
-
requiresTarget: feedback.effect === "action",
|
|
68
|
+
id: crypto.randomUUID(), effect: feedback.effect, label: label(event),
|
|
69
|
+
centered: feedback.effect === "read", persistentCursor: true, requiresTarget: feedback.effect === "action",
|
|
86
70
|
...(target ? { target } : {}),
|
|
87
71
|
};
|
|
88
72
|
if (feedback.effect !== "action") {
|
|
@@ -114,61 +98,32 @@ function OperationSurfaceContent({ toolRuntime, element, }) {
|
|
|
114
98
|
const page = BROWSER_TOOL_NAMES.has(event.name);
|
|
115
99
|
if (canDisplay && event.status === "running") {
|
|
116
100
|
if (page)
|
|
117
|
-
setVisual(event.name === "nxf_getSnapshot"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
feedback: {
|
|
121
|
-
id: event.id,
|
|
122
|
-
effect: "read",
|
|
123
|
-
label: label(event),
|
|
124
|
-
centered: true,
|
|
125
|
-
},
|
|
126
|
-
}
|
|
127
|
-
: undefined);
|
|
101
|
+
setVisual(event.name === "nxf_getSnapshot" ? { event, feedback: {
|
|
102
|
+
id: event.id, effect: "read", label: label(event), centered: true,
|
|
103
|
+
} } : undefined);
|
|
128
104
|
else {
|
|
129
|
-
const target = event.tool.definition.effect === "navigate"
|
|
130
|
-
? element.current
|
|
131
|
-
: runtime.resolveTarget(event.tool, event.input);
|
|
105
|
+
const target = event.tool.definition.effect === "navigate" ? element.current : runtime.resolveTarget(event.tool, event.input);
|
|
132
106
|
if (target?.isConnected && element.current?.contains(target)) {
|
|
133
107
|
const rect = target.getBoundingClientRect();
|
|
134
|
-
setVisual({
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
id: event.id,
|
|
138
|
-
effect: event.tool.definition.effect ?? "action",
|
|
139
|
-
label: label(event),
|
|
140
|
-
resolveTarget: () => event.tool.definition.effect === "navigate"
|
|
141
|
-
? (element.current ?? undefined)
|
|
142
|
-
: runtime.resolveTarget(event.tool, event.input),
|
|
143
|
-
position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 },
|
|
144
|
-
},
|
|
145
|
-
});
|
|
108
|
+
setVisual({ event, feedback: { id: event.id, effect: event.tool.definition.effect ?? "action", label: label(event),
|
|
109
|
+
resolveTarget: () => event.tool.definition.effect === "navigate" ? element.current ?? undefined : runtime.resolveTarget(event.tool, event.input),
|
|
110
|
+
position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 } } });
|
|
146
111
|
}
|
|
147
112
|
}
|
|
148
113
|
}
|
|
149
114
|
else if (canDisplay)
|
|
150
115
|
setVisual((current) => current?.event.id === event.id && current.event.operationId === event.operationId
|
|
151
|
-
? page
|
|
152
|
-
? undefined
|
|
153
|
-
: { ...current, event }
|
|
154
|
-
: current);
|
|
116
|
+
? page ? undefined : { ...current, event } : current);
|
|
155
117
|
if (page && !operation && event.status === "error")
|
|
156
118
|
setOutcome({ id: scope, status: event.cancelled ? "cancelled" : "failed" });
|
|
157
119
|
setHistory((current) => {
|
|
158
|
-
if (!belongsToOperation(event, operation) ||
|
|
159
|
-
(event.status !== "running" && current.scope !== scope))
|
|
120
|
+
if (!belongsToOperation(event, operation) || (event.status !== "running" && current.scope !== scope))
|
|
160
121
|
return current;
|
|
161
122
|
const entries = current.scope === scope ? current.entries : [];
|
|
162
|
-
const entry = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
scope,
|
|
168
|
-
entries: entries.some((item) => item.toolCallId === event.id)
|
|
169
|
-
? entries.map((item) => (item.toolCallId === event.id ? entry : item))
|
|
170
|
-
: [...entries, entry],
|
|
171
|
-
};
|
|
123
|
+
const entry = { toolCallId: event.id,
|
|
124
|
+
progressLabel: `${event.progressLabel || "正在处理你的请求"} · ${event.cancelled ? "已取消" : event.status === "running" ? "执行中" : event.status === "success" ? "已完成" : "失败"}` };
|
|
125
|
+
return { scope, entries: entries.some((item) => item.toolCallId === event.id)
|
|
126
|
+
? entries.map((item) => item.toolCallId === event.id ? entry : item) : [...entries, entry] };
|
|
172
127
|
});
|
|
173
128
|
};
|
|
174
129
|
const unsubscribe = toolRuntime.on("toolexecution", onExecution);
|
|
@@ -181,57 +136,25 @@ function OperationSurfaceContent({ toolRuntime, element, }) {
|
|
|
181
136
|
const waiting = cycle?.status === "waiting" && !executing;
|
|
182
137
|
const running = executing || (activated && cycle?.status !== "waiting");
|
|
183
138
|
const stopping = cycle?.status === "cancelling";
|
|
184
|
-
useLayoutEffect(() => {
|
|
185
|
-
|
|
186
|
-
setVisual(undefined);
|
|
187
|
-
}, [running, waiting]);
|
|
139
|
+
useLayoutEffect(() => { if (!running || waiting)
|
|
140
|
+
setVisual(undefined); }, [running, waiting]);
|
|
188
141
|
const serverExecuting = cycle?.taskProgress?.phase === "tool";
|
|
189
142
|
const visualExecuting = Boolean(visual && activity.executions.some((event) => event.id === visual.event.id));
|
|
190
|
-
const currentVisual = !stopping &&
|
|
191
|
-
!
|
|
192
|
-
visual &&
|
|
193
|
-
(!serverExecuting || (BROWSER_TOOL_NAMES.has(visual.event.name) && visualExecuting)) &&
|
|
194
|
-
canPresentInOperation(visual.event, cycle) &&
|
|
195
|
-
(cycle || visualExecuting)
|
|
196
|
-
? visual
|
|
197
|
-
: undefined;
|
|
143
|
+
const currentVisual = !stopping && !waiting && visual
|
|
144
|
+
&& (!serverExecuting || (BROWSER_TOOL_NAMES.has(visual.event.name) && visualExecuting))
|
|
145
|
+
&& canPresentInOperation(visual.event, cycle) && (cycle || visualExecuting) ? visual : undefined;
|
|
198
146
|
const browserExecution = activity.executions.find((event) => BROWSER_TOOL_NAMES.has(event.name));
|
|
199
|
-
const progressLabel = currentVisual?.feedback.label ??
|
|
200
|
-
|
|
201
|
-
? "
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
: cycle?.taskProgress
|
|
209
|
-
? "正在处理"
|
|
210
|
-
: "正在处理你的请求");
|
|
211
|
-
const operation = {
|
|
212
|
-
progressLabel,
|
|
213
|
-
status: currentVisual
|
|
214
|
-
? currentVisual.event.status === "running"
|
|
215
|
-
? "running"
|
|
216
|
-
: currentVisual.event.status === "success"
|
|
217
|
-
? "completed"
|
|
218
|
-
: "failed"
|
|
219
|
-
: running || waiting
|
|
220
|
-
? "running"
|
|
221
|
-
: outcome?.id === history.scope
|
|
222
|
-
? outcome.status
|
|
223
|
-
: "completed",
|
|
224
|
-
};
|
|
225
|
-
const feedback = currentVisual?.feedback ??
|
|
226
|
-
(serverExecuting && running && !waiting && !stopping
|
|
227
|
-
? {
|
|
228
|
-
id: cycle.taskProgress.toolCallId,
|
|
229
|
-
effect: "read",
|
|
230
|
-
label: progressLabel,
|
|
231
|
-
centered: true,
|
|
232
|
-
}
|
|
233
|
-
: undefined);
|
|
147
|
+
const progressLabel = currentVisual?.feedback.label ?? (waiting ? "等待你完成操作" : stopping ? "正在终止"
|
|
148
|
+
: browserExecution ? browserExecution.progressLabel || "正在浏览网页"
|
|
149
|
+
: cycle?.taskProgress?.phase === "tool" ? cycle.taskProgress.progressLabel || "正在执行工具"
|
|
150
|
+
: cycle?.taskProgress ? "正在处理" : "正在处理你的请求");
|
|
151
|
+
const operation = { progressLabel, status: currentVisual
|
|
152
|
+
? currentVisual.event.status === "running" ? "running" : currentVisual.event.status === "success" ? "completed" : "failed"
|
|
153
|
+
: running || waiting ? "running" : outcome?.id === history.scope ? outcome.status : "completed" };
|
|
154
|
+
const feedback = currentVisual?.feedback ?? (serverExecuting && running && !waiting && !stopping
|
|
155
|
+
? { id: cycle.taskProgress.toolCallId, effect: "read", label: progressLabel, centered: true } : undefined);
|
|
234
156
|
const resolveSurface = useCallback(() => element.current ?? undefined, [element]);
|
|
235
157
|
const entries = !cycle || history.scope === cycle.id ? history.entries : [];
|
|
236
|
-
return activated || executing || entries.length ?
|
|
158
|
+
return activated || executing || entries.length ? React.createElement(OperationOverlayView, { key: cycle?.id ?? history.scope, operation: operation, progressHistory: entries, running: running, humanHasControl: waiting, cancelling: stopping, ...(feedback ? { feedback } : {}), ...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {}), resolveSurface: resolveSurface }) : null;
|
|
237
159
|
}
|
|
160
|
+
//# sourceMappingURL=operation-surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-surface.js","sourceRoot":"","sources":["../src/operation-surface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAA0E,MAAM,OAAO,CAAC;AAC/I,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAoB,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI3D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAi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AAK,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,OAAO,SAAS,IAAI,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAC,oBAAoB,IAAC,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,OAAO,CAAC,KAAK,EACrG,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,KAC5G,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAC9B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC1F,cAAc,EAAE,cAAc,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC","sourcesContent":["import * as React from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { useCallback, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode, type RefObject, type SyntheticEvent } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim\";\nimport { PageCommandError } from \"./browser/locator.js\";\nimport type { AgentToolExecutionEvent } from \"./internal-types.js\";\nimport { getInternalToolRuntime, type ToolRuntime } from \"./runtime.js\";\nimport { isOperationSurfaceLocked } from \"./operation-lock.js\";\nimport { isAgentActivation } from \"./browser/focus.js\";\nimport { OperationOverlayView } from \"./operation-view.js\";\nimport type { AgentOperation, AgentOperationProgressEntry, OperationFeedback } from \"./operation-types.js\";\nimport type { OperationSnapshot } from \"./operation-runtime.js\";\n\nconst BROWSER_TOOL_NAMES = new Set([\"nxf_getSnapshot\", \"nxf_executeAction\", \"nxf_applyAction\"]);\n\nconst belongsToOperation = (event: AgentToolExecutionEvent, operation: OperationSnapshot | null) =>\n !operation || event.operationId === operation.id;\nconst canPresentInOperation = (event: AgentToolExecutionEvent, operation: OperationSnapshot | null) =>\n belongsToOperation(event, operation) && (!operation || operation.status === \"running\" || operation.status === \"ending\");\n\nexport interface AgentOperationSurfaceProps {\n toolRuntime: ToolRuntime;\n children: ReactNode;\n}\n\nconst surfaces = new WeakSet<ToolRuntime>();\n\nexport function AgentOperationSurface(props: AgentOperationSurfaceProps): ReactElement {\n const element = useRef<HTMLDivElement>(null);\n const initial = useRef(props.toolRuntime);\n if (initial.current !== props.toolRuntime) {\n throw new Error(\"AgentOperationSurface requires a stable Runtime. Remount it to change Runtime.\");\n }\n useLayoutEffect(() => {\n if (surfaces.has(props.toolRuntime)) throw new Error(\"Only one AgentOperationSurface is supported per Runtime.\");\n surfaces.add(props.toolRuntime);\n return () => { surfaces.delete(props.toolRuntime); };\n }, [props.toolRuntime]);\n const blockUserInput = useCallback((event: SyntheticEvent) => {\n if ((event.type === \"submit\" || event.type === \"reset\") && isAgentActivation()) return;\n if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted) return;\n event.preventDefault();\n event.stopPropagation();\n }, []);\n const blockPassiveUserInput = useCallback((event: SyntheticEvent) => {\n if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted) return;\n // Stop React's capture dispatch, but let the native event reach our non-passive\n // surface listener. React's passive root listener cannot prevent scrolling.\n event.isPropagationStopped = () => true;\n }, []);\n return <>\n <div ref={element} className=\"nexface-operation-surface\"\n onClickCapture={blockUserInput} onDoubleClickCapture={blockUserInput} onAuxClickCapture={blockUserInput}\n onPointerDownCapture={blockUserInput} onPointerUpCapture={blockUserInput}\n onPointerMoveCapture={blockUserInput} onPointerOverCapture={blockUserInput} onPointerOutCapture={blockUserInput}\n onMouseDownCapture={blockUserInput} onMouseUpCapture={blockUserInput} onContextMenuCapture={blockUserInput}\n onMouseMoveCapture={blockUserInput} onMouseOverCapture={blockUserInput} onMouseOutCapture={blockUserInput}\n onWheelCapture={blockPassiveUserInput} onTouchStartCapture={blockPassiveUserInput} onTouchMoveCapture={blockPassiveUserInput}\n onTouchEndCapture={blockUserInput} onTouchCancelCapture={blockUserInput}\n onKeyDownCapture={blockUserInput} onKeyUpCapture={blockUserInput} onKeyPressCapture={blockUserInput}\n onBeforeInputCapture={blockUserInput} onPasteCapture={blockUserInput} onCutCapture={blockUserInput}\n onDropCapture={blockUserInput} onDragStartCapture={blockUserInput}\n onSubmitCapture={blockUserInput} onResetCapture={blockUserInput}\n >{props.children}</div>\n <OperationSurfaceContent {...props} element={element} />\n </>;\n}\n\nfunction OperationSurfaceContent({ toolRuntime, element }: AgentOperationSurfaceProps & { element: RefObject<HTMLDivElement | null> }) {\n const runtime = getInternalToolRuntime(toolRuntime);\n const activity = useSyncExternalStore(runtime.subscribeActivity, runtime.getActivitySnapshot, runtime.getActivitySnapshot);\n const cycle = activity.operation;\n const [outcome, setOutcome] = useState<{ id: string; status: AgentOperation[\"status\"] }>();\n const [visual, setVisual] = useState<{ event: AgentToolExecutionEvent; feedback: OperationFeedback }>();\n const [history, setHistory] = useState<{ scope: string; entries: AgentOperationProgressEntry[] }>({ scope: \"\", entries: [] });\n const label = (event: AgentToolExecutionEvent) => event.progressLabel || (BROWSER_TOOL_NAMES.has(event.name) ? \"正在操作\" : \"正在处理你的请求\");\n useLayoutEffect(() => runtime.subscribeActivity(() => {\n const operation = runtime.getActivitySnapshot().operation;\n if (operation?.status === \"ending\" && operation.outcome) setOutcome({ id: operation.id, status: operation.outcome });\n }), [runtime]);\n useLayoutEffect(() => runtime.setPageActionFeedback((event, feedback, signal) => {\n const operation = runtime.getActivitySnapshot().operation;\n if (signal?.aborted || !canPresentInOperation(event, operation)) throw new PageCommandError({ code: \"EXECUTION_CANCELLED\", message: \"Page action presentation was interrupted.\" });\n const target = feedback.target;\n if (!feedback.effect || (feedback.effect === \"action\" && (!target?.isConnected || !element.current?.contains(target)))) {\n setVisual(undefined);\n return;\n }\n const next: OperationFeedback = {\n id: crypto.randomUUID(), effect: feedback.effect, label: label(event),\n centered: feedback.effect === \"read\", persistentCursor: true, requiresTarget: feedback.effect === \"action\",\n ...(target ? { target } : {}),\n };\n if (feedback.effect !== \"action\") { setVisual({ event, feedback: next }); return; }\n return new Promise<void>((resolve, reject) => {\n let finished = false;\n next.presentation = {\n ...(signal ? { signal } : {}),\n finish: (error) => {\n if (finished) return;\n finished = true;\n if (error) reject(error); else resolve();\n },\n };\n flushSync(() => setVisual({ event, feedback: next }));\n });\n }), [runtime, element]);\n useLayoutEffect(() => {\n const onExecution = (event: AgentToolExecutionEvent) => {\n const scope = event.operationId ?? event.id;\n const operation = runtime.getActivitySnapshot().operation;\n const canDisplay = !event.operationId || (operation !== null && canPresentInOperation(event, operation));\n const page = BROWSER_TOOL_NAMES.has(event.name);\n if (canDisplay && event.status === \"running\") {\n if (page) setVisual(event.name === \"nxf_getSnapshot\" ? { event, feedback: {\n id: event.id, effect: \"read\", label: label(event), centered: true,\n } } : undefined);\n else {\n const target = event.tool.definition.effect === \"navigate\" ? element.current : runtime.resolveTarget(event.tool, event.input);\n if (target?.isConnected && element.current?.contains(target)) {\n const rect = target.getBoundingClientRect();\n setVisual({ event, feedback: { id: event.id, effect: event.tool.definition.effect ?? \"action\", label: label(event),\n resolveTarget: () => event.tool.definition.effect === \"navigate\" ? element.current ?? undefined : runtime.resolveTarget(event.tool, event.input),\n position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 } } });\n }\n }\n } else if (canDisplay) setVisual((current) => current?.event.id === event.id && current.event.operationId === event.operationId\n ? page ? undefined : { ...current, event } : current);\n if (page && !operation && event.status === \"error\") setOutcome({ id: scope, status: event.cancelled ? \"cancelled\" : \"failed\" });\n setHistory((current) => {\n if (!belongsToOperation(event, operation) || (event.status !== \"running\" && current.scope !== scope)) return current;\n const entries = current.scope === scope ? current.entries : [];\n const entry = { toolCallId: event.id,\n progressLabel: `${event.progressLabel || \"正在处理你的请求\"} · ${event.cancelled ? \"已取消\" : event.status === \"running\" ? \"执行中\" : event.status === \"success\" ? \"已完成\" : \"失败\"}` };\n return { scope, entries: entries.some((item) => item.toolCallId === event.id)\n ? entries.map((item) => item.toolCallId === event.id ? entry : item) : [...entries, entry] };\n });\n };\n const unsubscribe = toolRuntime.on(\"toolexecution\", onExecution);\n for (const event of runtime.getActivitySnapshot().executions) onExecution(event);\n return unsubscribe;\n }, [runtime, toolRuntime, element]);\n const activated = Boolean(cycle && (cycle.source === \"webmcp\" || cycle.hasExecuted));\n const executing = activity.executions.length > 0;\n const waiting = cycle?.status === \"waiting\" && !executing;\n const running = executing || (activated && cycle?.status !== \"waiting\");\n const stopping = cycle?.status === \"cancelling\";\n useLayoutEffect(() => { if (!running || waiting) setVisual(undefined); }, [running, waiting]);\n const serverExecuting = cycle?.taskProgress?.phase === \"tool\";\n const visualExecuting = Boolean(visual && activity.executions.some((event) => event.id === visual.event.id));\n const currentVisual = !stopping && !waiting && visual\n && (!serverExecuting || (BROWSER_TOOL_NAMES.has(visual.event.name) && visualExecuting))\n && canPresentInOperation(visual.event, cycle) && (cycle || visualExecuting) ? visual : undefined;\n const browserExecution = activity.executions.find((event) => BROWSER_TOOL_NAMES.has(event.name));\n const progressLabel = currentVisual?.feedback.label ?? (waiting ? \"等待你完成操作\" : stopping ? \"正在终止\"\n : browserExecution ? browserExecution.progressLabel || \"正在浏览网页\"\n : cycle?.taskProgress?.phase === \"tool\" ? cycle.taskProgress.progressLabel || \"正在执行工具\"\n : cycle?.taskProgress ? \"正在处理\" : \"正在处理你的请求\");\n const operation: AgentOperation = { progressLabel, status: currentVisual\n ? currentVisual.event.status === \"running\" ? \"running\" : currentVisual.event.status === \"success\" ? \"completed\" : \"failed\"\n : running || waiting ? \"running\" : outcome?.id === history.scope ? outcome.status : \"completed\" };\n const feedback = currentVisual?.feedback ?? (serverExecuting && running && !waiting && !stopping\n ? { id: cycle.taskProgress.toolCallId, effect: \"read\" as const, label: progressLabel, centered: true } : undefined);\n const resolveSurface = useCallback(() => element.current ?? undefined, [element]);\n const entries = !cycle || history.scope === cycle.id ? history.entries : [];\n return activated || executing || entries.length ? <OperationOverlayView key={cycle?.id ?? history.scope}\n operation={operation} progressHistory={entries} running={running} humanHasControl={waiting} cancelling={stopping}\n {...(feedback ? { feedback } : {})}\n {...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {})}\n resolveSurface={resolveSurface} /> : null;\n}\n"]}
|
package/dist/operation-types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-types.js","sourceRoot":"","sources":["../src/operation-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentToolEffect } from \"./types.js\";\n\nexport interface AgentOperation {\n progressLabel: string;\n status: \"running\" | \"completed\" | \"failed\" | \"cancelled\";\n}\n\nexport interface AgentOperationProgressEntry {\n progressLabel: string;\n toolCallId: string;\n}\n\nexport interface OperationFeedback {\n id: string;\n effect: AgentToolEffect | \"processing\";\n label: string;\n target?: Element;\n resolveTarget?(): Element | undefined;\n position?: { left: number; top: number };\n centered?: boolean;\n persistentCursor?: boolean;\n requiresTarget?: boolean;\n presentation?: {\n signal?: AbortSignal;\n finish(error?: Error): void;\n };\n}\n"]}
|
package/dist/operation-view.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ export interface OperationOverlayViewProps {
|
|
|
10
10
|
onCancel?(): void;
|
|
11
11
|
resolveSurface?(): HTMLElement | undefined;
|
|
12
12
|
}
|
|
13
|
-
export declare function OperationOverlayView({ operation, feedback, progressHistory, running, humanHasControl, cancelling, onCancel: cancel, resolveSurface
|
|
13
|
+
export declare function OperationOverlayView({ operation, feedback, progressHistory, running, humanHasControl, cancelling, onCancel: cancel, resolveSurface }: OperationOverlayViewProps): React.ReactPortal | null;
|