@ai-matrx/records-ui 0.116.82 → 0.116.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/entity-doors.cjs +4 -4
- package/dist/entity-doors.cjs.map +1 -1
- package/dist/entity-doors.d.cts +2 -21
- package/dist/entity-doors.d.ts +2 -21
- package/dist/entity-doors.js +2 -5
- package/dist/entity-doors.js.map +1 -1
- package/dist/entity-ref.cjs +1 -4
- package/dist/entity-ref.cjs.map +1 -1
- package/dist/entity-ref.d.cts +2 -21
- package/dist/entity-ref.d.ts +2 -21
- package/dist/entity-ref.js +1 -4
- package/dist/entity-ref.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
# Changelog — @ai-matrx/records-ui
|
|
2
2
|
|
|
3
|
+
## 0.116.83
|
|
4
|
+
|
|
5
|
+
- **`isUuidValue` (`/entity-doors`) is kit's one `isUuidValue`**: UUID shape after trim (it was RFC 9562 version-checked, which withheld doors from shape-valid ids). Consumer action: none.
|
|
6
|
+
|
|
3
7
|
## 0.116.82
|
|
4
8
|
|
|
9
|
+
SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
|
|
10
|
+
so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
|
|
11
|
+
Diff: `git diff 76781ff66d 3d76b8e233 -- apps/shared/records-ui/src`
|
|
12
|
+
|
|
13
|
+
Changed shipped source files (1):
|
|
14
|
+
- `apps/shared/records-ui/src/entity-ref/slot.ts`
|
|
15
|
+
|
|
16
|
+
## 0.116.81
|
|
17
|
+
|
|
5
18
|
- **The grid's hover peek opens below its row, not beside it (live walk, 2026-10-22).** A row spans the whole grid, so the side placement had no room and the card landed partly off the screen's edge; it now opens below (above near the bottom) and slides sideways to stay on screen. Guard: `a-hovered-grid-row-shows-the-one-peek.test.tsx`. Consumer action: none.
|
|
6
19
|
|
|
20
|
+
- **References to other records live here: `@ai-matrx/records-ui/entity-ref` and `/entity-doors` (lane RU, 2026-10-22).** `EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`, `useEntityHref` and `RecordStamps` moved in from matrx-frontend `components/official/{entity-ref,record-stamps}`. Everything the app knows arrives through ONE host bound once with `configureEntityRefs({ registry, adminHref, hasPeek, openPeek, useAddress, Link, ErrorMenu, Person })` (a `globalThis` slot: references are drawn far outside `<RecordsUiProvider>`). Unbound, a reference draws its name with no door, carries `data-entity-ref-host="unconfigured"` and warns once. `/entity-doors` is the light, banner-free half (`isUuidValue`, `doorTokenFromColumnName` — renamed from `tokenFromColumnName`, which collided with design-system's looser helper —, `hasAnyDoor`, `resolveEntityDoors`, `segmentSentenceIds`, `tokenFromPrecedingWords`, `configureEntityRefs`). Guard: `src/entity-ref/entity-ref.test.tsx`. Consumer action: call `configureEntityRefs` once before the first render.
|
|
21
|
+
|
|
7
22
|
## 0.116.80
|
|
8
23
|
|
|
9
24
|
- **References to other records live here: `@ai-matrx/records-ui/entity-ref` and `/entity-doors` (lane RU, 2026-10-22).** `EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`, `useEntityHref` and `RecordStamps` moved in from matrx-frontend `components/official/{entity-ref,record-stamps}`. Everything the app knows arrives through ONE host bound once with `configureEntityRefs({ registry, adminHref, hasPeek, openPeek, useAddress, Link, ErrorMenu, Person })` (a `globalThis` slot: references are drawn far outside `<RecordsUiProvider>`). Unbound, a reference draws its name with no door, carries `data-entity-ref-host="unconfigured"` and warns once. `/entity-doors` is the light, banner-free half (`isUuidValue`, `doorTokenFromColumnName` — renamed from `tokenFromColumnName`, which collided with design-system's looser helper —, `hasAnyDoor`, `resolveEntityDoors`, `segmentSentenceIds`, `tokenFromPrecedingWords`, `configureEntityRefs`). Guard: `src/entity-ref/entity-ref.test.tsx`. Consumer action: call `configureEntityRefs` once before the first render.
|
package/dist/entity-doors.cjs
CHANGED
|
@@ -50,9 +50,6 @@ function entityRefPorts() {
|
|
|
50
50
|
function isNativeNewTabClick(e) {
|
|
51
51
|
return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);
|
|
52
52
|
}
|
|
53
|
-
function isUuidValue(value) {
|
|
54
|
-
return typeof value === "string" && uuid.isRfc9562Uuid(value.trim());
|
|
55
|
-
}
|
|
56
53
|
var PEEK_KEY_BY_TOKEN = {
|
|
57
54
|
app: "agent_app",
|
|
58
55
|
pick_list: "pick_list",
|
|
@@ -152,12 +149,15 @@ function segmentIdsOnly(text, defaultToken) {
|
|
|
152
149
|
return segments;
|
|
153
150
|
}
|
|
154
151
|
|
|
152
|
+
Object.defineProperty(exports, "isUuidValue", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function () { return uuid.isUuidValue; }
|
|
155
|
+
});
|
|
155
156
|
exports.configureEntityRefs = configureEntityRefs;
|
|
156
157
|
exports.doorTokenFromColumnName = doorTokenFromColumnName;
|
|
157
158
|
exports.entityRefsConfigured = entityRefsConfigured;
|
|
158
159
|
exports.hasAnyDoor = hasAnyDoor;
|
|
159
160
|
exports.isNativeNewTabClick = isNativeNewTabClick;
|
|
160
|
-
exports.isUuidValue = isUuidValue;
|
|
161
161
|
exports.resolveEntityDoors = resolveEntityDoors;
|
|
162
162
|
exports.segmentSentenceIds = segmentSentenceIds;
|
|
163
163
|
exports.tokenFromPrecedingWords = tokenFromPrecedingWords;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":["globalSlot","openOutbound","isRfc9562Uuid","findCodeRanges","codeSpanText"],"mappings":";;;;;;;;AAuHA,IAAM,QAAQA,qBAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IA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IAAA,CAAA;AAC7D,IAAA,IAAI,UAAU,IAAA,EAAM;AACpB,IAAA,IAAI,QAAQ,MAAA,EAAQ;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,KAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAA,EAAG,CAAA;AAAA,IACjE;AACA,IAAA,QAAA,CAAS,KAAK,EAAE,IAAA,EAAM,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACxC,IAAA,MAAA,GAAS,QAAQ,EAAA,CAAG,MAAA;AAAA,EACtB;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.cjs","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] no host configured: references draw names with no doors. \" +\n \"Call configureEntityRefs(...) once before the first render.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isRfc9562Uuid } from \"@ai-matrx/kit/uuid\";\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\nexport function isUuidValue(value: unknown): value is string {\n return typeof value === \"string\" && isRfc9562Uuid(value.trim());\n}\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":["globalSlot","openOutbound","findCodeRanges","codeSpanText"],"mappings":";;;;;;;;AAuHA,IAAM,QAAQA,qBAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,IAAI,MAAA,GAAS,KAAA;AACb,SAAS,oBAAA,GAA6B;AACpC,EAAA,IAAI,MAAA,EAAQ;AACZ,EAAA,MAAA,GAAS,IAAA;AACT,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KAEF;AAAA,EACF;AACF;AAEA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,SAAA,EAAW,CAAC,KAAA,KAAU,KAAA;AAAA,EACtB,UAAU,MAAM;AAClB,CAAA;AAEO,SAAS,iBAAiB,GAAA,EAA6B;AAC5D,EAAA,MAAM,IAA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A,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.cjs","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] no host configured: references draw names with no doors. \" +\n \"Call configureEntityRefs(...) once before the first render.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
package/dist/entity-doors.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComponentType, MouseEvent, ReactNode, Ref } from 'react';
|
|
2
|
+
export { isUuidValue } from '@ai-matrx/kit/uuid';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Door resolution — the ONE place a (token, id) pair becomes reachable doors.
|
|
@@ -26,26 +27,6 @@ import { ComponentType, MouseEvent, ReactNode, Ref } from 'react';
|
|
|
26
27
|
* one only when the kind deserves more than title/description/dates.
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
-
* True when a value is a real uuid — the guard a surface needs BEFORE handing an
|
|
31
|
-
* id to `EntityRef` / `EntityDoorControls`.
|
|
32
|
-
*
|
|
33
|
-
* Door resolution deliberately does not validate ids (a token's `hrefFor` is
|
|
34
|
-
* free to use slugs), so any surface that DERIVES an id — parsing it out of a
|
|
35
|
-
* surface key, reading an untyped column — must check first, or it mints a link
|
|
36
|
-
* to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks
|
|
37
|
-
* worse than no door at all.
|
|
38
|
-
*
|
|
39
|
-
* It lives here, beside `resolveEntityDoors`, because this module is the one
|
|
40
|
-
* component-free entry point on the door path. It used to live only inside
|
|
41
|
-
* `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its
|
|
42
|
-
* tooltip/toast/peek-host graph) into whatever chunk needed the check —
|
|
43
|
-
* THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved
|
|
44
|
-
* to this module in the same change — there is deliberately no re-export left
|
|
45
|
-
* behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the
|
|
46
|
-
* rule is right.
|
|
47
|
-
*/
|
|
48
|
-
declare function isUuidValue(value: unknown): value is string;
|
|
49
30
|
interface EntityDoors {
|
|
50
31
|
/** Canonical route to the record, or null when the token has no `hrefFor`. */
|
|
51
32
|
href: string | null;
|
|
@@ -286,4 +267,4 @@ declare function isNativeNewTabClick(e: {
|
|
|
286
267
|
button?: number;
|
|
287
268
|
}): boolean;
|
|
288
269
|
|
|
289
|
-
export { type EntityAddress, type EntityDoors, type EntityRefDescriptor, type EntityRefHost, type EntityRefLinkProps, type EntityRefPeekAsk, type EntityRefPerson, type EntityRefRegistry, type SentenceSegment, configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick,
|
|
270
|
+
export { type EntityAddress, type EntityDoors, type EntityRefDescriptor, type EntityRefHost, type EntityRefLinkProps, type EntityRefPeekAsk, type EntityRefPerson, type EntityRefRegistry, type SentenceSegment, configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick, resolveEntityDoors, segmentSentenceIds, tokenFromPrecedingWords };
|
package/dist/entity-doors.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComponentType, MouseEvent, ReactNode, Ref } from 'react';
|
|
2
|
+
export { isUuidValue } from '@ai-matrx/kit/uuid';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Door resolution — the ONE place a (token, id) pair becomes reachable doors.
|
|
@@ -26,26 +27,6 @@ import { ComponentType, MouseEvent, ReactNode, Ref } from 'react';
|
|
|
26
27
|
* one only when the kind deserves more than title/description/dates.
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
-
* True when a value is a real uuid — the guard a surface needs BEFORE handing an
|
|
31
|
-
* id to `EntityRef` / `EntityDoorControls`.
|
|
32
|
-
*
|
|
33
|
-
* Door resolution deliberately does not validate ids (a token's `hrefFor` is
|
|
34
|
-
* free to use slugs), so any surface that DERIVES an id — parsing it out of a
|
|
35
|
-
* surface key, reading an untyped column — must check first, or it mints a link
|
|
36
|
-
* to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks
|
|
37
|
-
* worse than no door at all.
|
|
38
|
-
*
|
|
39
|
-
* It lives here, beside `resolveEntityDoors`, because this module is the one
|
|
40
|
-
* component-free entry point on the door path. It used to live only inside
|
|
41
|
-
* `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its
|
|
42
|
-
* tooltip/toast/peek-host graph) into whatever chunk needed the check —
|
|
43
|
-
* THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved
|
|
44
|
-
* to this module in the same change — there is deliberately no re-export left
|
|
45
|
-
* behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the
|
|
46
|
-
* rule is right.
|
|
47
|
-
*/
|
|
48
|
-
declare function isUuidValue(value: unknown): value is string;
|
|
49
30
|
interface EntityDoors {
|
|
50
31
|
/** Canonical route to the record, or null when the token has no `hrefFor`. */
|
|
51
32
|
href: string | null;
|
|
@@ -286,4 +267,4 @@ declare function isNativeNewTabClick(e: {
|
|
|
286
267
|
button?: number;
|
|
287
268
|
}): boolean;
|
|
288
269
|
|
|
289
|
-
export { type EntityAddress, type EntityDoors, type EntityRefDescriptor, type EntityRefHost, type EntityRefLinkProps, type EntityRefPeekAsk, type EntityRefPerson, type EntityRefRegistry, type SentenceSegment, configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick,
|
|
270
|
+
export { type EntityAddress, type EntityDoors, type EntityRefDescriptor, type EntityRefHost, type EntityRefLinkProps, type EntityRefPeekAsk, type EntityRefPerson, type EntityRefRegistry, type SentenceSegment, configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick, resolveEntityDoors, segmentSentenceIds, tokenFromPrecedingWords };
|
package/dist/entity-doors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { globalSlot } from '@ai-matrx/kit/global-slot';
|
|
2
2
|
import { openOutbound } from '@ai-matrx/kit/outbound';
|
|
3
3
|
import { findCodeRanges, codeSpanText } from '@ai-matrx/content-ir/source';
|
|
4
|
-
|
|
4
|
+
export { isUuidValue } from '@ai-matrx/kit/uuid';
|
|
5
5
|
|
|
6
6
|
// src/entity-ref/slot.ts
|
|
7
7
|
var bound = globalSlot("ai-matrx.records-ui.entity-ref-host", () => ({ host: null }));
|
|
@@ -48,9 +48,6 @@ function entityRefPorts() {
|
|
|
48
48
|
function isNativeNewTabClick(e) {
|
|
49
49
|
return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);
|
|
50
50
|
}
|
|
51
|
-
function isUuidValue(value) {
|
|
52
|
-
return typeof value === "string" && isRfc9562Uuid(value.trim());
|
|
53
|
-
}
|
|
54
51
|
var PEEK_KEY_BY_TOKEN = {
|
|
55
52
|
app: "agent_app",
|
|
56
53
|
pick_list: "pick_list",
|
|
@@ -150,6 +147,6 @@ function segmentIdsOnly(text, defaultToken) {
|
|
|
150
147
|
return segments;
|
|
151
148
|
}
|
|
152
149
|
|
|
153
|
-
export { configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick,
|
|
150
|
+
export { configureEntityRefs, doorTokenFromColumnName, entityRefsConfigured, hasAnyDoor, isNativeNewTabClick, resolveEntityDoors, segmentSentenceIds, tokenFromPrecedingWords };
|
|
154
151
|
//# sourceMappingURL=entity-doors.js.map
|
|
155
152
|
//# sourceMappingURL=entity-doors.js.map
|
package/dist/entity-doors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":[],"mappings":";;;;;;AAuHA,IAAM,QAAQ,UAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,IAAI,MAAA,GAAS,KAAA;AACb,SAAS,oBAAA,GAA6B;AACpC,EAAA,IAAI,MAAA,EAAQ;AACZ,EAAA,MAAA,GAAS,IAAA;AACT,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KAEF;AAAA,EACF;AACF;AAEA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,SAAA,EAAW,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A,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.js","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] no host configured: references draw names with no doors. \" +\n \"Call configureEntityRefs(...) once before the first render.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isRfc9562Uuid } from \"@ai-matrx/kit/uuid\";\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\nexport function isUuidValue(value: unknown): value is string {\n return typeof value === \"string\" && isRfc9562Uuid(value.trim());\n}\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":[],"mappings":";;;;;;AAuHA,IAAM,QAAQ,UAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,IAAI,MAAA,GAAS,KAAA;AACb,SAAS,oBAAA,GAA6B;AACpC,EAAA,IAAI,MAAA,EAAQ;AACZ,EAAA,MAAA,GAAS,IAAA;AACT,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KAEF;AAAA,EACF;AACF;AAEA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,SAAA,EAAW,CAAC,KAAA,KAAU,KAAA;AAAA,EACtB,UAAU,MAAM;AAClB,CAAA;AAEO,SAAS,iBAAiB,GAAA,EAA6B;AAC5D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,YAAA,IAAgB,GAAA,CAAI,IAAA;AACrC,EAAA,IAAI,IAAA,EAAM,YAAA,CAAa,IAAA,EAAM,QAAA,EAAU,UAAU,CAAA;AACnD;AAYA,IAAM,YAAY,MAAM,IAAA;AAGjB,SAAS,kBAAA,GAA2C;AACzD,EAAA,OAAO,KAAA,CAAM,IAAA;AACf;AAEO,SAAS,cAAA,GAAiC;AAC/C,EAAA,MAAM,OAAO,kBAAA,EAAmB;AAChC,EAAA,IAAI,CAAC,MAAM,oBAAA,EAAqB;AAChC,EAAA,OAAO;AAAA,IACL,UAAA,EAAY,QAAQ,IAAI,CAAA;AAAA,IACxB,QAA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AAM,QAAQ,KAAA,CAAM,KAAA;AACpB,IAAA,MAAM,KAAA,GACJ,uBAAA,CAAwB,IAAA,CAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAC,CAAA,KAChD,YAAA,IAAgB,UAAA,CAAW,YAAY,CAAA,GAAI,YAAA,GAAe,IAAA,CAAA;AAC7D,IAAA,IAAI,UAAU,IAAA,EAAM;AACpB,IAAA,IAAI,QAAQ,MAAA,EAAQ;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,KAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAA,EAAG,CAAA;AAAA,IACjE;AACA,IAAA,QAAA,CAAS,KAAK,EAAE,IAAA,EAAM,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACxC,IAAA,MAAA,GAAS,QAAQ,EAAA,CAAG,MAAA;AAAA,EACtB;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.js","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] no host configured: references draw names with no doors. \" +\n \"Call configureEntityRefs(...) once before the first render.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
package/dist/entity-ref.cjs
CHANGED
|
@@ -43,7 +43,7 @@ __export(entityRefEntry_exports, {
|
|
|
43
43
|
entityRefsConfigured: () => entityRefsConfigured,
|
|
44
44
|
hasAnyDoor: () => hasAnyDoor,
|
|
45
45
|
isNativeNewTabClick: () => isNativeNewTabClick,
|
|
46
|
-
isUuidValue: () => isUuidValue,
|
|
46
|
+
isUuidValue: () => import_uuid.isUuidValue,
|
|
47
47
|
resolveEntityDoors: () => resolveEntityDoors,
|
|
48
48
|
segmentSentenceIds: () => segmentSentenceIds,
|
|
49
49
|
toastDoor: () => toastDoor,
|
|
@@ -103,9 +103,6 @@ function isNativeNewTabClick(e) {
|
|
|
103
103
|
// src/entity-ref/doors.ts
|
|
104
104
|
var import_source = require("@ai-matrx/content-ir/source");
|
|
105
105
|
var import_uuid = require("@ai-matrx/kit/uuid");
|
|
106
|
-
function isUuidValue(value) {
|
|
107
|
-
return typeof value === "string" && (0, import_uuid.isRfc9562Uuid)(value.trim());
|
|
108
|
-
}
|
|
109
106
|
var PEEK_KEY_BY_TOKEN = {
|
|
110
107
|
app: "agent_app",
|
|
111
108
|
pick_list: "pick_list",
|