@ggui-ai/ui-gen 0.10.0 → 0.11.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.
@@ -1,8 +1,158 @@
1
+ import { existsSync } from 'fs';
1
2
  import { createRequire } from 'module';
3
+ import { fileURLToPath, pathToFileURL } from 'url';
4
+ import { runSandboxed } from '@ggui-ai/sandbox';
2
5
  import { listContractGadgets, HOOK_NAME_RE } from '@ggui-ai/protocol';
3
6
  import ts from 'typescript';
4
7
 
5
- // src/harness/check/runtime-render/production-act-shim.ts
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __esm = (fn, res, err) => function __init() {
11
+ if (err) throw err[0];
12
+ try {
13
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
14
+ } catch (e) {
15
+ throw err = [e], e;
16
+ }
17
+ };
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, { get: all[name], enumerable: true });
21
+ };
22
+
23
+ // src/harness/check/runtime-render/render-check-host.ts
24
+ var render_check_host_exports = {};
25
+ __export(render_check_host_exports, {
26
+ mapSandboxResultToCheckResult: () => mapSandboxResultToCheckResult,
27
+ runRenderCheckViaWorker: () => runRenderCheckViaWorker
28
+ });
29
+ function resolveWorkerSpawn() {
30
+ const jsCandidates = [
31
+ // Sibling — when import.meta.url is already .../harness/check/runtime-render/.
32
+ new URL(`./${WORKER_BASENAME}.js`, import.meta.url),
33
+ // From dist/index.js.
34
+ new URL(`./harness/check/runtime-render/${WORKER_BASENAME}.js`, import.meta.url),
35
+ // From dist/harness/index.js.
36
+ new URL(`./check/runtime-render/${WORKER_BASENAME}.js`, import.meta.url),
37
+ // From dist/check/index.js, dist/advanced/index.js, dist/<flat>.js.
38
+ new URL(`../harness/check/runtime-render/${WORKER_BASENAME}.js`, import.meta.url)
39
+ ];
40
+ for (const jsUrl of jsCandidates) {
41
+ const jsPath = fileURLToPath(jsUrl);
42
+ if (existsSync(jsPath)) {
43
+ return { command: process.execPath, args: [jsPath] };
44
+ }
45
+ }
46
+ const tsCandidates = [
47
+ new URL(`./${WORKER_BASENAME}.ts`, import.meta.url),
48
+ new URL(`../harness/check/runtime-render/${WORKER_BASENAME}.ts`, import.meta.url)
49
+ ];
50
+ for (const tsUrl of tsCandidates) {
51
+ const tsPath = fileURLToPath(tsUrl);
52
+ if (existsSync(tsPath)) {
53
+ const require_ = createRequire(import.meta.url);
54
+ const tsxLoader = pathToFileURL(require_.resolve("tsx")).href;
55
+ return { command: process.execPath, args: ["--import", tsxLoader, tsPath] };
56
+ }
57
+ }
58
+ const tried = [...jsCandidates, ...tsCandidates].map((u) => fileURLToPath(u)).join(", ");
59
+ throw new Error(
60
+ `render-check: isolated worker not found at any of: ${tried}. Did \`pnpm build\` run?`
61
+ );
62
+ }
63
+ function failed(reason, t0) {
64
+ return {
65
+ ok: false,
66
+ issues: [{ check: "render-no-throw", outcome: "failed", reason }],
67
+ stats: { actionsChecked: 0, streamsChecked: 0, renderMs: Date.now() - t0 }
68
+ };
69
+ }
70
+ function unverified(reason, t0) {
71
+ return {
72
+ ok: false,
73
+ issues: [{ check: "render-no-throw", outcome: "unverified", reason }],
74
+ stats: { actionsChecked: 0, streamsChecked: 0, renderMs: Date.now() - t0 }
75
+ };
76
+ }
77
+ function mapSandboxResultToCheckResult(result, t0) {
78
+ if (result.outcome === "timeout") {
79
+ return failed(
80
+ `render check timed out after ${CHECK_TIMEOUT_MS}ms in the isolated worker (likely infinite loop or runaway effect in the component).`,
81
+ t0
82
+ );
83
+ }
84
+ if (result.outcome === "overflow-stdout" || result.outcome === "overflow-stderr") {
85
+ return failed(
86
+ `render check worker produced excessive output (${result.outcome}) \u2014 the component is likely in a pathological logging or error loop.`,
87
+ t0
88
+ );
89
+ }
90
+ if (result.outcome === "spawn-error") {
91
+ return unverified(
92
+ `render check worker failed to start \u2014 ${result.errorMessage}`,
93
+ t0
94
+ );
95
+ }
96
+ if (result.outcome === "canceled") {
97
+ return unverified("render check worker was canceled before completing.", t0);
98
+ }
99
+ if (result.outcome !== "exit") {
100
+ return unverified(
101
+ `render check worker ended with unexpected sandbox outcome '${result.outcome}'.`,
102
+ t0
103
+ );
104
+ }
105
+ if (result.exitCode !== 0) {
106
+ const tail = result.stderr.trim() || result.stdout.trim();
107
+ return unverified(
108
+ `render check worker exited ${result.exitCode}${tail ? ` \u2014 ${tail.slice(0, 600)}` : ""}`,
109
+ t0
110
+ );
111
+ }
112
+ const stdout = result.stdout.trim();
113
+ if (stdout.length === 0) {
114
+ return unverified("render check worker exited without producing a verdict.", t0);
115
+ }
116
+ try {
117
+ return JSON.parse(stdout);
118
+ } catch (err) {
119
+ return unverified(
120
+ `render check worker verdict was not valid JSON \u2014 ${err instanceof Error ? err.message : String(err)}`,
121
+ t0
122
+ );
123
+ }
124
+ }
125
+ async function runRenderCheckViaWorker(input) {
126
+ const t0 = Date.now();
127
+ let spawn;
128
+ try {
129
+ spawn = resolveWorkerSpawn();
130
+ } catch (err) {
131
+ return unverified(err instanceof Error ? err.message : String(err), t0);
132
+ }
133
+ const result = await runSandboxed({
134
+ command: spawn.command,
135
+ args: spawn.args,
136
+ timeoutMs: CHECK_TIMEOUT_MS,
137
+ maxStdoutBytes: CHECK_STDOUT_CAP,
138
+ nodeHeapMb: CHECK_NODE_HEAP_MB,
139
+ stdin: JSON.stringify(input),
140
+ // NODE_ENV steers React's production vs development build — keep
141
+ // parity with the caller; everything else stays on the sandbox's
142
+ // default allowlist.
143
+ env: { NODE_ENV: process.env.NODE_ENV ?? "production" }
144
+ });
145
+ return mapSandboxResultToCheckResult(result, t0);
146
+ }
147
+ var CHECK_TIMEOUT_MS, CHECK_STDOUT_CAP, CHECK_NODE_HEAP_MB, WORKER_BASENAME;
148
+ var init_render_check_host = __esm({
149
+ "src/harness/check/runtime-render/render-check-host.ts"() {
150
+ CHECK_TIMEOUT_MS = 3e4;
151
+ CHECK_STDOUT_CAP = 2 * 1024 * 1024;
152
+ CHECK_NODE_HEAP_MB = 512;
153
+ WORKER_BASENAME = "render-check-worker";
154
+ }
155
+ });
6
156
  var installed = false;
