@noetic-tools/types 2.0.0 → 2.1.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.
@@ -61,6 +61,32 @@ export interface ContextDetachedSpawnOverrides {
61
61
  resourceId?: string;
62
62
  cwdInit?: string;
63
63
  }
64
+ /**
65
+ * @public Caller-supplied wiring forwarded to the `createContext` call that
66
+ * `harness.restore()` makes internally.
67
+ *
68
+ * A snapshot recovers the item log, layer state, cwd, and identity — it cannot
69
+ * recover the live objects a host attached when it built the original context
70
+ * (event broadcasters, queues, per-host state). Pass the same wiring here that
71
+ * was passed to `createContext` originally, or the resumed run silently loses
72
+ * it.
73
+ *
74
+ * Snapshot-owned fields (`items`, `threadId`, `resourceId`, `cwdInit`) are
75
+ * deliberately absent: they always come from the persisted snapshot, so
76
+ * accepting them here would only offer a value that gets ignored.
77
+ *
78
+ * Anything a host attaches *after* construction — `Object.assign`ed fields,
79
+ * abort registration — stays the host's responsibility and can be applied to
80
+ * the context `restore()` returns.
81
+ */
82
+ export interface RestoreContextOptions {
83
+ /** Live parent context, when the restored execution hangs under one. */
84
+ parent?: Context;
85
+ /** Opaque per-execution state, same as `createContext({ state })`. */
86
+ state?: unknown;
87
+ /** Memory layers for the restored context. Defaults to the harness's configured layers. */
88
+ memory?: MemoryLayer[];
89
+ }
64
90
  export interface ContextRerenderRequest {
65
91
  layerId: string;
66
92
  slot: number;
@@ -150,7 +176,12 @@ export interface ContextHarness {
150
176
  initLayers(layers: MemoryLayer[], ctx: Context, storage: StorageAdapter): Promise<void>;
151
177
  disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
152
178
  checkpoint(ctx: Context): Promise<void>;
153
- restore(executionId: string): Promise<Context | null>;
179
+ restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
180
+ /**
181
+ * Cancel an execution: abort `ctx` and every live descendant context, then
182
+ * run memory-layer teardown (`onComplete` with `outcome: 'aborted'`, then
183
+ * `dispose`) bottom-up. A no-op on an already-cancelled context.
184
+ */
154
185
  cancel(ctx: Context, reason?: string): Promise<void>;
155
186
  /** Trace exporter spans are flushed to. Defaults to a no-op exporter. */
156
187
  readonly traceExporter: TraceExporter;
@@ -216,6 +247,18 @@ export interface Context<TMemory = ContextMemory, TState = unknown> {
216
247
  readonly completionValue: unknown;
217
248
  readonly aborted: boolean;
218
249
  readonly abortReason?: string;
250
+ /**
251
+ * Cancel this context and everything running beneath it. The first call wins
252
+ * (later calls are no-ops, so `abortReason` is stable), and it cascades
253
+ * *down* the execution tree: every live fork path and spawn child is aborted
254
+ * too. It never travels up — aborting a child leaves the parent running.
255
+ *
256
+ * Aborting rejects operations blocked on the context (channel `recv` waiters,
257
+ * parked back-pressure senders) with `cancelled`, cuts short the in-flight
258
+ * model call or sub-harness turn, and makes the next step boundary throw
259
+ * `cancelled`. Memory-layer teardown is NOT run — use
260
+ * `harness.cancel(ctx, reason)` for that.
261
+ */
219
262
  abort(reason?: string): void;
220
263
  }
221
264
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { ZodType } from 'zod';
2
2
  import type { Channel, ChannelHandle, ExternalChannel } from './channel.js';
3
3
  import type { LLMResponse, ModelParams, ServerToolSpec } from './common.js';
4
- import type { Context, CwdState } from './context.js';
4
+ import type { Context, CwdState, RestoreContextOptions } from './context.js';
5
5
  import type { DetachedHandle } from './detached.js';
6
6
  import type { FsAdapter } from './fs-adapter.js';
7
7
  import type { HarnessResponse, StreamEvent, StreamingItem } from './harness-result.js';
@@ -245,7 +245,22 @@ export interface AgentHarnessContract<TParams extends Record<string, unknown> =
245
245
  storeLayers(layers: MemoryLayer[], response: LLMResponse, ctx: Context): Promise<void>;
246
246
  disposeLayers(layers: MemoryLayer[], ctx: Context): Promise<void>;
247
247
  checkpoint(ctx: Context): Promise<void>;
248
- restore(executionId: string): Promise<Context | null>;
248
+ /**
249
+ * Rebuild a `Context` from a persisted snapshot. `opts` carries the wiring
250
+ * the host attached when it created the original context — without it a
251
+ * decorated context is silently replaced by a bare one on resume.
252
+ */
253
+ restore(executionId: string, opts?: RestoreContextOptions): Promise<Context | null>;
254
+ /**
255
+ * Cancel an execution. Aborts `ctx` and — cascading down the execution tree —
256
+ * every live fork path and spawn child, then runs memory-layer teardown
257
+ * (`onComplete` with `outcome: 'aborted'`, then `dispose`) bottom-up.
258
+ *
259
+ * Blocked channel operations reject with `cancelled`, the in-flight model
260
+ * call and sub-harness turn are cut short, and the next step boundary throws
261
+ * `cancelled`. Idempotent: cancelling an already-cancelled context is a
262
+ * no-op. Use `ctx.abort()` when you want the signal without layer teardown.
263
+ */
249
264
  cancel(ctx: Context, reason?: string): Promise<void>;
250
265
  /** Trace exporter spans are flushed to. Defaults to a no-op exporter. */
251
266
  readonly traceExporter: TraceExporter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/types",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "type": "module",
5
5
  "description": "Foundational type contracts and primitives shared across the Noetic framework (items, LLM config, adapters, steering, errors).",
6
6
  "license": "Apache-2.0",