@ap3x/browser-agent 0.1.0

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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -0
  3. package/dist/agent/agent.d.ts +160 -0
  4. package/dist/agent/agent.d.ts.map +1 -0
  5. package/dist/agent/backend.d.ts +38 -0
  6. package/dist/agent/backend.d.ts.map +1 -0
  7. package/dist/agent/captcha-watchdog.d.ts +31 -0
  8. package/dist/agent/captcha-watchdog.d.ts.map +1 -0
  9. package/dist/agent/context-builder.d.ts +24 -0
  10. package/dist/agent/context-builder.d.ts.map +1 -0
  11. package/dist/agent/event-stream.d.ts +104 -0
  12. package/dist/agent/event-stream.d.ts.map +1 -0
  13. package/dist/agent/executor.d.ts +37 -0
  14. package/dist/agent/executor.d.ts.map +1 -0
  15. package/dist/agent/gif.d.ts +23 -0
  16. package/dist/agent/gif.d.ts.map +1 -0
  17. package/dist/agent/history.d.ts +89 -0
  18. package/dist/agent/history.d.ts.map +1 -0
  19. package/dist/agent/judge.d.ts +36 -0
  20. package/dist/agent/judge.d.ts.map +1 -0
  21. package/dist/agent/message-manager.d.ts +94 -0
  22. package/dist/agent/message-manager.d.ts.map +1 -0
  23. package/dist/agent/output-schema.d.ts +26 -0
  24. package/dist/agent/output-schema.d.ts.map +1 -0
  25. package/dist/agent/png-decode.d.ts +9 -0
  26. package/dist/agent/png-decode.d.ts.map +1 -0
  27. package/dist/agent/rematch.d.ts +26 -0
  28. package/dist/agent/rematch.d.ts.map +1 -0
  29. package/dist/agent/replay.d.ts +155 -0
  30. package/dist/agent/replay.d.ts.map +1 -0
  31. package/dist/agent/step-loop.d.ts +124 -0
  32. package/dist/agent/step-loop.d.ts.map +1 -0
  33. package/dist/agent/variable-detector.d.ts +19 -0
  34. package/dist/agent/variable-detector.d.ts.map +1 -0
  35. package/dist/agent/video.d.ts +12 -0
  36. package/dist/agent/video.d.ts.map +1 -0
  37. package/dist/chunk-32HNRAQS.js +82 -0
  38. package/dist/chunk-UZALZUEE.js +2907 -0
  39. package/dist/filesystem/external-read.d.ts +18 -0
  40. package/dist/filesystem/external-read.d.ts.map +1 -0
  41. package/dist/filesystem/file-system.d.ts +61 -0
  42. package/dist/filesystem/file-system.d.ts.map +1 -0
  43. package/dist/index.d.ts +37 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +1070 -0
  46. package/dist/mcp/bin.d.ts +3 -0
  47. package/dist/mcp/bin.d.ts.map +1 -0
  48. package/dist/mcp/bin.js +19 -0
  49. package/dist/mcp/client.d.ts +45 -0
  50. package/dist/mcp/client.d.ts.map +1 -0
  51. package/dist/mcp/index.d.ts +3 -0
  52. package/dist/mcp/index.d.ts.map +1 -0
  53. package/dist/mcp/log.d.ts +6 -0
  54. package/dist/mcp/log.d.ts.map +1 -0
  55. package/dist/mcp/server.d.ts +36 -0
  56. package/dist/mcp/server.d.ts.map +1 -0
  57. package/dist/observability/logger.d.ts +25 -0
  58. package/dist/observability/logger.d.ts.map +1 -0
  59. package/dist/testing.d.ts +37 -0
  60. package/dist/testing.d.ts.map +1 -0
  61. package/dist/testing.js +18 -0
  62. package/dist/tools/actions.d.ts +9 -0
  63. package/dist/tools/actions.d.ts.map +1 -0
  64. package/dist/tools/registry.d.ts +125 -0
  65. package/dist/tools/registry.d.ts.map +1 -0
  66. package/dist/tools/sensitive.d.ts +59 -0
  67. package/dist/tools/sensitive.d.ts.map +1 -0
  68. package/dist/tools/types.d.ts +117 -0
  69. package/dist/tools/types.d.ts.map +1 -0
  70. package/dist/types.d.ts +2 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/usage/ledger.d.ts +27 -0
  73. package/dist/usage/ledger.d.ts.map +1 -0
  74. package/package.json +50 -0
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../src/mcp/bin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ logStderr,
4
+ runBrowserMcpServer
5
+ } from "../chunk-UZALZUEE.js";
6
+
7
+ // src/mcp/bin.ts
8
+ import { BrowserSession } from "@ap3x/browser";
9
+ async function main() {
10
+ const cdpUrl = process.env.AP3X_BROWSER_CDP_URL;
11
+ const session = cdpUrl ? await BrowserSession.connect(cdpUrl) : await BrowserSession.launch();
12
+ await runBrowserMcpServer({ session });
13
+ }
14
+ main().catch((error) => {
15
+ logStderr(
16
+ `browser MCP server failed to start: ${error instanceof Error ? error.stack ?? error.message : String(error)}`
17
+ );
18
+ process.exitCode = 1;
19
+ });
@@ -0,0 +1,45 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { type TSchema } from "@sinclair/typebox";
3
+ import { type ActionDefinition } from "../tools/registry";
4
+ /**
5
+ * Synthesize a TypeBox param schema from a remote MCP tool's JSON-Schema
6
+ * `inputSchema`. SHALLOW by design — top-level property types only; nested shapes
7
+ * stay permissive because the remote server is the deep validator. Returns
8
+ * `undefined` (⇒ the tool is SKIPPED, never fatal) when the schema isn't a plain
9
+ * object schema or carries composition keywords the action union can't represent.
10
+ * Every leaf is a real, registered TypeBox kind, so the registry's `Value.Check`
11
+ * validates without throwing — the wrapper can never explode inside the executor.
12
+ */
13
+ export declare function synthesizeParamSchema(inputSchema: unknown): TSchema | undefined;
14
+ export interface ImportMcpToolsOptions {
15
+ /** Prefix each generated action name (avoids collisions with built-ins). */
16
+ prefix?: string;
17
+ /** Keep only tools whose (unprefixed) name passes this predicate. */
18
+ toolFilter?: (name: string) => boolean;
19
+ }
20
+ /**
21
+ * List an already-connected MCP client's tools and turn each into a browser-agent
22
+ * action. A tool with an unconvertible schema is skipped (logged), not fatal —
23
+ * the returned list is every tool that DID convert. Register them on a `Registry`
24
+ * to expose them to the agent's LLM as ordinary actions.
25
+ */
26
+ export declare function importMcpTools(client: Client, options?: ImportMcpToolsOptions): Promise<Array<ActionDefinition<TSchema>>>;
27
+ export interface McpStdioConnection {
28
+ /** The server executable (e.g. `npx`). */
29
+ command: string;
30
+ args?: string[];
31
+ env?: Record<string, string>;
32
+ clientInfo?: {
33
+ name?: string;
34
+ version?: string;
35
+ };
36
+ }
37
+ /**
38
+ * Convenience: spawn a stdio MCP server and return a connected `Client`, ready to
39
+ * hand to {@link importMcpTools}. A connection failure throws
40
+ * `AgentMCPConnectionError` (reused from @ap3x/agent-core). For tests, construct a
41
+ * `Client` over an in-memory transport and pass it to `importMcpTools` directly —
42
+ * this helper is only the real-process path.
43
+ */
44
+ export declare function connectMcpClient(connection: McpStdioConnection): Promise<Client>;
45
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAEnE,OAAO,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,mBAAmB,CAAC;AA8BxE;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAkB/E;AA0DD,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAsB3C;AAED,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBtF"}
@@ -0,0 +1,3 @@
1
+ export * from "./server";
2
+ export * from "./client";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type Logger } from "../observability/logger";
2
+ /** The package logger, hard-wired to stderr for MCP stdio safety. */
3
+ export declare const mcpLogger: Logger;
4
+ /** Convenience shim for one-line stderr diagnostics (delegates to {@link mcpLogger}). */
5
+ export declare function logStderr(message: string): void;
6
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/mcp/log.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,yBAAyB,CAAC;AAEpE,qEAAqE;AACrE,eAAO,MAAM,SAAS,EAAE,MAItB,CAAC;AAEH,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C"}
@@ -0,0 +1,36 @@
1
+ import type { Api, Model, ProviderStreamOptions } from "@ap3x/ai";
2
+ import { BrowserDriver, type BrowserSession } from "@ap3x/browser";
3
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
+ import type { ExtractionLlm, Registry } from "../tools/registry";
5
+ export interface BrowserMcpServerOptions {
6
+ /** The session to drive. */
7
+ session: BrowserSession;
8
+ /** Override the driver built from `session`. */
9
+ driver?: BrowserDriver;
10
+ /** Action registry (default: the built-in set). Only the mapped tools are exposed. */
11
+ registry?: Registry;
12
+ /** Enables `browser_run_agent`. Omit to expose only the direct browser controls. */
13
+ llm?: {
14
+ model: Model<Api>;
15
+ extraction?: ExtractionLlm;
16
+ /** Per-call overrides (apiKey/headers/etc.) forwarded to the spun-up Agent. */
17
+ streamOptions?: ProviderStreamOptions;
18
+ };
19
+ /** Read/upload-only paths the actions may reference. */
20
+ availableFilePaths?: string[];
21
+ /** Base dir for the ActionContext FileSystem (default: an OS-temp dir). */
22
+ fileSystemDir?: string;
23
+ serverInfo?: {
24
+ name?: string;
25
+ version?: string;
26
+ };
27
+ }
28
+ /**
29
+ * Build (but do not start) the low-level MCP {@link Server}. Connect it to a
30
+ * transport — {@link runBrowserMcpServer} uses stdio; tests use the SDK's
31
+ * in-memory transport pair.
32
+ */
33
+ export declare function createBrowserMcpServer(options: BrowserMcpServerOptions): Server;
34
+ /** Create the server and serve it over stdio (the real-process entry point). */
35
+ export declare function runBrowserMcpServer(options: BrowserMcpServerOptions): Promise<Server>;
36
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAYnE,OAAO,KAAK,EAAiB,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AA0BhF,MAAM,WAAW,uBAAuB;IACtC,4BAA4B;IAC5B,OAAO,EAAE,cAAc,CAAC;IACxB,gDAAgD;IAChD,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,oFAAoF;IACpF,GAAG,CAAC,EAAE;QACJ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,UAAU,CAAC,EAAE,aAAa,CAAC;QAC3B,+EAA+E;QAC/E,aAAa,CAAC,EAAE,qBAAqB,CAAC;KACvC,CAAC;IACF,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAmDD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CA2I/E;AAED,gFAAgF;AAChF,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAK3F"}
@@ -0,0 +1,25 @@
1
+ export type LogLevel = "debug" | "info" | "warn" | "error";
2
+ /** Arbitrary structured fields attached to a log line. */
3
+ export type LogFields = Record<string, unknown>;
4
+ /** The surface the agent logs through. Inject your own or use {@link createLogger}. */
5
+ export interface Logger {
6
+ debug(message: string, fields?: LogFields): void;
7
+ info(message: string, fields?: LogFields): void;
8
+ warn(message: string, fields?: LogFields): void;
9
+ error(message: string, fields?: LogFields): void;
10
+ /** A logger that carries `fields` on every line (merged over this one's). */
11
+ child(fields: LogFields): Logger;
12
+ }
13
+ export interface LoggerOptions {
14
+ /** Lowest level that is emitted. Default `info`. */
15
+ level?: LogLevel;
16
+ /** Fields carried on every line (the logger's identity). */
17
+ fields?: LogFields;
18
+ /** Where a formatted line goes. Default: the matching `console` method. */
19
+ sink?: (level: LogLevel, line: string) => void;
20
+ }
21
+ /** A structured console logger with a level gate and child loggers. */
22
+ export declare function createLogger(options?: LoggerOptions): Logger;
23
+ /** A logger that discards everything. The library default (no output unless asked). */
24
+ export declare const silentLogger: Logger;
25
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/observability/logger.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEhD,uFAAuF;AACvF,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACjD,6EAA6E;IAC7E,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC;CAClC;AAID,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AA4BD,uEAAuE;AACvE,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAkBhE;AAED,uFAAuF;AACvF,eAAO,MAAM,YAAY,EAAE,MAQ1B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type Api, type AssistantMessage, type FauxProviderRegistration, type Model } from "@ap3x/ai";
2
+ import type { AgentOutput } from "./agent/output-schema";
3
+ import type { LogFields, LogLevel, Logger } from "./observability/logger";
4
+ /** A scripted turn: an AgentOutput (wrapped as a tool call) or a raw faux message. */
5
+ export type ScriptedStep = AgentOutput | AssistantMessage;
6
+ export interface ScriptedLlmHandle {
7
+ /** The model to hand to `new Agent({ llm: { model } })`. */
8
+ model: Model<Api>;
9
+ registration: FauxProviderRegistration;
10
+ /** Append more scripted turns. */
11
+ push(steps: ScriptedStep[]): void;
12
+ unregister(): void;
13
+ }
14
+ /** Register a faux provider that replays `steps` as structured-output responses. */
15
+ export declare function scriptedLlm(steps?: ScriptedStep[]): ScriptedLlmHandle;
16
+ /** Build a valid AgentOutput from an action list (brain fields default to empty). */
17
+ export declare function agentStep(actions: Array<Record<string, unknown>>, fields?: Partial<AgentOutput>): AgentOutput;
18
+ /** A response with no tool call and no text → generateObject reports `empty`. */
19
+ export declare function emptyLlmResponse(): AssistantMessage;
20
+ /** A response truncated at the token limit → generateObject reports `truncated`. */
21
+ export declare function truncatedLlmResponse(): AssistantMessage;
22
+ /** A schema-violating response (no `action`) → generateObject reports `invalid`. */
23
+ export declare function invalidLlmResponse(): AssistantMessage;
24
+ /** A provider transport error → generateObject reports `transport`. */
25
+ export declare function transportErrorResponse(message?: string): AssistantMessage;
26
+ /** One captured log line. */
27
+ export interface CapturedLog {
28
+ level: LogLevel;
29
+ message: string;
30
+ fields: LogFields;
31
+ }
32
+ /** A {@link Logger} that records every line (with merged child fields) into `lines`. */
33
+ export declare function collectingLogger(base?: LogFields): {
34
+ logger: Logger;
35
+ lines: CapturedLog[];
36
+ };
37
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,GAAG,EACR,KAAK,gBAAgB,EACrB,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,CAAC;IAAC,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,CAe/F"}
@@ -0,0 +1,18 @@
1
+ import {
2
+ agentStep,
3
+ collectingLogger,
4
+ emptyLlmResponse,
5
+ invalidLlmResponse,
6
+ scriptedLlm,
7
+ transportErrorResponse,
8
+ truncatedLlmResponse
9
+ } from "./chunk-32HNRAQS.js";
10
+ export {
11
+ agentStep,
12
+ collectingLogger,
13
+ emptyLlmResponse,
14
+ invalidLlmResponse,
15
+ scriptedLlm,
16
+ transportErrorResponse,
17
+ truncatedLlmResponse
18
+ };
@@ -0,0 +1,9 @@
1
+ import { type TSchema } from "@sinclair/typebox";
2
+ import { type ActionDefinition, Registry } from "./registry";
3
+ /** Every built-in action, in a stable order. */
4
+ export declare const BUILTIN_ACTIONS: ReadonlyArray<ActionDefinition<TSchema>>;
5
+ /** Register the built-in action set on a registry. */
6
+ export declare function registerBuiltins(registry: Registry): void;
7
+ /** A fresh registry preloaded with the built-in action set. */
8
+ export declare function createDefaultRegistry(): Registry;
9
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/tools/actions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAsB,KAAK,gBAAgB,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAkX/F,gDAAgD;AAChD,eAAO,MAAM,eAAe,EAqBZ,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzD,sDAAsD;AACtD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAEzD;AAED,+DAA+D;AAC/D,wBAAgB,qBAAqB,IAAI,QAAQ,CAIhD"}
@@ -0,0 +1,125 @@
1
+ import type { BrowserDriver, BrowserSession, CdpTransport } from "@ap3x/browser";
2
+ import { type Static, type TSchema } from "@sinclair/typebox";
3
+ import type { FileSystem } from "../filesystem/file-system";
4
+ import type { SecretMap, SensitiveData } from "./sensitive";
5
+ import { type ActionResult } from "./types";
6
+ /**
7
+ * The extraction-LLM seam. M4 leaves this undefined and `extract_content` returns
8
+ * the page's serialized text; M5 wires it to `@ap3x/ai` for real summarization.
9
+ */
10
+ export interface ExtractionLlm {
11
+ extract(prompt: string, options?: {
12
+ signal?: AbortSignal;
13
+ }): Promise<string>;
14
+ }
15
+ /**
16
+ * The ONE typed injection object handed to every action's `execute` (E5). It
17
+ * carries every capability an action needs, instead of injecting them by
18
+ * parameter name.
19
+ */
20
+ export interface ActionContext {
21
+ /** The live session — for primitives the driver doesn't surface (dropdowns, go-back, upload). */
22
+ session: BrowserSession;
23
+ /** The typed facade — navigate / click / type / scroll / tabs / screenshot / extract. */
24
+ driver: BrowserDriver;
25
+ /** The current page URL (domain scoping, extraction provenance). */
26
+ pageUrl: string;
27
+ /**
28
+ * Raw CDP transport, for custom actions that reach the protocol directly.
29
+ * Optional: no built-in action needs it, and a {@link BrowserSession} does not
30
+ * expose its transport publicly, so the step loop leaves it undefined. A custom
31
+ * action that requires raw CDP must be handed a transport by its author.
32
+ */
33
+ cdpClient?: CdpTransport;
34
+ /** The agent's workspace filesystem. */
35
+ fileSystem: FileSystem;
36
+ /** Optional extraction LLM (M5). */
37
+ extractionLlm?: ExtractionLlm;
38
+ /** Read/upload-only paths the agent may reference. */
39
+ availableFilePaths: readonly string[];
40
+ /** Whether sensitive data is in play for this step (drives masked logging). */
41
+ hasSensitiveData: boolean;
42
+ /**
43
+ * The composed per-step abort (run abort ∪ step timeout — design/06 §6.7–6.8).
44
+ * Actions forward it into driver/session/extraction calls so a run-abort or
45
+ * step-timeout cancels IN-FLIGHT work, not only the gap between actions.
46
+ */
47
+ signal?: AbortSignal;
48
+ }
49
+ /** The shape passed to {@link defineAction}. */
50
+ export interface ActionDefinition<S extends TSchema> {
51
+ /** Unique action name — the single key in the wire JSON `{ name: params }`. */
52
+ name: string;
53
+ /** One-line description shown to the model. */
54
+ description: string;
55
+ /** TypeBox param schema (the trust boundary). */
56
+ schema: S;
57
+ /** Glob URL filters. When set, the action only exists on matching pages. */
58
+ domains?: string[];
59
+ /** Abort remaining queued actions after this one (page-changing actions). */
60
+ terminatesSequence?: boolean;
61
+ /** The handler. Typed against the schema — a mismatch is a compile error. */
62
+ execute(params: Static<S>, ctx: ActionContext): Promise<ActionResult> | ActionResult;
63
+ }
64
+ /** A registered action, type-erased for storage. */
65
+ export interface RegisteredAction {
66
+ name: string;
67
+ description: string;
68
+ schema: TSchema;
69
+ domains?: string[];
70
+ terminatesSequence: boolean;
71
+ execute(params: unknown, ctx: ActionContext): Promise<ActionResult> | ActionResult;
72
+ }
73
+ /**
74
+ * Define a custom (or built-in) action. Identity function — it exists purely so
75
+ * the generic `S` is inferred and `execute`'s params are typed. This is the
76
+ * public extension API: `registry.register(defineAction({ ... }))`.
77
+ */
78
+ export declare function defineAction<S extends TSchema>(def: ActionDefinition<S>): ActionDefinition<S>;
79
+ export declare class Registry {
80
+ private readonly actions;
81
+ private readonly excluded;
82
+ private readonly unionCache;
83
+ /** Register an action. Later registration of an excluded name is a no-op. */
84
+ register<S extends TSchema>(def: ActionDefinition<S>): void;
85
+ /**
86
+ * A shallow copy sharing the same action definitions. The step loop clones a
87
+ * caller's registry before applying a vision filter so the caller's object is
88
+ * never mutated (E7). Excluded names carry over.
89
+ */
90
+ clone(): Registry;
91
+ /** Remove an action and block it from being re-registered. */
92
+ exclude(name: string): void;
93
+ get(name: string): RegisteredAction | undefined;
94
+ /** Actions available on `pageUrl` (unfiltered + domain-matching), name-sorted. */
95
+ available(pageUrl?: string): RegisteredAction[];
96
+ /**
97
+ * The per-page union of single-key action objects for structured output (A8).
98
+ * Cached by the set of admitted action names (so equivalent URLs share one).
99
+ */
100
+ actionUnion(pageUrl?: string): TSchema;
101
+ /** `name: description (param=type, ...)` lines for the prompt. */
102
+ promptDescriptions(pageUrl?: string): string;
103
+ /**
104
+ * Execute one action. `<secret>key</secret>` tags are substituted (enforcement
105
+ * point 3) and — ALWAYS, even with no secrets configured — scanned for
106
+ * survivors: any unresolved `<secret>…</secret>` short-circuits to an
107
+ * `ActionResult.error` and the action never runs, so a literal tag can never be
108
+ * typed (C5). Params are then validated against the action's schema before
109
+ * `execute`; afterwards every result string is masked against the resolved
110
+ * secrets so a real substituted value can never land in history.
111
+ *
112
+ * `allSensitiveData` (M8 follow-up), when provided, masks results against
113
+ * EVERY domain's secret values (mirroring `maskOutbound`'s all-domains
114
+ * approach), not just `secrets` (the current-URL-scoped subset used for
115
+ * substitution). Page content is not domain-sandboxed the way secret
116
+ * substitution is — a domain-B secret echoed while acting on domain A must
117
+ * still be masked on this method's outbound text (narration / event stream /
118
+ * ToolResultMessage), the same way the LLM-prompt path already masks via
119
+ * `maskOutbound` in the message manager. Without it, masking falls back to
120
+ * `secrets` alone (the pre-M11 behavior — still correct for the single-domain
121
+ * case, just narrower).
122
+ */
123
+ execute(name: string, rawParams: unknown, ctx: ActionContext, secrets?: SecretMap, allSensitiveData?: SensitiveData): Promise<ActionResult>;
124
+ }
125
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAC;AAEpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,SAAS,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAA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+ totpSeed: string;
4
+ };
5
+ /** `{ [domainPattern]: { [key]: value } }`. `'*'` = applies to any URL. */
6
+ export type SensitiveData = Record<string, Record<string, SecretValue>>;
7
+ /** Resolved secrets for a single URL: key → value. */
8
+ export type SecretMap = Record<string, SecretValue>;
9
+ /**
10
+ * The secrets that apply to `url` — every domain pattern that matches, flattened.
11
+ * Empty-string values are dropped (they count as missing). New-tab pages match
12
+ * nothing (the domain matcher already returns false for them).
13
+ */
14
+ export declare function resolveSecretsForUrl(data: SensitiveData, url: string): SecretMap;
15
+ /** The placeholder key names applicable to `url` (for the prompt block). */
16
+ export declare function applicablePlaceholders(data: SensitiveData, url: string): string[];
17
+ /**
18
+ * Point 1 — the `<sensitive_data>` prompt block for `url`, or `undefined` when no
19
+ * secrets apply. Lists names only; never values.
20
+ */
21
+ export declare function sensitiveDataDescription(data: SensitiveData, url: string): string | undefined;
22
+ /**
23
+ * Point 2 — mask every real value found in `text` back to `<secret>key</secret>`,
24
+ * longest value first. Domain-AGNOSTIC: all domains' values are masked (injection
25
+ * is domain-scoped, but a value could have been echoed anywhere). TOTP seeds have
26
+ * no static value and are not masked.
27
+ */
28
+ export declare function maskOutbound(text: string, data: SensitiveData): string;
29
+ /**
30
+ * Point 2, applied to a resolved {@link SecretMap} (key→value for one URL) rather
31
+ * than the whole {@link SensitiveData}: mask every real string value back to
32
+ * `<secret>key</secret>`, LONGEST value first. Used to scrub any secret that a
33
+ * post-substitution action wrote into its result text, so a real value can never
34
+ * land in history — regardless of the caller's `hasSensitiveData` flag. TOTP
35
+ * seeds have no static value and are not masked.
36
+ */
37
+ export declare function maskSecretMap(text: string, secrets: SecretMap): string;
38
+ /**
39
+ * Point 3 — substitute `<secret>key</secret>` tags (and bare strings that exactly
40
+ * equal a key name) throughout `params` with real values. Returns the substituted
41
+ * value plus the list of UNRESOLVED placeholder keys (referenced by a tag but not
42
+ * in `secrets`). The caller MUST error out when `unresolved` is non-empty rather
43
+ * than let a literal `<secret>` tag reach the page (C5).
44
+ */
45
+ export declare function substituteSecrets(params: unknown, secrets: SecretMap): {
46
+ value: unknown;
47
+ unresolved: string[];
48
+ };
49
+ export interface TotpOptions {
50
+ /** Unix time in seconds (default: now). */
51
+ time?: number;
52
+ /** Time step in seconds (default 30). */
53
+ step?: number;
54
+ /** Number of digits (default 6). */
55
+ digits?: number;
56
+ }
57
+ /** Generate a TOTP code from a base32 seed (RFC 6238). */
58
+ export declare function totp(seed: string, options?: TotpOptions): string;
59
+ //# sourceMappingURL=sensitive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sensitive.d.ts","sourceRoot":"","sources":["../../src/tools/sensitive.ts"],"names":[],"mappings":"AAsBA,mFAAmF;AACnF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAExE,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAcpD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAShF;AAED,4EAA4E;AAC5E,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjF;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK7F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,CAatE;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,MAAM,CAWtE;AASD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,SAAS,GACjB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CA0B1C;AAyBD,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,0DAA0D;AAC1D,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAkBpE"}
@@ -0,0 +1,117 @@
1
+ import type { ElementIndex } from "@ap3x/browser";
2
+ /** One action the agent can take. Discriminated on `kind`. */
3
+ export type Action = {
4
+ kind: "navigate";
5
+ url: string;
6
+ newTab?: boolean;
7
+ } | {
8
+ kind: "go_back";
9
+ } | {
10
+ kind: "click";
11
+ index: ElementIndex;
12
+ } | {
13
+ kind: "input_text";
14
+ index: ElementIndex;
15
+ text: string;
16
+ clear?: boolean;
17
+ } | {
18
+ kind: "scroll";
19
+ down?: boolean;
20
+ pages?: number;
21
+ index?: ElementIndex;
22
+ } | {
23
+ kind: "scroll_to_text";
24
+ text: string;
25
+ } | {
26
+ kind: "send_keys";
27
+ keys: string;
28
+ } | {
29
+ kind: "select_dropdown";
30
+ index: ElementIndex;
31
+ text: string;
32
+ } | {
33
+ kind: "get_dropdown_options";
34
+ index: ElementIndex;
35
+ } | {
36
+ kind: "switch_tab";
37
+ tabId: string;
38
+ } | {
39
+ kind: "open_tab";
40
+ url: string;
41
+ } | {
42
+ kind: "close_tab";
43
+ tabId: string;
44
+ } | {
45
+ kind: "upload_file";
46
+ index: ElementIndex;
47
+ path: string;
48
+ } | {
49
+ kind: "wait";
50
+ seconds?: number;
51
+ } | {
52
+ kind: "extract_content";
53
+ query: string;
54
+ } | {
55
+ kind: "write_file";
56
+ fileName: string;
57
+ content: string;
58
+ append?: boolean;
59
+ } | {
60
+ kind: "append_file";
61
+ fileName: string;
62
+ content: string;
63
+ } | {
64
+ kind: "read_file";
65
+ fileName: string;
66
+ } | {
67
+ kind: "replace_file";
68
+ fileName: string;
69
+ oldStr: string;
70
+ newStr: string;
71
+ } | {
72
+ kind: "done";
73
+ success: boolean;
74
+ text: string;
75
+ filesToDisplay?: string[];
76
+ };
77
+ /** Fields common to every action result — the action→prompt feedback contract. */
78
+ interface ActionResultBase {
79
+ /** Error text. Always folded into long-term memory; increments the failure count. */
80
+ error?: string;
81
+ /** Action output text. `done` text lands here. */
82
+ extractedContent?: string;
83
+ /** True ⇒ `extractedContent` goes to a one-shot read-state, not long-term memory. */
84
+ includeExtractedContentOnlyOnce?: boolean;
85
+ /** A line persisted verbatim into agent history (preferred over `extractedContent`). */
86
+ longTermMemory?: string;
87
+ /** File paths surfaced in the done message. */
88
+ attachments?: string[];
89
+ /** Images kept separate from text for efficient prompting. */
90
+ images?: Array<{
91
+ name: string;
92
+ data: string;
93
+ }>;
94
+ /** Observability side channel (e.g. click coordinates). */
95
+ metadata?: Record<string, unknown>;
96
+ /** @deprecated legacy routing flag; kept for shape parity. */
97
+ includeInMemory?: boolean;
98
+ }
99
+ /** Result of a non-terminal step. Carries NO success verdict (E3). */
100
+ export interface StepResult extends ActionResultBase {
101
+ isDone?: false;
102
+ }
103
+ /** Result of the terminal `done` action. `success` is only legal here. */
104
+ export interface DoneResult extends ActionResultBase {
105
+ isDone: true;
106
+ success: boolean;
107
+ }
108
+ /** Every action returns one of these. `success` exists only on `DoneResult`. */
109
+ export type ActionResult = StepResult | DoneResult;
110
+ /** Build a non-terminal result. */
111
+ export declare function stepResult(fields?: ActionResultBase): StepResult;
112
+ /** Build a terminal `done` result. `success` cannot be set without this path. */
113
+ export declare function doneResult(success: boolean, fields?: ActionResultBase): DoneResult;
114
+ /** Narrow a result to the terminal variant. */
115
+ export declare function isDoneResult(result: ActionResult): result is DoneResult;
116
+ export {};
117
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,8DAA8D;AAC9D,MAAM,MAAM,MAAM,GACd;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,YAAY,CAAA;CAAE,GACxE;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,UAAU,CAAC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C/C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,8DAA8D;IAC9D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,sEAAsE;AACtE,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAClD,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,0EAA0E;AAC1E,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAClD,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,gFAAgF;AAChF,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAEnD,mCAAmC;AACnC,wBAAgB,UAAU,CAAC,MAAM,GAAE,gBAAqB,GAAG,UAAU,CAEpE;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,gBAAqB,GAAG,UAAU,CAEtF;AAED,+CAA+C;AAC/C,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,UAAU,CAEvE"}
@@ -0,0 +1,2 @@
1
+ export * from "./tools/types";
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Usage } from "@ap3x/ai";
2
+ /** Per-model rollup. `invocations` counts generateObject calls for that model. */
3
+ export interface ModelUsageStats {
4
+ model: string;
5
+ invocations: number;
6
+ input: number;
7
+ output: number;
8
+ cacheRead: number;
9
+ cacheWrite: number;
10
+ totalTokens: number;
11
+ cost: number;
12
+ }
13
+ /** The whole-run usage summary rendered into `AgentHistoryList.usage`. */
14
+ export interface UsageSummary {
15
+ perModel: ModelUsageStats[];
16
+ totalTokens: number;
17
+ totalCost: number;
18
+ totalInvocations: number;
19
+ }
20
+ export declare class UsageLedger {
21
+ private readonly byModel;
22
+ /** Fold one LLM call's usage into the running totals for `model`. */
23
+ record(model: string, usage: Usage): void;
24
+ /** The end-of-run summary (per-model + grand totals). */
25
+ summary(): UsageSummary;
26
+ }
27
+ //# sourceMappingURL=ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/usage/ledger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsC;IAE9D,qEAAqE;IACrE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAwBzC,yDAAyD;IACzD,OAAO,IAAI,YAAY;CASxB"}