mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 19:05:11 +00:00
Merge branch 'badlogic:main' into fix/async-extension-factories
This commit is contained in:
commit
c2eb8d0f92
34 changed files with 461 additions and 85 deletions
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.37.6] - 2026-01-06
|
||||
|
||||
### Added
|
||||
|
||||
- Extension UI dialogs (`ctx.ui.select()`, `ctx.ui.confirm()`, `ctx.ui.input()`) now accept an optional `AbortSignal` to programmatically dismiss dialogs. Useful for implementing timeouts. See `examples/extensions/timed-confirm.ts`. ([#474](https://github.com/badlogic/pi-mono/issues/474))
|
||||
- HTML export now shows bridge prompts in model change messages for Codex sessions ([#510](https://github.com/badlogic/pi-mono/pull/510) by [@mitsuhiko](https://github.com/mitsuhiko))
|
||||
|
||||
## [0.37.5] - 2026-01-06
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -1094,6 +1094,38 @@ ctx.ui.notify("Done!", "info"); // "info" | "warning" | "error"
|
|||
- `ctx.ui.editor()`: [handoff.ts](../examples/extensions/handoff.ts)
|
||||
- `ctx.ui.setEditorText()`: [handoff.ts](../examples/extensions/handoff.ts), [qna.ts](../examples/extensions/qna.ts)
|
||||
|
||||
#### Auto-Dismissing Dialogs
|
||||
|
||||
Dialogs can be programmatically dismissed using `AbortSignal`. This is useful for implementing timeouts:
|
||||
|
||||
```typescript
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
const confirmed = await ctx.ui.confirm(
|
||||
"Timed Confirmation",
|
||||
"This dialog will auto-cancel in 5 seconds. Confirm?",
|
||||
{ signal: controller.signal }
|
||||
);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (confirmed) {
|
||||
// User confirmed
|
||||
} else if (controller.signal.aborted) {
|
||||
// Dialog timed out
|
||||
} else {
|
||||
// User cancelled (pressed Escape or selected "No")
|
||||
}
|
||||
```
|
||||
|
||||
**Return values on abort:**
|
||||
- `select()` returns `undefined`
|
||||
- `confirm()` returns `false`
|
||||
- `input()` returns `undefined`
|
||||
|
||||
See [examples/extensions/timed-confirm.ts](../examples/extensions/timed-confirm.ts) for a complete example.
|
||||
|
||||
### Widgets, Status, and Footer
|
||||
|
||||
```typescript
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
|
|||
| `status-line.ts` | Shows turn progress in footer via `ctx.ui.setStatus()` with themed colors |
|
||||
| `snake.ts` | Snake game with custom UI, keyboard handling, and session persistence |
|
||||
| `send-user-message.ts` | Demonstrates `pi.sendUserMessage()` for sending user messages from extensions |
|
||||
| `timed-confirm.ts` | Demonstrates AbortSignal for auto-dismissing `ctx.ui.confirm()` and `ctx.ui.select()` dialogs |
|
||||
|
||||
### Git Integration
|
||||
|
||||
|
|
|
|||
63
packages/coding-agent/examples/extensions/timed-confirm.ts
Normal file
63
packages/coding-agent/examples/extensions/timed-confirm.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Example extension demonstrating AbortSignal for auto-dismissing dialogs.
|
||||
*
|
||||
* Commands:
|
||||
* - /timed - Shows confirm dialog that auto-cancels after 5 seconds
|
||||
* - /timed-select - Shows select dialog that auto-cancels after 10 seconds
|
||||
*/
|
||||
|
||||
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
||||
|
||||
export default function (pi: ExtensionAPI) {
|
||||
pi.registerCommand("timed", {
|
||||
description: "Show a timed confirmation dialog (auto-cancels in 5s)",
|
||||
handler: async (_args, ctx) => {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
ctx.ui.notify("Dialog will auto-cancel in 5 seconds...", "info");
|
||||
|
||||
const confirmed = await ctx.ui.confirm(
|
||||
"Timed Confirmation",
|
||||
"This dialog will auto-cancel in 5 seconds. Confirm?",
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (confirmed) {
|
||||
ctx.ui.notify("Confirmed by user!", "info");
|
||||
} else if (controller.signal.aborted) {
|
||||
ctx.ui.notify("Dialog timed out (auto-cancelled)", "warning");
|
||||
} else {
|
||||
ctx.ui.notify("Cancelled by user", "info");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
pi.registerCommand("timed-select", {
|
||||
description: "Show a timed select dialog (auto-cancels in 10s)",
|
||||
handler: async (_args, ctx) => {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 10000);
|
||||
|
||||
ctx.ui.notify("Select dialog will auto-cancel in 10 seconds...", "info");
|
||||
|
||||
const choice = await ctx.ui.select(
|
||||
"Pick an option (auto-cancels in 10s)",
|
||||
["Option A", "Option B", "Option C"],
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
if (choice) {
|
||||
ctx.ui.notify(`Selected: ${choice}`, "info");
|
||||
} else if (controller.signal.aborted) {
|
||||
ctx.ui.notify("Selection timed out", "warning");
|
||||
} else {
|
||||
ctx.ui.notify("Selection cancelled", "info");
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "pi-extension-with-deps",
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "pi-extension-with-deps",
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.6",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "pi-extension-with-deps",
|
||||
"private": true,
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.6",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"clean": "echo 'nothing to clean'",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@mariozechner/pi-coding-agent",
|
||||
"version": "0.37.5",
|
||||
"version": "0.37.6",
|
||||
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
||||
"type": "module",
|
||||
"piConfig": {
|
||||
|
|
@ -39,9 +39,9 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@crosscopy/clipboard": "^0.2.8",
|
||||
"@mariozechner/pi-agent-core": "^0.37.5",
|
||||
"@mariozechner/pi-ai": "^0.37.5",
|
||||
"@mariozechner/pi-tui": "^0.37.5",
|
||||
"@mariozechner/pi-agent-core": "^0.37.6",
|
||||
"@mariozechner/pi-ai": "^0.37.6",
|
||||
"@mariozechner/pi-tui": "^0.37.6",
|
||||
"chalk": "^5.5.0",
|
||||
"cli-highlight": "^2.1.11",
|
||||
"diff": "^8.0.2",
|
||||
|
|
|
|||
|
|
@ -2057,9 +2057,9 @@ export class AgentSession {
|
|||
* @param outputPath Optional output path (defaults to session directory)
|
||||
* @returns Path to exported file
|
||||
*/
|
||||
exportToHtml(outputPath?: string): string {
|
||||
async exportToHtml(outputPath?: string): Promise<string> {
|
||||
const themeName = this.settingsManager.getTheme();
|
||||
return exportSessionToHtml(this.sessionManager, this.state, { outputPath, themeName });
|
||||
return await exportSessionToHtml(this.sessionManager, this.state, { outputPath, themeName });
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { AgentState } from "@mariozechner/pi-agent-core";
|
||||
import type { AgentState, AgentTool } from "@mariozechner/pi-agent-core";
|
||||
import { buildCodexPiBridge, getCodexInstructions } from "@mariozechner/pi-ai";
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
import { basename, join } from "path";
|
||||
import { APP_NAME, getExportTemplateDir } from "../../config.js";
|
||||
|
|
@ -10,6 +11,37 @@ export interface ExportOptions {
|
|||
themeName?: string;
|
||||
}
|
||||
|
||||
/** Info about Codex injection to show inline with model_change entries */
|
||||
interface CodexInjectionInfo {
|
||||
/** Codex instructions text */
|
||||
instructions: string;
|
||||
/** Bridge text (tool list) */
|
||||
bridge: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Codex injection info for display inline with model_change entries.
|
||||
*/
|
||||
async function buildCodexInjectionInfo(tools?: AgentTool[]): Promise<CodexInjectionInfo | undefined> {
|
||||
// Try to get cached instructions for default model family
|
||||
let instructions: string | null = null;
|
||||
try {
|
||||
instructions = await getCodexInstructions("gpt-5.1-codex");
|
||||
} catch {
|
||||
// Cache miss - that's fine
|
||||
}
|
||||
|
||||
const bridgeText = buildCodexPiBridge(tools);
|
||||
|
||||
const instructionsText =
|
||||
instructions || "(Codex instructions not cached. Run a Codex request to populate the local cache.)";
|
||||
|
||||
return {
|
||||
instructions: instructionsText,
|
||||
bridge: bridgeText,
|
||||
};
|
||||
}
|
||||
|
||||
/** Parse a color string to RGB values. Supports hex (#RRGGBB) and rgb(r,g,b) formats. */
|
||||
function parseColor(color: string): { r: number; g: number; b: number } | undefined {
|
||||
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
||||
|
|
@ -103,6 +135,8 @@ interface SessionData {
|
|||
entries: ReturnType<SessionManager["getEntries"]>;
|
||||
leafId: string | null;
|
||||
systemPrompt?: string;
|
||||
/** Info for rendering Codex injection inline with model_change entries */
|
||||
codexInjectionInfo?: CodexInjectionInfo;
|
||||
tools?: { name: string; description: string }[];
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +180,11 @@ function generateHtml(sessionData: SessionData, themeName?: string): string {
|
|||
* Export session to HTML using SessionManager and AgentState.
|
||||
* Used by TUI's /export command.
|
||||
*/
|
||||
export function exportSessionToHtml(sm: SessionManager, state?: AgentState, options?: ExportOptions | string): string {
|
||||
export async function exportSessionToHtml(
|
||||
sm: SessionManager,
|
||||
state?: AgentState,
|
||||
options?: ExportOptions | string,
|
||||
): Promise<string> {
|
||||
const opts: ExportOptions = typeof options === "string" ? { outputPath: options } : options || {};
|
||||
|
||||
const sessionFile = sm.getSessionFile();
|
||||
|
|
@ -162,6 +200,7 @@ export function exportSessionToHtml(sm: SessionManager, state?: AgentState, opti
|
|||
entries: sm.getEntries(),
|
||||
leafId: sm.getLeafId(),
|
||||
systemPrompt: state?.systemPrompt,
|
||||
codexInjectionInfo: await buildCodexInjectionInfo(state?.tools),
|
||||
tools: state?.tools?.map((t) => ({ name: t.name, description: t.description })),
|
||||
};
|
||||
|
||||
|
|
@ -181,7 +220,7 @@ export function exportSessionToHtml(sm: SessionManager, state?: AgentState, opti
|
|||
* Export session file to HTML (standalone, without AgentState).
|
||||
* Used by CLI for exporting arbitrary session files.
|
||||
*/
|
||||
export function exportFromFile(inputPath: string, options?: ExportOptions | string): string {
|
||||
export async function exportFromFile(inputPath: string, options?: ExportOptions | string): Promise<string> {
|
||||
const opts: ExportOptions = typeof options === "string" ? { outputPath: options } : options || {};
|
||||
|
||||
if (!existsSync(inputPath)) {
|
||||
|
|
@ -195,6 +234,7 @@ export function exportFromFile(inputPath: string, options?: ExportOptions | stri
|
|||
entries: sm.getEntries(),
|
||||
leafId: sm.getLeafId(),
|
||||
systemPrompt: undefined,
|
||||
codexInjectionInfo: await buildCodexInjectionInfo(undefined),
|
||||
tools: undefined,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -512,6 +512,39 @@
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.codex-bridge-toggle {
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.codex-bridge-toggle:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.codex-bridge-content {
|
||||
display: none;
|
||||
margin-top: 8px;
|
||||
padding: 8px;
|
||||
background: var(--exportCardBg);
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.codex-bridge-content pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.model-change.show-bridge .codex-bridge-content {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Compaction / Branch Summary - matches customMessage colors from TUI */
|
||||
.compaction {
|
||||
background: var(--customMessageBg);
|
||||
|
|
@ -593,6 +626,17 @@
|
|||
display: block;
|
||||
}
|
||||
|
||||
.system-prompt.provider-prompt {
|
||||
border-left: 3px solid var(--warning);
|
||||
}
|
||||
|
||||
.system-prompt-note {
|
||||
font-size: 10px;
|
||||
font-style: italic;
|
||||
color: var(--muted);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* Tools list */
|
||||
.tools-list {
|
||||
background: var(--customMessageBg);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
const data = JSON.parse(new TextDecoder('utf-8').decode(bytes));
|
||||
const { header, entries, leafId: defaultLeafId, systemPrompt, tools } = data;
|
||||
const { header, entries, leafId: defaultLeafId, systemPrompt, codexInjectionInfo, tools } = data;
|
||||
|
||||
// ============================================================
|
||||
// URL PARAMETER HANDLING
|
||||
|
|
@ -954,7 +954,17 @@
|
|||
}
|
||||
|
||||
if (entry.type === 'model_change') {
|
||||
return `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span></div>`;
|
||||
let html = `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span>`;
|
||||
|
||||
// Show expandable bridge prompt info when switching to openai-codex
|
||||
if (entry.provider === 'openai-codex' && codexInjectionInfo) {
|
||||
const fullContent = `# Codex Instructions\n${codexInjectionInfo.instructions}\n\n# Codex-Pi Bridge\n${codexInjectionInfo.bridge}`;
|
||||
html += ` <span class="codex-bridge-toggle" onclick="event.stopPropagation(); this.parentElement.classList.toggle('show-bridge')">[bridge prompt]</span>`;
|
||||
html += `<div class="codex-bridge-content"><pre>${escapeHtml(fullContent)}</pre></div>`;
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
if (entry.type === 'compaction') {
|
||||
|
|
@ -1060,6 +1070,7 @@
|
|||
</div>
|
||||
</div>`;
|
||||
|
||||
// Render system prompt (user's base prompt, applies to all providers)
|
||||
if (systemPrompt) {
|
||||
const lines = systemPrompt.split('\n');
|
||||
const previewLines = 10;
|
||||
|
|
|
|||
|
|
@ -52,13 +52,13 @@ export type { AgentToolResult, AgentToolUpdateCallback };
|
|||
*/
|
||||
export interface ExtensionUIContext {
|
||||
/** Show a selector and return the user's choice. */
|
||||
select(title: string, options: string[]): Promise<string | undefined>;
|
||||
select(title: string, options: string[], opts?: { signal?: AbortSignal }): Promise<string | undefined>;
|
||||
|
||||
/** Show a confirmation dialog. */
|
||||
confirm(title: string, message: string): Promise<boolean>;
|
||||
confirm(title: string, message: string, opts?: { signal?: AbortSignal }): Promise<boolean>;
|
||||
|
||||
/** Show a text input dialog. */
|
||||
input(title: string, placeholder?: string): Promise<string | undefined>;
|
||||
input(title: string, placeholder?: string, opts?: { signal?: AbortSignal }): Promise<string | undefined>;
|
||||
|
||||
/** Show a notification to the user. */
|
||||
notify(message: string, type?: "info" | "warning" | "error"): void;
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ export async function main(args: string[]) {
|
|||
if (parsed.export) {
|
||||
try {
|
||||
const outputPath = parsed.messages.length > 0 ? parsed.messages[0] : undefined;
|
||||
const result = exportFromFile(parsed.export, outputPath);
|
||||
const result = await exportFromFile(parsed.export, outputPath);
|
||||
console.log(`Exported to: ${result}`);
|
||||
return;
|
||||
} catch (error: unknown) {
|
||||
|
|
|
|||
|
|
@ -739,9 +739,9 @@ export class InteractiveMode {
|
|||
*/
|
||||
private createExtensionUIContext(): ExtensionUIContext {
|
||||
return {
|
||||
select: (title, options) => this.showExtensionSelector(title, options),
|
||||
confirm: (title, message) => this.showExtensionConfirm(title, message),
|
||||
input: (title, placeholder) => this.showExtensionInput(title, placeholder),
|
||||
select: (title, options, opts) => this.showExtensionSelector(title, options, opts),
|
||||
confirm: (title, message, opts) => this.showExtensionConfirm(title, message, opts),
|
||||
input: (title, placeholder, opts) => this.showExtensionInput(title, placeholder, opts),
|
||||
notify: (message, type) => this.showExtensionNotify(message, type),
|
||||
setStatus: (key, text) => this.setExtensionStatus(key, text),
|
||||
setWidget: (key, content) => this.setExtensionWidget(key, content),
|
||||
|
|
@ -761,16 +761,33 @@ export class InteractiveMode {
|
|||
/**
|
||||
* Show a selector for extensions.
|
||||
*/
|
||||
private showExtensionSelector(title: string, options: string[]): Promise<string | undefined> {
|
||||
private showExtensionSelector(
|
||||
title: string,
|
||||
options: string[],
|
||||
opts?: { signal?: AbortSignal },
|
||||
): Promise<string | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
if (opts?.signal?.aborted) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const onAbort = () => {
|
||||
this.hideExtensionSelector();
|
||||
resolve(undefined);
|
||||
};
|
||||
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
|
||||
this.extensionSelector = new ExtensionSelectorComponent(
|
||||
title,
|
||||
options,
|
||||
(option) => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
this.hideExtensionSelector();
|
||||
resolve(option);
|
||||
},
|
||||
() => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
this.hideExtensionSelector();
|
||||
resolve(undefined);
|
||||
},
|
||||
|
|
@ -797,24 +814,45 @@ export class InteractiveMode {
|
|||
/**
|
||||
* Show a confirmation dialog for extensions.
|
||||
*/
|
||||
private async showExtensionConfirm(title: string, message: string): Promise<boolean> {
|
||||
const result = await this.showExtensionSelector(`${title}\n${message}`, ["Yes", "No"]);
|
||||
private async showExtensionConfirm(
|
||||
title: string,
|
||||
message: string,
|
||||
opts?: { signal?: AbortSignal },
|
||||
): Promise<boolean> {
|
||||
const result = await this.showExtensionSelector(`${title}\n${message}`, ["Yes", "No"], opts);
|
||||
return result === "Yes";
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a text input for extensions.
|
||||
*/
|
||||
private showExtensionInput(title: string, placeholder?: string): Promise<string | undefined> {
|
||||
private showExtensionInput(
|
||||
title: string,
|
||||
placeholder?: string,
|
||||
opts?: { signal?: AbortSignal },
|
||||
): Promise<string | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
if (opts?.signal?.aborted) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const onAbort = () => {
|
||||
this.hideExtensionInput();
|
||||
resolve(undefined);
|
||||
};
|
||||
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
|
||||
this.extensionInput = new ExtensionInputComponent(
|
||||
title,
|
||||
placeholder,
|
||||
(value) => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
this.hideExtensionInput();
|
||||
resolve(value);
|
||||
},
|
||||
() => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
this.hideExtensionInput();
|
||||
resolve(undefined);
|
||||
},
|
||||
|
|
@ -1051,7 +1089,7 @@ export class InteractiveMode {
|
|||
return;
|
||||
}
|
||||
if (text.startsWith("/export")) {
|
||||
this.handleExportCommand(text);
|
||||
await this.handleExportCommand(text);
|
||||
this.editor.setText("");
|
||||
return;
|
||||
}
|
||||
|
|
@ -2453,12 +2491,12 @@ export class InteractiveMode {
|
|||
// Command handlers
|
||||
// =========================================================================
|
||||
|
||||
private handleExportCommand(text: string): void {
|
||||
private async handleExportCommand(text: string): Promise<void> {
|
||||
const parts = text.split(/\s+/);
|
||||
const outputPath = parts.length > 1 ? parts[1] : undefined;
|
||||
|
||||
try {
|
||||
const filePath = this.session.exportToHtml(outputPath);
|
||||
const filePath = await this.session.exportToHtml(outputPath);
|
||||
this.showStatus(`Session exported to: ${filePath}`);
|
||||
} catch (error: unknown) {
|
||||
this.showError(`Failed to export session: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||
|
|
@ -2481,7 +2519,7 @@ export class InteractiveMode {
|
|||
// Export to a temp file
|
||||
const tmpFile = path.join(os.tmpdir(), "session.html");
|
||||
try {
|
||||
this.session.exportToHtml(tmpFile);
|
||||
await this.session.exportToHtml(tmpFile);
|
||||
} catch (error: unknown) {
|
||||
this.showError(`Failed to export session: ${error instanceof Error ? error.message : "Unknown error"}`);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -67,11 +67,22 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
* Create an extension UI context that uses the RPC protocol.
|
||||
*/
|
||||
const createExtensionUIContext = (): ExtensionUIContext => ({
|
||||
async select(title: string, options: string[]): Promise<string | undefined> {
|
||||
async select(title: string, options: string[], opts?: { signal?: AbortSignal }): Promise<string | undefined> {
|
||||
if (opts?.signal?.aborted) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
return new Promise((resolve, reject) => {
|
||||
const onAbort = () => {
|
||||
pendingExtensionRequests.delete(id);
|
||||
resolve(undefined);
|
||||
};
|
||||
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
|
||||
pendingExtensionRequests.set(id, {
|
||||
resolve: (response: RpcExtensionUIResponse) => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
if ("cancelled" in response && response.cancelled) {
|
||||
resolve(undefined);
|
||||
} else if ("value" in response) {
|
||||
|
|
@ -86,11 +97,22 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
});
|
||||
},
|
||||
|
||||
async confirm(title: string, message: string): Promise<boolean> {
|
||||
async confirm(title: string, message: string, opts?: { signal?: AbortSignal }): Promise<boolean> {
|
||||
if (opts?.signal?.aborted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
return new Promise((resolve, reject) => {
|
||||
const onAbort = () => {
|
||||
pendingExtensionRequests.delete(id);
|
||||
resolve(false);
|
||||
};
|
||||
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
|
||||
pendingExtensionRequests.set(id, {
|
||||
resolve: (response: RpcExtensionUIResponse) => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
if ("cancelled" in response && response.cancelled) {
|
||||
resolve(false);
|
||||
} else if ("confirmed" in response) {
|
||||
|
|
@ -105,11 +127,22 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
});
|
||||
},
|
||||
|
||||
async input(title: string, placeholder?: string): Promise<string | undefined> {
|
||||
async input(title: string, placeholder?: string, opts?: { signal?: AbortSignal }): Promise<string | undefined> {
|
||||
if (opts?.signal?.aborted) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
return new Promise((resolve, reject) => {
|
||||
const onAbort = () => {
|
||||
pendingExtensionRequests.delete(id);
|
||||
resolve(undefined);
|
||||
};
|
||||
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
|
||||
pendingExtensionRequests.set(id, {
|
||||
resolve: (response: RpcExtensionUIResponse) => {
|
||||
opts?.signal?.removeEventListener("abort", onAbort);
|
||||
if ("cancelled" in response && response.cancelled) {
|
||||
resolve(undefined);
|
||||
} else if ("value" in response) {
|
||||
|
|
@ -443,7 +476,7 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
}
|
||||
|
||||
case "export_html": {
|
||||
const path = session.exportToHtml(command.outputPath);
|
||||
const path = await session.exportToHtml(command.outputPath);
|
||||
return success(id, "export_html", { path });
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue