@nexface/agent 0.1.21 → 0.1.22

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 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,12 +17,14 @@ 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
+ // Internal to the evals CLI. Browser definitions and dispatch belong to the same model step.
21
+ const stepToolsKey = Symbol.for("@nexface/evals/getStepTools");
20
22
  function systemPromptFor(useToolProxy) {
21
23
  return SYSTEM_PROMPT.replace("{{CURRENT_TOOLS}}", useToolProxy
22
24
  ? "The latest NEXFACE_RUNTIME_V1 checkpoint lists current application capabilities; ignore older catalogs."
23
25
  : "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. For a confirmation tool, use arguments: { input: businessArguments } initially and arguments: { confirmation: { requestId, approved } } after the user answers. Invoke other functions directly."
25
- : "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.");
26
+ ? "Invoke application capabilities through nxf_callAppTool with their exact name and an arguments object matching the capability schema. Invoke other functions directly."
27
+ : "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.");
26
28
  }
27
29
  const SYSTEM_PROMPT = "You are an application agent. Handle the latest user request.\n\n" +
28
30
  "Decision:\n" +
@@ -40,7 +42,7 @@ const SYSTEM_PROMPT = "You are an application agent. Handle the latest user requ
40
42
  "- 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" +
41
43
  "- 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" +
42
44
  "- Batch only independent calls. The host executes them in order and skips remaining calls after a failure.\n" +
43
- "- Provide progressLabel for application or page automation calls whose schemas accept it.\n\n" +
45
+ "- Supply a short progress label only when the schema describes a field for reporting action progress. Other fields, including fields named progressLabel, follow their own business descriptions.\n\n" +
44
46
  "Completion:\n" +
45
47
  "- Once tool execution is required, continue until the latest request is fulfilled or cannot safely proceed.\n" +
46
48
  "- 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" +
