@ai-matrx/content-ir-react 0.15.2 → 0.16.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 +35 -0
- package/dist/{directive-host-DJfF35FD.d.cts → directive-host-C4TcPpxX.d.cts} +19 -2
- package/dist/{directive-host-DJfF35FD.d.ts → directive-host-C4TcPpxX.d.ts} +19 -2
- package/dist/directives.cjs +145 -28
- package/dist/directives.cjs.map +1 -1
- package/dist/directives.d.cts +85 -41
- package/dist/directives.d.ts +85 -41
- package/dist/directives.js +145 -28
- package/dist/directives.js.map +1 -1
- package/dist/{host-types-9NfBeqrG.d.ts → host-types-CEc86R-v.d.ts} +1 -1
- package/dist/{host-types-DVIaaGR_.d.cts → host-types-a0XEr5b3.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 +151 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -42
- package/dist/index.d.ts +85 -42
- package/dist/index.js +148 -31
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +144 -33
- 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 +141 -30
- package/dist/react.js.map +1 -1
- package/dist/{route-DDbgc-ID.d.ts → route-De9c5YgW.d.ts} +19 -2
- package/dist/{route-BCtPhF7W.d.cts → route-YcoyR3Fj.d.cts} +19 -2
- package/dist/route.d.cts +1 -1
- package/dist/route.d.ts +1 -1
- package/package.json +3 -3
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\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 /** The records the original apply wrote — the tally's doors. */\n records?: DirectiveRecordRef[];\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 label: string;\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 * 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 /** 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\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;AAwLtD;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;;;AD/LM,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\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\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 label: string;\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 /** 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\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;AAyMtD;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;;;ADhNM,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
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
DIRECTIVE_BLOCK_TYPE: () => DIRECTIVE_BLOCK_TYPE,
|
|
39
39
|
DbKindComponentErrorBoundary: () => DbKindComponentErrorBoundary,
|
|
40
40
|
DelegatedOutput: () => DelegatedOutput,
|
|
41
|
+
DirectiveChangeList: () => DirectiveChangeList,
|
|
41
42
|
DirectiveFallbackCard: () => DirectiveFallbackCard,
|
|
42
43
|
DirectiveHostProvider: () => DirectiveHostProvider,
|
|
43
44
|
DirectiveProvisionalCard: () => DirectiveProvisionalCard,
|
|
@@ -58,6 +59,7 @@ __export(index_exports, {
|
|
|
58
59
|
consoleErrorReporter: () => consoleErrorReporter,
|
|
59
60
|
createDbKindComponentCache: () => createDbKindComponentCache,
|
|
60
61
|
createKindRouteBinding: () => createKindRouteBinding,
|
|
62
|
+
describeChangeValue: () => describeChangeValue,
|
|
61
63
|
envelopeFromPartialKind: () => envelopeFromPartialKind,
|
|
62
64
|
fieldLabel: () => fieldLabel,
|
|
63
65
|
getDirectiveRenderer: () => getDirectiveRenderer,
|
|
@@ -86,7 +88,8 @@ __export(index_exports, {
|
|
|
86
88
|
useContentIrKindVersion: () => useContentIrKindVersion,
|
|
87
89
|
useDirectiveHost: () => useDirectiveHost,
|
|
88
90
|
useDirectiveScope: () => useDirectiveScope,
|
|
89
|
-
useKindRouteEnv: () => useKindRouteEnv
|
|
91
|
+
useKindRouteEnv: () => useKindRouteEnv,
|
|
92
|
+
useRecordValues: () => useRecordValues
|
|
90
93
|
});
|
|
91
94
|
module.exports = __toCommonJS(index_exports);
|
|
92
95
|
|
|
@@ -817,7 +820,7 @@ function useContentIrKindVersion(kind, sources) {
|
|
|
817
820
|
}
|
|
818
821
|
|
|
819
822
|
// react/KindInstanceRender.tsx
|
|
820
|
-
var
|
|
823
|
+
var import_react7 = require("react");
|
|
821
824
|
var import_content_ir9 = require("@ai-matrx/content-ir");
|
|
822
825
|
|
|
823
826
|
// directives/DirectiveRender.tsx
|
|
@@ -849,6 +852,9 @@ function recordFallbackName(nounLabel3, id) {
|
|
|
849
852
|
const short = (0, import_uuid.isUuidShape)(id) ? id.slice(0, 8) : id.length > 12 ? `${id.slice(0, 12)}\u2026` : id;
|
|
850
853
|
return `${nounLabel3} ${short}`;
|
|
851
854
|
}
|
|
855
|
+
function describeChangeValue(value) {
|
|
856
|
+
return describeValue(value);
|
|
857
|
+
}
|
|
852
858
|
function describeValue(value) {
|
|
853
859
|
if (value === null || value === void 0) return { value: "cleared", full: "cleared", clears: true };
|
|
854
860
|
if (typeof value === "string") {
|
|
@@ -877,11 +883,28 @@ function safeJson(value) {
|
|
|
877
883
|
return String(value);
|
|
878
884
|
}
|
|
879
885
|
}
|
|
880
|
-
function
|
|
886
|
+
function sameValue(a, b) {
|
|
887
|
+
if (a === b) return true;
|
|
888
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
889
|
+
const emptyA = a === null || a === void 0 || a === "";
|
|
890
|
+
const emptyB = b === null || b === void 0 || b === "";
|
|
891
|
+
return emptyA && emptyB;
|
|
892
|
+
}
|
|
893
|
+
if (typeof a === "object" || typeof b === "object") return safeJson(a) === safeJson(b);
|
|
894
|
+
return false;
|
|
895
|
+
}
|
|
896
|
+
function itemChanges(item, current, options = {}) {
|
|
881
897
|
const out = [];
|
|
898
|
+
const titleColumn = options.titleColumn ?? null;
|
|
882
899
|
for (const [key, raw] of Object.entries(item)) {
|
|
883
900
|
if (NOT_A_CHANGE.has(key)) continue;
|
|
884
|
-
|
|
901
|
+
const label = key === titleColumn ? "Title" : fieldLabel(key);
|
|
902
|
+
const change = { key, label, ...describeValue(raw) };
|
|
903
|
+
if (current && Object.prototype.hasOwnProperty.call(current, key)) {
|
|
904
|
+
change.before = describeValue(current[key]);
|
|
905
|
+
change.same = sameValue(current[key], raw);
|
|
906
|
+
}
|
|
907
|
+
out.push(change);
|
|
885
908
|
}
|
|
886
909
|
return out;
|
|
887
910
|
}
|
|
@@ -994,12 +1017,23 @@ function ApplyDirectiveButton({
|
|
|
994
1017
|
const conversationId = scope.conversationId || void 0;
|
|
995
1018
|
const items = directive.items;
|
|
996
1019
|
const readsLedger = !!host.applyState && !!host.confirm && directive.parsed.executes && items.length > 0;
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
);
|
|
1020
|
+
const initial = readsLedger ? { status: "checking" } : { status: "idle" };
|
|
1021
|
+
const [state, setState] = (0, import_react4.useState)(initial);
|
|
1000
1022
|
const [elapsed, setElapsed] = (0, import_react4.useState)(0);
|
|
1001
1023
|
const [askingAgain, setAskingAgain] = (0, import_react4.useState)(false);
|
|
1002
1024
|
const startedAt = (0, import_react4.useRef)(null);
|
|
1025
|
+
const identity = JSON.stringify([directive.slug, items, conversationId ?? null]);
|
|
1026
|
+
const [stateFor, setStateFor] = (0, import_react4.useState)(identity);
|
|
1027
|
+
if (stateFor !== identity) {
|
|
1028
|
+
setStateFor(identity);
|
|
1029
|
+
setState(initial);
|
|
1030
|
+
setAskingAgain(false);
|
|
1031
|
+
setElapsed(0);
|
|
1032
|
+
}
|
|
1033
|
+
const currentIdentity = (0, import_react4.useRef)(identity);
|
|
1034
|
+
(0, import_react4.useEffect)(() => {
|
|
1035
|
+
currentIdentity.current = identity;
|
|
1036
|
+
}, [identity]);
|
|
1003
1037
|
const nounText = (0, import_content_ir3.nounLabel)(directive.noun, host.nouns);
|
|
1004
1038
|
const shellKey = readsLedger ? JSON.stringify([directive.slug, items, conversationId ?? null]) : "";
|
|
1005
1039
|
const read = host.applyState;
|
|
@@ -1022,7 +1056,8 @@ function ApplyDirectiveButton({
|
|
|
1022
1056
|
applied: shellItems.length,
|
|
1023
1057
|
failed: 0,
|
|
1024
1058
|
message: answer.message?.trim() ? answer.message.trim() : null,
|
|
1025
|
-
records: answer.records ?? []
|
|
1059
|
+
records: answer.records ?? [],
|
|
1060
|
+
copies: Math.max(1, answer.copies ?? 1)
|
|
1026
1061
|
} : prev
|
|
1027
1062
|
);
|
|
1028
1063
|
} else if (answer.state === "in_flight" && polls < FINISH_POLLS_MAX) {
|
|
@@ -1062,6 +1097,9 @@ function ApplyDirectiveButton({
|
|
|
1062
1097
|
async function handleApply(again = false) {
|
|
1063
1098
|
if (!confirm) return;
|
|
1064
1099
|
const before = state;
|
|
1100
|
+
const askedFor = identity;
|
|
1101
|
+
const stillHere = () => currentIdentity.current === askedFor;
|
|
1102
|
+
const priorCopies = state.status === "applied" ? state.copies : 0;
|
|
1065
1103
|
if (host.ask) {
|
|
1066
1104
|
if (again) setAskingAgain(true);
|
|
1067
1105
|
else setState({ status: "asking" });
|
|
@@ -1074,6 +1112,7 @@ function ApplyDirectiveButton({
|
|
|
1074
1112
|
...again ? { again: true } : {}
|
|
1075
1113
|
});
|
|
1076
1114
|
} catch (error) {
|
|
1115
|
+
if (!stillHere()) return;
|
|
1077
1116
|
setAskingAgain(false);
|
|
1078
1117
|
setState({
|
|
1079
1118
|
status: "error",
|
|
@@ -1081,6 +1120,7 @@ function ApplyDirectiveButton({
|
|
|
1081
1120
|
});
|
|
1082
1121
|
return;
|
|
1083
1122
|
}
|
|
1123
|
+
if (!stillHere()) return;
|
|
1084
1124
|
setAskingAgain(false);
|
|
1085
1125
|
if (!ok) {
|
|
1086
1126
|
setState(again ? before : { status: "idle" });
|
|
@@ -1094,15 +1134,19 @@ function ApplyDirectiveButton({
|
|
|
1094
1134
|
if (conversationId) shell.conversationId = conversationId;
|
|
1095
1135
|
if (again) shell.force = true;
|
|
1096
1136
|
const result = await confirm(shell);
|
|
1137
|
+
if (!stillHere()) return;
|
|
1097
1138
|
setState({
|
|
1098
1139
|
status: "applied",
|
|
1099
1140
|
applied: result.applied,
|
|
1100
1141
|
failed: result.failed,
|
|
1101
1142
|
message: result.message?.trim() ? result.message.trim() : null,
|
|
1102
|
-
records: result.records ?? []
|
|
1143
|
+
records: result.records ?? [],
|
|
1144
|
+
// "Run again" made one more; a first apply (or a replay of one) is one.
|
|
1145
|
+
copies: again ? Math.max(1, priorCopies) + 1 : Math.max(1, priorCopies)
|
|
1103
1146
|
});
|
|
1104
1147
|
onApplied?.();
|
|
1105
1148
|
} catch (error) {
|
|
1149
|
+
if (!stillHere()) return;
|
|
1106
1150
|
setState({
|
|
1107
1151
|
status: "error",
|
|
1108
1152
|
message: error instanceof Error && error.message ? error.message : "That couldn't be applied just now. Please try again."
|
|
@@ -1127,6 +1171,15 @@ function ApplyDirectiveButton({
|
|
|
1127
1171
|
bad && !state.message ? ` \xB7 ${state.failed} failed` : ""
|
|
1128
1172
|
] })
|
|
1129
1173
|
] }),
|
|
1174
|
+
state.copies > 1 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1175
|
+
"span",
|
|
1176
|
+
{
|
|
1177
|
+
className: "shrink-0 text-muted-foreground",
|
|
1178
|
+
"data-apply-copies": state.copies,
|
|
1179
|
+
title: records.length > 0 ? directive.directiveClass === "create" ? "Links to the latest copy." : "Links to the latest run." : void 0,
|
|
1180
|
+
children: directive.directiveClass === "create" ? `${state.copies} copies` : `Ran ${state.copies} times`
|
|
1181
|
+
}
|
|
1182
|
+
) : null,
|
|
1130
1183
|
records.map((record) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "inline-flex min-w-0 items-center", children: host.renderRecord?.({
|
|
1131
1184
|
...record,
|
|
1132
1185
|
fallback: recordFallbackName(label2, record.id),
|
|
@@ -1177,6 +1230,7 @@ function ApplyDirectiveButton({
|
|
|
1177
1230
|
}
|
|
1178
1231
|
);
|
|
1179
1232
|
}
|
|
1233
|
+
const destructive = directive.directiveClass === "delete";
|
|
1180
1234
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "inline-flex items-center gap-2", children: [
|
|
1181
1235
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1182
1236
|
"button",
|
|
@@ -1184,7 +1238,8 @@ function ApplyDirectiveButton({
|
|
|
1184
1238
|
type: "button",
|
|
1185
1239
|
onClick: () => void handleApply(),
|
|
1186
1240
|
disabled: state.status === "applying" || state.status === "asking" || items.length === 0,
|
|
1187
|
-
|
|
1241
|
+
"data-apply-tone": destructive ? "destructive" : "default",
|
|
1242
|
+
className: `inline-flex items-center gap-1 rounded-md border px-2 py-1 text-xs font-medium disabled:opacity-50 ${destructive ? "border-destructive/50 bg-background text-destructive hover:bg-destructive/10" : "border-border bg-background hover:bg-accent"}`,
|
|
1188
1243
|
children: [
|
|
1189
1244
|
state.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" }),
|
|
1190
1245
|
state.status === "applying" ? `Applying${itemCount ? ` ${itemCount} ${itemCount === 1 ? "item" : "items"}` : ""}\u2026${elapsed ? ` ${elapsed}s` : ""}` : label
|
|
@@ -1285,8 +1340,41 @@ function resetDirectiveRenderers() {
|
|
|
1285
1340
|
}
|
|
1286
1341
|
|
|
1287
1342
|
// directives/SideEffectDirectiveCard.tsx
|
|
1288
|
-
var
|
|
1343
|
+
var import_react6 = require("react");
|
|
1289
1344
|
var import_content_ir7 = require("@ai-matrx/content-ir");
|
|
1345
|
+
|
|
1346
|
+
// directives/record-values.ts
|
|
1347
|
+
var import_react5 = require("react");
|
|
1348
|
+
function useRecordValues(read, ref) {
|
|
1349
|
+
const key = ref && read ? `${ref.noun}:${ref.id}` : "";
|
|
1350
|
+
const [result, setResult] = (0, import_react5.useState)({
|
|
1351
|
+
key: "",
|
|
1352
|
+
values: null,
|
|
1353
|
+
status: "idle"
|
|
1354
|
+
});
|
|
1355
|
+
(0, import_react5.useEffect)(() => {
|
|
1356
|
+
if (!key || !read) return;
|
|
1357
|
+
const split = key.indexOf(":");
|
|
1358
|
+
const target = { noun: key.slice(0, split), id: key.slice(split + 1) };
|
|
1359
|
+
let live = true;
|
|
1360
|
+
setResult({ key, values: null, status: "loading" });
|
|
1361
|
+
read(target).then((values) => {
|
|
1362
|
+
if (!live) return;
|
|
1363
|
+
setResult({ key, values, status: values ? "ready" : "unavailable" });
|
|
1364
|
+
}).catch(() => {
|
|
1365
|
+
if (!live) return;
|
|
1366
|
+
setResult({ key, values: null, status: "unavailable" });
|
|
1367
|
+
});
|
|
1368
|
+
return () => {
|
|
1369
|
+
live = false;
|
|
1370
|
+
};
|
|
1371
|
+
}, [key, read]);
|
|
1372
|
+
if (!key) return { values: null, status: "idle" };
|
|
1373
|
+
if (result.key !== key) return { values: null, status: "loading" };
|
|
1374
|
+
return { values: result.values, status: result.status };
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
// directives/SideEffectDirectiveCard.tsx
|
|
1290
1378
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1291
1379
|
var ROWS_BEFORE_FOLD = 3;
|
|
1292
1380
|
function ItemRow({
|
|
@@ -1340,44 +1428,73 @@ function ItemRow({
|
|
|
1340
1428
|
host.renderCopy?.({ label: title, value: item, kind, size: "xs" })
|
|
1341
1429
|
] });
|
|
1342
1430
|
}
|
|
1343
|
-
function
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
recordId
|
|
1431
|
+
function DirectiveChangeList({
|
|
1432
|
+
changes,
|
|
1433
|
+
className
|
|
1347
1434
|
}) {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
host.renderCopy?.({ label: fallback, value: item, size: "xs" })
|
|
1356
|
-
] }),
|
|
1357
|
-
directive.directiveClass === "update" ? changes.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "px-1 text-[11px] text-muted-foreground", children: "Sets no fields \u2014 nothing would change." }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "mt-0.5 space-y-0.5 px-1", children: changes.map((change) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1435
|
+
if (changes.length === 0) {
|
|
1436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: `text-[11px] text-muted-foreground${className ? ` ${className}` : ""}`, children: "Sets no fields \u2014 nothing would change." });
|
|
1437
|
+
}
|
|
1438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: `space-y-0.5${className ? ` ${className}` : ""}`, "data-directive-changes": "", children: changes.map((change) => {
|
|
1439
|
+
const before = change.before && !change.same ? change.before : null;
|
|
1440
|
+
const was = before ? before.clears ? "empty" : before.value : null;
|
|
1441
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1358
1442
|
"li",
|
|
1359
1443
|
{
|
|
1360
1444
|
className: "flex min-w-0 items-baseline gap-1.5 text-[11px]",
|
|
1361
|
-
title: `${change.label} \u2192 ${change.full}`,
|
|
1445
|
+
title: before ? `${change.label}: ${before.clears ? "empty" : before.full} \u2192 ${change.full}` : `${change.label} \u2192 ${change.full}`,
|
|
1446
|
+
"data-change-key": change.key,
|
|
1362
1447
|
children: [
|
|
1363
1448
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "shrink-0 text-muted-foreground", children: change.label }),
|
|
1449
|
+
was !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1450
|
+
"span",
|
|
1451
|
+
{
|
|
1452
|
+
className: "min-w-0 max-w-[40%] shrink truncate text-muted-foreground line-through",
|
|
1453
|
+
"data-change-before": "",
|
|
1454
|
+
children: was
|
|
1455
|
+
}
|
|
1456
|
+
) : null,
|
|
1364
1457
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "aria-hidden": true, className: "shrink-0 text-muted-foreground", children: "\u2192" }),
|
|
1365
1458
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1366
1459
|
"span",
|
|
1367
1460
|
{
|
|
1368
1461
|
className: `min-w-0 truncate ${change.clears ? "italic text-muted-foreground" : "text-foreground"}`,
|
|
1462
|
+
"data-change-after": "",
|
|
1369
1463
|
children: change.value
|
|
1370
1464
|
}
|
|
1371
|
-
)
|
|
1465
|
+
),
|
|
1466
|
+
change.same ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "shrink-0 text-muted-foreground", children: "(no change)" }) : null
|
|
1372
1467
|
]
|
|
1373
1468
|
},
|
|
1374
1469
|
change.key
|
|
1375
|
-
)
|
|
1470
|
+
);
|
|
1471
|
+
}) });
|
|
1472
|
+
}
|
|
1473
|
+
function TargetRow({
|
|
1474
|
+
directive,
|
|
1475
|
+
item,
|
|
1476
|
+
recordId
|
|
1477
|
+
}) {
|
|
1478
|
+
const host = useDirectiveHost();
|
|
1479
|
+
const fallback = recordFallbackName((0, import_content_ir7.nounLabel)(directive.noun, host.nouns), recordId);
|
|
1480
|
+
const isUpdate = directive.directiveClass === "update";
|
|
1481
|
+
const current = useRecordValues(
|
|
1482
|
+
isUpdate ? host.readRecord : void 0,
|
|
1483
|
+
isUpdate ? { noun: directive.noun, id: recordId } : null
|
|
1484
|
+
);
|
|
1485
|
+
const changes = isUpdate ? itemChanges(item, current.values, { titleColumn: (0, import_content_ir7.nounTitleColumn)(directive.noun, host.nouns) }) : [];
|
|
1486
|
+
const name = host.renderRecord ? host.renderRecord({ noun: directive.noun, id: recordId, fallback, context: "row" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "truncate font-medium text-foreground", children: fallback });
|
|
1487
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "py-1 text-xs", "data-directive-target": recordId, children: [
|
|
1488
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
1489
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "flex min-w-0 flex-1 items-center gap-1 px-1", children: name }),
|
|
1490
|
+
host.renderCopy?.({ label: fallback, value: item, size: "xs" })
|
|
1491
|
+
] }),
|
|
1492
|
+
isUpdate ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DirectiveChangeList, { changes, className: "mt-0.5 px-1" }) : null
|
|
1376
1493
|
] });
|
|
1377
1494
|
}
|
|
1378
1495
|
function SideEffectDirectiveCard({ directive }) {
|
|
1379
1496
|
const host = useDirectiveHost();
|
|
1380
|
-
const [expanded, setExpanded] = (0,
|
|
1497
|
+
const [expanded, setExpanded] = (0, import_react6.useState)(false);
|
|
1381
1498
|
const items = directive.items;
|
|
1382
1499
|
const total = items.length;
|
|
1383
1500
|
const display = (0, import_content_ir7.directiveDisplay)(directive.directiveClass, directive.noun, host.nouns);
|
|
@@ -1491,10 +1608,10 @@ function KindInstanceRenderInner({
|
|
|
1491
1608
|
className
|
|
1492
1609
|
}) {
|
|
1493
1610
|
const host = useContentIrHost();
|
|
1494
|
-
const [routingStatus, setRoutingStatus] = (0,
|
|
1611
|
+
const [routingStatus, setRoutingStatus] = (0, import_react7.useState)(
|
|
1495
1612
|
() => kindIsRoutable(kind, host) ? "routable" : "checking"
|
|
1496
1613
|
);
|
|
1497
|
-
(0,
|
|
1614
|
+
(0, import_react7.useEffect)(() => {
|
|
1498
1615
|
let cancelled = false;
|
|
1499
1616
|
let warmed = false;
|
|
1500
1617
|
const syncRoutingStatus = () => {
|
|
@@ -1542,9 +1659,9 @@ function KindInstanceRenderInner({
|
|
|
1542
1659
|
}
|
|
1543
1660
|
|
|
1544
1661
|
// react/ProvisionalKindBoundary.tsx
|
|
1545
|
-
var
|
|
1662
|
+
var import_react8 = __toESM(require("react"), 1);
|
|
1546
1663
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1547
|
-
var ProvisionalKindBoundaryInner = class extends
|
|
1664
|
+
var ProvisionalKindBoundaryInner = class extends import_react8.default.Component {
|
|
1548
1665
|
state = { failed: false };
|
|
1549
1666
|
static getDerivedStateFromError() {
|
|
1550
1667
|
return { failed: true };
|
|
@@ -1580,7 +1697,7 @@ function ProvisionalKindFrame({ children }) {
|
|
|
1580
1697
|
}
|
|
1581
1698
|
|
|
1582
1699
|
// react/GenericStructuredView.tsx
|
|
1583
|
-
var
|
|
1700
|
+
var import_react9 = require("react");
|
|
1584
1701
|
var import_content_ir10 = require("@ai-matrx/content-ir");
|
|
1585
1702
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1586
1703
|
function readStructuredValue(content, metadata) {
|