@ai-matrx/code-runtime 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/execute.cjs +890 -0
- package/dist/execute.cjs.map +1 -0
- package/dist/execute.d.cts +11 -0
- package/dist/execute.d.ts +11 -0
- package/dist/execute.js +858 -0
- package/dist/execute.js.map +1 -0
- package/dist/gate-lists.json +105 -0
- package/dist/gate.cjs +291 -0
- package/dist/gate.cjs.map +1 -0
- package/dist/gate.d.cts +49 -0
- package/dist/gate.d.ts +49 -0
- package/dist/gate.js +268 -0
- package/dist/gate.js.map +1 -0
- package/dist/index.cjs +1196 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +87 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +1164 -0
- package/dist/index.js.map +1 -0
- package/dist/scope-lrQkC0jP.d.cts +205 -0
- package/dist/scope-lrQkC0jP.d.ts +205 -0
- package/dist/scope.cjs +597 -0
- package/dist/scope.cjs.map +1 -0
- package/dist/scope.d.cts +2 -0
- package/dist/scope.d.ts +2 -0
- package/dist/scope.js +565 -0
- package/dist/scope.js.map +1 -0
- package/dist/transform.cjs +140 -0
- package/dist/transform.cjs.map +1 -0
- package/dist/transform.d.cts +12 -0
- package/dist/transform.d.ts +12 -0
- package/dist/transform.js +117 -0
- package/dist/transform.js.map +1 -0
- package/dist/types-DL6oTcV_.d.cts +50 -0
- package/dist/types-DL6oTcV_.d.ts +50 -0
- package/package.json +137 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The error every refusal carries. Structurally identical to
|
|
5
|
+
* `@ai-matrx/applets`' `AppletError` (CONTRACTS §0); mirrored here because
|
|
6
|
+
* applets depends on this package, never the reverse.
|
|
7
|
+
*/
|
|
8
|
+
interface CodeRuntimeError {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
retryable: boolean;
|
|
12
|
+
diagnostic?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What a compile may import (CONTRACTS §7). `entries` are import paths from
|
|
16
|
+
* the one documented registry (`listScopeEntries()`); `overrides` are
|
|
17
|
+
* host-owned replacements by scope name (e.g. a runtime-aware MarkdownStream);
|
|
18
|
+
* `shadowDangerousGlobals` installs throwing stubs over fetch/eval/… for
|
|
19
|
+
* organization-authored code.
|
|
20
|
+
*/
|
|
21
|
+
interface ScopeSpec {
|
|
22
|
+
entries: string[];
|
|
23
|
+
overrides?: Record<string, unknown>;
|
|
24
|
+
shadowDangerousGlobals: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** One name the code referenced that nothing could supply. */
|
|
27
|
+
interface UnresolvedImport {
|
|
28
|
+
identifier: string;
|
|
29
|
+
/** null for a bare JSX reference with no import behind it. */
|
|
30
|
+
importPath: string | null;
|
|
31
|
+
}
|
|
32
|
+
type CompiledComponent = React.ComponentType<Record<string, unknown>>;
|
|
33
|
+
type CompileResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
Component: CompiledComponent;
|
|
36
|
+
/** One readable line per unresolved name (`X from "path"`). */
|
|
37
|
+
unresolved: string[];
|
|
38
|
+
/** The same list, structured. */
|
|
39
|
+
unresolvedImports: UnresolvedImport[];
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
error: CodeRuntimeError;
|
|
43
|
+
};
|
|
44
|
+
/** One source-gate finding (CONTRACTS §7). */
|
|
45
|
+
interface Finding {
|
|
46
|
+
rule: string;
|
|
47
|
+
file: string;
|
|
48
|
+
line: number;
|
|
49
|
+
message: string;
|
|
50
|
+
severity: "refuse" | "warn";
|
|
51
|
+
}
|
|
52
|
+
/** One import specifier, recorded before the declaration is rewritten. */
|
|
53
|
+
interface ImportBinding {
|
|
54
|
+
local: string;
|
|
55
|
+
source: string;
|
|
56
|
+
/** Exported name, `"default"`, or `"*"` for a namespace import. */
|
|
57
|
+
imported: string;
|
|
58
|
+
}
|
|
59
|
+
/** One transformed file: plain JSON, so it crosses `postMessage` unchanged. */
|
|
60
|
+
interface TransformedModule {
|
|
61
|
+
file: string;
|
|
62
|
+
/** CommonJS-shaped JS (`require`, `module`, `exports` are supplied at run). */
|
|
63
|
+
code: string;
|
|
64
|
+
declaredTopLevel: string[];
|
|
65
|
+
/** Top-level PascalCase bindings in declaration order. */
|
|
66
|
+
componentCandidates: string[];
|
|
67
|
+
importBindings: ImportBinding[];
|
|
68
|
+
}
|
|
69
|
+
/** A whole transformed file graph — the parent → frame payload. */
|
|
70
|
+
interface TransformedGraph {
|
|
71
|
+
entry: string;
|
|
72
|
+
modules: Record<string, TransformedModule>;
|
|
73
|
+
}
|
|
74
|
+
type TransformResult = {
|
|
75
|
+
ok: true;
|
|
76
|
+
graph: TransformedGraph;
|
|
77
|
+
} | {
|
|
78
|
+
ok: false;
|
|
79
|
+
error: CodeRuntimeError;
|
|
80
|
+
};
|
|
81
|
+
/** Options every compile entry accepts (a superset of the contract call). */
|
|
82
|
+
interface CompileOptions {
|
|
83
|
+
/**
|
|
84
|
+
* Which stored thing this is — `tool:<name>`, `applet:<id>`, `kind:<slug>`…
|
|
85
|
+
* Every unresolved name is reported under it.
|
|
86
|
+
*/
|
|
87
|
+
origin?: string;
|
|
88
|
+
/** Where unresolved names are reported (default: one console warning per name). */
|
|
89
|
+
onUnresolved?: (origin: string, unresolved: readonly UnresolvedImport[]) => void;
|
|
90
|
+
/**
|
|
91
|
+
* With no default export, which top-level PascalCase binding is the
|
|
92
|
+
* component: `"last"` (default — the stored-component contract) or
|
|
93
|
+
* `"conventional"` (App, Main, Page, Component, Demo, Example or Root
|
|
94
|
+
* first, else the last — chat code blocks).
|
|
95
|
+
*/
|
|
96
|
+
componentCandidate?: "last" | "conventional";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type AnyRecord = Record<string, unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* Throwing stubs for the globals stored code may not use. Named error, never
|
|
102
|
+
* silence: the reader's error boundary shows which global it reached for.
|
|
103
|
+
* BACKSTOP, not a sandbox — bare identifiers only; `window.fetch` still
|
|
104
|
+
* resolves. The write-time gate refuses `window.fetch`; the sandbox frame is
|
|
105
|
+
* the real boundary.
|
|
106
|
+
*/
|
|
107
|
+
declare function buildDangerousGlobalStubs(): AnyRecord;
|
|
108
|
+
/**
|
|
109
|
+
* `buildScope` (CONTRACTS §7): the named, documented values a spec puts in
|
|
110
|
+
* scope. Async entries not yet prepared are absent (see `prepareScope`).
|
|
111
|
+
*/
|
|
112
|
+
declare function buildScope(spec: ScopeSpec): Record<string, unknown>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* THE ONE DOCUMENTED SCOPE REGISTRY — every import path stored code may name.
|
|
116
|
+
*
|
|
117
|
+
* Merged from matrx-frontend's two registries (`agent-apps/utils/
|
|
118
|
+
* allowed-imports.ts` and `dynamic-react/toolRendererScope.ts`), which
|
|
119
|
+
* disagreed on strategies, lists and loading. Rules that hold:
|
|
120
|
+
* - every entry is EXPLICITLY named and documented; no wildcard;
|
|
121
|
+
* - nothing here reaches data: no database client, no fetch wrapper, no
|
|
122
|
+
* store — data reach belongs to the host (CONTRACTS §1);
|
|
123
|
+
* - an entry is `package`-owned (this package ships its module, so a plain
|
|
124
|
+
* Vite page gets it) or `host`-owned (declared and documented here, the
|
|
125
|
+
* module supplied by the host through `provideScopeModules`); a host entry
|
|
126
|
+
* no host supplied renders named stand-ins and is reported, never crashes;
|
|
127
|
+
* - `@/components/ui/*` are LEGACY ALIASES kept while stored code uses them
|
|
128
|
+
* (census 2026-10-06: 67 kind components, 78 apps). Each names the same
|
|
129
|
+
* design-system export the frontend file re-exports; new code imports
|
|
130
|
+
* `@ai-matrx/design-system/controls` (the primary UI set).
|
|
131
|
+
*
|
|
132
|
+
* Pure data: no React, no module loads — `gate.ts` and servers read it.
|
|
133
|
+
* `gate-lists.json#allowedImports` must equal `listScopeEntryPaths()` sorted
|
|
134
|
+
* (guard: `scope-registry.test.ts`).
|
|
135
|
+
*/
|
|
136
|
+
type ScopeStrategy = "named" | "spread" | "namespace";
|
|
137
|
+
interface ScopeEntryDeclaration {
|
|
138
|
+
/** The import path stored code writes. */
|
|
139
|
+
path: string;
|
|
140
|
+
/** `named`: listed exports; `spread`: every export; `namespace`: the module under `namespaceName`. */
|
|
141
|
+
strategy: ScopeStrategy;
|
|
142
|
+
exports?: readonly string[];
|
|
143
|
+
/** moduleKey → scope name (`{ default: "MarkdownStream" }`). */
|
|
144
|
+
exportMap?: Readonly<Record<string, string>>;
|
|
145
|
+
namespaceName?: string;
|
|
146
|
+
/** Missing PascalCase names resolve to a visible stand-in (icon sets). */
|
|
147
|
+
safeProxy?: boolean;
|
|
148
|
+
/** Always present for chat code blocks (cheap, already in shared chunks). */
|
|
149
|
+
core?: boolean;
|
|
150
|
+
/** Identifiers whose bare use implies this entry (heavy-lib demand detection). */
|
|
151
|
+
provides?: readonly string[];
|
|
152
|
+
owner: "package" | "host";
|
|
153
|
+
description: string;
|
|
154
|
+
}
|
|
155
|
+
declare const SCOPE_ENTRIES: readonly ScopeEntryDeclaration[];
|
|
156
|
+
declare function getScopeEntry(path: string): ScopeEntryDeclaration | undefined;
|
|
157
|
+
/** Every documented path, in registry order. */
|
|
158
|
+
declare function listScopeEntryPaths(): string[];
|
|
159
|
+
/** Every documented entry with its description (for builders, agents and docs). */
|
|
160
|
+
declare function listScopeEntries(): readonly ScopeEntryDeclaration[];
|
|
161
|
+
/**
|
|
162
|
+
* The default scope for stored components (kind components, tool renderers,
|
|
163
|
+
* Applets): everything except the heavy optional libraries, which are added
|
|
164
|
+
* by demand detection. Order is spread precedence: later entries win.
|
|
165
|
+
*/
|
|
166
|
+
declare function defaultComponentEntries(): string[];
|
|
167
|
+
/** Paths always loaded for chat code blocks. */
|
|
168
|
+
declare function coreEntryPaths(): string[];
|
|
169
|
+
/**
|
|
170
|
+
* The entries a set of files needs: the core set, every documented path it
|
|
171
|
+
* imports, and every heavy library whose identifiers it uses bare.
|
|
172
|
+
*/
|
|
173
|
+
declare function detectEntries(files: Readonly<Record<string, string>>): string[];
|
|
174
|
+
|
|
175
|
+
type ScopeModuleLoader = () => unknown;
|
|
176
|
+
/**
|
|
177
|
+
* Supply (or replace) the modules for scope entries. Keys must be documented
|
|
178
|
+
* registry paths; an unknown key throws, because a module nobody documented
|
|
179
|
+
* is exactly the reach the registry exists to prevent.
|
|
180
|
+
*/
|
|
181
|
+
declare function provideScopeModules(map: Readonly<Record<string, ScopeModuleLoader>>): void;
|
|
182
|
+
/** Resolve every async module the given entries need. Never rejects. */
|
|
183
|
+
declare function prepareScopeModules(paths: readonly string[]): Promise<void>;
|
|
184
|
+
/** Test seam: forget every provided and loaded module. */
|
|
185
|
+
declare function resetScopeModules(): void;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* NOTHING FAILS SILENTLY. Stored code that names something the scope cannot
|
|
189
|
+
* supply still renders — one bad import must not blank a whole display — but
|
|
190
|
+
* the gap is SHOWN where it sits: a compact dashed chip carrying the missing
|
|
191
|
+
* name (tooltip: the import path), with the element's children rendered after
|
|
192
|
+
* it. Moved verbatim from matrx-frontend
|
|
193
|
+
* `features/agent-apps/utils/patch-scope-identifiers.ts`; the mark symbol is
|
|
194
|
+
* unchanged (`Symbol.for`) so stand-ins made by either copy are recognised.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
/** The stand-in's own record, or null when `value` is a real binding. */
|
|
198
|
+
declare function readUnresolvedImportMark(value: unknown): UnresolvedImport | null;
|
|
199
|
+
declare function createUnresolvedImportStandIn(identifier: string, importPath?: string | null): React.ForwardRefExoticComponent<{
|
|
200
|
+
children?: React.ReactNode;
|
|
201
|
+
} & React.RefAttributes<HTMLSpanElement>>;
|
|
202
|
+
/** One readable line per unresolved name. */
|
|
203
|
+
declare function describeUnresolved(entry: UnresolvedImport): string;
|
|
204
|
+
|
|
205
|
+
export { type CompileOptions as C, type Finding as F, type ImportBinding as I, type ScopeSpec as S, type TransformResult as T, type UnresolvedImport as U, type CompileResult as a, type CompiledComponent as b, type CodeRuntimeError as c, SCOPE_ENTRIES as d, type ScopeEntryDeclaration as e, type ScopeModuleLoader as f, type ScopeStrategy as g, type TransformedGraph as h, type TransformedModule as i, buildDangerousGlobalStubs as j, buildScope as k, coreEntryPaths as l, createUnresolvedImportStandIn as m, defaultComponentEntries as n, describeUnresolved as o, detectEntries as p, getScopeEntry as q, listScopeEntries as r, listScopeEntryPaths as s, provideScopeModules as t, readUnresolvedImportMark as u, resetScopeModules as v, prepareScopeModules as w };
|