@nexface/tools 0.1.5 → 0.1.7
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.d.ts +8 -0
- package/dist/browser/actions.js +73 -0
- package/dist/browser/actions.js.map +1 -0
- package/dist/browser/controller.d.ts +1 -1
- package/dist/browser/controller.js +49 -8
- package/dist/browser/controller.js.map +1 -1
- package/dist/browser/diagnostics.d.ts +1 -0
- package/dist/browser/diagnostics.js +20 -0
- package/dist/browser/diagnostics.js.map +1 -0
- package/dist/browser/dom.js +12 -4
- package/dist/browser/dom.js.map +1 -1
- package/dist/browser/focus.d.ts +2 -0
- package/dist/browser/focus.js +14 -0
- package/dist/browser/focus.js.map +1 -1
- package/dist/browser/prompt.d.ts +1 -1
- package/dist/browser/prompt.generated.d.ts +1 -1
- package/dist/browser/prompt.generated.js +10 -4
- package/dist/browser/prompt.generated.js.map +1 -1
- package/dist/browser/snapshot.d.ts +2 -2
- package/dist/browser/snapshot.js +11 -3
- package/dist/browser/snapshot.js.map +1 -1
- package/dist/browser/toolset.d.ts +4 -1
- package/dist/browser/toolset.js +164 -70
- package/dist/browser/toolset.js.map +1 -1
- package/dist/browser/types.d.ts +21 -2
- package/dist/browser/types.js.map +1 -1
- package/dist/definition.js +3 -5
- package/dist/definition.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/operation-lock.js +3 -1
- package/dist/operation-lock.js.map +1 -1
- package/dist/operation-runtime.d.ts +0 -1
- package/dist/operation-runtime.js +2 -5
- package/dist/operation-runtime.js.map +1 -1
- package/dist/operation-surface.js +53 -5
- package/dist/operation-surface.js.map +1 -1
- package/dist/operation-view.d.ts +2 -1
- package/dist/operation-view.js +54 -33
- package/dist/operation-view.js.map +1 -1
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +27 -6
- package/dist/runtime.js.map +1 -1
- package/dist/styles.css +3 -0
- package/package.json +1 -1
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const TOOL_ERROR_CODES: readonly ["ACTION_IN_FLIGHT", "ACTION_NOT_HANDLED", "ACTION_TARGET_UNAVAILABLE", "BROWSER_EXECUTION_FAILED", "BROWSER_SNAPSHOT_REQUIRED", "BROWSER_TOOLS_UNAVAILABLE", "CONTRACT_MISMATCH", "DUPLICATE_BINDING", "INVALID_INPUT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_REJECTED", "TOOL_ERROR", "TOOL_REGISTRATION_TIMEOUT", "TOOL_SKIPPED", "TOOL_UNAVAILABLE", "UNKNOWN_TOOL"];
|
|
1
|
+
export declare const TOOL_ERROR_CODES: readonly ["EXECUTION_OUTCOME_UNKNOWN", "ACTION_IN_FLIGHT", "ACTION_NOT_HANDLED", "ACTION_TARGET_UNAVAILABLE", "BROWSER_EXECUTION_FAILED", "BROWSER_SNAPSHOT_REQUIRED", "BROWSER_TOOLS_UNAVAILABLE", "CONTRACT_MISMATCH", "DUPLICATE_BINDING", "INVALID_INPUT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_REJECTED", "TOOL_ERROR", "TOOL_REGISTRATION_TIMEOUT", "TOOL_SKIPPED", "TOOL_UNAVAILABLE", "UNKNOWN_TOOL"];
|
|
2
2
|
type AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];
|
|
3
3
|
export declare class AgentToolError extends Error {
|
|
4
4
|
readonly code: AgentToolErrorCode;
|
package/dist/errors.js
CHANGED
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,kBAAkB;IAClB,oBAAoB;IACpB,2BAA2B;IAC3B,0BAA0B;IAC1B,2BAA2B;IAC3B,2BAA2B;IAC3B,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,+BAA+B;IAC/B,4BAA4B;IAC5B,YAAY;IACZ,2BAA2B;IAC3B,cAAc;IACd,kBAAkB;IAClB,cAAc;CACN,CAAC;AAIX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAK5B;IAEA;IANF,IAAI,GAAG,oBAA6B,CAAC;IACrC,MAAM,GAAG,MAAe,CAAC;IAElC,YACW,IAAwB,EACjC,OAAe,EACN,OAAiB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAoB;QAExB,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF","sourcesContent":["export const TOOL_ERROR_CODES = [\n \"ACTION_IN_FLIGHT\",\n \"ACTION_NOT_HANDLED\",\n \"ACTION_TARGET_UNAVAILABLE\",\n \"BROWSER_EXECUTION_FAILED\",\n \"BROWSER_SNAPSHOT_REQUIRED\",\n \"BROWSER_TOOLS_UNAVAILABLE\",\n \"CONTRACT_MISMATCH\",\n \"DUPLICATE_BINDING\",\n \"INVALID_INPUT\",\n \"INVALID_TOOL_RUNTIME\",\n \"OPERATION_BUSY\",\n \"TOOL_CANCELLED\",\n \"TOOL_CONFIRMATION_INVALIDATED\",\n \"TOOL_CONFIRMATION_REJECTED\",\n \"TOOL_ERROR\",\n \"TOOL_REGISTRATION_TIMEOUT\",\n \"TOOL_SKIPPED\",\n \"TOOL_UNAVAILABLE\",\n \"UNKNOWN_TOOL\",\n] as const;\n\ntype AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];\n\nexport class AgentToolError extends Error {\n readonly type = \"tool_runtime_error\" as const;\n readonly domain = \"tool\" as const;\n\n constructor(\n readonly code: AgentToolErrorCode,\n message: string,\n readonly details?: unknown,\n ) {\n super(message);\n this.name = \"ToolRuntimeError\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,2BAA2B;IAC3B,kBAAkB;IAClB,oBAAoB;IACpB,2BAA2B;IAC3B,0BAA0B;IAC1B,2BAA2B;IAC3B,2BAA2B;IAC3B,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,+BAA+B;IAC/B,4BAA4B;IAC5B,YAAY;IACZ,2BAA2B;IAC3B,cAAc;IACd,kBAAkB;IAClB,cAAc;CACN,CAAC;AAIX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAK5B;IAEA;IANF,IAAI,GAAG,oBAA6B,CAAC;IACrC,MAAM,GAAG,MAAe,CAAC;IAElC,YACW,IAAwB,EACjC,OAAe,EACN,OAAiB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAoB;QAExB,YAAO,GAAP,OAAO,CAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF","sourcesContent":["export const TOOL_ERROR_CODES = [\n \"EXECUTION_OUTCOME_UNKNOWN\",\n \"ACTION_IN_FLIGHT\",\n \"ACTION_NOT_HANDLED\",\n \"ACTION_TARGET_UNAVAILABLE\",\n \"BROWSER_EXECUTION_FAILED\",\n \"BROWSER_SNAPSHOT_REQUIRED\",\n \"BROWSER_TOOLS_UNAVAILABLE\",\n \"CONTRACT_MISMATCH\",\n \"DUPLICATE_BINDING\",\n \"INVALID_INPUT\",\n \"INVALID_TOOL_RUNTIME\",\n \"OPERATION_BUSY\",\n \"TOOL_CANCELLED\",\n \"TOOL_CONFIRMATION_INVALIDATED\",\n \"TOOL_CONFIRMATION_REJECTED\",\n \"TOOL_ERROR\",\n \"TOOL_REGISTRATION_TIMEOUT\",\n \"TOOL_SKIPPED\",\n \"TOOL_UNAVAILABLE\",\n \"UNKNOWN_TOOL\",\n] as const;\n\ntype AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];\n\nexport class AgentToolError extends Error {\n readonly type = \"tool_runtime_error\" as const;\n readonly domain = \"tool\" as const;\n\n constructor(\n readonly code: AgentToolErrorCode,\n message: string,\n readonly details?: unknown,\n ) {\n super(message);\n this.name = \"ToolRuntimeError\";\n }\n}\n"]}
|
package/dist/internal.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AgentContextError, ToolRuntimeImplementation, ToolRuntimeImplementation
|
|
|
2
2
|
export type { ToolRuntime as PublicToolRuntime, ToolRuntimeOptions, ToolOperation, InternalToolRuntime, } from "./runtime.js";
|
|
3
3
|
export type { AgentToolExecutionEvent } from "./internal-types.js";
|
|
4
4
|
export { defineSystemAgentTool } from "./definition.js";
|
|
5
|
-
export { browserToolsAvailable, createBrowserToolset, executeActionTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
|
|
5
|
+
export { browserToolsAvailable, createBrowserToolset, executeActionTool, applyActionTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
|
|
6
6
|
export { BROWSER_TOOLS_SKILL, serializeBrowserToolsSkill, } from "./browser/prompt.js";
|
|
7
7
|
export type { BrowserToolHandler, PageAutomationOptions, BrowserToolset, PageTransitionSettleResult, PageTransitionTracker, } from "./browser/toolset.js";
|
|
8
8
|
export type * from "./browser/types.js";
|
package/dist/internal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AgentContextError, ToolRuntimeImplementation, ToolRuntimeImplementation as ToolRuntime, AgentToolError, createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
|
|
2
2
|
export { defineSystemAgentTool } from "./definition.js";
|
|
3
|
-
export { browserToolsAvailable, createBrowserToolset, executeActionTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
|
|
3
|
+
export { browserToolsAvailable, createBrowserToolset, executeActionTool, applyActionTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
|
|
4
4
|
export { BROWSER_TOOLS_SKILL, serializeBrowserToolsSkill, } from "./browser/prompt.js";
|
|
5
5
|
export { assertAgentToolInputSchema, validateAgentToolInput } from "./schema.js";
|
|
6
6
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,IAAI,WAAW,EACxC,cAAc,EACd,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n AgentContextError,\n ToolRuntimeImplementation,\n ToolRuntimeImplementation as ToolRuntime,\n AgentToolError,\n createToolRuntime,\n getInternalToolRuntime,\n} from \"./runtime.js\";\nexport type {\n ToolRuntime as PublicToolRuntime,\n ToolRuntimeOptions,\n ToolOperation,\n InternalToolRuntime,\n} from \"./runtime.js\";\nexport type { AgentToolExecutionEvent } from \"./internal-types.js\";\nexport { defineSystemAgentTool } from \"./definition.js\";\nexport {\n browserToolsAvailable,\n createBrowserToolset,\n executeActionTool,\n getSnapshotTool,\n startPageTransitionTracker,\n} from \"./browser/toolset.js\";\nexport {\n BROWSER_TOOLS_SKILL,\n serializeBrowserToolsSkill,\n} from \"./browser/prompt.js\";\nexport type {\n BrowserToolHandler,\n PageAutomationOptions,\n BrowserToolset,\n PageTransitionSettleResult,\n PageTransitionTracker,\n} from \"./browser/toolset.js\";\nexport type * from \"./browser/types.js\";\nexport type { AgentContextRegistration } from \"./types.js\";\n\nexport { assertAgentToolInputSchema, validateAgentToolInput } from \"./schema.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,IAAI,WAAW,EACxC,cAAc,EACd,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n AgentContextError,\n ToolRuntimeImplementation,\n ToolRuntimeImplementation as ToolRuntime,\n AgentToolError,\n createToolRuntime,\n getInternalToolRuntime,\n} from \"./runtime.js\";\nexport type {\n ToolRuntime as PublicToolRuntime,\n ToolRuntimeOptions,\n ToolOperation,\n InternalToolRuntime,\n} from \"./runtime.js\";\nexport type { AgentToolExecutionEvent } from \"./internal-types.js\";\nexport { defineSystemAgentTool } from \"./definition.js\";\nexport {\n browserToolsAvailable,\n createBrowserToolset,\n executeActionTool,\n applyActionTool,\n getSnapshotTool,\n startPageTransitionTracker,\n} from \"./browser/toolset.js\";\nexport {\n BROWSER_TOOLS_SKILL,\n serializeBrowserToolsSkill,\n} from \"./browser/prompt.js\";\nexport type {\n BrowserToolHandler,\n PageAutomationOptions,\n BrowserToolset,\n PageTransitionSettleResult,\n PageTransitionTracker,\n} from \"./browser/toolset.js\";\nexport type * from \"./browser/types.js\";\nexport type { AgentContextRegistration } from \"./types.js\";\n\nexport { assertAgentToolInputSchema, validateAgentToolInput } from \"./schema.js\";\n"]}
|
package/dist/operation-lock.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAgentFocus } from "./browser/focus.js";
|
|
1
|
+
import { isAgentActivation, isAgentFocus } from "./browser/focus.js";
|
|
2
2
|
const lockedSurfaces = new WeakSet();
|
|
3
3
|
export function isOperationSurfaceLocked(surface) {
|
|
4
4
|
return lockedSurfaces.has(surface);
|
|
@@ -7,6 +7,8 @@ export function isOperationSurfaceLocked(surface) {
|
|
|
7
7
|
export function lockOperationSurface(surface, redirectFocus) {
|
|
8
8
|
const previousBusy = surface.getAttribute("aria-busy");
|
|
9
9
|
const block = (event) => {
|
|
10
|
+
if ((event.type === "submit" || event.type === "reset") && isAgentActivation())
|
|
11
|
+
return;
|
|
10
12
|
if (!event.isTrusted)
|
|
11
13
|
return;
|
|
12
14
|
if (event.type === "focus" || event.type === "focusin") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-lock.js","sourceRoot":"","sources":["../src/operation-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"operation-lock.js","sourceRoot":"","sources":["../src/operation-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,OAAO,EAAe,CAAC;AAElD,MAAM,UAAU,wBAAwB,CAAC,OAAoB;IAC3D,OAAO,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,8EA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AAU,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChb,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,MAAM;QAAE,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpG,OAAO,GAAG,EAAE;QACV,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,MAAM;YAAE,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1E,IAAI,YAAY,KAAK,IAAI;YAAE,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;;YAC3D,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { isAgentActivation, isAgentFocus } from \"./browser/focus.js\";\n\nconst lockedSurfaces = new WeakSet<HTMLElement>();\n\nexport function isOperationSurfaceLocked(surface: HTMLElement): boolean {\n return lockedSurfaces.has(surface);\n}\n\n/** Block user input inside the surface without hiding DOM from page tools. */\nexport function lockOperationSurface(surface: HTMLElement, redirectFocus?: () => void): () => void {\n const previousBusy = surface.getAttribute(\"aria-busy\");\n const block = (event: Event) => {\n if ((event.type === \"submit\" || event.type === \"reset\") && isAgentActivation()) return;\n if (!event.isTrusted) return;\n if (event.type === \"focus\" || event.type === \"focusin\") {\n if (isAgentFocus()) return;\n event.stopImmediatePropagation();\n if (event.target instanceof HTMLElement) event.target.blur();\n redirectFocus?.();\n return;\n }\n if (event.type === \"keydown\" && (event as KeyboardEvent).key === \"Tab\") {\n event.preventDefault();\n event.stopImmediatePropagation();\n redirectFocus?.();\n return;\n }\n event.preventDefault();\n event.stopImmediatePropagation();\n };\n // Wheel and touch defaults are blocked here: React delegates them passively.\n const events = [\"focus\", \"focusin\", \"mouseenter\", \"mouseleave\", \"pointerenter\", \"pointerleave\", \"pointerdown\", \"pointerup\", \"pointermove\", \"pointerover\", \"pointerout\", \"mousedown\", \"mouseup\", \"mousemove\", \"mouseover\", \"mouseout\", \"click\", \"dblclick\", \"auxclick\", \"contextmenu\", \"keydown\", \"keyup\", \"beforeinput\", \"paste\", \"cut\", \"drop\", \"dragstart\", \"touchstart\", \"touchmove\", \"touchend\", \"touchcancel\", \"wheel\", \"submit\", \"reset\"];\n lockedSurfaces.add(surface);\n surface.setAttribute(\"aria-busy\", \"true\");\n for (const name of events) surface.addEventListener(name, block, { capture: true, passive: false });\n return () => {\n lockedSurfaces.delete(surface);\n for (const name of events) surface.removeEventListener(name, block, true);\n if (previousBusy === null) surface.removeAttribute(\"aria-busy\");\n else surface.setAttribute(\"aria-busy\", previousBusy);\n };\n}\n"]}
|
|
@@ -13,7 +13,6 @@ export interface OperationSnapshot {
|
|
|
13
13
|
readonly source: "host" | "webmcp";
|
|
14
14
|
readonly status: "running" | "waiting" | "cancelling" | "ending";
|
|
15
15
|
readonly hasExecuted: boolean;
|
|
16
|
-
readonly hasStartedTool: boolean;
|
|
17
16
|
readonly outcome?: "completed" | "failed" | "cancelled";
|
|
18
17
|
readonly reason?: "bridge_disposed";
|
|
19
18
|
readonly canCancel: boolean;
|
|
@@ -26,7 +26,7 @@ export class OperationTracker {
|
|
|
26
26
|
const endPromise = new Promise((resolve) => { resolveEnd = resolve; });
|
|
27
27
|
const id = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
28
28
|
const operation = {
|
|
29
|
-
snapshot: Object.freeze({ id, source: options.source ?? "host", status: "running", hasExecuted: false,
|
|
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
30
|
handle: undefined, pending: 0, resolveEnd,
|
|
31
31
|
...(options.onCancel ? { onCancel: options.onCancel } : {}),
|
|
32
32
|
removeAbort: () => options.signal?.removeEventListener("abort", onAbort),
|
|
@@ -66,10 +66,7 @@ export class OperationTracker {
|
|
|
66
66
|
const operation = this.#operation;
|
|
67
67
|
if (operation?.handle !== handle || operation.snapshot.status === "ending")
|
|
68
68
|
return;
|
|
69
|
-
this.#update(operation, {
|
|
70
|
-
taskProgress: Object.freeze(progress),
|
|
71
|
-
hasStartedTool: operation.snapshot.hasStartedTool || progress.phase === "tool",
|
|
72
|
-
});
|
|
69
|
+
this.#update(operation, { taskProgress: Object.freeze(progress) });
|
|
73
70
|
}
|
|
74
71
|
disposeBridge(handle) {
|
|
75
72
|
const operation = this.#operation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-runtime.js","sourceRoot":"","sources":["../src/operation-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA+B7C,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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C;YACnF,CAAC;QACH,CAAC;;YAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,SAAoB;QAC1B,IAAI,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,KAAK,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 \"./errors.js\";\nimport type { ToolOperation } from \"./runtime.js\";\n\nexport type TaskProgress = { readonly phase: \"processing\" } | { readonly phase: \"tool\"; readonly toolCallId: string; readonly progressLabel?: string };\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 hasStartedTool: 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, hasStartedTool: options.taskProgress?.phase === \"tool\", 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 setWaitingForUser: (waiting: boolean) => {\n if (this.#operation !== operation || ![\"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 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 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, {\n taskProgress: Object.freeze(progress),\n hasStartedTool: operation.snapshot.hasStartedTool || progress.phase === \"tool\",\n });\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?.snapshot.status === \"ending\" ? undefined : this.#operation;\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
|
+
{"version":3,"file":"operation-runtime.js","sourceRoot":"","sources":["../src/operation-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA8B7C,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,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Q,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YACnF,CAAC;QACH,CAAC;;YAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,SAAoB;QAC1B,IAAI,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,KAAK,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 \"./errors.js\";\nimport type { ToolOperation } from \"./runtime.js\";\n\nexport type TaskProgress = { readonly phase: \"processing\" } | { readonly phase: \"tool\"; readonly toolCallId: string; readonly progressLabel?: string };\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 setWaitingForUser: (waiting: boolean) => {\n if (this.#operation !== operation || ![\"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 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 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?.snapshot.status === \"ending\" ? undefined : this.#operation;\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"]}
|
|
@@ -2,8 +2,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { getInternalToolRuntime } from "./runtime.js";
|
|
4
4
|
import { isOperationSurfaceLocked } from "./operation-lock.js";
|
|
5
|
+
import { isAgentActivation } from "./browser/focus.js";
|
|
5
6
|
import { OperationOverlayView } from "./operation-view.js";
|
|
6
|
-
const
|
|
7
|
+
const CENTER_BROWSER_TOOL_NAMES = new Set(["nxf_getSnapshot", "nxf_executeAction"]);
|
|
7
8
|
const surfaces = new WeakSet();
|
|
8
9
|
export function AgentOperationSurface(props) {
|
|
9
10
|
const element = useRef(null);
|
|
@@ -18,6 +19,8 @@ export function AgentOperationSurface(props) {
|
|
|
18
19
|
return () => { surfaces.delete(props.toolRuntime); };
|
|
19
20
|
}, [props.toolRuntime]);
|
|
20
21
|
const blockUserInput = useCallback((event) => {
|
|
22
|
+
if ((event.type === "submit" || event.type === "reset") && isAgentActivation())
|
|
23
|
+
return;
|
|
21
24
|
if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted)
|
|
22
25
|
return;
|
|
23
26
|
event.preventDefault();
|
|
@@ -49,6 +52,46 @@ function OperationSurfaceContent({ toolRuntime, element }) {
|
|
|
49
52
|
setOutcome({ id: current.id, status: current.outcome });
|
|
50
53
|
}), [runtime]);
|
|
51
54
|
const [visual, setVisual] = useState();
|
|
55
|
+
const pendingPresentation = useRef(undefined);
|
|
56
|
+
useLayoutEffect(() => {
|
|
57
|
+
const dispose = runtime.setPageActionPresentation((event, signal) => {
|
|
58
|
+
const target = runtime.resolveTarget(event.tool, event.input);
|
|
59
|
+
if (!target || !element.current?.contains(target))
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
let finished = false;
|
|
63
|
+
const settle = (error) => {
|
|
64
|
+
if (finished)
|
|
65
|
+
return;
|
|
66
|
+
finished = true;
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
signal?.removeEventListener("abort", finish);
|
|
69
|
+
if (pendingPresentation.current?.id === event.id)
|
|
70
|
+
pendingPresentation.current = undefined;
|
|
71
|
+
if (error)
|
|
72
|
+
reject(error);
|
|
73
|
+
else
|
|
74
|
+
resolve();
|
|
75
|
+
};
|
|
76
|
+
const finish = () => settle();
|
|
77
|
+
const timer = setTimeout(finish, 750);
|
|
78
|
+
pendingPresentation.current = {
|
|
79
|
+
id: event.id,
|
|
80
|
+
finish,
|
|
81
|
+
interrupt: () => settle(new Error("Page action presentation was interrupted.")),
|
|
82
|
+
};
|
|
83
|
+
if (signal?.aborted)
|
|
84
|
+
finish();
|
|
85
|
+
else
|
|
86
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
return () => { pendingPresentation.current?.interrupt(); dispose(); };
|
|
90
|
+
}, [runtime, element]);
|
|
91
|
+
const onPointerReady = useCallback((id) => {
|
|
92
|
+
if (pendingPresentation.current?.id === id)
|
|
93
|
+
pendingPresentation.current.finish();
|
|
94
|
+
}, []);
|
|
52
95
|
const [history, setHistory] = useState({ scope: "", entries: [] });
|
|
53
96
|
useLayoutEffect(() => {
|
|
54
97
|
const onExecution = (event) => {
|
|
@@ -63,9 +106,12 @@ function OperationSurfaceContent({ toolRuntime, element }) {
|
|
|
63
106
|
const rect = target.getBoundingClientRect();
|
|
64
107
|
setVisual({ event, target, position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 } });
|
|
65
108
|
}
|
|
66
|
-
else if (
|
|
109
|
+
else if (CENTER_BROWSER_TOOL_NAMES.has(event.name)) {
|
|
67
110
|
setVisual({ event });
|
|
68
111
|
}
|
|
112
|
+
else if (event.name === "nxf_applyAction") {
|
|
113
|
+
setVisual(undefined);
|
|
114
|
+
}
|
|
69
115
|
}
|
|
70
116
|
else if (canDisplay) {
|
|
71
117
|
setVisual((current) => current?.event.id === event.id && current.event.operationId === event.operationId
|
|
@@ -90,7 +136,7 @@ function OperationSurfaceContent({ toolRuntime, element }) {
|
|
|
90
136
|
onExecution(event);
|
|
91
137
|
return unsubscribe;
|
|
92
138
|
}, [runtime, toolRuntime, element]);
|
|
93
|
-
const activated = Boolean(cycle && (cycle.
|
|
139
|
+
const activated = Boolean(cycle && (cycle.source === "webmcp" || cycle.hasExecuted));
|
|
94
140
|
const executing = activity.executions.length > 0;
|
|
95
141
|
const waiting = cycle?.status === "waiting" && !executing;
|
|
96
142
|
const running = executing || (activated && cycle?.status !== "waiting");
|
|
@@ -99,7 +145,8 @@ function OperationSurfaceContent({ toolRuntime, element }) {
|
|
|
99
145
|
if (!running || waiting)
|
|
100
146
|
setVisual(undefined);
|
|
101
147
|
}, [running, waiting]);
|
|
102
|
-
const
|
|
148
|
+
const serverExecuting = cycle?.taskProgress?.phase === "tool";
|
|
149
|
+
const currentVisual = !serverExecuting && !stopping && !waiting && visual && (cycle
|
|
103
150
|
? cycle.status === "running" && visual.event.operationId === cycle.id
|
|
104
151
|
: activity.executions.some((event) => event.id === visual.event.id)) ? visual : undefined;
|
|
105
152
|
const resolveSurface = useCallback(() => element.current ?? undefined, [element]);
|
|
@@ -122,10 +169,11 @@ function OperationSurfaceContent({ toolRuntime, element }) {
|
|
|
122
169
|
} : {
|
|
123
170
|
toolCallId: cycle?.taskProgress?.phase === "tool" ? cycle.taskProgress.toolCallId : cycle?.id ?? history.scope,
|
|
124
171
|
name: "agent",
|
|
172
|
+
...(serverExecuting ? { effect: "read" } : {}),
|
|
125
173
|
progressLabel: waiting ? "等待你完成操作" : cycle?.status === "cancelling" ? "正在终止" : cycle?.taskProgress?.phase === "tool" ? cycle.taskProgress.progressLabel || "正在执行工具" : cycle?.taskProgress ? "正在处理" : "正在处理你的请求",
|
|
126
174
|
status: running || waiting ? "running" : outcome?.id === history.scope ? outcome.status : "completed",
|
|
127
175
|
};
|
|
128
176
|
const entries = !cycle || history.scope === cycle.id ? history.entries : [];
|
|
129
|
-
return activated || executing || entries.length ? _jsx(OperationOverlayView, { operation: operation, progressHistory: entries, running: running, feedbackActive: Boolean(currentVisual) && running && !waiting && !stopping, humanHasControl: waiting, ...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {}), cancelling: cycle?.status === "cancelling" || cycle?.status === "ending", ...(currentVisual?.position ? { fallbackPosition: currentVisual.position } : {}), resolveSurface: resolveSurface, resolveTarget: resolveTarget }) : null;
|
|
177
|
+
return activated || executing || entries.length ? _jsx(OperationOverlayView, { operation: operation, progressHistory: entries, running: running, feedbackActive: Boolean(currentVisual || serverExecuting) && running && !waiting && !stopping, humanHasControl: waiting, ...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {}), cancelling: cycle?.status === "cancelling" || cycle?.status === "ending", ...(currentVisual?.position ? { fallbackPosition: currentVisual.position } : {}), resolveSurface: resolveSurface, resolveTarget: resolveTarget, onPointerReady: onPointerReady }) : null;
|
|
130
178
|
}
|
|
131
179
|
//# sourceMappingURL=operation-surface.js.map
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,oBAAoB,EAAuD,MAAM,OAAO,CAAC;AAElJ,OAAO,EAAE,sBAAsB,EAAoB,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAO7E,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAe,CAAC;AAE5C,MAAM,UAAU,qBAAqB,CAAC,KAAiC;IACrE,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,CAAC;IACD,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QACjH,QAAQ,C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K,QAAQ,KACpE,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACjF,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa,GAC5B,CAAC,CAAC,CAAC,IAAI,CAAC;AACZ,CAAC","sourcesContent":["import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore, type ReactNode, type RefObject, type SyntheticEvent } from \"react\";\nimport type { AgentToolExecutionEvent } from \"./internal-types.js\";\nimport { getInternalToolRuntime, type ToolRuntime } from \"./runtime.js\";\nimport { isOperationSurfaceLocked } from \"./operation-lock.js\";\nimport { OperationOverlayView } from \"./operation-view.js\";\nimport type { AgentOperation, AgentOperationProgressEntry } from \"./operation-types.js\";\n\nconst BROWSER_TOOL_NAMES = new Set([\"nxf_getSnapshot\", \"nxf_executeAction\"]);\n\nexport interface AgentOperationSurfaceProps {\n toolRuntime: ToolRuntime;\n children: ReactNode;\n}\n\nconst surfaces = new WeakSet<ToolRuntime>();\n\nexport function AgentOperationSurface(props: AgentOperationSurfaceProps) {\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 (!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: \"completed\" | \"failed\" | \"cancelled\" }>();\n useLayoutEffect(() => runtime.subscribeActivity(() => {\n const current = runtime.getActivitySnapshot().operation;\n // Task progress does not replace page feedback. Only lifecycle boundaries clear it.\n setVisual((visual) => {\n if (current) return current.status === \"running\" && visual?.event.operationId === current.id ? visual : undefined;\n return visual && runtime.getActivitySnapshot().executions.some((event) => event.id === visual.event.id) ? visual : undefined;\n });\n if (current?.status === \"ending\" && current.outcome) setOutcome({ id: current.id, status: current.outcome });\n }), [runtime]);\n const [visual, setVisual] = useState<{ event: AgentToolExecutionEvent; target?: HTMLElement; position?: { left: number; top: number } }>();\n const [history, setHistory] = useState<{ scope: string; entries: AgentOperationProgressEntry[] }>({ scope: \"\", entries: [] });\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?.id === event.operationId && operation.status === \"running\");\n if (canDisplay && event.status === \"running\") {\n const target = event.tool.definition.effect === \"navigate\"\n ? element.current\n : runtime.resolveTarget(event.tool, event.input);\n if (target?.isConnected && element.current?.contains(target)) {\n const rect = target.getBoundingClientRect();\n setVisual({ event, target, position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 } });\n } else if (BROWSER_TOOL_NAMES.has(event.name)) {\n setVisual({ event });\n }\n } else if (canDisplay) {\n setVisual((current) => current?.event.id === event.id && current.event.operationId === event.operationId\n ? { ...current, event: { ...current.event, ...event } }\n : current);\n }\n setHistory((current) => {\n if ((operation && event.operationId !== operation.id) || (event.status !== \"running\" && current.scope !== scope)) return current;\n const entries = current.scope === scope ? current.entries : [];\n const entry = {\n toolCallId: event.id,\n progressLabel: `${event.progressLabel || \"正在处理你的请求\"} · ${event.cancelled ? \"已取消\" : event.status === \"running\" ? \"执行中\" : event.status === \"success\" ? \"已完成\" : \"失败\"}`,\n };\n return { scope, entries: entries.some((item) => item.toolCallId === event.id)\n ? entries.map((item) => item.toolCallId === event.id ? entry : item)\n : [...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.hasStartedTool || 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\" || cycle?.status === \"ending\";\n useLayoutEffect(() => {\n if (!running || waiting) setVisual(undefined);\n }, [running, waiting]);\n const currentVisual = !stopping && !waiting && visual && (cycle\n ? cycle.status === \"running\" && visual.event.operationId === cycle.id\n : activity.executions.some((event) => event.id === visual.event.id)) ? visual : undefined;\n const resolveSurface = useCallback(() => element.current ?? undefined, [element]);\n const resolveTarget = useCallback(() => {\n if (!currentVisual) return undefined;\n const target = currentVisual.target;\n if (target?.isConnected && element.current?.contains(target)\n && (currentVisual.event.tool.definition.effect === \"navigate\" || toolRuntime.getTools().includes(currentVisual.event.tool))) return { element: target };\n return undefined;\n }, [currentVisual, element, toolRuntime]);\n const operation: AgentOperation = currentVisual ? {\n toolCallId: currentVisual.event.id,\n name: currentVisual.event.name,\n input: currentVisual.event.input,\n effect: currentVisual.event.tool.definition.effect,\n progressLabel: currentVisual.event.progressLabel || \"正在处理你的请求\",\n status: currentVisual.event.status === \"running\" ? \"running\" : currentVisual.event.status === \"success\" ? \"completed\" : \"failed\",\n } : {\n toolCallId: cycle?.taskProgress?.phase === \"tool\" ? cycle.taskProgress.toolCallId : cycle?.id ?? history.scope,\n name: \"agent\",\n progressLabel: waiting ? \"等待你完成操作\" : cycle?.status === \"cancelling\" ? \"正在终止\" : cycle?.taskProgress?.phase === \"tool\" ? cycle.taskProgress.progressLabel || \"正在执行工具\" : cycle?.taskProgress ? \"正在处理\" : \"正在处理你的请求\",\n status: running || waiting ? \"running\" : outcome?.id === history.scope ? outcome.status : \"completed\",\n };\n const entries = !cycle || history.scope === cycle.id ? history.entries : [];\n return activated || executing || entries.length ? <OperationOverlayView\n operation={operation}\n progressHistory={entries}\n running={running}\n feedbackActive={Boolean(currentVisual) && running && !waiting && !stopping}\n humanHasControl={waiting}\n {...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {})}\n cancelling={cycle?.status === \"cancelling\" || cycle?.status === \"ending\"}\n {...(currentVisual?.position ? { fallbackPosition: currentVisual.position } : {})}\n resolveSurface={resolveSurface}\n resolveTarget={resolveTarget}\n /> : null;\n}\n"]}
|
|
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,EAAE,oBAAoB,EAAuD,MAAM,OAAO,CAAC;AAElJ,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;AAG3D,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAOpF,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAe,CAAC;AAE5C,MAAM,UAAU,qBAAqB,CAAC,KAAiC;IACrE,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IACpG,CAAC;IACD,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QACjH,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAChC,OAAO,GAAG,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CA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, type RefObject, type SyntheticEvent } from \"react\";\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 } from \"./operation-types.js\";\n\nconst CENTER_BROWSER_TOOL_NAMES = new Set([\"nxf_getSnapshot\", \"nxf_executeAction\"]);\n\nexport interface AgentOperationSurfaceProps {\n toolRuntime: ToolRuntime;\n children: ReactNode;\n}\n\nconst surfaces = new WeakSet<ToolRuntime>();\n\nexport function AgentOperationSurface(props: AgentOperationSurfaceProps) {\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: \"completed\" | \"failed\" | \"cancelled\" }>();\n useLayoutEffect(() => runtime.subscribeActivity(() => {\n const current = runtime.getActivitySnapshot().operation;\n // Task progress does not replace page feedback. Only lifecycle boundaries clear it.\n setVisual((visual) => {\n if (current) return current.status === \"running\" && visual?.event.operationId === current.id ? visual : undefined;\n return visual && runtime.getActivitySnapshot().executions.some((event) => event.id === visual.event.id) ? visual : undefined;\n });\n if (current?.status === \"ending\" && current.outcome) setOutcome({ id: current.id, status: current.outcome });\n }), [runtime]);\n const [visual, setVisual] = useState<{ event: AgentToolExecutionEvent; target?: HTMLElement; position?: { left: number; top: number } }>();\n const pendingPresentation = useRef<{ id: string; finish(): void; interrupt(): void } | undefined>(undefined);\n useLayoutEffect(() => {\n const dispose = runtime.setPageActionPresentation((event, signal) => {\n const target = runtime.resolveTarget(event.tool, event.input);\n if (!target || !element.current?.contains(target)) return Promise.resolve();\n return new Promise<void>((resolve, reject) => {\n let finished = false;\n const settle = (error?: Error) => {\n if (finished) return;\n finished = true;\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", finish);\n if (pendingPresentation.current?.id === event.id) pendingPresentation.current = undefined;\n if (error) reject(error);\n else resolve();\n };\n const finish = () => settle();\n const timer = setTimeout(finish, 750);\n pendingPresentation.current = {\n id: event.id,\n finish,\n interrupt: () => settle(new Error(\"Page action presentation was interrupted.\")),\n };\n if (signal?.aborted) finish();\n else signal?.addEventListener(\"abort\", finish, { once: true });\n });\n });\n return () => { pendingPresentation.current?.interrupt(); dispose(); };\n }, [runtime, element]);\n const onPointerReady = useCallback((id: string) => {\n if (pendingPresentation.current?.id === id) pendingPresentation.current.finish();\n }, []);\n const [history, setHistory] = useState<{ scope: string; entries: AgentOperationProgressEntry[] }>({ scope: \"\", entries: [] });\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?.id === event.operationId && operation.status === \"running\");\n if (canDisplay && event.status === \"running\") {\n const target = event.tool.definition.effect === \"navigate\"\n ? element.current\n : runtime.resolveTarget(event.tool, event.input);\n if (target?.isConnected && element.current?.contains(target)) {\n const rect = target.getBoundingClientRect();\n setVisual({ event, target, position: { left: rect.left + rect.width / 2, top: rect.top + rect.height / 2 } });\n } else if (CENTER_BROWSER_TOOL_NAMES.has(event.name)) {\n setVisual({ event });\n } else if (event.name === \"nxf_applyAction\") {\n setVisual(undefined);\n }\n } else if (canDisplay) {\n setVisual((current) => current?.event.id === event.id && current.event.operationId === event.operationId\n ? { ...current, event: { ...current.event, ...event } }\n : current);\n }\n setHistory((current) => {\n if ((operation && event.operationId !== operation.id) || (event.status !== \"running\" && current.scope !== scope)) return current;\n const entries = current.scope === scope ? current.entries : [];\n const entry = {\n toolCallId: event.id,\n progressLabel: `${event.progressLabel || \"正在处理你的请求\"} · ${event.cancelled ? \"已取消\" : event.status === \"running\" ? \"执行中\" : event.status === \"success\" ? \"已完成\" : \"失败\"}`,\n };\n return { scope, entries: entries.some((item) => item.toolCallId === event.id)\n ? entries.map((item) => item.toolCallId === event.id ? entry : item)\n : [...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\" || cycle?.status === \"ending\";\n useLayoutEffect(() => {\n if (!running || waiting) setVisual(undefined);\n }, [running, waiting]);\n const serverExecuting = cycle?.taskProgress?.phase === \"tool\";\n const currentVisual = !serverExecuting && !stopping && !waiting && visual && (cycle\n ? cycle.status === \"running\" && visual.event.operationId === cycle.id\n : activity.executions.some((event) => event.id === visual.event.id)) ? visual : undefined;\n const resolveSurface = useCallback(() => element.current ?? undefined, [element]);\n const resolveTarget = useCallback(() => {\n if (!currentVisual) return undefined;\n const target = currentVisual.target;\n if (target?.isConnected && element.current?.contains(target)\n && (currentVisual.event.tool.definition.effect === \"navigate\" || toolRuntime.getTools().includes(currentVisual.event.tool))) return { element: target };\n return undefined;\n }, [currentVisual, element, toolRuntime]);\n const operation: AgentOperation = currentVisual ? {\n toolCallId: currentVisual.event.id,\n name: currentVisual.event.name,\n input: currentVisual.event.input,\n effect: currentVisual.event.tool.definition.effect,\n progressLabel: currentVisual.event.progressLabel || \"正在处理你的请求\",\n status: currentVisual.event.status === \"running\" ? \"running\" : currentVisual.event.status === \"success\" ? \"completed\" : \"failed\",\n } : {\n toolCallId: cycle?.taskProgress?.phase === \"tool\" ? cycle.taskProgress.toolCallId : cycle?.id ?? history.scope,\n name: \"agent\",\n ...(serverExecuting ? { effect: \"read\" as const } : {}),\n progressLabel: waiting ? \"等待你完成操作\" : cycle?.status === \"cancelling\" ? \"正在终止\" : cycle?.taskProgress?.phase === \"tool\" ? cycle.taskProgress.progressLabel || \"正在执行工具\" : cycle?.taskProgress ? \"正在处理\" : \"正在处理你的请求\",\n status: running || waiting ? \"running\" : outcome?.id === history.scope ? outcome.status : \"completed\",\n };\n const entries = !cycle || history.scope === cycle.id ? history.entries : [];\n return activated || executing || entries.length ? <OperationOverlayView\n operation={operation}\n progressHistory={entries}\n running={running}\n feedbackActive={Boolean(currentVisual || serverExecuting) && running && !waiting && !stopping}\n humanHasControl={waiting}\n {...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {})}\n cancelling={cycle?.status === \"cancelling\" || cycle?.status === \"ending\"}\n {...(currentVisual?.position ? { fallbackPosition: currentVisual.position } : {})}\n resolveSurface={resolveSurface}\n resolveTarget={resolveTarget}\n onPointerReady={onPointerReady}\n /> : null;\n}\n"]}
|
package/dist/operation-view.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface OperationOverlayViewProps {
|
|
|
15
15
|
onCancel?(): void;
|
|
16
16
|
resolveSurface?(): HTMLElement | undefined;
|
|
17
17
|
resolveTarget?(operation: AgentOperation): AgentOperationTarget | undefined;
|
|
18
|
+
onPointerReady?(toolCallId: string): void;
|
|
18
19
|
}
|
|
19
|
-
export declare function OperationOverlayView({ operation, progressHistory, running, feedbackActive, labelActive, humanHasControl, cancelling, onCancel, resolveSurface, resolveTarget, fallbackPosition }: OperationOverlayViewProps): import("react").ReactPortal | null;
|
|
20
|
+
export declare function OperationOverlayView({ operation, progressHistory, running, feedbackActive, labelActive, humanHasControl, cancelling, onCancel, resolveSurface, resolveTarget, fallbackPosition, onPointerReady }: OperationOverlayViewProps): import("react").ReactPortal | null;
|
|
20
21
|
export {};
|