@arcforge/types 2.0.146 → 2.0.148

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/src/kernel/abi.ts CHANGED
@@ -1,10 +1,11 @@
1
- import type { AxonEngineCall } from "../engine"
1
+ import type { AxonEngineCall, AxonEngineResponse } from "../engine"
2
2
  import type { AxonEngineEvent } from "../session/events/engine"
3
3
  import type { AxonEntry } from "../session/session"
4
4
  import type { AxonOutputEvent } from "../session/events/stdio/output"
5
5
  import type { AxonStimulusEntry } from "../session/events/stdio/stimuli"
6
6
  import type { CognetEventMap } from "../session/events/cognet"
7
7
  import type { AxonScope } from "../scope"
8
+ import type { Modality } from "../inference"
8
9
  import type { CapsuleScope } from "../capsule-scope"
9
10
 
10
11
  /**
@@ -24,7 +25,7 @@ import type { CapsuleScope } from "../capsule-scope"
24
25
  * the rule is the enforcement. (Additive changes — new event types, new
25
26
  * optional fields — are compatible, like new syscalls.)
26
27
  */
27
- export const KERNEL_ABI_VERSION = "10"
28
+ export const KERNEL_ABI_VERSION = "11"
28
29
 
29
30
  /**
30
31
  * The cognet's own store schema — EMPTY here by design. A cognet declares
@@ -270,6 +271,141 @@ export type AxonRunResult = {
270
271
  */
271
272
  export type CognetEngineCall = Omit<AxonEngineCall, "signal" | "output" | "retries">
272
273
 
