@tangle-network/agent-app 0.60.99 → 0.60.101
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.d.ts +1 -0
- package/dist/chat-routes/index.js +100 -3
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/router-producer.d.ts +17 -0
- package/dist/chunk-3FH4GZ27.js +459 -0
- package/dist/chunk-3FH4GZ27.js.map +1 -0
- package/dist/{chunk-N2UQIEWN.js → chunk-MWJK4HLU.js} +50 -2
- package/dist/chunk-MWJK4HLU.js.map +1 -0
- package/dist/runtime/index.js +9 -303
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/loop.d.ts +10 -0
- package/dist/runtime/openai-stream.d.ts +4 -0
- package/dist/runtime/router-turn.d.ts +30 -1
- package/dist/sandbox/escalation-speculator.d.ts +66 -0
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +9 -1
- package/dist/sandbox/warm-lease.d.ts +5 -2
- package/package.json +1 -1
- package/dist/chunk-N2UQIEWN.js.map +0 -1
- package/dist/chunk-RN2N75EI.js +0 -119
- package/dist/chunk-RN2N75EI.js.map +0 -1
|
@@ -14,6 +14,7 @@ export * from './turn-progress';
|
|
|
14
14
|
export * from './gateway-adapter';
|
|
15
15
|
export * from './stale-turn-lock';
|
|
16
16
|
export * from './sandbox-producer';
|
|
17
|
+
export * from './router-producer';
|
|
17
18
|
export * from './protected-runtime-producer';
|
|
18
19
|
export * from './model-failover-stream';
|
|
19
20
|
export * from './draft-persistence';
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
flattenHistory,
|
|
43
43
|
readSandboxBinaryBytes,
|
|
44
44
|
statSandboxFileSize
|
|
45
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-MWJK4HLU.js";
|
|
46
46
|
import "../chunk-4LBCTFBP.js";
|
|
47
47
|
import "../chunk-WVESWAJJ.js";
|
|
48
48
|
import "../chunk-LWSJK546.js";
|
|
@@ -54,9 +54,11 @@ import "../chunk-BMZTYGKE.js";
|
|
|
54
54
|
import "../chunk-UGWQLQDS.js";
|
|
55
55
|
import "../chunk-TMOYOMSW.js";
|
|
56
56
|
import {
|
|
57
|
-
ProtectedModelSettlementError
|
|
58
|
-
|
|
57
|
+
ProtectedModelSettlementError,
|
|
58
|
+
runRouterTurn
|
|
59
|
+
} from "../chunk-3FH4GZ27.js";
|
|
59
60
|
import "../chunk-D6UJEOZQ.js";
|
|
61
|
+
import "../chunk-7YA4QNTU.js";
|
|
60
62
|
import {
|
|
61
63
|
assistantRowIdForTurn,
|
|
62
64
|
createAssistantDraftWriter,
|
|
@@ -1147,6 +1149,100 @@ ${diagnostic.userMessage}` : diagnostic.userMessage;
|
|
|
1147
1149
|
};
|
|
1148
1150
|
}
|
|
1149
1151
|
|
|
1152
|
+
// src/chat-routes/router-producer.ts
|
|
1153
|
+
function createRouterTurnProducer(options) {
|
|
1154
|
+
const queue = [];
|
|
1155
|
+
let wake = null;
|
|
1156
|
+
let done = false;
|
|
1157
|
+
let outcome = null;
|
|
1158
|
+
const parts = [];
|
|
1159
|
+
const toolParts = /* @__PURE__ */ new Map();
|
|
1160
|
+
let textPart = null;
|
|
1161
|
+
let textSegment = 0;
|
|
1162
|
+
const push = (event) => {
|
|
1163
|
+
queue.push(event);
|
|
1164
|
+
wake?.();
|
|
1165
|
+
};
|
|
1166
|
+
const run = runRouterTurn({
|
|
1167
|
+
...options,
|
|
1168
|
+
onEvent: (event) => {
|
|
1169
|
+
if (event.type === "text") {
|
|
1170
|
+
if (event.segment !== textSegment || !textPart) {
|
|
1171
|
+
textSegment = event.segment;
|
|
1172
|
+
textPart = { type: "text", text: "" };
|
|
1173
|
+
parts.push(textPart);
|
|
1174
|
+
}
|
|
1175
|
+
textPart.text += event.delta;
|
|
1176
|
+
push({ type: "text", text: event.delta });
|
|
1177
|
+
} else if (event.type === "tool") {
|
|
1178
|
+
if (event.status === "running") {
|
|
1179
|
+
const part = {
|
|
1180
|
+
type: "tool",
|
|
1181
|
+
id: event.callId,
|
|
1182
|
+
callID: event.callId,
|
|
1183
|
+
tool: event.toolName,
|
|
1184
|
+
state: { status: "running", input: event.input, time: { start: event.startedAt } }
|
|
1185
|
+
};
|
|
1186
|
+
toolParts.set(event.callId, part);
|
|
1187
|
+
parts.push(part);
|
|
1188
|
+
push({ type: "tool_call", call: { toolCallId: event.callId, toolName: event.toolName, args: event.input } });
|
|
1189
|
+
} else {
|
|
1190
|
+
const part = toolParts.get(event.callId);
|
|
1191
|
+
const state = event.status === "completed" ? { status: "completed", output: event.output, time: { start: event.startedAt, end: event.endedAt } } : { status: "error", error: event.error.message, time: { start: event.startedAt, end: event.endedAt } };
|
|
1192
|
+
if (part) part.state = { ...part.state, ...state };
|
|
1193
|
+
push({
|
|
1194
|
+
type: "tool_result",
|
|
1195
|
+
toolCallId: event.callId,
|
|
1196
|
+
toolName: event.toolName,
|
|
1197
|
+
outcome: event.status === "completed" ? { ok: true, result: event.output } : { ok: false, message: event.error.message }
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
} else if (event.type === "usage") {
|
|
1201
|
+
push({ type: "usage", usage: { promptTokens: event.promptTokens, completionTokens: event.completionTokens } });
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}).then((result) => {
|
|
1205
|
+
outcome = result;
|
|
1206
|
+
options.onOutcome?.(result);
|
|
1207
|
+
if (result.failure) {
|
|
1208
|
+
push({ type: "error", data: { message: result.failure.message, code: result.failure.code } });
|
|
1209
|
+
}
|
|
1210
|
+
}).finally(() => {
|
|
1211
|
+
done = true;
|
|
1212
|
+
wake?.();
|
|
1213
|
+
});
|
|
1214
|
+
async function* stream() {
|
|
1215
|
+
for (; ; ) {
|
|
1216
|
+
while (queue.length) yield queue.shift();
|
|
1217
|
+
if (done) break;
|
|
1218
|
+
await new Promise((resolve) => {
|
|
1219
|
+
wake = resolve;
|
|
1220
|
+
});
|
|
1221
|
+
wake = null;
|
|
1222
|
+
}
|
|
1223
|
+
await run;
|
|
1224
|
+
}
|
|
1225
|
+
const usage = () => ({
|
|
1226
|
+
inputTokens: outcome?.usage.promptTokens ?? 0,
|
|
1227
|
+
outputTokens: outcome?.usage.completionTokens ?? 0
|
|
1228
|
+
});
|
|
1229
|
+
return {
|
|
1230
|
+
stream: stream(),
|
|
1231
|
+
finalText: () => outcome?.text ?? "",
|
|
1232
|
+
assistantParts: () => parts.map((part) => ({ ...part })),
|
|
1233
|
+
draftParts: () => parts.map((part) => ({ ...part })),
|
|
1234
|
+
usage,
|
|
1235
|
+
get model() {
|
|
1236
|
+
return outcome?.servedModel ?? options.model;
|
|
1237
|
+
},
|
|
1238
|
+
modelAttribution: () => ({
|
|
1239
|
+
requestedModel: options.model,
|
|
1240
|
+
...outcome?.servedModel ? { servedModel: outcome.servedModel } : {},
|
|
1241
|
+
echoReceived: Boolean(outcome?.servedModel)
|
|
1242
|
+
})
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1150
1246
|
// src/chat-routes/protected-runtime-producer.ts
|
|
1151
1247
|
import { createExecutor, streamAgentTurn } from "@tangle-network/agent-runtime/kernel";
|
|
1152
1248
|
import {
|
|
@@ -3447,6 +3543,7 @@ export {
|
|
|
3447
3543
|
createChatTurnRoutes,
|
|
3448
3544
|
createD1PlanFollowUpGate,
|
|
3449
3545
|
createProtectedRuntimeChatProducer,
|
|
3546
|
+
createRouterTurnProducer,
|
|
3450
3547
|
createSandboxChatProducer,
|
|
3451
3548
|
createSandboxFileIndexRoute,
|
|
3452
3549
|
createUploadRoute,
|