@immediately-run/sdk 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/components/Include.cjs +24 -4
  2. package/dist/components/Include.cjs.map +1 -1
  3. package/dist/components/Include.d.cts +27 -10
  4. package/dist/components/Include.d.ts +27 -10
  5. package/dist/components/Include.js +23 -4
  6. package/dist/components/Include.js.map +1 -1
  7. package/dist/components/SafeInclude.cjs +103 -0
  8. package/dist/components/SafeInclude.cjs.map +1 -0
  9. package/dist/components/SafeInclude.d.cts +29 -0
  10. package/dist/components/SafeInclude.d.ts +29 -0
  11. package/dist/components/SafeInclude.js +77 -0
  12. package/dist/components/SafeInclude.js.map +1 -0
  13. package/dist/components/includeContexts.cjs +33 -0
  14. package/dist/components/includeContexts.cjs.map +1 -0
  15. package/dist/components/includeContexts.d.cts +22 -0
  16. package/dist/components/includeContexts.d.ts +22 -0
  17. package/dist/components/includeContexts.js +9 -0
  18. package/dist/components/includeContexts.js.map +1 -0
  19. package/dist/index.cjs +11 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +4 -1
  22. package/dist/index.d.ts +4 -1
  23. package/dist/index.js +6 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/sourceCache.cjs +48 -0
  26. package/dist/sourceCache.cjs.map +1 -0
  27. package/dist/sourceCache.d.cts +12 -0
  28. package/dist/sourceCache.d.ts +12 -0
  29. package/dist/sourceCache.js +25 -0
  30. package/dist/sourceCache.js.map +1 -0
  31. package/dist/version.cjs +1 -1
  32. package/dist/version.cjs.map +1 -1
  33. package/dist/version.d.cts +1 -1
  34. package/dist/version.d.ts +1 -1
  35. package/dist/version.js +1 -1
  36. package/dist/version.js.map +1 -1
  37. package/package.json +1 -1
@@ -19,8 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var Include_exports = {};
20
20
  __export(Include_exports, {
21
21
  Include: () => Include,
22
+ IncludeModeContext: () => import_includeContexts2.IncludeModeContext,
22
23
  RenderExportedComponent: () => RenderExportedComponent,
23
- RenderExportedComponentContext: () => RenderExportedComponentContext
24
+ RenderExportedComponentContext: () => import_includeContexts2.RenderExportedComponentContext
24
25
  });
25
26
  module.exports = __toCommonJS(Include_exports);
26
27
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -28,29 +29,48 @@ var import_react = require("react");
28
29
  var import_react_error_boundary = require("react-error-boundary");
29
30
  var import_moduleCache = require("../moduleCache");
30
31
  var import_defaults = require("./defaults");
31
- const RenderExportedComponentContext = (0, import_react.createContext)(null);
32
+ var import_includeContexts = require("./includeContexts");
33
+ var import_SafeInclude = require("./SafeInclude");
34
+ var import_includeContexts2 = require("./includeContexts");
32
35
  const RenderExportedComponent = ({
33
36
  evaluationContextPromise,
34
37
  exportedSymbol = "default"
35
38
  }) => {
36
39
  const evaluationContext = (0, import_react.use)(evaluationContextPromise);
37
40
  const Component = exportedSymbol === "*" ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];
38
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RenderExportedComponentContext, { value: { evaluationContext }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_includeContexts.RenderExportedComponentContext, { value: { evaluationContext }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) });
39
42
  };
40
43
  const Include = ({
41
44
  filename,
45
+ readSource,
42
46
  exportedSymbol = "default",
43
47
  LoadingComponent = import_defaults.defaultLoadingComponent,
44
48
  ErrorComponent = import_defaults.defaultErrorComponent,
45
- baseModule
49
+ baseModule,
50
+ mode,
51
+ components
46
52
  }) => {
53
+ const contextMode = (0, import_react.use)(import_includeContexts.IncludeModeContext);
47
54
  const moduleCache = (0, import_react.use)(import_moduleCache.ModuleCacheContext);
55
+ if ((mode ?? contextMode) === "interpreted") {
56
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
57
+ import_SafeInclude.SafeInclude,
58
+ {
59
+ filename,
60
+ components,
61
+ readSource,
62
+ LoadingComponent,
63
+ ErrorComponent
64
+ }
65
+ );
66
+ }
48
67
  const evaluationContextPromise = moduleCache.getEvaluationContext(filename, baseModule ?? module);
49
68
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, { fallbackRender: ErrorComponent, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingComponent, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RenderExportedComponent, { evaluationContextPromise, exportedSymbol }) }) });
50
69
  };
51
70
  // Annotate the CommonJS export names for ESM import in node:
