@pixerate/editor 0.135.0 → 0.137.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 (164) hide show
  1. package/dist/animation-editor/index.cjs +63 -55
  2. package/dist/animation-editor/index.cjs.map +1 -1
  3. package/dist/animation-editor/index.d.cts +8 -5
  4. package/dist/animation-editor/index.d.ts +8 -5
  5. package/dist/animation-editor/index.js +10 -2
  6. package/dist/animation-editor/index.js.map +1 -1
  7. package/dist/{bezier-J8i4uqSH.d.cts → bezier-CZ2AhjID.d.cts} +1 -1
  8. package/dist/{bezier-lNEOp0Jx.d.ts → bezier-Dywv3Bw8.d.ts} +1 -1
  9. package/dist/blending-D7jCmjO6.d.cts +1026 -0
  10. package/dist/blending-NgF3qo3d.d.ts +1026 -0
  11. package/dist/brushes-CnvZSYYU.d.cts +744 -0
  12. package/dist/brushes-DJmUbIgz.d.ts +744 -0
  13. package/dist/{brushstrokeRender-SII6MG4R.js → brushstrokeRender-2FAXA3XC.js} +13 -16
  14. package/dist/{brushstrokeRender-SII6MG4R.js.map → brushstrokeRender-2FAXA3XC.js.map} +1 -1
  15. package/dist/{brushstrokeRender-JNHVEUFG.cjs → brushstrokeRender-IMFY3FF6.cjs} +16 -19
  16. package/dist/brushstrokeRender-IMFY3FF6.cjs.map +1 -0
  17. package/dist/canvas/index.cjs +10 -10
  18. package/dist/canvas/index.cjs.map +1 -1
  19. package/dist/canvas/index.d.cts +10 -7
  20. package/dist/canvas/index.d.ts +10 -7
  21. package/dist/canvas/index.js +4 -4
  22. package/dist/{chunk-W4LNKTHT.cjs → chunk-2XS6LTUP.cjs} +63 -63
  23. package/dist/{chunk-W4LNKTHT.cjs.map → chunk-2XS6LTUP.cjs.map} +1 -1
  24. package/dist/{chunk-HHTCDFZC.js → chunk-3D77LOBM.js} +234 -136
  25. package/dist/chunk-3D77LOBM.js.map +1 -0
  26. package/dist/{chunk-BR7EKQUP.js → chunk-3G6J7UFV.js} +322 -2
  27. package/dist/chunk-3G6J7UFV.js.map +1 -0
  28. package/dist/{chunk-62XUO5LB.js → chunk-3X6IAJUQ.js} +2 -2
  29. package/dist/{chunk-EM3FMJWE.js → chunk-5FSRTP6E.js} +320 -3
  30. package/dist/chunk-5FSRTP6E.js.map +1 -0
  31. package/dist/{chunk-Z2H7KECK.cjs → chunk-5OOIUXNJ.cjs} +345 -247
  32. package/dist/chunk-5OOIUXNJ.cjs.map +1 -0
  33. package/dist/{chunk-7RJ6P7MI.js → chunk-6S6362D2.js} +2 -2
  34. package/dist/chunk-A3BVTI3G.js +150 -0
  35. package/dist/chunk-A3BVTI3G.js.map +1 -0
  36. package/dist/{chunk-24ATT2PE.cjs → chunk-AEAAN4AD.cjs} +120 -120
  37. package/dist/{chunk-24ATT2PE.cjs.map → chunk-AEAAN4AD.cjs.map} +1 -1
  38. package/dist/chunk-ECCXGELC.cjs +727 -0
  39. package/dist/chunk-ECCXGELC.cjs.map +1 -0
  40. package/dist/{chunk-SVYE5HIM.js → chunk-EQQMGO42.js} +2 -2
  41. package/dist/{chunk-FHPVDTI2.cjs → chunk-F2Y4E4GU.cjs} +22 -22
  42. package/dist/{chunk-FHPVDTI2.cjs.map → chunk-F2Y4E4GU.cjs.map} +1 -1
  43. package/dist/{chunk-OXSV64JX.js → chunk-G6IKY6PL.js} +4 -4
  44. package/dist/{chunk-UYQUPUR6.js → chunk-HUO3TI4C.js} +3 -3
  45. package/dist/chunk-I52DRGGJ.js +727 -0
  46. package/dist/chunk-I52DRGGJ.js.map +1 -0
  47. package/dist/{chunk-DDSO4HS7.cjs → chunk-KEENUAFN.cjs} +2 -2
  48. package/dist/{chunk-DDSO4HS7.cjs.map → chunk-KEENUAFN.cjs.map} +1 -1
  49. package/dist/{chunk-2HC4DRF4.js → chunk-LLFHCSU2.js} +2 -2
  50. package/dist/{chunk-J5BA3BQ6.cjs → chunk-O7LUD7MH.cjs} +323 -3
  51. package/dist/chunk-O7LUD7MH.cjs.map +1 -0
  52. package/dist/{chunk-ILYFOJUN.js → chunk-OIBIRXRG.js} +3 -3
  53. package/dist/{chunk-FWEO3HSL.js → chunk-PQQF5KOW.js} +8 -8
  54. package/dist/{chunk-T6TV6HY6.cjs → chunk-PRSRYHQD.cjs} +36 -36
  55. package/dist/{chunk-T6TV6HY6.cjs.map → chunk-PRSRYHQD.cjs.map} +1 -1
  56. package/dist/chunk-Q6OUXEK3.cjs +150 -0
  57. package/dist/chunk-Q6OUXEK3.cjs.map +1 -0
  58. package/dist/{chunk-6GFRKLLS.cjs → chunk-QBWEH3IM.cjs} +429 -112
  59. package/dist/chunk-QBWEH3IM.cjs.map +1 -0
  60. package/dist/{chunk-ESIWZMMK.js → chunk-SYT2TLQF.js} +35 -37
  61. package/dist/{chunk-ESIWZMMK.js.map → chunk-SYT2TLQF.js.map} +1 -1
  62. package/dist/{chunk-YT3JL7YM.cjs → chunk-TLCTTQFF.cjs} +53 -53
  63. package/dist/{chunk-YT3JL7YM.cjs.map → chunk-TLCTTQFF.cjs.map} +1 -1
  64. package/dist/{chunk-P3RQ5UJE.cjs → chunk-UTQKC66X.cjs} +4 -4
  65. package/dist/{chunk-P3RQ5UJE.cjs.map → chunk-UTQKC66X.cjs.map} +1 -1
  66. package/dist/{chunk-J3B45HTA.cjs → chunk-XB25WOC2.cjs} +6 -6
  67. package/dist/{chunk-J3B45HTA.cjs.map → chunk-XB25WOC2.cjs.map} +1 -1
  68. package/dist/{chunk-YAFS2QFZ.cjs → chunk-XN2NBLV5.cjs} +313 -315
  69. package/dist/chunk-XN2NBLV5.cjs.map +1 -0
  70. package/dist/effects/index.d.cts +7 -4
  71. package/dist/effects/index.d.ts +7 -4
  72. package/dist/{export-DMeG6E06.d.ts → export-41rL6Cne.d.ts} +1 -1
  73. package/dist/{export-AZSwX087.d.cts → export-CyJdfP_Z.d.cts} +5 -4
  74. package/dist/{export-KzubBKo7.d.cts → export-D9mXp05Q.d.cts} +1 -1
  75. package/dist/{export-BDkyDNM8.d.ts → export-DwnZ_hvQ.d.ts} +5 -4
  76. package/dist/extensions/index.cjs +3 -3
  77. package/dist/extensions/index.cjs.map +1 -1
  78. package/dist/extensions/index.js +2 -2
  79. package/dist/generation/index.cjs +150 -945
  80. package/dist/generation/index.cjs.map +1 -1
  81. package/dist/generation/index.d.cts +3 -423
  82. package/dist/generation/index.d.ts +3 -423
  83. package/dist/generation/index.js +59 -854
  84. package/dist/generation/index.js.map +1 -1
  85. package/dist/grammar/index.cjs +3 -3
  86. package/dist/grammar/index.cjs.map +1 -1
  87. package/dist/grammar/index.js +2 -2
  88. package/dist/{helpers-Coa4e2j_.d.ts → helpers-C-RgeyvH.d.ts} +25 -8
  89. package/dist/{helpers-DHl28yLO.d.cts → helpers-v6GMazzg.d.cts} +25 -8
  90. package/dist/image-editor/index.cjs +986 -986
  91. package/dist/image-editor/index.cjs.map +1 -1
  92. package/dist/image-editor/index.d.cts +15 -11
  93. package/dist/image-editor/index.d.ts +15 -11
  94. package/dist/image-editor/index.js +94 -94
  95. package/dist/index.cjs +28 -28
  96. package/dist/index.cjs.map +1 -1
  97. package/dist/index.js +36 -36
  98. package/dist/{opentype-BWR7Qv8W.d.cts → opentype-KR_jj6b_.d.cts} +1 -1
  99. package/dist/{opentype-Dfcx6wFx.d.ts → opentype-a1KAW-qs.d.ts} +1 -1
  100. package/dist/paint/index.cjs +5 -8
  101. package/dist/paint/index.cjs.map +1 -1
  102. package/dist/paint/index.d.cts +4 -2
  103. package/dist/paint/index.d.ts +4 -2
  104. package/dist/paint/index.js +15 -18
  105. package/dist/paint-editor/index.cjs +405 -403
  106. package/dist/paint-editor/index.cjs.map +1 -1
  107. package/dist/paint-editor/index.d.cts +15 -748
  108. package/dist/paint-editor/index.d.ts +15 -748
  109. package/dist/paint-editor/index.js +79 -77
  110. package/dist/paint-editor/index.js.map +1 -1
  111. package/dist/{pathfinder-D8KQ6blQ.d.cts → pathfinder-BHS4vQNm.d.cts} +1 -1
  112. package/dist/{pathfinder-Celbi3e6.d.ts → pathfinder-BVvTIBMo.d.ts} +1 -1
  113. package/dist/{pool-8JZGWHvR.d.ts → pool-CZQOrSXZ.d.ts} +1 -1
  114. package/dist/{pool-BfuxBKTd.d.cts → pool-FjZZmZ80.d.cts} +1 -1
  115. package/dist/provenance-DmlcgdzT.d.cts +426 -0
  116. package/dist/provenance-uh5r2TQ8.d.ts +426 -0
  117. package/dist/rand-8xbUb6ur.d.ts +1118 -0
  118. package/dist/rand-Cw9VLrVC.d.cts +1118 -0
  119. package/dist/raster/index.cjs +17 -19
  120. package/dist/raster/index.cjs.map +1 -1
  121. package/dist/raster/index.js +9 -11
  122. package/dist/raster/index.js.map +1 -1
  123. package/dist/{svg-CxxqG3_W.d.ts → svg-CSz3mzkw.d.ts} +2 -2
  124. package/dist/{svg-pwXWq6s2.d.cts → svg-DTb40ICU.d.cts} +2 -2
  125. package/dist/{tools-y1M6O3UT.d.ts → tools-B0wXP5cF.d.ts} +1 -1
  126. package/dist/{tools-3EBjR91b.d.cts → tools-Ca0kI1qo.d.cts} +1 -1
  127. package/dist/vector/index.cjs +2698 -1674
  128. package/dist/vector/index.cjs.map +1 -1
  129. package/dist/vector/index.d.cts +390 -72
  130. package/dist/vector/index.d.ts +390 -72
  131. package/dist/vector/index.js +1665 -641
  132. package/dist/vector/index.js.map +1 -1
  133. package/dist/video-editor/index.d.cts +7 -4
  134. package/dist/video-editor/index.d.ts +7 -4
  135. package/dist/{warp-Ceqdz7kj.d.cts → warp-DTOp0lON.d.cts} +1 -1
  136. package/dist/{warp-C1gwu2G_.d.ts → warp-pd7hrH4T.d.ts} +1 -1
  137. package/package.json +1 -1
  138. package/skills/pixerate-vector/SKILL.md +22 -0
  139. package/dist/brushstrokeRender-JNHVEUFG.cjs.map +0 -1
  140. package/dist/chunk-64PYNEHJ.js +0 -340
  141. package/dist/chunk-64PYNEHJ.js.map +0 -1
  142. package/dist/chunk-6GFRKLLS.cjs.map +0 -1
  143. package/dist/chunk-7QN76ESJ.js +0 -323
  144. package/dist/chunk-7QN76ESJ.js.map +0 -1
  145. package/dist/chunk-BR7EKQUP.js.map +0 -1
  146. package/dist/chunk-DCLJNVZS.cjs +0 -323
  147. package/dist/chunk-DCLJNVZS.cjs.map +0 -1
  148. package/dist/chunk-EM3FMJWE.js.map +0 -1
  149. package/dist/chunk-HHTCDFZC.js.map +0 -1
  150. package/dist/chunk-J5BA3BQ6.cjs.map +0 -1
  151. package/dist/chunk-YAFS2QFZ.cjs.map +0 -1
  152. package/dist/chunk-Z2H7KECK.cjs.map +0 -1
  153. package/dist/chunk-Z6OUCS2K.cjs +0 -340
  154. package/dist/chunk-Z6OUCS2K.cjs.map +0 -1
  155. package/dist/rand-BszBST4s.d.ts +0 -2140
  156. package/dist/rand-DOH_aMvm.d.cts +0 -2140
  157. /package/dist/{chunk-62XUO5LB.js.map → chunk-3X6IAJUQ.js.map} +0 -0
  158. /package/dist/{chunk-7RJ6P7MI.js.map → chunk-6S6362D2.js.map} +0 -0
  159. /package/dist/{chunk-SVYE5HIM.js.map → chunk-EQQMGO42.js.map} +0 -0
  160. /package/dist/{chunk-OXSV64JX.js.map → chunk-G6IKY6PL.js.map} +0 -0
  161. /package/dist/{chunk-UYQUPUR6.js.map → chunk-HUO3TI4C.js.map} +0 -0
  162. /package/dist/{chunk-2HC4DRF4.js.map → chunk-LLFHCSU2.js.map} +0 -0
  163. /package/dist/{chunk-ILYFOJUN.js.map → chunk-OIBIRXRG.js.map} +0 -0
  164. /package/dist/{chunk-FWEO3HSL.js.map → chunk-PQQF5KOW.js.map} +0 -0
@@ -1,10 +1,30 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
2
14
 
3
15
 
4
16
 
5
17
 
6
- var _chunkFD4LPFAEcjs = require('../chunk-FD4LPFAE.cjs');
7
- require('../chunk-MKA3AHLV.cjs');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ var _chunkECCXGELCcjs = require('../chunk-ECCXGELC.cjs');
8
28
 
9
29
 
10
30
 
@@ -12,664 +32,23 @@ require('../chunk-MKA3AHLV.cjs');
12
32
  var _chunkBVP3TSLHcjs = require('../chunk-BVP3TSLH.cjs');
13
33
 
14
34
 
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+ var _chunkQ6OUXEK3cjs = require('../chunk-Q6OUXEK3.cjs');
43
+
44
+
15
45
  var _chunkRIWPYSKUcjs = require('../chunk-RIWPYSKU.cjs');
