🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(automations): remove API version dropdown from webhook actions (#15755)
Mark Salpeter6982ff837608
diff --git a/web/src/features/automations/components/actions/BaseActionHandler.ts b/web/src/features/automations/components/actions/BaseActionHandler.tsindex 15c976d7ef..824c68706b 100644--- a/web/src/features/automations/components/actions/BaseActionHandler.ts+++ b/web/src/features/automations/components/actions/BaseActionHandler.ts@@ -24,8 +24,13 @@ export interface BaseActionHandler<errors?: string[];};- // Build the action config for API submission- buildActionConfig(formData: TFormData): ActionCreate;+ // Build the action config for API submission. `eventSource` is passed for+ // action types whose config depends on the trigger (webhooks derive their+ // payload apiVersion from it); other handlers ignore it.+ buildActionConfig(+ formData: TFormData,+ eventSource?: TriggerEventSource,+ ): ActionCreate;// Render the action form UI - using any for form to allow flexibilityrenderForm(props: {diff --git a/web/src/features/automations/components/actions/WebhookActionForm.tsx b/web/src/features/automations/components/actions/WebhookActionForm.tsxindex e87dfb5c75..e58bd13010 100644--- a/web/src/features/automations/components/actions/WebhookActionForm.tsx+++ b/web/src/features/automations/components/actions/WebhookActionForm.tsx@@ -8,20 +8,12 @@ import {FormLabel,FormMessage,} from "@/src/components/ui/form";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/src/components/ui/select";import { X, Plus, RefreshCw, Lock, LockOpen } from "lucide-react";import { useFieldArray, type UseFormReturn } from "react-hook-form";import { z } from "zod";import {type ActionDomain,type ActionDomainWithSecrets,- AvailableWebhookApiSchema,type SafeWebhookActionConfig,WebhookDefaultHeaders,WebhookProtectedHeaders,@@ -66,7 +58,6 @@ export const webhookSchema = z.object({wasSecret: z.boolean(),}),),- apiVersion: AvailableWebhookApiSchema,});export type WebhookFormValues = z.infer<typeof webhookSchema>;@@ -143,35 +134,6 @@ export const WebhookActionForm: React.FC<WebhookActionFormProps> = ({)}/>- <FormField- control={form.control}- name="webhook.apiVersion.prompt"- render={({ field }) => (- <FormItem>- <FormLabel>API Version</FormLabel>- <Select- onValueChange={field.onChange}- value={field.value}- disabled={disabled}- >- <FormControl>- <SelectTrigger>- <SelectValue placeholder="Select API version" />- </SelectTrigger>- </FormControl>- <SelectContent>- <SelectItem value="v1">v1</SelectItem>- </SelectContent>- </Select>- <FormDescription>- The API version to use for the webhook payload format when prompt- events are triggered.- </FormDescription>- <FormMessage />- </FormItem>- )}- />-<div><FormLabel>Headers</FormLabel>diff --git a/web/src/features/automations/components/actions/WebhookActionHandler.clienttest.ts b/web/src/features/automations/components/actions/WebhookActionHandler.clienttest.tsindex bab9cbe01d..cb06d8598d 100644--- a/web/src/features/automations/components/actions/WebhookActionHandler.clienttest.ts+++ b/web/src/features/automations/components/actions/WebhookActionHandler.clienttest.ts@@ -1,62 +1,43 @@import { describe, expect, it } from "vitest";-import { type AutomationDomain, TriggerEventSource } from "@langfuse/shared";+import { TriggerEventSource } from "@langfuse/shared";import { WebhookActionHandler } from "./WebhookActionHandler";const handler = new WebhookActionHandler();-const webhookAutomation = (- apiVersion: Record<string, "v1">,-): AutomationDomain =>- ({- id: "automation-1",- name: "test",- trigger: {- id: "trigger-1",- eventSource: TriggerEventSource.Monitor,- eventActions: ["created"],- filter: [],- status: "ACTIVE",- },- action: {- id: "action-1",- type: "WEBHOOK",- config: {- type: "WEBHOOK",- url: "https://example.com",- apiVersion,- displaySecretKey: "sk_...abcd",- },- },- }) as unknown as AutomationDomain;--describe("WebhookActionHandler.getDefaultValues", () => {- it("monitor-source new automation: seeds apiVersion { monitor: v1 }", () => {- expect(- handler.getDefaultValues(undefined, TriggerEventSource.Monitor).webhook- .apiVersion,- ).toEqual({ monitor: "v1" });+const formData = {+ webhook: {+ url: "https://example.com/hook",+ headers: [],+ },+};++const apiVersionFor = (eventSource?: TriggerEventSource) => {+ const config = handler.buildActionConfig(formData, eventSource);+ if (config.type !== "WEBHOOK") throw new Error("expected webhook config");+ return config.apiVersion;+};++// apiVersion is not user-editable; it is derived from the trigger's event+// source at submit time so it cannot drift when the source changes.+describe("WebhookActionHandler.buildActionConfig apiVersion", () => {+ it("monitor source: derives { monitor: v1 }", () => {+ expect(apiVersionFor(TriggerEventSource.Monitor)).toEqual({+ monitor: "v1",+ });});- it("prompt-source new automation: seeds apiVersion { prompt: v1 }", () => {- expect(- handler.getDefaultValues(undefined, TriggerEventSource.Prompt).webhook- .apiVersion,- ).toEqual({ prompt: "v1" });+ it("prompt source: derives { prompt: v1 }", () => {+ expect(apiVersionFor(TriggerEventSource.Prompt)).toEqual({ prompt: "v1" });});- it("no eventSource: seeds apiVersion { prompt: v1 }", () => {- expect(handler.getDefaultValues(undefined).webhook.apiVersion).toEqual({- prompt: "v1",+ it("project-notification source: derives { project-notification: v1 }", () => {+ expect(apiVersionFor(TriggerEventSource.ProjectNotification)).toEqual({+ "project-notification": "v1",});});- it("editing existing config: stored apiVersion wins over eventSource", () => {- expect(- handler.getDefaultValues(- webhookAutomation({ monitor: "v1" }),- TriggerEventSource.Prompt,- ).webhook.apiVersion,- ).toEqual({ monitor: "v1" });+ it("no eventSource: falls back to { prompt: v1 }", () => {+ expect(apiVersionFor(undefined)).toEqual({ prompt: "v1" });});});diff --git a/web/src/features/automations/components/actions/WebhookActionHandler.tsx b/web/src/features/automations/components/actions/WebhookActionHandler.tsxindex 614bd254b8..b4db68bd93 100644--- a/web/src/features/automations/components/actions/WebhookActionHandler.tsx+++ b/web/src/features/automations/components/actions/WebhookActionHandler.tsx@@ -4,7 +4,7 @@ import { type BaseActionHandler } from "./BaseActionHandler";import { WebhookActionForm, formatWebhookHeaders } from "./WebhookActionForm";import {type AutomationDomain,- AvailableWebhookApiSchema,+ type AvailableWebhookApiSchema,WebhookProtectedHeaders,TriggerEventSource,type ActionCreate,@@ -29,12 +29,30 @@ export const WebhookActionFormSchema = z.object({}),).default([]),- apiVersion: AvailableWebhookApiSchema.default({ prompt: "v1" }),}),});type WebhookActionFormData = z.infer<typeof WebhookActionFormSchema>;+/**+ * apiVersionForEventSource derives the stored webhook payload version from the+ * trigger's event source. There is only one version per source today, so this+ * is not user-editable and is deliberately not part of the form state — keeping+ * it derived is what stops it from drifting when the event source changes.+ */+const apiVersionForEventSource = (+ eventSource?: TriggerEventSource,+): z.infer<typeof AvailableWebhookApiSchema> => {+ switch (eventSource) {+ case TriggerEventSource.Monitor:+ return { monitor: "v1" };+ case TriggerEventSource.ProjectNotification:+ return { "project-notification": "v1" };+ default:+ return { prompt: "v1" };+ }+};+// Define a type for header pairstype HeaderPair = {name: string;@@ -73,26 +91,7 @@ export class WebhookActionHandler implements BaseActionHandler<WebhookActionFormreturn [];}- getDefaultValues(- automation?: AutomationDomain,- eventSource?: TriggerEventSource,- ): WebhookActionFormData {- // Extract apiVersion from existing config- let apiVersion: z.infer<typeof AvailableWebhookApiSchema> =- eventSource === TriggerEventSource.Monitor- ? { monitor: "v1" }- : eventSource === TriggerEventSource.ProjectNotification- ? { "project-notification": "v1" }- : { prompt: "v1" };- if (- automation?.action?.type === "WEBHOOK" &&- automation?.action?.config &&- "apiVersion" in automation.action.config &&- automation.action.config.apiVersion- ) {- apiVersion = automation.action.config.apiVersion;- }-+ getDefaultValues(automation?: AutomationDomain): WebhookActionFormData {return {webhook: {url:@@ -102,7 +101,6 @@ export class WebhookActionHandler implements BaseActionHandler<WebhookActionFormautomation.action.config.url) ||"",headers: this.parseHeaders(automation),- apiVersion,},};}@@ -166,7 +164,10 @@ export class WebhookActionHandler implements BaseActionHandler<WebhookActionForm};}- buildActionConfig(formData: WebhookActionFormData): ActionCreate {+ buildActionConfig(+ formData: WebhookActionFormData,+ eventSource?: TriggerEventSource,+ ): ActionCreate {// Convert headers array to requestHeaders formatlet headersObject: Record<string, { secret: boolean; value: string }> = {};@@ -178,7 +179,7 @@ export class WebhookActionHandler implements BaseActionHandler<WebhookActionFormtype: "WEBHOOK",url: formData.webhook?.url || "",requestHeaders: headersObject,- apiVersion: formData.webhook?.apiVersion || { prompt: "v1" },+ apiVersion: apiVersionForEventSource(eventSource),};}diff --git a/web/src/features/automations/components/automationForm.clienttest.tsx b/web/src/features/automations/components/automationForm.clienttest.tsxindex 3e78cac289..cce5aaf0c3 100644--- a/web/src/features/automations/components/automationForm.clienttest.tsx+++ b/web/src/features/automations/components/automationForm.clienttest.tsx@@ -25,11 +25,25 @@ vi.mock("@/src/utils/api", () => ({useQuery: () => ({ data: undefined }),},},+ // Pulled in by the prompt-source filter builder.+ projects: { byId: { useQuery: () => ({ data: undefined }) } },+ naturalLanguageFilters: {+ createCompletion: { useMutation: () => ({ mutateAsync: vi.fn() }) },+ },},}));+vi.mock("next-auth/react", () => ({+ useSession: () => ({ data: undefined, status: "unauthenticated" }),+}));+vi.mock("next/router", () => ({- useRouter: () => ({ asPath: "/", push: vi.fn() }),+ // query.projectId is read by the prompt-source filter builder.+ useRouter: () => ({+ asPath: "/",+ push: vi.fn(),+ query: { projectId: "p1" },+ }),}));vi.mock("@/src/features/rbac/utils/checkProjectAccess", () => ({@@ -40,6 +54,11 @@ vi.mock("@/src/features/feature-flags/hooks/useIsFeatureEnabled", () => ({default: () => true,}));+// Cloud-only: the Monitor option in the event-source picker is gated on this.+vi.mock("@/src/features/organizations/hooks", () => ({+ useLangfuseCloudRegion: () => ({ isLangfuseCloud: true, region: "US" }),+}));+import { AutomationForm } from "./automationForm";describe("AutomationForm handleActionTypeChange", () => {@@ -73,7 +92,7 @@ describe("AutomationForm handleActionTypeChange", () => {/>,);- // comboboxes: [0] eventSource, [1] actionType, [2] webhook apiVersion.+ // comboboxes: [0] eventSource, [1] actionType.fireEvent.click(screen.getAllByRole("combobox")[1]);fireEvent.click(await screen.findByRole("option", { name: "Slack" }));@@ -96,4 +115,47 @@ describe("AutomationForm handleActionTypeChange", () => {const payload = createAutomationMutateAsync.mock.calls[0][0];expect(payload.actionConfig.apiVersion).toEqual({ monitor: "v1" });});++ it("switching event source from prompt to monitor derives apiVersion monitor", async () => {+ render(+ <AutomationForm+ projectId="p1"+ isEditing={true}+ prefill={{ actionType: "WEBHOOK" }}+ />,+ );++ // comboboxes: [0] eventSource, [1] actionType.+ fireEvent.click(screen.getAllByRole("combobox")[0]);+ fireEvent.click(await screen.findByRole("option", { name: "Monitor" }));++ fireEvent.change(screen.getByPlaceholderText(/automation name/i), {+ target: { value: "My automation" },+ });+ fireEvent.change(screen.getByPlaceholderText(/https/i), {+ target: { value: "https://example.com/hook" },+ });++ fireEvent.click(screen.getByRole("button", { name: /save automation/i }));++ await waitFor(() => {+ expect(createAutomationMutateAsync).toHaveBeenCalledTimes(1);+ });++ const payload = createAutomationMutateAsync.mock.calls[0][0];+ expect(payload.actionConfig.apiVersion).toEqual({ monitor: "v1" });+ });++ it("does not render an API version control for webhook actions", () => {+ render(+ <AutomationForm+ projectId="p1"+ isEditing={true}+ prefill={{ actionType: "WEBHOOK" }}+ />,+ );++ expect(screen.queryByText("API Version")).toBeNull();+ expect(screen.queryByText("Select API version")).toBeNull();+ });});diff --git a/web/src/features/automations/components/automationForm.tsx b/web/src/features/automations/components/automationForm.tsxindex d875a921a7..35321a363b 100644--- a/web/src/features/automations/components/automationForm.tsx+++ b/web/src/features/automations/components/automationForm.tsx@@ -464,19 +464,13 @@ export const AutomationForm = ({if (actionType === "WEBHOOK") {// Use action handler to get default values with proper typingconst handler = ActionHandlerRegistry.getHandler("WEBHOOK");- const webhookDefaults = handler.getDefaultValues(- automation,- resolvedEventSource,- );+ const webhookDefaults = handler.getDefaultValues(automation);return {...baseValues,actionType: "WEBHOOK" as const,webhook: {url: webhookDefaults.webhook.url || "",headers: webhookDefaults.webhook.headers || [],- apiVersion: webhookDefaults.webhook.apiVersion || {- prompt: "v1" as const,- },},};} else if (actionType === "SLACK") {@@ -539,7 +533,10 @@ export const AutomationForm = ({return;}- const actionConfig = handler.buildActionConfig(data);+ const actionConfig = handler.buildActionConfig(+ data,+ data.eventSource as TriggerEventSource,+ );// Project-notification names are auto-generated from the destination (the// name field is hidden for this source; regenerated on every save so the@@ -605,10 +602,7 @@ export const AutomationForm = ({if (value === "WEBHOOK") {const handler = ActionHandlerRegistry.getHandler("WEBHOOK");- const defaultValues = handler.getDefaultValues(- undefined,- form.getValues("eventSource") as TriggerEventSource,- );+ const defaultValues = handler.getDefaultValues();form.setValue("webhook", defaultValues.webhook);} else if (value === "SLACK") {const handler = ActionHandlerRegistry.getHandler("SLACK");