@tangle-network/agent-app 0.47.12 → 0.47.14
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/chat-routes/index.js +65 -19
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/model-failover-stream.d.ts +23 -0
- package/dist/chat-routes/sandbox-producer.d.ts +5 -0
- package/dist/{chunk-P6YXUGNA.js → chunk-3G4IUF3D.js} +63 -58
- package/dist/chunk-3G4IUF3D.js.map +1 -0
- package/dist/sandbox/index.d.ts +21 -0
- package/dist/sandbox/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-P6YXUGNA.js.map +0 -1
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
flattenHistory,
|
|
42
42
|
readSandboxBinaryBytes,
|
|
43
43
|
statSandboxFileSize
|
|
44
|
-
} from "../chunk-
|
|
44
|
+
} from "../chunk-3G4IUF3D.js";
|
|
45
45
|
import "../chunk-MCYJON3F.js";
|
|
46
46
|
import "../chunk-LWSJK546.js";
|
|
47
47
|
import "../chunk-P5PIAQVS.js";
|
|
@@ -160,6 +160,10 @@ function summarizeFailoverReason(reason) {
|
|
|
160
160
|
const lastSpace = clipped.lastIndexOf(" ");
|
|
161
161
|
return `${(lastSpace > LIMIT - 30 ? clipped.slice(0, lastSpace) : clipped).trimEnd()}\u2026`;
|
|
162
162
|
}
|
|
163
|
+
function isLiveLifecycleEvent(event) {
|
|
164
|
+
const type = asString(asRecord(event)?.type) ?? "";
|
|
165
|
+
return type === "start" || type === "execution.started" || type === "status" || type === "model-processing" || type === "model.processing" || type === "session.created" || type === "session.updated" || type === "session.idle";
|
|
166
|
+
}
|
|
163
167
|
function classifyTerminalFailure(event) {
|
|
164
168
|
const record = asRecord(event);
|
|
165
169
|
if (!record) return null;
|
|
@@ -247,6 +251,8 @@ function streamWithModelFailover(options) {
|
|
|
247
251
|
DEFAULT_MODEL_FIRST_RESPONSE_TIMEOUT_MS,
|
|
248
252
|
"firstResponseTimeoutMs"
|
|
249
253
|
);
|
|
254
|
+
const liveLifecycle = options.liveLifecycleEvents === true;
|
|
255
|
+
const progress = createProgressQueue();
|
|
250
256
|
let serving;
|
|
251
257
|
let trail = [];
|
|
252
258
|
let fellBack = false;
|
|
@@ -368,7 +374,11 @@ function streamWithModelFailover(options) {
|
|
|
368
374
|
empty: false
|
|
369
375
|
};
|
|
370
376
|
}
|
|
371
|
-
|
|
377
|
+
if (liveLifecycle && !failure && !commits && isLiveLifecycleEvent(event)) {
|
|
378
|
+
progress.push(event);
|
|
379
|
+
} else {
|
|
380
|
+
buffered.push(event);
|
|
381
|
+
}
|
|
372
382
|
if (failure) {
|
|
373
383
|
firstResponseDeadline.clear();
|
|
374
384
|
return { outcome: { committed: true, buffered, iterator, abort }, empty: false };
|
|
@@ -437,24 +447,31 @@ function streamWithModelFailover(options) {
|
|
|
437
447
|
};
|
|
438
448
|
const events = (async function* () {
|
|
439
449
|
let handle;
|
|
450
|
+
const settled = runWithModelFailover({
|
|
451
|
+
models: options.models,
|
|
452
|
+
run: probe,
|
|
453
|
+
// The probe has already classified the raw payload with
|
|
454
|
+
// `isUpstreamUnavailable`; this reads its verdict rather than
|
|
455
|
+
// re-classifying a wrapper object, so the two can never disagree.
|
|
456
|
+
isUnavailableResult: (result) => result.committed === false,
|
|
457
|
+
onFallback: (attempt, nextModel) => {
|
|
458
|
+
const info = {
|
|
459
|
+
from: attempt.model,
|
|
460
|
+
to: nextModel,
|
|
461
|
+
reason: attempt.reason ?? "upstream unavailable"
|
|
462
|
+
};
|
|
463
|
+
options.log?.("[chat-routes] model upstream unavailable; falling over", { ...info });
|
|
464
|
+
options.onFallback?.(info);
|
|
465
|
+
}
|
|
466
|
+
}).finally(() => progress.close());
|
|
467
|
+
settled.catch(() => void 0);
|
|
468
|
+
for (; ; ) {
|
|
469
|
+
const item = await progress.pull();
|
|
470
|
+
if (item === PROGRESS_CLOSED) break;
|
|
471
|
+
yield item;
|
|
472
|
+
}
|
|
440
473
|
try {
|
|
441
|
-
const outcome = await
|
|
442
|
-
models: options.models,
|
|
443
|
-
run: probe,
|
|
444
|
-
// The probe has already classified the raw payload with
|
|
445
|
-
// `isUpstreamUnavailable`; this reads its verdict rather than
|
|
446
|
-
// re-classifying a wrapper object, so the two can never disagree.
|
|
447
|
-
isUnavailableResult: (result) => result.committed === false,
|
|
448
|
-
onFallback: (attempt, nextModel) => {
|
|
449
|
-
const info = {
|
|
450
|
-
from: attempt.model,
|
|
451
|
-
to: nextModel,
|
|
452
|
-
reason: attempt.reason ?? "upstream unavailable"
|
|
453
|
-
};
|
|
454
|
-
options.log?.("[chat-routes] model upstream unavailable; falling over", { ...info });
|
|
455
|
-
options.onFallback?.(info);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
474
|
+
const outcome = await settled;
|
|
458
475
|
serving = outcome.model;
|
|
459
476
|
trail = outcome.attempts;
|
|
460
477
|
fellBack = outcome.usedFallback;
|
|
@@ -494,6 +511,33 @@ function streamWithModelFailover(options) {
|
|
|
494
511
|
usedFallback: () => fellBack
|
|
495
512
|
};
|
|
496
513
|
}
|
|
514
|
+
var PROGRESS_CLOSED = /* @__PURE__ */ Symbol("progress-closed");
|
|
515
|
+
function createProgressQueue() {
|
|
516
|
+
const items = [];
|
|
517
|
+
const waiters = [];
|
|
518
|
+
let closed = false;
|
|
519
|
+
const deliver = (value) => {
|
|
520
|
+
const waiter = waiters.shift();
|
|
521
|
+
if (waiter) waiter(value);
|
|
522
|
+
else items.push(value);
|
|
523
|
+
};
|
|
524
|
+
return {
|
|
525
|
+
push(event) {
|
|
526
|
+
if (closed) return;
|
|
527
|
+
deliver(event);
|
|
528
|
+
},
|
|
529
|
+
close() {
|
|
530
|
+
if (closed) return;
|
|
531
|
+
closed = true;
|
|
532
|
+
deliver(PROGRESS_CLOSED);
|
|
533
|
+
},
|
|
534
|
+
pull() {
|
|
535
|
+
if (items.length > 0) return Promise.resolve(items.shift());
|
|
536
|
+
if (closed) return Promise.resolve(PROGRESS_CLOSED);
|
|
537
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
497
541
|
|
|
498
542
|
// src/chat-routes/sandbox-turn-usage.ts
|
|
499
543
|
function addStepFinishUsage(part, usage) {
|
|
@@ -656,6 +700,7 @@ function createSandboxChatProducer(options) {
|
|
|
656
700
|
...options.firstResponseTimeoutMs !== void 0 ? { firstResponseTimeoutMs: options.firstResponseTimeoutMs } : {},
|
|
657
701
|
...options.emptyTurnRetries !== void 0 ? { emptyTurnRetries: options.emptyTurnRetries } : {},
|
|
658
702
|
...options.onEmptyTurnRetry ? { onEmptyTurnRetry: options.onEmptyTurnRetry } : {},
|
|
703
|
+
...options.liveLifecycleEvents !== void 0 ? { liveLifecycleEvents: options.liveLifecycleEvents } : {},
|
|
659
704
|
onFallback: (info) => {
|
|
660
705
|
modelNoticeCount += 1;
|
|
661
706
|
pendingModelNotices.push({
|
|
@@ -2804,6 +2849,7 @@ export {
|
|
|
2804
2849
|
immutableAttachmentPath,
|
|
2805
2850
|
isCommittingSandboxEvent,
|
|
2806
2851
|
isDraftContentEvent,
|
|
2852
|
+
isLiveLifecycleEvent,
|
|
2807
2853
|
mediaTypeForMentionPath,
|
|
2808
2854
|
mentionKindForPath,
|
|
2809
2855
|
normalizeChatPromptForSandbox,
|