@ai-matrx/content-ir-react 0.24.5 → 0.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/{directive-host-QjoZEeik.d.cts → directive-host-BF9Zzfbr.d.cts} +6 -0
- package/dist/{directive-host-QjoZEeik.d.ts → directive-host-BF9Zzfbr.d.ts} +6 -0
- package/dist/directives.cjs +43 -9
- package/dist/directives.cjs.map +1 -1
- package/dist/directives.d.cts +12 -3
- package/dist/directives.d.ts +12 -3
- package/dist/directives.js +44 -10
- package/dist/directives.js.map +1 -1
- package/dist/{host-types-DvZukz6J.d.ts → host-types-CBZTM8am.d.ts} +1 -1
- package/dist/{host-types-B2Q8fiU8.d.cts → host-types-CuCbs6Bc.d.cts} +1 -1
- package/dist/host.cjs.map +1 -1
- package/dist/host.d.cts +3 -3
- package/dist/host.d.ts +3 -3
- package/dist/host.js.map +1 -1
- package/dist/index.cjs +43 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +46 -12
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +42 -9
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +45 -12
- package/dist/react.js.map +1 -1
- package/dist/{route-Bq6db_zH.d.cts → route-B9dsQHWZ.d.cts} +6 -0
- package/dist/{route-DStinBoZ.d.ts → route-CO_7dx0A.d.ts} +6 -0
- package/dist/route.d.cts +1 -1
- package/dist/route.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { KindDefinition } from '@ai-matrx/content-ir';
|
|
3
3
|
import { d as ComponentResolutionSource, a as ContentIrErrorReporter } from './component-resolution.types-BQa2ik3i.js';
|
|
4
|
-
import { D as DirectiveHost } from './directive-host-
|
|
4
|
+
import { D as DirectiveHost } from './directive-host-BF9Zzfbr.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* THE HOST CONTRACT — everything this package refuses to decide.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { KindDefinition } from '@ai-matrx/content-ir';
|
|
3
3
|
import { d as ComponentResolutionSource, a as ContentIrErrorReporter } from './component-resolution.types-BQa2ik3i.cjs';
|
|
4
|
-
import { D as DirectiveHost } from './directive-host-
|
|
4
|
+
import { D as DirectiveHost } from './directive-host-BF9Zzfbr.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* THE HOST CONTRACT — everything this package refuses to decide.
|
package/dist/host.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../host.ts","../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx","../directives/directive-host.tsx"],"sourcesContent":["/**\n * `@ai-matrx/content-ir-react/host` — the contract every consumer wires once:\n * the scream seam, the host/seam types, and the React provider.\n *\n * NOTE: this entry is stamped \"use client\" (it carries the provider). The\n * TYPES here are importable from anywhere; a server-side module that needs\n * only pure route logic imports `/route` instead.\n */\nexport * from \"./host/error-report\";\nexport * from \"./host/host-types\";\nexport * from \"./host/ContentIrProvider\";\n","/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\nimport type { DirectiveHost } from \"../directives/directive-host\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n /**\n * The Kind Directives seams (apply / open item / copy / noun catalog / item\n * kind). Optional: a host without them still renders every directive card,\n * apply-less and copy-less — honest chrome, never hidden content. Provided\n * to the directive tier by `ContentIrRenderProvider`; a host that has not\n * adopted the render provider mounts `DirectiveHostProvider` directly.\n */\n directives?: DirectiveHost;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n /**\n * `hasSettled` is optional and read ONLY to suppress a negative verdict from\n * a registry that has not loaded yet — see THE COLD-VERDICT RULE on\n * `ComponentResolutionSource`.\n */\n components: Pick<ComponentResolutionSource, \"resolve\"> &\n Partial<Pick<ComponentResolutionSource, \"hasSettled\">>;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\nimport { DirectiveHostProvider } from \"../directives/directive-host\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n <DirectiveHostProvider host={host.directives ?? {}}>{children}</DirectiveHostProvider>\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC0HO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC1IA,IAAAA,gBAAmE;;;ACQnE,mBAA0D;AA0QtD;AApBJ,IAAM,2BAAuB,4BAAoC,IAAI;AAOrE,IAAM,4BAAwB,4BAA8B,CAAC,CAAC;AA4BvD,SAAS,sBAAsB,EAAE,MAAM,SAAS,GAA+B;AACpF,SAAO,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,MAAO,UAAS;AAC/D;;;ADjRM,IAAAC,sBAAA;AAbN,IAAM,2BAAuB,6BAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,6CAAC,qBAAqB,UAArB,EAA8B,OAAO,MACpC,uDAAC,yBAAsB,MAAM,KAAK,cAAc,CAAC,GAAI,UAAS,GAChE;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,aAAO,0BAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,aAAO,uBAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":["import_react","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../host.ts","../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx","../directives/directive-host.tsx"],"sourcesContent":["/**\n * `@ai-matrx/content-ir-react/host` — the contract every consumer wires once:\n * the scream seam, the host/seam types, and the React provider.\n *\n * NOTE: this entry is stamped \"use client\" (it carries the provider). The\n * TYPES here are importable from anywhere; a server-side module that needs\n * only pure route logic imports `/route` instead.\n */\nexport * from \"./host/error-report\";\nexport * from \"./host/host-types\";\nexport * from \"./host/ContentIrProvider\";\n","/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\nimport type { DirectiveHost } from \"../directives/directive-host\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n /**\n * The Kind Directives seams (apply / open item / copy / noun catalog / item\n * kind). Optional: a host without them still renders every directive card,\n * apply-less and copy-less — honest chrome, never hidden content. Provided\n * to the directive tier by `ContentIrRenderProvider`; a host that has not\n * adopted the render provider mounts `DirectiveHostProvider` directly.\n */\n directives?: DirectiveHost;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n /**\n * `hasSettled` is optional and read ONLY to suppress a negative verdict from\n * a registry that has not loaded yet — see THE COLD-VERDICT RULE on\n * `ComponentResolutionSource`.\n */\n components: Pick<ComponentResolutionSource, \"resolve\"> &\n Partial<Pick<ComponentResolutionSource, \"hasSettled\">>;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\nimport { DirectiveHostProvider } from \"../directives/directive-host\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n <DirectiveHostProvider host={host.directives ?? {}}>{children}</DirectiveHostProvider>\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n /**\n * The text behind \"Details\", when the host words it (e.g. the server's field\n * names read as the form labels them — \"Title is required\", never\n * \"name is required\"). Absent → the raw text.\n */\n details?: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC0HO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC1IA,IAAAA,gBAAmE;;;ACQnE,mBAA0D;AAgRtD;AApBJ,IAAM,2BAAuB,4BAAoC,IAAI;AAOrE,IAAM,4BAAwB,4BAA8B,CAAC,CAAC;AA4BvD,SAAS,sBAAsB,EAAE,MAAM,SAAS,GAA+B;AACpF,SAAO,4CAAC,qBAAqB,UAArB,EAA8B,OAAO,MAAO,UAAS;AAC/D;;;ADvRM,IAAAC,sBAAA;AAbN,IAAM,2BAAuB,6BAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,6CAAC,qBAAqB,UAArB,EAA8B,OAAO,MACpC,uDAAC,yBAAsB,MAAM,KAAK,cAAc,CAAC,GAAI,UAAS,GAChE;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,aAAO,0BAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,aAAO,uBAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":["import_react","import_jsx_runtime"]}
|
package/dist/host.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { b as ContentIrErrorReport, a as ContentIrErrorReporter, c as consoleErrorReporter } from './component-resolution.types-BQa2ik3i.cjs';
|
|
2
|
-
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-
|
|
3
|
-
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-
|
|
2
|
+
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-CuCbs6Bc.cjs';
|
|
3
|
+
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-CuCbs6Bc.cjs';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import '@ai-matrx/content-ir';
|
|
7
|
-
import './directive-host-
|
|
7
|
+
import './directive-host-BF9Zzfbr.cjs';
|
|
8
8
|
|
|
9
9
|
interface ContentIrRenderProviderProps {
|
|
10
10
|
host: ContentIrHost;
|
package/dist/host.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { b as ContentIrErrorReport, a as ContentIrErrorReporter, c as consoleErrorReporter } from './component-resolution.types-BQa2ik3i.js';
|
|
2
|
-
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-
|
|
3
|
-
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-
|
|
2
|
+
import { C as ContentIrHost, K as KindRouteEnv } from './host-types-CBZTM8am.js';
|
|
3
|
+
export { a as ContentIrRenderSeams, I as IrRenderBlock, b as IrRoutableBlock, c as KindDefinitionSource, S as StructuredValueRenderProps, r as routeEnvOf } from './host-types-CBZTM8am.js';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
import '@ai-matrx/content-ir';
|
|
7
|
-
import './directive-host-
|
|
7
|
+
import './directive-host-BF9Zzfbr.js';
|
|
8
8
|
|
|
9
9
|
interface ContentIrRenderProviderProps {
|
|
10
10
|
host: ContentIrHost;
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx","../directives/directive-host.tsx"],"sourcesContent":["/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\nimport type { DirectiveHost } from \"../directives/directive-host\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n /**\n * The Kind Directives seams (apply / open item / copy / noun catalog / item\n * kind). Optional: a host without them still renders every directive card,\n * apply-less and copy-less — honest chrome, never hidden content. Provided\n * to the directive tier by `ContentIrRenderProvider`; a host that has not\n * adopted the render provider mounts `DirectiveHostProvider` directly.\n */\n directives?: DirectiveHost;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n /**\n * `hasSettled` is optional and read ONLY to suppress a negative verdict from\n * a registry that has not loaded yet — see THE COLD-VERDICT RULE on\n * `ComponentResolutionSource`.\n */\n components: Pick<ComponentResolutionSource, \"resolve\"> &\n Partial<Pick<ComponentResolutionSource, \"hasSettled\">>;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\nimport { DirectiveHostProvider } from \"../directives/directive-host\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n <DirectiveHostProvider host={host.directives ?? {}}>{children}</DirectiveHostProvider>\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n"],"mappings":";;;AA2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC0HO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC1IA,SAAS,iBAAAA,gBAAe,cAAAC,aAAY,eAA+B;;;ACQnE,SAAS,eAAe,kBAAkC;AA0QtD;AApBJ,IAAM,uBAAuB,cAAoC,IAAI;AAOrE,IAAM,wBAAwB,cAA8B,CAAC,CAAC;AA4BvD,SAAS,sBAAsB,EAAE,MAAM,SAAS,GAA+B;AACpF,SAAO,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,MAAO,UAAS;AAC/D;;;ADjRM,gBAAAC,YAAA;AAbN,IAAM,uBAAuBC,eAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,gBAAAD,KAAC,qBAAqB,UAArB,EAA8B,OAAO,MACpC,0BAAAA,KAAC,yBAAsB,MAAM,KAAK,cAAc,CAAC,GAAI,UAAS,GAChE;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,SAAOE,YAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,SAAO,QAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":["createContext","useContext","jsx","createContext","useContext"]}
|
|
1
|
+
{"version":3,"sources":["../host/error-report.ts","../host/host-types.ts","../host/ContentIrProvider.tsx","../directives/directive-host.tsx"],"sourcesContent":["/**\n * THE SCREAM SEAM.\n *\n * Every recovery path in this package is loud: a defective component row, a\n * failed resolver load, a kind whose component throws on a provisional value.\n * The package refuses to own where those screams land — matrx-frontend routes\n * them to the Error Inspector, the dashboard to its own log, the extension to\n * its background page. Each host binds one function.\n *\n * A host that binds a no-op has chosen silence, which is a defect in itself;\n * {@link consoleErrorReporter} is the honest default.\n */\n\nexport interface ContentIrErrorReport {\n /** Always `\"content-ir\"` — hosts key their capture stores on it. */\n source: \"content-ir\";\n message: string;\n name?: string;\n stack?: string;\n /** Free-form grouping key (the host's `relation`), e.g. `\"partial-kind\"`. */\n relation?: string;\n raw?: unknown;\n}\n\nexport type ContentIrErrorReporter = (report: ContentIrErrorReport) => void;\n\n/** The default when a host binds nothing: never silent. */\nexport const consoleErrorReporter: ContentIrErrorReporter = (report) => {\n console.error(`[content-ir] ${report.message}`, report.raw ?? \"\");\n};\n","/**\n * THE HOST CONTRACT — everything this package refuses to decide.\n *\n * The kernel (`@ai-matrx/content-ir`) proved the shape: extract the portable\n * part, let host capability enter through explicit named seams. The render\n * layer needs four things it must never own:\n *\n * 1. WHERE KIND DEFINITIONS COME FROM (a bundled table, `content_ir`, a REST\n * call). The route only asks \"is this kind registered, and does it carry a\n * legacy bridge / a partial-ready opt-in\".\n * 2. WHERE COMPONENT ROWS COME FROM — {@link ComponentResolutionSource}. The\n * package ships `ComponentResolver`, which any host can construct with its\n * own loaders; a host with its own resolver only has to satisfy the type.\n * 3. HOW A ROUTED BLOCK ACTUALLY DRAWS. `applyIrKindRoute` decides a block's\n * TYPE; turning that type into pixels is the host's dispatch table\n * (matrx-frontend's `BlockRenderer`, the dashboard's small map). The\n * package never imports a component library.\n * 4. WHERE SCREAMS LAND — {@link ContentIrErrorReporter}.\n *\n * No Next.js, no Redux, no Supabase, no router, no host error capture. If a\n * seam is missing, ADD A SEAM — never an import.\n */\n\nimport type { ReactNode } from \"react\";\nimport type { KindDefinition } from \"@ai-matrx/content-ir\";\nimport type { ContentIrErrorReporter } from \"./error-report\";\nimport type { ComponentResolutionSource } from \"../resolver/component-resolution.types\";\nimport type { DirectiveHost } from \"../directives/directive-host\";\n\n/**\n * The minimum a render block must expose for the kind route to work. Hosts\n * pass their own richer block type through; the route is generic over `T` and\n * preserves every extra field.\n */\nexport interface IrRoutableBlock {\n type: string;\n serverData?: Record<string, unknown>;\n metadata?: Record<string, unknown>;\n}\n\n/** A routable block that also carries its source text (the raw region). */\nexport interface IrRenderBlock extends IrRoutableBlock {\n content: string;\n language?: string;\n}\n\n/**\n * Where registered kinds come from. `getDefinition` is the only method the\n * pure route needs; the rest drive the granular repaint and the warm-up tick\n * that keeps a cold registry from being mistaken for \"this kind has no\n * component\".\n */\nexport interface KindDefinitionSource {\n getDefinition(kind: string): KindDefinition | undefined;\n /** Monotonic per-kind version — the repaint snapshot key. */\n getKindVersion(kind: string): number;\n subscribeKind(kind: string, listener: () => void): () => void;\n /** One definition load per app session. */\n ensureWarm(): Promise<void>;\n}\n\n/**\n * The rendering seams. Everything here returns host UI; the package supplies\n * the DECISIONS and the chrome-free structure around them.\n */\nexport interface ContentIrRenderSeams {\n /**\n * Draw a block the kind route has already typed. This is the host's dispatch\n * table — the single place a component key becomes a component.\n */\n renderBlock(block: IrRenderBlock): ReactNode;\n /**\n * THE FLOOR: render ANY JSON value as a human document. Reached when a kind\n * has no render-trusted component, when the value is not an object at all,\n * and by the generic structured view.\n *\n * This is deliberately a seam and not a bundled component. Rendering a value\n * WELL means prose through the host's markdown renderer, media through the\n * host's file handler, and uniform arrays through the host's data table —\n * all of which are host property. A host that has none of those can pass a\n * `<pre>`; it will be honest, just plain.\n */\n renderValue(props: StructuredValueRenderProps): ReactNode;\n /**\n * The \"still arriving\" indicator used by the provisional frame. Optional —\n * hosts without a shimmer get plain text.\n */\n renderShimmer?(text: string): ReactNode;\n /**\n * The honest \"this shape has no custom component yet\" notice. Optional: the\n * package draws a plain amber line when a host supplies nothing, and a host\n * with an icon set or its own callout component supplies that instead. It is\n * a seam and not a bundled component because this package depends on no icon\n * library.\n */\n renderNotice?(text: string): ReactNode;\n}\n\nexport interface StructuredValueRenderProps {\n value: unknown;\n /** The kind slug this value claims, when known. Honesty line only — never a renderer choice. */\n kind?: string;\n /** Why this shape has no custom view, in human words. */\n note?: string;\n /** Show the \"what this is / raw data\" footer. Default true. */\n footer?: boolean;\n}\n\n/**\n * One host, wired once, read by every component in this package through\n * {@link ContentIrRenderProvider}.\n */\nexport interface ContentIrHost extends ContentIrRenderSeams {\n kinds: KindDefinitionSource;\n components: ComponentResolutionSource;\n reportError: ContentIrErrorReporter;\n /**\n * The `kind_component.platform` this host resolves as. \"web\" for every\n * browser UI; the column already models \"react-native\" and friends, and a\n * host that lies here renders the wrong component everywhere.\n */\n platform: string;\n /**\n * The Kind Directives seams (apply / open item / copy / noun catalog / item\n * kind). Optional: a host without them still renders every directive card,\n * apply-less and copy-less — honest chrome, never hidden content. Provided\n * to the directive tier by `ContentIrRenderProvider`; a host that has not\n * adopted the render provider mounts `DirectiveHostProvider` directly.\n */\n directives?: DirectiveHost;\n}\n\n/**\n * The pure route's dependencies — a strict subset of {@link ContentIrHost},\n * because `applyIrKindRoute` is called OUTSIDE React (reducers, stream\n * accumulators, tests) where there is no provider to read.\n */\nexport interface KindRouteEnv {\n kinds: Pick<KindDefinitionSource, \"getDefinition\">;\n /**\n * `hasSettled` is optional and read ONLY to suppress a negative verdict from\n * a registry that has not loaded yet — see THE COLD-VERDICT RULE on\n * `ComponentResolutionSource`.\n */\n components: Pick<ComponentResolutionSource, \"resolve\"> &\n Partial<Pick<ComponentResolutionSource, \"hasSettled\">>;\n reportError: ContentIrErrorReporter;\n platform: string;\n}\n\n/** Narrow a host (or anything host-shaped) to what the pure route needs. */\nexport function routeEnvOf(host: ContentIrHost): KindRouteEnv {\n return {\n kinds: host.kinds,\n components: host.components,\n reportError: host.reportError,\n platform: host.platform,\n };\n}\n","\"use client\";\n\n/**\n * The one place a host is wired in. Everything React in this package reads its\n * capability from here — no module singleton, no import into an app.\n *\n * A host mounts this ONCE, high enough that every kind-rendering surface is\n * inside it:\n *\n * ```tsx\n * <ContentIrRenderProvider host={matrxContentIrHost}>\n * <App />\n * </ContentIrRenderProvider>\n * ```\n *\n * Reading it outside a provider THROWS rather than falling back to a default.\n * A silent default would render the wrong component for every kind in the app\n * and look like a data problem for weeks.\n */\n\nimport { createContext, useContext, useMemo, type ReactNode } from \"react\";\nimport type { ContentIrHost, KindRouteEnv } from \"./host-types\";\nimport { routeEnvOf } from \"./host-types\";\nimport { DirectiveHostProvider } from \"../directives/directive-host\";\n\nconst ContentIrHostContext = createContext<ContentIrHost | null>(null);\n\nexport interface ContentIrRenderProviderProps {\n host: ContentIrHost;\n children: ReactNode;\n}\n\nexport function ContentIrRenderProvider({\n host,\n children,\n}: ContentIrRenderProviderProps) {\n return (\n <ContentIrHostContext.Provider value={host}>\n <DirectiveHostProvider host={host.directives ?? {}}>{children}</DirectiveHostProvider>\n </ContentIrHostContext.Provider>\n );\n}\n\n/**\n * The wired host, or null. For the rare consumer that can legitimately run\n * without a provider because it was handed its sources explicitly (see\n * `useContentIrKindVersion`). Everything else uses {@link useContentIrHost}.\n */\nexport function useContentIrHostOrNull(): ContentIrHost | null {\n return useContext(ContentIrHostContext);\n}\n\n/** The wired host. Throws outside a provider — see the module doc. */\nexport function useContentIrHost(): ContentIrHost {\n const host = useContentIrHostOrNull();\n if (!host) {\n throw new Error(\n \"[content-ir-react] No ContentIrRenderProvider above this component. \" +\n \"Mount one at the app root with your host adapter (kind definitions, \" +\n \"component resolver, renderBlock, renderValue, reportError).\",\n );\n }\n return host;\n}\n\n/** The wired host narrowed to what the pure route functions take. */\nexport function useKindRouteEnv(): KindRouteEnv {\n const host = useContentIrHost();\n return useMemo(() => routeEnvOf(host), [host]);\n}\n","\"use client\";\n\n/**\n * THE DIRECTIVE HOST CONTRACT — what the directive tier refuses to decide.\n *\n * The package owns the DECISIONS (decode → renderer → card → floor, the\n * position law, never-null rendering) and the card itself. Four things stay\n * host property and enter through named seams:\n *\n * 1. APPLYING a side-effect directive — `POST /directives/confirm` as the\n * user, with the host's auth and base URL. Absent → the Apply control is\n * ABSENT (honest), never a dead button.\n * 2. OPENING an item to read it before approving — a window panel, a dialog,\n * a route. Absent → items are not clickable.\n * 3. COPY controls — host chrome (matrx-frontend's CopyButtons). Absent → none.\n * 4. The NOUN catalog + item-kind lookup — server-derived tables the host\n * mirrors (or reads from its kind catalog's `items` edges).\n * 5. ASKING (`ask`), NAMING a record (`renderRecord`), and READING the ledger\n * (`applyState`) — the consequence before the click, the doors, and the\n * state that survives a reload.\n *\n * A host that has adopted `ContentIrRenderProvider` passes `directives` on its\n * ContentIrHost; a host that has NOT (Workflow Studio, 2026-09-08) mounts\n * `DirectiveHostProvider` alone — the directive tier never requires the full\n * render host, because a chat bubble must be able to draw a directive card\n * identically everywhere, today.\n */\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type {\n DecodedDirective,\n DirectiveItemKindLookup,\n DirectiveNounCatalog,\n} from \"@ai-matrx/content-ir\";\n\nexport interface DirectiveApplyResult {\n applied: number;\n failed: number;\n /**\n * The server's own receipt sentence (\"Deleted task “Ship it”.\"), shown in\n * place of a bare count. Never composed client-side.\n */\n message?: string | null;\n /**\n * The records the apply created or changed, so the tally is a way IN to them\n * (no dead ends). Rendered through `renderRecord`; absent → the sentence alone.\n */\n records?: DirectiveRecordRef[];\n /**\n * For an UPDATE: what each item's fields held just BEFORE the write, by item\n * index (`null` for an item the server did not record). The card draws the\n * applied change from this record — never from a live re-read, which after the\n * apply answers the NEW value (G6A review, 2026-10-02: \"(no change)\" for a\n * change that happened).\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/**\n * What the server's action ledger says about ONE block, read on mount so a\n * reloaded page never offers \"Apply\" for work that already ran (reviewer\n * defect 5, 2026-10-02).\n *\n * - `not_applied` — still to do (or partly done: the batch re-applies, and the\n * server replays the members it already holds). The card offers Apply.\n * - `in_flight` — another request is applying it right now. The card says it\n * is finishing and asks again shortly; it offers neither Apply nor a tally.\n * - `applied` — the ledger holds every item. The card shows the tally exactly\n * as a fresh apply would: the ledger's own sentence and the records, as doors.\n */\nexport interface DirectiveApplyState {\n state: \"not_applied\" | \"in_flight\" | \"applied\";\n /** The ledger row's sentence (\"Created task.\"), never composed client-side. */\n message?: string | null;\n /**\n * The records the LATEST apply wrote — the tally's doors. After \"Run again\"\n * that is the newest copy, never the first.\n */\n records?: DirectiveRecordRef[];\n /**\n * How many times the ledger holds this block as applied: 1 for the original,\n * one more for every \"Run again\". Absent → 1. A create that ran twice made\n * two records, and the card says so (reviewer, 2026-10-02).\n */\n copies?: number;\n /**\n * For an applied UPDATE: each item's replaced values, by item index, from the\n * ledger row (`null` where the ledger has none — a row from before 2026-10-02).\n * Absent → the card says only what each field was set to.\n */\n before?: ReadonlyArray<Record<string, unknown> | null>;\n}\n\n/** One record a directive names: the noun it is, and its id. */\nexport interface DirectiveRecordRef {\n noun: string;\n id: string;\n}\n\nexport interface DirectiveRecordProps extends DirectiveRecordRef {\n /**\n * What to show until (or unless) the host resolves the live name —\n * \"Task 1a2b3c4d\". Never blank, never \"Item\".\n */\n fallback: string;\n /** Where it is drawn: an item row, the confirm dialog, or the applied tally. */\n context: \"row\" | \"dialog\" | \"applied\";\n /**\n * True when the record is (about to be) in the trash — the host may still\n * name it but should not promise it opens as a live record.\n */\n trashed?: boolean;\n}\n\n/** What the person is being asked to approve — everything the card knows. */\nexport interface DirectiveAskRequest {\n directive: DecodedDirective;\n /** The items, exactly as they will be sent. */\n items: Record<string, unknown>[];\n /** The noun's human label (\"Task\"), from the host's catalog when it has one. */\n nounLabel: string;\n /**\n * True for \"Run again\": the ledger already holds this block, and a yes runs\n * it a SECOND time (`force`) — another copy for a create, the same fields\n * written again for an update, another delete for a restored record. The\n * question must say so.\n */\n again?: boolean;\n}\n\n/**\n * The shell a card hands its host — the two keys, plus WHERE it sits.\n *\n * `conversationId` is the conversation the card renders in (a chat message),\n * absent in a person's own content (a note). It is the idempotency NAMESPACE:\n * a card in an agent's message must apply under the SAME key as that\n * proposal's Approve button, or the one action could run twice.\n */\nexport interface DirectiveShell {\n __kind: string;\n items: Record<string, unknown>[];\n conversationId?: string;\n /** \"Run again\": skip the ledger's dedup and apply a second time. */\n force?: boolean;\n}\n\nexport interface DirectiveOpenItemOptions {\n /** The item, `__kind`-stamped when the shape has an item kind. */\n item: Record<string, unknown>;\n /** The content-IR kind this item IS, or null when the shape has none. */\n itemKind: string | null;\n /** What the item is called — the same title the card shows. */\n title: string;\n /** \"Run Create agent definition · item 1 of 1\". */\n subtitle: string | null;\n directive: DecodedDirective;\n index: number;\n total: number;\n}\n\nexport interface DirectiveCopyProps {\n /**\n * What the control is called to a screen reader. Never an id: for a record it\n * is type-generic (\"this task\"); a host with the record's live name replaces\n * it through `record`.\n */\n label: string;\n /** The existing record this control copies, when it copies one — to name it. */\n record?: DirectiveRecordRef;\n /** The value to copy — the whole shell or one item. */\n value: unknown;\n /** The item's kind, when copying an item. */\n kind?: string | null;\n size: \"icon\" | \"xs\";\n}\n\nexport interface DirectiveHost {\n /**\n * Apply a side-effect directive as the user (the server re-validates every\n * item against the registered model and runs the ONE handler; idempotent).\n * Reject with an Error whose message is safe to show.\n */\n confirm?: (shell: DirectiveShell) => Promise<DirectiveApplyResult>;\n /**\n * Ask the person BEFORE anything runs, naming the consequence (the records,\n * what changes). Resolve `true` to go ahead, `false` to leave the card as it\n * was. The Apply control stays idle while this is open — nothing reads as\n * \"applying\" until the person has said yes. Absent → `confirm` is called\n * directly (a host that asks inside `confirm` keeps working, but its card\n * will read \"Applying…\" while its dialog is up).\n */\n ask?: (request: DirectiveAskRequest) => Promise<boolean>;\n /**\n * Has this exact block already been applied? Read ONCE when the card mounts\n * (and again while the answer is `in_flight`), so the card survives a reload:\n * the server ledger, not component state, is what knows. The identity is the\n * server's (it hashes the validated items in the same namespace `confirm`\n * applies in), so a host asks — it never computes. Batch on the host side if\n * a page carries many cards. Reject with an Error when the ledger cannot be\n * read: the card reports it and offers Apply, which is safe because `confirm`\n * is idempotent. Absent → the card starts at Apply, as before.\n */\n applyState?: (shell: DirectiveShell) => Promise<DirectiveApplyState>;\n /**\n * Read the CURRENT values of ONE existing record, so an update says what it\n * replaces — \"Status open → done\", never just \"→ done\" (reviewer,\n * 2026-10-02). Resolve `null` when the record cannot be read (no access, no\n * such record, a noun the host cannot read); reject only for a real failure.\n * Absent → an update row shows the new values alone, as before.\n */\n readRecord?: (ref: DirectiveRecordRef) => Promise<Record<string, unknown> | null>;\n /**\n * Draw ONE existing record by its live name, as a way to open it. Used on\n * update/delete rows (the record that will change), in the host's own ask\n * dialog if it likes, and on the applied tally (what was written). Absent →\n * the fallback text, unlinked.\n */\n renderRecord?: (props: DirectiveRecordProps) => ReactNode;\n /** Open ONE item to read it properly before approving the write. */\n openItem?: (options: DirectiveOpenItemOptions) => void;\n /** Host copy controls. */\n renderCopy?: (props: DirectiveCopyProps) => ReactNode;\n /**\n * The app's word for one stored value of one pick-list field — the SAME word\n * the record's own screens and the write forms show (\"incomplete\" on a task\n * reads \"Inbox\"). One value, one display word everywhere (G8A review,\n * 2026-10-02: the card said \"Status incomplete → completed\"). Return null for\n * a field that is not a pick-list: its value is shown as written. Absent →\n * every value is shown as stored.\n */\n valueLabel?: (ref: DirectiveValueRef) => string | null;\n /** The mirrored noun catalog (label / family / title column). */\n nouns?: DirectiveNounCatalog;\n /** slug → the kind ONE item is (THE DIRECTIVE⇄KIND SEAM), or null. */\n itemKind?: DirectiveItemKindLookup;\n /** Where a decode failure or an unhonourable shell is reported. Default: console.error. */\n reportError?: (message: string) => void;\n /**\n * Plain words for a failed apply the host recognises (\"This button can't\n * create a task yet.\" + \"Create it from Tasks instead.\"). The card never shows\n * the server's raw text as its sentence: it shows these words — or its own\n * verb-aware default — and keeps the raw text behind \"Details\". Return null\n * to use the default.\n */\n explainFailure?: (failure: DirectiveFailure) => DirectiveFailureWords | null;\n}\n\n/** One stored value of one field of one record type. */\nexport interface DirectiveValueRef {\n noun: string;\n field: string;\n value: string;\n}\n\n/** One failed apply, as the card knows it. */\nexport interface DirectiveFailure {\n /** The server's / host's own text — technical; shown only behind Details. */\n raw: string;\n directiveClass: string;\n noun: string;\n /** The noun's display label (\"Task\"). */\n nounLabel: string;\n /** Items that failed, when some applied and some did not. */\n failed?: number;\n /** Items in the block. */\n total?: number;\n}\n\n/** What failed and what to do — each one short sentence. */\nexport interface DirectiveFailureWords {\n what: string;\n next: string;\n /**\n * The text behind \"Details\", when the host words it (e.g. the server's field\n * names read as the form labels them — \"Title is required\", never\n * \"name is required\"). Absent → the raw text.\n */\n details?: string;\n}\n\nconst DirectiveHostContext = createContext<DirectiveHost | null>(null);\n\n/** Where a directive renders — today, the conversation it sits in (if any). */\nexport interface DirectiveScope {\n conversationId?: string | null;\n}\n\nconst DirectiveScopeContext = createContext<DirectiveScope>({});\n\n/**\n * Tell every card below WHERE it renders. A host draws a chat message's\n * directives inside one of these (or passes `conversationId` to\n * `DirectiveRender`), so the card applies in that conversation's namespace —\n * the same key the agent's proposal approves under. A note mounts none.\n */\nexport function DirectiveScopeProvider({\n conversationId,\n children,\n}: DirectiveScope & { children: ReactNode }) {\n return (\n <DirectiveScopeContext.Provider value={{ conversationId: conversationId ?? null }}>\n {children}\n </DirectiveScopeContext.Provider>\n );\n}\n\nexport function useDirectiveScope(): DirectiveScope {\n return useContext(DirectiveScopeContext);\n}\n\nexport interface DirectiveHostProviderProps {\n host: DirectiveHost;\n children: ReactNode;\n}\n\nexport function DirectiveHostProvider({ host, children }: DirectiveHostProviderProps) {\n return <DirectiveHostContext.Provider value={host}>{children}</DirectiveHostContext.Provider>;\n}\n\nconst EMPTY_HOST: DirectiveHost = {};\n\n/**\n * The wired directive host. Unlike the render host this does NOT throw when\n * unwired: a directive still renders (named, itemised, copy-less, apply-less)\n * — degrading the chrome is honest, hiding the content is not.\n */\nexport function useDirectiveHost(): DirectiveHost {\n return useContext(DirectiveHostContext) ?? EMPTY_HOST;\n}\n"],"mappings":";;;AA2BO,IAAM,uBAA+C,CAAC,WAAW;AACtE,UAAQ,MAAM,gBAAgB,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE;AAClE;;;AC0HO,SAAS,WAAW,MAAmC;AAC5D,SAAO;AAAA,IACL,OAAO,KAAK;AAAA,IACZ,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,EACjB;AACF;;;AC1IA,SAAS,iBAAAA,gBAAe,cAAAC,aAAY,eAA+B;;;ACQnE,SAAS,eAAe,kBAAkC;AAgRtD;AApBJ,IAAM,uBAAuB,cAAoC,IAAI;AAOrE,IAAM,wBAAwB,cAA8B,CAAC,CAAC;AA4BvD,SAAS,sBAAsB,EAAE,MAAM,SAAS,GAA+B;AACpF,SAAO,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,MAAO,UAAS;AAC/D;;;ADvRM,gBAAAC,YAAA;AAbN,IAAM,uBAAuBC,eAAoC,IAAI;AAO9D,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AACF,GAAiC;AAC/B,SACE,gBAAAD,KAAC,qBAAqB,UAArB,EAA8B,OAAO,MACpC,0BAAAA,KAAC,yBAAsB,MAAM,KAAK,cAAc,CAAC,GAAI,UAAS,GAChE;AAEJ;AAOO,SAAS,yBAA+C;AAC7D,SAAOE,YAAW,oBAAoB;AACxC;AAGO,SAAS,mBAAkC;AAChD,QAAM,OAAO,uBAAuB;AACpC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,kBAAgC;AAC9C,QAAM,OAAO,iBAAiB;AAC9B,SAAO,QAAQ,MAAM,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;AAC/C;","names":["createContext","useContext","jsx","createContext","useContext"]}
|
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ __export(index_exports, {
|
|
|
58
58
|
SideEffectDirectiveCard: () => SideEffectDirectiveCard,
|
|
59
59
|
TARGETING_CLASSES: () => TARGETING_CLASSES,
|
|
60
60
|
applyIrKindRoute: () => applyIrKindRoute,
|
|
61
|
+
changesNothing: () => changesNothing,
|
|
61
62
|
consoleErrorReporter: () => consoleErrorReporter,
|
|
62
63
|
createDbKindComponentCache: () => createDbKindComponentCache,
|
|
63
64
|
createKindRouteBinding: () => createKindRouteBinding,
|
|
@@ -932,6 +933,9 @@ function itemChanges(item, current, options = {}) {
|
|
|
932
933
|
}
|
|
933
934
|
return out;
|
|
934
935
|
}
|
|
936
|
+
function changesNothing(changes) {
|
|
937
|
+
return changes.every((change) => change.same === true);
|
|
938
|
+
}
|
|
935
939
|
|
|
936
940
|
// directives/record-values.ts
|
|
937
941
|
var import_react4 = require("react");
|
|
@@ -1440,7 +1444,7 @@ function ApplyDirectiveButton({
|
|
|
1440
1444
|
onFocus: warm,
|
|
1441
1445
|
disabled: view.status === "applying" || view.status === "asking" || items.length === 0,
|
|
1442
1446
|
"data-apply-tone": muted ? "muted" : destructive ? "destructive" : "default",
|
|
1443
|
-
title: muted ? "
|
|
1447
|
+
title: muted ? "Applying it changes nothing." : void 0,
|
|
1444
1448
|
className: `inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 py-1 text-xs font-medium disabled:opacity-50 ${muted ? "border-border/60 bg-background text-muted-foreground hover:bg-accent" : destructive ? "border-destructive/50 bg-background text-destructive hover:bg-destructive/10" : "border-border bg-background hover:bg-accent"}`,
|
|
1445
1449
|
children: [
|
|
1446
1450
|
view.status === "applying" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(LoaderIcon, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PlayIcon, { className: "h-3.5 w-3.5" }),
|
|
@@ -1480,7 +1484,7 @@ function FailureNotice({
|
|
|
1480
1484
|
raw
|
|
1481
1485
|
}) {
|
|
1482
1486
|
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
1483
|
-
const detail = raw?.trim()
|
|
1487
|
+
const detail = raw?.trim() ? words.details?.trim() || raw.trim() : "";
|
|
1484
1488
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "flex min-w-0 flex-col gap-0.5", "data-apply-failure": true, children: [
|
|
1485
1489
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "min-w-0", children: [
|
|
1486
1490
|
words.what,
|
|
@@ -1613,12 +1617,23 @@ function ItemRow({
|
|
|
1613
1617
|
item,
|
|
1614
1618
|
index,
|
|
1615
1619
|
total,
|
|
1616
|
-
phase
|
|
1620
|
+
phase,
|
|
1621
|
+
onNothing
|
|
1617
1622
|
}) {
|
|
1618
1623
|
const host = useDirectiveHost();
|
|
1619
1624
|
const recordId = TARGETING_CLASSES.has(directive.directiveClass) ? itemRecordId(item) : null;
|
|
1620
1625
|
if (recordId) {
|
|
1621
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1626
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1627
|
+
TargetRow,
|
|
1628
|
+
{
|
|
1629
|
+
directive,
|
|
1630
|
+
item,
|
|
1631
|
+
recordId,
|
|
1632
|
+
index,
|
|
1633
|
+
phase,
|
|
1634
|
+
onNothing
|
|
1635
|
+
}
|
|
1636
|
+
);
|
|
1622
1637
|
}
|
|
1623
1638
|
const titleColumn = (0, import_content_ir8.nounTitleColumn)(directive.noun, host.nouns);
|
|
1624
1639
|
const ownName = itemOwnName(item, titleColumn);
|
|
@@ -1637,7 +1652,8 @@ function ItemRow({
|
|
|
1637
1652
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1638
1653
|
"span",
|
|
1639
1654
|
{
|
|
1640
|
-
className: `min-w-0 shrink-0 truncate
|
|
1655
|
+
className: `min-w-0 line-clamp-2 font-medium [overflow-wrap:anywhere] sm:shrink-0 sm:truncate ${ownName ? "text-foreground" : "italic text-muted-foreground"}`,
|
|
1656
|
+
"data-item-name": "",
|
|
1641
1657
|
"data-item-untitled": ownName ? void 0 : "",
|
|
1642
1658
|
children: title
|
|
1643
1659
|
}
|
|
@@ -1726,7 +1742,8 @@ function TargetRow({
|
|
|
1726
1742
|
item,
|
|
1727
1743
|
recordId,
|
|
1728
1744
|
index,
|
|
1729
|
-
phase
|
|
1745
|
+
phase,
|
|
1746
|
+
onNothing
|
|
1730
1747
|
}) {
|
|
1731
1748
|
const host = useDirectiveHost();
|
|
1732
1749
|
const fallback = recordFallbackName((0, import_content_ir8.nounLabel)(directive.noun, host.nouns));
|
|
@@ -1741,7 +1758,11 @@ function TargetRow({
|
|
|
1741
1758
|
titleColumn: (0, import_content_ir8.nounTitleColumn)(directive.noun, host.nouns),
|
|
1742
1759
|
valueWord: directiveValueWord(host, directive.noun)
|
|
1743
1760
|
}) : [];
|
|
1744
|
-
const
|
|
1761
|
+
const nothing = readsLive && live.values !== null && changesNothing(changes);
|
|
1762
|
+
(0, import_react6.useEffect)(() => {
|
|
1763
|
+
onNothing?.(index, nothing);
|
|
1764
|
+
}, [onNothing, index, nothing]);
|
|
1765
|
+
const name = host.renderRecord ? host.renderRecord({ noun: directive.noun, id: recordId, fallback, context: "row" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "line-clamp-2 min-w-0 font-medium text-foreground [overflow-wrap:anywhere]", children: fallback });
|
|
1745
1766
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "py-1 text-xs", "data-directive-target": recordId, children: [
|
|
1746
1767
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
1747
1768
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "flex min-w-0 flex-1 items-center gap-1 px-1", children: name }),
|
|
@@ -1765,7 +1786,9 @@ function SideEffectDirectiveCard({ directive }) {
|
|
|
1765
1786
|
const [phase, setPhase] = (0, import_react6.useState)(
|
|
1766
1787
|
() => readsApplyLedger(host, directive) ? { phase: "pending" } : { phase: "open" }
|
|
1767
1788
|
);
|
|
1768
|
-
const
|
|
1789
|
+
const [nothingAt, setNothingAt] = (0, import_react6.useState)({});
|
|
1790
|
+
const noteNothing = (index, nothing) => setNothingAt((prev) => prev[index] === nothing ? prev : { ...prev, [index]: nothing });
|
|
1791
|
+
const nothingToChange = directive.directiveClass === "update" && total > 0 && items.every((item, index) => itemChanges(item).length === 0 || nothingAt[index] === true);
|
|
1769
1792
|
const shown = expanded ? items : items.slice(0, ROWS_BEFORE_FOLD);
|
|
1770
1793
|
const hidden = total - shown.length;
|
|
1771
1794
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "my-3 rounded-md border border-border bg-card px-2.5 py-1.5", "data-directive": directive.slug, children: [
|
|
@@ -1794,7 +1817,18 @@ function SideEffectDirectiveCard({ directive }) {
|
|
|
1794
1817
|
total === 0 ? (
|
|
1795
1818
|
// Stated, never silent: an empty batch is a real (and suspicious) state.
|
|
1796
1819
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "mt-1 text-xs text-muted-foreground", children: "No items \u2014 nothing would be written." })
|
|
1797
|
-
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mt-0.5 divide-y divide-border/60", children: shown.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1820
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mt-0.5 divide-y divide-border/60", children: shown.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1821
|
+
ItemRow,
|
|
1822
|
+
{
|
|
1823
|
+
directive,
|
|
1824
|
+
item,
|
|
1825
|
+
index: i,
|
|
1826
|
+
total,
|
|
1827
|
+
phase,
|
|
1828
|
+
onNothing: noteNothing
|
|
1829
|
+
},
|
|
1830
|
+
i
|
|
1831
|
+
)) }),
|
|
1798
1832
|
hidden > 0 || expanded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1799
1833
|
"button",
|
|
1800
1834
|
{
|