@noetic-tools/core 5.16.0 → 5.16.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.
@@ -6,8 +6,8 @@ import { AcpSessionStore } from '../runtime/acp-session-store.js';
6
6
  import { callDecide } from './decide-call.js';
7
7
  import { createInMemoryFsAdapter, createInMemoryShellAdapter, createInMemorySubprocessAdapter, OpenRouter, OpenRouterSdk, } from './deps/adapters.js';
8
8
  import { afterModelCallLayers, allocateBudgets, assembleView, beforeToolCallLayers, completeLayers, contextToExecCtx, createContextCacheStore, createLayerStateStore, createRecallCache, DEFAULT_PROJECTION, disposeLayers, executeRerender, initLayers, notifyDecision, onSteerLayers, projectHistoryLayers, recallLayers, recallLayersAtomic, recallLayersEventual, resolveLayerTools, runAppendPipeline, storeLayers, } from './deps/context.js';
9
- import { collectAllTools, collectCustomItems, customItemGates, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, someStep, } from './deps/interpreter.js';
10
- import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createCheckpointStore, createInMemoryStorage, createSessionStore, createStepLedgerStore, filterReasoningStream, filterTextStream, INTERRUPT_REASON, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, warnToConsole, } from './deps/runtime.js';
9
+ import { collectAllTools, collectCustomItems, deduplicateTools, dispatchStepThroughAdapter, execute, prepareBandedView, someStep, } from './deps/interpreter.js';
10
+ import { buildItemStream, ChannelStore, ContextImpl, captureCheckpoint, clearCheckpoint, collectContextTree, createCheckpointStore, createInMemoryStorage, createSessionStore, createStepLedgerStore, customItemGates, filterReasoningStream, filterTextStream, INTERRUPT_REASON, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, warnToConsole, } from './deps/runtime.js';
11
11
  import { SteeringAction } from './deps/types.js';
12
12
  import { AgentHarnessModelCaller, noLlmProviderError } from './model-call.js';
13
13
  import { ThreadRecord } from './thread-record.js';
@@ -374,7 +374,7 @@ export class AgentHarness {
374
374
  strictUnknownExtensions: opts.itemSchemas?.strict ?? true,
375
375
  }).extend({
376
376
  items: opts.agentGraph
377
- ? customItemGates(collectCustomItems(frameworkCast(opts.agentGraph)))
377
+ ? customItemGates(collectCustomItems(frameworkCast(opts.agentGraph)).map((item) => item.type))
378
378
  : [],
379
379
  });