16
46
 
17
- // src/generation/capabilities.ts
18
- var REFERENCE_ROLE_NAME_REGEX = /^[A-Za-z](?:[A-Za-z0-9_-]*[A-Za-z0-9])?$/;
19
- function isReferenceRoleName(value) {
20
- return typeof value === "string" && value.length <= 64 && REFERENCE_ROLE_NAME_REGEX.test(value);
21
- }
22
- var REFERENCE_ROLES = [
23
- "start_frame",
24
- "end_frame",
25
- "style_ref",
26
- "character_ref",
27
- "background_ref",
28
- "mask",
29
- "image_ref",
30
- "video_ref",
31
- "audio_ref"
32
- ];
33
- var REFERENCE_ROLE_LABELS = {
34
- start_frame: "Start frame",
35
- end_frame: "End frame",
36
- style_ref: "Style reference",
37
- character_ref: "Character reference",
38
- background_ref: "Background reference",
39
- mask: "Mask",
40
- image_ref: "Image reference",
41
- video_ref: "Video reference",
42
- audio_ref: "Audio reference"
43
- };
44
- var REFERENCE_ROLE_ALIASES = {
45
- reference: "image_ref",
46
- image: "image_ref",
47
- style: "style_ref",
48
- character: "character_ref",
49
- background: "background_ref",
50
- "start-frame": "start_frame",
51
- "first-frame": "start_frame",
52
- first_frame: "start_frame",
53
- "end-frame": "end_frame",
54
- "last-frame": "end_frame",
55
- last_frame: "end_frame",
56
- "style-ref": "style_ref",
57
- "character-ref": "character_ref",
58
- "background-ref": "background_ref",
59
- "image-ref": "image_ref",
60
- "video-ref": "video_ref",
61
- "audio-ref": "audio_ref",
62
- video: "video_ref",
63
- audio: "audio_ref"
64
- };
65
- var isBuiltinRole = (role) => REFERENCE_ROLES.includes(role);
66
- function referenceRoleLabel(role, caps) {
67
- const declared = _optionalChain([caps, 'optionalAccess', _ => _.references, 'optionalAccess', _2 => _2.roles, 'access', _3 => _3[role], 'optionalAccess', _4 => _4.label]);
68
- if (declared) return declared;
69
- if (isBuiltinRole(role)) return REFERENCE_ROLE_LABELS[role];
70
- const words = String(role).replace(/[_-]+/g, " ").trim();
71
- return words.charAt(0).toUpperCase() + words.slice(1);
72
- }
73
- function normalizeReferenceRole(role, caps) {
74
- const name = String(role).trim();
75
- if (caps ? !!_optionalChain([caps, 'access', _5 => _5.references, 'optionalAccess', _6 => _6.roles, 'access', _7 => _7[name]]) : isBuiltinRole(name)) return name;
76
- const lower = name.toLowerCase();
77
- if (_optionalChain([caps, 'optionalAccess', _8 => _8.references, 'optionalAccess', _9 => _9.roles, 'access', _10 => _10[lower]])) return lower;
78
- if (!caps && isBuiltinRole(lower)) return lower;
79
- return _nullishCoalesce(REFERENCE_ROLE_ALIASES[lower], () => ( (isBuiltinRole(lower) ? lower : name)));
80
- }
81
- function mediaTypeMatches(mediaType, accepts) {
82
- if (!accepts || accepts.length === 0) return true;
83
- if (!mediaType) return false;
84
- const type = mediaType.split(";")[0].trim().toLowerCase();
85
- const kind = type.split("/")[0];
86
- return accepts.some((entry) => {
87
- const pattern = entry.trim().toLowerCase();
88
- if (pattern === "*" || pattern === "*/*" || pattern === type) return true;
89
- if (!pattern.includes("/")) return pattern === kind;
90
- if (pattern.endsWith("/*")) return pattern.slice(0, -2) === kind;
91
- return false;
92
- });
93
- }
94
- var GENERATION_REQUEST_FIELDS = [
95
- "model",
96
- "prompt",
97
- "negativePrompt",
98
- "systemPrompt",
99
- "aspectRatio",
100
- "resolution",
101
- "quality",
102
- "count",
103
- "duration",
104
- "seed",
105
- "mode",
106
- "references",
107
- "params"
108
- ];
109
- function textFieldCapability(value) {
110
- if (!value) return null;
111
- return value === true ? {} : value;
112
- }
113
- function seedCapability(value) {
114
- if (!value) return null;
115
- return value === true ? {} : value;
116
- }
117
- function supportedReferenceRoles(caps) {
118
- const roles = _nullishCoalesce(_optionalChain([caps, 'access', _11 => _11.references, 'optionalAccess', _12 => _12.roles]), () => ( {}));
119
- const builtin = REFERENCE_ROLES.filter((role) => (_nullishCoalesce(_optionalChain([roles, 'access', _13 => _13[role], 'optionalAccess', _14 => _14.max]), () => ( 0))) > 0);
120
- const custom = Object.keys(roles).filter(
121
- (role) => !isBuiltinRole(role) && isReferenceRoleName(role) && (_nullishCoalesce(_optionalChain([roles, 'access', _15 => _15[role], 'optionalAccess', _16 => _16.max]), () => ( 0))) > 0
122
- );
123
- return [...builtin, ...custom];
124
- }
125
- function supportedModes(caps) {
126
- const modes = ["generate"];
127
- if (caps.editing) modes.push("edit");
128
- if (caps.inpainting) modes.push("inpaint");
129
- return modes;
130
- }
131
- var PRESENTATION_KEYS = ["name", "description", "badges", "icon", "group"];
132
- function mergeCapabilities(remote, overlay = []) {
133
- const overlayById = new Map(overlay.map((entry) => [entry.id, entry]));
134
- const remoteIds = new Set(remote.map((model) => model.id));
135
- const merged = remote.map((model) => {
136
- const extra = overlayById.get(model.id);
137
- if (!extra) return { ...model };
138
- const next = { ...model };
139
- for (const key of PRESENTATION_KEYS) {
140
- if (extra[key] !== void 0) next[key] = extra[key];
141
- }
142
- return next;
143
- });
144
- for (const entry of overlay) {
145
- if (remoteIds.has(entry.id) || !entry.media) continue;
146
- remoteIds.add(entry.id);
147
- merged.push({ ...entry });
148
- }
149
- return merged;
150
- }
151
47
 
