@tangle-network/agent-app 0.60.221 → 0.60.223
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 +3 -2
- package/dist/assistant/index.js.map +1 -1
- package/dist/chat-react/index.js +2 -1
- package/dist/chat-routes/hybrid-producer.d.ts +93 -0
- package/dist/chat-routes/index.d.ts +1 -0
- package/dist/chat-routes/index.js +116 -3
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/router-producer.d.ts +3 -1
- package/dist/{chunk-A5DGO2XT.js → chunk-2JY3SQD2.js} +2 -2
- package/dist/{chunk-KNTRS7OZ.js → chunk-BQILMP73.js} +70 -115
- package/dist/chunk-BQILMP73.js.map +1 -0
- package/dist/{chunk-2XUIWCRW.js → chunk-DA5XLDZR.js} +7 -2
- package/dist/chunk-DA5XLDZR.js.map +1 -0
- package/dist/{chunk-DMXEPYB5.js → chunk-HDY72UBR.js} +12 -7
- package/dist/chunk-HDY72UBR.js.map +1 -0
- package/dist/chunk-OXUBZ5SE.js +54 -0
- package/dist/chunk-OXUBZ5SE.js.map +1 -0
- package/dist/{chunk-N7WTF5P2.js → chunk-XWJDF34U.js} +10 -2
- package/dist/chunk-XWJDF34U.js.map +1 -0
- package/dist/{chunk-C7WAGXQN.js → chunk-YS2RYZQG.js} +9 -8
- package/dist/{chunk-C7WAGXQN.js.map → chunk-YS2RYZQG.js.map} +1 -1
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/router-turn.d.ts +16 -4
- package/dist/runtime/router-turn.js +1 -1
- package/dist/sandbox/escalation-speculator.d.ts +15 -27
- package/dist/sandbox/index.js +1 -3
- package/dist/sandbox/sandbox-run-tool.d.ts +4 -3
- package/dist/signoff/cli.js +1 -1
- package/dist/signoff/index.js +1 -1
- package/dist/web-react/chat-composer.d.ts +2 -1
- package/dist/web-react/index.js +10 -4
- package/dist/web-react/workspace-prewarm.d.ts +7 -0
- package/dist/workspace-react/index.d.ts +9 -1
- package/dist/workspace-react/index.js +8 -2
- package/dist/workspace-react/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2XUIWCRW.js.map +0 -1
- package/dist/chunk-DMXEPYB5.js.map +0 -1
- package/dist/chunk-KNTRS7OZ.js.map +0 -1
- package/dist/chunk-N7WTF5P2.js.map +0 -1
- /package/dist/{chunk-A5DGO2XT.js.map → chunk-2JY3SQD2.js.map} +0 -0
package/dist/chat-react/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComposerModeControls,
|
|
3
3
|
EntryComposer
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-DA5XLDZR.js";
|
|
5
5
|
import "../chunk-L7MB2LLM.js";
|
|
6
|
+
import "../chunk-OXUBZ5SE.js";
|
|
6
7
|
import "../chunk-SJWIZT7B.js";
|
|
7
8
|
import "../chunk-5IS3GCMR.js";
|
|
8
9
|
import "../chunk-HEPEGY6Q.js";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createHybridTurnProducer`: the default chat turn. The model answers first
|
|
3
|
+
* through the Tangle Router with the app's tools in process, and work that
|
|
4
|
+
* needs a computer escalates to the workspace box through one `sandbox_run`
|
|
5
|
+
* call whose answer comes back to the model.
|
|
6
|
+
*
|
|
7
|
+
* WHY THIS IS THE DEFAULT. Measured on production (2026-10-19/20): the
|
|
8
|
+
* Hospitality Router lane gave first text at 3.6 s with 0 of 39 failures; its
|
|
9
|
+
* sandbox lane 31.0 s with 2 of 8. Legal's sandbox lane gave first text at
|
|
10
|
+
* p50 137 s because the box agent writes nothing until its last tool call. The
|
|
11
|
+
* box only wins after about 8 tool calls through the API path (3 to 6 when it
|
|
12
|
+
* is warm), and those turns still reach it here, through `sandbox_run`.
|
|
13
|
+
*
|
|
14
|
+
* THE BOX. The producer starts it at most once per turn and every caller
|
|
15
|
+
* shares that start: the speculator, the `sandbox_run` call, and a start that
|
|
16
|
+
* admission already began (`box.started`, from {@link startHybridBox} in
|
|
17
|
+
* `afterAuthorize`). A failed start is forgotten, so the tool's own call
|
|
18
|
+
* retries it. Across isolates the product's `acquire` keeps its existing
|
|
19
|
+
* single flight (`runForegroundSandboxSingleFlight` over the D1 claim, or the
|
|
20
|
+
* warm lease).
|
|
21
|
+
*
|
|
22
|
+
* THE SPECULATOR is always on: words that ask for execution, a code fence or a
|
|
23
|
+
* process-shaped attachment start the box before the model call, and the model
|
|
24
|
+
* naming `sandbox_run` starts it while the call's arguments still stream.
|
|
25
|
+
*
|
|
26
|
+
* FIRST WORDS. Unless the product passes its own `guidance`, the prompt tells
|
|
27
|
+
* the model to say in one sentence what it is about to do before its first
|
|
28
|
+
* tool call, so a turn that writes a deliverable or escalates to the box shows
|
|
29
|
+
* text at the model's first token, not after its last tool call.
|
|
30
|
+
*
|
|
31
|
+
* The trace passes through: model calls, tool calls, the box claim and the box
|
|
32
|
+
* run are recorded under the turn's `trace` when the route gives one.
|
|
33
|
+
*/
|
|
34
|
+
import type { SandboxInstance } from '@tangle-network/sandbox';
|
|
35
|
+
import type { RouterTurnTool } from '../runtime/router-turn';
|
|
36
|
+
import { type EscalationHint, type EscalationInput } from '../sandbox/escalation-speculator';
|
|
37
|
+
import { type SandboxRunToolOptions } from '../sandbox/sandbox-run-tool';
|
|
38
|
+
import type { PersistedChatMessageForTurn } from '../stream/index';
|
|
39
|
+
import { type RouterTurnProducerOptions } from './router-producer';
|
|
40
|
+
import type { ChatTurnRouteProducer } from './turn-routes';
|
|
41
|
+
import type { ChatTurnPartInput, ChatTurnRequestPayload } from './wire';
|
|
42
|
+
/** What the default prompt adds so the Router lane answers first and escalates out loud. */
|
|
43
|
+
export declare const HYBRID_TURN_GUIDANCE: string;
|
|
44
|
+
export interface HybridTurnBox {
|
|
45
|
+
/** Start or adopt the workspace box. The product provisions, binds and bills it, and keeps its own single flight
|
|
46
|
+
* across isolates. A throw reaches the model as `sandbox_unavailable` (or the `SandboxRunError` it throws). */
|
|
47
|
+
acquire(signal: AbortSignal): Promise<SandboxInstance>;
|
|
48
|
+
/** A start admission already began ({@link startHybridBox}); the producer takes it as the turn's start. */
|
|
49
|
+
started?: Promise<SandboxInstance>;
|
|
50
|
+
/** Runs the task on the box and returns its answer: `sandboxPromptRunner(shell, …)` or the product's runner. */
|
|
51
|
+
runTask: SandboxRunToolOptions['runTask'];
|
|
52
|
+
/** Wall-clock cap for one `sandbox_run` call, box start included. Default 4 minutes. */
|
|
53
|
+
timeoutMs?: number;
|
|
54
|
+
warm?: SandboxRunToolOptions['warm'];
|
|
55
|
+
onFailure?: SandboxRunToolOptions['onFailure'];
|
|
56
|
+
/** The tool's name and description. Default `sandbox_run` and its shared description. */
|
|
57
|
+
name?: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface HybridTurnProducerOptions extends RouterTurnProducerOptions {
|
|
61
|
+
/** The app's in-process tools. `sandbox_run` is added after them. */
|
|
62
|
+
tools?: RouterTurnTool[];
|
|
63
|
+
box: HybridTurnBox;
|
|
64
|
+
/** The text the speculator reads. Default `userMessage`; pass what the member typed when `userMessage` carries
|
|
65
|
+
* injected context that would trip the execution words. */
|
|
66
|
+
speculateOn?: string;
|
|
67
|
+
/** The turn's attachments, for the speculator. */
|
|
68
|
+
attachments?: EscalationInput['attachments'];
|
|
69
|
+
onSpeculate?(hint: EscalationHint): void;
|
|
70
|
+
/** Appended to `systemPrompt`. Default {@link HYBRID_TURN_GUIDANCE}; `false` when the prompt already says it. */
|
|
71
|
+
guidance?: string | false;
|
|
72
|
+
/** Runs once when the turn's stream ends, however it ends (revoke a per-turn key, close a key scope). Its
|
|
73
|
+
* failure is logged, never thrown to the route. */
|
|
74
|
+
onSettled?(): Promise<void> | void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Start the box at admission when the request asks for execution, so its resume overlaps the turn lock and the
|
|
78
|
+
* profile pin instead of following them. Call it in `afterAuthorize` with the turn's body and hand the promise to
|
|
79
|
+
* the producer as `box.started`. Returns undefined, and starts nothing, for a turn that does not look like it needs
|
|
80
|
+
* the box.
|
|
81
|
+
*/
|
|
82
|
+
export declare function startHybridBox(body: Pick<ChatTurnRequestPayload, 'content' | 'parts'>, acquire: () => Promise<SandboxInstance>): Promise<SandboxInstance> | undefined;
|
|
83
|
+
/** The turn's prompt as the text the model reads: text parts joined; file parts are not text. */
|
|
84
|
+
export declare function turnPromptText(prompt: string | readonly ChatTurnPartInput[]): string;
|
|
85
|
+
/** Whether the turn carries files. Files live in the box, so a turn with them runs on the sandbox lane. */
|
|
86
|
+
export declare function turnCarriesFiles(prompt: string | readonly ChatTurnPartInput[]): boolean;
|
|
87
|
+
/** The conversation so far as the plain text history a Router turn replays: the last `limit` user and assistant
|
|
88
|
+
* messages that have text. Tool parts are not replayed. */
|
|
89
|
+
export declare function routerTurnHistory(priorMessages: ReadonlyArray<Pick<PersistedChatMessageForTurn, 'role' | 'content'>>, limit?: number): Array<{
|
|
90
|
+
role: 'user' | 'assistant';
|
|
91
|
+
content: string;
|
|
92
|
+
}>;
|
|
93
|
+
export declare function createHybridTurnProducer(options: HybridTurnProducerOptions): ChatTurnRouteProducer;
|
|
@@ -15,6 +15,7 @@ export * from './gateway-adapter';
|
|
|
15
15
|
export * from './stale-turn-lock';
|
|
16
16
|
export * from './sandbox-producer';
|
|
17
17
|
export * from './router-producer';
|
|
18
|
+
export * from './hybrid-producer';
|
|
18
19
|
export * from './protected-runtime-producer';
|
|
19
20
|
export * from './model-failover-stream';
|
|
20
21
|
export * from './draft-persistence';
|
|
@@ -37,10 +37,13 @@ import {
|
|
|
37
37
|
reconcileStaleTurnLock
|
|
38
38
|
} from "../chunk-CCVWR33L.js";
|
|
39
39
|
import {
|
|
40
|
+
createEscalationSpeculator,
|
|
41
|
+
createSandboxRunTool,
|
|
42
|
+
escalationHints,
|
|
40
43
|
flattenHistory,
|
|
41
44
|
readSandboxBinaryBytes,
|
|
42
45
|
statSandboxFileSize
|
|
43
|
-
} from "../chunk-
|
|
46
|
+
} from "../chunk-YS2RYZQG.js";
|
|
44
47
|
import "../chunk-4LBCTFBP.js";
|
|
45
48
|
import {
|
|
46
49
|
ModelFailoverExhaustedError,
|
|
@@ -62,10 +65,10 @@ import "../chunk-UGWQLQDS.js";
|
|
|
62
65
|
import "../chunk-E65YV7VV.js";
|
|
63
66
|
import {
|
|
64
67
|
runProtectedRouterTurn
|
|
65
|
-
} from "../chunk-
|
|
68
|
+
} from "../chunk-2JY3SQD2.js";
|
|
66
69
|
import {
|
|
67
70
|
runRouterTurn
|
|
68
|
-
} from "../chunk-
|
|
71
|
+
} from "../chunk-HDY72UBR.js";
|
|
69
72
|
import "../chunk-J63KUZBE.js";
|
|
70
73
|
import "../chunk-D6UJEOZQ.js";
|
|
71
74
|
import "../chunk-AMUXRAUO.js";
|
|
@@ -1297,6 +1300,12 @@ function createRouterTurnProducer(options) {
|
|
|
1297
1300
|
}
|
|
1298
1301
|
push({ type: "tool.event", data: { toolCallId: event.callId, toolName: event.toolName, kind: event.kind, data: event.data, at: event.at } });
|
|
1299
1302
|
}
|
|
1303
|
+
if (options.onEvent) {
|
|
1304
|
+
try {
|
|
1305
|
+
options.onEvent(event);
|
|
1306
|
+
} catch {
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1300
1309
|
}
|
|
1301
1310
|
}).then((result) => {
|
|
1302
1311
|
outcome = result;
|
|
@@ -1342,6 +1351,104 @@ function createRouterTurnProducer(options) {
|
|
|
1342
1351
|
};
|
|
1343
1352
|
}
|
|
1344
1353
|
|
|
1354
|
+
// src/chat-routes/hybrid-producer.ts
|
|
1355
|
+
var HYBRID_TURN_GUIDANCE = "Start your reply with text: before your first tool call, write one short sentence telling the member what you are about to do, so they never wait in silence. Use sandbox_run only for work that needs code execution or files on the workspace computer; describe the whole task in it and report what it returns.";
|
|
1356
|
+
var DEFAULT_SANDBOX_RUN_TIMEOUT_MS = 4 * 6e4;
|
|
1357
|
+
function startHybridBox(body, acquire) {
|
|
1358
|
+
const attachments = (body.parts ?? []).map((part) => ({
|
|
1359
|
+
...part.mediaType ? { mediaType: part.mediaType } : {},
|
|
1360
|
+
...part.filename ? { name: part.filename } : {}
|
|
1361
|
+
}));
|
|
1362
|
+
if (escalationHints({ text: body.content ?? "", attachments }).length === 0) return void 0;
|
|
1363
|
+
const started = acquire();
|
|
1364
|
+
started.catch(() => void 0);
|
|
1365
|
+
return started;
|
|
1366
|
+
}
|
|
1367
|
+
function turnPromptText(prompt) {
|
|
1368
|
+
return typeof prompt === "string" ? prompt : prompt.map((part) => part.type === "text" ? part.text : "").join("\n");
|
|
1369
|
+
}
|
|
1370
|
+
function turnCarriesFiles(prompt) {
|
|
1371
|
+
return typeof prompt !== "string" && prompt.some((part) => part.type !== "text");
|
|
1372
|
+
}
|
|
1373
|
+
function routerTurnHistory(priorMessages, limit = 40) {
|
|
1374
|
+
return priorMessages.filter((message) => (message.role === "user" || message.role === "assistant") && Boolean(message.content?.trim())).slice(-limit).map(({ role, content }) => ({ role, content }));
|
|
1375
|
+
}
|
|
1376
|
+
function createHybridTurnProducer(options) {
|
|
1377
|
+
const { box, tools = [], speculateOn, attachments, onSpeculate, guidance, onSettled, signal, ...router } = options;
|
|
1378
|
+
const abort = new AbortController();
|
|
1379
|
+
const stop = signal ? AbortSignal.any([abort.signal, signal]) : abort.signal;
|
|
1380
|
+
const timeoutMs = box.timeoutMs ?? DEFAULT_SANDBOX_RUN_TIMEOUT_MS;
|
|
1381
|
+
let start = box.started?.catch((error) => {
|
|
1382
|
+
start = void 0;
|
|
1383
|
+
throw error;
|
|
1384
|
+
});
|
|
1385
|
+
start?.catch(() => void 0);
|
|
1386
|
+
const acquire = () => start ??= box.acquire(stop).catch((error) => {
|
|
1387
|
+
start = void 0;
|
|
1388
|
+
throw error;
|
|
1389
|
+
});
|
|
1390
|
+
const sandboxRun = createSandboxRunTool({
|
|
1391
|
+
box: () => acquire(),
|
|
1392
|
+
runTask: box.runTask,
|
|
1393
|
+
timeoutMs,
|
|
1394
|
+
signal: stop,
|
|
1395
|
+
...box.warm ? { warm: box.warm } : {},
|
|
1396
|
+
...box.onFailure ? { onFailure: box.onFailure } : {},
|
|
1397
|
+
...box.name ? { name: box.name } : {},
|
|
1398
|
+
...box.description ? { description: box.description } : {}
|
|
1399
|
+
});
|
|
1400
|
+
const speculator = createEscalationSpeculator({
|
|
1401
|
+
warm: acquire,
|
|
1402
|
+
escalationTools: [sandboxRun.name],
|
|
1403
|
+
...onSpeculate ? { onSpeculate } : {}
|
|
1404
|
+
});
|
|
1405
|
+
speculator.onInput({ text: speculateOn ?? router.userMessage, ...attachments ? { attachments } : {} });
|
|
1406
|
+
const extra = guidance === false ? "" : guidance ?? HYBRID_TURN_GUIDANCE;
|
|
1407
|
+
const producer = createRouterTurnProducer({
|
|
1408
|
+
...router,
|
|
1409
|
+
systemPrompt: extra ? `${router.systemPrompt}
|
|
1410
|
+
|
|
1411
|
+
${extra}` : router.systemPrompt,
|
|
1412
|
+
tools: [...tools, sandboxRun],
|
|
1413
|
+
// A turn that calls the box must outlive the call it waits on.
|
|
1414
|
+
budgetMs: router.budgetMs ?? timeoutMs + 6e4,
|
|
1415
|
+
signal: stop,
|
|
1416
|
+
onEvent: (event) => {
|
|
1417
|
+
speculator.onEvent(event);
|
|
1418
|
+
router.onEvent?.(event);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
let settled = false;
|
|
1422
|
+
const settle = async () => {
|
|
1423
|
+
if (settled) return;
|
|
1424
|
+
settled = true;
|
|
1425
|
+
try {
|
|
1426
|
+
await onSettled?.();
|
|
1427
|
+
} catch (error) {
|
|
1428
|
+
console.error(JSON.stringify({
|
|
1429
|
+
event: "hybrid_turn_settle_failed",
|
|
1430
|
+
error: error instanceof Error ? error.message.slice(0, 300) : String(error).slice(0, 300)
|
|
1431
|
+
}));
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
return {
|
|
1435
|
+
...producer,
|
|
1436
|
+
stream: (async function* () {
|
|
1437
|
+
let finished = false;
|
|
1438
|
+
try {
|
|
1439
|
+
for await (const event of producer.stream) yield event;
|
|
1440
|
+
finished = true;
|
|
1441
|
+
} finally {
|
|
1442
|
+
if (!finished) abort.abort(new Error("The chat route stopped reading this turn"));
|
|
1443
|
+
await settle();
|
|
1444
|
+
}
|
|
1445
|
+
})(),
|
|
1446
|
+
get model() {
|
|
1447
|
+
return producer.model;
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1345
1452
|
// src/chat-routes/protected-runtime-producer.ts
|
|
1346
1453
|
import { profileMaterializationAxes } from "@tangle-network/agent-interface";
|
|
1347
1454
|
var PROTECTED_TURN_AXES = /* @__PURE__ */ new Set([
|
|
@@ -3769,6 +3876,7 @@ export {
|
|
|
3769
3876
|
DISPATCH_MAX_PARTS,
|
|
3770
3877
|
DISPATCH_REQUEST_MAX_BYTES,
|
|
3771
3878
|
DISPATCH_STRUCTURAL_RESERVE_BYTES,
|
|
3879
|
+
HYBRID_TURN_GUIDANCE,
|
|
3772
3880
|
INLINE_PARTS_MAX_BYTES,
|
|
3773
3881
|
INTENT_LINE_HISTORY_MESSAGES,
|
|
3774
3882
|
INTENT_LINE_MAX_CHARS,
|
|
@@ -3821,6 +3929,7 @@ export {
|
|
|
3821
3929
|
createAttachmentUploadRoute,
|
|
3822
3930
|
createChatTurnRoutes,
|
|
3823
3931
|
createD1PlanFollowUpGate,
|
|
3932
|
+
createHybridTurnProducer,
|
|
3824
3933
|
createProtectedRuntimeChatProducer,
|
|
3825
3934
|
createRouterTurnProducer,
|
|
3826
3935
|
createSandboxChatProducer,
|
|
@@ -3855,6 +3964,7 @@ export {
|
|
|
3855
3964
|
resolveChatAttachments,
|
|
3856
3965
|
resolveEmptyTurnRetries,
|
|
3857
3966
|
resolvePlanFollowUpRequest,
|
|
3967
|
+
routerTurnHistory,
|
|
3858
3968
|
rowIdOf,
|
|
3859
3969
|
runDetachedTurn,
|
|
3860
3970
|
sanitizeAttachmentFileName,
|
|
@@ -3863,11 +3973,14 @@ export {
|
|
|
3863
3973
|
sniffBinary,
|
|
3864
3974
|
sniffMimeFromName,
|
|
3865
3975
|
sniffedMimeImpliedByName,
|
|
3976
|
+
startHybridBox,
|
|
3866
3977
|
storeSupportsDraftPersistence,
|
|
3867
3978
|
streamChatRouteAsSandboxEvents,
|
|
3868
3979
|
streamPlanFollowUpEvents,
|
|
3869
3980
|
streamWithModelFailover,
|
|
3870
3981
|
summarizeFailoverReason,
|
|
3982
|
+
turnCarriesFiles,
|
|
3983
|
+
turnPromptText,
|
|
3871
3984
|
turnResponseEventFor,
|
|
3872
3985
|
unwrapSessionEventPayload,
|
|
3873
3986
|
validateSandboxMentionPath,
|