@noetic-tools/core 5.13.0 → 5.14.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.
Files changed (44) hide show
  1. package/dist/builders/decide-builders.d.ts +2 -2
  2. package/dist/builders/dynamic-workflow.js +2 -0
  3. package/dist/builders/provide-builder.d.ts +2 -2
  4. package/dist/builders/spawn-builder.d.ts +2 -2
  5. package/dist/builders/step-builders.d.ts +5 -5
  6. package/dist/builders/workflow-hydrator.d.ts +1 -1
  7. package/dist/builders/workflow-hydrator.js +53 -3
  8. package/dist/expression/check.js +14 -0
  9. package/dist/expression/jsonata.d.ts +7 -0
  10. package/dist/expression/jsonata.js +11 -1
  11. package/dist/harness/agent-harness.d.ts +59 -5
  12. package/dist/harness/agent-harness.js +176 -25
  13. package/dist/harness/deps/runtime.d.ts +4 -0
  14. package/dist/harness/deps/runtime.js +2 -0
  15. package/dist/harness/model-call.js +69 -0
  16. package/dist/harness/model-rounds.d.ts +52 -0
  17. package/dist/harness/model-rounds.js +115 -0
  18. package/dist/harness/thread-record.d.ts +54 -0
  19. package/dist/harness/thread-record.js +159 -0
  20. package/dist/index.d.ts +2 -2
  21. package/dist/interpreter/emit-items.d.ts +19 -0
  22. package/dist/interpreter/emit-items.js +106 -0
  23. package/dist/interpreter/execute-action.js +4 -1
  24. package/dist/interpreter/execute-control.js +7 -3
  25. package/dist/interpreter/execute.js +66 -9
  26. package/dist/observability/span-impl.d.ts +9 -0
  27. package/dist/observability/span-impl.js +13 -0
  28. package/dist/runtime/context-impl.d.ts +156 -14
  29. package/dist/runtime/context-impl.js +326 -28
  30. package/dist/runtime/durable/harness-checkpoints.d.ts +13 -3
  31. package/dist/runtime/durable/harness-checkpoints.js +66 -7
  32. package/dist/runtime/durable/session-store.d.ts +37 -0
  33. package/dist/runtime/durable/session-store.js +58 -0
  34. package/dist/runtime/durable/step-ledger.d.ts +77 -40
  35. package/dist/runtime/durable/step-ledger.js +193 -73
  36. package/dist/runtime/item-log-impl.d.ts +6 -0
  37. package/dist/runtime/item-log-impl.js +12 -0
  38. package/dist/runtime/session-runner.d.ts +25 -1
  39. package/dist/runtime/session-runner.js +83 -11
  40. package/dist/schemas/workflow.d.ts +1 -1
  41. package/dist/types/checkpoint.d.ts +21 -4
  42. package/dist/types/checkpoint.js +33 -3
  43. package/package.json +2 -2
  44. package/schema/noetic-workflow.schema.json +391 -0
@@ -14,8 +14,13 @@ import { z } from 'zod';
14
14
  * layer id, so a v1 snapshot carries state under ids no current layer reads
15
15
  * — restoring it would silently drop that state. There is no migration;
16
16
  * discard via `CheckpointStore.clear()` and start fresh.
17
+ * - v2 → v3: `itemLog` holds the log as it stood when the run in flight began, not
18
+ * at the moment of capture, and `occurrences` records the dispatch counts from that
19
+ * same moment. A resumed run replays its recorded steps, which put their items
20
+ * back; a v2 log already holds them, so restoring it would duplicate history. No
21
+ * migration — discard and start fresh.
17
22
  */
18
- export declare const CheckpointSchemaVersion = 2;
23
+ export declare const CheckpointSchemaVersion = 3;
19
24
  /**
20
25
  * @public
21
26
  * One entry in the execution frontier — a pointer to a step currently in
@@ -60,8 +65,9 @@ export declare const PendingAskUserSnapshotSchema: z.ZodObject<{
60
65
  export type PendingAskUserSnapshot = z.infer<typeof PendingAskUserSnapshotSchema>;
61
66
  /**
62
67
  * @public
63
- * Item log state captured in a snapshot. We store the ordered list of items
64
- * directly — the `ItemLogImpl` is append-only so the list is its own cursor.
68
+ * Item log state captured in a snapshot: the log as it stood when the run in
69
+ * flight began, or the live log when no run is in flight. The steps a resumed run
70
+ * replays put the rest back, from the items the step ledger recorded for each.
65
71
  *
66
72
  * Items are carried as `unknown` here and re-parsed on restore via the
67
73
  * harness's `ItemSchemaRegistry`, which is the same gate production traffic
@@ -99,7 +105,7 @@ export type ChannelSnapshot = z.infer<typeof ChannelSnapshotSchema>;
99
105
  * instead of producing a silently corrupt restored context.
100
106
  */