52
71
  0 && (module.exports = {
53
72
  Include,
73
+ IncludeModeContext,
54
74
  RenderExportedComponent,
55
75
  RenderExportedComponentContext
56
76
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/Include.tsx"],"sourcesContent":["import { Suspense, createContext, use } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { ModuleCacheContext } from '../moduleCache';\nimport { EvaluationContext } from '../sandboxTypes';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\n\n/** The value exposed on {@link RenderExportedComponentContext}: the evaluation\n * context of the module {@link Include} resolved. */\nexport type RenderFileContextType = {\n evaluationContext: EvaluationContext;\n};\n\n/** Context carrying the included module's {@link EvaluationContext} to its subtree. */\nexport const RenderExportedComponentContext = createContext<RenderFileContextType | null>(null);\n\n/** Low-level: render one export of an already-resolving module evaluation. Most\n * code should use {@link Include}, which resolves the module and adds Suspense. */\nexport const RenderExportedComponent = ({\n evaluationContextPromise,\n exportedSymbol = 'default',\n}: {\n evaluationContextPromise: Promise<EvaluationContext>;\n exportedSymbol: string;\n}) => {\n const evaluationContext = use(evaluationContextPromise);\n // TODO: handle case where exported symbol not found.\n const Component = exportedSymbol === '*' ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];\n return (\n <RenderExportedComponentContext value={{ evaluationContext }}>\n <Component />\n </RenderExportedComponentContext>\n );\n};\n\n/** Render another repo file's exported component inline, resolving + evaluating it\n * through the module cache (with Suspense + an error boundary). */\nexport const Include = ({\n filename,\n exportedSymbol = 'default',\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n baseModule,\n}: {\n filename: string;\n exportedSymbol?: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n baseModule?: EvaluationContext;\n}) => {\n const moduleCache = use(ModuleCacheContext);\n // @ts-ignore\n const evaluationContextPromise = moduleCache!.getEvaluationContext(filename, baseModule ?? module);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <RenderExportedComponent evaluationContextPromise={evaluationContextPromise} exportedSymbol={exportedSymbol} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BM;AA9BN,mBAA6C;AAC7C,kCAA8B;AAE9B,yBAAmC;AAEnC,sBAA+D;AASxD,MAAM,qCAAiC,4BAA4C,IAAI;AAIvF,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA,iBAAiB;AACnB,MAGM;AACJ,QAAM,wBAAoB,kBAAI,wBAAwB;AAEtD,QAAM,YAAY,mBAAmB,MAAM,kBAAkB,UAAU,kBAAkB,QAAQ,cAAc;AAC/G,SACE,4CAAC,kCAA+B,OAAO,EAAE,kBAAkB,GACzD,sDAAC,aAAU,GACb;AAEJ;AAIO,MAAM,UAAU,CAAC;AAAA,EACtB;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AACF,MAMM;AACJ,QAAM,kBAAc,kBAAI,qCAAkB;AAE1C,QAAM,2BAA2B,YAAa,qBAAqB,UAAU,cAAc,MAAM;AACjG,SACE,4CAAC,6CAAc,gBAAgB,gBAC7B,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC,sDAAC,2BAAwB,0BAAoD,gBAAgC,GAC/G,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/Include.tsx"],"sourcesContent":["import { Suspense, use } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { ModuleCacheContext } from '../moduleCache';\nimport { EvaluationContext } from '../sandboxTypes';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { IncludeModeContext, RenderExportedComponentContext, type IncludeMode } from './includeContexts';\nimport { SafeInclude } from './SafeInclude';\nimport type { SourceReader } from '../sourceCache';\n\n// The contexts live in `./includeContexts` so `Include` and `SafeInclude` do not import each\n// other (`check:circular`); re-exported here because this is the public entry point and the\n// import path must not change.\nexport { IncludeModeContext, RenderExportedComponentContext } from './includeContexts';\nexport type { IncludeMode, RenderFileContextType } from './includeContexts';\n\n/** Low-level: render one export of an already-resolving module evaluation. Most\n * code should use {@link Include}, which resolves the module and adds Suspense. */\nexport const RenderExportedComponent = ({\n evaluationContextPromise,\n exportedSymbol = 'default',\n}: {\n evaluationContextPromise: Promise<EvaluationContext>;\n exportedSymbol: string;\n}) => {\n const evaluationContext = use(evaluationContextPromise);\n // TODO: handle case where exported symbol not found.\n const Component = exportedSymbol === '*' ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];\n return (\n <RenderExportedComponentContext value={{ evaluationContext }}>\n <Component />\n </RenderExportedComponentContext>\n );\n};\n\n/** Render another repo file's exported component inline, resolving + evaluating it\n * through the module cache (with Suspense + an error boundary).\n *\n * Under `mode=\"interpreted\"` (or inside an {@link IncludeModeContext} set to it) the file is\n * instead rendered **as data** through the safe renderer — no author JavaScript executes,\n * and the file need not be an evaluable module at all. */\nexport const Include = ({\n filename,\n readSource,\n exportedSymbol = 'default',\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n baseModule,\n mode,\n components,\n}: {\n filename: string;\n exportedSymbol?: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n baseModule?: EvaluationContext;\n /** Override {@link IncludeModeContext} for this one include. */\n mode?: IncludeMode;\n /** Interpreted mode only: components merged OVER the surrounding MDXProvider map.\n *\n * An app's SAFE component set is not always the same as the one it hands\n * `boot({ mdxComponents })`. Grove is the worked example: under the safe renderer it also\n * needs sanitizing wrappers for structural tags (`main`, `section`, …), and it must NOT\n * register those globally, because MDX consults the provider for intrinsics on the\n * COMPILED path too — so a global registration would silently strip `style` and other\n * non-allow-listed props from compiled authors who legitimately pass them. Ignored in\n * compiled mode, where components come from the provider as they always have. */\n components?: Record<string, unknown>;\n /** Interpreted mode only: read the raw bytes yourself — e.g. through a mount fs you\n * already hold, or a cache you share with the rest of your app. The default reader\n * handles both an app-source path and an absolute path in a mount, so this is for\n * control, not for reach. Ignored in compiled mode. */\n readSource?: SourceReader;\n}) => {\n // Both contexts are read unconditionally, before the branch, so hook order is stable\n // whichever renderer this include resolves to.\n const contextMode = use(IncludeModeContext);\n const moduleCache = use(ModuleCacheContext);\n // The prop wins over the context so a single file can opt out either way: an interpreter\n // app including one trusted, executable component of its own, or a compiled app rendering\n // one file it does not trust (the shape Grove's non-executable proof page needs).\n if ((mode ?? contextMode) === 'interpreted') {\n return (\n <SafeInclude\n filename={filename}\n components={components}\n readSource={readSource}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n />\n );\n }\n // @ts-ignore\n const evaluationContextPromise = moduleCache!.getEvaluationContext(filename, baseModule ?? module);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <RenderExportedComponent evaluationContextPromise={evaluationContextPromise} exportedSymbol={exportedSymbol} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BM;AA9BN,mBAA8B;AAC9B,kCAA8B;AAE9B,yBAAmC;AAEnC,sBAA+D;AAC/D,6BAAqF;AACrF,yBAA4B;AAM5B,IAAAA,0BAAmE;AAK5D,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA,iBAAiB;AACnB,MAGM;AACJ,QAAM,wBAAoB,kBAAI,wBAAwB;AAEtD,QAAM,YAAY,mBAAmB,MAAM,kBAAkB,UAAU,kBAAkB,QAAQ,cAAc;AAC/G,SACE,4CAAC,yDAA+B,OAAO,EAAE,kBAAkB,GACzD,sDAAC,aAAU,GACb;AAEJ;AAQO,MAAM,UAAU,CAAC;AAAA,EACtB;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,MAuBM;AAGJ,QAAM,kBAAc,kBAAI,yCAAkB;AAC1C,QAAM,kBAAc,kBAAI,qCAAkB;AAI1C,OAAK,QAAQ,iBAAiB,eAAe;AAC3C,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AAEA,QAAM,2BAA2B,YAAa,qBAAqB,UAAU,cAAc,MAAM;AACjG,SACE,4CAAC,6CAAc,gBAAgB,gBAC7B,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC,sDAAC,2BAAwB,0BAAoD,gBAAgC,GAC/G,GACF;AAEJ;","names":["import_includeContexts"]}
@@ -1,15 +1,11 @@
1
1
  import * as react from 'react';
2
2
  import { EvaluationContext } from '../sandboxTypes.cjs';
3
3
  import { defaultLoadingComponent, defaultErrorComponent } from './defaults.cjs';
4
+ import { IncludeMode } from './includeContexts.cjs';
5
+ export { IncludeModeContext, RenderExportedComponentContext, RenderFileContextType } from './includeContexts.cjs';
6
+ import { SourceReader } from '../sourceCache.cjs';
4
7
  import 'react-error-boundary';
5
8
 
6
- /** The value exposed on {@link RenderExportedComponentContext}: the evaluation
7
- * context of the module {@link Include} resolved. */
8
- type RenderFileContextType = {
9
- evaluationContext: EvaluationContext;
10
- };
11
- /** Context carrying the included module's {@link EvaluationContext} to its subtree. */
12
- declare const RenderExportedComponentContext: react.Context<RenderFileContextType | null>;
13
9
  /** Low-level: render one export of an already-resolving module evaluation. Most
14
10
  * code should use {@link Include}, which resolves the module and adds Suspense. */
15
11
  declare const RenderExportedComponent: ({ evaluationContextPromise, exportedSymbol, }: {
@@ -17,13 +13,34 @@ declare const RenderExportedComponent: ({ evaluationContextPromise, exportedSymb
17
13
  exportedSymbol: string;
18
14
  }) => react.JSX.Element;
19
15
  /** Render another repo file's exported component inline, resolving + evaluating it
20
- * through the module cache (with Suspense + an error boundary). */
21
- declare const Include: ({ filename, exportedSymbol, LoadingComponent, ErrorComponent, baseModule, }: {
16
+ * through the module cache (with Suspense + an error boundary).
17
+ *
18
+ * Under `mode="interpreted"` (or inside an {@link IncludeModeContext} set to it) the file is
19
+ * instead rendered **as data** through the safe renderer — no author JavaScript executes,
20
+ * and the file need not be an evaluable module at all. */
21
+ declare const Include: ({ filename, readSource, exportedSymbol, LoadingComponent, ErrorComponent, baseModule, mode, components, }: {
22
22
  filename: string;
23
23
  exportedSymbol?: string;
24
24
  LoadingComponent?: typeof defaultLoadingComponent;
25
25
  ErrorComponent?: typeof defaultErrorComponent;
26
26
  baseModule?: EvaluationContext;
27
+ /** Override {@link IncludeModeContext} for this one include. */
28
+ mode?: IncludeMode;
29
+ /** Interpreted mode only: components merged OVER the surrounding MDXProvider map.
30
+ *
31
+ * An app's SAFE component set is not always the same as the one it hands
32
+ * `boot({ mdxComponents })`. Grove is the worked example: under the safe renderer it also
33
+ * needs sanitizing wrappers for structural tags (`main`, `section`, …), and it must NOT
34
+ * register those globally, because MDX consults the provider for intrinsics on the
35
+ * COMPILED path too — so a global registration would silently strip `style` and other
36
+ * non-allow-listed props from compiled authors who legitimately pass them. Ignored in
37
+ * compiled mode, where components come from the provider as they always have. */
38
+ components?: Record<string, unknown>;
39
+ /** Interpreted mode only: read the raw bytes yourself — e.g. through a mount fs you
40
+ * already hold, or a cache you share with the rest of your app. The default reader
41
+ * handles both an app-source path and an absolute path in a mount, so this is for
42
+ * control, not for reach. Ignored in compiled mode. */
43
+ readSource?: SourceReader;
27
44
  }) => react.JSX.Element;
28
45
 
29
- export { Include, RenderExportedComponent, RenderExportedComponentContext, type RenderFileContextType };
46
+ export { Include, IncludeMode, RenderExportedComponent };
@@ -1,15 +1,11 @@
1
1
  import * as react from 'react';
2
2
  import { EvaluationContext } from '../sandboxTypes.js';
3
3
  import { defaultLoadingComponent, defaultErrorComponent } from './defaults.js';
4
+ import { IncludeMode } from './includeContexts.js';
5
+ export { IncludeModeContext, RenderExportedComponentContext, RenderFileContextType } from './includeContexts.js';
6
+ import { SourceReader } from '../sourceCache.js';
4
7
  import 'react-error-boundary';
5
8
 
6
- /** The value exposed on {@link RenderExportedComponentContext}: the evaluation
7
- * context of the module {@link Include} resolved. */
8
- type RenderFileContextType = {
9
- evaluationContext: EvaluationContext;
10
- };
11
- /** Context carrying the included module's {@link EvaluationContext} to its subtree. */
12
- declare const RenderExportedComponentContext: react.Context<RenderFileContextType | null>;
13
9
  /** Low-level: render one export of an already-resolving module evaluation. Most
14
10
  * code should use {@link Include}, which resolves the module and adds Suspense. */
15
11
  declare const RenderExportedComponent: ({ evaluationContextPromise, exportedSymbol, }: {
@@ -17,13 +13,34 @@ declare const RenderExportedComponent: ({ evaluationContextPromise, exportedSymb
17
13
  exportedSymbol: string;
18
14
  }) => react.JSX.Element;
19
15
  /** Render another repo file's exported component inline, resolving + evaluating it
20
- * through the module cache (with Suspense + an error boundary). */
21
- declare const Include: ({ filename, exportedSymbol, LoadingComponent, ErrorComponent, baseModule, }: {
16
+ * through the module cache (with Suspense + an error boundary).
17
+ *
18
+ * Under `mode="interpreted"` (or inside an {@link IncludeModeContext} set to it) the file is
19
+ * instead rendered **as data** through the safe renderer — no author JavaScript executes,
20
+ * and the file need not be an evaluable module at all. */
21
+ declare const Include: ({ filename, readSource, exportedSymbol, LoadingComponent, ErrorComponent, baseModule, mode, components, }: {
22
22
  filename: string;
23
23
  exportedSymbol?: string;
24
24
  LoadingComponent?: typeof defaultLoadingComponent;
25
25
  ErrorComponent?: typeof defaultErrorComponent;
26
26
  baseModule?: EvaluationContext;
27
+ /** Override {@link IncludeModeContext} for this one include. */
28
+ mode?: IncludeMode;
29
+ /** Interpreted mode only: components merged OVER the surrounding MDXProvider map.
30
+ *
31
+ * An app's SAFE component set is not always the same as the one it hands
32
+ * `boot({ mdxComponents })`. Grove is the worked example: under the safe renderer it also
33
+ * needs sanitizing wrappers for structural tags (`main`, `section`, …), and it must NOT
34
+ * register those globally, because MDX consults the provider for intrinsics on the
35
+ * COMPILED path too — so a global registration would silently strip `style` and other
36
+ * non-allow-listed props from compiled authors who legitimately pass them. Ignored in
37
+ * compiled mode, where components come from the provider as they always have. */
38
+ components?: Record<string, unknown>;
39
+ /** Interpreted mode only: read the raw bytes yourself — e.g. through a mount fs you
40
+ * already hold, or a cache you share with the rest of your app. The default reader
41
+ * handles both an app-source path and an absolute path in a mount, so this is for
42
+ * control, not for reach. Ignored in compiled mode. */
43
+ readSource?: SourceReader;
27
44
  }) => react.JSX.Element;
28
45
 
29
- export { Include, RenderExportedComponent, RenderExportedComponentContext, type RenderFileContextType };
46
+ export { Include, IncludeMode, RenderExportedComponent };
@@ -1,10 +1,12 @@
1
1
  import "../chunk-VHAA22YE.js";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import { Suspense, createContext, use } from "react";
3
+ import { Suspense, use } from "react";
4
4
  import { ErrorBoundary } from "react-error-boundary";
5
5
  import { ModuleCacheContext } from "../moduleCache";
6
6
  import { defaultErrorComponent, defaultLoadingComponent } from "./defaults";
7
- const RenderExportedComponentContext = createContext(null);
7
+ import { IncludeModeContext, RenderExportedComponentContext } from "./includeContexts";
8
+ import { SafeInclude } from "./SafeInclude";
9
+ import { IncludeModeContext as IncludeModeContext2, RenderExportedComponentContext as RenderExportedComponentContext2 } from "./includeContexts";
8
10
  const RenderExportedComponent = ({
9
11
  evaluationContextPromise,
10
12
  exportedSymbol = "default"
@@ -15,18 +17,35 @@ const RenderExportedComponent = ({
15
17
  };
16
18
  const Include = ({
17
19
  filename,
20
+ readSource,
18
21
  exportedSymbol = "default",
19
22
  LoadingComponent = defaultLoadingComponent,
20
23
  ErrorComponent = defaultErrorComponent,
21
- baseModule
24
+ baseModule,
25
+ mode,
26
+ components
22
27
  }) => {
28
+ const contextMode = use(IncludeModeContext);
23
29
  const moduleCache = use(ModuleCacheContext);
30
+ if ((mode ?? contextMode) === "interpreted") {
31
+ return /* @__PURE__ */ jsx(
32
+ SafeInclude,
33
+ {
34
+ filename,
35
+ components,
36
+ readSource,
37
+ LoadingComponent,
38
+ ErrorComponent
39
+ }
40
+ );
41
+ }
24
42
  const evaluationContextPromise = moduleCache.getEvaluationContext(filename, baseModule ?? module);
25
43
  return /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorComponent, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingComponent, {}), children: /* @__PURE__ */ jsx(RenderExportedComponent, { evaluationContextPromise, exportedSymbol }) }) });
26
44
  };
27
45
  export {
28
46
  Include,
47
+ IncludeModeContext2 as IncludeModeContext,
29
48
  RenderExportedComponent,
30
- RenderExportedComponentContext
49
+ RenderExportedComponentContext2 as RenderExportedComponentContext
31
50
  };
32
51
  //# sourceMappingURL=Include.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/Include.tsx"],"sourcesContent":["import { Suspense, createContext, use } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { ModuleCacheContext } from '../moduleCache';\nimport { EvaluationContext } from '../sandboxTypes';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\n\n/** The value exposed on {@link RenderExportedComponentContext}: the evaluation\n * context of the module {@link Include} resolved. */\nexport type RenderFileContextType = {\n evaluationContext: EvaluationContext;\n};\n\n/** Context carrying the included module's {@link EvaluationContext} to its subtree. */\nexport const RenderExportedComponentContext = createContext<RenderFileContextType | null>(null);\n\n/** Low-level: render one export of an already-resolving module evaluation. Most\n * code should use {@link Include}, which resolves the module and adds Suspense. */\nexport const RenderExportedComponent = ({\n evaluationContextPromise,\n exportedSymbol = 'default',\n}: {\n evaluationContextPromise: Promise<EvaluationContext>;\n exportedSymbol: string;\n}) => {\n const evaluationContext = use(evaluationContextPromise);\n // TODO: handle case where exported symbol not found.\n const Component = exportedSymbol === '*' ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];\n return (\n <RenderExportedComponentContext value={{ evaluationContext }}>\n <Component />\n </RenderExportedComponentContext>\n );\n};\n\n/** Render another repo file's exported component inline, resolving + evaluating it\n * through the module cache (with Suspense + an error boundary). */\nexport const Include = ({\n filename,\n exportedSymbol = 'default',\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n baseModule,\n}: {\n filename: string;\n exportedSymbol?: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n baseModule?: EvaluationContext;\n}) => {\n const moduleCache = use(ModuleCacheContext);\n // @ts-ignore\n const evaluationContextPromise = moduleCache!.getEvaluationContext(filename, baseModule ?? module);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <RenderExportedComponent evaluationContextPromise={evaluationContextPromise} exportedSymbol={exportedSymbol} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";AA8BM;AA9BN,SAAS,UAAU,eAAe,WAAW;AAC7C,SAAS,qBAAqB;AAE9B,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB,+BAA+B;AASxD,MAAM,iCAAiC,cAA4C,IAAI;AAIvF,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA,iBAAiB;AACnB,MAGM;AACJ,QAAM,oBAAoB,IAAI,wBAAwB;AAEtD,QAAM,YAAY,mBAAmB,MAAM,kBAAkB,UAAU,kBAAkB,QAAQ,cAAc;AAC/G,SACE,oBAAC,kCAA+B,OAAO,EAAE,kBAAkB,GACzD,8BAAC,aAAU,GACb;AAEJ;AAIO,MAAM,UAAU,CAAC;AAAA,EACtB;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AACF,MAMM;AACJ,QAAM,cAAc,IAAI,kBAAkB;AAE1C,QAAM,2BAA2B,YAAa,qBAAqB,UAAU,cAAc,MAAM;AACjG,SACE,oBAAC,iBAAc,gBAAgB,gBAC7B,8BAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC,8BAAC,2BAAwB,0BAAoD,gBAAgC,GAC/G,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/Include.tsx"],"sourcesContent":["import { Suspense, use } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { ModuleCacheContext } from '../moduleCache';\nimport { EvaluationContext } from '../sandboxTypes';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\nimport { IncludeModeContext, RenderExportedComponentContext, type IncludeMode } from './includeContexts';\nimport { SafeInclude } from './SafeInclude';\nimport type { SourceReader } from '../sourceCache';\n\n// The contexts live in `./includeContexts` so `Include` and `SafeInclude` do not import each\n// other (`check:circular`); re-exported here because this is the public entry point and the\n// import path must not change.\nexport { IncludeModeContext, RenderExportedComponentContext } from './includeContexts';\nexport type { IncludeMode, RenderFileContextType } from './includeContexts';\n\n/** Low-level: render one export of an already-resolving module evaluation. Most\n * code should use {@link Include}, which resolves the module and adds Suspense. */\nexport const RenderExportedComponent = ({\n evaluationContextPromise,\n exportedSymbol = 'default',\n}: {\n evaluationContextPromise: Promise<EvaluationContext>;\n exportedSymbol: string;\n}) => {\n const evaluationContext = use(evaluationContextPromise);\n // TODO: handle case where exported symbol not found.\n const Component = exportedSymbol === '*' ? evaluationContext.exports : evaluationContext.exports[exportedSymbol];\n return (\n <RenderExportedComponentContext value={{ evaluationContext }}>\n <Component />\n </RenderExportedComponentContext>\n );\n};\n\n/** Render another repo file's exported component inline, resolving + evaluating it\n * through the module cache (with Suspense + an error boundary).\n *\n * Under `mode=\"interpreted\"` (or inside an {@link IncludeModeContext} set to it) the file is\n * instead rendered **as data** through the safe renderer — no author JavaScript executes,\n * and the file need not be an evaluable module at all. */\nexport const Include = ({\n filename,\n readSource,\n exportedSymbol = 'default',\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n baseModule,\n mode,\n components,\n}: {\n filename: string;\n exportedSymbol?: string;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n baseModule?: EvaluationContext;\n /** Override {@link IncludeModeContext} for this one include. */\n mode?: IncludeMode;\n /** Interpreted mode only: components merged OVER the surrounding MDXProvider map.\n *\n * An app's SAFE component set is not always the same as the one it hands\n * `boot({ mdxComponents })`. Grove is the worked example: under the safe renderer it also\n * needs sanitizing wrappers for structural tags (`main`, `section`, …), and it must NOT\n * register those globally, because MDX consults the provider for intrinsics on the\n * COMPILED path too — so a global registration would silently strip `style` and other\n * non-allow-listed props from compiled authors who legitimately pass them. Ignored in\n * compiled mode, where components come from the provider as they always have. */\n components?: Record<string, unknown>;\n /** Interpreted mode only: read the raw bytes yourself — e.g. through a mount fs you\n * already hold, or a cache you share with the rest of your app. The default reader\n * handles both an app-source path and an absolute path in a mount, so this is for\n * control, not for reach. Ignored in compiled mode. */\n readSource?: SourceReader;\n}) => {\n // Both contexts are read unconditionally, before the branch, so hook order is stable\n // whichever renderer this include resolves to.\n const contextMode = use(IncludeModeContext);\n const moduleCache = use(ModuleCacheContext);\n // The prop wins over the context so a single file can opt out either way: an interpreter\n // app including one trusted, executable component of its own, or a compiled app rendering\n // one file it does not trust (the shape Grove's non-executable proof page needs).\n if ((mode ?? contextMode) === 'interpreted') {\n return (\n <SafeInclude\n filename={filename}\n components={components}\n readSource={readSource}\n LoadingComponent={LoadingComponent}\n ErrorComponent={ErrorComponent}\n />\n );\n }\n // @ts-ignore\n const evaluationContextPromise = moduleCache!.getEvaluationContext(filename, baseModule ?? module);\n return (\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <RenderExportedComponent evaluationContextPromise={evaluationContextPromise} exportedSymbol={exportedSymbol} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n"],"mappings":";AA8BM;AA9BN,SAAS,UAAU,WAAW;AAC9B,SAAS,qBAAqB;AAE9B,SAAS,0BAA0B;AAEnC,SAAS,uBAAuB,+BAA+B;AAC/D,SAAS,oBAAoB,sCAAwD;AACrF,SAAS,mBAAmB;AAM5B,SAAS,sBAAAA,qBAAoB,kCAAAC,uCAAsC;AAK5D,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA,iBAAiB;AACnB,MAGM;AACJ,QAAM,oBAAoB,IAAI,wBAAwB;AAEtD,QAAM,YAAY,mBAAmB,MAAM,kBAAkB,UAAU,kBAAkB,QAAQ,cAAc;AAC/G,SACE,oBAAC,kCAA+B,OAAO,EAAE,kBAAkB,GACzD,8BAAC,aAAU,GACb;AAEJ;AAQO,MAAM,UAAU,CAAC;AAAA,EACtB;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AACF,MAuBM;AAGJ,QAAM,cAAc,IAAI,kBAAkB;AAC1C,QAAM,cAAc,IAAI,kBAAkB;AAI1C,OAAK,QAAQ,iBAAiB,eAAe;AAC3C,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AAEA,QAAM,2BAA2B,YAAa,qBAAqB,UAAU,cAAc,MAAM;AACjG,SACE,oBAAC,iBAAc,gBAAgB,gBAC7B,8BAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC,8BAAC,2BAAwB,0BAAoD,gBAAgC,GAC/G,GACF;AAEJ;","names":["IncludeModeContext","RenderExportedComponentContext"]}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var SafeInclude_exports = {};
20
+ __export(SafeInclude_exports, {
21
+ SafeInclude: () => SafeInclude,
22
+ appMountRelative: () => appMountRelative,
23
+ isForeignMountPath: () => isForeignMountPath,
24
+ stripFrontmatter: () => stripFrontmatter
25
+ });
26
+ module.exports = __toCommonJS(SafeInclude_exports);
27
+ var import_jsx_runtime = require("react/jsx-runtime");
28
+ var import_react = require("react");
29
+ var import_react_error_boundary = require("react-error-boundary");
30
+ var import_fs = require("../fs");
31
+ var import_mounts = require("../mounts");
32
+ var import_MDXProvider = require("../MDXProvider");
33
+ var import_SafeContent = require("../safeContent/SafeContent");
34
+ var import_sourceCache = require("../sourceCache");
35
+ var import_includeContexts = require("./includeContexts");
36
+ var import_defaults = require("./defaults");
37
+ function stripFrontmatter(source) {
38
+ return source.replace(/^\uFEFF?---\r?\n[\s\S]*?\r?\n---[ \t]*\r?\n?/, "");
39
+ }
40
+ function appMountRelative(filename) {
41
+ const root = (0, import_mounts.getAppMountPath)().replace(/\/+$/, "");
42
+ const abs = filename.startsWith(root + "/") ? filename.slice(root.length) : filename;
43
+ return abs.replace(/^\/+/, "");
44
+ }
45
+ function isForeignMountPath(filename) {
46
+ if (!filename.startsWith("/")) return false;
47
+ const root = (0, import_mounts.getAppMountPath)().replace(/\/+$/, "");
48
+ return !filename.startsWith(`${root}/`) && filename !== root;
49
+ }
50
+ function readInterpretedSource(filename) {
51
+ if (isForeignMountPath(filename)) {
52
+ return (0, import_fs.openFs)({ path: "/", type: "mount" }).readFile(
53
+ filename.replace(/^\/+/, ""),
54
+ "utf8"
55
+ );
56
+ }
57
+ return (0, import_fs.openAppFs)().readFile(appMountRelative(filename), "utf8");
58
+ }
59
+ const defaultSources = (0, import_sourceCache.createSourceCache)(readInterpretedSource);
60
+ function InterpretedBody({
61
+ filename,
62
+ components,
63
+ readSource
64
+ }) {
65
+ const sources = (0, import_react.useMemo)(
66
+ () => readSource ? (0, import_sourceCache.createSourceCache)(readSource) : defaultSources,
67
+ [readSource]
68
+ );
69
+ const raw = (0, import_react.use)(sources.read(filename));
70
+ const provided = (0, import_MDXProvider.useMDXComponents)(components);
71
+ const body = stripFrontmatter(raw);
72
+ return (
73
+ // Publishing the included file's path is what lets the WikiLink resolver know which file
74
+ // a relative `[[target]]` (and its `#sec-…` fragment) is relative TO — the same context
75
+ // the compiled path publishes from the module's evaluation.
76
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
77
+ import_includeContexts.RenderExportedComponentContext,
78
+ {
79
+ value: { evaluationContext: { evaluation: { module: { filepath: filename } } } },
80
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SafeContent.SafeContent, { source: body, components: provided })
81
+ }
82
+ )
83
+ );
84
+ }
85
+ const SafeInclude = ({
86
+ filename,
87
+ components,
88
+ readSource,
89
+ LoadingComponent = import_defaults.defaultLoadingComponent,
90
+ ErrorComponent = import_defaults.defaultErrorComponent
91
+ }) => (
92
+ // Same boundary shape as the compiled path: a file that fails to read renders the error
93
+ // component rather than taking down the tree that included it.
94
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_error_boundary.ErrorBoundary, { fallbackRender: ErrorComponent, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingComponent, {}), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InterpretedBody, { filename, components, readSource }) }) })
95
+ );
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ SafeInclude,
99
+ appMountRelative,
100
+ isForeignMountPath,
101
+ stripFrontmatter
102
+ });
103
+ //# sourceMappingURL=SafeInclude.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/SafeInclude.tsx"],"sourcesContent":["import { Suspense, use, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { openAppFs, openFs } from '../fs';\nimport { getAppMountPath } from '../mounts';\nimport { useMDXComponents } from '../MDXProvider';\nimport { SafeContent } from '../safeContent/SafeContent';\nimport { createSourceCache, type SourceReader } from '../sourceCache';\nimport { RenderExportedComponentContext } from './includeContexts';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\n\n// `<Include mode=\"interpreted\">` — the same tag, the NON-EXECUTABLE renderer. (R3-263)\n//\n// WHY THIS EXISTS. `<Include>` resolves a file through the module cache and *evaluates* it,\n// which is right for an app's own source and wrong for content. An interpreter app\n// (TRUST_MODES_SPEC §5) had no way to say \"include this file, but as data\": it could render\n// its own bodies through `<SafeContent>` while any file it pulled in with `<Include>` still\n// executed. Grove hit exactly that — a wiki declaring `render: safe` still ran author\n// JavaScript out of its `_layout.mdx`, because the layout chain went through `<Include>`.\n//\n// It is also what makes such a file renderable AT ALL when it does not live in the app: the\n// compiled path evaluates an app-source module, which a file resident in a content mount is\n// not. That is the `AGENT_AUTHORING §10` MDX-from-mount gate, which `TRUST_MODES §5.1` says\n// MUST terminate in the safe renderer and never in compiled MDX.\n//\n// The component map comes from `useMDXComponents` — the SAME provider map `boot({\n// mdxComponents })` establishes for the compiled path — so a document resolves the identical\n// vocabulary under either renderer and an app wires nothing extra to get it.\n\n/** Strip a leading YAML frontmatter block (and an optional BOM). The compiled path never\n * renders frontmatter — the MDX loader consumes it — so the safe path must not either, or\n * the same file gains a wall of raw YAML when the renderer changes. */\nexport function stripFrontmatter(source: string): string {\n return source.replace(/^\\uFEFF?---\\r?\\n[\\s\\S]*?\\r?\\n---[ \\t]*\\r?\\n?/, '');\n}\n\n/** `/app/content/x.mdx` → `content/x.mdx`. {@link openAppFs} is anchored at the app mount,\n * so an absolute module path has to be made mount-relative before it is read. A path that\n * is already relative is passed through untouched. */\nexport function appMountRelative(filename: string): string {\n const root = getAppMountPath().replace(/\\/+$/, '');\n const abs = filename.startsWith(root + '/') ? filename.slice(root.length) : filename;\n return abs.replace(/^\\/+/, '');\n}\n\n/** Is this an absolute path that lies OUTSIDE this app's own repo mount — i.e. a file\n * resident in a content mount rather than in the app? */\nexport function isForeignMountPath(filename: string): boolean {\n if (!filename.startsWith('/')) return false;\n const root = getAppMountPath().replace(/\\/+$/, '');\n return !filename.startsWith(`${root}/`) && filename !== root;\n}\n\n/**\n * Read an interpreted include's bytes.\n *\n * The reason this is not just `openAppFs()`: **the whole point of the interpreted include\n * is files the app did not author**, and the two consumers named in this file's header —\n * a dispatched wiki's `_layout.mdx`, a whiteboard object body — live in a MOUNT. An\n * app-anchored read cannot reach them, and it does not fail loudly either: the absolute\n * path is stripped to a relative one and looked up *inside the app*, so\n * `/task/<slot>/dir/_layout.mdx` becomes a miss at `task/<slot>/dir/_layout.mdx` in the\n * app's own tree. A silent wrong-file lookup, in the component whose job is rendering\n * other people's content.\n *\n * So: a path under the app mount reads exactly as before, and an absolute path outside it\n * — which could only ever have failed — reads from the unified sandbox namespace, where\n * every mount is addressable. This widens what resolves and changes nothing that resolved.\n */\nfunction readInterpretedSource(filename: string): Promise<string> {\n if (isForeignMountPath(filename)) {\n // Anchored at the namespace root: mounts are addressable by their absolute paths, and\n // this component has no way to know (and no need to know) which mount a path belongs\n // to. It confers nothing — the ZenFS port is already chroot/`ro`-enforced host-side.\n return openFs({ path: '/', type: 'mount' } as never).readFile(\n filename.replace(/^\\/+/, ''),\n 'utf8',\n ) as Promise<string>;\n }\n return openAppFs().readFile(appMountRelative(filename), 'utf8') as Promise<string>;\n}\n\n// One cache for every interpreted include in the app: a layout file is included on every\n// page, so a per-component cache would re-read it per navigation. See `../sourceCache` for\n// why a REJECTED read must not be memoised.\nconst defaultSources = createSourceCache(readInterpretedSource);\n\nfunction InterpretedBody({\n filename,\n components,\n readSource,\n}: {\n filename: string;\n components?: Record<string, unknown>;\n readSource?: SourceReader;\n}) {\n // A caller-supplied reader gets its own cache; the shared one is used otherwise. Memoised\n // on the reader identity so `use()` still sees a stable promise across renders.\n const sources = useMemo(\n () => (readSource ? createSourceCache(readSource) : defaultSources),\n [readSource],\n );\n const raw = use(sources.read(filename));\n const provided = useMDXComponents(components) as Record<string, unknown>;\n const body = stripFrontmatter(raw);\n return (\n // Publishing the included file's path is what lets the WikiLink resolver know which file\n // a relative `[[target]]` (and its `#sec-…` fragment) is relative TO — the same context\n // the compiled path publishes from the module's evaluation.\n <RenderExportedComponentContext\n value={{ evaluationContext: { evaluation: { module: { filepath: filename } } } } as never}\n >\n <SafeContent source={body} components={provided as never} />\n </RenderExportedComponentContext>\n );\n}\n\n/** Render another file's Markdown/MDX **as data** — no author JavaScript executes. Reached\n * via `<Include mode=\"interpreted\">` or `<IncludeModeContext value=\"interpreted\">`. */\nexport const SafeInclude = ({\n filename,\n components,\n readSource,\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n filename: string;\n /** Extra/override components, merged OVER the surrounding MDXProvider map. */\n components?: Record<string, unknown>;\n /** Read the raw bytes yourself — e.g. from a content mount rather than the app repo. */\n readSource?: SourceReader;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n}) => (\n // Same boundary shape as the compiled path: a file that fails to read renders the error\n // component rather than taking down the tree that included it.\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <InterpretedBody filename={filename} components={components} readSource={readSource} />\n </Suspense>\n </ErrorBoundary>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgHM;AAhHN,mBAAuC;AACvC,kCAA8B;AAE9B,gBAAkC;AAClC,oBAAgC;AAChC,yBAAiC;AACjC,yBAA4B;AAC5B,yBAAqD;AACrD,6BAA+C;AAC/C,sBAA+D;AAuBxD,SAAS,iBAAiB,QAAwB;AACvD,SAAO,OAAO,QAAQ,gDAAgD,EAAE;AAC1E;AAKO,SAAS,iBAAiB,UAA0B;AACzD,QAAM,WAAO,+BAAgB,EAAE,QAAQ,QAAQ,EAAE;AACjD,QAAM,MAAM,SAAS,WAAW,OAAO,GAAG,IAAI,SAAS,MAAM,KAAK,MAAM,IAAI;AAC5E,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;AAIO,SAAS,mBAAmB,UAA2B;AAC5D,MAAI,CAAC,SAAS,WAAW,GAAG,EAAG,QAAO;AACtC,QAAM,WAAO,+BAAgB,EAAE,QAAQ,QAAQ,EAAE;AACjD,SAAO,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,KAAK,aAAa;AAC1D;AAkBA,SAAS,sBAAsB,UAAmC;AAChE,MAAI,mBAAmB,QAAQ,GAAG;AAIhC,eAAO,kBAAO,EAAE,MAAM,KAAK,MAAM,QAAQ,CAAU,EAAE;AAAA,MACnD,SAAS,QAAQ,QAAQ,EAAE;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACA,aAAO,qBAAU,EAAE,SAAS,iBAAiB,QAAQ,GAAG,MAAM;AAChE;AAKA,MAAM,qBAAiB,sCAAkB,qBAAqB;AAE9D,SAAS,gBAAgB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAGD,QAAM,cAAU;AAAA,IACd,MAAO,iBAAa,sCAAkB,UAAU,IAAI;AAAA,IACpD,CAAC,UAAU;AAAA,EACb;AACA,QAAM,UAAM,kBAAI,QAAQ,KAAK,QAAQ,CAAC;AACtC,QAAM,eAAW,qCAAiB,UAAU;AAC5C,QAAM,OAAO,iBAAiB,GAAG;AACjC;AAAA;AAAA;AAAA;AAAA,IAIE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,SAAS,EAAE,EAAE,EAAE;AAAA,QAE/E,sDAAC,kCAAY,QAAQ,MAAM,YAAY,UAAmB;AAAA;AAAA,IAC5D;AAAA;AAEJ;AAIO,MAAM,cAAc,CAAC;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AACnB;AAAA;AAAA;AAAA,EAWE,4CAAC,6CAAc,gBAAgB,gBAC7B,sDAAC,yBAAS,UAAU,4CAAC,oBAAiB,GACpC,sDAAC,mBAAgB,UAAoB,YAAwB,YAAwB,GACvF,GACF;AAAA;","names":[]}
@@ -0,0 +1,29 @@
1
+ import * as react from 'react';
2
+ import { SourceReader } from '../sourceCache.cjs';
3
+ import { defaultLoadingComponent, defaultErrorComponent } from './defaults.cjs';
4
+ import 'react-error-boundary';
5
+
6
+ /** Strip a leading YAML frontmatter block (and an optional BOM). The compiled path never
7
+ * renders frontmatter — the MDX loader consumes it — so the safe path must not either, or
8
+ * the same file gains a wall of raw YAML when the renderer changes. */
9
+ declare function stripFrontmatter(source: string): string;
10
+ /** `/app/content/x.mdx` → `content/x.mdx`. {@link openAppFs} is anchored at the app mount,
11
+ * so an absolute module path has to be made mount-relative before it is read. A path that
12
+ * is already relative is passed through untouched. */
13
+ declare function appMountRelative(filename: string): string;
14
+ /** Is this an absolute path that lies OUTSIDE this app's own repo mount — i.e. a file
15
+ * resident in a content mount rather than in the app? */
16
+ declare function isForeignMountPath(filename: string): boolean;
17
+ /** Render another file's Markdown/MDX **as data** — no author JavaScript executes. Reached
18
+ * via `<Include mode="interpreted">` or `<IncludeModeContext value="interpreted">`. */
19
+ declare const SafeInclude: ({ filename, components, readSource, LoadingComponent, ErrorComponent, }: {
20
+ filename: string;
21
+ /** Extra/override components, merged OVER the surrounding MDXProvider map. */
22
+ components?: Record<string, unknown>;
23
+ /** Read the raw bytes yourself — e.g. from a content mount rather than the app repo. */
24
+ readSource?: SourceReader;
25
+ LoadingComponent?: typeof defaultLoadingComponent;
26
+ ErrorComponent?: typeof defaultErrorComponent;
27
+ }) => react.JSX.Element;
28
+
29
+ export { SafeInclude, appMountRelative, isForeignMountPath, stripFrontmatter };
@@ -0,0 +1,29 @@
1
+ import * as react from 'react';
2
+ import { SourceReader } from '../sourceCache.js';
3
+ import { defaultLoadingComponent, defaultErrorComponent } from './defaults.js';
4
+ import 'react-error-boundary';
5
+
6
+ /** Strip a leading YAML frontmatter block (and an optional BOM). The compiled path never
7
+ * renders frontmatter — the MDX loader consumes it — so the safe path must not either, or
8
+ * the same file gains a wall of raw YAML when the renderer changes. */
9
+ declare function stripFrontmatter(source: string): string;
10
+ /** `/app/content/x.mdx` → `content/x.mdx`. {@link openAppFs} is anchored at the app mount,
11
+ * so an absolute module path has to be made mount-relative before it is read. A path that
12
+ * is already relative is passed through untouched. */
13
+ declare function appMountRelative(filename: string): string;
14
+ /** Is this an absolute path that lies OUTSIDE this app's own repo mount — i.e. a file
15
+ * resident in a content mount rather than in the app? */
16
+ declare function isForeignMountPath(filename: string): boolean;
17
+ /** Render another file's Markdown/MDX **as data** — no author JavaScript executes. Reached
18
+ * via `<Include mode="interpreted">` or `<IncludeModeContext value="interpreted">`. */
19
+ declare const SafeInclude: ({ filename, components, readSource, LoadingComponent, ErrorComponent, }: {
20
+ filename: string;
21
+ /** Extra/override components, merged OVER the surrounding MDXProvider map. */
22
+ components?: Record<string, unknown>;
23
+ /** Read the raw bytes yourself — e.g. from a content mount rather than the app repo. */
24
+ readSource?: SourceReader;
25
+ LoadingComponent?: typeof defaultLoadingComponent;
26
+ ErrorComponent?: typeof defaultErrorComponent;
27
+ }) => react.JSX.Element;
28
+
29
+ export { SafeInclude, appMountRelative, isForeignMountPath, stripFrontmatter };
@@ -0,0 +1,77 @@
1
+ import "../chunk-VHAA22YE.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { Suspense, use, useMemo } from "react";
4
+ import { ErrorBoundary } from "react-error-boundary";
5
+ import { openAppFs, openFs } from "../fs";
6
+ import { getAppMountPath } from "../mounts";
7
+ import { useMDXComponents } from "../MDXProvider";
8
+ import { SafeContent } from "../safeContent/SafeContent";
9
+ import { createSourceCache } from "../sourceCache";
10
+ import { RenderExportedComponentContext } from "./includeContexts";
11
+ import { defaultErrorComponent, defaultLoadingComponent } from "./defaults";
12
+ function stripFrontmatter(source) {
13
+ return source.replace(/^\uFEFF?---\r?\n[\s\S]*?\r?\n---[ \t]*\r?\n?/, "");
14
+ }
15
+ function appMountRelative(filename) {
16
+ const root = getAppMountPath().replace(/\/+$/, "");
17
+ const abs = filename.startsWith(root + "/") ? filename.slice(root.length) : filename;
18
+ return abs.replace(/^\/+/, "");
19
+ }
20
+ function isForeignMountPath(filename) {
21
+ if (!filename.startsWith("/")) return false;
22
+ const root = getAppMountPath().replace(/\/+$/, "");
23
+ return !filename.startsWith(`${root}/`) && filename !== root;
24
+ }
25
+ function readInterpretedSource(filename) {
26
+ if (isForeignMountPath(filename)) {
27
+ return openFs({ path: "/", type: "mount" }).readFile(
28
+ filename.replace(/^\/+/, ""),
29
+ "utf8"
30
+ );
31
+ }
32
+ return openAppFs().readFile(appMountRelative(filename), "utf8");
33
+ }
34
+ const defaultSources = createSourceCache(readInterpretedSource);
35
+ function InterpretedBody({
36
+ filename,
37
+ components,
38
+ readSource
39
+ }) {
40
+ const sources = useMemo(
41
+ () => readSource ? createSourceCache(readSource) : defaultSources,
42
+ [readSource]
43
+ );
44
+ const raw = use(sources.read(filename));
45
+ const provided = useMDXComponents(components);
46
+ const body = stripFrontmatter(raw);
47
+ return (
48
+ // Publishing the included file's path is what lets the WikiLink resolver know which file
49
+ // a relative `[[target]]` (and its `#sec-…` fragment) is relative TO — the same context
50
+ // the compiled path publishes from the module's evaluation.
51
+ /* @__PURE__ */ jsx(
52
+ RenderExportedComponentContext,
53
+ {
54
+ value: { evaluationContext: { evaluation: { module: { filepath: filename } } } },
55
+ children: /* @__PURE__ */ jsx(SafeContent, { source: body, components: provided })
56
+ }
57
+ )
58
+ );
59
+ }
60
+ const SafeInclude = ({
61
+ filename,
62
+ components,
63
+ readSource,
64
+ LoadingComponent = defaultLoadingComponent,
65
+ ErrorComponent = defaultErrorComponent
66
+ }) => (
67
+ // Same boundary shape as the compiled path: a file that fails to read renders the error
68
+ // component rather than taking down the tree that included it.
69
+ /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorComponent, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingComponent, {}), children: /* @__PURE__ */ jsx(InterpretedBody, { filename, components, readSource }) }) })
70
+ );
71
+ export {
72
+ SafeInclude,
73
+ appMountRelative,
74
+ isForeignMountPath,
75
+ stripFrontmatter
76
+ };
77
+ //# sourceMappingURL=SafeInclude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/SafeInclude.tsx"],"sourcesContent":["import { Suspense, use, useMemo } from 'react';\nimport { ErrorBoundary } from 'react-error-boundary';\n\nimport { openAppFs, openFs } from '../fs';\nimport { getAppMountPath } from '../mounts';\nimport { useMDXComponents } from '../MDXProvider';\nimport { SafeContent } from '../safeContent/SafeContent';\nimport { createSourceCache, type SourceReader } from '../sourceCache';\nimport { RenderExportedComponentContext } from './includeContexts';\nimport { defaultErrorComponent, defaultLoadingComponent } from './defaults';\n\n// `<Include mode=\"interpreted\">` — the same tag, the NON-EXECUTABLE renderer. (R3-263)\n//\n// WHY THIS EXISTS. `<Include>` resolves a file through the module cache and *evaluates* it,\n// which is right for an app's own source and wrong for content. An interpreter app\n// (TRUST_MODES_SPEC §5) had no way to say \"include this file, but as data\": it could render\n// its own bodies through `<SafeContent>` while any file it pulled in with `<Include>` still\n// executed. Grove hit exactly that — a wiki declaring `render: safe` still ran author\n// JavaScript out of its `_layout.mdx`, because the layout chain went through `<Include>`.\n//\n// It is also what makes such a file renderable AT ALL when it does not live in the app: the\n// compiled path evaluates an app-source module, which a file resident in a content mount is\n// not. That is the `AGENT_AUTHORING §10` MDX-from-mount gate, which `TRUST_MODES §5.1` says\n// MUST terminate in the safe renderer and never in compiled MDX.\n//\n// The component map comes from `useMDXComponents` — the SAME provider map `boot({\n// mdxComponents })` establishes for the compiled path — so a document resolves the identical\n// vocabulary under either renderer and an app wires nothing extra to get it.\n\n/** Strip a leading YAML frontmatter block (and an optional BOM). The compiled path never\n * renders frontmatter — the MDX loader consumes it — so the safe path must not either, or\n * the same file gains a wall of raw YAML when the renderer changes. */\nexport function stripFrontmatter(source: string): string {\n return source.replace(/^\\uFEFF?---\\r?\\n[\\s\\S]*?\\r?\\n---[ \\t]*\\r?\\n?/, '');\n}\n\n/** `/app/content/x.mdx` → `content/x.mdx`. {@link openAppFs} is anchored at the app mount,\n * so an absolute module path has to be made mount-relative before it is read. A path that\n * is already relative is passed through untouched. */\nexport function appMountRelative(filename: string): string {\n const root = getAppMountPath().replace(/\\/+$/, '');\n const abs = filename.startsWith(root + '/') ? filename.slice(root.length) : filename;\n return abs.replace(/^\\/+/, '');\n}\n\n/** Is this an absolute path that lies OUTSIDE this app's own repo mount — i.e. a file\n * resident in a content mount rather than in the app? */\nexport function isForeignMountPath(filename: string): boolean {\n if (!filename.startsWith('/')) return false;\n const root = getAppMountPath().replace(/\\/+$/, '');\n return !filename.startsWith(`${root}/`) && filename !== root;\n}\n\n/**\n * Read an interpreted include's bytes.\n *\n * The reason this is not just `openAppFs()`: **the whole point of the interpreted include\n * is files the app did not author**, and the two consumers named in this file's header —\n * a dispatched wiki's `_layout.mdx`, a whiteboard object body — live in a MOUNT. An\n * app-anchored read cannot reach them, and it does not fail loudly either: the absolute\n * path is stripped to a relative one and looked up *inside the app*, so\n * `/task/<slot>/dir/_layout.mdx` becomes a miss at `task/<slot>/dir/_layout.mdx` in the\n * app's own tree. A silent wrong-file lookup, in the component whose job is rendering\n * other people's content.\n *\n * So: a path under the app mount reads exactly as before, and an absolute path outside it\n * — which could only ever have failed — reads from the unified sandbox namespace, where\n * every mount is addressable. This widens what resolves and changes nothing that resolved.\n */\nfunction readInterpretedSource(filename: string): Promise<string> {\n if (isForeignMountPath(filename)) {\n // Anchored at the namespace root: mounts are addressable by their absolute paths, and\n // this component has no way to know (and no need to know) which mount a path belongs\n // to. It confers nothing — the ZenFS port is already chroot/`ro`-enforced host-side.\n return openFs({ path: '/', type: 'mount' } as never).readFile(\n filename.replace(/^\\/+/, ''),\n 'utf8',\n ) as Promise<string>;\n }\n return openAppFs().readFile(appMountRelative(filename), 'utf8') as Promise<string>;\n}\n\n// One cache for every interpreted include in the app: a layout file is included on every\n// page, so a per-component cache would re-read it per navigation. See `../sourceCache` for\n// why a REJECTED read must not be memoised.\nconst defaultSources = createSourceCache(readInterpretedSource);\n\nfunction InterpretedBody({\n filename,\n components,\n readSource,\n}: {\n filename: string;\n components?: Record<string, unknown>;\n readSource?: SourceReader;\n}) {\n // A caller-supplied reader gets its own cache; the shared one is used otherwise. Memoised\n // on the reader identity so `use()` still sees a stable promise across renders.\n const sources = useMemo(\n () => (readSource ? createSourceCache(readSource) : defaultSources),\n [readSource],\n );\n const raw = use(sources.read(filename));\n const provided = useMDXComponents(components) as Record<string, unknown>;\n const body = stripFrontmatter(raw);\n return (\n // Publishing the included file's path is what lets the WikiLink resolver know which file\n // a relative `[[target]]` (and its `#sec-…` fragment) is relative TO — the same context\n // the compiled path publishes from the module's evaluation.\n <RenderExportedComponentContext\n value={{ evaluationContext: { evaluation: { module: { filepath: filename } } } } as never}\n >\n <SafeContent source={body} components={provided as never} />\n </RenderExportedComponentContext>\n );\n}\n\n/** Render another file's Markdown/MDX **as data** — no author JavaScript executes. Reached\n * via `<Include mode=\"interpreted\">` or `<IncludeModeContext value=\"interpreted\">`. */\nexport const SafeInclude = ({\n filename,\n components,\n readSource,\n LoadingComponent = defaultLoadingComponent,\n ErrorComponent = defaultErrorComponent,\n}: {\n filename: string;\n /** Extra/override components, merged OVER the surrounding MDXProvider map. */\n components?: Record<string, unknown>;\n /** Read the raw bytes yourself — e.g. from a content mount rather than the app repo. */\n readSource?: SourceReader;\n LoadingComponent?: typeof defaultLoadingComponent;\n ErrorComponent?: typeof defaultErrorComponent;\n}) => (\n // Same boundary shape as the compiled path: a file that fails to read renders the error\n // component rather than taking down the tree that included it.\n <ErrorBoundary fallbackRender={ErrorComponent}>\n <Suspense fallback={<LoadingComponent />}>\n <InterpretedBody filename={filename} components={components} readSource={readSource} />\n </Suspense>\n </ErrorBoundary>\n);\n"],"mappings":";AAgHM;AAhHN,SAAS,UAAU,KAAK,eAAe;AACvC,SAAS,qBAAqB;AAE9B,SAAS,WAAW,cAAc;AAClC,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,yBAA4C;AACrD,SAAS,sCAAsC;AAC/C,SAAS,uBAAuB,+BAA+B;AAuBxD,SAAS,iBAAiB,QAAwB;AACvD,SAAO,OAAO,QAAQ,gDAAgD,EAAE;AAC1E;AAKO,SAAS,iBAAiB,UAA0B;AACzD,QAAM,OAAO,gBAAgB,EAAE,QAAQ,QAAQ,EAAE;AACjD,QAAM,MAAM,SAAS,WAAW,OAAO,GAAG,IAAI,SAAS,MAAM,KAAK,MAAM,IAAI;AAC5E,SAAO,IAAI,QAAQ,QAAQ,EAAE;AAC/B;AAIO,SAAS,mBAAmB,UAA2B;AAC5D,MAAI,CAAC,SAAS,WAAW,GAAG,EAAG,QAAO;AACtC,QAAM,OAAO,gBAAgB,EAAE,QAAQ,QAAQ,EAAE;AACjD,SAAO,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,KAAK,aAAa;AAC1D;AAkBA,SAAS,sBAAsB,UAAmC;AAChE,MAAI,mBAAmB,QAAQ,GAAG;AAIhC,WAAO,OAAO,EAAE,MAAM,KAAK,MAAM,QAAQ,CAAU,EAAE;AAAA,MACnD,SAAS,QAAQ,QAAQ,EAAE;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACA,SAAO,UAAU,EAAE,SAAS,iBAAiB,QAAQ,GAAG,MAAM;AAChE;AAKA,MAAM,iBAAiB,kBAAkB,qBAAqB;AAE9D,SAAS,gBAAgB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAGD,QAAM,UAAU;AAAA,IACd,MAAO,aAAa,kBAAkB,UAAU,IAAI;AAAA,IACpD,CAAC,UAAU;AAAA,EACb;AACA,QAAM,MAAM,IAAI,QAAQ,KAAK,QAAQ,CAAC;AACtC,QAAM,WAAW,iBAAiB,UAAU;AAC5C,QAAM,OAAO,iBAAiB,GAAG;AACjC;AAAA;AAAA;AAAA;AAAA,IAIE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,SAAS,EAAE,EAAE,EAAE;AAAA,QAE/E,8BAAC,eAAY,QAAQ,MAAM,YAAY,UAAmB;AAAA;AAAA,IAC5D;AAAA;AAEJ;AAIO,MAAM,cAAc,CAAC;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AACnB;AAAA;AAAA;AAAA,EAWE,oBAAC,iBAAc,gBAAgB,gBAC7B,8BAAC,YAAS,UAAU,oBAAC,oBAAiB,GACpC,8BAAC,mBAAgB,UAAoB,YAAwB,YAAwB,GACvF,GACF;AAAA;","names":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var includeContexts_exports = {};
20
+ __export(includeContexts_exports, {
21
+ IncludeModeContext: () => IncludeModeContext,
22
+ RenderExportedComponentContext: () => RenderExportedComponentContext
23
+ });
24
+ module.exports = __toCommonJS(includeContexts_exports);
25
+ var import_react = require("react");
26
+ const RenderExportedComponentContext = (0, import_react.createContext)(null);
27
+ const IncludeModeContext = (0, import_react.createContext)("compiled");
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ IncludeModeContext,
31
+ RenderExportedComponentContext
32
+ });
33
+ //# sourceMappingURL=includeContexts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/includeContexts.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport { EvaluationContext } from '../sandboxTypes';\n\n// The contexts `<Include>` publishes and reads, in their own module so that `Include` and\n// `SafeInclude` can each import them without importing each other. `Include` branches to\n// `SafeInclude` and `SafeInclude` publishes `RenderExportedComponentContext`, which would be\n// a cycle if either owned the contexts — and `check:circular` is a CI gate, because a\n// circular SDK import once made the bundler infinite-loop.\n//\n// Both are re-exported from `./Include`, which is the public entry point; nothing outside\n// needs to know this module exists.\n\n/** The value exposed on {@link RenderExportedComponentContext}: the evaluation\n * context of the module `Include` resolved. */\nexport type RenderFileContextType = {\n evaluationContext: EvaluationContext;\n};\n\n/** Context carrying the included module's {@link EvaluationContext} to its subtree. */\nexport const RenderExportedComponentContext = createContext<RenderFileContextType | null>(null);\n\n/** Which renderer `Include` uses: `compiled` evaluates the module (the default, unchanged\n * behaviour); `interpreted` renders the file's Markdown/MDX **as data** through the safe\n * renderer, so no author JavaScript executes. */\nexport type IncludeMode = 'compiled' | 'interpreted';\n\n/** Declare the renderer for every `Include` in a subtree. An **interpreter** app\n * (TRUST_MODES_SPEC §5) sets this once at its root instead of remembering to pass `mode` at\n * each call site — the failure mode being silent (one forgotten `<Include>` executes author\n * code while the app believes it renders nothing but data). Defaults to `compiled`, so every\n * existing consumer is unaffected. */\nexport const IncludeModeContext = createContext<IncludeMode>('compiled');\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAoBvB,MAAM,qCAAiC,4BAA4C,IAAI;AAYvF,MAAM,yBAAqB,4BAA2B,UAAU;","names":[]}
@@ -0,0 +1,22 @@
1
+ import * as react from 'react';
2
+ import { EvaluationContext } from '../sandboxTypes.cjs';
3
+
4
+ /** The value exposed on {@link RenderExportedComponentContext}: the evaluation
5
+ * context of the module `Include` resolved. */
6
+ type RenderFileContextType = {
7
+ evaluationContext: EvaluationContext;
8
+ };
9
+ /** Context carrying the included module's {@link EvaluationContext} to its subtree. */
10
+ declare const RenderExportedComponentContext: react.Context<RenderFileContextType | null>;
11
+ /** Which renderer `Include` uses: `compiled` evaluates the module (the default, unchanged
12
+ * behaviour); `interpreted` renders the file's Markdown/MDX **as data** through the safe
13
+ * renderer, so no author JavaScript executes. */
14
+ type IncludeMode = 'compiled' | 'interpreted';
15
+ /** Declare the renderer for every `Include` in a subtree. An **interpreter** app
16
+ * (TRUST_MODES_SPEC §5) sets this once at its root instead of remembering to pass `mode` at
17
+ * each call site — the failure mode being silent (one forgotten `<Include>` executes author
18
+ * code while the app believes it renders nothing but data). Defaults to `compiled`, so every
19
+ * existing consumer is unaffected. */
20
+ declare const IncludeModeContext: react.Context<IncludeMode>;
21
+
22
+ export { type IncludeMode, IncludeModeContext, RenderExportedComponentContext, type RenderFileContextType };
@@ -0,0 +1,22 @@
1
+ import * as react from 'react';
2
+ import { EvaluationContext } from '../sandboxTypes.js';
3
+
4
+ /** The value exposed on {@link RenderExportedComponentContext}: the evaluation
5
+ * context of the module `Include` resolved. */
6
+ type RenderFileContextType = {
7
+ evaluationContext: EvaluationContext;
8
+ };
9
+ /** Context carrying the included module's {@link EvaluationContext} to its subtree. */
10
+ declare const RenderExportedComponentContext: react.Context<RenderFileContextType | null>;
11
+ /** Which renderer `Include` uses: `compiled` evaluates the module (the default, unchanged
12
+ * behaviour); `interpreted` renders the file's Markdown/MDX **as data** through the safe
13
+ * renderer, so no author JavaScript executes. */
14
+ type IncludeMode = 'compiled' | 'interpreted';
15
+ /** Declare the renderer for every `Include` in a subtree. An **interpreter** app
16
+ * (TRUST_MODES_SPEC §5) sets this once at its root instead of remembering to pass `mode` at
17
+ * each call site — the failure mode being silent (one forgotten `<Include>` executes author
18
+ * code while the app believes it renders nothing but data). Defaults to `compiled`, so every
19
+ * existing consumer is unaffected. */
20
+ declare const IncludeModeContext: react.Context<IncludeMode>;
21
+
22
+ export { type IncludeMode, IncludeModeContext, RenderExportedComponentContext, type RenderFileContextType };
@@ -0,0 +1,9 @@
1
+ import "../chunk-VHAA22YE.js";
2
+ import { createContext } from "react";
3
+ const RenderExportedComponentContext = createContext(null);
4
+ const IncludeModeContext = createContext("compiled");
5
+ export {
6
+ IncludeModeContext,
7
+ RenderExportedComponentContext
8
+ };
9
+ //# sourceMappingURL=includeContexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/includeContexts.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport { EvaluationContext } from '../sandboxTypes';\n\n// The contexts `<Include>` publishes and reads, in their own module so that `Include` and\n// `SafeInclude` can each import them without importing each other. `Include` branches to\n// `SafeInclude` and `SafeInclude` publishes `RenderExportedComponentContext`, which would be\n// a cycle if either owned the contexts — and `check:circular` is a CI gate, because a\n// circular SDK import once made the bundler infinite-loop.\n//\n// Both are re-exported from `./Include`, which is the public entry point; nothing outside\n// needs to know this module exists.\n\n/** The value exposed on {@link RenderExportedComponentContext}: the evaluation\n * context of the module `Include` resolved. */\nexport type RenderFileContextType = {\n evaluationContext: EvaluationContext;\n};\n\n/** Context carrying the included module's {@link EvaluationContext} to its subtree. */\nexport const RenderExportedComponentContext = createContext<RenderFileContextType | null>(null);\n\n/** Which renderer `Include` uses: `compiled` evaluates the module (the default, unchanged\n * behaviour); `interpreted` renders the file's Markdown/MDX **as data** through the safe\n * renderer, so no author JavaScript executes. */\nexport type IncludeMode = 'compiled' | 'interpreted';\n\n/** Declare the renderer for every `Include` in a subtree. An **interpreter** app\n * (TRUST_MODES_SPEC §5) sets this once at its root instead of remembering to pass `mode` at\n * each call site — the failure mode being silent (one forgotten `<Include>` executes author\n * code while the app believes it renders nothing but data). Defaults to `compiled`, so every\n * existing consumer is unaffected. */\nexport const IncludeModeContext = createContext<IncludeMode>('compiled');\n"],"mappings":";AAAA,SAAS,qBAAqB;AAoBvB,MAAM,iCAAiC,cAA4C,IAAI;AAYvF,MAAM,qBAAqB,cAA2B,UAAU;","names":[]}
package/dist/index.cjs CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -14,11 +18,16 @@ var __copyProps = (to, from, except, desc) => {
14
18
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
20
  var index_exports = {};
21
+ __export(index_exports, {
22
+ SafeInclude: () => import_SafeInclude.SafeInclude
23
+ });
17
24
  module.exports = __toCommonJS(index_exports);
18
25
  __reExport(index_exports, require("./MDXProvider"), module.exports);
19
26
  __reExport(index_exports, require("./routing"), module.exports);
20
27
  __reExport(index_exports, require("./boot"), module.exports);
21
28
  __reExport(index_exports, require("./components/Include"), module.exports);
29
+ var import_SafeInclude = require("./components/SafeInclude");
30
+ __reExport(index_exports, require("./sourceCache"), module.exports);
22
31
  __reExport(index_exports, require("./components/MDXComponents"), module.exports);
23
32
  __reExport(index_exports, require("./components/MountImage"), module.exports);
24
33
  __reExport(index_exports, require("./components/Routes"), module.exports);
@@ -53,10 +62,12 @@ __reExport(index_exports, require("./sandboxTypes"), module.exports);
53
62
  __reExport(index_exports, require("./safeContent"), module.exports);
54
63
  // Annotate the CommonJS export names for ESM import in node:
55
64
  0 && (module.exports = {
65
+ SafeInclude,
56
66
  ...require("./MDXProvider"),
57
67
  ...require("./routing"),
58
68
  ...require("./boot"),
59
69
  ...require("./components/Include"),
70
+ ...require("./sourceCache"),
60
71
  ...require("./components/MDXComponents"),
61
72
  ...require("./components/MountImage"),
62
73
  ...require("./components/Routes"),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './region';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './secrets';\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,uCAJd;AAKA,0BAAc,oCALd;AAMA,0BAAc,gCANd;AAOA,0BAAc,oBAPd;AAQA,0BAAc,mBARd;AASA,0BAAc,oBATd;AAUA,0BAAc,4BAVd;AAWA,0BAAc,qBAXd;AAYA,0BAAc,yBAZd;AAaA,0BAAc,qBAbd;AAcA,0BAAc,qBAdd;AAeA,0BAAc,yBAfd;AAgBA,0BAAc,sBAhBd;AAiBA,0BAAc,kBAjBd;AAkBA,0BAAc,kBAlBd;AAmBA,0BAAc,uBAnBd;AAoBA,0BAAc,sBApBd;AAqBA,0BAAc,kBArBd;AAsBA,0BAAc,0BAtBd;AAuBA,0BAAc,kBAvBd;AAwBA,0BAAc,yBAxBd;AAyBA,0BAAc,iBAzBd;AA0BA,0BAAc,oBA1Bd;AA2BA,0BAAc,oBA3Bd;AA4BA,0BAAc,qBA5Bd;AA6BA,0BAAc,sBA7Bd;AA8BA,0BAAc,wBA9Bd;AA+BA,0BAAc,oBA/Bd;AAgCA,0BAAc,sBAhCd;AAiCA,0BAAc,6BAjCd;AAkCA,0BAAc,2BAlCd;AAmCA,0BAAc,0BAnCd;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './region';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './secrets';\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAQA,yBAA4B;AAC5B,0BAAc,0BATd;AAUA,0BAAc,uCAVd;AAWA,0BAAc,oCAXd;AAYA,0BAAc,gCAZd;AAaA,0BAAc,oBAbd;AAcA,0BAAc,mBAdd;AAeA,0BAAc,oBAfd;AAgBA,0BAAc,4BAhBd;AAiBA,0BAAc,qBAjBd;AAkBA,0BAAc,yBAlBd;AAmBA,0BAAc,qBAnBd;AAoBA,0BAAc,qBApBd;AAqBA,0BAAc,yBArBd;AAsBA,0BAAc,sBAtBd;AAuBA,0BAAc,kBAvBd;AAwBA,0BAAc,kBAxBd;AAyBA,0BAAc,uBAzBd;AA0BA,0BAAc,sBA1Bd;AA2BA,0BAAc,kBA3Bd;AA4BA,0BAAc,0BA5Bd;AA6BA,0BAAc,kBA7Bd;AA8BA,0BAAc,yBA9Bd;AA+BA,0BAAc,iBA/Bd;AAgCA,0BAAc,oBAhCd;AAiCA,0BAAc,oBAjCd;AAkCA,0BAAc,qBAlCd;AAmCA,0BAAc,sBAnCd;AAoCA,0BAAc,wBApCd;AAqCA,0BAAc,oBArCd;AAsCA,0BAAc,sBAtCd;AAuCA,0BAAc,6BAvCd;AAwCA,0BAAc,2BAxCd;AAyCA,0BAAc,0BAzCd;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { MDXProvider, useMDXComponents } from './MDXProvider.cjs';
2
2
  export { AppliedRoutingRule, Router, applyRoutingRule, navigate, renderRoute, useRoute, useRouteParams, useTinkerableLink } from './routing.cjs';
3
3
  export { BootProps, CATCH_ALL_ROUTING_SPEC, DEFAULT_ROUTING_SPEC, MdxComponents, TinkerableApp, boot, resolveMdxComponents } from './boot.cjs';
4
- export { Include, RenderExportedComponent, RenderExportedComponentContext, RenderFileContextType } from './components/Include.cjs';
4
+ export { Include, RenderExportedComponent } from './components/Include.cjs';
5
+ export { SafeInclude } from './components/SafeInclude.cjs';
6
+ export { SourceCache, SourceReader, createSourceCache } from './sourceCache.cjs';
5
7
  export { DEFAULT_MDX_COMPONENTS } from './components/MDXComponents.cjs';
6
8
  export { MountImage, MountImageProps } from './components/MountImage.cjs';
7
9
  export { Route, RouteProps, Routes } from './components/Routes.cjs';
@@ -42,6 +44,7 @@ export { Admonition, AdmonitionType } from './components/Admonition.cjs';
42
44
  export { GrantRecord, Member, ResolvedUser, Role, SpaceInfo, getSpaceMembers, inviteToSpace, listAllSpaces, listGrants, listSpaces, lookupUser, revokeGrant, setSpaceRole, unshareSpace } from './generated/spaces.cjs';
43
45
  export { HeadingAnchor } from './components/HeadingAnchor.cjs';
44
46
  export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.cjs';
47
+ export { IncludeMode, IncludeModeContext, RenderExportedComponentContext, RenderFileContextType } from './components/includeContexts.cjs';
45
48
  export { InternalLink, Link } from './components/Link.cjs';
46
49
  export { SDK_VERSION } from './version.cjs';
47
50
  export { WikiLink } from './components/WikiLink.cjs';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { MDXProvider, useMDXComponents } from './MDXProvider.js';
2
2
  export { AppliedRoutingRule, Router, applyRoutingRule, navigate, renderRoute, useRoute, useRouteParams, useTinkerableLink } from './routing.js';
3
3
  export { BootProps, CATCH_ALL_ROUTING_SPEC, DEFAULT_ROUTING_SPEC, MdxComponents, TinkerableApp, boot, resolveMdxComponents } from './boot.js';
4
- export { Include, RenderExportedComponent, RenderExportedComponentContext, RenderFileContextType } from './components/Include.js';
4
+ export { Include, RenderExportedComponent } from './components/Include.js';
5
+ export { SafeInclude } from './components/SafeInclude.js';
6
+ export { SourceCache, SourceReader, createSourceCache } from './sourceCache.js';
5
7
  export { DEFAULT_MDX_COMPONENTS } from './components/MDXComponents.js';
6
8
  export { MountImage, MountImageProps } from './components/MountImage.js';
7
9
  export { Route, RouteProps, Routes } from './components/Routes.js';
@@ -42,6 +44,7 @@ export { Admonition, AdmonitionType } from './components/Admonition.js';
42
44
  export { GrantRecord, Member, ResolvedUser, Role, SpaceInfo, getSpaceMembers, inviteToSpace, listAllSpaces, listGrants, listSpaces, lookupUser, revokeGrant, setSpaceRole, unshareSpace } from './generated/spaces.js';
43
45
  export { HeadingAnchor } from './components/HeadingAnchor.js';
44
46
  export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.js';
47
+ export { IncludeMode, IncludeModeContext, RenderExportedComponentContext, RenderFileContextType } from './components/includeContexts.js';
45
48
  export { InternalLink, Link } from './components/Link.js';
46
49
  export { SDK_VERSION } from './version.js';
47
50
  export { WikiLink } from './components/WikiLink.js';
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import "./chunk-VHAA22YE.js";
1
2
  export * from "./MDXProvider";
2
3
  export * from "./routing";
3
4
  export * from "./boot";
4
5
  export * from "./components/Include";
6
+ import { SafeInclude } from "./components/SafeInclude";
7
+ export * from "./sourceCache";
5
8
  export * from "./components/MDXComponents";
6
9
  export * from "./components/MountImage";
7
10
  export * from "./components/Routes";
@@ -34,4 +37,7 @@ export * from "./loading";
34
37
  export * from "./protocolStream";
35
38
  export * from "./sandboxTypes";
36
39
  export * from "./safeContent";
40
+ export {
41
+ SafeInclude
42
+ };
37
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './region';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './secrets';\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './region';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './secrets';\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,SAAS,mBAAmB;AAC5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sourceCache_exports = {};
20
+ __export(sourceCache_exports, {
21
+ createSourceCache: () => createSourceCache
22
+ });
23
+ module.exports = __toCommonJS(sourceCache_exports);
24
+ function createSourceCache(reader) {
25
+ const cache = /* @__PURE__ */ new Map();
26
+ return {
27
+ read(path) {
28
+ const hit = cache.get(path);
29
+ if (hit) return hit;
30
+ const p = reader(path).catch((error) => {
31
+ if (cache.get(path) === p) cache.delete(path);
32
+ throw error;
33
+ });
34
+ cache.set(path, p);
35
+ return p;
36
+ },
37
+ invalidate(path) {
38
+ if (path === void 0) cache.clear();
39
+ else cache.delete(path);
40
+ },
41
+ size: () => cache.size
42
+ };
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ createSourceCache
47
+ });
48
+ //# sourceMappingURL=sourceCache.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sourceCache.ts"],"sourcesContent":["// A memoised raw-source reader for React `use()`. (R3-263)\n//\n// `use()` needs a STABLE promise across renders, so a component that reads a file must not\n// start a new read every time it renders. That much is obvious. The part that is not, and\n// the reason this lives in the SDK rather than being re-derived per app, is what happens\n// when a read FAILS:\n//\n// a rejected promise left in the cache is returned to EVERY later render, so the file can\n// never recover.\n//\n// That is not theoretical. The host↔sandbox RPC drops requests during a navigation\n// (\"Invalid RPC id\"), and a wiki entry whose read lost that race stayed **permanently blank\n// for the rest of the session** — no error, no retry, nothing short of a reload. Evicting on\n// rejection makes the next attempt a fresh read, so a transient failure costs a retry\n// instead of the page.\n//\n// Injectable reader, no `fs` import: the cache is pure and testable without a host, and the\n// same instance serves whatever mount the caller reads from.\n\nexport type SourceReader = (path: string) => Promise<string>;\n\nexport interface SourceCache {\n /** The memoised read for `path` — the same promise identity until it settles-and-fails. */\n read: (path: string) => Promise<string>;\n /** Drop a memoised read (a live edit, or an explicit refresh); no argument clears all. */\n invalidate: (path?: string) => void;\n /** Testing/diagnostics: how many paths are memoised right now. */\n size: () => number;\n}\n\nexport function createSourceCache(reader: SourceReader): SourceCache {\n const cache = new Map<string, Promise<string>>();\n return {\n read(path) {\n const hit = cache.get(path);\n if (hit) return hit;\n const p = reader(path).catch((error: unknown) => {\n // Never let a failure become the permanent answer for this path. Guarded on\n // identity so a newer read started after an invalidate is not evicted by an older\n // one settling late.\n if (cache.get(path) === p) cache.delete(path);\n throw error;\n });\n cache.set(path, p);\n return p;\n },\n invalidate(path) {\n if (path === undefined) cache.clear();\n else cache.delete(path);\n },\n size: () => cache.size,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,kBAAkB,QAAmC;AACnE,QAAM,QAAQ,oBAAI,IAA6B;AAC/C,SAAO;AAAA,IACL,KAAK,MAAM;AACT,YAAM,MAAM,MAAM,IAAI,IAAI;AAC1B,UAAI,IAAK,QAAO;AAChB,YAAM,IAAI,OAAO,IAAI,EAAE,MAAM,CAAC,UAAmB;AAI/C,YAAI,MAAM,IAAI,IAAI,MAAM,EAAG,OAAM,OAAO,IAAI;AAC5C,cAAM;AAAA,MACR,CAAC;AACD,YAAM,IAAI,MAAM,CAAC;AACjB,aAAO;AAAA,IACT;AAAA,IACA,WAAW,MAAM;AACf,UAAI,SAAS,OAAW,OAAM,MAAM;AAAA,UAC/B,OAAM,OAAO,IAAI;AAAA,IACxB;AAAA,IACA,MAAM,MAAM,MAAM;AAAA,EACpB;AACF;","names":[]}
@@ -0,0 +1,12 @@
1
+ type SourceReader = (path: string) => Promise<string>;
2
+ interface SourceCache {
3
+ /** The memoised read for `path` — the same promise identity until it settles-and-fails. */
4
+ read: (path: string) => Promise<string>;
5
+ /** Drop a memoised read (a live edit, or an explicit refresh); no argument clears all. */
6
+ invalidate: (path?: string) => void;
7
+ /** Testing/diagnostics: how many paths are memoised right now. */
8
+ size: () => number;
9
+ }
10
+ declare function createSourceCache(reader: SourceReader): SourceCache;
11
+
12
+ export { type SourceCache, type SourceReader, createSourceCache };
@@ -0,0 +1,12 @@
1
+ type SourceReader = (path: string) => Promise<string>;
2
+ interface SourceCache {
3
+ /** The memoised read for `path` — the same promise identity until it settles-and-fails. */
4
+ read: (path: string) => Promise<string>;
5
+ /** Drop a memoised read (a live edit, or an explicit refresh); no argument clears all. */
6
+ invalidate: (path?: string) => void;
7
+ /** Testing/diagnostics: how many paths are memoised right now. */
8
+ size: () => number;
9
+ }
10
+ declare function createSourceCache(reader: SourceReader): SourceCache;
11
+
12
+ export { type SourceCache, type SourceReader, createSourceCache };
@@ -0,0 +1,25 @@
1
+ import "./chunk-VHAA22YE.js";
2
+ function createSourceCache(reader) {
3
+ const cache = /* @__PURE__ */ new Map();
4
+ return {
5
+ read(path) {
6
+ const hit = cache.get(path);
7
+ if (hit) return hit;
8
+ const p = reader(path).catch((error) => {
9
+ if (cache.get(path) === p) cache.delete(path);
10
+ throw error;
11
+ });
12
+ cache.set(path, p);
13
+ return p;
14
+ },
15
+ invalidate(path) {
16
+ if (path === void 0) cache.clear();
17
+ else cache.delete(path);
18
+ },
19
+ size: () => cache.size
20
+ };
21
+ }
22
+ export {
23
+ createSourceCache
24
+ };
25
+ //# sourceMappingURL=sourceCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sourceCache.ts"],"sourcesContent":["// A memoised raw-source reader for React `use()`. (R3-263)\n//\n// `use()` needs a STABLE promise across renders, so a component that reads a file must not\n// start a new read every time it renders. That much is obvious. The part that is not, and\n// the reason this lives in the SDK rather than being re-derived per app, is what happens\n// when a read FAILS:\n//\n// a rejected promise left in the cache is returned to EVERY later render, so the file can\n// never recover.\n//\n// That is not theoretical. The host↔sandbox RPC drops requests during a navigation\n// (\"Invalid RPC id\"), and a wiki entry whose read lost that race stayed **permanently blank\n// for the rest of the session** — no error, no retry, nothing short of a reload. Evicting on\n// rejection makes the next attempt a fresh read, so a transient failure costs a retry\n// instead of the page.\n//\n// Injectable reader, no `fs` import: the cache is pure and testable without a host, and the\n// same instance serves whatever mount the caller reads from.\n\nexport type SourceReader = (path: string) => Promise<string>;\n\nexport interface SourceCache {\n /** The memoised read for `path` — the same promise identity until it settles-and-fails. */\n read: (path: string) => Promise<string>;\n /** Drop a memoised read (a live edit, or an explicit refresh); no argument clears all. */\n invalidate: (path?: string) => void;\n /** Testing/diagnostics: how many paths are memoised right now. */\n size: () => number;\n}\n\nexport function createSourceCache(reader: SourceReader): SourceCache {\n const cache = new Map<string, Promise<string>>();\n return {\n read(path) {\n const hit = cache.get(path);\n if (hit) return hit;\n const p = reader(path).catch((error: unknown) => {\n // Never let a failure become the permanent answer for this path. Guarded on\n // identity so a newer read started after an invalidate is not evicted by an older\n // one settling late.\n if (cache.get(path) === p) cache.delete(path);\n throw error;\n });\n cache.set(path, p);\n return p;\n },\n invalidate(path) {\n if (path === undefined) cache.clear();\n else cache.delete(path);\n },\n size: () => cache.size,\n };\n}\n"],"mappings":";AA8BO,SAAS,kBAAkB,QAAmC;AACnE,QAAM,QAAQ,oBAAI,IAA6B;AAC/C,SAAO;AAAA,IACL,KAAK,MAAM;AACT,YAAM,MAAM,MAAM,IAAI,IAAI;AAC1B,UAAI,IAAK,QAAO;AAChB,YAAM,IAAI,OAAO,IAAI,EAAE,MAAM,CAAC,UAAmB;AAI/C,YAAI,MAAM,IAAI,IAAI,MAAM,EAAG,OAAM,OAAO,IAAI;AAC5C,cAAM;AAAA,MACR,CAAC;AACD,YAAM,IAAI,MAAM,CAAC;AACjB,aAAO;AAAA,IACT;AAAA,IACA,WAAW,MAAM;AACf,UAAI,SAAS,OAAW,OAAM,MAAM;AAAA,UAC/B,OAAM,OAAO,IAAI;AAAA,IACxB;AAAA,IACA,MAAM,MAAM,MAAM;AAAA,EACpB;AACF;","names":[]}
package/dist/version.cjs CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  SDK_VERSION: () => SDK_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const SDK_VERSION = "0.39.0";
24
+ const SDK_VERSION = "0.41.0";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  SDK_VERSION
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.39.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.41.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,cAAc;","names":[]}
@@ -1,4 +1,4 @@
1
1
  /** This SDK's package version, baked from package.json at build (SP2-6). */
2
- declare const SDK_VERSION = "0.39.0";
2
+ declare const SDK_VERSION = "0.41.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** This SDK's package version, baked from package.json at build (SP2-6). */
2
- declare const SDK_VERSION = "0.39.0";
2
+ declare const SDK_VERSION = "0.41.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-VHAA22YE.js";
2
- const SDK_VERSION = "0.39.0";
2
+ const SDK_VERSION = "0.41.0";
3
3
  export {
4
4
  SDK_VERSION
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.39.0';\n"],"mappings":";AAIO,MAAM,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.41.0';\n"],"mappings":";AAIO,MAAM,cAAc;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/sdk",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "Runtime SDK for code executing inside an immediately.run sandbox.",
5
5
  "license": "MIT",
6
6
  "repository": "github:immediately-run/immediately-run-sdk",