@ggui-ai/blueprint-probe 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +54 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +232 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Loqu, Inc. (Guuey)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @ggui-ai/blueprint-probe
|
|
2
|
+
|
|
3
|
+
> Dev / CI runtime probe for ggui blueprint manifests.
|
|
4
|
+
|
|
5
|
+
A development and continuous-integration tool that catches blueprints
|
|
6
|
+
which throw on initial render — hook misuse, destructuring of `undefined`,
|
|
7
|
+
missing prop coercions — at publish/CI time instead of at iframe-load
|
|
8
|
+
time.
|
|
9
|
+
|
|
10
|
+
The static gates in `@ggui-ai/registry-core`'s `checkConformance()` catch
|
|
11
|
+
syntax errors and shape mismatches. This probe goes one step further: it
|
|
12
|
+
actually compiles the blueprint, calls its default export through React's
|
|
13
|
+
server renderer (`renderToString`), and reports a failure if the first
|
|
14
|
+
render throws.
|
|
15
|
+
|
|
16
|
+
## Not a production runtime dependency
|
|
17
|
+
|
|
18
|
+
This package **executes blueprint code** via Node's `vm` module. `vm` is
|
|
19
|
+
not a security boundary — a malicious blueprint can climb the prototype
|
|
20
|
+
chain to host globals. Treat `blueprint-probe` as a dev / CI tool:
|
|
21
|
+
|
|
22
|
+
- Use it in CI, local publish flows, and authoring tooling.
|
|
23
|
+
- Do **not** wire it into a production path that handles untrusted
|
|
24
|
+
blueprints without an additional isolation layer (a separate process
|
|
25
|
+
with no secrets in its environment, or a true V8 isolate such as
|
|
26
|
+
`isolated-vm`).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { blueprintProbeRunner } from "@ggui-ai/blueprint-probe";
|
|
32
|
+
|
|
33
|
+
const result = await blueprintProbeRunner.probe(blueprintManifest);
|
|
34
|
+
if (!result.ok) {
|
|
35
|
+
console.error(result.errors);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`blueprintProbeRunner` implements the `BlueprintProbeRunner` interface
|
|
40
|
+
from `@ggui-ai/registry-core`. Wire it into the publish flow as the
|
|
41
|
+
optional `blueprintProbe` deps slot so static gates always run while the
|
|
42
|
+
runtime probe stays opt-in (it pulls `react-dom` into the import graph).
|
|
43
|
+
|
|
44
|
+
## Caveats
|
|
45
|
+
|
|
46
|
+
This is a **best-effort smoke check**, not a guarantee:
|
|
47
|
+
|
|
48
|
+
- `renderToString` is server-side — there is no `window`/`document`, and
|
|
49
|
+
`useEffect` does not fire. Blueprints that synchronously touch
|
|
50
|
+
`document.*`/`window.*` during render may false-positive (probe fails,
|
|
51
|
+
iframe would render fine). Blueprints that surface a runtime error only
|
|
52
|
+
inside `useEffect` may false-negative.
|
|
53
|
+
- Treat probe success as "no obvious render-time crash" — not "guaranteed
|
|
54
|
+
to work in the iframe runtime".
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BlueprintProbeRunner } from '@ggui-ai/registry-core';
|
|
2
|
+
/**
|
|
3
|
+
* Server-side blueprint runtime probe — a dev / CI tool. Wire it into
|
|
4
|
+
* the publish flow as the opt-in `PublishArtifactDeps.blueprintProbe`
|
|
5
|
+
* deps slot so the static gates always run while the runtime probe
|
|
6
|
+
* stays opt-in (avoids forcing react-dom into every conformance HTTP
|
|
7
|
+
* caller). It executes blueprint code via `vm`, so do not place it on
|
|
8
|
+
* a production path handling untrusted blueprints without a separate
|
|
9
|
+
* isolation layer — see the file-level security caveat.
|
|
10
|
+
*/
|
|
11
|
+
export declare const blueprintProbeRunner: BlueprintProbeRunner;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4DA,OAAO,KAAK,EACV,oBAAoB,EAErB,MAAM,wBAAwB,CAAC;AAsBhC;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,oBAuClC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ggui-ai/blueprint-probe` — server-side runtime probe for blueprint
|
|
3
|
+
* manifests.
|
|
4
|
+
*
|
|
5
|
+
* Implements {@link BlueprintProbeRunner} from `@ggui-ai/registry-core`.
|
|
6
|
+
* The static gates in `checkConformance()` catch syntax errors, missing
|
|
7
|
+
* exports, and obvious shape mismatches; this probe goes one step
|
|
8
|
+
* further by actually CALLING the blueprint's default export through
|
|
9
|
+
* React's server renderer to catch:
|
|
10
|
+
*
|
|
11
|
+
* - destructuring of `undefined` (e.g. `const { foo } = props` where
|
|
12
|
+
* fixtureProps omits `foo`)
|
|
13
|
+
* - hook-call-order violations
|
|
14
|
+
* - thrown errors during the first render
|
|
15
|
+
* - missing prop coercions (e.g. calling `.toFixed()` on a string)
|
|
16
|
+
*
|
|
17
|
+
* Implementation: compile TSX → CJS via esbuild, run inside Node's
|
|
18
|
+
* `vm` module with a `require` shim that resolves the always-allowed
|
|
19
|
+
* blueprint imports (react, react/jsx-runtime) to the real impls and
|
|
20
|
+
* stubs `@ggui-ai/gadgets` with a no-op Proxy. The default export is
|
|
21
|
+
* then rendered via {@link renderToString} with the manifest's
|
|
22
|
+
* `fixtureProps` (or `{}` if absent).
|
|
23
|
+
*
|
|
24
|
+
* Why not happy-dom: the probe doesn't need a window/document —
|
|
25
|
+
* `renderToString` is server-side. Skipping happy-dom keeps the
|
|
26
|
+
* dependency footprint smaller (~6 MB delta) and avoids the
|
|
27
|
+
* "happy-dom diverges from real iframe env" risk class.
|
|
28
|
+
*
|
|
29
|
+
* Why CJS not ESM: Node's `vm.runInContext` runs synchronous code in
|
|
30
|
+
* a context; ESM requires `vm.Module` which is unstable. CJS keeps
|
|
31
|
+
* the surface small.
|
|
32
|
+
*
|
|
33
|
+
* SSR / CSR caveat — this is a best-effort smoke check.
|
|
34
|
+
* `renderToString` is server-side: there is no `window`,
|
|
35
|
+
* no `document`, and `useEffect` does NOT fire. Blueprints that
|
|
36
|
+
* synchronously read `document.*` or `window.*` during render (or rely
|
|
37
|
+
* on layout effects to bail out of a render path) will false-positive
|
|
38
|
+
* here — the probe will report `probe_failed` even though the live
|
|
39
|
+
* iframe runtime would render them fine. Inverse: a blueprint that
|
|
40
|
+
* relies on `useEffect` to surface a runtime error will false-NEGATIVE
|
|
41
|
+
* (probe says ok; iframe blows up). Consumers should treat probe
|
|
42
|
+
* success as "no obvious render-time crash" — not "guaranteed to work
|
|
43
|
+
* in the iframe runtime".
|
|
44
|
+
*
|
|
45
|
+
* Security caveat — `vm.runInContext` is NOT a security boundary.
|
|
46
|
+
* A malicious blueprint that imports `react`
|
|
47
|
+
* (always-allowed) can climb the prototype chain to the host's
|
|
48
|
+
* `Function` constructor and read `process.env`. This probe is a
|
|
49
|
+
* smoke check, not a sandbox; do not wire it into a path that handles
|
|
50
|
+
* untrusted blueprints without first running it in a separate
|
|
51
|
+
* isolation layer (separate Lambda with no secrets in env, or
|
|
52
|
+
* `isolated-vm` for a real V8 isolate).
|
|
53
|
+
*/
|
|
54
|
+
import { createRequire } from 'node:module';
|
|
55
|
+
import * as vm from 'node:vm';
|
|
56
|
+
import { transformSync } from 'esbuild';
|
|
57
|
+
import * as React from 'react';
|
|
58
|
+
/**
|
|
59
|
+
* Timeout bound for `vm.runInContext`. An unbounded probe can hang
|
|
60
|
+
* the host on a `while(true){}` blueprint until the HTTP gateway's
|
|
61
|
+
* 30s ceiling fires — denying publish throughput. The timeout is
|
|
62
|
+
* comfortably above any legitimate blueprint render but far enough
|
|
63
|
+
* below the transport ceiling that the probe failure is the one
|
|
64
|
+
* observed.
|
|
65
|
+
*
|
|
66
|
+
* NOTE: `vm.runInContext` only times out synchronous CJS evaluation.
|
|
67
|
+
* `renderToString` runs OUTSIDE the vm context and is also
|
|
68
|
+
* synchronous + CPU-bound — a blueprint that puts a setState-in-
|
|
69
|
+
* render loop into its component body can still hang React's
|
|
70
|
+
* server renderer. There's no synchronous way to bound that without
|
|
71
|
+
* a worker thread; the HTTP gateway's 30s transport ceiling is the
|
|
72
|
+
* fallback bound for that case.
|
|
73
|
+
*/
|
|
74
|
+
const PROBE_VM_TIMEOUT_MS = 5000;
|
|
75
|
+
/**
|
|
76
|
+
* Server-side blueprint runtime probe — a dev / CI tool. Wire it into
|
|
77
|
+
* the publish flow as the opt-in `PublishArtifactDeps.blueprintProbe`
|
|
78
|
+
* deps slot so the static gates always run while the runtime probe
|
|
79
|
+
* stays opt-in (avoids forcing react-dom into every conformance HTTP
|
|
80
|
+
* caller). It executes blueprint code via `vm`, so do not place it on
|
|
81
|
+
* a production path handling untrusted blueprints without a separate
|
|
82
|
+
* isolation layer — see the file-level security caveat.
|
|
83
|
+
*/
|
|
84
|
+
export const blueprintProbeRunner = {
|
|
85
|
+
async probe(manifest) {
|
|
86
|
+
try {
|
|
87
|
+
const compiled = compileToCjs(manifest.source);
|
|
88
|
+
const moduleDefault = evaluateModule(compiled);
|
|
89
|
+
if (typeof moduleDefault !== 'function') {
|
|
90
|
+
return probeFailed(`blueprint default export is not a function/component (got ${describeType(moduleDefault)})`);
|
|
91
|
+
}
|
|
92
|
+
const Component = moduleDefault;
|
|
93
|
+
const props = manifest.fixtureProps !== undefined &&
|
|
94
|
+
manifest.fixtureProps !== null &&
|
|
95
|
+
typeof manifest.fixtureProps === 'object' &&
|
|
96
|
+
!Array.isArray(manifest.fixtureProps)
|
|
97
|
+
? manifest.fixtureProps
|
|
98
|
+
: {};
|
|
99
|
+
// `react-dom/server` is loaded via dynamic import so the module
|
|
100
|
+
// graph here doesn't drag the server-side renderer into every
|
|
101
|
+
// consumer that just imports `BlueprintProbeRunner` for the
|
|
102
|
+
// type. The import is awaited once per probe.
|
|
103
|
+
const { renderToString } = await import('react-dom/server');
|
|
104
|
+
renderToString(React.createElement(Component, props));
|
|
105
|
+
return { ok: true, errors: [] };
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
109
|
+
// Server-side absolute paths in error text would leak deployment
|
|
110
|
+
// topology to anyone publishing a broken blueprint. Scrub paths
|
|
111
|
+
// and drop the stack entirely — the publisher can't act on a
|
|
112
|
+
// stack from the probe's vm context.
|
|
113
|
+
const scrubbedMessage = scrubServerPaths(message);
|
|
114
|
+
return probeFailed(`runtime probe threw: ${scrubbedMessage}`, {
|
|
115
|
+
message: scrubbedMessage,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
function compileToCjs(source) {
|
|
121
|
+
// `jsx: 'automatic'` emits `require('react/jsx-runtime')` calls so
|
|
122
|
+
// the probe doesn't need a `React` global in scope. `format: 'cjs'`
|
|
123
|
+
// keeps the eval-via-vm surface small.
|
|
124
|
+
const { code } = transformSync(source, {
|
|
125
|
+
loader: 'tsx',
|
|
126
|
+
format: 'cjs',
|
|
127
|
+
target: 'es2020',
|
|
128
|
+
jsx: 'automatic',
|
|
129
|
+
sourcemap: false,
|
|
130
|
+
});
|
|
131
|
+
return code;
|
|
132
|
+
}
|
|
133
|
+
function evaluateModule(code) {
|
|
134
|
+
const moduleObj = { exports: {} };
|
|
135
|
+
// `createRequire` against this file resolves react / react-dom /
|
|
136
|
+
// react/jsx-runtime through the package's own node_modules graph —
|
|
137
|
+
// the same React instance the probe later calls `renderToString`
|
|
138
|
+
// on. Without a shared instance, hooks throw the "more than one
|
|
139
|
+
// copy of React" runtime check.
|
|
140
|
+
const realRequire = createRequire(import.meta.url);
|
|
141
|
+
const requireShim = (specifier) => {
|
|
142
|
+
if (specifier === '@ggui-ai/gadgets') {
|
|
143
|
+
return gadgetsStub;
|
|
144
|
+
}
|
|
145
|
+
// Only react surfaces are routed through — anything else got
|
|
146
|
+
// through the gate-7 import allow-list already, so we don't
|
|
147
|
+
// expect other specifiers here. Surface as a probe failure so
|
|
148
|
+
// misconfigured blueprints fail loud.
|
|
149
|
+
if (specifier === 'react' ||
|
|
150
|
+
specifier === 'react-dom' ||
|
|
151
|
+
specifier === 'react/jsx-runtime' ||
|
|
152
|
+
specifier === 'react-dom/server') {
|
|
153
|
+
return realRequire(specifier);
|
|
154
|
+
}
|
|
155
|
+
throw new Error(`probe require-shim does not resolve \`${specifier}\` — only the always-allowed blueprint imports are routed through.`);
|
|
156
|
+
};
|
|
157
|
+
const context = vm.createContext({
|
|
158
|
+
module: moduleObj,
|
|
159
|
+
exports: moduleObj.exports,
|
|
160
|
+
require: requireShim,
|
|
161
|
+
// `console` lets blueprints log without crashing the probe.
|
|
162
|
+
console,
|
|
163
|
+
});
|
|
164
|
+
// Bound synchronous evaluation. Without `timeout`, a
|
|
165
|
+
// `while(true){}` blueprint hangs the host. Node surfaces the
|
|
166
|
+
// bound as a thrown Error; the outer catch maps it to
|
|
167
|
+
// `blueprint_runtime_probe_failed` with a clear message.
|
|
168
|
+
vm.runInContext(code, context, {
|
|
169
|
+
filename: 'blueprint.cjs.js',
|
|
170
|
+
timeout: PROBE_VM_TIMEOUT_MS,
|
|
171
|
+
});
|
|
172
|
+
return moduleObj.exports.default;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Stub for `@ggui-ai/gadgets`. Every hook returns `undefined` (or
|
|
176
|
+
* `[undefined, () => undefined]` for setState-shaped tuples). The
|
|
177
|
+
* Proxy responds to any property access with a no-op function so
|
|
178
|
+
* blueprints that call hooks the probe doesn't pre-stub still get a
|
|
179
|
+
* survivable answer.
|
|
180
|
+
*/
|
|
181
|
+
const noopHook = () => undefined;
|
|
182
|
+
// The stub mimics what `require('@ggui-ai/gadgets')` would return —
|
|
183
|
+
// a CJS module namespace whose shape is unknown by design (the probe
|
|
184
|
+
// doesn't ship a gadget registry). `Record<string, unknown>` is the
|
|
185
|
+
// honest type; the `as Record<string, unknown>` on the Proxy target
|
|
186
|
+
// is the lone shape-unknown cast in this file (the stub is the
|
|
187
|
+
// shape-unknown construct, not data with a known type).
|
|
188
|
+
const gadgetsStub = new Proxy({}, {
|
|
189
|
+
get(_, prop) {
|
|
190
|
+
if (prop === '__esModule')
|
|
191
|
+
return true;
|
|
192
|
+
if (typeof prop === 'symbol')
|
|
193
|
+
return undefined;
|
|
194
|
+
return noopHook;
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
function probeFailed(message, detail) {
|
|
198
|
+
return {
|
|
199
|
+
ok: false,
|
|
200
|
+
errors: [
|
|
201
|
+
{
|
|
202
|
+
code: 'blueprint_runtime_probe_failed',
|
|
203
|
+
message,
|
|
204
|
+
...(detail !== undefined ? { detail } : {}),
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function describeType(v) {
|
|
210
|
+
if (v === null)
|
|
211
|
+
return 'null';
|
|
212
|
+
if (Array.isArray(v))
|
|
213
|
+
return 'array';
|
|
214
|
+
return typeof v;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Strip absolute filesystem paths from probe error messages.
|
|
218
|
+
* Lambda's `/var/task/...` and the dev host's `/home/node/...`
|
|
219
|
+
* paths leak through esbuild diagnostics + thrown Error messages;
|
|
220
|
+
* the publisher can't act on them and they reveal deployment
|
|
221
|
+
* topology.
|
|
222
|
+
*
|
|
223
|
+
* The regex matches any `/`-prefixed run up to a `packages/`, `cloud/`,
|
|
224
|
+
* or `node_modules/` segment and keeps the tail from that segment on —
|
|
225
|
+
* so `/var/task/node_modules/react/index.js` becomes
|
|
226
|
+
* `node_modules/react/index.js`. Anything that doesn't match a
|
|
227
|
+
* recognised segment is left as-is; we'd rather over-keep than
|
|
228
|
+
* accidentally strip a user-meaningful identifier.
|
|
229
|
+
*/
|
|
230
|
+
function scrubServerPaths(input) {
|
|
231
|
+
return input.replace(/\/[^\s)]+\/(packages|cloud|node_modules)\b/g, '$1');
|
|
232
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ggui-ai/blueprint-probe",
|
|
3
|
+
"version": "0.1.0-rc.1",
|
|
4
|
+
"description": "Dev/CI runtime probe for ggui blueprint manifests. Implements BlueprintProbeRunner from @ggui-ai/registry-core using Node's vm module + React's renderToString. Catches blueprints that throw on initial render (hook misuse, destructuring errors, missing props) in CI instead of at iframe-load time.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ggui",
|
|
8
|
+
"blueprint",
|
|
9
|
+
"registry",
|
|
10
|
+
"conformance",
|
|
11
|
+
"ci",
|
|
12
|
+
"react"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/ggui-ai/ggui/tree/main/packages/blueprint-probe",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ggui-ai/ggui/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/ggui-ai/ggui.git",
|
|
21
|
+
"directory": "packages/blueprint-probe"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"esbuild": "^0.25.0",
|
|
43
|
+
"react": "^19.0.0",
|
|
44
|
+
"react-dom": "^19.0.0",
|
|
45
|
+
"@ggui-ai/artifact-manifest": "0.1.0-rc.1",
|
|
46
|
+
"@ggui-ai/registry-core": "0.1.0-rc.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^24.0.0",
|
|
50
|
+
"@types/react": "^19.0.0",
|
|
51
|
+
"@types/react-dom": "^19.0.0",
|
|
52
|
+
"typescript": "^5.0.0",
|
|
53
|
+
"vitest": "^3.0.0"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=20.0.0"
|
|
57
|
+
},
|
|
58
|
+
"author": "ggui contributors <hello@ggui.ai>",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -p tsconfig.build.json",
|
|
61
|
+
"dev": "tsc --watch",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest",
|
|
65
|
+
"clean": "rm -rf dist"
|
|
66
|
+
}
|
|
67
|
+
}
|