@nexface/tools 0.1.1-alpha.4 → 0.1.1-alpha.5
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/definition.js +2 -0
- package/dist/definition.js.map +1 -1
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +34 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +3 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal-react.d.ts +0 -1
- package/dist/internal-react.js +0 -1
- package/dist/internal-react.js.map +1 -1
- package/dist/internal-types.d.ts +1 -0
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/operation-lock.d.ts +3 -0
- package/dist/operation-lock.js +46 -0
- package/dist/operation-lock.js.map +1 -0
- package/dist/operation-runtime.d.ts +33 -0
- package/dist/operation-runtime.js +144 -0
- package/dist/operation-runtime.js.map +1 -0
- package/dist/operation-surface.d.ts +1 -1
- package/dist/operation-surface.js +78 -53
- package/dist/operation-surface.js.map +1 -1
- package/dist/operation-view.d.ts +2 -2
- package/dist/operation-view.js +14 -48
- package/dist/operation-view.js.map +1 -1
- package/dist/runtime.d.ts +40 -10
- package/dist/runtime.js +58 -57
- package/dist/runtime.js.map +1 -1
- package/dist/webmcp.js +119 -6
- package/dist/webmcp.js.map +1 -1
- package/package.json +4 -11
- package/dist/operation-host.d.ts +0 -17
- package/dist/operation-host.js +0 -9
- package/dist/operation-host.js.map +0 -1
- package/dist/react-entry.d.ts +0 -2
- package/dist/react-entry.js +0 -3
- package/dist/react-entry.js.map +0 -1
package/dist/definition.js
CHANGED
|
@@ -13,6 +13,8 @@ const reservedContextNames = new Set([
|
|
|
13
13
|
const reservedToolNames = new Set([
|
|
14
14
|
...reservedContextNames,
|
|
15
15
|
"loadSkill",
|
|
16
|
+
"beginOperation",
|
|
17
|
+
"endOperation",
|
|
16
18
|
]);
|
|
17
19
|
export function isValidAgentContextName(name) {
|
|
18
20
|
return agentNamePattern.test(name) && !reservedContextNames.has(name);
|
package/dist/definition.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAMA,MAAM,gBAAgB,GAAyB,MAAM,CAAC,MAAM,CAAC;IAC3D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7B,oBAAoB,EAAE,KAAK;CAC5B,CAAC,CAAC;AAQH,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAEjD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,aAAa;IACb,QAAQ;IACR,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,oBAAoB;IACvB,WAAW;
|
|
1
|
+
{"version":3,"file":"definition.js","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAMA,MAAM,gBAAgB,GAAyB,MAAM,CAAC,MAAM,CAAC;IAC3D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7B,oBAAoB,EAAE,KAAK;CAC5B,CAAC,CAAC;AAQH,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAEjD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,aAAa;IACb,QAAQ;IACR,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,oBAAoB;IACvB,WAAW;IACX,gBAAgB;IAChB,cAAc;CACf,CAAC,CAAC;AAEH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,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AW;QACnC,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC;QACnD,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC,CAAC;AACL,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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"];
|
|
2
|
+
type AgentToolErrorCode = typeof TOOL_ERROR_CODES[number];
|
|
3
|
+
export declare class AgentToolError extends Error {
|
|
4
|
+
readonly code: AgentToolErrorCode;
|
|
5
|
+
readonly details?: unknown | undefined;
|
|
6
|
+
readonly type: "tool_runtime_error";
|
|
7
|
+
readonly domain: "tool";
|
|
8
|
+
constructor(code: AgentToolErrorCode, message: string, details?: unknown | undefined);
|
|
9
|
+
}
|
|
10
|
+
export {};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const TOOL_ERROR_CODES = [
|
|
2
|
+
"ACTION_IN_FLIGHT",
|
|
3
|
+
"ACTION_NOT_HANDLED",
|
|
4
|
+
"ACTION_TARGET_UNAVAILABLE",
|
|
5
|
+
"BROWSER_EXECUTION_FAILED",
|
|
6
|
+
"BROWSER_SNAPSHOT_REQUIRED",
|
|
7
|
+
"BROWSER_TOOLS_UNAVAILABLE",
|
|
8
|
+
"CONTRACT_MISMATCH",
|
|
9
|
+
"DUPLICATE_BINDING",
|
|
10
|
+
"INVALID_INPUT",
|
|
11
|
+
"INVALID_TOOL_RUNTIME",
|
|
12
|
+
"OPERATION_BUSY",
|
|
13
|
+
"TOOL_CANCELLED",
|
|
14
|
+
"TOOL_CONFIRMATION_INVALIDATED",
|
|
15
|
+
"TOOL_CONFIRMATION_REJECTED",
|
|
16
|
+
"TOOL_ERROR",
|
|
17
|
+
"TOOL_REGISTRATION_TIMEOUT",
|
|
18
|
+
"TOOL_SKIPPED",
|
|
19
|
+
"TOOL_UNAVAILABLE",
|
|
20
|
+
"UNKNOWN_TOOL",
|
|
21
|
+
];
|
|
22
|
+
export class AgentToolError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
details;
|
|
25
|
+
type = "tool_runtime_error";
|
|
26
|
+
domain = "tool";
|
|
27
|
+
constructor(code, message, details) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.details = details;
|
|
31
|
+
this.name = "ToolRuntimeError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,cAAc,YAAY,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { defineAgentTool } from "./definition.js";
|
|
2
2
|
export { defineAgentNavigation } from "./navigation.js";
|
|
3
|
+
export { AgentOperationSurface, type AgentOperationSurfaceProps } from "./operation-surface.js";
|
|
3
4
|
export { createToolRuntime, isToolRuntimeError, } from "./runtime.js";
|
|
4
5
|
export { AgentContext, ToolsProvider, AgentUIAction, useAgentContext, useAgentNavigation, useAgentTool, } from "./react.js";
|
|
5
6
|
export type { AgentNavigation, AgentNavigationConfig, AgentNavigationExecutors, AgentNavigationRouteConfig, } from "./navigation.js";
|
|
6
7
|
export type { AgentToolBinding, AgentToolChatConfirmationConfig, AgentToolPageConfirmationConfig, AgentUIActionChildProps, AgentUIActionEvent, AgentUIActionProps, UseAgentToolDefaultOptions, UseAgentToolPageConfirmationOptions, } from "./react.js";
|
|
7
|
-
export type { AgentToolConfirmationConfig, RuntimeAgentTool, ToolRuntime, ToolRuntimeOptions, ToolRuntimeToolChangeEvent, } from "./runtime.js";
|
|
8
|
+
export type { AgentToolConfirmationConfig, RuntimeAgentTool, ToolRuntime, ToolOperation, ToolRuntimeOptions, ToolRuntimeToolChangeEvent, } from "./runtime.js";
|
|
8
9
|
export type { AgentContextEntry, AgentContextValue, AgentToolDefinition, AgentToolEffect, AgentToolExecutionContext, AgentToolExecutor, AgentToolInputSchema, InferJsonSchema, JsonSchema, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { defineAgentTool } from "./definition.js";
|
|
2
2
|
export { defineAgentNavigation } from "./navigation.js";
|
|
3
|
+
export { AgentOperationSurface } from "./operation-surface.js";
|
|
3
4
|
export { createToolRuntime, isToolRuntimeError, } from "./runtime.js";
|
|
4
5
|
export { AgentContext, ToolsProvider, AgentUIAction, useAgentContext, useAgentNavigation, useAgentTool, } from "./react.js";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAmC,MAAM,wBAAwB,CAAC;AAChG,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,YAAY,CAAC"}
|
package/dist/internal-react.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
export { OperationHostContext } from "./operation-host.js";
|
|
3
2
|
export type { PageConfirmableAgentToolBinding } from "./react.js";
|
|
4
3
|
import { type ToolRuntime, type InternalToolRuntime } from "./runtime.js";
|
|
5
4
|
export interface InternalToolRuntimeHostProps {
|
package/dist/internal-react.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useMemo, } from "react";
|
|
3
|
-
export { OperationHostContext } from "./operation-host.js";
|
|
4
3
|
import { createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
|
|
5
4
|
const InternalToolRuntimeContext = createContext(null);
|
|
6
5
|
export function InternalToolRuntimeHost({ children, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-react.js","sourceRoot":"","sources":["../src/internal-react.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,GAER,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"internal-react.js","sourceRoot":"","sources":["../src/internal-react.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,GAER,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GAGvB,MAAM,cAAc,CAAC;AAEtB,MAAM,0BAA0B,GAC9B,aAAa,CAA6B,IAAI,CAAC,CAAC;AAMlD,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,GACqB;IAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,CACL,KAAC,wBAAwB,IAAC,OAAO,EAAE,OAAO,YACvC,QAAQ,GACgB,CAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,eAAe,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACxD,OAAO,CACL,KAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,YACxD,QAAQ,GAC2B,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,8BAA8B;IAG5C,OAAO,UAAU,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/internal-types.d.ts
CHANGED
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentContextError, ToolRuntimeImplementation, ToolRuntimeImplementation as ToolRuntime, AgentToolError, createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
|
|
2
|
-
export type { ToolRuntime as PublicToolRuntime, ToolRuntimeOptions, InternalToolRuntime, } from "./runtime.js";
|
|
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
5
|
export { browserToolsAvailable, createBrowserToolset, executeCodeTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
|
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;
|
|
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,eAAe,EACf,eAAe,EACf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isAgentFocus } from "./browser/focus.js";
|
|
2
|
+
const lockedSurfaces = new WeakSet();
|
|
3
|
+
export function isOperationSurfaceLocked(surface) {
|
|
4
|
+
return lockedSurfaces.has(surface);
|
|
5
|
+
}
|
|
6
|
+
/** Block user input inside the surface without hiding DOM from page tools. */
|
|
7
|
+
export function lockOperationSurface(surface, redirectFocus) {
|
|
8
|
+
const previousBusy = surface.getAttribute("aria-busy");
|
|
9
|
+
const block = (event) => {
|
|
10
|
+
if (!event.isTrusted)
|
|
11
|
+
return;
|
|
12
|
+
if (event.type === "focus" || event.type === "focusin") {
|
|
13
|
+
if (isAgentFocus())
|
|
14
|
+
return;
|
|
15
|
+
event.stopImmediatePropagation();
|
|
16
|
+
if (event.target instanceof HTMLElement)
|
|
17
|
+
event.target.blur();
|
|
18
|
+
redirectFocus?.();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (event.type === "keydown" && event.key === "Tab") {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
event.stopImmediatePropagation();
|
|
24
|
+
redirectFocus?.();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
event.stopImmediatePropagation();
|
|
29
|
+
};
|
|
30
|
+
// Wheel and touch defaults are blocked here: React delegates them passively.
|
|
31
|
+
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"];
|
|
32
|
+
lockedSurfaces.add(surface);
|
|
33
|
+
surface.setAttribute("aria-busy", "true");
|
|
34
|
+
for (const name of events)
|
|
35
|
+
surface.addEventListener(name, block, { capture: true, passive: false });
|
|
36
|
+
return () => {
|
|
37
|
+
lockedSurfaces.delete(surface);
|
|
38
|
+
for (const name of events)
|
|
39
|
+
surface.removeEventListener(name, block, true);
|
|
40
|
+
if (previousBusy === null)
|
|
41
|
+
surface.removeAttribute("aria-busy");
|
|
42
|
+
else
|
|
43
|
+
surface.setAttribute("aria-busy", previousBusy);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=operation-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-lock.js","sourceRoot":"","sources":["../src/operation-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,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,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAAC,OAAoB,EAAE,aAA0B;IACnF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACvD,MAAM,KAAK,GAAG,CAAC,KAAY,EAAE,EAAE;QAC7B,IAAI,CAAC,KAAK,CAAC,SAAS;YAAE,OAAO;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;Y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AAE,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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentToolExecutionEvent } from "./internal-types.js";
|
|
2
|
+
import type { ToolOperation } from "./runtime.js";
|
|
3
|
+
export interface OperationSnapshot {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly source: "host" | "webmcp";
|
|
6
|
+
readonly status: "running" | "waiting" | "cancelling" | "ending";
|
|
7
|
+
readonly hasExecuted: boolean;
|
|
8
|
+
readonly outcome?: "completed" | "failed" | "cancelled";
|
|
9
|
+
readonly reason?: "bridge_disposed";
|
|
10
|
+
readonly canCancel: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface RuntimeActivitySnapshot {
|
|
13
|
+
readonly operation: OperationSnapshot | null;
|
|
14
|
+
readonly executions: readonly AgentToolExecutionEvent[];
|
|
15
|
+
}
|
|
16
|
+
export declare class OperationTracker {
|
|
17
|
+
#private;
|
|
18
|
+
getSnapshot: () => RuntimeActivitySnapshot;
|
|
19
|
+
subscribe: (listener: () => void) => (() => void);
|
|
20
|
+
begin(options?: {
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
onCancel?: () => void;
|
|
23
|
+
source?: "host" | "webmcp";
|
|
24
|
+
replaceWaiting?: ToolOperation;
|
|
25
|
+
}): ToolOperation;
|
|
26
|
+
disposeBridge(handle: ToolOperation): Promise<void>;
|
|
27
|
+
requestCancel(id: string): void;
|
|
28
|
+
admit(): {
|
|
29
|
+
operationId?: string;
|
|
30
|
+
release(): void;
|
|
31
|
+
};
|
|
32
|
+
observe(event: AgentToolExecutionEvent): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { AgentToolError } from "./errors.js";
|
|
2
|
+
export class OperationTracker {
|
|
3
|
+
#operation;
|
|
4
|
+
#unscoped = 0;
|
|
5
|
+
#executions = new Map();
|
|
6
|
+
#listeners = new Set();
|
|
7
|
+
#snapshot = Object.freeze({ operation: null, executions: Object.freeze([]) });
|
|
8
|
+
getSnapshot = () => this.#snapshot;
|
|
9
|
+
subscribe = (listener) => {
|
|
10
|
+
this.#listeners.add(listener);
|
|
11
|
+
return () => { this.#listeners.delete(listener); };
|
|
12
|
+
};
|
|
13
|
+
begin(options = {}) {
|
|
14
|
+
options.signal?.throwIfAborted();
|
|
15
|
+
const previous = this.#operation;
|
|
16
|
+
const replacing = previous && previous.handle === options.replaceWaiting
|
|
17
|
+
&& previous.snapshot.status === "waiting" && previous.pending === 0;
|
|
18
|
+
if (this.#unscoped || (previous && !replacing)) {
|
|
19
|
+
throw new AgentToolError("OPERATION_BUSY", "The Runtime already has an operation or outstanding tool calls.");
|
|
20
|
+
}
|
|
21
|
+
if (replacing) {
|
|
22
|
+
previous.removeAbort();
|
|
23
|
+
previous.resolveEnd();
|
|
24
|
+
}
|
|
25
|
+
let resolveEnd;
|
|
26
|
+
const endPromise = new Promise((resolve) => { resolveEnd = resolve; });
|
|
27
|
+
const id = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
|
|
28
|
+
const operation = {
|
|
29
|
+
snapshot: Object.freeze({ id, source: options.source ?? "host", status: "running", hasExecuted: false, canCancel: Boolean(options.onCancel) }),
|
|
30
|
+
handle: undefined, pending: 0, resolveEnd,
|
|
31
|
+
...(options.onCancel ? { onCancel: options.onCancel } : {}),
|
|
32
|
+
removeAbort: () => options.signal?.removeEventListener("abort", onAbort),
|
|
33
|
+
};
|
|
34
|
+
const onAbort = () => {
|
|
35
|
+
if (this.#operation !== operation || operation.snapshot.status === "ending")
|
|
36
|
+
return;
|
|
37
|
+
this.#update(operation, { status: "cancelling" });
|
|
38
|
+
};
|
|
39
|
+
const handle = Object.freeze({
|
|
40
|
+
id,
|
|
41
|
+
setWaitingForUser: (waiting) => {
|
|
42
|
+
if (this.#operation !== operation || !["running", "waiting"].includes(operation.snapshot.status))
|
|
43
|
+
return;
|
|
44
|
+
const status = waiting ? "waiting" : "running";
|
|
45
|
+
if (status !== operation.snapshot.status)
|
|
46
|
+
this.#update(operation, { status });
|
|
47
|
+
},
|
|
48
|
+
end: (endOptions) => {
|
|
49
|
+
if (this.#operation !== operation || operation.snapshot.status === "ending")
|
|
50
|
+
return endPromise;
|
|
51
|
+
operation.removeAbort();
|
|
52
|
+
operation.snapshot = Object.freeze({ ...operation.snapshot, status: "ending", outcome: endOptions?.outcome ?? "completed" });
|
|
53
|
+
this.#publish();
|
|
54
|
+
if (this.#finish(operation))
|
|
55
|
+
this.#publish();
|
|
56
|
+
return endPromise;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
operation.handle = handle;
|
|
60
|
+
this.#operation = operation;
|
|
61
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
62
|
+
this.#publish();
|
|
63
|
+
return handle;
|
|
64
|
+
}
|
|
65
|
+
disposeBridge(handle) {
|
|
66
|
+
const operation = this.#operation;
|
|
67
|
+
if (operation?.handle === handle)
|
|
68
|
+
operation.snapshot = Object.freeze({ ...operation.snapshot, reason: "bridge_disposed" });
|
|
69
|
+
return handle.end();
|
|
70
|
+
}
|
|
71
|
+
requestCancel(id) {
|
|
72
|
+
const operation = this.#operation;
|
|
73
|
+
if (!operation || operation.snapshot.id !== id || !operation.onCancel
|
|
74
|
+
|| operation.snapshot.status === "ending" || operation.snapshot.status === "cancelling")
|
|
75
|
+
return;
|
|
76
|
+
const previous = operation.snapshot.status;
|
|
77
|
+
this.#update(operation, { status: "cancelling" });
|
|
78
|
+
try {
|
|
79
|
+
operation.onCancel();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (this.#operation === operation && this.#snapshot.operation?.status === "cancelling") {
|
|
83
|
+
this.#update(operation, { status: previous });
|
|
84
|
+
}
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Admission is captured before execution and released exactly once, including queued aborts.
|
|
89
|
+
admit() {
|
|
90
|
+
const operation = this.#operation?.snapshot.status === "ending" ? undefined : this.#operation;
|
|
91
|
+
if (operation)
|
|
92
|
+
operation.pending += 1;
|
|
93
|
+
else
|
|
94
|
+
this.#unscoped += 1;
|
|
95
|
+
let released = false;
|
|
96
|
+
return {
|
|
97
|
+
...(operation ? { operationId: operation.snapshot.id } : {}),
|
|
98
|
+
release: () => {
|
|
99
|
+
if (released)
|
|
100
|
+
return;
|
|
101
|
+
released = true;
|
|
102
|
+
if (operation) {
|
|
103
|
+
operation.pending -= 1;
|
|
104
|
+
if (this.#finish(operation))
|
|
105
|
+
this.#publish();
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
this.#unscoped -= 1;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
observe(event) {
|
|
113
|
+
if (event.status === "running") {
|
|
114
|
+
this.#executions.set(event.id, event);
|
|
115
|
+
const operation = this.#operation;
|
|
116
|
+
if (operation && event.operationId === operation.snapshot.id && !operation.snapshot.hasExecuted) {
|
|
117
|
+
operation.snapshot = Object.freeze({ ...operation.snapshot, hasExecuted: true });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
this.#executions.delete(event.id);
|
|
122
|
+
this.#publish();
|
|
123
|
+
}
|
|
124
|
+
#finish(operation) {
|
|
125
|
+
if (operation.pending || operation.snapshot.status !== "ending" || this.#operation !== operation)
|
|
126
|
+
return false;
|
|
127
|
+
this.#operation = undefined;
|
|
128
|
+
operation.resolveEnd();
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
#update(operation, patch) {
|
|
132
|
+
operation.snapshot = Object.freeze({ ...operation.snapshot, ...patch });
|
|
133
|
+
this.#publish();
|
|
134
|
+
}
|
|
135
|
+
#publish() {
|
|
136
|
+
this.#snapshot = Object.freeze({
|
|
137
|
+
operation: this.#operation?.snapshot ?? null,
|
|
138
|
+
executions: Object.freeze([...this.#executions.values()]),
|
|
139
|
+
});
|
|
140
|
+
for (const listener of this.#listeners)
|
|
141
|
+
listener();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# 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,aAAa,CAAC;AA2B7C,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,CAAC;IAEF,KAAK,CAAC,UAKF,EAAE;QACJ,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAA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,CAAC;QACH,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU;YAAE,QAAQ,EAAE,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -4,4 +4,4 @@ export interface AgentOperationSurfaceProps {
|
|
|
4
4
|
toolRuntime: ToolRuntime;
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
}
|
|
7
|
-
export declare function AgentOperationSurface(
|
|
7
|
+
export declare function AgentOperationSurface(props: AgentOperationSurfaceProps): import("react").JSX.Element;
|
|
@@ -1,83 +1,108 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { getInternalToolRuntime } from "./runtime.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isOperationSurfaceLocked } from "./operation-lock.js";
|
|
5
5
|
import { OperationOverlayView } from "./operation-view.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (chat.toolRuntime !== toolRuntime)
|
|
9
|
-
throw new Error("AgentOperationSurface requires the NexfaceProvider Runtime.");
|
|
6
|
+
const surfaces = new WeakSet();
|
|
7
|
+
export function AgentOperationSurface(props) {
|
|
10
8
|
const element = useRef(null);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const turn = chat.turnId;
|
|
16
|
-
const running = chat.running;
|
|
17
|
-
const waiting = chat.waiting && !running;
|
|
18
|
-
useLayoutEffect(() => {
|
|
19
|
-
if (chat.operationSurface.current)
|
|
20
|
-
throw new Error("Only one AgentOperationSurface is supported per NexfaceProvider.");
|
|
21
|
-
chat.operationSurface.current = owner.current;
|
|
22
|
-
return () => { chat.operationSurface.current = null; };
|
|
23
|
-
}, [chat.operationSurface]);
|
|
9
|
+
const initial = useRef(props.toolRuntime);
|
|
10
|
+
if (initial.current !== props.toolRuntime) {
|
|
11
|
+
throw new Error("AgentOperationSurface requires a stable Runtime. Remount it to change Runtime.");
|
|
12
|
+
}
|
|
24
13
|
useLayoutEffect(() => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
if (surfaces.has(props.toolRuntime))
|
|
15
|
+
throw new Error("Only one AgentOperationSurface is supported per Runtime.");
|
|
16
|
+
surfaces.add(props.toolRuntime);
|
|
17
|
+
return () => { surfaces.delete(props.toolRuntime); };
|
|
18
|
+
}, [props.toolRuntime]);
|
|
19
|
+
const blockUserInput = useCallback((event) => {
|
|
20
|
+
if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted)
|
|
21
|
+
return;
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
event.stopPropagation();
|
|
24
|
+
}, []);
|
|
25
|
+
const blockPassiveUserInput = useCallback((event) => {
|
|
26
|
+
if (!element.current || !isOperationSurfaceLocked(element.current) || !event.nativeEvent.isTrusted)
|
|
33
27
|
return;
|
|
28
|
+
// Stop React's capture dispatch, but let the native event reach our non-passive
|
|
29
|
+
// surface listener. React's passive root listener cannot prevent scrolling.
|
|
30
|
+
event.isPropagationStopped = () => true;
|
|
31
|
+
}, []);
|
|
32
|
+
return _jsxs(_Fragment, { children: [_jsx("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, children: props.children }), _jsx(OperationSurfaceContent, { ...props, element: element })] });
|
|
33
|
+
}
|
|
34
|
+
function OperationSurfaceContent({ toolRuntime, element }) {
|
|
35
|
+
const runtime = getInternalToolRuntime(toolRuntime);
|
|
36
|
+
const activity = useSyncExternalStore(runtime.subscribeActivity, runtime.getActivitySnapshot, runtime.getActivitySnapshot);
|
|
37
|
+
const cycle = activity.operation;
|
|
38
|
+
const activeEvent = activity.executions.at(-1);
|
|
39
|
+
const [outcome, setOutcome] = useState();
|
|
40
|
+
useLayoutEffect(() => runtime.subscribeActivity(() => {
|
|
41
|
+
const current = runtime.getActivitySnapshot().operation;
|
|
42
|
+
if (current?.status === "ending" && current.outcome)
|
|
43
|
+
setOutcome({ id: current.id, status: current.outcome });
|
|
44
|
+
}), [runtime]);
|
|
45
|
+
const [visual, setVisual] = useState();
|
|
46
|
+
const [history, setHistory] = useState({ scope: "", entries: [] });
|
|
47
|
+
useLayoutEffect(() => toolRuntime.on("toolexecution", (event) => {
|
|
48
|
+
const scope = event.operationId ?? event.id;
|
|
34
49
|
if (event.status === "running") {
|
|
35
|
-
setVisual({ event, target:
|
|
50
|
+
setVisual({ event, target: runtime.resolveTarget(event.tool, event.input) });
|
|
36
51
|
}
|
|
37
52
|
else {
|
|
38
53
|
setVisual((current) => current?.event.id === event.id
|
|
39
|
-
? event.status === "success" && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
|
|
54
|
+
? event.status === "success" && !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
|
|
55
|
+
? { ...current, event: { ...current.event, ...event } }
|
|
56
|
+
: undefined
|
|
40
57
|
: current);
|
|
41
58
|
}
|
|
42
|
-
setHistory((
|
|
59
|
+
setHistory((current) => {
|
|
60
|
+
const entries = current.scope === scope ? current.entries : [];
|
|
43
61
|
const entry = {
|
|
44
62
|
toolCallId: event.id,
|
|
45
63
|
progressLabel: `${event.progressLabel || "正在处理你的请求"} · ${event.cancelled ? "已取消" : event.status === "running" ? "执行中" : event.status === "success" ? "已完成" : "失败"}`,
|
|
46
64
|
};
|
|
47
|
-
return entries.some((item) => item.toolCallId === event.id)
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
return { scope, entries: entries.some((item) => item.toolCallId === event.id)
|
|
66
|
+
? entries.map((item) => item.toolCallId === event.id ? entry : item)
|
|
67
|
+
: [...entries, entry] };
|
|
50
68
|
});
|
|
51
|
-
}), [toolRuntime]);
|
|
69
|
+
}), [runtime, toolRuntime]);
|
|
70
|
+
const activated = Boolean(cycle && (cycle.source === "webmcp" || cycle.hasExecuted));
|
|
71
|
+
const executing = activity.executions.length > 0;
|
|
72
|
+
const waiting = cycle?.status === "waiting" && !executing;
|
|
73
|
+
const running = executing || (activated && cycle?.status !== "waiting");
|
|
52
74
|
useLayoutEffect(() => {
|
|
53
|
-
if (!running)
|
|
75
|
+
if (!running || waiting)
|
|
54
76
|
setVisual(undefined);
|
|
55
|
-
}
|
|
56
77
|
}, [running, waiting]);
|
|
57
|
-
const
|
|
78
|
+
const currentVisual = activeEvent
|
|
79
|
+
? visual?.event.id === activeEvent.id ? visual : { event: activeEvent, target: runtime.resolveTarget(activeEvent.tool, activeEvent.input) }
|
|
80
|
+
: running && visual?.event.operationId === cycle?.id ? visual : undefined;
|
|
81
|
+
const resolveSurface = useCallback(() => element.current ?? undefined, [element]);
|
|
58
82
|
const resolveTarget = useCallback(() => {
|
|
59
|
-
if (!
|
|
83
|
+
if (!currentVisual)
|
|
60
84
|
return undefined;
|
|
61
|
-
const target =
|
|
62
|
-
if (target?.isConnected && element.current?.contains(target) && toolRuntime.getTools().includes(
|
|
85
|
+
const target = currentVisual.target;
|
|
86
|
+
if (target?.isConnected && element.current?.contains(target) && toolRuntime.getTools().includes(currentVisual.event.tool))
|
|
63
87
|
return { element: target };
|
|
64
|
-
return
|
|
88
|
+
return currentVisual.event.tool.definition.effect === "navigate" && element.current?.isConnected
|
|
65
89
|
? { element: element.current }
|
|
66
90
|
: undefined;
|
|
67
|
-
}, [
|
|
68
|
-
const operation =
|
|
69
|
-
toolCallId:
|
|
70
|
-
name:
|
|
71
|
-
input:
|
|
72
|
-
effect:
|
|
73
|
-
progressLabel:
|
|
74
|
-
status:
|
|
91
|
+
}, [currentVisual, element, toolRuntime]);
|
|
92
|
+
const operation = currentVisual ? {
|
|
93
|
+
toolCallId: currentVisual.event.id,
|
|
94
|
+
name: currentVisual.event.name,
|
|
95
|
+
input: currentVisual.event.input,
|
|
96
|
+
effect: currentVisual.event.tool.definition.effect,
|
|
97
|
+
progressLabel: currentVisual.event.progressLabel || "正在处理你的请求",
|
|
98
|
+
status: currentVisual.event.status === "running" ? "running" : "completed",
|
|
75
99
|
} : {
|
|
76
|
-
toolCallId:
|
|
100
|
+
toolCallId: cycle?.id ?? history.scope,
|
|
77
101
|
name: "agent",
|
|
78
|
-
progressLabel: waiting ? "等待你完成操作" :
|
|
79
|
-
status:
|
|
102
|
+
progressLabel: waiting ? "等待你完成操作" : "正在处理你的请求",
|
|
103
|
+
status: running || waiting ? "running" : outcome?.id === history.scope ? outcome.status : "completed",
|
|
80
104
|
};
|
|
81
|
-
|
|
105
|
+
const entries = !cycle || history.scope === cycle.id ? history.entries : [];
|
|
106
|
+
return activated || executing || entries.length ? _jsx(OperationOverlayView, { operation: operation, progressHistory: entries, running: running, feedbackActive: Boolean(currentVisual) && running && !waiting, humanHasControl: waiting, ...(cycle?.canCancel ? { onCancel: () => runtime.requestOperationCancel(cycle.id) } : {}), cancelling: cycle?.status === "cancelling" || cycle?.status === "ending", resolveSurface: resolveSurface, resolveTarget: resolveTarget }) : null;
|
|
82
107
|
}
|
|
83
108
|
//# sourceMappingURL=operation-surface.js.map
|