feat: add ctx.prompt.form() API for multi-field form dialogs

Add PromptFormRequest and PromptFormResponse types to enable plugins to
display forms with multiple input fields. Implement the form() method in
the prompt context and wire up frontend event handling to show and collect
form responses from users.
This commit is contained in:
Gregory Schier
2026-01-09 19:35:47 -08:00
parent 4c8f768624
commit fa3e6e6508
6 changed files with 68 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ import { stringToColor } from './color';
import { generateId } from './generateId';
import { jotaiStore } from './jotai';
import { showPrompt } from './prompt';
import { showPromptForm } from './prompt-form';
import { invokeCmd } from './tauri';
import { showToast } from './toast';
@@ -47,6 +48,27 @@ export function initGlobalListeners() {
},
};
await emit(event.id, result);
} else if (event.payload.type === 'prompt_form_request') {
const values = await showPromptForm({
id: event.payload.id,
title: event.payload.title,
description: event.payload.description,
inputs: event.payload.inputs,
confirmText: event.payload.confirmText,
cancelText: event.payload.cancelText,
});
const result: InternalEvent = {
id: generateId(),
replyId: event.id,
pluginName: event.pluginName,
pluginRefId: event.pluginRefId,
context: event.context,
payload: {
type: 'prompt_form_response',
values,
},
};
await emit(event.id, result);
}
});