import { type WeixinSetupScope } from './weixin-setup-scope.js'; import type { Config } from '../../config/schema.js'; import { type McpResearch } from './discovery.js'; import type { McpConnectionProbe } from './connection-setup.js'; type Phase = 'approval_required' | 'planned' | 'oauth_required' | 'authorizing' | 'token_required' | 'auth_unknown' | 'blocked' | 'ready' | 'cancelled'; export type McpSetupContext = { conversationId: string; agentId: string; canConfigure: boolean; canRequestWeixinSetup?: boolean; showSetupCard?: boolean; canOpenMobileForm?: boolean; signal?: AbortSignal; authorizeResearch?: (tool: 'web_search' | 'web_fetch', args: Record) => Promise; }; type Save = (next: Config, expected?: Config) => Promise<{ saved: boolean; persisted?: boolean; conflict?: boolean; }>; /** Coordinates HTTP MCP setup; pi remains the sole MCP and OAuth implementation. */ export declare class McpConversationSetup { private readonly options; private readonly goals; private readonly drafts; private readonly draftIds; private readonly busy; private readonly authorizations; private disposed; private readonly retryTimers; private readonly discovery; constructor(options: { readConfig: () => Config; saveConfig: Save; research?: McpResearch; changed?: (conversationId: string) => void; deliver?: (channel: WeixinSetupScope, text: string, setupId: string) => Promise; withConfigLock: (operation: () => Promise) => Promise; resume: (goal: { id: string; conversationId: string; transcriptId: string; serverId: string; purpose: string; objective?: 'connect_only' | 'complete_task'; channel?: WeixinSetupScope; }) => Promise; }); private notify; private save; private current; private get; private canProvideToken; private canApproveWithToken; private view; private cancelGoal; cancelConversation(conversationId: string): Promise; revokeWeixinRequests(accountId: string, peerId: string): void; reconcileWeixinScopes(): void; private inspect; currentForConversation(conversationId: string): { setup: { purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interaction: "chat_card"; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interactionPath: string; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | null; }; command(command: string, input: Record, context: McpSetupContext, dryRun?: boolean): Promise; private startDraftAuthorization; private advance; private scheduleRetry; /** Owner-only UI; secret values and OAuth URLs never pass through the model API. */ interact(id: string, action: 'get' | 'advance' | 'token' | 'authorize' | 'cancel' | 'approve' | 'retry_delivery', value?: string | Record, expectedVersion?: number, ownerPrincipalId?: string, options?: { mobileCallbackOrigin?: string; }): Promise<{ purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interaction: "chat_card"; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interactionPath: string; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { phase: string; endpointOrigin: string; purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interaction: "chat_card"; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { phase: string; endpointOrigin: string; purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interactionPath: string; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { endpointOrigin: string; approval: { endpoint: string; purpose: string; accountId: string; peerId: string; principalId: string; origin: string; } | undefined; canReplaceToken: boolean; authorizationUrl: string | undefined; authState: string | undefined; requiresRecheck: boolean; purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interaction: "chat_card"; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; } | { endpointOrigin: string; approval: { endpoint: string; purpose: string; accountId: string; peerId: string; principalId: string; origin: string; } | undefined; canReplaceToken: boolean; authorizationUrl: string | undefined; authState: string | undefined; requiresRecheck: boolean; purpose: string; returnChannel: string | undefined; managementPath: string; continuationQueued: boolean; replyDelivery: "failed" | "pending" | "delivered" | undefined; instruction: string; interactionPath: string; approveWithToken: boolean; documentedTokenPortal: boolean | undefined; secretFields: { id: string; label: string; location: "header" | "env"; name: string; prefix: "" | "Bearer "; }[] | undefined; helpUrl: string | undefined; objective: "connect_only" | "complete_task" | undefined; planApproval: { sources: { url: string; hash: string; }[]; execution: { command: string; args: string[]; sourceUrl: string; cwd?: string | undefined; } | undefined; endpoint: string | undefined; purpose: string; } | undefined; diagnosis: Pick | undefined; nextRetryAt: number | undefined; attempts: number; errorCode: string | undefined; conversationId: string; expiresAt: number; defaultAuthMethod?: "headers" | "apiKey" | "none" | "oauth" | "bearer" | undefined; setupId: string; serverId: string; displayName: string | undefined; version: number; phase: Phase; expired: boolean; reloadRequired: boolean; canProvideToken: boolean; reauth: boolean; }>; private settleAuthorization; dispose(): void; relayCallback(id: string, callbackUrl: string): string; completeContinuation(input: { conversationId: string; clientMessageId: string; expectedTranscriptId?: string; origin: { type: string; source?: string; }; runId?: string; }, text: string): Promise; private deliverReply; private resume; permitsContinuation(input: { conversationId: string; clientMessageId: string; expectedTranscriptId?: string; origin: { type: string; source?: string; }; }): boolean; resumePending(runtimeReloaded?: boolean): Promise; } export {};