eve 0.46.0 → 0.46.1
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/CHANGELOG.md +10 -0
- package/dist/src/chunks/{use-eve-agent-DI2j5XK8.js → use-eve-agent-CacMaX4P.js} +91 -43
- package/dist/src/chunks/{use-eve-agent-BH7Z6SDu.js → use-eve-agent-kmlFdOBB.js} +91 -43
- package/dist/src/cli/commands/info.d.ts +2 -0
- package/dist/src/cli/commands/info.js +2 -2
- package/dist/src/cli/dev/tui/prompt-commands.d.ts +2 -0
- package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
- package/dist/src/cli/dev/tui/runner.d.ts +3 -0
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/client/message-reducer-primitives.d.ts +8 -0
- package/dist/src/client/message-reducer-primitives.js +1 -0
- package/dist/src/client/message-reducer-types.d.ts +2 -0
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/index.d.ts +2 -1
- package/dist/src/compiled/@linqapp/chat-sdk-adapter/index.js +3 -3
- package/dist/src/compiler/extension-compatibility.d.ts +18 -18
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/execution/tools/connection-search.js +1 -1
- package/dist/src/harness/emission.d.ts +1 -8
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/ordered-stream-emitter.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/packages/eve-catalog/src/index.js +1 -1
- package/dist/src/protocol/message.d.ts +29 -2
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/public/definitions/connections/tool-call.d.ts +2 -0
- package/dist/src/public/definitions/hook.d.ts +1 -0
- package/dist/src/runtime/connections/mcp-client.d.ts +1 -1
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/openapi-client.d.ts +1 -1
- package/dist/src/runtime/connections/openapi-client.js +1 -1
- package/dist/src/runtime/connections/provided-arguments.d.ts +1 -0
- package/dist/src/runtime/connections/provided-arguments.js +1 -1
- package/dist/src/setup/integrations/registry.js +1 -1
- package/dist/src/setup/integrations/shopify/setup.d.ts +20 -0
- package/dist/src/setup/integrations/shopify/setup.js +1 -0
- package/dist/src/setup/integrations/shopify/templates.d.ts +1 -0
- package/dist/src/setup/integrations/shopify/templates.js +88 -0
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/connection-types.d.ts +3 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/concepts/sessions-runs-and-streaming.md +5 -2
- package/docs/connections/mcp.mdx +1 -1
- package/docs/connections/openapi.mdx +1 -1
- package/docs/guides/client/streaming.mdx +18 -15
- package/docs/guides/dev-tui.md +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# eve
|
|
2
2
|
|
|
3
|
+
## 0.46.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 16c8b63: Expose a replay-stable `callId` to MCP and OpenAPI `providedArguments` callbacks so connection tools can derive per-call idempotency keys.
|
|
8
|
+
- e2d9162: Update the Linq channel adapter to preserve supported text decorations, including bold, italic, strikethrough, and underline, in outbound messages.
|
|
9
|
+
- fbc3080: Add Shopify registry setup for searching products and building UCP carts and checkouts. Setup now generates an anonymous UCP profile that the connection advertises in production.
|
|
10
|
+
- 2af4a4c: Tool inputs now stream through the durable event protocol as `action.input.appended` before the matching validated `actions.requested` event. Each event stores only its raw delta and UTF-16 offset, while the default message reducer exposes cumulative raw input on `dynamic-tool.inputText` in the `input-streaming` state. This advances the stream protocol to version 24; when assistant text precedes a tool call, `message.completed` now arrives before that call's streamed input events.
|
|
11
|
+
- 122f565: Add a local dev TUI `/info` command that shows the same application, artifact, diagnostic, and messaging details as `eve info`. The human-readable report now begins directly with its application details instead of repeating an `eve Info` heading.
|
|
12
|
+
|
|
3
13
|
## 0.46.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -2215,6 +2215,62 @@ function stringifyUnknown(value) {
|
|
|
2215
2215
|
}
|
|
2216
2216
|
}
|
|
2217
2217
|
|
|
2218
|
+
//#endregion
|
|
2219
|
+
//#region src/client/message-reducer-primitives.ts
|
|
2220
|
+
function projectReceivedParts(parts, message) {
|
|
2221
|
+
return parts?.map((part) => part.type === "text" ? {
|
|
2222
|
+
state: "done",
|
|
2223
|
+
text: part.text,
|
|
2224
|
+
type: "text"
|
|
2225
|
+
} : {
|
|
2226
|
+
filename: part.filename,
|
|
2227
|
+
mediaType: part.mediaType,
|
|
2228
|
+
size: part.size,
|
|
2229
|
+
type: "file",
|
|
2230
|
+
url: part.url
|
|
2231
|
+
}) ?? [{
|
|
2232
|
+
state: "done",
|
|
2233
|
+
text: message,
|
|
2234
|
+
type: "text"
|
|
2235
|
+
}];
|
|
2236
|
+
}
|
|
2237
|
+
function partKey(part) {
|
|
2238
|
+
switch (part.type) {
|
|
2239
|
+
case "text": return `text:${part.stepIndex ?? 0}`;
|
|
2240
|
+
case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
|
|
2241
|
+
case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
|
|
2242
|
+
case "step-start": return "step-start";
|
|
2243
|
+
case "authorization": return `authorization:${part.turnId}:${part.stepIndex}:${part.name}`;
|
|
2244
|
+
case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
function upsertMessage(data, next) {
|
|
2248
|
+
const index = data.messages.findIndex((message) => message.id === next.id);
|
|
2249
|
+
if (index === -1) return { messages: [...data.messages, next] };
|
|
2250
|
+
return { messages: [
|
|
2251
|
+
...data.messages.slice(0, index),
|
|
2252
|
+
next,
|
|
2253
|
+
...data.messages.slice(index + 1)
|
|
2254
|
+
] };
|
|
2255
|
+
}
|
|
2256
|
+
function removeStreamingToolPartsForTurn(data, turnId) {
|
|
2257
|
+
const index = data.messages.findIndex((message) => message.role === "assistant" && message.metadata?.turnId === turnId);
|
|
2258
|
+
const message = data.messages[index];
|
|
2259
|
+
if (message === void 0) return data;
|
|
2260
|
+
return upsertMessage(data, {
|
|
2261
|
+
...message,
|
|
2262
|
+
parts: message.parts.filter((part) => part.type !== "dynamic-tool" || part.state !== "input-streaming")
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
function optimisticUserMessageId(submissionId) {
|
|
2266
|
+
return `optimistic:${submissionId}:user`;
|
|
2267
|
+
}
|
|
2268
|
+
function appendToolInputDelta(inputText, offset, delta) {
|
|
2269
|
+
if (offset === 0) return delta;
|
|
2270
|
+
if (inputText?.length !== offset) return void 0;
|
|
2271
|
+
return inputText + delta;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2218
2274
|
//#endregion
|
|
2219
2275
|
//#region src/client/message-reducer.ts
|
|
2220
2276
|
function defaultMessageReducer() {
|
|
@@ -2285,6 +2341,27 @@ function reduceMessageData(data, event) {
|
|
|
2285
2341
|
text: event.data.reasoning,
|
|
2286
2342
|
type: "reasoning"
|
|
2287
2343
|
}));
|
|
2344
|
+
case "action.input.appended": {
|
|
2345
|
+
const existing = findToolPart(data, event.data.callId);
|
|
2346
|
+
if (existing !== void 0 && existing.state !== "input-streaming") return data;
|
|
2347
|
+
const inputText = appendToolInputDelta(existing?.state === "input-streaming" ? existing.inputText : void 0, event.data.inputTextOffset, event.data.inputTextDelta);
|
|
2348
|
+
if (inputText === void 0) return data;
|
|
2349
|
+
const nextPart = {
|
|
2350
|
+
input: void 0,
|
|
2351
|
+
inputText,
|
|
2352
|
+
state: "input-streaming",
|
|
2353
|
+
stepIndex: event.data.stepIndex,
|
|
2354
|
+
toolCallId: event.data.callId,
|
|
2355
|
+
toolMetadata: existing?.toolMetadata ?? { eve: {
|
|
2356
|
+
kind: "unknown",
|
|
2357
|
+
name: event.data.toolName
|
|
2358
|
+
} },
|
|
2359
|
+
toolName: event.data.toolName,
|
|
2360
|
+
type: "dynamic-tool"
|
|
2361
|
+
};
|
|
2362
|
+
if (existing !== void 0) return updateToolPart(data, event.data.callId, nextPart);
|
|
2363
|
+
return updateAssistantMessage(data, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), nextPart));
|
|
2364
|
+
}
|
|
2288
2365
|
case "actions.requested": {
|
|
2289
2366
|
let next = data;
|
|
2290
2367
|
for (const action of event.data.actions) {
|
|
@@ -2428,23 +2505,33 @@ function reduceMessageData(data, event) {
|
|
|
2428
2505
|
});
|
|
2429
2506
|
});
|
|
2430
2507
|
case "result.completed": return updateAssistantMetadata(data, event.data.turnId, { result: event.data.result });
|
|
2431
|
-
case "turn.completed": return
|
|
2508
|
+
case "turn.completed": return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
2509
|
+
...message,
|
|
2510
|
+
metadata: {
|
|
2511
|
+
...message.metadata,
|
|
2512
|
+
status: "complete"
|
|
2513
|
+
},
|
|
2514
|
+
parts: removeStreamingToolParts(message.parts)
|
|
2515
|
+
}));
|
|
2432
2516
|
case "turn.cancelled": return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
2433
2517
|
...message,
|
|
2434
2518
|
metadata: {
|
|
2435
2519
|
...message.metadata,
|
|
2436
2520
|
status: "complete"
|
|
2437
2521
|
},
|
|
2438
|
-
parts: message.parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" ? {
|
|
2522
|
+
parts: removeStreamingToolParts(message.parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" ? {
|
|
2439
2523
|
...part,
|
|
2440
2524
|
state: "done"
|
|
2441
|
-
} : part)
|
|
2525
|
+
} : part))
|
|
2442
2526
|
}));
|
|
2443
|
-
case "turn.failed":
|
|
2527
|
+
case "turn.failed": return removeStreamingToolPartsForTurn(data, event.data.turnId);
|
|
2444
2528
|
case "session.failed": return data;
|
|
2445
2529
|
default: return data;
|
|
2446
2530
|
}
|
|
2447
2531
|
}
|
|
2532
|
+
function removeStreamingToolParts(parts) {
|
|
2533
|
+
return parts.filter((part) => part.type !== "dynamic-tool" || part.state !== "input-streaming");
|
|
2534
|
+
}
|
|
2448
2535
|
function respondToInputRequest(data, response) {
|
|
2449
2536
|
const existing = findToolPartByApprovalId(data, response.requestId);
|
|
2450
2537
|
if (!existing) return data;
|
|
@@ -2598,45 +2685,6 @@ function findLatestPendingAuthorizationPart(data, name) {
|
|
|
2598
2685
|
function findToolPartByApprovalId(data, approvalId) {
|
|
2599
2686
|
for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.approval?.id === approvalId) return part;
|
|
2600
2687
|
}
|
|
2601
|
-
function projectReceivedParts(parts, message) {
|
|
2602
|
-
return parts?.map((part) => part.type === "text" ? {
|
|
2603
|
-
state: "done",
|
|
2604
|
-
text: part.text,
|
|
2605
|
-
type: "text"
|
|
2606
|
-
} : {
|
|
2607
|
-
filename: part.filename,
|
|
2608
|
-
mediaType: part.mediaType,
|
|
2609
|
-
size: part.size,
|
|
2610
|
-
type: "file",
|
|
2611
|
-
url: part.url
|
|
2612
|
-
}) ?? [{
|
|
2613
|
-
state: "done",
|
|
2614
|
-
text: message,
|
|
2615
|
-
type: "text"
|
|
2616
|
-
}];
|
|
2617
|
-
}
|
|
2618
|
-
function partKey(part) {
|
|
2619
|
-
switch (part.type) {
|
|
2620
|
-
case "text": return `text:${part.stepIndex ?? 0}`;
|
|
2621
|
-
case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
|
|
2622
|
-
case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
|
|
2623
|
-
case "step-start": return "step-start";
|
|
2624
|
-
case "authorization": return `authorization:${part.turnId}:${part.stepIndex}:${part.name}`;
|
|
2625
|
-
case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
function upsertMessage(data, next) {
|
|
2629
|
-
const index = data.messages.findIndex((message) => message.id === next.id);
|
|
2630
|
-
if (index === -1) return { messages: [...data.messages, next] };
|
|
2631
|
-
return { messages: [
|
|
2632
|
-
...data.messages.slice(0, index),
|
|
2633
|
-
next,
|
|
2634
|
-
...data.messages.slice(index + 1)
|
|
2635
|
-
] };
|
|
2636
|
-
}
|
|
2637
|
-
function optimisticUserMessageId(submissionId) {
|
|
2638
|
-
return `optimistic:${submissionId}:user`;
|
|
2639
|
-
}
|
|
2640
2688
|
|
|
2641
2689
|
//#endregion
|
|
2642
2690
|
//#region src/vue/use-eve-agent.ts
|
|
@@ -2215,6 +2215,62 @@ function stringifyUnknown(value) {
|
|
|
2215
2215
|
}
|
|
2216
2216
|
}
|
|
2217
2217
|
|
|
2218
|
+
//#endregion
|
|
2219
|
+
//#region src/client/message-reducer-primitives.ts
|
|
2220
|
+
function projectReceivedParts(parts, message) {
|
|
2221
|
+
return parts?.map((part) => part.type === "text" ? {
|
|
2222
|
+
state: "done",
|
|
2223
|
+
text: part.text,
|
|
2224
|
+
type: "text"
|
|
2225
|
+
} : {
|
|
2226
|
+
filename: part.filename,
|
|
2227
|
+
mediaType: part.mediaType,
|
|
2228
|
+
size: part.size,
|
|
2229
|
+
type: "file",
|
|
2230
|
+
url: part.url
|
|
2231
|
+
}) ?? [{
|
|
2232
|
+
state: "done",
|
|
2233
|
+
text: message,
|
|
2234
|
+
type: "text"
|
|
2235
|
+
}];
|
|
2236
|
+
}
|
|
2237
|
+
function partKey(part) {
|
|
2238
|
+
switch (part.type) {
|
|
2239
|
+
case "text": return `text:${part.stepIndex ?? 0}`;
|
|
2240
|
+
case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
|
|
2241
|
+
case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
|
|
2242
|
+
case "step-start": return "step-start";
|
|
2243
|
+
case "authorization": return `authorization:${part.turnId}:${part.stepIndex}:${part.name}`;
|
|
2244
|
+
case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
function upsertMessage(data, next) {
|
|
2248
|
+
const index = data.messages.findIndex((message) => message.id === next.id);
|
|
2249
|
+
if (index === -1) return { messages: [...data.messages, next] };
|
|
2250
|
+
return { messages: [
|
|
2251
|
+
...data.messages.slice(0, index),
|
|
2252
|
+
next,
|
|
2253
|
+
...data.messages.slice(index + 1)
|
|
2254
|
+
] };
|
|
2255
|
+
}
|
|
2256
|
+
function removeStreamingToolPartsForTurn(data, turnId) {
|
|
2257
|
+
const index = data.messages.findIndex((message) => message.role === "assistant" && message.metadata?.turnId === turnId);
|
|
2258
|
+
const message = data.messages[index];
|
|
2259
|
+
if (message === void 0) return data;
|
|
2260
|
+
return upsertMessage(data, {
|
|
2261
|
+
...message,
|
|
2262
|
+
parts: message.parts.filter((part) => part.type !== "dynamic-tool" || part.state !== "input-streaming")
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
function optimisticUserMessageId(submissionId) {
|
|
2266
|
+
return `optimistic:${submissionId}:user`;
|
|
2267
|
+
}
|
|
2268
|
+
function appendToolInputDelta(inputText, offset, delta) {
|
|
2269
|
+
if (offset === 0) return delta;
|
|
2270
|
+
if (inputText?.length !== offset) return void 0;
|
|
2271
|
+
return inputText + delta;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2218
2274
|
//#endregion
|
|
2219
2275
|
//#region src/client/message-reducer.ts
|
|
2220
2276
|
function defaultMessageReducer() {
|
|
@@ -2285,6 +2341,27 @@ function reduceMessageData(data, event) {
|
|
|
2285
2341
|
text: event.data.reasoning,
|
|
2286
2342
|
type: "reasoning"
|
|
2287
2343
|
}));
|
|
2344
|
+
case "action.input.appended": {
|
|
2345
|
+
const existing = findToolPart(data, event.data.callId);
|
|
2346
|
+
if (existing !== void 0 && existing.state !== "input-streaming") return data;
|
|
2347
|
+
const inputText = appendToolInputDelta(existing?.state === "input-streaming" ? existing.inputText : void 0, event.data.inputTextOffset, event.data.inputTextDelta);
|
|
2348
|
+
if (inputText === void 0) return data;
|
|
2349
|
+
const nextPart = {
|
|
2350
|
+
input: void 0,
|
|
2351
|
+
inputText,
|
|
2352
|
+
state: "input-streaming",
|
|
2353
|
+
stepIndex: event.data.stepIndex,
|
|
2354
|
+
toolCallId: event.data.callId,
|
|
2355
|
+
toolMetadata: existing?.toolMetadata ?? { eve: {
|
|
2356
|
+
kind: "unknown",
|
|
2357
|
+
name: event.data.toolName
|
|
2358
|
+
} },
|
|
2359
|
+
toolName: event.data.toolName,
|
|
2360
|
+
type: "dynamic-tool"
|
|
2361
|
+
};
|
|
2362
|
+
if (existing !== void 0) return updateToolPart(data, event.data.callId, nextPart);
|
|
2363
|
+
return updateAssistantMessage(data, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), nextPart));
|
|
2364
|
+
}
|
|
2288
2365
|
case "actions.requested": {
|
|
2289
2366
|
let next = data;
|
|
2290
2367
|
for (const action of event.data.actions) {
|
|
@@ -2428,23 +2505,33 @@ function reduceMessageData(data, event) {
|
|
|
2428
2505
|
});
|
|
2429
2506
|
});
|
|
2430
2507
|
case "result.completed": return updateAssistantMetadata(data, event.data.turnId, { result: event.data.result });
|
|
2431
|
-
case "turn.completed": return
|
|
2508
|
+
case "turn.completed": return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
2509
|
+
...message,
|
|
2510
|
+
metadata: {
|
|
2511
|
+
...message.metadata,
|
|
2512
|
+
status: "complete"
|
|
2513
|
+
},
|
|
2514
|
+
parts: removeStreamingToolParts(message.parts)
|
|
2515
|
+
}));
|
|
2432
2516
|
case "turn.cancelled": return updateAssistantMessage(data, event.data.turnId, (message) => ({
|
|
2433
2517
|
...message,
|
|
2434
2518
|
metadata: {
|
|
2435
2519
|
...message.metadata,
|
|
2436
2520
|
status: "complete"
|
|
2437
2521
|
},
|
|
2438
|
-
parts: message.parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" ? {
|
|
2522
|
+
parts: removeStreamingToolParts(message.parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" ? {
|
|
2439
2523
|
...part,
|
|
2440
2524
|
state: "done"
|
|
2441
|
-
} : part)
|
|
2525
|
+
} : part))
|
|
2442
2526
|
}));
|
|
2443
|
-
case "turn.failed":
|
|
2527
|
+
case "turn.failed": return removeStreamingToolPartsForTurn(data, event.data.turnId);
|
|
2444
2528
|
case "session.failed": return data;
|
|
2445
2529
|
default: return data;
|
|
2446
2530
|
}
|
|
2447
2531
|
}
|
|
2532
|
+
function removeStreamingToolParts(parts) {
|
|
2533
|
+
return parts.filter((part) => part.type !== "dynamic-tool" || part.state !== "input-streaming");
|
|
2534
|
+
}
|
|
2448
2535
|
function respondToInputRequest(data, response) {
|
|
2449
2536
|
const existing = findToolPartByApprovalId(data, response.requestId);
|
|
2450
2537
|
if (!existing) return data;
|
|
@@ -2598,45 +2685,6 @@ function findLatestPendingAuthorizationPart(data, name) {
|
|
|
2598
2685
|
function findToolPartByApprovalId(data, approvalId) {
|
|
2599
2686
|
for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.approval?.id === approvalId) return part;
|
|
2600
2687
|
}
|
|
2601
|
-
function projectReceivedParts(parts, message) {
|
|
2602
|
-
return parts?.map((part) => part.type === "text" ? {
|
|
2603
|
-
state: "done",
|
|
2604
|
-
text: part.text,
|
|
2605
|
-
type: "text"
|
|
2606
|
-
} : {
|
|
2607
|
-
filename: part.filename,
|
|
2608
|
-
mediaType: part.mediaType,
|
|
2609
|
-
size: part.size,
|
|
2610
|
-
type: "file",
|
|
2611
|
-
url: part.url
|
|
2612
|
-
}) ?? [{
|
|
2613
|
-
state: "done",
|
|
2614
|
-
text: message,
|
|
2615
|
-
type: "text"
|
|
2616
|
-
}];
|
|
2617
|
-
}
|
|
2618
|
-
function partKey(part) {
|
|
2619
|
-
switch (part.type) {
|
|
2620
|
-
case "text": return `text:${part.stepIndex ?? 0}`;
|
|
2621
|
-
case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
|
|
2622
|
-
case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
|
|
2623
|
-
case "step-start": return "step-start";
|
|
2624
|
-
case "authorization": return `authorization:${part.turnId}:${part.stepIndex}:${part.name}`;
|
|
2625
|
-
case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
function upsertMessage(data, next) {
|
|
2629
|
-
const index = data.messages.findIndex((message) => message.id === next.id);
|
|
2630
|
-
if (index === -1) return { messages: [...data.messages, next] };
|
|
2631
|
-
return { messages: [
|
|
2632
|
-
...data.messages.slice(0, index),
|
|
2633
|
-
next,
|
|
2634
|
-
...data.messages.slice(index + 1)
|
|
2635
|
-
] };
|
|
2636
|
-
}
|
|
2637
|
-
function optimisticUserMessageId(submissionId) {
|
|
2638
|
-
return `optimistic:${submissionId}:user`;
|
|
2639
|
-
}
|
|
2640
2688
|
|
|
2641
2689
|
//#endregion
|
|
2642
2690
|
//#region src/svelte/use-eve-agent.ts
|
|
@@ -52,4 +52,6 @@ export declare function buildApplicationInfoJson(inspection: ApplicationInspecti
|
|
|
52
52
|
* Writes resolved application details and the active message-route contract.
|
|
53
53
|
*/
|
|
54
54
|
export declare function printApplicationInfo(logger: CliInfoLogger, appRoot: string, options?: PrintApplicationInfoOptions): Promise<void>;
|
|
55
|
+
/** Renders the human-readable `eve info` report for CLI and TUI surfaces. */
|
|
56
|
+
export declare function renderApplicationInfo(inspection: ApplicationInspection): string;
|
|
55
57
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createCliTheme,
|
|
2
|
-
`)
|
|
1
|
+
import{createCliTheme,renderCliSection}from"#cli/ui/output.js";import{inspectApplication}from"#services/inspect-application.js";function formatInstructions(e){return e.map(e=>`${e.logicalPath} (${e.role})`).join(`, `)}function buildApplicationInfoJson(e){let{application:t,compiledState:n,messaging:r}=e;return{appRoot:t.appRoot,agentRoot:n?.project.agentRoot??null,layout:n?.project.layout??null,status:n?.metadata.status??`unavailable`,diagnostics:n?{errors:n.metadata.discovery.summary.errors,warnings:n.metadata.discovery.summary.warnings}:null,model:n?.manifest.config.model?.id??null,instructions:n===null||n.manifest.instructions.length===0?null:formatInstructions(n.manifest.instructions),skills:(n?.manifest.skills??[]).map(e=>e.name),tools:(n?.manifest.tools??[]).map(e=>e.name),subagents:(n?.manifest.subagents??[]).map(e=>e.name),schedules:(n?.manifest.schedules??[]).map(e=>e.name),channels:(n?.manifest.channelRoutes.effective??[]).map(e=>({name:e.name,kind:e.adapterKind??null,method:e.method,urlPath:e.urlPath})),messaging:{create:r.createSessionRoutePath,messages:r.sessionMessagesRoutePattern,stream:r.streamRoutePattern},artifacts:n?{compiledManifest:n.paths.compiledManifestPath,discoveryManifest:n.paths.discoveryManifestPath,diagnostics:n.paths.diagnosticsPath,moduleMap:n.paths.moduleMapPath,metadata:n.paths.compileMetadataPath}:null}}function pluralize(e,t){return`${e} ${t}${e===1?``:`s`}`}function formatDiscoverySummary(e,t){return`${pluralize(e,`error`)}, ${pluralize(t,`warning`)}`}function resolveCompileTone(e){switch(e){case`ready`:return`success`;case`failed`:return`danger`;default:return`warning`}}async function printApplicationInfo(e,t,r={}){let i=await inspectApplication(t);if(r.json){e.log(JSON.stringify(buildApplicationInfoJson(i),null,2));return}e.log(renderApplicationInfo(i))}function renderApplicationInfo(n){let r=n.compiledState,i=n.application,a=createCliTheme(),o=[{label:`App Root`,value:i.appRoot}],s=[{label:`Workflow Build`,value:i.workflowBuildDir},{label:`Output`,value:i.outputDir}],c=[];return r===null?o.push({label:`Compile`,tone:`warning`,value:`unavailable`}):(o.push({label:`Agent Root`,value:r.project.agentRoot},{label:`Layout`,value:r.project.layout},{label:`Compile`,tone:resolveCompileTone(r.metadata.status),value:r.metadata.status},{label:`Diagnostics`,tone:r.metadata.discovery.summary.errors>0?`danger`:r.metadata.discovery.summary.warnings>0?`warning`:`success`,value:formatDiscoverySummary(r.metadata.discovery.summary.errors,r.metadata.discovery.summary.warnings)},{label:`Instructions`,value:r.manifest.instructions.length===0?`none`:formatInstructions(r.manifest.instructions)},{label:`Skills`,value:pluralize(r.manifest.skills.length,`skill`)},{label:`Tools`,value:pluralize(r.manifest.tools.length,`tool`)},{label:`Subagents`,value:pluralize(r.manifest.subagents.length,`subagent`)},{label:`Schedules`,value:pluralize(r.manifest.schedules.length,`schedule`)}),s.unshift({label:`Compiled Manifest`,value:r.paths.compiledManifestPath},{label:`Discovery Manifest`,value:r.paths.discoveryManifestPath},{label:`Diagnostics`,value:r.paths.diagnosticsPath},{label:`Module Map`,value:r.paths.moduleMapPath},{label:`Metadata`,value:r.paths.compileMetadataPath}),c.push(r.manifest.instructions.length===0?{label:`Instructions`,value:`No instructions prompt discovered.`}:{label:`Instructions`,value:formatInstructions(r.manifest.instructions)})),[renderCliSection(a,{rows:o,title:`Application`}),``,renderCliSection(a,{rows:s,title:`Artifacts`}),...r===null?[]:[``,renderCliSection(a,{rows:c,title:`Instructions`})],``,renderCliSection(a,{rows:[{label:`Workflow ID`,value:i.workflowId},{label:`Source Dir`,value:i.workflowSourceDir},{label:`Create`,tone:`info`,value:`POST ${n.messaging.createSessionRoutePath}`},{label:`Messages`,tone:`info`,value:`POST ${n.messaging.sessionMessagesRoutePattern}`},{label:`Stream`,tone:`info`,value:`GET ${n.messaging.streamRoutePattern}`}],title:`Messaging`})].join(`
|
|
2
|
+
`)}export{buildApplicationInfoJson,printApplicationInfo,renderApplicationInfo};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const PROMPT_COMMAND_DEFINITIONS=[{name:`help`,aliases:[],description:`Show available commands`,takesArgument:!1,build:()=>({type:`help`}),targets:[`local`,`remote`]},{name:`reset`,aliases:[],description:`Start a fresh session`,takesArgument:!1,build:()=>({type:`reset`}),targets:[`local`,`remote`]},{name:`cancel`,aliases:[],description:`Cancel the running turn`,takesArgument:!1,build:()=>({type:`cancel`}),targets:[`local`,`remote`]},{name:`clear`,aliases:[`new`],description:`Clear the current session context`,takesArgument:!1,build:()=>({type:`clear`}),targets:[`local`,`remote`]},{name:`compact`,aliases:[],description:`Compact the current session context`,takesArgument:!1,build:()=>({type:`compact`}),targets:[`local`,`remote`]},{name:`vc:install`,aliases:[],description:`Install the Vercel CLI`,takesArgument:!1,build:()=>({type:`extension`,name:`vc:install`,argument:``}),targets:[`local`,`remote`]},{name:`vc:login`,aliases:[],description:`Authenticate with Vercel`,takesArgument:!1,build:()=>({type:`extension`,name:`vc:login`,argument:``}),targets:[`local`,`remote`]},{name:`model`,aliases:[],description:`Configure the agent's model and provider`,argumentHint:`[provider/model]`,takesArgument:!0,build:e=>({type:`extension`,name:`model`,argument:e}),targets:[`local`]},{name:`loglevel`,aliases:[],description:`Show or hide captured stdout/stderr/sandbox logs`,argumentHint:`[all|stderr|sandbox|none]`,takesArgument:!0,build:e=>({type:`loglevel`,argument:e}),targets:[`local`,`remote`]},{name:`traces`,aliases:[],description:`Open the local trace viewer`,argumentHint:`[trace]`,takesArgument:!0,build:e=>({type:`traces`,argument:e}),targets:[`local`]},{name:`add`,aliases:[],description:`Add an integration from the registry`,takesArgument:!0,build:e=>({type:`extension`,name:`add`,argument:e}),targets:[`local`]},{name:`deploy`,aliases:[],description:`Deploy the agent to Vercel`,takesArgument:!1,build:()=>({type:`extension`,name:`deploy`,argument:``}),targets:[`local`]},{name:`exit`,aliases:[`quit`],description:`Quit the TUI`,takesArgument:!1,build:()=>({type:`exit`}),targets:[`local`,`remote`]}],PROMPT_COMMANDS=PROMPT_COMMAND_DEFINITIONS;function promptCommandsFor(t){return PROMPT_COMMAND_DEFINITIONS.filter(e=>e.targets.some(e=>e===t))}function isPromptCommandAvailableFor(t,n){return(PROMPT_COMMAND_DEFINITIONS.find(e=>e.name===t)?.targets)?.includes(n)??!1}function parsePromptCommand(e){let n=e.trim();if(!n.startsWith(`/`))return null;for(let e of PROMPT_COMMANDS)for(let t of[e.name,...e.aliases]){let r=`/${t}`;if(n===r)return e.build(``);if(e.takesArgument&&n.startsWith(`${r} `))return e.build(n.slice(r.length).trim())}return null}function isPromptControlCommand(e){return parsePromptCommand(e)!==null}function formatPromptCommandHelp(e=PROMPT_COMMANDS){let n=e.map(e=>{let t=e.argumentHint===void 0?``:` ${e.argumentHint}`,n=e.aliases.map(e=>` (/${e})`).join(``);return{invocation:`/${e.name}${t}${n}`,description:e.description}}),r=Math.max(...n.map(e=>e.invocation.length))+2;return n.map(e=>e.invocation.padEnd(r)+e.description).join(`
|
|
1
|
+
const PROMPT_COMMAND_DEFINITIONS=[{name:`help`,aliases:[],description:`Show available commands`,takesArgument:!1,build:()=>({type:`help`}),targets:[`local`,`remote`]},{name:`info`,aliases:[],description:`Show application and messaging information`,takesArgument:!1,build:()=>({type:`info`}),targets:[`local`]},{name:`reset`,aliases:[],description:`Start a fresh session`,takesArgument:!1,build:()=>({type:`reset`}),targets:[`local`,`remote`]},{name:`cancel`,aliases:[],description:`Cancel the running turn`,takesArgument:!1,build:()=>({type:`cancel`}),targets:[`local`,`remote`]},{name:`clear`,aliases:[`new`],description:`Clear the current session context`,takesArgument:!1,build:()=>({type:`clear`}),targets:[`local`,`remote`]},{name:`compact`,aliases:[],description:`Compact the current session context`,takesArgument:!1,build:()=>({type:`compact`}),targets:[`local`,`remote`]},{name:`vc:install`,aliases:[],description:`Install the Vercel CLI`,takesArgument:!1,build:()=>({type:`extension`,name:`vc:install`,argument:``}),targets:[`local`,`remote`]},{name:`vc:login`,aliases:[],description:`Authenticate with Vercel`,takesArgument:!1,build:()=>({type:`extension`,name:`vc:login`,argument:``}),targets:[`local`,`remote`]},{name:`model`,aliases:[],description:`Configure the agent's model and provider`,argumentHint:`[provider/model]`,takesArgument:!0,build:e=>({type:`extension`,name:`model`,argument:e}),targets:[`local`]},{name:`loglevel`,aliases:[],description:`Show or hide captured stdout/stderr/sandbox logs`,argumentHint:`[all|stderr|sandbox|none]`,takesArgument:!0,build:e=>({type:`loglevel`,argument:e}),targets:[`local`,`remote`]},{name:`traces`,aliases:[],description:`Open the local trace viewer`,argumentHint:`[trace]`,takesArgument:!0,build:e=>({type:`traces`,argument:e}),targets:[`local`]},{name:`add`,aliases:[],description:`Add an integration from the registry`,takesArgument:!0,build:e=>({type:`extension`,name:`add`,argument:e}),targets:[`local`]},{name:`deploy`,aliases:[],description:`Deploy the agent to Vercel`,takesArgument:!1,build:()=>({type:`extension`,name:`deploy`,argument:``}),targets:[`local`]},{name:`exit`,aliases:[`quit`],description:`Quit the TUI`,takesArgument:!1,build:()=>({type:`exit`}),targets:[`local`,`remote`]}],PROMPT_COMMANDS=PROMPT_COMMAND_DEFINITIONS;function promptCommandsFor(t){return PROMPT_COMMAND_DEFINITIONS.filter(e=>e.targets.some(e=>e===t))}function isPromptCommandAvailableFor(t,n){return(PROMPT_COMMAND_DEFINITIONS.find(e=>e.name===t)?.targets)?.includes(n)??!1}function parsePromptCommand(e){let n=e.trim();if(!n.startsWith(`/`))return null;for(let e of PROMPT_COMMANDS)for(let t of[e.name,...e.aliases]){let r=`/${t}`;if(n===r)return e.build(``);if(e.takesArgument&&n.startsWith(`${r} `))return e.build(n.slice(r.length).trim())}return null}function isPromptControlCommand(e){return parsePromptCommand(e)!==null}function formatPromptCommandHelp(e=PROMPT_COMMANDS){let n=e.map(e=>{let t=e.argumentHint===void 0?``:` ${e.argumentHint}`,n=e.aliases.map(e=>` (/${e})`).join(``);return{invocation:`/${e.name}${t}${n}`,description:e.description}}),r=Math.max(...n.map(e=>e.invocation.length))+2;return n.map(e=>e.invocation.padEnd(r)+e.description).join(`
|
|
2
2
|
`)}export{PROMPT_COMMANDS,formatPromptCommandHelp,isPromptCommandAvailableFor,isPromptControlCommand,parsePromptCommand,promptCommandsFor};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AgentInfoResult, type ConnectionAuthorizationOutcome, type InputRequest, Client, ClientSession } from "#client/index.js";
|
|
2
|
+
import { inspectApplication } from "#services/inspect-application.js";
|
|
2
3
|
import { type SubagentView } from "./subagent-pump.js";
|
|
3
4
|
export type { SubagentRun, SubagentStepUpdate, SubagentToolUpdate, SubagentView, } from "./subagent-pump.js";
|
|
4
5
|
import { type DevBootProgressReporter } from "#internal/dev-boot-progress.js";
|
|
@@ -369,6 +370,8 @@ export type EveTUIRunnerOptions = TuiDisplayOptions & {
|
|
|
369
370
|
bootDetections?: readonly BootDetection[];
|
|
370
371
|
/** Test seam for the status line's Vercel link probe; defaults to the real one. */
|
|
371
372
|
detectProjectIdentity?: typeof detectProjectIdentity;
|
|
373
|
+
/** Test seam for `/info`; defaults to the filesystem application inspector. */
|
|
374
|
+
inspectApplication?: typeof inspectApplication;
|
|
372
375
|
/** Test seam for the off-critical-path boot login probe; defaults to the real one. */
|
|
373
376
|
getVercelAuthStatus?: typeof getVercelAuthStatus;
|
|
374
377
|
/** Reports phases from this runner's initial local-dev connection. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PROMPT_COMMANDS,formatPromptCommandHelp,parsePromptCommand}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{failureKey,formatFailureDetail,formatFailureHint,formatFailureMessage,isInterruptedError,localFailureHint}from"./errors.js";import{parseLogDisplayMode}from"./log-display-mode.js";import{createMcpConnectionStatusTracker}from"./mcp-connection-status.js";import{createRemoteConnectionController}from"./remote-connection.js";import{SubagentPump}from"./subagent-pump.js";import{BOOT_DETECTIONS,CLI_MISSING_SETUP_ISSUE,LOGIN_SETUP_ISSUE,detectSetupIssues,formatSetupIssuesLine,normalizeLocalModelEndpoint,orderedSetupIssues}from"./setup-issues.js";import{TerminalRenderer}from"./terminal-renderer.js";import{createVercelStatusTracker}from"./vercel-status.js";import"#client/index.js";import{loadDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{createDevelopmentRuntimeArtifactRefresher}from"#services/dev-client.js";import{devBootPhase}from"#internal/dev-boot-progress.js";async function delayMs(e){await new Promise(t=>{setTimeout(t,e).unref?.()})}function authIssueForStatus(e){if(e===`logged-out`)return LOGIN_SETUP_ISSUE;if(e===`cli-missing`)return CLI_MISSING_SETUP_ISSUE}var EveTUIRunner=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S=!1;#C=new AbortController;#w=!1;#T=[];#E;#D;#O;#k=pickAgentHeaderTip();#A;#j=new Map;#M;#N;#P=new Map;#F=new Set;#I;#L;#R;constructor(t){this.#e=t.session,t.client!==void 0&&(this.#t=t.client),t.lifecycle!==void 0&&(this.#R=t.lifecycle),this.#n=createRenderer(t);let n={formatActionResultError};if(this.#t!==void 0&&(n.client=this.#t),this.#n.subagents!==void 0&&(n.view=this.#n.subagents),this.#N=new SubagentPump(n),this.#r=t.name??`eve`,this.#_=t.withExclusiveTerminal,this.#i=t.tools??`full`,this.#a=t.reasoning??`full`,this.#o=t.subagents??`full`,this.#s=t.connectionAuth??`full`,this.#c=t.assistantResponseStats??`tokensPerSecond`,this.#l=t.contextSize,this.#u=t.formatTransportError??toErrorMessage,t.initialInput!==void 0&&(this.#m=t.initialInput),t.appRoot!==void 0){this.#p=t.appRoot;let e={appRoot:t.appRoot,onChange:e=>this.#n.setVercelStatus?.(e)};t.detectProjectIdentity!==void 0&&(e.detectIdentity=t.detectProjectIdentity),this.#D=createVercelStatusTracker(e),t.probeMcpConnection!==void 0&&(this.#O=createMcpConnectionStatusTracker({onChange:()=>{},probe:t.probeMcpConnection}))}if(t.promptCommandHandler!==void 0&&(this.#h=t.promptCommandHandler),this.#g=t.availablePromptCommands??PROMPT_COMMANDS,t.remote!==void 0){if(this.#t===void 0)throw Error(`A remote TUI requires a configured development client.`);this.#v=createRemoteConnectionController({client:this.#t,credentials:t.remote.credentials,target:t.remote.target,onChange:e=>this.#n.setRemoteConnectionStatus?.(e),resolveOidcToken:t.remote.resolveOidcToken,resolveDeployment:t.remote.resolveDeployment})}this.#y=t.bootDetections??BOOT_DETECTIONS,this.#b=t.getVercelAuthStatus??getVercelAuthStatus,t.onBootProgress!==void 0&&(this.#x=t.onBootProgress),t.serverUrl!==void 0&&(this.#f=t.serverUrl),t.serverUrl!==void 0&&t.remote===void 0&&(this.#d=createDevelopmentRuntimeArtifactRefresher({serverUrl:t.serverUrl}))}async#z(){if(this.#f===void 0){this.#V(),await this.#$(void 0);return}let e;if(this.#v!==void 0){let t=await this.#v.check();t.state===`ready`&&(e=t.info)}else{let t=this.#t;if(t!==void 0)try{let n=await devBootPhase(`connecting to agent`,()=>probeAgentInfo({client:t}),this.#x);n.kind===`ready`&&(e=n.info)}catch{e=void 0}}this.#V();let t=this.#B(e);await this.#$(t)}#B(e){let t=this.#p===void 0?e:normalizeLocalModelEndpoint(e,process.env);this.#A=t;let n=this.#f;if(n===void 0)return t;let r={name:this.#r,serverUrl:n};return t!==void 0&&(r.info=t),this.#p!==void 0&&(r.tip=this.#k),this.#n.renderAgentHeader?.(r),t}#V(){let e=this.#x;this.#x=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#R?.signal.aborted===!0?onStop():this.#R?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#H()}finally{this.#R?.signal.removeEventListener(`abort`,onStop),this.#S=!0,this.#C.abort(),this.#N.abortAll(),this.#L?.(),this.#L=void 0,this.#n.shutdown?.(),this.#D?.dispose(),this.#O?.dispose(),this.#v?.dispose()}}async#H(){let e=this.#r,r,i,a=!1,o=!1,s=!1,l=this.#m;await this.#z(),this.#v?.current().connection.state===`auth-required`&&await this.#ce({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`}),this.#re(),this.#D?.refreshIdentity(),this.#O?.refresh();let u=this.#m===void 0?void 0:parsePromptCommand(this.#m);for(u?.type===`extension`&&u.name===`model`&&u.argument===``&&this.#p!==void 0&&this.#h!==void 0&&this.#n.setupFlow!==void 0&&(l=void 0,await this.#le(e));;){if(this.#R?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;if(!s){if(r==null){if(!this.#n.readPrompt){if(a)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let t={title:e};l!==void 0&&(t.initialDraft=l,l=void 0);try{r=await this.#q(t)}catch(e){if(isInterruptedError(e)){if(this.#M===void 0)return;s=!0,r=``}else throw e}if(r==null&&this.#M===void 0)return}let u=this.#M===void 0?parsePromptCommand(r):null;if(u?.type===`exit`){this.#R?.requestStop();return}if(u?.type===`cancel`){if(this.#e===void 0){this.#ie(`No active turn to cancel.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.cancel();if(this.#ie(e.status===`accepted`?`Turn cancellation requested.`:`No active turn to cancel.`),e.status===`no_active_turn`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ie(`Couldn't cancel the turn: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`reset`){if(!await this.#G()){i=void 0,s=!1,r=void 0;continue}i=void 0,s=!1,r=void 0;continue}if(u?.type===`compact`){if(this.#e===void 0){this.#ie(`No active session to compact.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.compact();if(this.#ie(e.status===`accepted`?`Compaction requested.`:`No active session to compact.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ie(`Couldn't compact the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`clear`){if(this.#e===void 0){this.#ie(`No active session to clear.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.clear();if(this.#ie(e.status===`accepted`?`Context clear requested.`:`No active session to clear.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ie(`Couldn't clear the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`help`){this.#ie(formatPromptCommandHelp(this.#g)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`loglevel`){this.#ie(this.#fe(u.argument)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`traces`){await this.#de(u.argument),i=void 0,s=!1,r=void 0;continue}if(u?.type===`extension`){try{await this.#ce(u,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}i=void 0,r=void 0,s=!1;continue}a=!0}let u=this.#M;this.#M=void 0;let d=u??(o?this.#Z():await(async()=>(this.#W(),await this.#Y({prompt:s?void 0:r,inputResponses:i})))()),f=this.#e?.state.sessionId;f!==void 0&&this.#n.setSessionId?.(f);let p=r,m=!1;try{for(;;){await this.#n.renderStream(d,{title:e,submittedPrompt:p,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let t=d.turnState?.pendingApprovals??[],n=d.turnState?.pendingQuestions??[];if(t.length>0||n.length>0){let a=[];if(t.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let n of t){let t=await this.#n.readToolApproval(n,{title:e});a.push({requestId:n.approvalId,optionId:t.approved?`approve`:`cancel`}),this.#j.delete(n.approvalId)}}if(n.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of n){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),a.push(i),this.#j.delete(t.requestId)}}if(a.length===0)break;s=!0,i=a,r=void 0,m=!0;break}if(this.#_e(d)){d=this.#Z(),p=void 0;continue}if(d.turnState&&d.turnState.boundaryEvent===void 0&&!d.turnState.aborted){let e=this.#e?.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(m)continue;o=!1,s=!1,i=void 0,r=void 0;let h=d.turnState?.boundaryEvent;this.#I!==this.#e&&(h===`session.waiting`||h===`session.completed`)&&(r=this.#n.takeQueuedPrompt?.()),this.#W(d.turnState?.aborted===!0)}}#U(){this.#N.abortAll(),this.#j.clear(),this.#P.clear(),this.#F.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#W(e=!1){let t=this.#I;t!==void 0&&(this.#I=void 0,this.#e===t&&(this.#U(),e?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary()))}async#G(){if(this.#e===void 0)return this.#U(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#U(),this.#n.reset?.(),!0}async#K(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,o=0,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#he()});let e=this.#A?.agent.model.endpoint,t=e?.kind===`chatgpt`&&(e.state===`signed-out`||e.state===`reauth-required`),r=Date.now();if(t&&r-o>=5e3){o=r;let e=await this.#me();e!==void 0&&this.#B(e)}}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let s=setInterval(()=>{startRefresh()},500);s.unref?.();try{return await t}finally{r=!0,clearInterval(s),await a}}async#q(e){let t=this.#K(e);if(this.#n.renderIdleStream===void 0||this.#e?.state.sessionId===void 0)return await t;let n=new AbortController,r=this.#J(n.signal,e).catch(e=>{n.signal.aborted||this.#n.renderNotice?.(`Stopped following session updates: ${toErrorMessage(e)}`)});try{return await t}finally{n.abort(),await r}}async#J(e,t){let n=this.#e;if(n===void 0)return;let r=n.stream({signal:e})[Symbol.asyncIterator]();try{for(;!e.aborted;){let i=!1,a={async*[Symbol.asyncIterator](){for(;!e.aborted;){let e=await r.next();if(e.done===!0||(i=!0,yield e.value,isCurrentTurnBoundaryEvent(e.value)))return}}},o=this.#Q(a,()=>{},n);if(await this.#n.renderIdleStream(o,{...t,continueSession:!0}),this.#_e(o),(o.turnState?.pendingApprovals.length??0)>0||(o.turnState?.pendingQuestions.length??0)>0){this.#M={events:(async function*(){})(),turnState:o.turnState},this.#n.suspendPromptForInput?.();return}if(!i)return}}finally{await r.return?.()}}async#Y(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r,i=this.#e;try{if(this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#he()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),this.#e===void 0){if(this.#t===void 0)throw Error(`Cannot create a session without an eve client.`);if(n.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let e=await this.#t.sessions.create({...n,message:n.message});this.#e=e.session,r=e.response}else r=n.inputResponses===void 0?await this.#e.send(n.message,{signal:n.signal,turnPolicy:`queue`}):await this.#e.respond(n.inputResponses,{signal:n.signal})}catch(e){if(isInterruptedError(e))throw e;return this.#v?.reportFailure(e),this.#I=i,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#Q(r,()=>t.abort(),this.#e)}async#X(e,t){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let n=0;n<8;n+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let n=e.turnId;try{if((await t?.cancel(n===void 0?void 0:{turnId:n}))?.status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#Z(){if(this.#e===void 0)throw Error(`Cannot stream a session before its first turn is accepted.`);let e=new AbortController,t=this.#e;return this.#Q(t.stream({signal:e.signal}),()=>e.abort(),t)}#Q(e,t,n){let r=createTurnState();return{abort:()=>{r.aborted=!0,this.#I=n,t()},cancel:()=>{this.#X(r,n)},events:eveEventsToTUIStream({events:e,pendingInputRequests:this.#j,turnState:r,onSubagentCalled:e=>this.#N.begin(e),onSubagentBackgrounded:e=>this.#N.background(e),onSubagentCompleted:e=>this.#N.settle(e),onTurnCancelled:e=>this.#N.settleCancelledTurn(e),onConnectionAuthRequired:e=>this.#ge(e),onConnectionAuthCompleted:e=>this.#ve(e),onTerminalFailure:()=>{this.#I=n},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:r}}async#$(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#T=await detectSetupIssues(t,this.#y),this.#n.renderSetupWarning!==void 0&&(this.#ee(),this.#te())}#ee(){let e=orderedSetupIssues(this.#T,this.#E);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#te(){let e=this.#p;if(e===void 0)return;let t;try{t=await this.#b(e,{signal:this.#C.signal})}catch{return}this.#S||this.#w||(this.#E=authIssueForStatus(t),this.#ee())}async#ne(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n={appRoot:t,env:process.env};e!==void 0&&(n.info=e);try{this.#T=await detectSetupIssues(n,this.#y);let e=await this.#b(t,{signal:this.#C.signal});this.#E=authIssueForStatus(e)}catch{return}this.#S||this.#ee()}#re(){this.#p===void 0||this.#n.renderSandboxLog===void 0||this.#L===void 0&&(this.#L=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#ie(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#ae(e,t){let n=this.#h;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r=this.#A?.agent.model.endpoint,i={renderer:this.#n,title:t.title,initialModelStep:t.initialModelStep,chatGptAccountLabel:r?.kind===`chatgpt`&&r.state===`ready`?r.accountLabel:void 0,remoteConnection:this.#v,withExclusiveTerminal:this.#_},a=this.#O?.current(),o=a!==void 0&&Object.keys(a).length>0?{...i,disabledConnectionReasons:a}:i;return t.keepSetupFlowOpen===!0?await n.handle(e,{...o,keepSetupFlowOpen:!0}):await n.handle(e,o)}#oe(e,t){if(t!==`startup`)return;let n=this.#v?.current().connection.state,r=n===`auth-failed`||n===`unavailable`?`failed`:void 0,i=e.argument.length===0?``:` ${e.argument}`;this.#n.renderCommandInvocation?.(`/${e.name}${i}`,r)}async#se(e){if(e?.kind===`model-access-changed`){this.#D?.applyEffect({kind:`refresh-identity`}),this.#w=!0,await this.#pe();return}e!==void 0&&(this.#D?.applyEffect(e),this.#w=!0,this.#ne(this.#A))}async#ce(e,t,n){let r=await this.#ae(e,{initialModelStep:n.initialModelStep,keepSetupFlowOpen:n.keepSetupFlowOpen,title:t});this.#oe(e,n.trigger),this.#ie(r?.message,r?.tone),await this.#se(r?.effect),this.#ue()}async#le(e){let t=this.#p;if(t===void 0)return;let authStatus=async()=>{try{return await this.#b(t,{signal:this.#C.signal})}catch{return}},n=await authStatus();if(n===`cli-missing`&&(await this.#ce({type:`extension`,name:`vc:install`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`)){this.#n.setupFlow?.end();return}if(n===`logged-out`&&(await this.#ce({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`||n===`logged-out`)){this.#n.setupFlow?.end();return}await this.#ce({type:`extension`,name:`model`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`}),await this.#ce({type:`extension`,name:`add`,argument:``},e,{trigger:`startup`})}#ue(){let e=this.#v?.current().connection;e?.state!==`ready`||e.info===this.#A||(this.#A=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#de(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ie(`/traces is only available in local dev sessions.`);return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e?.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}}#fe(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#pe(){let e=this.#p;if(e===void 0)return;loadDevelopmentEnvironmentFiles(e),await this.#d?.refreshAfterSourceChange({});let t=this.#B(await this.#me());this.#ne(t)}async#me(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}async#he(){let e=this.#A,t=await this.#me();t!==void 0&&this.#B(t),(!this.#n.renderAgentHeader||t===void 0)&&this.#n.renderNotice?.(formatAgentUpdateNotice(e,t))}#ge(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#P.set(e.data.name,t),this.#ye(t)}#_e(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#P.values())e.state!==`required`||e.webhookUrl===void 0||(e.state=`pending`,this.#F.add(e.name),this.#ye(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#F.size),this.#F.size>0}#ve(e){let t=this.#P.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#P.set(e.data.name,t),this.#F.delete(e.data.name),this.#ye(t),this.#n.setConnectionAuthPendingCount?.(this.#F.size)}#ye(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentBackgrounded:a,onSubagentCompleted:o,onTurnCancelled:s,onConnectionAuthRequired:c,onConnectionAuthCompleted:l,onTerminalFailure:u,failureHintOverride:d}=e,f=new Map,p=new Map,m=createEventDeduper(),h=0,g=new Set,_=new Set,v=new Set,y=!1,b=!1,x;for await(let e of t)if(m.admit(e)&&!(b&&isPostTurnVisibleEvent(e)))switch(e.type){case`session.started`:case`message.received`:break;case`turn.started`:r.turnId=e.data.turnId;break;case`step.started`:h+=1,yield{type:`step-start`};break;case`step.completed`:{let t=e;x=t.data.usage,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`step-finish`,usage:t.data.usage};break}case`message.appended`:{let t=e,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(f,n),i=t.data.messageSoFar;if(r.completed){if(h<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`message.completed`:{let t=textPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(f,t),r=e.data.message;if(n.completed){if(r===null||h<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=h,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let e=r.slice(n.text.length);e.length>0&&(yield{type:`assistant-delta`,id:i,delta:e}),n.text=r,n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i}}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let t=e,n=reasoningPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(p,n),i=t.data.reasoningSoFar;if(r.completed){if(h<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`reasoning-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`reasoning.completed`:{let t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(p,t),r=e.data.reasoning;if(n.completed){if(r.length===0||h<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=h;let e=partGenerationId(t,n.generation);yield{type:`reasoning-delta`,id:e,delta:r},yield{type:`reasoning-complete`,id:e};break}let i=partGenerationId(t,n.generation);if(n.text.length===0&&r.length>0)n.text=r,yield{type:`reasoning-delta`,id:i,delta:r};else if(r.length>0&&!r.startsWith(n.text))break;n.completed=!0,n.completedEpoch=h,yield{type:`reasoning-complete`,id:i};break}case`actions.requested`:{let t=e.data.actions.filter(e=>e.kind===`tool-call`);if(t.length===0)break;for(let e of t)g.has(e.callId)||(g.add(e.callId),yield{type:`tool-call`,toolCallId:e.callId,toolName:e.toolName,input:e.input});break}case`input.requested`:{let t=e.data.requests.filter(e=>e.action.kind===`tool-call`);if(t.length===0)break;for(let e of t){let t=e.action.callId;if(e.kind!==`session-limit`&&!g.has(t)&&(g.add(t),yield{type:`tool-call`,toolCallId:t,toolName:e.action.toolName,input:e.action.input}),!_.has(e.requestId)){if(_.add(e.requestId),n.set(e.requestId,e),e.kind!==`tool-approval`){upsertPendingQuestion(r,e);continue}upsertPendingApproval(r,e),yield{type:`tool-approval-request`,approvalId:e.requestId,toolCallId:t}}}break}case`action.result`:{let t=e;if(t.data.result.kind!==`tool-result`)break;let n=t.data.result.callId;if(!g.has(n))break;switch(t.data.status){case`completed`:yield{type:`tool-result`,toolCallId:n,output:t.data.result.output};break;case`failed`:yield{type:`tool-error`,toolCallId:n,errorText:formatActionResultError(t)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:n,reason:formatActionResultError(t)};break}break}case`step.failed`:case`turn.failed`:{let t=toFailureEvent(e,v,d);t&&(yield t);break}case`session.failed`:{r.sawSessionFailure=!0,u?.(e);let t=toFailureEvent(e,v,d);t&&(yield t),r.boundaryEvent=e.type,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x},y=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=e.type,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x},y=!0;return;case`turn.completed`:b=!0,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h);break;case`turn.cancelled`:s?.(e.data.turnId),yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(e);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:{let t=e;t.data.backgroundTask===void 0?o?.(t.data.callId):a?.(t.data.callId);break}case`authorization.required`:c?.(e);break;case`authorization.completed`:l?.(e);break;default:break}y||(yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let c={type:`error`,errorText:formatFailureMessage(e)},l=n?.(e)??formatFailureHint(e);l!==void 0&&(c.hint=l);let u=formatFailureDetail(e);return u!==void 0&&(c.detail=u),c}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand};
|
|
1
|
+
import{PROMPT_COMMANDS,formatPromptCommandHelp,parsePromptCommand}from"./prompt-commands.js";import{pickAgentHeaderTip}from"./agent-header.js";import{failureKey,formatFailureDetail,formatFailureHint,formatFailureMessage,isInterruptedError,localFailureHint}from"./errors.js";import{parseLogDisplayMode}from"./log-display-mode.js";import{createMcpConnectionStatusTracker}from"./mcp-connection-status.js";import{createRemoteConnectionController}from"./remote-connection.js";import{SubagentPump}from"./subagent-pump.js";import{BOOT_DETECTIONS,CLI_MISSING_SETUP_ISSUE,LOGIN_SETUP_ISSUE,detectSetupIssues,formatSetupIssuesLine,normalizeLocalModelEndpoint,orderedSetupIssues}from"./setup-issues.js";import{TerminalRenderer}from"./terminal-renderer.js";import{createVercelStatusTracker}from"./vercel-status.js";import"#client/index.js";import{loadDevelopmentEnvironmentFiles}from"#cli/dev/environment.js";import{inspectApplication}from"#services/inspect-application.js";import{toErrorMessage}from"#shared/errors.js";import{getVercelAuthStatus}from"#setup/vercel-project.js";import{probeAgentInfo}from"#services/dev-client/agent-info-probe.js";import{renderApplicationInfo}from"#cli/commands/info.js";import{subscribeDevelopmentSandboxPrewarmLogs}from"#execution/sandbox/development-prewarm.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{createDevelopmentRuntimeArtifactRefresher}from"#services/dev-client.js";import{devBootPhase}from"#internal/dev-boot-progress.js";async function delayMs(e){await new Promise(t=>{setTimeout(t,e).unref?.()})}function authIssueForStatus(e){if(e===`logged-out`)return LOGIN_SETUP_ISSUE;if(e===`cli-missing`)return CLI_MISSING_SETUP_ISSUE}var EveTUIRunner=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h;#g;#_;#v;#y;#b;#x;#S;#C=!1;#w=new AbortController;#T=!1;#E=[];#D;#O;#k;#A=pickAgentHeaderTip();#j;#M=new Map;#N;#P;#F=new Map;#I=new Set;#L;#R;#z;constructor(t){this.#e=t.session,t.client!==void 0&&(this.#t=t.client),t.lifecycle!==void 0&&(this.#z=t.lifecycle),this.#n=createRenderer(t);let n={formatActionResultError};if(this.#t!==void 0&&(n.client=this.#t),this.#n.subagents!==void 0&&(n.view=this.#n.subagents),this.#P=new SubagentPump(n),this.#r=t.name??`eve`,this.#_=t.withExclusiveTerminal,this.#i=t.tools??`full`,this.#a=t.reasoning??`full`,this.#o=t.subagents??`full`,this.#s=t.connectionAuth??`full`,this.#c=t.assistantResponseStats??`tokensPerSecond`,this.#l=t.contextSize,this.#u=t.formatTransportError??toErrorMessage,t.initialInput!==void 0&&(this.#m=t.initialInput),t.appRoot!==void 0){this.#p=t.appRoot;let e={appRoot:t.appRoot,onChange:e=>this.#n.setVercelStatus?.(e)};t.detectProjectIdentity!==void 0&&(e.detectIdentity=t.detectProjectIdentity),this.#O=createVercelStatusTracker(e),t.probeMcpConnection!==void 0&&(this.#k=createMcpConnectionStatusTracker({onChange:()=>{},probe:t.probeMcpConnection}))}if(t.promptCommandHandler!==void 0&&(this.#h=t.promptCommandHandler),this.#g=t.availablePromptCommands??PROMPT_COMMANDS,t.remote!==void 0){if(this.#t===void 0)throw Error(`A remote TUI requires a configured development client.`);this.#v=createRemoteConnectionController({client:this.#t,credentials:t.remote.credentials,target:t.remote.target,onChange:e=>this.#n.setRemoteConnectionStatus?.(e),resolveOidcToken:t.remote.resolveOidcToken,resolveDeployment:t.remote.resolveDeployment})}this.#y=t.bootDetections??BOOT_DETECTIONS,this.#b=t.getVercelAuthStatus??getVercelAuthStatus,this.#x=t.inspectApplication??inspectApplication,t.onBootProgress!==void 0&&(this.#S=t.onBootProgress),t.serverUrl!==void 0&&(this.#f=t.serverUrl),t.serverUrl!==void 0&&t.remote===void 0&&(this.#d=createDevelopmentRuntimeArtifactRefresher({serverUrl:t.serverUrl}))}async#B(){if(this.#f===void 0){this.#H(),await this.#ee(void 0);return}let e;if(this.#v!==void 0){let t=await this.#v.check();t.state===`ready`&&(e=t.info)}else{let t=this.#t;if(t!==void 0)try{let n=await devBootPhase(`connecting to agent`,()=>probeAgentInfo({client:t}),this.#S);n.kind===`ready`&&(e=n.info)}catch{e=void 0}}this.#H();let t=this.#V(e);await this.#ee(t)}#V(e){let t=this.#p===void 0?e:normalizeLocalModelEndpoint(e,process.env);this.#j=t;let n=this.#f;if(n===void 0)return t;let r={name:this.#r,serverUrl:n};return t!==void 0&&(r.info=t),this.#p!==void 0&&(r.tip=this.#A),this.#n.renderAgentHeader?.(r),t}#H(){let e=this.#S;this.#S=void 0,e?.({type:`before-first-paint`})}async run(){let onStop=()=>this.#n.requestInterrupt?.();this.#z?.signal.aborted===!0?onStop():this.#z?.signal.addEventListener(`abort`,onStop,{once:!0});try{await this.#U()}finally{this.#z?.signal.removeEventListener(`abort`,onStop),this.#C=!0,this.#w.abort(),this.#P.abortAll(),this.#R?.(),this.#R=void 0,this.#n.shutdown?.(),this.#O?.dispose(),this.#k?.dispose(),this.#v?.dispose()}}async#U(){let e=this.#r,r,i,a=!1,o=!1,s=!1,l=this.#m;await this.#B(),this.#v?.current().connection.state===`auth-required`&&await this.#le({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`}),this.#ie(),this.#O?.refreshIdentity(),this.#k?.refresh();let u=this.#m===void 0?void 0:parsePromptCommand(this.#m);for(u?.type===`extension`&&u.name===`model`&&u.argument===``&&this.#p!==void 0&&this.#h!==void 0&&this.#n.setupFlow!==void 0&&(l=void 0,await this.#ue(e));;){if(this.#z?.signal.aborted===!0||this.#n.exitRequested?.()===!0)return;if(!s){if(r==null){if(!this.#n.readPrompt){if(a)return;throw Error(`No prompt was provided and the renderer does not support prompt input.`)}let t={title:e};l!==void 0&&(t.initialDraft=l,l=void 0);try{r=await this.#J(t)}catch(e){if(isInterruptedError(e)){if(this.#N===void 0)return;s=!0,r=``}else throw e}if(r==null&&this.#N===void 0)return}let u=this.#N===void 0?parsePromptCommand(r):null;if(u?.type===`exit`){this.#z?.requestStop();return}if(u?.type===`cancel`){if(this.#e===void 0){this.#ae(`No active turn to cancel.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.cancel();if(this.#ae(e.status===`accepted`?`Turn cancellation requested.`:`No active turn to cancel.`),e.status===`no_active_turn`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ae(`Couldn't cancel the turn: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`reset`){if(!await this.#K()){i=void 0,s=!1,r=void 0;continue}i=void 0,s=!1,r=void 0;continue}if(u?.type===`compact`){if(this.#e===void 0){this.#ae(`No active session to compact.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.compact();if(this.#ae(e.status===`accepted`?`Compaction requested.`:`No active session to compact.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ae(`Couldn't compact the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`clear`){if(this.#e===void 0){this.#ae(`No active session to clear.`),i=void 0,o=!1,s=!1,r=void 0;continue}try{let e=await this.#e.clear();if(this.#ae(e.status===`accepted`?`Context clear requested.`:`No active session to clear.`),e.status===`no_active_session`){i=void 0,o=!1,s=!1,r=void 0;continue}}catch(e){this.#ae(`Couldn't clear the session: ${toErrorMessage(e)}`),i=void 0,o=!1,s=!1,r=void 0;continue}i=void 0,o=!0,s=!1,r=void 0}if(u?.type===`help`){this.#ae(formatPromptCommandHelp(this.#g)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`info`){await this.#pe(),i=void 0,s=!1,r=void 0;continue}if(u?.type===`loglevel`){this.#ae(this.#me(u.argument)),i=void 0,s=!1,r=void 0;continue}if(u?.type===`traces`){await this.#fe(u.argument),i=void 0,s=!1,r=void 0;continue}if(u?.type===`extension`){try{await this.#le(u,e,{trigger:`command`})}catch(e){if(isInterruptedError(e))return;throw e}i=void 0,r=void 0,s=!1;continue}a=!0}let u=this.#N;this.#N=void 0;let d=u??(o?this.#Q():await(async()=>(this.#G(),await this.#X({prompt:s?void 0:r,inputResponses:i})))()),f=this.#e?.state.sessionId;f!==void 0&&this.#n.setSessionId?.(f);let p=r,m=!1;try{for(;;){await this.#n.renderStream(d,{title:e,submittedPrompt:p,continueSession:!!this.#n.readPrompt,tools:this.#i,reasoning:this.#a,subagents:this.#o,connectionAuth:this.#s,assistantResponseStats:this.#c,contextSize:this.#l});let t=d.turnState?.pendingApprovals??[],n=d.turnState?.pendingQuestions??[];if(t.length>0||n.length>0){let a=[];if(t.length>0){if(!this.#n.readToolApproval)throw Error(`Tool approval was requested, but the renderer does not support tool approval input.`);for(let n of t){let t=await this.#n.readToolApproval(n,{title:e});a.push({requestId:n.approvalId,optionId:t.approved?`approve`:`cancel`}),this.#M.delete(n.approvalId)}}if(n.length>0){if(!this.#n.readInputQuestion)throw Error(`An interactive question was requested, but the renderer does not support input questions.`);for(let t of n){let n=toAgentTUIInputQuestion(t),r=await this.#n.readInputQuestion(n,{title:e});if(r===void 0)continue;let i={requestId:t.requestId};r.optionId!==void 0&&(i.optionId=r.optionId),r.text!==void 0&&(i.text=r.text),a.push(i),this.#M.delete(t.requestId)}}if(a.length===0)break;s=!0,i=a,r=void 0,m=!0;break}if(this.#ye(d)){d=this.#Q(),p=void 0;continue}if(d.turnState&&d.turnState.boundaryEvent===void 0&&!d.turnState.aborted){let e=this.#e?.state.sessionId;this.#n.renderNotice?.(e?`Lost the event stream — the turn may still be running on the server (session ${e}). Your next message resumes this session; use /cancel to stop the turn.`:`Lost the connection to the running turn.`)}break}}catch(e){if(isInterruptedError(e))return;throw e}if(m)continue;o=!1,s=!1,i=void 0,r=void 0;let h=d.turnState?.boundaryEvent;this.#L!==this.#e&&(h===`session.waiting`||h===`session.completed`)&&(r=this.#n.takeQueuedPrompt?.()),this.#G(d.turnState?.aborted===!0)}}#W(){this.#P.abortAll(),this.#M.clear(),this.#F.clear(),this.#I.clear(),this.#n.setConnectionAuthPendingCount?.(0),this.#e=void 0,this.#d?.clear()}#G(e=!1){let t=this.#L;t!==void 0&&(this.#L=void 0,this.#e===t&&(this.#W(),e?this.#n.renderNotice?.(`Stopped following the turn and started a new session. Earlier context was cleared; the interrupted turn may still be running on the server.`):this.#n.renderSessionBoundary===void 0?this.#n.renderNotice?.(`Session ended — started a new session. Earlier context was cleared.`):this.#n.renderSessionBoundary()))}async#K(){if(this.#e===void 0)return this.#W(),this.#n.reset?.(),!0;try{await this.#e.reset()}catch(e){return this.#n.renderNotice?.(`Couldn't reset the session: ${toErrorMessage(e)}`),!1}return this.#W(),this.#n.reset?.(),!0}async#q(e){if(!this.#n.readPrompt)return;let t=this.#n.readPrompt(e),n=this.#d;if(n===void 0)return await t;let r=!1,i=!1,a,o=0,refresh=async()=>{if(!(r||i)){i=!0;try{await n.refreshIdle({onRuntimeArtifactsChanged:()=>this.#_e()});let e=this.#j?.agent.model.endpoint,t=e?.kind===`chatgpt`&&(e.state===`signed-out`||e.state===`reauth-required`),r=Date.now();if(t&&r-o>=5e3){o=r;let e=await this.#ge();e!==void 0&&this.#V(e)}}finally{i=!1}}},startRefresh=()=>{if(r||i)return;let e=refresh().finally(()=>{a===e&&(a=void 0)});a=e};startRefresh();let s=setInterval(()=>{startRefresh()},500);s.unref?.();try{return await t}finally{r=!0,clearInterval(s),await a}}async#J(e){let t=this.#q(e);if(this.#n.renderIdleStream===void 0||this.#e?.state.sessionId===void 0)return await t;let n=new AbortController,r=this.#Y(n.signal,e).catch(e=>{n.signal.aborted||this.#n.renderNotice?.(`Stopped following session updates: ${toErrorMessage(e)}`)});try{return await t}finally{n.abort(),await r}}async#Y(e,t){let n=this.#e;if(n===void 0)return;let r=n.stream({signal:e})[Symbol.asyncIterator]();try{for(;!e.aborted;){let i=!1,a={async*[Symbol.asyncIterator](){for(;!e.aborted;){let e=await r.next();if(e.done===!0||(i=!0,yield e.value,isCurrentTurnBoundaryEvent(e.value)))return}}},o=this.#$(a,()=>{},n);if(await this.#n.renderIdleStream(o,{...t,continueSession:!0}),this.#ye(o),(o.turnState?.pendingApprovals.length??0)>0||(o.turnState?.pendingQuestions.length??0)>0){this.#N={events:(async function*(){})(),turnState:o.turnState},this.#n.suspendPromptForInput?.();return}if(!i)return}}finally{await r.return?.()}}async#X(e){let t=new AbortController,n={signal:t.signal};e.prompt!==void 0&&(n.message=e.prompt),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses);let r,i=this.#e;try{if(this.#d!==void 0&&await this.#d.refresh({inputResponses:n.inputResponses,message:n.message,onRuntimeArtifactsChanged:()=>this.#_e()}),n.message!==void 0&&(n.inputResponses?.length??0)===0&&this.#n.flushDelayedDevBuildErrors?.(),this.#e===void 0){if(this.#t===void 0)throw Error(`Cannot create a session without an eve client.`);if(n.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let e=await this.#t.sessions.create({...n,message:n.message});this.#e=e.session,r=e.response}else r=n.inputResponses===void 0?await this.#e.send(n.message,{signal:n.signal,turnPolicy:`queue`}):await this.#e.respond(n.inputResponses,{signal:n.signal})}catch(e){if(isInterruptedError(e))throw e;return this.#v?.reportFailure(e),this.#L=i,{events:errorOnlyTUIStream({errorText:this.#u(e)}),turnState:createTurnState()}}return this.#$(r,()=>t.abort(),this.#e)}async#Z(e,t){if(e.cancelInFlight!==!0){e.cancelInFlight=!0;try{for(let n=0;n<8;n+=1){if(e.boundaryEvent!==void 0||e.aborted===!0)return;let n=e.turnId;try{if((await t?.cancel(n===void 0?void 0:{turnId:n}))?.status===`accepted`)return}catch{}await delayMs(250)}}finally{e.cancelInFlight=!1}}}#Q(){if(this.#e===void 0)throw Error(`Cannot stream a session before its first turn is accepted.`);let e=new AbortController,t=this.#e;return this.#$(t.stream({signal:e.signal}),()=>e.abort(),t)}#$(e,t,n){let r=createTurnState();return{abort:()=>{r.aborted=!0,this.#L=n,t()},cancel:()=>{this.#Z(r,n)},events:eveEventsToTUIStream({events:e,pendingInputRequests:this.#M,turnState:r,onSubagentCalled:e=>this.#P.begin(e),onSubagentBackgrounded:e=>this.#P.background(e),onSubagentCompleted:e=>this.#P.settle(e),onTurnCancelled:e=>this.#P.settleCancelledTurn(e),onConnectionAuthRequired:e=>this.#ve(e),onConnectionAuthCompleted:e=>this.#be(e),onTerminalFailure:()=>{this.#L=n},failureHintOverride:this.#p===void 0?void 0:localFailureHint}),turnState:r}}async#ee(e){if(this.#p===void 0)return;let t={appRoot:this.#p,env:process.env};e!==void 0&&(t.info=e),this.#E=await detectSetupIssues(t,this.#y),this.#n.renderSetupWarning!==void 0&&(this.#te(),this.#ne())}#te(){let e=orderedSetupIssues(this.#E,this.#D);e.length>0?this.#n.renderSetupWarning?.(formatSetupIssuesLine(e)):this.#n.clearSetupWarning?.()}async#ne(){let e=this.#p;if(e===void 0)return;let t;try{t=await this.#b(e,{signal:this.#w.signal})}catch{return}this.#C||this.#T||(this.#D=authIssueForStatus(t),this.#te())}async#re(e){let t=this.#p;if(t===void 0||this.#n.renderSetupWarning===void 0)return;let n={appRoot:t,env:process.env};e!==void 0&&(n.info=e);try{this.#E=await detectSetupIssues(n,this.#y);let e=await this.#b(t,{signal:this.#w.signal});this.#D=authIssueForStatus(e)}catch{return}this.#C||this.#te()}#ie(){this.#p===void 0||this.#n.renderSandboxLog===void 0||this.#R===void 0&&(this.#R=subscribeDevelopmentSandboxPrewarmLogs({appRoot:this.#p,log:e=>this.#n.renderSandboxLog?.(e)}))}#ae(e,t){if(e!==void 0){if(this.#n.renderCommandResult!==void 0){this.#n.renderCommandResult(e,t);return}this.#n.renderNotice?.(e)}}async#oe(e,t){let n=this.#h;if(n===void 0)return{message:`/${e.name} is not available in this session.`};let r=this.#j?.agent.model.endpoint,i={renderer:this.#n,title:t.title,initialModelStep:t.initialModelStep,chatGptAccountLabel:r?.kind===`chatgpt`&&r.state===`ready`?r.accountLabel:void 0,remoteConnection:this.#v,withExclusiveTerminal:this.#_},a=this.#k?.current(),o=a!==void 0&&Object.keys(a).length>0?{...i,disabledConnectionReasons:a}:i;return t.keepSetupFlowOpen===!0?await n.handle(e,{...o,keepSetupFlowOpen:!0}):await n.handle(e,o)}#se(e,t){if(t!==`startup`)return;let n=this.#v?.current().connection.state,r=n===`auth-failed`||n===`unavailable`?`failed`:void 0,i=e.argument.length===0?``:` ${e.argument}`;this.#n.renderCommandInvocation?.(`/${e.name}${i}`,r)}async#ce(e){if(e?.kind===`model-access-changed`){this.#O?.applyEffect({kind:`refresh-identity`}),this.#T=!0,await this.#he();return}e!==void 0&&(this.#O?.applyEffect(e),this.#T=!0,this.#re(this.#j))}async#le(e,t,n){let r=await this.#oe(e,{initialModelStep:n.initialModelStep,keepSetupFlowOpen:n.keepSetupFlowOpen,title:t});this.#se(e,n.trigger),this.#ae(r?.message,r?.tone),await this.#ce(r?.effect),this.#de()}async#ue(e){let t=this.#p;if(t===void 0)return;let authStatus=async()=>{try{return await this.#b(t,{signal:this.#w.signal})}catch{return}},n=await authStatus();if(n===`cli-missing`&&(await this.#le({type:`extension`,name:`vc:install`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`)){this.#n.setupFlow?.end();return}if(n===`logged-out`&&(await this.#le({type:`extension`,name:`vc:login`,argument:``},e,{trigger:`startup`,keepSetupFlowOpen:!0}),n=await authStatus(),n===`cli-missing`||n===`logged-out`)){this.#n.setupFlow?.end();return}await this.#le({type:`extension`,name:`model`,argument:``},e,{trigger:`startup`,initialModelStep:`provider`}),await this.#le({type:`extension`,name:`add`,argument:``},e,{trigger:`startup`})}#de(){let e=this.#v?.current().connection;e?.state!==`ready`||e.info===this.#j||(this.#j=e.info,this.#f!==void 0&&this.#n.renderAgentHeader?.({info:e.info,name:this.#r,serverUrl:this.#f}))}async#fe(e){if(this.#p===void 0||this.#n.traceViewer===void 0){this.#ae(`/traces is only available in local dev sessions.`);return}try{await this.#n.traceViewer.open({appRoot:this.#p,sessionId:this.#e?.state.sessionId,reference:e===``?void 0:e})}catch(e){if(isInterruptedError(e))return;throw e}}async#pe(){let e=this.#p;if(e===void 0){this.#ae(`/info is only available in local dev sessions.`);return}try{this.#ae(renderApplicationInfo(await this.#x(e)))}catch(e){this.#ae(`Couldn't inspect the application: ${toErrorMessage(e)}`,`error`)}}#me(e){let t=this.#n;if(t.logDisplayMode===void 0||t.setLogDisplayMode===void 0)return`/loglevel is not available in this session.`;if(e===``)return`Logs: ${t.logDisplayMode()}. Use /loglevel all|stderr|sandbox|none — logs stay buffered, so switching also hides or restores past lines.`;let n=parseLogDisplayMode(e);if(n===void 0)return`Unknown log level "${e}". Use all, stderr, sandbox, or none.`;if(n===t.logDisplayMode())return`Logs already set to ${n}.`;switch(t.setLogDisplayMode(n),n){case`none`:return`Logs hidden. Output stays buffered — /loglevel all restores it.`;case`stderr`:return`Showing stderr logs only.`;case`sandbox`:return`Showing sandbox logs only.`;case`all`:return`Showing all logs.`}}async#he(){let e=this.#p;if(e===void 0)return;loadDevelopmentEnvironmentFiles(e),await this.#d?.refreshAfterSourceChange({});let t=this.#V(await this.#ge());this.#re(t)}async#ge(){let e=this.#t;if(e===void 0)return;let t=await probeAgentInfo({client:e});return t.kind===`ready`?t.info:void 0}async#_e(){let e=this.#j,t=await this.#ge();t!==void 0&&this.#V(t),(!this.#n.renderAgentHeader||t===void 0)&&this.#n.renderNotice?.(formatAgentUpdateNotice(e,t))}#ve(e){let t={name:e.data.name,description:e.data.description,state:`required`};e.data.authorization!==void 0&&(t.challenge=e.data.authorization),e.data.webhookUrl!==void 0&&(t.webhookUrl=e.data.webhookUrl),this.#F.set(e.data.name,t),this.#xe(t)}#ye(e){if(e.turnState?.boundaryEvent!==`session.waiting`)return!1;let t=!1;for(let e of this.#F.values())e.state!==`required`||e.webhookUrl===void 0||(e.state=`pending`,this.#I.add(e.name),this.#xe(e),t=!0);return t&&this.#n.setConnectionAuthPendingCount?.(this.#I.size),this.#I.size>0}#be(e){let t=this.#F.get(e.data.name)??{name:e.data.name,description:``,state:e.data.outcome};t.state=e.data.outcome,e.data.reason!==void 0&&(t.reason=e.data.reason),this.#F.set(e.data.name,t),this.#I.delete(e.data.name),this.#xe(t),this.#n.setConnectionAuthPendingCount?.(this.#I.size)}#xe(e){let t={name:e.name,description:e.description,state:e.state};e.challenge!==void 0&&(t.challenge=e.challenge),e.reason!==void 0&&(t.reason=e.reason),this.#n.upsertConnectionAuth?.(t)}};function createRenderer(e){return e.renderer?e.renderer:new TerminalRenderer({tools:e.tools,reasoning:e.reasoning,subagents:e.subagents,connectionAuth:e.connectionAuth,assistantResponseStats:e.assistantResponseStats,contextSize:e.contextSize,logs:e.logs,availablePromptCommands:e.availablePromptCommands,input:e.userInput,output:e.screen,diagnostics:e.diagnostics,onExitRequest:e.lifecycle?.requestStop})}function formatAgentUpdateNotice(e,t){let n=e?.agent.model.id,r=t?.agent.model.id;return n!==void 0&&r!==void 0&&n!==r?`Agent updated: Model ${n} -> ${r}`:`Agent updated.`}async function*eveEventsToTUIStream(e){let{events:t,pendingInputRequests:n,turnState:r,onSubagentCalled:i,onSubagentBackgrounded:a,onSubagentCompleted:o,onTurnCancelled:s,onConnectionAuthRequired:c,onConnectionAuthCompleted:l,onTerminalFailure:u,failureHintOverride:d}=e,f=new Map,p=new Map,m=createEventDeduper(),h=0,g=new Set,_=new Set,v=new Set,y=!1,b=!1,x;for await(let e of t)if(m.admit(e)&&!(b&&isPostTurnVisibleEvent(e)))switch(e.type){case`session.started`:case`message.received`:break;case`turn.started`:r.turnId=e.data.turnId;break;case`step.started`:h+=1,yield{type:`step-start`};break;case`step.completed`:{let t=e;x=t.data.usage,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`step-finish`,usage:t.data.usage};break}case`message.appended`:{let t=e,n=textPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(f,n),i=t.data.messageSoFar;if(r.completed){if(h<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`assistant-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`message.completed`:{let t=textPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(f,t),r=e.data.message;if(n.completed){if(r===null||h<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=h,yield{type:`assistant-complete`,id:partGenerationId(t,n.generation),text:r};break}let i=partGenerationId(t,n.generation);if(r!==null){if(n.text.length===0)n.text=r,n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i,text:r};else if(r.startsWith(n.text)){let e=r.slice(n.text.length);e.length>0&&(yield{type:`assistant-delta`,id:i,delta:e}),n.text=r,n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i}}}else n.text.length>0&&(n.completed=!0,n.completedEpoch=h,yield{type:`assistant-complete`,id:i});break}case`reasoning.appended`:{let t=e,n=reasoningPartId(t.data.turnId,t.data.stepIndex),r=partStateFor(p,n),i=t.data.reasoningSoFar;if(r.completed){if(h<=r.completedEpoch)break;r.generation+=1,r.text=``,r.completed=!1}if(!i.startsWith(r.text)||i.length<=r.text.length)break;let a=i.slice(r.text.length);r.text=i,yield{type:`reasoning-delta`,id:partGenerationId(n,r.generation),delta:a};break}case`reasoning.completed`:{let t=reasoningPartId(e.data.turnId,e.data.stepIndex),n=partStateFor(p,t),r=e.data.reasoning;if(n.completed){if(r.length===0||h<=n.completedEpoch)break;n.generation+=1,n.text=r,n.completedEpoch=h;let e=partGenerationId(t,n.generation);yield{type:`reasoning-delta`,id:e,delta:r},yield{type:`reasoning-complete`,id:e};break}let i=partGenerationId(t,n.generation);if(n.text.length===0&&r.length>0)n.text=r,yield{type:`reasoning-delta`,id:i,delta:r};else if(r.length>0&&!r.startsWith(n.text))break;n.completed=!0,n.completedEpoch=h,yield{type:`reasoning-complete`,id:i};break}case`actions.requested`:{let t=e.data.actions.filter(e=>e.kind===`tool-call`);if(t.length===0)break;for(let e of t)g.has(e.callId)||(g.add(e.callId),yield{type:`tool-call`,toolCallId:e.callId,toolName:e.toolName,input:e.input});break}case`input.requested`:{let t=e.data.requests.filter(e=>e.action.kind===`tool-call`);if(t.length===0)break;for(let e of t){let t=e.action.callId;if(e.kind!==`session-limit`&&!g.has(t)&&(g.add(t),yield{type:`tool-call`,toolCallId:t,toolName:e.action.toolName,input:e.action.input}),!_.has(e.requestId)){if(_.add(e.requestId),n.set(e.requestId,e),e.kind!==`tool-approval`){upsertPendingQuestion(r,e);continue}upsertPendingApproval(r,e),yield{type:`tool-approval-request`,approvalId:e.requestId,toolCallId:t}}}break}case`action.result`:{let t=e;if(t.data.result.kind!==`tool-result`)break;let n=t.data.result.callId;if(!g.has(n))break;switch(t.data.status){case`completed`:yield{type:`tool-result`,toolCallId:n,output:t.data.result.output};break;case`failed`:yield{type:`tool-error`,toolCallId:n,errorText:formatActionResultError(t)};break;case`rejected`:yield{type:`tool-rejected`,toolCallId:n,reason:formatActionResultError(t)};break}break}case`step.failed`:case`turn.failed`:{let t=toFailureEvent(e,v,d);t&&(yield t);break}case`session.failed`:{r.sawSessionFailure=!0,u?.(e);let t=toFailureEvent(e,v,d);t&&(yield t),r.boundaryEvent=e.type,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x},y=!0;return}case`session.waiting`:case`session.completed`:r.boundaryEvent=e.type,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x},y=!0;return;case`turn.completed`:b=!0,yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h);break;case`turn.cancelled`:s?.(e.data.turnId),yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`turn-cancelled`};break;case`subagent.called`:i?.(e);break;case`subagent.started`:case`subagent.event`:break;case`subagent.completed`:{let t=e;t.data.backgroundTask===void 0?o?.(t.data.callId):a?.(t.data.callId);break}case`authorization.required`:c?.(e);break;case`authorization.completed`:l?.(e);break;default:break}y||(yield*closeOpenParts(f,`assistant-complete`,h),yield*closeOpenParts(p,`reasoning-complete`,h),yield{type:`finish`,usage:x})}async function*errorOnlyTUIStream(e){yield{type:`error`,errorText:e.errorText},yield{type:`finish`}}function createTurnState(){return{aborted:!1,pendingApprovals:[],pendingQuestions:[],sawSessionFailure:!1}}function upsertPendingApproval(e,t){let n=toAgentTUIToolApprovalRequest(t),r=e.pendingApprovals.findIndex(e=>e.approvalId===n.approvalId);r===-1?e.pendingApprovals.push(n):e.pendingApprovals[r]=n}function toAgentTUIToolApprovalRequest(e){return{approvalId:e.requestId,toolCallId:e.action.callId,toolName:e.action.toolName,input:e.action.input}}function upsertPendingQuestion(e,t){let n=e.pendingQuestions.findIndex(e=>e.requestId===t.requestId);n===-1?e.pendingQuestions.push(t):e.pendingQuestions[n]=t}function textPartId(e,t){return`text:${e}:${t}`}function reasoningPartId(e,t){return`reasoning:${e}:${t}`}function partStateFor(e,t){let n=e.get(t);return n===void 0&&(n={generation:0,text:``,completed:!1,completedEpoch:0},e.set(t,n)),n}function partGenerationId(e,t){return t===0?e:`${e}#${t}`}function*closeOpenParts(e,t,n){for(let[r,i]of e)i.completed||i.text.length===0||(i.completed=!0,i.completedEpoch=n,yield{type:t,id:partGenerationId(r,i.generation)})}function isPostTurnVisibleEvent(e){switch(e.type){case`actions.requested`:case`authorization.completed`:case`authorization.required`:case`input.requested`:case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:case`result.completed`:case`step.completed`:case`step.failed`:case`step.started`:case`subagent.called`:case`subagent.completed`:case`subagent.event`:case`subagent.started`:case`turn.completed`:case`turn.failed`:return!0;default:return!1}}function formatActionResultError(e){if(e.data.error?.message)return e.data.error.message;let t=e.data.result.output;if(typeof t==`string`)return t;try{return JSON.stringify(t)}catch{return`Tool execution failed.`}}function toFailureEvent(e,t,n){let r=failureKey(e);if(t.has(r))return;t.add(r);let c={type:`error`,errorText:formatFailureMessage(e)},l=n?.(e)??formatFailureHint(e);l!==void 0&&(c.hint=l);let u=formatFailureDetail(e);return u!==void 0&&(c.detail=u),c}function toAgentTUIInputQuestion(e){let t=e.display===`text`?`text`:e.display===`select`||e.options!==void 0&&e.options.length>0?`select`:`text`,n={requestId:e.requestId,prompt:e.prompt,display:t};return e.options!==void 0&&(n.options=e.options.map(e=>{let t={id:e.id,label:e.label};return e.description!==void 0&&(t.description=e.description),e.style!==void 0&&(t.style=e.style),t})),e.allowFreeform!==void 0&&(n.allowFreeform=e.allowFreeform),n}export{EveTUIRunner,parsePromptCommand};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EveMessage, EveMessageData, EveMessagePart } from "#client/message-reducer-types.js";
|
|
2
|
+
import type { MessageReceivedPart } from "#protocol/message.js";
|
|
3
|
+
export declare function projectReceivedParts(parts: readonly MessageReceivedPart[] | undefined, message: string): readonly EveMessagePart[];
|
|
4
|
+
export declare function partKey(part: EveMessagePart): string;
|
|
5
|
+
export declare function upsertMessage(data: EveMessageData, next: EveMessage): EveMessageData;
|
|
6
|
+
export declare function removeStreamingToolPartsForTurn(data: EveMessageData, turnId: string): EveMessageData;
|
|
7
|
+
export declare function optimisticUserMessageId(submissionId: string): string;
|
|
8
|
+
export declare function appendToolInputDelta(inputText: string | undefined, offset: number, delta: string): string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function projectReceivedParts(e,t){return e?.map(e=>e.type===`text`?{state:`done`,text:e.text,type:`text`}:{filename:e.filename,mediaType:e.mediaType,size:e.size,type:`file`,url:e.url})??[{state:`done`,text:t,type:`text`}]}function partKey(e){switch(e.type){case`text`:return`text:${e.stepIndex??0}`;case`reasoning`:return`reasoning:${e.stepIndex??0}`;case`file`:return`file:${e.stepIndex??0}:${e.filename??e.url??e.mediaType}`;case`step-start`:return`step-start`;case`authorization`:return`authorization:${e.turnId}:${e.stepIndex}:${e.name}`;case`dynamic-tool`:return`dynamic-tool:${e.toolCallId}`}}function upsertMessage(e,t){let n=e.messages.findIndex(e=>e.id===t.id);return n===-1?{messages:[...e.messages,t]}:{messages:[...e.messages.slice(0,n),t,...e.messages.slice(n+1)]}}function removeStreamingToolPartsForTurn(e,t){let n=e.messages.findIndex(e=>e.role===`assistant`&&e.metadata?.turnId===t),r=e.messages[n];return r===void 0?e:upsertMessage(e,{...r,parts:r.parts.filter(e=>e.type!==`dynamic-tool`||e.state!==`input-streaming`)})}function optimisticUserMessageId(e){return`optimistic:${e}:user`}function appendToolInputDelta(e,t,n){if(t===0)return n;if(e?.length===t)return e+n}export{appendToolInputDelta,optimisticUserMessageId,partKey,projectReceivedParts,removeStreamingToolPartsForTurn,upsertMessage};
|
|
@@ -122,6 +122,8 @@ export type EveDynamicToolPart = {
|
|
|
122
122
|
readonly approval?: never;
|
|
123
123
|
readonly errorText?: never;
|
|
124
124
|
readonly input: unknown | undefined;
|
|
125
|
+
/** Accumulated raw tool input, which may be incomplete JSON. */
|
|
126
|
+
readonly inputText: string;
|
|
125
127
|
readonly output?: never;
|
|
126
128
|
readonly state: "input-streaming";
|
|
127
129
|
} | {
|