@noetic-tools/core 5.21.0 → 5.22.0-next.2

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 (101) hide show
  1. package/dist/adapters/openrouter.d.ts +6 -1
  2. package/dist/adapters/openrouter.js +10 -0
  3. package/dist/builders/decide-builders.d.ts +7 -0
  4. package/dist/builders/tool-builder.d.ts +25 -1
  5. package/dist/builders/tool-builder.js +25 -1
  6. package/dist/builders/workflow-control-nodes.js +1 -0
  7. package/dist/builders/workflow-hydrator.d.ts +19 -0
  8. package/dist/builders/workflow-hydrator.js +19 -0
  9. package/dist/builders/workflow-step.js +7 -1
  10. package/dist/connections/cron-schedule.js +12 -3
  11. package/dist/connections/durability.d.ts +1 -2
  12. package/dist/connections/durability.js +1 -4
  13. package/dist/connections/gates.js +6 -2
  14. package/dist/connections/harness-wiring.d.ts +5 -0
  15. package/dist/connections/harness-wiring.js +76 -10
  16. package/dist/connections/in-memory-connection.d.ts +4 -0
  17. package/dist/connections/in-memory-connection.js +10 -0
  18. package/dist/connections/model-tools.js +5 -1
  19. package/dist/connections/registry.d.ts +6 -2
  20. package/dist/connections/registry.js +10 -0
  21. package/dist/connections/sources.js +261 -20
  22. package/dist/connections/triggers.d.ts +62 -2
  23. package/dist/connections/triggers.js +375 -35
  24. package/dist/harness/agent-harness.d.ts +317 -4
  25. package/dist/harness/agent-harness.js +1264 -96
  26. package/dist/harness/connection-gate.d.ts +3 -0
  27. package/dist/harness/connection-gate.js +4 -0
  28. package/dist/harness/decide-call.d.ts +15 -0
  29. package/dist/harness/decide-call.js +57 -7
  30. package/dist/harness/deps/runtime.d.ts +3 -0
  31. package/dist/harness/deps/runtime.js +2 -0
  32. package/dist/harness/flow-version.d.ts +13 -0
  33. package/dist/harness/flow-version.js +66 -0
  34. package/dist/harness/harness-options.d.ts +91 -0
  35. package/dist/harness/llm-client.d.ts +2 -0
  36. package/dist/harness/llm-client.js +9 -5
  37. package/dist/harness/model-call.js +8 -0
  38. package/dist/harness/model-rounds.d.ts +30 -0
  39. package/dist/harness/model-rounds.js +146 -1
  40. package/dist/harness/model-tool-round.d.ts +3 -0
  41. package/dist/harness/model-tool-round.js +249 -22
  42. package/dist/harness/park-watchers.d.ts +93 -0
  43. package/dist/harness/park-watchers.js +217 -0
  44. package/dist/harness/read-decision.d.ts +23 -0
  45. package/dist/harness/read-decision.js +100 -0
  46. package/dist/harness/spend.js +4 -0
  47. package/dist/harness/steer-inbox.js +3 -1
  48. package/dist/harness/thread-record.d.ts +77 -1
  49. package/dist/harness/thread-record.js +272 -13
  50. package/dist/index.d.ts +22 -8
  51. package/dist/index.js +12 -2
  52. package/dist/interpreter/acp-resume.d.ts +77 -0
  53. package/dist/interpreter/acp-resume.js +164 -0
  54. package/dist/interpreter/acp-tools.d.ts +11 -0
  55. package/dist/interpreter/acp-tools.js +94 -7
  56. package/dist/interpreter/connection-steps.d.ts +24 -1
  57. package/dist/interpreter/connection-steps.js +77 -2
  58. package/dist/interpreter/execute-acp-agent.js +111 -15
  59. package/dist/interpreter/execute-action.js +7 -0
  60. package/dist/interpreter/execute-call.js +30 -4
  61. package/dist/interpreter/execute-control.js +21 -0
  62. package/dist/interpreter/execute-decide.js +5 -0
  63. package/dist/interpreter/execute-invoke-tool.js +149 -5
  64. package/dist/interpreter/execute-wait.js +67 -9
  65. package/dist/interpreter/execute.js +4 -0
  66. package/dist/interpreter/turn-ending.d.ts +15 -0
  67. package/dist/interpreter/turn-ending.js +46 -0
  68. package/dist/portable/builders.d.ts +1 -1
  69. package/dist/portable/builders.js +1 -1
  70. package/dist/portable/runtime.d.ts +4 -0
  71. package/dist/portable/runtime.js +2 -0
  72. package/dist/runtime/durable/parking.d.ts +61 -0
  73. package/dist/runtime/durable/parking.js +137 -0
  74. package/dist/runtime/durable/session-store.d.ts +38 -0
  75. package/dist/runtime/durable/session-store.js +79 -1
  76. package/dist/runtime/durable/step-ledger.d.ts +121 -2
  77. package/dist/runtime/durable/step-ledger.js +352 -15
  78. package/dist/runtime/durable/turn-lease.d.ts +128 -0
  79. package/dist/runtime/durable/turn-lease.js +307 -0
  80. package/dist/runtime/event-broadcaster.d.ts +9 -1
  81. package/dist/runtime/event-broadcaster.js +16 -1
  82. package/dist/runtime/held-calls.d.ts +192 -0
  83. package/dist/runtime/held-calls.js +496 -0
  84. package/dist/runtime/in-memory-storage.d.ts +10 -1
  85. package/dist/runtime/in-memory-storage.js +20 -2
  86. package/dist/runtime/message-queue.d.ts +2 -0
  87. package/dist/runtime/message-queue.js +8 -0
  88. package/dist/runtime/output-store.d.ts +88 -0
  89. package/dist/runtime/output-store.js +241 -0
  90. package/dist/runtime/session-runner.d.ts +18 -2
  91. package/dist/runtime/session-runner.js +88 -3
  92. package/dist/runtime/session-streams.d.ts +28 -7
  93. package/dist/runtime/session-streams.js +112 -67
  94. package/dist/runtime/tool-approval.d.ts +46 -6
  95. package/dist/runtime/tool-approval.js +160 -38
  96. package/dist/runtime/tool-call.d.ts +34 -2
  97. package/dist/runtime/tool-call.js +182 -13
  98. package/dist/runtime/tool-context.d.ts +15 -1
  99. package/dist/runtime/tool-context.js +38 -2
  100. package/package.json +3 -3
  101. package/schema/noetic-workflow.schema.json +27 -0
