@serene-pub/contracts 0.6.0-pr-2 → 0.6.0-pr-4

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.
@@ -0,0 +1,1386 @@
1
+ /**
2
+ * Core's **oracle** node definitions — calls out to an external, nondeterministic
3
+ * source: a model, TTS, image generation, embeddings, a person.
4
+ *
5
+ * One file per node kind, with the helpers only that kind uses; `index.ts`
6
+ * re-exports them all.
7
+ */
8
+ import { S, tf, IoKinds } from '@serene-pub/sdk';
9
+ import { jinja2 } from '@serene-pub/sdk';
10
+ import { describeOracleDefinition, pin } from '@serene-pub/sdk';
11
+ /**
12
+ * How a provider node wants its request sent.
13
+ *
14
+ * Two values, because only two are deliverable. `auto` defers to the
15
+ * CONNECTION, which already holds an answer and holds a different default per
16
+ * service; `off` forces the single-request branch every adapter has. There is
17
+ * no `on`: a connection whose adapter has no streaming branch could not honour
18
+ * one, and a control that silently means nothing on half the rows is the
19
+ * defect this vocabulary avoids.
20
+ *
21
+ * A factory rather than a shared constant so the four declarations are four
22
+ * objects — a descriptor is snapshotted into registry rows, and an alias
23
+ * shared across pins is one edit away from being four.
24
+ */
25
+ const streamingParam = () => ({
26
+ type: 'enum',
27
+ of: ['auto', 'off'],
28
+ members: [
29
+ {
30
+ key: 'auto',
31
+ label: { en: 'Automatic' },
32
+ description: { en: "Keeps the connection's own Stream setting." },
33
+ },
34
+ {
35
+ key: 'off',
36
+ label: { en: 'Off' },
37
+ description: { en: 'Sends one request and waits — cheaper for background steps.' },
38
+ },
39
+ ],
40
+ default: 'auto',
41
+ description: "Automatic keeps the connection's own Stream setting; Off sends one request and waits, which is cheaper for background steps.",
42
+ });
43
+ /**
44
+ * **The model decides who speaks** (PLAN-turn-order R41, M4): the oracle on
45
+ * the turn-order spec's optional model path (`decide.model.advise`). Same
46
+ * ports as a strategy — candidates and the visible history in, prepared turn
47
+ * entries out on `main` and `order` — so the junction's result port reads
48
+ * the same whichever path fired. Its answer is held to the candidates: a
49
+ * ref the pool did not admit is dropped with a note, and an answer that
50
+ * names nobody (or no answer at all) falls back to round robin, noted —
51
+ * never a halt, so a model hiccup never leaves a session without an order.
52
+ *
53
+ * A plugin's own model strategy is a swap for this node: an oracle with
54
+ * these ports and these three slots (the fit check holds it to them).
55
+ * @experimental
56
+ */
57
+ export const turnAdvise = pin(describeOracleDefinition({
58
+ id: 'core:oracle/turn-advise@1',
59
+ i18n: {
60
+ name: { en: 'Model decides who speaks' },
61
+ description: {
62
+ en: 'Asks the model who should speak next, from the cast that may be seated and the recent conversation. Falls back to round robin when the answer names nobody.',
63
+ },
64
+ },
65
+ shape: S.textGen,
66
+ effects: 'external',
67
+ review: { fields: [] },
68
+ timeoutMs: 60000,
69
+ usage: 'response.usage',
70
+ slots: {
71
+ connection: {
72
+ kind: 'connection',
73
+ quick: true,
74
+ shape: S.textGen,
75
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
76
+ /**
77
+ * Asked rather than required (the `ctx.can` ruling, as
78
+ * generate-json): the answer's schema goes out through the
79
+ * strongest door the connection has — json_schema (natively or
80
+ * as a grammar), then json_object — and the prompt's own
81
+ * words are the rung that works everywhere.
82
+ */
83
+ optional: ['json_schema', 'json_object'],
84
+ },
85
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
86
+ prompts: {
87
+ kind: 'prompts',
88
+ quick: true,
89
+ facet: 'prompts',
90
+ fields: { turnAdvice: { type: 'text' } },
91
+ },
92
+ },
93
+ ports: {
94
+ in: { candidates: S.turnCandidates, messages: S.messages },
95
+ out: { main: S.turnEntries, order: S.turnEntries },
96
+ },
97
+ }));
98
+ /**
99
+ * Run the tool the model asked for, and hand the answer back as text it can
100
+ * read on the next pass (20 §9).
101
+ *
102
+ * ## Why this is a Provider and not a Task
103
+ *
104
+ * The two halves either side of it are pure and this one cannot be: a tool
105
+ * reads the session, or reaches an extension's sandboxed hook, which may in
106
+ * turn reach the network under its own grants. That is `effects: 'external'`
107
+ * exactly — and it is the kind that is handed `ctx.call`, so the tool's own
108
+ * dispatch stays behind the host seam where every other outward call lives.
109
+ * A Task with database access would be a second, unaudited read path.
110
+ *
111
+ * ## What it refuses, and what it never throws
112
+ *
113
+ * `tools` is the advertisement the model was actually given, so a name that
114
+ * was never offered is refused **by name** rather than resolved: a model
115
+ * inventing a tool must not be able to reach one that exists but was withheld
116
+ * from this step.
117
+ *
118
+ * A tool that fails is a **result, not an exception**. `main` is
119
+ * `{ tool, error }` and `text` renders it, because the model asking for a
120
+ * missing file needs to read "no such file" and try something else — a throw
121
+ * would end the run at the one moment the agent could have recovered. The
122
+ * type's `timeoutMs` is the time-box per call: one node invocation is one
123
+ * tool, so the executor's own timeout already is the tool's.
124
+ *
125
+ * `call` may be null — that is the ordinary last iteration, where the model
126
+ * answered in prose and the loop is about to stop. Nothing runs and `text` is
127
+ * empty.
128
+ * @experimental
129
+ */
130
+ export const runTool = pin(describeOracleDefinition({
131
+ id: 'core:oracle/run-tool@1',
132
+ i18n: { name: { en: 'Run tool' } },
133
+ effects: 'external',
134
+ /** The call was the model's and the tool list the install's: approve or refuse (R-15 review fields). */
135
+ review: { fields: [] },
136
+ timeoutMs: 30000,
137
+ ports: {
138
+ // `call` is parse-tool-call's `{ tool, args } | null`; `tools` is
139
+ // advertise-tools' input, so refusal reads the same list the model
140
+ // saw; `text` is the prose parse-tool-call stripped the call out of.
141
+ in: { call: S.json, tools: S.json, text: S.text },
142
+ /**
143
+ * Three ports because an iteration produces up to three different
144
+ * things and one port carrying two of them is a port a downstream
145
+ * node has to interrogate.
146
+ *
147
+ * - `main` — `{ tool, result }` or `{ tool, error }`, or null when
148
+ * nothing was called. One shape, two arms, so nothing downstream
149
+ * decides what happened by looking for a missing key.
150
+ * - `text` — that rendered as the tool-result block **the next
151
+ * prompt carries**. Empty when nothing ran.
152
+ * - `answer` — what this iteration contributes to the
153
+ * **conversation**: the model's prose, and only on the iteration
154
+ * that called no tool, which is the one where the model stopped
155
+ * working and answered. Empty otherwise, so joining every
156
+ * iteration's `answer` yields the turn's reply and nothing else.
157
+ */
158
+ out: { main: S.json, text: S.text, answer: S.text },
159
+ },
160
+ }));
161
+ // ── Providers — identical structure across three modalities (17 §2) ─────────
162
+ /** @experimental */
163
+ export const embedText = pin(describeOracleDefinition({
164
+ id: 'core:oracle/embed-text@1',
165
+ shape: S.embeddings,
166
+ effects: 'external',
167
+ /** Nothing to edit: an embedding of a text somebody else wrote (R-15 review fields). */
168
+ review: { fields: [] },
169
+ timeoutMs: 5000,
170
+ /**
171
+ * ⚠ **Producing nothing is a legitimate outcome, and this is what makes
172
+ * that structural rather than careful.**
173
+ *
174
+ * Embeddings are optional in this product by design: most installs have
175
+ * no model loaded, and the retrieval plan's second governing rule is an
176
+ * absolute — *an unavailable mechanism subtracts a signal; it never
177
+ * reroutes, disables a path, or excludes a candidate.* The host answers
178
+ * "no embedding model is loaded and validated" by **throwing**, which is
179
+ * the right answer to give a caller and the wrong thing to let end a
180
+ * turn.
181
+ *
182
+ * `optional` is what turns that error into an empty `ok` in the executor
183
+ * — recorded, with `recoveredAsEmpty` and the reason on the receipt, so
184
+ * it is tolerated rather than hidden. The binding's `enabled` parameter
185
+ * decides how *loudly*: `auto` treats an unavailable model as an absence
186
+ * and returns no vectors without calling it a failure, `on` lets the
187
+ * failure be recorded as one. Neither can cost somebody a reply, and
188
+ * that is the point of putting the guarantee here instead of in a
189
+ * `try`.
190
+ *
191
+ * It also earns the node a "Use this source" switch. ⚠ Not the semantic
192
+ * mechanism's switch: that is `core:task/query-windows@1`'s
193
+ * `searchByMeaning`, on the chain's first node, which cuts the probes
194
+ * before this node is reached. Off here (or `enabled: 'off'`) still
195
+ * spends nothing, and switches off every embed step that shares
196
+ * `enabled` — the entity-vector mechanism's too — but it leaves the
197
+ * semantic chain running on empty, and `vector-search` can only say
198
+ * nothing was embedded, not why.
199
+ */
200
+ optional: true,
201
+ /**
202
+ * ⚠ **No `connection` slot** (removed 2026-10-05, owner ruling D-c). A
203
+ * pipeline never chooses its embedding connection: the host embeds
204
+ * through the install's one active embedding connection, whatever a
205
+ * step names. The slot it carried resolved a value into a port no host
206
+ * read — ten inert controls across five reply specs, held at the active
207
+ * connection only so Search by meaning's Automatic could read it.
208
+ * `core:task/query-windows@1` asks that question on its own slot now.
209
+ */
210
+ slots: {
211
+ params: {
212
+ kind: 'parameters',
213
+ schema: {
214
+ /**
215
+ * `shared`: one switch for every embed step of a spec (R-7
216
+ * P2). `respond` puts it on the semantic mechanism's embed
217
+ * and the entity-vector mechanism's embed reads it through
218
+ * `slot.params({ node })` — an install with no embedding
219
+ * model switches both off in one place, which is the only
220
+ * reading of "embedding: off" a person means.
221
+ */
222
+ enabled: {
223
+ type: 'enum',
224
+ of: ['auto', 'on', 'off'],
225
+ members: [
226
+ {
227
+ key: 'auto',
228
+ label: { en: 'Automatic' },
229
+ description: {
230
+ en: 'Embeds when a model is loaded; without one, retrieval goes on without vectors.',
231
+ },
232
+ },
233
+ {
234
+ key: 'on',
235
+ label: { en: 'On' },
236
+ description: {
237
+ en: 'Always embeds; a missing model is recorded as a failure, and the reply still goes out.',
238
+ },
239
+ },
240
+ {
241
+ key: 'off',
242
+ label: { en: 'Off' },
243
+ description: { en: 'Never embeds: semantic matching is switched off.' },
244
+ },
245
+ ],
246
+ default: 'auto',
247
+ shared: true,
248
+ },
249
+ },
250
+ },
251
+ },
252
+ ports: {
253
+ in: {
254
+ text: S.text,
255
+ /** Batched: one call, one vector each, in order. */
256
+ texts: S.json,
257
+ },
258
+ out: { main: S.vector, vector: S.vector, vectors: S.json },
259
+ },
260
+ }));
261
+ /**
262
+ * An MCP tool call (14 §2) — the generic Provider for a tool on any MCP
263
+ * connection. The snapshot path (14 §3) projects each advertised tool as its
264
+ * own registry row under the connection's namespace, typed off the tool's
265
+ * declared input schema; this generic type is the escape hatch beneath them —
266
+ * pin it, choose the connection, name the tool in params.
267
+ *
268
+ * `effects: 'external'` unconditionally: MCP annotations (`readOnlyHint` and
269
+ * friends) are advisory by specification and are never trusted for gating
270
+ * (14 §4). The admin's per-tool classification lives on the snapshot rows;
271
+ * this generic type gates always, because through it any tool is reachable.
272
+ *
273
+ * The result carries the request and response verbatim in its output — which
274
+ * is the receipt, which is the pitch (14 §5): no other MCP client can answer
275
+ * "what did this tool actually do, and did I approve it" from a row.
276
+ * @experimental
277
+ */
278
+ export const mcpTool = pin(describeOracleDefinition({
279
+ id: 'core:oracle/mcp-tool@1',
280
+ i18n: {
281
+ name: { en: 'MCP tool' },
282
+ description: {
283
+ en: 'Call one tool on a Model Context Protocol server, recorded verbatim and gated like every effectful step.',
284
+ },
285
+ },
286
+ shape: S.mcp,
287
+ effects: 'external',
288
+ /** Declared, not bound — plans/28 owns the handler (plans/29 R-2). */
289
+ provisional: true,
290
+ /** The arguments are the model's invocation: approve or refuse it, never rewrite it (R-15 review fields). */
291
+ review: { fields: [] },
292
+ timeoutMs: 60000,
293
+ slots: {
294
+ connection: {
295
+ kind: 'connection',
296
+ quick: true,
297
+ shape: S.mcp,
298
+ /**
299
+ * ⚠ No `requires`, and that is deliberate rather than an omission.
300
+ *
301
+ * The capability space describes io TRANSFORMS — what a model can
302
+ * be handed and what it gives back. An MCP server is not one: it
303
+ * serves tools, it does not turn text into anything. The nearest
304
+ * id, `text->text`, would be false, and claiming it would make
305
+ * every chat connection in the install look offerable here.
306
+ *
307
+ * So this slot keeps filtering by `shape` alone, which is the
308
+ * right axis for it. `requires` is for slots whose answer is "what
309
+ * must this connection be able to DO".
310
+ */
311
+ description: 'Which MCP server this step calls.',
312
+ },
313
+ params: {
314
+ kind: 'parameters',
315
+ schema: {
316
+ tool: {
317
+ type: 'string',
318
+ quick: true,
319
+ label: { en: 'Tool' },
320
+ description: {
321
+ en: 'The advertised tool name on the connected server.',
322
+ },
323
+ },
324
+ },
325
+ },
326
+ },
327
+ ports: {
328
+ in: {
329
+ /** Arguments for the tool, merged over any declared in params. */
330
+ args: S.json,
331
+ },
332
+ out: {
333
+ main: S.json,
334
+ text: S.text,
335
+ /** The content blocks exactly as the server returned them. */
336
+ content: S.json,
337
+ },
338
+ },
339
+ }));
340
+ /**
341
+ * An MCP resource read (14 §2) — a Provider, deliberately not a Query. A
342
+ * Query may not reach the network (16 §1), and everything crossing the
343
+ * process boundary must be recorded verbatim so replay never re-infers
344
+ * (F16); a resource is external state that can change between runs, and
345
+ * modelling it as a Query would quietly break both rules.
346
+ * @experimental
347
+ */
348
+ export const mcpResource = pin(describeOracleDefinition({
349
+ id: 'core:oracle/mcp-resource@1',
350
+ i18n: {
351
+ name: { en: 'MCP resource' },
352
+ description: {
353
+ en: 'Read one resource from a Model Context Protocol server, recorded verbatim.',
354
+ },
355
+ },
356
+ shape: S.mcp,
357
+ effects: 'external',
358
+ /** Declared, not bound — plans/28 owns the handler (plans/29 R-2). */
359
+ provisional: true,
360
+ /** The uri is the invocation: approve or refuse (R-15 review fields). */
361
+ review: { fields: [] },
362
+ timeoutMs: 60000,
363
+ slots: {
364
+ connection: {
365
+ kind: 'connection',
366
+ quick: true,
367
+ shape: S.mcp,
368
+ // No `requires` — see the sibling MCP node above: a tool server is
369
+ // not an io transform, so `shape` is the right filter here.
370
+ description: 'Which MCP server this step reads from.',
371
+ },
372
+ params: {
373
+ kind: 'parameters',
374
+ schema: {
375
+ uri: {
376
+ type: 'string',
377
+ quick: true,
378
+ label: { en: 'Resource URI' },
379
+ description: {
380
+ en: 'The advertised resource URI on the connected server.',
381
+ },
382
+ },
383
+ },
384
+ },
385
+ },
386
+ ports: {
387
+ in: {
388
+ /** Overrides the declared URI when wired. */
389
+ uri: S.text,
390
+ },
391
+ out: {
392
+ main: S.json,
393
+ text: S.text,
394
+ content: S.json,
395
+ },
396
+ },
397
+ }));
398
+ /** @public */
399
+ export const generateText = pin(describeOracleDefinition({
400
+ id: 'core:oracle/generate-text@1',
401
+ i18n: { name: { en: 'Generate reply' } },
402
+ shape: S.textGen,
403
+ effects: 'external',
404
+ /** The payload is the compiled prompt; a prompt rewritten at the gate is one the receipt cannot explain — approve or refuse (R-15 review fields). */
405
+ review: { fields: [] },
406
+ timeoutMs: 120000,
407
+ timeoutKind: 'idle',
408
+ usage: 'response.usage',
409
+ slots: {
410
+ connection: {
411
+ kind: 'connection',
412
+ quick: true,
413
+ shape: S.textGen,
414
+ /**
415
+ * What the connection must be able to do, as opposed to what it
416
+ * is called. `shape` above still types the SLOT; this types the
417
+ * connection, and it is what the picker filters on and what the
418
+ * bind check refuses by — naming "Chat" rather than an id.
419
+ *
420
+ * Only `requires`, deliberately — still, now that the binding DOES
421
+ * consume `attachments`. It is the Anthropic adapter that sends
422
+ * them today (as base64 content blocks on the last user turn); a
423
+ * connection whose adapter has no such code REFUSES a request
424
+ * carrying files rather than sending it without them, so the
425
+ * `attachments` port is honest without a slot-level requirement.
426
+ *
427
+ * An `optional` vision requirement would meanwhile put a "no
428
+ * vision" caveat on every text connection in the app, on every
429
+ * run — and the port is empty on nearly all of them.
430
+ */
431
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
432
+ description: 'Which model server this step sends its request to.',
433
+ },
434
+ sampling: {
435
+ kind: 'sampling',
436
+ quick: true,
437
+ shape: S.textGen,
438
+ description: 'The sampling settings — temperature and friends — used for this request.',
439
+ },
440
+ /**
441
+ * ⚠ No `prompts` slot, and there was one — `system` and
442
+ * `postHistory`, "the written instructions sent with every request
443
+ * from this step" (culled 2026-09-16, R-12). No handler read it:
444
+ * the instructions reach the model INSIDE the assembled context,
445
+ * through `core:task/assemble@2`'s own `prompts` slot, and this
446
+ * node sends what it is handed on `context`. Every shipped spec
447
+ * wired it as `slot.prompts({ node: 'context' })` for one reason
448
+ * only — so the panel would not render a second copy of the
449
+ * context builder's text — which is a declaration existing to hide
450
+ * itself. The same slot on `generate-with-tools@1` and
451
+ * `generate-json@1` went with it.
452
+ */
453
+ /**
454
+ * ⚠ No `template` slot, and there was one — "how the assembled
455
+ * context is wrapped for this model before sending".
456
+ *
457
+ * Nothing read it and nothing seeded a row, so it rendered as an
458
+ * empty picker beside the settings that do work. Wrapping for the
459
+ * wire is the `wire` slot's job and the connection adapter's; a
460
+ * second, inert way to express it invited the two to disagree.
461
+ */
462
+ params: {
463
+ kind: 'parameters',
464
+ facet: 'weights',
465
+ schema: {
466
+ stopSequences: {
467
+ type: 'string[]',
468
+ description: 'Sequences that end the reply the moment the model writes one. One per line.',
469
+ },
470
+ streaming: streamingParam(),
471
+ },
472
+ },
473
+ },
474
+ /**
475
+ * Vision and interleaved output, declared.
476
+ *
477
+ * `accepts` is what makes a multimodal model reachable at all: before
478
+ * this the only image ports in the whole graph pointed *outward*
479
+ * (render, attach), so an image could be produced and stored but never
480
+ * sent. `emits` says a reply may contain generated media — which is
481
+ * what a single call now routinely returns, interleaved with the prose
482
+ * rather than beside it.
483
+ *
484
+ * Declaring both here does not oblige a connection to do either; the
485
+ * adapter reports what its model actually supports and the two are
486
+ * resolved at bind time.
487
+ */
488
+ media: {
489
+ accepts: ['image', 'document'],
490
+ emits: ['image'],
491
+ },
492
+ ports: {
493
+ in: {
494
+ context: S.assembled,
495
+ /**
496
+ * Whose reply is being generated — the stop-string exclusion
497
+ * (§27l): the speaking character's own name must not stop
498
+ * their own reply. The host already preferred a payload value
499
+ * over the run scope's; this port is what lets a spec supply
500
+ * one, so the exclusion follows the next-speaker node's output
501
+ * (19 §5) instead of the pre-run guess.
502
+ */
503
+ currentCharacterId: S.rowIds,
504
+ /**
505
+ * Media travelling with the request — the page a user
506
+ * attached, the frame a vision step is asked about. A list
507
+ * because interleaving is ordered and a single ref could not
508
+ * express "these three, in this order".
509
+ *
510
+ * Optional, and never quietly ignored: the host forwards these
511
+ * references to the dispatch, which resolves each one to bytes
512
+ * (checking it belongs to this run's session or user) and hands
513
+ * them to the adapter in this order. A request whose connection
514
+ * has vision switched off, or whose adapter has no code that
515
+ * sends files, is REFUSED rather than sent without them —
516
+ * dropping a file is indistinguishable from a model ignoring it.
517
+ */
518
+ attachments: S.mediaList,
519
+ },
520
+ /**
521
+ * `parts` is the honest shape of a completion: an ordered list of
522
+ * text, reasoning, generated media and tool calls. `main` and
523
+ * `text` stay exactly as they were — `part-stream` is assignable
524
+ * to `text-stream`, so every spec wired to them keeps working and
525
+ * degrades by concatenating the prose.
526
+ *
527
+ * `reasoning` is the reasoning trace the dispatch separated from
528
+ * the text before the text reached the port — published by the
529
+ * binding since it first stripped one, declared now that a
530
+ * downstream write (`update-message`) takes it. Empty when the
531
+ * model produced none.
532
+ */
533
+ out: {
534
+ main: S.partStream,
535
+ text: S.textStream,
536
+ parts: S.partStream,
537
+ reasoning: S.text,
538
+ },
539
+ },
540
+ }));
541
+ /**
542
+ * Generate, with the tools on the wire (20 §9) — the native door.
543
+ *
544
+ * ## Why this is a second type rather than two ports on `generate-text`
545
+ *
546
+ * `core:oracle/generate-text@1` is published and frozen: a spec that pinned
547
+ * it must keep meaning what it meant. Adding ports would move its content hash
548
+ * and every install would need a re-projection to keep booting — for a
549
+ * capability most connections do not have. A new pin costs a row and conflicts
550
+ * with nothing.
551
+ *
552
+ * It is otherwise the same node: same shape, same slots, same `context` in and
553
+ * the same `main`/`text`/`parts` out. A spec swaps one for the other and
554
+ * nothing else changes.
555
+ *
556
+ * ## The two doors, and why only one of them parses
557
+ *
558
+ * `advertise-tools` publishes both: `prompt` for models that never heard of
559
+ * tools, `native` for APIs that take a declaration list. Wire `native` here and
560
+ * the adapter puts the tools in the field its service calls them — and reads
561
+ * the answer back out of the structured field, so `toolCall` arrives as data.
562
+ * **There is nothing for `parse-tool-call` to do on this door**: the loop's
563
+ * predicate is this node's own `toolCall`, and `run-tool` takes it directly.
564
+ * Parsing prose the API already parsed would be a second reading of one answer.
565
+ *
566
+ * A connection whose adapter cannot send tools REFUSES a request carrying them
567
+ * rather than sending it without: a model that was never offered a tool and a
568
+ * model that declined one produce the same empty `toolCall`, and dropping the
569
+ * declarations silently is indistinguishable from a model choosing not to call.
570
+ * @experimental
571
+ */
572
+ export const generateWithTools = pin(describeOracleDefinition({
573
+ id: 'core:oracle/generate-with-tools@1',
574
+ i18n: { name: { en: 'Generate with tools' } },
575
+ shape: S.textGen,
576
+ effects: 'external',
577
+ /** The compiled prompt and the tool list: approve or refuse, as `generate-text` (R-15 review fields). */
578
+ review: { fields: [] },
579
+ timeoutMs: 120000,
580
+ timeoutKind: 'idle',
581
+ usage: 'response.usage',
582
+ slots: {
583
+ connection: {
584
+ kind: 'connection',
585
+ quick: true,
586
+ shape: S.textGen,
587
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
588
+ /**
589
+ * Asked rather than required, so this node is bindable to every
590
+ * text connection and the author decides what to do without one
591
+ * — which is the ruling on `optional` (`ctx.can`): the type
592
+ * system makes absence impossible to forget about, and the
593
+ * fallback is the author's to write. A spec that wants the
594
+ * emulated door instead wires `advertise-tools`' `prompt`.
595
+ */
596
+ optional: ['tools'],
597
+ description: 'Which model server this step sends its request to.',
598
+ },
599
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
600
+ // No `prompts` slot — see `generateText` (culled 2026-09-16, R-12).
601
+ params: {
602
+ kind: 'parameters',
603
+ facet: 'weights',
604
+ schema: {
605
+ stopSequences: {
606
+ type: 'string[]',
607
+ description: 'Sequences that end the reply the moment the model writes one. One per line.',
608
+ },
609
+ streaming: streamingParam(),
610
+ },
611
+ },
612
+ },
613
+ media: { accepts: ['image', 'document'], emits: ['image'] },
614
+ ports: {
615
+ in: {
616
+ context: S.assembled,
617
+ /** `advertise-tools`' `native` port — the declarations, verbatim. */
618
+ tools: S.json,
619
+ currentCharacterId: S.rowIds,
620
+ attachments: S.mediaList,
621
+ },
622
+ out: {
623
+ main: S.partStream,
624
+ text: S.textStream,
625
+ parts: S.partStream,
626
+ /**
627
+ * `{ tool, args }` when the model called one, null when it
628
+ * answered — the same shape `parse-tool-call` publishes, so
629
+ * `run-tool` and the loop's predicate take either door without
630
+ * knowing which was used.
631
+ */
632
+ toolCall: S.json,
633
+ },
634
+ },
635
+ }));
636
+ /**
637
+ * Generate, with the ANSWER's shape on the wire — the structured door.
638
+ *
639
+ * ## Why a third generate type rather than a schema port on the other two
640
+ *
641
+ * The same reason `generate-with-tools` is a second one: `generate-text@1` is
642
+ * published and frozen, and a port added to it moves the content hash every
643
+ * spec in every install pins. But the stronger reason here is that this node
644
+ * does not make the same REQUEST. `generate-text` sends a turn — a speaker, a
645
+ * trailing assistant line the model continues — and this sends an instruction.
646
+ * A parameter cannot express that difference honestly: a node whose prompt is
647
+ * sometimes a turn and sometimes a question is two nodes with a flag between
648
+ * them, and the flag is the thing a reader has to find before the receipt makes
649
+ * sense.
650
+ *
651
+ * So: no `currentCharacterId` and no `attachments`, and neither is an omission.
652
+ * The first is the speaker whose reply is being written, and nobody's reply is
653
+ * being written. The second is files travelling with a turn.
654
+ *
655
+ * ⚠ **The trailing assistant line is the TRANSCRIPT's business, not this
656
+ * node's.** A prompt arrives here already rendered, and on a completion wire the
657
+ * seed is an open block inside one string that nothing can take back out. So the
658
+ * guarantee is made where the line is never written:
659
+ * `core:task/prose-transcript@1`, which is what a spec wires into the assemble
660
+ * step feeding this node.
661
+ *
662
+ * ## It parses, and that is not the Provider doing two jobs
663
+ *
664
+ * `parse-json@1`'s own header says why the reading is a separate Task *there*:
665
+ * `generate-text` publishes prose, so the reading is a second step over
666
+ * somebody else's output, and every way it can fail deserves its own node on
667
+ * the receipt. Here the structure IS the output — a request that named a schema
668
+ * and came back with a document has nothing left to interpret — so publishing
669
+ * prose and asking the next node to recover the document from it would be
670
+ * undoing the work this node exists to do.
671
+ *
672
+ * The failures still show. `json` is null and `parseError` carries the sentence
673
+ * when the answer could not be read, and `structured` says which door the
674
+ * request actually went out through, so "the model ignored the schema" and
675
+ * "this connection takes no schema, so there was none" are told apart by
676
+ * reading rather than by guessing.
677
+ *
678
+ * `parse-json@1` stays declared and unchanged: it is content-addressed, other
679
+ * specs pin it, and a reply from `generate-text` still needs it.
680
+ * @public
681
+ */
682
+ export const generateJson = pin(describeOracleDefinition({
683
+ id: 'core:oracle/generate-json@1',
684
+ i18n: { name: { en: 'Generate JSON' } },
685
+ shape: S.textGen,
686
+ effects: 'external',
687
+ /** The compiled prompt and the schema: approve or refuse, as `generate-text` (R-15 review fields). */
688
+ review: { fields: [] },
689
+ timeoutMs: 120000,
690
+ timeoutKind: 'idle',
691
+ usage: 'response.usage',
692
+ /**
693
+ * An answer nobody can read costs the structure and nothing else.
694
+ *
695
+ * The same guarantee `parse-json@1` makes, kept here because this node
696
+ * replaced it in the chain: a planner whose document came back malformed
697
+ * should leave a turn with no plan, narrated anyway, rather than a turn
698
+ * that failed. The executor records `recoveredAsEmpty` and every
699
+ * downstream port reads absent, so a `map` over the missing list runs
700
+ * zero times.
701
+ */
702
+ optional: true,
703
+ slots: {
704
+ connection: {
705
+ kind: 'connection',
706
+ quick: true,
707
+ shape: S.textGen,
708
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
709
+ /**
710
+ * Asked rather than required, which is the `ctx.can` ruling: the
711
+ * node binds to every text connection and the binding decides
712
+ * what to do without them. The ladder is `json_schema` (the
713
+ * shape on the wire, natively or compiled to a grammar), then
714
+ * `json_object` (JSON, shape unsaid), then a sentence in the
715
+ * prompt — and the last rung works everywhere, so an absence
716
+ * costs fidelity rather than the step.
717
+ */
718
+ optional: ['json_schema', 'json_object'],
719
+ description: 'Which model server this step sends its request to.',
720
+ },
721
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
722
+ // No `prompts` slot — see `generateText` (culled 2026-09-16, R-12).
723
+ params: {
724
+ kind: 'parameters',
725
+ facet: 'weights',
726
+ schema: {
727
+ /**
728
+ * Which value inside the answer reaches `value` and `items`.
729
+ *
730
+ * A data reference is `{node, port}` with no sub-path, so a
731
+ * downstream `map` cannot iterate `plan.speakers` off a port
732
+ * carrying the whole document — the same reason `parse-json`
733
+ * carries this parameter, and the same spelling.
734
+ *
735
+ * Several dotted paths separated by commas are read in order
736
+ * and their lists joined. That is what makes an answer split
737
+ * into arms wireable at all: a keeper reports
738
+ * `{values, inventory}` (its item arm, named for the stat
739
+ * it resolves onto) because a schema can only be strict
740
+ * about a list whose items are all one shape, and the node
741
+ * that resolves them takes one list.
742
+ */
743
+ path: {
744
+ type: 'string',
745
+ quick: true,
746
+ description: 'Which value inside the answer to publish on `value` and `items`, as a dotted path. Several paths, separated by commas, are joined in order. Empty publishes the whole answer.',
747
+ },
748
+ stopSequences: {
749
+ type: 'string[]',
750
+ description: 'Sequences that end the reply the moment the model writes one. One per line.',
751
+ },
752
+ streaming: streamingParam(),
753
+ },
754
+ },
755
+ },
756
+ ports: {
757
+ in: {
758
+ context: S.assembled,
759
+ /**
760
+ * The shape the answer must take, as a JSON Schema document.
761
+ *
762
+ * Optional, and the node is useful without it: an unschema'd
763
+ * request still asks for JSON rather than prose. Supplied, it
764
+ * reaches whichever field the connection's service calls it —
765
+ * Ollama's `format`, OpenAI's `json_schema`, a GBNF grammar on
766
+ * the llama.cpp family — and a connection that takes none
767
+ * ignores it, which is the degradation rule the adapters
768
+ * already follow for `responseFormat`.
769
+ */
770
+ schema: S.json,
771
+ },
772
+ out: {
773
+ /** The parsed document, which is what this node is for. */
774
+ main: S.json,
775
+ json: S.json,
776
+ /** The value at `path` — the document itself when `path` is empty. */
777
+ value: S.json,
778
+ /** That same value as a list, for a `map` to iterate. */
779
+ items: S.json,
780
+ /** What the model actually wrote, for a reader diagnosing the above. */
781
+ text: S.textStream,
782
+ },
783
+ },
784
+ }));
785
+ /** @experimental */
786
+ export const speak = pin(describeOracleDefinition({
787
+ id: 'core:oracle/speak@1',
788
+ i18n: { name: { en: 'Speak' } },
789
+ shape: S.tts,
790
+ effects: 'external',
791
+ /** Declared, not bound — plans/14 owns the handler (plans/29 R-2). */
792
+ provisional: true,
793
+ /** The words to be spoken may be corrected before the call (R-15 review fields). */
794
+ review: { fields: ['text'] },
795
+ timeoutMs: 60000,
796
+ slots: {
797
+ connection: {
798
+ kind: 'connection',
799
+ quick: true,
800
+ shape: S.tts,
801
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.audio] })],
802
+ },
803
+ sampling: { kind: 'sampling', quick: true, shape: S.tts },
804
+ template: {
805
+ kind: 'template',
806
+ engine: jinja2.id,
807
+ facet: 'templates',
808
+ },
809
+ params: {
810
+ kind: 'parameters',
811
+ facet: 'weights',
812
+ schema: { skipCodeBlocks: { type: 'boolean', default: true } },
813
+ },
814
+ },
815
+ ports: { in: { text: S.text }, out: { main: S.audio, audio: S.audio } },
816
+ }));
817
+ /**
818
+ * Render an image.
819
+ *
820
+ * The structural twin of `generate-text` and `speak`, which is the whole point:
821
+ * one node KIND (`provider`), one type per modality, and the type's `shape`
822
+ * naming which one. That shape is what makes an image node offerable only an
823
+ * image connection and an image sampling config — and, just as importantly, what
824
+ * gives whatever is wired downstream a settled answer about what comes out of it.
825
+ * A single "generate anything" provider whose ports changed with its connection
826
+ * would be a node no spec could plan around.
827
+ *
828
+ * ## Nothing here belongs to one backend
829
+ *
830
+ * An A1111-compatible server takes width and height directly and names its
831
+ * schedulers its own way; ComfyUI takes a whole graph; a hosted API ignores seed
832
+ * and steps entirely. None
833
+ * of that appears in this declaration, because a slot only one backend honours is
834
+ * a control that does nothing on the other three. What a backend alone offers
835
+ * lives on its CONNECTION, declared by its adapter as a profile schema; what a
836
+ * person means lives here and in the sampling config, and the adapter translates
837
+ * — reporting whatever it could not carry across rather than dropping it quietly.
838
+ *
839
+ * ## Ports
840
+ *
841
+ * `media` carries references, never bytes (media.ts): the run stores the image
842
+ * and passes its uuid on, so a consumer that attaches it and a consumer that
843
+ * posts it both work from the same stored row rather than from a base64 string
844
+ * travelling through the graph. `image` is the first of them, for the common
845
+ * single-image wiring, and `caption` is the prompt that produced it — which is
846
+ * what a message posting the image usually wants as its text.
847
+ *
848
+ * `init` is declared now rather than added later: img2img changes nothing else
849
+ * about this contract, and retrofitting a port onto a published type costs a
850
+ * version bump for every spec pinning it.
851
+ * @experimental
852
+ */
853
+ export const generateImage = pin(describeOracleDefinition({
854
+ id: 'core:oracle/generate-image@1',
855
+ i18n: { name: { en: 'Generate image' } },
856
+ shape: S.imageGen,
857
+ effects: 'external',
858
+ /** The prompt and the negative may be edited; `init` names an asset and may not (R-15 review fields). */
859
+ review: { fields: ['prompt', 'negative'] },
860
+ // Idle rather than wall: a render is minutes on modest hardware, and a
861
+ // backend still reporting progress is working, not hung.
862
+ timeoutMs: 600000,
863
+ timeoutKind: 'idle',
864
+ slots: {
865
+ connection: {
866
+ kind: 'connection',
867
+ quick: true,
868
+ shape: S.imageGen,
869
+ /**
870
+ * The declaration that makes a KoboldCPP connection offerable
871
+ * here at all: its TYPE says text, and what it can do says
872
+ * otherwise.
873
+ */
874
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.image] })],
875
+ description: 'Which image server this step sends its request to.',
876
+ },
877
+ sampling: {
878
+ kind: 'sampling',
879
+ quick: true,
880
+ shape: S.imageGen,
881
+ description: 'Steps, CFG, size, seed — the settings every image backend shares.',
882
+ },
883
+ prompts: {
884
+ kind: 'prompts',
885
+ quick: true,
886
+ facet: 'prompts',
887
+ description: 'How the incoming text becomes what the image model is asked for.',
888
+ fields: {
889
+ positive: { type: 'text' },
890
+ negative: { type: 'text' },
891
+ },
892
+ },
893
+ /**
894
+ * No `facet`, unlike the text nodes' `weights`: the one parameter
895
+ * here decides how the request is SENT, and the weights facet is
896
+ * where a person looks for what the model is asked for.
897
+ *
898
+ * On an image backend `off` is the difference between one request
899
+ * and a render polled for progress and previews, which is the
900
+ * whole of what a background step saves by turning it off.
901
+ */
902
+ params: {
903
+ kind: 'parameters',
904
+ schema: { streaming: streamingParam() },
905
+ },
906
+ },
907
+ media: { emits: ['image', 'video'] },
908
+ ports: {
909
+ in: {
910
+ prompt: S.text,
911
+ negative: S.text,
912
+ /** An input image, for backends that report `img2img`. */
913
+ init: S.media,
914
+ },
915
+ out: {
916
+ main: S.mediaList,
917
+ media: S.mediaList,
918
+ image: S.image,
919
+ caption: S.text,
920
+ },
921
+ },
922
+ }));
923
+ /**
924
+ * A plugin's own image provider, kept as the worked example of one: same shape,
925
+ * same slots, a `params` schema of its own. Nothing in core dispatches it.
926
+ * @internal
927
+ */
928
+ export const renderImage = pin(describeOracleDefinition({
929
+ id: 'chariot.comfy:render-image@1',
930
+ shape: S.imageGen,
931
+ effects: 'external',
932
+ /** A sample plugin oracle: its payload is a compiled prompt — approve or refuse (R-15 review fields). */
933
+ review: { fields: [] },
934
+ timeoutMs: 300000,
935
+ slots: {
936
+ connection: {
937
+ kind: 'connection',
938
+ quick: true,
939
+ shape: S.imageGen,
940
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.image] })],
941
+ },
942
+ sampling: { kind: 'sampling', quick: true, shape: S.imageGen },
943
+ prompts: {
944
+ kind: 'prompts',
945
+ quick: true,
946
+ facet: 'prompts',
947
+ fields: {
948
+ positive: { type: 'text' },
949
+ negative: { type: 'text' },
950
+ },
951
+ },
952
+ params: {
953
+ kind: 'parameters',
954
+ facet: 'weights',
955
+ schema: { steps: { type: 'integer', default: 25 } },
956
+ },
957
+ },
958
+ ports: {
959
+ in: { context: S.assembled },
960
+ out: { main: S.image, image: S.image },
961
+ },
962
+ }));
963
+ // ── Sprites (DESIGN-sprites §5, 2026-09-24; in-pipeline 2026-10-05) ─────────
964
+ //
965
+ // A **sprite** is one labelled image a card can show — an emotion, an outfit,
966
+ // a pose. After a reply is saved, each reply spec chooses which one the line
967
+ // shows in two steps it writes out itself: the **sprite picker**
968
+ // (`core:oracle/pick-sprite@1`), handed the line's own text and whose line it
969
+ // is, and `show-sprite`, which records the pick on the line.
970
+ //
971
+ // Until 2026-10-05 a core-catalog wrapper appended a hidden tail of four nodes
972
+ // to five reply specs — `sprites-for` (which re-read the line from its message
973
+ // id and embedded inside the host), a junction, a pure picker task and the
974
+ // outlet — and the host read the picker's settings ahead of the run. The owner
975
+ // ruled it in-pipeline: every input is visible where the spec places the step.
976
+ /**
977
+ * **The sprite picker** — which sprite a line shows, chosen in one step from
978
+ * what the reply spec hands it: the line's text, whose line it is, and (when
979
+ * the spec knows it) the sprite set.
980
+ *
981
+ * All in one (owner, 2026-10-05). The step reads what the speaker can show —
982
+ * the set in force and that set's sprite labels, and the speaker's recent
983
+ * faces — then embeds the line and the labels, and picks the label whose
984
+ * vector is closest to the line's, with a small penalty on labels shown in the
985
+ * speaker's recent lines and a **stickiness margin**: the last shown sprite is
986
+ * kept unless the best beats it by `margin`, which stops a face flickering on
987
+ * every line. The receipt answers "why this face": `choices` carries the set
988
+ * and how it was decided, `pick` the label, its score, the runner-up and
989
+ * whether stickiness held.
990
+ *
991
+ * ⚠ **An oracle, because it embeds.** An embedding model is an external,
992
+ * nondeterministic source, and with an embedding service it is a provider
993
+ * call — one per reply whose speaker has sprites, after the reply is saved, so
994
+ * it never delays the reply. A task is pure and a query may not reach the
995
+ * network; this step does both of the things they may not.
996
+ *
997
+ * ⚠ **No connection slot.** A pipeline never chooses its embedding connection:
998
+ * the host embeds through the install's one active embedding connection, by
999
+ * policy, as it does for `embed-text`. Label vectors are the host's to cache
1000
+ * per model.
1001
+ *
1002
+ * **Picks nothing** — null, and embeds nothing — when `enabled` is off, when
1003
+ * the speaker has no sprites (no `speaker`, an envoy, a card with no art), or
1004
+ * when no embedding model is set up: an absent mechanism subtracts a signal, it
1005
+ * never guesses. A fault here must never fail a delivered reply, so the
1006
+ * binding answers a failure with null rather than an error.
1007
+ *
1008
+ * Not `core:outlet/show-sprite@1`, which records a pick; not the sprite set
1009
+ * slot (`core:slot/sprite-set@1`), which is the session's override this step
1010
+ * reads.
1011
+ * @experimental
1012
+ */
1013
+ export const pickSprite = pin(describeOracleDefinition({
1014
+ id: 'core:oracle/pick-sprite@1',
1015
+ i18n: { name: { en: 'Closest sprite' } },
1016
+ effects: 'external',
1017
+ /** Nothing to edit: a choice among the card's own sprites (R-15 review fields). */
1018
+ review: { fields: [] },
1019
+ timeoutMs: 5000,
1020
+ slots: {
1021
+ params: {
1022
+ kind: 'parameters',
1023
+ schema: {
1024
+ /**
1025
+ * Sprites off for this session (or instance): the picker
1026
+ * picks nothing and embeds nothing, and faces stay as they
1027
+ * are.
1028
+ */
1029
+ enabled: {
1030
+ type: 'boolean',
1031
+ label: 'Choose sprites',
1032
+ description: "Choose a sprite for each character's line. Off leaves faces as they are.",
1033
+ default: true,
1034
+ },
1035
+ margin: {
1036
+ type: 'number',
1037
+ label: 'Stickiness',
1038
+ description: 'How much closer a new sprite must be before the face changes. Higher keeps faces steadier.',
1039
+ min: 0,
1040
+ max: 0.5,
1041
+ default: 0.04,
1042
+ },
1043
+ floor: {
1044
+ type: 'number',
1045
+ label: 'Minimum similarity',
1046
+ description: 'A line less similar than this to every sprite keeps the last one, or shows neutral.',
1047
+ min: 0,
1048
+ max: 1,
1049
+ default: 0.1,
1050
+ },
1051
+ },
1052
+ },
1053
+ },
1054
+ ports: {
1055
+ in: {
1056
+ /**
1057
+ * The line's own text — the reply string the spec saved, wired
1058
+ * from the step that produced it. Never re-read from the row:
1059
+ * that is the hidden read this step replaced.
1060
+ */
1061
+ text: S.text,
1062
+ /**
1063
+ * Whose line it is, as a **participant reference** — the one the
1064
+ * spec wrote the reply row as (the inlet's `speaker`, or a
1065
+ * character turn's own). `character:<id>` has a card, and so may
1066
+ * have sprites; `envoy:<slug>`, or none at all (a narrator's
1067
+ * line), has none, and the pick is null.
1068
+ */
1069
+ speaker: S.participantRef,
1070
+ /**
1071
+ * The session the line is in — where the set is decided (the
1072
+ * session's override, the cast member's set at the session's
1073
+ * reading) and the speaker's recent faces are found: their
1074
+ * lines in this session other than the one this run is
1075
+ * writing. ⚠ Never read for whose line it is; that is `speaker`.
1076
+ */
1077
+ scope: S.sessionScope,
1078
+ /**
1079
+ * The sprite set to choose within, when the spec knows it.
1080
+ * Absent — every core spec — the set is decided from the
1081
+ * speaker, in one order: the session's override, then the cast
1082
+ * member's set, then the card's default set. A name the card
1083
+ * has no set by falls to the default set and says so on
1084
+ * `choices`, never silently.
1085
+ */
1086
+ set: S.text,
1087
+ },
1088
+ out: {
1089
+ /** The pick, `sprite-pick@1`: `{ set, label, … }`, or null for none. */
1090
+ main: S.spritePick,
1091
+ pick: S.spritePick,
1092
+ /**
1093
+ * What the speaker could show, and how the set was decided
1094
+ * (`decidedBy`, `missing`) — for the receipt, never for the line.
1095
+ */
1096
+ choices: S.spriteChoices,
1097
+ },
1098
+ },
1099
+ }));
1100
+ // ── Summarization ───────────────────────────────────────────────────────────
1101
+ /** Phase 1 — one batch, drafted without sight of any other. @internal */
1102
+ export const summarizeBatch = pin(describeOracleDefinition({
1103
+ id: 'core:oracle/summarize-batch@1',
1104
+ i18n: { name: { en: 'Draft a batch' } },
1105
+ shape: S.textGen,
1106
+ effects: 'external',
1107
+ /** A drafting call over a batch: approve or refuse (R-15 review fields). */
1108
+ review: { fields: [] },
1109
+ timeoutMs: 120000,
1110
+ timeoutKind: 'idle',
1111
+ usage: 'response.usage',
1112
+ /**
1113
+ * The first interior point (18 §4e), and core dogfooding it (07 §0b):
1114
+ * every intermediate draft passes the user's chain before synthesis
1115
+ * reads it — slop killed in the material summaries are built *from*,
1116
+ * not only in final replies. Invoked by the binding via
1117
+ * `ctx.scripts.applyText('each-draft', …)`; recorded per application
1118
+ * as `appliedBy: 'binding'`. Declares what it accepts (R-11): a draft
1119
+ * is text, so text transforms — said here rather than assumed by the
1120
+ * broker, which is the difference between a point a plugin can shape
1121
+ * and a literal in the executor.
1122
+ */
1123
+ scriptPoints: [
1124
+ {
1125
+ key: 'each-draft',
1126
+ accepts: ['core:script:text/transform@1'],
1127
+ label: { en: 'Each draft' },
1128
+ description: {
1129
+ en: 'Runs over every intermediate draft this step produces, before synthesis reads them.',
1130
+ },
1131
+ },
1132
+ ],
1133
+ slots: {
1134
+ connection: {
1135
+ kind: 'connection',
1136
+ quick: true,
1137
+ shape: S.textGen,
1138
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
1139
+ },
1140
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
1141
+ prompts: {
1142
+ kind: 'prompts',
1143
+ quick: true,
1144
+ facet: 'prompts',
1145
+ fields: { batch: { type: 'text' } },
1146
+ },
1147
+ },
1148
+ ports: {
1149
+ // `request` carries what a person asked for — the topic line, most
1150
+ // visibly — so the drafting prompt can honour it. The whole request
1151
+ // object travels rather than a plucked field, because what the
1152
+ // request holds is the socket's contract with its modal, not this
1153
+ // node's to enumerate.
1154
+ in: {
1155
+ batch: S.messages,
1156
+ request: S.summarizeRequest,
1157
+ /**
1158
+ * Which kind of entry this pipeline writes — the word every
1159
+ * summarize prompt template branches on (D-I).
1160
+ *
1161
+ * ## A port, not a parameter, and the call site is what decides
1162
+ *
1163
+ * `summarizeSpec` writes it as a **literal into the node's
1164
+ * config**, in the same map as `batch` and `request` and
1165
+ * alongside them: `C.summarizeBatch.v1({ batch, request,
1166
+ * loreType, … })`. `resolveInput` passes a non-ref config value
1167
+ * through untouched, so the binding reads `input.loreType`
1168
+ * exactly the way it reads a port — same position, same access,
1169
+ * same absence-is-`undefined`. Declaring it as anything else
1170
+ * would describe a mechanism that is not the one running.
1171
+ *
1172
+ * A `params` field is the alternative, and it is the wrong one
1173
+ * twice over. It would move the read to `input.params.loreType`
1174
+ * — a different value from a different layer — and it would put
1175
+ * the control in the panel, stored per configuration and
1176
+ * layered instance → user → session like every other parameter.
1177
+ * `SummarizeShape` in the catalog already rules on that: this is
1178
+ * "the thing that distinguishes the four namespaces from one
1179
+ * another", and a user who changed it "would turn their scene
1180
+ * summarizer into a world summarizer without renaming
1181
+ * anything".
1182
+ *
1183
+ * ⚠ An in-port no edge feeds is not a contradiction here. A
1184
+ * port is a named input the node reads; where the value comes
1185
+ * from — an upstream node, or an author writing it down — is the
1186
+ * document's business. What the declaration buys is that the
1187
+ * name is now checkable: the app's binding types derive their
1188
+ * legal reads from `ports.in`, so `input.loreTypes` stops
1189
+ * compiling, and the panel and the plugin validator can both see
1190
+ * that this node takes one.
1191
+ *
1192
+ * `text` rather than an enum shape: a shape ids a payload, and
1193
+ * the four legal words are the prompt templates' vocabulary,
1194
+ * which a plugin summarizer is free to extend.
1195
+ */
1196
+ loreType: S.text,
1197
+ },
1198
+ out: { main: S.textStream, draft: S.textStream },
1199
+ },
1200
+ }));
1201
+ /** Phase 2 — the ordered drafts merged into one past-tense narrative. @internal */
1202
+ export const summarizeSynth = pin(describeOracleDefinition({
1203
+ id: 'core:oracle/summarize-synth@1',
1204
+ i18n: { name: { en: 'Synthesize the drafts' } },
1205
+ shape: S.textGen,
1206
+ effects: 'external',
1207
+ /** The merge call: approve or refuse (R-15 review fields). */
1208
+ review: { fields: [] },
1209
+ timeoutMs: 120000,
1210
+ timeoutKind: 'idle',
1211
+ usage: 'response.usage',
1212
+ slots: {
1213
+ connection: {
1214
+ kind: 'connection',
1215
+ quick: true,
1216
+ shape: S.textGen,
1217
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
1218
+ },
1219
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
1220
+ prompts: {
1221
+ kind: 'prompts',
1222
+ quick: true,
1223
+ facet: 'prompts',
1224
+ fields: { synth: { type: 'text' } },
1225
+ },
1226
+ },
1227
+ ports: {
1228
+ // Same `request` pass-through as the batch step: the topic reaches
1229
+ // synthesis too, or a focused summary drifts back to a general one
1230
+ // the moment the drafts are merged.
1231
+ in: {
1232
+ drafts: S.drafts,
1233
+ request: S.summarizeRequest,
1234
+ /** Authored on the node, exactly as on the batch step — see it. */
1235
+ loreType: S.text,
1236
+ },
1237
+ out: { main: S.textStream, content: S.textStream },
1238
+ },
1239
+ }));
1240
+ /** What the entry gets called. Its own step because it has its own prompt. @internal */
1241
+ export const nameEntry = pin(describeOracleDefinition({
1242
+ id: 'core:oracle/name-entry@1',
1243
+ i18n: { name: { en: 'Name the entry' } },
1244
+ shape: S.textGen,
1245
+ effects: 'external',
1246
+ /** Approve or refuse; the name it produces is reviewed at the entry's write (R-15 review fields). */
1247
+ review: { fields: [] },
1248
+ timeoutMs: 60000,
1249
+ usage: 'response.usage',
1250
+ slots: {
1251
+ connection: {
1252
+ kind: 'connection',
1253
+ quick: true,
1254
+ shape: S.textGen,
1255
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
1256
+ },
1257
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
1258
+ prompts: {
1259
+ kind: 'prompts',
1260
+ quick: true,
1261
+ facet: 'prompts',
1262
+ fields: { name: { type: 'text' } },
1263
+ },
1264
+ },
1265
+ ports: {
1266
+ in: {
1267
+ content: S.text,
1268
+ /** Authored on the node, exactly as on the two steps above — see them. */
1269
+ loreType: S.text,
1270
+ },
1271
+ out: { main: S.textStream, name: S.textStream },
1272
+ },
1273
+ }));
1274
+ /**
1275
+ * Who was in the scene — scene summaries only.
1276
+ *
1277
+ * Present on one summarize pipeline and not the other three, which is exactly
1278
+ * why they are four specs rather than one spec with a flag. A flag would put the
1279
+ * difference in a condition somebody has to find; four specs put it in the shape.
1280
+ * @internal
1281
+ */
1282
+ export const extractCast = pin(describeOracleDefinition({
1283
+ id: 'core:oracle/extract-cast@1',
1284
+ i18n: { name: { en: 'Extract the cast' } },
1285
+ shape: S.textGen,
1286
+ effects: 'external',
1287
+ /** Approve or refuse (R-15 review fields). */
1288
+ review: { fields: [] },
1289
+ timeoutMs: 60000,
1290
+ usage: 'response.usage',
1291
+ slots: {
1292
+ connection: {
1293
+ kind: 'connection',
1294
+ quick: true,
1295
+ shape: S.textGen,
1296
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
1297
+ },
1298
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
1299
+ prompts: {
1300
+ kind: 'prompts',
1301
+ quick: true,
1302
+ facet: 'prompts',
1303
+ fields: { characterExtraction: { type: 'text' } },
1304
+ },
1305
+ /**
1306
+ * The two halves of a replaceable core function, on the scripts
1307
+ * rung. Scripts here *shape* the extraction — what the model reads,
1308
+ * what the pipeline keeps. Replacing the extractor itself is the
1309
+ * other rung: a same-shaped provider offered by the swap list,
1310
+ * because extraction calls a model and scripts are pure compute.
1311
+ */
1312
+ scripts: {
1313
+ kind: 'scripts',
1314
+ accepts: ['core:script:text/transform@1'],
1315
+ port: 'content',
1316
+ phase: 'before',
1317
+ description: 'Scripts over the scene text before the extractor reads it — strip out-of-character chatter, normalise a nickname, redact.',
1318
+ },
1319
+ castScripts: {
1320
+ kind: 'scripts',
1321
+ accepts: ['core:script:cast/transform@1'],
1322
+ port: 'cast',
1323
+ phase: 'after',
1324
+ description: 'Scripts over the extracted cast — rename someone, merge aliases, drop a junk detection, add someone the model missed.',
1325
+ },
1326
+ },
1327
+ ports: {
1328
+ // `request` carries the known cast list ([id: N] entries) so the
1329
+ // extraction prompt can reference real ids — without it the model
1330
+ // invents castIds and the resolve step silently drops every one.
1331
+ //
1332
+ // ⚠ No `messages` in-port, and there was one (culled 2026-09-16,
1333
+ // R-12). `summarize` wired the transcript into it and the handler
1334
+ // never read it: the extractor works from `content` — the synthesised
1335
+ // summary — which is what the prompt builder takes. A port a spec
1336
+ // fills and nothing reads costs the run a copy of the transcript
1337
+ // and tells a reader the extractor sees it.
1338
+ in: {
1339
+ content: S.text,
1340
+ request: S.summarizeRequest,
1341
+ },
1342
+ out: { main: S.json, cast: S.json },
1343
+ },
1344
+ }));
1345
+ // ── Graph build ─────────────────────────────────────────────────────────────
1346
+ const graphStep = (id, label, field, extra = {}) => pin(describeOracleDefinition({
1347
+ id,
1348
+ i18n: { name: { en: label } },
1349
+ shape: S.textGen,
1350
+ effects: 'external',
1351
+ /** Each graph step sends a compiled prompt: approve or refuse (R-15 review fields). */
1352
+ review: { fields: [] },
1353
+ timeoutMs: extra.timeoutMs ?? 120000,
1354
+ timeoutKind: 'idle',
1355
+ usage: 'response.usage',
1356
+ slots: {
1357
+ connection: {
1358
+ kind: 'connection',
1359
+ quick: true,
1360
+ shape: S.textGen,
1361
+ requires: [tf({ in: [IoKinds.text], out: [IoKinds.text] })],
1362
+ },
1363
+ sampling: { kind: 'sampling', quick: true, shape: S.textGen },
1364
+ prompts: {
1365
+ kind: 'prompts',
1366
+ quick: true,
1367
+ facet: 'prompts',
1368
+ fields: { [field]: { type: 'text' } },
1369
+ },
1370
+ },
1371
+ ports: {
1372
+ in: { scenes: S.graphScenes },
1373
+ out: { main: S.json, result: S.json },
1374
+ },
1375
+ }));
1376
+ /** Which existing node a mentioned name refers to, or whether it is new. @internal */
1377
+ export const graphNodeResolution = graphStep('core:oracle/graph-node-resolution@1', 'Resolve nodes', 'nodeResolution');
1378
+ /** Drop what is not worth graphing before the expensive steps run. @internal */
1379
+ export const graphPreFilter = graphStep('core:oracle/graph-pre-filter@1', 'Pre-filter', 'preFilter');
1380
+ /** Whose account of the scene this is. @internal */
1381
+ export const graphPerspective = graphStep('core:oracle/graph-perspective@1', 'Perspective', 'perspective');
1382
+ /** The two-sentence introduction written for a newly discovered character. @internal */
1383
+ export const graphNodeDescription = graphStep('core:oracle/graph-node-description@1', 'Describe new nodes', 'nodeDescription');
1384
+ /** Did any present character reach a new lifecycle state this scene? @internal */
1385
+ export const graphStateDetection = graphStep('core:oracle/graph-state-detection@1', 'Detect state changes', 'stateDetection');
1386
+ //# sourceMappingURL=oracles.js.map