@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
package/dist/config.js ADDED
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Configuration resolution (12 §2). Four layers, first hit wins, evaluated
3
+ * independently per path — which is what makes an admin's connection change reach a
4
+ * user who has customized their prompts (F20).
5
+ *
6
+ * ## The chain (R-10, ruled 2026-09-15; 09-B B8)
7
+ *
8
+ * **`session · config · defaults · author`.**
9
+ *
10
+ * - `session` — a session's own override of a value (the *chat override* of
11
+ * 12 §2's "pipeline → config → chat override").
12
+ * - `config` — the rows of the **selected config**: the config IS the
13
+ * instance's tuning. An administrator's edit lands in the config (ruled
14
+ * 2026-08-24), so there is no separate `instance` layer for it to be shadowed
15
+ * by, and no `user` layer — a preference that differs per user is a session's
16
+ * to hold.
17
+ * - `defaults` — values a host *projects* rather than values anyone decided:
18
+ * system settings, connection defaults, a legacy layer. Nothing interactive
19
+ * writes here (it appears in no write matrix row).
20
+ * - `author` — the definition's declared parameter defaults; the floor.
21
+ *
22
+ * `user` and `instance` stood in this list until 2026-09-16 and were pushed by
23
+ * nothing: `world.ts` never projected a row at either (plans/29a §3). Their
24
+ * semantics fold into `config` — the config an admin edits is the instance's
25
+ * configuration — which is the 2026-08-24 ruling stated as a constant.
26
+ *
27
+ * Resolved run-wide *before* execution, which is why referencing another node's
28
+ * config is not a data edge (F35).
29
+ *
30
+ * ## `config`, not `preset` (R1)
31
+ *
32
+ * Two other things are called a preset — a **session preset** (the bundle a
33
+ * session is born on) and an author's `.preset(…)` on a spec — and neither is
34
+ * this layer, so the scope takes the canon's word for what it holds: the
35
+ * **config**.
36
+ */
37
+ /** @internal */
38
+ export const SCOPE_ORDER = ['session', 'config', 'defaults', 'author'];
39
+ /**
40
+ * A row's scope kind. Anything that is not a `ScopeKind` is `undefined` — a
41
+ * row at a scope nobody resolves at, which resolution skips rather than
42
+ * guesses about.
43
+ * @experimental 🚧
44
+ */
45
+ export function scopeKindOf(raw) {
46
+ return SCOPE_ORDER.includes(raw) ? raw : undefined;
47
+ }
48
+ /**
49
+ * The path a REF slot's single value lives at.
50
+ *
51
+ * A `connection` or `sampling` slot holds exactly one thing — the id of a row in
52
+ * its own table — so it has no sub-paths and its address is the empty one.
53
+ *
54
+ * This constant exists because that fact was written down three different ways
55
+ * and the three never met. The panel wrote `''`, the app's legacy projection
56
+ * wrote `'ref'`, and this file's own executor read `'$ref'`; resolution below is
57
+ * exact-match on `(nodeKey, slot, path)`, so the three were unrelated addresses
58
+ * that could never collide and never warn. A pick made in the config panel was
59
+ * saved, shown back, and read by nobody — for as long as the feature has existed.
60
+ *
61
+ * `''` is the winner because it is what the writer already emits, so it is what
62
+ * is already in every user's `pipeline_config_values`. Any other choice would
63
+ * migrate live data to match a convention only the reader believed in.
64
+ *
65
+ * @internal
66
+ */
67
+ export const SLOT_VALUE = '';
68
+ /**
69
+ * The endpoint half of a connection slot's value, or null when it names none.
70
+ *
71
+ * Returns the id **exactly as stored** — a string stays a string, a number
72
+ * stays a number. Row ids belong to the host, and this package has no business
73
+ * ruling that they are one or the other; the string/number divide is reconciled
74
+ * where the comparison happens, not here.
75
+ * @internal
76
+ */
77
+ export function slotConnectionId(value) {
78
+ if (typeof value === 'number')
79
+ return Number.isFinite(value) ? value : null;
80
+ if (typeof value === 'string')
81
+ return value === '' ? null : value;
82
+ if (value && typeof value === 'object') {
83
+ const o = value;
84
+ const inner = o.ref ?? o.id;
85
+ if (typeof inner === 'number')
86
+ return Number.isFinite(inner) ? inner : null;
87
+ if (typeof inner === 'string')
88
+ return inner === '' ? null : inner;
89
+ }
90
+ return null;
91
+ }
92
+ /**
93
+ * The model half of a connection slot's value, or null when it names no model.
94
+ *
95
+ * Null for every value written before the pair existed, which is the whole
96
+ * compatibility story — and null is *absence*, never a model the endpoint is
97
+ * taken to mean. Same id-type rule as {@link slotConnectionId}: stored as
98
+ * given, back as stored.
99
+ * @internal
100
+ */
101
+ export function slotConnectionModelId(value) {
102
+ if (!value || typeof value !== 'object')
103
+ return null;
104
+ const inner = value.modelId;
105
+ if (typeof inner === 'number')
106
+ return Number.isFinite(inner) ? inner : null;
107
+ if (typeof inner === 'string')
108
+ return inner === '' ? null : inner;
109
+ return null;
110
+ }
111
+ /**
112
+ * Effective config **with provenance** = base ⊕ overrides, per (nodeKey, slot, path).
113
+ *
114
+ * This is the primitive; `resolveConfig` is derived from it rather than written
115
+ * beside it. Two implementations of a five-layer walk are two implementations
116
+ * that eventually disagree about which layer wins — and the one that disagrees
117
+ * silently is whichever one the UI is not using.
118
+ * @internal
119
+ */
120
+ export function resolveConfigSources(world, nodeKeys) {
121
+ const out = {};
122
+ for (const nodeKey of nodeKeys) {
123
+ const node = {};
124
+ out[nodeKey] = node;
125
+ const author = world.authorDefaults?.[nodeKey] ?? {};
126
+ for (const [slot, paths] of Object.entries(author))
127
+ for (const [path, value] of Object.entries(paths)) {
128
+ node[slot] ??= {};
129
+ node[slot][path] = { value, scopeKind: 'author' };
130
+ }
131
+ const rows = world.overrides.filter((o) => o.nodeKey === nodeKey);
132
+ // Addressed by the pair itself, and keyed on a separator no path can
133
+ // contain. Grouping on `${slot} ${path}` and splitting the pair back out
134
+ // made a declared field named `opening line` resolve against the path
135
+ // `opening`, so it matched nothing — silently, for whoever declared it.
136
+ // No core path has a space in it; nothing stops a plugin's from having one.
137
+ //
138
+ // `\u0000` as an escape, deliberately, rather than the raw NUL byte the
139
+ // first fix used: a literal NUL in a source file makes git classify it as
140
+ // binary, so `git diff` emits "Binary files differ" and a patch generated
141
+ // without `--binary` carries no content at all. That is how the previous
142
+ // version of this fix was lost in transit.
143
+ const SEP = '\u0000';
144
+ const addresses = new Map();
145
+ for (const r of rows)
146
+ addresses.set(`${r.slot}${SEP}${r.path}`, [r.slot, r.path]);
147
+ for (const [slot, path] of addresses.values()) {
148
+ const candidates = rows.filter((r) => r.slot === slot && r.path === path);
149
+ for (const scope of SCOPE_ORDER) {
150
+ const hit = candidates.find((c) => scopeKindOf(c.scopeKind) === scope);
151
+ if (hit) {
152
+ node[slot] ??= {};
153
+ node[slot][path] = {
154
+ value: hit.value,
155
+ scopeKind: scope,
156
+ ...(hit.scopeId !== undefined ? { scopeId: hit.scopeId } : {}),
157
+ };
158
+ break;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return out;
164
+ }
165
+ /** Effective config = base ⊕ overrides, per (nodeKey, slot, path). @internal */
166
+ export function resolveConfig(world, nodeKeys) {
167
+ const out = {};
168
+ for (const [nodeKey, slots] of Object.entries(resolveConfigSources(world, nodeKeys))) {
169
+ const node = {};
170
+ out[nodeKey] = node;
171
+ for (const [slot, paths] of Object.entries(slots)) {
172
+ node[slot] = {};
173
+ for (const [path, resolved] of Object.entries(paths))
174
+ node[slot][path] = resolved.value;
175
+ }
176
+ }
177
+ return out;
178
+ }
179
+ /**
180
+ * Which scopes may write which slot (12 §4). The admin cascade needs no mechanism:
181
+ * connection has no writable scope below the config for a non-admin, so an
182
+ * admin's choice reaches everyone automatically.
183
+ *
184
+ * `config` here is the selected config — the one place an administrator's
185
+ * edit lands (R-10 folded `instance` into it, 2026-09-16). A slot a session may
186
+ * not write is a slot only the config carries.
187
+ * @internal
188
+ */
189
+ export const WRITE_MATRIX = {
190
+ // A session names no connection (ruled 2026-09-30): the pair a step runs
191
+ // on is the pipeline configuration's, or the instance default, so the
192
+ // only scope that may write it is `config` — an admin's edit to the
193
+ // configuration itself. What a session tunes is `sampling` and `prompts`.
194
+ // ⚠ An AUTHOR preset (12 §3a, `PresetBuilder`) still may not carry a
195
+ // connection — it does not export — which is F20's actual concern; that
196
+ // refusal is `PresetBuilder`'s deliberate absence of `.connection()`.
197
+ connection: ['config'],
198
+ sampling: ['session', 'config'],
199
+ template: ['config'],
200
+ // How a context variable is presented is a property of the instance's
201
+ // configuration, not a personal preference: two users whose characters render
202
+ // differently are two users whose bug reports cannot be compared. Same
203
+ // scopes as `template`, which is the same decision one level up.
204
+ variables: ['config'],
205
+ prompts: ['session', 'config'],
206
+ params: ['session', 'config'],
207
+ settings: ['session', 'config'],
208
+ // A chain changes what every run of the pipeline sends — the `variables`
209
+ // argument one tier up: two users whose chains differ are two users whose
210
+ // reports cannot be compared. Same scopes as `template`; widening to
211
+ // session later is one entry here, additively (18 §4a).
212
+ scripts: ['config'],
213
+ };
214
+ /** @internal */
215
+ export function mayWrite(slot, scope) {
216
+ const kind = scopeKindOf(scope);
217
+ return kind !== undefined && (WRITE_MATRIX[slot] ?? []).includes(kind);
218
+ }
219
+ /** Reject a write the matrix forbids, with the reason (15 §1.3). @experimental */
220
+ export function assertWritable(slot, scope) {
221
+ if (!mayWrite(slot, scope)) {
222
+ throw new Error(`scope '${scope}' may not write slot '${slot}'. ` +
223
+ `Allowed: ${(WRITE_MATRIX[slot] ?? ['(none)']).join(', ')}. ` +
224
+ (slot === 'connection'
225
+ ? scope === 'session'
226
+ ? 'A session never picks its own connection: it runs on the pair its pipeline configuration names, or the pub default. Change it in Pipelines.'
227
+ : 'Connections are admin-only so credentials and compute stay under admin control (12 §4).'
228
+ : ''));
229
+ }
230
+ }
231
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,89 @@
1
+ /**
2
+ * What an import has to wire before it can run — the ruling on 13 §10a.
3
+ *
4
+ * The question was whether connection bindings deserve their own table, so that an
5
+ * export could state *structurally* that connections were excluded rather than relying
6
+ * on the exporter to strip them.
7
+ *
8
+ * **Ruled: no table.** A second table implies a second lifecycle — its own ids, its own
9
+ * ownership rules, its own migration — and there isn't one. A connection binding is a
10
+ * config value at instance scope, which 12's five-layer chain already owns.
11
+ *
12
+ * The guarantee people wanted from the table is available without it, and stronger. A
13
+ * table could only ever report the connections the exporting instance had *filled in*,
14
+ * so a spec exported before anyone configured it would claim to need nothing and the
15
+ * importer would find out at the first run. Slots are declared on the **type**, so
16
+ * deriving the requirement from descriptors is complete by construction — independent of
17
+ * what the exporter did, and independent of whether the exporter was even configured.
18
+ */
19
+ import type { SpecDocument } from './document.js';
20
+ import { type CapabilityId, type CapabilitySet, type Verdict } from './capabilities.js';
21
+ /** @experimental */
22
+ export interface ConnectionRequirement {
23
+ nodeKey: string;
24
+ slot: string;
25
+ /** Which connection kind satisfies it — the produced shape (F17). */
26
+ kind?: string;
27
+ definitionId: string;
28
+ /** What the connection must be able to do. Unmet is a hard failure at bind. */
29
+ requires?: readonly CapabilityId[];
30
+ /** What it would use if available. The binding handles absence either way. */
31
+ optional?: readonly CapabilityId[];
32
+ }
33
+ /**
34
+ * Every connection this document needs, derived from its types.
35
+ *
36
+ * "Needs" means a binding an importer has to make. A slot the document already
37
+ * points at another node's is not one of those — see `sharedWithAnotherNode`.
38
+ * @experimental
39
+ */
40
+ export declare function requiredConnections(doc: SpecDocument): ConnectionRequirement[];
41
+ /**
42
+ * What is still unwired, given what the importing instance has bound so far.
43
+ *
44
+ * Feeds `needs-configuration` (12 §6), which is deliberately not `broken`. A spec nobody
45
+ * has given a connection is not damaged, it is unfinished — and the difference decides
46
+ * whether a user files a bug or opens settings.
47
+ * @experimental
48
+ */
49
+ export declare function unwiredConnections(doc: SpecDocument, bound: ReadonlyArray<{
50
+ nodeKey: string;
51
+ slot: string;
52
+ }>): ConnectionRequirement[];
53
+ /**
54
+ * The line an import screen shows.
55
+ *
56
+ * Names the capability in the words the connection form used — "needs a
57
+ * connection that supports Image generation" — rather than a shape id. Somebody
58
+ * reading this is deciding which of their connections to point at it, and
59
+ * `core:shape/image-gen@1` does not help them decide anything.
60
+ *
61
+ * `supports`, not `can`: every capability label is a noun phrase ("Vision",
62
+ * "Embeddings", "Image generation"), so `can` only reads for the handful that
63
+ * happen to start with a verb and gives "a connection that can Embeddings" for
64
+ * the rest.
65
+ * @experimental
66
+ */
67
+ export declare const renderRequirement: (r: ConnectionRequirement) => string;
68
+ /** One slot, checked against what the connection bound to it can actually do. @experimental */
69
+ export interface UnsatisfiedConnection extends ConnectionRequirement {
70
+ verdict: Verdict;
71
+ }
72
+ /**
73
+ * Which bound connections cannot do what their slot asks.
74
+ *
75
+ * Distinct from `unwiredConnections`, and the distinction is the whole point of
76
+ * the capability model: *unwired* means nobody chose yet, *unsatisfied* means
77
+ * somebody chose and the choice will not work. The first is an unfinished setup;
78
+ * the second is a setup that looks finished and fails at the first run.
79
+ *
80
+ * Takes the resolved capability set per slot rather than a connection id, so
81
+ * this stays pure — the caller does the lookup it was going to do anyway.
82
+ * @experimental
83
+ */
84
+ export declare function unsatisfiedConnections(doc: SpecDocument, boundCapabilities: ReadonlyArray<{
85
+ nodeKey: string;
86
+ slot: string;
87
+ capabilities: CapabilitySet;
88
+ }>): UnsatisfiedConnection[];
89
+ //# sourceMappingURL=connections.d.ts.map
@@ -0,0 +1,131 @@
1
+ /**
2
+ * What an import has to wire before it can run — the ruling on 13 §10a.
3
+ *
4
+ * The question was whether connection bindings deserve their own table, so that an
5
+ * export could state *structurally* that connections were excluded rather than relying
6
+ * on the exporter to strip them.
7
+ *
8
+ * **Ruled: no table.** A second table implies a second lifecycle — its own ids, its own
9
+ * ownership rules, its own migration — and there isn't one. A connection binding is a
10
+ * config value at instance scope, which 12's five-layer chain already owns.
11
+ *
12
+ * The guarantee people wanted from the table is available without it, and stronger. A
13
+ * table could only ever report the connections the exporting instance had *filled in*,
14
+ * so a spec exported before anyone configured it would claim to need nothing and the
15
+ * importer would find out at the first run. Slots are declared on the **type**, so
16
+ * deriving the requirement from descriptors is complete by construction — independent of
17
+ * what the exporter did, and independent of whether the exporter was even configured.
18
+ */
19
+ import { getDefinition } from './descriptors.js';
20
+ import { capabilityLabel, satisfies, } from './capabilities.js';
21
+ /**
22
+ * A slot this node reads from ANOTHER node's config (16 §5b-i).
23
+ *
24
+ * `resolvedRefs` is what publish leaves behind for `slot.connectionOf('x')`, and
25
+ * the executor honours it: `resolveSlot` reads the TARGET's stored value, so a
26
+ * value written against this node would be resolved by nothing.
27
+ *
28
+ * Same rule the config panel already applies — a slot wired to another node's is
29
+ * not this node's to configure, and offering a second box for one value is the
30
+ * defect that rule exists to close. It reaches here for the first time because
31
+ * `core:task/assemble@2` is the first core type to share a CONNECTION reference:
32
+ * it renders the prompt for whatever the sending Provider is bound to, and has
33
+ * nothing of its own for an importer to bind.
34
+ */
35
+ const sharedWithAnotherNode = (n, slot) => {
36
+ const target = n.resolvedRefs?.[slot];
37
+ if (target !== undefined)
38
+ return target !== n.key;
39
+ // A document that predates `resolvedRefs`, or one hand-written: the wiring is
40
+ // still in the stored config as a slot reference carrying `ofNode`.
41
+ const wired = n.config?.[slot];
42
+ return (!!wired &&
43
+ typeof wired === 'object' &&
44
+ wired.__ref === 'slot' &&
45
+ !!wired.ofNode &&
46
+ wired.ofNode !== n.key);
47
+ };
48
+ /**
49
+ * Every connection this document needs, derived from its types.
50
+ *
51
+ * "Needs" means a binding an importer has to make. A slot the document already
52
+ * points at another node's is not one of those — see `sharedWithAnotherNode`.
53
+ * @experimental
54
+ */
55
+ export function requiredConnections(doc) {
56
+ const out = [];
57
+ for (const n of doc.nodes) {
58
+ const d = getDefinition(`${n.definitionId}@${n.definitionVersion}`);
59
+ for (const [slot, decl] of Object.entries(d?.slots ?? {}))
60
+ if (decl.kind === 'connection' && !sharedWithAnotherNode(n, slot))
61
+ out.push({
62
+ nodeKey: n.key,
63
+ slot,
64
+ kind: decl.shape,
65
+ definitionId: n.definitionId,
66
+ ...(decl.requires ? { requires: decl.requires } : {}),
67
+ ...(decl.optional ? { optional: decl.optional } : {}),
68
+ });
69
+ }
70
+ return out;
71
+ }
72
+ /**
73
+ * What is still unwired, given what the importing instance has bound so far.
74
+ *
75
+ * Feeds `needs-configuration` (12 §6), which is deliberately not `broken`. A spec nobody
76
+ * has given a connection is not damaged, it is unfinished — and the difference decides
77
+ * whether a user files a bug or opens settings.
78
+ * @experimental
79
+ */
80
+ export function unwiredConnections(doc, bound) {
81
+ const has = new Set(bound.map((b) => `${b.nodeKey} ${b.slot}`));
82
+ return requiredConnections(doc).filter((r) => !has.has(`${r.nodeKey} ${r.slot}`));
83
+ }
84
+ /**
85
+ * The line an import screen shows.
86
+ *
87
+ * Names the capability in the words the connection form used — "needs a
88
+ * connection that supports Image generation" — rather than a shape id. Somebody
89
+ * reading this is deciding which of their connections to point at it, and
90
+ * `core:shape/image-gen@1` does not help them decide anything.
91
+ *
92
+ * `supports`, not `can`: every capability label is a noun phrase ("Vision",
93
+ * "Embeddings", "Image generation"), so `can` only reads for the handful that
94
+ * happen to start with a verb and gives "a connection that can Embeddings" for
95
+ * the rest.
96
+ * @experimental
97
+ */
98
+ export const renderRequirement = (r) => {
99
+ const caps = (r.requires ?? []).map(capabilityLabel);
100
+ const what = caps.length
101
+ ? `a connection that supports ${caps.join(' and ')}`
102
+ : `a ${r.kind ?? 'connection'} connection`;
103
+ return `${r.nodeKey}.${r.slot} — needs ${what} (${r.definitionId})`;
104
+ };
105
+ /**
106
+ * Which bound connections cannot do what their slot asks.
107
+ *
108
+ * Distinct from `unwiredConnections`, and the distinction is the whole point of
109
+ * the capability model: *unwired* means nobody chose yet, *unsatisfied* means
110
+ * somebody chose and the choice will not work. The first is an unfinished setup;
111
+ * the second is a setup that looks finished and fails at the first run.
112
+ *
113
+ * Takes the resolved capability set per slot rather than a connection id, so
114
+ * this stays pure — the caller does the lookup it was going to do anyway.
115
+ * @experimental
116
+ */
117
+ export function unsatisfiedConnections(doc, boundCapabilities) {
118
+ const byAddress = new Map(boundCapabilities.map((b) => [`${b.nodeKey} ${b.slot}`, b.capabilities]));
119
+ const out = [];
120
+ for (const r of requiredConnections(doc)) {
121
+ const have = byAddress.get(`${r.nodeKey} ${r.slot}`);
122
+ // Nothing bound is `unwiredConnections`' business, not this one.
123
+ if (!have)
124
+ continue;
125
+ const verdict = satisfies({ requires: r.requires, optional: r.optional }, have);
126
+ if (!verdict.ok)
127
+ out.push({ ...r, verdict });
128
+ }
129
+ return out;
130
+ }
131
+ //# sourceMappingURL=connections.js.map