274
+ /**
275
+ * One bound role, as the cognet holds it.
276
+ *
277
+ * A HANDLE, not a driver: what fills a role can be swapped while the agent
278
+ * runs (a user picks a different model), and a cognet holding the inner
279
+ * thing would be stranded by that. Calls dispatch through the manager, so a
280
+ * rebind is invisible here.
281
+ *
282
+ * `context` and `modalities` report what the role ACTUALLY got, which is how
283
+ * a brain that declared a floor decides how hard to push against it. `slots`
284
+ * is the concurrency granted: 1 on a laptop, more on a hosted route, never
285
+ * zero — a fanned-out role always degrades to sequential rather than absent.
286
+ */
287
+ export type KernelEngine = GenerateEngine | TransformEngine | StreamEngine
288
+
289
+ /** What every engine handle reports about what it actually got. */
290
+ type EngineFacts = {
291
+ /** Usable context window of the bound model. Undefined when the source does not report one. */
292
+ readonly context: number | undefined
293
+ /** What the bound model accepts and produces. */
294
+ readonly modalities: { in: readonly Modality[]; out: readonly Modality[] }
295
+ /** Concurrent calls this role may run. At least 1. */
296
+ readonly slots: number
297
+ }
298
+
299
+ /**
300
+ * Autoregressive generation over MESSAGES — the AIR protocol.
301
+ *
302
+ * `generate` is defined by its call shape, not by whether the model happens
303
+ * to sample autoregressively: a handle here takes a conversation and yields
304
+ * parsed blocks. That is why text-to-speech is a `transform` even though the
305
+ * model behind it generates token by token — it takes a string, not a
306
+ * timeline, and nothing about the grammar applies.
307
+ */
308
+ export type GenerateEngine = EngineFacts & {
309
+ readonly type: "generate"
310
+ /** Stream block events in real time, terminated by a single engine:done. */
311
+ stream(req: CognetEngineCall): AsyncGenerator<AxonEngineEvent>
312
+ /** Single-shot completion. Same response shape as the stream's done event. */
313
+ request(req: CognetEngineCall): Promise<AxonEngineResponse>
314
+ }
315
+
316
+ /**
317
+ * One shot in, one shot out — ASR, embeddings, classifiers, depth, TTS.
318
+ *
319
+ * The kernel does NOT interpret either side. A depth map is a shaped array, a
320
+ * transcript is text with timings, an embedding is a vector; what the bytes
321
+ * MEAN is the cognet's business, exactly as the weights behind `models:` were.
322
+ * The one thing this contract guarantees is that the call happened and the
323
+ * result came back.
324
+ *
325
+ * `onProgress` exists because "one shot" is about SHAPE, not duration: an
326
+ * image generation is thirty seconds of denoising steps, and a bare promise
327
+ * makes that indistinguishable from a hang. Absent for the many transforms
328
+ * that finish in milliseconds and report nothing.
329
+ */
330
+ export type TransformEngine = EngineFacts & {
331
+ readonly type: "transform"
332
+ transform(input: unknown, opts?: TransformOptions): Promise<unknown>
333
+ }
334
+
335
+ export type TransformOptions = {
336
+ /**
337
+ * Progress for a long transform, when the binding reports any.
338
+ *
339
+ * `fraction` is 0..1 where the model knows its own total (denoising
340
+ * steps); absent where it does not, so a caller renders a spinner rather
341
+ * than a bar that lies.
342
+ */
343
+ onProgress?: (progress: { fraction?: number; message?: string }) => void
344
+ }
345
+
346
+ /**
347
+ * A stateful sequential feed — VAD, streaming ASR, trackers.
348
+ *
349
+ * Distinct from `transform` because the model carries hidden state ACROSS
350
+ * calls: Silero's LSTM is what lets it tell a pause mid-sentence from
351
+ * silence, and feeding frames out of order or through two sessions destroys
352
+ * exactly that. So a caller opens one session and pushes into it, rather than
353
+ * making N independent calls.
354
+ *
355
+ * The session is the cognet's to hold — it is resident memory of precisely
356
+ * the kind a brain keeps.
357
+ */
358
+ export type StreamEngine = EngineFacts & {
359
+ readonly type: "stream"
360
+ /** Begin one sequence. Every push into it shares the model's hidden state. */
361
+ open(): EngineSession
362
+ }
363
+
364
+ export type EngineSession = {
365
+ /** Feed one item. Order is significant — that is what makes this not a transform. */
366
+ push(input: unknown): Promise<unknown>
367
+ /**
368
+ * Forget the sequence so far, keeping the session.
369
+ *
370
+ * Every stateful model has some version of "this is a new utterance" —
371
+ * reopening instead would rebuild the graph, which is the expensive part
372
+ * and exactly what a session exists to amortise.
373
+ */
374
+ reset(): void
375
+ /** Release the session. The engine stays loaded; only this sequence ends. */
376
+ close(): void
377
+ }
378
+
379
+ /**
380
+ * The cognet's whole inference vocabulary: name a role, get a handle.
381
+ *
382
+ * Callable, with `has` hanging off it, so the common case reads as one verb
383
+ * (`kernel.engine("main")`) and the degradation check reads as a question
384
+ * (`kernel.engine.has("percept")`).
385
+ */
386
+ export type KernelEngines = {
387
+ /**
388
+ * The handle for a declared role.
389
+ *
390
+ * Throws for an unbound one. Deliberately loud: a REQUIRED role that
391
+ * could not be filled already stopped the boot, so reaching here means a
392
+ * cognet called an OPTIONAL engine without asking `has()` first — a
393
+ * cognet bug, and a null handle would only move the crash one frame
394
+ * later with less to say about it.
395
+ */
396
+ (role: string): KernelEngine
397
+
398
+ /**
399
+ * Is this role filled?
400
+ *
401
+ * The entire degradation contract. A cognet asks before using anything
402
+ * it declared optional and takes a cheaper path when the answer is no —
403
+ * which is what lets one brain run against a frontier account and
404
+ * against a single local model without knowing which it got.
405
+ */
406
+ has(role: string): boolean
407
+ }
408
+
273
409
  export type KernelAbi = {
274
410
  /**
275
411
  * Emit a fact to the world — text, audio, visual, or a declared field
@@ -282,21 +418,25 @@ export type KernelAbi = {
282
418
  output<K extends keyof AxonOutputEvent>(type: K, data: AxonOutputEvent[K]): Promise<void>
283
419
 
284
420
  /**
285
- * Inference — messages in, structured engine events out. The kernel
286
- * mediates access to the provider (auth, metering, later quotas); the
287
- * program owns everything about what the messages contain. Yields raw
288
- * engine:* wire events (see session/events/engine.ts) — the cognet
289
- * decides what to do with each: output() a text block, run() a
290
- * typescript block. The kernel never pre-labels these as the cognet's
291
- * own committed output; that decision belongs to the cognet alone.
421
+ * Inference, by ROLE — the names this cognet declared in `engines:`.
292
422
  *
293
- * `protocol` selects the grammar the reply is parsed with, and belongs
294
- * to the caller because the caller is what rendered the context — a
295
- * cognet showing the model one contract while the kernel parsed
296
- * classic tags would discard every block silently. Omitted keeps the
297
- * default, so a cognet that never mentions it is unaffected.
423
+ * ```ts
424
+ * const main = kernel.engine("main")
425
+ * for await (const event of main.stream({ messages })) { }
426
+ * ```
427
+ *
428
+ * Replaces the old flat `stream()`, which could only ever reach one
429
+ * model because an agent could only configure one. A cognet now names
430
+ * what an engine is FOR and the kernel hands over whatever the user's
431
+ * declared providers could fill it with — so a compression pass, a
432
+ * critic and a cortex are three roles rather than three reasons to
433
+ * couple a brain to a provider.
434
+ *
435
+ * The kernel still mediates every call (auth, metering, the grammar the
436
+ * reply is parsed with); what it no longer decides is WHICH model, and
437
+ * the cognet still never learns.
298
438
  */
299
- stream(req: CognetEngineCall): AsyncGenerator<AxonEngineEvent>
439
+ engine: KernelEngines
300
440
 
301
441
  /**
302
442
  * Execute code in the capsule — ring 3, policy-mediated. The only
@@ -437,24 +577,6 @@ export type KernelAbi = {
437
577
  */
438
578
  clock(): KernelClock
439
579
 
440
- /**
441
- * Absolute paths to the weights this cognet declared, by the name it gave
442
- * them. Empty when none were declared.
443
- *
444
- * ```ts
445
- * const session = await ort.InferenceSession.create(kernel.models.vad)
446
- * ```
447
- *
448
- * Handed over at load rather than read from the cognet's own config,
449
- * because a filesystem path is ENVIRONMENTAL: the same brain gets a
450
- * different absolute path on every machine, and must never learn that.
451
- * The config says which weights are needed; this says where they landed.
452
- *
453
- * Whether they were fetched from a registry, restored from a shared
454
- * cache, or baked into a deployment image is invisible here — the kernel
455
- * guarantees the file exists and was verified, nothing more.
456
- */
457
- models: Readonly<Record<string, string>>
458
580
  }
