@noetic-tools/context 1.5.0 → 1.6.0

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.
@@ -90,6 +90,12 @@ interface SpawnLayersParams {
90
90
  }
91
91
  interface ReturnLayersParams<T = unknown> {
92
92
  layers: ContextLayer[];
93
+ /**
94
+ * Id of the spawn (or inParallel) step whose child is returning. Names the
95
+ * step in `spawn_summary_failed` diagnostics; defaults to the child's
96
+ * execution id.
97
+ */
98
+ stepId?: string;
93
99
  parentCtx: ExecutionContext;
94
100
  childCtx: ExecutionContext;
95
101
  childLog: ItemLog;
@@ -180,6 +186,8 @@ export interface RecallCache {
180
186
  }
181
187
  export declare function createRecallCache(): RecallCache;
182
188
  export declare function mostRestrictive(decisions: SteeringDecision[]): SteeringDecision;
189
+ /** Span event added to the child's span when a layer's `onReturn` hook fails. */
190
+ export declare const SPAWN_SUMMARY_FAILED_EVENT = "spawn.summary_failed";
183
191
  export declare function initLayers({ layers, ctx, storage, store, keep, }: InitLayersParams): Promise<void>;
184
192
  export declare function recallLayers({ layers, query, ctx, log, budgets, store, itemSchemas, peek, }: RecallLayersParams): Promise<RecallEntry[]>;
185
193
  type RecallEntry = {
@@ -229,7 +237,14 @@ export declare function spawnLayers({ layers, parentCtx, childCtx, store, itemSc
229
237
  childState: unknown;
230
238
  items: Item[];
231
239
  }[]>;
232
- export declare function returnLayers<T>({ layers, parentCtx, childCtx, childLog, result, store, }: ReturnLayersParams<T>): Promise<T>;
240
+ /**
241
+ * Pipes a child's result through each layer's `onReturn` hook in slot order.
242
+ *
243
+ * A failing hook never fails the spawn: the child's work already succeeded,
244
+ * so the result passes on unchanged and the failure is reported as a
245
+ * `spawn_summary_failed` diagnostic plus a span event on the child's span.
246
+ */
247
+ export declare function returnLayers<T>({ layers, stepId, parentCtx, childCtx, childLog, result, store, }: ReturnLayersParams<T>): Promise<T>;
233
248
  export declare function completeLayers({ layers, ctx, log, outcome, store, }: CompleteLayersParams): Promise<void>;
234
249
  export declare function beforeToolCallLayers({ layers, toolName, toolArgs, callId, ctx, store, }: BeforeToolCallLayersParams): Promise<SteeringDecision>;
235
250
  export declare function afterModelCallLayers({ layers, response, ctx, store, }: AfterModelCallLayersParams): Promise<SteeringDecision>;
@@ -1,4 +1,4 @@
1
- import { createMessage, defaultItemSchemaRegistry, estimateTokens, frameworkCast, NoeticConfigError, SteeringAction, } from '@noetic-tools/types';
1
+ import { createMessage, defaultItemSchemaRegistry, estimateTokens, frameworkCast, NoeticConfigError, NoeticErrorImpl, SteeringAction, } from '@noetic-tools/types';
2
2
  import { createScopedStorage, resolveScopeKey } from './scope.js';
3
3
  /** Maximum allowed re-render depth to prevent infinite loops */
4
4
  const MAX_RERENDER_DEPTH = 3;
@@ -177,6 +177,23 @@ export function mostRestrictive(decisions) {
177
177
  function layerItemSchemas(layer, base = defaultItemSchemaRegistry) {
178
178
  return base.extend(layer.itemSchemas);
179
179
  }
180
+ /** Span event added to the child's span when a layer's `onReturn` hook fails. */
181
+ export const SPAWN_SUMMARY_FAILED_EVENT = 'spawn.summary_failed';
182
+ function reportSummaryFailure({ layerId, stepId, childOutput, cause, childCtx, store, }) {
183
+ const summaryCause = cause instanceof Error ? cause : new Error(String(cause));
184
+ const error = new NoeticErrorImpl({
185
+ kind: 'spawn_summary_failed',
186
+ stepId,
187
+ childOutput,
188
+ summaryCause,
189
+ });
190
+ childCtx.trace.addEvent(SPAWN_SUMMARY_FAILED_EVENT, {
191
+ stepId,
192
+ layerId,
193
+ message: summaryCause.message,
194
+ });
195
+ store.diagnostic(layerId, 'onReturn', error);
196
+ }
180
197
  //#endregion
181
198
  //#region Public API
182
199
  export async function initLayers({ layers, ctx, storage, store, keep = false, }) {
@@ -560,7 +577,14 @@ export async function spawnLayers({ layers, parentCtx, childCtx, store, itemSche
560
577
  }
561
578
  return results;
562
579
  }
563
- export async function returnLayers({ layers, parentCtx, childCtx, childLog, result, store, }) {
580
+ /**
581
+ * Pipes a child's result through each layer's `onReturn` hook in slot order.
582
+ *
583
+ * A failing hook never fails the spawn: the child's work already succeeded,
584
+ * so the result passes on unchanged and the failure is reported as a
585
+ * `spawn_summary_failed` diagnostic plus a span event on the child's span.
586
+ */
587
+ export async function returnLayers({ layers, stepId, parentCtx, childCtx, childLog, result, store, }) {
564
588
  const sorted = [
565
589
  ...layers,
566
590
  ].sort((a, b) => a.slot - b.slot);
@@ -594,7 +618,14 @@ export async function returnLayers({ layers, parentCtx, childCtx, childLog, resu
594
618
  }
595
619
  }
596
620
  catch (e) {
597
- store.diagnostic(layer.id, 'onReturn', e);
621
+ reportSummaryFailure({
622
+ layerId: layer.id,
623
+ stepId: stepId ?? childCtx.executionId,
624
+ childOutput: currentResult,
625
+ cause: e,
626
+ childCtx,
627
+ store,
628
+ });
598
629
  }
599
630
  }
600
631
  // The child execution's store is typically cleaned up right after onReturn —
@@ -27,5 +27,6 @@ export interface HistoryConfig {
27
27
  * @public
28
28
  * @param config - Optional `{ maxItems }`. Defaults to 40.
29
29
  * @returns A `ContextLayer` that contributes only a `projectHistory` hook.
30
+ * @throws `NoeticConfigError` with code `INVALID_HISTORY_MAX_ITEMS` if `maxItems` is not an integer in the allowed range.
30
31
  */
31
32
  export declare function history(config?: HistoryConfig): ContextLayer<null>;
@@ -100,6 +100,7 @@ function findHeadAnchor(items, windowStart) {
100
100
  * @public
101
101
  * @param config - Optional `{ maxItems }`. Defaults to 40.
102
102
  * @returns A `ContextLayer` that contributes only a `projectHistory` hook.
103
+ * @throws `NoeticConfigError` with code `INVALID_HISTORY_MAX_ITEMS` if `maxItems` is not an integer in the allowed range.
103
104
  */
104
105
  export function history(config) {
105
106
  const maxItems = config?.maxItems ?? DEFAULT_MAX_ITEMS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/context",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "description": "Context layer system for Noetic agents: the ContextLayer contract, lifecycle, budget/projection machinery, and built-in layer implementations.",
6
6
  "license": "Apache-2.0",
@@ -44,7 +44,7 @@
44
44
  "zod": "^4.0.0"
45
45
  },
46
46
  "dependencies": {
47
- "@noetic-tools/types": "^3.6.0",
47
+ "@noetic-tools/types": "^3.7.0",
48
48
  "zod": "^4.0.0"
49
49
  },
50
50
  "scripts": {