@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.
- package/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A handler's `input`, derived from the contract it is bound to.
|
|
3
|
+
*
|
|
4
|
+
* The ruling (2026-09-10): **handler input types are generated from the
|
|
5
|
+
* contract.** A node handler's `input` is its type's own `ports.in` plus the
|
|
6
|
+
* `params` slot's declared schema — so a declared field nothing reads is
|
|
7
|
+
* *visible*, and a read of a name nothing declares is a **type error** rather
|
|
8
|
+
* than a property access on `any` that is `undefined` at runtime and silent at
|
|
9
|
+
* build.
|
|
10
|
+
*
|
|
11
|
+
* That failure is not hypothetical and it is not subtle in hindsight. Two core
|
|
12
|
+
* bindings shipped reading names their own contract does not declare —
|
|
13
|
+
* `input.topK` on `core:query/vector-search@1` (a *parameter*, at
|
|
14
|
+
* `input.params.topK`, so the host ran on a literal `?? 40` for the mechanism's
|
|
15
|
+
* whole life) and `input.limit` on `core:query/session-history@1` (the same
|
|
16
|
+
* shape, the same silence). Each was found by hand, twice, after the fact.
|
|
17
|
+
*
|
|
18
|
+
* ## What is derivable and what is not
|
|
19
|
+
*
|
|
20
|
+
* **Port names, yes. Port values, no.** `ports.in` maps a port to a `ShapeId`,
|
|
21
|
+
* which is a string id in a runtime registry with no TS payload behind it (see
|
|
22
|
+
* src/shapes.ts), so there is nothing to derive a value type *from*. Ports
|
|
23
|
+
* therefore carry `any` and the derivation's job is the set of **names**.
|
|
24
|
+
*
|
|
25
|
+
* **Parameter names and values, both.** A `parameters` slot declares a
|
|
26
|
+
* `schema` of `FieldDecl`s, and a `FieldDecl` carries its `type` — so
|
|
27
|
+
* `params.maxEntries` is a `number` because the declaration says `'integer'`,
|
|
28
|
+
* and `params.strategy` is the union of its `of: [...]` choices. That is a real
|
|
29
|
+
* static shape rather than a name check.
|
|
30
|
+
*
|
|
31
|
+
* ## Shared handlers stay structural
|
|
32
|
+
*
|
|
33
|
+
* One handler may serve several node types. Its input is then the
|
|
34
|
+
* **intersection** of what those contracts supply — it may read only what
|
|
35
|
+
* *every* one of them declares — which is what `SharedInput<[A, B]>` computes.
|
|
36
|
+
* A handler is never coupled to one type id; it is coupled to a shape, and the
|
|
37
|
+
* shape is checkable. `structuralCompat` in the host applies the same rule at
|
|
38
|
+
* runtime, for a plugin binding to somebody else's type and for the pipeline
|
|
39
|
+
* orchestrator composing nodes in the UI.
|
|
40
|
+
*
|
|
41
|
+
* @see src/descriptors.ts — why every `describe*` is generic over its slots
|
|
42
|
+
*/
|
|
43
|
+
import type { Descriptor, PortDecl } from './descriptors.js';
|
|
44
|
+
import type { Hook } from './executor.js';
|
|
45
|
+
import type { FieldType, MemberDecl } from './settings.js';
|
|
46
|
+
/**
|
|
47
|
+
* A type's own declared keys, with index signatures stripped.
|
|
48
|
+
*
|
|
49
|
+
* Load-bearing twice over, and both reasons are the same defect wearing
|
|
50
|
+
* different clothes.
|
|
51
|
+
*
|
|
52
|
+
* The **first** is `Descriptor.slots`, which is the open
|
|
53
|
+
* `Record<string, SlotDecl>`. Every `describe*` returns
|
|
54
|
+
* `Descriptor<…> & { slots?: S }`, so the slots type arrives as
|
|
55
|
+
* `Record<string, SlotDecl> & { params: {…literal…} }` — the literal survives,
|
|
56
|
+
* and so does the index signature. `keyof` that intersection is `string`, which
|
|
57
|
+
* would accept **every** name and opt the whole exercise out silently.
|
|
58
|
+
*
|
|
59
|
+
* The **second** is a declaration that names no ports at all: `ports.in` then
|
|
60
|
+
* infers the open `PortDecl`, whose `keyof` is likewise `string`. Without this,
|
|
61
|
+
* exactly the types that declare least would be the ones checked least.
|
|
62
|
+
*
|
|
63
|
+
* ⚠ A homomorphic mapped type (`K in keyof T`, with the filtering in `as`) is
|
|
64
|
+
* required. `keyof (Record<string, X> & { params: Y })` collapses to `string`
|
|
65
|
+
* *before* a non-homomorphic mapping could see `params`; mapping over `T`
|
|
66
|
+
* itself visits declared properties and index signatures separately, which is
|
|
67
|
+
* what leaves `params` behind after `string` is filtered out. Same construction
|
|
68
|
+
* as `DeclaredKeysOnly` in src/capabilities.ts, which keeps `ctx.can()` from
|
|
69
|
+
* widening to every capability in the app.
|
|
70
|
+
*/
|
|
71
|
+
type DeclaredOnly<T> = {
|
|
72
|
+
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The declared names of `T`, or nothing at all when there is no `T`.
|
|
76
|
+
*
|
|
77
|
+
* ⚠ The `never` guard is not defensive. A mapped type over `never` is `never`,
|
|
78
|
+
* and `keyof never` is `string | number | symbol` — so without this, a contract
|
|
79
|
+
* that declares **no** parameters derives *every* parameter name, which is the
|
|
80
|
+
* precise inversion of the point. It cost an afternoon: `userMessage.params`
|
|
81
|
+
* type-checked because `ParamNamesOf` had quietly answered `string`.
|
|
82
|
+
*/
|
|
83
|
+
type DeclaredNames<T> = [T] extends [never] ? never : Extract<keyof DeclaredOnly<T>, string>;
|
|
84
|
+
/**
|
|
85
|
+
* The descriptor behind a contract reference.
|
|
86
|
+
*
|
|
87
|
+
* Accepts the pinned form (`typeof C.vectorSearch` — a `Pinned<D>`, which is
|
|
88
|
+
* what `@serene-pub/contracts` exports and what a spec author already holds)
|
|
89
|
+
* and a bare descriptor, so a plugin that has only its own `describeQueryDefinition`
|
|
90
|
+
* return value can use these helpers without wrapping it in a `pin` first.
|
|
91
|
+
* @experimental
|
|
92
|
+
*/
|
|
93
|
+
export type DescriptorOf<P> = P extends {
|
|
94
|
+
descriptor: infer D;
|
|
95
|
+
} ? D : P extends Descriptor<any, any, any> ? P : never;
|
|
96
|
+
/** The in-port map a contract declares, or `{}` when it declares none. */
|
|
97
|
+
type InPortMap<P> = DescriptorOf<P> extends {
|
|
98
|
+
ports: {
|
|
99
|
+
in?: infer I;
|
|
100
|
+
};
|
|
101
|
+
} ? NonNullable<I> : PortDecl;
|
|
102
|
+
/**
|
|
103
|
+
* The in-port names a contract declares, as a union of literals.
|
|
104
|
+
*
|
|
105
|
+
* Names only — see the file header for why a `ShapeId` has no value type to
|
|
106
|
+
* derive.
|
|
107
|
+
* @experimental
|
|
108
|
+
*/
|
|
109
|
+
export type InPortsOf<P> = DeclaredNames<InPortMap<P>>;
|
|
110
|
+
/** The slot map a contract declares, or `{}` when it declares none. */
|
|
111
|
+
type SlotMap<P> = DescriptorOf<P> extends {
|
|
112
|
+
slots?: infer S;
|
|
113
|
+
} ? NonNullable<S> : never;
|
|
114
|
+
/**
|
|
115
|
+
* The slot names a contract declares.
|
|
116
|
+
*
|
|
117
|
+
* ⚠ **Per node, and that is new.** This used to be a fixed vocabulary — a
|
|
118
|
+
* closed `CoreSlot` union in the app — because `describe*` erased its slot keys
|
|
119
|
+
* into `Record<string, SlotDecl>` and there was nothing left to derive from.
|
|
120
|
+
* Now that every `describe*` captures its argument, a node that declares no
|
|
121
|
+
* `template` slot no longer silently accepts `input.template`.
|
|
122
|
+
* @experimental
|
|
123
|
+
*/
|
|
124
|
+
export type SlotNamesOf<P> = DeclaredNames<SlotMap<P>>;
|
|
125
|
+
/** The `params` slot's declared schema, or `never` when there is none. */
|
|
126
|
+
type ParamsSchema<P> = DeclaredOnly<SlotMap<P>> extends {
|
|
127
|
+
params: infer Slot;
|
|
128
|
+
} ? Slot extends {
|
|
129
|
+
schema?: infer Sch;
|
|
130
|
+
} ? [NonNullable<Sch>] extends [never] ? never : DeclaredOnly<NonNullable<Sch>> : never : never;
|
|
131
|
+
/** The parameter names a contract declares. @experimental */
|
|
132
|
+
export type ParamNamesOf<P> = DeclaredNames<ParamsSchema<P>>;
|
|
133
|
+
/**
|
|
134
|
+
* What one declared field is, as a TS type.
|
|
135
|
+
*
|
|
136
|
+
* The mapping is the field language's own (src/settings.ts) and the two must
|
|
137
|
+
* stay in step; the check that they do is `checkFieldTypes` in the conformance
|
|
138
|
+
* suite plus the assertions in sdk-tests/nodeInput.assert.ts, both of which
|
|
139
|
+
* fail on a `FieldType` this does not answer.
|
|
140
|
+
*
|
|
141
|
+
* ⚠ `unknown` for an unanswered type rather than `any`, deliberately. A field
|
|
142
|
+
* type nobody mapped should make the *use* fail loudly at the binding, not
|
|
143
|
+
* quietly become the thing `any` becomes: another silent read.
|
|
144
|
+
* @experimental
|
|
145
|
+
*/
|
|
146
|
+
export type FieldValue<F> = F extends {
|
|
147
|
+
type: infer T;
|
|
148
|
+
} ? T extends 'string' | 'text' | 'secret' | 'media' ? string : T extends 'number' | 'integer' ? number : T extends 'boolean' ? boolean : T extends 'string[]' ? string[] : T extends 'enum' ? EnumValue<F> : T extends 'share' | 'perMember' | 'strengths' ? Record<string, number> : unknown : unknown;
|
|
149
|
+
/**
|
|
150
|
+
* An `enum`'s value: its declared choices when it lists them, `string`
|
|
151
|
+
* otherwise.
|
|
152
|
+
*
|
|
153
|
+
* `of` is the canonical list and `members[].key` is the labelled spelling of
|
|
154
|
+
* the same thing (settings.ts: "an `enum` may use this **instead of** `of`"),
|
|
155
|
+
* so both are read here — a declaration that labels its choices must not
|
|
156
|
+
* degrade to a bare `string` for having been written the more helpful way.
|
|
157
|
+
*/
|
|
158
|
+
type EnumValue<F> = F extends {
|
|
159
|
+
of: readonly (infer V)[];
|
|
160
|
+
} ? V extends string ? V : string : F extends {
|
|
161
|
+
members: readonly (infer M)[];
|
|
162
|
+
} ? M extends {
|
|
163
|
+
key: infer K;
|
|
164
|
+
} ? K extends string ? K : string : string : string;
|
|
165
|
+
/**
|
|
166
|
+
* A contract's `params` object.
|
|
167
|
+
*
|
|
168
|
+
* Every key is optional, and that is the substrate's shape rather than a
|
|
169
|
+
* hedge: `resolveInput` hands a binding the node's stored config, and a config
|
|
170
|
+
* that never set a control simply has no key for it. The declared `default` is
|
|
171
|
+
* applied by the *binding*, with `??`, which is why every core read of a param
|
|
172
|
+
* already has one.
|
|
173
|
+
* @experimental
|
|
174
|
+
*/
|
|
175
|
+
export type ParamsOf<P> = {
|
|
176
|
+
[K in ParamNamesOf<P>]?: FieldValue<ParamsSchema<P>[K]>;
|
|
177
|
+
};
|
|
178
|
+
/** Everything a contract puts on `input` except `params`, which is typed. */
|
|
179
|
+
type PlainKeys<P> = Exclude<InPortsOf<P> | SlotNamesOf<P>, 'params'>;
|
|
180
|
+
/**
|
|
181
|
+
* A node handler's `input`, derived from its contract.
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* const search = async (input: InputOf<typeof C.vectorSearch>) => {
|
|
185
|
+
* input.vectors // ✅ a declared in-port
|
|
186
|
+
* input.params?.topK // ✅ a declared parameter, typed `number`
|
|
187
|
+
* input.topK // ❌ not a port — this is the defect that shipped
|
|
188
|
+
* input.params?.minScore // ❌ not in the schema — nor was it ever read
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* `Partial` over the ports because a port is only present when a spec wired
|
|
193
|
+
* one, and a spec that wires nothing into an optional in-port is legal — the
|
|
194
|
+
* binding's `??` is the contract there, not the type.
|
|
195
|
+
* @experimental
|
|
196
|
+
*/
|
|
197
|
+
export type InputOf<P> = Partial<Record<PlainKeys<P>, any>> & ([ParamNamesOf<P>] extends [never] ? unknown : {
|
|
198
|
+
params?: ParamsOf<P>;
|
|
199
|
+
});
|
|
200
|
+
/**
|
|
201
|
+
* The keys every contract in the list declares.
|
|
202
|
+
*
|
|
203
|
+
* Folded pairwise with `Extract` rather than written as an intersection of
|
|
204
|
+
* unions. `('a' | 'b') & ('b' | 'c')` does reduce to `'b'`, but only because
|
|
205
|
+
* TS normalises intersections of unit types — a rule that has no business
|
|
206
|
+
* being load-bearing three types deep. `Extract` says what is meant.
|
|
207
|
+
*/
|
|
208
|
+
type SharedNames<Ps extends readonly unknown[]> = Ps extends readonly [infer H, ...infer R] ? R extends readonly [] ? PlainKeys<H> : Extract<PlainKeys<H>, SharedNames<R>> : never;
|
|
209
|
+
type SharedParamNames<Ps extends readonly unknown[]> = Ps extends readonly [infer H, ...infer R] ? R extends readonly [] ? ParamNamesOf<H> : Extract<ParamNamesOf<H>, SharedParamNames<R>> : never;
|
|
210
|
+
/**
|
|
211
|
+
* What one shared parameter is: the **union** of what each contract declares
|
|
212
|
+
* it to be.
|
|
213
|
+
*
|
|
214
|
+
* A union rather than an intersection, and the direction is the whole point. A
|
|
215
|
+
* handler serving three types is handed whichever one the run resolved, so it
|
|
216
|
+
* has to cope with every declaration — `number | string` is the honest type for
|
|
217
|
+
* a key two contracts type differently, where `number & string` (`never`) would
|
|
218
|
+
* say the read is impossible when it is merely varied. In practice the shared
|
|
219
|
+
* lanes declare identically and the union collapses to one type.
|
|
220
|
+
*/
|
|
221
|
+
type SharedParamValue<Ps extends readonly unknown[], K extends string> = {
|
|
222
|
+
[I in keyof Ps]: K extends ParamNamesOf<Ps[I]> ? FieldValue<ParamsSchema<Ps[I]>[K]> : never;
|
|
223
|
+
}[number];
|
|
224
|
+
/**
|
|
225
|
+
* One handler, several node types — typed as the **intersection** of what they
|
|
226
|
+
* supply.
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* // world lore, character lore and history are one scan filtered three ways
|
|
230
|
+
* const loreFor = (source: string, input: SharedInput<[
|
|
231
|
+
* typeof C.worldLore, typeof C.characterLore, typeof C.historyEntries
|
|
232
|
+
* ]>) => …
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* The handler may read only what *every* listed contract declares, which is
|
|
236
|
+
* exactly what makes it safe to bind to all three: whichever one the run
|
|
237
|
+
* resolved, every name it touches is declared. A key one lane adds is
|
|
238
|
+
* unreadable here until the others add it too — visible as a type error at the
|
|
239
|
+
* read, rather than as `undefined` on two lanes out of three.
|
|
240
|
+
* @experimental
|
|
241
|
+
*/
|
|
242
|
+
export type SharedInput<Ps extends readonly unknown[]> = Partial<Record<SharedNames<Ps>, any>> & ([SharedParamNames<Ps>] extends [never] ? unknown : {
|
|
243
|
+
params?: {
|
|
244
|
+
[K in SharedParamNames<Ps>]?: SharedParamValue<Ps, K>;
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* The names a handler reads off its input — the runtime shadow of `InputOf`.
|
|
249
|
+
*
|
|
250
|
+
* A type cannot be inspected at run time, and two of the three consumers of
|
|
251
|
+
* this rule are runtime consumers: a plugin binding a handler to a type it did
|
|
252
|
+
* not declare, and the admin-side orchestrator composing nodes in the UI.
|
|
253
|
+
* Neither can typecheck anything. So a handler *declares* what it reads, in
|
|
254
|
+
* the same two categories `InputOf` derives, and `structuralCompat` (core,
|
|
255
|
+
* src/lib/server/pipelines/runtime/structuralCompat.ts) decides whether a
|
|
256
|
+
* given contract supplies it.
|
|
257
|
+
*
|
|
258
|
+
* ⚠ `ports` covers **in-ports and slot names together**, because they arrive
|
|
259
|
+
* on `input` indistinguishably: `resolveInput` builds one flat object out of
|
|
260
|
+
* the node's config, wired edges and resolved slot refs alike. Splitting them
|
|
261
|
+
* here would ask a caller to know which of the two a name is, which is
|
|
262
|
+
* precisely the knowledge the flat input takes away.
|
|
263
|
+
* @experimental
|
|
264
|
+
*/
|
|
265
|
+
export interface HandlerRequires {
|
|
266
|
+
/** In-port and slot names read off `input` directly. */
|
|
267
|
+
ports: readonly string[];
|
|
268
|
+
/** Names read off `input.params`. */
|
|
269
|
+
params: readonly string[];
|
|
270
|
+
/**
|
|
271
|
+
* A field type a param is required to have, for the reads that care.
|
|
272
|
+
*
|
|
273
|
+
* Optional and rarely written: most handlers care that `limit` exists, not
|
|
274
|
+
* that it is an `integer` rather than a `number`. Where it is written,
|
|
275
|
+
* `structuralCompat` reports a mismatch instead of a missing name.
|
|
276
|
+
*/
|
|
277
|
+
paramTypes?: Readonly<Record<string, FieldType>>;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* A hook that says what it reads.
|
|
281
|
+
*
|
|
282
|
+
* Additive by construction: `Bindings` values stay plain `Hook`s, and a
|
|
283
|
+
* function carrying an extra property is assignable to a function type — so a
|
|
284
|
+
* host that never looks at `requires` is unaffected, and one that does gets the
|
|
285
|
+
* declaration where the handler is.
|
|
286
|
+
* @experimental
|
|
287
|
+
*/
|
|
288
|
+
export type DeclaredHook<H extends (...args: any[]) => any> = H & {
|
|
289
|
+
readonly requires: HandlerRequires;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Attach a read declaration to a handler.
|
|
293
|
+
*
|
|
294
|
+
* ```ts
|
|
295
|
+
* declaresReads(async (input: InputOf<typeof C.sessionHistory>, ctx) => …, {
|
|
296
|
+
* ports: ['scope'],
|
|
297
|
+
* params: ['limit', 'channel'],
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
301
|
+
* Returns the same function object rather than a wrapper: a wrapper would
|
|
302
|
+
* change the identity the executor's binding table holds, and one binding table
|
|
303
|
+
* keyed by identity is how a shared handler is recognised as shared.
|
|
304
|
+
* @experimental
|
|
305
|
+
*/
|
|
306
|
+
export declare function declaresReads<H extends (...args: any[]) => any>(hook: H, requires: HandlerRequires): DeclaredHook<H>;
|
|
307
|
+
/**
|
|
308
|
+
* The names a handler bound to `P` may declare it reads off `input` — its
|
|
309
|
+
* in-ports and slot names, or, for a tuple of contracts, the intersection.
|
|
310
|
+
*
|
|
311
|
+
* `P` is one pinned contract (`typeof C.sessionHistory`) or a readonly tuple of
|
|
312
|
+
* them (`[typeof C.worldLore, typeof C.characterLore, typeof C.historyEntries]`),
|
|
313
|
+
* the same two spellings `InputOf` and `SharedInput` take. A pinned contract is
|
|
314
|
+
* an object and never an array, so the tuple branch cannot be entered by
|
|
315
|
+
* accident.
|
|
316
|
+
* @experimental
|
|
317
|
+
*/
|
|
318
|
+
export type ReadablePorts<P> = P extends readonly unknown[] ? SharedNames<P> : PlainKeys<P>;
|
|
319
|
+
/** The parameter names a handler bound to `P` may declare it reads. @experimental */
|
|
320
|
+
export type ReadableParams<P> = P extends readonly unknown[] ? SharedParamNames<P> : ParamNamesOf<P>;
|
|
321
|
+
/**
|
|
322
|
+
* A read declaration whose every name the contract has to supply.
|
|
323
|
+
*
|
|
324
|
+
* `HandlerRequires` with the two arrays narrowed from `string` to the
|
|
325
|
+
* contract's own literals — so `params: ['limt']` fails to compile where the
|
|
326
|
+
* untyped form would let the typo through to `structuralCompat` at boot, or,
|
|
327
|
+
* on a name the guard never reaches, through to nothing at all.
|
|
328
|
+
* @experimental
|
|
329
|
+
*/
|
|
330
|
+
export interface TypedReads<P> {
|
|
331
|
+
/** In-port and slot names read off `input` directly. */
|
|
332
|
+
ports: readonly ReadablePorts<P>[];
|
|
333
|
+
/** Names read off `input.params`. Optional: most nodes declare none. */
|
|
334
|
+
params?: readonly ReadableParams<P>[];
|
|
335
|
+
/** A field type a param is required to have, where the read cares. */
|
|
336
|
+
paramTypes?: Partial<Record<ReadableParams<P>, FieldType>>;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Attach a read declaration a contract has checked (ruling R-12, 2026-09-15).
|
|
340
|
+
*
|
|
341
|
+
* ```ts
|
|
342
|
+
* reads<typeof C.sessionHistory>(
|
|
343
|
+
* async (input: InputOf<typeof C.sessionHistory>, ctx) => …,
|
|
344
|
+
* { ports: ['scope'], params: ['limit', 'channel'] },
|
|
345
|
+
* )
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* The compile-time half of what `declaresReads` records at run time. `InputOf`
|
|
349
|
+
* makes a read of an **undeclared** name a type error; this makes the
|
|
350
|
+
* declaration name nothing `P` lacks — `params: ['limt']` does not compile.
|
|
351
|
+
* The reverse direction (a declared name **no** handler reads) is the guard's
|
|
352
|
+
* job, in the host, and it is what this declaration exists to feed.
|
|
353
|
+
*
|
|
354
|
+
* ⚠ **What this cannot check.** `P` is the contract the *declaration* is
|
|
355
|
+
* narrowed against; the handler is a plain `Hook`, so nothing here proves the
|
|
356
|
+
* handler's own `input` was typed against the same `P`. Pairing
|
|
357
|
+
* `reads<typeof C.X>` with a handler whose input is `NodeInput<typeof C.X>` is
|
|
358
|
+
* a **convention**, and the host keeps it by a test over the source of its
|
|
359
|
+
* bindings files (`boot/readsPairing.test.ts`) rather than by the type system.
|
|
360
|
+
*
|
|
361
|
+
* `P` is written explicitly and the hook is a plain `Hook`, rather than both
|
|
362
|
+
* inferred, because TypeScript infers all of a call's type arguments or none
|
|
363
|
+
* — and the contract cannot be inferred from a handler whose `input` is an
|
|
364
|
+
* intersection, an alias, or `any`.
|
|
365
|
+
*
|
|
366
|
+
* ⚠ **One declaration per function object.** Like `declaresReads` this attaches
|
|
367
|
+
* to the hook itself rather than wrapping it, so a handler two pins share
|
|
368
|
+
* carries ONE `requires` — and a second, different declaration on the same
|
|
369
|
+
* function would silently replace the first. That is refused here: bind a
|
|
370
|
+
* shared handler through a per-pin arrow (`(input, ctx) => shared(input, ctx)`)
|
|
371
|
+
* when the two pins read differently, and declare the intersection when they
|
|
372
|
+
* do not. An identical redeclaration is a no-op, on the registry's own terms.
|
|
373
|
+
* @experimental
|
|
374
|
+
*/
|
|
375
|
+
export declare function reads<P>(hook: Hook, requires: TypedReads<P>): DeclaredHook<Hook>;
|
|
376
|
+
/** Does this hook carry a read declaration? @internal */
|
|
377
|
+
export declare function readsOf(hook: unknown): HandlerRequires | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* The names a contract puts on a handler's `input`, read off the descriptor at
|
|
380
|
+
* run time.
|
|
381
|
+
*
|
|
382
|
+
* The runtime twin of `InputOf`, and the two are asserted to agree in
|
|
383
|
+
* sdk-tests/nodeInput.assert.ts. It lives in the SDK rather than in core
|
|
384
|
+
* because both sides of a plugin-to-plugin binding need the same answer, and a
|
|
385
|
+
* second implementation on either side is a second answer.
|
|
386
|
+
*
|
|
387
|
+
* `SlotDecl` is imported for the shape of what is walked; nothing here reads a
|
|
388
|
+
* slot's `kind` except to find the schema, because a schema is a schema
|
|
389
|
+
* whatever the slot is called.
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
export declare function suppliesOf(contract: unknown): {
|
|
393
|
+
id: string;
|
|
394
|
+
ports: string[];
|
|
395
|
+
params: string[];
|
|
396
|
+
paramTypes: Record<string, FieldType>;
|
|
397
|
+
};
|
|
398
|
+
export type { FieldType, MemberDecl };
|
|
399
|
+
//# sourceMappingURL=nodeInput.d.ts.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A handler's `input`, derived from the contract it is bound to.
|
|
3
|
+
*
|
|
4
|
+
* The ruling (2026-09-10): **handler input types are generated from the
|
|
5
|
+
* contract.** A node handler's `input` is its type's own `ports.in` plus the
|
|
6
|
+
* `params` slot's declared schema — so a declared field nothing reads is
|
|
7
|
+
* *visible*, and a read of a name nothing declares is a **type error** rather
|
|
8
|
+
* than a property access on `any` that is `undefined` at runtime and silent at
|
|
9
|
+
* build.
|
|
10
|
+
*
|
|
11
|
+
* That failure is not hypothetical and it is not subtle in hindsight. Two core
|
|
12
|
+
* bindings shipped reading names their own contract does not declare —
|
|
13
|
+
* `input.topK` on `core:query/vector-search@1` (a *parameter*, at
|
|
14
|
+
* `input.params.topK`, so the host ran on a literal `?? 40` for the mechanism's
|
|
15
|
+
* whole life) and `input.limit` on `core:query/session-history@1` (the same
|
|
16
|
+
* shape, the same silence). Each was found by hand, twice, after the fact.
|
|
17
|
+
*
|
|
18
|
+
* ## What is derivable and what is not
|
|
19
|
+
*
|
|
20
|
+
* **Port names, yes. Port values, no.** `ports.in` maps a port to a `ShapeId`,
|
|
21
|
+
* which is a string id in a runtime registry with no TS payload behind it (see
|
|
22
|
+
* src/shapes.ts), so there is nothing to derive a value type *from*. Ports
|
|
23
|
+
* therefore carry `any` and the derivation's job is the set of **names**.
|
|
24
|
+
*
|
|
25
|
+
* **Parameter names and values, both.** A `parameters` slot declares a
|
|
26
|
+
* `schema` of `FieldDecl`s, and a `FieldDecl` carries its `type` — so
|
|
27
|
+
* `params.maxEntries` is a `number` because the declaration says `'integer'`,
|
|
28
|
+
* and `params.strategy` is the union of its `of: [...]` choices. That is a real
|
|
29
|
+
* static shape rather than a name check.
|
|
30
|
+
*
|
|
31
|
+
* ## Shared handlers stay structural
|
|
32
|
+
*
|
|
33
|
+
* One handler may serve several node types. Its input is then the
|
|
34
|
+
* **intersection** of what those contracts supply — it may read only what
|
|
35
|
+
* *every* one of them declares — which is what `SharedInput<[A, B]>` computes.
|
|
36
|
+
* A handler is never coupled to one type id; it is coupled to a shape, and the
|
|
37
|
+
* shape is checkable. `structuralCompat` in the host applies the same rule at
|
|
38
|
+
* runtime, for a plugin binding to somebody else's type and for the pipeline
|
|
39
|
+
* orchestrator composing nodes in the UI.
|
|
40
|
+
*
|
|
41
|
+
* @see src/descriptors.ts — why every `describe*` is generic over its slots
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Attach a read declaration to a handler.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* declaresReads(async (input: InputOf<typeof C.sessionHistory>, ctx) => …, {
|
|
48
|
+
* ports: ['scope'],
|
|
49
|
+
* params: ['limit', 'channel'],
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* Returns the same function object rather than a wrapper: a wrapper would
|
|
54
|
+
* change the identity the executor's binding table holds, and one binding table
|
|
55
|
+
* keyed by identity is how a shared handler is recognised as shared.
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
export function declaresReads(hook, requires) {
|
|
59
|
+
return Object.assign(hook, { requires });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Attach a read declaration a contract has checked (ruling R-12, 2026-09-15).
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* reads<typeof C.sessionHistory>(
|
|
66
|
+
* async (input: InputOf<typeof C.sessionHistory>, ctx) => …,
|
|
67
|
+
* { ports: ['scope'], params: ['limit', 'channel'] },
|
|
68
|
+
* )
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* The compile-time half of what `declaresReads` records at run time. `InputOf`
|
|
72
|
+
* makes a read of an **undeclared** name a type error; this makes the
|
|
73
|
+
* declaration name nothing `P` lacks — `params: ['limt']` does not compile.
|
|
74
|
+
* The reverse direction (a declared name **no** handler reads) is the guard's
|
|
75
|
+
* job, in the host, and it is what this declaration exists to feed.
|
|
76
|
+
*
|
|
77
|
+
* ⚠ **What this cannot check.** `P` is the contract the *declaration* is
|
|
78
|
+
* narrowed against; the handler is a plain `Hook`, so nothing here proves the
|
|
79
|
+
* handler's own `input` was typed against the same `P`. Pairing
|
|
80
|
+
* `reads<typeof C.X>` with a handler whose input is `NodeInput<typeof C.X>` is
|
|
81
|
+
* a **convention**, and the host keeps it by a test over the source of its
|
|
82
|
+
* bindings files (`boot/readsPairing.test.ts`) rather than by the type system.
|
|
83
|
+
*
|
|
84
|
+
* `P` is written explicitly and the hook is a plain `Hook`, rather than both
|
|
85
|
+
* inferred, because TypeScript infers all of a call's type arguments or none
|
|
86
|
+
* — and the contract cannot be inferred from a handler whose `input` is an
|
|
87
|
+
* intersection, an alias, or `any`.
|
|
88
|
+
*
|
|
89
|
+
* ⚠ **One declaration per function object.** Like `declaresReads` this attaches
|
|
90
|
+
* to the hook itself rather than wrapping it, so a handler two pins share
|
|
91
|
+
* carries ONE `requires` — and a second, different declaration on the same
|
|
92
|
+
* function would silently replace the first. That is refused here: bind a
|
|
93
|
+
* shared handler through a per-pin arrow (`(input, ctx) => shared(input, ctx)`)
|
|
94
|
+
* when the two pins read differently, and declare the intersection when they
|
|
95
|
+
* do not. An identical redeclaration is a no-op, on the registry's own terms.
|
|
96
|
+
* @experimental
|
|
97
|
+
*/
|
|
98
|
+
export function reads(hook, requires) {
|
|
99
|
+
const plain = {
|
|
100
|
+
ports: [...requires.ports],
|
|
101
|
+
params: [...(requires.params ?? [])],
|
|
102
|
+
...(requires.paramTypes
|
|
103
|
+
? { paramTypes: requires.paramTypes }
|
|
104
|
+
: {}),
|
|
105
|
+
};
|
|
106
|
+
const existing = readsOf(hook);
|
|
107
|
+
if (existing && !sameRequires(existing, plain))
|
|
108
|
+
throw new Error(`reads(): this handler already declares what it reads (ports ${JSON.stringify(existing.ports)}, params ${JSON.stringify(existing.params)}) and the new declaration differs ` +
|
|
109
|
+
`(ports ${JSON.stringify(plain.ports)}, params ${JSON.stringify(plain.params)}). ` +
|
|
110
|
+
`A declaration attaches to the function object, so a handler two pins share ` +
|
|
111
|
+
`can carry only one — bind each pin through its own arrow and declare there.`);
|
|
112
|
+
return declaresReads(hook, plain);
|
|
113
|
+
}
|
|
114
|
+
function sameRequires(a, b) {
|
|
115
|
+
const sorted = (xs) => [...new Set(xs)].sort();
|
|
116
|
+
const eq = (xs, ys) => {
|
|
117
|
+
const [p, q] = [sorted(xs), sorted(ys)];
|
|
118
|
+
return p.length === q.length && p.every((x, i) => x === q[i]);
|
|
119
|
+
};
|
|
120
|
+
if (!eq(a.ports, b.ports) || !eq(a.params, b.params))
|
|
121
|
+
return false;
|
|
122
|
+
const [ta, tb] = [a.paramTypes ?? {}, b.paramTypes ?? {}];
|
|
123
|
+
const keys = sorted([...Object.keys(ta), ...Object.keys(tb)]);
|
|
124
|
+
return keys.every((k) => ta[k] === tb[k]);
|
|
125
|
+
}
|
|
126
|
+
/** Does this hook carry a read declaration? @internal */
|
|
127
|
+
export function readsOf(hook) {
|
|
128
|
+
const r = hook?.requires;
|
|
129
|
+
if (!r || typeof r !== 'object')
|
|
130
|
+
return undefined;
|
|
131
|
+
const { ports, params } = r;
|
|
132
|
+
if (!Array.isArray(ports) || !Array.isArray(params))
|
|
133
|
+
return undefined;
|
|
134
|
+
return r;
|
|
135
|
+
}
|
|
136
|
+
// ── What a contract supplies (the runtime half of the other side) ───────────
|
|
137
|
+
/**
|
|
138
|
+
* The names a contract puts on a handler's `input`, read off the descriptor at
|
|
139
|
+
* run time.
|
|
140
|
+
*
|
|
141
|
+
* The runtime twin of `InputOf`, and the two are asserted to agree in
|
|
142
|
+
* sdk-tests/nodeInput.assert.ts. It lives in the SDK rather than in core
|
|
143
|
+
* because both sides of a plugin-to-plugin binding need the same answer, and a
|
|
144
|
+
* second implementation on either side is a second answer.
|
|
145
|
+
*
|
|
146
|
+
* `SlotDecl` is imported for the shape of what is walked; nothing here reads a
|
|
147
|
+
* slot's `kind` except to find the schema, because a schema is a schema
|
|
148
|
+
* whatever the slot is called.
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
export function suppliesOf(contract) {
|
|
152
|
+
const d = descriptorOf(contract);
|
|
153
|
+
const ports = [
|
|
154
|
+
...Object.keys((d?.ports?.in ?? {})),
|
|
155
|
+
...Object.keys((d?.slots ?? {})),
|
|
156
|
+
];
|
|
157
|
+
const params = [];
|
|
158
|
+
const paramTypes = {};
|
|
159
|
+
for (const slot of Object.values((d?.slots ?? {})))
|
|
160
|
+
for (const [name, field] of Object.entries((slot?.schema ?? {}))) {
|
|
161
|
+
params.push(name);
|
|
162
|
+
if (field?.type)
|
|
163
|
+
paramTypes[name] = field.type;
|
|
164
|
+
}
|
|
165
|
+
return { id: d?.id ?? '(unknown type)', ports: [...new Set(ports)], params, paramTypes };
|
|
166
|
+
}
|
|
167
|
+
/** Unwrap the pinned form, tolerate a bare descriptor, refuse anything else. */
|
|
168
|
+
function descriptorOf(contract) {
|
|
169
|
+
if (!contract || typeof contract !== 'object')
|
|
170
|
+
return undefined;
|
|
171
|
+
const c = contract;
|
|
172
|
+
if (c.descriptor && typeof c.descriptor === 'object')
|
|
173
|
+
return c.descriptor;
|
|
174
|
+
if (typeof c.id === 'string' && c.ports)
|
|
175
|
+
return contract;
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=nodeInput.js.map
|