@@ -752,6 +754,7 @@ class Nexface {
752
754
  #pageHistoryTruncated = false;
753
755
  #pageTransitions = [];
754
756
  #toolRuntime;
757
+ #getStepTools;
755
758
  #runtimeTools = new WeakMap();
756
759
  #registered = new Map();
757
760
  #request;
@@ -785,8 +788,10 @@ class Nexface {
785
788
  #operation;
786
789
  #pendingInterrupt;
787
790
  #authorizedPageResponses = new WeakSet();
791
+ #hostConfirmation;
788
792
  #hasPageConfirmation = (_toolName) => false;
789
793
  constructor(options) {
794
+ this.#getStepTools = options[stepToolsKey];
790
795
  if (options.useToolProxy !== undefined && typeof options.useToolProxy !== "boolean")
791
796
  throw new Error("useToolProxy must be a boolean.");
792
797
  this.#useToolProxy = options.useToolProxy ?? false;
@@ -794,10 +799,6 @@ class Nexface {
794
799
  options.pageDecision === undefined ? undefined : resolvePageDecision(options.pageDecision);
795
800
  this.#skills = normalizeSkills(options.skills);
796
801
  this.#skillsByName = new Map(this.#skills.map((skill) => [skill.name, skill]));
797
- const systemPrompt = systemPromptFor(this.#useToolProxy) + (this.#pageDecision ? PAGE_DELEGATION_PROMPT : "");
798
- this.#systemPrompt = this.#skills.length
799
- ? `${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)}`
800
- : systemPrompt;
801
802
  const hasToolRuntime = "toolRuntime" in options && options.toolRuntime !== undefined;
802
803
  if ("toolBridge" in options) {
803
804
  throw new AgentError("AGENT_TOOL_RUNTIME_UNAVAILABLE", "toolBridge is no longer supported. Use toolRuntime locally or NexfaceProvider with HTTP + SSE.");
@@ -809,6 +810,11 @@ class Nexface {
809
810
  else {
810
811
  this.#toolRuntime = undefined;
811
812
  }
813
+ const systemPrompt = systemPromptFor(this.#useToolProxy) +
814
+ (this.#pageDecision ? PAGE_DELEGATION_PROMPT : "");
815
+ this.#systemPrompt = this.#skills.length
816
+ ? `${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)}`
817
+ : systemPrompt;
812
818
  for (const tool of options.tools ?? []) {
813
819
  if (!tool?.definition ||
814
820
  typeof tool.execute !== "function" ||
@@ -868,6 +874,9 @@ class Nexface {
868
874
  authorizePageResponse: (response) => {
869
875
  this.#authorizedPageResponses.add(response);
870
876
  },
877
+ setHostConfirmation: (handler) => {
878
+ this.#hostConfirmation = handler;
879
+ },
871
880
  setPageConfirmationResolver: (resolver) => {
872
881
  this.#hasPageConfirmation = resolver;
873
882
  },
@@ -881,6 +890,8 @@ class Nexface {
881
890
  }
882
891
  async #getTools(signal) {
883
892
  signal.throwIfAborted();
893
+ if (this.#getStepTools)
894
+ return this.#getStepTools(signal);
884
895
  const runtimeTools = this.#toolRuntime?.getTools() ?? [];
885
896
  for (const tool of runtimeTools)
886
897
  this.#runtimeTools.set(tool.definition, tool);
@@ -2236,6 +2247,7 @@ class Nexface {
2236
2247
  if (prepared.preparationError)
2237
2248
  throw prepared.preparationError;
2238
2249
  let output;
2250
+ const executeStepTool = this.#getStepTools && applicationDefinitionsByName.get(prepared.displayName)?.execute;
2239
2251
  if (browserResult) {
2240
2252
  this.#requestResult = undefined;
2241
2253
  if (browserResult.confirmed)
@@ -2284,6 +2296,13 @@ class Nexface {
2284
2296
  skillToLoad = skill;
2285
2297
  output = { name: skillName, loaded };
2286
2298
  }
2299
+ else if (prepared.kind === "application" && executeStepTool) {
2300
+ toolInput =
2301
+ prepared.call.name === CALL_APPLICATION_TOOL_NAME
2302
+ ? prepared.input
2303
+ : parseArguments(prepared.call);
2304
+ output = await executeStepTool(toolInput, signal);
2305
+ }
2287
2306
  else if (prepared.kind === "application") {
2288
2307
  toolInput = prepared.input;
2289
2308
  const expectedDefinition = applicationDefinitionsByName.get(prepared.displayName);
@@ -2428,9 +2447,40 @@ class Nexface {
2428
2447
  }
2429
2448
  else if (runtimeTool && this.#toolRuntime) {
2430
2449
  const runtime = this.#toolRuntime;
2450
+ const hostConfirmation = this.#hostConfirmation;
2431
2451
  const execute = () => runtime.execute(runtimeTool, toolInput, {
2432
2452
  signal,
2433
2453
  ...(prepared.progressLabel ? { progressLabel: prepared.progressLabel } : {}),
2454
+ ...(!this.#request && hostConfirmation
2455
+ ? {
2456
+ [hostConfirmationSymbol]: async (message, confirmationSignal) => {
2457
+ const operation = this.#operation?.handle;
2458
+ const controller = getRuntimeController(runtime);
2459
+ if (operation)
2460
+ controller.setOperationWaiting(operation, true);
2461
+ try {
2462
+ const approved = await hostConfirmation({
2463
+ type: "tool-approval",
2464
+ mode: "chat",
2465
+ id: createId(),
2466
+ runId,
2467
+ toolCallId: prepared.call.id,
2468
+ toolName: prepared.displayName,
2469
+ input: structuredClone(toolInput),
2470
+ title: message,
2471
+ }, runtimeTool, confirmationSignal);
2472
+ confirmedCallId = prepared.call.id;
2473
+ if (!approved)
2474
+ rejectedCallId = prepared.call.id;
2475
+ return approved;
2476
+ }
2477
+ finally {
2478
+ if (operation)
2479
+ controller.setOperationWaiting(operation, false);
2480
+ }
2481
+ },
2482
+ }
2483
+ : {}),
2434
2484
  });
2435
2485
  output = this.#request
2436
2486
  ? await this.#executeWithProgress(execute, prepared.call.id, prepared.progressLabel, emit)
@@ -1,4 +1,22 @@
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
+ ]);
2
20
  /** Convert only the model-facing schema; Runtime continues validating the original. */
3
21
  export function strictToolSchema(schema, path) {
4
22
  const fail = (reason) => {
@@ -13,6 +31,11 @@ export function strictToolSchema(schema, path) {
13
31
  // Keep the entire tool non-strict rather than dropping its Runtime constraint.
14
32
  if (schema.uniqueItems !== undefined)
15
33
  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.");
16
39
  const result = { ...schema };
17
40
  if (schema.type === "object") {
18
41
  if (schema.additionalProperties !== false) {
package/dist/models/k.js CHANGED
@@ -333,6 +333,24 @@ 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
+ ]);
336
354
  function strictToolSchema(schema, path) {
337
355
  const fail = (reason)=>{
338
356
  throw new AgentModelError("MODEL_CONFIG_INVALID", `Strict tool schema at ${path}: ${reason}`);
@@ -340,6 +358,7 @@ function strictToolSchema(schema, path) {
340
358
  if (!schema.type) fail("an explicit type is required.");
341
359
  if (schema.enum?.some((value)=>null !== value && "object" == typeof value)) fail("object and array enum values are not supported.");
342
360
  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.");
343
362
  const result = {
344
363
  ...schema
345
364
  };
@@ -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", "TOOL_CONFIRMATION_LIMIT", "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_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;
@@ -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",
3
+ "version": "0.1.22",
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"
76
+ "@nexface/tools": "0.1.22"
77
77
  },
78
78
  "repository": {
79
79
  "type": "git",