🪢 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): filter prompt events by label (#17612)
tobi_klcfdd5daa7f8f
diff --git a/packages/shared/src/tableDefinitions/promptsTable.ts b/packages/shared/src/tableDefinitions/promptsTable.tsindex 6f20ca3805..a2f1801605 100644--- a/packages/shared/src/tableDefinitions/promptsTable.ts+++ b/packages/shared/src/tableDefinitions/promptsTable.ts@@ -81,6 +81,10 @@ export function promptsTableColsWithOptions(});}-export function webhookActionFilterOptions(): ColumnDefinition[] {- return promptsTableCols.filter((col) => col.id === "name");+export function webhookActionFilterOptions(+ labels: SingleValueOption[] = [],+): ColumnDefinition[] {+ return promptsTableColsWithOptions({ labels, tags: [] }).filter((col) =>+ ["name", "labels"].includes(col.id),+ );}diff --git a/web/src/features/automations/components/automationForm.clienttest.tsx b/web/src/features/automations/components/automationForm.clienttest.tsxindex dff3b80317..fdec59abb8 100644--- a/web/src/features/automations/components/automationForm.clienttest.tsx+++ b/web/src/features/automations/components/automationForm.clienttest.tsx@@ -26,6 +26,9 @@ vi.mock("@/src/utils/api", () => ({},},// Pulled in by the prompt-source filter builder.+ prompts: {+ allLabels: { useQuery: () => ({ data: [], isFetching: false }) },+ },projects: { byId: { useQuery: () => ({ data: undefined }) } },naturalLanguageFilters: {createCompletion: { useMutation: () => ({ mutateAsync: vi.fn() }) },diff --git a/web/src/features/automations/components/automationForm.tsx b/web/src/features/automations/components/automationForm.tsxindex 495ede1eb8..6571584252 100644--- a/web/src/features/automations/components/automationForm.tsx+++ b/web/src/features/automations/components/automationForm.tsx@@ -267,75 +267,92 @@ const EventSourceField = ({/** PromptTriggerFields renders the eventAction picker and inline filter builder for prompt-source automations. */const PromptTriggerFields = ({+ projectId,control,disabled,}: {+ projectId: string;control: Control<FormValues>;disabled: boolean;-}) => (- <>- <FormField- control={control}- name="eventAction"- render={({ field }) => (- <FormItem>- <FormLabel>Event Action</FormLabel>- <FormControl>- <MultiSelect- title="Event Actions"- label="Actions"- values={field.value}- onValueChange={field.onChange}- options={[- {- value: "created",- description: "Whenever a new prompt version is created",- },- {- value: "updated",- description:- "Whenever tags or labels on a prompt version are updated",- },- {- value: "deleted",- description: "Whenever a prompt version is deleted",- },- ]}- className="my-0 w-auto overflow-hidden"- disabled={disabled}- labelTruncateCutOff={4}- />- </FormControl>- <FormDescription>- The actions on the event source that trigger this automation.- </FormDescription>- <FormMessage />- </FormItem>- )}- />- <FormField- control={control}- name="filter"- render={({ field }) => (- <FormItem>- <FormLabel>Filter</FormLabel>- <FormControl>- <InlineFilterBuilder- columns={webhookActionFilterOptions()}- filterState={field.value || []}- onChange={field.onChange}- disabled={disabled}- />- </FormControl>- <FormDescription>- Add conditions to narrow down when this trigger fires.- </FormDescription>- <FormMessage />- </FormItem>- )}- />- </>-);+}) => {+ const [labelsOpened, setLabelsOpened] = React.useState(false);+ const { data: labels = [], isFetching: labelsLoading } =+ api.prompts.allLabels.useQuery({ projectId }, { enabled: labelsOpened });++ return (+ <>+ <FormField+ control={control}+ name="eventAction"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Event Action</FormLabel>+ <FormControl>+ <MultiSelect+ title="Event Actions"+ label="Actions"+ values={field.value}+ onValueChange={field.onChange}+ options={[+ {+ value: "created",+ description: "Whenever a new prompt version is created",+ },+ {+ value: "updated",+ description:+ "Whenever tags or labels on a prompt version are updated",+ },+ {+ value: "deleted",+ description: "Whenever a prompt version is deleted",+ },+ ]}+ className="my-0 w-auto overflow-hidden"+ disabled={disabled}+ labelTruncateCutOff={4}+ />+ </FormControl>+ <FormDescription>+ The actions on the event source that trigger this automation.+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={control}+ name="filter"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Filter</FormLabel>+ <FormControl>+ <InlineFilterBuilder+ columns={webhookActionFilterOptions(+ labels.map((value) => ({ value })),+ )}+ columnsWithCustomSelect={["labels"]}+ loadingOptionColumns={labelsLoading ? ["labels"] : []}+ onOptionsOpen={(columnId) => {+ if (columnId === "labels") {+ setLabelsOpened(true);+ }+ }}+ filterState={field.value || []}+ onChange={field.onChange}+ disabled={disabled}+ />+ </FormControl>+ <FormDescription>+ Add conditions to narrow down when this trigger fires.+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ </>+ );+};/** MonitorTriggerFields renders an info card explaining that monitors connect to this automation via the create-monitor page. */const MonitorTriggerFields = ({ projectId }: { projectId: string }) => (@@ -731,6 +748,7 @@ export const AutomationForm = ({<MonitorTriggerFields projectId={projectId} />) : (<PromptTriggerFields+ projectId={projectId}control={form.control}disabled={!hasAccess || !isEditing}/>diff --git a/web/src/features/filters/components/filter-builder.tsx b/web/src/features/filters/components/filter-builder.tsxindex 0aebf24f65..0d52df8025 100644--- a/web/src/features/filters/components/filter-builder.tsx+++ b/web/src/features/filters/components/filter-builder.tsx@@ -447,6 +447,8 @@ export function InlineFilterBuilder({columnIdentifier = "name",disabled,columnsWithCustomSelect,+ onOptionsOpen,+ loadingOptionColumns = [],columnsHiddenUnlessSelected,stringObjectValueOptions,onStringObjectKeyChange,@@ -462,6 +464,8 @@ export function InlineFilterBuilder({columnIdentifier?: ColumnIdentifier;disabled?: boolean;columnsWithCustomSelect?: string[];+ onOptionsOpen?: (columnId: string) => void;+ loadingOptionColumns?: string[];/*** Column ids/names that stay in the picker only for rows that already use* them. Used to grandfather retired columns without offering them on new rows.@@ -520,6 +524,8 @@ export function InlineFilterBuilder({onChange={setWipFilterState}disabled={disabled}columnsWithCustomSelect={columnsWithCustomSelect}+ onOptionsOpen={onOptionsOpen}+ loadingOptionColumns={loadingOptionColumns}columnsHiddenUnlessSelected={columnsHiddenUnlessSelected}stringObjectValueOptions={stringObjectValueOptions}onStringObjectKeyChange={onStringObjectKeyChange}@@ -567,6 +573,8 @@ function FilterBuilderForm({onChange,disabled,columnsWithCustomSelect = [],+ onOptionsOpen,+ loadingOptionColumns = [],columnsHiddenUnlessSelected = [],stringObjectValueOptions = {},onStringObjectKeyChange,@@ -580,6 +588,8 @@ function FilterBuilderForm({onChange: Dispatch<SetStateAction<WipFilterState>>;disabled?: boolean;columnsWithCustomSelect?: string[];+ onOptionsOpen?: (columnId: string) => void;+ loadingOptionColumns?: string[];/*** Column ids/names that stay in the picker only for rows that already use* them. Used to grandfather retired columns without offering them on new rows.@@ -1020,6 +1030,10 @@ function FilterBuilderForm({chipsOnly={compact}className="min-w-[100px]"options={column?.type === filter.type ? column.options : []}+ isLoading={!!column && loadingOptionColumns.includes(column.id)}+ onOpenChange={(open) => {+ if (open && column) onOptionsOpen?.(column.id);+ }}onValueChange={(value) => handleFilterChange({ ...filter, value }, i)}values={Array.isArray(filter.value) ? filter.value : []}disabled={disabled}diff --git a/web/src/features/filters/components/multi-select.tsx b/web/src/features/filters/components/multi-select.tsxindex 27692be614..f6a7355e96 100644--- a/web/src/features/filters/components/multi-select.tsx+++ b/web/src/features/filters/components/multi-select.tsx@@ -1,6 +1,6 @@/* eslint-disable @repo/no-style-props, @repo/no-abstracted-overlay-trigger */import * as React from "react";-import { Check, ChevronDown } from "lucide-react";+import { Check, ChevronDown, Loader2 } from "lucide-react";import { cn } from "@/src/utils/tailwind";import { Badge } from "@/src/components/ui/badge";@@ -48,6 +48,8 @@ export function MultiSelect({isCustomSelectEnabled = false,labelTruncateCutOff = 2,chipsOnly = false,+ onOpenChange,+ isLoading = false,}: {title?: string;label?: string;@@ -60,6 +62,8 @@ export function MultiSelect({labelTruncateCutOff?: number;/** chipsOnly hides the placeholder/separator once values are selected, showing just the chips and chevron. */chipsOnly?: boolean;+ onOpenChange?: (open: boolean) => void;+ isLoading?: boolean;}) {const selectedValues = useMemo(() => new Set(values), [values]);const optionValues = new Set(options.map((option) => option.value));@@ -170,7 +174,7 @@ export function MultiSelect({);return (- <Popover>+ <Popover onOpenChange={onOpenChange}><PopoverTrigger asChild><Buttonvariant="outline"@@ -213,16 +217,33 @@ export function MultiSelect({</PopoverTrigger><PopoverContent className="w-[200px] p-0" align="center"><InputCommand>- <InputCommandInput placeholder={title} variant="bottom" />+ <InputCommandInput+ placeholder={title}+ variant="bottom"+ disabled={isLoading}+ /><InputCommandList>+ {isLoading && (+ <div+ role="status"+ className="text-muted-foreground flex items-center gap-2 px-3 py-2 text-sm"+ >+ <Loader2 className="h-4 w-4 animate-spin" aria-hidden="true" />+ Loading…+ </div>+ )}{/* if isCustomSelectEnabled we always show custom select hence never empty */}- {!isCustomSelectEnabled && (+ {!isCustomSelectEnabled && !isLoading && (<InputCommandEmpty>No results found.</InputCommandEmpty>)}<InputCommandGroup>{showSelectAll && (<>- <InputCommandItem key="select-all" onSelect={handleSelectAll}>+ <InputCommandItem+ key="select-all"+ onSelect={handleSelectAll}+ disabled={isLoading}+ ><divclassName={cn("border-control-border mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",@@ -253,6 +274,7 @@ export function MultiSelect({const commandItem = (<InputCommandItemkey={option.value}+ disabled={isLoading}onSelect={() => {if (isSelected) {selectedValues.delete(option.value);@@ -308,6 +330,7 @@ export function MultiSelect({<InputCommandSeparator /><InputCommandItemkey="freeTextField"+ disabled={isLoading}onSelect={() => {const freeTextInput = getFreeTextInput(isCustomSelectEnabled,@@ -343,6 +366,7 @@ export function MultiSelect({</div><Inputtype="text"+ disabled={isLoading}value={freeText}onChange={(e) => {setFreeText(e.target.value);@@ -367,6 +391,7 @@ export function MultiSelect({<InputCommandSeparator /><InputCommandGroup><InputCommandItem+ disabled={isLoading}onSelect={() => onValueChange([])}className="justify-center text-center">diff --git a/worker/src/features/entityChange/promptVersionProcessor.ts b/worker/src/features/entityChange/promptVersionProcessor.tsindex 77b78fe34f..6fd1fc1b31 100644--- a/worker/src/features/entityChange/promptVersionProcessor.ts+++ b/worker/src/features/entityChange/promptVersionProcessor.ts@@ -51,7 +51,11 @@ export const promptVersionProcessor = async (for (const trigger of triggers) {try {const eventMatches = matchesTriggerFilter(- { Name: event.prompt.name, action: event.action },+ {+ Name: event.prompt.name,+ Labels: event.prompt.labels,+ action: event.action,+ },trigger,);