7
157
  function installProductionActShim() {
8
158
  if (installed) return;
@@ -205,8 +355,8 @@ ${cjsResult.code}
205
355
  // src/harness/check/runtime-render/load-component.ts
206
356
  async function loadComponent(input) {
207
357
  const { sourceCode, moduleResolutions = {} } = input;
208
- const { createRequire: createRequire2 } = await import('module');
209
- const require_ = createRequire2(import.meta.url);
358
+ const { createRequire: createRequire3 } = await import('module');
359
+ const require_ = createRequire3(import.meta.url);
210
360
  const sandboxRequire = (id) => {
211
361
  if (id in moduleResolutions) return moduleResolutions[id];
212
362
  if (id === "react/jsx-runtime" || id === "react/jsx-dev-runtime") {
@@ -524,6 +674,14 @@ function parentLink(node) {
524
674
 
525
675
  // src/harness/check/runtime-render/render-check.ts
526
676
  async function runRenderCheck(input) {
677
+ const g = hostGlobals();
678
+ if ("window" in g && "document" in g) {
679
+ return runRenderCheckInProcess(input);
680
+ }
681
+ const { runRenderCheckViaWorker: runRenderCheckViaWorker2 } = await Promise.resolve().then(() => (init_render_check_host(), render_check_host_exports));
682
+ return runRenderCheckViaWorker2(input);
683
+ }
684
+ async function runRenderCheckInProcess(input) {
527
685
  const t0 = Date.now();
528
686
  const issues = [];
529
687
  const teardown = await setupHappyDom();