@noetic-tools/core 5.22.0-next.2 → 5.22.0-next.3
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.
- package/dist/adapters/in-memory-subprocess-adapter.js +4 -2
- package/dist/builders/custom-item.d.ts +1 -1
- package/dist/builders/custom-item.js +14 -3
- package/dist/connections/pool.d.ts +18 -0
- package/dist/connections/pool.js +54 -9
- package/dist/connections/registry.js +11 -0
- package/dist/harness/agent-harness.d.ts +76 -3
- package/dist/harness/agent-harness.js +229 -21
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/harness/forget.d.ts +57 -0
- package/dist/harness/forget.js +496 -0
- package/dist/harness/harness-options.d.ts +15 -1
- package/dist/harness/model-rounds.d.ts +6 -0
- package/dist/harness/model-rounds.js +7 -3
- package/dist/harness/model-tool-round.js +19 -5
- package/dist/harness/recorded-tool-calls.d.ts +16 -0
- package/dist/harness/recorded-tool-calls.js +106 -0
- package/dist/harness/spend.d.ts +13 -1
- package/dist/harness/spend.js +82 -1
- package/dist/harness/steer-inbox.js +9 -5
- package/dist/harness/thread-record.d.ts +12 -1
- package/dist/harness/thread-record.js +63 -19
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -3
- package/dist/interpreter/acp-tools.js +21 -4
- package/dist/interpreter/execute-action.js +7 -1
- package/dist/interpreter/execute.js +55 -3
- package/dist/interpreter/step-dispatcher.js +17 -1
- package/dist/interpreter/step-kind-dispatch.js +9 -1
- package/dist/runtime/durable/child-links.d.ts +61 -0
- package/dist/runtime/durable/child-links.js +127 -0
- package/dist/runtime/durable/session-store.d.ts +6 -0
- package/dist/runtime/durable/session-store.js +16 -2
- package/dist/runtime/durable/turn-lease.d.ts +10 -0
- package/dist/runtime/durable/turn-lease.js +10 -2
- package/dist/runtime/held-calls.d.ts +65 -6
- package/dist/runtime/held-calls.js +257 -5
- package/dist/runtime/output-store.d.ts +2 -0
- package/dist/runtime/output-store.js +3 -1
- package/dist/runtime/tool-approval.d.ts +1 -3
- package/dist/runtime/tool-approval.js +1 -1
- package/package.json +2 -2
|
@@ -4,7 +4,6 @@ import { runEvery } from '../connections/settle.js';
|
|
|
4
4
|
import { pendingTasksOf, resumableWaitsOf } from '../interpreter/connection-steps.js';
|
|
5
5
|
import { turnEndingIn } from '../interpreter/turn-ending.js';
|
|
6
6
|
import { AcpSessionStore } from '../runtime/acp-session-store.js';
|
|
7
|
-
import { emitFrameworkEvent, getBroadcaster } from '../runtime/broadcaster-utils.js';
|
|
8
7
|
import { stubOf } from '../runtime/durable/step-ledger.js';
|
|
9
8
|
import { heldCallsOf, toHeldCall } from '../runtime/held-calls.js';
|
|
10
9
|
import { OutputStore } from '../runtime/output-store.js';
|
|
@@ -15,12 +14,14 @@ import { clearPendingEntries, collectAllTools, collectCustomItems, deduplicateTo
|
|
|
15
14
|
import { buildItemStream, ChannelStore, ContextImpl, canSwap, captureCheckpoint, clearCheckpoint, collectContextTree, createInMemoryStorage, createSessionStore, createSpendLog, createStepLedgerStore, customItemGates, DEFAULT_LEASE_TTL_MS, DEFAULT_PARK_GRACE_MS, Drains, filterReasoningStream, filterTextStream, heldElsewhere, heldElsewhereUntil, INTERRUPT_REASON, isSteer, PARK_REASON, resolveStepLedgerRetention, restoreFromCheckpoint, rootIdOf, SessionRunner, StepLedger, snapshotCwdState, TurnLease, } from './deps/runtime.js';
|
|
16
15
|
import { SteeringAction } from './deps/types.js';
|
|
17
16
|
import { flowVersionOf } from './flow-version.js';
|
|
17
|
+
import { forgetExecution, forgetThread, listStoredExecutions, listStoredThreads } from './forget.js';
|
|
18
18
|
import { resolveCheckpointStore, resolveEnvironmentAdapters } from './harness-options.js';
|
|
19
19
|
import { createHarnessSpan, recordChannelWarning, resolveTraceExporter } from './harness-tracing.js';
|
|
20
20
|
import { LlmGateway } from './llm-client.js';
|
|
21
21
|
import { buildItemSchemaRegistry } from './model-schema.js';
|
|
22
22
|
import { DEFAULT_TASK_POLL_MS, DEFAULT_WAKE_DEBOUNCE_MS, ParkWatchers } from './park-watchers.js';
|
|
23
23
|
import { readDecision } from './read-decision.js';
|
|
24
|
+
import { recordedToolCalls } from './recorded-tool-calls.js';
|
|
24
25
|
import { Spend } from './spend.js';
|
|
25
26
|
import { ThreadRecord } from './thread-record.js';
|
|
26
27
|
/** Keep `message` in storage for after the thread's parked turn, with its options. */
|
|
@@ -30,6 +31,28 @@ function keepForLater(session, record, message) {
|
|
|
30
31
|
}
|
|
31
32
|
//#endregion
|
|
32
33
|
const DEFAULT_THREAD_ID = '__default__';
|
|
34
|
+
/**
|
|
35
|
+
* `store`, noting in `ids` the id of every layer it keeps durable state for, so a
|
|
36
|
+
* forget knows which layers' storage to look in (spec 23 § Forgetting).
|
|
37
|
+
*/
|
|
38
|
+
function noteDurableLayers(store, ids) {
|
|
39
|
+
const register = store.registerDurable;
|
|
40
|
+
if (!register) {
|
|
41
|
+
return store;
|
|
42
|
+
}
|
|
43
|
+
return new Proxy(store, {
|
|
44
|
+
get(target, property) {
|
|
45
|
+
if (property === 'registerDurable') {
|
|
46
|
+
return (executionId, layerId, storage) => {
|
|
47
|
+
ids.add(layerId);
|
|
48
|
+
register.call(target, executionId, layerId, storage);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const value = Reflect.get(target, property, target);
|
|
52
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
33
56
|
/** What a `turn_stuck` error says about where the turn stopped, or undefined for any other error. */
|
|
34
57
|
function stuckOf(error) {
|
|
35
58
|
const ending = turnEndingIn(error)?.noeticError;
|
|
@@ -202,6 +225,10 @@ export class AgentHarness {
|
|
|
202
225
|
outputStorage;
|
|
203
226
|
/** The display output each thread of an interactive harness records, by thread id. */
|
|
204
227
|
outputs = new Map();
|
|
228
|
+
/** Forgets in progress, by thread id: a turn of the thread waits for its forget. */
|
|
229
|
+
forgetting = new Map();
|
|
230
|
+
/** Ids of the context layers whose state this harness has kept durably. */
|
|
231
|
+
durableLayerIds = new Set();
|
|
205
232
|
/** Thread id → what stops recording it. */
|
|
206
233
|
stopRecording = new Map();
|
|
207
234
|
/** Threads named by a host-built context's own id, dropped when its run ends. */
|
|
@@ -310,6 +337,8 @@ export class AgentHarness {
|
|
|
310
337
|
decisionModel: opts.decisionModel,
|
|
311
338
|
emitItemsOnReplay: opts.emitItemsOnReplay,
|
|
312
339
|
approveToolCall: opts.approveToolCall,
|
|
340
|
+
onHeld: opts.onHeld,
|
|
341
|
+
steerWhileHeld: opts.steerWhileHeld,
|
|
313
342
|
now: opts.now,
|
|
314
343
|
};
|
|
315
344
|
this.outputStorage = this.config.storage ?? createInMemoryStorage();
|
|
@@ -353,11 +382,10 @@ export class AgentHarness {
|
|
|
353
382
|
onWarning: (warning) => this.recordChannelWarning(warning),
|
|
354
383
|
});
|
|
355
384
|
this.traceExporter = resolveTraceExporter(opts.traceExporter);
|
|
356
|
-
this.layerStateStore =
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
});
|
|
385
|
+
this.layerStateStore = noteDurableLayers(storageEnv?.layerStateStore ??
|
|
386
|
+
createLayerStateStore((layerId, hook, error) => {
|
|
387
|
+
console.warn(`[noetic] context layer '${layerId}' ${hook} error:`, error);
|
|
388
|
+
}), this.durableLayerIds);
|
|
361
389
|
this.recallCache = createRecallCache();
|
|
362
390
|
this.contextCache = createContextCacheStore();
|
|
363
391
|
this.defaultDeliveryMode = opts.defaultDeliveryMode ?? 'next-turn';
|
|
@@ -492,6 +520,7 @@ export class AgentHarness {
|
|
|
492
520
|
*/
|
|
493
521
|
async close() {
|
|
494
522
|
this.parkWatchers?.stopAll();
|
|
523
|
+
heldCallsOf(this).releaseWatches();
|
|
495
524
|
await runEvery([
|
|
496
525
|
...[
|
|
497
526
|
...this.outputs.values(),
|
|
@@ -630,6 +659,11 @@ export class AgentHarness {
|
|
|
630
659
|
return Promise.reject(missingModel);
|
|
631
660
|
}
|
|
632
661
|
const threadId = options?.threadId ?? DEFAULT_THREAD_ID;
|
|
662
|
+
const forgetting = this.forgetting.get(threadId);
|
|
663
|
+
if (forgetting) {
|
|
664
|
+
// A message for a thread being forgotten starts the thread afresh once the forget is done.
|
|
665
|
+
return forgetting.then(() => this.deliverInput(input, options));
|
|
666
|
+
}
|
|
633
667
|
const deliveryMode = options?.deliveryMode ?? this.defaultDeliveryMode;
|
|
634
668
|
const session = this.getOrCreateSession(threadId);
|
|
635
669
|
const message = {
|
|
@@ -653,9 +687,13 @@ export class AgentHarness {
|
|
|
653
687
|
* deliveries doing that at once would each miss the other.
|
|
654
688
|
*/
|
|
655
689
|
deliver(session, message) {
|
|
690
|
+
session.arriving = (session.arriving ?? 0) + 1;
|
|
656
691
|
const turn = (session.delivering ?? Promise.resolve())
|
|
657
692
|
.catch(() => undefined)
|
|
658
|
-
.then(() => this.deliverOne(session, message))
|
|
693
|
+
.then(() => this.deliverOne(session, message))
|
|
694
|
+
.finally(() => {
|
|
695
|
+
session.arriving = (session.arriving ?? 1) - 1;
|
|
696
|
+
});
|
|
659
697
|
session.delivering = turn;
|
|
660
698
|
return turn;
|
|
661
699
|
}
|
|
@@ -1107,7 +1145,9 @@ export class AgentHarness {
|
|
|
1107
1145
|
// A harness that was replaced says nothing about the turn: it is the new
|
|
1108
1146
|
// holder's now, and marking it stopped would keep a wake from resuming it.
|
|
1109
1147
|
const replaced = isLeaseLost(error) || session.lease?.lost === true;
|
|
1110
|
-
|
|
1148
|
+
// An interrupted turn answers its held calls "Cancelled before it ran." in
|
|
1149
|
+
// the history it restarts from: no answer could reach them any more.
|
|
1150
|
+
if (ctx.aborted && !replaced) {
|
|
1111
1151
|
await heldCallsOf(this).clear(ctx.id);
|
|
1112
1152
|
}
|
|
1113
1153
|
if (record && !replaced && ctx.abortReason !== INTERRUPT_REASON) {
|
|
@@ -1163,6 +1203,10 @@ export class AgentHarness {
|
|
|
1163
1203
|
: await this.sessionStore.threads();
|
|
1164
1204
|
const woken = [];
|
|
1165
1205
|
for (const threadId of threadIds) {
|
|
1206
|
+
// A thread being forgotten has no turn left to wake.
|
|
1207
|
+
if (this.forgetting.has(threadId)) {
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1166
1210
|
// A turn asked for by name may be closing out its park this instant: its
|
|
1167
1211
|
// runner is busy, though nothing is running. Wait for it rather than skip.
|
|
1168
1212
|
const closing = scope?.threadId ? this.sessions.get(threadId)?.runner : undefined;
|
|
@@ -1320,7 +1364,29 @@ export class AgentHarness {
|
|
|
1320
1364
|
if (scope && 'executionId' in scope) {
|
|
1321
1365
|
return;
|
|
1322
1366
|
}
|
|
1323
|
-
|
|
1367
|
+
await this.wakeAnswered(scope?.threadId ?? DEFAULT_THREAD_ID, options);
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* An `onHeld` handler's answer: for the execution that held the call, never for a
|
|
1371
|
+
* later turn on the same thread. Wakes the thread's turn when it is that execution.
|
|
1372
|
+
* @internal
|
|
1373
|
+
*/
|
|
1374
|
+
async answerHeld(answer) {
|
|
1375
|
+
await heldCallsOf(this).resolve(answer.executionId, {
|
|
1376
|
+
callId: answer.callId,
|
|
1377
|
+
argsHash: answer.argsHash,
|
|
1378
|
+
resolution: answer.resolution,
|
|
1379
|
+
});
|
|
1380
|
+
if (answer.threadId === undefined) {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
if ((await this.turnExecutionId(answer.threadId)) !== answer.executionId) {
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
await this.wakeAnswered(answer.threadId);
|
|
1387
|
+
}
|
|
1388
|
+
/** A thread's turn was answered: resume it if parked, now or once it comes to rest. */
|
|
1389
|
+
async wakeAnswered(threadId, options) {
|
|
1324
1390
|
const runner = this.sessions.get(threadId)?.runner;
|
|
1325
1391
|
if (runner?.context === undefined) {
|
|
1326
1392
|
await this.wake({
|
|
@@ -1412,13 +1478,27 @@ export class AgentHarness {
|
|
|
1412
1478
|
});
|
|
1413
1479
|
return true;
|
|
1414
1480
|
}
|
|
1481
|
+
/**
|
|
1482
|
+
* The tool calls a resume of `executionId` goes on from rather than having the
|
|
1483
|
+
* model ask for them again: every call whose request its step ledger holds, in a
|
|
1484
|
+
* completed step or a recorded round, read from storage. `settled` says whether
|
|
1485
|
+
* the call's result is on record too; an unsettled call runs again on resume (spec
|
|
1486
|
+
* 23a § Tool calls in a round). A host that journals tool traffic of its own adds
|
|
1487
|
+
* none of these to a restored context, or the model sees them twice. Empty without
|
|
1488
|
+
* durable storage.
|
|
1489
|
+
* @public
|
|
1490
|
+
*/
|
|
1491
|
+
async recordedToolCalls(executionId) {
|
|
1492
|
+
const window = await this.stepLedgerStore?.load(executionId);
|
|
1493
|
+
return window ? recordedToolCalls(window) : [];
|
|
1494
|
+
}
|
|
1415
1495
|
/**
|
|
1416
1496
|
* What a run did, step by step: who ran each step, under which flow version, and
|
|
1417
1497
|
* the receipt of a step with a lasting effect (spec 23 § The trail). Marks outlive
|
|
1418
1498
|
* the ledger entries they came from, so the trail of a finished run stays readable.
|
|
1419
1499
|
*
|
|
1420
|
-
* `scope` names an execution, or a thread, whose
|
|
1421
|
-
*
|
|
1500
|
+
* `scope` names an execution, or a thread, whose turns are then listed in order:
|
|
1501
|
+
* every turn it began, two reads per turn.
|
|
1422
1502
|
* @public
|
|
1423
1503
|
*/
|
|
1424
1504
|
async getAuditTrail(scope) {
|
|
@@ -1450,6 +1530,128 @@ export class AgentHarness {
|
|
|
1450
1530
|
return marks;
|
|
1451
1531
|
}
|
|
1452
1532
|
//#endregion
|
|
1533
|
+
//#region Forgetting
|
|
1534
|
+
/**
|
|
1535
|
+
* Delete everything the harness keeps for a thread or an execution, so a host never
|
|
1536
|
+
* builds a storage key itself (spec 23 § Forgetting).
|
|
1537
|
+
*
|
|
1538
|
+
* A thread's forget covers every execution the thread ran, its context-layer state,
|
|
1539
|
+
* display output, record and turn lease. An execution's forget covers what is stored
|
|
1540
|
+
* under it and its layer state, and leaves any thread's record alone. Pending spend
|
|
1541
|
+
* is settled first: priced through the provider, waiting up to `patienceMs`, else
|
|
1542
|
+
* written off at its ceiling (at 0, flagged `unbounded`, when it has none). The trail
|
|
1543
|
+
* goes too unless `keepTrail`.
|
|
1544
|
+
*
|
|
1545
|
+
* A thread's forget holds and renews the thread's lease until it is done, and a
|
|
1546
|
+
* message sent to the thread on this harness meanwhile waits for it, then starts
|
|
1547
|
+
* the thread afresh.
|
|
1548
|
+
*
|
|
1549
|
+
* @throws NoeticError `lease_lost` when the thread has a turn running, queued or
|
|
1550
|
+
* being delivered in this harness, is already being forgotten, or the execution
|
|
1551
|
+
* has a run in flight; when another harness still holds the thread's lease after
|
|
1552
|
+
* `waitMs`; or when the lease is lost part way.
|
|
1553
|
+
* @throws NoeticError `ledger_write_failed` when a spend record could not be
|
|
1554
|
+
* settled; nothing was deleted.
|
|
1555
|
+
* @throws NoeticConfigError `INVALID_FORGET_SCOPE` for a scope with neither id.
|
|
1556
|
+
* @public
|
|
1557
|
+
*/
|
|
1558
|
+
async forget(scope, options) {
|
|
1559
|
+
if ('executionId' in scope) {
|
|
1560
|
+
return forgetExecution(this.forgetHost(), scope.executionId, options);
|
|
1561
|
+
}
|
|
1562
|
+
const threadId = scope.threadId;
|
|
1563
|
+
if (typeof threadId !== 'string' || threadId === '') {
|
|
1564
|
+
throw new NoeticConfigError({
|
|
1565
|
+
code: 'INVALID_FORGET_SCOPE',
|
|
1566
|
+
message: 'harness.forget() needs a threadId or an executionId.',
|
|
1567
|
+
hint: 'Pass { threadId } to forget a thread, or { executionId } to forget one execution.',
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
const running = this.forgetting.get(threadId);
|
|
1571
|
+
if (running) {
|
|
1572
|
+
throw new NoeticErrorImpl({
|
|
1573
|
+
kind: 'lease_lost',
|
|
1574
|
+
executionId: threadId,
|
|
1575
|
+
term: 0,
|
|
1576
|
+
reason: `thread "${threadId}" is already being forgotten`,
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
const forgetting = forgetThread(this.forgetHost(), threadId, options);
|
|
1580
|
+
this.forgetting.set(threadId, forgetting.catch(() => undefined));
|
|
1581
|
+
try {
|
|
1582
|
+
return await forgetting;
|
|
1583
|
+
}
|
|
1584
|
+
finally {
|
|
1585
|
+
this.forgetting.delete(threadId);
|
|
1586
|
+
await this.announceWakeTimeQuietly();
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Every thread with a record, a turn lease, or display output stored: what
|
|
1591
|
+
* `forget({ threadId })` deletes. Sorted; `prefix` narrows to ids that start with it.
|
|
1592
|
+
* @public
|
|
1593
|
+
*/
|
|
1594
|
+
async listStoredThreads(options) {
|
|
1595
|
+
return listStoredThreads(this.forgetHost(), options);
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Every execution with anything stored, with what is stored for it. `resumable` is
|
|
1599
|
+
* set when a snapshot or ledger entries are: a trail alone is not a checkpoint.
|
|
1600
|
+
* Sorted; `prefix` narrows to ids that start with it.
|
|
1601
|
+
* @public
|
|
1602
|
+
*/
|
|
1603
|
+
async listStoredExecutions(options) {
|
|
1604
|
+
return listStoredExecutions(this.forgetHost(), options);
|
|
1605
|
+
}
|
|
1606
|
+
forgetHost() {
|
|
1607
|
+
return {
|
|
1608
|
+
storage: this.config.storage,
|
|
1609
|
+
outputStorage: this.outputStorage,
|
|
1610
|
+
checkpointStore: this.checkpointStore,
|
|
1611
|
+
sessionStore: this.sessionStore,
|
|
1612
|
+
leaseOptions: this.leaseOptions,
|
|
1613
|
+
threadBusy: (threadId) => {
|
|
1614
|
+
const session = this.sessions.get(threadId);
|
|
1615
|
+
if (!session) {
|
|
1616
|
+
return false;
|
|
1617
|
+
}
|
|
1618
|
+
return (session.lease !== undefined ||
|
|
1619
|
+
session.runner.context !== undefined ||
|
|
1620
|
+
session.runner.getStatus().kind !== 'idle' ||
|
|
1621
|
+
session.runner.queue.size > 0 ||
|
|
1622
|
+
(session.arriving ?? 0) > 0);
|
|
1623
|
+
},
|
|
1624
|
+
executionBusy: (executionId) => this.liveRoots.has(executionId),
|
|
1625
|
+
closeSpend: async (owns, patienceMs) => (await this.spend?.close(owns, patienceMs)) ?? [],
|
|
1626
|
+
clearCheckpoint: (executionId) => this.clearCheckpoint(executionId),
|
|
1627
|
+
settleOutput: async (threadId) => {
|
|
1628
|
+
const output = this.outputs.get(threadId);
|
|
1629
|
+
this.outputs.delete(threadId);
|
|
1630
|
+
await output?.flush().catch(() => undefined);
|
|
1631
|
+
},
|
|
1632
|
+
dropThread: (threadId) => {
|
|
1633
|
+
this.parkWatchers?.stop(threadId);
|
|
1634
|
+
this.sessions.delete(threadId);
|
|
1635
|
+
},
|
|
1636
|
+
layerIds: () => this.layerIds(),
|
|
1637
|
+
releaseConnections: (executionId) => this.#connections.registry.releaseRun(executionId),
|
|
1638
|
+
subprocess: this.subprocess,
|
|
1639
|
+
harness: this,
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
/** Ids of the layers that may keep durable state: this harness's thread-wide layers, and any it has kept state for. */
|
|
1643
|
+
layerIds() {
|
|
1644
|
+
const ids = new Set(this.durableLayerIds);
|
|
1645
|
+
for (const layer of this._contextLayers ?? []) {
|
|
1646
|
+
if (layer.scope !== 'execution') {
|
|
1647
|
+
ids.add(layer.id);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
return [
|
|
1651
|
+
...ids,
|
|
1652
|
+
];
|
|
1653
|
+
}
|
|
1654
|
+
//#endregion
|
|
1453
1655
|
//#region Triggers
|
|
1454
1656
|
/**
|
|
1455
1657
|
* Add a trigger while the harness runs (spec 35 § Triggers). A trigger written
|
|
@@ -1664,6 +1866,21 @@ export class AgentHarness {
|
|
|
1664
1866
|
}
|
|
1665
1867
|
return true;
|
|
1666
1868
|
}
|
|
1869
|
+
/**
|
|
1870
|
+
* The thread whose turn `ctx` runs in, or `undefined` for a run the host started
|
|
1871
|
+
* itself. Where an `onHeld` answer goes.
|
|
1872
|
+
* @internal
|
|
1873
|
+
*/
|
|
1874
|
+
heldThreadOf(ctx) {
|
|
1875
|
+
const executionId = rootIdOf(ctx);
|
|
1876
|
+
for (const [threadId, session] of this.sessions) {
|
|
1877
|
+
const running = session.runner.context;
|
|
1878
|
+
if (running && rootIdOf(running) === executionId) {
|
|
1879
|
+
return threadId;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return undefined;
|
|
1883
|
+
}
|
|
1667
1884
|
/** The execution whose held calls `scope` names. */
|
|
1668
1885
|
heldExecutionId(scope) {
|
|
1669
1886
|
if (scope && 'executionId' in scope) {
|
|
@@ -1701,6 +1918,7 @@ export class AgentHarness {
|
|
|
1701
1918
|
restore: (executionId, opts) => this.restore(executionId, opts),
|
|
1702
1919
|
clearCheckpoint: (executionId) => this.clearCheckpoint(executionId),
|
|
1703
1920
|
parseItems: (raw) => this.itemSchemas.parseMany(raw),
|
|
1921
|
+
layerIds: () => this.layerIds(),
|
|
1704
1922
|
}, threadId);
|
|
1705
1923
|
}
|
|
1706
1924
|
requireSession(scope) {
|
|
@@ -1741,16 +1959,6 @@ export class AgentHarness {
|
|
|
1741
1959
|
callId: request.callId,
|
|
1742
1960
|
ctx: request.ctx,
|
|
1743
1961
|
park: request.park,
|
|
1744
|
-
onHeld: (held) => {
|
|
1745
|
-
emitFrameworkEvent({
|
|
1746
|
-
broadcaster: getBroadcaster(request.ctx),
|
|
1747
|
-
agentName: this.config.name,
|
|
1748
|
-
eventType: 'tool_call_held',
|
|
1749
|
-
data: {
|
|
1750
|
-
...held,
|
|
1751
|
-
},
|
|
1752
|
-
});
|
|
1753
|
-
},
|
|
1754
1962
|
});
|
|
1755
1963
|
return approval.decision;
|
|
1756
1964
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, ExecutionContext, ProjectionPolicy, StorageAdapter, } from '@noetic-tools/context';
|
|
2
|
-
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, Steps, StepsInput, StepsOutput, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, ValidStepChain, WriteOffSpendOptions, } from '@noetic-tools/types';
|
|
2
|
+
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, HeldCallHandler, HeldSteerPolicy, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, Steps, StepsInput, StepsOutput, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, ValidStepChain, WriteOffSpendOptions, } from '@noetic-tools/types';
|
|
3
3
|
export { SteeringAction } from '@noetic-tools/types';
|
|
4
4
|
export type { ZodType } from 'zod';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgetting a thread or an execution: deleting every record core keeps for it,
|
|
3
|
+
* after settling the spend it left pending, and listing what is stored so a host
|
|
4
|
+
* never builds a storage key itself (spec 23 § Forgetting).
|
|
5
|
+
*/
|
|
6
|
+
import type { ForgetOptions, ForgetReport, ListStoredOptions, SpendSettlement, StorageAdapter, StoredExecution, SubprocessAdapter } from '@noetic-tools/types';
|
|
7
|
+
import type { CheckpointStore } from '../runtime/durable/checkpoint-store.js';
|
|
8
|
+
import type { SessionStore } from '../runtime/durable/session-store.js';
|
|
9
|
+
import type { SpendRecord } from '../runtime/durable/spend-log.js';
|
|
10
|
+
import type { TurnLeaseOptions } from '../runtime/durable/turn-lease.js';
|
|
11
|
+
/** @internal What forgetting needs from its harness. */
|
|
12
|
+
export interface ForgetHost {
|
|
13
|
+
/** The harness's durable storage. Undefined when it has none. */
|
|
14
|
+
readonly storage?: StorageAdapter;
|
|
15
|
+
/** Where display output is kept: `storage`, or memory without it. */
|
|
16
|
+
readonly outputStorage: StorageAdapter;
|
|
17
|
+
readonly checkpointStore?: CheckpointStore;
|
|
18
|
+
readonly sessionStore?: SessionStore;
|
|
19
|
+
readonly leaseOptions?: TurnLeaseOptions;
|
|
20
|
+
/** True when this harness has a turn of the thread running. */
|
|
21
|
+
threadBusy(threadId: string): boolean;
|
|
22
|
+
/** True when this harness has a run in flight on the execution. */
|
|
23
|
+
executionBusy(executionId: string): boolean;
|
|
24
|
+
/** Settle the pending dispatches `owns` picks; empty without durable storage. */
|
|
25
|
+
closeSpend(owns: (record: SpendRecord) => boolean, patienceMs?: number): Promise<SpendSettlement[]>;
|
|
26
|
+
/** `clearCheckpoint`: the snapshot, ledger, held calls and pending entries. */
|
|
27
|
+
clearCheckpoint(executionId: string): Promise<void>;
|
|
28
|
+
/** Wait for the thread's queued display output to land, then drop it from memory. */
|
|
29
|
+
settleOutput(threadId: string): Promise<void>;
|
|
30
|
+
/** Drop what this harness holds in memory for the thread: its session and park watch. */
|
|
31
|
+
dropThread(threadId: string): void;
|
|
32
|
+
/** Ids of the context layers this harness keeps durable state for. */
|
|
33
|
+
layerIds(): ReadonlyArray<string>;
|
|
34
|
+
/** Release the pool leases this harness still holds for the run, freeing their connections. */
|
|
35
|
+
releaseConnections(executionId: string): Promise<void>;
|
|
36
|
+
/** The harness's `environment.subprocess`. */
|
|
37
|
+
readonly subprocess: SubprocessAdapter;
|
|
38
|
+
/** The harness itself: what it dispatched out of process is kept against it. */
|
|
39
|
+
readonly harness: object;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
* Forget a thread: settle its spend, then delete its executions, layer state,
|
|
44
|
+
* display output, record and lease, in that order, holding the lease throughout.
|
|
45
|
+
* The caller keeps new turns of the thread from starting in this harness meanwhile.
|
|
46
|
+
*/
|
|
47
|
+
export declare function forgetThread(host: ForgetHost, threadId: string, options?: ForgetOptions): Promise<ForgetReport>;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
* Forget one execution: settle its spend, then delete everything under
|
|
51
|
+
* `execution:<id>:`. A thread's record is left alone.
|
|
52
|
+
*/
|
|
53
|
+
export declare function forgetExecution(host: ForgetHost, executionId: string, options?: ForgetOptions): Promise<ForgetReport>;
|
|
54
|
+
/** @internal Every thread with a record, a lease, or display output stored. */
|
|
55
|
+
export declare function listStoredThreads(host: ForgetHost, options?: ListStoredOptions): Promise<string[]>;
|
|
56
|
+
/** @internal Every execution with anything stored, and what is stored for it. */
|
|
57
|
+
export declare function listStoredExecutions(host: ForgetHost, options?: ListStoredOptions): Promise<StoredExecution[]>;
|