Improved prompt function add add ctx.* functions (#301)

This commit is contained in:
Gregory Schier
2025-11-15 08:19:58 -08:00
committed by GitHub
parent 7ced183b11
commit 84219571e8
29 changed files with 454 additions and 150 deletions

View File

@@ -147,6 +147,9 @@ pub enum InternalEventPayload {
PromptTextRequest(PromptTextRequest),
PromptTextResponse(PromptTextResponse),
WindowInfoRequest(WindowInfoRequest),
WindowInfoResponse(WindowInfoResponse),
GetHttpRequestByIdRequest(GetHttpRequestByIdRequest),
GetHttpRequestByIdResponse(GetHttpRequestByIdResponse),
@@ -521,6 +524,8 @@ pub struct PromptTextRequest {
/// Text to add to the confirmation button
#[ts(optional)]
pub confirm_text: Option<String>,
#[ts(optional)]
pub password: Option<bool>,
/// Text to add to the cancel button
#[ts(optional)]
pub cancel_text: Option<String>,
@@ -536,6 +541,23 @@ pub struct PromptTextResponse {
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 WindowInfoRequest {
pub label: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "gen_events.ts")]
pub struct WindowInfoResponse {
pub request_id: Option<String>,
pub environment_id: Option<String>,
pub workspace_id: Option<String>,
pub label: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export, export_to = "gen_events.ts")]
@@ -710,12 +732,24 @@ pub struct GetTemplateFunctionConfigResponse {
pub plugin_ref_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export, export_to = "gen_events.ts")]
pub enum TemplateFunctionPreviewType {
Live,
Click,
None,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export, export_to = "gen_events.ts")]
pub struct TemplateFunction {
pub name: String,
#[ts(optional)]
pub preview_type: Option<TemplateFunctionPreviewType>,
#[ts(optional)]
pub description: Option<String>,
@@ -972,6 +1006,9 @@ pub struct FormInputAccordion {
pub struct FormInputHStack {
#[ts(optional)]
pub inputs: Option<Vec<FormInput>>,
#[ts(optional)]
pub hidden: Option<bool>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]

View File

@@ -1,6 +1,6 @@
use crate::events::{
FormInput, FormInputBase, FormInputText, PluginContext, RenderPurpose, TemplateFunction,
TemplateFunctionArg,
TemplateFunctionArg, TemplateFunctionPreviewType,
};
use crate::template_callback::PluginTemplateCallback;
use base64::Engine;
@@ -17,6 +17,7 @@ use yaak_templates::{FnArg, Parser, Token, Tokens, Val, transform_args};
pub(crate) fn template_function_secure() -> TemplateFunction {
TemplateFunction {
name: "secure".to_string(),
preview_type: Some(TemplateFunctionPreviewType::None),
description: Some("Securely store encrypted text".to_string()),
aliases: None,
args: vec![TemplateFunctionArg::FormInput(FormInput::Text(
@@ -37,6 +38,7 @@ pub(crate) fn template_function_secure() -> TemplateFunction {
pub(crate) fn template_function_keyring() -> TemplateFunction {
TemplateFunction {
name: "keychain".to_string(),
preview_type: Some(TemplateFunctionPreviewType::Live),
description: Some("Get a password from the OS keychain or keyring".to_string()),
aliases: Some(vec!["keyring".to_string()]),
args: vec![