@noetic-tools/core 5.22.0-next.1 → 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/adapters/openrouter.d.ts +6 -1
- package/dist/adapters/openrouter.js +10 -0
- package/dist/builders/custom-item.d.ts +1 -1
- package/dist/builders/custom-item.js +14 -3
- package/dist/builders/decide-builders.d.ts +7 -0
- package/dist/builders/tool-builder.d.ts +5 -1
- package/dist/builders/tool-builder.js +2 -0
- package/dist/builders/workflow-control-nodes.js +1 -0
- 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 +130 -3
- package/dist/harness/agent-harness.js +337 -22
- package/dist/harness/decide-call.d.ts +15 -0
- package/dist/harness/decide-call.js +57 -7
- 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 +24 -1
- package/dist/harness/llm-client.d.ts +2 -0
- package/dist/harness/llm-client.js +9 -5
- package/dist/harness/model-rounds.d.ts +6 -0
- package/dist/harness/model-rounds.js +7 -3
- package/dist/harness/model-tool-round.js +67 -8
- 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 +9 -6
- package/dist/index.js +4 -3
- package/dist/interpreter/acp-tools.js +21 -4
- package/dist/interpreter/execute-action.js +7 -1
- package/dist/interpreter/execute-decide.js +5 -0
- 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/portable/runtime.d.ts +4 -0
- package/dist/portable/runtime.js +2 -0
- 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/event-broadcaster.d.ts +9 -1
- package/dist/runtime/event-broadcaster.js +16 -1
- package/dist/runtime/held-calls.d.ts +65 -6
- package/dist/runtime/held-calls.js +257 -5
- package/dist/runtime/output-store.d.ts +90 -0
- package/dist/runtime/output-store.js +243 -0
- package/dist/runtime/session-streams.d.ts +28 -7
- package/dist/runtime/session-streams.js +112 -67
- package/dist/runtime/tool-approval.d.ts +1 -3
- package/dist/runtime/tool-approval.js +1 -1
- package/package.json +2 -2
- package/schema/noetic-workflow.schema.json +27 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ItemStream } from './session-streams.js';
|
|
3
|
+
//#region Types
|
|
4
|
+
const OutputSnapshotSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
type: z.string(),
|
|
7
|
+
id: z.string().optional(),
|
|
8
|
+
isComplete: z.boolean().optional(),
|
|
9
|
+
})
|
|
10
|
+
.catchall(z.unknown());
|
|
11
|
+
/**
|
|
12
|
+
* @public A thread's display output could not be read or written. `scope` is the
|
|
13
|
+
* thread id; `cause` is what storage, or the snapshot check, failed with.
|
|
14
|
+
*/
|
|
15
|
+
export class OutputStoreError extends Error {
|
|
16
|
+
scope;
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options.message, {
|
|
19
|
+
cause: options.cause,
|
|
20
|
+
});
|
|
21
|
+
this.name = 'OutputStoreError';
|
|
22
|
+
this.scope = options.scope;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region Helpers
|
|
27
|
+
/** How many times one write is tried before the failure is kept. */
|
|
28
|
+
const WRITE_ATTEMPTS = 3;
|
|
29
|
+
/** How many times a write may lose to another writer before it is a failure. */
|
|
30
|
+
const SWAP_ATTEMPTS = 20;
|
|
31
|
+
const WRITE_RETRY_MS = 10;
|
|
32
|
+
/** @internal The prefix every thread's display output key starts with. */
|
|
33
|
+
export const OUTPUT_PREFIX = 'output:';
|
|
34
|
+
/** @internal The storage key a thread's display output is kept under. */
|
|
35
|
+
export function outputKey(scope) {
|
|
36
|
+
return `${OUTPUT_PREFIX}${scope}`;
|
|
37
|
+
}
|
|
38
|
+
/** What makes two snapshots the same item: its id, else its call, else its content. */
|
|
39
|
+
function keyOf(item) {
|
|
40
|
+
if (typeof item.id === 'string') {
|
|
41
|
+
return item.id;
|
|
42
|
+
}
|
|
43
|
+
if (typeof item.callId === 'string') {
|
|
44
|
+
return `${item.type}:${item.callId}`;
|
|
45
|
+
}
|
|
46
|
+
return JSON.stringify(item);
|
|
47
|
+
}
|
|
48
|
+
function wait(ms) {
|
|
49
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region OutputStore
|
|
53
|
+
/**
|
|
54
|
+
* @public A thread's display output, kept in storage under `output:<scope>`:
|
|
55
|
+
* the latest snapshot of every item its stream produced, including items that
|
|
56
|
+
* never finished. It is for showing a thread again, in a new process or after a
|
|
57
|
+
* failed run. Nothing resumes from it: checkpoints, the step ledger and the
|
|
58
|
+
* model's history are stored apart and never read here.
|
|
59
|
+
*
|
|
60
|
+
* `record` and `write` queue snapshots and save them in the background, one
|
|
61
|
+
* write at a time, each holding the whole output. `flush` and `read` wait for
|
|
62
|
+
* what is queued and throw `OutputStoreError` when it could not be saved; the
|
|
63
|
+
* snapshots stay queued, so the next call tries again. On storage with `swap` a
|
|
64
|
+
* write never replaces what another store saved meanwhile.
|
|
65
|
+
*/
|
|
66
|
+
export class OutputStore {
|
|
67
|
+
storage;
|
|
68
|
+
scope;
|
|
69
|
+
stream;
|
|
70
|
+
pending = new Map();
|
|
71
|
+
writing;
|
|
72
|
+
failure;
|
|
73
|
+
constructor(storage, scope, schemas) {
|
|
74
|
+
this.storage = storage;
|
|
75
|
+
this.scope = scope;
|
|
76
|
+
this.stream = new ItemStream(schemas);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Fold one stream event into the output. Never throws: an event that cannot be
|
|
80
|
+
* read as display output is left out, with a warning, and the run goes on.
|
|
81
|
+
*/
|
|
82
|
+
record(event) {
|
|
83
|
+
try {
|
|
84
|
+
for (const item of this.stream.push(event)) {
|
|
85
|
+
this.queue(OutputSnapshotSchema.parse(item));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (cause) {
|
|
89
|
+
console.warn(`[noetic] left a stream event out of the display output of "${this.scope}":`, cause);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.start();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Save display snapshots, each replacing the stored one with its id, and resolve
|
|
96
|
+
* the whole stored output.
|
|
97
|
+
*
|
|
98
|
+
* @throws OutputStoreError when `items` are not snapshots, or storage fails.
|
|
99
|
+
*/
|
|
100
|
+
async write(items) {
|
|
101
|
+
const parsed = OutputSnapshotSchema.array().safeParse(items);
|
|
102
|
+
if (!parsed.success) {
|
|
103
|
+
throw this.error('Could not read display snapshots.', parsed.error);
|
|
104
|
+
}
|
|
105
|
+
for (const item of parsed.data) {
|
|
106
|
+
this.queue(item);
|
|
107
|
+
}
|
|
108
|
+
return this.read();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The stored output, after everything queued is saved.
|
|
112
|
+
*
|
|
113
|
+
* @throws OutputStoreError when storage fails or holds something else.
|
|
114
|
+
*/
|
|
115
|
+
async read() {
|
|
116
|
+
await this.flush();
|
|
117
|
+
return (await this.load()).items;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Wait until everything queued is saved.
|
|
121
|
+
*
|
|
122
|
+
* @throws OutputStoreError when it could not be. What was queued stays queued,
|
|
123
|
+
* and every flush throws until a later one saves it.
|
|
124
|
+
*/
|
|
125
|
+
async flush() {
|
|
126
|
+
this.start();
|
|
127
|
+
while (this.writing) {
|
|
128
|
+
await this.writing;
|
|
129
|
+
}
|
|
130
|
+
// Not cleared here: two callers waiting on one failed write are both told.
|
|
131
|
+
if (this.failure) {
|
|
132
|
+
throw this.failure;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
queue(item) {
|
|
136
|
+
this.pending.set(keyOf(item), structuredClone(item));
|
|
137
|
+
}
|
|
138
|
+
start() {
|
|
139
|
+
if (this.pending.size === 0 || this.writing) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.writing = this.drain().then(() => {
|
|
143
|
+
this.failure = undefined;
|
|
144
|
+
this.writing = undefined;
|
|
145
|
+
this.start();
|
|
146
|
+
}, (cause) => {
|
|
147
|
+
this.failure =
|
|
148
|
+
cause instanceof OutputStoreError
|
|
149
|
+
? cause
|
|
150
|
+
: this.error('Could not write streamed output.', cause);
|
|
151
|
+
this.writing = undefined;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** What storage holds under the key, as it is stored and as snapshots. */
|
|
155
|
+
async load() {
|
|
156
|
+
try {
|
|
157
|
+
const raw = (await this.storage.get(outputKey(this.scope))) ?? null;
|
|
158
|
+
return {
|
|
159
|
+
raw,
|
|
160
|
+
items: OutputSnapshotSchema.array().parse(raw ?? []),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
catch (cause) {
|
|
164
|
+
throw this.error('Could not read streamed output.', cause);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Save what is queued over what is stored, until nothing is queued. */
|
|
168
|
+
async drain() {
|
|
169
|
+
while (this.pending.size > 0) {
|
|
170
|
+
const batch = new Map(this.pending);
|
|
171
|
+
this.pending.clear();
|
|
172
|
+
try {
|
|
173
|
+
await this.save(batch);
|
|
174
|
+
}
|
|
175
|
+
catch (cause) {
|
|
176
|
+
// Put back what was not saved, behind anything newer queued meanwhile.
|
|
177
|
+
for (const [key, item] of batch) {
|
|
178
|
+
if (!this.pending.has(key)) {
|
|
179
|
+
this.pending.set(key, item);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
throw cause;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async save(batch) {
|
|
187
|
+
let lost = 0;
|
|
188
|
+
for (let attempt = 1;;) {
|
|
189
|
+
try {
|
|
190
|
+
if (await this.saveOver(batch)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (cause) {
|
|
195
|
+
if (cause instanceof OutputStoreError) {
|
|
196
|
+
throw cause;
|
|
197
|
+
}
|
|
198
|
+
if (attempt >= WRITE_ATTEMPTS) {
|
|
199
|
+
throw this.error('Could not write streamed output.', cause);
|
|
200
|
+
}
|
|
201
|
+
attempt++;
|
|
202
|
+
await wait(WRITE_RETRY_MS);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
// Another writer saved first: merge over what it wrote.
|
|
206
|
+
lost++;
|
|
207
|
+
if (lost >= SWAP_ATTEMPTS) {
|
|
208
|
+
throw this.error('Could not write streamed output.', new Error(`Lost to another writer ${lost} times.`));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Write `batch` over what is stored now. On storage with `swap` the write lands
|
|
214
|
+
* only if nothing else was saved since the read, and false means it did not.
|
|
215
|
+
*/
|
|
216
|
+
async saveOver(batch) {
|
|
217
|
+
const stored = await this.load();
|
|
218
|
+
const held = new Map(stored.items.map((item) => [
|
|
219
|
+
keyOf(item),
|
|
220
|
+
item,
|
|
221
|
+
]));
|
|
222
|
+
for (const [key, item] of batch) {
|
|
223
|
+
held.set(key, item);
|
|
224
|
+
}
|
|
225
|
+
const next = [
|
|
226
|
+
...held.values(),
|
|
227
|
+
];
|
|
228
|
+
const key = outputKey(this.scope);
|
|
229
|
+
if (!this.storage.swap) {
|
|
230
|
+
await this.storage.set(key, next);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
return this.storage.swap(key, stored.raw, next);
|
|
234
|
+
}
|
|
235
|
+
error(message, cause) {
|
|
236
|
+
return new OutputStoreError({
|
|
237
|
+
scope: this.scope,
|
|
238
|
+
message,
|
|
239
|
+
cause,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
@@ -1,14 +1,35 @@
|
|
|
1
|
-
import type { ItemSchemaRegistry, StreamingItem } from '@noetic-tools/types';
|
|
1
|
+
import type { ItemSchemaRegistry, StreamEvent, StreamingItem } from '@noetic-tools/types';
|
|
2
2
|
import type { EventBroadcaster } from './event-broadcaster.js';
|
|
3
3
|
/** @internal Yield text deltas from the session broadcaster. */
|
|
4
4
|
export declare function filterTextStream(broadcaster: EventBroadcaster): AsyncIterable<string>;
|
|
5
5
|
/** @internal Yield reasoning-token deltas from the session broadcaster. */
|
|
6
6
|
export declare function filterReasoningStream(broadcaster: EventBroadcaster): AsyncIterable<string>;
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* multiple turns within a session don't collide.
|
|
7
|
+
/**
|
|
8
|
+
* @internal Yield cumulative StreamingItem snapshots.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* SDK events cover model output only; framework-authored items — turn input
|
|
11
|
+
* messages, between-rounds injections, tool results — arrive via the
|
|
12
|
+
* `item_appended` framework event and are yielded already complete.
|
|
13
|
+
*/
|
|
14
14
|
export declare function buildItemStream(broadcaster: EventBroadcaster, itemSchemas?: ItemSchemaRegistry): AsyncIterable<StreamingItem>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal Folds stream events into item snapshots, one event at a time: what
|
|
17
|
+
* `getItemStream` yields and what an `OutputStore` keeps.
|
|
18
|
+
*
|
|
19
|
+
* An event that names its item is matched by that id, which keeps model calls
|
|
20
|
+
* running at once apart. One that does not is matched by round and output index,
|
|
21
|
+
* the round counted from `response.created`, so the items of later tool rounds
|
|
22
|
+
* and later turns do not collide.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ItemStream {
|
|
25
|
+
private readonly accumulators;
|
|
26
|
+
private readonly byId;
|
|
27
|
+
private roundOffset;
|
|
28
|
+
private readonly itemSchemas;
|
|
29
|
+
constructor(itemSchemas?: ItemSchemaRegistry);
|
|
30
|
+
/** The snapshots `event` produces: none, or one. */
|
|
31
|
+
push(event: StreamEvent): Generator<StreamingItem>;
|
|
32
|
+
private add;
|
|
33
|
+
/** The accumulator `event` is about. `missingIndex` stands in for an absent output index. */
|
|
34
|
+
private find;
|
|
35
|
+
}
|
|
@@ -110,6 +110,40 @@ function completeStreamingItem(item) {
|
|
|
110
110
|
isComplete: true,
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
+
/** The id of the item an SDK event is about, when the event names one. */
|
|
114
|
+
function itemIdOf(event) {
|
|
115
|
+
const { itemId, item } = event.data;
|
|
116
|
+
if (typeof itemId === 'string') {
|
|
117
|
+
return itemId;
|
|
118
|
+
}
|
|
119
|
+
return isItemRecord(item) && typeof item.id === 'string' ? item.id : undefined;
|
|
120
|
+
}
|
|
121
|
+
/** Framework-authored snapshots: a custom item in progress, or an appended item. */
|
|
122
|
+
function* frameworkSnapshots(event) {
|
|
123
|
+
// A custom item's event streams in progress under the id its final item takes.
|
|
124
|
+
if (event.type.endsWith(':custom_item_event')) {
|
|
125
|
+
yield frameworkCast({
|
|
126
|
+
...event.data,
|
|
127
|
+
isComplete: false,
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (event.type.endsWith(':item_appended') &&
|
|
132
|
+
typeof event.data.item === 'object' &&
|
|
133
|
+
event.data.item !== null) {
|
|
134
|
+
yield {
|
|
135
|
+
...frameworkCast(event.data.item),
|
|
136
|
+
isComplete: true,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** How each delta event changes the item it is about. */
|
|
141
|
+
const ACCUMULATOR_UPDATES = {
|
|
142
|
+
'response.output_text.delta': updateMessageAccumulator,
|
|
143
|
+
'response.output_text.done': updateMessageAccumulator,
|
|
144
|
+
'response.function_call_arguments.delta': updateFunctionCallAccumulator,
|
|
145
|
+
'response.function_call_arguments.done': updateFunctionCallAccumulator,
|
|
146
|
+
};
|
|
113
147
|
//#endregion
|
|
114
148
|
//#region Public stream filters
|
|
115
149
|
/** @internal Yield text deltas from the session broadcaster. */
|
|
@@ -136,92 +170,103 @@ export async function* filterReasoningStream(broadcaster) {
|
|
|
136
170
|
}
|
|
137
171
|
}
|
|
138
172
|
}
|
|
139
|
-
/**
|
|
140
|
-
*
|
|
141
|
-
* multiple turns within a session don't collide.
|
|
173
|
+
/**
|
|
174
|
+
* @internal Yield cumulative StreamingItem snapshots.
|
|
142
175
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
176
|
+
* SDK events cover model output only; framework-authored items — turn input
|
|
177
|
+
* messages, between-rounds injections, tool results — arrive via the
|
|
178
|
+
* `item_appended` framework event and are yielded already complete.
|
|
179
|
+
*/
|
|
146
180
|
export async function* buildItemStream(broadcaster, itemSchemas = defaultItemSchemaRegistry) {
|
|
147
|
-
const
|
|
148
|
-
let roundOffset = 0;
|
|
181
|
+
const stream = new ItemStream(itemSchemas);
|
|
149
182
|
for await (const event of broadcaster) {
|
|
183
|
+
yield* stream.push(event);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ItemStream
|
|
188
|
+
/**
|
|
189
|
+
* @internal Folds stream events into item snapshots, one event at a time: what
|
|
190
|
+
* `getItemStream` yields and what an `OutputStore` keeps.
|
|
191
|
+
*
|
|
192
|
+
* An event that names its item is matched by that id, which keeps model calls
|
|
193
|
+
* running at once apart. One that does not is matched by round and output index,
|
|
194
|
+
* the round counted from `response.created`, so the items of later tool rounds
|
|
195
|
+
* and later turns do not collide.
|
|
196
|
+
*/
|
|
197
|
+
export class ItemStream {
|
|
198
|
+
accumulators = new Map();
|
|
199
|
+
byId = new Map();
|
|
200
|
+
roundOffset = 0;
|
|
201
|
+
itemSchemas;
|
|
202
|
+
constructor(itemSchemas = defaultItemSchemaRegistry) {
|
|
203
|
+
this.itemSchemas = itemSchemas;
|
|
204
|
+
}
|
|
205
|
+
/** The snapshots `event` produces: none, or one. */
|
|
206
|
+
*push(event) {
|
|
150
207
|
if (event.source === 'framework') {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
yield frameworkCast({
|
|
154
|
-
...event.data,
|
|
155
|
-
isComplete: false,
|
|
156
|
-
});
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
if (event.type.endsWith(':item_appended') &&
|
|
160
|
-
typeof event.data.item === 'object' &&
|
|
161
|
-
event.data.item !== null) {
|
|
162
|
-
yield {
|
|
163
|
-
...frameworkCast(event.data.item),
|
|
164
|
-
isComplete: true,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
continue;
|
|
208
|
+
yield* frameworkSnapshots(event);
|
|
209
|
+
return;
|
|
168
210
|
}
|
|
169
211
|
if (event.source !== 'sdk') {
|
|
170
|
-
|
|
212
|
+
return;
|
|
171
213
|
}
|
|
172
214
|
if (event.type === 'response.created') {
|
|
173
|
-
roundOffset++;
|
|
174
|
-
|
|
215
|
+
this.roundOffset++;
|
|
216
|
+
return;
|
|
175
217
|
}
|
|
176
218
|
if (event.type === 'response.output_item.added') {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const acc = createAccumulatorFromItemAdded(event, itemSchemas);
|
|
180
|
-
if (acc) {
|
|
181
|
-
accumulators.set(key, acc);
|
|
182
|
-
yield {
|
|
183
|
-
...acc.item,
|
|
184
|
-
isComplete: false,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
continue;
|
|
219
|
+
yield* this.add(event);
|
|
220
|
+
return;
|
|
188
221
|
}
|
|
189
222
|
if (event.type === 'response.output_item.done') {
|
|
190
|
-
const
|
|
191
|
-
const key = accumulatorKey(roundOffset, outputIndex);
|
|
192
|
-
const acc = accumulators.get(key);
|
|
223
|
+
const acc = this.find(event, -1);
|
|
193
224
|
if (acc) {
|
|
194
225
|
acc.isComplete = true;
|
|
195
226
|
yield completeStreamingItem(acc.item);
|
|
196
227
|
}
|
|
197
|
-
|
|
228
|
+
return;
|
|
198
229
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
isComplete: acc.isComplete,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
continue;
|
|
230
|
+
const update = ACCUMULATOR_UPDATES[event.type];
|
|
231
|
+
const acc = update ? this.find(event, 0) : undefined;
|
|
232
|
+
if (update && acc) {
|
|
233
|
+
update(acc, event);
|
|
234
|
+
yield {
|
|
235
|
+
...acc.item,
|
|
236
|
+
isComplete: acc.isComplete,
|
|
237
|
+
};
|
|
211
238
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
239
|
+
}
|
|
240
|
+
*add(event) {
|
|
241
|
+
const outputIndex = typeof event.outputIndex === 'number' ? event.outputIndex : this.accumulators.size;
|
|
242
|
+
const acc = createAccumulatorFromItemAdded(event, this.itemSchemas);
|
|
243
|
+
if (!acc) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
this.accumulators.set(accumulatorKey(this.roundOffset, outputIndex), acc);
|
|
247
|
+
if (acc.id !== '') {
|
|
248
|
+
this.byId.set(acc.id, acc);
|
|
249
|
+
}
|
|
250
|
+
yield {
|
|
251
|
+
...acc.item,
|
|
252
|
+
isComplete: false,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** The accumulator `event` is about. `missingIndex` stands in for an absent output index. */
|
|
256
|
+
find(event, missingIndex) {
|
|
257
|
+
const id = itemIdOf(event);
|
|
258
|
+
const named = id === undefined ? undefined : this.byId.get(id);
|
|
259
|
+
if (named) {
|
|
260
|
+
return named;
|
|
261
|
+
}
|
|
262
|
+
// An event that names an item this stream never saw is about the item at its
|
|
263
|
+
// own output index, which the provider renamed after `added`. One with no
|
|
264
|
+
// index is given to no item: it could be another call's.
|
|
265
|
+
if (id !== undefined && typeof event.outputIndex !== 'number') {
|
|
266
|
+
return undefined;
|
|
224
267
|
}
|
|
268
|
+
const outputIndex = typeof event.outputIndex === 'number' ? event.outputIndex : missingIndex;
|
|
269
|
+
return this.accumulators.get(accumulatorKey(this.roundOffset, outputIndex));
|
|
225
270
|
}
|
|
226
271
|
}
|
|
227
272
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context,
|
|
1
|
+
import type { Context, SteeringDecision } from '@noetic-tools/types';
|
|
2
2
|
import type { HoldHost } from './held-calls.js';
|
|
3
3
|
/** How the approval stage settled a call, as recorded on its `tool.call` span. */
|
|
4
4
|
export declare const ApprovalOutcome: {
|
|
@@ -58,8 +58,6 @@ export declare function awaitApproval(params: {
|
|
|
58
58
|
*/
|
|
59
59
|
recordId?: string;
|
|
60
60
|
ctx: Context;
|
|
61
|
-
/** Called once, when the call is first held. */
|
|
62
|
-
onHeld?: (held: HeldCall) => void;
|
|
63
61
|
/** False when the turn must stay live while the call is held. Default true. */
|
|
64
62
|
park?: boolean;
|
|
65
63
|
}): Promise<ToolApproval>;
|
|
@@ -173,7 +173,7 @@ export async function awaitApproval(params) {
|
|
|
173
173
|
});
|
|
174
174
|
if (!announced) {
|
|
175
175
|
announced = true;
|
|
176
|
-
|
|
176
|
+
announcerOf(params.harness, params.ctx)(toHeldCall(record));
|
|
177
177
|
}
|
|
178
178
|
await waitOnHeldCalls({
|
|
179
179
|
harness: params.harness,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noetic-tools/core",
|
|
3
|
-
"version": "5.22.0-next.
|
|
3
|
+
"version": "5.22.0-next.3",
|
|
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": "^2.0.0-next.1",
|
|
72
|
-
"@noetic-tools/types": "^3.19.0-next.
|
|
72
|
+
"@noetic-tools/types": "^3.19.0-next.2",
|
|
73
73
|
"@openrouter/agent": "^0.11.0",
|
|
74
74
|
"@openrouter/sdk": "1.4.25",
|
|
75
75
|
"jsonata": "2.2.2",
|
|
@@ -1373,6 +1373,15 @@
|
|
|
1373
1373
|
"type": "integer",
|
|
1374
1374
|
"exclusiveMinimum": 0,
|
|
1375
1375
|
"maximum": 9007199254740991
|
|
1376
|
+
},
|
|
1377
|
+
"headers": {
|
|
1378
|
+
"type": "object",
|
|
1379
|
+
"propertyNames": {
|
|
1380
|
+
"type": "string"
|
|
1381
|
+
},
|
|
1382
|
+
"additionalProperties": {
|
|
1383
|
+
"type": "string"
|
|
1384
|
+
}
|
|
1376
1385
|
}
|
|
1377
1386
|
},
|
|
1378
1387
|
"required": [
|
|
@@ -1738,6 +1747,15 @@
|
|
|
1738
1747
|
"type": "integer",
|
|
1739
1748
|
"exclusiveMinimum": 0,
|
|
1740
1749
|
"maximum": 9007199254740991
|
|
1750
|
+
},
|
|
1751
|
+
"headers": {
|
|
1752
|
+
"type": "object",
|
|
1753
|
+
"propertyNames": {
|
|
1754
|
+
"type": "string"
|
|
1755
|
+
},
|
|
1756
|
+
"additionalProperties": {
|
|
1757
|
+
"type": "string"
|
|
1758
|
+
}
|
|
1741
1759
|
}
|
|
1742
1760
|
},
|
|
1743
1761
|
"required": [
|
|
@@ -4463,6 +4481,15 @@
|
|
|
4463
4481
|
"type": "integer",
|
|
4464
4482
|
"exclusiveMinimum": 0,
|
|
4465
4483
|
"maximum": 9007199254740991
|
|
4484
|
+
},
|
|
4485
|
+
"headers": {
|
|
4486
|
+
"type": "object",
|
|
4487
|
+
"propertyNames": {
|
|
4488
|
+
"type": "string"
|
|
4489
|
+
},
|
|
4490
|
+
"additionalProperties": {
|
|
4491
|
+
"type": "string"
|
|
4492
|
+
}
|
|
4466
4493
|
}
|
|
4467
4494
|
},
|
|
4468
4495
|
"required": [
|