@pixerate/editor 0.23.0 → 0.25.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.
Files changed (187) hide show
  1. package/README.md +167 -2
  2. package/THIRD_PARTY_NOTICES.md +80 -0
  3. package/dist/agent/index.cjs +10 -8
  4. package/dist/agent/index.cjs.map +1 -1
  5. package/dist/agent/index.d.cts +4 -3
  6. package/dist/agent/index.d.ts +4 -3
  7. package/dist/agent/index.js +4 -2
  8. package/dist/agent/index.js.map +1 -1
  9. package/dist/canvas/index.cjs +4437 -411
  10. package/dist/canvas/index.cjs.map +1 -1
  11. package/dist/canvas/index.d.cts +934 -4
  12. package/dist/canvas/index.d.ts +934 -4
  13. package/dist/canvas/index.js +4309 -283
  14. package/dist/canvas/index.js.map +1 -1
  15. package/dist/chunk-4BVP64JJ.cjs +1406 -0
  16. package/dist/chunk-4BVP64JJ.cjs.map +1 -0
  17. package/dist/chunk-664LQYFJ.js +115 -0
  18. package/dist/chunk-664LQYFJ.js.map +1 -0
  19. package/dist/chunk-7WISYZFO.cjs +740 -0
  20. package/dist/chunk-7WISYZFO.cjs.map +1 -0
  21. package/dist/chunk-AL6JMGWW.cjs +783 -0
  22. package/dist/chunk-AL6JMGWW.cjs.map +1 -0
  23. package/dist/chunk-BVP3TSLH.cjs +69 -0
  24. package/dist/chunk-BVP3TSLH.cjs.map +1 -0
  25. package/dist/{chunk-RIKBJLS2.cjs → chunk-C7P22VIP.cjs} +2001 -279
  26. package/dist/chunk-C7P22VIP.cjs.map +1 -0
  27. package/dist/chunk-D6FH2YAX.cjs +131 -0
  28. package/dist/chunk-D6FH2YAX.cjs.map +1 -0
  29. package/dist/chunk-ECCCYKGL.js +740 -0
  30. package/dist/chunk-ECCCYKGL.js.map +1 -0
  31. package/dist/{chunk-4SUNJZWB.cjs → chunk-FD4LPFAE.cjs} +48 -200
  32. package/dist/chunk-FD4LPFAE.cjs.map +1 -0
  33. package/dist/{chunk-QBJ22YZR.js → chunk-FH6F67DN.js} +1999 -277
  34. package/dist/chunk-FH6F67DN.js.map +1 -0
  35. package/dist/{chunk-OYXSKQFR.js → chunk-FPENXAEJ.js} +35 -187
  36. package/dist/chunk-FPENXAEJ.js.map +1 -0
  37. package/dist/chunk-HLIMTC6N.js +1 -0
  38. package/dist/chunk-HLIMTC6N.js.map +1 -0
  39. package/dist/chunk-HRMEDT2L.js +1406 -0
  40. package/dist/chunk-HRMEDT2L.js.map +1 -0
  41. package/dist/{chunk-QGHGJ56O.js → chunk-IXHSYOVY.js} +2518 -122
  42. package/dist/chunk-IXHSYOVY.js.map +1 -0
  43. package/dist/chunk-MKA3AHLV.cjs +256 -0
  44. package/dist/chunk-MKA3AHLV.cjs.map +1 -0
  45. package/dist/chunk-NAXVVS5I.js +783 -0
  46. package/dist/chunk-NAXVVS5I.js.map +1 -0
  47. package/dist/chunk-O5RYH2PG.js +69 -0
  48. package/dist/chunk-O5RYH2PG.js.map +1 -0
  49. package/dist/chunk-OXSV64JX.js +689 -0
  50. package/dist/chunk-OXSV64JX.js.map +1 -0
  51. package/dist/chunk-P3RQ5UJE.cjs +689 -0
  52. package/dist/chunk-P3RQ5UJE.cjs.map +1 -0
  53. package/dist/chunk-P6ODPZ4W.js +256 -0
  54. package/dist/chunk-P6ODPZ4W.js.map +1 -0
  55. package/dist/chunk-PL4JB3BF.cjs +1 -0
  56. package/dist/chunk-PL4JB3BF.cjs.map +1 -0
  57. package/dist/{chunk-GVSMRPHB.cjs → chunk-PO6A6QQH.cjs} +2607 -211
  58. package/dist/chunk-PO6A6QQH.cjs.map +1 -0
  59. package/dist/{chunk-JJDLPEWL.js → chunk-QGYDWPRM.js} +2 -2
  60. package/dist/chunk-RR7F5GUM.js +5726 -0
  61. package/dist/chunk-RR7F5GUM.js.map +1 -0
  62. package/dist/chunk-TNNJXF46.cjs +115 -0
  63. package/dist/chunk-TNNJXF46.cjs.map +1 -0
  64. package/dist/chunk-U5HZSFCS.js +131 -0
  65. package/dist/chunk-U5HZSFCS.js.map +1 -0
  66. package/dist/{chunk-MJZBNWG7.js → chunk-UAKDG62Z.js} +309 -581
  67. package/dist/chunk-UAKDG62Z.js.map +1 -0
  68. package/dist/{chunk-CL37JGFW.cjs → chunk-V3CHHWOE.cjs} +4 -4
  69. package/dist/{chunk-CL37JGFW.cjs.map → chunk-V3CHHWOE.cjs.map} +1 -1
  70. package/dist/chunk-WSQKHXW7.cjs +5726 -0
  71. package/dist/chunk-WSQKHXW7.cjs.map +1 -0
  72. package/dist/{chunk-AA4ZEVCC.cjs → chunk-X4N4WUKB.cjs} +336 -608
  73. package/dist/chunk-X4N4WUKB.cjs.map +1 -0
  74. package/dist/commands/index.cjs +74 -1
  75. package/dist/commands/index.cjs.map +1 -1
  76. package/dist/commands/index.d.cts +38 -353
  77. package/dist/commands/index.d.ts +38 -353
  78. package/dist/commands/index.js +73 -0
  79. package/dist/commands/index.js.map +1 -1
  80. package/dist/comment-store-BEMgVlAA.d.cts +135 -0
  81. package/dist/comment-store-BEMgVlAA.d.ts +135 -0
  82. package/dist/compare/index.cjs +15 -0
  83. package/dist/compare/index.cjs.map +1 -0
  84. package/dist/compare/index.d.cts +58 -0
  85. package/dist/compare/index.d.ts +58 -0
  86. package/dist/compare/index.js +15 -0
  87. package/dist/compare/index.js.map +1 -0
  88. package/dist/controller-BIJiNoVs.d.cts +1842 -0
  89. package/dist/controller-BIJiNoVs.d.ts +1842 -0
  90. package/dist/documents-CHT1U5Vs.d.ts +86 -0
  91. package/dist/documents-Gp7wb0Me.d.cts +86 -0
  92. package/dist/extensions/index.cjs +100 -5
  93. package/dist/extensions/index.cjs.map +1 -1
  94. package/dist/extensions/index.d.cts +16 -4
  95. package/dist/extensions/index.d.ts +16 -4
  96. package/dist/extensions/index.js +100 -5
  97. package/dist/generation/index.cjs +2317 -0
  98. package/dist/generation/index.cjs.map +1 -0
  99. package/dist/generation/index.d.cts +1015 -0
  100. package/dist/generation/index.d.ts +1015 -0
  101. package/dist/generation/index.js +2317 -0
  102. package/dist/generation/index.js.map +1 -0
  103. package/dist/grammar/index.cjs +48 -3
  104. package/dist/grammar/index.cjs.map +1 -1
  105. package/dist/grammar/index.d.cts +322 -100
  106. package/dist/grammar/index.d.ts +322 -100
  107. package/dist/grammar/index.js +54 -9
  108. package/dist/image-editor/index.cjs +4392 -481
  109. package/dist/image-editor/index.cjs.map +1 -1
  110. package/dist/image-editor/index.d.cts +1249 -97
  111. package/dist/image-editor/index.d.ts +1249 -97
  112. package/dist/image-editor/index.js +4281 -370
  113. package/dist/image-editor/index.js.map +1 -1
  114. package/dist/index-7a6bHTLy.d.ts +1754 -0
  115. package/dist/index-Csd5qI8u.d.cts +1754 -0
  116. package/dist/index.cjs +1682 -99
  117. package/dist/index.cjs.map +1 -1
  118. package/dist/index.d.cts +118 -21
  119. package/dist/index.d.ts +118 -21
  120. package/dist/index.js +1630 -47
  121. package/dist/index.js.map +1 -1
  122. package/dist/mention-text-CDnCFd3c.d.cts +53 -0
  123. package/dist/mention-text-CDnCFd3c.d.ts +53 -0
  124. package/dist/migrate-iTlm3a8h.d.cts +112 -0
  125. package/dist/migrate-iTlm3a8h.d.ts +112 -0
  126. package/dist/model-C1zApQM8.d.cts +219 -0
  127. package/dist/model-C1zApQM8.d.ts +219 -0
  128. package/dist/persistence/index.cjs +676 -0
  129. package/dist/persistence/index.cjs.map +1 -0
  130. package/dist/persistence/index.d.cts +230 -0
  131. package/dist/persistence/index.d.ts +230 -0
  132. package/dist/persistence/index.js +676 -0
  133. package/dist/persistence/index.js.map +1 -0
  134. package/dist/{registry-D5-R90p0.d.cts → registry-BDe-vlv3.d.ts} +2 -40
  135. package/dist/{registry-GJI4gToU.d.ts → registry-CEgwXED1.d.cts} +12 -1
  136. package/dist/{registry-GJI4gToU.d.cts → registry-CEgwXED1.d.ts} +12 -1
  137. package/dist/registry-D32LpIc4.d.cts +354 -0
  138. package/dist/{registry-D5-R90p0.d.ts → registry-DnzpgY27.d.cts} +2 -40
  139. package/dist/registry-evKTP4ls.d.ts +354 -0
  140. package/dist/schema-DYDGdYL9.d.cts +41 -0
  141. package/dist/schema-DYDGdYL9.d.ts +41 -0
  142. package/dist/serializers/index.cjs +12 -3
  143. package/dist/serializers/index.cjs.map +1 -1
  144. package/dist/serializers/index.d.cts +40 -12
  145. package/dist/serializers/index.d.ts +40 -12
  146. package/dist/serializers/index.js +12 -3
  147. package/dist/sourcemap-C8AH3MBQ.d.cts +91 -0
  148. package/dist/sourcemap-DA1Evhrv.d.ts +91 -0
  149. package/dist/spreadsheet/index.cjs +161 -3
  150. package/dist/spreadsheet/index.cjs.map +1 -1
  151. package/dist/spreadsheet/index.d.cts +611 -20
  152. package/dist/spreadsheet/index.d.ts +611 -20
  153. package/dist/spreadsheet/index.js +168 -10
  154. package/dist/storage-BpFfspHm.d.cts +120 -0
  155. package/dist/storage-BpFfspHm.d.ts +120 -0
  156. package/dist/tokens/index.cjs +115 -0
  157. package/dist/tokens/index.cjs.map +1 -0
  158. package/dist/tokens/index.d.cts +212 -0
  159. package/dist/tokens/index.d.ts +212 -0
  160. package/dist/tokens/index.js +115 -0
  161. package/dist/tokens/index.js.map +1 -0
  162. package/dist/{tokens-CyLZmIei.d.cts → tokens-D7yXvUU6.d.cts} +15 -2
  163. package/dist/{tokens-CyLZmIei.d.ts → tokens-D7yXvUU6.d.ts} +15 -2
  164. package/dist/{track-changes-BSF58RK0.d.cts → track-changes-D_VAPELi.d.cts} +110 -144
  165. package/dist/{track-changes-BSF58RK0.d.ts → track-changes-Db_fGEvx.d.ts} +110 -144
  166. package/package.json +21 -1
  167. package/dist/chunk-4SUNJZWB.cjs.map +0 -1
  168. package/dist/chunk-AA4ZEVCC.cjs.map +0 -1
  169. package/dist/chunk-AXV2ZW34.cjs +0 -118
  170. package/dist/chunk-AXV2ZW34.cjs.map +0 -1
  171. package/dist/chunk-B2ZRLN4S.js +0 -118
  172. package/dist/chunk-B2ZRLN4S.js.map +0 -1
  173. package/dist/chunk-GVSMRPHB.cjs.map +0 -1
  174. package/dist/chunk-K3R5NG2D.js +0 -3100
  175. package/dist/chunk-K3R5NG2D.js.map +0 -1
  176. package/dist/chunk-MJZBNWG7.js.map +0 -1
  177. package/dist/chunk-OYXSKQFR.js.map +0 -1
  178. package/dist/chunk-QBJ22YZR.js.map +0 -1
  179. package/dist/chunk-QGHGJ56O.js.map +0 -1
  180. package/dist/chunk-RIKBJLS2.cjs.map +0 -1
  181. package/dist/chunk-XDMXXC4Z.cjs +0 -3100
  182. package/dist/chunk-XDMXXC4Z.cjs.map +0 -1
  183. package/dist/controller-pePCJLT1.d.cts +0 -959
  184. package/dist/controller-pePCJLT1.d.ts +0 -959
  185. package/dist/index-CCr_z9kF.d.cts +0 -899
  186. package/dist/index-Ck6ajwXh.d.ts +0 -899
  187. /package/dist/{chunk-JJDLPEWL.js.map → chunk-QGYDWPRM.js.map} +0 -0
