/** * Event triggers as people edit and read them: the editable draft, the * request it becomes, validation in the product's words, and short summaries * for rows and pages. Pure; every automation surface shares it. Words come * from the host's message catalog, so each function that returns text takes * the `t` of `useOpenGeniText()` first. */ import { DEFAULT_EVENT_RUNS_PER_HOUR, EVENT_TRIGGER_CONDITIONS_MAX, EVENT_TRIGGER_TYPES_MAX, EVENT_TRIGGERS_PER_AUTOMATION_MAX, MAX_EVENT_RUNS_PER_HOUR } from "@opengeni/contracts/event-triggers"; import type { AutomationTemplateEventSource, EventCondition, EventConditionOperator, EventSource, EventTrigger, EventTypeDescriptor, ScheduledTaskEvents, ScheduledTaskEventsInput } from "@opengeni/sdk"; import type { OpenGeniText } from "../../messages/runtime.js"; export { DEFAULT_EVENT_RUNS_PER_HOUR, EVENT_TRIGGER_CONDITIONS_MAX, EVENT_TRIGGER_TYPES_MAX, EVENT_TRIGGERS_PER_AUTOMATION_MAX, MAX_EVENT_RUNS_PER_HOUR, }; /** One condition while it is edited; `value` stays the text a person typed. */ export interface EventConditionDraft { key: string; field: string; op: EventConditionOperator; value: string; } /** One event trigger while it is edited. */ export interface EventTriggerDraft { /** Stable across edits, for list keys and error lookup. */ key: string; sourceId: string; eventTypes: string[]; conditions: EventConditionDraft[]; includeOwnEvents: boolean; /** MCP subscription arguments as JSON text; empty for none. */ argumentsText: string; /** * The kind of source a template asked this trigger to listen on, while the * person has none of that kind yet. Picking one of that kind keeps the * template's events; the editor offers to add one. */ templateSource?: AutomationTemplateEventSource | undefined; } /** An automation's event triggers and their run policy while they are edited. */ export interface EventTriggersDraft { triggers: EventTriggerDraft[]; /** Finish after the first run, whichever trigger fires first. */ once: boolean; /** The storm guard: at most this many event runs in a rolling hour. */ maxRunsPerHour: number; } export declare function emptyEventTriggersDraft(): EventTriggersDraft; /** A new trigger on `sourceId`, with no event types picked yet. */ export declare function newEventTriggerDraft(sourceId?: string): EventTriggerDraft; export declare function newEventConditionDraft(field?: string): EventConditionDraft; export declare function eventConditionDraftFrom(condition: EventCondition): EventConditionDraft; export declare function eventTriggerDraftFrom(trigger: Pick): EventTriggerDraft; /** The draft of a saved automation's events, or an empty draft when it has none. */ export declare function eventTriggersDraftFrom(events: ScheduledTaskEvents | null | undefined): EventTriggersDraft; export interface EventConditionOperatorOption { value: EventConditionOperator; /** What the value box holds; null when the operator takes no value. */ takes: "one" | "list" | null; } export declare const EVENT_CONDITION_OPERATORS: readonly EventConditionOperatorOption[]; export declare function eventConditionOperator(op: EventConditionOperator): EventConditionOperatorOption; /** How an operator reads after the field: "data.action is opened". */ export declare function eventConditionOperatorLabel(t: OpenGeniText, op: EventConditionOperator): string; /** The fields every event has, besides its app's own `data.*` fields. */ export declare function eventCommonFields(t: OpenGeniText): Array<{ field: string; description: string; }>; export declare function eventConditionFromDraft(draft: EventConditionDraft): EventCondition; /** The `events` field of a create or update request. */ export declare function eventTriggersInputFrom(draft: EventTriggersDraft): ScheduledTaskEventsInput; /** Whether two drafts would save the same triggers and policy. */ export declare function sameEventTriggers(left: EventTriggersDraft, right: EventTriggersDraft): boolean; export interface EventTriggerIssues { source?: string; eventTypes?: string; arguments?: string; /** By condition key. */ conditions?: Record; } export interface EventTriggersIssues { /** By trigger key. */ triggers: Record; maxRunsPerHour?: string; } /** Why an event type can't be saved, or null when it can. */ export declare function eventTypeIssue(t: OpenGeniText, type: string): string | null; export declare function validateEventTriggers(t: OpenGeniText, draft: EventTriggersDraft, sources: readonly Pick[]): EventTriggersIssues; export declare function hasEventTriggerIssues(issues: EventTriggersIssues): boolean; /** "Every event", "Every pull_request event" or the type itself. */ export declare function eventTypeLabel(t: OpenGeniText, type: string): string; /** "pull_request.opened", "pull_request.opened or issues.opened", "pull_request.opened and 2 more". */ export declare function eventTypesLabel(t: OpenGeniText, types: readonly string[]): string; /** "only when data.action is opened", or "only when 3 conditions hold". */ export declare function eventConditionsLabel(t: OpenGeniText, conditions: readonly EventCondition[]): string | null; export interface EventTriggerWords { /** The source's name, or "A source you can't see" when it is gone or hidden. */ source: string; /** The event types in words. */ events: string; /** The conditions in words, or null without any. */ conditions: string | null; /** "deploy.finished from Deploys", for rows. */ short: string; } export declare function eventTriggerWords(t: OpenGeniText, trigger: Pick, sources: readonly Pick[]): EventTriggerWords; /** One line for a list row: the first trigger, and how many more there are. */ export declare function eventTriggersShortLabel(t: OpenGeniText, triggers: readonly Pick[], sources: readonly Pick[]): string | null; /** The descriptor a source lists for exactly this type. */ export declare function eventTypeDescriptor(type: string, descriptors: readonly EventTypeDescriptor[]): EventTypeDescriptor | undefined; /** * Fields worth matching for the picked types: their app's own fields first, * then the fields every event has. Each field once. */ export declare function eventConditionFieldSuggestions(t: OpenGeniText, eventTypes: readonly string[], descriptors: readonly EventTypeDescriptor[]): Array<{ field: string; description: string; }>;