@nexface/agent 0.1.21-alpha.6 → 0.1.21-alpha.8
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/agent.js +45 -20
- package/dist/model/strict-tools.js +0 -23
- package/dist/models/k.js +0 -19
- package/dist/shared/errors.d.ts +1 -1
- package/dist/shared/errors.js +1 -1
- package/dist/shared/runtime-execution.d.ts +6 -0
- package/dist/shared/runtime-execution.js +3 -0
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { decodeToolProxy } from "./shared/tool-proxy.js";
|
|
2
|
-
import { pageDecisionSymbol } from "./shared/runtime-execution.js";
|
|
2
|
+
import { hostConfirmationSymbol, pageDecisionSymbol } from "./shared/runtime-execution.js";
|
|
3
3
|
import { recordPageDiagnostic } from "./page-diagnostics.js";
|
|
4
4
|
import { isNavigationLoadingPage, isPendingPage, navigationLoadingWaits, pageFingerprint, } from "./page-observation.js";
|
|
5
5
|
import { assertCurrentHistory } from "./history-version.js";
|
|
@@ -17,14 +17,12 @@ import { getHistoryCompactionInput, HISTORY_COMPACTION_MIN_SAVINGS_BYTES, modelH
|
|
|
17
17
|
import { validateContextCatalog, validateToolCatalog } from "./tool-catalog.js";
|
|
18
18
|
import { getSnapshotTool, executeActionTool, applyActionTool } from "./shared/page-tools.js";
|
|
19
19
|
const CALL_APPLICATION_TOOL_NAME = "nxf_callAppTool";
|
|
20
|
-
function systemPromptFor(useToolProxy
|
|
20
|
+
function systemPromptFor(useToolProxy) {
|
|
21
21
|
return SYSTEM_PROMPT.replace("{{CURRENT_TOOLS}}", useToolProxy
|
|
22
22
|
? "The latest NEXFACE_RUNTIME_V1 checkpoint lists current application capabilities; ignore older catalogs."
|
|
23
23
|
: "The provided tools list contains the currently available tools.").replace("{{TOOL_CALLING}}", useToolProxy
|
|
24
|
-
? "Invoke application capabilities through nxf_callAppTool with their exact name and an arguments object matching the capability schema.
|
|
25
|
-
:
|
|
26
|
-
? "Invoke each tool directly using its name and schema from the provided tools list. Pass business fields at the level declared by the tool. Use a confirmation field only as described by that tool and wait for an explicit user decision before submitting an approval."
|
|
27
|
-
: "Invoke each tool directly using its name and schema from the provided tools list. If its schema has input and confirmation branches, call with { input: businessArguments } initially, then { confirmation: { requestId, approved } } only after the user answers. Do not flatten input fields into the top-level arguments.");
|
|
24
|
+
? "Invoke application capabilities through nxf_callAppTool with their exact name and an arguments object matching the capability schema. Invoke other functions directly."
|
|
25
|
+
: "Invoke each tool directly using its name and schema from the provided tools list. If the schema wraps business arguments in input, preserve that nesting.");
|
|
28
26
|
}
|
|
29
27
|
const SYSTEM_PROMPT = "You are an application agent. Handle the latest user request.\n\n" +
|
|
30
28
|
"Decision:\n" +
|
|
@@ -42,7 +40,7 @@ const SYSTEM_PROMPT = "You are an application agent. Handle the latest user requ
|
|
|
42
40
|
"- The catalog changes with the page. If a needed tool is missing and navigation to the relevant page is available, navigate there and inspect the updated catalog before using page automation or declaring the task unsupported. Do not batch navigation or opening UI with operations that depend on newly available tools.\n" +
|
|
43
41
|
"- When an application tool reports a permission restriction, required user confirmation, or a blocked write, follow its recovery requirements. Do not bypass the restriction through page automation.\n" +
|
|
44
42
|
"- Batch only independent calls. The host executes them in order and skips remaining calls after a failure.\n" +
|
|
45
|
-
"-
|
|
43
|
+
"- Provide progressLabel for application or page automation calls whose schemas accept it.\n\n" +
|
|
46
44
|
"Completion:\n" +
|
|
47
45
|
"- Once tool execution is required, continue until the latest request is fulfilled or cannot safely proceed.\n" +
|
|
48
46
|
"- Claim success only from Tool Results produced for the latest request or their explicitly confirmed execution records in a history summary attributed to that request. Do not repeat a confirmed operation merely because its original Tool Result was summarized.\n" +
|
|
@@ -787,6 +785,7 @@ class Nexface {
|
|
|
787
785
|
#operation;
|
|
788
786
|
#pendingInterrupt;
|
|
789
787
|
#authorizedPageResponses = new WeakSet();
|
|
788
|
+
#hostConfirmation;
|
|
790
789
|
#hasPageConfirmation = (_toolName) => false;
|
|
791
790
|
constructor(options) {
|
|
792
791
|
if (options.useToolProxy !== undefined && typeof options.useToolProxy !== "boolean")
|
|
@@ -796,6 +795,10 @@ class Nexface {
|
|
|
796
795
|
options.pageDecision === undefined ? undefined : resolvePageDecision(options.pageDecision);
|
|
797
796
|
this.#skills = normalizeSkills(options.skills);
|
|
798
797
|
this.#skillsByName = new Map(this.#skills.map((skill) => [skill.name, skill]));
|
|
798
|
+
const systemPrompt = systemPromptFor(this.#useToolProxy) + (this.#pageDecision ? PAGE_DELEGATION_PROMPT : "");
|
|
799
|
+
this.#systemPrompt = this.#skills.length
|
|
800
|
+
? `${systemPrompt} The NEXFACE_AVAILABLE_SKILLS_V1 catalog lists optional host-provided instructions. When a Skill matches the task, call nxf_loadSkill as the only tool call in the response, then follow its instructions starting in the next model step.\n\n${serializeSkillCatalog(this.#skills)}`
|
|
801
|
+
: systemPrompt;
|
|
799
802
|
const hasToolRuntime = "toolRuntime" in options && options.toolRuntime !== undefined;
|
|
800
803
|
if ("toolBridge" in options) {
|
|
801
804
|
throw new AgentError("AGENT_TOOL_RUNTIME_UNAVAILABLE", "toolBridge is no longer supported. Use toolRuntime locally or NexfaceProvider with HTTP + SSE.");
|
|
@@ -807,11 +810,6 @@ class Nexface {
|
|
|
807
810
|
else {
|
|
808
811
|
this.#toolRuntime = undefined;
|
|
809
812
|
}
|
|
810
|
-
const systemPrompt = systemPromptFor(this.#useToolProxy, Boolean(this.#webMcpCatalog)) +
|
|
811
|
-
(this.#pageDecision ? PAGE_DELEGATION_PROMPT : "");
|
|
812
|
-
this.#systemPrompt = this.#skills.length
|
|
813
|
-
? `${systemPrompt} The NEXFACE_AVAILABLE_SKILLS_V1 catalog lists optional host-provided instructions. When a Skill matches the task, call nxf_loadSkill as the only tool call in the response, then follow its instructions starting in the next model step.\n\n${serializeSkillCatalog(this.#skills)}`
|
|
814
|
-
: systemPrompt;
|
|
815
813
|
for (const tool of options.tools ?? []) {
|
|
816
814
|
if (!tool?.definition ||
|
|
817
815
|
typeof tool.execute !== "function" ||
|
|
@@ -871,6 +869,9 @@ class Nexface {
|
|
|
871
869
|
authorizePageResponse: (response) => {
|
|
872
870
|
this.#authorizedPageResponses.add(response);
|
|
873
871
|
},
|
|
872
|
+
setHostConfirmation: (handler) => {
|
|
873
|
+
this.#hostConfirmation = handler;
|
|
874
|
+
},
|
|
874
875
|
setPageConfirmationResolver: (resolver) => {
|
|
875
876
|
this.#hasPageConfirmation = resolver;
|
|
876
877
|
},
|
|
@@ -882,15 +883,8 @@ class Nexface {
|
|
|
882
883
|
get model() {
|
|
883
884
|
return { ...this.#modelInfo };
|
|
884
885
|
}
|
|
885
|
-
// The evaluation runtime reads the live browser catalog at each model decision.
|
|
886
|
-
get #webMcpCatalog() {
|
|
887
|
-
const key = Symbol.for("@nexface/evals/webmcp-catalog");
|
|
888
|
-
const runtime = this.#toolRuntime;
|
|
889
|
-
return runtime?.[key];
|
|
890
|
-
}
|
|
891
886
|
async #getTools(signal) {
|
|
892
887
|
signal.throwIfAborted();
|
|
893
|
-
await this.#webMcpCatalog?.refresh(signal);
|
|
894
888
|
const runtimeTools = this.#toolRuntime?.getTools() ?? [];
|
|
895
889
|
for (const tool of runtimeTools)
|
|
896
890
|
this.#runtimeTools.set(tool.definition, tool);
|
|
@@ -1979,7 +1973,7 @@ class Nexface {
|
|
|
1979
1973
|
? applicationDefinitions.map((definition) => ({
|
|
1980
1974
|
name: definition.name,
|
|
1981
1975
|
description: definition.description,
|
|
1982
|
-
inputSchema: canonicalizeCatalogValue(
|
|
1976
|
+
inputSchema: canonicalizeCatalogValue(definition.inputSchema),
|
|
1983
1977
|
}))
|
|
1984
1978
|
: applicationDefinitions.length
|
|
1985
1979
|
? [
|
|
@@ -2438,9 +2432,40 @@ class Nexface {
|
|
|
2438
2432
|
}
|
|
2439
2433
|
else if (runtimeTool && this.#toolRuntime) {
|
|
2440
2434
|
const runtime = this.#toolRuntime;
|
|
2435
|
+
const hostConfirmation = this.#hostConfirmation;
|
|
2441
2436
|
const execute = () => runtime.execute(runtimeTool, toolInput, {
|
|
2442
2437
|
signal,
|
|
2443
2438
|
...(prepared.progressLabel ? { progressLabel: prepared.progressLabel } : {}),
|
|
2439
|
+
...(!this.#request && hostConfirmation
|
|
2440
|
+
? {
|
|
2441
|
+
[hostConfirmationSymbol]: async (message, confirmationSignal) => {
|
|
2442
|
+
const operation = this.#operation?.handle;
|
|
2443
|
+
const controller = getRuntimeController(runtime);
|
|
2444
|
+
if (operation)
|
|
2445
|
+
controller.setOperationWaiting(operation, true);
|
|
2446
|
+
try {
|
|
2447
|
+
const approved = await hostConfirmation({
|
|
2448
|
+
type: "tool-approval",
|
|
2449
|
+
mode: "chat",
|
|
2450
|
+
id: createId(),
|
|
2451
|
+
runId,
|
|
2452
|
+
toolCallId: prepared.call.id,
|
|
2453
|
+
toolName: prepared.displayName,
|
|
2454
|
+
input: structuredClone(toolInput),
|
|
2455
|
+
title: message,
|
|
2456
|
+
}, runtimeTool, confirmationSignal);
|
|
2457
|
+
confirmedCallId = prepared.call.id;
|
|
2458
|
+
if (!approved)
|
|
2459
|
+
rejectedCallId = prepared.call.id;
|
|
2460
|
+
return approved;
|
|
2461
|
+
}
|
|
2462
|
+
finally {
|
|
2463
|
+
if (operation)
|
|
2464
|
+
controller.setOperationWaiting(operation, false);
|
|
2465
|
+
}
|
|
2466
|
+
},
|
|
2467
|
+
}
|
|
2468
|
+
: {}),
|
|
2444
2469
|
});
|
|
2445
2470
|
output = this.#request
|
|
2446
2471
|
? await this.#executeWithProgress(execute, prepared.call.id, prepared.progressLabel, emit)
|
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
import { AgentModelError } from "./error.js";
|
|
2
|
-
const strictKeywords = new Set([
|
|
3
|
-
"type",
|
|
4
|
-
"description",
|
|
5
|
-
"properties",
|
|
6
|
-
"required",
|
|
7
|
-
"additionalProperties",
|
|
8
|
-
"items",
|
|
9
|
-
"enum",
|
|
10
|
-
"minLength",
|
|
11
|
-
"maxLength",
|
|
12
|
-
"pattern",
|
|
13
|
-
"minimum",
|
|
14
|
-
"maximum",
|
|
15
|
-
"exclusiveMinimum",
|
|
16
|
-
"exclusiveMaximum",
|
|
17
|
-
"minItems",
|
|
18
|
-
"maxItems",
|
|
19
|
-
]);
|
|
20
2
|
/** Convert only the model-facing schema; Runtime continues validating the original. */
|
|
21
3
|
export function strictToolSchema(schema, path) {
|
|
22
4
|
const fail = (reason) => {
|
|
@@ -31,11 +13,6 @@ export function strictToolSchema(schema, path) {
|
|
|
31
13
|
// Keep the entire tool non-strict rather than dropping its Runtime constraint.
|
|
32
14
|
if (schema.uniqueItems !== undefined)
|
|
33
15
|
fail("uniqueItems is not supported.");
|
|
34
|
-
// Published WebMCP schemas may use presence constraints or explicit nullable unions.
|
|
35
|
-
// Requiring every property and restoring nulls would change those contracts.
|
|
36
|
-
if (typeof schema.type !== "string" ||
|
|
37
|
-
Object.keys(schema).some((key) => !strictKeywords.has(key)))
|
|
38
|
-
fail("cannot preserve this JSON Schema in strict mode.");
|
|
39
16
|
const result = { ...schema };
|
|
40
17
|
if (schema.type === "object") {
|
|
41
18
|
if (schema.additionalProperties !== false) {
|
package/dist/models/k.js
CHANGED
|
@@ -333,24 +333,6 @@ function selectModelHistory(messages, summary, options) {
|
|
|
333
333
|
}
|
|
334
334
|
return options?.pageDelegation ? projectPageDelegationHistory(entries) : entries;
|
|
335
335
|
}
|
|
336
|
-
const strictKeywords = new Set([
|
|
337
|
-
"type",
|
|
338
|
-
"description",
|
|
339
|
-
"properties",
|
|
340
|
-
"required",
|
|
341
|
-
"additionalProperties",
|
|
342
|
-
"items",
|
|
343
|
-
"enum",
|
|
344
|
-
"minLength",
|
|
345
|
-
"maxLength",
|
|
346
|
-
"pattern",
|
|
347
|
-
"minimum",
|
|
348
|
-
"maximum",
|
|
349
|
-
"exclusiveMinimum",
|
|
350
|
-
"exclusiveMaximum",
|
|
351
|
-
"minItems",
|
|
352
|
-
"maxItems"
|
|
353
|
-
]);
|
|
354
336
|
function strictToolSchema(schema, path) {
|
|
355
337
|
const fail = (reason)=>{
|
|
356
338
|
throw new AgentModelError("MODEL_CONFIG_INVALID", `Strict tool schema at ${path}: ${reason}`);
|
|
@@ -358,7 +340,6 @@ function strictToolSchema(schema, path) {
|
|
|
358
340
|
if (!schema.type) fail("an explicit type is required.");
|
|
359
341
|
if (schema.enum?.some((value)=>null !== value && "object" == typeof value)) fail("object and array enum values are not supported.");
|
|
360
342
|
if (void 0 !== schema.uniqueItems) fail("uniqueItems is not supported.");
|
|
361
|
-
if ("string" != typeof schema.type || Object.keys(schema).some((key)=>!strictKeywords.has(key))) fail("cannot preserve this JSON Schema in strict mode.");
|
|
362
343
|
const result = {
|
|
363
344
|
...schema
|
|
364
345
|
};
|
package/dist/shared/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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_CONFIRMATION_RESULT", "
|
|
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_CONFIRMATION_RESULT", "INVALID_TOOL_RUNTIME", "OPERATION_BUSY", "TOOL_CANCELLED", "TOOL_CONFIRMATION_INVALIDATED", "TOOL_CONFIRMATION_UNAVAILABLE", "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/shared/errors.js
CHANGED
|
@@ -11,11 +11,11 @@ export const TOOL_ERROR_CODES = [
|
|
|
11
11
|
"DUPLICATE_BINDING",
|
|
12
12
|
"INVALID_INPUT",
|
|
13
13
|
"INVALID_CONFIRMATION_RESULT",
|
|
14
|
-
"TOOL_CONFIRMATION_LIMIT",
|
|
15
14
|
"INVALID_TOOL_RUNTIME",
|
|
16
15
|
"OPERATION_BUSY",
|
|
17
16
|
"TOOL_CANCELLED",
|
|
18
17
|
"TOOL_CONFIRMATION_INVALIDATED",
|
|
18
|
+
"TOOL_CONFIRMATION_UNAVAILABLE",
|
|
19
19
|
"TOOL_CONFIRMATION_REJECTED",
|
|
20
20
|
"TOOL_ERROR",
|
|
21
21
|
"TOOL_REGISTRATION_TIMEOUT",
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ToolRuntime } from "@nexface/tools";
|
|
2
2
|
export declare const pageDecisionSymbol: unique symbol;
|
|
3
|
+
export declare const hostConfirmationSymbol: unique symbol;
|
|
4
|
+
export declare const executionStartSymbol: unique symbol;
|
|
5
|
+
export declare const executionStartedSymbol: unique symbol;
|
|
6
|
+
export type HostConfirmation = (message: string, signal: AbortSignal) => Promise<boolean>;
|
|
3
7
|
export type InternalExecutionOptions = NonNullable<Parameters<ToolRuntime["execute"]>[2]> & {
|
|
4
8
|
readonly [pageDecisionSymbol]?: boolean;
|
|
9
|
+
readonly [hostConfirmationSymbol]?: HostConfirmation;
|
|
10
|
+
readonly [executionStartSymbol]?: () => void;
|
|
5
11
|
};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
// Generated from shared/runtime-execution.ts. Do not edit manually.
|
|
2
2
|
export const pageDecisionSymbol = Symbol.for("@nexface/tools/page-decision");
|
|
3
|
+
export const hostConfirmationSymbol = Symbol.for("@nexface/tools/host-confirmation");
|
|
4
|
+
export const executionStartSymbol = Symbol.for("@nexface/tools/execution-start");
|
|
5
|
+
export const executionStartedSymbol = Symbol.for("@nexface/tools/execution-started");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexface/agent",
|
|
3
|
-
"version": "0.1.21-alpha.
|
|
3
|
+
"version": "0.1.21-alpha.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"engines": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@nexface/tools": "0.1.21-alpha.
|
|
76
|
+
"@nexface/tools": "0.1.21-alpha.8"
|
|
77
77
|
},
|
|
78
78
|
"repository": {
|
|
79
79
|
"type": "git",
|