@@ -0,0 +1,1015 @@
1
+ import { J as JsonSchema } from '../schema-DYDGdYL9.cjs';
2
+ export { S as SchemaValidationError, v as validateJsonSchema } from '../schema-DYDGdYL9.cjs';
3
+ import { A as AgentToolProvider } from '../registry-DnzpgY27.cjs';
4
+ export { a as AgentTool, d as McpToolDefinition, e as McpToolResult } from '../registry-DnzpgY27.cjs';
5
+ import { S as SourceMapSegment } from '../sourcemap-C8AH3MBQ.cjs';
6
+ import { T as Template, P as PromptValues } from '../tokens-D7yXvUU6.cjs';
7
+ import { S as StorageAdapter } from '../storage-BpFfspHm.cjs';
8
+ export { a as MentionRoleSyntax, T as TextMention, f as findTextMentions, b as formatMentionText, s as setMentionRoleInText } from '../mention-text-CDnCFd3c.cjs';
9
+
10
+ /**
11
+ * Declarative descriptions of generative models (what a model accepts) and of
12
+ * the requests sent to them. Everything here is plain data so capabilities can
13
+ * come from a server, be merged with local presentation overlays, and be
14
+ * turned into JSON Schema for agents.
15
+ */
16
+ type GenerationMediaKind = 'image' | 'video' | 'audio' | 'text';
17
+ /** The reference roles this library knows by name (labels, aliases, schema order). */
18
+ type BuiltinReferenceRole = 'start_frame' | 'end_frame' | 'style_ref' | 'character_ref' | 'background_ref' | 'mask' | 'image_ref' | 'video_ref' | 'audio_ref';
19
+ /**
20
+ * What a reference input (an asset) is used for. The built-in roles are
21
+ * listed in {@link REFERENCE_ROLES}; models may declare any other role name
22
+ * (e.g. `subject`, `pose`) in `references.roles`, which makes it valid for
23
+ * that model. Role names match {@link REFERENCE_ROLE_NAME_REGEX}.
24
+ */
25
+ type ReferenceRole = BuiltinReferenceRole | (string & {});
26
+ /** Valid role names: a letter, then letters, digits, `_` or `-`, not ending in `_` or `-`. */
27
+ declare const REFERENCE_ROLE_NAME_REGEX: RegExp;
28
+ /** True for a string usable as a role name. */
29
+ declare function isReferenceRoleName(value: unknown): value is ReferenceRole;
30
+ /** Every built-in reference role, in a stable display order. */
31
+ declare const REFERENCE_ROLES: readonly BuiltinReferenceRole[];
32
+ /** Human-readable default labels for reference roles. */
33
+ declare const REFERENCE_ROLE_LABELS: Readonly<Record<BuiltinReferenceRole, string>>;
34
+ /**
35
+ * Friendly role names accepted wherever a role is written by hand (asset
36
+ * mentions such as `@fox:style`, agent calls). A model that declares the
37
+ * alias itself (e.g. its own `style` role) keeps it; otherwise the alias maps
38
+ * to the built-in role. Keys are lower case.
39
+ */
40
+ declare const REFERENCE_ROLE_ALIASES: Readonly<Record<string, BuiltinReferenceRole>>;
41
+ /** Display label of a role: the model's label, the built-in label, or the name made readable. */
42
+ declare function referenceRoleLabel(role: ReferenceRole, caps?: ModelCapabilities): string;
43
+ /**
44
+ * Canonical role for a hand-written name: the name itself when the model
45
+ * declares it (or, without a model, when it is built in), else its alias
46
+ * ({@link REFERENCE_ROLE_ALIASES}, case-insensitive), else the trimmed name.
47
+ */
48
+ declare function normalizeReferenceRole(role: string, caps?: ModelCapabilities): ReferenceRole;
49
+ /**
50
+ * Whether `mediaType` (a MIME type such as `image/png`, or a media kind such
51
+ * as `image`) matches one of `accepts` (`image`, `image/*`, `image/png`).
52
+ * An empty or missing `accepts` accepts everything; an unknown media type
53
+ * only matches a missing `accepts`.
54
+ */
55
+ declare function mediaTypeMatches(mediaType: string | undefined, accepts: readonly string[] | undefined): boolean;
56
+ /** A choice from a fixed list. `options` order matters (low → high where it applies). */
57
+ interface EnumCapability<T extends string | number = string> {
58
+ options: readonly T[];
59
+ default?: T;
60
+ /** Display labels by option value. */
61
+ labels?: Readonly<Record<string, string>>;
62
+ }
63
+ interface TextFieldCapability {
64
+ maxLength?: number;
65
+ }
66
+ interface PromptCapability extends TextFieldCapability {
67
+ /**
68
+ * Count the resolved prompt (templates expanded, variables substituted)
69
+ * against `maxLength` rather than the raw template text. Default `true`.
70
+ * Pass the resolved text to the planner as `resolvedPrompt`.
71
+ */
72
+ countResolved?: boolean;
73
+ /** The prompt must be non-empty. */
74
+ required?: boolean;
75
+ }
76
+ interface CountCapability {
77
+ /** Largest number of outputs per request. */
78
+ max: number;
79
+ /** Predefined choices; when given, requests snap to one of them. */
80
+ options?: readonly number[];
81
+ default?: number;
82
+ }
83
+ interface DurationCapability {
84
+ /** Seconds. */
85
+ min?: number;
86
+ max?: number;
87
+ /** Predefined choices; when given, requests snap to one of them. */
88
+ options?: readonly number[];
89
+ default?: number;
90
+ step?: number;
91
+ }
92
+ interface SeedCapability {
93
+ min?: number;
94
+ max?: number;
95
+ }
96
+ interface ReferenceRoleCapability {
97
+ /** Most references of this role. */
98
+ max: number;
99
+ /** Fewest references of this role (e.g. an image-to-video model needs a `start_frame`). */
100
+ min?: number;
101
+ label?: string;
102
+ description?: string;
103
+ /**
104
+ * Media accepted for this role: kinds (`image`), wildcards (`image/*`) or
105
+ * MIME types (`image/png`). Absent: anything. References whose
106
+ * `mediaType` does not match are dropped or rejected by the planner.
107
+ */
108
+ accepts?: readonly string[];
109
+ }
110
+ interface ReferenceCapability {
111
+ /** Supported roles and their per-role limits. Roles not listed are unsupported. */
112
+ roles: Partial<Readonly<Record<ReferenceRole, ReferenceRoleCapability>>>;
113
+ /** Most references across all roles. */
114
+ maxTotal?: number;
115
+ }
116
+ interface NumberParamSpec {
117
+ type: 'number' | 'integer';
118
+ min?: number;
119
+ max?: number;
120
+ step?: number;
121
+ default?: number;
122
+ label?: string;
123
+ description?: string;
124
+ }
125
+ interface EnumParamSpec {
126
+ type: 'enum';
127
+ options: readonly (string | number)[];
128
+ default?: string | number;
129
+ label?: string;
130
+ description?: string;
131
+ }
132
+ interface BooleanParamSpec {
133
+ type: 'boolean';
134
+ default?: boolean;
135
+ label?: string;
136
+ description?: string;
137
+ }
138
+ /** A model-specific parameter (`guidance`, `motion_strength`, `style`, …). */
139
+ type ExtraParamSpec = NumberParamSpec | EnumParamSpec | BooleanParamSpec;
140
+ /** Rough timing used for progress estimates (`expectedDurationFor`). */
141
+ interface TimingCapability {
142
+ /** Fixed cost of one request in ms. */
143
+ baseMs: number;
144
+ /** Extra ms per output beyond the first. */
145
+ perItemMs?: number;
146
+ /** Extra ms per second of requested duration (video/audio). */
147
+ perSecondMs?: number;
148
+ /** Extra ms per megapixel of the requested resolution. */
149
+ perMegapixelMs?: number;
150
+ }
151
+ /** Presentation-only fields; overlays may set these (see `mergeCapabilities`). */
152
+ interface CapabilityPresentation {
153
+ name?: string;
154
+ description?: string;
155
+ badges?: readonly string[];
156
+ icon?: string;
157
+ group?: string;
158
+ }
159
+ /** Everything a generative model accepts. Absent sections mean "unsupported". */
160
+ interface ModelCapabilities extends CapabilityPresentation {
161
+ id: string;
162
+ media: GenerationMediaKind;
163
+ prompt?: PromptCapability;
164
+ /** Negative prompt support (`true` or limits). */
165
+ negativePrompt?: boolean | TextFieldCapability;
166
+ /** System prompt support (`true` or limits). */
167
+ systemPrompt?: boolean | TextFieldCapability;
168
+ /** E.g. `['1:1', '16:9', '9:16']`. */
169
+ aspectRatios?: EnumCapability<string>;
170
+ /** E.g. `['512x512', '1024x1024']`, `['720p', '1080p']` or `['1k', '2k', '4k']`, low → high. */
171
+ resolutions?: EnumCapability<string>;
172
+ /** Ordered low → high, e.g. `['draft', 'standard', 'high']`. */
173
+ quality?: EnumCapability<string>;
174
+ count?: CountCapability;
175
+ duration?: DurationCapability;
176
+ seed?: boolean | SeedCapability;
177
+ references?: ReferenceCapability;
178
+ /** Accepts a source to edit (`mode: 'edit'`). */
179
+ editing?: boolean;
180
+ /** Accepts a source plus a `mask` reference (`mode: 'inpaint'`). */
181
+ inpainting?: boolean;
182
+ params?: Readonly<Record<string, ExtraParamSpec>>;
183
+ timing?: TimingCapability;
184
+ }
185
+ interface GenerationReference {
186
+ /** Asset id (opaque to this library). */
187
+ id: string;
188
+ role: ReferenceRole;
189
+ url?: string;
190
+ /** MIME type or media kind, checked against the role's `accepts`. */
191
+ mediaType?: string;
192
+ /** Content hash of the asset when it was referenced (used by generation records). */
193
+ contentHash?: string;
194
+ }
195
+ type GenerationMode = 'generate' | 'edit' | 'inpaint';
196
+ type GenerationParamValue = string | number | boolean;
197
+ /** A request for one model. Every field is optional; the planner fills and fixes. */
198
+ interface GenerationRequest {
199
+ model?: string;
200
+ prompt?: string;
201
+ negativePrompt?: string;
202
+ systemPrompt?: string;
203
+ aspectRatio?: string;
204
+ resolution?: string;
205
+ quality?: string;
206
+ count?: number;
207
+ /** Seconds. */
208
+ duration?: number;
209
+ seed?: number;
210
+ mode?: GenerationMode;
211
+ references?: GenerationReference[];
212
+ params?: Record<string, GenerationParamValue>;
213
+ }
214
+ /** Fields of {@link GenerationRequest} the planner knows about, in planning order. */
215
+ declare const GENERATION_REQUEST_FIELDS: readonly ["model", "prompt", "negativePrompt", "systemPrompt", "aspectRatio", "resolution", "quality", "count", "duration", "seed", "mode", "references", "params"];
216
+ /** Text field limits normalized from `boolean | TextFieldCapability`. */
217
+ declare function textFieldCapability(value: boolean | TextFieldCapability | undefined): TextFieldCapability | null;
218
+ /** Seed limits normalized from `boolean | SeedCapability`. */
219
+ declare function seedCapability(value: boolean | SeedCapability | undefined): SeedCapability | null;
220
+ /**
221
+ * Supported reference roles of a model: built-in roles in
222
+ * {@link REFERENCE_ROLES} order, then custom roles in declaration order.
223
+ */
224
+ declare function supportedReferenceRoles(caps: ModelCapabilities): ReferenceRole[];
225
+ /** Supported generation modes of a model. */
226
+ declare function supportedModes(caps: ModelCapabilities): GenerationMode[];
227
+ /** A partial model entry used to decorate (or add) models locally. */
228
+ type CapabilityOverlay = Partial<ModelCapabilities> & {
229
+ id: string;
230
+ };
231
+ /**
232
+ * Merges server-reported capabilities with a local overlay. For models the
233
+ * server knows, every capability value comes from `remote`; the overlay only
234
+ * contributes presentation fields (`name`, `description`, `badges`, `icon`,
235
+ * `group`), filling in or replacing the remote ones. Overlay entries for
236
+ * models the server does not report are appended when they are complete
237
+ * (have a `media` kind). Remote order is kept; overlay-only models follow in
238
+ * overlay order.
239
+ */
240
+ declare function mergeCapabilities(remote: readonly ModelCapabilities[], overlay?: readonly CapabilityOverlay[]): ModelCapabilities[];
241
+
242
+ /**
243
+ * How the planner treats values the model does not support:
244
+ *
245
+ * - `error`: nothing is changed; every mismatch is an error.
246
+ * - `nearest`: snap to the closest supported value (ties go to the higher
247
+ * value), clamp ranges, truncate lists, drop unsupported fields and
248
+ * unsupported references.
249
+ * - `downgrade`: like `nearest`, but ties go to the lower value.
250
+ * - `upgrade`: like `nearest`, but never drops references the model cannot
251
+ * use (that would lose intent), so those are errors.
252
+ *
253
+ * "Lower" means a narrower aspect ratio, fewer pixels, an earlier quality
254
+ * option, a smaller number.
255
+ */
256
+ type PlanStrategy = 'error' | 'upgrade' | 'downgrade' | 'nearest';
257
+ type PlanAdjustmentKind = 'snapped' | 'clamped' | 'truncated' | 'dropped' | 'defaulted';
258
+ interface PlanAdjustment {
259
+ /** Request path, e.g. `aspectRatio`, `params.guidance`, `references.style_ref`. */
260
+ field: string;
261
+ from: unknown;
262
+ to: unknown;
263
+ reason: string;
264
+ kind: PlanAdjustmentKind;
265
+ }
266
+ interface PlanError {
267
+ field: string;
268
+ value: unknown;
269
+ message: string;
270
+ }
271
+ interface GenerationPlan {
272
+ /** `true` when there are no errors and `request` can be sent. */
273
+ ok: boolean;
274
+ /** The adjusted request (always a copy; the input is never mutated). */
275
+ request: GenerationRequest;
276
+ adjustments: PlanAdjustment[];
277
+ errors: PlanError[];
278
+ /** Model the plan was made for. */
279
+ model: string;
280
+ strategy: PlanStrategy;
281
+ }
282
+ interface PlanOptions {
283
+ /** Default `nearest`. */
284
+ strategy?: PlanStrategy;
285
+ /**
286
+ * The prompt with templates and variables resolved. Measured against
287
+ * `prompt.maxLength` when the model counts resolved text (the default).
288
+ */
289
+ resolvedPrompt?: string;
290
+ /** Fill missing fields that have a capability `default` (reported as `defaulted`). */
291
+ fillDefaults?: boolean;
292
+ /** Override whether references with unsupported roles may be dropped (default: `nearest` and `downgrade` only). */
293
+ dropUnsupportedReferences?: boolean;
294
+ /**
295
+ * Assets mentioned in the prompt (e.g. from `extractMentions(text, { details: true, roles: true })`
296
+ * joined with your asset library). They are appended to `request.references`
297
+ * and validated per role like any other reference. A mention without a role
298
+ * gets `defaultMentionRole`, or the first role of the model that accepts its
299
+ * media type (reported as `defaulted`).
300
+ */
301
+ mentions?: readonly PlanAssetMention[];
302
+ /** Role for mentions that have none (see `mentions`). */
303
+ defaultMentionRole?: ReferenceRole;
304
+ }
305
+ /** An asset mention handed to the planner (see {@link PlanOptions.mentions}). */
306
+ interface PlanAssetMention {
307
+ /** Asset id. */
308
+ id: string;
309
+ role?: ReferenceRole | null;
310
+ mediaType?: string;
311
+ contentHash?: string;
312
+ url?: string;
313
+ /** The mention text, used in messages (default: the id). */
314
+ label?: string;
315
+ }
316
+ /** Numeric rank of an aspect ratio such as `16:9` (log of width / height). */
317
+ declare function aspectRatioRank(value: string): number | undefined;
318
+ /**
319
+ * Numeric rank of a resolution: `1024x768` (pixels), `720p` (16:9 pixels at
320
+ * that height) or `2k` (square of that many kibi-pixels). Log scale.
321
+ */
322
+ declare function resolutionRank(value: string): number | undefined;
323
+ /** Megapixels of a resolution string, when it can be parsed. */
324
+ declare function resolutionMegapixels(value: string): number | undefined;
325
+ /** Common quality names, low → high. Used to compare values missing from a model's options. */
326
+ declare const QUALITY_LADDER: Readonly<Record<string, number>>;
327
+ declare function qualityRank(value: string): number | undefined;
328
+ /**
329
+ * Picks the option closest to `value` by `rank`. Ties go to the lower or
330
+ * higher rank. Returns `undefined` when `value` or no option can be ranked.
331
+ */
332
+ declare function snapToOption<T>(value: unknown, options: readonly T[], rank: (value: any) => number | undefined, tie: 'lower' | 'higher'): T | undefined;
333
+ /**
334
+ * Plans `request` against a model's capabilities before sending it: snaps
335
+ * enum values (aspect ratio, resolution, quality, count/duration choices) to
336
+ * the nearest supported option, clamps ranges, truncates text and reference
337
+ * lists over their limits, drops unsupported fields, and reports every change
338
+ * in `adjustments` and every unfixable problem in `errors`.
339
+ *
340
+ * Pure and deterministic: the input is not mutated and the same input always
341
+ * gives the same plan.
342
+ */
343
+ declare function planGenerationRequest(request: GenerationRequest, caps: ModelCapabilities, options?: PlanOptions): GenerationPlan;
344
+
345
+ /**
346
+ * JSON Schema for a request to one model: enums for choices, `minimum` /
347
+ * `maximum` for ranges, `maxItems` for reference lists and `description`s that
348
+ * spell out limits the schema cannot express (per-role reference counts,
349
+ * resolved-prompt length). Unsupported fields are absent and
350
+ * `additionalProperties` is `false`, so `validateJsonSchema` rejects them.
351
+ */
352
+ declare function capabilitiesToJsonSchema(caps: ModelCapabilities): JsonSchema & {
353
+ type: 'object';
354
+ };
355
+
356
+ interface GenerateContext {
357
+ model: ModelCapabilities;
358
+ plan: GenerationPlan;
359
+ idempotencyKey: string;
360
+ signal?: AbortSignal;
361
+ }
362
+ interface EstimateContext {
363
+ model: ModelCapabilities;
364
+ plan: GenerationPlan;
365
+ signal?: AbortSignal;
366
+ }
367
+ interface GenerationToolProviderOptions {
368
+ /** Provider id (default `generation`). */
369
+ id?: string;
370
+ namespace?: string;
371
+ /** Models, or a function returning the current models (re-read on every list/call). */
372
+ models: readonly ModelCapabilities[] | (() => readonly ModelCapabilities[]);
373
+ /** Sends a planned request. Its resolved value is the tool result (e.g. `{ jobId }`). */
374
+ generate: (request: GenerationRequest, context: GenerateContext) => unknown | Promise<unknown>;
375
+ /** Optional cost/time estimate; adds the `estimate_generation` tool. */
376
+ estimate?: (request: GenerationRequest, context: EstimateContext) => unknown | Promise<unknown>;
377
+ /** Strategy used when the caller does not pass one (default `nearest`). */
378
+ defaultStrategy?: PlanStrategy;
379
+ /** Completed idempotency keys remembered (default 500, oldest evicted first). */
380
+ maxIdempotencyKeys?: number;
381
+ /** Lets the host signal that the model list changed. */
382
+ subscribe?: AgentToolProvider['subscribe'];
383
+ }
384
+ interface GenerationToolProvider extends AgentToolProvider {
385
+ /** Forgets remembered idempotency keys (all, or one). */
386
+ clearIdempotencyKeys(key?: string): void;
387
+ }
388
+ /**
389
+ * Exposes generation models to a `ToolRegistry`:
390
+ *
391
+ * - `list_models` (read-only): ids, presentation fields and per-model request schemas.
392
+ * - `plan_generation` (read-only): the adjusted request, adjustments and errors.
393
+ * - `estimate_generation` (read-only, only with `estimate`): your estimate for the planned request.
394
+ * - `generate` (destructive): plans, then calls `generate` with the adjusted
395
+ * request. Requires an `idempotencyKey`: a retry with the same key and
396
+ * arguments returns the first call's result (or joins it while in flight)
397
+ * instead of generating again; the same key with different arguments is
398
+ * rejected. Failed calls forget their key so they can be retried.
399
+ */
400
+ declare function createGenerationToolProvider(options: GenerationToolProviderOptions): GenerationToolProvider;
401
+
402
+ declare const PROVENANCE_FORMAT = "pixerate.generation-provenance";
403
+ declare const PROVENANCE_VERSION = 1;
404
+ /** The exact template body a generation used. */
405
+ interface PinnedTemplate {
406
+ name: string;
407
+ templateId?: string;
408
+ /** Version id or version label the body came from (absent for unversioned templates). */
409
+ versionId?: string;
410
+ version?: string | number;
411
+ body: string;
412
+ }
413
+ /** Everything needed to explain and reproduce one generation. */
414
+ interface GenerationProvenance {
415
+ format: typeof PROVENANCE_FORMAT;
416
+ version: typeof PROVENANCE_VERSION;
417
+ /** Raw prompt as typed, with `{{templates}}` and `{variables}`. */
418
+ rawPrompt: string;
419
+ /** Every template the prompt reached (recursively), pinned to the body used. */
420
+ templates: PinnedTemplate[];
421
+ /** Version bindings in effect (`{ templateName: versionId }`) for every pinned versioned template. */
422
+ bindings: Record<string, string>;
423
+ /** Variable values, or `null` when variables were left unresolved. */
424
+ values: PromptValues | null;
425
+ resolvedPrompt: string;
426
+ sourceMap: SourceMapSegment[];
427
+ modelId: string;
428
+ /** The planned (adjusted) request that was sent. */
429
+ request: GenerationRequest;
430
+ adjustments: PlanAdjustment[];
431
+ references: {
432
+ id: string;
433
+ role: ReferenceRole;
434
+ }[];
435
+ /** ISO timestamps. */
436
+ createdAt: string;
437
+ startedAt?: string;
438
+ completedAt?: string;
439
+ /** Ids of the outputs this generation produced. */
440
+ outputIds?: string[];
441
+ meta?: Record<string, unknown>;
442
+ }
443
+ interface CreateProvenanceOptions {
444
+ rawPrompt: string;
445
+ templates?: Template[];
446
+ /** Template version bindings (`{ templateName: versionIdOrVersion }`). */
447
+ bindings?: Record<string, string>;
448
+ values?: PromptValues;
449
+ model: string | ModelCapabilities;
450
+ /** The plan the request came from (its request and adjustments are recorded) … */
451
+ plan?: GenerationPlan;
452
+ /** … or the request that was sent. */
453
+ request?: GenerationRequest;
454
+ adjustments?: PlanAdjustment[];
455
+ /** Creation time (default `Date.now()`). */
456
+ createdAt?: Date | number | string;
457
+ startedAt?: Date | number | string;
458
+ completedAt?: Date | number | string;
459
+ outputIds?: string[];
460
+ meta?: Record<string, unknown>;
461
+ maxDepth?: number;
462
+ }
463
+ declare class ProvenanceParseError extends Error {
464
+ constructor(message: string);
465
+ }
466
+ /** Templates that reproduce the pinned bodies exactly (one single-version template each). */
467
+ declare function pinnedTemplatesToTemplates(pinned: readonly PinnedTemplate[]): Template[];
468
+ /**
469
+ * Records what produced an output: the raw prompt, the exact template bodies
470
+ * and versions it reached, variable values, the resolved prompt and its
471
+ * source map, the model, the planned settings and adjustments, and the
472
+ * references by role.
473
+ */
474
+ declare function createProvenance(options: CreateProvenanceOptions): GenerationProvenance;
475
+ /** Versioned JSON for storage next to an output. */
476
+ declare function serializeProvenance(provenance: GenerationProvenance): string;
477
+ /** Parses and checks serialized provenance. Throws {@link ProvenanceParseError}. */
478
+ declare function parseProvenance(input: string | unknown): GenerationProvenance;
479
+ /**
480
+ * Re-resolves the raw prompt against the pinned template bodies and values,
481
+ * e.g. to check a record or to open it in an editor with its source map.
482
+ */
483
+ declare function replayProvenancePrompt(provenance: GenerationProvenance): {
484
+ text: string;
485
+ map: SourceMapSegment[];
486
+ matches: boolean;
487
+ };
488
+
489
+ interface BatchResolverOptions<K, V> {
490
+ /** Loads many keys at once. Keys missing from the map resolve to `undefined`. */
491
+ fetch: (keys: K[]) => Promise<Map<K, V>>;
492
+ /** Largest batch passed to `fetch` (default 50). */
493
+ maxBatch?: number;
494
+ /** How long to collect keys before fetching, in ms (default 0: the same tick). */
495
+ delayMs?: number;
496
+ /** Called once per failed batch. The batch's keys are recorded as resolved-empty. */
497
+ onError?: (error: unknown, keys: K[]) => void;
498
+ }
499
+ interface BatchResolver<K, V> {
500
+ /** Resolves one key, batched with other loads in the same window. Never rejects. */
501
+ load(key: K): Promise<V | undefined>;
502
+ loadMany(keys: readonly K[]): Promise<(V | undefined)[]>;
503
+ /** The settled value for a key, if it has been resolved. */
504
+ peek(key: K): V | undefined;
505
+ /** Whether a key has settled (found, missing or failed). */
506
+ has(key: K): boolean;
507
+ /** Whether a key's last fetch failed. */
508
+ failed(key: K): boolean;
509
+ /** Seeds a value without fetching. */
510
+ prime(key: K, value: V): void;
511
+ /** Forgets one key (or all) so the next `load` fetches again. */
512
+ clear(key?: K): void;
513
+ /** Fetches anything still waiting now, without waiting for `delayMs`. */
514
+ flush(): void;
515
+ }
516
+ /**
517
+ * Coalesces lookups (e.g. asset ids → thumbnails, template ids → bodies) into
518
+ * batched `fetch` calls: keys requested within `delayMs` share a batch of at
519
+ * most `maxBatch`, duplicate keys are fetched once, and results are cached.
520
+ * A failed batch resolves its keys to `undefined` and records them as
521
+ * resolved-empty (`failed(key)` is `true`) so one bad response does not cause
522
+ * a retry storm; `clear(key)` allows a retry.
523
+ */
524
+ declare function createBatchResolver<K, V>(options: BatchResolverOptions<K, V>): BatchResolver<K, V>;
525
+
526
+ interface JobProgressInput {
527
+ /** Start time (ms since epoch, `Date` or ISO string). */
528
+ startedAt: number | Date | string;
529
+ /** Current time (default `Date.now()`). */
530
+ now?: number | Date | string;
531
+ /** Expected total duration in ms. Without it progress eases towards 95%. */
532
+ expectedMs?: number;
533
+ /** The job finished. */
534
+ done?: boolean;
535
+ }
536
+ interface JobProgressEstimate {
537
+ /** 0–100. Never above 95 until `done`. */
538
+ percent: number;
539
+ /** E.g. `~2m left`, `~40s left`, `Almost done…`, `Starting…`, `Done`. */
540
+ label: string;
541
+ elapsedMs: number;
542
+ /** Estimated ms left (`undefined` without `expectedMs`). */
543
+ remainingMs?: number;
544
+ /** Running longer than expected. */
545
+ overdue: boolean;
546
+ }
547
+ /** Highest percentage shown before a job reports completion. */
548
+ declare const MAX_PENDING_PERCENT = 95;
549
+ /** `~45s left`, `~2m left`, `~1h 5m left`. Minutes and seconds round up. */
550
+ declare function formatRemaining(ms: number): string;
551
+ /**
552
+ * Progress for a job that reports no progress of its own: linear in elapsed
553
+ * time over `expectedMs`, held at 95% until `done` (so the bar never sits at
554
+ * 100% while still waiting), with a "~2m left" style label that turns into
555
+ * "Almost done…" near or past the expected end. Pure: pass `now` to test.
556
+ */
557
+ declare function estimateJobProgress(input: JobProgressInput): JobProgressEstimate;
558
+ /**
559
+ * Expected duration of a request from the model's `timing`: `baseMs`, plus
560
+ * `perItemMs` per output beyond the first, `perSecondMs` per second of
561
+ * duration and `perMegapixelMs` per megapixel of resolution. `undefined` when
562
+ * the model has no timing.
563
+ */
564
+ declare function expectedDurationFor(caps: ModelCapabilities, request?: GenerationRequest): number | undefined;
565
+
566
+ interface GenerationControlOption {
567
+ value: string | number;
568
+ label: string;
569
+ }
570
+ /**
571
+ * A UI control derived from capabilities. `key` is a request path:
572
+ * `aspectRatio`, `count`, `params.guidance`, …
573
+ */
574
+ interface GenerationControl {
575
+ key: string;
576
+ label: string;
577
+ /** `select` for choices, `range` for bounded numbers, `number` for open numbers. */
578
+ kind: 'select' | 'range' | 'number' | 'textarea' | 'checkbox';
579
+ valueType: 'string' | 'number' | 'boolean';
580
+ options?: GenerationControlOption[];
581
+ min?: number;
582
+ max?: number;
583
+ step?: number;
584
+ maxLength?: number;
585
+ defaultValue?: string | number | boolean;
586
+ description?: string;
587
+ }
588
+ interface ReferenceSlot {
589
+ role: ReferenceRole;
590
+ label: string;
591
+ description?: string;
592
+ min: number;
593
+ max: number;
594
+ /** Media accepted for this role (see `ReferenceRoleCapability.accepts`). */
595
+ accepts?: string[];
596
+ references: GenerationReference[];
597
+ /** More references of this role fit (per role and in total). */
598
+ canAdd: boolean;
599
+ }
600
+ /**
601
+ * The settings controls a model supports, in display order. Excludes the
602
+ * prompt (edited by the prompt editor) and references (see
603
+ * {@link getReferenceSlots}).
604
+ */
605
+ declare function getGenerationControls(caps: ModelCapabilities): GenerationControl[];
606
+ /** Reads a request value by control key (`params.x` reads a param). */
607
+ declare function getRequestValue(request: GenerationRequest, key: string): unknown;
608
+ /** Returns a copy of `request` with `key` set (`undefined` or `''` removes it). */
609
+ declare function setRequestValue(request: GenerationRequest, key: string, value: unknown): GenerationRequest;
610
+ /** Parses a DOM control's string value into the control's value type. */
611
+ declare function parseControlValue(control: GenerationControl, raw: string | boolean): string | number | boolean | undefined;
612
+ /** Reference slots for every role the model accepts, filled from `request`. */
613
+ declare function getReferenceSlots(caps: ModelCapabilities, request?: GenerationRequest): ReferenceSlot[];
614
+ /** Returns a copy of `request` with a reference appended. */
615
+ declare function addReference(request: GenerationRequest, reference: GenerationReference): GenerationRequest;
616
+ /** Returns a copy of `request` without the reference `id` in `role`. */
617
+ declare function removeReference(request: GenerationRequest, role: ReferenceRole, id: string): GenerationRequest;
618
+
619
+ /**
620
+ * Stable JSON: object keys sorted, `undefined` members left out, so equal
621
+ * values always give the same string regardless of key order.
622
+ */
623
+ declare function stableStringify(value: unknown): string;
624
+ /**
625
+ * A short, stable, synchronous content hash (two independent 32-bit FNV-1a
626
+ * lanes over the UTF-16 code units, 16 hex digits, prefixed with `h1-`).
627
+ * It detects changes; it is not cryptographic, so do not use it to
628
+ * authenticate content.
629
+ */
630
+ declare function hashText(text: string): string;
631
+ /** {@link hashText} of the {@link stableStringify} form of `value`. */
632
+ declare function hashValue(value: unknown): string;
633
+ /**
634
+ * Hash of what a model accepts. Presentation fields (`name`, `description`,
635
+ * `badges`, `icon`, `group`) and `timing` are left out, so renaming a model or
636
+ * changing its progress estimate is not reported as a capability change.
637
+ */
638
+ declare function hashCapabilities(caps: ModelCapabilities): string;
639
+
640
+ /** A role a model accepts for asset mentions / references, for pickers. */
641
+ interface AssetRoleOption {
642
+ role: ReferenceRole;
643
+ label: string;
644
+ description?: string;
645
+ min: number;
646
+ max: number;
647
+ accepts?: string[];
648
+ }
649
+ /** What the host knows about an asset (for planning, records and drift checks). */
650
+ interface AssetInfo {
651
+ id: string;
652
+ label?: string;
653
+ /** MIME type or media kind (`image/png`, `image`). */
654
+ mediaType?: string;
655
+ /** Content hash; a change is reported as `asset-changed` drift. */
656
+ contentHash?: string;
657
+ url?: string;
658
+ }
659
+ /** Assets by id: a lookup function, a map, or a list. */
660
+ type AssetLookup = ((id: string) => AssetInfo | null | undefined) | ReadonlyMap<string, AssetInfo> | readonly AssetInfo[];
661
+ /** Normalizes an {@link AssetLookup} to a function. */
662
+ declare function toAssetResolver(lookup: AssetLookup | undefined): ((id: string) => AssetInfo | undefined) | undefined;
663
+ /** The roles a model accepts, with labels, limits and accepted media (inpainting adds `mask`). */
664
+ declare function getAssetRoleOptions(caps: ModelCapabilities): AssetRoleOption[];
665
+ type AssetMentionIssueCode = 'missing-role' | 'unsupported-role' | 'renamed-role' | 'media-mismatch' | 'too-many';
666
+ interface AssetMentionIssue {
667
+ /** Index of the mention in the input. */
668
+ index: number;
669
+ id: string;
670
+ role?: ReferenceRole;
671
+ code: AssetMentionIssueCode;
672
+ /** `error` blocks generation under the `error` strategy; `warning` is fixed by planning. */
673
+ severity: 'error' | 'warning';
674
+ message: string;
675
+ /** The role the planner will use instead (`renamed-role`). */
676
+ suggestion?: ReferenceRole;
677
+ }
678
+ interface AssetMentionValidation {
679
+ ok: boolean;
680
+ issues: AssetMentionIssue[];
681
+ /** Mentions per (canonical) role. */
682
+ counts: Record<string, number>;
683
+ /** Roles below their `min`. */
684
+ missing: {
685
+ role: ReferenceRole;
686
+ min: number;
687
+ count: number;
688
+ }[];
689
+ }
690
+ /**
691
+ * Checks asset mentions against what a model accepts, per mention, for UI
692
+ * feedback (badges, popovers). Mirrors the planner: aliases (`style` →
693
+ * `style_ref`) are accepted with a `renamed-role` warning, unsupported roles,
694
+ * media types the role does not accept and mentions beyond a role's `max`
695
+ * are reported, and roles below their `min` are listed in `missing`.
696
+ */
697
+ declare function validateAssetMentions(mentions: readonly PlanAssetMention[], caps: ModelCapabilities, options?: {
698
+ assets?: AssetLookup;
699
+ }): AssetMentionValidation;
700
+ /**
701
+ * Joins mentions (`{ handle, role }`, e.g. from `extractMentions(text, { details: true, roles: true })`)
702
+ * with your assets: each handle is looked up by id, then by label
703
+ * (case-insensitive). Mentions that are not assets are left out.
704
+ */
705
+ declare function resolveAssetMentions(mentions: readonly {
706
+ handle: string;
707
+ role?: string | null;
708
+ }[], assets: readonly AssetInfo[]): PlanAssetMention[];
709
+ /** Built-in roles as picker options, for when no model is selected. */
710
+ declare function defaultAssetRoleOptions(): AssetRoleOption[];
711
+ /** An asset mention prepared for display as a chip. */
712
+ interface AssetMentionChip {
713
+ /** Position among the chips. */
714
+ index: number;
715
+ /** Offset of the `@` in the text, when known (for `setMentionRoleInText`). */
716
+ start?: number;
717
+ handle: string;
718
+ asset: AssetInfo;
719
+ role?: ReferenceRole;
720
+ /** Display label of the role (the model's, else built-in). */
721
+ roleLabel?: string;
722
+ /** Problems with this mention for the model (`validateAssetMentions`). */
723
+ issues: AssetMentionIssue[];
724
+ }
725
+ /**
726
+ * Chips for the asset mentions among `mentions` (e.g. `findTextMentions(text)`
727
+ * from `@pixerate/editor/serializers`): each mention whose handle is an asset
728
+ * id or label, with its role label and the problems the model has with it.
729
+ */
730
+ declare function describeAssetMentions(mentions: readonly {
731
+ handle: string;
732
+ role?: string | null;
733
+ start?: number;
734
+ }[], assets: readonly AssetInfo[], caps?: ModelCapabilities): AssetMentionChip[];
735
+
736
+ declare const GENERATION_RECORD_FORMAT = "pixerate.generation-record";
737
+ declare const GENERATION_RECORD_VERSION = 1;
738
+ /** How a record came about. */
739
+ type GenerationRecordKind = 'generate' | 'recreate' | 'variation';
740
+ /** A template the generation used, with a hash of the exact body. */
741
+ interface RecordedTemplate {
742
+ name: string;
743
+ templateId?: string;
744
+ versionId?: string;
745
+ version?: string | number;
746
+ /** {@link hashText} of the body that was used. */
747
+ hash: string;
748
+ }
749
+ /** An asset the generation used, by role, with its content hash at the time. */
750
+ interface RecordedAsset {
751
+ id: string;
752
+ role: ReferenceRole;
753
+ contentHash?: string;
754
+ mediaType?: string;
755
+ url?: string;
756
+ }
757
+ /**
758
+ * Everything needed to reproduce one generation. The prompt, templates,
759
+ * values, resolved prompt, source map, planned request and adjustments live
760
+ * in `provenance` (see `createProvenance`); the record adds hashes for
761
+ * change detection, the user's original settings, assets and lineage.
762
+ */
763
+ interface GenerationRecord {
764
+ format: typeof GENERATION_RECORD_FORMAT;
765
+ version: typeof GENERATION_RECORD_VERSION;
766
+ id: string;
767
+ /** The record this one was recreated or varied from. */
768
+ parentId?: string;
769
+ kind: GenerationRecordKind;
770
+ provenance: GenerationProvenance;
771
+ /** One entry per template in `provenance.templates`, same order. */
772
+ templates: RecordedTemplate[];
773
+ /** {@link hashText} of `provenance.resolvedPrompt`. */
774
+ promptHash: string;
775
+ /** {@link hashCapabilities} of the model when the record was made (absent when only an id was known). */
776
+ capabilityHash?: string;
777
+ /** The request as the user set it, before planning (snapping, clamping, dropping). */
778
+ settings: GenerationRequest;
779
+ /** Strategy the request was planned with. */
780
+ strategy: PlanStrategy;
781
+ /** Seed used: the one the provider reported, else the planned one. */
782
+ seed?: number;
783
+ assets: RecordedAsset[];
784
+ /** Asset mentions that were planned as references (kept apart from `settings`). */
785
+ mentions?: PlanAssetMention[];
786
+ /** ISO timestamp (same as `provenance.createdAt`). */
787
+ createdAt: string;
788
+ updatedAt?: string;
789
+ }
790
+ interface CreateGenerationRecordOptions extends Omit<CreateProvenanceOptions, 'model' | 'plan' | 'request' | 'adjustments'> {
791
+ /** The model (needed for the capability hash and for planning when `plan` is absent). */
792
+ model: ModelCapabilities | string;
793
+ /** The user's settings before planning. */
794
+ request?: GenerationRequest;
795
+ /** The plan that was sent. Without it the request is planned here (needs capabilities). */
796
+ plan?: GenerationPlan;
797
+ /** Strategy for planning here, and recorded for recreating (default: the plan's, else `nearest`). */
798
+ strategy?: PlanStrategy;
799
+ /** Asset mentions to plan as references (see `PlanOptions.mentions`). */
800
+ mentions?: readonly PlanAssetMention[];
801
+ /** Fills in content hashes and media types of referenced assets. */
802
+ assets?: AssetLookup;
803
+ /** Seed the provider actually used, when it differs from the planned one (e.g. random). */
804
+ seed?: number;
805
+ id?: string;
806
+ parentId?: string;
807
+ kind?: GenerationRecordKind;
808
+ }
809
+ /** A unique record id (`crypto.randomUUID` when available). */
810
+ declare function createGenerationRecordId(): string;
811
+ /**
812
+ * Records a generation so it can be listed, explained and recreated. Builds
813
+ * the provenance (pinned template bodies, values, resolved prompt and source
814
+ * map, planned request, adjustments) and adds a hash per template body, the
815
+ * capability hash of the model, the user's original settings, the seed, the
816
+ * referenced assets with their roles and content hashes, and the parent
817
+ * record. Plans the request when no `plan` is given and `model` is a
818
+ * capability object.
819
+ */
820
+ declare function createGenerationRecord(options: CreateGenerationRecordOptions): GenerationRecord;
821
+ /** Returns a copy of `record` with outputs and completion time added (e.g. when the job finishes). */
822
+ declare function completeGenerationRecord(record: GenerationRecord, update: {
823
+ outputIds?: string[];
824
+ completedAt?: Date | number | string;
825
+ seed?: number;
826
+ meta?: Record<string, unknown>;
827
+ }): GenerationRecord;
828
+ /** Versioned JSON for storage. */
829
+ declare function serializeGenerationRecord(record: GenerationRecord): string;
830
+ /** Parses and checks a serialized record. Throws `ProvenanceParseError`. */
831
+ declare function parseGenerationRecord(input: string | unknown): GenerationRecord;
832
+ /** True for a {@link GenerationRecord} (as opposed to bare provenance). */
833
+ declare function isGenerationRecord(value: unknown): value is GenerationRecord;
834
+ /**
835
+ * `exact`: the same resolved prompt (pinned template bodies), the planned
836
+ * settings that were sent, the same seed. `latest`: the raw prompt resolved
837
+ * against today's templates (latest versions) and the user's original
838
+ * settings planned against today's capabilities, with the same seed.
839
+ */
840
+ type RecreateMode = 'exact' | 'latest';
841
+ type DriftType = 'template-changed' | 'template-missing' | 'prompt-changed' | 'model-missing' | 'model-changed' | 'setting-unsupported' | 'setting-changed' | 'asset-missing' | 'asset-changed';
842
+ interface DriftItem {
843
+ type: DriftType;
844
+ /** `error` items make `ok` false (the request cannot reproduce the record). */
845
+ severity: 'info' | 'warning' | 'error';
846
+ message: string;
847
+ /** Template name (template drift). */
848
+ template?: string;
849
+ /** Request path, e.g. `resolution`, `params.guidance`, `references` (setting drift). */
850
+ field?: string;
851
+ /** Asset id and role (asset drift). */
852
+ assetId?: string;
853
+ role?: ReferenceRole;
854
+ modelId?: string;
855
+ /** Recorded and current value, version or hash. */
856
+ from?: unknown;
857
+ to?: unknown;
858
+ /** Whether the change is in the returned request (`latest` mode), or only reported (`exact`). */
859
+ applied?: boolean;
860
+ }
861
+ interface RecreateOptions {
862
+ /** Current templates (to detect edits, and to resolve in `latest` mode). */
863
+ templates?: readonly Template[];
864
+ /** Current model capabilities: one model, or a list to find the record's model in. */
865
+ capabilities?: ModelCapabilities | readonly ModelCapabilities[];
866
+ /** Default `exact`. */
867
+ mode?: RecreateMode;
868
+ /** Current assets, to report missing or changed assets. */
869
+ assets?: AssetLookup;
870
+ /** Planning strategy (default: the record's). */
871
+ strategy?: PlanStrategy;
872
+ }
873
+ interface RecreateResult {
874
+ mode: RecreateMode;
875
+ /** No `error` drift and (when capabilities were given) the plan has no errors. */
876
+ ok: boolean;
877
+ /** The request to send (re-planned when capabilities were given). */
878
+ request: GenerationRequest;
879
+ /** The plan against current capabilities (absent without capabilities or when the model is gone). */
880
+ plan?: GenerationPlan;
881
+ rawPrompt: string;
882
+ resolvedPrompt: string;
883
+ sourceMap: SourceMapSegment[];
884
+ values: PromptValues | null;
885
+ /** Templates and bindings the prompt was resolved with. */
886
+ templates: Template[];
887
+ bindings: Record<string, string>;
888
+ drift: DriftItem[];
889
+ /** The record this request comes from. */
890
+ parentId: string;
891
+ kind: Exclude<GenerationRecordKind, 'generate'>;
892
+ /** Options for {@link createGenerationRecord} once the new generation has run. */
893
+ recordOptions: CreateGenerationRecordOptions;
894
+ }
895
+ /** Changes for {@link variationRequest}. */
896
+ interface VariationOverrides {
897
+ /** New seed, `null` for none, or absent for a random one different from the record's. */
898
+ seed?: number | null;
899
+ /** Values merged over the recorded ones. */
900
+ values?: PromptValues;
901
+ /** Settings merged over the recreated request (`params` are merged too). */
902
+ settings?: Partial<GenerationRequest>;
903
+ /** A different raw prompt. */
904
+ rawPrompt?: string;
905
+ /** Random source in [0, 1) for the seed (default `Math.random`). */
906
+ random?: () => number;
907
+ }
908
+ /**
909
+ * Rebuilds the request of a recorded generation.
910
+ *
911
+ * - With a {@link GenerationRecord}: returns a {@link RecreateResult} with the
912
+ * re-planned request and a drift report: templates edited or deleted since,
913
+ * model capabilities changed or the model gone, settings no longer
914
+ * supported (or, in `latest` mode, planned differently), assets missing or
915
+ * changed. `mode: 'exact'` (default) reproduces the recorded prompt and
916
+ * settings; `mode: 'latest'` uses current templates and re-plans the
917
+ * original settings. Template edits are always reported; only `latest`
918
+ * applies them.
919
+ * - With bare {@link GenerationProvenance} (the original API): returns the
920
+ * planned request that was sent, with the prompt as resolved at the time.
921
+ */
922
+ declare function recreateRequest(provenance: GenerationProvenance): GenerationRequest;
923
+ declare function recreateRequest(record: GenerationRecord, options?: RecreateOptions): RecreateResult;
924
+ /**
925
+ * A request for a variation of a recorded generation: the same prompt,
926
+ * settings and assets (as {@link recreateRequest} would rebuild them, `exact`
927
+ * mode by default) with a new seed (random within the model's range unless
928
+ * given) and any overrides. Setting drift is not reported for the fields you
929
+ * change; template, model and asset drift are.
930
+ */
931
+ declare function variationRequest(record: GenerationRecord, overrides?: VariationOverrides, options?: RecreateOptions): RecreateResult;
932
+ /** Short display labels for drift types (history panels, badges). */
933
+ declare const DRIFT_TYPE_LABELS: Readonly<Record<DriftType, string>>;
934
+ /** Drift items that block an exact reproduction (`severity: 'error'`). */
935
+ declare function blockingDrift(drift: readonly DriftItem[]): DriftItem[];
936
+
937
+ /** What the store indexes per record (kept in one index entry, so lists need no record reads). */
938
+ interface GenerationRecordSummary {
939
+ id: string;
940
+ modelId: string;
941
+ kind: GenerationRecordKind;
942
+ parentId?: string;
943
+ createdAt: string;
944
+ /** Template names and ids used. */
945
+ templates: string[];
946
+ templateIds: string[];
947
+ /** Asset ids and roles used. */
948
+ assets: string[];
949
+ roles: ReferenceRole[];
950
+ /** First 160 characters of the resolved prompt, for lists. */
951
+ preview: string;
952
+ }
953
+ interface GenerationRecordFilter {
954
+ /** Model id(s). */
955
+ model?: string | readonly string[];
956
+ /** Template name or id. */
957
+ template?: string;
958
+ /** Asset id. */
959
+ asset?: string;
960
+ role?: ReferenceRole;
961
+ kind?: GenerationRecordKind;
962
+ parentId?: string;
963
+ /** Created at or after / before (exclusive). */
964
+ since?: Date | number | string;
965
+ until?: Date | number | string;
966
+ /** Case-insensitive text in the prompt preview. */
967
+ text?: string;
968
+ offset?: number;
969
+ limit?: number;
970
+ }
971
+ interface PruneOptions {
972
+ /** Keep at most this many records (newest first). */
973
+ maxRecords?: number;
974
+ /** Remove records created before this time. */
975
+ olderThan?: Date | number | string;
976
+ /** Records for which this returns `true` are never removed (they still count toward `maxRecords`). */
977
+ keep?: (summary: GenerationRecordSummary) => boolean;
978
+ }
979
+ interface GenerationRecordStoreOptions {
980
+ storage: Pick<StorageAdapter, 'get' | 'set' | 'remove'>;
981
+ /** Key prefix (default `pixerate.generation-records`). */
982
+ namespace?: string;
983
+ /** Prune to this many records after every `put`. */
984
+ maxRecords?: number;
985
+ }
986
+ interface GenerationRecordStore {
987
+ /** Adds or replaces a record. */
988
+ put(record: GenerationRecord): Promise<void>;
989
+ get(id: string): Promise<GenerationRecord | null>;
990
+ /** Records matching `filter`, newest first. Unreadable records are skipped. */
991
+ list(filter?: GenerationRecordFilter): Promise<GenerationRecord[]>;
992
+ /** Index entries matching `filter`, newest first (no record reads). */
993
+ summaries(filter?: GenerationRecordFilter): Promise<GenerationRecordSummary[]>;
994
+ remove(id: string): Promise<boolean>;
995
+ /** Removes records by count and age; returns the removed ids. */
996
+ prune(options: PruneOptions): Promise<string[]>;
997
+ clear(): Promise<void>;
998
+ /** Called after every change. Returns an unsubscribe function. */
999
+ subscribe(listener: () => void): () => void;
1000
+ }
1001
+ /** The index entry for a record. */
1002
+ declare function summarizeGenerationRecord(record: GenerationRecord): GenerationRecordSummary;
1003
+ /** True when `summary` matches every condition of `filter` (ignores `offset` / `limit`). */
1004
+ declare function matchesRecordFilter(summary: GenerationRecordSummary, filter?: GenerationRecordFilter): boolean;
1005
+ /**
1006
+ * Persists generation records on a key/value `StorageAdapter`
1007
+ * (`createMemoryStorage`, `createLocalStorageAdapter`, `createIndexedDbAdapter`,
1008
+ * `createOpfsAdapter`). Each record is stored under its own key and a single
1009
+ * index entry holds the summaries used for listing and filtering. Operations
1010
+ * run one at a time, so concurrent `put`s do not lose index entries. The index
1011
+ * is cached after the first read: use one store per storage namespace.
1012
+ */
1013
+ declare function createGenerationRecordStore(options: GenerationRecordStoreOptions): GenerationRecordStore;
1014
+
1015
+ export { AgentToolProvider, type AssetInfo, type AssetLookup, type AssetMentionChip, type AssetMentionIssue, type AssetMentionIssueCode, type AssetMentionValidation, type AssetRoleOption, type BatchResolver, type BatchResolverOptions, type BooleanParamSpec, type BuiltinReferenceRole, type CapabilityOverlay, type CapabilityPresentation, type CountCapability, type CreateGenerationRecordOptions, type CreateProvenanceOptions, DRIFT_TYPE_LABELS, type DriftItem, type DriftType, type DurationCapability, type EnumCapability, type EnumParamSpec, type EstimateContext, type ExtraParamSpec, GENERATION_RECORD_FORMAT, GENERATION_RECORD_VERSION, GENERATION_REQUEST_FIELDS, type GenerateContext, type GenerationControl, type GenerationControlOption, type GenerationMediaKind, type GenerationMode, type GenerationParamValue, type GenerationPlan, type GenerationProvenance, type GenerationRecord, type GenerationRecordFilter, type GenerationRecordKind, type GenerationRecordStore, type GenerationRecordStoreOptions, type GenerationRecordSummary, type GenerationReference, type GenerationRequest, type GenerationToolProvider, type GenerationToolProviderOptions, type JobProgressEstimate, type JobProgressInput, JsonSchema, MAX_PENDING_PERCENT, type ModelCapabilities, type NumberParamSpec, PROVENANCE_FORMAT, PROVENANCE_VERSION, type PinnedTemplate, type PlanAdjustment, type PlanAdjustmentKind, type PlanAssetMention, type PlanError, type PlanOptions, type PlanStrategy, type PromptCapability, ProvenanceParseError, type PruneOptions, QUALITY_LADDER, REFERENCE_ROLES, REFERENCE_ROLE_ALIASES, REFERENCE_ROLE_LABELS, REFERENCE_ROLE_NAME_REGEX, type RecordedAsset, type RecordedTemplate, type RecreateMode, type RecreateOptions, type RecreateResult, type ReferenceCapability, type ReferenceRole, type ReferenceRoleCapability, type ReferenceSlot, type SeedCapability, type TextFieldCapability, type TimingCapability, type VariationOverrides, addReference, aspectRatioRank, blockingDrift, capabilitiesToJsonSchema, completeGenerationRecord, createBatchResolver, createGenerationRecord, createGenerationRecordId, createGenerationRecordStore, createGenerationToolProvider, createProvenance, defaultAssetRoleOptions, describeAssetMentions, estimateJobProgress, expectedDurationFor, formatRemaining, getAssetRoleOptions, getGenerationControls, getReferenceSlots, getRequestValue, hashCapabilities, hashText, hashValue, isGenerationRecord, isReferenceRoleName, matchesRecordFilter, mediaTypeMatches, mergeCapabilities, normalizeReferenceRole, parseControlValue, parseGenerationRecord, parseProvenance, pinnedTemplatesToTemplates, planGenerationRequest, qualityRank, recreateRequest, referenceRoleLabel, removeReference, replayProvenancePrompt, resolutionMegapixels, resolutionRank, resolveAssetMentions, seedCapability, serializeGenerationRecord, serializeProvenance, setRequestValue, snapToOption, stableStringify, summarizeGenerationRecord, supportedModes, supportedReferenceRoles, textFieldCapability, toAssetResolver, validateAssetMentions, variationRequest };