152
- // src/generation/plan.ts
153
- var EPSILON = 1e-9;
154
- function aspectRatioRank(value) {
155
- const match = /^\s*(\d+(?:\.\d+)?)\s*[:x/×]\s*(\d+(?:\.\d+)?)\s*$/i.exec(String(value));
156
- if (!match) return void 0;
157
- const w = Number(match[1]);
158
- const h = Number(match[2]);
159
- if (!(w > 0) || !(h > 0)) return void 0;
160
- return Math.log(w / h);
161
- }
162
- function resolutionRank(value) {
163
- const text = String(value).trim().toLowerCase();
164
- let pixels;
165
- let match = /^(\d+(?:\.\d+)?)\s*[x×*]\s*(\d+(?:\.\d+)?)$/.exec(text);
166
- if (match) pixels = Number(match[1]) * Number(match[2]);
167
- else if (match = /^(\d+(?:\.\d+)?)p$/.exec(text)) pixels = Number(match[1]) ** 2 * 16 / 9;
168
- else if (match = /^(\d+(?:\.\d+)?)k$/.exec(text)) pixels = (Number(match[1]) * 1024) ** 2;
169
- return pixels && pixels > 0 ? Math.log(pixels) : void 0;
170
- }
171
- function resolutionMegapixels(value) {
172
- const rank = resolutionRank(value);
173
- return rank === void 0 ? void 0 : Math.exp(rank) / 1e6;
174
- }
175
- var QUALITY_LADDER = {
176
- draft: 0,
177
- preview: 0,
178
- low: 1,
179
- fast: 1,
180
- turbo: 1,
181
- standard: 2,
182
- normal: 2,
183
- medium: 2,
184
- balanced: 2,
185
- high: 3,
186
- hd: 3,
187
- quality: 3,
188
- ultra: 4,
189
- max: 5,
190
- best: 5
191
- };
192
- function qualityRank(value) {
193
- return QUALITY_LADDER[String(value).trim().toLowerCase()];
194
- }
195
- var numberRank = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
196
- function snapToOption(value, options, rank, tie) {
197
- const target = rank(value);
198
- if (target === void 0) return void 0;
199
- let best;
200
- for (const option of options) {
201
- const r = rank(option);
202
- if (r === void 0) continue;
203
- const distance = Math.abs(r - target);
204
- if (!best || distance < best.distance - EPSILON || Math.abs(distance - best.distance) <= EPSILON && (tie === "lower" ? r < best.rank : r > best.rank)) {
205
- best = { option, distance, rank: r };
206
- }
207
- }
208
- return _optionalChain([best, 'optionalAccess', _17 => _17.option]);
209
- }
210
- function truncateText(text, max) {
211
- if (text.length <= max) return text;
212
- let end = max;
213
- const code = text.charCodeAt(end - 1);
214
- if (end > 0 && code >= 55296 && code <= 56319) end -= 1;
215
- return text.slice(0, end);
216
- }
217
- function cloneRequest(request) {
218
- const copy = { ...request };
219
- if (request.references) copy.references = request.references.map((ref) => ({ ...ref }));
220
- if (request.params) copy.params = { ...request.params };
221
- return copy;
222
- }
223
- var describe = (value) => typeof value === "string" ? `"${value}"` : JSON.stringify(value);
224
- var list = (options) => options.map(describe).join(", ");
225
- var Planner = (_class = class {
226
- constructor(caps, request, options, strategy) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
227
- this.caps = caps;
228
- this.request = request;
229
- this.options = options;
230
- this.strategy = strategy;
231
- this.tie = strategy === "downgrade" ? "lower" : "higher";
232
- this.strict = strategy === "error";
233
- }
234
-
235
-
236
-
237
-
238
- __init() {this.adjustments = []}
239
- __init2() {this.errors = []}
240
-
241
-
242
- adjust(field, from, to, kind, reason) {
243
- this.adjustments.push({ field, from, to, kind, reason });
244
- }
245
- error(field, value, message) {
246
- this.errors.push({ field, value, message });
247
- }
248
- /** Removes an unsupported field (or reports it under `error`). */
249
- unsupported(field, message) {
250
- const value = this.request[field];
251
- if (this.strict) {
252
- this.error(field, value, message);
253
- return;
254
- }
255
- delete this.request[field];
256
- this.adjust(field, value, void 0, "dropped", message);
257
- }
258
- defaulted(field, value, set) {
259
- if (!this.options.fillDefaults || value === void 0) return;
260
- set();
261
- this.adjust(field, void 0, value, "defaulted", "Filled with the model default.");
262
- }
263
- planText(field, maxLength, measured) {
264
- const value = this.request[field];
265
- if (value === void 0 || maxLength === void 0) return;
266
- if (typeof value !== "string") {
267
- this.error(field, value, `Expected text.`);
268
- return;
269
- }
270
- const text = _nullishCoalesce(measured, () => ( value));
271
- if (text.length <= maxLength) return;
272
- if (this.strict || measured !== void 0) {
273
- this.error(
274
- field,
275
- text.length,
276
- `${measured !== void 0 ? "Resolved text" : "Text"} is ${text.length} characters; the model accepts at most ${maxLength}.`
277
- );
278
- return;
279
- }
280
- const next = truncateText(value, maxLength);
281
- this.request[field] = next;
282
- this.adjust(field, value.length, next.length, "truncated", `Truncated to the model's ${maxLength}-character limit.`);
283
- }
284
- planEnum(field, cap, rank, label) {
285
- const value = this.request[field];
286
- if (value === void 0) {
287
- if (cap) this.defaulted(field, cap.default, () => this.request[field] = cap.default);
288
- return;
289
- }
290
- if (!cap || cap.options.length === 0) {
291
- this.unsupported(field, `The model does not take a ${label}.`);
292
- return;
293
- }
294
- if (cap.options.includes(value)) return;
295
- if (this.strict) {
296
- this.error(field, value, `${describe(value)} is not a supported ${label}; supported: ${list(cap.options)}.`);
297
- return;
298
- }
299
- const snapped = snapToOption(value, cap.options, rank, this.tie);
300
- const next = _nullishCoalesce(_nullishCoalesce(snapped, () => ( cap.default)), () => ( cap.options[0]));
301
- this.request[field] = next;
302
- this.adjust(
303
- field,
304
- value,
305
- next,
306
- "snapped",
307
- snapped !== void 0 ? `${describe(value)} is not supported; using the nearest ${label}.` : `${describe(value)} is not supported; using ${cap.default !== void 0 ? "the default" : "the first option"}.`
308
- );
309
- }
310
- /** Clamps/rounds/snaps a number. Returns the next value or `undefined` after an error. */
311
- planNumber(field, value, spec, label) {
312
- if (typeof value !== "number" || !Number.isFinite(value)) {
313
- this.error(field, value, `Expected a number for ${label}.`);
314
- return void 0;
315
- }
316
- const options = _optionalChain([spec, 'access', _18 => _18.options, 'optionalAccess', _19 => _19.filter, 'call', _20 => _20(
317
- (o) => (spec.min === void 0 || o >= spec.min) && (spec.max === void 0 || o <= spec.max)
318
- )]);
319
- if (options && options.length > 0) {
320
- if (options.includes(value)) return { value, changed: false };
321
- if (this.strict) {
322
- this.error(field, value, `${value} is not a supported ${label}; supported: ${list(options)}.`);
323
- return void 0;
324
- }
325
- const next2 = snapToOption(value, options, numberRank, this.tie);
326
- this.adjust(field, value, next2, "snapped", `${value} is not supported; using the nearest ${label}.`);
327
- return { value: next2, changed: true };
328
- }
329
- let next = value;
330
- if (spec.step !== void 0 && spec.step > 0) {
331
- const base = _nullishCoalesce(spec.min, () => ( 0));
332
- const steps = (next - base) / spec.step;
333
- const rounded = Math.abs(steps - Math.trunc(steps) - 0.5) < EPSILON ? this.tie === "lower" ? Math.floor(steps) : Math.ceil(steps) : Math.round(steps);
334
- next = Number((base + rounded * spec.step).toPrecision(12));
335
- }
336
- if (spec.integer && !Number.isInteger(next)) {
337
- const frac = next - Math.floor(next);
338
- next = Math.abs(frac - 0.5) < EPSILON ? this.tie === "lower" ? Math.floor(next) : Math.ceil(next) : Math.round(next);
339
- }
340
- let kind = "snapped";
341
- if (spec.min !== void 0 && next < spec.min) {
342
- next = spec.min;
343
- kind = "clamped";
344
- }
345
- if (spec.max !== void 0 && next > spec.max) {
346
- next = spec.max;
347
- kind = "clamped";
348
- }
349
- if (next === value) return { value, changed: false };
350
- const range = `${_nullishCoalesce(spec.min, () => ( "-\u221E"))}\u2013${_nullishCoalesce(spec.max, () => ( "\u221E"))}`;
351
- if (this.strict) {
352
- this.error(
353
- field,
354
- value,
355
- kind === "clamped" ? `${label} must be within ${range}.` : `${value} is not a valid ${label} (try ${next}).`
356
- );
357
- return void 0;
358
- }
359
- this.adjust(
360
- field,
361
- value,
362
- next,
363
- kind,
364
- kind === "clamped" ? `Clamped to the supported range ${range}.` : `Rounded to a supported ${label}.`
365
- );
366
- return { value: next, changed: true };
367
- }
368
- planCount() {
369
- const value = this.request.count;
370
- const cap = this.caps.count;
371
- if (value === void 0) {
372
- if (cap) this.defaulted("count", cap.default, () => this.request.count = cap.default);
373
- return;
374
- }
375
- if (!cap) {
376
- if (value === 1) return;
377
- this.unsupported("count", "The model produces one output per request.");
378
- return;
379
- }
380
- const result = this.planNumber("count", value, { min: 1, max: cap.max, integer: true, options: cap.options }, "output count");
381
- if (result) this.request.count = result.value;
382
- }
383
- planDuration() {
384
- const value = this.request.duration;
385
- const cap = this.caps.duration;
386
- if (value === void 0) {
387
- if (cap) this.defaulted("duration", cap.default, () => this.request.duration = cap.default);
388
- return;
389
- }
390
- if (!cap) {
391
- this.unsupported("duration", "The model does not take a duration.");
392
- return;
393
- }
394
- const result = this.planNumber("duration", value, cap, "duration");
395
- if (result) this.request.duration = result.value;
396
- }
397
- planSeed() {
398
- const value = this.request.seed;
399
- if (value === void 0) return;
400
- const cap = seedCapability(this.caps.seed);
401
- if (!cap) {
402
- this.unsupported("seed", "The model does not take a seed.");
403
- return;
404
- }
405
- const result = this.planNumber("seed", value, { ...cap, integer: true }, "seed");
406
- if (result) this.request.seed = result.value;
407
- }
408
- planMode() {
409
- const mode = this.request.mode;
410
- if (mode === void 0) return;
411
- const modes = supportedModes(this.caps);
412
- if (!modes.includes(mode)) {
413
- this.error("mode", mode, `The model does not support ${describe(mode)}; supported: ${list(modes)}.`);
414
- }
415
- }
416
- roleCapability(role) {
417
- const cap = _optionalChain([this, 'access', _21 => _21.caps, 'access', _22 => _22.references, 'optionalAccess', _23 => _23.roles, 'access', _24 => _24[role]]);
418
- if (cap && cap.max > 0) return cap;
419
- if (role === "mask" && this.caps.inpainting) return { max: 1 };
420
- return void 0;
421
- }
422
- /** Turns `options.mentions` into references (appended after the request's own). */
423
- addMentions() {
424
- const mentions = this.options.mentions;
425
- if (!_optionalChain([mentions, 'optionalAccess', _25 => _25.length])) return;
426
- const refs = [..._nullishCoalesce(this.request.references, () => ( []))];
427
- for (const mention of mentions) {
428
- if (!mention || typeof mention.id !== "string" || mention.id === "") continue;
429
- let role = _nullishCoalesce(mention.role, () => ( void 0));
430
- if (!role) {
431
- role = _nullishCoalesce(this.options.defaultMentionRole, () => ( this.inferRole(mention.mediaType)));
432
- this.adjust(
433
- `references.${role}`,
434
- void 0,
435
- role,
436
- "defaulted",
437
- `@${_nullishCoalesce(mention.label, () => ( mention.id))} has no role; using ${role}.`
438
- );
439
- }
440
- refs.push({
441
- id: mention.id,
442
- role,
443
- ...mention.url !== void 0 ? { url: mention.url } : {},
444
- ...mention.mediaType !== void 0 ? { mediaType: mention.mediaType } : {},
445
- ...mention.contentHash !== void 0 ? { contentHash: mention.contentHash } : {}
446
- });
447
- }
448
- this.request.references = refs;
449
- }
450
- /** First role of the model (other than `mask`) whose `accepts` matches `mediaType`. */
451
- inferRole(mediaType) {
452
- for (const role of supportedReferenceRoles(this.caps)) {
453
- if (role === "mask") continue;
454
- const cap = this.roleCapability(role);
455
- if (cap && (mediaType === void 0 || mediaTypeMatches(mediaType, cap.accepts))) return role;
456
- }
457
- return "image_ref";
458
- }
459
- planReferences() {
460
- const refs = this.request.references;
461
- const allowDrop = !this.strict && (_nullishCoalesce(this.options.dropUnsupportedReferences, () => ( (this.strategy === "nearest" || this.strategy === "downgrade"))));
462
- const byRole = /* @__PURE__ */ new Map();
463
- const kept = [];
464
- const unsupported = /* @__PURE__ */ new Map();
465
- for (const [index, original] of (_nullishCoalesce(refs, () => ( []))).entries()) {
466
- let ref = original;
467
- if (!ref || typeof ref.id !== "string" || ref.id === "" || !isReferenceRoleName(ref.role)) {
468
- this.error(`references.${index}`, ref, "Each reference needs an `id` and a valid `role`.");
469
- continue;
470
- }
471
- if (!this.roleCapability(ref.role)) {
472
- const alias = normalizeReferenceRole(ref.role, this.caps);
473
- if (alias !== ref.role && this.roleCapability(alias)) {
474
- if (this.strict) {
475
- this.error(`references.${ref.role}`, ref.role, `The model calls this role ${describe(alias)}.`);
476
- continue;
477
- }
478
- this.adjust(
479
- `references.${ref.role}`,
480
- ref.role,
481
- alias,
482
- "snapped",
483
- `Using the model's ${alias} role for ${describe(ref.role)}.`
484
- );
485
- ref = { ...ref, role: alias };
486
- } else {
487
- unsupported.set(ref.role, (_nullishCoalesce(unsupported.get(ref.role), () => ( 0))) + 1);
488
- continue;
489
- }
490
- }
491
- const cap = this.roleCapability(ref.role);
492
- if (ref.mediaType !== void 0 && !mediaTypeMatches(ref.mediaType, cap.accepts)) {
493
- const message = `${describe(ref.id)} is ${describe(ref.mediaType)}; ${ref.role} accepts ${list(_nullishCoalesce(cap.accepts, () => ( [])))}.`;
494
- if (allowDrop) this.adjust(`references.${ref.role}`, ref.id, void 0, "dropped", message);
495
- else this.error(`references.${ref.role}`, ref.id, message);
496
- continue;
497
- }
498
- const group = _nullishCoalesce(byRole.get(ref.role), () => ( []));
499
- if (group.some((other) => other.id === ref.id)) {
500
- this.adjust(`references.${ref.role}`, ref.id, void 0, "dropped", `Duplicate reference "${ref.id}" removed.`);
501
- continue;
502
- }
503
- group.push(ref);
504
- byRole.set(ref.role, group);
505
- kept.push(ref);
506
- }
507
- for (const [role, count] of unsupported) {
508
- const message = this.caps.media === "text" || !this.caps.references ? `The ${this.caps.media} model "${this.caps.id}" does not accept reference inputs (${role}).` : `The model does not accept ${role} references.`;
509
- if (allowDrop) this.adjust(`references.${role}`, count, 0, "dropped", message);
510
- else this.error(`references.${role}`, count, message);
511
- }
512
- const removed = /* @__PURE__ */ new Set();
513
- const custom = supportedReferenceRoles(this.caps).filter(
514
- (role) => !REFERENCE_ROLES.includes(role)
515
- );
516
- for (const role of [...REFERENCE_ROLES, ...custom]) {
517
- const cap = this.roleCapability(role);
518
- const group = _nullishCoalesce(byRole.get(role), () => ( []));
519
- if (!cap) continue;
520
- if (group.length > cap.max) {
521
- if (this.strict) {
522
- this.error(`references.${role}`, group.length, `At most ${cap.max} ${role} reference(s) are supported.`);
523
- } else {
524
- group.slice(cap.max).forEach((ref) => removed.add(ref));
525
- this.adjust(
526
- `references.${role}`,
527
- group.length,
528
- cap.max,
529
- "truncated",
530
- `Kept the first ${cap.max} ${role} reference(s); the model accepts no more.`
531
- );
532
- }
533
- }
534
- if (cap.min !== void 0 && group.length < cap.min) {
535
- this.error(`references.${role}`, group.length, `At least ${cap.min} ${role} reference(s) are required.`);
536
- }
537
- }
538
- let next = kept.filter((ref) => !removed.has(ref));
539
- const maxTotal = _optionalChain([this, 'access', _26 => _26.caps, 'access', _27 => _27.references, 'optionalAccess', _28 => _28.maxTotal]);
540
- if (maxTotal !== void 0 && next.length > maxTotal) {
541
- if (this.strict) {
542
- this.error("references", next.length, `At most ${maxTotal} references are supported in total.`);
543
- } else {
544
- this.adjust(
545
- "references",
546
- next.length,
547
- maxTotal,
548
- "truncated",
549
- `Kept the first ${maxTotal} references; the model accepts no more in total.`
550
- );
551
- next = next.slice(0, maxTotal);
552
- }
553
- }
554
- if (this.request.mode === "inpaint" && !next.some((ref) => ref.role === "mask")) {
555
- this.error("references.mask", 0, "Inpainting needs a `mask` reference.");
556
- }
557
- if (refs === void 0) return;
558
- if (!this.strict) {
559
- if (next.length > 0) this.request.references = next;
560
- else delete this.request.references;
561
- }
562
- }
563
- planParam(name, spec, value) {
564
- const field = `params.${name}`;
565
- if (!spec) {
566
- if (this.strict) this.error(field, value, `Unknown parameter "${name}".`);
567
- else this.adjust(field, value, void 0, "dropped", `The model has no "${name}" parameter.`);
568
- return void 0;
569
- }
570
- const label = _nullishCoalesce(spec.label, () => ( name));
571
- if (spec.type === "boolean") {
572
- if (typeof value !== "boolean") this.error(field, value, `Expected true or false for ${label}.`);
573
- return value;
574
- }
575
- if (spec.type === "enum") {
576
- if (spec.options.includes(value)) return value;
577
- if (this.strict) {
578
- this.error(field, value, `${describe(value)} is not a supported ${label}; supported: ${list(spec.options)}.`);
579
- return value;
580
- }
581
- const numeric = spec.options.every((o) => typeof o === "number");
582
- const snapped = numeric ? snapToOption(value, spec.options, numberRank, this.tie) : void 0;
583
- const next = _nullishCoalesce(_nullishCoalesce(snapped, () => ( spec.default)), () => ( spec.options[0]));
584
- this.adjust(
585
- field,
586
- value,
587
- next,
588
- "snapped",
589
- snapped !== void 0 ? `Using the nearest supported ${label}.` : `${describe(value)} is not supported; using ${spec.default !== void 0 ? "the default" : "the first option"}.`
590
- );
591
- return next;
592
- }
593
- const result = this.planNumber(field, value, { ...spec, integer: spec.type === "integer" }, label);
594
- return result ? result.value : value;
595
- }
596
- planParams() {
597
- const params = this.request.params;
598
- const specs = _nullishCoalesce(this.caps.params, () => ( {}));
599
- const next = {};
600
- for (const [name, value] of Object.entries(_nullishCoalesce(params, () => ( {})))) {
601
- if (value === void 0) continue;
602
- const planned = this.planParam(name, specs[name], value);
603
- if (planned !== void 0) next[name] = planned;
604
- else if (this.strict) next[name] = value;
605
- }
606
- if (this.options.fillDefaults) {
607
- for (const [name, spec] of Object.entries(specs)) {
608
- if (next[name] === void 0 && spec.default !== void 0) {
609
- next[name] = spec.default;
610
- this.adjust(`params.${name}`, void 0, spec.default, "defaulted", "Filled with the model default.");
611
- }
612
- }
613
- }
614
- if (Object.keys(next).length > 0) this.request.params = next;
615
- else delete this.request.params;
616
- }
617
- run() {
618
- const { caps, request } = this;
619
- for (const key of Object.keys(request)) {
620
- if (GENERATION_REQUEST_FIELDS.includes(key)) continue;
621
- const value = request[key];
622
- if (this.strict) this.error(key, value, `Unknown request field "${key}".`);
623
- else {
624
- delete request[key];
625
- this.adjust(key, value, void 0, "dropped", `Unknown request field "${key}".`);
626
- }
627
- }
628
- if (request.model !== void 0 && request.model !== caps.id) {
629
- this.error("model", request.model, `The request targets "${request.model}" but the plan is for "${caps.id}".`);
630
- }
631
- request.model = caps.id;
632
- const promptCap = _nullishCoalesce(caps.prompt, () => ( {}));
633
- if (promptCap.required && !(_nullishCoalesce(request.prompt, () => ( ""))).trim()) {
634
- this.error("prompt", request.prompt, "A prompt is required.");
635
- }
636
- const countResolved = _nullishCoalesce(promptCap.countResolved, () => ( true));
637
- const measured = countResolved && this.options.resolvedPrompt !== void 0 && this.options.resolvedPrompt !== request.prompt ? this.options.resolvedPrompt : void 0;
638
- this.planText("prompt", promptCap.maxLength, measured);
639
- for (const field of ["negativePrompt", "systemPrompt"]) {
640
- if (request[field] === void 0) continue;
641
- const cap = textFieldCapability(caps[field]);
642
- if (!cap) {
643
- this.unsupported(field, `The model does not take a ${field === "negativePrompt" ? "negative" : "system"} prompt.`);
644
- continue;
645
- }
646
- this.planText(field, cap.maxLength);
647
- }
648
- this.planEnum("aspectRatio", caps.aspectRatios, aspectRatioRank, "aspect ratio");
649
- this.planEnum("resolution", caps.resolutions, resolutionRank, "resolution");
650
- this.planEnum("quality", caps.quality, qualityRank, "quality");
651
- this.planCount();
652
- this.planDuration();
653
- this.planSeed();
654
- this.planMode();
655
- this.addMentions();
656
- this.planReferences();
657
- this.planParams();
658
- }
659
- }, _class);
660
- function planGenerationRequest(request, caps, options = {}) {
661
- const strategy = _nullishCoalesce(options.strategy, () => ( "nearest"));
662
- const planner = new Planner(caps, cloneRequest(_nullishCoalesce(request, () => ( {}))), options, strategy);
663
- planner.run();
664
- return {
665
- ok: planner.errors.length === 0,
666
- request: planner.request,
667
- adjustments: planner.adjustments,
668
- errors: planner.errors,
669
- model: caps.id,
670
- strategy
671
- };
672
- }
48
+
49
+
50
+ var _chunkFD4LPFAEcjs = require('../chunk-FD4LPFAE.cjs');
51
+ require('../chunk-MKA3AHLV.cjs');
673
52
 
674
53
  // src/generation/schema.ts
