{"version":3,"sources":["../src/mcp/server.ts","../src/presence/wrap-tool-with-activity.ts","../src/undo/undo-tools.ts","../src/bridges/passkeys.ts"],"names":["emitActivity","undoOne","redoOne","readHistory","pushUndoEntry"],"mappings":";;;;;AAoOO,SAAS,UAAA,CAAW,MAAc,UAAA,EAAkC;AACzE,EAAA,OAAO;AAAA,IACL,SAAS,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,CAAA;AAAA,IAChC,GAAI,UAAA,KAAe,MAAA,GAAY,EAAE,iBAAA,EAAmB,UAAA,KAAe;AAAC,GACtE;AACF;AAEO,SAAS,YAAY,IAAA,EAA8B;AACxD,EAAA,OAAO,EAAE,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,QAAQ,IAAA,EAAM,CAAA,EAAG,OAAA,EAAS,IAAA,EAAK;AAC5D;;;AC9LO,SAAS,oBAAA,CACd,SACA,OAAA,EAmBoB;AACpB,EAAA,OAAO,OAAO,IAAA,KAAS;AACrB,IAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,IAAI,CAAA;AACjC,IAAA,IAAI,MAAA,CAAO,SAAS,OAAO,MAAA;AAE3B,IAAA,IAAI,MAAA;AACJ,IAAA,IAAI,QAAQ,aAAA,EAAe;AACzB,MAAA,MAAA,GAAS,OAAA,CAAQ,cAAc,EAAE,QAAA,EAAU,QAAQ,QAAA,EAAU,IAAA,EAAM,QAAQ,CAAA;AAAA,IAC7E,CAAA,MAAO;AACL,MAAA,MAAA,GAAS,EAAE,IAAA,EAAM,OAAA,CAAQ,IAAA,EAAM,QAAA,EAAU,QAAQ,QAAA,EAAS;AAAA,IAC5D;AACA,IAAA,IAAI,CAAC,QAAQ,OAAO,MAAA;AAEpB,IAAAA,4BAAA,CAAa;AAAA,MACX,OAAA,EAAS,QAAQ,KAAA,CAAM,EAAA;AAAA,MACvB,SAAA,EAAW,QAAQ,KAAA,CAAM,IAAA;AAAA,MACzB,UAAA,EAAY,QAAQ,KAAA,CAAM,KAAA;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IAAA,KAAS,KAAA,CAAA,GAAY,EAAC,GAAI,EAAE,IAAA,EAAK,EAAG;AACpF,MAAA,OAAO,UAAA;AAAA,QACL,oIAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF,CAAA;AAAA,IACA,CAAC,IAAA,KAAS,MAAA,CAAO,MAAA,EAAW,mBAAmB,IAAA,CAAK,IAAA,GAAO,CAAA,EAAA,EAAK,GAAA,CAAI,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAA,GAAM,EAAE,CAAA,CAAE;AAAA,GAC1F;AAOA,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,QAAA;AAAA,IACJ,KAAA,EAAO,QAAQ,KAAA,IAAS,UAAA;AAAA,IACxB,SAAS,MAAM;AACb,MAAA,KAAA,MAAW,CAAA,IAAK,SAAA,CAAU,MAAA,CAAO,CAAC,GAAG,CAAA,EAAE;AAAA,IACzC;AAAA,GACF;AACF","file":"bridges-passkeys.cjs","sourcesContent":["import {\n  type CallToolResult,\n  type JsonObject,\n  type JsonRpcMessage,\n  type JsonRpcRequest,\n  type JsonRpcId,\n  type RegisteredTool,\n  type ServerCapabilities,\n  type ServerInfo,\n  type ToolDefinition,\n  type ToolHandler,\n  JSONRPC_INTERNAL_ERROR,\n  JSONRPC_INVALID_PARAMS,\n  JSONRPC_METHOD_NOT_FOUND,\n  MCP_PROTOCOL_VERSION,\n} from \"./types\";\nimport { ToolRegistry } from \"./tool-host\";\n\nexport type McpServerOptions = {\n  info: ServerInfo;\n  /** Defaults to { tools: { listChanged: true } } */\n  capabilities?: ServerCapabilities;\n  /** Free-text instructions surfaced to clients during initialize. */\n  instructions?: string;\n  /**\n   * The protocol revisions this server speaks, NEWEST FIRST.\n   *\n   * `initialize` echoes the client's requested revision when it is in this\n   * list, and answers the first entry otherwise — the spec's rule, which leaves\n   * the client to decide whether it can live with the answer.\n   *\n   * Defaults to `[MCP_PROTOCOL_VERSION]`: one revision, answered whatever the\n   * client asks, which is exactly what this server did before the option\n   * existed. Only list a revision the tools you register are correct under.\n   */\n  protocolVersions?: readonly string[];\n};\n\nexport type Transport = {\n  /** Called by the server when it has a message to deliver to the client. */\n  send: (message: JsonRpcMessage) => void;\n  /** Called by the server when it's torn down so the transport can clean up. */\n  close?: () => void;\n};\n\n/**\n * MicroMcpServer — protocol-level MCP server, transport-agnostic.\n *\n * Use it like:\n *\n *   const server = new MicroMcpServer({ info: { name: \"session\", version: \"0.1\" } });\n *   server.registerTool({ name: \"...\", inputSchema: { type: \"object\" } }, async (args) => ({...}));\n *   const transport = new InProcessTransport();\n *   server.attach(transport);\n *   transport.deliver({ ... }); // client → server frames\n *\n * The same server can serve multiple transports (e.g. an in-process agent\n * AND a relayed external client) by attaching each one.\n */\nexport class MicroMcpServer extends ToolRegistry {\n  private transports = new Set<Transport>();\n  /**\n   * Transports owed a `tools/list_changed` at the end of this tick. Empty when\n   * none is scheduled. See {@link scheduleListChangedNotification}.\n   */\n  private listChangedOwed = new Set<Transport>();\n\n  readonly info: ServerInfo;\n  readonly capabilities: ServerCapabilities;\n  readonly instructions?: string;\n  readonly protocolVersions: readonly string[];\n\n  constructor(options: McpServerOptions) {\n    super();\n    this.info = options.info;\n    this.capabilities = options.capabilities ?? { tools: { listChanged: true } };\n    this.instructions = options.instructions;\n    if (options.protocolVersions && options.protocolVersions.length === 0) {\n      // No answer exists for a client's initialize. Fail here, next to the\n      // mistake, rather than in a handshake nobody is watching.\n      throw new Error(\"MicroMcpServer: protocolVersions is empty — a server must speak at least one protocol revision.\");\n    }\n    this.protocolVersions = options.protocolVersions ? [...options.protocolVersions] : [MCP_PROTOCOL_VERSION];\n  }\n\n  attach(transport: Transport): () => void {\n    this.transports.add(transport);\n    return () => this.detach(transport);\n  }\n\n  detach(transport: Transport): void {\n    if (this.transports.delete(transport)) {\n      transport.close?.();\n    }\n  }\n\n  unregisterTool(name: string): void {\n    if (this.tools.delete(name)) {\n      this.scheduleListChangedNotification();\n    }\n  }\n\n  protected onToolsChanged(): void {\n    this.scheduleListChangedNotification();\n  }\n\n  /**\n   * Receive a JSON-RPC frame from a client (called by the transport).\n   * The transport is responsible for sending the response back.\n   */\n  async receive(transport: Transport, message: JsonRpcMessage): Promise<void> {\n    if (!(\"method\" in message)) return; // It's a response, not a request — ignore.\n\n    const isNotification = !(\"id\" in message);\n    if (isNotification) {\n      // Notifications are fire-and-forget. We ignore unknown methods.\n      return;\n    }\n\n    const request = message as JsonRpcRequest;\n    try {\n      const result = await this.handle(request, transport);\n      transport.send({ jsonrpc: \"2.0\", id: request.id, result });\n    } catch (err) {\n      transport.send({\n        jsonrpc: \"2.0\",\n        id: request.id,\n        error: this.toRpcError(err),\n      });\n    }\n  }\n\n  private async handle(request: JsonRpcRequest, transport: Transport): Promise<any> {\n    const { method, params } = request;\n    switch (method) {\n      case \"initialize\":\n        return {\n          protocolVersion: this.negotiate(params?.protocolVersion),\n          capabilities: this.capabilities,\n          serverInfo: this.info,\n          ...(this.instructions ? { instructions: this.instructions } : {}),\n        };\n\n      case \"tools/list\":\n        return { tools: this.listTools() };\n\n      case \"tools/call\": {\n        const name = params?.name;\n        const args = (params?.arguments ?? {}) as JsonObject;\n        if (typeof name !== \"string\") {\n          throw rpcError(JSONRPC_INVALID_PARAMS, \"tools/call requires `name`\");\n        }\n        const tool = this.tools.get(name);\n        if (!tool) {\n          throw rpcError(JSONRPC_METHOD_NOT_FOUND, this.missingToolMessage(name));\n        }\n        const result = await tool.handler(args, { transport });\n        return result satisfies CallToolResult;\n      }\n\n      case \"ping\":\n        return {};\n\n      default:\n        throw rpcError(JSONRPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);\n    }\n  }\n\n  /** The revision to answer `initialize` with: the one asked for if spoken, else the newest. */\n  private negotiate(requested: unknown): string {\n    return typeof requested === \"string\" && this.protocolVersions.includes(requested)\n      ? requested\n      : this.protocolVersions[0];\n  }\n\n  /**\n   * Tell the transports that SAW the old tool list that it changed.\n   *\n   * Changes in one tick coalesce into one notification. The recipients are the\n   * transports attached at the moment of a change, not at the moment the\n   * notification goes out: a transport attached afterwards never had the old\n   * list, so \"your list is stale\" is noise to it — and on stdio, where a host\n   * builds the server and attaches stdin/stdout in the same tick, it was the\n   * first frame a client received, before it had even sent `initialize`.\n   */\n  private scheduleListChangedNotification(): void {\n    if (this.transports.size === 0) return;\n    const scheduled = this.listChangedOwed.size > 0;\n    for (const t of this.transports) this.listChangedOwed.add(t);\n    if (scheduled) return;\n    queueMicrotask(() => {\n      const owed = this.listChangedOwed;\n      this.listChangedOwed = new Set();\n      for (const t of owed) {\n        // Detached since the change: it is not listening any more.\n        if (this.transports.has(t)) t.send({ jsonrpc: \"2.0\", method: \"notifications/tools/list_changed\" });\n      }\n    });\n  }\n\n  /** Send an application notification to every client, or one attached transport. */\n  notify(message: JsonRpcMessage, transport?: Transport): void {\n    if (transport) transport.send(message);\n    else this.broadcast(message);\n  }\n\n  private broadcast(message: JsonRpcMessage): void {\n    for (const t of this.transports) t.send(message);\n  }\n\n  private toRpcError(err: unknown): { code: number; message: string; data?: any } {\n    if (err && typeof err === \"object\" && \"code\" in err && \"message\" in err) {\n      return err as any;\n    }\n    return {\n      code: JSONRPC_INTERNAL_ERROR,\n      message: err instanceof Error ? err.message : String(err),\n    };\n  }\n}\n\nexport function rpcError(code: number, message: string, data?: any) {\n  return { code, message, ...(data !== undefined ? { data } : {}) };\n}\n\n/**\n * Helper to build a CallToolResult from a string or structured value.\n */\nexport function textResult(text: string, structured?: any): CallToolResult {\n  return {\n    content: [{ type: \"text\", text }],\n    ...(structured !== undefined ? { structuredContent: structured } : {}),\n  };\n}\n\nexport function errorResult(text: string): CallToolResult {\n  return { content: [{ type: \"text\", text }], isError: true };\n}\n\n// Internal helper so the JsonRpcId import isn't dropped by tsup\ntype _KeepIdImport = JsonRpcId;\n","import type { CallToolResult } from \"../mcp/types\";\nimport { emitActivity } from \"./registry\";\nimport type { AgentTarget } from \"./types\";\n\nexport type ActivityAgent = { id: string; name?: string; color?: string };\n\nexport type ActivityResolverContext<TArgs = Record<string, unknown>> = {\n  /** Tool name as registered. */\n  toolName: string;\n  /** Arguments the tool was called with. */\n  args: TArgs;\n  /** The CallToolResult the underlying handler produced. */\n  result: CallToolResult;\n};\n\n/**\n * Resolves an `AgentTarget` for an executed tool. Bridges declare one of\n * these per registration so the wrapper knows which surface / element /\n * screen the activity belongs to.\n *\n * The resolver runs AFTER the tool handler so it can inspect the result\n * (e.g. read a newly-created item id from `structuredContent`).\n */\nexport type ActivityTargetResolver<TArgs = Record<string, unknown>> = (\n  ctx: ActivityResolverContext<TArgs>,\n) => AgentTarget | null;\n\nexport type ToolHandler<TArgs = Record<string, unknown>> = (\n  args: TArgs,\n) => Promise<CallToolResult> | CallToolResult;\n\n/**\n * wrapToolWithActivity — decorate a bridge tool handler so every successful\n * call emits an `AgentActivityEvent`. Returns a new handler with the same shape.\n *\n * Usage in a bridge:\n *\n *   server.registerTool(\n *     definition,\n *     wrapToolWithActivity(\n *       handler,\n *       { agent, kind: \"whiteboard\", resolveTarget: ({ args }) => ({\n *           kind: \"whiteboard\", elementId: args.id as string,\n *         }) },\n *     ),\n *   );\n */\nexport function wrapToolWithActivity<TArgs = Record<string, unknown>>(\n  handler: ToolHandler<TArgs>,\n  options: {\n    toolName: string;\n    agent: ActivityAgent;\n    /** Optional fancy-screens screen id this bridge is scoped to. */\n    screenId?: string;\n    /** Default target kind if the resolver returns one without `kind`. */\n    kind: AgentTarget[\"kind\"];\n    /** Per-call resolver. Return `null` to skip emitting (e.g. for read-only tools). */\n    resolveTarget?: ActivityTargetResolver<TArgs>;\n    /** Optional ttl override. */\n    ttlMs?: number;\n    /**\n     * Build the `meta` broadcast to all relay peers. Defaults to the tool's full\n     * `structuredContent`. Override to REDACT sensitive fields before fan-out —\n     * e.g. the terminal bridge strips raw command/keystroke bytes so a command\n     * line (or its secrets) is never broadcast verbatim to every peer.\n     */\n    buildMeta?: (result: CallToolResult) => Record<string, unknown> | undefined;\n  },\n): ToolHandler<TArgs> {\n  return async (args) => {\n    const result = await handler(args);\n    if (result.isError) return result;\n\n    let target: AgentTarget | null;\n    if (options.resolveTarget) {\n      target = options.resolveTarget({ toolName: options.toolName, args, result });\n    } else {\n      target = { kind: options.kind, screenId: options.screenId };\n    }\n    if (!target) return result;\n\n    emitActivity({\n      agentId: options.agent.id,\n      agentName: options.agent.name,\n      agentColor: options.agent.color,\n      target: { ...target, kind: target.kind ?? options.kind, screenId: target.screenId ?? options.screenId },\n      action: options.toolName,\n      timestamp: Date.now(),\n      meta: options.buildMeta ? options.buildMeta(result) : extractMeta(result),\n      ttlMs: options.ttlMs,\n    });\n    return result;\n  };\n}\n\nfunction extractMeta(result: CallToolResult): Record<string, unknown> | undefined {\n  const sc = result.structuredContent;\n  if (sc && typeof sc === \"object\" && !Array.isArray(sc)) {\n    return sc as Record<string, unknown>;\n  }\n  return undefined;\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport { readHistory, redoOne, undoOne } from \"./undo-stack\";\n\nexport type UndoToolsOptions = {\n  /** Default agent id when the caller doesn't pass one. */\n  defaultAgentId?: string;\n};\n\n/**\n * Idempotent tracker so multiple bridges on the same server only register\n * agent_undo / agent_redo / agent_history once.\n */\nconst installedHosts = new WeakSet<ToolHost>();\n\n/**\n * The one owner every copy of the undo tools registers under. They are SHARED\n * on purpose — every bridge ensures them, and a host may also call\n * `registerUndoTools` itself — so all of those are the same registrant, and a\n * second registration replaces the first instead of being refused as a\n * collision. Anything else claiming `agent_undo` is still refused.\n */\nconst UNDO_TOOLS_OWNER = \"agent-undo\";\n\n/**\n * ensureUndoToolsRegistered — bridges call this on construction. Safe to\n * call repeatedly with the same server; subsequent calls are no-ops.\n */\nexport function ensureUndoToolsRegistered(host: ToolHost, options: UndoToolsOptions = {}): void {\n  if (installedHosts.has(host)) return;\n  installedHosts.add(host);\n  registerUndoTools(host, options);\n}\n\n/**\n * registerUndoTools — add agent_undo / agent_redo / agent_history to the\n * server. Returns a disposer that unregisters all three.\n */\nexport function registerUndoTools(host: ToolHost, options: UndoToolsOptions = {}): () => void {\n  const defaultAgent = options.defaultAgentId ?? \"agent\";\n  const disposers: Array<() => void> = [];\n  const agentOf = (args: any): string =>\n    typeof args?.agentId === \"string\" ? args.agentId : defaultAgent;\n\n  disposers.push(\n    host.registerTool(\n      {\n        name: \"agent_undo\",\n        description: \"Undo the most recent action on the agent's stack. Optional agentId targets a specific agent.\",\n        inputSchema: {\n          type: \"object\",\n          properties: { agentId: { type: \"string\" } },\n          additionalProperties: false,\n        },\n      },\n      async (args) => {\n        const entry = await undoOne(agentOf(args));\n        if (!entry) return errorResult(\"Nothing to undo.\");\n        return textResult(`Undid: ${entry.label}`, { entry: serialize(entry) });\n      },\n      { owner: UNDO_TOOLS_OWNER },\n    ),\n  );\n\n  disposers.push(\n    host.registerTool(\n      {\n        name: \"agent_redo\",\n        description: \"Redo the most recently undone action.\",\n        inputSchema: {\n          type: \"object\",\n          properties: { agentId: { type: \"string\" } },\n          additionalProperties: false,\n        },\n      },\n      async (args) => {\n        const entry = await redoOne(agentOf(args));\n        if (!entry) return errorResult(\"Nothing to redo.\");\n        return textResult(`Redid: ${entry.label}`, { entry: serialize(entry) });\n      },\n      { owner: UNDO_TOOLS_OWNER },\n    ),\n  );\n\n  disposers.push(\n    host.registerTool(\n      {\n        name: \"agent_history\",\n        description: \"List the agent's undo stack (oldest first). Useful for understanding what's reversible.\",\n        inputSchema: {\n          type: \"object\",\n          properties: { agentId: { type: \"string\" } },\n          additionalProperties: false,\n        },\n      },\n      async (args) => {\n        const history = readHistory(agentOf(args)).map(serialize);\n        const text = history.map((e) => `${new Date(e.timestamp).toISOString()} ${e.bridgeId} ${e.action}: ${e.label}`).join(\"\\n\");\n        return textResult(text || \"(empty)\", history);\n      },\n      { owner: UNDO_TOOLS_OWNER },\n    ),\n  );\n\n  return () => disposers.forEach((d) => d());\n}\n\nfunction serialize(entry: import(\"./undo-stack\").UndoEntry) {\n  return {\n    timestamp: entry.timestamp,\n    bridgeId: entry.bridgeId,\n    action: entry.action,\n    label: entry.label,\n  };\n}\n","import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\n\n/**\n * Bridge for `@particle-academy/fancy-passkeys-ui` — the **management** half of\n * a passkey (WebAuthn) surface, and only that half.\n *\n * ## The absence is the design\n *\n * There is **no tool here that completes an authentication or registration\n * ceremony**, and there must never be one. Not `passkey_authenticate`, not\n * `passkey_sign_in`, not `passkey_complete`, not a \"headless\" variant behind a\n * flag.\n *\n * The reason is construction, not policy. `navigator.credentials.get()` requires\n * a user gesture and a biometric or PIN — both things only the person at the\n * keyboard has. An agent-drivable passkey login would be a bypass of the exact\n * property that makes a passkey worth more than a password: that possession of\n * the credential cannot be delegated, replayed, or phished. A bridge offering\n * one would quietly turn a phishing-resistant factor back into a bearer token.\n *\n * So the boundary sits where the cryptography already puts it, and the tool set\n * is drawn to match: **read the management surface, rename, propose, ask the\n * human to start a ceremony.** `bridges/__tests__/passkeys.test.ts` asserts the\n * registered tool names against a closed list, so \"finishing\" this bridge with a\n * sign-in tool fails CI rather than shipping.\n *\n * ## What it does do\n *\n *   passkey_list              the user's credentials (whitelisted fields only)\n *   passkey_status            browser support + what the surface currently shows\n *   passkey_rename            relabel one credential, by credential ID (undoable)\n *   passkey_revoke            **STAGES** a revoke for the human to confirm\n *   passkey_begin_enrollment  opens the enrollment prompt; returns immediately\n *\n * `passkey_revoke` never revokes. Revoking a passkey is destructive and revoking\n * the last one is a lockout, so the confirming click comes from the human at the\n * surface — there is deliberately **no `pendingMode: false`**, no `confirm: true`\n * argument, and no host hook that turns staging off. On this bridge staging is\n * not a mode.\n *\n * The adapter type is declared LOCALLY (like `features` / `catalog`) so the\n * bridge builds and type-checks with the sibling package absent. A host wiring a\n * live `PasskeyManager` satisfies it structurally, with no import.\n */\n\n/**\n * One credential as the bridge is willing to describe it — the `PasskeySummary`\n * shape both passkey backends already serialise.\n *\n * Everything the server stores that is NOT on this list — the COSE public key,\n * the user handle, the signature counter, the attestation statement and trust\n * path — is absent on purpose, and {@link toSummary} re-projects onto exactly\n * these keys rather than trusting the adapter to have withheld them. A host that\n * hands `list()` its raw ORM model (the obvious thing to do) therefore cannot\n * leak credential material through an MCP tool by accident.\n */\nexport type PasskeySummaryLike = {\n  /** base64url credential ID — the handle every action here is keyed by. */\n  id: string;\n  /** Human-chosen label, or null when the user never named it. */\n  name: string | null;\n  /** ISO-8601. */\n  createdAt: string;\n  /** ISO-8601, or null when never used to sign in. */\n  lastUsedAt: string | null;\n  /** Transport hints (\"internal\", \"hybrid\", \"usb\", …). */\n  transports: string[];\n  /** True for a synced passkey (BE/BS flags); false means this device only. */\n  backedUp: boolean;\n  /** Authenticator model id. Stored, never a trust decision. */\n  aaguid: string;\n  /** ISO-8601 when the signature counter regressed — a suspected clone. */\n  clonedAt: string | null;\n};\n\n/** What the browser can do, as the three `./client` predicates report it. */\nexport type PasskeySupport = {\n  supported: boolean;\n  /** Touch ID / Windows Hello present? `null` while unknown. */\n  platformAuthenticator?: boolean | null;\n  /** Can the browser offer a passkey from a username field? `null` while unknown. */\n  conditionalUi?: boolean | null;\n};\n\n/** A read of what the management surface is currently showing. */\nexport type PasskeySurfaceState = {\n  status?: \"idle\" | \"busy\" | \"error\";\n  /** `{ code, message }` as carried in surface state — never an Error. */\n  error?: { code: string; message: string } | null;\n  /** The revoke awaiting a human's confirmation, if any. */\n  pendingRevoke?: { id: string; isLastPasskey: boolean } | null;\n  /** Credential ID currently being renamed, if any. */\n  renamingId?: string | null;\n};\n\n/**\n * Host-provided access to the management surface. Mirrors the props a\n * `PasskeyManager` is already wired with, so a host usually passes the same four\n * callbacks it passed the component.\n */\nexport type PasskeyBridgeAdapter = {\n  /** Stable id for this surface instance. Surfaces in activity logs. */\n  id?: string;\n  title?: string;\n  screenId?: string;\n\n  /** The signed-in user's credentials. */\n  list(): PasskeySummaryLike[] | Promise<PasskeySummaryLike[]>;\n\n  /** Relabel one credential. Cosmetic, reversible, and undoable here. */\n  rename(input: { id: string; name: string }): void | Promise<void>;\n\n  /**\n   * **Stage** a revoke for human confirmation — the `pendingRevoke` the surface\n   * renders a confirm/cancel dialog for. It must NOT revoke; a host that wires\n   * this to a delete call has removed the human from the loop the bridge was\n   * built around.\n   */\n  proposeRevoke(input: { id: string }): PasskeyProposal | Promise<PasskeyProposal>;\n\n  /**\n   * Open the enrollment prompt on the human's screen and return immediately.\n   * The ceremony completes on their authenticator or not at all.\n   */\n  beginEnrollment?(input: { name?: string }): void | Promise<void>;\n\n  /** Browser capability flags, if the host tracks them. */\n  support?(): PasskeySupport | Promise<PasskeySupport>;\n\n  /** What the surface currently shows. */\n  state?(): PasskeySurfaceState | Promise<PasskeySurfaceState>;\n};\n\nexport type PasskeyProposal = { staged: true; isLastPasskey: boolean };\n\nexport type PasskeyBridgeOptions = {\n  adapter: PasskeyBridgeAdapter;\n  agent?: { id: string; name?: string; color?: string };\n  /**\n   * Also route `passkey_rename` through {@link confirm}. Off by default: a\n   * rename is cosmetic, reversible and pushed onto the undo stack. Worth turning\n   * on where the label itself carries trust — a rogue credential relabelled\n   * \"Avery's iPhone\" survives a human's audit of the list.\n   */\n  confirmRename?: boolean;\n  /**\n   * Host confirmation hook for renames, when {@link confirmRename} is on.\n   *\n   * Note there is no revoke case: a revoke is staged into the surface and\n   * confirmed there, never through a hook the agent's own host supplies.\n   */\n  confirm?: (req: { action: \"passkey_rename\"; id: string; name: string }) => boolean | Promise<boolean>;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst str = (v: unknown, fallback = \"\"): string => (typeof v === \"string\" ? v : fallback);\n\n/**\n * Project an adapter record onto exactly the public summary fields.\n *\n * Deliberately a whitelist and not a `delete` of known-bad keys: a blacklist has\n * to be updated every time a backend grows a column, and the failure mode of\n * forgetting is silently publishing credential material to every agent in the\n * session.\n */\nfunction toSummary(record: PasskeySummaryLike): PasskeySummaryLike {\n  return {\n    id: str(record?.id),\n    name: typeof record?.name === \"string\" ? record.name : null,\n    createdAt: str(record?.createdAt),\n    lastUsedAt: typeof record?.lastUsedAt === \"string\" ? record.lastUsedAt : null,\n    transports: Array.isArray(record?.transports) ? record.transports.map((t) => String(t)) : [],\n    backedUp: record?.backedUp === true,\n    aaguid: str(record?.aaguid),\n    clonedAt: typeof record?.clonedAt === \"string\" ? record.clonedAt : null,\n  };\n}\n\n/**\n * The complete set of tools this bridge may ever register.\n *\n * Exported so the test suite — and anyone auditing what an agent can reach —\n * can assert the registered names against it rather than eyeballing the file.\n */\nexport const PASSKEY_BRIDGE_TOOLS = [\n  \"passkey_list\",\n  \"passkey_status\",\n  \"passkey_rename\",\n  \"passkey_revoke\",\n  \"passkey_begin_enrollment\",\n] as const;\n\n/**\n * registerPasskeyBridge — MCP tools over a passkey **management** surface.\n *\n * Read the credential list, read browser support and surface state, rename a\n * credential, propose a revoke for the human to confirm, and ask for an\n * enrollment prompt. Nothing signs anyone in; see the file header for why that\n * is a property rather than a gap.\n */\nexport function registerPasskeyBridge(host: ToolHost, options: PasskeyBridgeOptions): Bridge {\n  const { adapter } = options;\n  const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n  const surfaceId = adapter.id ?? \"passkeys\";\n  const disposers: Array<() => void> = [];\n  // The bridge id is also its registrant identity on the host: the same bridge\n  // may re-register (a remount), a different one claiming a name is refused.\n  const bridgeId = `passkeys:${surfaceId}`;\n\n  ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n  const target = (elementId?: string, label?: string): AgentTarget => ({\n    kind: \"custom\",\n    screenId: adapter.screenId,\n    elementId,\n    label: label ?? surfaceId,\n  });\n\n  const reg = (\n    name: string,\n    description: string,\n    properties: Record<string, unknown>,\n    required: string[],\n    handler: (args: JsonObject) => Promise<unknown> | unknown,\n    resolveTarget: false | ((args: JsonObject) => AgentTarget),\n  ) => {\n    const wrapped = async (args: JsonObject) => {\n      try {\n        return await handler(args);\n      } catch (e) {\n        return errorResult(e instanceof Error ? e.message : String(e));\n      }\n    };\n    const final = resolveTarget\n      ? wrapToolWithActivity(wrapped as never, {\n          toolName: name,\n          agent,\n          kind: \"custom\",\n          screenId: adapter.screenId,\n          resolveTarget: ({ args }) => resolveTarget(args as JsonObject),\n        })\n      : wrapped;\n    disposers.push(\n      host.registerTool(\n        {\n          name,\n          description,\n          inputSchema: {\n            type: \"object\",\n            properties: properties as Record<string, never>,\n            required,\n            additionalProperties: false,\n          },\n        },\n        final as never,\n        { owner: bridgeId },\n      ),\n    );\n  };\n\n  const findById = async (id: string): Promise<PasskeySummaryLike | null> =>\n    (await adapter.list()).map(toSummary).find((p) => p.id === id) ?? null;\n\n  // ─── Read ────────────────────────────────────────────────────────────────\n\n  reg(\n    \"passkey_list\",\n    \"List the signed-in user's passkeys: credential id, label, when it was added and last used, transports, whether it is a synced passkey, and whether the server flagged it as a possible clone. Read-only. Public keys, user handles and signature counters are never returned.\",\n    {},\n    [],\n    async () => {\n      const passkeys = (await adapter.list()).map(toSummary);\n      return textResult(JSON.stringify(passkeys, null, 2), { passkeys, count: passkeys.length });\n    },\n    false,\n  );\n\n  reg(\n    \"passkey_status\",\n    \"Read what this browser can do (passkey support, a built-in authenticator, autofill sign-in) and what the management surface is currently showing (busy/error, a revoke awaiting confirmation, a rename in progress).\",\n    {},\n    [],\n    async () => {\n      const support = adapter.support ? await adapter.support() : null;\n      const state = adapter.state ? await adapter.state() : null;\n      const out = {\n        support,\n        state,\n        // Said in the payload, not only in the docs: an agent reading this to\n        // work out \"how do I sign the user in\" should find the answer here.\n        canCompleteCeremony: false,\n        note: \"A passkey ceremony needs a user gesture and a biometric or PIN. No tool on this bridge can perform one; ask the human to complete it on their device.\",\n      };\n      return textResult(JSON.stringify(out, null, 2), out);\n    },\n    false,\n  );\n\n  // ─── Rename (undoable) ───────────────────────────────────────────────────\n\n  reg(\n    \"passkey_rename\",\n    \"Rename one passkey, by credential id (from passkey_list). Cosmetic and undoable with agent_undo.\",\n    {\n      id: { type: \"string\", description: \"base64url credential id.\" },\n      name: { type: \"string\", description: \"New label, e.g. 'MacBook Touch ID'. Empty string clears it.\" },\n    },\n    [\"id\", \"name\"],\n    async (args) => {\n      const id = str(args.id);\n      const name = str(args.name);\n      if (!id) return errorResult(\"id is required.\");\n\n      const existing = await findById(id);\n      if (!existing) return errorResult(`No passkey with id ${id}.`);\n\n      if (options.confirmRename) {\n        if (!options.confirm) {\n          return errorResult(\n            \"passkey_rename requires confirmation (confirmRename), but the host wired no confirm hook.\",\n          );\n        }\n        const ok = await options.confirm({ action: \"passkey_rename\", id, name });\n        if (!ok) return errorResult(`Declined: rename ${id} (human did not confirm).`);\n      }\n\n      const previous = existing.name ?? \"\";\n      await adapter.rename({ id, name });\n      pushUndoEntry(agent.id, {\n        timestamp: Date.now(),\n        bridgeId: surfaceId,\n        action: \"passkey_rename\",\n        label: `Renamed passkey to ${name || \"(unnamed)\"}`,\n        undo: async () => { await adapter.rename({ id, name: previous }); },\n        redo: async () => { await adapter.rename({ id, name }); },\n      });\n\n      return textResult(`Renamed passkey ${id} to ${name || \"(unnamed)\"}`, { id, name, previous });\n    },\n    (args) => target(str(args.id), `rename ${str(args.id)}`),\n  );\n\n  // ─── Revoke — PROPOSAL ONLY ──────────────────────────────────────────────\n\n  reg(\n    \"passkey_revoke\",\n    \"PROPOSE revoking one passkey. This does NOT revoke it: the request is staged on the surface and the human confirms or cancels there. Revoking the last passkey can lock the user out, and the response says when that is the case so you can tell them before they confirm.\",\n    { id: { type: \"string\", description: \"base64url credential id.\" } },\n    [\"id\"],\n    async (args) => {\n      const id = str(args.id);\n      if (!id) return errorResult(\"id is required.\");\n\n      const existing = await findById(id);\n      if (!existing) return errorResult(`No passkey with id ${id}.`);\n\n      const proposal = await adapter.proposeRevoke({ id });\n      const isLastPasskey = proposal?.isLastPasskey === true;\n      const out = {\n        id,\n        name: existing.name,\n        staged: true as const,\n        awaitingHuman: true as const,\n        isLastPasskey,\n      };\n\n      return textResult(\n        isLastPasskey\n          ? `Staged a revoke of ${existing.name ?? id}. This is the account's LAST passkey — confirming it removes passkey sign-in entirely. Waiting for the human to confirm or cancel.`\n          : `Staged a revoke of ${existing.name ?? id}. Waiting for the human to confirm or cancel on the surface.`,\n        out,\n      );\n    },\n    (args) => target(str(args.id), `propose revoke ${str(args.id)}`),\n  );\n\n  // ─── Enrollment — opens the prompt, never completes it ───────────────────\n\n  reg(\n    \"passkey_begin_enrollment\",\n    \"Ask the surface to start enrolling a new passkey. This only opens the prompt: the ceremony completes on the human's authenticator (Touch ID, Windows Hello, phone, security key) or it does not complete at all. Returns immediately.\",\n    { name: { type: \"string\", description: \"Optional label to pre-fill for the new passkey.\" } },\n    [],\n    async (args) => {\n      if (!adapter.beginEnrollment) return errorResult(\"Host did not wire beginEnrollment().\");\n      const name = args.name === undefined ? undefined : str(args.name);\n      await adapter.beginEnrollment(name === undefined ? {} : { name });\n      const out = { awaitingHuman: true as const, ...(name === undefined ? {} : { name }) };\n      return textResult(\n        \"Enrollment prompt opened. The human has to complete it on their authenticator — there is no tool that can finish it for them.\",\n        out,\n      );\n    },\n    (args) => target(undefined, `begin enrollment${args.name ? ` (${str(args.name)})` : \"\"}`),\n  );\n\n  // ── There is deliberately NO tool below that completes a ceremony. ────────\n  // No passkey_authenticate, no passkey_sign_in, no passkey_complete, no\n  // passkey_assert. Do not \"finish\" this bridge by adding one — see the header,\n  // and see the closed-tool-list test that will fail if you do.\n\n  return {\n    id: bridgeId,\n    title: adapter.title ?? \"Passkeys\",\n    dispose: () => {\n      for (const d of disposers.splice(0)) d();\n    },\n  };\n}\n"]}