/** * Automations as people read and edit them: when one runs in words, its next * run, the name it gets when none is typed, and the draft a form edits with * the create and update requests it becomes. Pure; the Automations panel and * the web app's Automations pages share it. Words come from the host's message * catalog, so each function that returns text takes the `t` of * `useOpenGeniText()` first. */ import type { CreateScheduledTaskRequest, EventSource, ScheduledTask, ScheduledTaskRun, ScheduledTaskScheduleSpec, UpdateScheduledTaskRequest } from "@opengeni/sdk"; import type { OpenGeniText } from "../../messages/runtime.js"; import { type SessionAutomationWait, type SessionListRow } from "../../session-list-model.js"; import { type CadenceValue } from "../../ui/cadence-picker.js"; import { type EventTriggersDraft, type EventTriggersIssues } from "./event-trigger-model.js"; /** The viewer's IANA time zone, or UTC when the runtime can't tell. */ export declare function viewerTimeZone(): string; /** "Every weekday at 09:00, your time": where a new schedule starts. */ export declare function defaultAutomationCadence(timeZone?: string): CadenceValue; /** A stored schedule as an editable cadence; null when it has none (events or Run now only). */ export declare function automationCadence(schedule: ScheduledTaskScheduleSpec, fallbackTimeZone?: string): CadenceValue | null; /** The stored schedule for a cadence; no cadence stores `{ type: "manual" }`. */ export declare function automationScheduleSpec(cadence: CadenceValue | null, now: Date): ScheduledTaskScheduleSpec; export interface AutomationScheduleWords { /** "Every weekday at 08:00 · Oslo", for rows and meta lines. */ short: string; /** "Runs every weekday at 08:00 Oslo time", for sentences (no full stop). */ sentence: string; } /** A cadence in words. */ export declare function automationCadenceWords(t: OpenGeniText, cadence: CadenceValue, now: Date): AutomationScheduleWords; /** A stored schedule in words; one without a cadence runs only with Run now. */ export declare function automationScheduleWords(t: OpenGeniText, schedule: ScheduledTaskScheduleSpec, now: Date): AutomationScheduleWords; /** Whether a schedule problem stops the cadence from saving, in words; null when it saves. */ export declare function automationCadenceIssue(t: OpenGeniText, cadence: CadenceValue | null, now: Date): string | null; /** The cadence runs more than once; a run-once automation can't have one. */ export declare function automationCadenceRepeats(cadence: CadenceValue | null): boolean; type AutomationState = Pick; /** It has event triggers, so events can start it. */ export declare function hasEventTriggers(task: Pick): boolean; /** A run-once automation whose run happened: it no longer listens or runs. */ export declare function isFinishedOnce(task: Pick): boolean; /** Its next scheduled run, or null when it is paused, finished, or has no schedule or runs left. */ export declare function automationNextRun(task: AutomationState, now: Date): Date | null; /** Events can start it now: it is on, has triggers and has not finished. */ export declare function automationListensForEvents(task: AutomationState): boolean; /** An agent automation, as opposed to a knowledge source sync. */ export declare function isAgentAutomation(task: Pick & { agentConfig?: { knowledgeSource?: unknown; }; }): boolean; /** * Scheduled ones by next run (soonest first), then those waiting for events, * then everything that won't fire (paused, finished, Run now only) by name. */ export declare function sortAutomations>(tasks: readonly Task[], now: Date): Task[]; /** * When it runs, in one line: "Every weekday at 08:00 · Oslo", * "pull_request.opened from GitHub", or both. */ export declare function automationWhenWords(t: OpenGeniText, task: Pick, sources: readonly Pick[], now: Date): string; /** * When it runs, as a sentence: "Runs every weekday at 08:00 Oslo time, and * when a matching event arrives.", or "Runs once, on the first matching event." */ export declare function automationWhenSentence(t: OpenGeniText, task: Pick, now: Date): string; /** * The events a run carried, in a few words: the first event's summary and how * many more came with it. Null for a run no event started. */ export declare function automationRunEventsLabel(t: OpenGeniText, run: Pick): string | null; /** A run's outcome in a word: "Done", "Failed". */ export declare function automationRunStatusLabel(t: OpenGeniText, status: ScheduledTaskRun["status"]): string; /** What started a run: "On schedule", "Run now", "Event". */ export declare function automationRunTriggerLabel(t: OpenGeniText, triggerType: ScheduledTaskRun["triggerType"]): string; /** * Why a run failed or was skipped, as a sentence for people: "Skipped because * the chat was still busy with earlier work." Runs record a reason code; a * code this version doesn't know reads as a plain "something went wrong", never * as the code. An error recorded as a sentence passes through. */ export declare function automationRunErrorText(t: OpenGeniText, error: string): string; export declare const AUTOMATION_NAME_MAX_LENGTH = 80; /** * The name an automation gets when none is typed: the first sentence of the * instructions, without a leading "Every weekday at 08:00:" and at most 60 * characters, ending on a word that carries meaning. */ export declare function deriveAutomationName(instructions: string): string; /** What the Automations panel's form edits. */ export interface AutomationDraft { /** What the agent does on each run. */ instructions: string; /** Empty: named after the instructions. */ name: string; /** Null when it runs only on events or with Run now. */ cadence: CadenceValue | null; /** Its event triggers and their run policy; no triggers when it runs on a schedule only. */ events: EventTriggersDraft; } /** Where a new automation's runs go: on in one chat, or a new chat each run. */ export type AutomationDestination = { kind: "chat"; sessionId: string; } | { kind: "new_chat"; }; /** A blank draft. Without a `cadence` option it starts on the default schedule. */ export declare function newAutomationDraft(options?: { cadence?: CadenceValue | null; }): AutomationDraft; /** The draft of a saved automation. */ export declare function automationDraftFrom(task: Pick): AutomationDraft; /** The name it saves with: the typed one, else one from the instructions. */ export declare function automationName(t: OpenGeniText, draft: Pick): string; export interface AutomationDraftIssues { instructions?: string | undefined; name?: string | undefined; /** The schedule can't be saved as it is. */ cadence?: string | undefined; /** The schedule and events don't fit together. */ when?: string | undefined; events?: EventTriggersIssues | undefined; } export declare function validateAutomationDraft(t: OpenGeniText, draft: AutomationDraft, sources: readonly Pick[], now: Date): AutomationDraftIssues; export declare function hasAutomationDraftIssues(issues: AutomationDraftIssues): boolean; /** * The create request for a draft. One that continues a chat posts the * instructions there and runs with that chat's settings; one that starts a new * chat each run follows the workspace's default tools and machine at each run, * like a new chat, with the owner's access. Nothing is scoped down unless a * person chooses to elsewhere. */ export declare function automationCreateRequest(t: OpenGeniText, draft: AutomationDraft, destination: AutomationDestination, now: Date): CreateScheduledTaskRequest; /** * The PATCH for an edited draft: only what changed. Instructions use the * lossless `prompt` edit, so settings the form doesn't show stay as saved. */ export declare function automationUpdateRequest(t: OpenGeniText, initial: AutomationDraft, draft: AutomationDraft, now: Date): UpdateScheduledTaskRequest; export interface SessionAutomationWaitWords { /** An event can start a run (it wins when both apply), or only the schedule will. */ kind: SessionAutomationWait; /** * A sentence for a tooltip or hover card: "Waiting for deploy.finished from * Deploys or message.received from Gmail", "Next run: Tomorrow, 09:00" or * both. Servers without the details get the plain "Waiting for an event". */ label: string; /** A few words for a chip: "Waiting on Deploys and Gmail", "Next: Tomorrow, 09:00". */ short: string; } /** * What the automations posting into a chat are waiting for, in words, or null * when none of them will start a run. Times are in `timeZone` (the viewer's). */ export declare function sessionAutomationWaitWords(t: OpenGeniText, session: Pick, { now, timeZone }: { now: Date; timeZone?: string; }): SessionAutomationWaitWords | null; /** One thing a chat's automations wait for, for a line in a hover card. */ export interface SessionAutomationWaitLine { kind: SessionAutomationWait | "none"; /** "message.received from Gmail", "Next run: Tomorrow, 09:00", "Nothing upcoming". */ text: string; } /** * What a chat's automations wait for, one line per event and one for the * soonest run, so a hover card can list them. A chat whose automations are * all paused or finished gets one "Nothing upcoming" line. */ export declare function sessionAutomationWaitLines(t: OpenGeniText, session: Pick, { now, timeZone }: { now: Date; timeZone?: string; }): SessionAutomationWaitLine[]; export {};