import { IObservable } from "../../../../../base/common/observable.js"; import { CancellationToken } from "../../../../../base/common/cancellation.js"; import { URI } from "../../../../../base/common/uri.js"; import type { AutomationTriggerDefinition } from "../../../../../platform/github/common/missionControl/automations.js"; import { IAutomationCloudTrigger, IAutomationDescriptor, IAutomationRun, IAutomationSchedule, IAutomationSessionTemplate, AutomationTarget } from "./automation.js"; export declare const ConfigureAutomationToolReferenceName = "configureAutomation"; /** Provider-owned cloud configuration consumed by the Automation dialog and tools. */ export interface IAutomationProviderConfiguration { readonly sessionTypes: readonly string[]; readonly description: string; readonly timeZone: "UTC"; readonly targetChangeDisabledReason: string; /** The provider's selectable tools; loaded on demand by {@link loadTools} and cached by the provider. */ readonly tools: IObservable; /** Starts loading the tool catalog if it is not loaded or loading, retrying after a failure. */ loadTools(): void; readonly triggers?: IObservable; loadTriggers?(): void; pickWorkspace(token: CancellationToken): Promise; getWorkspaceTarget(workspace: URI | undefined): IObservable; } export interface IAutomationTool { readonly id: string; readonly label: string; readonly description?: string; } /** A provider-defined group of tools, in the provider's order. */ export interface IAutomationToolGroup { readonly id: string; readonly label: string; readonly tools: readonly IAutomationTool[]; } export type AutomationToolCatalog = { readonly kind: "loading"; } | { readonly kind: "ready"; readonly groups: readonly IAutomationToolGroup[]; } | { readonly kind: "error"; readonly message: string; }; export type AutomationTriggerCatalog = { readonly kind: "loading"; } | { readonly kind: "ready"; readonly definitions: readonly AutomationTriggerDefinition[]; } | { readonly kind: "error"; readonly message: string; }; /** A checked canonical workspace, or an explanation while checking or unavailable. */ export interface IAutomationWorkspaceTarget { readonly workspace?: URI; readonly repositoryLabel?: string; readonly disabledReason?: string; readonly pending?: boolean; readonly isRepository?: boolean; readonly isPrivateRepository?: boolean; readonly allowReadAccessTriggers?: boolean; } /** Catalogue completeness; only `ready` makes an empty snapshot authoritative. */ export type AutomationCatalogueState = "loading" | "ready" | "unavailable" | "error"; export declare function combineAutomationCatalogueStates(states: readonly AutomationCatalogueState[]): AutomationCatalogueState; /** * A caller-supplied check immediately before a definition mutation is dispatched; throwing prevents dispatch. * Rechecks transient client conditions, not host authorization or editable-state conflicts. */ export type AutomationMutationGuard = () => void; /** The selected Automation authority cannot currently accept the operation. */ export declare class AutomationUnavailableError extends Error { } /** Repository ownership is unavailable for the selected Automation target. */ export declare class AutomationRepositoryOwnershipUnavailableError extends Error { } /** The provider may have accepted a mutation; reconcile its outcome before retrying. */ export declare class AutomationMutationUncertainError extends Error { } /** Rejects ownership changes because AHP has no history-preserving cross-host transfer operation. */ export declare function assertAutomationTargetAuthority(current: IAutomationDescriptor, target: AutomationTarget | undefined): void; /** Signals that deprecated configuration aliases cannot modify an explicit provider template. */ export declare class AutomationSessionTemplateAuthorityError extends Error { constructor(); } export declare function assertAutomationSessionTemplateAuthority(current: IAutomationDescriptor, patch: IUpdateAutomationOptions): void; /** * Input for `createAutomation`. The service fills in `id`, timestamps, and * `nextRunAt`. */ export interface ICreateAutomationOptions { readonly ownership?: "user" | "repository"; readonly name: string; readonly prompt: string; readonly schedule: IAutomationSchedule; readonly cloudTrigger?: IAutomationCloudTrigger; readonly target: AutomationTarget; readonly sessionTemplate?: IAutomationSessionTemplate; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly modelId?: string; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly mode?: string; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly permissionLevel?: string; readonly enabled?: boolean; /** * Ids of the {@link IAutomationCustomizationChoice | customizations} to sync. * Absent means the provider's default: every customization enabled for the target. */ readonly customizationIds?: readonly string[]; } /** * A customization an automation can sync, as offered by * {@link IAutomationStore.getCustomizationChoices}. */ export interface IAutomationCustomizationChoice { readonly id: string; readonly label: string; readonly description?: string; /** Initially selected: enabled for the target when creating, saved in the definition when editing. */ readonly selected: boolean; /** Saved in the definition but changed locally since; saving the automation refreshes it. */ readonly outdated: boolean; } /** * Patch for `updateAutomation`. Absent fields are unchanged; a target change * replaces the complete discriminated target atomically. */ export interface IUpdateAutomationOptions { readonly name?: string; readonly prompt?: string; readonly schedule?: IAutomationSchedule; readonly cloudTrigger?: IAutomationCloudTrigger; readonly target?: AutomationTarget; readonly sessionTemplate?: IAutomationSessionTemplate | null; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly modelId?: string | null; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly mode?: string | null; /** @deprecated Compatibility input translated into {@link sessionTemplate}. */ readonly permissionLevel?: string | null; readonly enabled?: boolean; /** * Ids of the customizations to sync. Selected entries that are outdated are refreshed. * Absent keeps the saved customizations unless the target changes. */ readonly customizationIds?: readonly string[]; } /** * Result of an optimistic automation update. * `current` is absent when the automation was deleted before the update committed. */ export type IGuardedAutomationUpdateResult = { readonly kind: "updated"; readonly automation: IAutomationDescriptor; } | { readonly kind: "conflict"; readonly current: IAutomationDescriptor | undefined; }; /** * Returns the canonical editable state used by optimistic automation updates. * Runtime-only timestamps are intentionally excluded. Workspace URIs use their * canonical serialized form so any mismatch fails closed as a conflict. */ export declare function serializeAutomationEditableState(automation: IAutomationDescriptor): string; /** Result of requesting a manual run from its host, never a claim authorizing client-side execution. */ export type IAutomationRunRequestResult = /** The provider accepted dispatch without returning a correlated run. */ { readonly kind: "accepted"; } /** An existing run already occupies this Automation's active-run slot. */ | { readonly kind: "alreadyRunning"; readonly run: IAutomationRun; } | { /** The host handled the request, possibly failing before creating a session. */ readonly kind: "dispatched"; readonly run: IAutomationRun; /** Resolves on a terminal host outcome, not necessarily success; rejects if observation fails. */ readonly whenCompleted: Promise; /** Requests host cancellation when the negotiated capability supports it. */ cancel?(): void; }; export interface IAutomationRefreshOptions { /** Reload catalogue data without invalidating workspace eligibility used by open drafts. */ readonly background?: boolean; } export interface IDeleteAutomationOptions { readonly deleteHistory: boolean; } export type AutomationHistoryState = "retained" | "deleting" | "interrupted"; /** * Provider-neutral catalogue and command contract shared by individual providers and the aggregate service. * Reads projected state and requests host mutations; it does not grant browser persistence or execution authority. */ export interface IAutomationStore { refresh?(options?: IAutomationRefreshOptions): Promise; /** Full catalogue refresh activity, including its history read but excluding independent history polling. */ readonly isRefreshing?: IObservable; /** History refresh completeness, independent of definition mutation readiness. */ readonly historyState?: IObservable; /** Completeness of the Automation catalogue, independent of individual providers' operation availability. */ readonly catalogueState: IObservable; /** All defined automations, newest first. */ readonly automations: IObservable; /** All recorded runs across all automations, newest first. */ readonly runs: IObservable; /** Snapshot accessor (no observable dependency). */ getAutomation(id: string): IAutomationDescriptor | undefined; /** Runs for a single automation, newest first. */ runsFor(automationId: string): IObservable; /** Creates and persists an automation after validating the complete definition. */ createAutomation(options: ICreateAutomationOptions, mutationGuard?: AutomationMutationGuard): Promise; /** Applies a patch to the latest automation state; throws when `id` does not exist. */ updateAutomation(id: string, patch: IUpdateAutomationOptions): Promise; /** * Applies `patch` only when the current editable fields still match `expected`. * Runtime timestamps may change without conflicting, so reviewed edits preserve scheduler progress. */ updateAutomationIfUnchanged(id: string, patch: IUpdateAutomationOptions, expected: IAutomationDescriptor, mutationGuard?: AutomationMutationGuard): Promise; /** Deletes an automation and, by default, its retained history. Explicit history options require provider support; missing IDs are ignored. */ deleteAutomation(id: string, mutationGuard?: AutomationMutationGuard, options?: IDeleteAutomationOptions): Promise; /** Whether this provider supports an explicit keep/delete history policy. */ supportsDeleteHistoryChoice?(id: string): boolean; /** Includes removed definitions whose run history is retained. */ getAutomationHistoryName?(id: string): string | undefined; /** State of a removed definition's retained history. */ getAutomationHistoryState?(id: string): AutomationHistoryState | undefined; /** Permanently deletes retained history or retries an interrupted deletion. */ deleteAutomationHistory?(id: string): Promise; canDeleteAutomationHistory?(id: string): boolean; /** * Lists the customizations an automation targeting `target` can sync, including * those saved in automation `existingId`. Resolves `undefined` when the provider * does not support choosing customizations for that target. */ getCustomizationChoices?(target: AutomationTarget, existingId: string | undefined, token: CancellationToken): Promise; /** Requests a manual run, forwarding supported cancellation after admission even while session creation is pending. */ runAutomation(automationId: string, token?: CancellationToken): Promise; stopRun?(run: IAutomationRun): Promise; canStopRun?(run: IAutomationRun): boolean; /** Most recent `pending`/`running` run for an automation, or `undefined`. */ getActiveRunFor(automationId: string): IAutomationRun | undefined; canRunAutomation(automationId: string): boolean; canUpdateAutomation(automationId: string): boolean; canDeleteAutomation(automationId: string): boolean; } export type AutomationUnavailableReasonCode = "disconnected" | "initializing" | "disabled" | "unsupported" | "incompatible"; /** Identity and optional unavailability explanation of a concrete Automation provider. */ export interface IAutomationProviderDescriptor { readonly id: string; readonly label: string; /** Optional category for grouping providers without interpreting localized explanations. */ readonly unavailableReasonCode?: AutomationUnavailableReasonCode; /** A provider-specific explanation, absent when none applies. */ readonly unavailableReason?: string; /** A complete provider-supplied sentence shown instead of the generic per-provider unavailability message. */ readonly unavailableMessage?: string; }