@ai-matrx/summon 0.0.0 → 0.1.1

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 (87) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +379 -1
  4. package/dist/closeBinding-C6raC3qJ.d.cts +20 -0
  5. package/dist/closeBinding-C6raC3qJ.d.ts +20 -0
  6. package/dist/dialog.cjs +60 -0
  7. package/dist/dialog.cjs.map +1 -0
  8. package/dist/dialog.d.cts +16 -0
  9. package/dist/dialog.d.ts +16 -0
  10. package/dist/dialog.js +38 -0
  11. package/dist/dialog.js.map +1 -0
  12. package/dist/errors-eJrKXq33.d.cts +30 -0
  13. package/dist/errors-eJrKXq33.d.ts +30 -0
  14. package/dist/handles.cjs +411 -0
  15. package/dist/handles.cjs.map +1 -0
  16. package/dist/handles.d.cts +166 -0
  17. package/dist/handles.d.ts +166 -0
  18. package/dist/handles.js +388 -0
  19. package/dist/handles.js.map +1 -0
  20. package/dist/index.cjs +2383 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +1259 -0
  23. package/dist/index.d.ts +1259 -0
  24. package/dist/index.js +2363 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/lite.cjs +460 -0
  27. package/dist/lite.cjs.map +1 -0
  28. package/dist/lite.d.cts +56 -0
  29. package/dist/lite.d.ts +56 -0
  30. package/dist/lite.js +444 -0
  31. package/dist/lite.js.map +1 -0
  32. package/dist/next.cjs +61 -0
  33. package/dist/next.cjs.map +1 -0
  34. package/dist/next.d.cts +5 -0
  35. package/dist/next.d.ts +5 -0
  36. package/dist/next.js +39 -0
  37. package/dist/next.js.map +1 -0
  38. package/dist/persistence-data.cjs +143 -0
  39. package/dist/persistence-data.cjs.map +1 -0
  40. package/dist/persistence-data.d.cts +72 -0
  41. package/dist/persistence-data.d.ts +72 -0
  42. package/dist/persistence-data.js +120 -0
  43. package/dist/persistence-data.js.map +1 -0
  44. package/dist/persistence.cjs +1073 -0
  45. package/dist/persistence.cjs.map +1 -0
  46. package/dist/persistence.d.cts +236 -0
  47. package/dist/persistence.d.ts +236 -0
  48. package/dist/persistence.js +1077 -0
  49. package/dist/persistence.js.map +1 -0
  50. package/dist/react.cjs +738 -0
  51. package/dist/react.cjs.map +1 -0
  52. package/dist/react.d.cts +266 -0
  53. package/dist/react.d.ts +266 -0
  54. package/dist/react.js +723 -0
  55. package/dist/react.js.map +1 -0
  56. package/dist/sheet.cjs +71 -0
  57. package/dist/sheet.cjs.map +1 -0
  58. package/dist/sheet.d.cts +17 -0
  59. package/dist/sheet.d.ts +17 -0
  60. package/dist/sheet.js +49 -0
  61. package/dist/sheet.js.map +1 -0
  62. package/dist/styles.css +78 -0
  63. package/dist/testing.cjs +132 -0
  64. package/dist/testing.cjs.map +1 -0
  65. package/dist/testing.d.cts +44 -0
  66. package/dist/testing.d.ts +44 -0
  67. package/dist/testing.js +115 -0
  68. package/dist/testing.js.map +1 -0
  69. package/dist/url.cjs +362 -0
  70. package/dist/url.cjs.map +1 -0
  71. package/dist/url.d.cts +153 -0
  72. package/dist/url.d.ts +153 -0
  73. package/dist/url.js +352 -0
  74. package/dist/url.js.map +1 -0
  75. package/dist/window-host.cjs +123 -0
  76. package/dist/window-host.cjs.map +1 -0
  77. package/dist/window-host.d.cts +72 -0
  78. package/dist/window-host.d.ts +72 -0
  79. package/dist/window-host.js +104 -0
  80. package/dist/window-host.js.map +1 -0
  81. package/dist/window.cjs +3977 -0
  82. package/dist/window.cjs.map +1 -0
  83. package/dist/window.d.cts +796 -0
  84. package/dist/window.d.ts +796 -0
  85. package/dist/window.js +4002 -0
  86. package/dist/window.js.map +1 -0
  87. package/package.json +239 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/url.ts","../src/url/useOverlayLink.ts","../src/url/grammar.ts","../src/url/OverlayLinkManager.tsx","../src/url/door.ts"],"sourcesContent":["// @ai-matrx/summon/url — address-bar links: the `?panels=` grammar, the link manager, the\n// `useOverlayLink` publisher and the one door (`openFromLink`) every link source goes through.\nexport { useOverlayLink } from \"./url/useOverlayLink\";\nexport {\n parseLinkToken,\n parseLinkParam,\n formatLinkToken,\n encodeLinkId,\n encodeLinkArg,\n decodeLinkPart,\n readPanelsParam,\n withPanelsParam,\n type LinkToken,\n type LinkEntry,\n} from \"./url/grammar\";\nexport {\n OverlayLinkManager,\n serializeLinkEntries,\n mergeManagedLinkParam,\n withUnresolvedTokens,\n unopenedWindowNotice,\n type OverlayLinkManagerProps,\n} from \"./url/OverlayLinkManager\";\nexport {\n openFromLink,\n openPanelRequest,\n hydrateLinkToken,\n canonicalLinkKey,\n canonicalizeToken,\n openRegisteredOverlay,\n type OpenFromLinkResult,\n type OpenFromLinkOptions,\n type OpenPanelRequest,\n type OpenPanelResult,\n type TokenOutcome,\n type LinkDispatch,\n} from \"./url/door\";\n","import { useEffect, useMemo } from \"react\";\nimport { registerSyncEntry, unregisterSyncEntry } from \"@ai-matrx/summon\";\nimport { useSummonDispatch } from \"@ai-matrx/summon/react\";\n\n/**\n * Publish an open instance's address into `?panels=` while it is mounted. `linkKey` undefined →\n * nothing is published (a window with no link); so is an undefined or empty `id`. The token is `linkKey:id[:args]`; args are\n * compared by value, so a new object with equal contents never re-registers.\n */\nexport function useOverlayLink(linkKey: string | undefined, id: string | undefined, args?: Readonly<Record<string, string>>): void {\n const dispatch = useSummonDispatch();\n const argsKey = args\n ? JSON.stringify(\n Object.keys(args)\n .sort()\n .map((k) => [k, args[k]]),\n )\n : \"\";\n // Rebuilt only when the VALUES change (argsKey), never on a fresh object with equal contents.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableArgs = useMemo(() => (args ? { ...args } : undefined), [argsKey]);\n\n useEffect(() => {\n if (!linkKey || !id) return undefined;\n dispatch(registerSyncEntry(stableArgs ? { typeKey: linkKey, instanceId: id, args: stableArgs } : { typeKey: linkKey, instanceId: id }));\n return () => {\n dispatch(unregisterSyncEntry({ typeKey: linkKey, instanceId: id }));\n };\n }, [dispatch, linkKey, id, stableArgs]);\n}\n","/**\n * The `?panels=` link grammar.\n *\n * panels = token (\",\" token)*\n * token = key [\":\" id [\":\" args]]\n * args = k \"-\" v (\"_\" k \"-\" v)*\n *\n * GRAMMAR v2 (this file): on WRITE, ids are percent-encoded for `% , :` and arg keys and values\n * for `% , : _ -`, so any value — a uuid, a date, a path, a list — survives the round trip.\n * Keys and ids keep `-` and `_` unencoded: they are not separators inside an id, and leaving them means a\n * uuid id writes byte-identically to v1. On READ, v1 tokens (unencoded) parse unchanged: an arg\n * pair splits on its FIRST hyphen, and decoding only touches well-formed `%XX` escapes.\n *\n * Framework-free; this is the one grammar every door (address bar, notifications, extension)\n * shares.\n */\n\nexport interface LinkToken {\n /** The token exactly as it appeared (the verbatim form written back while unresolved). */\n readonly raw: string;\n readonly key: string;\n /** `undefined` for a bare-key token (`keyword_research`). */\n readonly id: string | undefined;\n /** `undefined` when the token carries no args segment. */\n readonly args: Readonly<Record<string, string>> | undefined;\n}\n\nexport interface LinkEntry {\n readonly key: string;\n readonly id: string;\n readonly args?: Readonly<Record<string, string>> | undefined;\n}\n\nconst hex = (ch: string): string => `%${ch.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\")}`;\n\n/** Encode a token id (`% , :`). */\nexport function encodeLinkId(id: string): string {\n return id.replace(/[%,:]/g, hex);\n}\n\n/** Encode an arg key or value (`% , : _ -`). */\nexport function encodeLinkArg(value: string): string {\n return value.replace(/[%,:_-]/g, hex);\n}\n\n/** Decode well-formed `%XX` escapes; anything else (a v1 literal `%`) is kept as written. */\nexport function decodeLinkPart(value: string): string {\n if (!value.includes(\"%\")) return value;\n return value.replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {\n try {\n return decodeURIComponent(run);\n } catch {\n return run;\n }\n });\n}\n\n/** Parse one token (v1 or v2). Returns `null` for an empty token. */\nexport function parseLinkToken(raw: string): LinkToken | null {\n if (!raw) return null;\n const first = raw.indexOf(\":\");\n const key = first === -1 ? raw : raw.slice(0, first);\n if (!key) return null;\n if (first === -1) return { raw, key, id: undefined, args: undefined };\n const rest = raw.slice(first + 1);\n const second = rest.indexOf(\":\");\n const idPart = second === -1 ? rest : rest.slice(0, second);\n const argsPart = second === -1 ? undefined : rest.slice(second + 1);\n let args: Record<string, string> | undefined;\n if (argsPart) {\n args = {};\n for (const pair of argsPart.split(\"_\")) {\n // Split on the FIRST hyphen only: a v1 value may hold hyphens (uuid, date).\n const at = pair.indexOf(\"-\");\n if (at <= 0 || at === pair.length - 1) continue;\n args[decodeLinkPart(pair.slice(0, at))] = decodeLinkPart(pair.slice(at + 1));\n }\n }\n return { raw, key: decodeLinkPart(key), id: decodeLinkPart(idPart), args };\n}\n\n/** Parse a whole `panels` value. Empty segments are skipped. */\nexport function parseLinkParam(param: string | null | undefined): LinkToken[] {\n if (!param) return [];\n const out: LinkToken[] = [];\n for (const raw of param.split(\",\")) {\n const token = parseLinkToken(raw);\n if (token) out.push(token);\n }\n return out;\n}\n\n/** Write one entry as a v2 token. Args are written in key order so equal entries write equal tokens. */\nexport function formatLinkToken(entry: LinkEntry): string {\n let token = `${encodeLinkId(entry.key)}:${encodeLinkId(entry.id)}`;\n const args = entry.args;\n if (args) {\n const keys = Object.keys(args).sort();\n if (keys.length > 0) {\n token += `:${keys.map((k) => `${encodeLinkArg(k)}-${encodeLinkArg(args[k] ?? \"\")}`).join(\"_\")}`;\n }\n }\n return token;\n}\n\n/** The `panels` value from a search string or a full URL (`null` when absent). */\nexport function readPanelsParam(searchOrUrl: string): string | null {\n const q = searchOrUrl.indexOf(\"?\");\n const hash = searchOrUrl.indexOf(\"#\");\n let search: string;\n if (q === -1) {\n // A bare query string without \"?\" (`panels=…`) or a URL with no query.\n search = searchOrUrl.includes(\"=\") && !searchOrUrl.includes(\"/\") ? searchOrUrl : \"\";\n } else {\n search = searchOrUrl.slice(q + 1, hash > q ? hash : undefined);\n }\n return new URLSearchParams(search).get(\"panels\");\n}\n\n/** `search` with `panels` set to `param` (removed when empty). Returns \"\" or \"?…\". */\nexport function withPanelsParam(search: string, param: string): string {\n const params = new URLSearchParams(search.startsWith(\"?\") ? search.slice(1) : search);\n if (param) params.set(\"panels\", param);\n else params.delete(\"panels\");\n const qs = params.toString();\n return qs ? `?${qs}` : \"\";\n}\n","/**\n * OverlayLinkManager — the address bar's `?panels=` channel (successor of matrx-frontend's\n * UrlPanelManager). Mount ONCE inside <SummonProvider>. Driven entirely by `ports.router`.\n *\n * 1. On mount: read `?panels=`, hydrate each token through the one door (`hydrateLinkToken`).\n * 2. After that: write back the union of registered link entries (`useOverlayLink`) plus every\n * pasted token that has not been settled yet, via `router.replaceSearch` — never navigation.\n *\n * THE ADDRESS IS NEVER DESTROYED BY A CLOCK (matrx-frontend V-28 NEW-5). A token whose window has\n * not registered yet is kept verbatim in the address however long its lazy chunk takes. The\n * deadline (12 s prod / 45 s dev) decides one thing only: when to stop waiting silently and tell\n * the person, through `ports.notify` and `ports.errors`.\n *\n * A token is SETTLED when ANY registered entry carries its canonical key — the window a hydrator\n * opens may publish a different id (a vault link names an item, the vault window publishes its\n * singleton id) and may even be a different overlay than the one owning the key (key `agent`\n * opens display-mode shells). An alias resolves to its definition's own `link.key`.\n */\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport {\n LAZY_WINDOW_MOUNT_DEADLINE_MS,\n getOverlayMetaByLinkKey,\n selectIsUrlHydrated,\n selectUrlSyncEntries,\n setHydrated,\n type UrlSyncEntry,\n} from \"@ai-matrx/summon\";\nimport { useSummonDispatch, useSummonPorts, useSummonSelector } from \"@ai-matrx/summon/react\";\nimport { canonicalLinkKey, canonicalizeToken, hydrateLinkToken } from \"./door\";\nimport { formatLinkToken, parseLinkParam, readPanelsParam, withPanelsParam } from \"./grammar\";\n\nexport interface OverlayLinkManagerProps {\n /**\n * Restrict hydration and write-back to these link keys (a route-scoped manager). Tokens of\n * other keys are preserved verbatim and never hydrated. Omit for the app-wide manager.\n */\n readonly managedKeys?: readonly string[];\n /** Override the notice deadline (ms). Default: 12 s in production, 45 s in development. */\n readonly noticeDeadlineMs?: number;\n}\n\n/** Serialize registered entries as v2 tokens (only managed keys when given). */\nexport function serializeLinkEntries(entries: Readonly<Record<string, UrlSyncEntry>>, managedKeys?: readonly string[]): string {\n const managed = managedKeys ? new Set(managedKeys) : null;\n return Object.values(entries)\n .filter((entry) => !managed || managed.has(entry.typeKey))\n .map((entry) => formatLinkToken({ key: entry.typeKey, id: entry.instanceId, args: entry.args }))\n .join(\",\");\n}\n\n/** Keep the current param's unmanaged tokens; replace the managed ones with `nextManaged`. */\nexport function mergeManagedLinkParam(currentParam: string, nextManaged: string, managedKeys?: readonly string[]): string {\n if (!managedKeys) return nextManaged;\n const managed = new Set(managedKeys);\n const unmanaged = currentParam\n .split(\",\")\n .filter(Boolean)\n .filter((token) => !managed.has(token.split(\":\")[0] ?? \"\"));\n return [...unmanaged, ...nextManaged.split(\",\").filter(Boolean)].join(\",\");\n}\n\n/**\n * Re-attach pasted tokens no window has settled. A token is skipped when its CANONICAL key is\n * already represented by a live entry, so a late registration replaces the placeholder.\n */\nexport function withUnresolvedTokens(managedParam: string, unresolvedTokens: readonly string[]): string {\n if (unresolvedTokens.length === 0) return managedParam;\n const managed = managedParam.split(\",\").filter(Boolean);\n const represented = new Set(managed.map((token) => canonicalLinkKey(token.split(\":\")[0] ?? \"\")));\n const kept = unresolvedTokens.filter((token) => Boolean(token) && !represented.has(canonicalLinkKey(token.split(\":\")[0] ?? \"\")));\n return [...managed, ...kept].join(\",\");\n}\n\n/** The honest sentence for a link naming a window that did not open. */\nexport function unopenedWindowNotice(keys: readonly string[]): string {\n return (\n `This link names a window this build could not open: ${keys.join(\", \")}. ` +\n `The link is unchanged in your address bar — reload to try again, or report it if it keeps failing.`\n );\n}\n\ninterface PendingToken {\n /** What is written back while unsettled (canonical key, pasted id and args). */\n readonly token: string;\n /** The key the person pasted (named in the notice). */\n readonly tokenKey: string;\n readonly canonicalKey: string;\n}\n\nconst noopSubscribe = () => () => {};\n\nexport function OverlayLinkManager({ managedKeys, noticeDeadlineMs }: OverlayLinkManagerProps): null {\n const ports = useSummonPorts();\n const dispatch = useSummonDispatch();\n const entries = useSummonSelector(selectUrlSyncEntries);\n const isHydrated = useSummonSelector(selectIsUrlHydrated);\n const router = ports.router;\n // Re-run the write-back after ANY address change the router reports.\n const search = useSyncExternalStore(router.subscribe ?? noopSubscribe, router.search, () => \"\");\n\n const initialLoadDone = useRef(false);\n // Keyed by canonical key + id so two tokens that canonicalise together never overwrite each\n // other (V-30 NEW-5); the settle sweep still runs on canonical key.\n const unresolved = useRef(new Map<string, PendingToken>());\n const announced = useRef(new Set<string>());\n const [noticeDue, setNoticeDue] = useState(false);\n const [asyncTick, setAsyncTick] = useState(0);\n const deadline = noticeDeadlineMs ?? LAZY_WINDOW_MOUNT_DEADLINE_MS;\n\n const announce = (keys: readonly string[], reason: \"no-hydrator\" | \"never-registered\" | \"hydrator-threw\"): void => {\n const fresh = keys.filter((key) => !announced.current.has(key));\n if (fresh.length === 0) return;\n for (const key of fresh) announced.current.add(key);\n const joined = fresh.join(\", \");\n const why =\n reason === \"no-hydrator\"\n ? `no registered definition owns ${fresh.length > 1 ? \"these keys\" : \"this key\"}`\n : reason === \"hydrator-threw\"\n ? \"its hydrator threw\"\n : `hydrated, but no window registered its link within ${deadline}ms`;\n const message =\n `[overlays/url] ?panels= token(s) [${joined}]: ${why}. The token is KEPT in the address. ` +\n `Give the overlay definition a matching \\`link\\` (key or alias), or stop publishing the link.`;\n ports.errors.capture(new Error(message), {\n source: \"url-panel-unopened\",\n relation: `?panels=${joined}`,\n code: reason,\n typeKeys: fresh,\n deadlineMs: deadline,\n userMessage: unopenedWindowNotice(fresh),\n });\n ports.notify.error(unopenedWindowNotice(fresh), { duration: 12_000 });\n };\n const announceRef = useRef(announce);\n announceRef.current = announce;\n\n // 1. HYDRATION (address → store), once.\n useEffect(() => {\n if (initialLoadDone.current) return;\n initialLoadDone.current = true;\n const managed = managedKeys ? new Set(managedKeys) : null;\n const tokens = parseLinkParam(readPanelsParam(router.search()));\n const noHydrator: string[] = [];\n for (const token of tokens) {\n if (managed && !managed.has(token.key)) continue; // preserved verbatim by the write-back\n const canonicalKey = canonicalLinkKey(token.key);\n const pendingKey = `${canonicalKey}\\u0000${token.id ?? \"\"}`;\n const pending: PendingToken = { token: canonicalizeToken(token.raw), tokenKey: token.key, canonicalKey };\n if (!getOverlayMetaByLinkKey(token.key)?.link) {\n unresolved.current.set(pendingKey, { ...pending, token: token.raw });\n noHydrator.push(token.key);\n continue;\n }\n unresolved.current.set(pendingKey, pending);\n const outcome = hydrateLinkToken(token, dispatch, (error) => {\n ports.errors.capture(error, { source: \"url-panel-hydrator\", token: token.raw });\n });\n const apply = (result: string): void => {\n // A refused link is dropped from the address; it is not \"still to come\".\n if (result === \"refused\" && unresolved.current.get(pendingKey) === pending) {\n unresolved.current.delete(pendingKey);\n setAsyncTick((n) => n + 1);\n }\n };\n if (typeof outcome === \"string\") apply(outcome);\n else void outcome.then(apply);\n }\n if (noHydrator.length > 0) announceRef.current(noHydrator, \"no-hydrator\");\n dispatch(setHydrated());\n }, [dispatch, managedKeys, router, ports]);\n\n // The notice deadline: never gates a write; only turns a silent wait into a visible notice.\n useEffect(() => {\n if (!isHydrated || unresolved.current.size === 0) return undefined;\n const timer = setTimeout(() => setNoticeDue(true), deadline);\n return () => clearTimeout(timer);\n }, [isHydrated, deadline]);\n\n // 2. WRITE-BACK (store → address).\n useEffect(() => {\n if (!isHydrated) return;\n const observed = new Set(Object.values(entries).map((entry) => canonicalLinkKey(entry.typeKey)));\n for (const [key, pending] of [...unresolved.current.entries()]) {\n if (observed.has(pending.canonicalKey)) unresolved.current.delete(key);\n }\n const stillPending = [...unresolved.current.values()];\n if (noticeDue && stillPending.length > 0) {\n announceRef.current(\n stillPending.map((pending) => pending.tokenKey),\n \"never-registered\",\n );\n }\n // The LIVE address, never a snapshot: the page may have written `?view=` a moment ago.\n const liveSearch = router.search();\n const currentParam = readPanelsParam(liveSearch) ?? \"\";\n const nextManaged = withUnresolvedTokens(\n serializeLinkEntries(entries, managedKeys),\n stillPending.map((pending) => pending.token),\n );\n const nextParam = mergeManagedLinkParam(currentParam, nextManaged, managedKeys);\n if (currentParam !== nextParam) router.replaceSearch(withPanelsParam(liveSearch, nextParam));\n }, [entries, isHydrated, managedKeys, router, search, noticeDue, asyncTick]);\n\n return null;\n}\n","/**\n * The ONE door every link source goes through: the address-bar manager on load, a notification\n * that opens its link in place, the extension bridge. A token is resolved through the registry —\n * `getOverlayMetaByLinkKey(key).link.hydrate({ id, args, open, dispatch })` — never a side table.\n */\nimport type { Dispatch, UnknownAction } from \"@reduxjs/toolkit\";\nimport {\n DEFAULT_INSTANCE_ID,\n getOverlayMeta,\n getOverlayMetaByLinkKey,\n isRegisteredOverlay,\n overlaysRawActions,\n type AnyOverlayMeta,\n type OverlayHostDispatch,\n} from \"@ai-matrx/summon\";\nimport { parseLinkParam, readPanelsParam, type LinkToken } from \"./grammar\";\n\n/** Any Redux dispatch that takes plain actions (a host's thunk-aware dispatch qualifies). */\nexport type LinkDispatch = Dispatch<UnknownAction>;\n\n/**\n * Open an overlay by its registry id from inside the package. Uses the raw action so internal\n * code passes plain strings (a host's augmented `OverlayId` union never needs a cast here); the\n * definition's `defaults` are merged underneath exactly as the typed creator does.\n */\nexport function openRegisteredOverlay(\n dispatch: LinkDispatch,\n overlayId: string,\n instanceId: string = DEFAULT_INSTANCE_ID,\n data?: unknown,\n): void {\n const defaults = getOverlayMeta(overlayId)?.defaults;\n dispatch(\n overlaysRawActions.openOverlay({\n overlayId,\n instanceId,\n ...(data === undefined ? {} : { data }),\n ...(isRecord(defaults) ? { defaults } : {}),\n }),\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The key a token is judged by: the owning definition's own `link.key` (aliases resolve to it). */\nexport function canonicalLinkKey(key: string): string {\n return getOverlayMetaByLinkKey(key)?.link?.key ?? key;\n}\n\n/** The token with its key replaced by the canonical key; id and args carry across untouched. */\nexport function canonicalizeToken(raw: string): string {\n const at = raw.indexOf(\":\");\n const key = at === -1 ? raw : raw.slice(0, at);\n const canonical = canonicalLinkKey(key);\n if (canonical === key) return raw;\n return at === -1 ? canonical : `${canonical}${raw.slice(at)}`;\n}\n\nexport type TokenOutcome = \"opened\" | \"refused\" | \"unknown\" | \"failed\";\n\n/**\n * Run one token's hydrator. Synchronous hydrators dispatch before this returns; an async one\n * yields a promise. A throw (sync or async) is `\"failed\"` and is reported to `onError`.\n */\nexport function hydrateLinkToken(\n token: LinkToken,\n dispatch: LinkDispatch,\n onError?: (error: unknown, token: LinkToken) => void,\n): TokenOutcome | Promise<TokenOutcome> {\n const meta: AnyOverlayMeta | undefined = getOverlayMetaByLinkKey(token.key);\n const link = meta?.link;\n if (!meta || !link) return \"unknown\";\n const ownerId = meta.id;\n const settle = (result: void | \"refused\"): TokenOutcome => (result === \"refused\" ? \"refused\" : \"opened\");\n const fail = (error: unknown): TokenOutcome => {\n onError?.(error, token);\n return \"failed\";\n };\n try {\n const result = link.hydrate({\n id: token.id ?? \"\",\n args: token.args ?? {},\n open: (options) => openRegisteredOverlay(dispatch, ownerId, options?.instanceId ?? DEFAULT_INSTANCE_ID, options?.data),\n // The host's store dispatch IS the host dispatch at runtime; its thunk-aware type is the\n // host's augmentation (`OverlayHostTypes`), which the package cannot see.\n dispatch: dispatch as unknown as OverlayHostDispatch,\n });\n if (result && typeof (result as PromiseLike<unknown>).then === \"function\") {\n return Promise.resolve(result).then(settle, fail);\n }\n return settle(result as void | \"refused\");\n } catch (error) {\n return fail(error);\n }\n}\n\nexport interface OpenFromLinkResult {\n /** Tokens (verbatim) whose hydrator ran and did not refuse. */\n readonly opened: string[];\n /** Tokens whose hydrator declined the link on purpose. */\n readonly refused: string[];\n /** Tokens whose key no registered definition owns. */\n readonly unknown: string[];\n /** Tokens whose hydrator threw. */\n readonly failed: string[];\n}\n\nexport interface OpenFromLinkOptions {\n readonly dispatch: LinkDispatch;\n /**\n * All or nothing: when any token's key is unknown, open NOTHING and report the unknown tokens\n * (a notification then opens the link in a new tab instead of half of it in place).\n */\n readonly requireAll?: boolean;\n readonly onError?: (error: unknown, token: LinkToken) => void;\n}\n\n/**\n * Open every `?panels=` token of a search string or URL through its definition's hydrator.\n * Synchronous hydrators have dispatched by the time this returns; the promise settles once\n * async hydrators finish.\n */\nexport async function openFromLink(searchOrUrl: string, options: OpenFromLinkOptions): Promise<OpenFromLinkResult> {\n const tokens = parseLinkParam(readPanelsParam(searchOrUrl));\n const result: OpenFromLinkResult = { opened: [], refused: [], unknown: [], failed: [] };\n const unknown = tokens.filter((token) => !getOverlayMetaByLinkKey(token.key)?.link);\n if (options.requireAll && unknown.length > 0) {\n result.unknown.push(...unknown.map((token) => token.raw));\n return result;\n }\n const outcomes = tokens.map((token) => hydrateLinkToken(token, options.dispatch, options.onError));\n const settled = await Promise.all(outcomes.map((outcome) => Promise.resolve(outcome)));\n settled.forEach((outcome, index) => {\n const raw = tokens[index]?.raw ?? \"\";\n result[outcome === \"opened\" ? \"opened\" : outcome].push(raw);\n });\n return result;\n}\n\n// ── The extension door ──────────────────────────────────────────────────────────────────────\n\nexport interface OpenPanelRequest {\n readonly panelId: string;\n readonly instanceId?: string;\n readonly data?: Readonly<Record<string, unknown>>;\n}\n\nexport type OpenPanelResult =\n | { readonly ok: true; readonly opened: true; readonly panelId: string; readonly instanceId: string | null }\n | { readonly ok: false; readonly error: \"invalid_payload\" | \"unknown_panel\"; readonly details?: unknown };\n\nfunction readOpenPanelRequest(raw: unknown): OpenPanelRequest | string {\n if (!isRecord(raw)) return \"payload must be an object\";\n const { panelId, instanceId, data } = raw;\n if (typeof panelId !== \"string\" || panelId.length === 0) return \"panelId must be a non-empty string\";\n if (instanceId !== undefined && instanceId !== null && (typeof instanceId !== \"string\" || instanceId.length === 0)) {\n return \"instanceId must be a non-empty string when given\";\n }\n if (data !== undefined && data !== null && !isRecord(data)) return \"data must be an object when given\";\n return {\n panelId,\n ...(typeof instanceId === \"string\" ? { instanceId } : {}),\n ...(isRecord(data) ? { data } : {}),\n };\n}\n\n/**\n * Open a registered overlay by id for an outside caller (the browser extension's `openPanel`\n * envelope). Validates the payload and the id; failures come back as values, never throws, so\n * the bridge can reply verbatim. `instanceId: null` in the reply = the caller used the singleton.\n */\nexport function openPanelRequest(rawPayload: unknown, options: { readonly dispatch: LinkDispatch }): OpenPanelResult {\n const request = readOpenPanelRequest(rawPayload);\n if (typeof request === \"string\") return { ok: false, error: \"invalid_payload\", details: request };\n if (!isRegisteredOverlay(request.panelId)) {\n return {\n ok: false,\n error: \"unknown_panel\",\n details: { panelId: request.panelId, hint: \"panelId must be the id of a registered overlay definition.\" },\n };\n }\n openRegisteredOverlay(options.dispatch, request.panelId, request.instanceId ?? DEFAULT_INSTANCE_ID, request.data);\n return { ok: true, opened: true, panelId: request.panelId, instanceId: request.instanceId ?? null };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAmC;AACnC,oBAAuD;AACvD,IAAAA,gBAAkC;AAO3B,SAAS,eAAe,SAA6B,IAAwB,MAA+C;AACjI,QAAM,eAAW,iCAAkB;AACnC,QAAM,UAAU,OACZ,KAAK;AAAA,IACH,OAAO,KAAK,IAAI,EACb,KAAK,EACL,IAAI,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AAAA,EAC5B,IACA;AAGJ,QAAM,iBAAa,sBAAQ,MAAO,OAAO,EAAE,GAAG,KAAK,IAAI,QAAY,CAAC,OAAO,CAAC;AAE5E,8BAAU,MAAM;AACd,QAAI,CAAC,WAAW,CAAC,GAAI,QAAO;AAC5B,iBAAS,iCA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AK,CAAC;AAGzC,+BAAU,MAAM;AACd,QAAI,CAAC,cAAc,WAAW,QAAQ,SAAS,EAAG,QAAO;AACzD,UAAM,QAAQ,WAAW,MAAM,aAAa,IAAI,GAAG,QAAQ;AAC3D,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC,GAAG,CAAC,YAAY,QAAQ,CAAC;AAGzB,+BAAU,MAAM;AACd,QAAI,CAAC,WAAY;AACjB,UAAM,WAAW,IAAI,IAAI,OAAO,OAAO,OAAO,EAAE,IAAI,CAAC,UAAU,iBAAiB,MAAM,OAAO,CAAC,CAAC;AAC/F,eAAW,CAAC,KAAK,OAAO,KAAK,CAAC,GAAG,WAAW,QAAQ,QAAQ,CAAC,GAAG;AAC9D,UAAI,SAAS,IAAI,QAAQ,YAAY,EAAG,YAAW,QAAQ,OAAO,GAAG;AAAA,IACvE;AACA,UAAM,eAAe,CAAC,GAAG,WAAW,QAAQ,OAAO,CAAC;AACpD,QAAI,aAAa,aAAa,SAAS,GAAG;AACxC,kBAAY;AAAA,QACV,aAAa,IAAI,CAAC,YAAY,QAAQ,QAAQ;AAAA,QAC9C;AAAA,MACF;AAAA,IACF;AAEA,UAAM,aAAa,OAAO,OAAO;AACjC,UAAM,eAAe,gBAAgB,UAAU,KAAK;AACpD,UAAM,cAAc;AAAA,MAClB,qBAAqB,SAAS,WAAW;AAAA,MACzC,aAAa,IAAI,CAAC,YAAY,QAAQ,KAAK;AAAA,IAC7C;AACA,UAAM,YAAY,sBAAsB,cAAc,aAAa,WAAW;AAC9E,QAAI,iBAAiB,UAAW,QAAO,cAAc,gBAAgB,YAAY,SAAS,CAAC;AAAA,EAC7F,GAAG,CAAC,SAAS,YAAY,aAAa,QAAQ,QAAQ,WAAW,SAAS,CAAC;AAE3E,SAAO;AACT;","names":["import_react","import_react","import_summon","import_summon"]}
