import { CancellationToken } from "../../../base/common/cancellation.js"; import { Event } from "../../../base/common/event.js"; import { IDisposable, IReference } from "../../../base/common/lifecycle.js"; import { IObservable } from "../../../base/common/observable.js"; import { URI } from "../../../base/common/uri.js"; import type { ArtifactAutomationNotice } from "./artifactRuntime.js"; export declare const ArtifactIntegrationsSettingId = "chat.artifactIntegrations.enabled"; export type ArtifactJsonValue = null | boolean | number | string | readonly ArtifactJsonValue[] | { readonly [key: string]: ArtifactJsonValue; }; export interface ArtifactOrigin { readonly chat: string; readonly turnId?: string; } export interface ArtifactRecord { readonly id: string; readonly resource: string; readonly label: string; readonly isArtifact?: boolean; readonly origin?: ArtifactOrigin; } export declare function artifactBindingId(authority: string, session: string, artifactId: string, integrationId: string): string; export interface ArtifactAuthority { readonly id: string; readonly targetHost: string; readonly location: "host" | "client"; } export type ArtifactAvailability = { readonly kind: "available"; readonly observedAt?: number; } | { readonly kind: "loading"; } | { readonly kind: "stale" | "unavailable" | "error"; readonly reason: string; readonly observedAt?: number; } | { readonly kind: "authenticationRequired"; readonly reason: string; readonly observedAt?: number; /** * A secure page where the user grants the current credential the access it * lacks, such as GitHub's page authorizing it for an organization's single * sign-on. Signing in again would not grant it, so clients open this page * instead. */ readonly authorizationUrl?: string; }; export interface ArtifactIcon { readonly id: string; readonly colorId?: string; } export interface ArtifactPartPresentation { readonly icon: ArtifactIcon; readonly label: string; /** A plain-text explanation of a compact label, including its status. */ readonly description?: string; readonly detailsId: string; } export interface ArtifactSectionPresentation extends ArtifactPartPresentation { readonly id: string; } /** * How one artifact contributes to a grouped presentation of several artifacts sharing a {@link ArtifactContributionView.groupId}. * Only the artifact's main integration is consulted, and priorities are compared only among the group's artifacts: * the group shows the icon with the highest priority, and ties keep the earlier artifact. */ export interface ArtifactGroupPresentation { readonly icon: ArtifactIcon; readonly priority: number; } export interface ArtifactDetailsList { readonly id: string; readonly label: string; /** List identity independent of the presence of a compact pill section. */ readonly icon?: ArtifactIcon; readonly detailsId: string; } export interface ArtifactActionAvailability { readonly enabled: boolean; readonly disabledReason?: string; } export interface ArtifactActionView extends ArtifactActionAvailability { readonly id: string; /** When present, manual invocation also requires an enabled entry for the invoking chat. */ readonly chatAvailability?: Readonly>; } export interface ArtifactContributionView { readonly availability: ArtifactAvailability; readonly main?: ArtifactPartPresentation; /** * Gives the artifact a pill of its own, shared with the other artifacts whose main integration assigns the same ID, * including those of other integrations. Without one, the artifact is listed in the pill for its kind, such as * Artifacts, with the other artifacts. Only the main integration's ID is consulted. */ readonly groupId?: string; /** This artifact's contribution to a group of several artifacts sharing its {@link groupId}. */ readonly group?: ArtifactGroupPresentation; readonly sections: readonly ArtifactSectionPresentation[]; /** Independent state lists, including lists without a compact pill section. */ readonly lists?: readonly ArtifactDetailsList[]; /** Actions relevant to the current resource state. Omit inapplicable actions; disable those temporarily blocked. */ readonly stateActions: readonly ArtifactActionView[]; readonly generalActions: readonly ArtifactActionView[]; readonly automationAvailability: readonly { readonly id: string; readonly available: boolean; readonly unavailableReason?: string; readonly enablement?: ArtifactActionAvailability; }[]; } export type ArtifactDetailsLink = { readonly kind: "action"; readonly actionId: string; } | { readonly kind: "automation"; readonly optionId: string; }; /** An action on one details item, such as rerunning a check. */ export interface ArtifactItemActionDescriptor { readonly id: string; readonly iconId: string; readonly label: string; /** * Runs the integration's registered action with this ID for the item, with {@link ArtifactItemActionInput} as its input, * instead of {@link IArtifactDetailsModel.runItemAction}. The registered action must be offered and enabled. */ readonly actionId?: string; } /** The input of a registered action that runs for one details item. */ export interface ArtifactItemActionInput { readonly [key: string]: string; readonly detailsId: string; readonly itemId: string; } export interface ArtifactDetailsItem { readonly id: string; readonly icon: ArtifactIcon; readonly label: string; readonly description?: string; readonly resource: string; /** IDs of the details' `itemActions` that currently apply to this item. Omit inapplicable actions. */ readonly actions?: readonly string[]; } export interface ArtifactDetails { readonly availability: ArtifactAvailability; readonly title: string; readonly description?: string; /** Descriptions are plain text unless explicitly marked as untrusted Markdown. */ readonly descriptionFormat?: "plaintext" | "markdown"; readonly facts?: readonly { readonly id: string; readonly label: string; readonly value: string; }[]; readonly links: readonly ArtifactDetailsLink[]; /** Actions that items reference by ID. Run them with {@link IArtifactDetailsModel.runItemAction}. */ readonly itemActions?: readonly ArtifactItemActionDescriptor[]; readonly items: readonly ArtifactDetailsItem[]; readonly completeness: "complete" | "partial"; } export interface IArtifactDetailsModel extends IDisposable { readonly details: IObservable; loadMore?(token: CancellationToken): Promise; /** * Runs an item action directly, without run tracking, activity history, or automation. Use it only for effects that * are safe to repeat, and use registered artifact actions for anything else. The provider revalidates that the * action still applies to the item and rejects with a user-facing reason otherwise. */ runItemAction?(itemId: string, actionId: string, token: CancellationToken): Promise; } interface ArtifactAutomationOptionBase { readonly id: string; readonly label: string; readonly description: string; readonly actionIds: readonly string[]; readonly maxAttempts: number; /** Change this when the rule's meaning, schedule, or permissions expand. */ readonly consentVersion?: string; } export type ArtifactAutomationOption = ArtifactAutomationOptionBase & ({ readonly kind: "boolean"; readonly defaultValue: false; } | { readonly kind: "enum"; readonly choices: readonly { readonly value: string; readonly label: string; readonly description?: string; }[]; readonly disabledValue: string; readonly defaultValue: string; }); export interface ArtifactAutomationDisablement { readonly reason: string; readonly attempts: number; readonly lastRunId?: string; } /** Who asked for a change: a person in the UI, or an agent through its tools, with the person's confirmation where required. */ export type ArtifactActor = { readonly kind: "user"; } | { readonly kind: "agent"; readonly chat: string; readonly turnId?: string; }; export interface ArtifactAutomationConfiguration { readonly revision: number; readonly values: Readonly>; readonly generations: Readonly>; /** Absent on configurations persisted before enablement timestamps were recorded. */ readonly enabledAt?: Readonly>; /** Who turned on each option's current consent generation; meaningful only while the option is enabled. */ readonly grants?: Readonly>; readonly disablements: Readonly>; } export interface IArtifactBindingStateStore { read(): { readonly revision: number; readonly value?: ArtifactJsonValue; }; write(expectedRevision: number, value: ArtifactJsonValue): Promise; } export interface IArtifactBindingContext { readonly session: string; readonly artifact: ArtifactRecord; readonly configuration: IObservable; readonly state: IArtifactBindingStateStore; } export interface ArtifactResourceMatch { readonly resource: URI; /** Stable canonical identity within this integration, including aliases of the same resource. */ readonly key: string; readonly credentialScope: string; } /** A protected resource challenge, never a credential or permission to execute an artifact action. */ export interface ArtifactAuthenticationRequest { readonly resource: string; readonly authorizationServers?: readonly string[]; readonly scopes?: readonly string[]; } /** Allows matching or resource creation to expose recovery without establishing an account binding. */ export declare class ArtifactAuthenticationRequiredError extends Error { readonly main: ArtifactPartPresentation; constructor(message: string, main: ArtifactPartPresentation); } /** * Thrown by a code action's execution when the external system definitively refused the action, so it cannot have * taken effect. Unlike other errors after dispatch, the run fails with a known outcome instead of requiring reconciliation. */ export declare class ArtifactActionRejectedError extends Error { constructor(message: string); } export interface IArtifactResourceContext { readonly authority: ArtifactAuthority; readonly runtimeId: string; } export interface IArtifactIntegration { readonly id: string; readonly label: string; /** Plain text naming the recorded resources this integration supports, so agents know when to use it. */ readonly description?: string; /** One line of plain text naming several of this integration's artifacts, such as "Pull Requests", when they share a group ID. */ readonly groupLabel?: string; readonly automationOptions: readonly ArtifactAutomationOption[]; /** Higher priority wins; ties are resolved by integration ID, never response order. */ readonly presentationPriority?: number; readonly onDidChange?: Event; match(resource: URI, token: CancellationToken, artifact: ArtifactRecord): ArtifactResourceMatch | undefined | Promise; /** Supplies a challenge the client fulfills by authenticating with the coordinator that runs this integration. */ getAuthenticationRequest?(resource: URI, token: CancellationToken, artifact: ArtifactRecord): ArtifactAuthenticationRequest | Promise; /** Signs in within this integration's own runtime, so its credentials never reach another coordinator. */ signIn?(resource: URI, token: CancellationToken, artifact: ArtifactRecord): Promise; createResource(match: ArtifactResourceMatch, context: IArtifactResourceContext, token: CancellationToken): Promise; createBinding(resource: TResource, context: IArtifactBindingContext): IArtifactIntegrationBinding; } export interface IArtifactIntegrationBinding extends IDisposable { readonly view: IObservable; readonly actions: readonly ArtifactAction[]; acquireDetails(detailsId: string): IArtifactDetailsModel; activateAutomation(context: IArtifactAutomationContext): IDisposable; } export interface ArtifactActionDescriptor { readonly id: string; readonly iconId: string; readonly label: string; readonly kind: "code" | "prompt"; /** Change this when an existing action's effects or required permissions expand. */ readonly consentVersion?: string; } export type ArtifactPreparation = { readonly kind: "ready"; readonly value: T; } | { readonly kind: "skip"; readonly reason: string; }; export type ArtifactAction = ArtifactActionDescriptor & ({ readonly kind: "code"; readonly executionScope: "resource" | "resourceAndWorkspace"; prepare(context: IArtifactActionContext, token: CancellationToken): Promise>; reconcile?(context: IArtifactActionContext, token: CancellationToken): Promise; } | { readonly kind: "prompt"; prepare(context: IArtifactActionContext, token: CancellationToken): Promise>; }); export interface IArtifactActionContext { readonly authority: ArtifactAuthority; readonly session: string; readonly artifact: ArtifactRecord; readonly integrationId: string; readonly run: ArtifactRun; } export interface IArtifactCodeExecution { run(context: { readonly token: CancellationToken; readonly runId: string; }): Promise; } export type ArtifactCodeResult = { readonly kind: "completed"; readonly summary: string; readonly result?: ArtifactJsonValue; } | { readonly kind: "skipped"; readonly reason: string; }; export type ArtifactReconciliation = { readonly kind: "completed"; readonly summary: string; } | { readonly kind: "notExecuted"; } | { readonly kind: "indeterminate"; readonly reason: string; }; export interface ArtifactPrompt { readonly text: string; /** * The details this prompt is about, such as only the failing checks it asks to fix. When present, the request * presents these instead of the details linked to the action. They are not part of the model-facing prompt. */ readonly details?: readonly ArtifactDetails[]; } /** A point-in-time description of an artifact action, independent of its model-facing prompt. */ export interface ArtifactRequestPresentation { readonly version: 1; readonly integrationLabel: string; readonly source: "manual" | "automation"; readonly action: { readonly label: string; readonly iconId: string; }; readonly artifact: { readonly resource: string; readonly label: string; readonly description?: string; readonly icon?: ArtifactIcon; }; readonly details: readonly ArtifactDetails[]; } export interface ArtifactAutomationRequest { readonly optionId: string; readonly actionId: string; readonly configurationRevision: number; readonly occurrenceKey: string; readonly reason: string; readonly input?: ArtifactJsonValue; readonly retryOf?: string; } export interface IArtifactAutomationContext { runAutomation(request: ArtifactAutomationRequest): Promise; reconcileRun(runId: string): Promise; /** Providers may revoke consent, but cannot grant or broaden it. */ disableAutomation(optionId: string, expectedRevision: number, reason: string): Promise; readonly runs: IObservable; } export type ArtifactRunState = "queued" | "preparing" | "blocked" | "submitted" | "running" | "completed" | "skipped" | "failed" | "cancelled" | "interrupted"; export type ArtifactPromptReceipt = { readonly kind: "queued"; readonly queuedMessageId: string; } | { readonly kind: "turn"; readonly turnId: string; }; export interface ArtifactRun { readonly id: string; readonly bindingId: string; readonly integrationId: string; readonly actionId: string; readonly actionKind: "code" | "prompt"; readonly actionConsent: string; readonly source: "manual" | "automation"; /** Who asked for a manual run. */ readonly requestedBy?: ArtifactActor; readonly requestId: string; readonly state: ArtifactRunState; readonly createdAt: number; readonly updatedAt: number; readonly reason: string; readonly input?: ArtifactJsonValue; readonly optionId?: string; readonly configurationRevision?: number; readonly generation?: number; readonly occurrenceKey?: string; readonly retryOf?: string; readonly chat?: string; readonly admission?: "atomic" | "bestEffort"; readonly receipt?: ArtifactPromptReceipt; readonly prompt?: ArtifactPrompt; readonly presentation?: ArtifactRequestPresentation; readonly dispatched: boolean; readonly indeterminate?: boolean; readonly result?: ArtifactJsonValue; } export interface ArtifactContributionSnapshot { readonly integrationId: string; /** Execution authority when contributions from multiple runtimes share a presentation. */ readonly authority?: ArtifactAuthority; readonly label: string; /** The integration's name for several of its artifacts, shown when they are grouped. */ readonly groupLabel?: string; /** * The integration's canonical identity for the bound resource, shared by aliases such as a pull request's * overview and checks pages. Absent until the artifact is bound to a resource. */ readonly resourceKey?: string; readonly view: ArtifactContributionView; readonly actions: readonly ArtifactActionDescriptor[]; readonly options: readonly ArtifactAutomationOption[]; readonly configuration: ArtifactAutomationConfiguration; /** Sign-in availability; `handledByIntegration` means the integration signs in within its own runtime. */ readonly authentication?: ArtifactActionAvailability & { readonly handledByIntegration?: boolean; }; } export interface ArtifactSnapshot { readonly authority: ArtifactAuthority; readonly session: string; readonly artifact: ArtifactRecord; readonly contributions: readonly ArtifactContributionSnapshot[]; readonly mainIntegrationId?: string; readonly runs: readonly ArtifactRun[]; } /** The contribution of the integration that presents an artifact's main part, if any. */ export declare function getArtifactMainContribution(snapshot: ArtifactSnapshot): ArtifactContributionSnapshot | undefined; export interface IArtifactModel { readonly snapshot: IObservable; /** * Requests recovery in the invoking client; completion does not imply that authentication succeeded. * Resolves with the challenge the client fulfilled, or `undefined` when the integration signed in within its own runtime. */ requestAuthentication(integrationId: string): Promise; /** `actor` defaults to the user; agents pass their chat and turn so consent records who asked. */ configure(integrationId: string, expectedRevision: number, values: Readonly>, actor?: ArtifactActor): Promise; /** * `actor` defaults to the user; agents pass their chat and turn so the run records who asked. `input` is passed to the action, * for example the details item it runs for. */ invoke(integrationId: string, actionId: string, chat: string, requestId: string, actor?: ArtifactActor, input?: ArtifactJsonValue): Promise; cancel(runId: string): Promise; reconcile(runId: string): Promise; /** Newest first. The optional cursor is the preceding page's last run ID; page size is 1-200. */ getRuns(before?: string, limit?: number): Promise<{ readonly runs: readonly ArtifactRun[]; readonly next?: string; }>; acquireDetails(integrationId: string, detailsId: string): Promise; } export interface IArtifactIntegrationAccess { acquireArtifact(session: string, artifactId: string): Promise>; postNotice?(notice: ArtifactAutomationNotice): Promise; } export declare const MAX_ARTIFACT_INTEGRATION_DESCRIPTION_LENGTH = 300; export declare const MAX_ARTIFACT_INTEGRATION_LABEL_LENGTH = 100; /** An agent-facing summary of a registered integration, independent of any recorded artifact. */ export interface ArtifactIntegrationDescriptor { readonly id: string; readonly label: string; readonly description?: string; readonly automationOptions: readonly { readonly id: string; readonly label: string; }[]; } export declare function toArtifactIntegrationDescriptor(integration: { readonly id: string; readonly label: string; readonly description?: string; readonly options: readonly ArtifactAutomationOption[]; }): ArtifactIntegrationDescriptor; export declare function getArtifactActionAvailability(action: ArtifactActionView, chat: string | undefined): ArtifactActionAvailability; /** Who started a run: a person, an agent through its tools, or an automation rule. */ export type ArtifactRunInitiator = "user" | "agent" | "automation"; export declare function getArtifactRunInitiator(run: Pick): ArtifactRunInitiator; export declare function isArtifactRunSettled(run: ArtifactRun): boolean; export declare function artifactOptionDisabledValue(option: ArtifactAutomationOption): boolean | string; export declare function isArtifactOptionEnabled(option: ArtifactAutomationOption, value: boolean | string | undefined): boolean; export {};