mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-11 20:00:29 +01:00
feat: add ctx.prompt.form() plugin API for multi-field form dialogs (#359)
This commit is contained in:
@@ -57,6 +57,10 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
|
|||||||
let window = get_window_from_plugin_context(app_handle, &plugin_context)?;
|
let window = get_window_from_plugin_context(app_handle, &plugin_context)?;
|
||||||
Ok(call_frontend(&window, event).await)
|
Ok(call_frontend(&window, event).await)
|
||||||
}
|
}
|
||||||
|
InternalEventPayload::PromptFormRequest(_) => {
|
||||||
|
let window = get_window_from_plugin_context(app_handle, &plugin_context)?;
|
||||||
|
Ok(call_frontend(&window, event).await)
|
||||||
|
}
|
||||||
InternalEventPayload::FindHttpResponsesRequest(req) => {
|
InternalEventPayload::FindHttpResponsesRequest(req) => {
|
||||||
let http_responses = app_handle
|
let http_responses = app_handle
|
||||||
.db()
|
.db()
|
||||||
|
|||||||
6
crates/yaak-plugins/bindings/gen_events.ts
generated
6
crates/yaak-plugins/bindings/gen_events.ts
generated
File diff suppressed because one or more lines are too long
@@ -157,6 +157,9 @@ pub enum InternalEventPayload {
|
|||||||
PromptTextRequest(PromptTextRequest),
|
PromptTextRequest(PromptTextRequest),
|
||||||
PromptTextResponse(PromptTextResponse),
|
PromptTextResponse(PromptTextResponse),
|
||||||
|
|
||||||
|
PromptFormRequest(PromptFormRequest),
|
||||||
|
PromptFormResponse(PromptFormResponse),
|
||||||
|
|
||||||
WindowInfoRequest(WindowInfoRequest),
|
WindowInfoRequest(WindowInfoRequest),
|
||||||
WindowInfoResponse(WindowInfoResponse),
|
WindowInfoResponse(WindowInfoResponse),
|
||||||
|
|
||||||
@@ -571,6 +574,28 @@ pub struct PromptTextResponse {
|
|||||||
pub value: Option<String>,
|
pub value: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "gen_events.ts")]
|
||||||
|
pub struct PromptFormRequest {
|
||||||
|
pub id: String,
|
||||||
|
pub title: String,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub description: Option<String>,
|
||||||
|
pub inputs: Vec<FormInput>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub confirm_text: Option<String>,
|
||||||
|
#[ts(optional)]
|
||||||
|
pub cancel_text: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
|
#[serde(default, rename_all = "camelCase")]
|
||||||
|
#[ts(export, export_to = "gen_events.ts")]
|
||||||
|
pub struct PromptFormResponse {
|
||||||
|
pub values: Option<HashMap<String, JsonPrimitive>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||||
#[serde(default, rename_all = "camelCase")]
|
#[serde(default, rename_all = "camelCase")]
|
||||||
#[ts(export, export_to = "gen_events.ts")]
|
#[ts(export, export_to = "gen_events.ts")]
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -11,6 +11,8 @@ import type {
|
|||||||
ListHttpRequestsRequest,
|
ListHttpRequestsRequest,
|
||||||
ListHttpRequestsResponse,
|
ListHttpRequestsResponse,
|
||||||
OpenWindowRequest,
|
OpenWindowRequest,
|
||||||
|
PromptFormRequest,
|
||||||
|
PromptFormResponse,
|
||||||
PromptTextRequest,
|
PromptTextRequest,
|
||||||
PromptTextResponse,
|
PromptTextResponse,
|
||||||
RenderGrpcRequestRequest,
|
RenderGrpcRequestRequest,
|
||||||
@@ -37,6 +39,7 @@ export interface Context {
|
|||||||
};
|
};
|
||||||
prompt: {
|
prompt: {
|
||||||
text(args: PromptTextRequest): Promise<PromptTextResponse['value']>;
|
text(args: PromptTextRequest): Promise<PromptTextResponse['value']>;
|
||||||
|
form(args: PromptFormRequest): Promise<PromptFormResponse['values']>;
|
||||||
};
|
};
|
||||||
store: {
|
store: {
|
||||||
set<T>(key: string, value: T): Promise<void>;
|
set<T>(key: string, value: T): Promise<void>;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import type {
|
|||||||
ListHttpRequestsResponse,
|
ListHttpRequestsResponse,
|
||||||
ListWorkspacesResponse,
|
ListWorkspacesResponse,
|
||||||
PluginContext,
|
PluginContext,
|
||||||
|
PromptFormResponse,
|
||||||
PromptTextResponse,
|
PromptTextResponse,
|
||||||
RenderGrpcRequestResponse,
|
RenderGrpcRequestResponse,
|
||||||
RenderHttpRequestResponse,
|
RenderHttpRequestResponse,
|
||||||
@@ -661,6 +662,13 @@ export class PluginInstance {
|
|||||||
});
|
});
|
||||||
return reply.value;
|
return reply.value;
|
||||||
},
|
},
|
||||||
|
form: async (args) => {
|
||||||
|
const reply: PromptFormResponse = await this.#sendForReply(context, {
|
||||||
|
type: 'prompt_form_request',
|
||||||
|
...args,
|
||||||
|
});
|
||||||
|
return reply.values;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
httpResponse: {
|
httpResponse: {
|
||||||
find: async (args) => {
|
find: async (args) => {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { stringToColor } from './color';
|
|||||||
import { generateId } from './generateId';
|
import { generateId } from './generateId';
|
||||||
import { jotaiStore } from './jotai';
|
import { jotaiStore } from './jotai';
|
||||||
import { showPrompt } from './prompt';
|
import { showPrompt } from './prompt';
|
||||||
|
import { showPromptForm } from './prompt-form';
|
||||||
import { invokeCmd } from './tauri';
|
import { invokeCmd } from './tauri';
|
||||||
import { showToast } from './toast';
|
import { showToast } from './toast';
|
||||||
|
|
||||||
@@ -47,6 +48,27 @@ export function initGlobalListeners() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
await emit(event.id, result);
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user