package/dist/url.d.cts ADDED
@@ -0,0 +1,153 @@
1
+ import { UrlSyncEntry } from '@ai-matrx/summon';
2
+ import { Dispatch, UnknownAction } from '@reduxjs/toolkit';
3
+
4
+ /**
5
+ * Publish an open instance's address into `?panels=` while it is mounted. `linkKey` undefined →
6
+ * nothing is published (a window with no link); so is an undefined or empty `id`. The token is `linkKey:id[:args]`; args are
7
+ * compared by value, so a new object with equal contents never re-registers.
8
+ */
9
+ declare function useOverlayLink(linkKey: string | undefined, id: string | undefined, args?: Readonly<Record<string, string>>): void;
10
+
11
+ /**
12
+ * The `?panels=` link grammar.
13
+ *
14
+ * panels = token ("," token)*
15
+ * token = key [":" id [":" args]]
16
+ * args = k "-" v ("_" k "-" v)*
17
+ *
18
+ * GRAMMAR v2 (this file): on WRITE, ids are percent-encoded for `% , :` and arg keys and values
19
+ * for `% , : _ -`, so any value — a uuid, a date, a path, a list — survives the round trip.
20
+ * Keys and ids keep `-` and `_` unencoded: they are not separators inside an id, and leaving them means a
21
+ * uuid id writes byte-identically to v1. On READ, v1 tokens (unencoded) parse unchanged: an arg
22
+ * pair splits on its FIRST hyphen, and decoding only touches well-formed `%XX` escapes.
23
+ *
24
+ * Framework-free; this is the one grammar every door (address bar, notifications, extension)
25
+ * shares.
26
+ */
27
+ interface LinkToken {
28
+ /** The token exactly as it appeared (the verbatim form written back while unresolved). */
29
+ readonly raw: string;
30
+ readonly key: string;
31
+ /** `undefined` for a bare-key token (`keyword_research`). */
32
+ readonly id: string | undefined;
33
+ /** `undefined` when the token carries no args segment. */
34
+ readonly args: Readonly<Record<string, string>> | undefined;
35
+ }
36
+ interface LinkEntry {
37
+ readonly key: string;
38
+ readonly id: string;
39
+ readonly args?: Readonly<Record<string, string>> | undefined;
40
+ }
41
+ /** Encode a token id (`% , :`). */
42
+ declare function encodeLinkId(id: string): string;
43
+ /** Encode an arg key or value (`% , : _ -`). */
44
+ declare function encodeLinkArg(value: string): string;
45
+ /** Decode well-formed `%XX` escapes; anything else (a v1 literal `%`) is kept as written. */
46
+ declare function decodeLinkPart(value: string): string;
47
+ /** Parse one token (v1 or v2). Returns `null` for an empty token. */
48
+ declare function parseLinkToken(raw: string): LinkToken | null;
49
+ /** Parse a whole `panels` value. Empty segments are skipped. */
50
+ declare function parseLinkParam(param: string | null | undefined): LinkToken[];
51
+ /** Write one entry as a v2 token. Args are written in key order so equal entries write equal tokens. */
52
+ declare function formatLinkToken(entry: LinkEntry): string;
53
+ /** The `panels` value from a search string or a full URL (`null` when absent). */
54
+ declare function readPanelsParam(searchOrUrl: string): string | null;
55
+ /** `search` with `panels` set to `param` (removed when empty). Returns "" or "?…". */
56
+ declare function withPanelsParam(search: string, param: string): string;
57
+
58
+ interface OverlayLinkManagerProps {
59
+ /**
60
+ * Restrict hydration and write-back to these link keys (a route-scoped manager). Tokens of
61
+ * other keys are preserved verbatim and never hydrated. Omit for the app-wide manager.
62
+ */
63
+ readonly managedKeys?: readonly string[];
64
+ /** Override the notice deadline (ms). Default: 12 s in production, 45 s in development. */
65
+ readonly noticeDeadlineMs?: number;
66
+ }
67
+ /** Serialize registered entries as v2 tokens (only managed keys when given). */
68
+ declare function serializeLinkEntries(entries: Readonly<Record<string, UrlSyncEntry>>, managedKeys?: readonly string[]): string;
69
+ /** Keep the current param's unmanaged tokens; replace the managed ones with `nextManaged`. */
70
+ declare function mergeManagedLinkParam(currentParam: string, nextManaged: string, managedKeys?: readonly string[]): string;
71
+ /**
72
+ * Re-attach pasted tokens no window has settled. A token is skipped when its CANONICAL key is
73
+ * already represented by a live entry, so a late registration replaces the placeholder.
74
+ */
75
+ declare function withUnresolvedTokens(managedParam: string, unresolvedTokens: readonly string[]): string;
76
+ /** The honest sentence for a link naming a window that did not open. */
77
+ declare function unopenedWindowNotice(keys: readonly string[]): string;
78
+ declare function OverlayLinkManager({ managedKeys, noticeDeadlineMs }: OverlayLinkManagerProps): null;
79
+
80
+ /**
81
+ * The ONE door every link source goes through: the address-bar manager on load, a notification
82
+ * that opens its link in place, the extension bridge. A token is resolved through the registry —
83
+ * `getOverlayMetaByLinkKey(key).link.hydrate({ id, args, open, dispatch })` — never a side table.
84
+ */
85
+
86
+ /** Any Redux dispatch that takes plain actions (a host's thunk-aware dispatch qualifies). */
87
+ type LinkDispatch = Dispatch<UnknownAction>;
88
+ /**
89
+ * Open an overlay by its registry id from inside the package. Uses the raw action so internal
90
+ * code passes plain strings (a host's augmented `OverlayId` union never needs a cast here); the
91
+ * definition's `defaults` are merged underneath exactly as the typed creator does.
92
+ */
93
+ declare function openRegisteredOverlay(dispatch: LinkDispatch, overlayId: string, instanceId?: string, data?: unknown): void;
94
+ /** The key a token is judged by: the owning definition's own `link.key` (aliases resolve to it). */
95
+ declare function canonicalLinkKey(key: string): string;
96
+ /** The token with its key replaced by the canonical key; id and args carry across untouched. */
97
+ declare function canonicalizeToken(raw: string): string;
98
+ type TokenOutcome = "opened" | "refused" | "unknown" | "failed";
99
+ /**
100
+ * Run one token's hydrator. Synchronous hydrators dispatch before this returns; an async one
101
+ * yields a promise. A throw (sync or async) is `"failed"` and is reported to `onError`.
102
+ */
103
+ declare function hydrateLinkToken(token: LinkToken, dispatch: LinkDispatch, onError?: (error: unknown, token: LinkToken) => void): TokenOutcome | Promise<TokenOutcome>;
104
+ interface OpenFromLinkResult {
105
+ /** Tokens (verbatim) whose hydrator ran and did not refuse. */
106
+ readonly opened: string[];
107
+ /** Tokens whose hydrator declined the link on purpose. */
108
+ readonly refused: string[];
109
+ /** Tokens whose key no registered definition owns. */
110
+ readonly unknown: string[];
111
+ /** Tokens whose hydrator threw. */
112
+ readonly failed: string[];
113
+ }
114
+ interface OpenFromLinkOptions {
115
+ readonly dispatch: LinkDispatch;
116
+ /**
117
+ * All or nothing: when any token's key is unknown, open NOTHING and report the unknown tokens
118
+ * (a notification then opens the link in a new tab instead of half of it in place).
119
+ */
120
+ readonly requireAll?: boolean;
121
+ readonly onError?: (error: unknown, token: LinkToken) => void;
122
+ }
123
+ /**
124
+ * Open every `?panels=` token of a search string or URL through its definition's hydrator.
125
+ * Synchronous hydrators have dispatched by the time this returns; the promise settles once
126
+ * async hydrators finish.
127
+ */
128
+ declare function openFromLink(searchOrUrl: string, options: OpenFromLinkOptions): Promise<OpenFromLinkResult>;
129
+ interface OpenPanelRequest {
130
+ readonly panelId: string;
131
+ readonly instanceId?: string;
132
+ readonly data?: Readonly<Record<string, unknown>>;
133
+ }
134
+ type OpenPanelResult = {
135
+ readonly ok: true;
136
+ readonly opened: true;
137
+ readonly panelId: string;
138
+ readonly instanceId: string | null;
139
+ } | {
140
+ readonly ok: false;
141
+ readonly error: "invalid_payload" | "unknown_panel";
142
+ readonly details?: unknown;
143
+ };
144
+ /**
145
+ * Open a registered overlay by id for an outside caller (the browser extension's `openPanel`
146
+ * envelope). Validates the payload and the id; failures come back as values, never throws, so
147
+ * the bridge can reply verbatim. `instanceId: null` in the reply = the caller used the singleton.
148
+ */
149
+ declare function openPanelRequest(rawPayload: unknown, options: {
150
+ readonly dispatch: LinkDispatch;
151
+ }): OpenPanelResult;
152
+
153
+ export { type LinkDispatch, type LinkEntry, type LinkToken, type OpenFromLinkOptions, type OpenFromLinkResult, type OpenPanelRequest, type OpenPanelResult, OverlayLinkManager, type OverlayLinkManagerProps, type TokenOutcome, canonicalLinkKey, canonicalizeToken, decodeLinkPart, encodeLinkArg, encodeLinkId, formatLinkToken, hydrateLinkToken, mergeManagedLinkParam, openFromLink, openPanelRequest, openRegisteredOverlay, parseLinkParam, parseLinkToken, readPanelsParam, serializeLinkEntries, unopenedWindowNotice, useOverlayLink, withPanelsParam, withUnresolvedTokens };
package/dist/url.d.ts ADDED
@@ -0,0 +1,153 @@
1
+ import { UrlSyncEntry } from '@ai-matrx/summon';
2
+ import { Dispatch, UnknownAction } from '@reduxjs/toolkit';
3
+
4
+ /**
5
+ * Publish an open instance's address into `?panels=` while it is mounted. `linkKey` undefined →
6
+ * nothing is published (a window with no link); so is an undefined or empty `id`. The token is `linkKey:id[:args]`; args are
7
+ * compared by value, so a new object with equal contents never re-registers.
8
+ */
9
+ declare function useOverlayLink(linkKey: string | undefined, id: string | undefined, args?: Readonly<Record<string, string>>): void;
10
+
11
+ /**
12
+ * The `?panels=` link grammar.
13
+ *
14
+ * panels = token ("," token)*
15
+ * token = key [":" id [":" args]]
16
+ * args = k "-" v ("_" k "-" v)*
17
+ *
18
+ * GRAMMAR v2 (this file): on WRITE, ids are percent-encoded for `% , :` and arg keys and values
19
+ * for `% , : _ -`, so any value — a uuid, a date, a path, a list — survives the round trip.
20
+ * Keys and ids keep `-` and `_` unencoded: they are not separators inside an id, and leaving them means a
21
+ * uuid id writes byte-identically to v1. On READ, v1 tokens (unencoded) parse unchanged: an arg
22
+ * pair splits on its FIRST hyphen, and decoding only touches well-formed `%XX` escapes.
23
+ *
24
+ * Framework-free; this is the one grammar every door (address bar, notifications, extension)
25
+ * shares.
26
+ */
27
+ interface LinkToken {
28
+ /** The token exactly as it appeared (the verbatim form written back while unresolved). */
29
+ readonly raw: string;
30
+ readonly key: string;
31
+ /** `undefined` for a bare-key token (`keyword_research`). */
32
+ readonly id: string | undefined;
33
+ /** `undefined` when the token carries no args segment. */
34
+ readonly args: Readonly<Record<string, string>> | undefined;
35
+ }
36
+ interface LinkEntry {
37
+ readonly key: string;
38
+ readonly id: string;
39
+ readonly args?: Readonly<Record<string, string>> | undefined;
40
+ }
41
+ /** Encode a token id (`% , :`). */
42
+ declare function encodeLinkId(id: string): string;
43
+ /** Encode an arg key or value (`% , : _ -`). */
44
+ declare function encodeLinkArg(value: string): string;
45
+ /** Decode well-formed `%XX` escapes; anything else (a v1 literal `%`) is kept as written. */
46
+ declare function decodeLinkPart(value: string): string;
47
+ /** Parse one token (v1 or v2). Returns `null` for an empty token. */
48
+ declare function parseLinkToken(raw: string): LinkToken | null;
49
+ /** Parse a whole `panels` value. Empty segments are skipped. */
50
+ declare function parseLinkParam(param: string | null | undefined): LinkToken[];
51
+ /** Write one entry as a v2 token. Args are written in key order so equal entries write equal tokens. */
52
+ declare function formatLinkToken(entry: LinkEntry): string;
53
+ /** The `panels` value from a search string or a full URL (`null` when absent). */
54
+ declare function readPanelsParam(searchOrUrl: string): string | null;
55
+ /** `search` with `panels` set to `param` (removed when empty). Returns "" or "?…". */
56
+ declare function withPanelsParam(search: string, param: string): string;
57
+
58
+ interface OverlayLinkManagerProps {
59
+ /**
60
+ * Restrict hydration and write-back to these link keys (a route-scoped manager). Tokens of
61
+ * other keys are preserved verbatim and never hydrated. Omit for the app-wide manager.
62
+ */
63
+ readonly managedKeys?: readonly string[];
64
+ /** Override the notice deadline (ms). Default: 12 s in production, 45 s in development. */
65
+ readonly noticeDeadlineMs?: number;
66
+ }
67
+ /** Serialize registered entries as v2 tokens (only managed keys when given). */
68
+ declare function serializeLinkEntries(entries: Readonly<Record<string, UrlSyncEntry>>, managedKeys?: readonly string[]): string;
69
+ /** Keep the current param's unmanaged tokens; replace the managed ones with `nextManaged`. */
70
+ declare function mergeManagedLinkParam(currentParam: string, nextManaged: string, managedKeys?: readonly string[]): string;
71
+ /**
72
+ * Re-attach pasted tokens no window has settled. A token is skipped when its CANONICAL key is
73
+ * already represented by a live entry, so a late registration replaces the placeholder.
74
+ */
75
+ declare function withUnresolvedTokens(managedParam: string, unresolvedTokens: readonly string[]): string;
76
+ /** The honest sentence for a link naming a window that did not open. */
77
+ declare function unopenedWindowNotice(keys: readonly string[]): string;
78
+ declare function OverlayLinkManager({ managedKeys, noticeDeadlineMs }: OverlayLinkManagerProps): null;
79
+
80
+ /**
81
+ * The ONE door every link source goes through: the address-bar manager on load, a notification
82
+ * that opens its link in place, the extension bridge. A token is resolved through the registry —
83
+ * `getOverlayMetaByLinkKey(key).link.hydrate({ id, args, open, dispatch })` — never a side table.
84
+ */
85
+
86
+ /** Any Redux dispatch that takes plain actions (a host's thunk-aware dispatch qualifies). */
87
+ type LinkDispatch = Dispatch<UnknownAction>;
88
+ /**
89
+ * Open an overlay by its registry id from inside the package. Uses the raw action so internal
90
+ * code passes plain strings (a host's augmented `OverlayId` union never needs a cast here); the
91
+ * definition's `defaults` are merged underneath exactly as the typed creator does.
92
+ */
93
+ declare function openRegisteredOverlay(dispatch: LinkDispatch, overlayId: string, instanceId?: string, data?: unknown): void;
94
+ /** The key a token is judged by: the owning definition's own `link.key` (aliases resolve to it). */
95
+ declare function canonicalLinkKey(key: string): string;
96
+ /** The token with its key replaced by the canonical key; id and args carry across untouched. */
97
+ declare function canonicalizeToken(raw: string): string;
98
+ type TokenOutcome = "opened" | "refused" | "unknown" | "failed";
99
+ /**
100
+ * Run one token's hydrator. Synchronous hydrators dispatch before this returns; an async one
101
+ * yields a promise. A throw (sync or async) is `"failed"` and is reported to `onError`.
102
+ */
103
+ declare function hydrateLinkToken(token: LinkToken, dispatch: LinkDispatch, onError?: (error: unknown, token: LinkToken) => void): TokenOutcome | Promise<TokenOutcome>;
104
+ interface OpenFromLinkResult {
105
+ /** Tokens (verbatim) whose hydrator ran and did not refuse. */
106
+ readonly opened: string[];
107
+ /** Tokens whose hydrator declined the link on purpose. */
108
+ readonly refused: string[];
109
+ /** Tokens whose key no registered definition owns. */
110
+ readonly unknown: string[];
111
+ /** Tokens whose hydrator threw. */
112
+ readonly failed: string[];
113
+ }
114
+ interface OpenFromLinkOptions {
115
+ readonly dispatch: LinkDispatch;
116
+ /**
117
+ * All or nothing: when any token's key is unknown, open NOTHING and report the unknown tokens
118
+ * (a notification then opens the link in a new tab instead of half of it in place).
119
+ */
120
+ readonly requireAll?: boolean;
121
+ readonly onError?: (error: unknown, token: LinkToken) => void;
122
+ }
123
+ /**
124
+ * Open every `?panels=` token of a search string or URL through its definition's hydrator.
125
+ * Synchronous hydrators have dispatched by the time this returns; the promise settles once
126
+ * async hydrators finish.
127
+ */
128
+ declare function openFromLink(searchOrUrl: string, options: OpenFromLinkOptions): Promise<OpenFromLinkResult>;
129
+ interface OpenPanelRequest {
130
+ readonly panelId: string;
131
+ readonly instanceId?: string;
132
+ readonly data?: Readonly<Record<string, unknown>>;
133
+ }
134
+ type OpenPanelResult = {
135
+ readonly ok: true;
136
+ readonly opened: true;
137
+ readonly panelId: string;
138
+ readonly instanceId: string | null;
139
+ } | {
140
+ readonly ok: false;
141
+ readonly error: "invalid_payload" | "unknown_panel";
142
+ readonly details?: unknown;
143
+ };
144
+ /**
145
+ * Open a registered overlay by id for an outside caller (the browser extension's `openPanel`
146
+ * envelope). Validates the payload and the id; failures come back as values, never throws, so
147
+ * the bridge can reply verbatim. `instanceId: null` in the reply = the caller used the singleton.
148
+ */
149
+ declare function openPanelRequest(rawPayload: unknown, options: {
150
+ readonly dispatch: LinkDispatch;
151
+ }): OpenPanelResult;
152
+
153
+ export { type LinkDispatch, type LinkEntry, type LinkToken, type OpenFromLinkOptions, type OpenFromLinkResult, type OpenPanelRequest, type OpenPanelResult, OverlayLinkManager, type OverlayLinkManagerProps, type TokenOutcome, canonicalLinkKey, canonicalizeToken, decodeLinkPart, encodeLinkArg, encodeLinkId, formatLinkToken, hydrateLinkToken, mergeManagedLinkParam, openFromLink, openPanelRequest, openRegisteredOverlay, parseLinkParam, parseLinkToken, readPanelsParam, serializeLinkEntries, unopenedWindowNotice, useOverlayLink, withPanelsParam, withUnresolvedTokens };