import type { ErrorInfo } from "../../../../platform/agentHost/common/state/protocol/state.js"; import { ChatEntitlement } from "../../../services/chat/common/chatEntitlementService.js"; import { IChatResponseErrorDetails } from "./chatService/chatService.js"; /** * Mirror of the Copilot extension's `ChatFetchResponseType` (see * `extensions/copilot/src/platform/chat/common/commonTypes.ts`). These string * values are forwarded verbatim from the agent host harnesses (Copilot CLI, * Claude, Codex) over `_meta`, so they MUST stay in sync with the extension. */ export declare enum ChatFetchResponseType { OffTopic = "offTopic", Canceled = "canceled", Filtered = "filtered", FilteredRetry = "filteredRetry", PromptFiltered = "promptFiltered", Length = "length", RateLimited = "rateLimited", QuotaExceeded = "quotaExceeded", ExtensionBlocked = "extensionBlocked", BadRequest = "badRequest", NotFound = "notFound", Failed = "failed", Unknown = "unknown", NetworkError = "networkError", AgentUnauthorized = "agent_unauthorized", AgentFailedDependency = "agent_failed_dependency", InvalidStatefulMarker = "invalid_stateful_marker", Success = "success" } /** * Mirror of the Copilot extension's `FilterReason` (see * `extensions/copilot/src/platform/networking/common/openai.ts`). */ export declare enum FilterReason { Hate = "hate", SelfHarm = "self_harm", Sexual = "sexual", Violence = "violence", Copyright = "snippy", Prompt = "prompt" } /** * Raw error payload forwarded from an agent host harness. This is the * serialized `ChatFetchError` from the Copilot extension. Because it crosses * the extension/core boundary as untyped JSON inside `_meta`, every field is * optional and consumers type-cast based on `type`. */ export interface IChatFetchErrorPayload { readonly type: ChatFetchResponseType | string; readonly reason?: string; readonly reasonDetail?: string; readonly requestId?: string; readonly serverRequestId?: string | undefined; readonly category?: FilterReason | string; readonly retryAfter?: number; readonly rateLimitKey?: string; readonly isAuto?: boolean; readonly capiError?: { code?: string; message?: string; }; } /** * The full forwarded chat error payload, including the user-context fields that * the extension would normally read from the Copilot token. This is the value * placed at `_meta.chatError` by the harnesses. */ export interface IForwardedChatError { readonly fetchError: IChatFetchErrorPayload; readonly copilotPlan?: string; readonly isUsageBasedBilling?: boolean; readonly quotaResetDate?: string; } export declare function getQuotaMessageForPlan(copilotPlan: string | undefined, isUsageBasedBilling?: boolean, quotaResetDate?: string): string; export declare function getFilteredMessage(category: FilterReason | string, supportsMarkdown?: boolean): string; /** * Builds the user-facing {@link IChatResponseErrorDetails} from a forwarded raw * chat fetch error. This is the core analog of the Copilot extension's * `getErrorDetailsFromChatFetchError`. Unlike the extension, core has no * access to the GitHub outage status, so the outage note is never appended * (assume no outage). */ export declare function getChatErrorDetailsFromFetchError(fetchError: IChatFetchErrorPayload, copilotPlan: string | undefined, isUsageBasedBilling?: boolean, quotaResetDate?: string): IChatResponseErrorDetails; /** * Extracts and formats {@link IChatResponseErrorDetails} from the `_meta` * forwarded by an agent host harness, if present. Returns `undefined` when no * forwarded chat error is found so callers can fall back to their existing * error handling. * * The agent host does not know the signed-in user's plan, so callers in core * pass an {@link IChatErrorContext} (resolved from `IChatEntitlementService`) * whose fields take precedence over the values forwarded in `_meta`. */ export declare function getChatErrorDetailsFromMeta(error: ErrorInfo | undefined, context?: IChatErrorContext): IChatResponseErrorDetails | undefined; /** * User-context overrides for {@link getChatErrorDetailsFromMeta}. When a field * is set it takes precedence over the value forwarded by the agent host. Core * resolves these from `IChatEntitlementService`. */ export interface IChatErrorContext { readonly copilotPlan?: string; readonly isUsageBasedBilling?: boolean; readonly quotaResetDate?: string; } /** * Maps a core {@link ChatEntitlement} to the Copilot plan string understood by * the quota/rate-limit message helpers (mirrors the Copilot extension's * `CopilotToken.copilotPlan` values). */ export declare function getCopilotPlanFromEntitlement(entitlement: ChatEntitlement): string | undefined;