@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,771 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal executor — enough to run a compiled document and produce a receipt.
|
|
3
|
+
*
|
|
4
|
+
* Not the real thing, but it enforces the laws the design says the executor owns:
|
|
5
|
+
* discriminated results including halt, per-run seed, timeouts that bound execution
|
|
6
|
+
* but never waiting, consumption budgets, per-kind injection, and core-emitted events.
|
|
7
|
+
*/
|
|
8
|
+
import { type SpecDocument } from './document.js';
|
|
9
|
+
import { type Kind } from './descriptors.js';
|
|
10
|
+
import type { Receipt, NodeSwap, Outcome, ReceiptMeta, ScriptApplicationRecord } from './receipt.js';
|
|
11
|
+
import { type ConfigWorld } from './config.js';
|
|
12
|
+
import type { CapabilityId, CapabilitySet, Grade, OptionalCapsOf } from './capabilities.js';
|
|
13
|
+
import { type Reviewer } from './review.js';
|
|
14
|
+
/**
|
|
15
|
+
* The row a resolved ref slot's VALUES were read from.
|
|
16
|
+
*
|
|
17
|
+
* ## Why this exists
|
|
18
|
+
*
|
|
19
|
+
* `connection` and `sampling` are both ref slots, and `resolveSlot` returns two
|
|
20
|
+
* different KINDS of thing for them: a connection resolves to a *reference*
|
|
21
|
+
* (`{ id, kind, metadata }` — material is injected at call time), while sampling
|
|
22
|
+
* resolves to the config's *values*, deliberately without an id, because the
|
|
23
|
+
* nodes that read a sampling slot need the numbers. `core:task/context-budget@1`
|
|
24
|
+
* derives the token budget from `contextTokens`, and the summarize batch cutter
|
|
25
|
+
* fits a transcript into that same window.
|
|
26
|
+
*
|
|
27
|
+
* A host, however, does not send values — it sends a request built from a
|
|
28
|
+
* `sampling_configs` ROW, so what it needs from this slot is the row id. It read
|
|
29
|
+
* one off the connection slot's `{ id }` and found nothing on sampling's, which
|
|
30
|
+
* a host cannot distinguish from "this node picked nothing" — so a per-node pick
|
|
31
|
+
* moved the budget while the request went out on the capability default. The
|
|
32
|
+
* budget was computed against one window and the prompt sent against another.
|
|
33
|
+
*
|
|
34
|
+
* ## Why a symbol, and why `Symbol.for`
|
|
35
|
+
*
|
|
36
|
+
* The values object is read by nodes, hashed into a plugin node's RNG label,
|
|
37
|
+
* and written into the receipt. An ordinary key would show up in all three:
|
|
38
|
+
* `Object.keys`, `JSON.stringify` and `for…in` skip symbol keys, so this is
|
|
39
|
+
* invisible to every value reader while object spread — which copies own
|
|
40
|
+
* enumerable symbol properties — still carries it to the host.
|
|
41
|
+
*
|
|
42
|
+
* `Symbol.for` rather than `Symbol()` because the registry is process-wide: two
|
|
43
|
+
* copies of this module (a `dist` build and a source import, say) still agree on
|
|
44
|
+
* the key. A `Symbol()` would differ between them and the reference would vanish
|
|
45
|
+
* again, silently — which is the exact failure mode this whole mechanism exists
|
|
46
|
+
* to end.
|
|
47
|
+
*
|
|
48
|
+
* ⚠ **It does not survive serialization**, by construction. That is safe only
|
|
49
|
+
* because the one consumer — the host's `call` — runs in-process with the
|
|
50
|
+
* binding that forwards it. Plugin node bindings receive their input across a
|
|
51
|
+
* sandbox transport and get no `ctx.call`, so none of them can be on the reading
|
|
52
|
+
* end today. If a plugin node ever gains the ability to dispatch, this reference
|
|
53
|
+
* has to be re-projected at that transport rather than assumed to cross it.
|
|
54
|
+
* @experimental
|
|
55
|
+
*/
|
|
56
|
+
export declare const SLOT_REF: unique symbol;
|
|
57
|
+
/**
|
|
58
|
+
* The row id carried alongside a resolved slot's values, if there is one.
|
|
59
|
+
*
|
|
60
|
+
* Absent means "this node named nothing" — never "the id was lost". Read through
|
|
61
|
+
* this rather than by indexing the symbol, so a host never has to know how the
|
|
62
|
+
* reference is attached.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export declare function slotRef(value: unknown): string | number | null;
|
|
66
|
+
/** @experimental */
|
|
67
|
+
export type Result<T = unknown> = {
|
|
68
|
+
kind: 'ok';
|
|
69
|
+
value: T;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'err';
|
|
72
|
+
reason: string;
|
|
73
|
+
} | {
|
|
74
|
+
kind: 'cancelled';
|
|
75
|
+
reason?: string;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'halt';
|
|
78
|
+
reason: string;
|
|
79
|
+
};
|
|
80
|
+
/** @public */
|
|
81
|
+
export declare const ok: <T>(value: T) => Result<T>;
|
|
82
|
+
/** @experimental */
|
|
83
|
+
export declare const err: (reason: string) => Result<never>;
|
|
84
|
+
/** @public */
|
|
85
|
+
export declare const halt: (reason: string) => Result<never>;
|
|
86
|
+
/** @experimental */
|
|
87
|
+
export declare const cancelled: (reason: string) => Result<never>;
|
|
88
|
+
/**
|
|
89
|
+
* One entry per branch, in **declaration order** — never completion order, which is
|
|
90
|
+
* the same rule 11 §3 already applies to event dispatch, so the system has one
|
|
91
|
+
* ordering rule rather than two.
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
94
|
+
export interface BranchResult {
|
|
95
|
+
branchKey: string;
|
|
96
|
+
index: number;
|
|
97
|
+
result: Result;
|
|
98
|
+
/**
|
|
99
|
+
* junction clauses only (20 §10): whether this branch's predicate selected it.
|
|
100
|
+
* A skipped branch publishes `halt('not selected')` with `fired: false`;
|
|
101
|
+
* the union's `ok`/`values` read the fired branches. Absent on
|
|
102
|
+
* async/map/loop, whose branches all ran by construction.
|
|
103
|
+
*/
|
|
104
|
+
fired?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/** What a clause publishes. `main` aliases `branches` so `$ref(clauseId)` works bare. @experimental */
|
|
107
|
+
export interface BranchResults {
|
|
108
|
+
branches: BranchResult[];
|
|
109
|
+
main: BranchResult[];
|
|
110
|
+
/** The `ok` values in order — what a downstream fold actually wants. */
|
|
111
|
+
values: unknown[];
|
|
112
|
+
ok: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** @experimental */
|
|
115
|
+
export type WriteResult = {
|
|
116
|
+
status: 'committed';
|
|
117
|
+
ids: Record<string, unknown>;
|
|
118
|
+
} | {
|
|
119
|
+
status: 'pending';
|
|
120
|
+
proposalId: string;
|
|
121
|
+
};
|
|
122
|
+
/** @experimental */
|
|
123
|
+
export declare const isCommitted: (w: WriteResult) => w is Extract<WriteResult, {
|
|
124
|
+
status: 'committed';
|
|
125
|
+
}>;
|
|
126
|
+
import type { LogLevel } from './hooks.js';
|
|
127
|
+
import { type StatusText } from './status.js';
|
|
128
|
+
/** @experimental */
|
|
129
|
+
export interface TaskCtx {
|
|
130
|
+
/** Only present when the descriptor declares randomness — keeps Tasks pure (F11). */
|
|
131
|
+
random?: () => number;
|
|
132
|
+
signal: AbortSignal;
|
|
133
|
+
/**
|
|
134
|
+
* Says this node is still making progress (F36).
|
|
135
|
+
*
|
|
136
|
+
* A definition whose `timeoutKind` is `'idle'` is timed on the gap
|
|
137
|
+
* between signs of progress rather than on its whole run: each `pulse()`
|
|
138
|
+
* restarts that window. A long reply streaming steadily never times out;
|
|
139
|
+
* one that goes quiet for the definition's `timeoutMs` does. The instance
|
|
140
|
+
* ceiling (`RunOptions.timeoutCeilingMs`) still bounds the invocation, so
|
|
141
|
+
* pulsing never runs a node forever. On a `'wall'` definition it does
|
|
142
|
+
* nothing — that clock was never about progress.
|
|
143
|
+
*
|
|
144
|
+
* Cheap enough to call on every chunk. The host is handed the same
|
|
145
|
+
* function for the request it performs on a node's behalf
|
|
146
|
+
* (`CallHandles.pulse`), so an oracle that only calls `ctx.call` gets its
|
|
147
|
+
* stream counted without doing anything; call it yourself when the work
|
|
148
|
+
* is your own (a long loop, a read in pages).
|
|
149
|
+
*
|
|
150
|
+
* **Not** `progress` (a message for display, never timed) and **not**
|
|
151
|
+
* `status` (what the person watching is told). Nothing is recorded.
|
|
152
|
+
*
|
|
153
|
+
* Always supplied by the executor; optional on the type for the reason
|
|
154
|
+
* `status` is — an older host and a hand-built ctx in a test are still a
|
|
155
|
+
* `TaskCtx` — so a handler calls it as `ctx.pulse?.()`.
|
|
156
|
+
*
|
|
157
|
+
* ⏳ Core handlers only today: a process-transport plugin hook's ctx
|
|
158
|
+
* carries `{ input }` (see `status`), and its own timeout is the host's.
|
|
159
|
+
*/
|
|
160
|
+
pulse?(): void;
|
|
161
|
+
progress(message: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* What this node is doing, for the person watching (R-19).
|
|
164
|
+
*
|
|
165
|
+
* Callable at any point, by any kind: a query says *{speaker} is
|
|
166
|
+
* thinking*, the oracle five nodes later says *{speaker} is typing*. The
|
|
167
|
+
* text is a locale map with `{vars}`; the client resolves the locale, and
|
|
168
|
+
* `{speaker}` is the one variable the host fills (a handler is blind to
|
|
169
|
+
* who is speaking, and stays so). A status persists until the next one
|
|
170
|
+
* or the run's end; the host hears each change through
|
|
171
|
+
* `RunOptions.onStatus`.
|
|
172
|
+
*
|
|
173
|
+
* **Ephemeral** (F34): never a parameter, never declared on the
|
|
174
|
+
* definition, never a node row on the receipt. The one record the
|
|
175
|
+
* receipt keeps is the *last* status, and only when the run ended
|
|
176
|
+
* `halt`, `err` or `cancelled` — `Receipt.lastStatus`. A malformed text
|
|
177
|
+
* (no `en`) is dropped with a note on the node row rather than failing
|
|
178
|
+
* the node: a typo in a status must never cost somebody their reply.
|
|
179
|
+
*
|
|
180
|
+
* Always supplied by the executor; optional on the type for the same
|
|
181
|
+
* reason `reportCacheUsage` is — an older host, and every hand-built
|
|
182
|
+
* ctx in a test, is still a `TaskCtx` — so a handler calls it as
|
|
183
|
+
* `ctx.status?.(…)`. A status is progress, and progress must never be
|
|
184
|
+
* the reason a handler throws.
|
|
185
|
+
*
|
|
186
|
+
* ⏳ A process-transport plugin hook's ctx carries `{ input }` only
|
|
187
|
+
* today; `ctx.status` is core-handler only until the sandbox ctx is
|
|
188
|
+
* projected (U6). A plugin node calling it sees nothing throw — the
|
|
189
|
+
* optional-chain above is what makes that quiet rather than a crash —
|
|
190
|
+
* it just has no status to set.
|
|
191
|
+
*/
|
|
192
|
+
status?(text: StatusText): void;
|
|
193
|
+
/**
|
|
194
|
+
* Which iteration of an `each` or `loop` body this invocation is —
|
|
195
|
+
* present only inside one, the `random` posture. `index` is 0-based;
|
|
196
|
+
* `count` is how many the `each` has and is absent inside a `loop`,
|
|
197
|
+
* whose `max` is a ceiling rather than a total. Identity for a status
|
|
198
|
+
* (*summarising part 2 of 5*), never a value: the item itself arrives on
|
|
199
|
+
* the port the spec wired.
|
|
200
|
+
*/
|
|
201
|
+
iteration?: {
|
|
202
|
+
index: number;
|
|
203
|
+
count?: number;
|
|
204
|
+
};
|
|
205
|
+
log(level: LogLevel, message: string, detail?: unknown): void;
|
|
206
|
+
/**
|
|
207
|
+
* This run's tokenizer, already loaded and therefore **synchronous**.
|
|
208
|
+
*
|
|
209
|
+
* The same function the wire measurement and the receipt use, so a binding
|
|
210
|
+
* that counts a candidate and the executor that later checks whether the
|
|
211
|
+
* formed payload fits are measuring with one instrument. That is the whole
|
|
212
|
+
* reason it is granted rather than left to each binding: retrieval decides
|
|
213
|
+
* a candidate's cost, ranking spends a budget in those units, and Assemble
|
|
214
|
+
* allocates over the integers they produced — three steps that must agree,
|
|
215
|
+
* and did not while each reached for `roughTokens` independently.
|
|
216
|
+
*
|
|
217
|
+
* Always present. It is `roughTokens` when no tokenizer was configured or
|
|
218
|
+
* the configured one could not be loaded (`RunOptions.tokenizer`), never
|
|
219
|
+
* absent, so a binding never needs a fallback of its own — a binding's own
|
|
220
|
+
* fallback is how the two sides start disagreeing again.
|
|
221
|
+
*/
|
|
222
|
+
countTokens(value: unknown): number;
|
|
223
|
+
/**
|
|
224
|
+
* The interior-point broker (18 §4e) — present **only** when the
|
|
225
|
+
* descriptor declares `scriptPoints` and the host supplied an engine, the
|
|
226
|
+
* `declaresRandomness` posture: which nodes can run scripts, and where, is
|
|
227
|
+
* answerable from the document. The binding provides the *moment*; the
|
|
228
|
+
* user's configuration provides the *content* — a point name is the only
|
|
229
|
+
* thing that can be passed, never script ids, and an undeclared point
|
|
230
|
+
* throws. Applications land in the receipt marked `appliedBy: 'binding'`.
|
|
231
|
+
*
|
|
232
|
+
* `apply` is the broker: whatever the point's kinds flow — a string, a
|
|
233
|
+
* selection, a cast — goes in and the chain's fold comes back, or the
|
|
234
|
+
* input unchanged when nothing was attached. `applyText` is the
|
|
235
|
+
* text-only spelling it began as (18 §4e, v1), kept as a typed alias.
|
|
236
|
+
*/
|
|
237
|
+
scripts?: {
|
|
238
|
+
apply(point: string, value: unknown): Promise<unknown>;
|
|
239
|
+
applyText(point: string, text: string): Promise<string>;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** @experimental */
|
|
243
|
+
export interface QueryCtx extends TaskCtx {
|
|
244
|
+
read(table: string, q?: unknown): unknown;
|
|
245
|
+
}
|
|
246
|
+
/** @experimental */
|
|
247
|
+
export interface OracleCtx<Caps extends CapabilityId = CapabilityId> extends TaskCtx {
|
|
248
|
+
/** Material is injected here per call and never readable from config. */
|
|
249
|
+
call(payload: unknown): Promise<unknown>;
|
|
250
|
+
connectionMetadata: Record<string, unknown>;
|
|
251
|
+
sampling: Record<string, unknown>;
|
|
252
|
+
reportUsage(tokens: number): void;
|
|
253
|
+
reportSampling(applied: Record<string, unknown>, ignored: string[]): void;
|
|
254
|
+
/**
|
|
255
|
+
* What the provider REPORTED about this call's prompt, as opposed to what
|
|
256
|
+
* the run spent on it (`reportUsage`).
|
|
257
|
+
*
|
|
258
|
+
* ⚠ **Recording only.** Nothing here is charged to the budget, nothing is
|
|
259
|
+
* reordered, and a binding that calls this has changed no request. It exists
|
|
260
|
+
* so "is the prompt caching I am paying for actually happening" has an
|
|
261
|
+
* answer on the receipt instead of nowhere.
|
|
262
|
+
*
|
|
263
|
+
* ⚠ **Pass only the numbers the service actually gave.** An absent field
|
|
264
|
+
* stays absent on the receipt: "does not report reuse" and "reused nothing"
|
|
265
|
+
* are opposite findings and a zero collapses them.
|
|
266
|
+
*
|
|
267
|
+
* Optional so that an older host, and every hand-built ctx in a test, is
|
|
268
|
+
* still a `OracleCtx` — the binding calls it as `ctx.reportCacheUsage?.()`.
|
|
269
|
+
*/
|
|
270
|
+
reportCacheUsage?(usage: {
|
|
271
|
+
prompt?: number;
|
|
272
|
+
cached?: number;
|
|
273
|
+
cacheWrite?: number;
|
|
274
|
+
}): void;
|
|
275
|
+
/**
|
|
276
|
+
* Is this capability available on the connection actually bound?
|
|
277
|
+
*
|
|
278
|
+
* Returns the GRADE rather than a boolean, so a binding can tell "the API
|
|
279
|
+
* does this itself" from "we are emulating it" — the two have different costs
|
|
280
|
+
* and sometimes different output. `false` means no, and 0 never escapes as a
|
|
281
|
+
* grade, so a plain truthiness test is correct.
|
|
282
|
+
*
|
|
283
|
+
* A grade is read against the capability's own bands (`topGrade(id)` is its
|
|
284
|
+
* best), never against a global scale: `1` is a middling `tools` and the very
|
|
285
|
+
* best `text->image` there is.
|
|
286
|
+
*
|
|
287
|
+
* **Only the ids this node declared `optional` are askable.** A `requires` id
|
|
288
|
+
* is guaranteed by the time a binding runs — asking would be dead code — and
|
|
289
|
+
* an undeclared id is a question the node has no business asking, so both are
|
|
290
|
+
* compile errors when the binding is written through `providerBinding()`.
|
|
291
|
+
*
|
|
292
|
+
* The fallback is the author's to write. That is the ruling: the type system
|
|
293
|
+
* makes absence impossible to *forget about*, and what to do instead is a
|
|
294
|
+
* decision only the author can make.
|
|
295
|
+
*/
|
|
296
|
+
can(id: Caps): Grade | false;
|
|
297
|
+
}
|
|
298
|
+
/** @experimental */
|
|
299
|
+
export interface OutletCtx extends TaskCtx {
|
|
300
|
+
commit(payload: unknown): Promise<Record<string, unknown>>;
|
|
301
|
+
emit(handle: string, payload: unknown): void;
|
|
302
|
+
}
|
|
303
|
+
/** @experimental */
|
|
304
|
+
export type Hook = (input: any, ctx: any) => Result | Promise<Result>;
|
|
305
|
+
/**
|
|
306
|
+
* An oracle handler, with `ctx.can()` narrowed to what its own definition declared.
|
|
307
|
+
*
|
|
308
|
+
* The one hop that matters. `pin` already carries the descriptor's literal type
|
|
309
|
+
* through, so reading `optional` off it here is enough — there is no need to
|
|
310
|
+
* thread capability generics through a catalog and a binding map, and every hop
|
|
311
|
+
* that does not exist is a hop that cannot silently widen to `string` and take
|
|
312
|
+
* the safety with it.
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* providerBinding(C.generateText, async (input, ctx) => {
|
|
316
|
+
* ctx.can('json_schema') // ✅ declared optional on the connection slot
|
|
317
|
+
* ctx.can('grammar') // ❌ compile error — this node never declared it
|
|
318
|
+
* })
|
|
319
|
+
* ```
|
|
320
|
+
* @experimental
|
|
321
|
+
*/
|
|
322
|
+
export declare function providerBinding<D extends {
|
|
323
|
+
slots?: Record<string, {
|
|
324
|
+
optional?: readonly CapabilityId[];
|
|
325
|
+
}>;
|
|
326
|
+
}>(_type: {
|
|
327
|
+
descriptor: D;
|
|
328
|
+
}): (fn: (input: any, ctx: OracleCtx<OptionalCapsOf<D['slots']>>) => Result | Promise<Result>) => Hook;
|
|
329
|
+
/** @experimental */
|
|
330
|
+
export interface Bindings {
|
|
331
|
+
[definitionIdAtVersion: string]: Hook;
|
|
332
|
+
}
|
|
333
|
+
/** @internal */
|
|
334
|
+
export declare function seededRandom(seed: string): () => number;
|
|
335
|
+
/**
|
|
336
|
+
* One node invocation, starting or settling. Identity only — no payloads, no
|
|
337
|
+
* values: this exists so a progress card can say "step 3 of 7 · drafting",
|
|
338
|
+
* and anything richer belongs to the receipt.
|
|
339
|
+
* @experimental
|
|
340
|
+
*/
|
|
341
|
+
export interface NodeEvent {
|
|
342
|
+
phase: 'start' | 'end';
|
|
343
|
+
nodeKey: string;
|
|
344
|
+
definitionId: string;
|
|
345
|
+
/**
|
|
346
|
+
* The node's kind, typed so a consumer that compares it against a
|
|
347
|
+
* spelling the vocabulary has since retired fails to compile rather than
|
|
348
|
+
* silently never matching (the U3 rename left one progress card dead).
|
|
349
|
+
*/
|
|
350
|
+
kind: Kind;
|
|
351
|
+
/** Invocations begun so far — a done-count, monotonic within the run. */
|
|
352
|
+
seq: number;
|
|
353
|
+
/**
|
|
354
|
+
* Nodes the document declares. A floor, not a total: map fan-out adds
|
|
355
|
+
* invocations at runtime, so `seq` may legitimately pass it.
|
|
356
|
+
*/
|
|
357
|
+
declared: number;
|
|
358
|
+
iteration?: number;
|
|
359
|
+
/** Present on `end`. */
|
|
360
|
+
result?: Result['kind'];
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* One declared hook, as the applier sees it: the address, the phase, and the
|
|
364
|
+
* declaration's attachment rule. The executor computes this from the type's
|
|
365
|
+
* `scripts` slot; the applier never reads a descriptor.
|
|
366
|
+
* @experimental
|
|
367
|
+
*/
|
|
368
|
+
export interface ScriptHookSite {
|
|
369
|
+
nodeKey: string;
|
|
370
|
+
definitionId: string;
|
|
371
|
+
slot: string;
|
|
372
|
+
phase: 'before' | 'after';
|
|
373
|
+
port: string;
|
|
374
|
+
accepts: string[];
|
|
375
|
+
extras: string[];
|
|
376
|
+
/**
|
|
377
|
+
* Who triggered the application: the executor at a declared port hook
|
|
378
|
+
* (`substrate`, the default), or a binding invoking a declared interior
|
|
379
|
+
* point through `ctx.scripts` (`binding`, 18 §4e). The applier records it
|
|
380
|
+
* per link, so hook interiors letting user policy in stay visible.
|
|
381
|
+
*/
|
|
382
|
+
origin?: 'substrate' | 'binding';
|
|
383
|
+
}
|
|
384
|
+
/** @experimental */
|
|
385
|
+
export interface ScriptChainOutcome {
|
|
386
|
+
value: unknown;
|
|
387
|
+
applications: ScriptApplicationRecord[];
|
|
388
|
+
/**
|
|
389
|
+
* What the applier had to say about the chain AS A WHOLE, beside the
|
|
390
|
+
* per-link records — a value it declined to hand on, say. Folded into the
|
|
391
|
+
* node's `notes` on the receipt, so a reader finds it where the node's
|
|
392
|
+
* other asides are rather than under a link that did nothing wrong.
|
|
393
|
+
*/
|
|
394
|
+
notes?: string[];
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* The host's script engine, behind a seam (18 §4a, §7).
|
|
398
|
+
*
|
|
399
|
+
* The executor owns *where* chains apply — the substrate placement that keeps
|
|
400
|
+
* a binding unable to see or decline one — and the host owns *how* a script
|
|
401
|
+
* runs, because the sandbox is an engine choice the SDK must not embed. The
|
|
402
|
+
* contract the applier must keep is 18's law set: a failing link degrades
|
|
403
|
+
* (S2 — skip it, record `err`, continue), transforms fold in order, verdicts
|
|
404
|
+
* reduce to the earliest index, and every link comes back as an application
|
|
405
|
+
* record whatever happened. A *thrown* applier is treated as engine failure:
|
|
406
|
+
* the value passes through unchanged and the failure is recorded — a broken
|
|
407
|
+
* engine must never cost somebody their reply, and must never vanish either.
|
|
408
|
+
* @experimental
|
|
409
|
+
*/
|
|
410
|
+
export type ScriptChainApplier = (site: ScriptHookSite,
|
|
411
|
+
/** The resolved slot value — an ordered list of script row ids. */
|
|
412
|
+
chain: unknown,
|
|
413
|
+
/** The current value at the site's port. */
|
|
414
|
+
value: unknown) => Promise<ScriptChainOutcome>;
|
|
415
|
+
/** A run's place in a tree of runs — see `RunOptions.lineage`. @experimental */
|
|
416
|
+
export interface RunLineage {
|
|
417
|
+
parentRunId: string;
|
|
418
|
+
rootRunId: string;
|
|
419
|
+
/** 0 for a root; a child is its parent's depth plus one. */
|
|
420
|
+
depth: number;
|
|
421
|
+
}
|
|
422
|
+
/** @experimental */
|
|
423
|
+
export interface RunOptions {
|
|
424
|
+
input: unknown;
|
|
425
|
+
bindings: Bindings;
|
|
426
|
+
world?: ConfigWorld;
|
|
427
|
+
seed?: string;
|
|
428
|
+
runId?: string;
|
|
429
|
+
triggerSource?: Receipt['triggerSource'];
|
|
430
|
+
triggerRef?: string;
|
|
431
|
+
actorUserId?: string;
|
|
432
|
+
/**
|
|
433
|
+
* Who portrays each participant this run concerns — the host's answer,
|
|
434
|
+
* resolved before `run` is called and stamped on the receipt at
|
|
435
|
+
* construction, so it is pinned before the first node (R-21 (4)). The
|
|
436
|
+
* executor never reads it and no node can: a definition that needs the
|
|
437
|
+
* answer declares an in-port and the host wires it.
|
|
438
|
+
*/
|
|
439
|
+
portrayals?: Receipt['portrayals'];
|
|
440
|
+
/**
|
|
441
|
+
* The swaps the host seated before calling `run`, by node key: the
|
|
442
|
+
* document's `definitionId` there is already the swap, and this names the
|
|
443
|
+
* pin it replaced and whose choice it was. Recorded on that node's row as
|
|
444
|
+
* `swap`; every other node's row says `swap: null` — the pin ran. Pass
|
|
445
|
+
* `{}` when nothing was swapped; left out, rows carry no `swap` at all,
|
|
446
|
+
* because the executor cannot tell a pin from a swap it was not told
|
|
447
|
+
* about. The executor never resolves a swap itself.
|
|
448
|
+
* @experimental 🚧
|
|
449
|
+
*/
|
|
450
|
+
swaps?: Record<string, NodeSwap>;
|
|
451
|
+
/**
|
|
452
|
+
* Host facts about how the run was reached (`ReceiptMeta`), recorded
|
|
453
|
+
* verbatim on the receipt at construction.
|
|
454
|
+
* @experimental 🚧
|
|
455
|
+
*/
|
|
456
|
+
meta?: ReceiptMeta;
|
|
457
|
+
/**
|
|
458
|
+
* Where this run stands in a tree of runs (01 §8 *lineage*): the run
|
|
459
|
+
* that dispatched it, the root of the tree, and how deep. Stamped on the
|
|
460
|
+
* receipt at construction as `parentRunId`, `rootRunId` and `depth`; a
|
|
461
|
+
* run nothing dispatched is its own root at depth 0. The host enforces
|
|
462
|
+
* the per-root caps at dispatch (`form-addressed`, U5d) and reads these
|
|
463
|
+
* back off the receipt; the executor only records them.
|
|
464
|
+
*/
|
|
465
|
+
lineage?: RunLineage;
|
|
466
|
+
/**
|
|
467
|
+
* Instance ceiling — config may not exceed it (F36). Caps every
|
|
468
|
+
* definition's `timeoutMs`, and is also the absolute bound on an `idle`
|
|
469
|
+
* definition's invocation: pulses restart its window, never this.
|
|
470
|
+
*/
|
|
471
|
+
timeoutCeilingMs?: number;
|
|
472
|
+
/** Force every clause sequential, as an admin may (01 §4). */
|
|
473
|
+
forceSequential?: boolean;
|
|
474
|
+
budget?: {
|
|
475
|
+
tokens?: number;
|
|
476
|
+
nodeExecutions?: number;
|
|
477
|
+
};
|
|
478
|
+
/** Which subscribers core would dispatch to, for the emitted record. */
|
|
479
|
+
subscribers?: Record<string, number>;
|
|
480
|
+
/** Simulated wait — never counted against a timeout (01 §5). */
|
|
481
|
+
now?: () => number;
|
|
482
|
+
/** Host-supplied review resolver. `sync` parks on it; waiting is free (F13). */
|
|
483
|
+
reviewer?: Reviewer;
|
|
484
|
+
/**
|
|
485
|
+
* Host-supplied script engine (18 §4a). Absent means no chains apply —
|
|
486
|
+
* a host that has not built the sandbox runs every spec exactly as before,
|
|
487
|
+
* which is what makes this seam additive.
|
|
488
|
+
*/
|
|
489
|
+
applyScripts?: ScriptChainApplier;
|
|
490
|
+
/**
|
|
491
|
+
* Node lifecycle observation, for progress display and nothing else.
|
|
492
|
+
*
|
|
493
|
+
* Fired as each node's invocation starts and again when it settles, with
|
|
494
|
+
* enough identity to drive a progress card — never the payload. Progress is
|
|
495
|
+
* not a second receipt: it carries no values, it is not recorded, and a
|
|
496
|
+
* host that wants what ran reads the receipt afterwards (F34). Inherent to
|
|
497
|
+
* every run rather than wired per trigger, which is what lets any UI show
|
|
498
|
+
* "step 3 of 7" without knowing what the pipeline does.
|
|
499
|
+
*/
|
|
500
|
+
onNode?: (event: NodeEvent) => void;
|
|
501
|
+
/**
|
|
502
|
+
* A node set its status (R-19) — `ctx.status` on any kind's ctx.
|
|
503
|
+
*
|
|
504
|
+
* Fired with the node's key and the text as the handler wrote it: the
|
|
505
|
+
* host fills `{speaker}` (`HOST_FILLED_STATUS_VARS`), routes the text to
|
|
506
|
+
* the run's live row, its progress card and the session list, and
|
|
507
|
+
* resolves nothing — the locale is the client's. Fired only when the
|
|
508
|
+
* text CHANGES: a second node repeating the status the first set is not
|
|
509
|
+
* a new status, and six parallel retrieval reads all saying *thinking*
|
|
510
|
+
* are one status, not six. Ephemeral like `onNode` (F34): not recorded,
|
|
511
|
+
* except as `Receipt.lastStatus` on a run that did not end `ok`. An
|
|
512
|
+
* observer that throws is its own problem.
|
|
513
|
+
*/
|
|
514
|
+
onStatus?: (nodeKey: string, text: StatusText) => void;
|
|
515
|
+
/**
|
|
516
|
+
* Time this run sat in the admin-visible queue before being dequeued (13 §3).
|
|
517
|
+
* Recorded, and deliberately **not** added to any elapsed figure: queue wait
|
|
518
|
+
* consumes no budget (F13) and trips no timeout (F36) — a run's clock starts
|
|
519
|
+
* when it is dequeued.
|
|
520
|
+
*/
|
|
521
|
+
queuedMs?: number;
|
|
522
|
+
/**
|
|
523
|
+
* Checked between nodes. Returning a value stops the run as `cancelled`, with the
|
|
524
|
+
* actor recorded — so "an admin stopped it" stays distinguishable from "it broke",
|
|
525
|
+
* which is why there are four result kinds rather than three (13 §3).
|
|
526
|
+
*/
|
|
527
|
+
cancelSignal?: () => {
|
|
528
|
+
by: string;
|
|
529
|
+
reason: string;
|
|
530
|
+
} | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* Compact a receipt that halts before any effectful node: trigger, spec version,
|
|
533
|
+
* halt node/reason and elapsed, with no payloads and no node rows (13 §2).
|
|
534
|
+
*
|
|
535
|
+
* Defaults to on **for event-triggered runs only**. That is where the multiplier
|
|
536
|
+
* lives — a hot event × every subscribed pipeline × every message, where most
|
|
537
|
+
* subscribers halt immediately and that is success (01 §5). A run someone started
|
|
538
|
+
* by clicking happens once per click and keeps its full detail.
|
|
539
|
+
*/
|
|
540
|
+
compactHaltReceipts?: boolean;
|
|
541
|
+
/**
|
|
542
|
+
* Debug mode in chat: run normally, then **halt at the pre-call substrate** instead of
|
|
543
|
+
* invoking the oracle — after the input resolves and the payload is formed, so the
|
|
544
|
+
* numbers shown are the numbers that would have been sent (src/preview.ts).
|
|
545
|
+
*
|
|
546
|
+
* `true` stops at the first oracle **on the spine**; pass `atNode` to override. The
|
|
547
|
+
* preview costs whatever ran before it, including the embedding call inside the gather
|
|
548
|
+
* block — a preview that skipped retrieval would show a context nobody would get.
|
|
549
|
+
*
|
|
550
|
+
* A preview is a **dry run** unless `dry` says otherwise — see there. The
|
|
551
|
+
* pipeline creates its own reply row now (R-17), as an outlet placed before
|
|
552
|
+
* the oracle; a preview that committed it would leave a row behind for
|
|
553
|
+
* every token estimate.
|
|
554
|
+
*/
|
|
555
|
+
preview?: boolean | {
|
|
556
|
+
atNode?: string;
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* Perform no writes (R-21 (1), F36).
|
|
560
|
+
*
|
|
561
|
+
* Every outlet still runs — its binding is invoked, its payload is formed,
|
|
562
|
+
* the review gate still sees it — but `ctx.commit` returns a **synthetic
|
|
563
|
+
* id** (`dry:<nodeKey>`) instead of reaching the host, `ctx.emit` reaches
|
|
564
|
+
* nothing, the node row is marked `dry: true`, and the event the write
|
|
565
|
+
* would have caused is recorded flagged `dry` rather than as emitted.
|
|
566
|
+
* Downstream nodes read the synthetic id exactly as they would a real one,
|
|
567
|
+
* so the run's shape is the shape a real run has.
|
|
568
|
+
*
|
|
569
|
+
* Defaults to `true` when `preview` is set and `false` otherwise. Pass it
|
|
570
|
+
* explicitly to run a document to completion without leaving anything
|
|
571
|
+
* behind — the oracle is still called, because nothing here is a stand-in
|
|
572
|
+
* for the model.
|
|
573
|
+
*
|
|
574
|
+
* ⚠ **For a plugin author:** a preview of your spec performs none of its
|
|
575
|
+
* writes, including any outlet you placed *before* the node the preview
|
|
576
|
+
* halts at — that outlet runs, its binding is invoked, and its commit is
|
|
577
|
+
* a synthetic id. If a downstream node in your spec needs a real row to
|
|
578
|
+
* exist during a preview, that is a design to reconsider rather than a
|
|
579
|
+
* flag to flip: there is no per-outlet exemption, and `dry: false` on a
|
|
580
|
+
* preview is the host's call, not the document's.
|
|
581
|
+
*/
|
|
582
|
+
dry?: boolean;
|
|
583
|
+
/**
|
|
584
|
+
* The run has ended, whatever way it ended.
|
|
585
|
+
*
|
|
586
|
+
* Called exactly once, after the receipt is final and before it is
|
|
587
|
+
* returned, with the outcome and the run's **live row** — the row the most
|
|
588
|
+
* recent live-row outlet committed (see `Descriptor.liveRow`). This is the
|
|
589
|
+
* one seam a host has for the guarantee no node can give: a run stopped
|
|
590
|
+
* mid-stream has nothing left to run, so the row its placeholder created
|
|
591
|
+
* would stay generating forever unless the host finalises it here. The
|
|
592
|
+
* partial text is the host's — it owns the stream — which is why the
|
|
593
|
+
* summary carries the row and not the text.
|
|
594
|
+
*
|
|
595
|
+
* Awaited, so a host can finish its row before the receipt is stored. A
|
|
596
|
+
* throwing hook is absorbed: finalising a row is the host's promise to its
|
|
597
|
+
* users, and a broken promise must not also cost the receipt.
|
|
598
|
+
*
|
|
599
|
+
* **Whatever way it ended** includes the run throwing. A host seam that
|
|
600
|
+
* fails outside a binding — a reviewer, a slot resolution — propagates
|
|
601
|
+
* out of `run`, and before this was a `finally` it propagated past the
|
|
602
|
+
* hook, so the placeholder a fresh turn had made stayed generating with
|
|
603
|
+
* nobody left to finish it. Now the hook fires first with `kind: 'err'`
|
|
604
|
+
* and `error` set to the thrown object, and the throw continues after it.
|
|
605
|
+
*/
|
|
606
|
+
onRunEnd?: (end: RunEnd) => void | Promise<void>;
|
|
607
|
+
/**
|
|
608
|
+
* Which tokenizer this run budgets with — an **id**, not a function.
|
|
609
|
+
*
|
|
610
|
+
* The id core stores on the connection (`connections.token_counter`), passed
|
|
611
|
+
* through unchanged. `run` resolves it before the clock starts: loading is
|
|
612
|
+
* asynchronous and happens once, here; counting is synchronous everywhere
|
|
613
|
+
* after, which is what lets the allocation and wire-measurement loops stay
|
|
614
|
+
* loops (see `src/tokenizers.ts` for why that split is the whole design).
|
|
615
|
+
*
|
|
616
|
+
* An id nobody registered a loader for, or one whose loader throws, degrades
|
|
617
|
+
* to `roughTokens` and says so in `receipt.notes`. A tokenizer never fails a
|
|
618
|
+
* run.
|
|
619
|
+
*/
|
|
620
|
+
tokenizer?: string;
|
|
621
|
+
/**
|
|
622
|
+
* A counter supplied directly, bypassing `tokenizer`.
|
|
623
|
+
*
|
|
624
|
+
* Predates `tokenizer` and still honoured, because a test that wants a
|
|
625
|
+
* deterministic count should not have to register a loader to get one — the
|
|
626
|
+
* SDK's own preview suite passes a counter that returns 999_999 for objects
|
|
627
|
+
* precisely to prove the wire measurement is what the receipt reports.
|
|
628
|
+
*
|
|
629
|
+
* **Wins when both are given.** An explicit function is a more specific
|
|
630
|
+
* instruction than an id to look up, and the precedence has to be stated
|
|
631
|
+
* somewhere rather than discovered. A host should pass `tokenizer`: an id is
|
|
632
|
+
* a fact that lands in configuration and in the receipt, where a closure is
|
|
633
|
+
* neither.
|
|
634
|
+
*/
|
|
635
|
+
countTokens?: (v: unknown) => number;
|
|
636
|
+
/**
|
|
637
|
+
* The host's I/O, injected into the per-kind contexts (see `HostServices`).
|
|
638
|
+
*
|
|
639
|
+
* Absent, every service is the in-memory stand-in this draft has always used —
|
|
640
|
+
* which is what keeps the SDK's own suite hermetic. Present, a Query's `read`
|
|
641
|
+
* reaches a real database and an outlet's `commit` writes a real row.
|
|
642
|
+
*/
|
|
643
|
+
host?: HostServices;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* What only the host can do.
|
|
647
|
+
*
|
|
648
|
+
* The executor owns *sequencing*; it has never owned *I/O*, and the split is why the
|
|
649
|
+
* same executor can run in an author's test with no database and in core against a
|
|
650
|
+
* live one. Until this existed, core's only way to reach a database from a binding was
|
|
651
|
+
* to close over a connection — which works, and quietly moves the effect outside the
|
|
652
|
+
* substrate that the review gate, the budget and the receipt all sit in.
|
|
653
|
+
*
|
|
654
|
+
* So the shape here is deliberate: **a binding describes the effect and the host
|
|
655
|
+
* performs it.** An outlet returns what it wants written, and `commit` writes it. That
|
|
656
|
+
* is already how a sidecar outlet has to work (F19 — no DB channel across a process
|
|
657
|
+
* boundary), and having in-process and out-of-process outlets obey the same rule
|
|
658
|
+
* means the review gate sees the same thing in both cases: a payload, before anything
|
|
659
|
+
* happened.
|
|
660
|
+
* @experimental
|
|
661
|
+
*/
|
|
662
|
+
export interface HostServices {
|
|
663
|
+
/** Scoped read for a Query. The node is passed so the host can enforce scope (F30). */
|
|
664
|
+
read?(table: string, query: unknown, node: NodeRef): unknown | Promise<unknown>;
|
|
665
|
+
/** Perform an outlet's described write and return the row identity. */
|
|
666
|
+
commit?(payload: unknown, node: NodeRef): Promise<Record<string, unknown>>;
|
|
667
|
+
/**
|
|
668
|
+
* Dispatch an oracle call. Credentials are injected here and never readable (F18).
|
|
669
|
+
*
|
|
670
|
+
* `run` carries the run-level facts a call may need and a node may not
|
|
671
|
+
* see — today the **live row** (R-21 (2)). Streaming is run-level: the
|
|
672
|
+
* oracle publishes its stream and stays blind to messages; the host routes
|
|
673
|
+
* it to the row this run's placeholder created, if there is one. Passed on
|
|
674
|
+
* every call rather than kept anywhere a binding could read.
|
|
675
|
+
*
|
|
676
|
+
* `handles` is the calling node's own: its signal, which aborts when the
|
|
677
|
+
* node's clock runs out, and its `pulse`. A host performing a request
|
|
678
|
+
* listens to the first (together with its own cancel) and calls the
|
|
679
|
+
* second on every sign of life — see `CallHandles`. The executor always
|
|
680
|
+
* passes them; optional so a host can still be driven directly, as a test
|
|
681
|
+
* does, with no node clock behind the call. A host that wraps another
|
|
682
|
+
* must forward them.
|
|
683
|
+
*/
|
|
684
|
+
call?(payload: unknown, node: NodeRef, run: RunFacts, handles?: CallHandles): Promise<unknown>;
|
|
685
|
+
/** Core emits; a node only names the handle (F8). */
|
|
686
|
+
emit?(handle: string, payload: unknown, node: NodeRef): void;
|
|
687
|
+
/**
|
|
688
|
+
* Connection **metadata** for an oracle — readable. Material is never returned
|
|
689
|
+
* here; it is applied inside `call` and never crosses into a binding (F18).
|
|
690
|
+
*/
|
|
691
|
+
connection?(node: NodeRef): {
|
|
692
|
+
metadata?: Record<string, unknown>;
|
|
693
|
+
sampling?: Record<string, unknown>;
|
|
694
|
+
/**
|
|
695
|
+
* What the bound connection can actually do — the resolved set, never the
|
|
696
|
+
* declaration. Readable like `metadata` and for the same reason: a binding
|
|
697
|
+
* has to be able to take a different path when a capability is absent, and
|
|
698
|
+
* it cannot do that from a fact it is not told.
|
|
699
|
+
*/
|
|
700
|
+
capabilities?: CapabilitySet;
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
/** @experimental */
|
|
704
|
+
export interface NodeRef {
|
|
705
|
+
key: string;
|
|
706
|
+
definitionId: string;
|
|
707
|
+
definitionVersion: number;
|
|
708
|
+
kind: string;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* What the executor knows about the run as a whole, handed to the host.
|
|
712
|
+
*
|
|
713
|
+
* **Not** a value: nothing here lands on a port or in a node's input, which
|
|
714
|
+
* is what keeps the oracle blind to messages. A binding asks for text and gets
|
|
715
|
+
* text; the host, which is the one party that can write a row, is told which
|
|
716
|
+
* row this run is currently filling.
|
|
717
|
+
* @experimental
|
|
718
|
+
*/
|
|
719
|
+
export interface RunFacts {
|
|
720
|
+
/**
|
|
721
|
+
* The row the most recent live-row outlet committed in this run
|
|
722
|
+
* (`Descriptor.liveRow`), or undefined when none has. A create → update
|
|
723
|
+
* pair on one row inside one run is one primary row (01 §7 restated, R-17);
|
|
724
|
+
* this is that row while the run is between the two.
|
|
725
|
+
*/
|
|
726
|
+
liveRow?: string | number;
|
|
727
|
+
/** Whether this run performs writes — see `RunOptions.dry`. */
|
|
728
|
+
dry: boolean;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* The calling node's own handles on one `HostServices.call` — as opposed to
|
|
732
|
+
* `RunFacts`, which are the run's.
|
|
733
|
+
*
|
|
734
|
+
* A request the host performs for an oracle is the oracle's work as far as
|
|
735
|
+
* its clock is concerned (F36), and only the host sees that work happen: the
|
|
736
|
+
* stream's chunks, the wait for a model server's queue, a model loading. So
|
|
737
|
+
* the executor hands over both ends of the clock.
|
|
738
|
+
* @experimental
|
|
739
|
+
*/
|
|
740
|
+
export interface CallHandles {
|
|
741
|
+
/**
|
|
742
|
+
* Aborts when the node's clock runs out (`timeoutMs`). Abort the request
|
|
743
|
+
* on it — combined with the run's own cancel, e.g. `AbortSignal.any` — or
|
|
744
|
+
* a timed-out node leaves the model server generating into nothing.
|
|
745
|
+
*/
|
|
746
|
+
signal: AbortSignal;
|
|
747
|
+
/**
|
|
748
|
+
* The node's `ctx.pulse` (see `TaskCtx.pulse`): call it on every sign that
|
|
749
|
+
* the request is alive. Restarts an `idle` clock; does nothing to a `wall`
|
|
750
|
+
* one.
|
|
751
|
+
*/
|
|
752
|
+
pulse(): void;
|
|
753
|
+
}
|
|
754
|
+
/** What `RunOptions.onRunEnd` is told. @experimental */
|
|
755
|
+
export interface RunEnd extends RunFacts {
|
|
756
|
+
kind: Outcome;
|
|
757
|
+
receipt: Receipt;
|
|
758
|
+
/**
|
|
759
|
+
* What the run THREW, when it ended by throwing rather than by a node's
|
|
760
|
+
* verdict — a host seam that failed outside any binding's try (a reviewer
|
|
761
|
+
* that could not push its form, a slot that would not resolve). `kind` is
|
|
762
|
+
* `err` and the receipt carries the message; this is the object, for a
|
|
763
|
+
* host whose redaction rule needs the class. Absent on every other end.
|
|
764
|
+
*/
|
|
765
|
+
error?: unknown;
|
|
766
|
+
}
|
|
767
|
+
/** @experimental */
|
|
768
|
+
export declare function run(doc: SpecDocument, opts: RunOptions): Promise<Receipt>;
|
|
769
|
+
/** replay(receipt) — deterministic, never re-infers (F16). @experimental */
|
|
770
|
+
export declare function replay(doc: SpecDocument, receipt: Receipt, bindings: Bindings): Promise<Receipt>;
|
|
771
|
+
//# sourceMappingURL=executor.d.ts.map
|