@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,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Receipts (01 §1, 02 §2). The first-class record of a run, and the thing the
|
|
3
|
+
* whole design's explicability claim rests on.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately absent: progress messages (F34, ephemeral) and raw embedding
|
|
6
|
+
* vectors (16 §1a, recorded by reference).
|
|
7
|
+
*/
|
|
8
|
+
import type { ScopeKind } from './config.js';
|
|
9
|
+
/** @experimental */
|
|
10
|
+
export type Outcome = 'ok' | 'err' | 'cancelled' | 'halt';
|
|
11
|
+
/** @experimental */
|
|
12
|
+
export interface NodeReceipt {
|
|
13
|
+
nodeKey: string;
|
|
14
|
+
seq: number;
|
|
15
|
+
kind: string;
|
|
16
|
+
definitionId: string;
|
|
17
|
+
result: Outcome;
|
|
18
|
+
startedAt: number;
|
|
19
|
+
endedAt: number;
|
|
20
|
+
elapsedMs: number;
|
|
21
|
+
input?: unknown;
|
|
22
|
+
output?: unknown;
|
|
23
|
+
/** halt/err detail — "why did nothing happen" is otherwise unanswerable (01 §5). */
|
|
24
|
+
reason?: string;
|
|
25
|
+
attempts?: number;
|
|
26
|
+
cacheHit?: boolean;
|
|
27
|
+
blockMode?: 'sequential' | 'parallel';
|
|
28
|
+
/** Which map iteration produced this entry (01 §4). */
|
|
29
|
+
iteration?: number;
|
|
30
|
+
timeoutMsApplied?: number;
|
|
31
|
+
timedOut?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The node failed, its type declares `optional`, and the run continued with
|
|
34
|
+
* an empty value. `result` and `reason` still say what happened — this is
|
|
35
|
+
* the flag that stops that reading as a success.
|
|
36
|
+
*/
|
|
37
|
+
recoveredAsEmpty?: boolean;
|
|
38
|
+
/** Which sampler fields the adapter honoured vs dropped (12 §2). */
|
|
39
|
+
samplingApplied?: Record<string, unknown>;
|
|
40
|
+
samplingIgnored?: string[];
|
|
41
|
+
/** Provider only — recorded verbatim (F16). */
|
|
42
|
+
request?: unknown;
|
|
43
|
+
response?: unknown;
|
|
44
|
+
tokens?: number;
|
|
45
|
+
/**
|
|
46
|
+
* What the PROMPT cost, as the service counted it — not this app's estimate.
|
|
47
|
+
*
|
|
48
|
+
* Beside `tokens` rather than folded into it: `tokens` is what the run SPENT
|
|
49
|
+
* against its budget, and these three are what the provider REPORTED about
|
|
50
|
+
* one call. Nothing here is charged to anything.
|
|
51
|
+
*/
|
|
52
|
+
tokensPrompt?: number;
|
|
53
|
+
/**
|
|
54
|
+
* How much of that prompt the service served from a cached prefix.
|
|
55
|
+
*
|
|
56
|
+
* ⚠ **Absent is not zero.** "This connection does not report reuse" and
|
|
57
|
+
* "nothing was reused" are opposite findings, and a 0 written over the first
|
|
58
|
+
* tells a reader their cache is broken when the truth is that their service
|
|
59
|
+
* never says. Several do not.
|
|
60
|
+
*/
|
|
61
|
+
tokensCached?: number;
|
|
62
|
+
/** Tokens WRITTEN to the cache, where a service bills the two halves apart. */
|
|
63
|
+
tokensCacheWrite?: number;
|
|
64
|
+
/** Resolved config reference, e.g. oracleRef → 'generate' (16 §5b-i). */
|
|
65
|
+
resolvedRefs?: Record<string, string>;
|
|
66
|
+
/**
|
|
67
|
+
* Which layer each of this node's config values won at, per slot, per
|
|
68
|
+
* path: `configLayers.params.weight === 'session'`. The same answer the
|
|
69
|
+
* resolver computes (`ResolvedSource.scopeKind`) and the config panel shows,
|
|
70
|
+
* kept rather than discarded — *"I changed this and nothing happened"* is
|
|
71
|
+
* answered by the row that ran. Values only; the layer's owner
|
|
72
|
+
* (`scopeId`) is not recorded.
|
|
73
|
+
*
|
|
74
|
+
* Absent on a receipt written before 2026-09-26, and on a node with no
|
|
75
|
+
* resolved config at all. A path absent here was never resolved: the
|
|
76
|
+
* binding read its own fallback.
|
|
77
|
+
* @experimental 🚧
|
|
78
|
+
*/
|
|
79
|
+
configLayers?: Record<string, Record<string, ScopeKind>>;
|
|
80
|
+
/**
|
|
81
|
+
* Whether `definitionId` is the spec's **pin** or a **swap**, and who
|
|
82
|
+
* seated the swap. `null` — the pin ran. A `NodeSwap` — the host seated
|
|
83
|
+
* another definition (`RunOptions.swaps`) and `pin` names the one it
|
|
84
|
+
* replaced. Absent when the host did not say (`RunOptions.swaps` left
|
|
85
|
+
* out), which includes every receipt written before 2026-09-26.
|
|
86
|
+
* @experimental 🚧
|
|
87
|
+
*/
|
|
88
|
+
swap?: NodeSwap | null;
|
|
89
|
+
/**
|
|
90
|
+
* This outlet ran in a dry run and committed nothing (R-21 (1)). Its
|
|
91
|
+
* output carries a synthetic id, and the event it would have caused is
|
|
92
|
+
* flagged the same way in `emitted`.
|
|
93
|
+
*/
|
|
94
|
+
dry?: true;
|
|
95
|
+
notes?: string[];
|
|
96
|
+
/**
|
|
97
|
+
* Script chains applied around this invocation (18 S5), one record per
|
|
98
|
+
* link, in application order. `appliedBy` distinguishes the substrate
|
|
99
|
+
* (executor-applied at a declared hook) from a binding invoking an
|
|
100
|
+
* interior point (18 §4e). "Which of my thirty filters ate that word" is
|
|
101
|
+
* answered here, per link.
|
|
102
|
+
*/
|
|
103
|
+
scripts?: ScriptApplicationRecord[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A swap a host seated on one node before the run (`RunOptions.swaps`): the
|
|
107
|
+
* definition that ran is the receipt row's `definitionId`, this names the pin
|
|
108
|
+
* it replaced and the scope whose choice it was.
|
|
109
|
+
* @experimental 🚧
|
|
110
|
+
*/
|
|
111
|
+
export interface NodeSwap {
|
|
112
|
+
/** The pin the spec names, `id@version`. */
|
|
113
|
+
pin: string;
|
|
114
|
+
/** Whose swap: a session's choice, or the pub's. */
|
|
115
|
+
by: 'session' | 'pub';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* How the host reached the spec it ran, when that is worth saying — today,
|
|
119
|
+
* one fact: a session preset named a spec for this event that could not
|
|
120
|
+
* serve, so a lower layer chose it (`via: 'fallback'`). Stamped by the host
|
|
121
|
+
* (`RunOptions.meta`), never by the executor, which cannot know it.
|
|
122
|
+
* @experimental 🚧
|
|
123
|
+
*/
|
|
124
|
+
export interface ReceiptPresetRoute {
|
|
125
|
+
via: 'fallback';
|
|
126
|
+
presetId: number;
|
|
127
|
+
/** The session preset's name. */
|
|
128
|
+
preset: string;
|
|
129
|
+
event: string;
|
|
130
|
+
/** The spec the preset still names. */
|
|
131
|
+
bound: string;
|
|
132
|
+
/** Why it does not resolve, as a sentence. */
|
|
133
|
+
reason: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Host facts about how a run was reached (`Receipt.meta`). Open: a host may
|
|
137
|
+
* record a further fact under its own key; `preset` is the one typed here.
|
|
138
|
+
* @experimental 🚧
|
|
139
|
+
*/
|
|
140
|
+
export interface ReceiptMeta {
|
|
141
|
+
preset?: ReceiptPresetRoute;
|
|
142
|
+
[key: string]: unknown;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* One script link's application, as the receipt keeps it (18 S2/S4/S5).
|
|
146
|
+
*
|
|
147
|
+
* A failing link is tolerated, not hidden: `result: 'err'` with the reason,
|
|
148
|
+
* and the chain continues — recorded exactly like an optional node's absorbed
|
|
149
|
+
* failure. A stop script's `verdict` is its index; `won: true` marks the
|
|
150
|
+
* earliest, which is the answer to "why did my reply cut off" (S4).
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
export interface ScriptApplicationRecord {
|
|
154
|
+
scriptId: number;
|
|
155
|
+
name: string;
|
|
156
|
+
/** The script kind the link was checked against — `core:script:text/transform@1`. */
|
|
157
|
+
scriptKind: string;
|
|
158
|
+
phase: 'before' | 'after';
|
|
159
|
+
appliedBy: 'substrate' | 'binding';
|
|
160
|
+
/**
|
|
161
|
+
* Where the link came from when it was not the node's own chain — the
|
|
162
|
+
* provenance half of 18 §4c. `connection:KoboldCpp` marks a stop guard the
|
|
163
|
+
* connection carries (18 §4b), which every pipeline using that connection
|
|
164
|
+
* inherits; absent means the pipeline-resolved chain. "Reply ended by
|
|
165
|
+
* `connection:kobold / chatml-guard` at index 412" is this field plus S4.
|
|
166
|
+
*/
|
|
167
|
+
via?: string;
|
|
168
|
+
result: 'ok' | 'err' | 'skip';
|
|
169
|
+
reason?: string;
|
|
170
|
+
/** `ctx.log` lines, in order. */
|
|
171
|
+
logs?: string[];
|
|
172
|
+
durationMs?: number;
|
|
173
|
+
/** Transforms only: whether the value actually moved. */
|
|
174
|
+
changed?: boolean;
|
|
175
|
+
/** Verdict operations only: the stop index this link returned. */
|
|
176
|
+
verdict?: number;
|
|
177
|
+
/** Verdict operations only: this link's verdict was the earliest and applied. */
|
|
178
|
+
won?: boolean;
|
|
179
|
+
}
|
|
180
|
+
/** @experimental */
|
|
181
|
+
export interface Receipt {
|
|
182
|
+
runId: string;
|
|
183
|
+
specId: string;
|
|
184
|
+
specVersion: string;
|
|
185
|
+
schemaVersion: 1;
|
|
186
|
+
seed: string;
|
|
187
|
+
triggerSource: 'input' | 'event' | 'hook' | 'ui' | 'schedule';
|
|
188
|
+
triggerRef?: string;
|
|
189
|
+
actorUserId?: string;
|
|
190
|
+
parentRunId?: string;
|
|
191
|
+
rootRunId?: string;
|
|
192
|
+
depth: number;
|
|
193
|
+
startedAt: number;
|
|
194
|
+
endedAt: number;
|
|
195
|
+
outcome: Outcome;
|
|
196
|
+
haltNodeKey?: string;
|
|
197
|
+
haltReason?: string;
|
|
198
|
+
/** Who stopped it, when an admin did (13 §3). `cancelled` is not `err`. */
|
|
199
|
+
cancelledBy?: string;
|
|
200
|
+
/**
|
|
201
|
+
* Time spent in the admin-visible queue before dequeue (13 §3). Recorded and
|
|
202
|
+
* deliberately excluded from elapsed: queue wait consumes no budget (F13) and
|
|
203
|
+
* trips no timeout (F36).
|
|
204
|
+
*/
|
|
205
|
+
queuedMs?: number;
|
|
206
|
+
/**
|
|
207
|
+
* True when this run halted before any effectful node and the receipt was
|
|
208
|
+
* reduced to attribution only (13 §2). Default on for event-triggered runs,
|
|
209
|
+
* which is where the per-message multiplier lives.
|
|
210
|
+
*/
|
|
211
|
+
compact?: boolean;
|
|
212
|
+
/** How many node rows the compaction dropped — so the count is never a mystery. */
|
|
213
|
+
compactedNodeCount?: number;
|
|
214
|
+
/**
|
|
215
|
+
* Present when this run was a preview: it stopped at the pre-call substrate and the
|
|
216
|
+
* report is what would have been sent. A preview receipt is **never compacted** — the
|
|
217
|
+
* preview *is* the payload.
|
|
218
|
+
*/
|
|
219
|
+
preview?: import('./preview.js').PreviewReport;
|
|
220
|
+
/**
|
|
221
|
+
* Who portrays each participant this run asked about — resolved by the
|
|
222
|
+
* host **once, at run start**, and pinned here like config (R-21 (4)).
|
|
223
|
+
*
|
|
224
|
+
* Keyed by participant reference (`character:12` → `{ by: 'ai' }`,
|
|
225
|
+
* `character:7` → `{ by: 'person', userId: '3' }`, `owner` → …). The
|
|
226
|
+
* host supplies it through `RunOptions.portrayals`, before the first
|
|
227
|
+
* node; nothing in the run reads or rewrites it — a member joining
|
|
228
|
+
* mid-run changes the next run's answer, never this one's.
|
|
229
|
+
*
|
|
230
|
+
* Present exactly when the host resolved it, which is when the answer
|
|
231
|
+
* means something: a run **in a session** that is **not a pre-call
|
|
232
|
+
* preview** — a reply, a summarize, an event subscriber. Absent on a run
|
|
233
|
+
* with no session behind it and on a preview that halts before any
|
|
234
|
+
* oracle (a token count, the inspector's debug preview): nobody speaks
|
|
235
|
+
* on those, so there is nobody to portray.
|
|
236
|
+
*/
|
|
237
|
+
portrayals?: import('./participants.js').Portrayals;
|
|
238
|
+
/**
|
|
239
|
+
* What the run was doing when it ended badly (R-19, R-21 "optional,
|
|
240
|
+
* taken"): the last status a node set — *{speaker} is typing* — and the
|
|
241
|
+
* node that set it. Present only when the outcome is `halt`, `err` or
|
|
242
|
+
* `cancelled`; never on `ok`, never on a preview's halt, and never as a
|
|
243
|
+
* node row — statuses are ephemeral (F34) and this is the one exception.
|
|
244
|
+
* The host fills `{speaker}` before the receipt is stored; the client
|
|
245
|
+
* resolves the locale.
|
|
246
|
+
*/
|
|
247
|
+
lastStatus?: import('./status.js').LastStatus;
|
|
248
|
+
nodes: NodeReceipt[];
|
|
249
|
+
/**
|
|
250
|
+
* Run-level notes — facts about the whole run that no node row can carry.
|
|
251
|
+
*
|
|
252
|
+
* Two so far, and both are things that must be visible or the receipt lies by
|
|
253
|
+
* omission: "a loop reached its declared max," because a truncated loop that
|
|
254
|
+
* returns `ok` otherwise looks like one that finished; and "the configured
|
|
255
|
+
* tokenizer could not be loaded, so budgeting fell back to an estimate,"
|
|
256
|
+
* because every token figure below is then a different measurement from the
|
|
257
|
+
* one the connection asked for.
|
|
258
|
+
*/
|
|
259
|
+
notes?: string[];
|
|
260
|
+
/**
|
|
261
|
+
* One row per loop block that ran, and why it stopped (01 §4a).
|
|
262
|
+
*
|
|
263
|
+
* The note above says the same thing for the ceiling case in a sentence,
|
|
264
|
+
* and a sentence is not a fact anything can switch on: "did the agent
|
|
265
|
+
* finish, or did it run out of turns" is the question a tool loop's caller
|
|
266
|
+
* asks, and reading it back out of prose is how a caller ends up matching
|
|
267
|
+
* on wording. `iterations` counts the bodies that ran, whatever ended them.
|
|
268
|
+
*/
|
|
269
|
+
loops?: Array<{
|
|
270
|
+
clauseId: string;
|
|
271
|
+
iterations: number;
|
|
272
|
+
/**
|
|
273
|
+
* `predicate` — the loop asked to stop. `ceiling` — the declared max
|
|
274
|
+
* ended it, so the work may be unfinished. `interrupted` — the body
|
|
275
|
+
* halted, errored or was cancelled, and the run's own outcome says
|
|
276
|
+
* which.
|
|
277
|
+
*/
|
|
278
|
+
stopped: 'predicate' | 'ceiling' | 'interrupted';
|
|
279
|
+
}>;
|
|
280
|
+
/**
|
|
281
|
+
* Events core emitted as a consequence of writes in this run (01 §8).
|
|
282
|
+
* `dry` marks one a dry run recorded and never dispatched.
|
|
283
|
+
*/
|
|
284
|
+
emitted: Array<{
|
|
285
|
+
event: string;
|
|
286
|
+
cause: string;
|
|
287
|
+
subscribers: number;
|
|
288
|
+
dry?: true;
|
|
289
|
+
}>;
|
|
290
|
+
/** Gate decisions enter provenance; replay honours them (F15). */
|
|
291
|
+
reviews?: Array<{
|
|
292
|
+
nodeKey: string;
|
|
293
|
+
position: string;
|
|
294
|
+
action: string;
|
|
295
|
+
originalHash: string;
|
|
296
|
+
editedHash?: string;
|
|
297
|
+
by?: string;
|
|
298
|
+
at?: number;
|
|
299
|
+
}>;
|
|
300
|
+
consumption: {
|
|
301
|
+
tokens: number;
|
|
302
|
+
nodeExecutions: number;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* How the host reached this run (`ReceiptMeta`) — which the executor
|
|
306
|
+
* cannot know, so it is recorded verbatim from `RunOptions.meta`.
|
|
307
|
+
* @experimental 🚧
|
|
308
|
+
*/
|
|
309
|
+
meta?: ReceiptMeta;
|
|
310
|
+
}
|
|
311
|
+
/** Render a receipt the way the run inspector would (17 §4). Used in tests as documentation. @experimental */
|
|
312
|
+
export declare function renderReceipt(r: Receipt): string;
|
|
313
|
+
//# sourceMappingURL=receipt.d.ts.map
|
package/dist/receipt.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Receipts (01 §1, 02 §2). The first-class record of a run, and the thing the
|
|
3
|
+
* whole design's explicability claim rests on.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately absent: progress messages (F34, ephemeral) and raw embedding
|
|
6
|
+
* vectors (16 §1a, recorded by reference).
|
|
7
|
+
*/
|
|
8
|
+
import { renderPreview } from './preview.js';
|
|
9
|
+
import { renderStatusText } from './status.js';
|
|
10
|
+
/** Render a receipt the way the run inspector would (17 §4). Used in tests as documentation. @experimental */
|
|
11
|
+
export function renderReceipt(r) {
|
|
12
|
+
const out = [];
|
|
13
|
+
out.push(`run ${r.runId} spec ${r.specId} v${r.specVersion} seed ${r.seed}`);
|
|
14
|
+
out.push(`trigger ${r.triggerSource}${r.actorUserId ? ` · user ${r.actorUserId}` : ''} ` +
|
|
15
|
+
`${r.endedAt - r.startedAt} ms` +
|
|
16
|
+
(r.queuedMs ? ` (+${r.queuedMs} ms queued, uncharged)` : '') +
|
|
17
|
+
` outcome ${r.outcome}` +
|
|
18
|
+
(r.cancelledBy ? ` by ${r.cancelledBy}` : ''));
|
|
19
|
+
if (r.compact) {
|
|
20
|
+
out.push(` ▸ compact: halted at ${r.haltNodeKey ?? '?'} before any effectful node — ` +
|
|
21
|
+
`${r.compactedNodeCount ?? 0} node row(s) dropped (13 §2)`);
|
|
22
|
+
if (r.haltReason)
|
|
23
|
+
out.push(` reason: ${r.haltReason}`);
|
|
24
|
+
}
|
|
25
|
+
// The one status the receipt keeps (R-21): what the run was doing when it
|
|
26
|
+
// ended badly. Rendered in `en` here; the inspector resolves the locale.
|
|
27
|
+
if (r.lastStatus)
|
|
28
|
+
out.push(` ▸ while: ${renderStatusText(r.lastStatus.text)} (status set by ${r.lastStatus.nodeKey})`);
|
|
29
|
+
if (r.preview)
|
|
30
|
+
out.push(renderPreview(r.preview));
|
|
31
|
+
for (const n of r.nodes) {
|
|
32
|
+
out.push(` ▸ ${n.nodeKey.padEnd(24)} ${n.kind.padEnd(9)} ${n.result.padEnd(9)} ${String(n.elapsedMs).padStart(5)} ms` +
|
|
33
|
+
(n.blockMode ? ` [${n.blockMode}]` : ''));
|
|
34
|
+
if (n.reason)
|
|
35
|
+
out.push(` reason: ${n.reason}`);
|
|
36
|
+
for (const note of n.notes ?? [])
|
|
37
|
+
out.push(` ${note}`);
|
|
38
|
+
if (n.samplingIgnored?.length)
|
|
39
|
+
out.push(` ignored samplers: ${n.samplingIgnored.join(', ')}`);
|
|
40
|
+
}
|
|
41
|
+
for (const rev of r.reviews ?? []) {
|
|
42
|
+
if (rev.position === 'off')
|
|
43
|
+
continue;
|
|
44
|
+
out.push(` ▸ review ${rev.nodeKey}: ${rev.position} → ${rev.action}` +
|
|
45
|
+
(rev.editedHash ? ` (edited ${rev.originalHash} → ${rev.editedHash})` : '') +
|
|
46
|
+
(rev.by ? ` by ${rev.by}` : ''));
|
|
47
|
+
}
|
|
48
|
+
for (const l of r.loops ?? [])
|
|
49
|
+
out.push(` ▸ loop ${l.clauseId}: ${l.iterations} iteration(s), stopped on ${l.stopped}`);
|
|
50
|
+
for (const note of r.notes ?? [])
|
|
51
|
+
out.push(` ▸ ${note}`);
|
|
52
|
+
for (const e of r.emitted) {
|
|
53
|
+
out.push(e.dry
|
|
54
|
+
? ` ▸ core would emit ${e.event} (cause: ${e.cause}) — dry run, not dispatched`
|
|
55
|
+
: ` ▸ core emitted ${e.event} (cause: ${e.cause}) → ${e.subscribers} subscriber(s)`);
|
|
56
|
+
}
|
|
57
|
+
out.push(` consumption: ${r.consumption.tokens} tokens, ${r.consumption.nodeExecutions} node executions`);
|
|
58
|
+
return out.join('\n');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=receipt.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One attribute, judged: `{ value }` is what to write (`null` removes the
|
|
3
|
+
* attribute), `{ refused }` says why it is dropped. The host appends its own
|
|
4
|
+
* words (`— dropped`); the harness lists the sentence in `refused`.
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export type ReceiverAttribute = {
|
|
8
|
+
readonly value: string | null;
|
|
9
|
+
} | {
|
|
10
|
+
readonly refused: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Judge one attribute a remote writes on a vocabulary element (`tag`, already
|
|
14
|
+
* lowercased and in the vocabulary), in `owner`'s box.
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export declare function receiverAttribute(tag: string, attribute: string, value: unknown, owner: string): ReceiverAttribute;
|
|
18
|
+
/**
|
|
19
|
+
* Why an element a remote places in `owner`'s box does not land — its whole
|
|
20
|
+
* subtree is dropped — or `undefined` when it does.
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
23
|
+
export declare function receiverElementFinding(tag: string, owner: string): string | undefined;
|
|
24
|
+
//# sourceMappingURL=receiverRules.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 The receiver's rules (C7): what the page does with an element a remote
|
|
3
|
+
* component places and an attribute it writes, beyond the vocabulary table
|
|
4
|
+
* ({@link hostAttributeAllowed}, {@link hostAttributeValueFinding}) — the
|
|
5
|
+
* rules that turn on WHOSE box it is, and the rule that the value a check
|
|
6
|
+
* judged is the value that is written. ONE implementation, which the page's
|
|
7
|
+
* receiver and the component harness (`@serene-pub/cli/testing`) both call,
|
|
8
|
+
* so an author's green test describes the page it will run in.
|
|
9
|
+
*
|
|
10
|
+
* Whose box: `'core'` is core's own component — the host names it only for
|
|
11
|
+
* core's own modules, and refuses a `core` claim from anywhere else — and
|
|
12
|
+
* every other owner is a plugin's.
|
|
13
|
+
*
|
|
14
|
+
* - `sp-host-view` is core's: a plugin's widget does not place the page's own
|
|
15
|
+
* views (it could lay the page's controls under its own).
|
|
16
|
+
* - `autofocus` is core's to place: a plugin's field never takes the caret
|
|
17
|
+
* from core's on landing.
|
|
18
|
+
* - `hidden` / `inert` written as the string `"false"` are absent: a boolean
|
|
19
|
+
* reaching an sp element as its string would otherwise hide what the
|
|
20
|
+
* component meant to show.
|
|
21
|
+
* - `href` / `src` are trimmed BEFORE they are judged, and the trimmed value
|
|
22
|
+
* is the one written: the ends the URL parser strips (C0 controls and
|
|
23
|
+
* space) and the ones the value rules trim (Unicode white space). A value
|
|
24
|
+
* the rules read as a `#fragment` is then one the host's id prefix reaches,
|
|
25
|
+
* and one no parser reads as a path.
|
|
26
|
+
* - an `img src` in core's box may also be an `https:` URL or an inline
|
|
27
|
+
* `data:image/(png|jpeg|gif|webp);base64,…` image — an envoy's face, which
|
|
28
|
+
* the page's own CSP allows (`img-src https: data:`). A plugin's stays the
|
|
29
|
+
* app's own media: an image URL is a request the page makes, and a remote's
|
|
30
|
+
* only way out is its plugin's own server-side actions.
|
|
31
|
+
*
|
|
32
|
+
* What the guard adds, record by record (`guardedConnection`, which both also
|
|
33
|
+
* run): prefixing ids when the host names a prefix (the page does, per box;
|
|
34
|
+
* the harness does not), the tag an update is judged against, and what the
|
|
35
|
+
* remote writes into a subtree these rules refused.
|
|
36
|
+
*
|
|
37
|
+
* @experimental 🚧 provisional with the vocabulary it extends (C7, R21).
|
|
38
|
+
*/
|
|
39
|
+
import { hostAttributeAllowed, hostAttributeValueFinding, isHostElement } from './hostElements.js';
|
|
40
|
+
/** The owner id of core's own component — the one box the owner rules favour. */
|
|
41
|
+
const CORE_OWNER = 'core';
|
|
42
|
+
/** Global presence booleans a remote can only have meant OFF when it wrote `"false"`. */
|
|
43
|
+
const PRESENCE_GLOBALS = new Set(['hidden', 'inert']);
|
|
44
|
+
/** Attributes holding a URL: trimmed before they are judged, and written trimmed. */
|
|
45
|
+
const URL_ATTRIBUTES = new Set(['href', 'src']);
|
|
46
|
+
/** The ends the URL parser strips (C0 controls and space) and the ends `trim` strips (Unicode white space). */
|
|
47
|
+
const URL_EDGES = /^[\u0000- \s]+|[\u0000- \s]+$/g;
|
|
48
|
+
/** Core's box only: an `img src` on another host, over TLS. */
|
|
49
|
+
const CORE_IMAGE_HTTPS = /^https:\/\/[^\s]+$/i;
|
|
50
|
+
/**
|
|
51
|
+
* Core's box only: an inline raster image. Base64 alone, and the four types
|
|
52
|
+
* Remote DOM's own receiver floor also lets through — an `svg+xml` data URI
|
|
53
|
+
* it refuses outright, which would stop the whole box rather than drop one
|
|
54
|
+
* attribute.
|
|
55
|
+
*/
|
|
56
|
+
const CORE_IMAGE_DATA = /^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/]*={0,2}$/i;
|
|
57
|
+
/**
|
|
58
|
+
* Judge one attribute a remote writes on a vocabulary element (`tag`, already
|
|
59
|
+
* lowercased and in the vocabulary), in `owner`'s box.
|
|
60
|
+
* @experimental
|
|
61
|
+
*/
|
|
62
|
+
export function receiverAttribute(tag, attribute, value, owner) {
|
|
63
|
+
if (!hostAttributeAllowed(tag, attribute))
|
|
64
|
+
return { refused: `<${tag}> takes no '${attribute}'` };
|
|
65
|
+
if (attribute === 'autofocus' && owner !== CORE_OWNER)
|
|
66
|
+
return { refused: `<${tag}> autofocus is core's to place` };
|
|
67
|
+
if (value === null || value === undefined)
|
|
68
|
+
return { value: null };
|
|
69
|
+
let text = String(value);
|
|
70
|
+
if (URL_ATTRIBUTES.has(attribute))
|
|
71
|
+
text = text.replace(URL_EDGES, '');
|
|
72
|
+
if (PRESENCE_GLOBALS.has(attribute) && text === 'false')
|
|
73
|
+
return { value: null };
|
|
74
|
+
if (owner === CORE_OWNER &&
|
|
75
|
+
tag === 'img' &&
|
|
76
|
+
attribute === 'src' &&
|
|
77
|
+
(CORE_IMAGE_HTTPS.test(text) || CORE_IMAGE_DATA.test(text)))
|
|
78
|
+
return { value: text };
|
|
79
|
+
const finding = hostAttributeValueFinding(tag, attribute, text);
|
|
80
|
+
return finding ? { refused: finding } : { value: text };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Why an element a remote places in `owner`'s box does not land — its whole
|
|
84
|
+
* subtree is dropped — or `undefined` when it does.
|
|
85
|
+
* @experimental
|
|
86
|
+
*/
|
|
87
|
+
export function receiverElementFinding(tag, owner) {
|
|
88
|
+
if (!isHostElement(tag))
|
|
89
|
+
return `<${tag}> is not in the host-element vocabulary`;
|
|
90
|
+
if (tag.toLowerCase() === 'sp-host-view' && owner !== CORE_OWNER)
|
|
91
|
+
return `<sp-host-view> is core's — a plugin's widget does not place the page's own views`;
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=receiverRules.js.map
|
package/dist/refs.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* References — edges as data (04 §4), and config references (F35).
|
|
3
|
+
*
|
|
4
|
+
* $ref creates a *data* edge and compiles 1:1 to a pipeline_edges row.
|
|
5
|
+
* slot.* creates a *config* reference, which is resolved before execution and is
|
|
6
|
+
* therefore not an edge and creates no dependency in the graph.
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
9
|
+
export interface DataRef {
|
|
10
|
+
readonly __ref: 'data';
|
|
11
|
+
node: string;
|
|
12
|
+
port: string;
|
|
13
|
+
}
|
|
14
|
+
/** @public */
|
|
15
|
+
export interface SlotRef {
|
|
16
|
+
readonly __ref: 'slot';
|
|
17
|
+
slot: 'connection' | 'sampling' | 'prompts' | 'template' | 'params' | 'variables';
|
|
18
|
+
/** Whose config. Undefined = this node's own. */
|
|
19
|
+
ofNode?: string;
|
|
20
|
+
/**
|
|
21
|
+
* An **envoy's** config (plans/29 R-18 (2); built 2026-09-16 as U5g):
|
|
22
|
+
* the genre-declared defaults for `envoy:<key>`, resolved through the
|
|
23
|
+
* config chain at the address `envoy:<key>` exactly as a node's are —
|
|
24
|
+
* the host projects the declaration at `author` and an admin's tuning
|
|
25
|
+
* sits above it. Compiles to `resolvedRefs[slot] = 'envoy:<key>'`
|
|
26
|
+
* after the genre the spec serves is checked for the key.
|
|
27
|
+
*/
|
|
28
|
+
ofEnvoy?: string;
|
|
29
|
+
/** Unresolved marker: resolve to the first oracle reachable forward (16 §5b-i). */
|
|
30
|
+
resolveDownstreamOracle?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** @experimental */
|
|
33
|
+
export declare function $ref(node: string, port?: string): DataRef;
|
|
34
|
+
/**
|
|
35
|
+
* Config references accept a node accessor as well as a key, so a spec never has to
|
|
36
|
+
* name a node twice in two different ways: `slot.connectionOf($.generate)` reads the
|
|
37
|
+
* same as `$.generate.text` two lines below it.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export type NodeAddress = string | {
|
|
41
|
+
node: string;
|
|
42
|
+
};
|
|
43
|
+
/** An envoy's config, by the genre-local key: `slot.prompts({ envoy: 'mascot' })`. @experimental */
|
|
44
|
+
export type EnvoyAddress = {
|
|
45
|
+
envoy: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The address an envoy's config lives at in the resolved config — the
|
|
49
|
+
* synthetic node key `envoy:<key>`. One spelling, shared by the compiler
|
|
50
|
+
* (`resolvedRefs`), the executor (`resolveConfig`'s key list) and the host's
|
|
51
|
+
* projection, so the three cannot disagree about where a mascot's prompt is.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export declare const ENVOY_CONFIG_PREFIX = "envoy:";
|
|
55
|
+
/** @experimental */
|
|
56
|
+
export declare const envoyConfigKey: (key: string) => string;
|
|
57
|
+
/** @internal */
|
|
58
|
+
export declare const isEnvoyConfigKey: (key: string) => boolean;
|
|
59
|
+
/** @public */
|
|
60
|
+
export declare const slot: {
|
|
61
|
+
connection: (ofNode?: NodeAddress) => SlotRef;
|
|
62
|
+
sampling: (ofNode?: NodeAddress) => SlotRef;
|
|
63
|
+
/**
|
|
64
|
+
* With a target, the slot is *shared*: the node reads the target's authored
|
|
65
|
+
* prompts and declares none of its own to configure. One authored text, one
|
|
66
|
+
* place to edit it — three nodes that each demanded the same system prompt
|
|
67
|
+
* is the defect this exists to close (13 §12 finding i).
|
|
68
|
+
*/
|
|
69
|
+
prompts: (of?: NodeAddress | EnvoyAddress) => SlotRef;
|
|
70
|
+
template: () => SlotRef;
|
|
71
|
+
/**
|
|
72
|
+
* With a target, the slot's **shared** fields resolve at the target — and
|
|
73
|
+
* only those (R-7 P2, refined 2026-09-16; `FieldDecl.shared`).
|
|
74
|
+
*
|
|
75
|
+
* A definition marks the `params` fields several nodes of one spec hold in
|
|
76
|
+
* common — the lore lanes' seven scan knobs, the embed pair's switch —
|
|
77
|
+
* `shared: true`; a spec then names ONE owner and the other nodes reference
|
|
78
|
+
* it here. A referencing node's *unmarked* fields stay its own and resolve
|
|
79
|
+
* at its own address through the same reference: each lore lane's share
|
|
80
|
+
* of the window is that lane's, while the scan depth they run on is one
|
|
81
|
+
* number. One reference, both halves, and the panel draws the same line.
|
|
82
|
+
*
|
|
83
|
+
* ⚠ It used to read the whole slot at the target, and its docblock argued
|
|
84
|
+
* for the ranker as the owner of "every query's minimums and weights". That
|
|
85
|
+
* is the per-source map on the ranker 16 §5a rejected; per-source intent
|
|
86
|
+
* lives on the source now (R-7 P5) and travels as candidate metadata, so
|
|
87
|
+
* nothing needs to read the ranker's params from a query any more.
|
|
88
|
+
*/
|
|
89
|
+
params: (ofNode?: NodeAddress) => SlotRef;
|
|
90
|
+
/**
|
|
91
|
+
* With a target, the slot is *shared* — the same reading as `prompts`. A node
|
|
92
|
+
* that consumes another's rendered variables reads that node's selections
|
|
93
|
+
* rather than declaring a parallel set nobody would think to keep in step.
|
|
94
|
+
*/
|
|
95
|
+
variables: (ofNode?: NodeAddress) => SlotRef;
|
|
96
|
+
/** Explicit oracle reference — always unambiguous. */
|
|
97
|
+
oracleRef: (node: NodeAddress) => SlotRef;
|
|
98
|
+
connectionOf: (node: NodeAddress) => SlotRef;
|
|
99
|
+
samplingOf: (node: NodeAddress) => SlotRef;
|
|
100
|
+
/**
|
|
101
|
+
* Resolves at publish to the first oracle reachable forward. Compiles to the
|
|
102
|
+
* explicit form, so nothing implicit survives into rows (16 §5b-i).
|
|
103
|
+
*/
|
|
104
|
+
downstreamOracle: () => SlotRef;
|
|
105
|
+
};
|
|
106
|
+
/** @experimental */
|
|
107
|
+
export declare const isDataRef: (v: unknown) => v is DataRef;
|
|
108
|
+
/** @internal */
|
|
109
|
+
export declare const isSlotRef: (v: unknown) => v is SlotRef;
|
|
110
|
+
/** Walk a config object and collect every data ref, with the key path it sat at. @experimental */
|
|
111
|
+
export declare function collectDataRefs(config: unknown, path?: string[]): Array<{
|
|
112
|
+
path: string[];
|
|
113
|
+
ref: DataRef;
|
|
114
|
+
}>;
|
|
115
|
+
/** @experimental */
|
|
116
|
+
export declare function collectSlotRefs(config: unknown): SlotRef[];
|
|
117
|
+
//# sourceMappingURL=refs.d.ts.map
|