import { CancellationToken } from "../../../base/common/cancellation.js"; import { Event } from "../../../base/common/event.js"; import { IDisposable, IReference } from "../../../base/common/lifecycle.js"; import { IObservable, IReader } from "../../../base/common/observable.js"; import { ArtifactAuthority, ArtifactAvailability, ArtifactPrompt, ArtifactPromptReceipt, ArtifactRecord, ArtifactRequestPresentation, ArtifactRunInitiator, IArtifactActionContext } from "./artifactIntegration.js"; export interface ArtifactSessionState { readonly availability: ArtifactAvailability; readonly archived: boolean; readonly deleted?: boolean; readonly artifacts: readonly ArtifactRecord[]; } export interface ArtifactPromptRequest { readonly session: string; readonly chat: string; readonly requestId: string; readonly prompt: ArtifactPrompt; readonly presentation?: ArtifactRequestPresentation; /** Lets the chat tell turns a person started apart from automated ones. */ readonly initiator?: ArtifactRunInitiator; } export type ArtifactPromptSubmission = { readonly kind: "accepted"; readonly handle: IArtifactPromptHandle; } | { readonly kind: "busy"; } | { readonly kind: "notSent"; readonly reason: string; } | { readonly kind: "indeterminate"; readonly reason: string; }; export type ArtifactPromptRecovery = { readonly kind: "attached"; readonly handle: IArtifactPromptHandle; } | { readonly kind: "notSent"; } | { readonly kind: "indeterminate"; readonly reason: string; }; export type ArtifactPromptOutcome = { readonly kind: "completed" | "cancelled" | "failed"; readonly turnId?: string; readonly reason: string; }; export type ArtifactPromptState = { readonly kind: "submitted"; } | { readonly kind: "running"; readonly turnId: string; } | { readonly kind: "unavailable" | "indeterminate"; readonly reason: string; } | ArtifactPromptOutcome; export declare function isArtifactPromptOutcome(state: ArtifactPromptState): state is ArtifactPromptOutcome; export declare class ArtifactPromptTrackingError extends Error { constructor(message: string); } export interface IArtifactChatObservation extends IDisposable { readonly state: IObservable<{ readonly available: boolean; readonly busy: boolean; readonly reason?: string; }>; } /** A lease on tracking one request; disposal stops observation without cancelling its work. */ export interface IArtifactPromptHandle extends IDisposable { readonly requestId: string; readonly receipt: ArtifactPromptReceipt; readonly state: IObservable; /** Resolves for a confirmed terminal outcome; tracking loss rejects without implying execution failure. */ readonly completion: Promise; cancel(token: CancellationToken): Promise; } export interface IArtifactChatAccess { readonly admission: "atomic" | "bestEffort"; observeChat(session: string, chat: string): IArtifactChatObservation; submit(request: ArtifactPromptRequest, token: CancellationToken, isCurrent: () => boolean): Promise; /** Attaches to existing work using its persisted identity and receipt; never sends the prompt. */ recover(request: ArtifactPromptRequest, receipt: ArtifactPromptReceipt | undefined, token: CancellationToken): Promise; } export type ArtifactAuthorization = { readonly kind: "allowed"; } | { readonly kind: "blocked"; readonly reason: string; }; /** A change of one automation rule, described for a chat notice. */ export interface ArtifactAutomationNoticeChange { readonly integrationId: string; readonly optionId: string; readonly label: string; readonly kind: "enabled" | "changed" | "disabled"; /** Plain-text paragraphs that explain the new state of the rule. */ readonly details: readonly string[]; } /** Labels of the rules of one artifact integration that remain enabled. */ export interface ArtifactAutomationEnabledRules { readonly integrationId: string; readonly labels: readonly string[]; } export interface ArtifactAutomationNotice { readonly session: string; readonly artifact: ArtifactRecord; readonly kind: "enabled" | "changed" | "disabled"; /** Rendered text, used as is only when the notice carries no `changes`. */ readonly content: string; readonly iconId?: string; /** The rule changes of the notice. Only notices that carry them are rendered from them and merged with later changes. */ readonly changes?: readonly ArtifactAutomationNoticeChange[]; /** The enabled rules of each integration that `changes` belong to, after the changes. */ readonly enabledRules?: readonly ArtifactAutomationEnabledRules[]; } /** The composition must hold exclusive ownership of this authority's store until disposal. */ export interface IArtifactRuntime { readonly authority: ArtifactAuthority; readonly available: IObservable; /** Explicit feature enablement; disabling cancels automation without revoking consent. Absence means enabled. */ readonly enabled?: IObservable; /** An adapter may pause automation without disabling manual resource actions. */ readonly automationUnavailableReason?: IObservable; readonly chat: IArtifactChatAccess; /** Publishes a system-authored transcript notice when supported; never sends it to an agent. */ postNotice?(notice: ArtifactAutomationNotice): Promise; isOwner(): boolean; acquireSession(session: string): Promise>>; /** Fires when a session is permanently deleted, not merely unloaded, so its bindings can be removed. */ readonly onDidDeleteSession?: Event; authorize(context: IArtifactActionContext, scope: "resource" | "resourceAndWorkspace", token: CancellationToken): Promise; } export declare function isArtifactRuntimeAvailable(runtime: IArtifactRuntime, reader?: IReader): boolean; /** A write replaced the ledger, but confirming its durability failed. */ export declare class ArtifactStorageCommitError extends Error { constructor(cause: unknown); } /** Successful writes are durable and atomic; only ArtifactStorageCommitError may reject after publishing the new value. */ export interface IArtifactIntegrationStorage { read(): Promise; write(value: string): Promise; } export type ArtifactCoordinatorSelection = { readonly kind: "host"; } | { readonly kind: "client"; } | { readonly kind: "unavailable"; readonly reason: "pending" | "disconnected" | "denied" | "authorityChanged"; }; export declare function selectArtifactCoordinator(capability: "pending" | "supported" | "unsupported", connected: boolean, permitted: boolean, previous?: "host" | "client"): ArtifactCoordinatorSelection;