* feat: add OR logic support to kafka/websocket trigger filters Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref for OR logic filter support Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: add filter_logic to OpenAPI spec/save utils, fix websocket derive, show capture group ID - Add filter_logic field to all 6 Kafka/WebSocket OpenAPI schemas so it is included in the generated frontend client types - Include filter_logic in save request bodies (kafka/utils.ts, websocket/utils.ts) - Fix misplaced #[derive(FromRow)] on WebsocketConfig (was on the default fn) - Show copyable "Test group ID" in Kafka capture UI - Remove capture event-loss warning for Kafka (uses separate consumer group) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * update sqlx * update ee ref * chore: regenerate system prompts for filter_logic schema changes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove banned $bindable(default_value) pattern in TriggerFilters Use $bindable() without default and $derived with ?? for the effective value, per CLAUDE.md rules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: make filterLogic prop required in TriggerFilters All callers always pass it, no need for optional + derived fallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref to 5ee1382dfb23b6a1516e3c7586058cec8240fdf2 This commit updates the EE repository reference after PR #498 was merged in windmill-ee-private. Previous ee-repo-ref: bbd674991c07bff1cb2f3744e71fda10df53f09d New ee-repo-ref: 5ee1382dfb23b6a1516e3c7586058cec8240fdf2 Automated by sync-ee-ref workflow. * fix: reset filterLogic to 'and' in openNew for kafka/websocket editors Prevents stale OR logic from carrying over when creating a new trigger after editing one with OR filters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: hugocasa <hugo@casademont.ch> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
135 lines
3.8 KiB
Rust
135 lines
3.8 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::value::RawValue;
|
|
use sqlx::{types::Json as SqlxJson, FromRow};
|
|
use windmill_api_auth::ApiAuthed;
|
|
use windmill_common::{
|
|
error::{Error, Result},
|
|
jobs::JobTriggerKind,
|
|
triggers::{TriggerKind, TriggerMetadata},
|
|
worker::to_raw_value,
|
|
DB,
|
|
};
|
|
use windmill_queue::PushArgsOwned;
|
|
use windmill_trigger::trigger_helpers::{
|
|
trigger_runnable_and_wait_for_raw_result_with_error_ctx, TriggerJobArgs,
|
|
};
|
|
|
|
pub mod handler;
|
|
pub mod listener;
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub struct WebsocketTrigger;
|
|
|
|
impl TriggerJobArgs for WebsocketTrigger {
|
|
type Payload = String;
|
|
const TRIGGER_KIND: TriggerKind = TriggerKind::Websocket;
|
|
fn v1_payload_fn(payload: &Self::Payload) -> HashMap<String, Box<RawValue>> {
|
|
HashMap::from([("msg".to_string(), to_raw_value(&payload))])
|
|
}
|
|
}
|
|
|
|
fn default_filter_logic() -> String {
|
|
"and".to_string()
|
|
}
|
|
|
|
#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
|
|
pub struct WebsocketConfig {
|
|
pub url: String,
|
|
#[serde(default)]
|
|
pub filters: Vec<SqlxJson<Box<RawValue>>>,
|
|
#[serde(default = "default_filter_logic")]
|
|
pub filter_logic: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub initial_messages: Option<Vec<SqlxJson<Box<RawValue>>>>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub url_runnable_args: Option<SqlxJson<Box<RawValue>>>,
|
|
#[serde(default)]
|
|
pub can_return_message: bool,
|
|
#[serde(default)]
|
|
pub can_return_error_result: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct WebsocketConfigRequest {
|
|
url: String,
|
|
filters: Vec<serde_json::Value>,
|
|
#[serde(default = "default_filter_logic")]
|
|
filter_logic: String,
|
|
initial_messages: Option<Vec<serde_json::Value>>,
|
|
url_runnable_args: Option<serde_json::Value>,
|
|
can_return_message: bool,
|
|
can_return_error_result: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct TestWebsocketConfig {
|
|
url: String,
|
|
url_runnable_args: Option<serde_json::Value>,
|
|
}
|
|
|
|
pub fn value_to_args_hashmap(
|
|
args: Option<&Box<RawValue>>,
|
|
) -> Result<HashMap<String, Box<RawValue>>> {
|
|
let args = if let Some(args) = args {
|
|
let args_map: Option<HashMap<String, serde_json::Value>> = serde_json::from_str(args.get())
|
|
.map_err(|e| Error::BadRequest(format!("invalid json: {}", e)))?;
|
|
|
|
args_map
|
|
.unwrap_or_else(HashMap::new)
|
|
.into_iter()
|
|
.map(|(k, v)| {
|
|
let raw_value = serde_json::value::to_raw_value(&v).map_err(|e| {
|
|
Error::BadRequest(format!("failed to convert to raw value: {}", e))
|
|
})?;
|
|
Ok((k, raw_value))
|
|
})
|
|
.collect::<Result<HashMap<String, Box<RawValue>>>>()
|
|
} else {
|
|
Ok(HashMap::new())
|
|
}?;
|
|
Ok(args)
|
|
}
|
|
|
|
pub async fn get_url_from_runnable_value(
|
|
path: &str,
|
|
is_flow: bool,
|
|
db: &DB,
|
|
authed: ApiAuthed,
|
|
args: Option<&Box<RawValue>>,
|
|
workspace_id: &str,
|
|
) -> Result<String> {
|
|
tracing::info!(
|
|
"Running {} {} to get WebSocket URL",
|
|
if is_flow { "flow" } else { "script" },
|
|
path
|
|
);
|
|
|
|
let args = value_to_args_hashmap(args)?;
|
|
|
|
let result = trigger_runnable_and_wait_for_raw_result_with_error_ctx(
|
|
db,
|
|
None,
|
|
authed,
|
|
workspace_id,
|
|
path,
|
|
is_flow,
|
|
PushArgsOwned { args, extra: None },
|
|
None,
|
|
None,
|
|
None,
|
|
"".to_string(), // doesn't matter as no retry/error handler
|
|
TriggerMetadata::new(Some(path.to_owned()), JobTriggerKind::Websocket),
|
|
)
|
|
.await?;
|
|
|
|
serde_json::from_str::<String>(result.get()).map_err(|_| {
|
|
Error::BadConfig(format!(
|
|
"{} {} did not return a string",
|
|
if is_flow { "Flow" } else { "Script" },
|
|
path,
|
|
))
|
|
})
|
|
}
|