459
581
 
460
582
  /**
@@ -1,3 +1,3 @@
1
1
  export { KERNEL_ABI_VERSION } from "./abi"
2
- export type { KernelAbi, CognetWake, CognetEngineCall, AxonRunResult, KernelStore, KernelClock, KernelKnowledge, KnowledgeEntry } from "./abi"
2
+ export type { KernelAbi, CognetWake, CognetEngineCall, AxonRunResult, KernelStore, KernelClock, KernelKnowledge, KnowledgeEntry, KernelEngine, KernelEngines, GenerateEngine, TransformEngine, StreamEngine, EngineSession, TransformOptions } from "./abi"
3
3
 
package/src/policy.ts CHANGED
@@ -21,6 +21,36 @@ export type PolicyRule =
21
21
  }
22
22
 
23
23
 
24
+
25
+ /**
26
+ * A whole enforcement surface's policy — one rule for everything in it, or a
27
+ * rule per key.
28
+ *
29
+ * The bare form is what makes "lock this down" expressible. Keyed alone, a
30
+ * blanket statement had to be written out as one entry per installed module —
31
+ * a list that is complete the day it is written and silently stale the moment
32
+ * anything else is installed. `tools: "escalate"` cannot go stale, because it
33
+ * names the surface rather than its current contents.
34
+ *
35
+ * Deliberately NOT offered at the top level of `CapsulePolicy`. That object
36
+ * also holds `isolation`, `fs` and `limits`, which are OS facts with no
37
+ * verdict to give — so a bare `policy: "deny"` would have to mean "the
38
+ * permission-ish subset of these keys", a scope a reader has to be told rather
39
+ * than read. Each key here names exactly one surface, so a rule on it is
40
+ * unambiguous.
41
+ *
42
+ * The two forms compose: `{ "*": "escalate", fs: true }` is the keyed form
43
+ * with a wildcard, and a named key beats it — ordinary glob precedence, within
44
+ * one layer. Across layers the profile's blanket still wins outright; see
45
+ * `intersect`.
46
+ *
47
+ * AUTHORING ONLY. `CapsulePolicy` — the wire type the capsule enforces — stays
48
+ * keyed, because the mediator should never have to ask which shape it was
49
+ * handed on a hot path. The bare form is normalised into `{ "*": rule }` at
50
+ * the one seam that already normalises everything else.
51
+ */
52
+ export type PolicyBucket = PolicyRule | Record<string, PolicyRule>
53
+
24
54
  /**
25
55
  * Capsule-level wire type. Describes what the sandbox subprocess is allowed to
26
56
  * do. Passed directly to the capsule on boot or via `capsule.update()`.
@@ -42,7 +42,20 @@ export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cogn
42
42
 
43
43
  export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
44
44
  /** Kernel signal record — an interrupt is machinery, never a stimulus. */
