@serene-pub/sdk 0.6.0-pr-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +368 -0
  4. package/dist/actions.d.ts +572 -0
  5. package/dist/actions.js +829 -0
  6. package/dist/annexFields.d.ts +234 -0
  7. package/dist/annexFields.js +413 -0
  8. package/dist/announce.d.ts +464 -0
  9. package/dist/announce.js +426 -0
  10. package/dist/attributes.d.ts +670 -0
  11. package/dist/attributes.js +904 -0
  12. package/dist/bands.d.ts +125 -0
  13. package/dist/bands.js +256 -0
  14. package/dist/builder.d.ts +683 -0
  15. package/dist/builder.js +677 -0
  16. package/dist/candidates.d.ts +109 -0
  17. package/dist/candidates.js +118 -0
  18. package/dist/capabilities.d.ts +744 -0
  19. package/dist/capabilities.js +679 -0
  20. package/dist/channels.d.ts +106 -0
  21. package/dist/channels.js +129 -0
  22. package/dist/clauses.d.ts +40 -0
  23. package/dist/clauses.js +43 -0
  24. package/dist/component.d.ts +33 -0
  25. package/dist/component.js +27 -0
  26. package/dist/componentBuild.d.ts +48 -0
  27. package/dist/componentBuild.js +84 -0
  28. package/dist/componentClient.d.ts +100 -0
  29. package/dist/componentClient.js +13 -0
  30. package/dist/componentImports.d.ts +51 -0
  31. package/dist/componentImports.js +106 -0
  32. package/dist/componentModule.d.ts +8 -0
  33. package/dist/componentModule.js +270 -0
  34. package/dist/componentWire.d.ts +130 -0
  35. package/dist/componentWire.js +280 -0
  36. package/dist/config.d.ts +295 -0
  37. package/dist/config.js +231 -0
  38. package/dist/connections.d.ts +89 -0
  39. package/dist/connections.js +131 -0
  40. package/dist/declarations.d.ts +290 -0
  41. package/dist/declarations.js +794 -0
  42. package/dist/descriptors.d.ts +1774 -0
  43. package/dist/descriptors.js +1329 -0
  44. package/dist/dev.d.ts +136 -0
  45. package/dist/dev.js +161 -0
  46. package/dist/document.d.ts +202 -0
  47. package/dist/document.js +312 -0
  48. package/dist/engines.d.ts +117 -0
  49. package/dist/engines.js +203 -0
  50. package/dist/eventMapLaws.d.ts +63 -0
  51. package/dist/eventMapLaws.js +128 -0
  52. package/dist/events.d.ts +554 -0
  53. package/dist/events.js +633 -0
  54. package/dist/executor.d.ts +771 -0
  55. package/dist/executor.js +1829 -0
  56. package/dist/extension.d.ts +448 -0
  57. package/dist/extension.js +315 -0
  58. package/dist/facets.d.ts +53 -0
  59. package/dist/facets.js +60 -0
  60. package/dist/foldedSections.d.ts +74 -0
  61. package/dist/foldedSections.js +161 -0
  62. package/dist/genres.d.ts +507 -0
  63. package/dist/genres.js +633 -0
  64. package/dist/guardedConnection.d.ts +138 -0
  65. package/dist/guardedConnection.js +341 -0
  66. package/dist/handlebarsReach.d.ts +122 -0
  67. package/dist/handlebarsReach.js +222 -0
  68. package/dist/hash.d.ts +146 -0
  69. package/dist/hash.js +166 -0
  70. package/dist/hookGrants.d.ts +47 -0
  71. package/dist/hookGrants.js +68 -0
  72. package/dist/hooks.d.ts +290 -0
  73. package/dist/hooks.js +113 -0
  74. package/dist/hostElements.d.ts +447 -0
  75. package/dist/hostElements.js +702 -0
  76. package/dist/i18n.d.ts +94 -0
  77. package/dist/i18n.js +123 -0
  78. package/dist/identity.d.ts +93 -0
  79. package/dist/identity.js +135 -0
  80. package/dist/index.d.ts +85 -0
  81. package/dist/index.js +176 -0
  82. package/dist/layout.d.ts +194 -0
  83. package/dist/layout.js +40 -0
  84. package/dist/media.d.ts +202 -0
  85. package/dist/media.js +70 -0
  86. package/dist/messageBlocks.d.ts +487 -0
  87. package/dist/messageBlocks.js +683 -0
  88. package/dist/migration.d.ts +128 -0
  89. package/dist/migration.js +261 -0
  90. package/dist/names.d.ts +78 -0
  91. package/dist/names.js +136 -0
  92. package/dist/nodeInput.d.ts +399 -0
  93. package/dist/nodeInput.js +178 -0
  94. package/dist/participants.d.ts +291 -0
  95. package/dist/participants.js +252 -0
  96. package/dist/personGate.d.ts +62 -0
  97. package/dist/personGate.js +77 -0
  98. package/dist/pick.d.ts +84 -0
  99. package/dist/pick.js +103 -0
  100. package/dist/pluginHarness.d.ts +235 -0
  101. package/dist/pluginHarness.js +558 -0
  102. package/dist/pluginPermissions.d.ts +25 -0
  103. package/dist/pluginPermissions.js +97 -0
  104. package/dist/pluginRuleRef.d.ts +13 -0
  105. package/dist/pluginRuleRef.js +10 -0
  106. package/dist/predicates.d.ts +182 -0
  107. package/dist/predicates.js +249 -0
  108. package/dist/preview.d.ts +120 -0
  109. package/dist/preview.js +82 -0
  110. package/dist/promptBlocks.d.ts +130 -0
  111. package/dist/promptBlocks.js +197 -0
  112. package/dist/rankingDecisions.d.ts +60 -0
  113. package/dist/rankingDecisions.js +48 -0
  114. package/dist/receipt.d.ts +313 -0
  115. package/dist/receipt.js +60 -0
  116. package/dist/receiverRules.d.ts +24 -0
  117. package/dist/receiverRules.js +94 -0
  118. package/dist/refs.d.ts +117 -0
  119. package/dist/refs.js +137 -0
  120. package/dist/registry.d.ts +230 -0
  121. package/dist/registry.js +273 -0
  122. package/dist/review.d.ts +108 -0
  123. package/dist/review.js +97 -0
  124. package/dist/sampling.d.ts +152 -0
  125. package/dist/sampling.js +712 -0
  126. package/dist/scope.d.ts +65 -0
  127. package/dist/scope.js +128 -0
  128. package/dist/scripts.d.ts +243 -0
  129. package/dist/scripts.js +326 -0
  130. package/dist/sessionLayout.d.ts +339 -0
  131. package/dist/sessionLayout.js +503 -0
  132. package/dist/sessionSettings.d.ts +70 -0
  133. package/dist/sessionSettings.js +2 -0
  134. package/dist/settings.d.ts +501 -0
  135. package/dist/settings.js +604 -0
  136. package/dist/settingsSlot.d.ts +108 -0
  137. package/dist/settingsSlot.js +166 -0
  138. package/dist/shapes.d.ts +373 -0
  139. package/dist/shapes.js +408 -0
  140. package/dist/sheets.d.ts +165 -0
  141. package/dist/sheets.js +251 -0
  142. package/dist/statShapes.d.ts +96 -0
  143. package/dist/statShapes.js +112 -0
  144. package/dist/status.d.ts +103 -0
  145. package/dist/status.js +125 -0
  146. package/dist/storage.d.ts +145 -0
  147. package/dist/storage.js +33 -0
  148. package/dist/storyTime.d.ts +308 -0
  149. package/dist/storyTime.js +560 -0
  150. package/dist/surfaces.d.ts +501 -0
  151. package/dist/surfaces.js +292 -0
  152. package/dist/template.d.ts +312 -0
  153. package/dist/template.js +554 -0
  154. package/dist/templateCheck.d.ts +60 -0
  155. package/dist/templateCheck.js +516 -0
  156. package/dist/templateFit.d.ts +157 -0
  157. package/dist/templateFit.js +349 -0
  158. package/dist/templateIds.d.ts +138 -0
  159. package/dist/templateIds.js +144 -0
  160. package/dist/templateScopeAt.d.ts +131 -0
  161. package/dist/templateScopeAt.js +354 -0
  162. package/dist/testing.d.ts +177 -0
  163. package/dist/testing.js +383 -0
  164. package/dist/tokenizers.d.ts +113 -0
  165. package/dist/tokenizers.js +184 -0
  166. package/dist/turnLock.d.ts +96 -0
  167. package/dist/turnLock.js +79 -0
  168. package/dist/turnOrder.d.ts +143 -0
  169. package/dist/turnOrder.js +128 -0
  170. package/dist/validate.d.ts +74 -0
  171. package/dist/validate.js +1399 -0
  172. package/dist/values.d.ts +212 -0
  173. package/dist/values.js +390 -0
  174. package/dist/variables.d.ts +493 -0
  175. package/dist/variables.js +662 -0
  176. package/dist/verdicts.d.ts +275 -0
  177. package/dist/verdicts.js +348 -0
  178. package/dist/widgetDecls.d.ts +88 -0
  179. package/dist/widgetDecls.js +119 -0
  180. package/dist/widgets.d.ts +1527 -0
  181. package/dist/widgets.js +208 -0
  182. package/dist/wire.d.ts +126 -0
  183. package/dist/wire.js +140 -0
  184. package/dist/worldinfo.d.ts +150 -0
  185. package/dist/worldinfo.js +212 -0
  186. package/host-elements.d.ts +914 -0
  187. package/package.json +67 -0