380
380
  this.rootCwdState = {
@@ -770,9 +770,11 @@ export class AgentHarness {
770
770
  async rebuildFromStorage(ctx) {
771
771
  await this.pendingCheckpoints.get(ctx.id);
772
772
  const snapshot = await this.checkpointStore?.load(ctx.id).catch(() => null);
773
+ ctx.allowItemTypes(snapshot?.customItemTypes ?? []);
774
+ const itemSchemas = ctx.itemSchemas ?? this.itemSchemas;
773
775
  ctx.rebase(snapshot
774
776
  ? {
775
- items: this.itemSchemas.parseMany(snapshot.itemLog.items),
777
+ items: itemSchemas.parseMany(snapshot.itemLog.items),
776
778
  occurrences: snapshot.occurrences,
777
779
  }
778
780
  : ctx.runBaseline());
@@ -1,6 +1,6 @@
1
1
  export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
2
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
3
- export { collectCustomItems, customItemGates } from '../../interpreter/emit-items.js';
3
+ export { collectCustomItems } from '../../interpreter/emit-items.js';
4
4
  export { execute } from '../../interpreter/execute.js';
5
5
  export type { DetachedSpawnOverrides } from '../../interpreter/step-dispatcher.js';
6
6
  export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
@@ -1,6 +1,6 @@
1
1
  export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
2
2
  export { prepareBandedView } from '../../interpreter/context-assembly.js';
3
- export { collectCustomItems, customItemGates } from '../../interpreter/emit-items.js';
3
+ export { collectCustomItems } from '../../interpreter/emit-items.js';
4
4
  export { execute } from '../../interpreter/execute.js';
5
5
  export { dispatchStepThroughAdapter } from '../../interpreter/step-dispatcher.js';
6
6
  export { someStep } from '../../interpreter/step-walk.js';
@@ -12,6 +12,7 @@ export type { StepLedgerEntry, StepLedgerRetention, StepLedgerStore, } from '../
12
12
  export { createStepLedgerStore, resolveStepLedgerRetention, StepLedger, } from '../../runtime/durable/step-ledger.js';
13
13
  export type { EventBroadcaster } from '../../runtime/event-broadcaster.js';
14
14
  export { createInMemoryStorage } from '../../runtime/in-memory-storage.js';
15
+ export { customItemGates } from '../../runtime/item-gates.js';
15
16
  export type { QueuedMessage, SessionCtxExtension } from '../../runtime/message-queue.js';
16
17
  export { INTERRUPT_REASON } from '../../runtime/message-queue.js';
17
18
  export type { TurnUsage } from '../../runtime/session-runner.js';
@@ -6,6 +6,7 @@ export { captureCheckpoint, clearCheckpoint, restoreFromCheckpoint, } from '../.
6
6
  export { createSessionStore } from '../../runtime/durable/session-store.js';
7
7
  export { createStepLedgerStore, resolveStepLedgerRetention, StepLedger, } from '../../runtime/durable/step-ledger.js';
8
8
  export { createInMemoryStorage } from '../../runtime/in-memory-storage.js';
9
+ export { customItemGates } from '../../runtime/item-gates.js';
9
10
  export { INTERRUPT_REASON } from '../../runtime/message-queue.js';
10
11
  export { SessionRunner } from '../../runtime/session-runner.js';
11
12
  export { buildItemStream, filterReasoningStream, filterTextStream, } from '../../runtime/session-streams.js';
@@ -1,5 +1,4 @@
1
1
  import type { Context, CustomItem, Item, Step } from '@noetic-tools/types';
2
- import type { ZodTypeAny } from 'zod';
3
2
  /**
4
3
  * Starts what a step emits (spec 34 § Emitting): opens the dispatch's custom item, if
5
4
  * `emitItems` names one, and runs `onStart` with the step's input. Events stream at
@@ -41,11 +40,6 @@ export declare function allowCustomItems<TContext, I, O>(step: Step<TContext, I,
41
40
  * before it rebuilds or restores a log that may hold them.
42
41
  */
43
42
  export declare function collectCustomItems(step: Step): CustomItem[];
44
- /**
45
- * Schemas that let a context's item log accept these items' final forms. They gate on
46
- * `type` and `id` only: the emitter has already checked the fields against `output`.
47
- */
48
- export declare function customItemGates(items: ReadonlyArray<CustomItem>): ZodTypeAny[];
49
43
  /**
50
44
  * Puts a replayed entry's items back on the log. The ones at `emitted` (the entry's
51
45
  * `streamed` indices) keep their mark, so a parent that records on this resumed run
@@ -1,5 +1,4 @@
1
1
  import { frameworkCast, NoeticConfigError, validateSchema } from '@noetic-tools/types';
2
- import { z } from 'zod';
3
2
  import { emitFrameworkEvent, getBroadcaster } from '../runtime/broadcaster-utils.js';
4
3
  import { ContextImpl } from '../runtime/context-impl.js';
5
4
  import { stepChildren } from './step-walk.js';
@@ -98,7 +97,7 @@ export function allowCustomItems(step, ctx) {
98
97
  if (items.length === 0 || !(ctx instanceof ContextImpl)) {
99
98
  return;
100
99
  }
101
- ctx.allowItems(customItemGates(items));
100
+ ctx.allowItemTypes(items.map((item) => item.type));
102
101
  }
103
102
  /**
104
103
  * Every custom item declared anywhere in `step`'s static tree, for a harness to accept
@@ -110,18 +109,6 @@ export function collectCustomItems(step) {
110
109
  ...stepChildren(step).flatMap(collectCustomItems),
111
110
  ];
112
111
  }
113
- /**
114
- * Schemas that let a context's item log accept these items' final forms. They gate on
115
- * `type` and `id` only: the emitter has already checked the fields against `output`.
116
- */
117
- export function customItemGates(items) {
118
- return [
119
- ...new Set(items.map((item) => item.type)),
120
- ].map((type) => z.looseObject({
121
- type: z.literal(type),
122
- id: z.string(),
123
- }));
124
- }
125
112
  /**
126
113
  * Puts a replayed entry's items back on the log. The ones at `emitted` (the entry's
127
114
  * `streamed` indices) keep their mark, so a parent that records on this resumed run
@@ -1,4 +1,3 @@
1
- import type { ZodTypeAny } from 'zod';
2
1
  import type { AgentHarnessContract, Channel, ChannelStore, Context, ContextData, ContextLayer, CwdState, EventBroadcaster, FrontierFrame, FsAdapter, Item, ItemLog, ItemSchemaRegistry, LastLayerUsage, Span, StepMeta, TokenUsage, Tool } from './context-deps.js';
3
2
  import type { StepLedger } from './durable/step-ledger.js';
4
3
  /**
@@ -30,6 +29,8 @@ export declare class ContextImpl implements Context<ContextData> {
30
29
  readonly itemLog: ItemLog;
31
30
  /** The same log, typed for `rebase`. */
32
31
  private readonly log;
32
+ /** Custom item types `allowItemTypes` has accepted. Shared by every lane. */
33
+ private readonly _customItemTypes;
33
34
  lastStepMeta: StepMeta | null;
34
35
  lastLayerUsage: LastLayerUsage | undefined;
35
36
  readonly harness: AgentHarnessContract;
@@ -252,11 +253,14 @@ export declare class ContextImpl implements Context<ContextData> {
252
253
  emittedIndices(): number[];
253
254
  /**
254
255
  * @internal
255
- * Accept items matching `schemas` in this context's log from now on, as a step's
256
- * custom items need. Contexts created from this one afterwards inherit the wider
257
- * registry; a lane widens the context it views.
258
- */
259
- allowItems(schemas: ReadonlyArray<ZodTypeAny>): void;
256
+ * Accept the final items of these custom item types in this context's log from now
257
+ * on (spec 34). Contexts created from this one afterwards inherit the wider registry,
258
+ * and a lane widens the context it views. A checkpoint records the types, so a
259
+ * restore can accept a stored log that holds them before any step runs.
260
+ */
261
+ allowItemTypes(types: ReadonlyArray<string>): void;
262
+ /** @internal The custom item types this context accepts, for a checkpoint to record. */
263
+ customItemTypes(): string[];
260
264
  /**
261
265
  * @internal
262
266
  * Append an item a step emitted (`step.emitItems`), marking it in this lane's record
@@ -1,5 +1,6 @@
1
1
  import { buildContextData, defaultItemSchemaRegistry } from './context-deps.js';
2
2
  import { hashStepInput } from './durable/step-ledger.js';
3
+ import { customItemGates } from './item-gates.js';
3
4
  import { ItemLogImpl } from './item-log-impl.js';
4
5
  const EMPTY_CONTEXT = Object.freeze({});
5
6
  class NoopSpan {
@@ -60,6 +61,8 @@ export class ContextImpl {
60
61
  itemLog;
61
62
  /** The same log, typed for `rebase`. */
62
63
  log;
64
+ /** Custom item types `allowItemTypes` has accepted. Shared by every lane. */
65
+ _customItemTypes = new Set();
63
66
  lastStepMeta = null;
64
67
  lastLayerUsage = undefined;
65
68
  harness;
@@ -416,17 +419,31 @@ export class ContextImpl {
416
419
  }
417
420
  /**
418
421
  * @internal
419
- * Accept items matching `schemas` in this context's log from now on, as a step's
420
- * custom items need. Contexts created from this one afterwards inherit the wider
421
- * registry; a lane widens the context it views.
422
- */
423
- allowItems(schemas) {
422
+ * Accept the final items of these custom item types in this context's log from now
423
+ * on (spec 34). Contexts created from this one afterwards inherit the wider registry,
424
+ * and a lane widens the context it views. A checkpoint records the types, so a
425
+ * restore can accept a stored log that holds them before any step runs.
426
+ */
427
+ allowItemTypes(types) {
428
+ const added = types.filter((type) => !this._customItemTypes.has(type));
429
+ if (added.length === 0) {
430
+ return;
431
+ }
432
+ for (const type of added) {
433
+ this._customItemTypes.add(type);
434
+ }
424
435
  const registry = (this.itemSchemas ?? defaultItemSchemaRegistry).extend({
425
- items: schemas,
436
+ items: customItemGates(added),
426
437
  });
427
438
  this.itemSchemas = registry;
428
439
  this.log.useSchemas(registry);
429
440
  }
441
+ /** @internal The custom item types this context accepts, for a checkpoint to record. */
442
+ customItemTypes() {
443
+ return [
444
+ ...this._customItemTypes,
445
+ ];
446
+ }
430
447
  /**
431
448
  * @internal
432
449
  * Append an item a step emitted (`step.emitItems`), marking it in this lane's record
@@ -1,5 +1,6 @@
1
1
  import { CheckpointSchemaVersion } from '../../types/checkpoint.js';
2
2
  import { ContextImpl, rootIdOf } from '../context-impl.js';
3
+ import { customItemGates } from '../item-gates.js';
3
4
  import { StepLedger } from './step-ledger.js';
4
5
  //#endregion
5
6
  //#region captureCheckpoint
@@ -58,6 +59,11 @@ export async function captureCheckpoint(h, ctx) {
58
59
  items: baseline.items,
59
60
  },
60
61
  occurrences: baseline.occurrences,
62
+ ...(impl && impl.customItemTypes().length > 0
63
+ ? {
64
+ customItemTypes: impl.customItemTypes(),
65
+ }
66
+ : {}),
61
67
  ...(state.ok
62
68
  ? {
63
69
  state: state.value,
@@ -165,14 +171,28 @@ function contextFromSnapshot(h, snapshot, opts) {
165
171
  /* Caller wiring first, snapshot second: a host may legitimately swap the context
166
172
  * layers or hang the restored execution under a new parent, but it must never be
167
173
  * able to override the identity/history the snapshot is the record of. */
174
+ const customItemTypes = snapshot.customItemTypes ?? [];
175
+ const items = h.itemSchemas
176
+ .extend({
177
+ items: customItemGates(customItemTypes),
178
+ })
179
+ .parseMany(snapshot.itemLog.items);
168
180
  const ctx = h.createContext({
169
181
  ...opts,
170
182
  state: opts?.state ?? snapshot.state,
171
- items: h.itemSchemas.parseMany(snapshot.itemLog.items),
183
+ items: [],
172
184
  threadId: snapshot.threadId,
173
185
  resourceId: snapshot.resourceId,
174
186
  cwdInit: snapshot.cwd?.current ?? undefined,
175
187
  });
188
+ /* The log goes in after the context accepts the recorded custom item types:
189
+ * seeded at creation, it would be checked against the harness's schemas alone. */
190
+ if (ctx instanceof ContextImpl) {
191
+ ctx.allowItemTypes(customItemTypes);
192
+ }
193
+ for (const item of items) {
194
+ ctx.itemLog.append(item);
195
+ }
176
196
  if (ctx instanceof ContextImpl) {
177
197
  ctx.restoreOccurrences(snapshot.occurrences);
178
198
  if (snapshot.usage) {
@@ -0,0 +1,8 @@
1
+ import type { ZodTypeAny } from 'zod';
2
+ /**
3
+ * Item schemas that let a log accept the final items of these custom item types
4
+ * (spec 34). They gate on `type` and `id` only: an emitter checks an item's fields
5
+ * against its declared `output` before appending it, and a restore reads back items
6
+ * that were checked when they were emitted.
7
+ */
8
+ export declare function customItemGates(types: Iterable<string>): ZodTypeAny[];
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Item schemas that let a log accept the final items of these custom item types
4
+ * (spec 34). They gate on `type` and `id` only: an emitter checks an item's fields
5
+ * against its declared `output` before appending it, and a restore reads back items
6
+ * that were checked when they were emitted.
7
+ */
8
+ export function customItemGates(types) {
9
+ return [
10
+ ...new Set(types),
11
+ ].map((type) => z.looseObject({
12
+ type: z.literal(type),
13
+ id: z.string(),
14
+ }));
15
+ }
@@ -128,6 +128,7 @@ export declare const CheckpointSnapshotSchema: z.ZodObject<{
128
128
  items: z.ZodArray<z.ZodUnknown>;
129
129
  }, z.core.$strip>;
130
130
  occurrences: z.ZodRecord<z.ZodString, z.ZodNumber>;
131
+ customItemTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
131
132
  state: z.ZodOptional<z.ZodUnknown>;
132
133
  usage: z.ZodOptional<z.ZodObject<{
133
134
  tokens: z.ZodObject<{
@@ -120,6 +120,11 @@ export const CheckpointSnapshotSchema = z.object({
120
120
  * on the same execution does not land on an earlier run's paths.
121
121
  */
122
122
  occurrences: z.record(z.string(), z.number()),
123
+ /**
124
+ * Custom item types the context accepted (spec 34), so a restore can parse an
125
+ * `itemLog` that holds them before the steps that declare them run again.
126
+ */
127
+ customItemTypes: z.array(z.string()).optional(),
123
128
  /**
124
129
  * The execution's `ctx.state` at capture time. Absent when the state does not survive
125
130
  * JSON encoding, in which case restore keeps whatever state the host passes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/core",
3
- "version": "5.16.0",
3
+ "version": "5.16.1",
4
4
  "type": "module",
5
5
  "description": "Step primitives, interpreter, runtime, and context layer contract for Noetic agents.",
6
6
  "license": "Apache-2.0",