45
- "axon:interrupt": { reason: "user" | "shutdown" }
45
+ /**
46
+ * A run cut short.
47
+ *
48
+ * `reason` is WHY — a person changed their mind, or the process is going
49
+ * down. `from` is WHICH SURFACE said so, the same vocabulary a stimulus
50
+ * channel uses (`terminal`, `axon-cli`, `telegram:…`). They answer
51
+ * different questions and an agent reading its own history needs both: a
52
+ * shutdown is not something to ask about, and an interrupt from a channel
53
+ * the agent was mid-reply to is.
54
+ *
55
+ * `from` is optional because a shutdown has no surface behind it — nobody
56
+ * pressed anything. Absent means the runtime itself.
57
+ */
58
+ "axon:interrupt": { reason: "user" | "shutdown"; from?: string }
46
59
 
47
60
  /** Code the cognet ran via kernel.run(). `id` is referenced by cognet:action:result.for. */
48
61
  "cognet:action:typescript": { id: string; content: string }
@@ -50,6 +50,29 @@ export type AxonKernelEventMap =
50
50
  { attempts: number; text: string; thinking?: string; stopReason: "end" | "length" | "abort"; meta: AxonEngineMeta },
51
51
  { attempts: number; fault: AxonEngineFault }
52
52
  >
53
+ /**
54
+ * A non-generate engine call — ASR, embeddings, depth, TTS.
55
+ *
56
+ * Its OWN family rather than a reuse of kernel:engine, because that span's
57
+ * completion carries text, a stop reason and token meta: a depth map has
58
+ * none of those, and a transform forced into that shape would have to lie
59
+ * about four fields. Same reason kernel:run is not kernel:engine.
60
+ *
61
+ * The payload never appears — it is a tensor, an image or a waveform, and
62
+ * the log records what happened rather than copying what moved. What is
63
+ * here is the thing a reader wants: which role, which model, how long.
64
+ *
65
+ * `stream` engines are bracketed at OPEN and CLOSE, not per push. A VAD at
66
+ * 30Hz is 1800 pushes a minute; a span for each would drown every other
67
+ * event in the log, and the session's lifetime is the interval that
68
+ * actually means something.
69
+ */
70
+ & AxonSpan<
71
+ "kernel:transform",
72
+ { role: string; provider: string; model?: string },
73
+ { role: string; durationMs: number },
74
+ { role: string; fault: AxonEngineFault }
75
+ >
53
76
  & {
54
77
  /**
55
78
  * The rendered AIR document handed to the engine for this call — what the