@ai-matrx/content-ir-react 0.7.1 → 0.8.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 +84 -0
- package/dist/component-resolution.types-BS1ySIg-.d.cts +104 -0
- package/dist/component-resolution.types-BS1ySIg-.d.ts +104 -0
- package/dist/component-resolution.types-fvR92hW7.d.cts +142 -0
- package/dist/component-resolution.types-fvR92hW7.d.ts +142 -0
- package/dist/db-component.cjs +226 -0
- package/dist/db-component.cjs.map +1 -0
- package/dist/db-component.d.cts +267 -0
- package/dist/db-component.d.ts +267 -0
- package/dist/db-component.js +194 -0
- package/dist/db-component.js.map +1 -0
- package/dist/host-types-CZ_Bkp4R.d.ts +131 -0
- package/dist/host-types-DvGv8s9L.d.cts +131 -0
- package/dist/host.cjs +74 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.cts +24 -0
- package/dist/host.d.ts +24 -0
- package/dist/host.js +52 -0
- package/dist/host.js.map +1 -0
- package/dist/index.cjs +356 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +280 -672
- package/dist/index.d.ts +280 -672
- package/dist/index.js +316 -31
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +361 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +195 -0
- package/dist/react.d.ts +195 -0
- package/dist/react.js +344 -0
- package/dist/react.js.map +1 -0
- package/dist/resolver.cjs +327 -0
- package/dist/resolver.cjs.map +1 -0
- package/dist/resolver.d.cts +133 -0
- package/dist/resolver.d.ts +133 -0
- package/dist/resolver.js +304 -0
- package/dist/resolver.js.map +1 -0
- package/dist/route-C1XNcubB.d.ts +433 -0
- package/dist/route-C55jsF4B.d.cts +433 -0
- package/dist/route.cjs +259 -0
- package/dist/route.cjs.map +1 -0
- package/dist/route.d.cts +4 -0
- package/dist/route.d.ts +4 -0
- package/dist/route.js +247 -0
- package/dist/route.js.map +1 -0
- package/package.json +76 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import React, { createContext, useContext, useMemo, useCallback, useSyncExternalStore, useState, useEffect } from 'react';
|
|
2
|
-
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { readEnvelope, readObjectKind, envelopeFromCompleteValue, IR_VERSION, readPartialKindEvent, isProvisionalKind, IR_PARTIAL_KEY, IR_ENVELOPE_KEY, reconstructRegionValue, readNodeOutcomeValue, readRunResultValue } from '@ai-matrx/content-ir';
|
|
4
|
-
|
|
5
1
|
// host/error-report.ts
|
|
6
2
|
var consoleErrorReporter = (report) => {
|
|
7
3
|
console.error(`[content-ir] ${report.message}`, report.raw ?? "");
|
|
@@ -16,6 +12,10 @@ function routeEnvOf(host) {
|
|
|
16
12
|
platform: host.platform
|
|
17
13
|
};
|
|
18
14
|
}
|
|
15
|
+
|
|
16
|
+
// host/ContentIrProvider.tsx
|
|
17
|
+
import { createContext, useContext, useMemo } from "react";
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
19
|
var ContentIrHostContext = createContext(null);
|
|
20
20
|
function ContentIrRenderProvider({
|
|
21
21
|
host,
|
|
@@ -335,13 +335,23 @@ var ComponentResolver = class {
|
|
|
335
335
|
return this.warmPromise;
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
|
+
|
|
339
|
+
// route/kind-route.ts
|
|
340
|
+
import {
|
|
341
|
+
envelopeFromCompleteValue,
|
|
342
|
+
readEnvelope,
|
|
343
|
+
readObjectKind
|
|
344
|
+
} from "@ai-matrx/content-ir";
|
|
338
345
|
var IR_ROUTE_KEY = "__ir_route";
|
|
339
346
|
var GENERIC_STRUCTURED_COMPONENT_KEY = "generic_structured";
|
|
340
347
|
var DB_KIND_COMPONENT_KEY = "db_kind_component";
|
|
341
348
|
function isDbSourceResolution(resolution) {
|
|
342
349
|
return resolution !== null && resolution.resolvedBy === "db" && resolution.source === "db" && resolution.isActive;
|
|
343
350
|
}
|
|
344
|
-
var
|
|
351
|
+
var SOURCELESS_DB_ROW_SLOT = /* @__PURE__ */ Symbol.for(
|
|
352
|
+
"ai-matrx.content-ir-react.sourceless-db-row-reports"
|
|
353
|
+
);
|
|
354
|
+
var reportedSourcelessDbRows = globalThis[SOURCELESS_DB_ROW_SLOT] ??= /* @__PURE__ */ new Set();
|
|
345
355
|
function reportDbRowWithoutSource(kind, env) {
|
|
346
356
|
const message = `[content-ir] kind_component for "${kind}" declares source='db' + is_active but has NO component_source \u2014 data defect; falling through to bundled rendering.`;
|
|
347
357
|
if (!reportedSourcelessDbRows.has(kind)) {
|
|
@@ -462,6 +472,16 @@ function kindServerDataFromStoredValue(value, env) {
|
|
|
462
472
|
if (!def?.toLegacyServerData) return null;
|
|
463
473
|
return def.toLegacyServerData(envelopeFromCompleteValue(value, kind)) ?? null;
|
|
464
474
|
}
|
|
475
|
+
|
|
476
|
+
// route/partial-kind-route.ts
|
|
477
|
+
import {
|
|
478
|
+
IR_ENVELOPE_KEY,
|
|
479
|
+
IR_PARTIAL_KEY,
|
|
480
|
+
IR_VERSION,
|
|
481
|
+
isProvisionalKind,
|
|
482
|
+
readEnvelope as readEnvelope2,
|
|
483
|
+
readPartialKindEvent
|
|
484
|
+
} from "@ai-matrx/content-ir";
|
|
465
485
|
var IR_PROVISIONAL_KEY = "__ir_provisional";
|
|
466
486
|
function isProvisionalBlock(metadata) {
|
|
467
487
|
return metadata?.[IR_PROVISIONAL_KEY] === true;
|
|
@@ -477,7 +497,10 @@ function envelopeFromPartialKind(event) {
|
|
|
477
497
|
root: event.root
|
|
478
498
|
};
|
|
479
499
|
}
|
|
480
|
-
var
|
|
500
|
+
var PARTIAL_UNSAFE_SLOT = /* @__PURE__ */ Symbol.for(
|
|
501
|
+
"ai-matrx.content-ir-react.partial-unsafe-kinds"
|
|
502
|
+
);
|
|
503
|
+
var partialUnsafeKinds = globalThis[PARTIAL_UNSAFE_SLOT] ??= /* @__PURE__ */ new Set();
|
|
481
504
|
function markKindPartialUnsafe(kind) {
|
|
482
505
|
partialUnsafeKinds.add(kind);
|
|
483
506
|
}
|
|
@@ -494,7 +517,7 @@ function resolveAnnouncedKindLoading(block, options) {
|
|
|
494
517
|
if (!isProvisionalKind(event)) return null;
|
|
495
518
|
const kind = event.root.kind;
|
|
496
519
|
if (!kind) return null;
|
|
497
|
-
const verified =
|
|
520
|
+
const verified = readEnvelope2(block.metadata);
|
|
498
521
|
if (verified && verified.root.status === "complete") return null;
|
|
499
522
|
return { kind, envelope: envelopeFromPartialKind(event) };
|
|
500
523
|
}
|
|
@@ -504,9 +527,10 @@ function resolveProvisionalKindRender(block, env, options) {
|
|
|
504
527
|
if (!isProvisionalKind(event)) return null;
|
|
505
528
|
const kind = event.root.kind;
|
|
506
529
|
if (!isPartialReadyKind(kind, env)) return null;
|
|
507
|
-
const verified =
|
|
530
|
+
const verified = readEnvelope2(block.metadata);
|
|
508
531
|
if (verified && verified.root.status === "complete") return null;
|
|
509
532
|
const { [IR_PARTIAL_KEY]: _partial, ...rest } = block.metadata ?? {};
|
|
533
|
+
void _partial;
|
|
510
534
|
const envelope = envelopeFromPartialKind(event);
|
|
511
535
|
const provisionalBlock = {
|
|
512
536
|
...block,
|
|
@@ -526,6 +550,23 @@ function resolveProvisionalKindRender(block, env, options) {
|
|
|
526
550
|
}
|
|
527
551
|
return { block: routed, kind, seq: event.seq, envelope };
|
|
528
552
|
}
|
|
553
|
+
|
|
554
|
+
// route/route-binding.ts
|
|
555
|
+
function createKindRouteBinding(env, options) {
|
|
556
|
+
const ownedTypes = options?.ownedTypes;
|
|
557
|
+
return {
|
|
558
|
+
applyIrKindRoute: (block) => applyIrKindRoute(block, env, ownedTypes ? { ownedTypes } : void 0),
|
|
559
|
+
kindServerDataFromStoredValue: (value) => kindServerDataFromStoredValue(value, env),
|
|
560
|
+
isPartialReadyKind: (kind) => isPartialReadyKind(kind, env),
|
|
561
|
+
resolveProvisionalKindRender: (block, streamOptions) => resolveProvisionalKindRender(block, env, {
|
|
562
|
+
...streamOptions,
|
|
563
|
+
...ownedTypes ? { ownedTypes } : null
|
|
564
|
+
})
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// react/use-kind-version.ts
|
|
569
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
529
570
|
var noopSubscribe = () => () => {
|
|
530
571
|
};
|
|
531
572
|
var zero = () => 0;
|
|
@@ -562,6 +603,11 @@ function useContentIrKindVersion(kind, sources) {
|
|
|
562
603
|
);
|
|
563
604
|
return useSyncExternalStore(subscribe, getSnapshot, zero);
|
|
564
605
|
}
|
|
606
|
+
|
|
607
|
+
// react/KindInstanceRender.tsx
|
|
608
|
+
import { useEffect, useState } from "react";
|
|
609
|
+
import { envelopeFromCompleteValue as envelopeFromCompleteValue2, IR_ENVELOPE_KEY as IR_ENVELOPE_KEY2 } from "@ai-matrx/content-ir";
|
|
610
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
565
611
|
function isRecordValue(value) {
|
|
566
612
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
567
613
|
}
|
|
@@ -615,20 +661,24 @@ function KindInstanceRender({
|
|
|
615
661
|
content: JSON.stringify(value, null, 2),
|
|
616
662
|
language: "json",
|
|
617
663
|
metadata: {
|
|
618
|
-
[
|
|
664
|
+
[IR_ENVELOPE_KEY2]: envelopeFromCompleteValue2(value, kind)
|
|
619
665
|
}
|
|
620
666
|
} : null;
|
|
621
667
|
const frameClass = variant === "bare" ? void 0 : "rounded-md border border-border bg-card p-3";
|
|
622
668
|
if (routingStatus === "unroutable" && unroutableFallback !== void 0) {
|
|
623
|
-
return /* @__PURE__ */
|
|
669
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: unroutableFallback });
|
|
624
670
|
}
|
|
625
671
|
const onTheFloor = block === null || routingStatus === "unroutable";
|
|
626
672
|
const notice = "This shape has no custom component yet, so it renders through the universal viewer \u2014 exactly what production shows today.";
|
|
627
673
|
return /* @__PURE__ */ jsxs("div", { className: className ? `space-y-3 ${className}` : "space-y-3", children: [
|
|
628
|
-
showRoutingNote && routingStatus === "unroutable" ? host.renderNotice?.(notice) ?? /* @__PURE__ */
|
|
629
|
-
/* @__PURE__ */
|
|
674
|
+
showRoutingNote && routingStatus === "unroutable" ? host.renderNotice?.(notice) ?? /* @__PURE__ */ jsx2("div", { className: "rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-xs text-amber-800 dark:text-amber-200", children: notice }) : null,
|
|
675
|
+
/* @__PURE__ */ jsx2("div", { className: frameClass, children: onTheFloor ? host.renderValue({ value, kind }) : host.renderBlock(block) })
|
|
630
676
|
] });
|
|
631
677
|
}
|
|
678
|
+
|
|
679
|
+
// react/ProvisionalKindBoundary.tsx
|
|
680
|
+
import React from "react";
|
|
681
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
632
682
|
var ProvisionalKindBoundaryInner = class extends React.Component {
|
|
633
683
|
state = { failed: false };
|
|
634
684
|
static getDerivedStateFromError() {
|
|
@@ -653,18 +703,27 @@ var ProvisionalKindBoundaryInner = class extends React.Component {
|
|
|
653
703
|
};
|
|
654
704
|
function ProvisionalKindBoundary(props) {
|
|
655
705
|
const host = useContentIrHost();
|
|
656
|
-
return /* @__PURE__ */
|
|
706
|
+
return /* @__PURE__ */ jsx3(ProvisionalKindBoundaryInner, { ...props, reportError: host.reportError });
|
|
657
707
|
}
|
|
658
708
|
function ProvisionalKindFrame({ children }) {
|
|
659
709
|
const host = useContentIrHost();
|
|
660
710
|
const label = "Still arriving";
|
|
661
|
-
return /* @__PURE__ */
|
|
711
|
+
return /* @__PURE__ */ jsxs2("div", { className: "relative", "aria-busy": "true", children: [
|
|
662
712
|
children,
|
|
663
|
-
/* @__PURE__ */
|
|
713
|
+
/* @__PURE__ */ jsx3("span", { className: "pointer-events-none absolute -top-2 right-4 z-10 select-none rounded-full bg-background px-1.5 leading-4", children: host.renderShimmer?.(label) ?? /* @__PURE__ */ jsx3("span", { className: "text-[10px] text-muted-foreground", children: label }) })
|
|
664
714
|
] });
|
|
665
715
|
}
|
|
716
|
+
|
|
717
|
+
// react/GenericStructuredView.tsx
|
|
718
|
+
import "react";
|
|
719
|
+
import {
|
|
720
|
+
readEnvelope as readEnvelope3,
|
|
721
|
+
readObjectKind as readObjectKind2,
|
|
722
|
+
reconstructRegionValue
|
|
723
|
+
} from "@ai-matrx/content-ir";
|
|
724
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
666
725
|
function readStructuredValue(content, metadata) {
|
|
667
|
-
const envelope =
|
|
726
|
+
const envelope = readEnvelope3(metadata);
|
|
668
727
|
if (envelope) {
|
|
669
728
|
return { value: reconstructRegionValue(envelope), recovered: true };
|
|
670
729
|
}
|
|
@@ -681,21 +740,25 @@ function GenericStructuredView({
|
|
|
681
740
|
className
|
|
682
741
|
}) {
|
|
683
742
|
const host = useContentIrHost();
|
|
684
|
-
const envelope =
|
|
743
|
+
const envelope = readEnvelope3(metadata);
|
|
685
744
|
const status = envelope?.root.status ?? "complete";
|
|
686
745
|
const { value, recovered } = readStructuredValue(content, metadata);
|
|
687
|
-
const kind = envelope?.root.kind ?? (typeof value === "object" && value !== null && !Array.isArray(value) ?
|
|
746
|
+
const kind = envelope?.root.kind ?? (typeof value === "object" && value !== null && !Array.isArray(value) ? readObjectKind2(value) : null) ?? "";
|
|
688
747
|
const marker = readIrRouteMarker(metadata);
|
|
689
748
|
const note = marker?.reason === "inactive" ? "a custom view is registered but held inactive" : marker?.reason === "broken-instance" ? "this instance did not match the shape's schema" : marker?.reason === "unregistered" ? "this shape isn't registered on this platform" : "no custom view yet";
|
|
690
|
-
return /* @__PURE__ */
|
|
691
|
-
status === "streaming" ? streamingIndicator ?? /* @__PURE__ */
|
|
749
|
+
return /* @__PURE__ */ jsxs3("div", { className: className ? `my-2 min-w-0 ${className}` : "my-2 min-w-0", children: [
|
|
750
|
+
status === "streaming" ? streamingIndicator ?? /* @__PURE__ */ jsx4("div", { className: "mb-2 text-xs text-muted-foreground", children: "Still arriving\u2026" }) : null,
|
|
692
751
|
recovered ? host.renderValue({ value, ...kind ? { kind } : {}, note }) : (
|
|
693
752
|
// Zero-data-loss backstop: the region never parsed, so show the source
|
|
694
753
|
// verbatim rather than swallowing it.
|
|
695
|
-
/* @__PURE__ */
|
|
754
|
+
/* @__PURE__ */ jsx4("pre", { className: "max-h-96 overflow-auto font-mono text-xs leading-relaxed text-muted-foreground", children: content })
|
|
696
755
|
)
|
|
697
756
|
] });
|
|
698
757
|
}
|
|
758
|
+
|
|
759
|
+
// react/RuntimeWrapperViews.tsx
|
|
760
|
+
import { readNodeOutcomeValue, readObjectKind as readObjectKind3, readRunResultValue } from "@ai-matrx/content-ir";
|
|
761
|
+
import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
|
|
699
762
|
function isRecord2(value) {
|
|
700
763
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
701
764
|
}
|
|
@@ -711,16 +774,16 @@ function DelegatedOutput({
|
|
|
711
774
|
}) {
|
|
712
775
|
const host = useContentIrHost();
|
|
713
776
|
if (output === null || output === void 0) {
|
|
714
|
-
return /* @__PURE__ */
|
|
777
|
+
return /* @__PURE__ */ jsx5("p", { className: "text-xs text-muted-foreground", children: emptyLabel });
|
|
715
778
|
}
|
|
716
779
|
if (!isRecord2(output)) {
|
|
717
|
-
return /* @__PURE__ */
|
|
780
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children: host.renderValue({ value: output }) });
|
|
718
781
|
}
|
|
719
|
-
const kind =
|
|
782
|
+
const kind = readObjectKind3(output) ?? declaredKind;
|
|
720
783
|
if (!kind) {
|
|
721
|
-
return /* @__PURE__ */
|
|
784
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children: fallback?.(output) ?? host.renderValue({ value: output }) });
|
|
722
785
|
}
|
|
723
|
-
return /* @__PURE__ */
|
|
786
|
+
return /* @__PURE__ */ jsx5(
|
|
724
787
|
KindInstanceRender,
|
|
725
788
|
{
|
|
726
789
|
kind,
|
|
@@ -737,7 +800,7 @@ function NodeOutcomeView({ serverData, fallback }) {
|
|
|
737
800
|
readNodeOutcomeValue
|
|
738
801
|
);
|
|
739
802
|
if (!wrapper) return null;
|
|
740
|
-
return /* @__PURE__ */
|
|
803
|
+
return /* @__PURE__ */ jsx5(
|
|
741
804
|
DelegatedOutput,
|
|
742
805
|
{
|
|
743
806
|
output: wrapper.output,
|
|
@@ -752,14 +815,14 @@ function RunResultView({ serverData, fallback }) {
|
|
|
752
815
|
readRunResultValue
|
|
753
816
|
);
|
|
754
817
|
if (!wrapper) return null;
|
|
755
|
-
return /* @__PURE__ */
|
|
818
|
+
return /* @__PURE__ */ jsx5("div", { className: "space-y-2", children: wrapper.outputs.length > 0 ? wrapper.outputs.map((outcome) => /* @__PURE__ */ jsx5(
|
|
756
819
|
NodeOutcomeView,
|
|
757
820
|
{
|
|
758
821
|
serverData: { wrapper: outcome },
|
|
759
822
|
...fallback === void 0 ? {} : { fallback }
|
|
760
823
|
},
|
|
761
824
|
`${outcome.node_id}:${outcome.attempt}`
|
|
762
|
-
)) : /* @__PURE__ */
|
|
825
|
+
)) : /* @__PURE__ */ jsx5(
|
|
763
826
|
DelegatedOutput,
|
|
764
827
|
{
|
|
765
828
|
output: wrapper.output,
|
|
@@ -769,6 +832,228 @@ function RunResultView({ serverData, fallback }) {
|
|
|
769
832
|
) });
|
|
770
833
|
}
|
|
771
834
|
|
|
772
|
-
|
|
773
|
-
|
|
835
|
+
// db-component/db-kind-component-cache.ts
|
|
836
|
+
function isDbKindComponentBodyPending(resolution) {
|
|
837
|
+
return resolution.hasComponentSource && resolution.componentSource === null;
|
|
838
|
+
}
|
|
839
|
+
function isPlainObject(value) {
|
|
840
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
841
|
+
}
|
|
842
|
+
function createDbKindComponentCache(ports) {
|
|
843
|
+
const cache = /* @__PURE__ */ new Map();
|
|
844
|
+
const screamedKeys = /* @__PURE__ */ new Set();
|
|
845
|
+
const defaultPlatform = ports.platform ?? "web";
|
|
846
|
+
function cacheKey(kind, platform, role, updatedAt) {
|
|
847
|
+
return `${kind}${platform}${role}${updatedAt ?? ""}`;
|
|
848
|
+
}
|
|
849
|
+
function screamCompileFailure(key, kind, error, resolution, platform, role) {
|
|
850
|
+
const message = `[content-ir] DB kind component for "${kind}" failed to compile \u2014 rendering the generic structured viewer instead: ${error}`;
|
|
851
|
+
if (!screamedKeys.has(key)) {
|
|
852
|
+
screamedKeys.add(key);
|
|
853
|
+
console.error(message);
|
|
854
|
+
}
|
|
855
|
+
ports.reportError({ source: "content-ir", message, raw: { kind, error } });
|
|
856
|
+
ports.reportIncident?.({
|
|
857
|
+
kind,
|
|
858
|
+
errorType: "compile_error",
|
|
859
|
+
message,
|
|
860
|
+
platform,
|
|
861
|
+
role,
|
|
862
|
+
componentKey: resolution.componentKey,
|
|
863
|
+
componentUpdatedAt: resolution.updatedAt
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
function config(value, kind) {
|
|
867
|
+
if (isPlainObject(value)) return value;
|
|
868
|
+
if (value === null || value === void 0) return {};
|
|
869
|
+
const message = `[content-ir] kind_component.config for "${kind}" is not a JSON object (${typeof value}) \u2014 rendering with an empty config.`;
|
|
870
|
+
console.error(message);
|
|
871
|
+
ports.reportError({ source: "content-ir", message, raw: { kind } });
|
|
872
|
+
return {};
|
|
873
|
+
}
|
|
874
|
+
function resolveAllowedImports(rowConfig) {
|
|
875
|
+
const declared = rowConfig.allowed_imports;
|
|
876
|
+
if (Array.isArray(declared) && declared.every((entry) => typeof entry === "string")) {
|
|
877
|
+
return declared;
|
|
878
|
+
}
|
|
879
|
+
return ports.defaultAllowedImports();
|
|
880
|
+
}
|
|
881
|
+
function getOrCompile(kind, resolution, platform = defaultPlatform, role = "output") {
|
|
882
|
+
const key = cacheKey(kind, platform, role, resolution.updatedAt);
|
|
883
|
+
const cached = cache.get(key);
|
|
884
|
+
if (cached) return cached;
|
|
885
|
+
const source = resolution.componentSource;
|
|
886
|
+
if (!source || !source.trim()) {
|
|
887
|
+
const result2 = {
|
|
888
|
+
ok: false,
|
|
889
|
+
error: "db-source resolution has no component_source"
|
|
890
|
+
};
|
|
891
|
+
screamCompileFailure(key, kind, result2.error, resolution, platform, role);
|
|
892
|
+
cache.set(key, result2);
|
|
893
|
+
return result2;
|
|
894
|
+
}
|
|
895
|
+
const allowedImports = resolveAllowedImports(
|
|
896
|
+
config(resolution.config, kind)
|
|
897
|
+
);
|
|
898
|
+
const { Component: Component2, error } = ports.compile({ code: source, allowedImports });
|
|
899
|
+
if (!Component2 || error) {
|
|
900
|
+
const result2 = {
|
|
901
|
+
ok: false,
|
|
902
|
+
error: error ?? "compile produced no component"
|
|
903
|
+
};
|
|
904
|
+
screamCompileFailure(key, kind, result2.error, resolution, platform, role);
|
|
905
|
+
cache.set(key, result2);
|
|
906
|
+
return result2;
|
|
907
|
+
}
|
|
908
|
+
let transform = null;
|
|
909
|
+
if (resolution.propsTransform && resolution.propsTransform.trim()) {
|
|
910
|
+
const { Component: transformFn, error: transformError } = ports.compile({
|
|
911
|
+
code: resolution.propsTransform,
|
|
912
|
+
allowedImports: []
|
|
913
|
+
});
|
|
914
|
+
if (typeof transformFn === "function" && !transformError) {
|
|
915
|
+
transform = transformFn;
|
|
916
|
+
} else {
|
|
917
|
+
const message = `[content-ir] props_transform for kind "${kind}" failed to compile \u2014 value passes through untransformed: ${transformError ?? "no function produced"}`;
|
|
918
|
+
console.error(message);
|
|
919
|
+
ports.reportError({
|
|
920
|
+
source: "content-ir",
|
|
921
|
+
message,
|
|
922
|
+
raw: { kind, error: transformError }
|
|
923
|
+
});
|
|
924
|
+
ports.reportIncident?.({
|
|
925
|
+
kind,
|
|
926
|
+
errorType: "transform_error",
|
|
927
|
+
message,
|
|
928
|
+
platform,
|
|
929
|
+
role,
|
|
930
|
+
componentKey: resolution.componentKey,
|
|
931
|
+
componentUpdatedAt: resolution.updatedAt
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
const result = {
|
|
936
|
+
ok: true,
|
|
937
|
+
compiled: {
|
|
938
|
+
// The injected compiler types components as
|
|
939
|
+
// ComponentType<Record<string, unknown>>; the callsite always passes
|
|
940
|
+
// DbKindComponentRenderProps — the single deliberate narrowing where
|
|
941
|
+
// the generic compiler meets the kind contract.
|
|
942
|
+
Component: Component2,
|
|
943
|
+
transform
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
cache.set(key, result);
|
|
947
|
+
return result;
|
|
948
|
+
}
|
|
949
|
+
function applyPropsTransform(kind, compiled, value) {
|
|
950
|
+
if (!compiled.transform) return value;
|
|
951
|
+
try {
|
|
952
|
+
return compiled.transform(value);
|
|
953
|
+
} catch (error) {
|
|
954
|
+
const message = `[content-ir] props_transform for kind "${kind}" threw \u2014 using the untransformed value: ${error instanceof Error ? error.message : String(error)}`;
|
|
955
|
+
console.error(message);
|
|
956
|
+
ports.reportError({ source: "content-ir", message, raw: { kind } });
|
|
957
|
+
ports.reportIncident?.({
|
|
958
|
+
kind,
|
|
959
|
+
errorType: "transform_error",
|
|
960
|
+
message,
|
|
961
|
+
stack: error instanceof Error ? error.stack ?? null : null,
|
|
962
|
+
data: value
|
|
963
|
+
});
|
|
964
|
+
return value;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function invalidate(kind, platform = defaultPlatform, role = "output") {
|
|
968
|
+
const prefix = `${kind}${platform}${role}`;
|
|
969
|
+
for (const key of [...cache.keys()]) {
|
|
970
|
+
if (key.startsWith(prefix)) cache.delete(key);
|
|
971
|
+
}
|
|
972
|
+
for (const key of [...screamedKeys]) {
|
|
973
|
+
if (key.startsWith(prefix)) screamedKeys.delete(key);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
function invalidateAll() {
|
|
977
|
+
cache.clear();
|
|
978
|
+
screamedKeys.clear();
|
|
979
|
+
}
|
|
980
|
+
const api = {
|
|
981
|
+
getOrCompile,
|
|
982
|
+
applyPropsTransform,
|
|
983
|
+
config,
|
|
984
|
+
invalidate,
|
|
985
|
+
invalidateAll
|
|
986
|
+
};
|
|
987
|
+
ports.registerInvalidation?.(() => invalidateAll());
|
|
988
|
+
return api;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// db-component/DbKindComponentErrorBoundary.tsx
|
|
992
|
+
import * as React2 from "react";
|
|
993
|
+
var DbKindComponentErrorBoundary = class extends React2.Component {
|
|
994
|
+
constructor(props) {
|
|
995
|
+
super(props);
|
|
996
|
+
this.state = { hasError: false, signalAtLastRender: props.resetSignal };
|
|
997
|
+
}
|
|
998
|
+
static getDerivedStateFromError() {
|
|
999
|
+
return { hasError: true };
|
|
1000
|
+
}
|
|
1001
|
+
static getDerivedStateFromProps(props, state) {
|
|
1002
|
+
if (props.resetSignal === state.signalAtLastRender) return null;
|
|
1003
|
+
return { hasError: false, signalAtLastRender: props.resetSignal };
|
|
1004
|
+
}
|
|
1005
|
+
componentDidCatch(error, errorInfo) {
|
|
1006
|
+
const info = { componentStack: errorInfo.componentStack ?? null };
|
|
1007
|
+
if (this.props.onCaught) {
|
|
1008
|
+
this.props.onCaught(error, info);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
console.error(
|
|
1012
|
+
`[content-ir] DB kind component for "${this.props.kind}" threw during render \u2014 showing the fallback:`,
|
|
1013
|
+
error
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
render() {
|
|
1017
|
+
if (this.state.hasError) return this.props.fallback;
|
|
1018
|
+
return this.props.children;
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
export {
|
|
1022
|
+
ComponentResolver,
|
|
1023
|
+
ContentIrRenderProvider,
|
|
1024
|
+
DB_KIND_COMPONENT_KEY,
|
|
1025
|
+
DbKindComponentErrorBoundary,
|
|
1026
|
+
DelegatedOutput,
|
|
1027
|
+
GENERIC_STRUCTURED_COMPONENT_KEY,
|
|
1028
|
+
GenericStructuredView,
|
|
1029
|
+
IR_PROVISIONAL_KEY,
|
|
1030
|
+
IR_ROUTE_KEY,
|
|
1031
|
+
KindInstanceRender,
|
|
1032
|
+
NodeOutcomeView,
|
|
1033
|
+
ProvisionalKindBoundary,
|
|
1034
|
+
ProvisionalKindFrame,
|
|
1035
|
+
RunResultView,
|
|
1036
|
+
applyIrKindRoute,
|
|
1037
|
+
consoleErrorReporter,
|
|
1038
|
+
createDbKindComponentCache,
|
|
1039
|
+
createKindRouteBinding,
|
|
1040
|
+
envelopeFromPartialKind,
|
|
1041
|
+
isDbKindComponentBodyPending,
|
|
1042
|
+
isPartialReadyKind,
|
|
1043
|
+
isProvisionalBlock,
|
|
1044
|
+
isRecordValue,
|
|
1045
|
+
kindIsRoutable,
|
|
1046
|
+
kindServerDataFromStoredValue,
|
|
1047
|
+
markKindPartialUnsafe,
|
|
1048
|
+
readIrRouteMarker,
|
|
1049
|
+
resetPartialUnsafeKinds,
|
|
1050
|
+
resetSourcelessDbRowReports,
|
|
1051
|
+
resolveAnnouncedKindLoading,
|
|
1052
|
+
resolveProvisionalKindRender,
|
|
1053
|
+
routeEnvOf,
|
|
1054
|
+
useContentIrHost,
|
|
1055
|
+
useContentIrHostOrNull,
|
|
1056
|
+
useContentIrKindVersion,
|
|
1057
|
+
useKindRouteEnv
|
|
1058
|
+
};
|
|
774
1059
|
//# sourceMappingURL=index.js.map
|