@ggui-ai/ui-gen 0.28.0 → 0.29.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.
- package/dist/{adapter-h4_V69LI.d.ts → adapter-DLQ-5COm.d.ts} +1 -1
- package/dist/adapters/base.js +2 -27
- package/dist/adapters/base.js.map +1 -1
- package/dist/adapters/generation-dispatch.d.ts +14 -6
- package/dist/adapters/generation-dispatch.js +40 -19260
- package/dist/adapters/generation-dispatch.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +25 -3561
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/types.js +2 -9
- package/dist/adapters/types.js.map +1 -1
- package/dist/advanced/index.d.ts +13 -12
- package/dist/advanced/index.js +63 -21954
- package/dist/advanced/index.js.map +1 -1
- package/dist/{bank-Ctdp3FUA.d.ts → bank-LWaiAtaA.d.ts} +1 -1
- package/dist/blueprint-validator.js +6 -2301
- package/dist/blueprint-validator.js.map +1 -1
- package/dist/boilerplate.d.ts +3 -2
- package/dist/boilerplate.js +6 -1867
- package/dist/boilerplate.js.map +1 -1
- package/dist/check/index.d.ts +3 -2
- package/dist/check/index.js +6 -1923
- package/dist/check/index.js.map +1 -1
- package/dist/chunk-33B3BAWS.js +24 -0
- package/dist/chunk-33B3BAWS.js.map +1 -0
- package/dist/chunk-3HSGA6NI.js +591 -0
- package/dist/chunk-3HSGA6NI.js.map +1 -0
- package/dist/chunk-3NNNGNTO.js +1707 -0
- package/dist/chunk-3NNNGNTO.js.map +1 -0
- package/dist/chunk-3T2HMTON.js +79 -0
- package/dist/chunk-3T2HMTON.js.map +1 -0
- package/dist/chunk-3ZSSDV3L.js +123 -0
- package/dist/chunk-3ZSSDV3L.js.map +1 -0
- package/dist/chunk-4MBR5GA3.js +99 -0
- package/dist/chunk-4MBR5GA3.js.map +1 -0
- package/dist/chunk-56NJFD55.js +337 -0
- package/dist/chunk-56NJFD55.js.map +1 -0
- package/dist/chunk-5AGTY555.js +26 -0
- package/dist/chunk-5AGTY555.js.map +1 -0
- package/dist/chunk-5EJM7EGY.js +115 -0
- package/dist/chunk-5EJM7EGY.js.map +1 -0
- package/dist/chunk-5KXCQLLR.js +529 -0
- package/dist/chunk-5KXCQLLR.js.map +1 -0
- package/dist/chunk-5VBXHVEH.js +171 -0
- package/dist/chunk-5VBXHVEH.js.map +1 -0
- package/dist/chunk-6KDDEING.js +515 -0
- package/dist/chunk-6KDDEING.js.map +1 -0
- package/dist/chunk-6VDRWAP6.js +123 -0
- package/dist/chunk-6VDRWAP6.js.map +1 -0
- package/dist/chunk-732IBFEJ.js +2400 -0
- package/dist/chunk-732IBFEJ.js.map +1 -0
- package/dist/chunk-73AURS3I.js +46 -0
- package/dist/chunk-73AURS3I.js.map +1 -0
- package/dist/chunk-77H5SKLX.js +8 -0
- package/dist/chunk-77H5SKLX.js.map +1 -0
- package/dist/chunk-7QE3AHLE.js +35 -0
- package/dist/chunk-7QE3AHLE.js.map +1 -0
- package/dist/chunk-A375NNWN.js +11 -0
- package/dist/chunk-A375NNWN.js.map +1 -0
- package/dist/chunk-AOU33EFS.js +140 -0
- package/dist/chunk-AOU33EFS.js.map +1 -0
- package/dist/chunk-BA4QYA6E.js +461 -0
- package/dist/chunk-BA4QYA6E.js.map +1 -0
- package/dist/chunk-DBP764GL.js +3 -0
- package/dist/chunk-DBP764GL.js.map +1 -0
- package/dist/chunk-DUU3ZJDQ.js +41 -0
- package/dist/chunk-DUU3ZJDQ.js.map +1 -0
- package/dist/chunk-DXKRBXNU.js +30 -0
- package/dist/chunk-DXKRBXNU.js.map +1 -0
- package/dist/chunk-FB7OEEAH.js +1467 -0
- package/dist/chunk-FB7OEEAH.js.map +1 -0
- package/dist/chunk-FLRNMZV2.js +18 -0
- package/dist/chunk-FLRNMZV2.js.map +1 -0
- package/dist/chunk-FWJIMKFZ.js +2032 -0
- package/dist/chunk-FWJIMKFZ.js.map +1 -0
- package/dist/chunk-FXRHWYIQ.js +163 -0
- package/dist/chunk-FXRHWYIQ.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-GAJI7Y3P.js +13 -0
- package/dist/chunk-GAJI7Y3P.js.map +1 -0
- package/dist/chunk-GYINWMPR.js +2052 -0
- package/dist/chunk-GYINWMPR.js.map +1 -0
- package/dist/chunk-HD6ABIK7.js +484 -0
- package/dist/chunk-HD6ABIK7.js.map +1 -0
- package/dist/chunk-HDQVHYO6.js +100 -0
- package/dist/chunk-HDQVHYO6.js.map +1 -0
- package/dist/chunk-IHUT3SIW.js +7 -0
- package/dist/chunk-IHUT3SIW.js.map +1 -0
- package/dist/chunk-JDH5EGNZ.js +126 -0
- package/dist/chunk-JDH5EGNZ.js.map +1 -0
- package/dist/chunk-JMD4RGSV.js +37 -0
- package/dist/chunk-JMD4RGSV.js.map +1 -0
- package/dist/chunk-KJWGZL5B.js +33 -0
- package/dist/chunk-KJWGZL5B.js.map +1 -0
- package/dist/chunk-MKMDQFZ7.js +86 -0
- package/dist/chunk-MKMDQFZ7.js.map +1 -0
- package/dist/chunk-NF6JUZWF.js +85 -0
- package/dist/chunk-NF6JUZWF.js.map +1 -0
- package/dist/chunk-O2YC6XDC.js +1933 -0
- package/dist/chunk-O2YC6XDC.js.map +1 -0
- package/dist/chunk-OVLH5ICV.js +29 -0
- package/dist/chunk-OVLH5ICV.js.map +1 -0
- package/dist/chunk-PBOYHGSD.js +106 -0
- package/dist/chunk-PBOYHGSD.js.map +1 -0
- package/dist/chunk-PJFH7QWA.js +81 -0
- package/dist/chunk-PJFH7QWA.js.map +1 -0
- package/dist/chunk-PUH4CXGZ.js +284 -0
- package/dist/chunk-PUH4CXGZ.js.map +1 -0
- package/dist/chunk-QLXXPGTV.js +18 -0
- package/dist/chunk-QLXXPGTV.js.map +1 -0
- package/dist/chunk-R5GIGPW2.js +2845 -0
- package/dist/chunk-R5GIGPW2.js.map +1 -0
- package/dist/chunk-RH4IUSTO.js +83 -0
- package/dist/chunk-RH4IUSTO.js.map +1 -0
- package/dist/chunk-S2GVXKKY.js +153 -0
- package/dist/chunk-S2GVXKKY.js.map +1 -0
- package/dist/chunk-TVHGKFJS.js +58 -0
- package/dist/chunk-TVHGKFJS.js.map +1 -0
- package/dist/chunk-U7GALWLG.js +66 -0
- package/dist/chunk-U7GALWLG.js.map +1 -0
- package/dist/chunk-VTC263LT.js +256 -0
- package/dist/chunk-VTC263LT.js.map +1 -0
- package/dist/chunk-WEOXFEVE.js +739 -0
- package/dist/chunk-WEOXFEVE.js.map +1 -0
- package/dist/chunk-WYHP46LT.js +28 -0
- package/dist/chunk-WYHP46LT.js.map +1 -0
- package/dist/chunk-XGLO5LGG.js +274 -0
- package/dist/chunk-XGLO5LGG.js.map +1 -0
- package/dist/chunk-XRBCRKA2.js +29 -0
- package/dist/chunk-XRBCRKA2.js.map +1 -0
- package/dist/chunk-XW7ADFFV.js +340 -0
- package/dist/chunk-XW7ADFFV.js.map +1 -0
- package/dist/chunk-YIQ42IUX.js +34 -0
- package/dist/chunk-YIQ42IUX.js.map +1 -0
- package/dist/chunk-YJZTUY7B.js +101 -0
- package/dist/chunk-YJZTUY7B.js.map +1 -0
- package/dist/chunk-Z3CXME3K.js +107 -0
- package/dist/chunk-Z3CXME3K.js.map +1 -0
- package/dist/classifier/index.js +2 -527
- package/dist/classifier/index.js.map +1 -1
- package/dist/client-JBPCXU7W.js +4 -0
- package/dist/client-JBPCXU7W.js.map +1 -0
- package/dist/compose.js +3 -367
- package/dist/compose.js.map +1 -1
- package/dist/cost-tracker-HHGQ4FTW.js +67 -0
- package/dist/cost-tracker-HHGQ4FTW.js.map +1 -0
- package/dist/{create-ui-generator-BrZHF0cf.d.ts → create-ui-generator-BY-WeaPi.d.ts} +3 -3
- package/dist/{design-mode-DGWN_Gkm.d.ts → design-mode-XyOQmzE0.d.ts} +4 -3
- package/dist/{dispatch-B07TI30d.d.ts → dispatch-8LzTddKw.d.ts} +3 -2
- package/dist/dist-UALN6ZVB.js +543 -0
- package/dist/dist-UALN6ZVB.js.map +1 -0
- package/dist/dupe-break-X6K7QFIS.js +4 -0
- package/dist/dupe-break-X6K7QFIS.js.map +1 -0
- package/dist/evaluation/axis-checks/index.d.ts +5 -4
- package/dist/evaluation/axis-checks/index.js +6 -1914
- package/dist/evaluation/axis-checks/index.js.map +1 -1
- package/dist/evaluation/axis-checks/registry.d.ts +3 -2
- package/dist/evaluation/axis-checks/registry.js +3 -1844
- package/dist/evaluation/axis-checks/registry.js.map +1 -1
- package/dist/evaluation/index.d.ts +49 -132
- package/dist/evaluation/index.js +302 -6466
- package/dist/evaluation/index.js.map +1 -1
- package/dist/evaluation/types.d.ts +3 -2
- package/dist/evaluation/types.js +2 -5
- package/dist/evaluation/types.js.map +1 -1
- package/dist/fragments/index.js +2 -338
- package/dist/fragments/index.js.map +1 -1
- package/dist/{generate-tSO_shQ0.d.ts → generate-DQ4ci90s.d.ts} +1 -1
- package/dist/harness/check/runtime-render/index.d.ts +35 -15
- package/dist/harness/check/runtime-render/index.js +6 -2390
- package/dist/harness/check/runtime-render/index.js.map +1 -1
- package/dist/harness/check/runtime-render/render-check-worker.js +4 -1739
- package/dist/harness/check/runtime-render/render-check-worker.js.map +1 -1
- package/dist/harness/index.d.ts +3 -2
- package/dist/harness/index.js +23 -5126
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/llm-trace-sink.js +2 -24
- package/dist/harness/llm-trace-sink.js.map +1 -1
- package/dist/harness/prompts.d.ts +2 -2
- package/dist/harness/prompts.js +8 -324
- package/dist/harness/prompts.js.map +1 -1
- package/dist/harness/result-types.d.ts +6 -5
- package/dist/harness/result-types.js +2 -0
- package/dist/harness/result-types.js.map +1 -1
- package/dist/harness/runtime.d.ts +22 -5
- package/dist/harness/runtime.js +10 -2313
- package/dist/harness/runtime.js.map +1 -1
- package/dist/harness/types-public.d.ts +3 -2
- package/dist/harness/types-public.js +16 -2954
- package/dist/harness/types-public.js.map +1 -1
- package/dist/harness/validator-trace-sink.d.ts +3 -2
- package/dist/harness/validator-trace-sink.js +2 -26
- package/dist/harness/validator-trace-sink.js.map +1 -1
- package/dist/hash.js +2 -39
- package/dist/hash.js.map +1 -1
- package/dist/hashline-5OKREIRM.js +4 -0
- package/dist/hashline-5OKREIRM.js.map +1 -0
- package/dist/index.d.ts +50 -11
- package/dist/index.js +57 -22015
- package/dist/index.js.map +1 -1
- package/dist/llm-evaluator-PN3WFCS4.js +653 -0
- package/dist/llm-evaluator-PN3WFCS4.js.map +1 -0
- package/dist/magic-string.es-2NZTC4GZ.js +1307 -0
- package/dist/magic-string.es-2NZTC4GZ.js.map +1 -0
- package/dist/patch.d.ts +3 -2
- package/dist/patch.js +2 -56
- package/dist/patch.js.map +1 -1
- package/dist/policy-VCYKGSAC.js +5 -0
- package/dist/policy-VCYKGSAC.js.map +1 -0
- package/dist/policy.js +2 -35
- package/dist/policy.js.map +1 -1
- package/dist/primitive-index-2OF6F4TZ.js +131 -0
- package/dist/primitive-index-2OF6F4TZ.js.map +1 -0
- package/dist/primitive-slice-WTMBLYFJ.js +235 -0
- package/dist/primitive-slice-WTMBLYFJ.js.map +1 -0
- package/dist/{prompts-BhNUuRoZ.d.ts → prompts-CLZGywMP.d.ts} +1 -1
- package/dist/provider-adapter-contract.js +10407 -14204
- package/dist/provider-adapter-contract.js.map +1 -1
- package/dist/provider-adapter.js +2 -44
- package/dist/provider-adapter.js.map +1 -1
- package/dist/providers/index.d.ts +89 -1
- package/dist/providers/index.js +115 -44
- package/dist/providers/index.js.map +1 -1
- package/dist/raw-C6KBH5I3.js +141 -0
- package/dist/raw-C6KBH5I3.js.map +1 -0
- package/dist/raw-FXSBXQTZ.js +7 -0
- package/dist/raw-FXSBXQTZ.js.map +1 -0
- package/dist/raw-MURDUPGK.js +8 -0
- package/dist/raw-MURDUPGK.js.map +1 -0
- package/dist/raw-T3GW3UVX.js +8 -0
- package/dist/raw-T3GW3UVX.js.map +1 -0
- package/dist/render-check-host-ZNIS6BJ5.js +5 -0
- package/dist/render-check-host-ZNIS6BJ5.js.map +1 -0
- package/dist/sdk-4JNSDNSR.js +6 -0
- package/dist/sdk-4JNSDNSR.js.map +1 -0
- package/dist/sdk-DIVJMHCX.js +7 -0
- package/dist/sdk-DIVJMHCX.js.map +1 -0
- package/dist/sdk-QRJOCRTS.js +7 -0
- package/dist/sdk-QRJOCRTS.js.map +1 -0
- package/dist/tag-balance-CTHCTRJ7.js +123 -0
- package/dist/tag-balance-CTHCTRJ7.js.map +1 -0
- package/dist/tools/get-primitives-ts.d.ts +1 -1
- package/dist/tools/get-primitives-ts.js +3 -1
- package/dist/tools/get-primitives-ts.js.map +1 -1
- package/dist/tools/render-check-worker.js +3 -40
- package/dist/tools/render-check-worker.js.map +1 -1
- package/dist/{types-public-h8IMnYuh.d.ts → types-public-hYlrerZh.d.ts} +35 -2
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +3 -498
- package/dist/validation/index.js.map +1 -1
- package/dist/{visual-evaluator-C2strxqD.d.ts → visual-evaluator-KskajxD5.d.ts} +14 -4
- package/dist/visual-evaluator-TGEXYQTP.js +12 -0
- package/dist/visual-evaluator-TGEXYQTP.js.map +1 -0
- package/dist/workflows.d.ts +3 -2
- package/dist/workflows.js +2 -151
- package/dist/workflows.js.map +1 -1
- package/package.json +20 -16
- package/src/adapters/claude/sdk.ts +4 -2
- package/src/adapters/claude/tool-bridge.ts +2 -1
- package/src/adapters/generation-dispatch.ts +9 -0
- package/src/adapters/openai/raw.ts +4 -0
- package/src/adapters/openai/sdk.ts +6 -1
- package/src/adapters/openai/tokens.ts +21 -7
- package/src/adapters/tool-bridge.ts +1 -1
- package/src/adapters/tools.ts +1 -1
- package/src/advanced/feedback.ts +1 -2
- package/src/advanced/generator.ts +4 -3
- package/src/boilerplate/free-design-prompt.ts +7 -0
- package/src/boilerplate/generate.ts +18 -5
- package/src/boilerplate/hard-sections.ts +8 -3
- package/src/boilerplate/react-hooks.ts +56 -0
- package/src/boilerplate/system-prompt.ts +12 -3
- package/src/check/run-tier0.ts +233 -8
- package/src/check/type-checker.ts +128 -16
- package/src/coding-agent/tools.ts +26 -3
- package/src/design-mode.ts +4 -9
- package/src/evaluation/axis-checks/checks/state-merge.ts +2 -4
- package/src/evaluation/axis-checks/checks/state-payload.ts +1 -28
- package/src/evaluation/axis-checks/checks/tint.ts +197 -0
- package/src/evaluation/axis-checks/helpers.ts +121 -0
- package/src/evaluation/axis-checks/registry.ts +2 -0
- package/src/evaluation/criteria/__fixtures__/edge-v2-draw2.json +4629 -0
- package/src/evaluation/criteria/bank.ts +1 -1
- package/src/evaluation/criteria/edge-instruments.ts +14 -0
- package/src/evaluation/criteria/edge-probe-v2.ts +352 -0
- package/src/evaluation/criteria/edge-v2.ts +242 -0
- package/src/evaluation/criteria/resolve.ts +24 -5
- package/src/evaluation/index.ts +3 -5
- package/src/evaluation/mcp-server.ts +0 -50
- package/src/evaluation/types-public.ts +6 -1
- package/src/evaluation/visual-evaluator.ts +161 -30
- package/src/harness/check/runtime-render/index.ts +28 -4
- package/src/harness/check/runtime-render/render-check.ts +20 -21
- package/src/harness/claude-agent-sdk-loader.ts +93 -0
- package/src/harness/claude-code-login-query.ts +1 -1
- package/src/harness/coding/generate-task-runner.ts +1 -0
- package/src/harness/coding/run-coding-turn.ts +3 -0
- package/src/harness/coding/run-eval-round.ts +9 -0
- package/src/harness/llm-router.ts +50 -2
- package/src/harness/runtime.ts +17 -0
- package/src/index.ts +9 -0
- package/src/providers/anthropic-tool-call.ts +263 -0
- package/src/providers/index.ts +13 -0
- package/src/tools/get-primitives-ts.ts +1 -1
- package/src/tools/render-check.ts +4 -4
- package/src/validation/primitives.ts +2 -1
- package/src/evaluation/loop.ts +0 -218
|
@@ -0,0 +1,1467 @@
|
|
|
1
|
+
import { taughtTokenManifest, jsonSchemaTypeToTs, BOILERPLATE_REACT_IMPORT } from './chunk-Z3CXME3K.js';
|
|
2
|
+
import { buildStylingProfileSection, withStylingProfile } from './chunk-NF6JUZWF.js';
|
|
3
|
+
import { buildCodingCriteriaSummary } from './chunk-PUH4CXGZ.js';
|
|
4
|
+
import { DEFAULT_DESIGN_MODE, canvasForRendering, describeCanvas } from './chunk-3T2HMTON.js';
|
|
5
|
+
import { listContractGadgets, HOOK_NAME_RE, resolveAppGadgets } from '@ggui-ai/protocol';
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { dirname, resolve } from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { GGUI_MOUNT_CANVAS_EXPORT } from '@ggui-ai/design/rendering';
|
|
10
|
+
import ts from 'typescript';
|
|
11
|
+
|
|
12
|
+
var __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
var TEMPLATE_DIRS = [
|
|
14
|
+
resolve(__dirname$1, "templates"),
|
|
15
|
+
resolve(__dirname$1, "..", "src", "boilerplate", "templates"),
|
|
16
|
+
resolve(__dirname$1, "..", "..", "src", "boilerplate", "templates"),
|
|
17
|
+
resolve(__dirname$1, "..", "..", "..", "src", "boilerplate", "templates"),
|
|
18
|
+
resolve(__dirname$1, "..", "..", "..", "..", "src", "boilerplate", "templates")
|
|
19
|
+
];
|
|
20
|
+
var BASE_TEMPLATE_FILE = {
|
|
21
|
+
constrained: "base.tsx.tmpl",
|
|
22
|
+
free: "base-free.tsx.tmpl"
|
|
23
|
+
};
|
|
24
|
+
var FREE_LAYOUT = [
|
|
25
|
+
" <div style={{ width: '100%' }}>",
|
|
26
|
+
" {/* implement your UI here */}",
|
|
27
|
+
" </div>"
|
|
28
|
+
].join("\n");
|
|
29
|
+
var baseCache = /* @__PURE__ */ new Map();
|
|
30
|
+
var layoutCache = /* @__PURE__ */ new Map();
|
|
31
|
+
function loadBase(designMode) {
|
|
32
|
+
const cached = baseCache.get(designMode);
|
|
33
|
+
if (cached !== void 0) return cached;
|
|
34
|
+
const file = BASE_TEMPLATE_FILE[designMode];
|
|
35
|
+
for (const dir of TEMPLATE_DIRS) {
|
|
36
|
+
try {
|
|
37
|
+
const content = readFileSync(resolve(dir, file), "utf-8");
|
|
38
|
+
baseCache.set(designMode, content);
|
|
39
|
+
return content;
|
|
40
|
+
} catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`No ${file} found`);
|
|
45
|
+
}
|
|
46
|
+
function loadLayout(shellType, screen) {
|
|
47
|
+
const key = `${shellType}-${screen}`;
|
|
48
|
+
if (layoutCache.has(key)) return layoutCache.get(key);
|
|
49
|
+
const candidates = [
|
|
50
|
+
`${shellType}-${screen}.tsx.tmpl`,
|
|
51
|
+
`${shellType}-universal.tsx.tmpl`,
|
|
52
|
+
`fullscreen-universal.tsx.tmpl`
|
|
53
|
+
// final fallback
|
|
54
|
+
];
|
|
55
|
+
for (const filename of candidates) {
|
|
56
|
+
for (const dir of TEMPLATE_DIRS) {
|
|
57
|
+
try {
|
|
58
|
+
const content = readFileSync(resolve(dir, "layouts", filename), "utf-8");
|
|
59
|
+
layoutCache.set(key, content);
|
|
60
|
+
return content;
|
|
61
|
+
} catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`No layout found for ${key}`);
|
|
67
|
+
}
|
|
68
|
+
function renderBoilerplate(shellType, screen, markers, designMode = DEFAULT_DESIGN_MODE) {
|
|
69
|
+
let template = loadBase(designMode);
|
|
70
|
+
const layout = designMode === "free" ? FREE_LAYOUT : loadLayout(shellType, screen);
|
|
71
|
+
template = template.replace("{{LAYOUT}}", layout);
|
|
72
|
+
for (const [key, value] of Object.entries(markers)) {
|
|
73
|
+
template = template.replaceAll(`{{${key}}}`, value);
|
|
74
|
+
}
|
|
75
|
+
return template;
|
|
76
|
+
}
|
|
77
|
+
var ALL_PRIMITIVES = [
|
|
78
|
+
"Container",
|
|
79
|
+
"Card",
|
|
80
|
+
"Stack",
|
|
81
|
+
"Row",
|
|
82
|
+
"Grid",
|
|
83
|
+
"Box",
|
|
84
|
+
"Divider",
|
|
85
|
+
"Spacer",
|
|
86
|
+
"Text",
|
|
87
|
+
"Heading",
|
|
88
|
+
"Button",
|
|
89
|
+
"Input",
|
|
90
|
+
"TextArea",
|
|
91
|
+
"Select",
|
|
92
|
+
"Checkbox",
|
|
93
|
+
"Toggle",
|
|
94
|
+
"RadioGroup",
|
|
95
|
+
"Slider",
|
|
96
|
+
"Badge",
|
|
97
|
+
"Spinner",
|
|
98
|
+
"Skeleton",
|
|
99
|
+
"Avatar",
|
|
100
|
+
"Alert",
|
|
101
|
+
"Progress",
|
|
102
|
+
"Image",
|
|
103
|
+
"Icon",
|
|
104
|
+
"Link",
|
|
105
|
+
"Tooltip",
|
|
106
|
+
"Table",
|
|
107
|
+
"Tabs",
|
|
108
|
+
"Toast",
|
|
109
|
+
"Accordion",
|
|
110
|
+
"MotionKeyframes",
|
|
111
|
+
"useMotion",
|
|
112
|
+
"useAnimationKey"
|
|
113
|
+
].join(", ");
|
|
114
|
+
var ALL_COMPONENTS = [
|
|
115
|
+
"SearchField",
|
|
116
|
+
"FormField",
|
|
117
|
+
"MenuItem",
|
|
118
|
+
"Tag",
|
|
119
|
+
"Dropdown",
|
|
120
|
+
"Autocomplete",
|
|
121
|
+
"Breadcrumb",
|
|
122
|
+
"Pagination",
|
|
123
|
+
"EmptyState",
|
|
124
|
+
"Stat",
|
|
125
|
+
"Stepper",
|
|
126
|
+
"Markdown",
|
|
127
|
+
"MarkdownInline"
|
|
128
|
+
].join(", ");
|
|
129
|
+
var ALL_COMPOSITIONS = [
|
|
130
|
+
"Header",
|
|
131
|
+
"Sidebar",
|
|
132
|
+
"CardGrid",
|
|
133
|
+
"CommentThread",
|
|
134
|
+
"DataTable",
|
|
135
|
+
"ChatWindow",
|
|
136
|
+
"NavigationBar",
|
|
137
|
+
"FileUploader",
|
|
138
|
+
"NotificationCenter",
|
|
139
|
+
"Modal",
|
|
140
|
+
"CommandPalette",
|
|
141
|
+
"Footer",
|
|
142
|
+
"Hero"
|
|
143
|
+
].join(", ");
|
|
144
|
+
var ALL_INTERACT = ["Clickable", "Hoverable", "Pressable"].join(", ");
|
|
145
|
+
var ALL_DESIGN = [
|
|
146
|
+
ALL_PRIMITIVES,
|
|
147
|
+
ALL_COMPONENTS,
|
|
148
|
+
ALL_COMPOSITIONS,
|
|
149
|
+
ALL_INTERACT
|
|
150
|
+
].join(", ");
|
|
151
|
+
function inferTypeFromExample(example) {
|
|
152
|
+
const fields = [];
|
|
153
|
+
for (const [k, v] of Object.entries(example)) {
|
|
154
|
+
let t;
|
|
155
|
+
if (v === null || v === void 0) t = "unknown";
|
|
156
|
+
else if (typeof v === "string") t = "string";
|
|
157
|
+
else if (typeof v === "number") t = "number";
|
|
158
|
+
else if (typeof v === "boolean") t = "boolean";
|
|
159
|
+
else if (Array.isArray(v)) {
|
|
160
|
+
if (v.length === 0) t = "unknown[]";
|
|
161
|
+
else if (typeof v[0] === "string") t = "string[]";
|
|
162
|
+
else if (typeof v[0] === "number") t = "number[]";
|
|
163
|
+
else if (typeof v[0] === "object" && v[0] !== null)
|
|
164
|
+
t = `Array<${inferTypeFromExample(v[0])}>`;
|
|
165
|
+
else t = "unknown[]";
|
|
166
|
+
} else if (typeof v === "object") {
|
|
167
|
+
t = inferTypeFromExample(v);
|
|
168
|
+
} else {
|
|
169
|
+
t = "unknown";
|
|
170
|
+
}
|
|
171
|
+
fields.push(`${k}: ${t}`);
|
|
172
|
+
}
|
|
173
|
+
return `{ ${fields.join("; ")} }`;
|
|
174
|
+
}
|
|
175
|
+
function generateBoilerplate(_userPrompt, contract, shellType, screen, composedSections, appGadgets, designMode = DEFAULT_DESIGN_MODE) {
|
|
176
|
+
const propsFields = [];
|
|
177
|
+
const propsProperties = contract?.propsSpec?.properties ?? {};
|
|
178
|
+
for (const [key, entry] of Object.entries(propsProperties)) {
|
|
179
|
+
const required = entry.required === true;
|
|
180
|
+
const nullable = entry.schema.nullable === true;
|
|
181
|
+
const tsType = jsonSchemaTypeToTs(entry.schema);
|
|
182
|
+
const fullType = nullable ? `${tsType} | null` : tsType;
|
|
183
|
+
const parts = [];
|
|
184
|
+
if (entry.description) parts.push(entry.description);
|
|
185
|
+
if (entry.default !== void 0) parts.push(`(default: ${JSON.stringify(entry.default)})`);
|
|
186
|
+
if (!required) parts.push("(optional \u2014 the agent may omit it; guard or fall back)");
|
|
187
|
+
const desc = parts.length > 0 ? ` // ${parts.join(" ")}` : "";
|
|
188
|
+
propsFields.push(` ${key}${required ? "" : "?"}: ${fullType};${desc}`);
|
|
189
|
+
}
|
|
190
|
+
const actionTypeAliases = [];
|
|
191
|
+
const actionHookCalls = [];
|
|
192
|
+
let hasOneShotAction = false;
|
|
193
|
+
const actionsMap = contract?.actionSpec ?? {};
|
|
194
|
+
for (const [key, entry] of Object.entries(actionsMap)) {
|
|
195
|
+
const label = entry.label ?? key;
|
|
196
|
+
const desc = entry.description ?? "";
|
|
197
|
+
const tool = entry.nextStep ?? "";
|
|
198
|
+
const typeName = `Action${key.charAt(0).toUpperCase()}${key.slice(1)}Payload`;
|
|
199
|
+
let tsType = "void";
|
|
200
|
+
if (entry.schema) {
|
|
201
|
+
tsType = jsonSchemaTypeToTs(entry.schema);
|
|
202
|
+
} else if (entry.example && typeof entry.example === "object" && !Array.isArray(entry.example)) {
|
|
203
|
+
tsType = inferTypeFromExample(entry.example);
|
|
204
|
+
}
|
|
205
|
+
const toolNote = tool ? ` (label "${label}", nextStep hint \u2192 ${tool})` : "";
|
|
206
|
+
actionTypeAliases.push(
|
|
207
|
+
`/** Action payload: ${desc || label}${toolNote} \u2014 control copy: "${label}" VERBATIM */
|
|
208
|
+
type ${typeName} = ${tsType};`
|
|
209
|
+
);
|
|
210
|
+
const callSig = tsType === "void" ? "() => void \u2014 fire and forget" : `(data: ${tsType}) => void`;
|
|
211
|
+
const toolHint = tool ? ` \u2192 nextStep: ${tool}` : "";
|
|
212
|
+
const onceHint = " \u2014 if this is meant ONCE, disable its control after it fires";
|
|
213
|
+
if (entry.oneShot === true) {
|
|
214
|
+
hasOneShotAction = true;
|
|
215
|
+
actionHookCalls.push(
|
|
216
|
+
` const ${key} = useAction<${typeName}>('${key}'); // ${callSig}${toolHint} \u2014 declared oneShot: the runtime drops a second dispatch`
|
|
217
|
+
);
|
|
218
|
+
actionHookCalls.push(
|
|
219
|
+
` const ${key}Spent = useActionSpent('${key}'); // true once fired, also after a reload \u2014 render the control from THIS: disabled={${key}Spent} and a spent label`
|
|
220
|
+
);
|
|
221
|
+
} else {
|
|
222
|
+
actionHookCalls.push(` const ${key} = useAction<${typeName}>('${key}'); // ${callSig}${toolHint}${onceHint}`);
|
|
223
|
+
}
|
|
224
|
+
actionHookCalls.push(
|
|
225
|
+
` const ${key}Pending = useActionPending('${key}'); // true from the tap until the agent's answer repaints the card \u2014 render EVERY control that dispatches '${key}' (a Button, a Select's onChange, an Input's Enter) from THIS: disabled={${key}Pending} aria-busy={${key}Pending}, and a working label on a button; no other control carries its aria-busy`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
const streamChannels = contract?.streamSpec ?? {};
|
|
229
|
+
const streamChannelEntries = Object.entries(streamChannels);
|
|
230
|
+
const streamTypeAliases = [];
|
|
231
|
+
const streamHookCalls = [];
|
|
232
|
+
for (const [channelName, entry] of streamChannelEntries) {
|
|
233
|
+
const desc = entry.description ?? "";
|
|
234
|
+
const typeName = `Stream${channelName.charAt(0).toUpperCase()}${channelName.slice(1)}`;
|
|
235
|
+
const tsType = entry.schema ? jsonSchemaTypeToTs(entry.schema) : "unknown";
|
|
236
|
+
streamTypeAliases.push(`/** Stream channel: ${desc} */
|
|
237
|
+
type ${typeName} = ${tsType};`);
|
|
238
|
+
streamHookCalls.push(
|
|
239
|
+
` const ${channelName} = useStream<${typeName}>('${channelName}'); // .latest: ${typeName} | null, .all: ${typeName}[]`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const gadgetUses = contract ? listContractGadgets(contract) : [];
|
|
243
|
+
const gadgetCatalog = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const descriptor of appGadgets ?? []) {
|
|
245
|
+
for (const exp of descriptor.exports) {
|
|
246
|
+
if (exp.hook === void 0) continue;
|
|
247
|
+
gadgetCatalog.set(exp.hook, {
|
|
248
|
+
description: exp.description,
|
|
249
|
+
usage: exp.usage,
|
|
250
|
+
example: exp.example
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const gadgetImportsByPackage = /* @__PURE__ */ new Map();
|
|
255
|
+
const gadgetHookCalls = [];
|
|
256
|
+
for (const use of gadgetUses) {
|
|
257
|
+
const exportName = use.name;
|
|
258
|
+
const pkgExports = gadgetImportsByPackage.get(use.package);
|
|
259
|
+
if (pkgExports !== void 0) pkgExports.add(exportName);
|
|
260
|
+
else gadgetImportsByPackage.set(use.package, /* @__PURE__ */ new Set([exportName]));
|
|
261
|
+
if (!HOOK_NAME_RE.test(exportName)) continue;
|
|
262
|
+
const hook = exportName;
|
|
263
|
+
const contractDesc = use.description;
|
|
264
|
+
const contractUsage = use.usage;
|
|
265
|
+
const catalog = gadgetCatalog.get(hook) ?? {};
|
|
266
|
+
const desc = contractDesc ?? catalog.description ?? hook;
|
|
267
|
+
const usage = contractUsage ?? catalog.usage;
|
|
268
|
+
const example = catalog.example;
|
|
269
|
+
let callArgs = "";
|
|
270
|
+
let exampleComment = "";
|
|
271
|
+
if (example !== void 0 && example !== null) {
|
|
272
|
+
const callLine = typeof example === "object" && !Array.isArray(example) && typeof example.call === "string" ? example.call : void 0;
|
|
273
|
+
if (callLine !== void 0) {
|
|
274
|
+
exampleComment = `
|
|
275
|
+
// EXAMPLE: ${callLine.trim()}`;
|
|
276
|
+
} else {
|
|
277
|
+
callArgs = JSON.stringify(example);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const usageNote = usage ? ` USE: ${usage}` : "";
|
|
281
|
+
const bindingName = hook.length > 3 ? hook.charAt(3).toLowerCase() + hook.slice(4) : hook;
|
|
282
|
+
gadgetHookCalls.push(
|
|
283
|
+
` const ${bindingName} = ${hook}(${callArgs}); // ${desc}${usageNote}${exampleComment}`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const gadgetImportLine = gadgetImportsByPackage.size > 0 ? "// DO NOT EDIT \u2014 gadget imports. Each export is resolved by the iframe runtime; keep every import line and export name. self_check fails with gadget_preservation:<export> if a gadget import is removed.\n" + Array.from(gadgetImportsByPackage.entries()).sort(([a], [b]) => a.localeCompare(b)).map(
|
|
287
|
+
([pkg, hooks]) => `import { ${Array.from(hooks).sort().join(", ")} } from '${pkg}';`
|
|
288
|
+
).join("\n") : "";
|
|
289
|
+
const propsInterface = propsFields.length > 0 ? `// DO NOT EDIT \u2014 generated from data contract. Changing this will fail validation.
|
|
290
|
+
interface Props {
|
|
291
|
+
${propsFields.join("\n")}
|
|
292
|
+
}` : `// DO NOT EDIT \u2014 generated from data contract.
|
|
293
|
+
interface Props {
|
|
294
|
+
[key: string]: string | number | boolean | null | object;
|
|
295
|
+
}`;
|
|
296
|
+
const contextSpec = contract?.contextSpec ?? {};
|
|
297
|
+
const contextSpecEntries = Object.entries(contextSpec);
|
|
298
|
+
let contextHooks = "";
|
|
299
|
+
if (contextSpecEntries.length > 0) {
|
|
300
|
+
const hookLines = [];
|
|
301
|
+
for (const [slotKey, entry] of contextSpecEntries) {
|
|
302
|
+
const valueType = entry.schema ? jsonSchemaTypeToTs(entry.schema) : "unknown";
|
|
303
|
+
const setterName = `set${slotKey.charAt(0).toUpperCase()}${slotKey.slice(1)}`;
|
|
304
|
+
hookLines.push(
|
|
305
|
+
` const [${slotKey}, ${setterName}] = useGguiContext<${valueType}>('${slotKey}');`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
contextHooks = ` // DO NOT EDIT \u2014 auto-generated per contextSpec slot.
|
|
309
|
+
// Read \`<slotKey>\` to render, write via \`set<SlotKey>\` to
|
|
310
|
+
// surface the change to the agent's LLM context (debounced).
|
|
311
|
+
// The runtime owns the underlying useState + Provider; you
|
|
312
|
+
// write plain JSX, no wrap.
|
|
313
|
+
${hookLines.join("\n")}
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
316
|
+
const hasActions = actionHookCalls.length > 0;
|
|
317
|
+
const hasStream = streamHookCalls.length > 0;
|
|
318
|
+
const hasGadgetHookCalls = gadgetHookCalls.length > 0;
|
|
319
|
+
const hasContext = contextSpecEntries.length > 0;
|
|
320
|
+
const hasAnyHook = hasActions || hasStream || hasContext || hasGadgetHookCalls;
|
|
321
|
+
const hasAnyWireFromWire = hasActions || hasStream || hasContext;
|
|
322
|
+
const wireHooks = [];
|
|
323
|
+
if (hasActions) wireHooks.push("useAction");
|
|
324
|
+
if (hasOneShotAction) wireHooks.push("useActionSpent");
|
|
325
|
+
if (hasActions) wireHooks.push("useActionPending");
|
|
326
|
+
if (hasStream) wireHooks.push("useStream");
|
|
327
|
+
if (hasContext) wireHooks.push("useGguiContext");
|
|
328
|
+
const wireImport = hasAnyWireFromWire ? `import { ${wireHooks.join(", ")} } from '@ggui-ai/wire';
|
|
329
|
+
` : "";
|
|
330
|
+
const gadgetImport = gadgetImportLine.length > 0 ? `${gadgetImportLine}
|
|
331
|
+
` : "";
|
|
332
|
+
const reactImport = BOILERPLATE_REACT_IMPORT;
|
|
333
|
+
const hookParts = [];
|
|
334
|
+
if (hasActions) {
|
|
335
|
+
hookParts.push(" // \u2500\u2500 Actions (contract-typed, fire-and-forget to agent) \u2500\u2500");
|
|
336
|
+
hookParts.push(" // Call these to send user interactions to the agent. Types are enforced by the compiler.");
|
|
337
|
+
hookParts.push(...actionHookCalls);
|
|
338
|
+
}
|
|
339
|
+
if (hasStream) {
|
|
340
|
+
hookParts.push("");
|
|
341
|
+
hookParts.push(" // \u2500\u2500 Streams (contract-typed, real-time from agent) \u2500\u2500");
|
|
342
|
+
hookParts.push(" // .latest is the most recent event (or null). .all is the full history array.");
|
|
343
|
+
hookParts.push(...streamHookCalls);
|
|
344
|
+
}
|
|
345
|
+
if (hasGadgetHookCalls) {
|
|
346
|
+
hookParts.push("");
|
|
347
|
+
hookParts.push(" // \u2500\u2500 Gadgets (browser-capability hooks; UI-owned lifecycle) \u2500\u2500");
|
|
348
|
+
hookParts.push(" // Read .value / .status; call .start() to invoke. Surface .value through");
|
|
349
|
+
hookParts.push(" // an actionSpec payload or contextSpec slot if the agent needs to observe it.");
|
|
350
|
+
hookParts.push(...gadgetHookCalls);
|
|
351
|
+
}
|
|
352
|
+
const hookBody = hasAnyHook ? ` // DO NOT EDIT wire hooks \u2014 auto-generated from the data contract
|
|
353
|
+
${hookParts.join("\n")}
|
|
354
|
+
` : "";
|
|
355
|
+
const wrapTypes = (label, body) => `
|
|
356
|
+
/* eslint-disable no-unused-vars */
|
|
357
|
+
// DO NOT EDIT \u2014 ${label}
|
|
358
|
+
${body}
|
|
359
|
+
/* eslint-enable no-unused-vars */
|
|
360
|
+
`;
|
|
361
|
+
const actionTypesBlock = actionTypeAliases.length > 0 ? wrapTypes("action payload types generated from action contract.", actionTypeAliases.join("\n\n")) : "";
|
|
362
|
+
const streamTypesBlock = streamTypeAliases.length > 0 ? wrapTypes("stream event types generated from stream contract.", streamTypeAliases.join("\n\n")) : "";
|
|
363
|
+
const mountCanvas = `
|
|
364
|
+
|
|
365
|
+
// DO NOT EDIT \u2014 the canvas this card is composed for; the runtime reads it at mount.
|
|
366
|
+
export const ${GGUI_MOUNT_CANVAS_EXPORT} = "${canvasForRendering(shellType, screen)}";`;
|
|
367
|
+
return renderBoilerplate(shellType ?? "fullscreen", screen ?? "universal", {
|
|
368
|
+
REACT_IMPORT: reactImport,
|
|
369
|
+
ALL_DESIGN,
|
|
370
|
+
WIRE_IMPORT: wireImport + gadgetImport,
|
|
371
|
+
PROPS_INTERFACE: propsInterface + mountCanvas,
|
|
372
|
+
ACTION_TYPES: actionTypesBlock,
|
|
373
|
+
STREAM_TYPES: streamTypesBlock,
|
|
374
|
+
CONTEXT_HOOKS: contextHooks,
|
|
375
|
+
WIRE_HOOKS: hookBody,
|
|
376
|
+
AXIS_SECTIONS: composedSections ?? ""
|
|
377
|
+
}, designMode);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/boilerplate/hard-sections.ts
|
|
381
|
+
var PROTOCOL_NOTES = `## Protocol Notes
|
|
382
|
+
The boilerplate pre-declares every wire hook the contract requires (\`useAction\`, \`useStream\`, \`useGguiContext\`, plus capability hooks from \`@ggui-ai/gadgets\` when the contract declares \`clientCapabilities\`). Three rules:
|
|
383
|
+
1. **Do NOT delete any pre-declared hook.** \`self_check\` fails with \`wire_preservation:<kind>:<name>\` if you remove one.
|
|
384
|
+
2. **Consume every hook binding** somewhere in the component \u2014 in JSX, a callback, or an effect. Unused bindings fail lint with \`no-unused-vars\`.
|
|
385
|
+
3. **Do NOT invent new wire calls.** Every \`useAction('X')\`, \`useStream('X')\`, \`useGguiContext('X')\` etc. MUST correspond to a declared entry on the contract. Calling one that isn't declared fails \`self_check\` with \`wire_undeclared:<kind>:<name>\` because the runtime has no Context/registration for it and would throw at first paint. If you need a new wire surface, that's a contract authoring step the agent owns \u2014 your job is to honor what's declared.
|
|
386
|
+
|
|
387
|
+
Renaming a binding is fine \u2014 the wiring is the string-literal argument, not the identifier.`;
|
|
388
|
+
var CONTRACT_SURFACE = `## Contract surface \u2014 four specs + two catalogs
|
|
389
|
+
|
|
390
|
+
A \`DataContract\` declares everything a GguiSession exchanges with the outside world. **Four typed specs** for the four data-flow directions, **two reference catalogs** for tool / hook lookups:
|
|
391
|
+
|
|
392
|
+
| Surface | Direction | Role |
|
|
393
|
+
| -------------------- | -------------------------- | -------------------------------------------------------------------- |
|
|
394
|
+
| \`propsSpec\` | server \u2192 UI (one-shot) | Initial render values delivered once at \`ggui_render\` |
|
|
395
|
+
| \`streamSpec\` | agent \u2192 UI (many) | Typed channels for live updates via \`ggui_emit\` |
|
|
396
|
+
| \`actionSpec\` | UI \u2192 agent (events) | Discrete events driving the agent's next turn (consumed via \`ggui_consume\`) |
|
|
397
|
+
| \`contextSpec\` | UI \u2192 server (state mirror) | UI state the agent observes between turns |
|
|
398
|
+
| \`agentCapabilities.tools\` | catalog | Tools the contract references via \`actionSpec[*].nextStep\` and \`streamSpec[*].source.tool\` |
|
|
399
|
+
| \`clientCapabilities.gadgets\` | catalog | Browser-capability gadget hooks the component code mounts (e.g., \`useGeolocation\`) |
|
|
400
|
+
|
|
401
|
+
**Placement rule for inbound specs**: actions drive turns; context observes state. There is no third category.
|
|
402
|
+
|
|
403
|
+
**Data vs behavior**: the contract describes data flow; the component code describes behavior. Scroll, focus, toast, animation, clipboard write \u2014 all component code, never contract fields.`;
|
|
404
|
+
var DEFENSIVE_CODING = `## Defensive coding for absent / late-arriving data
|
|
405
|
+
|
|
406
|
+
Props arrive at mount and may be partial on first render; later prop changes reach the SAME mounted component via \`ggui_amend\` (in-place repaint) on the live channel. Stream channels start empty and fill over time. Context slots start at their declared default (often \`null\`). **Never assume a field exists before you read it.**
|
|
407
|
+
|
|
408
|
+
- **Optional contract props**: a \`Props\` field marked \`?\` in the boilerplate may be omitted by the agent ENTIRELY \u2014 the wire gate only enforces \`required: true\` entries, and the harness verifies your component with those props stripped. Guard them (\`?? default\`, \`?.\`, or an empty-state branch) from the FIRST render.
|
|
409
|
+
- **Array iteration**: always default to \`[]\` before \`.map\`/\`.filter\`/\`.length\`. Use \`(props.items ?? []).map(...)\` not \`props.items.map(...)\`. Same for stream.all, stream.latest, etc.
|
|
410
|
+
- **Object access**: optional-chain through nested fields. \`props.user?.name ?? 'Anonymous'\` not \`props.user.name\`.
|
|
411
|
+
- **Number ops**: default before arithmetic. \`(props.count ?? 0) + 1\` not \`props.count + 1\`.
|
|
412
|
+
- **Stream latest**: \`useStream\` returns \`{latest: T | null, all: T[], isComplete: boolean}\`. The default \`all\` is \`[]\` so it's safe to map; \`latest\` is null until the first frame arrives \u2014 guard before reading \`.foo\`.
|
|
413
|
+
- **Stream reconciliation**: when a stream event carries an \`action\` discriminant (e.g. \`create | move | edit | delete\`), the channel is a CRUD feed \u2014 your handler MUST branch on EVERY value: append on \`create\`, drop on \`delete\`, replace-by-id on \`move\` / \`edit\`. Merging only the "edit" case silently loses created and deleted items. Reconcile into the SAME state that seeds from \`props\` (e.g. \`useState(() => props.tasks ?? [])\`) so the seed data and the live feed render as one list \u2014 and handle an event whose id is not yet present (a \`create\` for an unknown item) by inserting it, not ignoring it.
|
|
414
|
+
- **Props re-sync on repaint**: props the agent owns are the source of truth for display \u2014 prefer rendering DIRECTLY from \`props\` (controlled, no local copy). When local optimistic state genuinely needs a prop seed (a click bumps a count before the agent confirms), it MUST re-sync on prop change \u2014 \`useEffect(() => setCount(props.count ?? 0), [props.count])\` \u2014 or a \`ggui_amend\` repaint applies the new props while the display keeps the stale local value. BAD: \`const [count, setCount] = useState(props.count ?? 0)\` alone. GOOD: the same seed + the one-line re-sync effect.
|
|
415
|
+
- **Loading state**: while data is still absent, render \`<Skeleton>\` placeholders \u2014 never a blank screen. \`<Skeleton variant="text" />\` for a text line, \`variant="circle"\` for an avatar slot, default \`rect\` for a block.
|
|
416
|
+
- **Empty state**: when a list or results array is empty, render \`<EmptyState title="\u2026" description="\u2026" />\` \u2014 a region that renders nothing when empty looks broken to the user.
|
|
417
|
+
|
|
418
|
+
Unhandled \`Cannot read properties of undefined\` errors trip the iframe error boundary and the user sees "Something went wrong" \u2014 a regression class the runtime can't recover from.`;
|
|
419
|
+
var GESTURE_ROUTING = `## Picking the right primitive for user gestures
|
|
420
|
+
|
|
421
|
+
Choose by what the user is DOING, not where the result goes \u2014 the runtime handles the routing.
|
|
422
|
+
|
|
423
|
+
| Gesture intent | LLM writes | Notes |
|
|
424
|
+
| -------------- | ---------- | ----- |
|
|
425
|
+
| Fire a server-side action | \`useAction(name)\` + call \`dispatch(name, payload)\` | Every action is agent-routed. The runtime emits an event on \`ggui_consume\`; the agent reacts on its next turn. If the contract entry declares \`nextStep: 'X'\`, that names the tool the agent SHOULD call next \u2014 advisory hint forwarded as event metadata. |
|
|
426
|
+
| Surface state to the agent's context | the auto-generated \`setSlotName\` setter (from the boilerplate's \`useGguiContext\` line) | The runtime owns useState + Provider; the boilerplate emits one \`const [slot, setSlot] = useGguiContext<T>('slot')\` line per declared \`contextSpec\` slot. Write plain JSX, no \`useState\`, no Provider wrap. Every value change auto-flows to the host LLM (debounced). One-way client \u2192 agent \u2014 see "Observable state via \`contextSpec\`" below. |
|
|
427
|
+
| Use a browser capability (camera, mic, geolocation, clipboard, file picker, notifications) | call the hook the contract declared, e.g., \`const loc = useGeolocation();\` and \`await loc.start()\` | The contract's \`clientCapabilities.gadgets\` declares which gadget exports the UI uses. The hook implementations live in \`@ggui-ai/gadgets\` (or a third-party package named in the \`Package\` column). Read \`status\` ("idle" / "prompting" / "active" / "completed" / "denied" / "error") to gate UI, and thread the resolved \`value\` into a contextSpec slot or actionSpec payload if the agent needs to see it. |
|
|
428
|
+
| Open external link | Plain \`<a href="https://...">\` (or \`target="_blank"\`) | External cross-origin clicks are intercepted and routed through the host (security warnings, app-internal navigation, audit). Same-origin links and \`#fragment\` jumps stay native. |
|
|
429
|
+
| Toggle fullscreen / chrome | Plain \`el.requestFullscreen()\` / \`document.exitFullscreen()\` | The native browser API is intercepted; the host adjusts iframe chrome accordingly. Returns a resolved promise so \`.then()\` / \`await\` chains don't break. |
|
|
430
|
+
|
|
431
|
+
Every gesture fires a uniform server-side audit envelope (\`ggui_runtime_submit_action\`) so operators see all three patterns in RenderInspector with the same shape.
|
|
432
|
+
|
|
433
|
+
**Don't import wire hooks for link / display-mode.** \`useAction\` is the only wire hook for user gestures; links and fullscreen use plain HTML / browser APIs.
|
|
434
|
+
|
|
435
|
+
**All actions are agent-routed.** Every action emits an event the agent reacts to on its next turn via \`ggui_consume\`. The optional \`nextStep: '<tool>'\` field on an \`actionSpec\` entry is a HINT naming the tool the agent SHOULD call next \u2014 the contract author's recommendation, NOT a binding directive. The agent decides whether to honor it. If you want to declare a tool catalog entry the contract references, add it to \`agentCapabilities.tools[<name>]\` with input/output schemas; the cross-ref linter rejects dangling \`nextStep\` values that don't resolve to a declared catalog entry.`;
|
|
436
|
+
var INTERACTIVE_TRAITS = `## Making a primitive interactive \u2014 \`as={Trait}\`
|
|
437
|
+
|
|
438
|
+
Structural primitives (\`Box\`, \`Stack\`, \`Row\`, \`Card\`) have NO \`onClick\` by default. Add interactivity with the \`as\` prop \u2014 a trait, not a wrapper:
|
|
439
|
+
|
|
440
|
+
\`\`\`tsx
|
|
441
|
+
<Card as={Clickable} onClick={() => dispatch('select', { id })}
|
|
442
|
+
hoverStyle={{ boxShadow: 'var(--ggui-shape-shadow-lg)' }}>\u2026</Card>
|
|
443
|
+
\`\`\`
|
|
444
|
+
|
|
445
|
+
- \`as={Clickable}\` \u2192 \`onClick\` + keyboard activation (Enter/Space) + \`role="button"\` + \`hoverStyle\`/\`activeStyle\`/\`cursor\`.
|
|
446
|
+
- \`as={Hoverable}\` \u2192 \`hoverStyle\` only (no click). \`as={Pressable}\` \u2192 \`onPress\` + \`pressStyle\`.
|
|
447
|
+
|
|
448
|
+
\`as={Trait}\` is a PROP \u2014 it does NOT re-nest the JSX. Never write \`<Clickable>\u2026</Clickable>\` around a primitive; put \`as={Clickable}\` on the primitive itself. The trait carries the keyboard + ARIA wiring, so don't hand-write \`onKeyDown\` / \`role\`. Trait components (\`Clickable\`, \`Hoverable\`, \`Pressable\`) import from \`@ggui-ai/design\` like everything else \u2014 the boilerplate already imports them.
|
|
449
|
+
|
|
450
|
+
**Semantic components are already interactive** \u2014 \`Button\` (\`onClick\`), \`Link\` (\`href\`), \`Input\` / \`Select\` (\`onChange\`). Use their own props; never put \`as\` on them. \`Text\` picks its element with \`is\` (\`<Text is="label">\`), not \`as\`.
|
|
451
|
+
|
|
452
|
+
**Never nest two interactive elements.** Interactive content MUST NOT contain other interactive content \u2014 a gesture on the inner control bubbles to the outer one and fires BOTH handlers (one user click \u2192 the action dispatched twice). Do NOT put a \`Button\`, \`Checkbox\`, \`Input\`, \`Select\`, \`Link\`, or another \`as={Clickable}\` primitive inside a \`Card\` / \`Box\` / \`Row\` / \`Stack\` that is itself \`as={Clickable}\`. Wire each \`useAction\` callback to exactly ONE surface: EITHER the whole card is the trigger (interactive container, no interactive children) OR an inner control is the trigger (plain container, no \`as={Clickable}\`) \u2014 never both. A row with a checkbox: put the action on the \`Checkbox onChange\` and leave the row plain.
|
|
453
|
+
|
|
454
|
+
**\`Text\` / \`Heading\` accept NO event handlers and NO \`as\` \u2014 only \`style\` / \`className\` plus their own typed props.** \`onClick\`, \`onDoubleClick\`, \`as={Clickable}\`, \`color\` are all type errors on \`Text\`. When the request says a label is "clickable", "editable", "edit on click / double-click", or "tap to \u2026", do ONE of these \u2014 never put the handler on \`Text\`:
|
|
455
|
+
|
|
456
|
+
\`\`\`tsx
|
|
457
|
+
// Click-to-edit a label: wrap the Text in a Clickable structural primitive.
|
|
458
|
+
<Box as={Clickable} onClick={() => setEditingId(task.id)}
|
|
459
|
+
style={{ cursor: 'pointer' }}>
|
|
460
|
+
<Text weight="semibold">{task.title}</Text>
|
|
461
|
+
</Box>
|
|
462
|
+
|
|
463
|
+
// Or pair the label with an explicit edit Button (clearer affordance).
|
|
464
|
+
<Row gap="xs" align="center">
|
|
465
|
+
<Text weight="semibold">{task.title}</Text>
|
|
466
|
+
<Button variant="ghost" size="xs" aria-label="Edit title"
|
|
467
|
+
onClick={() => setEditingId(task.id)}>Edit</Button>
|
|
468
|
+
</Row>
|
|
469
|
+
|
|
470
|
+
// In edit mode, swap the Text for an Input.
|
|
471
|
+
{editingId === task.id
|
|
472
|
+
? <Input value={draftTitle} onChange={setDraftTitle} label="Task title" />
|
|
473
|
+
: <Text weight="semibold">{task.title}</Text>}
|
|
474
|
+
\`\`\``;
|
|
475
|
+
var ANTI_PATTERNS = `## Anti-patterns \u2014 DO NOT WRITE
|
|
476
|
+
|
|
477
|
+
The following identifiers / shapes are RETIRED from the contract surface as of 2026-05-11. Pre-2026-05-11 examples in your training data may include them; do not reproduce. The linter / CI grep gate rejects:
|
|
478
|
+
|
|
479
|
+
- \`useWiredTool\`, \`useClientTool\` \u2014 retired hooks. Replace with \`useAction\` (events) and the named hook from \`@ggui-ai/gadgets\` (browser capabilities).
|
|
480
|
+
- \`dispatch: { kind: 'tool', tool: '...' }\` / \`dispatch: { kind: 'agent', intendedTool: '...' }\` \u2014 retired discriminated-union. Use the flat optional \`nextStep?: '<tool>'\` instead.
|
|
481
|
+
- \`mode: 'host-routed'\` / \`mode: 'tool'\` \u2014 retired \`mode\` field. Same fix: flat \`nextStep?\`.
|
|
482
|
+
- \`broadcast: {...}\` on the contract \u2014 retired top-level field. Use \`streamSpec[channel].source: {tool, args?}\` to declare a tool-fed channel.
|
|
483
|
+
- \`wiredTools\` / \`agentTools\` (top-level) \u2014 retired catalog names. Use \`agentCapabilities.tools\`.
|
|
484
|
+
- \`clientTools\` / \`clientCapabilities.capabilities\` \u2014 retired catalog shapes. Use \`clientCapabilities.gadgets\` (entries declare hooks, not RPC).
|
|
485
|
+
- \`@ggui-ai/client-tools\` \u2014 retired package name. Import gadget hooks from \`@ggui-ai/gadgets\`.
|
|
486
|
+
- \`intendedTool\` \u2014 retired. Use \`nextStep\` (flat).
|
|
487
|
+
- \`props: { properties: {...} }\` as a CONTRACT field \u2014 retired. The contract field is \`propsSpec\` (the wire \`props\` field on render / update still carries VALUES).`;
|
|
488
|
+
var CROSS_REFERENCE_RULES = `## Cross-reference rules
|
|
489
|
+
|
|
490
|
+
When you declare a reference, also declare the catalog entry it points at:
|
|
491
|
+
|
|
492
|
+
- \`actionSpec[X].nextStep = 'fetch_inbox'\` \u2192 \`agentCapabilities.tools.fetch_inbox = { toolInfo: { inputSchema, description?, outputSchema? }, usage?, example? }\` MUST exist. Cross-ref code: \`CTR_REF_NEXT_STEP\`.
|
|
493
|
+
- \`streamSpec[X].source.tool = 'list_messages'\` \u2192 \`agentCapabilities.tools.list_messages\` MUST exist. Cross-ref code: \`CTR_REF_STREAM_SOURCE\`.
|
|
494
|
+
- The catalog entry's schemas MUST be a superset of the referencing spec's schema. Cross-ref code: \`CTR_SCHEMA_INCOMPAT\`.`;
|
|
495
|
+
function renderGadgetCatalogSection(gadgetsSection) {
|
|
496
|
+
return `## clientCapabilities \u2014 registered catalog
|
|
497
|
+
|
|
498
|
+
${gadgetsSection}
|
|
499
|
+
|
|
500
|
+
Each hook conforms to \`GadgetHook<TOutput, TOptions>\`: call \`start(opts?)\` to fire, read \`{value, status, error, stop?}\`. \`status\` walks through \`idle \u2192 prompting \u2192 active|completed\` or routes to \`denied\` / \`error\` on failure.
|
|
501
|
+
|
|
502
|
+
3rd-party plugins (Leaflet maps, Mapbox, Stripe, Chart.js, \u2026) are registered via \`createGguiGadget\` from \`@ggui-ai/gadgets\` and surface in this same table when the operator has added them to \`App.gadgets\`. Reference any registered hook by name \u2014 render validation rejects hooks not in this catalog with \`gadget_not_registered\`.`;
|
|
503
|
+
}
|
|
504
|
+
var CONTEXT_SPEC_SECTION = `## Observable state via \`contextSpec\`
|
|
505
|
+
|
|
506
|
+
When the contract declares \`contextSpec\`, the boilerplate auto-generates one \`useGguiContext\` call per slot at the top of your component. The runtime owns the underlying \`useState\` and the Provider tree \u2014 **you do NOT write \`useState\` or any \`<Provider>\` wrap yourself**:
|
|
507
|
+
|
|
508
|
+
\`\`\`tsx
|
|
509
|
+
import { useGguiContext } from '@ggui-ai/wire';
|
|
510
|
+
|
|
511
|
+
export default function Component(props: Props) {
|
|
512
|
+
// AUTO-GENERATED \u2014 do not remove or rename:
|
|
513
|
+
const [currentStep, setCurrentStep] = useGguiContext<number>('currentStep');
|
|
514
|
+
const [draftText, setDraftText] = useGguiContext<string>('draftText');
|
|
515
|
+
|
|
516
|
+
// Plain JSX. No Provider wrap. The runtime already wrapped your
|
|
517
|
+
// component in nested SingleSlotProviders before this code ran.
|
|
518
|
+
return (
|
|
519
|
+
<Container>
|
|
520
|
+
<Text>Step {currentStep}</Text>
|
|
521
|
+
<Input value={draftText} onChange={setDraftText} />
|
|
522
|
+
<Button onClick={() => setCurrentStep((s) => s + 1)}>Next</Button>
|
|
523
|
+
</Container>
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
\`\`\`
|
|
527
|
+
|
|
528
|
+
For every declared slot you have **\`slotName\` + \`setSlotName\`** in scope:
|
|
529
|
+
- **Read** the value to render: \`<Text>Step {currentStep}</Text>\`
|
|
530
|
+
- **Write** via the setter: \`setCurrentStep(s => s + 1)\` (in callbacks, effects, anywhere)
|
|
531
|
+
|
|
532
|
+
Every value change is mirrored to the host LLM's context automatically (debounced, default 300ms \u2014 adjustable per-slot via \`entry.debounceMs\` in the contract). The agent sees the user's interaction state \u2014 drafts, current step, hover, selection \u2014 without you calling any API.
|
|
533
|
+
|
|
534
|
+
**When to use the auto-generated state.** Any slot the contract declared. If \`contextSpec.draftText\` exists, bind \`<Input value={draftText} onChange={setDraftText}>\` so the agent sees the typing live (a design control's \`onChange\` hands you the value, never an event). If \`contextSpec.currentStep\` exists, render the step indicator from \`currentStep\` and bump it via \`setCurrentStep\` in your "next" callback.
|
|
535
|
+
|
|
536
|
+
**Seeding a slot from a prop.** A slot starts at the contract's default, never at a prop. When a slot must start from a prop (a form pre-filled from \`props\`), seed it with \`useLayoutEffect(() => setName(props.name ?? ''), [props.name])\` \u2014 \`useLayoutEffect\`, not \`useEffect\`: \`useEffect\` lets the first frame paint the empty default before the prop arrives. The dependency array re-seeds the slot when the agent repaints with new props.
|
|
537
|
+
|
|
538
|
+
**When NOT to use it.** Local UI state the contract did NOT declare \u2014 \`isDropdownOpen\`, hover flags, animation phase, ephemeral toggles. For those, use a plain \`useState\` directly. The runtime ignores undeclared state.
|
|
539
|
+
|
|
540
|
+
**\`contextSpec\` direction is one-way: client \u2192 agent.** The agent uses \`propsSpec\` (via \`ggui_amend\` for in-place repaints of this mount, or \`ggui_update\` when it mints a new history card) and \`streamSpec\` (via the live channel) to push state TO the client. Don't try to write to the agent via \`contextSpec\` \u2014 there is no return path.
|
|
541
|
+
|
|
542
|
+
**Schema mismatches drop silently.** If you set a value that doesn't match the slot's schema (e.g. a string into a \`{type: 'number'}\` slot), the runtime logs a dev \`console.warn\` and skips the post. Make sure your setter calls produce values that match the declared shape.`;
|
|
543
|
+
var DATA_PARAMETERIZATION = `## Data Parameterization (CRITICAL)
|
|
544
|
+
|
|
545
|
+
Generated components are CACHED blueprints reused across requests. NEVER hardcode request-specific data (names, cities, numbers, dates) into the component body. Define data as default prop values so the blueprint works for ANY similar request:
|
|
546
|
+
|
|
547
|
+
\`\`\`tsx
|
|
548
|
+
// BAD \u2014 hardcoded, only works for Tokyo
|
|
549
|
+
const city = "Tokyo";
|
|
550
|
+
const temp = 18;
|
|
551
|
+
|
|
552
|
+
// GOOD \u2014 parameterized via props with defaults from the request
|
|
553
|
+
interface Props {
|
|
554
|
+
city?: string;
|
|
555
|
+
temperature?: number;
|
|
556
|
+
}
|
|
557
|
+
export default function WeatherCard({ city = "Tokyo", temperature = 18 }: Props) {
|
|
558
|
+
// A controller can override for Seoul, Paris, etc.
|
|
559
|
+
}
|
|
560
|
+
\`\`\`
|
|
561
|
+
|
|
562
|
+
Rules:
|
|
563
|
+
1. All request-specific data \u2192 props with defaults. City names, tickers, user names, dates, counts.
|
|
564
|
+
2. Layout and styling are universal. Colors, spacing, structure \u2014 these are the reusable part.
|
|
565
|
+
3. Default values come from the current request \u2014 so the component renders correctly standalone.
|
|
566
|
+
4. Copy comes from the props. NEVER invent display text the contract does not carry \u2014 no eyebrow / kicker / overline (a \`<Text caps>\` label), no helper line, no status text, no tagline. **Do NOT add a caps label above the heading** \u2014 not \`<Text caps>LET'S BEGIN</Text>\`, not \`WELCOME\`, not a section kicker like \`GETTING STARTED\` or \`OVERVIEW\` \u2014 UNLESS a prop supplies that exact text (\`<Text caps>{props.section}</Text>\`). When the request asks for a heading and a line, render the heading and the line and NOTHING above the heading. A heading's fallback is the request's own words, never a slogan of your own. Text the agent cannot change is chatter on every render, and a caps eyebrow you wrote is the most common form of it. An action's control shows the contract's \`label\` VERBATIM \u2014 every character, including \`&\`, \`/\`, \`\u2013\` and quotes \u2014 never paraphrased, shortened or re-cased (\`"Confirm & Schedule"\` is not \`"Confirm Schedule"\`).
|
|
567
|
+
5. Props interface must be typed and exported.
|
|
568
|
+
6. Keys on a mapped list come from the item's own identity: \`key={item.id}\` when the contract gives an id; when the items carry none (KPI tiles \`{label, value}\`, forecast days \`{day, high}\`), key by the field that names each one \u2014 \`key={item.label}\`, \`key={day.day}\` \u2014 never by the map index: a reorder or a stream merge re-keys by index and re-mounts the wrong rows, and the self-check refuses an index key.`;
|
|
569
|
+
var TERMINAL_ACTIONS = `## Actions the user means once
|
|
570
|
+
|
|
571
|
+
A second press is a mistake only when it would make a SECOND THING HAPPEN IN THE WORLD \u2014 a second booking, a second charge, a second order, a second application sent. If pressing again would only write the SAME STATE AGAIN \u2014 saving, updating, renaming, setting a preference, toggling \u2014 nothing is duplicated and the control stays armed.
|
|
572
|
+
|
|
573
|
+
**The contract says which actions are once.** An action the contract declares \`oneShot: true\` (in the Contract block above) is guarded by the runtime \u2014 a second dispatch is dropped \u2014 and its spent state is DATA you read, never state you hold: render its control from \`const spent = useActionSpent('<name>')\`, \`disabled={spent}\`, and say so in the label or beside it ("Submitted", "Request sent") \u2014 a control that is disabled without explanation reads as broken. The hook's answer survives a reload and a second tab; \`useState(false)\` does not, so a reloaded card built on local state re-arms a control that already fired.
|
|
574
|
+
|
|
575
|
+
**An action the contract does not declare \`oneShot\` stays armed.** Never guard one from a feeling about the verb \u2014 "confirm", "submit", "place" alone are not evidence. Guard it only where the request itself names a one-time commitment the contract failed to declare ("submit the application", "place the order"), and then with local state as the fallback: \`const [submitted, setSubmitted] = useState(false)\` set in the handler, \`disabled={submitted}\` with a label \u2014 knowing that this state lives with the component, not with the request, and starts fresh on a re-render with new props.
|
|
576
|
+
|
|
577
|
+
**When in doubt, leave it armed.** A control the user cannot press a second time has lost them something that worked \u2014 save, edit, save again is ordinary. A control left armed is only what every interface does by default.`;
|
|
578
|
+
var FRAME_SIZING = `## Sizing \u2014 the frame owns the height and the width
|
|
579
|
+
|
|
580
|
+
The host sizes the iframe; the component never sizes itself to the viewport. NEVER write \`100vh\` / \`100dvh\` / \`100svh\` (or an \`h-screen\` / \`min-h-screen\` class) as a height on any element:
|
|
581
|
+
- An inline card takes its natural height. A content-sized frame is measured FROM the content, so a \`100vh\` root can never shrink and grows the frame on every re-measure.
|
|
582
|
+
- Under fullscreen the frame already stretches your root to its full height. Centre inside it with flex (\`display: flex; flex-direction: column; justify-content: center\`), never with a viewport height.
|
|
583
|
+
- In EVERY fit (an inline card, a framed card, fullscreen) the card keeps ONE content edge: the runtime insets your root's content from the card's edge. Leave it, and never pad it back out. Only two things run edge to edge, in every fit:
|
|
584
|
+
- a \`surface="hero"\` band that is your root's FIRST child, opening the card (\`<Box surface="hero">\u2026</Box>\` directly inside the root, not wrapped in a \`Stack\`, not second);
|
|
585
|
+
- any other band that declares \`bleed\` (\`<Box surface="sunken" bleed>\u2026</Box>\`). Only a band MEANT to run edge to edge takes it: a full-width strip of rows, a closing action bar.
|
|
586
|
+
A band you paint yourself (a \`Box\` with a \`background\`) is NOT an edge-to-edge band. It sits inside the inset with the card's corners showing around it, like a box floating in the card. An opening band is always the kit's \`surface="hero"\`, never your own colour.
|
|
587
|
+
- To fill a parent that has a height use \`height: 100%\` or \`flex: 1\`; a viewport unit is only ever a \`max-height\` cap on a scroll region.
|
|
588
|
+
|
|
589
|
+
The width works the same way, and the mistake is the mirror image: **your outermost element FILLS the frame; a width cap belongs INSIDE it, on the column that holds text.**
|
|
590
|
+
|
|
591
|
+
- Never put \`maxWidth\` (or a \`max-w-*\` class) on the element you return at the top. On a wide canvas that turns your card into a narrow strip with the frame's ground on either side of it, and on a narrow one it does nothing \u2014 the same composition reading differently at two sizes.
|
|
592
|
+
- DO cap the reading measure inside: a column of prose is easiest to read at 60\u201370 characters, so wrap the TEXT in a \`<Container maxWidth="sm">\` (or your own \`max-width\`) and leave the root filling. A hero band, a toolbar, a table or an image then still uses the whole width, which is what makes a wide card look composed rather than padded.
|
|
593
|
+
- Centre that inner column with the container's own centring, not by shrinking the root \u2014 and give the card ONE column: every block of the reading flow (a heading, its text, and the chips or buttons that answer it) sits in a \`<Container>\` of the same \`maxWidth\`, so their left edges line up even where a full-width band runs between them.
|
|
594
|
+
- **They are two different elements.** Even when the whole card is one column of text, the root still fills and the column sits INSIDE it \u2014 \`<Box padding="lg"><Container maxWidth="sm">\u2026</Container></Box>\`, never a root that is itself the container. A centred card is centring inside a filled frame, not a shrunken frame.`;
|
|
595
|
+
var COMPONENT_STRUCTURE = `## Component Structure
|
|
596
|
+
|
|
597
|
+
Keep JSX nesting depth to 3\u20135 levels. When deeper, extract repeated/complex sections into helper components \u2014 named functions defined above the main Component in the same file. Helpers take data + callbacks via props; they don't own state.
|
|
598
|
+
|
|
599
|
+
\`\`\`tsx
|
|
600
|
+
import { useState } from 'react';
|
|
601
|
+
import { Container, Card, Stack, Text, Button, Input } from '@ggui-ai/design';
|
|
602
|
+
|
|
603
|
+
interface Props {
|
|
604
|
+
onSubmit?: (data: unknown) => void;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function ItemCard({ item, onEdit }: { item: Item; onEdit: (id: string) => void }) {
|
|
608
|
+
return <Card padding="md">\u2026</Card>;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export default function GeneratedComponent({ onSubmit }: Props) {
|
|
612
|
+
return (
|
|
613
|
+
<Container>
|
|
614
|
+
{items.map((item) => <ItemCard key={item.id} item={item} onEdit={handleEdit} />)}
|
|
615
|
+
</Container>
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
\`\`\``;
|
|
619
|
+
|
|
620
|
+
// src/boilerplate/free-design-prompt.ts
|
|
621
|
+
var FREE_GESTURE_SURFACE = `## One gesture surface per action binding
|
|
622
|
+
|
|
623
|
+
Every \`useAction\` binding is wired to exactly ONE interactive surface. Interactive content MUST NOT contain other interactive content that dispatches the same binding \u2014 a click on the inner control bubbles to the outer handler and the action fires TWICE, so a toggle-style action silently reverts the user's change. Concretely: never put a \`<button>\`, \`<a>\`, \`<input>\`, \`<select>\`, an element with \`role="button"\`, or any element with its own \`onClick\`, inside a \`<div>\` / \`<li>\` / \`<tr>\` / \`<Card>\` whose own \`onClick\` calls the same binding. EITHER the whole row is the trigger (interactive container, no interactive children) OR an inner control is the trigger (plain container) \u2014 never both. Tier-0 fails the nested shape with \`double-wired-action:certain\`. A row with a checkbox: put the action on the checkbox's \`onChange\` and leave the row plain. \`stopPropagation\` is not a fix \u2014 pick one surface.`;
|
|
624
|
+
var FREE_DESIGN_FREEDOM = `## Design freedom
|
|
625
|
+
|
|
626
|
+
You are not required to compose from the \`@ggui-ai/design\` primitives. Compose with raw HTML elements (\`<div>\`, \`<section>\`, \`<button>\`, \`<input>\`, \`<ul>\`, \`<table>\`, \u2026), inline \`style\` props and \`<style>\` blocks \u2014 regular CSS, \`@media\` and \`@container\` queries, \`@keyframes\`, \`:hover\` / \`:focus-visible\` (the host CSP permits \`'unsafe-inline'\` styles). Any layout: CSS grid, flexbox, absolute positioning, sticky headers. The runtime injects NO Tailwind and NO reset stylesheet \u2014 a raw element renders unstyled until your CSS styles it, so bring the CSS you need. Use class selectors in \`<style>\` blocks (an \`#id\` selector that reads as hex digits trips the color check).
|
|
627
|
+
|
|
628
|
+
\`@ggui-ai/design\` stays importable \u2014 \`import { Skeleton, EmptyState, Icon } from '@ggui-ai/design'\` \u2014 use a primitive when it saves work, skip it when it constrains you. Its props are documented in the optional catalog at the end of this prompt.
|
|
629
|
+
|
|
630
|
+
Spacing, typography, radius, shadow geometry and layout values MAY be literals: \`padding: '20px'\`, \`fontSize: 'clamp(1rem, 2vw, 1.5rem)'\`, \`borderRadius: 12\`, \`gap: '0.75rem'\`, \`boxShadow: '0 8px 24px var(--ggui-color-outlineVariant)'\`. Color is the one exception \u2014 next section.`;
|
|
631
|
+
var COLOR_PREFIX = "--ggui-color-";
|
|
632
|
+
var RAMP_FAMILIES = ["primary", "neutral", "success", "warning", "error", "info"];
|
|
633
|
+
var SEMANTIC_ROLES = [
|
|
634
|
+
{ names: ["ground", "onGround"], role: "the page / chat canvas behind everything + its text" },
|
|
635
|
+
{ names: ["container", "onContainer"], role: "a card, a bubble, a panel + body text on it" },
|
|
636
|
+
{ names: ["elevated", "onElevated"], role: "popover, menu, modal, toast \u2014 floats above a container" },
|
|
637
|
+
{ names: ["heroGround", "onHeroGround"], role: "a hero / greeting panel \u2014 brand-tinted on a light host, the ink pair on a dark one" },
|
|
638
|
+
{ names: ["sunken", "onSunken"], role: "wells, inputs at rest, code blocks + secondary text" },
|
|
639
|
+
{ names: ["link"], role: "accent TEXT \u2014 eyebrows, taglines, links, labels, inline arrows: the brand's readable ink per mode; a bare primary-300\u2026600 as a text color fails tier-0 (universal.accent_text_ink)" },
|
|
640
|
+
{ names: ["ground-subtle", "ground-gradient"], role: "quiet canvas fills" },
|
|
641
|
+
{ names: ["onPrimary"], role: "text on the brand color" },
|
|
642
|
+
{ names: ["outline", "outlineVariant"], role: "borders + dividers" },
|
|
643
|
+
{ names: ["onError"], role: "text on an error fill" },
|
|
644
|
+
{
|
|
645
|
+
names: ["tint-1", "tint-2", "tint-3", "tint-4", "tint-5", "tint-6", "tint-7", "tint-8"],
|
|
646
|
+
role: "categorical fills for DATA categories only (series, lanes, kinds, element groups) \u2014 never for state, never as decoration; the text on a tint is `onContainer` only, one short line, never muted text; the category is always also in words (a label or a legend); a category keeps its tint for the life of the card (assign from the data's order, never render order); more than eight categories: group to eight, or words only"
|
|
647
|
+
}
|
|
648
|
+
];
|
|
649
|
+
function colorVocabularyFromManifest(manifest) {
|
|
650
|
+
const colors = manifest.filter((t) => t.startsWith(COLOR_PREFIX)).map((t) => t.slice(COLOR_PREFIX.length));
|
|
651
|
+
const ramps = [];
|
|
652
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
653
|
+
for (const family of RAMP_FAMILIES) {
|
|
654
|
+
const steps = [];
|
|
655
|
+
for (const name of colors) {
|
|
656
|
+
const m = new RegExp(`^${family}-(\\d+)$`).exec(name);
|
|
657
|
+
if (m) {
|
|
658
|
+
steps.push(Number(m[1]));
|
|
659
|
+
claimed.add(name);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
if (steps.length === 0) continue;
|
|
663
|
+
steps.sort((a, b) => a - b);
|
|
664
|
+
const bare = colors.includes(family);
|
|
665
|
+
if (bare) claimed.add(family);
|
|
666
|
+
ramps.push({ family, steps, bare });
|
|
667
|
+
}
|
|
668
|
+
const roles = colors.filter((n) => !claimed.has(n)).sort();
|
|
669
|
+
return { ramps, roles };
|
|
670
|
+
}
|
|
671
|
+
function renderRamp(r) {
|
|
672
|
+
return `\`${r.family}-${r.steps.join("/")}\`${r.bare ? ` (plus bare \`${r.family}\`)` : ""}`;
|
|
673
|
+
}
|
|
674
|
+
function renderFreeColorRule(manifest = taughtTokenManifest) {
|
|
675
|
+
const { ramps, roles } = colorVocabularyFromManifest(manifest);
|
|
676
|
+
const brand = ramps.filter((r) => r.family === "primary" || r.family === "neutral");
|
|
677
|
+
const state = ramps.filter((r) => r.family !== "primary" && r.family !== "neutral");
|
|
678
|
+
const roleLines = [];
|
|
679
|
+
const named = /* @__PURE__ */ new Set();
|
|
680
|
+
for (const g of SEMANTIC_ROLES) {
|
|
681
|
+
const present = g.names.filter((n) => roles.includes(n));
|
|
682
|
+
if (present.length === 0) continue;
|
|
683
|
+
for (const n of present) named.add(n);
|
|
684
|
+
roleLines.push(`${present.map((n) => `\`${n}\``).join(" / ")} (${g.role})`);
|
|
685
|
+
}
|
|
686
|
+
const other = roles.filter((n) => !named.has(n));
|
|
687
|
+
if (other.length > 0) roleLines.push(`other roles: ${other.map((n) => `\`${n}\``).join(", ")}`);
|
|
688
|
+
const vocabulary = [
|
|
689
|
+
roleLines.length > 0 ? `- Semantic roles cover most needs: ${roleLines.join("; ")}.` : "",
|
|
690
|
+
brand.length > 0 ? `- Brand + neutral ramps (every step that exists, nothing else): ${brand.map(renderRamp).join(", ")}.` : "",
|
|
691
|
+
state.length > 0 ? `- State ramps (every step that exists, nothing else): ${state.map(renderRamp).join(", ")}.` : "",
|
|
692
|
+
"- A step not listed does not exist and renders unset; pick the nearest listed step."
|
|
693
|
+
].filter((l) => l.length > 0).join("\n");
|
|
694
|
+
return `## Color stays tokenized (the one hard styling rule)
|
|
695
|
+
|
|
696
|
+
Brand-bearing color \u2014 text, backgrounds, borders, fills, gradient stops, focus rings, shadow tints \u2014 comes ONLY from the closed \`--ggui-color-*\` token manifest, referenced BARE: \`color: 'var(--ggui-color-onContainer)'\`, \`background: 'var(--ggui-color-primary-50)'\`, \`border: '1px solid var(--ggui-color-outline)'\`, \`linear-gradient(135deg, var(--ggui-color-primary-500), var(--ggui-color-primary-700))\`.
|
|
697
|
+
|
|
698
|
+
- No hex (\`#7c3aed\`), no \`rgb()\` / \`rgba()\` / \`hsl()\` / \`hsla()\`, no CSS named colors (\`red\`, \`slategray\`) \u2014 anywhere in the file, including \`<style>\` blocks and shadows. Tier-0 fails them (\`tokens:hex-color\`, \`tokens:hardcoded-color-fn\`, \`tokens:named-color\`). \`transparent\`, \`currentColor\` and \`inherit\` are fine.
|
|
699
|
+
- No literal fallback inside ANY token reference: \`var(--ggui-color-primary-600)\` bare, never \`var(--ggui-color-primary-600, #0284c7)\` \u2014 the runtime injects every token on \`:root\`, and a fallback paints the wrong brand exactly when the operator's theme matters (\`tokens:token-fallback\`). This holds for every \`--ggui-*\` token you reference, not only colors.
|
|
700
|
+
- Only names from the manifest (listed at the end of this prompt) exist \u2014 an invented \`--ggui-color-*\` name renders unset (\`tokens:off-manifest-token\`).
|
|
701
|
+
- Shadows: \`var(--ggui-shape-shadow-sm|md|lg|xl)\`, or a literal offset/blur whose color is a token \u2014 never an \`rgba()\` tint.
|
|
702
|
+
- Why: the operator switches the whole app's theme (light, dark, branded) by redefining these variables. A component that reads them is on-brand everywhere; one that hardcodes color is off-brand everywhere but the default.
|
|
703
|
+
|
|
704
|
+
The color vocabulary (rendered from the manifest \u2014 these names and steps, exactly):
|
|
705
|
+
${vocabulary}`;
|
|
706
|
+
}
|
|
707
|
+
var FREE_COLOR_RULE = renderFreeColorRule();
|
|
708
|
+
var FREE_HOST_ENVELOPE = `## Where this renders
|
|
709
|
+
|
|
710
|
+
The compiled component is loaded into a sandboxed iframe by an MCP Apps host (chat clients, the ggui console, embedded panels):
|
|
711
|
+
|
|
712
|
+
- **Sandbox**: \`allow-scripts allow-forms\`, no same-origin. The only channel to the outside is \`postMessage\` through the wire hooks \u2014 the component never talks to a server itself.
|
|
713
|
+
- **No network from the component**: \`fetch\`, \`XMLHttpRequest\`, \`WebSocket\`, dynamic \`import()\` fail tier-0 and the CSP (\`connect-src 'none'\` on spec hosts). No \`<link rel="stylesheet">\`, no \`@import url()\`, no CDN scripts, no web fonts from a CDN \u2014 use \`var(--ggui-font-family-sans)\` / \`var(--ggui-font-family-mono)\` (system stacks) or a generic family.
|
|
714
|
+
- **No host document access**: \`window.*\`, \`document.*\` (other than the intercepted \`requestFullscreen\` / \`exitFullscreen\`), \`localStorage\`, \`sessionStorage\`, \`navigator\`, \`location\`, \`history\`, \`innerHTML\` / \`dangerouslySetInnerHTML\`, \`<script>\` \u2014 all rejected.
|
|
715
|
+
- **Props arrive through \`_meta["ai.ggui/render"]\`** on the host side and reach you as \`props\`; later repaints (\`ggui_amend\`) update the SAME mounted component \u2014 see "Defensive coding".
|
|
716
|
+
- **Display modes**: the host advertises \`availableDisplayModes\` (\`inline\` | \`fullscreen\` | \`pip\`); \`el.requestFullscreen()\` asks the host to switch \u2014 never assume it will.
|
|
717
|
+
- **Size**: the host sets the iframe's \`containerDimensions\` once per render; there is no live resize notification \u2014 a resize is a re-render, so layout must be fluid (\`width: 100%\`, \`max-width\`, no fixed width) and hold at any width inside the canvas range above.`;
|
|
718
|
+
var FREE_BUDGETS = `## Budgets (deterministic caps)
|
|
719
|
+
|
|
720
|
+
- Source \u2264 50 KB and \u2264 500 lines.
|
|
721
|
+
- Compiled bundle \u2264 2 MB.
|
|
722
|
+
- One file, one \`export default function Component(props: Props)\`.`;
|
|
723
|
+
var FREE_IMPORTS_AND_SECURITY = `## Imports & security (what you may import, what you may not call)
|
|
724
|
+
|
|
725
|
+
Import ONLY from: \`react\`, \`react-dom\`, \`@ggui-ai/design\` (single barrel \u2014 no \`/primitives\` / \`/components\` subpaths), \`@ggui-ai/wire\`, \`@ggui-ai/gadgets\`, or a gadget package the contract declares \u2014 never \`@ggui-ai/wire/internal\`. The iframe runtime rewrites exactly these specifiers to in-bundle shims; ANY other import fails at module evaluation and blanks the iframe (tier-0 \`imports\` fail). No \`require()\`.
|
|
726
|
+
|
|
727
|
+
Never call \`eval()\`, \`Function()\`, \`fetch()\` or the host-document APIs listed under "Where this renders" \u2014 tier-0 \`security\` fails them and the sandbox blocks them anyway.`;
|
|
728
|
+
var FREE_RESPONSIVE_INVARIANT = `## Responsive invariant
|
|
729
|
+
|
|
730
|
+
The component must fit the host-supplied iframe width at every point of the canvas range: \`width: 100%\` (plus \`max-width\` where you want to cap), never a fixed width, no horizontal scroll. Use \`@media\` / \`@container\` queries, \`clamp()\`, \`minmax()\`, \`auto-fit\` grids and \`flex-wrap\` freely. Compact chrome on \`xs-chat-card\` (the host draws the card border and shadow); own the chrome on the fullscreen canvases (\`mobile-fullscreen-small\`, \`md\`, \`lg\`, \`xl\`).`;
|
|
731
|
+
var FREE_ACCESSIBILITY = `## Accessibility (REQUIRED)
|
|
732
|
+
|
|
733
|
+
With raw elements YOU own the semantics \u2014 nothing is accessible by construction unless you import a \`@ggui-ai/design\` primitive (those carry their own roles / labels / keyboard handling; don't re-declare ARIA on them).
|
|
734
|
+
|
|
735
|
+
1. **Interactive = a real control.** A click target is a \`<button type="button">\` or an \`<a href>\` \u2014 never a bare \`<div onClick>\`. If a non-button element must be clickable, add \`role="button"\`, \`tabIndex={0}\` and an \`onKeyDown\` handling Enter/Space.
|
|
736
|
+
2. **Form inputs have labels.** \`<label htmlFor={id}>\` paired with the input's \`id\`, or \`aria-label\`; errors via \`aria-invalid\` + \`aria-describedby\`.
|
|
737
|
+
3. **Images have \`alt\`** (\`alt=""\` for decorative). Icon-only buttons need \`aria-label\`; decorative icons and emoji are \`aria-hidden="true"\`.
|
|
738
|
+
4. **Live & streaming data** (a \`useStream\` \`.latest\` value, counters, clocks, flashing prices) sits in an \`aria-live="polite"\` (or \`role="status"\`) region so screen readers announce the change.
|
|
739
|
+
5. **Headings nest**: one \`<h1>\` per screen, \`<h2>\` for sections, \`<h3>\` below \u2014 never skipped or inverted.
|
|
740
|
+
6. **Busy state is announced**: every control that dispatches an action (a button, a select whose change dispatches, an input that sends on Enter) stays pending from \`useActionPending('<action>')\` until the agent's answer repaints the card \u2014 \`<button disabled={sendPending} aria-busy={sendPending}>{sendPending ? 'Sending\u2026' : 'Send'}</button>\`. Only a control that dispatches the action carries its busy look; while it is pending, other controls of the same record may be disabled \u2014 nothing more (controls of other records, creation controls and the action's own cancel stay enabled); busy state the card owns (\`isLoading\`) the same way.
|
|
741
|
+
7. **Stateful controls announce state**: \`role="checkbox"\` + \`aria-checked\` on a toggleable row, \`aria-pressed\` on a toggle button, \`aria-selected\` on the chosen item, \`aria-expanded\` on an open/close affordance. Styling (strikethrough, color, a check mark) is never the only carrier of state.
|
|
742
|
+
8. **Focus is visible** \u2014 style \`:focus-visible\` with a token color; never \`outline: none\` without a replacement.`;
|
|
743
|
+
var FREE_QUALITY_CHECKLIST = `## Quality Checklist (verify before returning)
|
|
744
|
+
|
|
745
|
+
- [ ] Imports ONLY from: react, react-dom, @ggui-ai/design, @ggui-ai/wire, @ggui-ai/gadgets (+ contract gadget packages)
|
|
746
|
+
- [ ] ZERO literal colors \u2014 every color is a bare \`var(--ggui-color-*)\` from the manifest; no hex / rgb() / hsl() / named colors, no fallbacks \u2014 in \`style\` props AND \`<style>\` blocks
|
|
747
|
+
- [ ] Fluid width (\`width: 100%\`, \`max-width\`), holds across the whole canvas range, no horizontal scroll
|
|
748
|
+
- [ ] Typed Props interface exported; request-specific data is a prop with default
|
|
749
|
+
- [ ] Every \`useAction\` binding is wired to exactly ONE gesture surface \u2014 no handler on both a parent and a child
|
|
750
|
+
- [ ] Real controls (\`<button>\`, \`<a>\`, \`<input>\` + \`<label>\`), \`alt\` on images, \`aria-label\` on icon-only buttons
|
|
751
|
+
- [ ] State is ARIA-expressed (\`aria-checked\` / \`aria-pressed\` / \`aria-selected\` / \`aria-expanded\`) \u2014 never style-only
|
|
752
|
+
- [ ] Live/streaming regions wrapped in \`aria-live="polite"\`
|
|
753
|
+
- [ ] Headings nest \u2014 one \`<h1>\`, then \`<h2>\` / \`<h3>\` \u2014 never skipped or inverted
|
|
754
|
+
- [ ] No \`fetch\` / \`eval\` / \`window\` / \`document\` / \`localStorage\` / external stylesheets or fonts
|
|
755
|
+
- [ ] Source \u2264 50 KB / \u2264 500 lines; wire hooks (\`useAction\`, \`useStream\`, \`useGguiContext\`) kept and consumed`;
|
|
756
|
+
var FREE_SHAPE_GUIDANCE_NOTE = "In this mode the design-package components named above (`<Stepper>`, `<Modal>`, `<Card>`, `<Row>`, `<CardGrid>`) are defaults, not requirements \u2014 any composition that satisfies the behavioural rule (track the step index in state, a close affordance + focus trap, `key={item.id}`, no horizontal scroll) is acceptable. The crash anti-patterns are mandatory.";
|
|
757
|
+
var TOKEN_GROUPS = [
|
|
758
|
+
{ label: "Color (mandatory for every color)", prefixes: ["--ggui-color-"], note: "" },
|
|
759
|
+
{ label: "Spacing (optional \u2014 literals are fine)", prefixes: ["--ggui-spacing-"], note: "" },
|
|
760
|
+
{ label: "Typography (optional)", prefixes: ["--ggui-font-"], note: "" },
|
|
761
|
+
{ label: "Radius (optional)", prefixes: ["--ggui-shape-radius-"], note: "" },
|
|
762
|
+
{ label: "Shadow (optional)", prefixes: ["--ggui-shape-shadow-"], note: "" }
|
|
763
|
+
];
|
|
764
|
+
function renderTokenVocabulary(manifest = taughtTokenManifest) {
|
|
765
|
+
const sorted = [...manifest].sort();
|
|
766
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
767
|
+
const lines = [
|
|
768
|
+
"### Reference (optional): theme token vocabulary",
|
|
769
|
+
"",
|
|
770
|
+
"The closed manifest \u2014 the ONLY `--ggui-*` names the runtime defines on `:root`. Color names are mandatory for color; the rest are optional conveniences.",
|
|
771
|
+
""
|
|
772
|
+
];
|
|
773
|
+
for (const group of TOKEN_GROUPS) {
|
|
774
|
+
const names = sorted.filter((t) => group.prefixes.some((p) => t.startsWith(p)));
|
|
775
|
+
if (names.length === 0) continue;
|
|
776
|
+
for (const n of names) claimed.add(n);
|
|
777
|
+
lines.push(`- **${group.label}**: ${names.map((n) => `\`${n}\``).join(", ")}`);
|
|
778
|
+
}
|
|
779
|
+
const other = sorted.filter((t) => !claimed.has(t));
|
|
780
|
+
if (other.length > 0) {
|
|
781
|
+
lines.push(`- **Other**: ${other.map((n) => `\`${n}\``).join(", ")}`);
|
|
782
|
+
}
|
|
783
|
+
return lines.join("\n");
|
|
784
|
+
}
|
|
785
|
+
function buildFreeDesignPrompt(inputs) {
|
|
786
|
+
const axisSection = inputs.axisSection.length > 0 ? `${inputs.axisSection}
|
|
787
|
+
${FREE_SHAPE_GUIDANCE_NOTE}
|
|
788
|
+
` : "";
|
|
789
|
+
const head = `You are ggui's UI builder. You receive a typed boilerplate and fill it in using apply_changes.
|
|
790
|
+
|
|
791
|
+
## Your Task
|
|
792
|
+
${inputs.userRequest}
|
|
793
|
+
|
|
794
|
+
## Rendering canvas
|
|
795
|
+
${describeCanvas(inputs.canvas)}
|
|
796
|
+
|
|
797
|
+
## How It Works
|
|
798
|
+
1. Read the boilerplate \u2014 typed Props and wire hooks are pre-configured; the JSX body and its styling are yours to compose
|
|
799
|
+
2. Respond with one apply_changes call \u2014 add state, helpers, styles and JSX
|
|
800
|
+
3. If compilation or evaluation fails, you'll get errors to fix in the next turn
|
|
801
|
+
|
|
802
|
+
${inputs.criteriaBlock}
|
|
803
|
+
${axisSection}
|
|
804
|
+
`;
|
|
805
|
+
const sections = [
|
|
806
|
+
PROTOCOL_NOTES,
|
|
807
|
+
CONTRACT_SURFACE,
|
|
808
|
+
DEFENSIVE_CODING,
|
|
809
|
+
GESTURE_ROUTING,
|
|
810
|
+
TERMINAL_ACTIONS,
|
|
811
|
+
FREE_GESTURE_SURFACE,
|
|
812
|
+
ANTI_PATTERNS,
|
|
813
|
+
CROSS_REFERENCE_RULES,
|
|
814
|
+
renderGadgetCatalogSection(inputs.gadgetsSection),
|
|
815
|
+
CONTEXT_SPEC_SECTION,
|
|
816
|
+
`## Reference: Wire Hooks
|
|
817
|
+
${inputs.wireDoc}`,
|
|
818
|
+
FREE_DESIGN_FREEDOM,
|
|
819
|
+
FREE_COLOR_RULE,
|
|
820
|
+
FREE_HOST_ENVELOPE,
|
|
821
|
+
FREE_BUDGETS,
|
|
822
|
+
FREE_IMPORTS_AND_SECURITY,
|
|
823
|
+
DATA_PARAMETERIZATION,
|
|
824
|
+
FRAME_SIZING,
|
|
825
|
+
COMPONENT_STRUCTURE,
|
|
826
|
+
FREE_RESPONSIVE_INVARIANT,
|
|
827
|
+
FREE_ACCESSIBILITY,
|
|
828
|
+
...inputs.profileSection !== void 0 && inputs.profileSection.length > 0 ? [inputs.profileSection] : [],
|
|
829
|
+
FREE_QUALITY_CHECKLIST,
|
|
830
|
+
renderTokenVocabulary(),
|
|
831
|
+
`### Reference (optional): \`@ggui-ai/design\` component catalog
|
|
832
|
+
|
|
833
|
+
Optional \u2014 import a primitive only when it helps. Raw HTML + your own CSS is a first-class choice.
|
|
834
|
+
|
|
835
|
+
${inputs.primitivesDoc}`
|
|
836
|
+
];
|
|
837
|
+
return head + sections.join("\n\n") + "\n";
|
|
838
|
+
}
|
|
839
|
+
var VIRTUAL_DTS_PATH = "/__gadget__.d.ts";
|
|
840
|
+
var EXTRACTOR_COMPILER_OPTIONS = {
|
|
841
|
+
target: ts.ScriptTarget.ESNext,
|
|
842
|
+
module: ts.ModuleKind.ESNext,
|
|
843
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
844
|
+
allowJs: false,
|
|
845
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
846
|
+
noEmit: true,
|
|
847
|
+
esModuleInterop: true,
|
|
848
|
+
// skipLibCheck so an unresolvable wrapper-internal import (the
|
|
849
|
+
// sandbox doesn't carry the wrapper's transitive deps) doesn't abort
|
|
850
|
+
// the program before we can read the symbol's callable signature.
|
|
851
|
+
skipLibCheck: true,
|
|
852
|
+
strict: true
|
|
853
|
+
};
|
|
854
|
+
var callSignatureCache = /* @__PURE__ */ new Map();
|
|
855
|
+
var componentPropsCache = /* @__PURE__ */ new Map();
|
|
856
|
+
function buildExtractorContext(dtsContent, names) {
|
|
857
|
+
const sourceFile = ts.createSourceFile(
|
|
858
|
+
VIRTUAL_DTS_PATH,
|
|
859
|
+
dtsContent,
|
|
860
|
+
ts.ScriptTarget.ESNext,
|
|
861
|
+
/* setParentNodes */
|
|
862
|
+
true,
|
|
863
|
+
ts.ScriptKind.TS
|
|
864
|
+
);
|
|
865
|
+
const defaultLibName = ts.getDefaultLibFileName(EXTRACTOR_COMPILER_OPTIONS);
|
|
866
|
+
const host = {
|
|
867
|
+
getSourceFile(fileName) {
|
|
868
|
+
if (fileName === VIRTUAL_DTS_PATH) return sourceFile;
|
|
869
|
+
const libContent = ts.sys.readFile(
|
|
870
|
+
ts.getDefaultLibFilePath(EXTRACTOR_COMPILER_OPTIONS).replace(
|
|
871
|
+
/[^/\\]+$/,
|
|
872
|
+
fileName
|
|
873
|
+
)
|
|
874
|
+
);
|
|
875
|
+
if (libContent !== void 0) {
|
|
876
|
+
return ts.createSourceFile(
|
|
877
|
+
fileName,
|
|
878
|
+
libContent,
|
|
879
|
+
ts.ScriptTarget.ESNext,
|
|
880
|
+
true,
|
|
881
|
+
ts.ScriptKind.TS
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
return void 0;
|
|
885
|
+
},
|
|
886
|
+
getDefaultLibFileName() {
|
|
887
|
+
return defaultLibName;
|
|
888
|
+
},
|
|
889
|
+
writeFile() {
|
|
890
|
+
},
|
|
891
|
+
getCurrentDirectory() {
|
|
892
|
+
return "/";
|
|
893
|
+
},
|
|
894
|
+
getCanonicalFileName(f) {
|
|
895
|
+
return f;
|
|
896
|
+
},
|
|
897
|
+
useCaseSensitiveFileNames() {
|
|
898
|
+
return true;
|
|
899
|
+
},
|
|
900
|
+
getNewLine() {
|
|
901
|
+
return "\n";
|
|
902
|
+
},
|
|
903
|
+
fileExists(f) {
|
|
904
|
+
if (f === VIRTUAL_DTS_PATH) return true;
|
|
905
|
+
return ts.sys.fileExists(f);
|
|
906
|
+
},
|
|
907
|
+
readFile(f) {
|
|
908
|
+
if (f === VIRTUAL_DTS_PATH) return dtsContent;
|
|
909
|
+
return ts.sys.readFile(f);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
const program = ts.createProgram(
|
|
913
|
+
[VIRTUAL_DTS_PATH],
|
|
914
|
+
EXTRACTOR_COMPILER_OPTIONS,
|
|
915
|
+
host
|
|
916
|
+
);
|
|
917
|
+
const checker = program.getTypeChecker();
|
|
918
|
+
const parsed = program.getSourceFile(VIRTUAL_DTS_PATH);
|
|
919
|
+
if (parsed === void 0) {
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
const requested = new Set(names);
|
|
923
|
+
function isWrapperLocal(symbol) {
|
|
924
|
+
const decls = symbol?.getDeclarations();
|
|
925
|
+
if (decls === void 0) return false;
|
|
926
|
+
return decls.some((d) => d.getSourceFile().fileName === VIRTUAL_DTS_PATH);
|
|
927
|
+
}
|
|
928
|
+
const MAX_DEPTH = 4;
|
|
929
|
+
function renderType(t, depth) {
|
|
930
|
+
const plain = () => checker.typeToString(t, void 0, ts.TypeFormatFlags.NoTruncation);
|
|
931
|
+
if (depth >= MAX_DEPTH) return plain();
|
|
932
|
+
if ((t.getFlags() & ts.TypeFlags.Boolean) !== 0) return "boolean";
|
|
933
|
+
if (t.isUnion()) {
|
|
934
|
+
return t.types.map((member) => renderType(member, depth)).join(" | ");
|
|
935
|
+
}
|
|
936
|
+
if (t.isIntersection()) {
|
|
937
|
+
return t.types.map((member) => renderType(member, depth)).join(" & ");
|
|
938
|
+
}
|
|
939
|
+
const symbol = t.getSymbol() ?? t.aliasSymbol;
|
|
940
|
+
const callSigs = t.getCallSignatures();
|
|
941
|
+
if (callSigs.length > 0) {
|
|
942
|
+
const cs = callSigs[0];
|
|
943
|
+
const params = cs.getParameters().map((p) => {
|
|
944
|
+
const decl = p.valueDeclaration ?? p.declarations?.[0];
|
|
945
|
+
const pType = decl !== void 0 ? checker.getTypeOfSymbolAtLocation(p, decl) : checker.getDeclaredTypeOfSymbol(p);
|
|
946
|
+
const optional = decl !== void 0 && ts.isParameter(decl) && (decl.questionToken !== void 0 || decl.initializer !== void 0);
|
|
947
|
+
return `${p.getName()}${optional ? "?" : ""}: ${renderType(pType, depth + 1)}`;
|
|
948
|
+
}).join(", ");
|
|
949
|
+
const ret = renderType(cs.getReturnType(), depth + 1);
|
|
950
|
+
return `(${params}) => ${ret}`;
|
|
951
|
+
}
|
|
952
|
+
const isObject = (t.getFlags() & ts.TypeFlags.Object) !== 0;
|
|
953
|
+
const isArrayOrTuple = checker.isArrayType(t) || checker.isTupleType(t);
|
|
954
|
+
const typeArgs = t.typeArguments;
|
|
955
|
+
if (symbol !== void 0 && isObject && !isArrayOrTuple && !isWrapperLocal(symbol) && typeArgs !== void 0 && typeArgs.length > 0) {
|
|
956
|
+
const args = typeArgs.map((a) => renderType(a, depth + 1)).join(", ");
|
|
957
|
+
return `${symbol.getName()}<${args}>`;
|
|
958
|
+
}
|
|
959
|
+
if (symbol !== void 0 && isObject && !isArrayOrTuple && isWrapperLocal(symbol)) {
|
|
960
|
+
const props = checker.getPropertiesOfType(t);
|
|
961
|
+
if (props.length > 0) {
|
|
962
|
+
const body = props.map((p) => {
|
|
963
|
+
const decl = p.valueDeclaration ?? p.declarations?.[0];
|
|
964
|
+
const pType = decl !== void 0 ? checker.getTypeOfSymbolAtLocation(p, decl) : checker.getDeclaredTypeOfSymbol(p);
|
|
965
|
+
const optional = (p.getFlags() & ts.SymbolFlags.Optional) !== 0;
|
|
966
|
+
return `${p.getName()}${optional ? "?" : ""}: ${renderType(pType, depth + 1)}`;
|
|
967
|
+
}).join("; ");
|
|
968
|
+
return `{ ${body} }`;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return plain();
|
|
972
|
+
}
|
|
973
|
+
const moduleSymbol = checker.getSymbolAtLocation(parsed);
|
|
974
|
+
const exportSymbols = moduleSymbol !== void 0 ? checker.getExportsOfModule(moduleSymbol) : [];
|
|
975
|
+
const signaturesByName = /* @__PURE__ */ new Map();
|
|
976
|
+
for (const symbol of exportSymbols) {
|
|
977
|
+
const name = symbol.getName();
|
|
978
|
+
if (!requested.has(name)) continue;
|
|
979
|
+
if (signaturesByName.has(name)) continue;
|
|
980
|
+
const resolved = (symbol.flags & ts.SymbolFlags.Alias) !== 0 ? checker.getAliasedSymbol(symbol) : symbol;
|
|
981
|
+
const declarations = resolved.getDeclarations();
|
|
982
|
+
if (declarations === void 0 || declarations.length === 0) continue;
|
|
983
|
+
const declaration = declarations[0];
|
|
984
|
+
const type = checker.getTypeOfSymbolAtLocation(resolved, declaration);
|
|
985
|
+
const callSignatures = type.getCallSignatures();
|
|
986
|
+
if (callSignatures.length === 0) continue;
|
|
987
|
+
signaturesByName.set(name, callSignatures);
|
|
988
|
+
}
|
|
989
|
+
return { checker, renderType, signaturesByName };
|
|
990
|
+
}
|
|
991
|
+
function printCallSignature(sig, ctx) {
|
|
992
|
+
const params = sig.getParameters().map((p) => {
|
|
993
|
+
const decl = p.valueDeclaration ?? p.declarations?.[0];
|
|
994
|
+
const pType = decl !== void 0 ? ctx.checker.getTypeOfSymbolAtLocation(p, decl) : ctx.checker.getDeclaredTypeOfSymbol(p);
|
|
995
|
+
const optional = decl !== void 0 && ts.isParameter(decl) && (decl.questionToken !== void 0 || decl.initializer !== void 0);
|
|
996
|
+
return `${p.getName()}${optional ? "?" : ""}: ${ctx.renderType(pType, 0)}`;
|
|
997
|
+
}).join(", ");
|
|
998
|
+
const ret = ctx.renderType(sig.getReturnType(), 0);
|
|
999
|
+
return `(${params}) => ${ret}`.trim();
|
|
1000
|
+
}
|
|
1001
|
+
function printComponentProps(sig, ctx) {
|
|
1002
|
+
const params = sig.getParameters();
|
|
1003
|
+
if (params.length === 0) return "{}";
|
|
1004
|
+
const propsParam = params[0];
|
|
1005
|
+
const decl = propsParam.valueDeclaration ?? propsParam.declarations?.[0];
|
|
1006
|
+
const propsType = decl !== void 0 ? ctx.checker.getTypeOfSymbolAtLocation(propsParam, decl) : ctx.checker.getDeclaredTypeOfSymbol(propsParam);
|
|
1007
|
+
const rendered = ctx.renderType(propsType, 0);
|
|
1008
|
+
if (rendered.length === 0 || rendered.includes('import("')) return void 0;
|
|
1009
|
+
return rendered;
|
|
1010
|
+
}
|
|
1011
|
+
function extractCallSignaturesFromDts(dtsContent, hookNames) {
|
|
1012
|
+
if (hookNames.length === 0 || dtsContent.trim().length === 0) {
|
|
1013
|
+
return {};
|
|
1014
|
+
}
|
|
1015
|
+
const cacheKey = `${dtsContent}\0${[...hookNames].sort().join(",")}`;
|
|
1016
|
+
const cached = callSignatureCache.get(cacheKey);
|
|
1017
|
+
if (cached !== void 0) return cached;
|
|
1018
|
+
const result = {};
|
|
1019
|
+
const ctx = buildExtractorContext(dtsContent, hookNames);
|
|
1020
|
+
if (ctx === void 0) {
|
|
1021
|
+
callSignatureCache.set(cacheKey, result);
|
|
1022
|
+
return result;
|
|
1023
|
+
}
|
|
1024
|
+
for (const [name, signatures] of ctx.signaturesByName) {
|
|
1025
|
+
const printed = signatures.map((sig) => printCallSignature(sig, ctx)).filter((s) => s.length > 0 && !s.includes('import("')).join(" | ");
|
|
1026
|
+
if (printed.length > 0) {
|
|
1027
|
+
result[name] = printed;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
callSignatureCache.set(cacheKey, result);
|
|
1031
|
+
return result;
|
|
1032
|
+
}
|
|
1033
|
+
function extractComponentPropsFromDts(dtsContent, componentNames) {
|
|
1034
|
+
if (componentNames.length === 0 || dtsContent.trim().length === 0) {
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
const cacheKey = `${dtsContent}\0${[...componentNames].sort().join(",")}`;
|
|
1038
|
+
const cached = componentPropsCache.get(cacheKey);
|
|
1039
|
+
if (cached !== void 0) return cached;
|
|
1040
|
+
const result = {};
|
|
1041
|
+
const ctx = buildExtractorContext(dtsContent, componentNames);
|
|
1042
|
+
if (ctx === void 0) {
|
|
1043
|
+
componentPropsCache.set(cacheKey, result);
|
|
1044
|
+
return result;
|
|
1045
|
+
}
|
|
1046
|
+
for (const [name, signatures] of ctx.signaturesByName) {
|
|
1047
|
+
const first = signatures[0];
|
|
1048
|
+
if (first === void 0) continue;
|
|
1049
|
+
const props = printComponentProps(first, ctx);
|
|
1050
|
+
if (props !== void 0) {
|
|
1051
|
+
result[name] = props;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
componentPropsCache.set(cacheKey, result);
|
|
1055
|
+
return result;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// src/boilerplate/system-prompt.ts
|
|
1059
|
+
function isHookExport(exp) {
|
|
1060
|
+
return "hook" in exp;
|
|
1061
|
+
}
|
|
1062
|
+
function isComponentExport(exp) {
|
|
1063
|
+
return "component" in exp;
|
|
1064
|
+
}
|
|
1065
|
+
var SHELL_DESCRIPTIONS = {
|
|
1066
|
+
chat: "inline component inside ChatShell message bubble (~400px wide, compact)",
|
|
1067
|
+
fullscreen: "the full host viewport, responsive layout \u2014 the frame stretches your root to its height; size to content, never to the viewport",
|
|
1068
|
+
spatial: "floating AR/VR panel (~600px, touch-friendly)"
|
|
1069
|
+
};
|
|
1070
|
+
var SCREEN_DESCRIPTIONS = {
|
|
1071
|
+
mobile: "single column, large touch targets",
|
|
1072
|
+
tablet: "flexible columns, medium spacing",
|
|
1073
|
+
desktop: "multi-column, dense layout",
|
|
1074
|
+
universal: "responsive across all breakpoints"
|
|
1075
|
+
};
|
|
1076
|
+
function formatGadgetsSection(appGadgets, gadgetTypes) {
|
|
1077
|
+
if (appGadgets.length === 0) {
|
|
1078
|
+
return [
|
|
1079
|
+
"When the contract declares a `clientCapabilities.gadgets` entry,",
|
|
1080
|
+
"the hook MUST be one the operator has registered on",
|
|
1081
|
+
"`App.gadgets`. The default ggui server seeds the 7",
|
|
1082
|
+
"first-party STDLIB hooks; this server has none registered (the",
|
|
1083
|
+
"operator's `ggui.json#app.gadgets` is empty). Don't",
|
|
1084
|
+
"declare `clientCapabilities.gadgets` until a hook is registered."
|
|
1085
|
+
].join(" ");
|
|
1086
|
+
}
|
|
1087
|
+
const hookExports = appGadgets.flatMap(
|
|
1088
|
+
(descriptor) => descriptor.exports.filter(isHookExport).map((exp) => ({ exp, descriptor }))
|
|
1089
|
+
);
|
|
1090
|
+
const componentExports = appGadgets.flatMap(
|
|
1091
|
+
(descriptor) => descriptor.exports.filter(isComponentExport).map((exp) => ({ exp, descriptor }))
|
|
1092
|
+
);
|
|
1093
|
+
const header = "When the contract declares a hook gadget on `clientCapabilities.gadgets`, the hook MUST be one of the registered hooks below. The boilerplate has already emitted a direct import per gadget package \u2014 `import { <hook>, \u2026 } from '<package>'` \u2014 above a `// DO NOT EDIT` banner. KEEP those imports exactly; they are the runtime-resolution anchor and self_check rejects the code if one disappears. Import each STDLIB hook from `@ggui-ai/gadgets`; import each third-party hook from the package named in the `Package` column. DO NOT invent your own import paths. Available registered hooks:";
|
|
1094
|
+
const tableHead = [
|
|
1095
|
+
"| Hook | Package (import from here) | Permission | What it does |",
|
|
1096
|
+
"| --------------------- | ---------------------------------- | ------------------ | ------------------------------------------- |"
|
|
1097
|
+
];
|
|
1098
|
+
const rows = hookExports.map(({ exp, descriptor }) => {
|
|
1099
|
+
const hookCol = `\`${exp.hook}\``.padEnd(21, " ");
|
|
1100
|
+
const pkgCol = `\`${descriptor.package}\``.padEnd(34, " ");
|
|
1101
|
+
const permCol = exp.permission ? `\`${exp.permission}\``.padEnd(18, " ") : "(none)".padEnd(18, " ");
|
|
1102
|
+
const what = (exp.usage ?? exp.description ?? "").replace(/\s+/g, " ").trim().slice(0, 80);
|
|
1103
|
+
return `| ${hookCol} | ${pkgCol} | ${permCol} | ${what.padEnd(43, " ")} |`;
|
|
1104
|
+
});
|
|
1105
|
+
const typeLines = [];
|
|
1106
|
+
if (gadgetTypes !== void 0) {
|
|
1107
|
+
for (const { exp, descriptor } of hookExports) {
|
|
1108
|
+
const dts = gadgetTypes[descriptor.package];
|
|
1109
|
+
if (dts === void 0) continue;
|
|
1110
|
+
const signatures = extractCallSignaturesFromDts(dts, [exp.hook]);
|
|
1111
|
+
const sig = signatures[exp.hook];
|
|
1112
|
+
if (sig === void 0) continue;
|
|
1113
|
+
typeLines.push(`- \`${exp.hook}\`: \`${sig}\``);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
const typeBlock = typeLines.length > 0 ? [
|
|
1117
|
+
"",
|
|
1118
|
+
"**Type** (third-party gadgets \u2014 call signature from the wrapper's published `.d.ts`):",
|
|
1119
|
+
"",
|
|
1120
|
+
...typeLines
|
|
1121
|
+
] : [];
|
|
1122
|
+
const hookSection = hookExports.length > 0 ? [header, "", ...tableHead, ...rows, ...typeBlock].join("\n") : "";
|
|
1123
|
+
const componentRows = componentExports.map(({ exp, descriptor }) => {
|
|
1124
|
+
const compCol = `\`${exp.component}\``.padEnd(21, " ");
|
|
1125
|
+
const pkgCol = `\`${descriptor.package}\``.padEnd(34, " ");
|
|
1126
|
+
const what = (exp.usage ?? exp.description ?? "").replace(/\s+/g, " ").trim().slice(0, 80);
|
|
1127
|
+
return `| ${compCol} | ${pkgCol} | ${what.padEnd(53, " ")} |`;
|
|
1128
|
+
});
|
|
1129
|
+
const componentPropsLines = [];
|
|
1130
|
+
if (gadgetTypes !== void 0) {
|
|
1131
|
+
for (const { exp, descriptor } of componentExports) {
|
|
1132
|
+
const dts = gadgetTypes[descriptor.package];
|
|
1133
|
+
if (dts === void 0) continue;
|
|
1134
|
+
const propsMap = extractComponentPropsFromDts(dts, [exp.component]);
|
|
1135
|
+
const props = propsMap[exp.component];
|
|
1136
|
+
if (props === void 0) continue;
|
|
1137
|
+
componentPropsLines.push(`- \`${exp.component}\`: \`${props}\``);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
const componentPropsBlock = componentPropsLines.length > 0 ? [
|
|
1141
|
+
"",
|
|
1142
|
+
"**Props** (third-party component gadgets \u2014 prop shape from the wrapper's published `.d.ts`):",
|
|
1143
|
+
"",
|
|
1144
|
+
...componentPropsLines
|
|
1145
|
+
] : [];
|
|
1146
|
+
const componentSection = componentExports.length > 0 ? [
|
|
1147
|
+
"When the contract declares a component gadget on `clientCapabilities.gadgets`, the export is a COMPONENT \u2014 RENDER it as a JSX element (`<X \u2026 />`) in the tree you return. Do NOT call it like a hook. The boilerplate has already emitted a direct import per gadget package \u2014 `import { <Component>, \u2026 } from '<package>'` \u2014 above a `// DO NOT EDIT` banner. KEEP those imports exactly; they are the runtime-resolution anchor and self_check rejects the code if one disappears. Import each component from the package named in the `Package` column. Available registered components:",
|
|
1148
|
+
"",
|
|
1149
|
+
"| Component | Package (import from here) | What it does |",
|
|
1150
|
+
"| --------------------- | ---------------------------------- | ----------------------------------------------------- |",
|
|
1151
|
+
...componentRows,
|
|
1152
|
+
...componentPropsBlock
|
|
1153
|
+
].join("\n") : "";
|
|
1154
|
+
return [hookSection, componentSection].filter((section) => section.length > 0).join("\n\n");
|
|
1155
|
+
}
|
|
1156
|
+
function buildSystemPrompt(inputs) {
|
|
1157
|
+
const shell = inputs.shellType ?? "fullscreen";
|
|
1158
|
+
const scr = inputs.screen ?? "universal";
|
|
1159
|
+
const shellDesc = SHELL_DESCRIPTIONS[shell] ?? SHELL_DESCRIPTIONS.fullscreen;
|
|
1160
|
+
const screenDesc = SCREEN_DESCRIPTIONS[scr] ?? SCREEN_DESCRIPTIONS.universal;
|
|
1161
|
+
const designMode = inputs.designMode ?? DEFAULT_DESIGN_MODE;
|
|
1162
|
+
const criteriaBlock = inputs.criteriaBlock ?? buildCodingCriteriaSummary(designMode);
|
|
1163
|
+
const pitfallsBlock = inputs.pitfallsBlock ?? "";
|
|
1164
|
+
const designSystemDocs = inputs.designSystemDocs ?? "";
|
|
1165
|
+
const primitivesDoc = inputs.primitivesDoc ?? "";
|
|
1166
|
+
const wireDoc = inputs.wireDoc ?? "";
|
|
1167
|
+
const gadgetsSection = formatGadgetsSection(
|
|
1168
|
+
resolveAppGadgets(inputs.appGadgets),
|
|
1169
|
+
inputs.gadgetTypes
|
|
1170
|
+
);
|
|
1171
|
+
const profileSection = buildStylingProfileSection(inputs.profile);
|
|
1172
|
+
const axisSection = inputs.axisDelta && inputs.axisDelta.trim().length > 0 ? `
|
|
1173
|
+
## Shape Guidance
|
|
1174
|
+
${inputs.axisDelta}
|
|
1175
|
+
` : "";
|
|
1176
|
+
if (designMode === "free") {
|
|
1177
|
+
return buildFreeDesignPrompt({
|
|
1178
|
+
userRequest: inputs.userRequest,
|
|
1179
|
+
canvas: inputs.canvas ?? canvasForRendering(inputs.shellType, inputs.screen),
|
|
1180
|
+
axisSection,
|
|
1181
|
+
criteriaBlock,
|
|
1182
|
+
wireDoc,
|
|
1183
|
+
primitivesDoc,
|
|
1184
|
+
gadgetsSection,
|
|
1185
|
+
profileSection
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
return `You are ggui's UI builder. You receive a typed boilerplate and fill it in using apply_changes.
|
|
1189
|
+
|
|
1190
|
+
## Your Task
|
|
1191
|
+
${inputs.userRequest}
|
|
1192
|
+
|
|
1193
|
+
## Rendering Context
|
|
1194
|
+
- **Shell**: \`${shell}\` \u2014 ${shellDesc}
|
|
1195
|
+
- **Screen**: \`${scr}\` \u2014 ${screenDesc}
|
|
1196
|
+
|
|
1197
|
+
## How It Works
|
|
1198
|
+
1. Read the boilerplate \u2014 typed Props, wire hooks, and layout container are pre-configured
|
|
1199
|
+
2. Respond with one apply_changes call \u2014 add state, helpers, and JSX
|
|
1200
|
+
3. If compilation or evaluation fails, you'll get errors to fix in the next turn
|
|
1201
|
+
|
|
1202
|
+
${criteriaBlock}
|
|
1203
|
+
${axisSection}
|
|
1204
|
+
` + [
|
|
1205
|
+
PROTOCOL_NOTES,
|
|
1206
|
+
CONTRACT_SURFACE,
|
|
1207
|
+
DEFENSIVE_CODING,
|
|
1208
|
+
GESTURE_ROUTING,
|
|
1209
|
+
TERMINAL_ACTIONS,
|
|
1210
|
+
INTERACTIVE_TRAITS,
|
|
1211
|
+
ANTI_PATTERNS,
|
|
1212
|
+
CROSS_REFERENCE_RULES,
|
|
1213
|
+
renderGadgetCatalogSection(gadgetsSection),
|
|
1214
|
+
CONTEXT_SPEC_SECTION
|
|
1215
|
+
].join("\n\n") + `
|
|
1216
|
+
|
|
1217
|
+
${pitfallsBlock}
|
|
1218
|
+
|
|
1219
|
+
## Reference: Wire Hooks
|
|
1220
|
+
${wireDoc}
|
|
1221
|
+
|
|
1222
|
+
${withStylingProfile(DESIGN_SYSTEM_GUIDANCE, profileSection)}
|
|
1223
|
+
|
|
1224
|
+
### CSS Token Documentation
|
|
1225
|
+
${designSystemDocs}
|
|
1226
|
+
|
|
1227
|
+
### Component Reference
|
|
1228
|
+
${primitivesDoc}
|
|
1229
|
+
`;
|
|
1230
|
+
}
|
|
1231
|
+
var DESIGN_SYSTEM_GUIDANCE_SURFACE_AND_TOKENS = `## Imports & Component Surface
|
|
1232
|
+
|
|
1233
|
+
Import ONLY from: \`react\`, \`@ggui-ai/design\`, \`@ggui-ai/wire\`. The ENTIRE design system \u2014 every primitive, component, composition and trait \u2014 is exported from the single \`@ggui-ai/design\` entry: \`import { Card, Grid, Stack, Modal, Clickable } from '@ggui-ai/design'\`. There are NO subpaths (\`/primitives\`, \`/components\`, \u2026) \u2014 never import from them. Use the design components \u2014 DO NOT use raw HTML elements (\`<button>\`, \`<input>\`, \`<div>\` for layout) or Tailwind classes; those render unstyled in the iframe runtime.
|
|
1234
|
+
|
|
1235
|
+
Available primitives (all from \`@ggui-ai/design\`):
|
|
1236
|
+
- Layout: Box, Container, Stack, Row, Grid, Spacer, Divider
|
|
1237
|
+
- Typography: Heading, Text, Link
|
|
1238
|
+
- Form: Button, Input, TextArea, Checkbox, Toggle, RadioGroup, Select, Slider
|
|
1239
|
+
- Display: Card, Alert, Badge, Avatar, Image, Icon, Progress, Spinner, Skeleton, Tooltip
|
|
1240
|
+
- Composite: Accordion, Tabs, Table, Toast
|
|
1241
|
+
|
|
1242
|
+
Available compound components (all from \`@ggui-ai/design\`):
|
|
1243
|
+
- Autocomplete, Breadcrumb, Dropdown, EmptyState, FormField, Markdown, MarkdownInline, MenuItem, Pagination, SearchField, Stat, Stepper, Tag
|
|
1244
|
+
|
|
1245
|
+
**Choosing between similar components** \u2014 pick by intent, don't guess:
|
|
1246
|
+
- **Pick from options**: one value from a short fixed list (a form field) \u2192 \`Select\`. Type-to-filter a long list, then pick \u2192 \`Autocomplete\`. A menu of actions off a button (edit / delete / \u2026) \u2192 \`Dropdown\`. A search box that filters displayed content \u2192 \`SearchField\`.
|
|
1247
|
+
- **Tabular data** \u2192 \`Table\`. Reach for \`DataTable\` ONLY when you need built-in sorting / pagination / row-selection.
|
|
1248
|
+
- **Messaging**: an inline message in the layout flow \u2192 \`Alert\`. A transient popup \u2192 \`Toast\`. A panel listing many notifications \u2192 \`NotificationCenter\`.
|
|
1249
|
+
- **Step progress**: a wizard's step indicator \u2192 \`Stepper\`. NOT \`Tabs\` (implies free navigation), NOT \`Progress\` (continuous bar), NOT \`Breadcrumb\` (hierarchy).
|
|
1250
|
+
- **Containers**: width-constrain a page region \u2192 \`Container\`. A visually-contained surface (background + shadow + border) \u2192 \`Card\`. Plain grouping / spacing with no chrome \u2192 \`Box\`.
|
|
1251
|
+
|
|
1252
|
+
EXACT primitive prop values (other values are silently ignored \u2014 the design system maps them to defaults):
|
|
1253
|
+
- \`<Text size="...">\` \u2014 ONLY \`xs | sm | base | lg | xl | 2xl | 3xl | 4xl\`. For a HUGE number/temperature, use \`<Text size="4xl" weight="bold">\`. \`caps\` uppercases with letter-spacing \u2014 the eyebrow/overline label look is \`<Text size="xs" weight="semibold" caps tone="muted">\`.
|
|
1254
|
+
- \`<Text weight="...">\` \u2014 \`normal | medium | semibold | bold\`.
|
|
1255
|
+
- \`<Text tone="...">\` \u2014 typed semantic slot. \`default | muted | subtle | emphasized | loud | success | warning | error | info | inverse | inherit\`. The theme decides what each tone LOOKS like \u2014 \`muted\` is a quiet warm grey on Claudic, a cool slate on Indigo. \`tone\` is the ONLY way to set Text color; the legacy \`color="..."\` prop has been removed.
|
|
1256
|
+
- \`<Heading level={1|2|3|4|5|6}>\` \u2014 sizes are preset by level (h1 = 4xl bold, h2 = 3xl bold, h3 = 2xl semibold). Pass a number, not \`level="h1"\`. Heading uses the same \`tone\` slot vocabulary as Text.
|
|
1257
|
+
- \`<Icon name="..." tone="...">\` / \`<Spinner tone="...">\` / \`<Link href="..." tone="...">\` / \`<Divider tone="...">\` \u2014 same \`tone\` vocabulary as Text. Default = \`currentColor\` (Icon), primary-tinted (Spinner / Link), outlineVariant (Divider). Use \`tone="inherit"\` when you want the element to track the parent's foreground color (e.g. an Icon next to muted text).
|
|
1258
|
+
- \`<Button variant="...">\` \u2014 \`primary | secondary | outline | ghost | danger\`. Sizes \`xs | sm | md | lg\`. Use \`primary\` for the main action \u2014 renders in the brand color automatically.
|
|
1259
|
+
- \`<Card padding="lg" shadow="md" radius="lg" surface="default">\` \u2014 shadow \`none|sm|md|lg|xl\`, radius \`none|sm|md|lg|xl\`. \`surface\` slot picks the fill: \`default | elevated | sunken | accent | inverted | hero | transparent\`. Use \`inverted\` for dark testimonial-style cards on a light theme; \`accent\` for branded fills; \`hero\` for the one hero / greeting panel (the theme's hero ground: brand-tinted on a light host, the ink pair on a dark one). \`inverted\` and \`hero\` OWN their ground \u2014 never set \`background\` in their \`style\` (tier-0 fails it); the surface paints it.
|
|
1260
|
+
- \`<Box surface="...">\` \u2014 same surface slots as Card. \`surface\` (layout slots) and \`tint\` (data categories) are the ONLY theme-tracking background props; the legacy \`background="..."\` prop has been removed. To colour by a DATA CATEGORY (series, lanes, kinds, tags, element groups), use \`tint="tint-1"\`\u2026\`"tint-8"\` (see "Categorical tint" below). For non-theme-mapped brand colors (a partner's exact brand hex like Stripe purple), use the typed escape \`<Box assetColor="#635BFF" assetSemantic="stripe-brand-purple">\` \u2014 both props are required, and \`assetSemantic\` MUST be a non-empty human-readable label. Tier-0 self-check rejects every other hex / rgba on Box.
|
|
1261
|
+
- \`<Stack gap="...">\` / \`<Row gap="...">\` \u2014 \`gap\` takes the **spacing scale** (next bullet). \`align\` (cross-axis) is ONLY \`start | center | end | stretch\` and \`justify\` (main-axis) is ONLY \`start | center | end | between | around | evenly\` \u2014 NEVER the raw CSS values \`flex-start\` / \`flex-end\` / \`space-between\`, which are type errors.
|
|
1262
|
+
- **Spacing scale** \u2014 \`gap\` (Stack / Row / Grid) and \`padding\` (Card / Box / Container) take a t-shirt size: \`none | xs | sm | md | lg | xl | 2xl\`. Each resolves to a \`--ggui-spacing-*\` token (xs\u22484px, sm\u22488px, md\u224816px, lg\u224824px, xl\u224832px, 2xl\u224848px). A bare number is treated as pixels. NEVER pass a raw CSS length such as \`gap="8px"\` \u2014 it is silently dropped by the browser and the gap collapses to 0; use the scale name (\`gap="sm"\`).
|
|
1263
|
+
- **One content edge per card** \u2014 on \`Card\` and \`Box\`, \`padding\` sets the VERTICAL rhythm; the card owns the horizontal inset. Every block's content sits on the card's one left edge, and a filled or bordered surface steps its own content in by exactly one inset. So never use \`paddingX\` to push content sideways or a padded unstyled wrapper to indent a list. A badge, date or action on the right of a line belongs in a \`<Row justify="between">\` with content on its left, never alone on its own line.
|
|
1264
|
+
- \`<Grid columns={N} gap="md">\` \u2014 2-D layout (rows AND columns). Reach for it for card galleries, stat grids and dashboards \u2014 NEVER hand-roll \`style={{ display: 'grid' }}\`. When the request names exact per-breakpoint counts ("3 per row on desktop, 1 on mobile"), pass a map: \`<Grid columns={{ base: 1, md: 3 }}>\` (breakpoints \`sm\`/\`md\`/\`lg\`/\`xl\`; the design system emits the media queries). For an open-ended gallery where any column count is fine, use \`<Grid minColumnWidth={220}>\` \u2014 it fits as many equal columns as the width allows. \`radius\` (Card / Box / Image) takes the scale \`none | sm | md | lg | xl\`.
|
|
1265
|
+
- \`<Stat label="\u2026" value="\u2026" delta="+12%" trend="up">\` \u2014 KPI display (label + big value + trend-coloured delta + optional \`icon\`). \`trend\` is \`up | down | neutral\` (delta renders green / red / muted). Reach for it for any "show a number" UI; drop several into a \`<Grid>\` for a stat grid instead of hand-building label+value pairs.
|
|
1266
|
+
- \`<Stepper steps={STEPS} current={step} />\` \u2014 display-only step indicator for wizards/checkouts. \`steps\` is a top-level \`const\` array of labels; \`current\` is YOUR zero-indexed \`useState\` value; \`orientation\` is \`horizontal | vertical\`; optional \`onStepClick={(i) => \u2026}\` makes steps clickable. Stepper never owns navigation state \u2014 your Next/Back handlers move \`current\`.
|
|
1267
|
+
- \`<Badge variant="...">\` \u2014 \`default | primary | secondary | tertiary | success | warning | error | info\` for colored pills. Great for status/condition labels. There is NO \`neutral\` variant \u2014 use \`default\` (or \`secondary\`) for an un-tinted pill.
|
|
1268
|
+
|
|
1269
|
+
**Color choice rule of thumb.** Reach for typed slots first: Button \`variant\`, Badge \`variant\`, Alert \`variant\`, Text/Heading/Icon/Spinner/Link/Divider \`tone\`, Box/Card \`surface\`. NEVER hardcode hex \`#XXXXXX\`, rgba, or hsl \u2014 tier-0 self-check rejects them with \`tokens:hex-color\` / \`tokens:hardcoded-color-fn\` and the LLM must remediate. Hardcoded colors break the operator's theme switch (Indigo \u2192 Claudic \u2192 Cyberpunk preset has zero effect on a card hardcoded with \`background: '#000'\`).
|
|
1270
|
+
|
|
1271
|
+
**Asset-color escape (Box only).** When you genuinely need a non-theme color \u2014 a partner's exact brand hex (Stripe purple \`#635BFF\`, Slack aubergine \`#4A154B\`), a fixed product surface \u2014 use \`<Box assetColor="#635BFF" assetSemantic="stripe-brand-purple">\u2026</Box>\`. The \`assetSemantic\` is REQUIRED and MUST be a non-empty human-readable label that documents intent. Tier-0 allows hex inside this typed pair; one without the other fails the check. Reach for \`surface\` first \u2014 \`assetColor\` is rare.
|
|
1272
|
+
|
|
1273
|
+
**Categorical tint (data categories).** When cells, rows or swatches must be told apart by a data category \u2014 element groups in a periodic table, lanes on a board, series in a chart legend, tags \u2014 set \`tint="tint-1"\` \u2026 \`tint="tint-8"\` on the Box or Card. The eight steps are theme colours: they follow the operator's theme in light and dark, and the tinted surface sets its own readable text colour. Rules:
|
|
1274
|
+
- Tints are for **data categories only** \u2014 never for state (a status takes live, draft or signal, not a tint) and never as decoration.
|
|
1275
|
+
- The category is **always also in words** \u2014 a label in the cell or a legend on the card. Colour is never the only way to tell categories apart.
|
|
1276
|
+
- **Text on a tint is the theme's ink only, one short line** \u2014 a label, a symbol or a value, never \`tone="subtle"\` or muted text. Secondary or muted text sits beside the cell or in the legend, never on the tint.
|
|
1277
|
+
- **A category keeps its tint for the life of the card.** Assign tints deterministically from the data, in the order the categories are first listed or sorted, never by render order, so an update or repaint never recolours a category.
|
|
1278
|
+
- **More than eight categories:** group them to eight before assigning, or show the category in words only.
|
|
1279
|
+
- Never put a theme colour through \`assetColor\` \u2014 that escape is only for an exact external brand hex.
|
|
1280
|
+
|
|
1281
|
+
## Accessibility (REQUIRED)
|
|
1282
|
+
|
|
1283
|
+
The design-system primitives are accessible by construction \u2014 they emit their own roles, labels, keyboard handlers, and error wiring. Your job is to USE them correctly, NOT to re-declare ARIA on top of them.
|
|
1284
|
+
|
|
1285
|
+
1. **Form inputs** \u2014 give every \`Input\` / \`TextArea\` / \`Select\` a \`label\` prop. The primitive renders its own \`<label htmlFor>\`, and exposes \`aria-invalid\` + \`aria-describedby\` for errors. Do NOT add a separate \`<Text>\` label or your own \`htmlFor\` \u2014 that double-labels the field.
|
|
1286
|
+
\`\`\`tsx
|
|
1287
|
+
<Input label="Email" value={email} onChange={setEmail} type="email" />
|
|
1288
|
+
\`\`\`
|
|
1289
|
+
2. **Don't re-declare built-in ARIA.** \`Progress\`, \`RadioGroup\`, \`Tabs\`, \`Toggle\`, \`Slider\`, \`Spinner\`, \`Alert\`, \`Accordion\` already carry the correct \`role\` / \`aria-*\`. \`Card as={Clickable}\` already adds \`role="button"\` + keyboard activation. Adding your own is redundant and often wrong.
|
|
1290
|
+
3. **Icons are decorative by default** \u2014 \`<Icon name="check" />\` is hidden from screen readers, which is correct for an icon sitting next to text. Add \`aria-label\` ONLY for a standalone, meaning-bearing icon with no adjacent text. Icon-only \`Button\`s still need \`aria-label\` on the **Button** itself.
|
|
1291
|
+
4. **Live & streaming data** \u2014 wrap any region whose content updates on its own (a \`useStream\` \`.latest\` value, a live clock, an "N new" counter, a flashing price) in an element with \`aria-live="polite"\` so screen readers announce the change.
|
|
1292
|
+
5. **Headings nest** \u2014 one \`<Heading level={1}>\` per screen, \`level={2}\` for sections, \`level={3}\` for subsections. Never skip or invert levels.
|
|
1293
|
+
6. **Buttons** \u2014 descriptive text content; icon-only buttons need \`aria-label\`. Announce busy state. EVERY control that dispatches an action \u2014 a Button, a Select whose change dispatches, an Input that sends on Enter \u2014 stays pending from that action's \`useActionPending\` until the agent's answer repaints the card: with \`const sendPending = useActionPending('send');\`, write \`<Button disabled={sendPending} aria-busy={sendPending} onClick={() => send({ text })}>{sendPending ? 'Sending\u2026' : 'Send'}</Button>\`, and give a dispatching Select or Input the same \`disabled={sendPending} aria-busy={sendPending}\`. Only a control that dispatches the action carries its \`aria-busy\` and a working label. While it is pending, other controls of the SAME record may be \`disabled\` \u2014 nothing more; controls of other records, creation controls and the action's own cancel stay enabled. Busy state the card owns (a local \`isLoading\`) is announced the same way.
|
|
1294
|
+
7. **Stateful controls announce their state.** Toggleable / selectable / expandable things use the primitive that carries the semantics (\`Checkbox\`, \`Toggle\`, \`Tabs\`, \`Accordion\`) \u2014 never a styled \`Box\`/\`Icon\` that only *looks* checked. When you hand-roll one with \`as={Clickable}\`, \`Clickable\` adds button + keyboard semantics but NOT state \u2014 add it yourself: \`role="checkbox"\` + \`aria-checked={done}\` on a toggleable row, \`aria-pressed\` on a toggle button, \`aria-selected\` on the chosen item, \`aria-expanded\` on an open/close affordance. Styling (strikethrough, color, a check icon) must never be the only carrier of state.
|
|
1295
|
+
|
|
1296
|
+
## Design System Usage (CRITICAL)
|
|
1297
|
+
|
|
1298
|
+
EVERY color, spacing, typography, shadow, and radius value MUST come from design-system CSS variables. The runtime injects them on \`:root\`.
|
|
1299
|
+
|
|
1300
|
+
MANDATORY:
|
|
1301
|
+
1. NEVER use hardcoded hex colors like \`#7c3aed\` \u2014 ONLY \`var(--ggui-color-*)\` tokens.
|
|
1302
|
+
2. NEVER use CSS gradients with custom colors. If you need a gradient: \`linear-gradient(to bottom, var(--ggui-color-primary-500), var(--ggui-color-primary-700))\`.
|
|
1303
|
+
3. NEVER invent your own palette. The system provides primary, neutral, success, warning, error, and info \u2014 use ONLY these.
|
|
1304
|
+
4. NEVER include literal fallback values in ANY token reference \u2014 colors, spacing, typography, radius, shadows alike. Write \`var(--ggui-spacing-4)\` bare, never \`var(--ggui-spacing-4, 16px)\`; \`var(--ggui-color-primary-600)\` bare, never \`var(--ggui-color-primary-600, #0284c7)\`. The runtime injects every token; a literal fallback paints the wrong value exactly when the operator's theme matters most.
|
|
1305
|
+
5. NEVER set an inline \`border\`, \`borderColor\`, \`borderWidth\` or \`borderStyle\` on a kit control \u2014 \`Button\`, \`Input\`, \`Select\`, \`TextArea\`, \`Checkbox\`, \`RadioGroup\`, \`Toggle\`, \`SearchField\`. The control draws its own boundary, and it clears 3:1 on its surface in every theme: an outline chip is \`<Button variant="outline">\` exactly as it comes (its edge is \`controlAccentOutline\`). Where you draw a control-like edge on your own element, use \`var(--ggui-color-controlOutline)\`. A ramp step such as \`primary-200\` as a control's border is nearly invisible (about 1.1:1). Its ink and fill are the variant's too: NEVER set an inline \`color\`, \`background\` or \`backgroundColor\` on a kit control, a token as much as a literal \u2014 pick the variant that carries the look.
|
|
1306
|
+
|
|
1307
|
+
Token categories:
|
|
1308
|
+
- Brand fills: \`var(--ggui-color-primary-600)\`, \`var(--ggui-color-primary-50)\`
|
|
1309
|
+
- Accent text: \`var(--ggui-color-link)\` \u2014 eyebrows, taglines, links, labels; readable per mode (never a bare \`primary-<stop>\` as a text color)
|
|
1310
|
+
- Text: \`var(--ggui-color-onContainer)\`, \`var(--ggui-color-onSunken)\`
|
|
1311
|
+
- Backgrounds: \`var(--ggui-color-container)\`, \`var(--ggui-color-sunken)\`
|
|
1312
|
+
- Borders: \`var(--ggui-color-outline)\` \u2014 dividers and the edges of non-interactive boxes; a control's edge is the kit's (rule 5)
|
|
1313
|
+
- Spacing: \`var(--ggui-spacing-4)\`, \`var(--ggui-spacing-6)\`
|
|
1314
|
+
- Typography: \`var(--ggui-font-size-sm)\`, \`var(--ggui-font-weight-semibold)\`
|
|
1315
|
+
- Shadows: \`var(--ggui-shape-shadow-sm)\`, \`var(--ggui-shape-shadow-md)\`, \`var(--ggui-shape-shadow-lg)\`
|
|
1316
|
+
- Radius: \`var(--ggui-shape-radius-md)\`, \`var(--ggui-shape-radius-lg)\`
|
|
1317
|
+
|
|
1318
|
+
Prefer primitives' built-in styling props over inline styles when possible.
|
|
1319
|
+
|
|
1320
|
+
### Branded Color Strategy
|
|
1321
|
+
|
|
1322
|
+
Use the FULL primary palette throughout the component \u2014 NOT only on submit buttons. A well-themed component feels distinctly branded, not gray-with-one-colored-button.
|
|
1323
|
+
|
|
1324
|
+
| Element | Token | Purpose |
|
|
1325
|
+
|---------|-------|---------|
|
|
1326
|
+
| Section headers, hero areas, highlight strips | \`primary-50\` / \`primary-100\` | Subtle branded backgrounds |
|
|
1327
|
+
| Dividers, section rules, edges of non-interactive boxes | \`primary-200\` / \`primary-300\` | Branded structure \u2014 never a control's border (rule 5) |
|
|
1328
|
+
| Accent TEXT \u2014 eyebrows, taglines, links, labels, inline arrows | \`link\` (\`var(--ggui-color-link)\`) or \`<Text tone="emphasized">\` | The brand's READABLE ink, derived per mode to clear 4.5:1 \u2014 a bare \`primary-300\u2026600\` as a text color fails tier-0 |
|
|
1329
|
+
| Icon fills, badges, active indicators | \`primary-500\` / \`primary-600\` | Core accent fill |
|
|
1330
|
+
| Buttons, CTAs, filled interactive elements | \`primary-600\` / \`primary-700\` | Primary actions |
|
|
1331
|
+
| Headings on light primary backgrounds | \`primary-800\` / \`primary-900\` | High-contrast branded text |
|
|
1332
|
+
|
|
1333
|
+
Use the layering roles' inks (\`onContainer\` for body text on a card, \`onSunken\` for secondary text, captions, labels) \u2014 never raw neutrals. NEVER use raw \`neutral-*\` or \`gray-*\` for body text \u2014 they break in dark themes.
|
|
1334
|
+
|
|
1335
|
+
### Theme-Agnostic Design
|
|
1336
|
+
|
|
1337
|
+
Components MUST be theme-agnostic \u2014 they reference CSS variables but NEVER assume a specific style. The theme decides what \`primary-600\` looks like.
|
|
1338
|
+
|
|
1339
|
+
DO:
|
|
1340
|
+
- Use \`var(--ggui-color-primary-*)\` for brand elements \u2014 the theme controls what "primary" means
|
|
1341
|
+
- Use \`var(--ggui-shape-shadow-*)\` for depth, \`var(--ggui-shape-radius-*)\` for corners
|
|
1342
|
+
- Use semantic color roles: primary for brand; the layering roles (ground / container / elevated / sunken + their on* inks) for structure; success/error/warning for state
|
|
1343
|
+
|
|
1344
|
+
DON'T:
|
|
1345
|
+
- Don't assume primary is blue \u2014 could be red, green, purple
|
|
1346
|
+
- Don't hardcode gradients tuned for a specific theme
|
|
1347
|
+
- Don't use fixed shadow values
|
|
1348
|
+
|
|
1349
|
+
Visual hierarchy via tokens:
|
|
1350
|
+
- Elevated sections: \`var(--ggui-shape-shadow-md)\` + \`var(--ggui-shape-radius-lg)\`
|
|
1351
|
+
- Highlighted regions: \`var(--ggui-color-primary-50)\` background
|
|
1352
|
+
- Active/selected: \`var(--ggui-color-primary-100)\` background
|
|
1353
|
+
- Section headers / eyebrows: \`var(--ggui-color-link)\` text, or a \`var(--ggui-color-primary-600)\` border-bottom
|
|
1354
|
+
|
|
1355
|
+
## Responsive Design (CRITICAL)
|
|
1356
|
+
|
|
1357
|
+
Generated components become reusable blueprints \u2014 the same blueprint serves phones, tablets, desktops, spatial headsets. Design for ALL screen sizes:
|
|
1358
|
+
|
|
1359
|
+
1. Design tokens for ALL spacing \u2014 never hardcode pixel values for padding/margins/gaps. Use the named spacing scale on props (\`gap="md"\`, \`padding="lg"\`); for inline \`style\` use \`var(--ggui-spacing-*, \u2026)\`.
|
|
1360
|
+
2. Relative/fluid units \u2014 prefer \`%\`, \`em\`, \`rem\`, \`min()\`, \`max()\`, \`clamp()\` over fixed \`px\`.
|
|
1361
|
+
3. Fluid widths \u2014 \`max-width\` with \`width: 100%\`. Never set a fixed width.
|
|
1362
|
+
4. Compact padding \u2014 components are embedded in containers that provide their own chrome.
|
|
1363
|
+
5. No raw \`@media\` queries in component code \u2014 for a layout that must change by breakpoint, use \`<Grid columns={{ base: 1, md: 3 }}>\` (the design system emits the media queries for you) or a fluid \`minColumnWidth\` grid.`;
|
|
1364
|
+
var DESIGN_SYSTEM_GUIDANCE_AESTHETICS_AND_CHECKLIST = `## Aesthetic Guidance (READ CAREFULLY \u2014 this is what separates "polished" from "ok")
|
|
1365
|
+
|
|
1366
|
+
### Visual hierarchy \u2014 the SCALE GAP rule
|
|
1367
|
+
|
|
1368
|
+
A polished UI has ONE hero that dominates. Everything else supports it. Bad layouts have everything at similar sizes \u2014 the eye has nowhere to land. The rule:
|
|
1369
|
+
|
|
1370
|
+
**Hero metric vs supporting text must have a 2\u20133\xD7 size gap.** If the hero is the temperature, score, count, status, price \u2014 it's ENORMOUS. Use \`<Text size="4xl" weight="bold">\` \u2014 the largest \`size\` the type allows (\`4xl\` = 36px). Pair it with a small supporting label (\`size="sm"\`, ~14px) so the gap reads as 2\u20133\xD7. The hero number should feel oversized compared to the location/title around it. \`size\` accepts ONLY \`xs | sm | base | lg | xl | 2xl | 3xl | 4xl\` \u2014 \`5xl\` / \`6xl\` are NOT valid and fail tier-0 type-check.
|
|
1371
|
+
|
|
1372
|
+
\`\`\`tsx
|
|
1373
|
+
// BAD \u2014 temperature is the same size as the location heading
|
|
1374
|
+
<Heading level={1}>Seoul, South Korea</Heading>
|
|
1375
|
+
<Text size="lg" weight="bold">18\xB0C</Text>
|
|
1376
|
+
|
|
1377
|
+
// GOOD \u2014 temperature dominates (4xl), location supports it (sm)
|
|
1378
|
+
<Text size="sm" tone="muted">Seoul, South Korea</Text>
|
|
1379
|
+
<Text size="4xl" weight="bold">18\xB0C</Text>
|
|
1380
|
+
<Text size="lg" tone="muted">Partly Cloudy \xB7 Feels like 16\xB0C</Text>
|
|
1381
|
+
\`\`\`
|
|
1382
|
+
|
|
1383
|
+
### Color discipline \u2014 the 60/30/10 rule
|
|
1384
|
+
|
|
1385
|
+
Don't paint everything in primary. Use:
|
|
1386
|
+
- **60% container** (\`var(--ggui-color-container)\` / \`onContainer\`) \u2014 body text, default backgrounds, structure
|
|
1387
|
+
- **30% sunken + onSunken** \u2014 wells, secondary text, captions, labels, dividers
|
|
1388
|
+
- **10% primary** \u2014 hero number, ONE highlight element, CTAs, brand accent
|
|
1389
|
+
|
|
1390
|
+
If your component is 100% purple text on purple backgrounds, you've lost the eye. Headings can be \`onContainer\` (the card's ink) \u2014 they'll still feel weighty. Save the primary palette for one or two STAR moments.
|
|
1391
|
+
|
|
1392
|
+
\`\`\`tsx
|
|
1393
|
+
// BAD \u2014 everything purple, eye has no anchor
|
|
1394
|
+
<Heading tone="emphasized">Title</Heading>
|
|
1395
|
+
<Text tone="emphasized">42</Text>
|
|
1396
|
+
<Text tone="emphasized">all body text</Text>
|
|
1397
|
+
|
|
1398
|
+
// GOOD \u2014 hero pops, body is neutral, primary is reserved
|
|
1399
|
+
<Heading>Title</Heading> {/* defaults to onContainer */}
|
|
1400
|
+
<Text size="4xl" weight="bold" tone="emphasized">42</Text>
|
|
1401
|
+
<Text tone="muted">all body text</Text>
|
|
1402
|
+
\`\`\`
|
|
1403
|
+
|
|
1404
|
+
### Visual rhythm \u2014 vary your card treatments
|
|
1405
|
+
|
|
1406
|
+
A row of identical flat tiles feels monotone. Use card-treatment variation to create rhythm:
|
|
1407
|
+
- **Hero card**: \`<Card surface="hero" padding="xl" shadow="lg" radius="xl">\` \u2014 the theme's hero ground (brand-tinted on a light host, the ink pair on a dark one); anchors the eye.
|
|
1408
|
+
- **Stat tiles**: \`<Card padding="md" shadow="sm" radius="md">\` with surface bg \u2014 secondary
|
|
1409
|
+
- **Inline rows / list items**: no card chrome at all, just \`<Stack gap="sm">\` with dividers \u2014 tertiary
|
|
1410
|
+
|
|
1411
|
+
The hero should literally have higher elevation than the supporting tiles. If everything has \`shadow="md"\`, nothing does.
|
|
1412
|
+
|
|
1413
|
+
### Iconography \u2014 emoji + Icon are visual weight on the cheap
|
|
1414
|
+
|
|
1415
|
+
Don't render text-only metrics. A weather widget without a sun/cloud, a stock card without an arrow, a status panel without a colored dot \u2014 all feel undersold. Pair every hero metric with an icon or emoji at large size:
|
|
1416
|
+
|
|
1417
|
+
\`\`\`tsx
|
|
1418
|
+
<Row gap="md" align="center">
|
|
1419
|
+
<Text size="3xl">\u2600\uFE0F</Text>
|
|
1420
|
+
<Stack gap="xs">
|
|
1421
|
+
<Text size="4xl" weight="bold">18\xB0C</Text>
|
|
1422
|
+
<Text size="sm" tone="muted">Sunny \xB7 feels like 16\xB0</Text>
|
|
1423
|
+
</Stack>
|
|
1424
|
+
</Row>
|
|
1425
|
+
\`\`\`
|
|
1426
|
+
|
|
1427
|
+
Use \`<Icon name="..." />\` for line icons \u2014 ONLY the design system's curated set renders (~200 kebab-case Lucide names); a name OUTSIDE it renders an empty box and fails the check. On a single-pass render you cannot look the set up, so use ONLY a name you are sure is in it. Safe common names: \`check\` \`x\` \`plus\` \`minus\` \`search\` \`settings\` \`user\` \`users\` \`calendar\` \`clock\` \`arrow-right\` \`arrow-left\` \`chevron-right\` \`chevron-down\` \`trash-2\` \`edit\` \`info\` \`alert-circle\` \`bell\` \`home\` \`file\` \`file-text\` \`star\` \`heart\` \`mail\` \`send\` \`download\` \`upload\` \`external-link\` \`filter\` \`check-circle\`. The numbered variants (\`edit-2\`, \`edit-3\`) and synonyms (\`pencil\`, \`pen\`, \`trash\`, \`x-circle\`) are NOT in the set \u2014 use \`edit\` and \`trash-2\`. If the icon you want is not clearly one of these, OMIT it: a card with no icon beats one with an empty box. Emoji render directly for status/weather/mood. For per-stat tiny accents, use a small icon next to the label.
|
|
1428
|
+
|
|
1429
|
+
### Spacing \u2014 generosity beats compactness
|
|
1430
|
+
|
|
1431
|
+
Hero sections should feel airy. Use \`padding="xl"\` (32px) on the main card, not \`padding="md"\`. Whitespace IS design. A cramped polished card looks worse than a roomy plain one.
|
|
1432
|
+
|
|
1433
|
+
### Concrete recipes
|
|
1434
|
+
|
|
1435
|
+
- **Hero metric card** (weather, stock, score): hero number at \`size="4xl"\` (the max), icon/emoji at \`size="3xl"\` next to it (use \`<Row gap="md">\`), supporting label at \`size="sm"\` muted, branded gradient bg, \`shadow="lg"\`, \`padding="xl"\`.
|
|
1436
|
+
- **Stat grid** (3\u20136 quick metrics): \`<Grid columns={3} gap="md">\` of \`<Stat>\` \u2014 each \`<Stat label="\u2026" value="\u2026" delta="\u2026" trend="\u2026" />\` handles the label-on-top / value-below / trend-coloured-delta layout for you. Wrap each in a \`<Card padding="md" shadow="sm">\` if you want tile chrome.
|
|
1437
|
+
- **List item** (forecast day, todo, message): no card per item, use \`<Stack gap="md">\` with each row as \`<Row gap="md">\` of icon + content + meta. Add \`<Divider>\` between rows.
|
|
1438
|
+
- **Multi-step wizard** (survey, onboarding, checkout): \`<Stepper steps={STEPS} current={step} />\` at the top, the current step's fields below, Next/Back buttons that move \`step\`. Don't hand-roll a "2 of 4" indicator.
|
|
1439
|
+
- **Key-value rows** (specs, order summary, flight details): \`<Stack gap="sm">\` of \`<Row justify="between">\` \u2014 label as \`<Text size="sm" tone="muted">\`, value as \`<Text size="sm" weight="medium">\`.
|
|
1440
|
+
- **Section header**: \`<Heading level={2}>\` left-aligned, optional \`<Badge>\` to its right for count/status, optional muted caption below.
|
|
1441
|
+
- **CTA section**: ONE primary button. Other actions as ghost/outline. Don't stack three primary buttons.
|
|
1442
|
+
|
|
1443
|
+
## Quality Checklist (verify before returning)
|
|
1444
|
+
|
|
1445
|
+
- [ ] Imports ONLY from: react, @ggui-ai/design, @ggui-ai/wire
|
|
1446
|
+
- [ ] No raw HTML elements (\`<button>\`, \`<input>\`, \`<div>\` for layout) \u2014 uses primitives
|
|
1447
|
+
- [ ] ZERO hardcoded hex colors \u2014 every color is a bare \`var(--ggui-color-*)\`, no literal fallback
|
|
1448
|
+
- [ ] No raw pixel values for spacing \u2014 all via \`var(--ggui-spacing-*)\` tokens
|
|
1449
|
+
- [ ] Primary palette used throughout (headers, borders, icons) \u2014 not just buttons
|
|
1450
|
+
- [ ] Typed Props interface exported; request-specific data is a prop with default
|
|
1451
|
+
- [ ] Every Input/TextArea/Select has a \`label\` prop (no separate \`<Text>\` label)
|
|
1452
|
+
- [ ] Icon-only buttons have \`aria-label\`; no redundant \`role\`/\`aria-*\` on primitives
|
|
1453
|
+
- [ ] Toggleable/selected/expanded state is ARIA-expressed (\`aria-checked\`/\`aria-pressed\`/\`aria-selected\`/\`aria-expanded\`) \u2014 never style-only
|
|
1454
|
+
- [ ] Live/streaming regions wrapped in \`aria-live="polite"\`
|
|
1455
|
+
- [ ] Headings nest \u2014 one \`level={1}\`, then \`level={2}\`/\`{3}\` \u2014 never skipped or inverted
|
|
1456
|
+
- [ ] Wire hooks (\`useAction\`, \`useStream\`) imported from \`@ggui-ai/wire\` and consumed`;
|
|
1457
|
+
var DESIGN_SYSTEM_GUIDANCE = [
|
|
1458
|
+
DESIGN_SYSTEM_GUIDANCE_SURFACE_AND_TOKENS,
|
|
1459
|
+
DATA_PARAMETERIZATION,
|
|
1460
|
+
FRAME_SIZING,
|
|
1461
|
+
COMPONENT_STRUCTURE,
|
|
1462
|
+
DESIGN_SYSTEM_GUIDANCE_AESTHETICS_AND_CHECKLIST
|
|
1463
|
+
].join("\n\n");
|
|
1464
|
+
|
|
1465
|
+
export { buildSystemPrompt, generateBoilerplate };
|
|
1466
|
+
//# sourceMappingURL=chunk-FB7OEEAH.js.map
|
|
1467
|
+
//# sourceMappingURL=chunk-FB7OEEAH.js.map
|