@anvilkit/contracts 0.1.18

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/ai.d.cts ADDED
@@ -0,0 +1,265 @@
1
+ /**
2
+ * @file AI generation contract — the types `@anvilkit/schema`,
3
+ * `@anvilkit/validator`, and AI copilot plugins pass between each
4
+ * other when asking an LLM to generate or validate page content.
5
+ *
6
+ * ### Shape of the contract
7
+ *
8
+ * - {@link AiComponentSchema} is a describable-to-an-LLM version of a
9
+ * Puck component config. `@anvilkit/schema` derives this from a
10
+ * Puck `Config` automatically; this package just owns the
11
+ * destination shape.
12
+ * - {@link AiGenerationContext} is the complete input to a single
13
+ * LLM call — the available components plus optional environment
14
+ * hints (current page data, theme, locale).
15
+ * - {@link AiValidationResult} is the output of validating an LLM
16
+ * response against the expected shape. `@anvilkit/validator` owns
17
+ * the runtime check; this package owns the result shape.
18
+ *
19
+ * ### Design rules
20
+ *
21
+ * 1. **Types only.** No runtime code.
22
+ * 2. **Closed field-type union.** {@link AiFieldSchema.type} is a
23
+ * fixed set — adding a new field type is a breaking change so
24
+ * plugin authors are forced to handle every case.
25
+ * 3. **Type-only Puck import.** `Data` is imported via `import type`
26
+ * and erased at compile time — `ai.ts` adds zero runtime
27
+ * reference to `@puckeditor/core`.
28
+ *
29
+ * @see {@link https://github.com/anvilkit/studio/blob/main/docs/tasks/core-006-types-domain.md | core-006}
30
+ */
31
+ import type { Data as PuckData } from "@puckeditor/core";
32
+ /**
33
+ * The finite set of field types an AI schema can describe.
34
+ *
35
+ * Mirrors Puck's own field type union closely but is intentionally a
36
+ * separate, stable enum — the AI contract must not break every time
37
+ * Puck adds or renames a field type. `@anvilkit/schema` maps Puck
38
+ * field types to these values during derivation.
39
+ *
40
+ * Closed union by design: extending this list is a breaking change
41
+ * to the AI contract.
42
+ */
43
+ export type AiFieldType = "text" | "richtext" | "number" | "boolean" | "image" | "url" | "color" | "select" | "array" | "object";
44
+ /**
45
+ * Theme hint forwarded into AI prompts so the model can pick
46
+ * appropriate colors, imagery, and tone (review finding TS-4). Named
47
+ * once here rather than inlining `"light" | "dark"` at each AI context
48
+ * site. (Kept local to the type-only `ai.ts` layer rather than reusing
49
+ * the react-layer `ThemeResolved`, which would cross the engine
50
+ * boundary.)
51
+ */
52
+ export type AiThemeHint = "light" | "dark";
53
+ /**
54
+ * Description of a single prop on a component, in a shape an LLM can
55
+ * reason about.
56
+ *
57
+ * `@anvilkit/schema`'s `configToAiContext()` (Phase 3) produces an
58
+ * array of these from a Puck `Config` field descriptor. The AI
59
+ * copilot plugin then feeds them into its system prompt so the model
60
+ * knows which props it can set and what shape each one takes.
61
+ *
62
+ * Recursive: `select` fields carry {@link options}, `array` fields
63
+ * carry {@link itemSchema}, and `object` fields carry their own
64
+ * nested {@link itemSchema} describing the object shape.
65
+ *
66
+ * @remarks
67
+ * The recursive variants are modeled here with **loose optionals**
68
+ * (`options?` / `itemSchema?` / `properties?`) rather than a
69
+ * `type`-discriminated union (review finding TS-d). A discriminated
70
+ * union keyed on {@link AiFieldType} — following the closed-union
71
+ * precedents elsewhere in this package
72
+ * (`StudioAssetUploadEvent`, `StudioPluginCapabilities`) — would let
73
+ * the compiler enforce that `select` carries `options`, `array` carries
74
+ * `itemSchema`, etc. That refactor is **breaking** for the `0.1.x` AI
75
+ * contract, so it is deferred to the next contract major; until then,
76
+ * `@anvilkit/schema`/`@anvilkit/validator` own the per-type invariants
77
+ * at runtime (Zod).
78
+ */
79
+ export interface AiFieldSchema {
80
+ /**
81
+ * The prop name on the owning component (e.g. `"title"`,
82
+ * `"ctaHref"`). Must match the key in the component's
83
+ * `defaultProps`.
84
+ */
85
+ readonly name: string;
86
+ /**
87
+ * The field's data type. See {@link AiFieldType}.
88
+ */
89
+ readonly type: AiFieldType;
90
+ /**
91
+ * Whether the prop must be set for the component to render
92
+ * correctly. Defaults to `false` when omitted — the LLM will
93
+ * treat the field as optional.
94
+ */
95
+ readonly required?: boolean;
96
+ /**
97
+ * Human-readable description of what the prop is for. Forwarded
98
+ * verbatim into the LLM prompt, so write it in the voice of
99
+ * instructions to a collaborator ("The headline shown at the
100
+ * top of the hero section").
101
+ */
102
+ readonly description?: string;
103
+ /**
104
+ * For `type: "select"` fields, the allowed values. Each option
105
+ * carries both the machine-readable `value` (written into the
106
+ * prop) and the human-readable `label` (shown to the LLM so it
107
+ * picks the right one).
108
+ */
109
+ readonly options?: readonly {
110
+ readonly label: string;
111
+ readonly value: string;
112
+ }[];
113
+ /**
114
+ * For `type: "array"` fields, the schema of a single item. When the
115
+ * item is itself an object, the item carries its own
116
+ * {@link properties} listing the typed sub-fields.
117
+ *
118
+ * Absent on scalar field types and on `type: "object"` (which uses
119
+ * {@link properties} directly).
120
+ */
121
+ readonly itemSchema?: AiFieldSchema;
122
+ /**
123
+ * For `type: "object"` fields (and `type: "array"` items whose
124
+ * `itemSchema.type === "object"`), the typed sub-fields of the
125
+ * object. Each entry is a fully-formed {@link AiFieldSchema} so
126
+ * the LLM and the validator can reason about nested structure
127
+ * without parsing free-form descriptions.
128
+ *
129
+ * Absent on scalar field types.
130
+ */
131
+ readonly properties?: readonly AiFieldSchema[];
132
+ /**
133
+ * For slot fields (mapped to `type: "object"`), the list of
134
+ * component names that may be inserted into the slot. When
135
+ * omitted, any registered component is allowed.
136
+ *
137
+ * Mirrors Puck's `allow` array on slot field definitions.
138
+ */
139
+ readonly allow?: readonly string[];
140
+ /**
141
+ * For slot fields (mapped to `type: "object"`), the list of
142
+ * component names that may *not* be inserted into the slot.
143
+ *
144
+ * Mirrors Puck's `disallow` array on slot field definitions.
145
+ */
146
+ readonly disallow?: readonly string[];
147
+ }
148
+ /**
149
+ * Description of a single component in a shape an LLM can reason
150
+ * about — name, purpose, props, and an optional concrete example.
151
+ *
152
+ * An array of these is passed to the LLM so it knows what components
153
+ * are available and how to use them. Produced by
154
+ * `@anvilkit/schema`'s `configToAiContext()` (Phase 3) from a Puck
155
+ * `Config`; this package only owns the destination shape.
156
+ */
157
+ export interface AiComponentSchema {
158
+ /**
159
+ * The component name as registered in the Puck config (e.g.
160
+ * `"Hero"`, `"Button"`, `"Card"`). Matches the `type` used in
161
+ * Puck's component data.
162
+ */
163
+ readonly componentName: string;
164
+ /**
165
+ * Human-readable description of what the component does and when
166
+ * to use it. Forwarded verbatim into the LLM prompt — write it
167
+ * as guidance to a collaborator.
168
+ */
169
+ readonly description: string;
170
+ /**
171
+ * The component's props, described field-by-field.
172
+ */
173
+ readonly fields: readonly AiFieldSchema[];
174
+ /**
175
+ * Optional concrete example of a valid prop bag. The LLM uses
176
+ * this as a one-shot example of how the fields should look when
177
+ * populated; leaving it off falls back to zero-shot from the
178
+ * field descriptions alone.
179
+ */
180
+ readonly example?: Readonly<Record<string, unknown>>;
181
+ }
182
+ /**
183
+ * The full input to a single LLM generation call.
184
+ *
185
+ * Constructed by the AI copilot plugin at the moment the user asks
186
+ * for generation. {@link availableComponents} is derived from the
187
+ * Puck `Config` once per session and cached; the remaining fields
188
+ * are per-call hints.
189
+ */
190
+ export interface AiGenerationContext {
191
+ /**
192
+ * Every component the LLM is allowed to emit, described as an
193
+ * {@link AiComponentSchema}. The LLM cannot use a component that
194
+ * is not present in this list.
195
+ */
196
+ readonly availableComponents: readonly AiComponentSchema[];
197
+ /**
198
+ * Optional snapshot of the current Puck page data. Lets the LLM
199
+ * generate contextual edits (e.g. "add a CTA to the existing
200
+ * hero") instead of always producing a full page from scratch.
201
+ */
202
+ readonly currentData?: PuckData;
203
+ /**
204
+ * Optional theme hint (`"light"` or `"dark"`) so the LLM can
205
+ * pick appropriate colors, imagery, and tone. Host apps
206
+ * typically forward the current editor theme.
207
+ */
208
+ readonly theme?: AiThemeHint;
209
+ /**
210
+ * Optional BCP 47 language tag (e.g. `"en-US"`, `"fr-FR"`) so
211
+ * the LLM generates copy in the right language.
212
+ */
213
+ readonly locale?: string;
214
+ }
215
+ /**
216
+ * A single issue produced by validating an LLM's response against
217
+ * the expected component/field shape.
218
+ *
219
+ * `@anvilkit/validator` owns the runtime check that emits these;
220
+ * this package just owns the shape so validator output flows through
221
+ * a stable contract.
222
+ */
223
+ export interface AiValidationIssue {
224
+ /**
225
+ * JSON-pointer-style path to the offending value inside the LLM
226
+ * response (e.g. `"content.0.props.title"`). Empty string means
227
+ * the issue applies to the response as a whole.
228
+ */
229
+ readonly path: string;
230
+ /**
231
+ * Human-readable message describing what went wrong. Suitable
232
+ * for display in a dev console or a toast.
233
+ */
234
+ readonly message: string;
235
+ /**
236
+ * Severity of the issue.
237
+ *
238
+ * - `"warn"` — the response is usable but suspect (e.g. an
239
+ * unexpected extra field).
240
+ * - `"error"` — the response is unusable (e.g. required field
241
+ * missing, wrong type).
242
+ */
243
+ readonly severity: "error" | "warn";
244
+ }
245
+ /**
246
+ * The outcome of validating an LLM response.
247
+ *
248
+ * {@link valid} is `true` only when the response contains zero
249
+ * issues with `severity: "error"` — `"warn"`-level issues may be
250
+ * present even when the response is considered valid.
251
+ */
252
+ export interface AiValidationResult {
253
+ /**
254
+ * `true` iff the response contains no `severity: "error"`
255
+ * issues. A valid response may still carry `"warn"` entries in
256
+ * {@link issues}.
257
+ */
258
+ readonly valid: boolean;
259
+ /**
260
+ * The full list of issues found. Empty array when the response
261
+ * passed without complaint.
262
+ */
263
+ readonly issues: readonly AiValidationIssue[];
264
+ }
265
+ //# sourceMappingURL=ai.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.cts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,UAAU,GACV,QAAQ,GACR,SAAS,GACT,OAAO,GACP,KAAK,GACL,OAAO,GACP,QAAQ,GACR,OAAO,GACP,QAAQ,CAAC;AAEZ;;;;;;;GAO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mBAAmB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC3D;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;CACpC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC9C"}
package/dist/ai.d.ts ADDED
@@ -0,0 +1,265 @@
1
+ /**
2
+ * @file AI generation contract — the types `@anvilkit/schema`,
3
+ * `@anvilkit/validator`, and AI copilot plugins pass between each
4
+ * other when asking an LLM to generate or validate page content.
5
+ *
6
+ * ### Shape of the contract
7
+ *
8
+ * - {@link AiComponentSchema} is a describable-to-an-LLM version of a
9
+ * Puck component config. `@anvilkit/schema` derives this from a
10
+ * Puck `Config` automatically; this package just owns the
11
+ * destination shape.
12
+ * - {@link AiGenerationContext} is the complete input to a single
13
+ * LLM call — the available components plus optional environment
14
+ * hints (current page data, theme, locale).
15
+ * - {@link AiValidationResult} is the output of validating an LLM
16
+ * response against the expected shape. `@anvilkit/validator` owns
17
+ * the runtime check; this package owns the result shape.
18
+ *
19
+ * ### Design rules
20
+ *
21
+ * 1. **Types only.** No runtime code.
22
+ * 2. **Closed field-type union.** {@link AiFieldSchema.type} is a
23
+ * fixed set — adding a new field type is a breaking change so
24
+ * plugin authors are forced to handle every case.
25
+ * 3. **Type-only Puck import.** `Data` is imported via `import type`
26
+ * and erased at compile time — `ai.ts` adds zero runtime
27
+ * reference to `@puckeditor/core`.
28
+ *
29
+ * @see {@link https://github.com/anvilkit/studio/blob/main/docs/tasks/core-006-types-domain.md | core-006}
30
+ */
31
+ import type { Data as PuckData } from "@puckeditor/core";
32
+ /**
33
+ * The finite set of field types an AI schema can describe.
34
+ *
35
+ * Mirrors Puck's own field type union closely but is intentionally a
36
+ * separate, stable enum — the AI contract must not break every time
37
+ * Puck adds or renames a field type. `@anvilkit/schema` maps Puck
38
+ * field types to these values during derivation.
39
+ *
40
+ * Closed union by design: extending this list is a breaking change
41
+ * to the AI contract.
42
+ */
43
+ export type AiFieldType = "text" | "richtext" | "number" | "boolean" | "image" | "url" | "color" | "select" | "array" | "object";
44
+ /**
45
+ * Theme hint forwarded into AI prompts so the model can pick
46
+ * appropriate colors, imagery, and tone (review finding TS-4). Named
47
+ * once here rather than inlining `"light" | "dark"` at each AI context
48
+ * site. (Kept local to the type-only `ai.ts` layer rather than reusing
49
+ * the react-layer `ThemeResolved`, which would cross the engine
50
+ * boundary.)
51
+ */
52
+ export type AiThemeHint = "light" | "dark";
53
+ /**
54
+ * Description of a single prop on a component, in a shape an LLM can
55
+ * reason about.
56
+ *
57
+ * `@anvilkit/schema`'s `configToAiContext()` (Phase 3) produces an
58
+ * array of these from a Puck `Config` field descriptor. The AI
59
+ * copilot plugin then feeds them into its system prompt so the model
60
+ * knows which props it can set and what shape each one takes.
61
+ *
62
+ * Recursive: `select` fields carry {@link options}, `array` fields
63
+ * carry {@link itemSchema}, and `object` fields carry their own
64
+ * nested {@link itemSchema} describing the object shape.
65
+ *
66
+ * @remarks
67
+ * The recursive variants are modeled here with **loose optionals**
68
+ * (`options?` / `itemSchema?` / `properties?`) rather than a
69
+ * `type`-discriminated union (review finding TS-d). A discriminated
70
+ * union keyed on {@link AiFieldType} — following the closed-union
71
+ * precedents elsewhere in this package
72
+ * (`StudioAssetUploadEvent`, `StudioPluginCapabilities`) — would let
73
+ * the compiler enforce that `select` carries `options`, `array` carries
74
+ * `itemSchema`, etc. That refactor is **breaking** for the `0.1.x` AI
75
+ * contract, so it is deferred to the next contract major; until then,
76
+ * `@anvilkit/schema`/`@anvilkit/validator` own the per-type invariants
77
+ * at runtime (Zod).
78
+ */
79
+ export interface AiFieldSchema {
80
+ /**
81
+ * The prop name on the owning component (e.g. `"title"`,
82
+ * `"ctaHref"`). Must match the key in the component's
83
+ * `defaultProps`.
84
+ */
85
+ readonly name: string;
86
+ /**
87
+ * The field's data type. See {@link AiFieldType}.
88
+ */
89
+ readonly type: AiFieldType;
90
+ /**
91
+ * Whether the prop must be set for the component to render
92
+ * correctly. Defaults to `false` when omitted — the LLM will
93
+ * treat the field as optional.
94
+ */
95
+ readonly required?: boolean;
96
+ /**
97
+ * Human-readable description of what the prop is for. Forwarded
98
+ * verbatim into the LLM prompt, so write it in the voice of
99
+ * instructions to a collaborator ("The headline shown at the
100
+ * top of the hero section").
101
+ */
102
+ readonly description?: string;
103
+ /**
104
+ * For `type: "select"` fields, the allowed values. Each option
105
+ * carries both the machine-readable `value` (written into the
106
+ * prop) and the human-readable `label` (shown to the LLM so it
107
+ * picks the right one).
108
+ */
109
+ readonly options?: readonly {
110
+ readonly label: string;
111
+ readonly value: string;
112
+ }[];
113
+ /**
114
+ * For `type: "array"` fields, the schema of a single item. When the
115
+ * item is itself an object, the item carries its own
116
+ * {@link properties} listing the typed sub-fields.
117
+ *
118
+ * Absent on scalar field types and on `type: "object"` (which uses
119
+ * {@link properties} directly).
120
+ */
121
+ readonly itemSchema?: AiFieldSchema;
122
+ /**
123
+ * For `type: "object"` fields (and `type: "array"` items whose
124
+ * `itemSchema.type === "object"`), the typed sub-fields of the
125
+ * object. Each entry is a fully-formed {@link AiFieldSchema} so
126
+ * the LLM and the validator can reason about nested structure
127
+ * without parsing free-form descriptions.
128
+ *
129
+ * Absent on scalar field types.
130
+ */
131
+ readonly properties?: readonly AiFieldSchema[];
132
+ /**
133
+ * For slot fields (mapped to `type: "object"`), the list of
134
+ * component names that may be inserted into the slot. When
135
+ * omitted, any registered component is allowed.
136
+ *
137
+ * Mirrors Puck's `allow` array on slot field definitions.
138
+ */
139
+ readonly allow?: readonly string[];
140
+ /**
141
+ * For slot fields (mapped to `type: "object"`), the list of
142
+ * component names that may *not* be inserted into the slot.
143
+ *
144
+ * Mirrors Puck's `disallow` array on slot field definitions.
145
+ */
146
+ readonly disallow?: readonly string[];
147
+ }
148
+ /**
149
+ * Description of a single component in a shape an LLM can reason
150
+ * about — name, purpose, props, and an optional concrete example.
151
+ *
152
+ * An array of these is passed to the LLM so it knows what components
153
+ * are available and how to use them. Produced by
154
+ * `@anvilkit/schema`'s `configToAiContext()` (Phase 3) from a Puck
155
+ * `Config`; this package only owns the destination shape.
156
+ */
157
+ export interface AiComponentSchema {
158
+ /**
159
+ * The component name as registered in the Puck config (e.g.
160
+ * `"Hero"`, `"Button"`, `"Card"`). Matches the `type` used in
161
+ * Puck's component data.
162
+ */
163
+ readonly componentName: string;
164
+ /**
165
+ * Human-readable description of what the component does and when
166
+ * to use it. Forwarded verbatim into the LLM prompt — write it
167
+ * as guidance to a collaborator.
168
+ */
169
+ readonly description: string;
170
+ /**
171
+ * The component's props, described field-by-field.
172
+ */
173
+ readonly fields: readonly AiFieldSchema[];
174
+ /**
175
+ * Optional concrete example of a valid prop bag. The LLM uses
176
+ * this as a one-shot example of how the fields should look when
177
+ * populated; leaving it off falls back to zero-shot from the
178
+ * field descriptions alone.
179
+ */
180
+ readonly example?: Readonly<Record<string, unknown>>;
181
+ }
182
+ /**
183
+ * The full input to a single LLM generation call.
184
+ *
185
+ * Constructed by the AI copilot plugin at the moment the user asks
186
+ * for generation. {@link availableComponents} is derived from the
187
+ * Puck `Config` once per session and cached; the remaining fields
188
+ * are per-call hints.
189
+ */
190
+ export interface AiGenerationContext {
191
+ /**
192
+ * Every component the LLM is allowed to emit, described as an
193
+ * {@link AiComponentSchema}. The LLM cannot use a component that
194
+ * is not present in this list.
195
+ */
196
+ readonly availableComponents: readonly AiComponentSchema[];
197
+ /**
198
+ * Optional snapshot of the current Puck page data. Lets the LLM
199
+ * generate contextual edits (e.g. "add a CTA to the existing
200
+ * hero") instead of always producing a full page from scratch.
201
+ */
202
+ readonly currentData?: PuckData;
203
+ /**
204
+ * Optional theme hint (`"light"` or `"dark"`) so the LLM can
205
+ * pick appropriate colors, imagery, and tone. Host apps
206
+ * typically forward the current editor theme.
207
+ */
208
+ readonly theme?: AiThemeHint;
209
+ /**
210
+ * Optional BCP 47 language tag (e.g. `"en-US"`, `"fr-FR"`) so
211
+ * the LLM generates copy in the right language.
212
+ */
213
+ readonly locale?: string;
214
+ }
215
+ /**
216
+ * A single issue produced by validating an LLM's response against
217
+ * the expected component/field shape.
218
+ *
219
+ * `@anvilkit/validator` owns the runtime check that emits these;
220
+ * this package just owns the shape so validator output flows through
221
+ * a stable contract.
222
+ */
223
+ export interface AiValidationIssue {
224
+ /**
225
+ * JSON-pointer-style path to the offending value inside the LLM
226
+ * response (e.g. `"content.0.props.title"`). Empty string means
227
+ * the issue applies to the response as a whole.
228
+ */
229
+ readonly path: string;
230
+ /**
231
+ * Human-readable message describing what went wrong. Suitable
232
+ * for display in a dev console or a toast.
233
+ */
234
+ readonly message: string;
235
+ /**
236
+ * Severity of the issue.
237
+ *
238
+ * - `"warn"` — the response is usable but suspect (e.g. an
239
+ * unexpected extra field).
240
+ * - `"error"` — the response is unusable (e.g. required field
241
+ * missing, wrong type).
242
+ */
243
+ readonly severity: "error" | "warn";
244
+ }
245
+ /**
246
+ * The outcome of validating an LLM response.
247
+ *
248
+ * {@link valid} is `true` only when the response contains zero
249
+ * issues with `severity: "error"` — `"warn"`-level issues may be
250
+ * present even when the response is considered valid.
251
+ */
252
+ export interface AiValidationResult {
253
+ /**
254
+ * `true` iff the response contains no `severity: "error"`
255
+ * issues. A valid response may still carry `"warn"` entries in
256
+ * {@link issues}.
257
+ */
258
+ readonly valid: boolean;
259
+ /**
260
+ * The full list of issues found. Empty array when the response
261
+ * passed without complaint.
262
+ */
263
+ readonly issues: readonly AiValidationIssue[];
264
+ }
265
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../src/ai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,UAAU,GACV,QAAQ,GACR,SAAS,GACT,OAAO,GACP,KAAK,GACL,OAAO,GACP,QAAQ,GACR,OAAO,GACP,QAAQ,CAAC;AAEZ;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS;QAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACvB,EAAE,CAAC;IACJ;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACpC;;;;;;;;OAQG;IACH,QAAQ,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;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC9C"}
package/dist/ai.js ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Asset resolution types — live in their own module so `plugin.ts` and
3
+ * `export.ts` can both reference them without a cycle.
4
+ */
5
+ /**
6
+ * The outcome of resolving an indirect asset reference (e.g. `asset://…`) to a
7
+ * concrete, directly-usable location.
8
+ */
9
+ export interface AssetResolution {
10
+ /** The resolved asset URL — e.g. an `https:` / `data:` URL or a relative path. */
11
+ readonly url: string;
12
+ /**
13
+ * Optional resolver-supplied metadata (e.g. dimensions, MIME type,
14
+ * attribution). Opaque to the core — passed through to consumers verbatim.
15
+ */
16
+ readonly meta?: Readonly<Record<string, unknown>>;
17
+ }
18
+ /**
19
+ * Rewrites an asset reference to its resolved location, or returns `null` when
20
+ * this resolver does not handle the reference.
21
+ *
22
+ * Resolvers are registered via the plugin context's `registerAssetResolver`
23
+ * seam and collected into `StudioRuntime.assetResolvers` in registration
24
+ * order. A consuming export format consults each in order and stops at the
25
+ * first non-null result; how a format treats a reference that no resolver
26
+ * handles is the format's own policy. May run sync or async — the pipeline
27
+ * awaits the result.
28
+ *
29
+ * @param url - The raw reference to resolve (e.g. an `asset://…` URL).
30
+ */
31
+ export type IRAssetResolver = (url: string) => Promise<AssetResolution | null> | AssetResolution | null;
32
+ //# sourceMappingURL=assets.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.cts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,GAAG,EAAE,MAAM,KACP,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Asset resolution types — live in their own module so `plugin.ts` and
3
+ * `export.ts` can both reference them without a cycle.
4
+ */
5
+ /**
6
+ * The outcome of resolving an indirect asset reference (e.g. `asset://…`) to a
7
+ * concrete, directly-usable location.
8
+ */
9
+ export interface AssetResolution {
10
+ /** The resolved asset URL — e.g. an `https:` / `data:` URL or a relative path. */
11
+ readonly url: string;
12
+ /**
13
+ * Optional resolver-supplied metadata (e.g. dimensions, MIME type,
14
+ * attribution). Opaque to the core — passed through to consumers verbatim.
15
+ */
16
+ readonly meta?: Readonly<Record<string, unknown>>;
17
+ }
18
+ /**
19
+ * Rewrites an asset reference to its resolved location, or returns `null` when
20
+ * this resolver does not handle the reference.
21
+ *
22
+ * Resolvers are registered via the plugin context's `registerAssetResolver`
23
+ * seam and collected into `StudioRuntime.assetResolvers` in registration
24
+ * order. A consuming export format consults each in order and stops at the
25
+ * first non-null result; how a format treats a reference that no resolver
26
+ * handles is the format's own policy. May run sync or async — the pipeline
27
+ * awaits the result.
28
+ *
29
+ * @param url - The raw reference to resolve (e.g. an `asset://…` URL).
30
+ */
31
+ export type IRAssetResolver = (url: string) => Promise<AssetResolution | null> | AssetResolution | null;
32
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,kFAAkF;IAClF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG,CAC7B,GAAG,EAAE,MAAM,KACP,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC"}
package/dist/assets.js ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });