@tangle-network/agent-app 0.60.248 → 0.60.250
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/assistant/index.js +2 -2
- package/dist/chat-react/index.js +2 -2
- package/dist/chat-routes/dispatch-first.d.ts +43 -0
- package/dist/chat-routes/index.js +2 -2
- package/dist/chat-routes/turn-execution.d.ts +3 -1
- package/dist/chat-routes/turn-route-contracts.d.ts +31 -0
- package/dist/{chunk-OXUBZ5SE.js → chunk-2HQP2CTA.js} +33 -12
- package/dist/chunk-2HQP2CTA.js.map +1 -0
- package/dist/{chunk-CFGBGIRK.js → chunk-5Y7Z5G3Y.js} +148 -15
- package/dist/chunk-5Y7Z5G3Y.js.map +1 -0
- package/dist/{chunk-WCXHXCER.js → chunk-63QAQP7I.js} +2 -2
- package/dist/{chunk-BDCC6UVW.js → chunk-A3KPDLSF.js} +144 -23
- package/dist/chunk-A3KPDLSF.js.map +1 -0
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +1 -1
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +13 -1
- package/dist/sandbox/prewarm-route.d.ts +41 -35
- package/dist/sandbox/warm-receipts.d.ts +67 -0
- package/dist/web-react/index.js +2 -2
- package/dist/web-react/workspace-prewarm.d.ts +12 -4
- package/dist/workspace-react/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BDCC6UVW.js.map +0 -1
- package/dist/chunk-CFGBGIRK.js.map +0 -1
- package/dist/chunk-OXUBZ5SE.js.map +0 -1
- /package/dist/{chunk-WCXHXCER.js.map → chunk-63QAQP7I.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-L7MB2LLM.js";
|
|
4
4
|
import {
|
|
5
5
|
useWorkspacePrewarmHandle
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2HQP2CTA.js";
|
|
7
7
|
import {
|
|
8
8
|
filterCommandPaletteItems
|
|
9
9
|
} from "./chunk-SJWIZT7B.js";
|
|
@@ -1603,4 +1603,4 @@ export {
|
|
|
1603
1603
|
ComposerModeControls,
|
|
1604
1604
|
EntryComposer
|
|
1605
1605
|
};
|
|
1606
|
-
//# sourceMappingURL=chunk-
|
|
1606
|
+
//# sourceMappingURL=chunk-63QAQP7I.js.map
|
|
@@ -289,6 +289,109 @@ function userPartsWithFiles(userParts, fileParts, mentions) {
|
|
|
289
289
|
// src/chat-routes/turn-execution.ts
|
|
290
290
|
import { deriveExecutionId, handleChatTurn } from "@tangle-network/agent-runtime/durable";
|
|
291
291
|
|
|
292
|
+
// src/chat-routes/dispatch-first.ts
|
|
293
|
+
var TurnAdmissionRefusedError = class extends Error {
|
|
294
|
+
constructor() {
|
|
295
|
+
super("The turn was refused after its producer started; its output was discarded.");
|
|
296
|
+
this.name = "TurnAdmissionRefusedError";
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
function dispatchProducerFirst(produce, args, trace) {
|
|
300
|
+
const abort = new AbortController();
|
|
301
|
+
let admit;
|
|
302
|
+
let reject;
|
|
303
|
+
const admitted = new Promise((resolve, fail) => {
|
|
304
|
+
admit = resolve;
|
|
305
|
+
reject = fail;
|
|
306
|
+
});
|
|
307
|
+
admitted.catch(() => {
|
|
308
|
+
});
|
|
309
|
+
let settled;
|
|
310
|
+
let stopped = false;
|
|
311
|
+
const queue = [];
|
|
312
|
+
let ended = false;
|
|
313
|
+
let failure;
|
|
314
|
+
let wake;
|
|
315
|
+
const notify = () => {
|
|
316
|
+
const resume = wake;
|
|
317
|
+
wake = void 0;
|
|
318
|
+
resume?.();
|
|
319
|
+
};
|
|
320
|
+
let source;
|
|
321
|
+
const handoffCompletion = args.handoffCompletion;
|
|
322
|
+
const started = trace.measure("admission.produce", "admission", () => produce({
|
|
323
|
+
...args,
|
|
324
|
+
admitted,
|
|
325
|
+
admissionSignal: abort.signal,
|
|
326
|
+
...handoffCompletion ? { handoffCompletion: () => admitted.then(() => handoffCompletion()) } : {}
|
|
327
|
+
}));
|
|
328
|
+
const draining = started.then(async (producer) => {
|
|
329
|
+
try {
|
|
330
|
+
source = producer.stream[Symbol.asyncIterator]();
|
|
331
|
+
for (; ; ) {
|
|
332
|
+
const next = await source.next();
|
|
333
|
+
if (next.done || stopped) break;
|
|
334
|
+
queue.push(next.value);
|
|
335
|
+
notify();
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (!stopped) failure = { error };
|
|
339
|
+
} finally {
|
|
340
|
+
ended = true;
|
|
341
|
+
notify();
|
|
342
|
+
}
|
|
343
|
+
}, (error) => {
|
|
344
|
+
failure = { error };
|
|
345
|
+
ended = true;
|
|
346
|
+
notify();
|
|
347
|
+
});
|
|
348
|
+
const stop = (reason) => {
|
|
349
|
+
if (stopped) return;
|
|
350
|
+
stopped = true;
|
|
351
|
+
abort.abort(reason);
|
|
352
|
+
queue.length = 0;
|
|
353
|
+
notify();
|
|
354
|
+
void started.then(() => source?.return?.(), () => {
|
|
355
|
+
}).catch(() => {
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
async function* replay() {
|
|
359
|
+
try {
|
|
360
|
+
for (; ; ) {
|
|
361
|
+
while (queue.length) yield queue.shift();
|
|
362
|
+
if (ended) break;
|
|
363
|
+
await new Promise((resolve) => {
|
|
364
|
+
wake = resolve;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
await draining;
|
|
368
|
+
if (failure) throw failure.error;
|
|
369
|
+
} finally {
|
|
370
|
+
if (!ended) stop(new Error("The turn stopped reading its producer."));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
async take(final) {
|
|
375
|
+
if (settled) throw new Error(`dispatch-first producer already ${settled}`);
|
|
376
|
+
settled = "taken";
|
|
377
|
+
admit(final);
|
|
378
|
+
const producer = await started;
|
|
379
|
+
return Object.defineProperty(Object.create(producer), "stream", { value: replay(), enumerable: true });
|
|
380
|
+
},
|
|
381
|
+
refuse() {
|
|
382
|
+
if (settled) return;
|
|
383
|
+
settled = "refused";
|
|
384
|
+
reject(new TurnAdmissionRefusedError());
|
|
385
|
+
stop(new TurnAdmissionRefusedError());
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function dispatchFirstFor(options, args, trace) {
|
|
390
|
+
const policy = options.dispatchFirst;
|
|
391
|
+
if (!policy || !(policy.when?.(args) ?? true)) return void 0;
|
|
392
|
+
return dispatchProducerFirst(options.produce, args, trace);
|
|
393
|
+
}
|
|
394
|
+
|
|
292
395
|
// src/chat-routes/turn-event-stream.ts
|
|
293
396
|
function failureReasonOf(data) {
|
|
294
397
|
if (!data) return void 0;
|
|
@@ -460,6 +563,14 @@ async function closeIteratorAfterAbort(iterator) {
|
|
|
460
563
|
}
|
|
461
564
|
|
|
462
565
|
// src/chat-routes/turn-execution.ts
|
|
566
|
+
async function readTurnHistory(store, threadId) {
|
|
567
|
+
return (await store.listMessages(threadId)).map((m) => ({
|
|
568
|
+
id: m.id,
|
|
569
|
+
role: m.role,
|
|
570
|
+
content: m.content,
|
|
571
|
+
parts: m.parts ?? null
|
|
572
|
+
}));
|
|
573
|
+
}
|
|
463
574
|
function modelAttributionFields(attribution) {
|
|
464
575
|
return {
|
|
465
576
|
...attribution?.requestedModel ? { requestedModel: attribution.requestedModel } : {},
|
|
@@ -508,12 +619,7 @@ function createAdmittedTurnRunner({
|
|
|
508
619
|
}));
|
|
509
620
|
if (!prepared.ok) return prepared.response;
|
|
510
621
|
}
|
|
511
|
-
const readHistory =
|
|
512
|
-
id: m.id,
|
|
513
|
-
role: m.role,
|
|
514
|
-
content: m.content,
|
|
515
|
-
parts: m.parts ?? null
|
|
516
|
-
}));
|
|
622
|
+
const readHistory = () => readTurnHistory(options.store, payload.threadId);
|
|
517
623
|
const historySpan = trace.start("admission.history", "admission");
|
|
518
624
|
const existingMessages = await readHistory();
|
|
519
625
|
const historyBeforeLock = options.turnLock ? JSON.stringify(existingMessages) : void 0;
|
|
@@ -585,6 +691,8 @@ function createAdmittedTurnRunner({
|
|
|
585
691
|
...intentLine ? { intentLine } : {},
|
|
586
692
|
...ctx?.executionLimits ? { executionLimits: ctx.executionLimits } : {}
|
|
587
693
|
};
|
|
694
|
+
const dispatched = dispatchFirstFor(options, produceArgs, trace);
|
|
695
|
+
if (dispatched) early.add(dispatched.refuse);
|
|
588
696
|
let lockAcquired = false;
|
|
589
697
|
let lockHandle;
|
|
590
698
|
let lockReleased = false;
|
|
@@ -808,6 +916,7 @@ function createAdmittedTurnRunner({
|
|
|
808
916
|
const beforeTurn = options.beforeTurn;
|
|
809
917
|
if (beforeTurn) {
|
|
810
918
|
const patch = await trace.measure("admission.before_turn", "admission", (span) => beforeTurn(produceArgs, { span }));
|
|
919
|
+
if (patch && Object.keys(patch).length && dispatched) throw new Error("beforeTurn cannot patch a dispatchFirst turn: its prompt is already sent");
|
|
811
920
|
if (patch) produceArgs = { ...produceArgs, ...patch };
|
|
812
921
|
}
|
|
813
922
|
const streamSetup = trace.start("admission.stream_setup", "admission");
|
|
@@ -870,7 +979,7 @@ function createAdmittedTurnRunner({
|
|
|
870
979
|
// defer it into the generator's first pull.
|
|
871
980
|
produce: () => ({
|
|
872
981
|
stream: (async function* () {
|
|
873
|
-
producer = await trace.measure("admission.produce", "admission", () => options.produce(produceArgs));
|
|
982
|
+
producer = await (dispatched ? dispatched.take(produceArgs) : trace.measure("admission.produce", "admission", () => options.produce(produceArgs)));
|
|
874
983
|
let source = producer.stream;
|
|
875
984
|
if (ctx?.cancelOnDisconnect) {
|
|
876
985
|
source = abortOnSignal(source, request.signal);
|
|
@@ -1051,6 +1160,32 @@ function createAdmittedTurnRunner({
|
|
|
1051
1160
|
}
|
|
1052
1161
|
|
|
1053
1162
|
// src/chat-routes/turn-routes.ts
|
|
1163
|
+
function earlyTurnWork(release, log) {
|
|
1164
|
+
let free = release;
|
|
1165
|
+
let also = [];
|
|
1166
|
+
return {
|
|
1167
|
+
handOff: () => {
|
|
1168
|
+
free = void 0;
|
|
1169
|
+
also = [];
|
|
1170
|
+
},
|
|
1171
|
+
add: (more) => {
|
|
1172
|
+
also.push(more);
|
|
1173
|
+
},
|
|
1174
|
+
release: async () => {
|
|
1175
|
+
const product = free;
|
|
1176
|
+
const route = also;
|
|
1177
|
+
free = void 0;
|
|
1178
|
+
also = [];
|
|
1179
|
+
for (const stop of route) stop();
|
|
1180
|
+
if (!product) return;
|
|
1181
|
+
try {
|
|
1182
|
+
await product();
|
|
1183
|
+
} catch (err) {
|
|
1184
|
+
log("[chat-routes] afterAuthorize release failed", { error: err instanceof Error ? err.message : String(err) });
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1054
1189
|
function createChatTurnRoutes(options) {
|
|
1055
1190
|
const log = options.log ?? ((message, meta) => console.error(message, meta ?? ""));
|
|
1056
1191
|
const draftStore = options.store;
|
|
@@ -1241,21 +1376,7 @@ function createChatTurnRoutes(options) {
|
|
|
1241
1376
|
log("[chat-routes] afterAuthorize failed; the turn goes on without it", { error: err instanceof Error ? err.message : String(err) });
|
|
1242
1377
|
}
|
|
1243
1378
|
}
|
|
1244
|
-
return
|
|
1245
|
-
handOff: () => {
|
|
1246
|
-
release = void 0;
|
|
1247
|
-
},
|
|
1248
|
-
release: async () => {
|
|
1249
|
-
const free = release;
|
|
1250
|
-
release = void 0;
|
|
1251
|
-
if (!free) return;
|
|
1252
|
-
try {
|
|
1253
|
-
await free();
|
|
1254
|
-
} catch (err) {
|
|
1255
|
-
log("[chat-routes] afterAuthorize release failed", { error: err instanceof Error ? err.message : String(err) });
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1379
|
+
return earlyTurnWork(release, log);
|
|
1259
1380
|
}
|
|
1260
1381
|
async function runTurn(request, ctx, admitted, progress, startedIntent) {
|
|
1261
1382
|
const early = startAfterAuthorize(request, admitted);
|
|
@@ -1513,4 +1634,4 @@ export {
|
|
|
1513
1634
|
createChatTurnRoutes,
|
|
1514
1635
|
streamChatRouteAsSandboxEvents
|
|
1515
1636
|
};
|
|
1516
|
-
//# sourceMappingURL=chunk-
|
|
1637
|
+
//# sourceMappingURL=chunk-A3KPDLSF.js.map
|