@ggui-ai/gadgets 0.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Loqu, Inc. (Guuey)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # @ggui-ai/gadgets
2
+
3
+ > Browser-capability gadget hooks for ggui. Declared on a `DataContract` via `clientCapabilities.gadgets[*]`, mounted by the UI generator's component code, surfaced to agents through the protocol's gadget-discovery tool.
4
+
5
+ ## Why
6
+
7
+ LLM-generated component code needs a stable, narrow API for the small set of browser capabilities that interactive UIs reach for: geolocation, clipboard read/write, notifications, file pickers, microphone, camera. Each capability has the same lifecycle shape — pending → ready → error — and the same permission-prompt UX. Encoding that shape once, in a typed React hook, keeps the generator's output:
8
+
9
+ - predictable across providers and prompts,
10
+ - testable by code-property assertions on the generated source (not just the rendered DOM),
11
+ - bounded by the v1 stdlib catalog the protocol's contract linter recognizes.
12
+
13
+ The contract declares WHICH hooks the component will mount; the hooks own how they behave at runtime.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pnpm add @ggui-ai/gadgets
19
+ ```
20
+
21
+ Peer-dep: `react` ^18 || ^19.
22
+
23
+ ## v1 stdlib catalog
24
+
25
+ Seven hooks ship in v1, all with a shared `{ status, error, value | data | call }` shape:
26
+
27
+ | Hook | Permission | Description |
28
+ | ------------------- | ----------------- | ------------------------------------------------------------ |
29
+ | `useGeolocation` | `geolocation` | Current position + watch updates. |
30
+ | `useClipboardWrite` | `clipboard-write` | Write text or rich payload to the user's clipboard. |
31
+ | `useClipboardPaste` | `clipboard-read` | Read the user's clipboard on explicit user gesture. |
32
+ | `useNotifications` | `notifications` | Request permission + post a system notification. |
33
+ | `useFilePicker` | _none_ | Open the OS file picker (gated by user activation, no perm). |
34
+ | `useMicrophone` | `microphone` | Stream access to the user's microphone via `getUserMedia`. |
35
+ | `useCamera` | `camera` | Stream access to the user's camera via `getUserMedia`. |
36
+
37
+ The same list is exported from `@ggui-ai/protocol` as `STDLIB_GADGETS` and seeds the discovery tool (`ggui_list_gadgets`) for any app without an operator-mutated override.
38
+
39
+ ## How a contract uses these hooks
40
+
41
+ The agent declares the gadgets the component will mount on the contract's `clientCapabilities.gadgets` — a package-keyed map: the npm package name keys the outer map, the export name keys the inner map. The agent names which package + which exports; it does NOT pin a `version` (the operator's `App.gadgets` catalog owns the version). The permission a capability prompts for is NOT a contract field; it is declared by the operator on the registered descriptor's export (`GadgetExport.permission`), and the renderer reads it from there to derive a `Permissions-Policy` header:
42
+
43
+ ```ts
44
+ import { defineContract } from "@ggui-ai/protocol";
45
+
46
+ export const photoCaptureContract = defineContract({
47
+ propsSpec: {
48
+ properties: {
49
+ title: { schema: { type: "string" }, default: "Take a photo" },
50
+ },
51
+ },
52
+ actionSpec: {
53
+ capture: {
54
+ label: "Capture",
55
+ schema: { type: "object", properties: { dataUrl: { type: "string" } } },
56
+ },
57
+ },
58
+ clientCapabilities: {
59
+ // `gadgets` is package-keyed: `Record<package, Record<exportName,
60
+ // { description?, usage? }>>`. The wire carries identity only —
61
+ // `version`, transport fields, and per-export registry metadata
62
+ // (`permission`, `example`, `gotchas`, `required`) are NOT on the
63
+ // wire; the server resolves them from `App.gadgets` at push time.
64
+ gadgets: {
65
+ "@ggui-ai/gadgets": {
66
+ useCamera: {
67
+ usage: "Live camera preview + capture-to-data-URL on the capture action.",
68
+ },
69
+ },
70
+ },
71
+ },
72
+ } as const);
73
+ ```
74
+
75
+ The generator reads `clientCapabilities.gadgets` and emits matching `import { useCamera } from '@ggui-ai/gadgets'` lines at the top of the generated component. Permission strings — read from the registered descriptor's per-export `permission` field — union-deduplicate into a `Permissions-Policy` header on the public-render route and an `allow=""` attribute on the MCP-Apps iframe host.
76
+
77
+ ## Hook surface
78
+
79
+ Every hook returns a `{ status, ... }` object whose status is `'idle' | 'prompting' | 'active' | 'completed' | 'denied' | 'error'`. Specific value fields live alongside it. Example:
80
+
81
+ ```tsx
82
+ import { useGeolocation } from "@ggui-ai/gadgets";
83
+
84
+ function NearbyStores() {
85
+ const geo = useGeolocation();
86
+ if (geo.status === "completed" || geo.status === "active") {
87
+ return <List origin={geo.value} />;
88
+ }
89
+ if (geo.status === "denied") return <Disabled reason="Allow location to see nearby stores" />;
90
+ return <Skeleton />;
91
+ }
92
+ ```
93
+
94
+ See the per-hook source under `src/use*.ts` for the exact return shape and options surface.
95
+
96
+ ## Authoring your own gadget package
97
+
98
+ To wrap a third-party browser library (Leaflet, Mapbox, Chart.js, …) as a
99
+ gadget package, use `defineGadgetPackage` — it takes the package identity
100
+ once plus a list of export declarations (hooks and/or components) and
101
+ returns a validated `GadgetDescriptor`:
102
+
103
+ ```ts
104
+ import { defineGadgetPackage } from "@ggui-ai/gadgets";
105
+
106
+ export const chartDescriptor = defineGadgetPackage({
107
+ package: "@my-org/gadget-chart",
108
+ version: "0.1.0",
109
+ exports: [
110
+ { component: "Chart", impl: Chart, description: "…", usage: "…", example: {} },
111
+ { hook: "useChartTheme", impl: useChartTheme, description: "…", usage: "…", example: {} },
112
+ ],
113
+ });
114
+ ```
115
+
116
+ For a single-hook package, `createGguiGadget` is the convenience builder.
117
+ Emit `descriptor.json` for registry consumption via `@ggui-ai/gadgets/codegen`.
118
+
119
+ ## See also
120
+
121
+ - [`@ggui-ai/protocol`](https://github.com/ggui-ai/ggui/tree/main/packages/protocol) — `GadgetDescriptor`, `GadgetExport`, `ClientCapabilitiesSpec`, `STDLIB_GADGETS`, and the contract linter that validates contracts using these hooks.
@@ -0,0 +1,78 @@
1
+ import { GadgetDescriptor } from '@ggui-ai/protocol';
2
+
3
+ /**
4
+ * `@ggui-ai/gadgets/codegen` — wrapper-author build helper.
5
+ *
6
+ * Emits `descriptor.json` for registry consumption ({@link
7
+ * writeDescriptorJson}). A gadget wrapper's type narrowing comes from
8
+ * its own real `.d.ts` (emitted by `tsc --declaration` / `tsup --dts`)
9
+ * — the registry serves it via `typesUrl`, and the code-gen sandbox
10
+ * overlays it per-package so a direct `import { useLeafletMap } from
11
+ * '@scope/wrapper-leaflet'` resolves against the strict hook
12
+ * signatures. Gadgets are direct-imported — one idiom with the design
13
+ * primitives — so there is no catalog-augmentation codegen step.
14
+ *
15
+ * This file is Node-only — it uses `node:fs/promises`. The codegen
16
+ * lives at a separate entry (`@ggui-ai/gadgets/codegen`) so the
17
+ * browser-runtime bundle's import graph stays minimal.
18
+ */
19
+
20
+ /**
21
+ * Emit `descriptor.json` for registry consumption.
22
+ *
23
+ * Wrapper authors structure their build like:
24
+ *
25
+ * ```ts
26
+ * // build.ts
27
+ * import { writeDescriptorJson } from '@ggui-ai/gadgets/codegen';
28
+ * import { useLeafletMap } from './src/index';
29
+ *
30
+ * await writeDescriptorJson({
31
+ * descriptors: [useLeafletMap.descriptor],
32
+ * outputPath: 'dist/descriptor.json',
33
+ * });
34
+ * ```
35
+ *
36
+ * The author's build is responsible for type metadata: run
37
+ * `tsup --dts` (or `tsc --declaration`) to emit the wrapper's
38
+ * `.d.ts`, compute its SHA-384 SRI, and set `typesUrl` + `typesSri`
39
+ * on each descriptor BEFORE calling this helper. `writeDescriptorJson`
40
+ * itself is pure I/O + validation — no TS Compiler API, no signature
41
+ * extraction. Type narrowing is sourced from the real emitted `.d.ts`
42
+ * file, not an inline signature string.
43
+ *
44
+ * The helper:
45
+ * 1. Validates each descriptor against
46
+ * `registeredGadgetDescriptorSchema` (every registered descriptor
47
+ * MUST pass — same gate the `App.gadgets` registration handler
48
+ * applies, including the `typesUrl`-required refinement for
49
+ * non-stdlib gadgets).
50
+ * 2. Writes a JSON document `{ version: 'gg2', descriptors: [...] }`.
51
+ */
52
+ interface WriteDescriptorJsonInput {
53
+ /**
54
+ * Descriptors authored via `createGguiGadget(...).descriptor` (or
55
+ * hand-written), with `typesUrl` + `typesSri` already populated by
56
+ * the wrapper build.
57
+ */
58
+ readonly descriptors: readonly GadgetDescriptor[];
59
+ /**
60
+ * Output path for the JSON document. Parent directories are
61
+ * created as needed.
62
+ */
63
+ readonly outputPath: string;
64
+ }
65
+ /**
66
+ * Output payload of {@link writeDescriptorJson}. Returned for tests
67
+ * + callers that want to introspect the validated descriptors without
68
+ * re-reading the file.
69
+ */
70
+ interface DescriptorJsonDocument {
71
+ /** Schema-format marker for the descriptor.json document. */
72
+ readonly version: 'gg2';
73
+ /** Strict-validated descriptors. */
74
+ readonly descriptors: readonly GadgetDescriptor[];
75
+ }
76
+ declare function writeDescriptorJson(input: WriteDescriptorJsonInput): Promise<DescriptorJsonDocument>;
77
+
78
+ export { type DescriptorJsonDocument, type WriteDescriptorJsonInput, writeDescriptorJson };
@@ -0,0 +1,78 @@
1
+ import { GadgetDescriptor } from '@ggui-ai/protocol';
2
+
3
+ /**
4
+ * `@ggui-ai/gadgets/codegen` — wrapper-author build helper.
5
+ *
6
+ * Emits `descriptor.json` for registry consumption ({@link
7
+ * writeDescriptorJson}). A gadget wrapper's type narrowing comes from
8
+ * its own real `.d.ts` (emitted by `tsc --declaration` / `tsup --dts`)
9
+ * — the registry serves it via `typesUrl`, and the code-gen sandbox
10
+ * overlays it per-package so a direct `import { useLeafletMap } from
11
+ * '@scope/wrapper-leaflet'` resolves against the strict hook
12
+ * signatures. Gadgets are direct-imported — one idiom with the design
13
+ * primitives — so there is no catalog-augmentation codegen step.
14
+ *
15
+ * This file is Node-only — it uses `node:fs/promises`. The codegen
16
+ * lives at a separate entry (`@ggui-ai/gadgets/codegen`) so the
17
+ * browser-runtime bundle's import graph stays minimal.
18
+ */
19
+
20
+ /**
21
+ * Emit `descriptor.json` for registry consumption.
22
+ *
23
+ * Wrapper authors structure their build like:
24
+ *
25
+ * ```ts
26
+ * // build.ts
27
+ * import { writeDescriptorJson } from '@ggui-ai/gadgets/codegen';
28
+ * import { useLeafletMap } from './src/index';
29
+ *
30
+ * await writeDescriptorJson({
31
+ * descriptors: [useLeafletMap.descriptor],
32
+ * outputPath: 'dist/descriptor.json',
33
+ * });
34
+ * ```
35
+ *
36
+ * The author's build is responsible for type metadata: run
37
+ * `tsup --dts` (or `tsc --declaration`) to emit the wrapper's
38
+ * `.d.ts`, compute its SHA-384 SRI, and set `typesUrl` + `typesSri`
39
+ * on each descriptor BEFORE calling this helper. `writeDescriptorJson`
40
+ * itself is pure I/O + validation — no TS Compiler API, no signature
41
+ * extraction. Type narrowing is sourced from the real emitted `.d.ts`
42
+ * file, not an inline signature string.
43
+ *
44
+ * The helper:
45
+ * 1. Validates each descriptor against
46
+ * `registeredGadgetDescriptorSchema` (every registered descriptor
47
+ * MUST pass — same gate the `App.gadgets` registration handler
48
+ * applies, including the `typesUrl`-required refinement for
49
+ * non-stdlib gadgets).
50
+ * 2. Writes a JSON document `{ version: 'gg2', descriptors: [...] }`.
51
+ */
52
+ interface WriteDescriptorJsonInput {
53
+ /**
54
+ * Descriptors authored via `createGguiGadget(...).descriptor` (or
55
+ * hand-written), with `typesUrl` + `typesSri` already populated by
56
+ * the wrapper build.
57
+ */
58
+ readonly descriptors: readonly GadgetDescriptor[];
59
+ /**
60
+ * Output path for the JSON document. Parent directories are
61
+ * created as needed.
62
+ */
63
+ readonly outputPath: string;
64
+ }
65
+ /**
66
+ * Output payload of {@link writeDescriptorJson}. Returned for tests
67
+ * + callers that want to introspect the validated descriptors without
68
+ * re-reading the file.
69
+ */
70
+ interface DescriptorJsonDocument {
71
+ /** Schema-format marker for the descriptor.json document. */
72
+ readonly version: 'gg2';
73
+ /** Strict-validated descriptors. */
74
+ readonly descriptors: readonly GadgetDescriptor[];
75
+ }
76
+ declare function writeDescriptorJson(input: WriteDescriptorJsonInput): Promise<DescriptorJsonDocument>;
77
+
78
+ export { type DescriptorJsonDocument, type WriteDescriptorJsonInput, writeDescriptorJson };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/codegen.ts
31
+ var codegen_exports = {};
32
+ __export(codegen_exports, {
33
+ writeDescriptorJson: () => writeDescriptorJson
34
+ });
35
+ module.exports = __toCommonJS(codegen_exports);
36
+ var import_promises = require("fs/promises");
37
+ var import_node_path = require("path");
38
+ async function writeDescriptorJson(input) {
39
+ const { descriptors, outputPath } = input;
40
+ const { registeredGadgetDescriptorSchema } = await import("@ggui-ai/protocol");
41
+ const validated = [];
42
+ for (const descriptor of descriptors) {
43
+ const parsed = registeredGadgetDescriptorSchema.safeParse(descriptor);
44
+ if (!parsed.success) {
45
+ const issues = parsed.error.issues.map((i) => ` - ${i.path.join(".") || "<root>"}: ${i.message}`).join("\n");
46
+ throw new Error(
47
+ `writeDescriptorJson: descriptor for package '${descriptor.package}@${descriptor.version}' failed strict validation:
48
+ ${issues}`
49
+ );
50
+ }
51
+ validated.push(parsed.data);
52
+ }
53
+ const document = {
54
+ version: "gg2",
55
+ descriptors: validated
56
+ };
57
+ await (0, import_promises.mkdir)((0, import_node_path.dirname)(outputPath), { recursive: true });
58
+ await (0, import_promises.writeFile)(
59
+ outputPath,
60
+ `${JSON.stringify(document, null, 2)}
61
+ `,
62
+ "utf8"
63
+ );
64
+ return document;
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ writeDescriptorJson
69
+ });
@@ -0,0 +1,34 @@
1
+ // src/codegen.ts
2
+ import { mkdir, writeFile } from "fs/promises";
3
+ import { dirname } from "path";
4
+ async function writeDescriptorJson(input) {
5
+ const { descriptors, outputPath } = input;
6
+ const { registeredGadgetDescriptorSchema } = await import("@ggui-ai/protocol");
7
+ const validated = [];
8
+ for (const descriptor of descriptors) {
9
+ const parsed = registeredGadgetDescriptorSchema.safeParse(descriptor);
10
+ if (!parsed.success) {
11
+ const issues = parsed.error.issues.map((i) => ` - ${i.path.join(".") || "<root>"}: ${i.message}`).join("\n");
12
+ throw new Error(
13
+ `writeDescriptorJson: descriptor for package '${descriptor.package}@${descriptor.version}' failed strict validation:
14
+ ${issues}`
15
+ );
16
+ }
17
+ validated.push(parsed.data);
18
+ }
19
+ const document = {
20
+ version: "gg2",
21
+ descriptors: validated
22
+ };
23
+ await mkdir(dirname(outputPath), { recursive: true });
24
+ await writeFile(
25
+ outputPath,
26
+ `${JSON.stringify(document, null, 2)}
27
+ `,
28
+ "utf8"
29
+ );
30
+ return document;
31
+ }
32
+ export {
33
+ writeDescriptorJson
34
+ };