@@ -0,0 +1,712 @@
1
+ /**
2
+ * Sampling parameters, declared per shape.
3
+ *
4
+ * A sampling config used to be thirty typed columns and thirty `<key>Enabled`
5
+ * booleans on one table — a layout that could only ever describe *text*
6
+ * generation, because the columns named text samplers. Adding image generation
7
+ * would have meant either a second table with a second seeding path and a second
8
+ * picker, or image columns sitting empty on every text row. Both make the modality
9
+ * a branch in every consumer.
10
+ *
11
+ * So a row is now `{ shape, values, enabled }`: an id saying which vocabulary it
12
+ * speaks, an object of values, and the list of keys that are actually in play.
13
+ * The vocabulary itself lives here, in the SDK, next to the shapes it is keyed by
14
+ * — the same place a provider declares `shape: S.imageGen`, so a sampling config
15
+ * and the provider that consumes it cannot drift into disagreeing about what a
16
+ * parameter is called.
17
+ *
18
+ * ## Resolution
19
+ *
20
+ * `resolveSamplingValues` is the one path from a stored row to what an adapter
21
+ * receives:
22
+ *
23
+ * values → keep the keys named in `enabled` → keep the keys the shape declares
24
+ * → fill enabled-but-unset from the schema default → hand over
25
+ *
26
+ * Two kinds of key deliberately survive in the row without ever being sent: keys
27
+ * that are switched off, and keys the shape does not declare. Neither is an error
28
+ * and neither is discarded — turning a sampler off and back on must not lose the
29
+ * value you had, and a row written by a newer build (or carrying a UI-only flag
30
+ * like `contextTokensUnlocked`) must round-trip through an older one intact. The
31
+ * filter is on the way *out*, not on the way in.
32
+ *
33
+ * ## What is not here
34
+ *
35
+ * Backend-specific knobs. Fooocus' `performance_selection`, a ComfyUI workflow, an
36
+ * A1111 `override_settings` — those belong to the *connection*, declared by its
37
+ * adapter's `profileSchema`. A sampling config is the modality's shared vocabulary;
38
+ * if a key here meant something to only one backend, every other backend's picker
39
+ * would be showing a control that does nothing. Adapters translate what they can
40
+ * and report the rest as ignored.
41
+ */
42
+ import { S } from './shapes.js';
43
+ // ── The vocabularies ────────────────────────────────────────────────────────
44
+ /**
45
+ * Text generation — the union of what the shipped adapters can map.
46
+ *
47
+ * Every key here appears in at least one adapter's key map. A row may enable a
48
+ * key the *chosen* connection cannot honour (enabling DRY and then pointing the
49
+ * config at Anthropic); that is reported by the adapter as ignored, not blocked
50
+ * here, because the config outlives the connection it happens to be paired with.
51
+ * @internal
52
+ */
53
+ export const textSamplingSchema = {
54
+ // ── Core ────────────────────────────────────────────────────────────
55
+ temperature: {
56
+ type: 'number',
57
+ label: 'Temperature',
58
+ description: 'Controls randomness (0 = deterministic, higher = more random).',
59
+ min: 0,
60
+ max: 2,
61
+ default: 0.7,
62
+ quick: true,
63
+ group: 'Core',
64
+ },
65
+ topP: {
66
+ type: 'number',
67
+ label: 'Top P',
68
+ description: 'Nucleus sampling — keep tokens whose cumulative probability exceeds this.',
69
+ min: 0,
70
+ max: 1,
71
+ default: 0.92,
72
+ quick: true,
73
+ group: 'Core',
74
+ },
75
+ topK: {
76
+ type: 'integer',
77
+ label: 'Top K',
78
+ description: 'Limit selection to the K most likely tokens.',
79
+ min: 0,
80
+ max: 200,
81
+ default: 80,
82
+ quick: true,
83
+ group: 'Core',
84
+ },
85
+ minP: {
86
+ type: 'number',
87
+ label: 'Min P',
88
+ description: 'Minimum probability threshold for token selection.',
89
+ min: 0,
90
+ max: 1,
91
+ default: 0.05,
92
+ group: 'Core',
93
+ },
94
+ typicalP: {
95
+ type: 'number',
96
+ label: 'Typical P',
97
+ description: 'Typical sampling (1.0 = disabled).',
98
+ min: 0,
99
+ max: 1,
100
+ default: 1,
101
+ group: 'Core',
102
+ },
103
+ seed: {
104
+ type: 'integer',
105
+ label: 'Seed',
106
+ description: 'Reproducible generation. -1 draws a fresh one each time.',
107
+ min: -1,
108
+ default: -1,
109
+ group: 'Core',
110
+ },
111
+ // ── Repetition ──────────────────────────────────────────────────────
112
+ repetitionPenalty: {
113
+ type: 'number',
114
+ label: 'Repetition Penalty',
115
+ description: 'Penalty applied to repeated tokens (1.0 = none).',
116
+ min: 0.1,
117
+ max: 2,
118
+ default: 1.15,
119
+ quick: true,
120
+ group: 'Repetition',
121
+ },
122
+ repeatLastN: {
123
+ type: 'integer',
124
+ label: 'Repeat Last N',
125
+ description: 'How far back the repetition penalty looks.',
126
+ min: 0,
127
+ max: 2048,
128
+ default: 64,
129
+ group: 'Repetition',
130
+ },
131
+ frequencyPenalty: {
132
+ type: 'number',
133
+ label: 'Frequency Penalty',
134
+ description: 'Penalty scaled by how often a token has already appeared.',
135
+ min: -2,
136
+ max: 2,
137
+ default: 0.2,
138
+ quick: true,
139
+ group: 'Repetition',
140
+ },
141
+ presencePenalty: {
142
+ type: 'number',
143
+ label: 'Presence Penalty',
144
+ description: 'Penalty for a token appearing at all — encourages new topics.',
145
+ min: -2,
146
+ max: 2,
147
+ default: 0.6,
148
+ quick: true,
149
+ group: 'Repetition',
150
+ },
151
+ penalizeNewline: {
152
+ type: 'boolean',
153
+ label: 'Penalize Newline',
154
+ description: 'Apply the repetition penalty to newline tokens too.',
155
+ default: false,
156
+ group: 'Repetition',
157
+ },
158
+ // ── Mirostat ────────────────────────────────────────────────────────
159
+ mirostat: {
160
+ type: 'integer',
161
+ label: 'Mirostat',
162
+ description: 'Mirostat sampling: 0 disabled, 1 or 2 selects the version.',
163
+ min: 0,
164
+ max: 2,
165
+ default: 0,
166
+ group: 'Mirostat',
167
+ },
168
+ mirostatTau: {
169
+ type: 'number',
170
+ label: 'Mirostat Tau',
171
+ description: 'Target perplexity for Mirostat.',
172
+ min: 0,
173
+ max: 10,
174
+ default: 5,
175
+ group: 'Mirostat',
176
+ },
177
+ mirostatEta: {
178
+ type: 'number',
179
+ label: 'Mirostat Eta',
180
+ description: 'Learning rate for Mirostat.',
181
+ min: 0,
182
+ max: 1,
183
+ default: 0.1,
184
+ group: 'Mirostat',
185
+ },
186
+ // ── XTC ─────────────────────────────────────────────────────────────
187
+ xtcProbability: {
188
+ type: 'number',
189
+ label: 'XTC Probability',
190
+ description: 'Chance of applying Exclude Top Choices on a given token.',
191
+ min: 0,
192
+ max: 1,
193
+ default: 0,
194
+ group: 'XTC',
195
+ },
196
+ xtcThreshold: {
197
+ type: 'number',
198
+ label: 'XTC Threshold',
199
+ description: 'Probability floor a token must clear to be an XTC candidate.',
200
+ min: 0,
201
+ max: 0.5,
202
+ default: 0.1,
203
+ group: 'XTC',
204
+ },
205
+ // ── DRY ─────────────────────────────────────────────────────────────
206
+ dryMultiplier: {
207
+ type: 'number',
208
+ label: 'DRY Multiplier',
209
+ description: "Penalty multiplier for Don't Repeat Yourself sampling (0 = off).",
210
+ min: 0,
211
+ max: 5,
212
+ default: 0,
213
+ group: 'DRY',
214
+ },
215
+ dryBase: {
216
+ type: 'number',
217
+ label: 'DRY Base',
218
+ description: 'Exponential base for the DRY penalty.',
219
+ min: 1,
220
+ max: 10,
221
+ default: 1.75,
222
+ group: 'DRY',
223
+ },
224
+ dryAllowedLength: {
225
+ type: 'integer',
226
+ label: 'DRY Allowed Length',
227
+ description: 'Repetition this long or shorter goes unpenalised.',
228
+ min: 1,
229
+ max: 20,
230
+ default: 2,
231
+ group: 'DRY',
232
+ },
233
+ dryPenaltyLastN: {
234
+ type: 'integer',
235
+ label: 'DRY Penalty Last N',
236
+ description: 'How far back DRY looks. -1 is the whole context.',
237
+ min: -1,
238
+ max: 2048,
239
+ default: -1,
240
+ group: 'DRY',
241
+ },
242
+ drySequenceBreakers: {
243
+ type: 'string[]',
244
+ label: 'DRY Sequence Breakers',
245
+ description: 'Tokens that reset DRY’s idea of a repetition.',
246
+ default: ['\\n', ':', '"', '*'],
247
+ group: 'DRY',
248
+ },
249
+ // ── Dynamic temperature ─────────────────────────────────────────────
250
+ dynatempRange: {
251
+ type: 'number',
252
+ label: 'Dynamic Temperature Range',
253
+ description: 'Spread around the base temperature (0 = static).',
254
+ min: 0,
255
+ max: 5,
256
+ default: 0,
257
+ group: 'Dynamic temperature',
258
+ },
259
+ dynatempExponent: {
260
+ type: 'number',
261
+ label: 'Dynamic Temperature Exponent',
262
+ description: 'How sharply temperature moves within its range.',
263
+ min: 0.1,
264
+ max: 5,
265
+ default: 1,
266
+ group: 'Dynamic temperature',
267
+ },
268
+ tfsZ: {
269
+ type: 'number',
270
+ label: 'Tail Free Sampling',
271
+ description: 'Trims the low-probability tail (1.0 = disabled).',
272
+ min: 0,
273
+ max: 1,
274
+ default: 1,
275
+ group: 'Dynamic temperature',
276
+ },
277
+ // ── KoboldCPP-only ──────────────────────────────────────────────────
278
+ // These four are in koboldCppSamplingKeyMap and always have been, but had no
279
+ // column — so no row could ever set them and the mapping was unreachable.
280
+ // A declared vocabulary costs nothing to extend: off by default, translated
281
+ // by the one adapter that knows them, reported ignored by the rest.
282
+ topA: {
283
+ type: 'number',
284
+ label: 'Top A',
285
+ description: 'Top-A sampling (KoboldCPP).',
286
+ min: 0,
287
+ max: 1,
288
+ default: 0,
289
+ group: 'KoboldCPP',
290
+ },
291
+ nsigma: {
292
+ type: 'number',
293
+ label: 'N-Sigma',
294
+ description: 'Top N-Sigma. Above 0 enables it (KoboldCPP).',
295
+ min: 0,
296
+ max: 10,
297
+ default: 0,
298
+ group: 'KoboldCPP',
299
+ },
300
+ smoothingFactor: {
301
+ type: 'number',
302
+ label: 'Smoothing Factor',
303
+ description: 'Changes how temperature behaves. Above 0 uses smoothing (KoboldCPP).',
304
+ min: 0,
305
+ max: 10,
306
+ default: 0,
307
+ group: 'KoboldCPP',
308
+ },
309
+ bannedTokens: {
310
+ type: 'string[]',
311
+ label: 'Banned Tokens',
312
+ description: 'Words or phrases that may never be generated (KoboldCPP).',
313
+ default: [],
314
+ group: 'KoboldCPP',
315
+ },
316
+ // ── Reasoning ───────────────────────────────────────────────────────
317
+ // How hard the model thinks is a SAMPLING parameter, chosen per step
318
+ // through the sampling slot (ruling 2026-09-12) — never a flag on the
319
+ // connection. A connection is shared, so a flag there is one answer for
320
+ // every step that shares it, and a planner nobody reads cannot then differ
321
+ // from the prose the reader is waiting for.
322
+ //
323
+ // The four members below are the whole enum: there is no `default`/`auto`
324
+ // beside them, because a field that is switched OFF already sends nothing
325
+ // at all, which is how a config says "leave it to the service". A fifth
326
+ // member meaning that would be a second spelling of a state the switchboard
327
+ // has.
328
+ reasoning: {
329
+ type: 'enum',
330
+ label: 'Reasoning',
331
+ description: 'How much the model reasons before answering. Off sends none of it; the response token limit still counts reasoning on most services.',
332
+ of: ['off', 'low', 'medium', 'high'],
333
+ members: [
334
+ { key: 'off', label: 'Off' },
335
+ { key: 'low', label: 'Low' },
336
+ { key: 'medium', label: 'Medium' },
337
+ { key: 'high', label: 'High' },
338
+ ],
339
+ default: 'off',
340
+ group: 'Reasoning',
341
+ },
342
+ reasoningBudget: {
343
+ type: 'integer',
344
+ label: 'Reasoning Budget',
345
+ description: 'Reasoning tokens allowed, for services that take a number. Used with reasoning set to low, medium or high.',
346
+ min: 0,
347
+ // The HARD bound, in the sense the two budgets below use the word: the
348
+ // largest value that is valid at all, which is what
349
+ // `normalizeSamplingRow` clamps to. It sits just past the widest level
350
+ // the adapters' own table names (high = 32000), so a number chosen by
351
+ // hand can always exceed a level and never exceed a response.
352
+ max: 32768,
353
+ default: 8000,
354
+ group: 'Reasoning',
355
+ },
356
+ // ── Budgets and stops ───────────────────────────────────────────────
357
+ // `max` on these two is the HARD bound — the largest value that is valid at
358
+ // all, which is what `normalizeSamplingRow` clamps to. It is deliberately far
359
+ // above the range a form should offer by default: the sidebar shows a 4096 /
360
+ // 32768 slider and an "unlock max" toggle that opens it up to these. A schema
361
+ // max set to the comfortable range instead would clamp the unlocked value
362
+ // straight back down on save, which is the bug that shape invites.
363
+ responseTokens: {
364
+ type: 'integer',
365
+ label: 'Response Tokens',
366
+ description: 'Ceiling on how much is generated in one reply.',
367
+ min: 1,
368
+ max: 65536,
369
+ default: 512,
370
+ quick: true,
371
+ group: 'Budget',
372
+ },
373
+ contextTokens: {
374
+ type: 'integer',
375
+ label: 'Context Tokens',
376
+ description: 'How much conversation the model is given to read.',
377
+ min: 512,
378
+ max: 524288,
379
+ default: 4096,
380
+ quick: true,
381
+ group: 'Budget',
382
+ },
383
+ stop: {
384
+ type: 'string[]',
385
+ label: 'Stop Sequences',
386
+ description: 'Generation ends when one of these appears.',
387
+ default: [],
388
+ group: 'Budget',
389
+ },
390
+ logitBias: {
391
+ type: 'text',
392
+ format: 'json',
393
+ label: 'Logit Bias',
394
+ description: 'Token id → bias, as JSON.',
395
+ default: {},
396
+ group: 'Budget',
397
+ },
398
+ };
399
+ /**
400
+ * Image generation — the parameters every image backend either honours or can
401
+ * say it ignored.
402
+ *
403
+ * Everything is optional and nothing is required to have a value: an unset key
404
+ * means "whatever the backend does by default", which is the only honest answer
405
+ * when the same config is pointed at Fooocus, ComfyUI and a hosted API in turn.
406
+ * `sampler` and `scheduler` are free strings rather than enums for the same
407
+ * reason — the valid set is a property of the connection (its checkpoint, its
408
+ * build), not of the vocabulary, so a picker fills them from the adapter's
409
+ * reported capabilities.
410
+ *
411
+ * ⚠ These are the knobs of LOCAL DIFFUSION, and that is a real boundary rather
412
+ * than an accident of which adapters happened to ship first. A hosted image
413
+ * service shares almost none of them: OpenAI's gpt-image-1 takes `size` (an ENUM
414
+ * of exactly `1024x1024`, `1024x1536`, `1536x1024`), `quality`, `background`,
415
+ * `output_format`, `output_compression` and `n` — no steps, no CFG, no sampler,
416
+ * no scheduler, no seed. `batch` maps to `n`, a free width/height has to SNAP to
417
+ * one of the three allowed sizes, and the rest is inexpressible.
418
+ *
419
+ * That does not make this schema wrong; it makes it the shared vocabulary of the
420
+ * backends that HAVE these knobs — and the rest of the answer is already in
421
+ * place, so the fix is never "add hosted keys here". What one backend alone
422
+ * offers belongs to its CONNECTION, declared by the adapter's `profileSchema`
423
+ * (`quality` and `background` are profile fields); what a backend cannot honour
424
+ * is REPORTED through `applied`/`ignored`, not dropped. A hosted-only key added
425
+ * here would put a control that does nothing in front of every local user, which
426
+ * is exactly what the "What is not here" note above forbids — and by the same
427
+ * argument there is no such thing as a hosted sampling *preset*: a hosted
428
+ * service has no sampling knobs to preset, it has a profile.
429
+ * @internal
430
+ */
431
+ export const imageSamplingSchema = {
432
+ steps: {
433
+ type: 'integer',
434
+ label: 'Steps',
435
+ description: 'Denoising steps. More is slower and usually sharper, to a point.',
436
+ min: 1,
437
+ max: 150,
438
+ default: 25,
439
+ quick: true,
440
+ group: 'Core',
441
+ },
442
+ cfg: {
443
+ type: 'number',
444
+ label: 'CFG Scale',
445
+ description: 'How strictly the image follows the prompt.',
446
+ min: 0,
447
+ max: 30,
448
+ default: 5,
449
+ quick: true,
450
+ group: 'Core',
451
+ },
452
+ width: {
453
+ type: 'integer',
454
+ label: 'Width',
455
+ description: 'Requested width in pixels. Backends with fixed sizes snap to the nearest.',
456
+ min: 64,
457
+ max: 4096,
458
+ default: 1024,
459
+ quick: true,
460
+ group: 'Size',
461
+ },
462
+ height: {
463
+ type: 'integer',
464
+ label: 'Height',
465
+ description: 'Requested height in pixels.',
466
+ min: 64,
467
+ max: 4096,
468
+ default: 1024,
469
+ quick: true,
470
+ group: 'Size',
471
+ },
472
+ batch: {
473
+ type: 'integer',
474
+ label: 'Batch',
475
+ description: 'How many images per run.',
476
+ min: 1,
477
+ max: 8,
478
+ default: 1,
479
+ quick: true,
480
+ group: 'Core',
481
+ },
482
+ seed: {
483
+ type: 'integer',
484
+ label: 'Seed',
485
+ description: 'Reproducible generation. -1 draws a fresh one each time.',
486
+ min: -1,
487
+ default: -1,
488
+ quick: true,
489
+ group: 'Core',
490
+ },
491
+ sampler: {
492
+ type: 'string',
493
+ label: 'Sampler',
494
+ description: 'Sampling algorithm. Which names are valid depends on the backend.',
495
+ group: 'Advanced',
496
+ },
497
+ scheduler: {
498
+ type: 'string',
499
+ label: 'Scheduler',
500
+ description: 'Noise schedule. Which names are valid depends on the backend.',
501
+ group: 'Advanced',
502
+ },
503
+ clipSkip: {
504
+ type: 'integer',
505
+ label: 'CLIP Skip',
506
+ description: 'How many final CLIP layers to skip.',
507
+ min: 1,
508
+ max: 12,
509
+ default: 2,
510
+ group: 'Advanced',
511
+ },
512
+ denoise: {
513
+ type: 'number',
514
+ label: 'Denoise',
515
+ description: 'How much of the source image to overwrite. Only meaningful with an input image.',
516
+ min: 0,
517
+ max: 1,
518
+ default: 1,
519
+ group: 'Advanced',
520
+ },
521
+ };
522
+ /**
523
+ * Speech synthesis.
524
+ *
525
+ * Present because `core:oracle/speak@1` declares `sampling: { shape: S.tts }`,
526
+ * and a sampling slot whose shape has no vocabulary resolves to nothing at all —
527
+ * silently, since an unknown shape is an empty schema by design. A declared slot
528
+ * with no declared vocabulary is the one combination where that fallback is
529
+ * indistinguishable from a bug.
530
+ *
531
+ * `voice` is a free string for the same reason `sampler` is on images: the valid
532
+ * names belong to the connection, not to the vocabulary.
533
+ * @internal
534
+ */
535
+ export const ttsSamplingSchema = {
536
+ voice: {
537
+ type: 'string',
538
+ label: 'Voice',
539
+ description: 'Which voice to speak in. The available names come from the connection.',
540
+ quick: true,
541
+ group: 'Voice',
542
+ },
543
+ speed: {
544
+ type: 'number',
545
+ label: 'Speed',
546
+ description: 'Playback rate. 1 is the voice’s natural pace.',
547
+ min: 0.25,
548
+ max: 4,
549
+ default: 1,
550
+ quick: true,
551
+ group: 'Voice',
552
+ },
553
+ pitch: {
554
+ type: 'number',
555
+ label: 'Pitch',
556
+ description: 'Shift up or down from the voice’s natural pitch.',
557
+ min: -20,
558
+ max: 20,
559
+ default: 0,
560
+ group: 'Voice',
561
+ },
562
+ volume: {
563
+ type: 'number',
564
+ label: 'Volume',
565
+ description: 'Gain applied to the rendered audio.',
566
+ min: 0,
567
+ max: 2,
568
+ default: 1,
569
+ group: 'Voice',
570
+ },
571
+ };
572
+ /** Every vocabulary, keyed by the shape whose connections speak it. @internal */
573
+ export const SAMPLING_SCHEMAS = {
574
+ [S.textGen]: textSamplingSchema,
575
+ [S.imageGen]: imageSamplingSchema,
576
+ [S.tts]: ttsSamplingSchema,
577
+ };
578
+ /** The shape a row without one is assumed to speak. @experimental */
579
+ export const DEFAULT_SAMPLING_SHAPE = S.textGen;
580
+ /**
581
+ * The vocabulary for a shape.
582
+ *
583
+ * An unknown shape resolves to an empty schema rather than throwing: a row
584
+ * written by a plugin whose provider is not installed should read as "no
585
+ * parameters I can offer", not as a crash in whatever happened to load it.
586
+ * @internal
587
+ */
588
+ export function samplingSchemaFor(shape) {
589
+ return SAMPLING_SCHEMAS[shape ?? DEFAULT_SAMPLING_SHAPE] ?? {};
590
+ }
591
+ /**
592
+ * Stored row → what the adapter is handed.
593
+ *
594
+ * The whole filter lives here so that no consumer has to remember the order, and
595
+ * so "is this key on?" has exactly one answer in the codebase. Callers get a
596
+ * plain object: spreading a runtime override onto it is expected and is how
597
+ * per-call budgets are applied.
598
+ * @internal
599
+ */
600
+ export function resolveSamplingValues(row, schema = samplingSchemaFor(row.shape)) {
601
+ const values = row.values ?? {};
602
+ const enabled = row.enabled ?? [];
603
+ const out = {};
604
+ for (const key of enabled) {
605
+ const decl = schema[key];
606
+ // Enabled but not in this shape's vocabulary: kept in the row, not sent.
607
+ // A newer build's key travelling through an older one lands here.
608
+ if (!decl)
609
+ continue;
610
+ const stored = values[key];
611
+ const value = stored === undefined || stored === null ? decl.default : stored;
612
+ // A key with neither a stored value nor a default has nothing to say.
613
+ if (value === undefined)
614
+ continue;
615
+ out[key] = value;
616
+ }
617
+ return out;
618
+ }
619
+ /**
620
+ * Bring a row into a consistent state, without discarding anything.
621
+ *
622
+ * Called on the write path, so that what the form submits and what a seed
623
+ * declares end up identical in the table. It coerces the types the schema
624
+ * declares (a number field arriving as `"0.7"` from a form input is the common
625
+ * case) and drops duplicate/ill-typed entries from `enabled`.
626
+ *
627
+ * It deliberately does NOT drop unknown keys from `values`: `enabled` is the
628
+ * switchboard, `values` is the memory. Off-schema keys — a UI-only flag such as
629
+ * `contextTokensUnlocked`, or a parameter belonging to a shape this build does
630
+ * not know — stay exactly where they were, and `resolveSamplingValues` is what
631
+ * keeps them off the wire.
632
+ * @internal
633
+ */
634
+ export function normalizeSamplingRow(row, schema = samplingSchemaFor(row.shape)) {
635
+ const shape = row.shape ?? DEFAULT_SAMPLING_SHAPE;
636
+ const values = { ...(row.values ?? {}) };
637
+ for (const [key, decl] of Object.entries(schema)) {
638
+ if (!(key in values))
639
+ continue;
640
+ const coerced = coerce(values[key], decl);
641
+ if (coerced === undefined)
642
+ delete values[key];
643
+ else
644
+ values[key] = coerced;
645
+ }
646
+ const enabled = [...new Set(row.enabled ?? [])].filter((k) => typeof k === 'string' && k in schema);
647
+ return { shape, values, enabled };
648
+ }
649
+ /**
650
+ * A stored value in the type its declaration promises.
651
+ *
652
+ * `undefined` means "this cannot be that type" and the caller removes the key —
653
+ * better an unset parameter falling back to its default than `NaN` reaching a
654
+ * backend as a temperature.
655
+ */
656
+ function coerce(value, decl) {
657
+ if (value === null || value === undefined)
658
+ return undefined;
659
+ switch (decl.type) {
660
+ case 'number':
661
+ case 'integer': {
662
+ const n = typeof value === 'number' ? value : Number(value);
663
+ if (!Number.isFinite(n))
664
+ return undefined;
665
+ const r = decl.type === 'integer' ? Math.round(n) : n;
666
+ return clamp(r, decl.min, decl.max);
667
+ }
668
+ case 'boolean':
669
+ if (typeof value === 'boolean')
670
+ return value;
671
+ if (value === 'true')
672
+ return true;
673
+ if (value === 'false')
674
+ return false;
675
+ return undefined;
676
+ case 'string[]':
677
+ if (Array.isArray(value))
678
+ return value.map(String);
679
+ // A textarea that collected one line per entry.
680
+ if (typeof value === 'string')
681
+ return value
682
+ .split('\n')
683
+ .map((s) => s.trim())
684
+ .filter(Boolean);
685
+ return undefined;
686
+ case 'string':
687
+ case 'enum':
688
+ return typeof value === 'string' ? value : String(value);
689
+ case 'text':
690
+ // `format: 'json'` fields hold parsed data; the renderer stringifies
691
+ // for display and parses on submit, so either side may arrive here.
692
+ if (decl.format === 'json' && typeof value === 'string') {
693
+ try {
694
+ return JSON.parse(value);
695
+ }
696
+ catch {
697
+ return undefined;
698
+ }
699
+ }
700
+ return value;
701
+ default:
702
+ return value;
703
+ }
704
+ }
705
+ const clamp = (n, min, max) => {
706
+ if (min !== undefined && n < min)
707
+ return min;
708
+ if (max !== undefined && n > max)
709
+ return max;
710
+ return n;
711
+ };
712
+ //# sourceMappingURL=sampling.js.map