675
54
  function enumSchema(cap, description) {
@@ -716,7 +95,7 @@ function capabilitiesToJsonSchema(caps) {
716
95
  ...prompt.required ? { minLength: 1 } : {}
717
96
  };
718
97
  if (prompt.required) required.push("prompt");
719
- const negative = textFieldCapability(caps.negativePrompt);
98
+ const negative = _chunkECCXGELCcjs.textFieldCapability.call(void 0, caps.negativePrompt);
720
99
  if (negative) {
721
100
  properties.negativePrompt = {
722
101
  type: "string",
@@ -724,7 +103,7 @@ function capabilitiesToJsonSchema(caps) {
724
103
  ...negative.maxLength !== void 0 ? { maxLength: negative.maxLength } : {}
725
104
  };
726
105
  }
727
- const system = textFieldCapability(caps.systemPrompt);
106
+ const system = _chunkECCXGELCcjs.textFieldCapability.call(void 0, caps.systemPrompt);
728
107
  if (system) {
729
108
  properties.systemPrompt = {
730
109
  type: "string",
@@ -732,18 +111,18 @@ function capabilitiesToJsonSchema(caps) {
732
111
  ...system.maxLength !== void 0 ? { maxLength: system.maxLength } : {}
733
112
  };
734
113
  }
735
- if (_optionalChain([caps, 'access', _29 => _29.aspectRatios, 'optionalAccess', _30 => _30.options, 'access', _31 => _31.length])) properties.aspectRatio = enumSchema(caps.aspectRatios, "Aspect ratio (width:height).");
736
- if (_optionalChain([caps, 'access', _32 => _32.resolutions, 'optionalAccess', _33 => _33.options, 'access', _34 => _34.length])) properties.resolution = enumSchema(caps.resolutions, "Output resolution, low to high.");
737
- if (_optionalChain([caps, 'access', _35 => _35.quality, 'optionalAccess', _36 => _36.options, 'access', _37 => _37.length])) properties.quality = enumSchema(caps.quality, "Quality level, low to high.");
114
+ if (_optionalChain([caps, 'access', _ => _.aspectRatios, 'optionalAccess', _2 => _2.options, 'access', _3 => _3.length])) properties.aspectRatio = enumSchema(caps.aspectRatios, "Aspect ratio (width:height).");
115
+ if (_optionalChain([caps, 'access', _4 => _4.resolutions, 'optionalAccess', _5 => _5.options, 'access', _6 => _6.length])) properties.resolution = enumSchema(caps.resolutions, "Output resolution, low to high.");
116
+ if (_optionalChain([caps, 'access', _7 => _7.quality, 'optionalAccess', _8 => _8.options, 'access', _9 => _9.length])) properties.quality = enumSchema(caps.quality, "Quality level, low to high.");
738
117
  if (caps.count) {
739
- const options = _optionalChain([caps, 'access', _38 => _38.count, 'access', _39 => _39.options, 'optionalAccess', _40 => _40.filter, 'call', _41 => _41((o) => o >= 1 && o <= caps.count.max)]);
740
- properties.count = _optionalChain([options, 'optionalAccess', _42 => _42.length]) ? { type: "integer", enum: options, description: "Number of outputs." } : { type: "integer", minimum: 1, maximum: caps.count.max, description: "Number of outputs." };
118
+ const options = _optionalChain([caps, 'access', _10 => _10.count, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.filter, 'call', _13 => _13((o) => o >= 1 && o <= caps.count.max)]);
119
+ properties.count = _optionalChain([options, 'optionalAccess', _14 => _14.length]) ? { type: "integer", enum: options, description: "Number of outputs." } : { type: "integer", minimum: 1, maximum: caps.count.max, description: "Number of outputs." };
741
120
  if (caps.count.default !== void 0) properties.count.default = caps.count.default;
742
121
  }
743
122
  if (caps.duration) {
744
123
  const d = caps.duration;
745
- const options = _optionalChain([d, 'access', _43 => _43.options, 'optionalAccess', _44 => _44.filter, 'call', _45 => _45((o) => (d.min === void 0 || o >= d.min) && (d.max === void 0 || o <= d.max))]);
746
- properties.duration = _optionalChain([options, 'optionalAccess', _46 => _46.length]) ? { type: "number", enum: options, description: "Duration in seconds." } : {
124
+ const options = _optionalChain([d, 'access', _15 => _15.options, 'optionalAccess', _16 => _16.filter, 'call', _17 => _17((o) => (d.min === void 0 || o >= d.min) && (d.max === void 0 || o <= d.max))]);
125
+ properties.duration = _optionalChain([options, 'optionalAccess', _18 => _18.length]) ? { type: "number", enum: options, description: "Duration in seconds." } : {
747
126
  type: "number",
748
127
  description: d.step !== void 0 ? `Duration in seconds (step ${d.step}).` : "Duration in seconds.",
749
128
  ...d.min !== void 0 ? { minimum: d.min } : {},
@@ -751,7 +130,7 @@ function capabilitiesToJsonSchema(caps) {
751
130
  };
752
131
  if (d.default !== void 0) properties.duration.default = d.default;
753
132
  }
754
- const seed = seedCapability(caps.seed);
133
+ const seed = _chunkECCXGELCcjs.seedCapability.call(void 0, caps.seed);
755
134
  if (seed) {
756
135
  properties.seed = {
757
136
  type: "integer",
@@ -760,24 +139,24 @@ function capabilitiesToJsonSchema(caps) {
760
139
  ...seed.max !== void 0 ? { maximum: seed.max } : {}
761
140
  };
762
141
  }
763
- const modes = supportedModes(caps);
142
+ const modes = _chunkECCXGELCcjs.supportedModes.call(void 0, caps);
764
143
  if (modes.length > 1) {
765
144
  properties.mode = { type: "string", enum: modes, default: "generate", description: "Generate, edit a source, or inpaint with a mask." };
766
145
  }
767
- const roles = supportedReferenceRoles(caps);
146
+ const roles = _chunkECCXGELCcjs.supportedReferenceRoles.call(void 0, caps);
768
147
  if (caps.inpainting && !roles.includes("mask")) roles.push("mask");
769
148
  if (roles.length > 0) {
770
149
  const limits = roles.map((role) => {
771
- const cap = _nullishCoalesce(_optionalChain([caps, 'access', _47 => _47.references, 'optionalAccess', _48 => _48.roles, 'access', _49 => _49[role]]), () => ( { max: 1 }));
150
+ const cap = _nullishCoalesce(_optionalChain([caps, 'access', _19 => _19.references, 'optionalAccess', _20 => _20.roles, 'access', _21 => _21[role]]), () => ( { max: 1 }));
772
151
  const min = cap.min ? `${cap.min}\u2013` : "up to ";
773
- const accepts = "accepts" in cap && _optionalChain([cap, 'access', _50 => _50.accepts, 'optionalAccess', _51 => _51.length]) ? `, ${cap.accepts.join("/")} only` : "";
774
- return `${role} (${referenceRoleLabel(role, caps)}): ${min}${cap.max}${accepts}`;
152
+ const accepts = "accepts" in cap && _optionalChain([cap, 'access', _22 => _22.accepts, 'optionalAccess', _23 => _23.length]) ? `, ${cap.accepts.join("/")} only` : "";
153
+ return `${role} (${_chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps)}): ${min}${cap.max}${accepts}`;
775
154
  });
776
- const perRoleTotal = roles.reduce((sum, role) => sum + (_nullishCoalesce(_optionalChain([caps, 'access', _52 => _52.references, 'optionalAccess', _53 => _53.roles, 'access', _54 => _54[role], 'optionalAccess', _55 => _55.max]), () => ( 1))), 0);
777
- const maxItems = Math.min(_nullishCoalesce(_optionalChain([caps, 'access', _56 => _56.references, 'optionalAccess', _57 => _57.maxTotal]), () => ( Infinity)), perRoleTotal);
155
+ const perRoleTotal = roles.reduce((sum, role) => sum + (_nullishCoalesce(_optionalChain([caps, 'access', _24 => _24.references, 'optionalAccess', _25 => _25.roles, 'access', _26 => _26[role], 'optionalAccess', _27 => _27.max]), () => ( 1))), 0);
156
+ const maxItems = Math.min(_nullishCoalesce(_optionalChain([caps, 'access', _28 => _28.references, 'optionalAccess', _29 => _29.maxTotal]), () => ( Infinity)), perRoleTotal);
778
157
  properties.references = {
779
158
  type: "array",
780
- description: `Reference inputs by role. Limits: ${limits.join("; ")}${_optionalChain([caps, 'access', _58 => _58.references, 'optionalAccess', _59 => _59.maxTotal]) !== void 0 ? `; at most ${caps.references.maxTotal} in total` : ""}.`,
159
+ description: `Reference inputs by role. Limits: ${limits.join("; ")}${_optionalChain([caps, 'access', _30 => _30.references, 'optionalAccess', _31 => _31.maxTotal]) !== void 0 ? `; at most ${caps.references.maxTotal} in total` : ""}.`,
781
160
  maxItems,
782
161
  items: {
783
162
  type: "object",
@@ -792,7 +171,7 @@ function capabilitiesToJsonSchema(caps) {
792
171
  additionalProperties: false
793
172
  }
794
173
  };
795
- if (roles.some((role) => (_nullishCoalesce(_optionalChain([caps, 'access', _60 => _60.references, 'optionalAccess', _61 => _61.roles, 'access', _62 => _62[role], 'optionalAccess', _63 => _63.min]), () => ( 0))) > 0)) required.push("references");
174
+ if (roles.some((role) => (_nullishCoalesce(_optionalChain([caps, 'access', _32 => _32.references, 'optionalAccess', _33 => _33.roles, 'access', _34 => _34[role], 'optionalAccess', _35 => _35.min]), () => ( 0))) > 0)) required.push("references");
796
175
  }
797
176
  const params = Object.entries(_nullishCoalesce(caps.params, () => ( {})));
798
177
  if (params.length > 0) {
@@ -813,54 +192,12 @@ function capabilitiesToJsonSchema(caps) {
813
192
  };
814
193
  }
815
194
 
816
- // src/generation/hash.ts
817
- function stableStringify(value) {
818
- if (Array.isArray(value)) return `[${value.map((item) => item === void 0 ? "null" : stableStringify(item)).join(",")}]`;
819
- if (value && typeof value === "object") {
820
- const entries = Object.keys(value).filter((key) => value[key] !== void 0).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`);
821
- return `{${entries.join(",")}}`;
822
- }
823
- return _nullishCoalesce(JSON.stringify(value), () => ( "null"));
824
- }
825
- var FNV_PRIME = 16777619;
826
- function hashText(text) {
827
- let a = 2166136261;
828
- let b = 789454171;
829
- for (let i = 0; i < text.length; i++) {
830
- const unit = text.charCodeAt(i);
831
- a = Math.imul(a ^ unit & 255, FNV_PRIME);
832
- a = Math.imul(a ^ unit >>> 8, FNV_PRIME);
833
- b = Math.imul(b ^ unit >>> 8, FNV_PRIME);
834
- b = Math.imul(b ^ unit & 255, FNV_PRIME);
835
- b ^= b >>> 15;
836
- }
837
- a ^= a >>> 16;
838
- a = Math.imul(a, 2246822507);
839
- a ^= a >>> 13;
840
- b ^= b >>> 16;
841
- b = Math.imul(b, 3266489909);
842
- b ^= b >>> 13;
843
- const hex = (n) => (n >>> 0).toString(16).padStart(8, "0");
844
- return `h1-${hex(a)}${hex(b)}`;
845
- }
846
- function hashValue(value) {
847
- return hashText(stableStringify(value));
848
- }
849
- var PRESENTATION_ONLY = /* @__PURE__ */ new Set(["name", "description", "badges", "icon", "group", "timing"]);
850
- function hashCapabilities(caps) {
851
- const relevant = {};
852
- for (const key of Object.keys(caps)) {
853
- if (!PRESENTATION_ONLY.has(key)) relevant[key] = caps[key];
854
- }
855
- return hashValue(relevant);
856
- }
857
-
858
195
  // src/generation/tools.ts
859
196
  var STRATEGIES = ["nearest", "upgrade", "downgrade", "error"];
860
197
  function knownRoles(models) {
861
- const roles = [...REFERENCE_ROLES];
198
+ const roles = [..._chunkECCXGELCcjs.REFERENCE_ROLES];
862
199
  for (const model of models) {
863
- for (const role of supportedReferenceRoles(model)) if (!roles.includes(role)) roles.push(role);
200
+ for (const role of _chunkECCXGELCcjs.supportedReferenceRoles.call(void 0, model)) if (!roles.includes(role)) roles.push(role);
864
201
  }
865
202
  return roles;
866
203
  }
@@ -934,7 +271,7 @@ function createGenerationToolProvider(options) {
934
271
  const request = { ..._nullishCoalesce(args.request, () => ( {})), model: model.id };
935
272
  return {
936
273
  model,
937
- plan: planGenerationRequest(request, model, {
274
+ plan: _chunkECCXGELCcjs.planGenerationRequest.call(void 0, request, model, {
938
275
  strategy: _nullishCoalesce(args.strategy, () => ( defaultStrategy)),
939
276
  resolvedPrompt: args.resolvedPrompt
940
277
  })
@@ -959,7 +296,7 @@ function createGenerationToolProvider(options) {
959
296
  };
960
297
  };
961
298
  const tools = () => {
962
- const list2 = [
299
+ const list = [
963
300
  {
964
301
  name: "list_models",
965
302
  title: "List generation models",
@@ -984,7 +321,7 @@ function createGenerationToolProvider(options) {
984
321
  media: m.media,
985
322
  ...m.name ? { name: m.name } : {},
986
323
  ...m.description ? { description: m.description } : {},
987
- ..._optionalChain([m, 'access', _64 => _64.badges, 'optionalAccess', _65 => _65.length]) ? { badges: [...m.badges] } : {},
324
+ ..._optionalChain([m, 'access', _36 => _36.badges, 'optionalAccess', _37 => _37.length]) ? { badges: [...m.badges] } : {},
988
325
  requestSchema: capabilitiesToJsonSchema(m)
989
326
  }))
990
327
  })
@@ -1006,7 +343,7 @@ function createGenerationToolProvider(options) {
1006
343
  ];
1007
344
  if (options.estimate) {
1008
345
  const estimate = options.estimate;
1009
- list2.push({
346
+ list.push({
1010
347
  name: "estimate_generation",
1011
348
  title: "Estimate a generation",
1012
349
  description: "Estimates cost and/or time of a request after planning it. Does not generate anything.",
@@ -1027,7 +364,7 @@ function createGenerationToolProvider(options) {
1027
364
  });
1028
365
  }
1029
366
  const generateInput = planInput();
1030
- list2.push({
367
+ list.push({
1031
368
  name: "generate",
1032
369
  title: "Generate media",
1033
370
  description: "Plans the request and starts a generation. Pass a fresh `idempotencyKey` per intended generation and reuse it when retrying, so a retry never generates twice.",
@@ -1054,7 +391,7 @@ function createGenerationToolProvider(options) {
1054
391
  handler: async (args, context) => {
1055
392
  const key = String(args.idempotencyKey);
1056
393
  const { idempotencyKey: _key, ...rest } = args;
1057
- const signature = stableStringify(rest);
394
+ const signature = _chunkECCXGELCcjs.stableStringify.call(void 0, rest);
1058
395
  const existing = calls.get(key);
1059
396
  if (existing) {
1060
397
  if (existing.signature !== signature) {
@@ -1082,12 +419,12 @@ function createGenerationToolProvider(options) {
1082
419
  try {
1083
420
  return await result;
1084
421
  } catch (error) {
1085
- if (_optionalChain([calls, 'access', _66 => _66.get, 'call', _67 => _67(key), 'optionalAccess', _68 => _68.result]) === result) calls.delete(key);
422
+ if (_optionalChain([calls, 'access', _38 => _38.get, 'call', _39 => _39(key), 'optionalAccess', _40 => _40.result]) === result) calls.delete(key);
1086
423
  throw error;
1087
424
  }
1088
425
  }
1089
426
  });
1090
- return list2;
427
+ return list;
1091
428
  };
1092
429
  return {
1093
430
  id: _nullishCoalesce(options.id, () => ( "generation")),
@@ -1110,23 +447,23 @@ function toAssetResolver(lookup) {
1110
447
  return (id) => byId.get(id);
1111
448
  }
1112
449
  function roleCap(caps, role) {
1113
- const cap = _optionalChain([caps, 'access', _69 => _69.references, 'optionalAccess', _70 => _70.roles, 'access', _71 => _71[role]]);
450
+ const cap = _optionalChain([caps, 'access', _41 => _41.references, 'optionalAccess', _42 => _42.roles, 'access', _43 => _43[role]]);
1114
451
  if (cap && cap.max > 0) return cap;
1115
452
  if (role === "mask" && caps.inpainting) return { max: 1 };
1116
453
  return void 0;
1117
454
  }
1118
455
  function getAssetRoleOptions(caps) {
1119
- const roles = supportedReferenceRoles(caps);
456
+ const roles = _chunkECCXGELCcjs.supportedReferenceRoles.call(void 0, caps);
1120
457
  if (caps.inpainting && !roles.includes("mask")) roles.push("mask");
1121
458
  return roles.map((role) => {
1122
459
  const cap = _nullishCoalesce(roleCap(caps, role), () => ( { max: 1 }));
1123
460
  return {
1124
461
  role,
1125
- label: referenceRoleLabel(role, caps),
462
+ label: _chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps),
1126
463
  ...cap.description ? { description: cap.description } : {},
1127
464
  min: _nullishCoalesce(cap.min, () => ( 0)),
1128
465
  max: cap.max,
1129
- ..._optionalChain([cap, 'access', _72 => _72.accepts, 'optionalAccess', _73 => _73.length]) ? { accepts: [...cap.accepts] } : {}
466
+ ..._optionalChain([cap, 'access', _44 => _44.accepts, 'optionalAccess', _45 => _45.length]) ? { accepts: [...cap.accepts] } : {}
1130
467
  };
1131
468
  });
1132
469
  }
@@ -1143,7 +480,7 @@ function validateAssetMentions(mentions, caps, options = {}) {
1143
480
  }
1144
481
  let role = mention.role;
1145
482
  if (!roleCap(caps, role)) {
1146
- const alias = normalizeReferenceRole(role, caps);
483
+ const alias = _chunkECCXGELCcjs.normalizeReferenceRole.call(void 0, role, caps);
1147
484
  if (alias !== role && roleCap(caps, alias)) {
1148
485
  issues.push({
1149
486
  index,
@@ -1152,7 +489,7 @@ function validateAssetMentions(mentions, caps, options = {}) {
1152
489
  code: "renamed-role",
1153
490
  severity: "warning",
1154
491
  suggestion: alias,
1155
- message: `${label}: this model calls "${role}" ${referenceRoleLabel(alias, caps)} (${alias}).`
492
+ message: `${label}: this model calls "${role}" ${_chunkECCXGELCcjs.referenceRoleLabel.call(void 0, alias, caps)} (${alias}).`
1156
493
  });
1157
494
  role = alias;
1158
495
  } else {
@@ -1162,21 +499,21 @@ function validateAssetMentions(mentions, caps, options = {}) {
1162
499
  role,
1163
500
  code: "unsupported-role",
1164
501
  severity: "error",
1165
- message: `${label}: ${_nullishCoalesce(caps.name, () => ( caps.id))} does not accept ${referenceRoleLabel(role, caps).toLowerCase()} assets.`
502
+ message: `${label}: ${_nullishCoalesce(caps.name, () => ( caps.id))} does not accept ${_chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps).toLowerCase()} assets.`
1166
503
  });
1167
504
  return;
1168
505
  }
1169
506
  }
1170
507
  const cap = roleCap(caps, role);
1171
- const mediaType = _nullishCoalesce(mention.mediaType, () => ( _optionalChain([resolve, 'optionalCall', _74 => _74(id), 'optionalAccess', _75 => _75.mediaType])));
1172
- if (mediaType !== void 0 && !mediaTypeMatches(mediaType, cap.accepts)) {
508
+ const mediaType = _nullishCoalesce(mention.mediaType, () => ( _optionalChain([resolve, 'optionalCall', _46 => _46(id), 'optionalAccess', _47 => _47.mediaType])));
509
+ if (mediaType !== void 0 && !_chunkECCXGELCcjs.mediaTypeMatches.call(void 0, mediaType, cap.accepts)) {
1173
510
  issues.push({
1174
511
  index,
1175
512
  id,
1176
513
  role,
1177
514
  code: "media-mismatch",
1178
515
  severity: "error",
1179
- message: `${label} is ${mediaType}; ${referenceRoleLabel(role, caps)} accepts ${(_nullishCoalesce(cap.accepts, () => ( []))).join(", ")}.`
516
+ message: `${label} is ${mediaType}; ${_chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps)} accepts ${(_nullishCoalesce(cap.accepts, () => ( []))).join(", ")}.`
1180
517
  });
1181
518
  return;
1182
519
  }
@@ -1188,7 +525,7 @@ function validateAssetMentions(mentions, caps, options = {}) {
1188
525
  role,
1189
526
  code: "too-many",
1190
527
  severity: "warning",
1191
- message: `${label}: at most ${cap.max} ${referenceRoleLabel(role, caps).toLowerCase()} asset(s); extra ones are left out.`
528
+ message: `${label}: at most ${cap.max} ${_chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps).toLowerCase()} asset(s); extra ones are left out.`
1192
529
  });
1193
530
  }
1194
531
  });
@@ -1214,7 +551,7 @@ function resolveAssetMentions(mentions, assets) {
1214
551
  return result;
1215
552
  }
1216
553
  function defaultAssetRoleOptions() {
1217
- return REFERENCE_ROLES.map((role) => ({ role, label: referenceRoleLabel(role), min: 0, max: 1 }));
554
+ return _chunkECCXGELCcjs.REFERENCE_ROLES.map((role) => ({ role, label: _chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role), min: 0, max: 1 }));
1218
555
  }
1219
556
  function describeAssetMentions(mentions, assets, caps) {
1220
557
  const byId = new Map(assets.map((asset) => [asset.id, asset]));
@@ -1229,7 +566,7 @@ function describeAssetMentions(mentions, assets, caps) {
1229
566
  ...mention.start !== void 0 ? { start: mention.start } : {},
1230
567
  handle: mention.handle,
1231
568
  asset,
1232
- ...role ? { role, roleLabel: referenceRoleLabel(caps ? normalizeReferenceRole(role, caps) : role, caps) } : {},
569
+ ...role ? { role, roleLabel: _chunkECCXGELCcjs.referenceRoleLabel.call(void 0, caps ? _chunkECCXGELCcjs.normalizeReferenceRole.call(void 0, role, caps) : role, caps) } : {},
1233
570
  issues: []
1234
571
  });
1235
572
  }
@@ -1248,165 +585,33 @@ function describeAssetMentions(mentions, assets, caps) {
1248
585
  return chips;
1249
586
  }
1250
587
 
1251
- // src/generation/provenance.ts
1252
- var PROVENANCE_FORMAT = "pixerate.generation-provenance";
1253
- var PROVENANCE_VERSION = 1;
1254
- var ProvenanceParseError = class extends Error {
1255
- constructor(message) {
1256
- super(message);
1257
- this.name = "ProvenanceParseError";
1258
- }
1259
- };
1260
- var toIso = (value) => new Date(value).toISOString();
1261
- var clone = (value) => value === void 0 ? value : JSON.parse(JSON.stringify(value));
1262
- function pinTemplates(rawPrompt, templates, bindings, maxDepth) {
1263
- const byName = new Map(templates.map((t) => [t.name, t]));
1264
- const pinned = /* @__PURE__ */ new Map();
1265
- const visit = (text, depth) => {
1266
- if (depth > maxDepth) return;
1267
- for (const token of _chunkFD4LPFAEcjs.tokenizePrompt.call(void 0, text)) {
1268
- if (token.type !== "template" || pinned.has(token.value)) continue;
1269
- const template = byName.get(token.value);
1270
- if (!template) continue;
1271
- const body = _chunkFD4LPFAEcjs.getTemplateBody.call(void 0, template, bindings);
1272
- if (body === void 0) continue;
1273
- const bound = bindings[template.name];
1274
- const version = bound && template.versions ? template.versions.find((v) => v.id === bound || v.version === bound) : _chunkFD4LPFAEcjs.getLatestVersion.call(void 0, template);
1275
- const isVersioned = !!_optionalChain([template, 'access', _76 => _76.versions, 'optionalAccess', _77 => _77.length]) && !!version;
1276
- pinned.set(template.name, {
1277
- name: template.name,
1278
- ...template.id !== void 0 ? { templateId: template.id } : {},
1279
- ...isVersioned ? { versionId: version.id, version: version.version } : {},
1280
- body
1281
- });
1282
- visit(body, depth + 1);
1283
- }
1284
- };
1285
- visit(rawPrompt, 0);
1286
- return [...pinned.values()];
1287
- }
1288
- function pinnedTemplatesToTemplates(pinned) {
1289
- return pinned.map(
1290
- (p) => p.versionId !== void 0 ? {
1291
- ...p.templateId !== void 0 ? { id: p.templateId } : {},
1292
- name: p.name,
1293
- latestVersion: p.version,
1294
- versions: [{ id: p.versionId, version: _nullishCoalesce(p.version, () => ( p.versionId)), body: p.body }]
1295
- } : { ...p.templateId !== void 0 ? { id: p.templateId } : {}, name: p.name, body: p.body }
1296
- );
1297
- }
1298
- function createProvenance(options) {
1299
- const templates = _nullishCoalesce(options.templates, () => ( []));
1300
- const maxDepth = _nullishCoalesce(options.maxDepth, () => ( 10));
1301
- const resolved = _chunkFD4LPFAEcjs.resolvePrompt.call(void 0, options.rawPrompt, templates, {
1302
- bindings: options.bindings,
1303
- values: options.values,
1304
- maxDepth
1305
- });
1306
- const pinned = pinTemplates(options.rawPrompt, templates, _nullishCoalesce(options.bindings, () => ( {})), maxDepth);
1307
- const bindings = {};
1308
- for (const p of pinned) if (p.versionId !== void 0) bindings[p.name] = p.versionId;
1309
- const modelId = typeof options.model === "string" ? options.model : options.model.id;
1310
- const request = clone(_nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'access', _78 => _78.plan, 'optionalAccess', _79 => _79.request]), () => ( options.request)), () => ( {})));
1311
- request.model = modelId;
1312
- if (request.prompt === void 0) request.prompt = resolved.text;
1313
- const adjustments = clone(_nullishCoalesce(_nullishCoalesce(options.adjustments, () => ( _optionalChain([options, 'access', _80 => _80.plan, 'optionalAccess', _81 => _81.adjustments]))), () => ( [])));
1314
- return {
1315
- format: PROVENANCE_FORMAT,
1316
- version: PROVENANCE_VERSION,
1317
- rawPrompt: options.rawPrompt,
1318
- templates: pinned,
1319
- bindings,
1320
- values: options.values ? clone(options.values) : null,
1321
- resolvedPrompt: resolved.text,
1322
- sourceMap: resolved.map.map((segment) => {
1323
- const { locked: _locked, ...rest } = segment;
1324
- return rest;
1325
- }),
1326
- modelId,
1327
- request,
1328
- adjustments,
1329
- references: (_nullishCoalesce(request.references, () => ( []))).map(({ id, role }) => ({ id, role })),
1330
- createdAt: toIso(_nullishCoalesce(options.createdAt, () => ( Date.now()))),
1331
- ...options.startedAt !== void 0 ? { startedAt: toIso(options.startedAt) } : {},
1332
- ...options.completedAt !== void 0 ? { completedAt: toIso(options.completedAt) } : {},
1333
- ...options.outputIds ? { outputIds: [...options.outputIds] } : {},
1334
- ...options.meta ? { meta: clone(options.meta) } : {}
1335
- };
1336
- }
1337
- function serializeProvenance(provenance) {
1338
- return JSON.stringify(provenance);
1339
- }
1340
- var isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
1341
- function parseProvenance(input) {
1342
- let data = input;
1343
- if (typeof input === "string") {
1344
- try {
1345
- data = JSON.parse(input);
1346
- } catch (e2) {
1347
- throw new ProvenanceParseError("Provenance is not valid JSON.");
1348
- }
1349
- }
1350
- if (!isRecord(data) || data.format !== PROVENANCE_FORMAT) {
1351
- throw new ProvenanceParseError("Not a generation provenance record.");
1352
- }
1353
- if (typeof data.version !== "number" || data.version > PROVENANCE_VERSION) {
1354
- throw new ProvenanceParseError(`Unsupported provenance version ${JSON.stringify(data.version)}.`);
1355
- }
1356
- const checks = [
1357
- ["rawPrompt", typeof data.rawPrompt === "string"],
1358
- ["resolvedPrompt", typeof data.resolvedPrompt === "string"],
1359
- ["modelId", typeof data.modelId === "string"],
1360
- ["createdAt", typeof data.createdAt === "string"],
1361
- ["request", isRecord(data.request)],
1362
- ["templates", Array.isArray(data.templates) && data.templates.every((t) => isRecord(t) && typeof t.name === "string" && typeof t.body === "string")],
1363
- ["sourceMap", Array.isArray(data.sourceMap)],
1364
- ["adjustments", Array.isArray(data.adjustments)],
1365
- ["references", Array.isArray(data.references)]
1366
- ];
1367
- const bad = checks.find(([, ok]) => !ok);
1368
- if (bad) throw new ProvenanceParseError(`Invalid provenance field "${bad[0]}".`);
1369
- return {
1370
- ...data,
1371
- bindings: isRecord(data.bindings) ? data.bindings : {},
1372
- values: isRecord(data.values) ? data.values : null
1373
- };
1374
- }
1375
- function replayProvenancePrompt(provenance) {
1376
- const result = _chunkFD4LPFAEcjs.resolvePrompt.call(void 0, provenance.rawPrompt, pinnedTemplatesToTemplates(provenance.templates), {
1377
- bindings: provenance.bindings,
1378
- ...provenance.values ? { values: provenance.values } : {}
1379
- });
1380
- return { text: result.text, map: result.map, matches: result.text === provenance.resolvedPrompt };
1381
- }
1382
-
1383
588
  // src/generation/record.ts
1384
589
  var GENERATION_RECORD_FORMAT = "pixerate.generation-record";
1385
590
  var GENERATION_RECORD_VERSION = 1;
1386
591
  var idCounter = 0;
1387
592
  function createGenerationRecordId() {
1388
- const uuid = _optionalChain([globalThis, 'access', _82 => _82.crypto, 'optionalAccess', _83 => _83.randomUUID, 'optionalCall', _84 => _84()]);
593
+ const uuid = _optionalChain([globalThis, 'access', _48 => _48.crypto, 'optionalAccess', _49 => _49.randomUUID, 'optionalCall', _50 => _50()]);
1389
594
  if (typeof uuid === "string") return `gen_${uuid}`;
1390
595
  idCounter = (idCounter + 1) % 1679616;
1391
596
  const random = Math.floor(Math.random() * 2 ** 48).toString(36).padStart(10, "0");
1392
597
  return `gen_${Date.now().toString(36)}${idCounter.toString(36).padStart(4, "0")}${random}`;
1393
598
  }
1394
- var clone2 = (value) => value === void 0 ? value : JSON.parse(JSON.stringify(value));
599
+ var clone = (value) => value === void 0 ? value : JSON.parse(JSON.stringify(value));
1395
600
  function recordTemplates(pinned) {
1396
601
  return pinned.map((p) => ({
1397
602
  name: p.name,
1398
603
  ...p.templateId !== void 0 ? { templateId: p.templateId } : {},
1399
604
  ...p.versionId !== void 0 ? { versionId: p.versionId, version: p.version } : {},
1400
- hash: hashText(p.body)
605
+ hash: _chunkECCXGELCcjs.hashText.call(void 0, p.body)
1401
606
  }));
1402
607
  }
1403
608
  function recordAssets(references, lookup) {
1404
609
  const resolve = toAssetResolver(lookup);
1405
610
  return (_nullishCoalesce(references, () => ( []))).map((ref) => {
1406
- const info = _optionalChain([resolve, 'optionalCall', _85 => _85(ref.id)]);
1407
- const contentHash = _nullishCoalesce(ref.contentHash, () => ( _optionalChain([info, 'optionalAccess', _86 => _86.contentHash])));
1408
- const mediaType = _nullishCoalesce(ref.mediaType, () => ( _optionalChain([info, 'optionalAccess', _87 => _87.mediaType])));
1409
- const url = _nullishCoalesce(ref.url, () => ( _optionalChain([info, 'optionalAccess', _88 => _88.url])));
611
+ const info = _optionalChain([resolve, 'optionalCall', _51 => _51(ref.id)]);
612
+ const contentHash = _nullishCoalesce(ref.contentHash, () => ( _optionalChain([info, 'optionalAccess', _52 => _52.contentHash])));
613
+ const mediaType = _nullishCoalesce(ref.mediaType, () => ( _optionalChain([info, 'optionalAccess', _53 => _53.mediaType])));
614
+ const url = _nullishCoalesce(ref.url, () => ( _optionalChain([info, 'optionalAccess', _54 => _54.url])));
1410
615
  return {
1411
616
  id: ref.id,
1412
617
  role: ref.role,
@@ -1431,7 +636,7 @@ function createGenerationRecord(options) {
1431
636
  ...provenanceOptions
1432
637
  } = options;
1433
638
  const caps = typeof model === "string" ? void 0 : model;
1434
- const settings = clone2(_nullishCoalesce(_nullishCoalesce(settingsInput, () => ( _optionalChain([planInput, 'optionalAccess', _89 => _89.request]))), () => ( {})));
639
+ const settings = clone(_nullishCoalesce(_nullishCoalesce(settingsInput, () => ( _optionalChain([planInput, 'optionalAccess', _55 => _55.request]))), () => ( {})));
1435
640
  let plan = planInput;
1436
641
  if (!plan && caps) {
1437
642
  const resolved = _chunkFD4LPFAEcjs.resolvePrompt.call(void 0, options.rawPrompt, _nullishCoalesce(options.templates, () => ( [])), {
@@ -1439,13 +644,13 @@ function createGenerationRecord(options) {
1439
644
  values: options.values,
1440
645
  maxDepth: options.maxDepth
1441
646
  });
1442
- plan = planGenerationRequest(settings, caps, {
647
+ plan = _chunkECCXGELCcjs.planGenerationRequest.call(void 0, settings, caps, {
1443
648
  strategy: _nullishCoalesce(strategyInput, () => ( "nearest")),
1444
649
  resolvedPrompt: resolved.text,
1445
650
  ...mentions ? { mentions } : {}
1446
651
  });
1447
652
  }
1448
- const provenance = createProvenance({
653
+ const provenance = _chunkQ6OUXEK3cjs.createProvenance.call(void 0, {
1449
654
  ...provenanceOptions,
1450
655
  model,
1451
656
  ...plan ? { plan } : { request: settings }
@@ -1459,22 +664,22 @@ function createGenerationRecord(options) {
1459
664
  kind: _nullishCoalesce(kind, () => ( (parentId !== void 0 ? "recreate" : "generate"))),
1460
665
  provenance,
1461
666
  templates: recordTemplates(provenance.templates),
1462
- promptHash: hashText(provenance.resolvedPrompt),
1463
- ...caps ? { capabilityHash: hashCapabilities(caps) } : {},
667
+ promptHash: _chunkECCXGELCcjs.hashText.call(void 0, provenance.resolvedPrompt),
668
+ ...caps ? { capabilityHash: _chunkECCXGELCcjs.hashCapabilities.call(void 0, caps) } : {},
1464
669
  settings,
1465
- strategy: _nullishCoalesce(_nullishCoalesce(strategyInput, () => ( _optionalChain([plan, 'optionalAccess', _90 => _90.strategy]))), () => ( "nearest")),
670
+ strategy: _nullishCoalesce(_nullishCoalesce(strategyInput, () => ( _optionalChain([plan, 'optionalAccess', _56 => _56.strategy]))), () => ( "nearest")),
1466
671
  ...seed !== void 0 ? { seed } : {},
1467
672
  assets: recordAssets(provenance.request.references, assets),
1468
- ..._optionalChain([mentions, 'optionalAccess', _91 => _91.length]) ? { mentions: clone2([...mentions]) } : {},
673
+ ..._optionalChain([mentions, 'optionalAccess', _57 => _57.length]) ? { mentions: clone([...mentions]) } : {},
1469
674
  createdAt: provenance.createdAt
1470
675
  };
1471
676
  }
1472
677
  function completeGenerationRecord(record, update) {
1473
- const next = clone2(record);
678
+ const next = clone(record);
1474
679
  const now = new Date(_nullishCoalesce(update.completedAt, () => ( Date.now()))).toISOString();
1475
680
  if (update.outputIds) next.provenance.outputIds = [...update.outputIds];
1476
681
  next.provenance.completedAt = now;
1477
- if (update.meta) next.provenance.meta = { ..._nullishCoalesce(next.provenance.meta, () => ( {})), ...clone2(update.meta) };
682
+ if (update.meta) next.provenance.meta = { ..._nullishCoalesce(next.provenance.meta, () => ( {})), ...clone(update.meta) };
1478
683
  if (update.seed !== void 0) next.seed = update.seed;
1479
684
  next.updatedAt = now;
1480
685
  return next;
@@ -1488,15 +693,15 @@ function parseGenerationRecord(input) {
1488
693
  if (typeof input === "string") {
1489
694
  try {
1490
695
  data = JSON.parse(input);
1491
- } catch (e3) {
1492
- throw new ProvenanceParseError("Generation record is not valid JSON.");
696
+ } catch (e2) {
697
+ throw new (0, _chunkQ6OUXEK3cjs.ProvenanceParseError)("Generation record is not valid JSON.");
1493
698
  }
1494
699
  }
1495
700
  if (!isObject(data) || data.format !== GENERATION_RECORD_FORMAT) {
1496
- throw new ProvenanceParseError("Not a generation record.");
701
+ throw new (0, _chunkQ6OUXEK3cjs.ProvenanceParseError)("Not a generation record.");
1497
702
  }
1498
703
  if (typeof data.version !== "number" || data.version > GENERATION_RECORD_VERSION) {
1499
- throw new ProvenanceParseError(`Unsupported generation record version ${JSON.stringify(data.version)}.`);
704
+ throw new (0, _chunkQ6OUXEK3cjs.ProvenanceParseError)(`Unsupported generation record version ${JSON.stringify(data.version)}.`);
1500
705
  }
1501
706
  const checks = [
1502
707
  ["id", typeof data.id === "string" && data.id !== ""],
@@ -1507,8 +712,8 @@ function parseGenerationRecord(input) {
1507
712
  ["createdAt", typeof data.createdAt === "string"]
1508
713
  ];
1509
714
  const bad = checks.find(([, ok]) => !ok);
1510
- if (bad) throw new ProvenanceParseError(`Invalid generation record field "${bad[0]}".`);
1511
- const provenance = parseProvenance(data.provenance);
715
+ if (bad) throw new (0, _chunkQ6OUXEK3cjs.ProvenanceParseError)(`Invalid generation record field "${bad[0]}".`);
716
+ const provenance = _chunkQ6OUXEK3cjs.parseProvenance.call(void 0, data.provenance);
1512
717
  return {
1513
718
  ...data,
1514
719
  kind: data.kind === "recreate" || data.kind === "variation" ? data.kind : "generate",
@@ -1522,10 +727,10 @@ function isGenerationRecord(value) {
1522
727
  var SKIPPED_SETTING_FIELDS = /* @__PURE__ */ new Set(["model", "prompt", "references", "params", "seed"]);
1523
728
  function findModel(capabilities, modelId) {
1524
729
  if (!capabilities) return { given: false };
1525
- const list2 = Array.isArray(capabilities) ? capabilities : [capabilities];
1526
- return { given: true, caps: list2.find((m) => m.id === modelId) };
730
+ const list = Array.isArray(capabilities) ? capabilities : [capabilities];
731
+ return { given: true, caps: list.find((m) => m.id === modelId) };
1527
732
  }
1528
- var sameValue = (a, b) => stableStringify(a) === stableStringify(b);
733
+ var sameValue = (a, b) => _chunkECCXGELCcjs.stableStringify.call(void 0, a) === _chunkECCXGELCcjs.stableStringify.call(void 0, b);
1529
734
  var show = (value) => value === void 0 ? "unset" : typeof value === "string" ? `"${value}"` : JSON.stringify(value);
1530
735
  var refKey = (ref) => `${ref.role}:${ref.id}`;
1531
736
  function templateDrift(record, current, mode) {
@@ -1547,10 +752,10 @@ function templateDrift(record, current, mode) {
1547
752
  continue;
1548
753
  }
1549
754
  const body = _chunkFD4LPFAEcjs.getTemplateBody.call(void 0, template, {});
1550
- const hash = body === void 0 ? void 0 : hashText(body);
755
+ const hash = body === void 0 ? void 0 : _chunkECCXGELCcjs.hashText.call(void 0, body);
1551
756
  if (hash === recorded.hash) continue;
1552
757
  const latest = _chunkFD4LPFAEcjs.getLatestVersion.call(void 0, template);
1553
- const toVersion = _optionalChain([template, 'access', _92 => _92.versions, 'optionalAccess', _93 => _93.length]) ? _nullishCoalesce(_optionalChain([latest, 'optionalAccess', _94 => _94.version]), () => ( _optionalChain([latest, 'optionalAccess', _95 => _95.id]))) : void 0;
758
+ const toVersion = _optionalChain([template, 'access', _58 => _58.versions, 'optionalAccess', _59 => _59.length]) ? _nullishCoalesce(_optionalChain([latest, 'optionalAccess', _60 => _60.version]), () => ( _optionalChain([latest, 'optionalAccess', _61 => _61.id]))) : void 0;
1554
759
  const versions = fromVersion !== void 0 || toVersion !== void 0 ? ` (${_nullishCoalesce(fromVersion, () => ( "unversioned"))} \u2192 ${_nullishCoalesce(toVersion, () => ( "unversioned"))})` : "";
1555
760
  drift.push({
1556
761
  type: "template-changed",
@@ -1565,7 +770,7 @@ function templateDrift(record, current, mode) {
1565
770
  return drift;
1566
771
  }
1567
772
  function randomSeed(caps, previous, random) {
1568
- const cap = caps ? seedCapability(caps.seed) : {};
773
+ const cap = caps ? _chunkECCXGELCcjs.seedCapability.call(void 0, caps.seed) : {};
1569
774
  if (!cap) return void 0;
1570
775
  const min = Math.ceil(_nullishCoalesce(cap.min, () => ( 0)));
1571
776
  const max = Math.floor(_nullishCoalesce(cap.max, () => ( 2 ** 31 - 1)));
@@ -1581,9 +786,9 @@ function rebuild(record, options, kind, overrides) {
1581
786
  const mode = _nullishCoalesce(options.mode, () => ( "exact"));
1582
787
  const provenance = record.provenance;
1583
788
  const drift = templateDrift(record, options.templates, mode);
1584
- const rawPrompt = _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _96 => _96.rawPrompt]), () => ( provenance.rawPrompt));
1585
- const values = _optionalChain([overrides, 'optionalAccess', _97 => _97.values]) !== void 0 ? { ..._nullishCoalesce(provenance.values, () => ( {})), ...overrides.values } : provenance.values ? clone2(provenance.values) : null;
1586
- const pinned = pinnedTemplatesToTemplates(provenance.templates);
789
+ const rawPrompt = _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _62 => _62.rawPrompt]), () => ( provenance.rawPrompt));
790
+ const values = _optionalChain([overrides, 'optionalAccess', _63 => _63.values]) !== void 0 ? { ..._nullishCoalesce(provenance.values, () => ( {})), ...overrides.values } : provenance.values ? clone(provenance.values) : null;
791
+ const pinned = _chunkQ6OUXEK3cjs.pinnedTemplatesToTemplates.call(void 0, provenance.templates);
1587
792
  let templates;
1588
793
  let bindings;
1589
794
  if (mode === "latest" && options.templates) {
@@ -1613,11 +818,11 @@ function rebuild(record, options, kind, overrides) {
1613
818
  message: "The resolved prompt differs from the recorded one."
1614
819
  });
1615
820
  }
1616
- const base = clone2(mode === "exact" ? provenance.request : record.settings);
821
+ const base = clone(mode === "exact" ? provenance.request : record.settings);
1617
822
  const recordedPlanned = provenance.request;
1618
823
  if (base.prompt === void 0 || base.prompt === provenance.resolvedPrompt) base.prompt = resolved.text;
1619
824
  else if (base.prompt === provenance.rawPrompt) base.prompt = rawPrompt;
1620
- if (mode === "latest" && _optionalChain([record, 'access', _98 => _98.mentions, 'optionalAccess', _99 => _99.length])) {
825
+ if (mode === "latest" && _optionalChain([record, 'access', _64 => _64.mentions, 'optionalAccess', _65 => _65.length])) {
1621
826
  const plannedRole = new Map((_nullishCoalesce(recordedPlanned.references, () => ( []))).map((ref) => [ref.id, ref.role]));
1622
827
  base.references = [
1623
828
  ..._nullishCoalesce(base.references, () => ( [])),
@@ -1630,7 +835,7 @@ function rebuild(record, options, kind, overrides) {
1630
835
  }))
1631
836
  ];
1632
837
  } else if (mode === "latest" && base.references === void 0 && recordedPlanned.references) {
1633
- base.references = clone2(recordedPlanned.references);
838
+ base.references = clone(recordedPlanned.references);
1634
839
  }
1635
840
  if (record.seed !== void 0) base.seed = record.seed;
1636
841
  base.model = provenance.modelId;
@@ -1638,8 +843,8 @@ function rebuild(record, options, kind, overrides) {
1638
843
  if (overrides) {
1639
844
  if (overrides.settings) {
1640
845
  const { params, ...rest } = overrides.settings;
1641
- Object.assign(base, clone2(rest));
1642
- if (params) base.params = { ..._nullishCoalesce(base.params, () => ( {})), ...clone2(params) };
846
+ Object.assign(base, clone(rest));
847
+ if (params) base.params = { ..._nullishCoalesce(base.params, () => ( {})), ...clone(params) };
1643
848
  }
1644
849
  if (overrides.seed === null) delete base.seed;
1645
850
  else base.seed = _nullishCoalesce(overrides.seed, () => ( randomSeed(caps, record.seed, _nullishCoalesce(overrides.random, () => ( Math.random)))));
@@ -1661,7 +866,7 @@ function rebuild(record, options, kind, overrides) {
1661
866
  });
1662
867
  continue;
1663
868
  }
1664
- const recordedHash = _nullishCoalesce(_optionalChain([recordedById, 'access', _100 => _100.get, 'call', _101 => _101(refKey(ref)), 'optionalAccess', _102 => _102.contentHash]), () => ( ref.contentHash));
869
+ const recordedHash = _nullishCoalesce(_optionalChain([recordedById, 'access', _66 => _66.get, 'call', _67 => _67(refKey(ref)), 'optionalAccess', _68 => _68.contentHash]), () => ( ref.contentHash));
1665
870
  if (recordedHash !== void 0 && info.contentHash !== void 0 && recordedHash !== info.contentHash) {
1666
871
  drift.push({
1667
872
  type: "asset-changed",
@@ -1692,7 +897,7 @@ function rebuild(record, options, kind, overrides) {
1692
897
  message: `Model "${provenance.modelId}" is no longer available.`
1693
898
  });
1694
899
  } else if (caps) {
1695
- const capabilityHash = hashCapabilities(caps);
900
+ const capabilityHash = _chunkECCXGELCcjs.hashCapabilities.call(void 0, caps);
1696
901
  if (record.capabilityHash !== void 0 && record.capabilityHash !== capabilityHash) {
1697
902
  drift.push({
1698
903
  type: "model-changed",
@@ -1703,7 +908,7 @@ function rebuild(record, options, kind, overrides) {
1703
908
  message: `The capabilities of "${_nullishCoalesce(caps.name, () => ( caps.id))}" changed since this generation.`
1704
909
  });
1705
910
  }
1706
- plan = planGenerationRequest(base, caps, {
911
+ plan = _chunkECCXGELCcjs.planGenerationRequest.call(void 0, base, caps, {
1707
912
  strategy: _nullishCoalesce(options.strategy, () => ( record.strategy)),
1708
913
  resolvedPrompt: resolved.text
1709
914
  });
@@ -1723,7 +928,7 @@ function rebuild(record, options, kind, overrides) {
1723
928
  });
1724
929
  };
1725
930
  if (!overrides) {
1726
- for (const field of GENERATION_REQUEST_FIELDS) {
931
+ for (const field of _chunkECCXGELCcjs.GENERATION_REQUEST_FIELDS) {
1727
932
  if (SKIPPED_SETTING_FIELDS.has(field)) continue;
1728
933
  const from = recordedPlanned[field];
1729
934
  const to = request[field];
@@ -1731,8 +936,8 @@ function rebuild(record, options, kind, overrides) {
1731
936
  }
1732
937
  const paramNames = /* @__PURE__ */ new Set([...Object.keys(_nullishCoalesce(recordedPlanned.params, () => ( {}))), ...Object.keys(_nullishCoalesce(request.params, () => ( {})))]);
1733
938
  for (const name of [...paramNames].sort()) {
1734
- const from = _optionalChain([recordedPlanned, 'access', _103 => _103.params, 'optionalAccess', _104 => _104[name]]);
1735
- const to = _optionalChain([request, 'access', _105 => _105.params, 'optionalAccess', _106 => _106[name]]);
939
+ const from = _optionalChain([recordedPlanned, 'access', _69 => _69.params, 'optionalAccess', _70 => _70[name]]);
940
+ const to = _optionalChain([request, 'access', _71 => _71.params, 'optionalAccess', _72 => _72[name]]);
1736
941
  if (!sameValue(from, to)) describeChange(`params.${name}`, from, to);
1737
942
  }
1738
943
  if (!sameValue(_nullishCoalesce(record.seed, () => ( recordedPlanned.seed)), request.seed)) describeChange("seed", _nullishCoalesce(record.seed, () => ( recordedPlanned.seed)), request.seed);
@@ -1784,7 +989,7 @@ function rebuild(record, options, kind, overrides) {
1784
989
  function recreateRequest(input, options) {
1785
990
  if (isGenerationRecord(input)) return rebuild(input, _nullishCoalesce(options, () => ( {})), "recreate");
1786
991
  const provenance = input;
1787
- const request = clone2(provenance.request);
992
+ const request = clone(provenance.request);
1788
993
  request.model = provenance.modelId;
1789
994
  if (request.prompt === void 0) request.prompt = provenance.resolvedPrompt;
1790
995
  return request;
@@ -1959,16 +1164,16 @@ function createBatchResolver(options) {
1959
1164
  const run = (keys) => {
1960
1165
  const pendings = keys.map((key) => inFlight.get(key));
1961
1166
  const finish = (values, error) => {
1962
- if (values === null) _optionalChain([options, 'access', _107 => _107.onError, 'optionalCall', _108 => _108(error, keys)]);
1167
+ if (values === null) _optionalChain([options, 'access', _73 => _73.onError, 'optionalCall', _74 => _74(error, keys)]);
1963
1168
  keys.forEach((key, index) => {
1964
1169
  const pending = pendings[index];
1965
- const value = _optionalChain([values, 'optionalAccess', _109 => _109.get, 'call', _110 => _110(key)]);
1170
+ const value = _optionalChain([values, 'optionalAccess', _75 => _75.get, 'call', _76 => _76(key)]);
1966
1171
  if (pending && inFlight.get(key) === pending) {
1967
1172
  inFlight.delete(key);
1968
1173
  settled.set(key, value);
1969
1174
  if (values === null) failures.add(key);
1970
1175
  }
1971
- _optionalChain([pending, 'optionalAccess', _111 => _111.resolve, 'call', _112 => _112(value)]);
1176
+ _optionalChain([pending, 'optionalAccess', _77 => _77.resolve, 'call', _78 => _78(value)]);
1972
1177
  });
1973
1178
  };
1974
1179
  let promise;
@@ -2066,10 +1271,10 @@ function estimateJobProgress(input) {
2066
1271
  function expectedDurationFor(caps, request = {}) {
2067
1272
  const timing = caps.timing;
2068
1273
  if (!timing) return void 0;
2069
- const count = _nullishCoalesce(_nullishCoalesce(request.count, () => ( _optionalChain([caps, 'access', _113 => _113.count, 'optionalAccess', _114 => _114.default]))), () => ( 1));
2070
- const duration = _nullishCoalesce(_nullishCoalesce(request.duration, () => ( _optionalChain([caps, 'access', _115 => _115.duration, 'optionalAccess', _116 => _116.default]))), () => ( 0));
2071
- const resolution = _nullishCoalesce(request.resolution, () => ( _optionalChain([caps, 'access', _117 => _117.resolutions, 'optionalAccess', _118 => _118.default])));
2072
- const megapixels = resolution ? _nullishCoalesce(resolutionMegapixels(resolution), () => ( 0)) : 0;
1274
+ const count = _nullishCoalesce(_nullishCoalesce(request.count, () => ( _optionalChain([caps, 'access', _79 => _79.count, 'optionalAccess', _80 => _80.default]))), () => ( 1));
1275
+ const duration = _nullishCoalesce(_nullishCoalesce(request.duration, () => ( _optionalChain([caps, 'access', _81 => _81.duration, 'optionalAccess', _82 => _82.default]))), () => ( 0));
1276
+ const resolution = _nullishCoalesce(request.resolution, () => ( _optionalChain([caps, 'access', _83 => _83.resolutions, 'optionalAccess', _84 => _84.default])));
1277
+ const megapixels = resolution ? _nullishCoalesce(_chunkECCXGELCcjs.resolutionMegapixels.call(void 0, resolution), () => ( 0)) : 0;
2073
1278
  return Math.round(
2074
1279
  timing.baseMs + (_nullishCoalesce(timing.perItemMs, () => ( 0))) * Math.max(0, count - 1) + (_nullishCoalesce(timing.perSecondMs, () => ( 0))) * duration + (_nullishCoalesce(timing.perMegapixelMs, () => ( 0))) * megapixels
2075
1280
  );
@@ -2077,19 +1282,19 @@ function expectedDurationFor(caps, request = {}) {
2077
1282
 
2078
1283
  // src/generation/controls.ts
2079
1284
  function enumControl(key, label, cap) {
2080
- if (!_optionalChain([cap, 'optionalAccess', _119 => _119.options, 'access', _120 => _120.length])) return null;
1285
+ if (!_optionalChain([cap, 'optionalAccess', _85 => _85.options, 'access', _86 => _86.length])) return null;
2081
1286
  return {
2082
1287
  key,
2083
1288
  label,
2084
1289
  kind: "select",
2085
1290
  valueType: "string",
2086
- options: cap.options.map((value) => ({ value, label: _nullishCoalesce(_optionalChain([cap, 'access', _121 => _121.labels, 'optionalAccess', _122 => _122[value]]), () => ( value)) })),
1291
+ options: cap.options.map((value) => ({ value, label: _nullishCoalesce(_optionalChain([cap, 'access', _87 => _87.labels, 'optionalAccess', _88 => _88[value]]), () => ( value)) })),
2087
1292
  ...cap.default !== void 0 ? { defaultValue: cap.default } : {}
2088
1293
  };
2089
1294
  }
2090
1295
  function getGenerationControls(caps) {
2091
1296
  const controls = [];
2092
- const modes = supportedModes(caps);
1297
+ const modes = _chunkECCXGELCcjs.supportedModes.call(void 0, caps);
2093
1298
  if (modes.length > 1) {
2094
1299
  controls.push({
2095
1300
  key: "mode",
@@ -2100,24 +1305,24 @@ function getGenerationControls(caps) {
2100
1305
  defaultValue: "generate"
2101
1306
  });
2102
1307
  }
2103
- const negative = textFieldCapability(caps.negativePrompt);
1308
+ const negative = _chunkECCXGELCcjs.textFieldCapability.call(void 0, caps.negativePrompt);
2104
1309
  if (negative) controls.push({ key: "negativePrompt", label: "Negative prompt", kind: "textarea", valueType: "string", maxLength: negative.maxLength });
2105
- const system = textFieldCapability(caps.systemPrompt);
1310
+ const system = _chunkECCXGELCcjs.textFieldCapability.call(void 0, caps.systemPrompt);
2106
1311
  if (system) controls.push({ key: "systemPrompt", label: "System prompt", kind: "textarea", valueType: "string", maxLength: system.maxLength });
2107
1312
  controls.push(enumControl("aspectRatio", "Aspect ratio", caps.aspectRatios));
2108
1313
  controls.push(enumControl("resolution", "Resolution", caps.resolutions));
2109
1314
  controls.push(enumControl("quality", "Quality", caps.quality));
2110
1315
  if (caps.count) {
2111
- const options = _optionalChain([caps, 'access', _123 => _123.count, 'access', _124 => _124.options, 'optionalAccess', _125 => _125.filter, 'call', _126 => _126((o) => o >= 1 && o <= caps.count.max)]);
1316
+ const options = _optionalChain([caps, 'access', _89 => _89.count, 'access', _90 => _90.options, 'optionalAccess', _91 => _91.filter, 'call', _92 => _92((o) => o >= 1 && o <= caps.count.max)]);
2112
1317
  controls.push(
2113
- _optionalChain([options, 'optionalAccess', _127 => _127.length]) ? { key: "count", label: "Outputs", kind: "select", valueType: "number", options: options.map((o) => ({ value: o, label: String(o) })), defaultValue: caps.count.default } : { key: "count", label: "Outputs", kind: "range", valueType: "number", min: 1, max: caps.count.max, step: 1, defaultValue: _nullishCoalesce(caps.count.default, () => ( 1)) }
1318
+ _optionalChain([options, 'optionalAccess', _93 => _93.length]) ? { key: "count", label: "Outputs", kind: "select", valueType: "number", options: options.map((o) => ({ value: o, label: String(o) })), defaultValue: caps.count.default } : { key: "count", label: "Outputs", kind: "range", valueType: "number", min: 1, max: caps.count.max, step: 1, defaultValue: _nullishCoalesce(caps.count.default, () => ( 1)) }
2114
1319
  );
2115
1320
  }
2116
1321
  if (caps.duration) {
2117
1322
  const d = caps.duration;
2118
- const options = _optionalChain([d, 'access', _128 => _128.options, 'optionalAccess', _129 => _129.filter, 'call', _130 => _130((o) => (d.min === void 0 || o >= d.min) && (d.max === void 0 || o <= d.max))]);
1323
+ const options = _optionalChain([d, 'access', _94 => _94.options, 'optionalAccess', _95 => _95.filter, 'call', _96 => _96((o) => (d.min === void 0 || o >= d.min) && (d.max === void 0 || o <= d.max))]);
2119
1324
  controls.push(
2120
- _optionalChain([options, 'optionalAccess', _131 => _131.length]) ? { key: "duration", label: "Duration (s)", kind: "select", valueType: "number", options: options.map((o) => ({ value: o, label: `${o}s` })), defaultValue: d.default } : {
1325
+ _optionalChain([options, 'optionalAccess', _97 => _97.length]) ? { key: "duration", label: "Duration (s)", kind: "select", valueType: "number", options: options.map((o) => ({ value: o, label: `${o}s` })), defaultValue: d.default } : {
2121
1326
  key: "duration",
2122
1327
  label: "Duration (s)",
2123
1328
  kind: d.min !== void 0 && d.max !== void 0 ? "range" : "number",
@@ -2129,7 +1334,7 @@ function getGenerationControls(caps) {
2129
1334
  }
2130
1335
  );
2131
1336
  }
2132
- const seed = seedCapability(caps.seed);
1337
+ const seed = _chunkECCXGELCcjs.seedCapability.call(void 0, caps.seed);
2133
1338
  if (seed) controls.push({ key: "seed", label: "Seed", kind: "number", valueType: "number", min: seed.min, max: seed.max, step: 1 });
2134
1339
  for (const [name, spec] of Object.entries(_nullishCoalesce(caps.params, () => ( {})))) {
2135
1340
  const base = { key: `params.${name}`, label: _nullishCoalesce(spec.label, () => ( name)), ...spec.description ? { description: spec.description } : {} };
@@ -2159,7 +1364,7 @@ function getGenerationControls(caps) {
2159
1364
  return controls.filter((c) => c !== null);
2160
1365
  }
2161
1366
  function getRequestValue(request, key) {
2162
- if (key.startsWith("params.")) return _optionalChain([request, 'access', _132 => _132.params, 'optionalAccess', _133 => _133[key.slice(7)]]);
1367
+ if (key.startsWith("params.")) return _optionalChain([request, 'access', _98 => _98.params, 'optionalAccess', _99 => _99[key.slice(7)]]);
2163
1368
  return request[key];
2164
1369
  }
2165
1370
  function setRequestValue(request, key, value) {
@@ -2188,19 +1393,19 @@ function parseControlValue(control, raw) {
2188
1393
  return String(raw);
2189
1394
  }
2190
1395
  function getReferenceSlots(caps, request = {}) {
2191
- const roles = supportedReferenceRoles(caps);
1396
+ const roles = _chunkECCXGELCcjs.supportedReferenceRoles.call(void 0, caps);
2192
1397
  if (caps.inpainting && !roles.includes("mask")) roles.push("mask");
2193
1398
  const refs = _nullishCoalesce(request.references, () => ( []));
2194
1399
  const total = refs.length;
2195
- const maxTotal = _nullishCoalesce(_optionalChain([caps, 'access', _134 => _134.references, 'optionalAccess', _135 => _135.maxTotal]), () => ( Infinity));
1400
+ const maxTotal = _nullishCoalesce(_optionalChain([caps, 'access', _100 => _100.references, 'optionalAccess', _101 => _101.maxTotal]), () => ( Infinity));
2196
1401
  return roles.map((role) => {
2197
- const cap = _nullishCoalesce(_optionalChain([caps, 'access', _136 => _136.references, 'optionalAccess', _137 => _137.roles, 'access', _138 => _138[role]]), () => ( { max: 1 }));
1402
+ const cap = _nullishCoalesce(_optionalChain([caps, 'access', _102 => _102.references, 'optionalAccess', _103 => _103.roles, 'access', _104 => _104[role]]), () => ( { max: 1 }));
2198
1403
  const references = refs.filter((ref) => ref.role === role);
2199
1404
  return {
2200
1405
  role,
2201
- label: referenceRoleLabel(role, caps),
1406
+ label: _chunkECCXGELCcjs.referenceRoleLabel.call(void 0, role, caps),
2202
1407
  ...cap.description ? { description: cap.description } : {},
2203
- ..."accepts" in cap && _optionalChain([cap, 'access', _139 => _139.accepts, 'optionalAccess', _140 => _140.length]) ? { accepts: [...cap.accepts] } : {},
1408
+ ..."accepts" in cap && _optionalChain([cap, 'access', _105 => _105.accepts, 'optionalAccess', _106 => _106.length]) ? { accepts: [...cap.accepts] } : {},
2204
1409
  min: _nullishCoalesce(cap.min, () => ( 0)),
2205
1410
  max: cap.max,
2206
1411
  references,
@@ -2279,7 +1484,7 @@ function createGenerationRecordStore(options) {
2279
1484
  if (data && Array.isArray(data.items)) {
2280
1485
  items = data.items.filter((item) => item && typeof item.id === "string" && typeof item.createdAt === "string");
2281
1486
  }
2282
- } catch (e4) {
1487
+ } catch (e3) {
2283
1488
  items = [];
2284
1489
  }
2285
1490
  }
@@ -2302,7 +1507,7 @@ function createGenerationRecordStore(options) {
2302
1507
  let candidates = 0;
2303
1508
  const cutoff = prune.olderThan !== void 0 ? time(prune.olderThan) : void 0;
2304
1509
  for (const item of items) {
2305
- if (_optionalChain([prune, 'access', _141 => _141.keep, 'optionalCall', _142 => _142(item)])) {
1510
+ if (_optionalChain([prune, 'access', _107 => _107.keep, 'optionalCall', _108 => _108(item)])) {
2306
1511
  kept.push(item);
2307
1512
  candidates++;
2308
1513
  continue;
@@ -2335,7 +1540,7 @@ function createGenerationRecordStore(options) {
2335
1540
  if (!raw) return null;
2336
1541
  try {
2337
1542
  return parseGenerationRecord(raw);
2338
- } catch (e5) {
1543
+ } catch (e4) {
2339
1544
  return null;
2340
1545
  }
2341
1546
  }),
@@ -2347,7 +1552,7 @@ function createGenerationRecordStore(options) {
2347
1552
  if (!raw) continue;
2348
1553
  try {
2349
1554
  records.push(parseGenerationRecord(raw));
2350
- } catch (e6) {
1555
+ } catch (e5) {
2351
1556
  }
2352
1557
  }
2353
1558
  return records;
@@ -2454,5 +1659,5 @@ function createGenerationRecordStore(options) {
2454
1659
 
2455
1660
 
2456
1661
 
2457
- exports.DRIFT_TYPE_LABELS = DRIFT_TYPE_LABELS; exports.GENERATION_RECORD_FORMAT = GENERATION_RECORD_FORMAT; exports.GENERATION_RECORD_VERSION = GENERATION_RECORD_VERSION; exports.GENERATION_REQUEST_FIELDS = GENERATION_REQUEST_FIELDS; exports.MAX_PENDING_PERCENT = MAX_PENDING_PERCENT; exports.PROVENANCE_FORMAT = PROVENANCE_FORMAT; exports.PROVENANCE_VERSION = PROVENANCE_VERSION; exports.ProvenanceParseError = ProvenanceParseError; exports.QUALITY_LADDER = QUALITY_LADDER; exports.REFERENCE_ROLES = REFERENCE_ROLES; exports.REFERENCE_ROLE_ALIASES = REFERENCE_ROLE_ALIASES; exports.REFERENCE_ROLE_LABELS = REFERENCE_ROLE_LABELS; exports.REFERENCE_ROLE_NAME_REGEX = REFERENCE_ROLE_NAME_REGEX; exports.addReference = addReference; exports.aspectRatioRank = aspectRatioRank; exports.blockingDrift = blockingDrift; exports.capabilitiesToJsonSchema = capabilitiesToJsonSchema; exports.completeGenerationRecord = completeGenerationRecord; exports.createBatchResolver = createBatchResolver; exports.createGenerationHistoryToolProvider = createGenerationHistoryToolProvider; exports.createGenerationRecord = createGenerationRecord; exports.createGenerationRecordId = createGenerationRecordId; exports.createGenerationRecordStore = createGenerationRecordStore; exports.createGenerationToolProvider = createGenerationToolProvider; exports.createProvenance = createProvenance; exports.defaultAssetRoleOptions = defaultAssetRoleOptions; exports.describeAssetMentions = describeAssetMentions; exports.estimateJobProgress = estimateJobProgress; exports.expectedDurationFor = expectedDurationFor; exports.findTextMentions = _chunkBVP3TSLHcjs.findTextMentions; exports.formatMentionText = _chunkBVP3TSLHcjs.formatMentionText; exports.formatRemaining = formatRemaining; exports.getAssetRoleOptions = getAssetRoleOptions; exports.getGenerationControls = getGenerationControls; exports.getReferenceSlots = getReferenceSlots; exports.getRequestValue = getRequestValue; exports.hashCapabilities = hashCapabilities; exports.hashText = hashText; exports.hashValue = hashValue; exports.isGenerationRecord = isGenerationRecord; exports.isReferenceRoleName = isReferenceRoleName; exports.matchesRecordFilter = matchesRecordFilter; exports.mediaTypeMatches = mediaTypeMatches; exports.mergeCapabilities = mergeCapabilities; exports.normalizeReferenceRole = normalizeReferenceRole; exports.parseControlValue = parseControlValue; exports.parseGenerationRecord = parseGenerationRecord; exports.parseProvenance = parseProvenance; exports.pinnedTemplatesToTemplates = pinnedTemplatesToTemplates; exports.planGenerationRequest = planGenerationRequest; exports.qualityRank = qualityRank; exports.recreateRequest = recreateRequest; exports.referenceRoleLabel = referenceRoleLabel; exports.removeReference = removeReference; exports.replayProvenancePrompt = replayProvenancePrompt; exports.resolutionMegapixels = resolutionMegapixels; exports.resolutionRank = resolutionRank; exports.resolveAssetMentions = resolveAssetMentions; exports.seedCapability = seedCapability; exports.serializeGenerationRecord = serializeGenerationRecord; exports.serializeProvenance = serializeProvenance; exports.setMentionRoleInText = _chunkBVP3TSLHcjs.setMentionRoleInText; exports.setRequestValue = setRequestValue; exports.snapToOption = snapToOption; exports.stableStringify = stableStringify; exports.summarizeGenerationRecord = summarizeGenerationRecord; exports.supportedModes = supportedModes; exports.supportedReferenceRoles = supportedReferenceRoles; exports.textFieldCapability = textFieldCapability; exports.toAssetResolver = toAssetResolver; exports.validateAssetMentions = validateAssetMentions; exports.validateJsonSchema = _chunkRIWPYSKUcjs.validateJsonSchema; exports.variationRequest = variationRequest;
1662
+ exports.DRIFT_TYPE_LABELS = DRIFT_TYPE_LABELS; exports.GENERATION_RECORD_FORMAT = GENERATION_RECORD_FORMAT; exports.GENERATION_RECORD_VERSION = GENERATION_RECORD_VERSION; exports.GENERATION_REQUEST_FIELDS = _chunkECCXGELCcjs.GENERATION_REQUEST_FIELDS; exports.MAX_PENDING_PERCENT = MAX_PENDING_PERCENT; exports.PROVENANCE_FORMAT = _chunkQ6OUXEK3cjs.PROVENANCE_FORMAT; exports.PROVENANCE_VERSION = _chunkQ6OUXEK3cjs.PROVENANCE_VERSION; exports.ProvenanceParseError = _chunkQ6OUXEK3cjs.ProvenanceParseError; exports.QUALITY_LADDER = _chunkECCXGELCcjs.QUALITY_LADDER; exports.REFERENCE_ROLES = _chunkECCXGELCcjs.REFERENCE_ROLES; exports.REFERENCE_ROLE_ALIASES = _chunkECCXGELCcjs.REFERENCE_ROLE_ALIASES; exports.REFERENCE_ROLE_LABELS = _chunkECCXGELCcjs.REFERENCE_ROLE_LABELS; exports.REFERENCE_ROLE_NAME_REGEX = _chunkECCXGELCcjs.REFERENCE_ROLE_NAME_REGEX; exports.addReference = addReference; exports.aspectRatioRank = _chunkECCXGELCcjs.aspectRatioRank; exports.blockingDrift = blockingDrift; exports.capabilitiesToJsonSchema = capabilitiesToJsonSchema; exports.completeGenerationRecord = completeGenerationRecord; exports.createBatchResolver = createBatchResolver; exports.createGenerationHistoryToolProvider = createGenerationHistoryToolProvider; exports.createGenerationRecord = createGenerationRecord; exports.createGenerationRecordId = createGenerationRecordId; exports.createGenerationRecordStore = createGenerationRecordStore; exports.createGenerationToolProvider = createGenerationToolProvider; exports.createProvenance = _chunkQ6OUXEK3cjs.createProvenance; exports.defaultAssetRoleOptions = defaultAssetRoleOptions; exports.describeAssetMentions = describeAssetMentions; exports.estimateJobProgress = estimateJobProgress; exports.expectedDurationFor = expectedDurationFor; exports.findTextMentions = _chunkBVP3TSLHcjs.findTextMentions; exports.formatMentionText = _chunkBVP3TSLHcjs.formatMentionText; exports.formatRemaining = formatRemaining; exports.getAssetRoleOptions = getAssetRoleOptions; exports.getGenerationControls = getGenerationControls; exports.getReferenceSlots = getReferenceSlots; exports.getRequestValue = getRequestValue; exports.hashCapabilities = _chunkECCXGELCcjs.hashCapabilities; exports.hashText = _chunkECCXGELCcjs.hashText; exports.hashValue = _chunkECCXGELCcjs.hashValue; exports.isGenerationRecord = isGenerationRecord; exports.isReferenceRoleName = _chunkECCXGELCcjs.isReferenceRoleName; exports.matchesRecordFilter = matchesRecordFilter; exports.mediaTypeMatches = _chunkECCXGELCcjs.mediaTypeMatches; exports.mergeCapabilities = _chunkECCXGELCcjs.mergeCapabilities; exports.normalizeReferenceRole = _chunkECCXGELCcjs.normalizeReferenceRole; exports.parseControlValue = parseControlValue; exports.parseGenerationRecord = parseGenerationRecord; exports.parseProvenance = _chunkQ6OUXEK3cjs.parseProvenance; exports.pinnedTemplatesToTemplates = _chunkQ6OUXEK3cjs.pinnedTemplatesToTemplates; exports.planGenerationRequest = _chunkECCXGELCcjs.planGenerationRequest; exports.qualityRank = _chunkECCXGELCcjs.qualityRank; exports.recreateRequest = recreateRequest; exports.referenceRoleLabel = _chunkECCXGELCcjs.referenceRoleLabel; exports.removeReference = removeReference; exports.replayProvenancePrompt = _chunkQ6OUXEK3cjs.replayProvenancePrompt; exports.resolutionMegapixels = _chunkECCXGELCcjs.resolutionMegapixels; exports.resolutionRank = _chunkECCXGELCcjs.resolutionRank; exports.resolveAssetMentions = resolveAssetMentions; exports.seedCapability = _chunkECCXGELCcjs.seedCapability; exports.serializeGenerationRecord = serializeGenerationRecord; exports.serializeProvenance = _chunkQ6OUXEK3cjs.serializeProvenance; exports.setMentionRoleInText = _chunkBVP3TSLHcjs.setMentionRoleInText; exports.setRequestValue = setRequestValue; exports.snapToOption = _chunkECCXGELCcjs.snapToOption; exports.stableStringify = _chunkECCXGELCcjs.stableStringify; exports.summarizeGenerationRecord = summarizeGenerationRecord; exports.supportedModes = _chunkECCXGELCcjs.supportedModes; exports.supportedReferenceRoles = _chunkECCXGELCcjs.supportedReferenceRoles; exports.textFieldCapability = _chunkECCXGELCcjs.textFieldCapability; exports.toAssetResolver = toAssetResolver; exports.validateAssetMentions = validateAssetMentions; exports.validateJsonSchema = _chunkRIWPYSKUcjs.validateJsonSchema; exports.variationRequest = variationRequest;
2458
1663
  //# sourceMappingURL=index.cjs.map