101
107
  export declare const CheckpointSnapshotSchema: z.ZodObject<{
102
- schemaVersion: z.ZodLiteral<2>;
108
+ schemaVersion: z.ZodLiteral<3>;
103
109
  executionId: z.ZodString;
104
110
  threadId: z.ZodOptional<z.ZodString>;
105
111
  resourceId: z.ZodOptional<z.ZodString>;
@@ -121,6 +127,17 @@ export declare const CheckpointSnapshotSchema: z.ZodObject<{
121
127
  itemLog: z.ZodObject<{
122
128
  items: z.ZodArray<z.ZodUnknown>;
123
129
  }, z.core.$strip>;
130
+ occurrences: z.ZodRecord<z.ZodString, z.ZodNumber>;
131
+ state: z.ZodOptional<z.ZodUnknown>;
132
+ usage: z.ZodOptional<z.ZodObject<{
133
+ tokens: z.ZodObject<{
134
+ input: z.ZodNumber;
135
+ output: z.ZodNumber;
136
+ total: z.ZodNumber;
137
+ cached: z.ZodOptional<z.ZodNumber>;
138
+ }, z.core.$strip>;
139
+ cost: z.ZodNumber;
140
+ }, z.core.$strip>>;
124
141
  channels: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
125
142
  name: z.ZodString;
126
143
  mode: z.ZodLiteral<"value">;
@@ -15,8 +15,13 @@ import { z } from 'zod';
15
15
  * layer id, so a v1 snapshot carries state under ids no current layer reads
16
16
  * — restoring it would silently drop that state. There is no migration;
17
17
  * discard via `CheckpointStore.clear()` and start fresh.
18
+ * - v2 → v3: `itemLog` holds the log as it stood when the run in flight began, not
19
+ * at the moment of capture, and `occurrences` records the dispatch counts from that
20
+ * same moment. A resumed run replays its recorded steps, which put their items
21
+ * back; a v2 log already holds them, so restoring it would duplicate history. No
22
+ * migration — discard and start fresh.
18
23
  */
19
- export const CheckpointSchemaVersion = 2;
24
+ export const CheckpointSchemaVersion = 3;
20
25
  /**
21
26
  * @public
22
27
  * One entry in the execution frontier — a pointer to a step currently in
@@ -58,8 +63,9 @@ export const PendingAskUserSnapshotSchema = z.object({
58
63
  });
59
64
  /**
60
65
  * @public
61
- * Item log state captured in a snapshot. We store the ordered list of items
62
- * directly — the `ItemLogImpl` is append-only so the list is its own cursor.
66
+ * Item log state captured in a snapshot: the log as it stood when the run in
67
+ * flight began, or the live log when no run is in flight. The steps a resumed run
68
+ * replays put the rest back, from the items the step ledger recorded for each.
63
69
  *
64
70
  * Items are carried as `unknown` here and re-parsed on restore via the
65
71
  * harness's `ItemSchemaRegistry`, which is the same gate production traffic
@@ -107,6 +113,30 @@ export const CheckpointSnapshotSchema = z.object({
107
113
  cwd: CwdSnapshotSchema.nullable(),
108
114
  askUser: z.array(PendingAskUserSnapshotSchema),
109
115
  itemLog: ItemLogSnapshotSchema,
116
+ /**
117
+ * Dispatch counts per `<parent path>/<step id>`, taken at the same moment as
118
+ * `itemLog`. A restored context numbers its dispatches from here, so a resumed run
119
+ * meets its recorded steps at the paths they were recorded under, and a later run
120
+ * on the same execution does not land on an earlier run's paths.
121
+ */
122
+ occurrences: z.record(z.string(), z.number()),
123
+ /**
124
+ * The execution's `ctx.state` at capture time. Absent when the state does not survive
125
+ * JSON encoding, in which case restore keeps whatever state the host passes.
126
+ */
127
+ state: z.unknown().optional(),
128
+ /** Tokens and cost the execution had spent at capture time, so budgets carry over. */
129
+ usage: z
130
+ .object({
131
+ tokens: z.object({
132
+ input: z.number(),
133
+ output: z.number(),
134
+ total: z.number(),
135
+ cached: z.number().optional(),
136
+ }),
137
+ cost: z.number(),
138
+ })
139
+ .optional(),
110
140
  /**
111
141
  * Stored state of every channel the execution used. Optional so snapshots
112
142
  * written before channels were captured still load (they restore with no
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noetic-tools/core",
3
- "version": "5.13.0",
3
+ "version": "5.14.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",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "dependencies": {
71
71
  "@noetic-tools/context": "^1.9.0",
72
- "@noetic-tools/types": "^3.11.0",
72
+ "@noetic-tools/types": "^3.12.0",
73
73
  "@openrouter/agent": "^0.11.0",
74
74
  "@openrouter/sdk": "1.4.25",
75
75
  "jsonata": "2.2.2",
@@ -60,6 +60,29 @@
60
60
  }
61
61
  ]
62
62
  },
63
+ "emitItems": {
64
+ "anyOf": [
65
+ {
66
+ "type": "boolean"
67
+ },
68
+ {
69
+ "type": "object",
70
+ "properties": {
71
+ "expr": {
72
+ "$ref": "#/$defs/Expression"
73
+ },
74
+ "as": {
75
+ "type": "string",
76
+ "enum": [
77
+ "text",
78
+ "items"
79
+ ]
80
+ }
81
+ },
82
+ "additionalProperties": false
83
+ }
84
+ ]
85
+ },
63
86
  "model": {
64
87
  "type": "string"
65
88
  },
@@ -217,6 +240,29 @@
217
240
  }
218
241
  ]
219
242
  },
243
+ "emitItems": {
244
+ "anyOf": [
245
+ {
246
+ "type": "boolean"
247
+ },
248
+ {
249
+ "type": "object",
250
+ "properties": {
251
+ "expr": {
252
+ "$ref": "#/$defs/Expression"
253
+ },
254
+ "as": {
255
+ "type": "string",
256
+ "enum": [
257
+ "text",
258
+ "items"
259
+ ]
260
+ }
261
+ },
262
+ "additionalProperties": false
263
+ }
264
+ ]
265
+ },
220
266
  "toolName": {
221
267
  "type": "string",
222
268
  "minLength": 1
@@ -275,6 +321,29 @@
275
321
  }
276
322
  ]
277
323
  },
324
+ "emitItems": {
325
+ "anyOf": [
326
+ {
327
+ "type": "boolean"
328
+ },
329
+ {
330
+ "type": "object",
331
+ "properties": {
332
+ "expr": {
333
+ "$ref": "#/$defs/Expression"
334
+ },
335
+ "as": {
336
+ "type": "string",
337
+ "enum": [
338
+ "text",
339
+ "items"
340
+ ]
341
+ }
342
+ },
343
+ "additionalProperties": false
344
+ }
345
+ ]
346
+ },
278
347
  "execute": {
279
348
  "type": "string",
280
349
  "minLength": 1
@@ -362,6 +431,29 @@
362
431
  }
363
432
  ]
364
433
  },
434
+ "emitItems": {
435
+ "anyOf": [
436
+ {
437
+ "type": "boolean"
438
+ },
439
+ {
440
+ "type": "object",
441
+ "properties": {
442
+ "expr": {
443
+ "$ref": "#/$defs/Expression"
444
+ },
445
+ "as": {
446
+ "type": "string",
447
+ "enum": [
448
+ "text",
449
+ "items"
450
+ ]
451
+ }
452
+ },
453
+ "additionalProperties": false
454
+ }
455
+ ]
456
+ },
365
457
  "expr": {
366
458
  "$ref": "#/$defs/Expression"
367
459
  }
@@ -412,6 +504,29 @@
412
504
  }
413
505
  ]
414
506
  },
507
+ "emitItems": {
508
+ "anyOf": [
509
+ {
510
+ "type": "boolean"
511
+ },
512
+ {
513
+ "type": "object",
514
+ "properties": {
515
+ "expr": {
516
+ "$ref": "#/$defs/Expression"
517
+ },
518
+ "as": {
519
+ "type": "string",
520
+ "enum": [
521
+ "text",
522
+ "items"
523
+ ]
524
+ }
525
+ },
526
+ "additionalProperties": false
527
+ }
528
+ ]
529
+ },
415
530
  "routes": {
416
531
  "minItems": 1,
417
532
  "type": "array",
@@ -485,6 +600,29 @@
485
600
  }
486
601
  ]
487
602
  },
603
+ "emitItems": {
604
+ "anyOf": [
605
+ {
606
+ "type": "boolean"
607
+ },
608
+ {
609
+ "type": "object",
610
+ "properties": {
611
+ "expr": {
612
+ "$ref": "#/$defs/Expression"
613
+ },
614
+ "as": {
615
+ "type": "string",
616
+ "enum": [
617
+ "text",
618
+ "items"
619
+ ]
620
+ }
621
+ },
622
+ "additionalProperties": false
623
+ }
624
+ ]
625
+ },
488
626
  "model": {
489
627
  "type": "string",
490
628
  "minLength": 1
@@ -689,6 +827,29 @@
689
827
  }
690
828
  ]
691
829
  },
830
+ "emitItems": {
831
+ "anyOf": [
832
+ {
833
+ "type": "boolean"
834
+ },
835
+ {
836
+ "type": "object",
837
+ "properties": {
838
+ "expr": {
839
+ "$ref": "#/$defs/Expression"
840
+ },
841
+ "as": {
842
+ "type": "string",
843
+ "enum": [
844
+ "text",
845
+ "items"
846
+ ]
847
+ }
848
+ },
849
+ "additionalProperties": false
850
+ }
851
+ ]
852
+ },
692
853
  "decide": {
693
854
  "type": "object",
694
855
  "properties": {
@@ -728,6 +889,29 @@
728
889
  }
729
890
  ]
730
891
  },
892
+ "emitItems": {
893
+ "anyOf": [
894
+ {
895
+ "type": "boolean"
896
+ },
897
+ {
898
+ "type": "object",
899
+ "properties": {
900
+ "expr": {
901
+ "$ref": "#/$defs/Expression"
902
+ },
903
+ "as": {
904
+ "type": "string",
905
+ "enum": [
906
+ "text",
907
+ "items"
908
+ ]
909
+ }
910
+ },
911
+ "additionalProperties": false
912
+ }
913
+ ]
914
+ },
731
915
  "model": {
732
916
  "type": "string",
733
917
  "minLength": 1
@@ -965,6 +1149,29 @@
965
1149
  }
966
1150
  ]
967
1151
  },
1152
+ "emitItems": {
1153
+ "anyOf": [
1154
+ {
1155
+ "type": "boolean"
1156
+ },
1157
+ {
1158
+ "type": "object",
1159
+ "properties": {
1160
+ "expr": {
1161
+ "$ref": "#/$defs/Expression"
1162
+ },
1163
+ "as": {
1164
+ "type": "string",
1165
+ "enum": [
1166
+ "text",
1167
+ "items"
1168
+ ]
1169
+ }
1170
+ },
1171
+ "additionalProperties": false
1172
+ }
1173
+ ]
1174
+ },
968
1175
  "mode": {
969
1176
  "type": "string",
970
1177
  "enum": [
@@ -1047,6 +1254,29 @@
1047
1254
  }
1048
1255
  ]
1049
1256
  },
1257
+ "emitItems": {
1258
+ "anyOf": [
1259
+ {
1260
+ "type": "boolean"
1261
+ },
1262
+ {
1263
+ "type": "object",
1264
+ "properties": {
1265
+ "expr": {
1266
+ "$ref": "#/$defs/Expression"
1267
+ },
1268
+ "as": {
1269
+ "type": "string",
1270
+ "enum": [
1271
+ "text",
1272
+ "items"
1273
+ ]
1274
+ }
1275
+ },
1276
+ "additionalProperties": false
1277
+ }
1278
+ ]
1279
+ },
1050
1280
  "child": {
1051
1281
  "$ref": "#/$defs/WorkflowNode"
1052
1282
  },
@@ -1109,6 +1339,29 @@
1109
1339
  }
1110
1340
  ]
1111
1341
  },
1342
+ "emitItems": {
1343
+ "anyOf": [
1344
+ {
1345
+ "type": "boolean"
1346
+ },
1347
+ {
1348
+ "type": "object",
1349
+ "properties": {
1350
+ "expr": {
1351
+ "$ref": "#/$defs/Expression"
1352
+ },
1353
+ "as": {
1354
+ "type": "string",
1355
+ "enum": [
1356
+ "text",
1357
+ "items"
1358
+ ]
1359
+ }
1360
+ },
1361
+ "additionalProperties": false
1362
+ }
1363
+ ]
1364
+ },
1112
1365
  "child": {
1113
1366
  "$ref": "#/$defs/WorkflowNode"
1114
1367
  },
@@ -1168,6 +1421,29 @@
1168
1421
  }
1169
1422
  ]
1170
1423
  },
1424
+ "emitItems": {
1425
+ "anyOf": [
1426
+ {
1427
+ "type": "boolean"
1428
+ },
1429
+ {
1430
+ "type": "object",
1431
+ "properties": {
1432
+ "expr": {
1433
+ "$ref": "#/$defs/Expression"
1434
+ },
1435
+ "as": {
1436
+ "type": "string",
1437
+ "enum": [
1438
+ "text",
1439
+ "items"
1440
+ ]
1441
+ }
1442
+ },
1443
+ "additionalProperties": false
1444
+ }
1445
+ ]
1446
+ },
1171
1447
  "body": {
1172
1448
  "$ref": "#/$defs/WorkflowNode"
1173
1449
  },
@@ -1235,6 +1511,29 @@
1235
1511
  }
1236
1512
  ]
1237
1513
  },
1514
+ "emitItems": {
1515
+ "anyOf": [
1516
+ {
1517
+ "type": "boolean"
1518
+ },
1519
+ {
1520
+ "type": "object",
1521
+ "properties": {
1522
+ "expr": {
1523
+ "$ref": "#/$defs/Expression"
1524
+ },
1525
+ "as": {
1526
+ "type": "string",
1527
+ "enum": [
1528
+ "text",
1529
+ "items"
1530
+ ]
1531
+ }
1532
+ },
1533
+ "additionalProperties": false
1534
+ }
1535
+ ]
1536
+ },
1238
1537
  "steps": {
1239
1538
  "minItems": 1,
1240
1539
  "type": "array",
@@ -1289,6 +1588,29 @@
1289
1588
  }
1290
1589
  ]
1291
1590
  },
1591
+ "emitItems": {
1592
+ "anyOf": [
1593
+ {
1594
+ "type": "boolean"
1595
+ },
1596
+ {
1597
+ "type": "object",
1598
+ "properties": {
1599
+ "expr": {
1600
+ "$ref": "#/$defs/Expression"
1601
+ },
1602
+ "as": {
1603
+ "type": "string",
1604
+ "enum": [
1605
+ "text",
1606
+ "items"
1607
+ ]
1608
+ }
1609
+ },
1610
+ "additionalProperties": false
1611
+ }
1612
+ ]
1613
+ },
1292
1614
  "step": {
1293
1615
  "$ref": "#/$defs/WorkflowNode"
1294
1616
  },
@@ -1351,6 +1673,29 @@
1351
1673
  }
1352
1674
  ]
1353
1675
  },
1676
+ "emitItems": {
1677
+ "anyOf": [
1678
+ {
1679
+ "type": "boolean"
1680
+ },
1681
+ {
1682
+ "type": "object",
1683
+ "properties": {
1684
+ "expr": {
1685
+ "$ref": "#/$defs/Expression"
1686
+ },
1687
+ "as": {
1688
+ "type": "string",
1689
+ "enum": [
1690
+ "text",
1691
+ "items"
1692
+ ]
1693
+ }
1694
+ },
1695
+ "additionalProperties": false
1696
+ }
1697
+ ]
1698
+ },
1354
1699
  "document": {
1355
1700
  "$ref": "#"
1356
1701
  },
@@ -1407,6 +1752,29 @@
1407
1752
  }
1408
1753
  ]
1409
1754
  },
1755
+ "emitItems": {
1756
+ "anyOf": [
1757
+ {
1758
+ "type": "boolean"
1759
+ },
1760
+ {
1761
+ "type": "object",
1762
+ "properties": {
1763
+ "expr": {
1764
+ "$ref": "#/$defs/Expression"
1765
+ },
1766
+ "as": {
1767
+ "type": "string",
1768
+ "enum": [
1769
+ "text",
1770
+ "items"
1771
+ ]
1772
+ }
1773
+ },
1774
+ "additionalProperties": false
1775
+ }
1776
+ ]
1777
+ },
1410
1778
  "agent": {
1411
1779
  "type": "string",
1412
1780
  "minLength": 1
@@ -1926,6 +2294,29 @@
1926
2294
  }
1927
2295
  ]
1928
2296
  },
2297
+ "emitItems": {
2298
+ "anyOf": [
2299
+ {
2300
+ "type": "boolean"
2301
+ },
2302
+ {
2303
+ "type": "object",
2304
+ "properties": {
2305
+ "expr": {
2306
+ "$ref": "#/$defs/Expression"
2307
+ },
2308
+ "as": {
2309
+ "type": "string",
2310
+ "enum": [
2311
+ "text",
2312
+ "items"
2313
+ ]
2314
+ }
2315
+ },
2316
+ "additionalProperties": false
2317
+ }
2318
+ ]
2319
+ },
1929
2320
  "model": {
1930
2321
  "type": "string",
1931
2322
  "minLength": 1