@@ -7,6 +7,11 @@
7
7
  * read-modify-write of the stored record, so a harness that served the last turn and
8
8
  * a harness built a moment ago behave the same.
9
9
  */
10
+ import { NoeticErrorImpl } from '@noetic-tools/types';
11
+ /** How many finished turns a thread remembers, to answer a message delivered again. */
12
+ const MAX_DONE_TURNS = 20;
13
+ /** How many times a compare-and-set write is tried against a record that keeps changing. */
14
+ const COMMIT_ATTEMPTS = 8;
10
15
  const EMPTY_USAGE = {
11
16
  inputTokens: 0,
12
17
  outputTokens: 0,
@@ -25,10 +30,24 @@ export class ThreadRecord {
25
30
  host;
26
31
  threadId;
27
32
  queue = Promise.resolve();
33
+ /** The lease the turn in flight runs under, when storage can compare-and-set. */
34
+ fence;
28
35
  constructor(host, threadId) {
29
36
  this.host = host;
30
37
  this.threadId = threadId;
31
38
  }
39
+ /**
40
+ * Run the turn's own writes (`begin`, `end`) under `fence`: a harness that lost
41
+ * the lease does not overwrite the record, and a write that fails stops the turn
42
+ * (spec 23 § One writer per turn, § Fail-stop). `undefined` goes back to best-effort.
43
+ */
44
+ hold(fence) {
45
+ this.fence = fence;
46
+ }
47
+ /** The lease term the stored record was last written at, when it was written under one. */
48
+ term() {
49
+ return this.run(async () => (await this.load())?.term);
50
+ }
32
51
  /** The history the thread's next turn builds on: what storage holds, or none. */
33
52
  history() {
34
53
  return this.run(async () => this.host.parseItems((await this.load())?.items ?? []));
@@ -53,7 +72,7 @@ export class ThreadRecord {
53
72
  if (!turn) {
54
73
  return undefined;
55
74
  }
56
- if (sameIds(turn.messageIds, messageIds)) {
75
+ if (isSameDelivery(turn.messageIds, messageIds)) {
57
76
  return (await this.host.restore(turn.executionId, opts)) ?? undefined;
58
77
  }
59
78
  await this.write(withoutTurn);
@@ -61,16 +80,44 @@ export class ThreadRecord {
61
80
  return undefined;
62
81
  });
63
82
  }
83
+ /** Forget the turn in flight and what it recorded: the host aborted a parked turn. */
84
+ drop() {
85
+ return this.run(async () => {
86
+ const turn = (await this.load())?.turn;
87
+ if (!turn) {
88
+ return undefined;
89
+ }
90
+ await this.write(withoutTurn);
91
+ await this.host.clearCheckpoint(turn.executionId);
92
+ return turn;
93
+ });
94
+ }
64
95
  /** Keep a steer sent into the running turn, so a resumed turn still applies it. */
65
96
  keepSteer(message) {
66
97
  if (message.deliveryMode !== 'between-rounds' && message.deliveryMode !== 'next-item') {
67
98
  return Promise.resolve();
68
99
  }
100
+ return this.keepQueued(message);
101
+ }
102
+ /**
103
+ * Keep a message a parked turn has not taken yet, steer or not: with no process
104
+ * holding the turn, storage is the only queue there is. An `interrupt` is never
105
+ * kept; it replaces the turn.
106
+ */
107
+ keepQueued(message) {
108
+ if (message.deliveryMode === 'interrupt') {
109
+ return Promise.resolve();
110
+ }
69
111
  const steer = {
70
112
  id: message.id,
71
113
  input: message.input,
72
114
  deliveryMode: message.deliveryMode,
73
115
  enqueuedAt: message.enqueuedAt,
116
+ ...(message.options.resourceId === undefined
117
+ ? {}
118
+ : {
119
+ resourceId: message.options.resourceId,
120
+ }),
74
121
  };
75
122
  return this.update((record) => ({
76
123
  ...record,
@@ -86,9 +133,13 @@ export class ThreadRecord {
86
133
  id: steer.id,
87
134
  input: this.parseInput(steer.input),
88
135
  deliveryMode: steer.deliveryMode,
89
- // Options carry live objects (layers, state) that storage cannot hold; a
90
- // steer applied mid-turn never reads them.
91
- options: {},
136
+ // Options carry live objects (layers, state) that storage cannot hold. The
137
+ // harness the message was sent to still has them and puts them back.
138
+ options: steer.resourceId === undefined
139
+ ? {}
140
+ : {
141
+ resourceId: steer.resourceId,
142
+ },
92
143
  enqueuedAt: steer.enqueuedAt,
93
144
  })));
94
145
  }
@@ -97,7 +148,7 @@ export class ThreadRecord {
97
148
  * delivers as input stop being steers: re-delivering the turn re-sends them.
98
149
  */
99
150
  begin(ctx, messageIds) {
100
- return this.update((record) => ({
151
+ return this.updateHeld(ctx, (record) => ({
101
152
  ...record,
102
153
  steers: record.steers?.filter((steer) => !messageIds.includes(steer.id)),
103
154
  turn: {
@@ -105,15 +156,163 @@ export class ThreadRecord {
105
156
  messageIds: [
106
157
  ...messageIds,
107
158
  ],
159
+ ...(this.host.version === undefined
160
+ ? {}
161
+ : {
162
+ version: this.host.version,
163
+ }),
164
+ // Kept until the turn ends: a host that dies part way through going on
165
+ // must not find the same step stuck again.
166
+ ...(record.turn?.executionId === ctx.id && record.turn.accept !== undefined
167
+ ? {
168
+ accept: record.turn.accept,
169
+ }
170
+ : {}),
108
171
  },
109
172
  }));
110
173
  }
174
+ /**
175
+ * The turn on `ctx` stopped rather than redo a recorded effect under a newer flow
176
+ * version. It stays, marked, until the host settles it.
177
+ */
178
+ stick(ctx, stuck) {
179
+ return this.update((record) => record.turn?.executionId === ctx.id
180
+ ? {
181
+ ...record,
182
+ turn: {
183
+ ...record.turn,
184
+ stuck,
185
+ },
186
+ }
187
+ : record);
188
+ }
189
+ /**
190
+ * Settle a stuck turn. `continue` and `restart` clear the mark so the turn can
191
+ * run; `continue` also lets its next run discard what no longer matches.
192
+ * `abandon` forgets the turn. Resolves the turn it settled, or undefined when
193
+ * the thread has no stuck turn.
194
+ */
195
+ settle(action) {
196
+ return this.run(async () => {
197
+ const turn = (await this.load())?.turn;
198
+ if (!turn?.stuck) {
199
+ return undefined;
200
+ }
201
+ const { stuck, stopped: _stopped, ...rest } = turn;
202
+ await this.write((record) => action === 'abandon'
203
+ ? withoutTurn(record)
204
+ : {
205
+ ...record,
206
+ turn: {
207
+ ...rest,
208
+ ...(action === 'continue'
209
+ ? {
210
+ accept: stuck.path,
211
+ }
212
+ : {}),
213
+ },
214
+ });
215
+ return turn;
216
+ });
217
+ }
218
+ /**
219
+ * The turn on `ctx` parked: keep its record, marked with when to wake it. Its
220
+ * checkpoint and ledger stay, since they are what the woken turn resumes from.
221
+ */
222
+ park(ctx, until) {
223
+ return this.updateHeld(ctx, (record) => record.turn
224
+ ? {
225
+ ...record,
226
+ turn: {
227
+ ...record.turn,
228
+ parked: until === undefined
229
+ ? {}
230
+ : {
231
+ until,
232
+ },
233
+ },
234
+ }
235
+ : record);
236
+ }
237
+ /**
238
+ * The turn on `ctx` ended here without finishing. Best-effort: a turn whose mark
239
+ * does not land is simply taken for one that was cut off.
240
+ */
241
+ stop(ctx, reason, at) {
242
+ return this.update((record) => record.turn?.executionId === ctx.id
243
+ ? {
244
+ ...record,
245
+ turn: {
246
+ ...record.turn,
247
+ stopped: {
248
+ at,
249
+ reason,
250
+ },
251
+ },
252
+ }
253
+ : record);
254
+ }
255
+ /**
256
+ * The turn on `ctx` gave its answer: remember it under the turn's message ids, so
257
+ * the same messages delivered again get it back (`answerFor`). Call before `end`,
258
+ * which forgets the turn. Only the last few turns are kept.
259
+ */
260
+ answered(ctx, text) {
261
+ return this.update((record) => {
262
+ if (record.turn?.executionId !== ctx.id) {
263
+ return record;
264
+ }
265
+ const kept = (record.done ?? []).slice(1 - MAX_DONE_TURNS);
266
+ return {
267
+ ...record,
268
+ done: [
269
+ ...(MAX_DONE_TURNS > 1 ? kept : []),
270
+ {
271
+ messageIds: record.turn.messageIds,
272
+ text,
273
+ executionId: ctx.id,
274
+ },
275
+ ],
276
+ };
277
+ });
278
+ }
279
+ /**
280
+ * The answer a finished turn gave to the message `messageId`, when one of the
281
+ * thread's recent turns delivered it.
282
+ */
283
+ answerFor(messageId) {
284
+ return this.run(async () => {
285
+ const done = (await this.load())?.done ?? [];
286
+ return done.findLast((turn) => turn.messageIds.includes(messageId))?.text;
287
+ });
288
+ }
289
+ /** The executions of the thread's turns that have a trail: recent finished ones, then the one in flight. */
290
+ executions() {
291
+ return this.run(async () => {
292
+ const record = await this.load();
293
+ const ids = (record?.done ?? []).flatMap((turn) => turn.executionId === undefined
294
+ ? []
295
+ : [
296
+ turn.executionId,
297
+ ]);
298
+ return record?.turn
299
+ ? [
300
+ ...ids,
301
+ record.turn.executionId,
302
+ ]
303
+ : ids;
304
+ });
305
+ }
306
+ /** The turn in flight, cut off or parked, when one is recorded. */
307
+ turn() {
308
+ return this.run(async () => (await this.load())?.turn);
309
+ }
111
310
  /**
112
311
  * The turn on `ctx` finished: store the history it left and drop its checkpoint.
113
312
  * Only steers still queued are kept; the rest were applied or dropped.
114
313
  */
115
314
  async end(ctx, history, queuedIds) {
116
- await this.update((record) => ({
315
+ await this.updateHeld(ctx, (record) => ({
117
316
  ...withoutTurn(record),
118
317
  steers: record.steers?.filter((steer) => queuedIds.includes(steer.id)),
119
318
  items: [
@@ -140,19 +339,75 @@ export class ThreadRecord {
140
339
  update(change) {
141
340
  return this.run(() => this.write(change));
142
341
  }
143
- /** Read-modify-write the stored record. Call only from inside `run`. */
144
- async write(change) {
145
- const record = change((await this.load()) ?? {
146
- items: [],
342
+ /**
343
+ * A write the turn itself makes. Under a lease it carries the lease's term and is
344
+ * refused when the record already holds a higher one — another harness took the
345
+ * turn, whatever this one's clock says — and a write that fails throws instead of
346
+ * being logged (spec 23 § One writer per turn, § Fail-stop).
347
+ */
348
+ updateHeld(ctx, change) {
349
+ const fence = this.fence;
350
+ if (!fence) {
351
+ return this.update(change);
352
+ }
353
+ return this.run(async () => {
354
+ fence.assert();
355
+ try {
356
+ await this.commit((record) => {
357
+ if ((record.term ?? 0) > fence.term) {
358
+ throw fence.lose(`the thread record was written at term ${record.term}`);
359
+ }
360
+ return {
361
+ ...change(record),
362
+ term: fence.term,
363
+ };
364
+ });
365
+ }
366
+ catch (error) {
367
+ if (error instanceof NoeticErrorImpl) {
368
+ throw error;
369
+ }
370
+ throw new NoeticErrorImpl({
371
+ kind: 'ledger_write_failed',
372
+ executionId: ctx.id,
373
+ path: `session:${this.threadId}`,
374
+ cause: error instanceof Error ? error : new Error(String(error)),
375
+ });
376
+ }
147
377
  });
378
+ }
379
+ /** Read-modify-write the stored record, best-effort. Call only from inside `run`. */
380
+ async write(change) {
148
381
  try {
149
- await this.host.store.save(this.threadId, record);
382
+ await this.commit(change);
150
383
  }
151
384
  catch (error) {
152
385
  // Same rule as checkpoints: losing the record costs resumability, not the turn.
153
386
  console.warn(`AgentHarness: failed to persist session "${this.threadId}":`, error instanceof Error ? error.message : String(error));
154
387
  }
155
388
  }
389
+ /**
390
+ * Apply `change` to what storage holds now. On storage that can compare-and-set
391
+ * the write lands only if nothing else wrote meanwhile, and is tried again on what
392
+ * the other writer left, so two harnesses never overwrite each other's fields.
393
+ */
394
+ async commit(change) {
395
+ const store = this.host.store;
396
+ for (let attempt = 0; attempt < COMMIT_ATTEMPTS; attempt += 1) {
397
+ const stored = await store.read(this.threadId);
398
+ const next = change(stored.record ?? {
399
+ items: [],
400
+ });
401
+ if (!store.swap) {
402
+ await store.save(this.threadId, next);
403
+ return;
404
+ }
405
+ if (await store.swap(this.threadId, stored.raw, next)) {
406
+ return;
407
+ }
408
+ }
409
+ throw new Error(`session "${this.threadId}" kept changing while it was being written`);
410
+ }
156
411
  parseInput(input) {
157
412
  if (typeof input === 'string') {
158
413
  return input;
@@ -177,8 +432,12 @@ function withoutTurn(record) {
177
432
  void turn;
178
433
  return rest;
179
434
  }
180
- function sameIds(a, b) {
181
- return a.length === b.length && a.every((id, i) => id === b[i]);
435
+ /**
436
+ * True when `delivered` is the turn's own messages coming round again. Some of them
437
+ * is enough: a queue redelivers one at a time, and a wake hands them back together.
438
+ */
439
+ function isSameDelivery(turn, delivered) {
440
+ return delivered.length > 0 && delivered.every((id) => turn.includes(id));
182
441
  }
183
442
  function addUsage(total, spent) {
184
443
  const cost = (total.cost ?? 0) + spent.cost;
package/dist/index.d.ts CHANGED
@@ -47,7 +47,7 @@ export type { CallInput, CallModelOpts, CallOpName, CallOpts, CallOutput, Invoke
47
47
  /** @public */
48
48
  export { callModel, invokeTool, runCode, step } from './builders/step-builders.js';
49
49
  /** @public */
50
- export { tool, toolWithGenerator } from './builders/tool-builder.js';
50
+ export { hold, tool, toolWithGenerator } from './builders/tool-builder.js';
51
51
  /** @public */
52
52
  export type { VerifyConnectionRef, VerifyEachOutput, VerifyMatcherLike, VerifyOpts, } from './builders/verify-builder.js';
53
53
  /** @public */
@@ -68,12 +68,14 @@ export { aiCondition, allCondition, anyCondition, embeddingMatch, otherwise, sem
68
68
  export { cosineSimilarity } from './conditions/cosine-similarity.js';
69
69
  /** @public */
70
70
  /** @public */
71
- export { isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
71
+ export { DECISION_ITEM_TYPE, isDecisionItem, isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
72
72
  /** @public */
73
73
  export type { AskUserAnnotation, AskUserInput, AskUserOption, AskUserOutput, AskUserQuestion, } from './types/ask-user-types.js';
74
74
  /** @public */
75
75
  export { AskUserAnnotationSchema, AskUserInputSchema, AskUserOptionSchema, AskUserOutputSchema, AskUserQuestionSchema, } from './types/ask-user-types.js';
76
76
  /** @public */
77
+ export { ACP_RESUME_NOTICE } from './interpreter/acp-resume.js';
78
+ /** @public */
77
79
  export { execute } from './interpreter/execute.js';
78
80
  /** @public */
79
81
  /** @public */
@@ -102,6 +104,8 @@ export { GenAI, NoeticAttr, NoeticEvent, ToolAttr } from './observability/genai-
102
104
  /** @public */
103
105
  export { InMemoryExporter, NoopExporter } from './observability/trace-exporter.js';
104
106
  /** @public */
107
+ export type { CreateInMemoryStorageOptions } from './runtime/in-memory-storage.js';
108
+ /** @public */
105
109
  export { createInMemoryStorage } from './runtime/in-memory-storage.js';
106
110
  /** @public */
107
111
  export type { DynamicWorkflowOpts, ParseAndRunWorkflowOpts } from './builders/dynamic-workflow.js';
@@ -114,12 +118,22 @@ export { DEFAULT_EXPRESSION_LIMITS } from './expression/jsonata.js';
114
118
  /** @public */
115
119
  export { AgentHarness } from './harness/agent-harness.js';
116
120
  /** @public */
117
- export type { AgentEnvironmentConfig, StorageEnvironmentConfig, } from './harness/harness-options.js';
121
+ export type { AgentEnvironmentConfig, ParkConfig, StorageEnvironmentConfig, TurnLeaseConfig, WakeTimeListener, } from './harness/harness-options.js';
122
+ /** @public */
123
+ export { DEFAULT_TASK_POLL_MS, DEFAULT_WAKE_DEBOUNCE_MS } from './harness/park-watchers.js';
118
124
  /** @public */
119
125
  export type { AfterFirstTurnContext, CheckpointStore, CreateCheckpointStoreOptions, CreateNudgeMessageOpts, DetachedSignal, RunnableLoopHarness, RunnableLoopOpts, SessionSeedHarness, StallNudgeOpts, StepLedgerRetention, StepLedgerStats, } from './runtime/durable/index.js';
120
126
  /** @public */
121
127
  export { CheckpointKeys, createCheckpointStore, createDetachedSignal, createNudgeMessage, createStallNudgeHook, DEFAULT_NUDGE_MESSAGE_TEXT, DEFAULT_STEP_LEDGER_RETENTION, runnableLoop, seedFromItems, } from './runtime/durable/index.js';
122
128
  /** @public */
129
+ export { DEFAULT_PARK_GRACE_MS } from './runtime/durable/parking.js';
130
+ /** @public */
131
+ export { DEFAULT_LEASE_TTL_MS } from './runtime/durable/turn-lease.js';
132
+ /** @public */
133
+ export type { OutputSnapshot } from './runtime/output-store.js';
134
+ /** @public */
135
+ export { OutputStore, OutputStoreError } from './runtime/output-store.js';
136
+ /** @public */
123
137
  export { getRegistry, lookupStep, registerStep } from './runtime/step-registry.js';
124
138
  /** @public */
125
139
  export type { Expression } from '@noetic-tools/types';
@@ -134,7 +148,7 @@ export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDo
134
148
  export type { Channel, ChannelHandle, ExternalChannel } from '@noetic-tools/types';
135
149
  /** @public */
136
150
  /** @public */
137
- export type { InferSchemaInput, InferSchemaOutput, InputSchemaConfig, LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, RoundUsage, SchemaValidationFailure, SchemaValidationResult, SchemaValidationSuccess, ServerToolSpec, StandardJSONSchemaV1, StandardSchemaV1, StepMeta, TokenUsage, Tool, ToolChoice, ToolContextDeclaration, UsageCharge, } from '@noetic-tools/types';
151
+ export type { InferSchemaInput, InferSchemaOutput, InputSchemaConfig, LLMResponse, LlmProviderConfig, ModelParams, RetryPolicy, RoundUsage, SchemaValidationFailure, SchemaValidationResult, SchemaValidationSuccess, ServerToolSpec, StandardJSONSchemaV1, StandardSchemaV1, StepMeta, TokenUsage, Tool, ToolChoice, ToolContextDeclaration, ToolModelOutput, UsageCharge, } from '@noetic-tools/types';
138
152
  /** @public */
139
153
  export { isServerToolSpec, isStandardJsonSchema, isZodSchema, ServiceTier, standardIssuesToZodError, ToolChoiceMode, validateSchema, } from '@noetic-tools/types';
140
154
  /** @public */
@@ -156,7 +170,7 @@ export { ChannelSnapshotSchema, CheckpointSchemaVersion, CheckpointSnapshotSchem
156
170
  /** @public */
157
171
  export type { NoeticError } from '@noetic-tools/types';
158
172
  /** @public */
159
- export type { ContentPart, DeveloperMessageExtensionItem, ExecuteInput, ExtendedItem, ExtensionItem, FileSearchItem, FunctionCallItem, FunctionCallOutputItem, ImageGenerationItem, InferExtendedItem, InputContentPart, InputFilePart, InputImagePart, InputMessageItem, InputTextPart, Item, ItemBase, ItemSchemaExtensions, MessageItem, OutputItem, OutputTextPart, ReasoningItem, ReasoningTextPart, RefusalPart, ServerToolItem, SummaryTextPart, WebSearchItem, } from '@noetic-tools/types';
173
+ export type { ContentPart, DecisionItem, DeveloperMessageExtensionItem, ExecuteArgument, ExecuteInput, ExtendedItem, ExtensionItem, FileSearchItem, FunctionCallItem, FunctionCallOutputItem, ImageGenerationItem, InferExtendedItem, InputContentPart, InputFilePart, InputImagePart, InputMessageItem, InputTextPart, Item, ItemBase, ItemSchemaExtensions, MessageItem, OutputItem, OutputTextPart, ReasoningItem, ReasoningTextPart, RefusalPart, ServerToolItem, SummaryTextPart, WebSearchItem, } from '@noetic-tools/types';
160
174
  /** @public */
161
175
  export type { BudgetConfig, CompleteParams, ContextConfig, ContextData, ContextLayer, ContextLayerHooks, DisposeParams, InferContext, InferContextShape, InitParams, InitResult, LayerDataDecl, LayerFunctionDecl, LayerPlacement, LayerProvides, LayerTimeouts, ParentUpdateParams, ParentUpdateResult, ProjectionPolicy, RecallParams, RecallResult, RenderDeltaParams, ReturnParams, ReturnResult, ScopedStorage, SpawnParams, SpawnResult, StorageAdapter, StoreParams, StoreResult, } from '@noetic-tools/context';
162
176
  /** @public */
@@ -168,13 +182,13 @@ export type { LayerTraceSpan, Span, TraceExporter } from '@noetic-tools/types';
168
182
  /** @public */
169
183
  export type { FrameworkStreamEvent, HarnessResponse, SdkStreamEvent, StreamEvent, StreamingItem, } from '@noetic-tools/types';
170
184
  /** @public */
171
- export type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, ContextCacheConfig, ContextCacheStore, ContextEpoch, DeliveryMode, DrainCall, DrainReport, ExecuteOptions, ExecutionScope, ExecutionStatus, HarnessJudgmentContract, HarnessStatus, ItemSchemaConfig, ReanchorReason, RecallLayerOutput, SessionScope, SessionUsage, } from '@noetic-tools/types';
185
+ export type { AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, ContextCacheConfig, ContextCacheStore, ContextEpoch, DeliveryMode, DrainCall, DrainReport, ExecuteOptions, ExecutionScope, ExecutionStatus, HarnessJudgmentContract, HarnessStatus, HeldCall, HeldResolution, ItemSchemaConfig, ReanchorReason, RecallLayerOutput, SessionScope, SessionUsage, StuckTurn, ToolHold, TrailMark, } from '@noetic-tools/types';
172
186
  /** @public */
173
187
  export type { PendingSpend, ReconcileSpendOptions, SpendSettlement, WriteOffSpendOptions, } from '@noetic-tools/types';
174
188
  /** @public */
175
189
  export { SpendKind } from '@noetic-tools/types';
176
190
  /** @public */
177
- export type { AfterModelCallParams, AfterModelCallResult, ApproveToolCallParams, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, OnSteerParams, OnSteerResult, Steer, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, SteerVerdict, ToolApprover, } from '@noetic-tools/types';
191
+ export type { AfterModelCallParams, AfterModelCallResult, ApproveRequest, ApproveToolCallParams, BeforeToolCallParams, BeforeToolCallResult, LedgerEntry, OnSteerParams, OnSteerResult, Steer, SteeringConfig, SteeringDecision, SteeringRule, SteeringState, SteerVerdict, ToolApprover, } from '@noetic-tools/types';
178
192
  /** @public */
179
193
  export { LedgerEntryKind, SteerAction, SteeringAction, SteerPoint } from '@noetic-tools/types';
180
194
  /** @public */
@@ -205,7 +219,7 @@ export { createLiveHandles } from './adapters/live-handles.js';
205
219
  /** @public */
206
220
  export type { ToolContext, ToolExecutionContext } from '@noetic-tools/types';
207
221
  /** @public */
208
- export type { ArtifactLink, ArtifactMeta, ArtifactRecord, ArtifactRetention, ArtifactStore, BlobRef, BlobRefBody, BlobReference, CallOptions, CallOutcome, CallResult, Connection, ConnectionAllowlist, ConnectionAllowlistEntry, ConnectionConfig, ConnectionEntries, ConnectionEntry, ConnectionEvent, ConnectionEventInfo, ConnectionEventInit, ConnectionExpose, ConnectionHandle, ConnectionHandleOptions, ConnectionIdentity, ConnectionLease, ConnectionLook, ConnectionManifest, ConnectionMissing, ConnectionOperationAnnotations, ConnectionOperationInfo, ConnectionPick, ConnectionPolicy, ConnectionPoolConfig, ConnectionProvider, ConnectionRequirement, ConnectionResourceInfo, ConnectionSource, ConnectionState, ConnectionStatus, ConnectionsConfig, ConnectionTaskStatus, ConnectionTasks, ConnectionTrigger, ConnectOptions, CronOptions, CronTick, Determinism, EventStream, EventStreamMessage, FreshScope, GrantedMcpServer, ListenRequest, Locator, McpAllowlist, McpCommandGrant, McpNamedValue, McpUrlGrant, Receipt, Ref, RefBody, Secret, SecretResolver, SourceDefinition, SourceEmitEvent, Target, } from '@noetic-tools/types';
222
+ export type { ArtifactLink, ArtifactMeta, ArtifactRecord, ArtifactRetention, ArtifactStore, BlobRef, BlobRefBody, BlobReference, CallOptions, CallOutcome, CallResult, Connection, ConnectionAllowlist, ConnectionAllowlistEntry, ConnectionConfig, ConnectionEntries, ConnectionEntry, ConnectionEvent, ConnectionEventInfo, ConnectionEventInit, ConnectionExpose, ConnectionHandle, ConnectionHandleOptions, ConnectionIdentity, ConnectionLease, ConnectionLook, ConnectionManifest, ConnectionMissing, ConnectionOperationAnnotations, ConnectionOperationInfo, ConnectionPick, ConnectionPolicy, ConnectionPoolConfig, ConnectionProvider, ConnectionRequirement, ConnectionResourceInfo, ConnectionSource, ConnectionState, ConnectionStatus, ConnectionsConfig, ConnectionTaskStatus, ConnectionTasks, ConnectionTrigger, ConnectOptions, CronOptions, CronTick, Determinism, EventSchedule, EventStream, EventStreamMessage, FreshScope, GrantedMcpServer, ListenRequest, Locator, McpAllowlist, McpCommandGrant, McpNamedValue, McpUrlGrant, Receipt, Ref, RefBody, Secret, SecretResolver, SourceDefinition, SourceEmitEvent, Target, } from '@noetic-tools/types';
209
223
  /** @public */
210
224
  /** @public */
211
225
  export { ARTIFACT_URI_PREFIX, artifactDigest, artifactUri, ConnectionUnsatisfiedError, DEFAULT_ARTIFACT_MAX_BYTES_PER_RUN, DEFAULT_ARTIFACT_MAX_COUNT_PER_RUN, isBlobRef, isConnectionEntry, isConnectionPick, isConnectionUnsatisfiedError, isRef, isSecret, refId, secret, } from '@noetic-tools/types';
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ export { spawn } from './builders/spawn-builder.js';
36
36
  /** @public */
37
37
  export { callModel, invokeTool, runCode, step } from './builders/step-builders.js';
38
38
  /** @public */
39
- export { tool, toolWithGenerator } from './builders/tool-builder.js';
39
+ export { hold, tool, toolWithGenerator } from './builders/tool-builder.js';
40
40
  /** @public */
41
41
  export { verify } from './builders/verify-builder.js';
42
42
  /** @public */
@@ -51,12 +51,14 @@ export { cosineSimilarity } from './conditions/cosine-similarity.js';
51
51
  //#region Errors
52
52
  /** @public */
53
53
  /** @public */
54
- export { isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
54
+ export { DECISION_ITEM_TYPE, isDecisionItem, isNoeticConfigError, isNoeticError, NoeticConfigError, NoeticErrorImpl, } from '@noetic-tools/types';
55
55
  /** @public */
56
56
  export { AskUserAnnotationSchema, AskUserInputSchema, AskUserOptionSchema, AskUserOutputSchema, AskUserQuestionSchema, } from './types/ask-user-types.js';
57
57
  //#endregion
58
58
  //#region Execution
59
59
  /** @public */
60
+ export { ACP_RESUME_NOTICE } from './interpreter/acp-resume.js';
61
+ /** @public */
60
62
  export { execute } from './interpreter/execute.js';
61
63
  /** @public */
62
64
  /** @public */
@@ -92,8 +94,16 @@ export { DEFAULT_EXPRESSION_LIMITS } from './expression/jsonata.js';
92
94
  /** @public */
93
95
  export { AgentHarness } from './harness/agent-harness.js';
94
96
  /** @public */
97
+ export { DEFAULT_TASK_POLL_MS, DEFAULT_WAKE_DEBOUNCE_MS } from './harness/park-watchers.js';
98
+ /** @public */
95
99
  export { CheckpointKeys, createCheckpointStore, createDetachedSignal, createNudgeMessage, createStallNudgeHook, DEFAULT_NUDGE_MESSAGE_TEXT, DEFAULT_STEP_LEDGER_RETENTION, runnableLoop, seedFromItems, } from './runtime/durable/index.js';
96
100
  /** @public */
101
+ export { DEFAULT_PARK_GRACE_MS } from './runtime/durable/parking.js';
102
+ /** @public */
103
+ export { DEFAULT_LEASE_TTL_MS } from './runtime/durable/turn-lease.js';
104
+ /** @public */
105
+ export { OutputStore, OutputStoreError } from './runtime/output-store.js';
106
+ /** @public */
97
107
  export { getRegistry, lookupStep, registerStep } from './runtime/step-registry.js';
98
108
  /** @public */
99
109
  /** @public */
@@ -0,0 +1,77 @@
1
+ /**
2
+ * What an ACP step keeps so a resumed run can go on with the agent's own session
3
+ * instead of starting it over (spec 27 § Resuming a step).
4
+ *
5
+ * Two records, both beneath the step's place in the run:
6
+ *
7
+ * - The agent's session id, written when the step opens a session. A resumed step
8
+ * reloads that session (`session/load`) when the agent can.
9
+ * - Each tool call the agent made through the bridge, written as it finishes. A
10
+ * resumed agent that makes the same call again gets the recorded result.
11
+ */
12
+ import type { Context, ContextData, Tool } from '@noetic-tools/types';
13
+ import { z } from 'zod';
14
+ import type { ToolCallResult } from '../runtime/tool-call.js';
15
+ declare const AcpSessionRecordSchema: z.ZodObject<{
16
+ sessionId: z.ZodString;
17
+ agentId: z.ZodString;
18
+ }, z.core.$strip>;
19
+ /** The agent session a step opened, as stored. */
20
+ export type AcpSessionRecord = z.infer<typeof AcpSessionRecordSchema>;
21
+ /** The stored session of one step. */
22
+ export interface AcpSessionRecords {
23
+ load(): Promise<AcpSessionRecord | undefined>;
24
+ write(record: AcpSessionRecord): Promise<void>;
25
+ clear(): Promise<void>;
26
+ }
27
+ /** One bridged call's place in the step's records. */
28
+ export interface BridgedCallRecord {
29
+ /**
30
+ * The call's id for anything that must survive a resume: its held record, a
31
+ * durable tool's intent, its idempotency key. The agent's own id for the call
32
+ * changes when the agent makes it again.
33
+ */
34
+ readonly id: string;
35
+ /** The result an earlier attempt of the step recorded for this call. */
36
+ take(): ToolCallResult | undefined;
37
+ /** Record what the call produced. Resolves whether the record was stored. */
38
+ store(result: ToolCallResult): Promise<boolean>;
39
+ }
40
+ /**
41
+ * @public
42
+ * What a resumed ACP step tells the agent before its prompt, when it reloaded the
43
+ * agent's session.
44
+ */
45
+ export declare const ACP_RESUME_NOTICE = "Your previous turn on this task was cut off before it finished. Continue the task below from where you stopped. Do not redo work that is already done.";
46
+ /**
47
+ * The session record of the ACP step running on `ctx`, or undefined when the run
48
+ * is not durable: no ledger, no storage, or no place in the run.
49
+ */
50
+ export declare function acpSessionRecords(ctx: Context<ContextData>): AcpSessionRecords | undefined;
51
+ /**
52
+ * Hands out the record of each bridged call of one step run. A call is known by
53
+ * its tool, its arguments, and its place among the calls with that tool and those
54
+ * arguments: a resumed agent's ids are new, but what it asks for is not.
55
+ */
56
+ export declare class BridgedCallRecords {
57
+ private readonly seen;
58
+ private reloaded;
59
+ /**
60
+ * The agent's session was reloaded: it has its own record of the calls it
61
+ * finished, and was told not to redo them. A call it makes now is a new call,
62
+ * even with a tool and arguments it used before, so it must not be answered
63
+ * from a record. Each call's order starts after the ones already recorded.
64
+ *
65
+ * An agent that starts over in a new session makes its calls again from the
66
+ * first, and those are answered from the record.
67
+ */
68
+ sessionReloaded(): void;
69
+ recordFor(opts: {
70
+ ctx: Context<ContextData>;
71
+ stepId: string;
72
+ tool: Tool | undefined;
73
+ wireName: string;
74
+ args: unknown;
75
+ }): BridgedCallRecord;
76
+ }
77
+ export {};