export const IPC_CHANNELS = {
  workspaceGetSummary: "workspace:get-summary",
  workspaceWarmup: "workspace:warmup",
  windowMinimize: "window:minimize",
  windowMaximize: "window:maximize",
  windowClose: "window:close",
  gatewayStatus: "gateway:status",
  gatewayConnect: "gateway:connect",
  gatewayDisconnect: "gateway:disconnect",
  gatewayReconnect: "gateway:reconnect",
  gatewayHealth: "gateway:health",
  gatewayTailLogs: "gateway:tail-logs",
  runtimeGetStatus: "runtime:get-status",
  runtimeTailLogs: "runtime:tail-logs",
  runtimeStart: "runtime:start",
  runtimeStop: "runtime:stop",
  runtimeRestart: "runtime:restart",
  runtimeHealth: "runtime:health",
  runtimeCloudGetStatus: "runtime-cloud:get-status",
  runtimeCloudFetchConfig: "runtime-cloud:fetch-config",
  runtimeTelemetryGetStatus: "runtime-telemetry:get-status",
  configLoad: "config:load",
  configPickWorkspaceDirectory: "config:pick-workspace-directory",
  configSave: "config:save",
  configRevealSecret: "config:reveal-secret",
  projectsList: "projects:list",
  projectsSetActive: "projects:set-active",
  projectsResolveIntent: "projects:resolve-intent",
  skillCatalogList: "skill-catalog:list",
  chatListSessions: "chat:list-sessions",
  chatListSessionsByProject: "chat:list-sessions-by-project",
  chatCreateSession: "chat:create-session",
  chatCreateSessionForProject: "chat:create-session-for-project",
  chatCloseSession: "chat:close-session",
  chatListMessages: "chat:list-messages",
  chatPickAttachments: "chat:pick-attachments",
  chatPickImageAttachment: "chat:pick-image-attachment",
  chatReadImageAttachmentDataUrl: "chat:read-image-attachment-data-url",
  chatSendPrompt: "chat:send-prompt",
  chatStreamPrompt: "chat:stream-prompt",
  chatStreamEvent: "chat:stream-event",
  diagnosticsOpenControlUi: "diagnostics:open-control-ui",
  diagnosticsExportSnapshot: "diagnostics:export-snapshot",
  authGetSession: "auth:get-session",
  authSignIn: "auth:sign-in",
  authSignOut: "auth:sign-out",
  profileGetSummary: "profile:get-summary",
  creditsGetSummary: "credits:get-summary",
  skillsList: "skills:list",
  expertsList: "experts:list",
  modelConfigGetSummary: "model-config:get-summary",
  systemGetSummary: "system:get-summary",
  tasksListByDate: "tasks:list-by-date"
} as const;

export type GatewayState = "unknown" | "connecting" | "connected" | "disconnected" | "error";
export type LogLevel = "info" | "warn" | "error";
export type MessageRole = "system" | "user" | "assistant" | "tool" | "toolResult";
export type AuthSessionState = "authenticated" | "anonymous" | "expired" | "error";
export type CreditStatus = "ok" | "low" | "empty";
export type RuntimeMode = "external-gateway" | "bundled-runtime";
export type RuntimeModePreference = "auto" | RuntimeMode;
export type RuntimePayloadState = "missing" | "placeholder" | "ready";
export type RuntimeProcessState = "stopped" | "starting" | "running" | "stopping" | "error";
export type ModelRoutingMode = "platform-managed" | "skill-bound" | "user-selectable";
export type ModelConfigFallbackMode = "cloud-required" | "last-known-cache";
export type ModelCapability = "chat" | "reasoning" | "tools" | "vision" | "audio-input" | "audio-output";
export type ModelRecommendation = "default" | "chat" | "skills" | "analysis";
export type SkillModelBindingMode = "default" | "forced" | "selectable";
export type RuntimeCloudFetchAction = "init" | "sync";
export type RuntimeCloudState = "unconfigured" | "loading" | "ready" | "error";
export type RuntimeCloudApiBaseUrlSource = "config" | "env" | "default";
export type RuntimeTelemetryState = "idle" | "running" | "stopped" | "error";
export type RuntimeCloudEventType = "startup" | "shutdown" | "message_sent" | "message_received" | "error" | "config_updated";
export type PluginStatus = "included" | "extension" | "unavailable";
export type SetupMode = "employee-key" | "direct-provider";
export type ChatLaunchState = "unbound" | "starting" | "ready" | "error";
export type WorkspaceStartupPhase = "idle" | "syncing-config" | "syncing-projects" | "starting-runtime" | "connecting-gateway" | "ready" | "error";
export type SkillDownloadState = "pending" | "downloading" | "ready" | "failed" | "removed";
export type ExpertEntryMode = "standalone" | "home-chat-shortcut";
export type DailyReportDeliveryState = "draft" | "sent" | "failed";
export type TaskPanelStatus = "pending" | "running" | "completed" | "failed";
export type ConfigSecretId =
  | "lobsterKey"
  | "copywritingModelApiKey"
  | "imageModelApiKey"
  | "videoModelApiKey"
  | "digitalHumanVolcAccessKey"
  | "digitalHumanVolcSecretKey"
  | "digitalHumanQiniuAccessKey"
  | "digitalHumanQiniuSecretKey"
  | "videoAnalyzerApiKey"
  | "replicationBriefApiKey"
  | "vectcutApiKey"
  | "xhsFeishuAppId"
  | "xhsFeishuAppSecret"
  | "xhsFeishuAppToken"
  | "xhsFeishuTableId";

export interface WorkspaceWarmupResult {
  accepted: boolean;
  state: "scheduled" | "skipped";
  message: string;
}

export interface GatewayStatus {
  state: GatewayState;
  url: string;
  host: string;
  port: number;
  version: string;
  transport: "websocket";
  lastConnectedAt?: string;
  lastError?: string;
  availableMethods?: string[];
  message?: string;
}

export interface GatewayHealth {
  ok: boolean;
  latencyMs: number;
  checkedAt: string;
  transport: "websocket";
  details?: string;
}

export interface RuntimeHealth {
  ok: boolean;
  checkedAt: string;
  processState: RuntimeProcessState;
  selectedMode: RuntimeMode;
  activeMode: RuntimeMode;
  pid?: number;
  gatewayUrl?: string;
  uptimeMs?: number;
  details?: string;
  lastError?: string;
}

export interface RuntimeStatus {
  requestedMode: RuntimeModePreference;
  selectedMode: RuntimeMode;
  activeMode: RuntimeMode;
  payloadState: RuntimePayloadState;
  processState: RuntimeProcessState;
  runtimeDir: string;
  nodeExecutable: string;
  openClawEntry: string;
  defaultConfigPath: string;
  pythonExecutable?: string;
  pythonManifestPath?: string;
  pythonReady?: boolean;
  pythonVersion?: string;
  installedPythonPackages?: string[];
  pythonMissingModules?: string[];
  runtimeDataDir: string;
  runtimeStateDir: string;
  runtimeLogsDir: string;
  logFilePath: string;
  gatewayUrl?: string;
  gatewayTokenConfigured: boolean;
  pid?: number;
  startedAt?: string;
  stoppedAt?: string;
  lastExitCode?: number | null;
  lastError?: string;
  message: string;
  modeReason: string;
  detectedFiles: string[];
  missingFiles: string[];
  checkedAt?: string;
}

export interface RuntimeCloudConfigSummary {
  employeeId: string;
  employeeName: string;
  employeeStatus?: string;
  deploymentType?: string;
  configVersion: string;
  fetchedAt: string;
  providerName?: string;
  providerType?: string;
  baseUrl?: string;
  modelId?: string;
  modelDisplayName?: string;
  temperature?: number;
  maxTokens?: number;
  skillCount: number;
  channelCount: number;
  personaPromptConfigured: boolean;
  welcomeMessage?: string;
  heartbeatUrl?: string;
  eventsUrl?: string;
}

export interface RuntimeCloudStatus {
  state: RuntimeCloudState;
  baseUrl: string;
  baseUrlSource?: RuntimeCloudApiBaseUrlSource;
  baseHost?: string;
  apiKeyConfigured: boolean;
  apiKeyFingerprint?: string;
  lastFetchedAt?: string;
  lastError?: string;
  config?: RuntimeCloudConfigSummary;
}

export interface RuntimeHeartbeatBillingSummary {
  success: boolean;
  tokenDelta?: number;
  creditsDeducted?: number;
  balanceBefore?: number;
  balanceAfter?: number;
}

export interface OpenClawDailyReportChannelSummary {
  type: string;
  name: string;
}

export interface OpenClawDailyReportPayload {
  api_key: string;
  summary_date: string;
  total_conversations: number;
  total_messages: number;
  total_tokens: number;
  total_errors: number;
  highlights: string[];
  issues: string[];
  raw_summary_text: string;
  active_channels: OpenClawDailyReportChannelSummary[];
}

export interface OpenClawDailyReportResponse {
  ok: boolean;
  summaryId?: string;
  employeeId?: string;
  summaryDate: string;
}

export interface RuntimeTelemetryStatus {
  state: RuntimeTelemetryState;
  startedAt?: string;
  stoppedAt?: string;
  heartbeatIntervalMs: number;
  configSyncIntervalMs: number;
  eventFlushIntervalMs: number;
  eventBatchSize: number;
  queuedEventCount: number;
  droppedEventCount: number;
  messageCount: number;
  activeConversationCount: number;
  errorCount: number;
  configSyncInFlight: boolean;
  lastError?: string;
  currentConfigVersion?: string;
  lastHeartbeatAt?: string;
  lastHeartbeatOk?: boolean;
  lastHeartbeatStatus?: string;
  lastHeartbeatError?: string;
  lastHeartbeatBilling?: RuntimeHeartbeatBillingSummary;
  lastConfigSyncAt?: string;
  lastConfigSyncChanged?: boolean;
  lastConfigSyncError?: string;
  configSyncSuccessCount: number;
  heartbeatSuccessCount: number;
  lastEventFlushAt?: string;
  lastAcceptedEventCount?: number;
  lastEventTypes: RuntimeCloudEventType[];
  lastEventFlushError?: string;
  totalAcceptedEventCount: number;
}

export interface WorkspaceSkillSummary {
  id: string;
  name: string;
  description: string;
  category: string;
  enabled: boolean;
  ready: boolean;
  downloadState: SkillDownloadState;
  fileName?: string;
  fileSize?: number;
  lastSyncedAt?: string;
  lastError?: string;
}

export interface ExpertDefinition {
  id: string;
  name: string;
  entryMode: ExpertEntryMode;
  description?: string;
  starterPrompt?: string;
  promptFile?: string;
  promptAvailable: boolean;
  projectMatchKeywords: string[];
}

export interface PluginSummary {
  id: string;
  name: string;
  description: string;
  status: PluginStatus;
  includedByDefault: boolean;
}

export interface WorkspaceSummary {
  shellReady: boolean;
  apiKeyConfigured: boolean;
  bindingRequired: boolean;
  setupRequired: boolean;
  setupMode: SetupMode;
  chatReady: boolean;
  chatLaunchState: ChatLaunchState;
  chatStatusMessage?: string;
  startupPhase: WorkspaceStartupPhase;
  startupMessage?: string;
  employeeId?: string;
  employeeName?: string;
  welcomeMessage?: string;
  modelId?: string;
  modelDisplayName?: string;
  configVersion?: string;
  lastFetchedAt?: string;
  runtimeCloudState: RuntimeCloudState;
  runtimeState: RuntimeProcessState | "unavailable";
  runtimeMessage?: string;
  currentProjectId?: string;
  currentProjectName?: string;
  projectVersion?: string;
  projectReady: boolean;
  projectCount: number;
  projects: ProjectSummary[];
  sessions: ProjectSessionSummary[];
  skillCount: number;
  skills: WorkspaceSkillSummary[];
  plugins: PluginSummary[];
  lastError?: string;
}

export interface LogEntry {
  ts: string;
  level: LogLevel;
  source: "app" | "runtime" | "gateway" | "cloud";
  message: string;
}

export interface SessionSummary {
  id: string;
  title: string;
  updatedAt: string;
}

export type ProjectPackageEntryType = "skill" | "workspace-entry";
export type ProjectConfirmationPolicy = "always" | "never" | "publish-only";

export interface ProjectPackageEntry {
  id: string;
  type: ProjectPackageEntryType;
  requiresSkills: string[];
  capabilities: string[];
  intentAliases: string[];
  confirmationPolicy?: ProjectConfirmationPolicy;
}

export interface ProjectPackageConfig {
  projectType?: string;
  platform?: string;
  capabilities: string[];
  requires: string[];
  confirmationPolicy?: ProjectConfirmationPolicy;
  defaultEntry?: ProjectPackageEntry;
  entries: ProjectPackageEntry[];
}

export interface ProjectSummary {
  id: string;
  name: string;
  displayName?: string;
  isBuiltinHome?: boolean;
  description?: string;
  version?: string;
  updatedAt: string;
  skillCount: number;
  ready: boolean;
  projectType?: string;
  platform?: string;
  defaultEntryId?: string;
  defaultEntryType?: ProjectPackageEntryType;
}

export interface ProjectIntentSuggestion {
  projectId: string;
  projectName: string;
  projectDisplayName: string;
  score: number;
  confidence: "low" | "medium" | "high";
  reason: string;
  matchedAliases: string[];
}

export interface ProjectSessionSummary extends SessionSummary {
  projectId: string;
}

export interface ProjectContextBoundSkill {
  id: string;
  name: string;
  description?: string;
}

export interface ProjectContextSnapshot {
  projectId: string;
  projectName: string;
  projectRoot: string;
  snapshotId: string;
  generatedAt: string;
  soul: string | null;
  user: string | null;
  readme: string | null;
  memorySummary: string | null;
  boundSkills: ProjectContextBoundSkill[];
}

export interface ProjectSessionState {
  sessionId: string;
  projectId: string;
  projectRoot: string;
  title: string;
  createdAt: string;
  updatedAt: string;
  lastActiveAt: string;
  contextSnapshotId: string | null;
  contextLoadedAt: string | null;
  selectedSkillId: string | null;
  draft: string;
}

export interface ChatAttachment {
  kind: "image" | "file";
  name: string;
  mimeType: string;
  localPath: string;
}

export interface ProjectResolvedAttachment extends ChatAttachment {
  projectPath: string;
  relativeProjectPath: string;
}

export interface ProjectExecutionRequest {
  sessionId: string;
  projectId: string;
  projectRoot: string;
  userPrompt: string;
  context: ProjectContextSnapshot;
  selectedSkillId: string | null;
  attachments?: ProjectResolvedAttachment[];
  projectConfig?: ProjectPackageConfig | null;
}

export type ProjectExecutionDecision =
  | {
      kind: "skill";
      skillId: string;
      preparedPrompt: string;
    }
  | {
      kind: "workspace-entry";
      projectRoot: string;
      preparedPrompt: string;
      reason: string;
    }
  | {
      kind: "chat-fallback";
      preparedPrompt: string;
    };

export interface ChatMessage {
  id: string;
  role: MessageRole;
  content: string;
  createdAt: string;
  attachments?: ChatAttachment[];
  streamState?: "streaming" | "error";
  statusLabel?: string;
  statusDetail?: string;
}

export type ChatExecutionPolicySource = "cloud-default" | "cloud-skill-binding" | "local-fallback" | "client-config";
export type ChatExecutionRoutingMode = ModelRoutingMode | SkillModelBindingMode | "fallback";

export interface ChatExecutionPolicy {
  source: ChatExecutionPolicySource;
  modelId: string;
  modelLabel: string;
  routingMode: ChatExecutionRoutingMode;
  skillId?: string;
  skillName?: string;
  message: string;
}

export interface ChatStreamPromptResult {
  requestId: string;
  sessionId: string;
  runId?: string;
  userMessageId?: string;
  assistantMessageId: string;
  executionPolicy?: ChatExecutionPolicy;
}

export interface ChatStreamStartedEvent {
  type: "started";
  requestId: string;
  sessionId: string;
  runId?: string;
  executionPolicy?: ChatExecutionPolicy;
}

export interface ChatStreamDeltaEvent {
  type: "delta";
  requestId: string;
  sessionId: string;
  runId: string;
  textDelta: string;
  fullText?: string;
}

export interface ChatStreamStatusEvent {
  type: "status";
  requestId: string;
  sessionId: string;
  runId?: string;
  stage: string;
  label: string;
  detail?: string;
}

export interface ChatStreamCompletedEvent {
  type: "completed";
  requestId: string;
  sessionId: string;
  runId: string;
  reply: ChatMessage;
  executionPolicy?: ChatExecutionPolicy;
}

export interface ChatStreamErrorEvent {
  type: "error";
  requestId: string;
  sessionId: string;
  runId?: string;
  message: string;
  errorCategory?: string;
}

export type ChatStreamEvent = ChatStreamStartedEvent | ChatStreamStatusEvent | ChatStreamDeltaEvent | ChatStreamCompletedEvent | ChatStreamErrorEvent;

export type ChatStreamListener = (event: ChatStreamEvent) => void;

export interface PromptResult {
  sessionId: string;
  reply: ChatMessage;
  executionPolicy?: ChatExecutionPolicy;
}

export interface ModelEndpointConfig {
  baseUrl: string;
  apiKeyConfigured: boolean;
  modelId?: string;
}

export interface DigitalHumanModelConfig {
  volcRegion: string;
  volcService: string;
  volcHost: string;
  volcScheme: string;
  ttsVoice: string;
  qiniuBucket: string;
  qiniuDomain: string;
  qiniuKeyPrefix: string;
  volcAccessKeyConfigured: boolean;
  volcSecretKeyConfigured: boolean;
  qiniuAccessKeyConfigured: boolean;
  qiniuSecretKeyConfigured: boolean;
}

export interface DouyinTextModelConfig {
  baseUrl: string;
  apiKeyConfigured: boolean;
  modelId?: string;
}

export interface VectCutModelConfig {
  baseUrl: string;
  fileBaseUrl: string;
  apiKeyConfigured: boolean;
}

export interface ExpertModelConfig {
  image: ModelEndpointConfig;
  video: ModelEndpointConfig;
  copywriting: ModelEndpointConfig;
  digitalHuman: DigitalHumanModelConfig;
}

export interface DouyinRuntimeConfig {
  videoAnalyzer: DouyinTextModelConfig;
  replicationBrief: DouyinTextModelConfig;
  vectcut: VectCutModelConfig;
}

export interface XhsFeishuConfig {
  appIdConfigured: boolean;
  appSecretConfigured: boolean;
  appTokenConfigured: boolean;
  tableIdConfigured: boolean;
}

export const FIXED_EXPERT_MODEL_ENDPOINTS = {
  copywriting: {
    baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1",
    modelId: "qwen3.6-plus"
  },
  image: {
    baseUrl: "https://ark.cn-beijing.volces.com/api/v3/images/generations",
    modelId: "doubao-seedream-5-0-260128"
  },
  video: {
    baseUrl: "https://ark.cn-beijing.volces.com/api/v3",
    modelId: "doubao-seedance-2-0-260128"
  }
} as const;

export const FIXED_DIGITAL_HUMAN_CONFIG = {
  volcRegion: "cn-north-1",
  volcService: "cv",
  volcHost: "visual.volcengineapi.com",
  volcScheme: "https",
  ttsVoice: "zh-CN-YunxiNeural",
  qiniuBucket: "alketas",
  qiniuDomain: "http://tcwwu6wg4.hd-bkt.clouddn.com",
  qiniuKeyPrefix: "omnihuman"
} as const;

export const FIXED_DOUYIN_RUNTIME_CONFIG = {
  videoAnalyzer: {
    baseUrl: "https://ark.cn-beijing.volces.com/api/v3",
    modelId: "doubao-vision",
  },
  replicationBrief: {
    baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1",
    modelId: "qwen-max",
  },
  vectcut: {
    baseUrl: "https://open.vectcut.com/cut_jianying",
    fileBaseUrl: "https://open.vectcut.com"
  }
} as const;

export interface AppConfig {
  setupMode: SetupMode;
  provider: string;
  baseUrl: string;
  apiKeyConfigured: boolean;
  gatewayTokenConfigured: boolean;
  authTokenConfigured: boolean;
  defaultModel: string;
  workspacePath: string;
  gatewayUrl: string;
  cloudApiBaseUrl: string;
  runtimeCloudApiBaseUrl: string;
  runtimeMode: RuntimeModePreference;
  expertModelConfig: ExpertModelConfig;
  douyinRuntimeConfig: DouyinRuntimeConfig;
  xhsFeishuConfig: XhsFeishuConfig;
}

export interface DiagnosticsExportResult {
  filePath: string;
  createdAt: string;
  startupLogPath?: string;
}

export interface ModelEndpointInput {
  baseUrl?: string;
  apiKey?: string;
  modelId?: string;
}

export interface DigitalHumanModelInput {
  volcAccessKey?: string;
  volcSecretKey?: string;
  qiniuAccessKey?: string;
  qiniuSecretKey?: string;
}

export interface DouyinTextModelInput {
  baseUrl?: string;
  apiKey?: string;
  modelId?: string;
}

export interface VectCutModelInput {
  baseUrl?: string;
  fileBaseUrl?: string;
  apiKey?: string;
}

export interface XhsFeishuConfigInput {
  appId?: string;
  appSecret?: string;
  appToken?: string;
  tableId?: string;
}

export interface SaveConfigInput {
  setupMode: SetupMode;
  provider: string;
  baseUrl: string;
  apiKey?: string;
  gatewayToken?: string;
  authToken?: string;
  defaultModel: string;
  workspacePath: string;
  gatewayUrl: string;
  cloudApiBaseUrl: string;
  runtimeCloudApiBaseUrl: string;
  runtimeMode: RuntimeModePreference;
  expertModelConfig?: {
    image?: ModelEndpointInput;
    video?: ModelEndpointInput;
    copywriting?: ModelEndpointInput;
    digitalHuman?: DigitalHumanModelInput;
  };
  douyinRuntimeConfig?: {
    videoAnalyzer?: DouyinTextModelInput;
    replicationBrief?: DouyinTextModelInput;
    vectcut?: VectCutModelInput;
  };
  xhsFeishuConfig?: XhsFeishuConfigInput;
}

export interface AuthSessionSummary {
  state: AuthSessionState;
  tokenConfigured: boolean;
  message: string;
  displayName?: string;
  email?: string;
  organizationName?: string;
  lastValidatedAt?: string;
}

export interface SignInInput {
  accessToken: string;
}

export interface UserProfileSummary {
  userId: string;
  displayName: string;
  email: string;
  organizationName: string;
  avatarUrl?: string;
  title?: string;
}

export interface CreditSummary {
  balance: number;
  granted: number;
  used: number;
  currency: "credits";
  status: CreditStatus;
  updatedAt: string;
  expiresAt?: string;
}

export interface SkillSummary {
  id: string;
  name: string;
  description: string;
  category: string;
  enabled: boolean;
  ready: boolean;
  downloadState: SkillDownloadState;
  fileName?: string;
  fileSize?: number;
  lastSyncedAt?: string;
  lastError?: string;
  requiresCredits?: number;
}

export type SkillCatalogAvailability = "usable" | "info-only";
export type SkillCatalogSource = "project" | "q-skills" | "hybrid";

export interface SkillCatalogItem {
  id: string;
  name: string;
  zhName: string;
  description: string;
  zhDescription: string;
  category: string;
  source: SkillCatalogSource;
  availability: SkillCatalogAvailability;
  selectable: boolean;
  isProjectSkill: boolean;
  showInSkillsPage: boolean;
  searchText: string;
  selectionHint?: string;
}

export interface ModelCatalogItemSummary {
  id: string;
  label: string;
  provider: string;
  family: string;
  description?: string;
  enabled: boolean;
  contextWindow?: number;
  maxOutputTokens?: number;
  capabilities: ModelCapability[];
  recommendedFor: ModelRecommendation[];
}

export interface SkillModelBindingSummary {
  skillId: string;
  skillName: string;
  modelId: string;
  modelLabel: string;
  routingMode: SkillModelBindingMode;
}

export interface ModelConfigSummary {
  source: "cloud";
  catalogVersion?: string;
  updatedAt: string;
  fetchedAt: string;
  routingMode: ModelRoutingMode;
  fallbackMode: ModelConfigFallbackMode;
  defaultChatModelId: string;
  defaultChatModelLabel: string;
  defaultSkillModelId?: string;
  defaultSkillModelLabel?: string;
  items: ModelCatalogItemSummary[];
  skillBindings: SkillModelBindingSummary[];
  message: string;
}

export interface SystemSummary {
  appName: string;
  appVersion: string;
  isPackaged: boolean;
  platform: string;
  arch: string;
  appPath: string;
  resourcesPath: string;
  userDataPath: string;
  logsPath: string;
}

export interface TaskPanelArtifact {
  id: string;
  name: string;
  kind?: string;
  summary?: string;
  url?: string;
}

export interface TaskPanelItem {
  id: string;
  date: string;
  expertName: string;
  taskTitle: string;
  status: TaskPanelStatus;
  statusDetail: string;
  creditsUsed?: number;
  messageCount?: number;
  updatedAt?: string;
  artifacts: TaskPanelArtifact[];
}

export interface DesktopApi {
  workspace: {
    getSummary(): Promise<WorkspaceSummary>;
    warmup(): Promise<WorkspaceWarmupResult>;
  };
  window: {
    minimize(): Promise<void>;
    maximize(): Promise<void>;
    close(): Promise<void>;
  };
  gateway: {
    status(): Promise<GatewayStatus>;
    connect(): Promise<GatewayStatus>;
    disconnect(): Promise<GatewayStatus>;
    reconnect(): Promise<GatewayStatus>;
    health(): Promise<GatewayHealth>;
    tailLogs(limit?: number): Promise<LogEntry[]>;
  };
  runtime: {
    getStatus(): Promise<RuntimeStatus>;
    tailLogs(limit?: number): Promise<LogEntry[]>;
    start(): Promise<RuntimeStatus>;
    stop(): Promise<RuntimeStatus>;
    restart(): Promise<RuntimeStatus>;
    health(): Promise<RuntimeHealth>;
  };
  runtimeCloud: {
    getStatus(): Promise<RuntimeCloudStatus>;
    fetchConfig(action?: RuntimeCloudFetchAction): Promise<RuntimeCloudStatus>;
  };
  runtimeTelemetry: {
    getStatus(): Promise<RuntimeTelemetryStatus>;
  };
  config: {
    load(): Promise<AppConfig>;
    pickWorkspaceDirectory(currentPath?: string): Promise<string | null>;
    save(input: SaveConfigInput): Promise<AppConfig>;
    revealSecret(secretId: ConfigSecretId): Promise<string | null>;
  };
  projects: {
    list(): Promise<ProjectSummary[]>;
    setActive(projectId: string): Promise<WorkspaceSummary>;
    resolveIntent(prompt: string, currentProjectId?: string): Promise<ProjectIntentSuggestion | null>;
  };
  skillCatalog: {
    list(): Promise<SkillCatalogItem[]>;
  };
  auth: {
    getSessionSummary(): Promise<AuthSessionSummary>;
    signIn(input: SignInInput): Promise<AuthSessionSummary>;
    signOut(): Promise<AuthSessionSummary>;
  };
  profile: {
    getSummary(): Promise<UserProfileSummary>;
  };
  credits: {
    getSummary(): Promise<CreditSummary>;
  };
  skills: {
    list(): Promise<SkillSummary[]>;
  };
  experts: {
    list(): Promise<ExpertDefinition[]>;
  };
  modelConfig: {
    getSummary(): Promise<ModelConfigSummary>;
  };
  system: {
    getSummary(): Promise<SystemSummary>;
  };
  tasks: {
    listByDate(date: string): Promise<TaskPanelItem[]>;
  };
  chat: {
    listSessions(): Promise<ProjectSessionSummary[]>;
    listSessionsByProject(projectId: string): Promise<ProjectSessionSummary[]>;
    createSession(title?: string): Promise<ProjectSessionSummary>;
    createSessionForProject(projectId: string, title?: string): Promise<ProjectSessionSummary>;
    closeSession(sessionId: string): Promise<ProjectSessionSummary[]>;
    listMessages(sessionId: string): Promise<ChatMessage[]>;
    pickAttachments(): Promise<ChatAttachment[]>;
    pickImageAttachment(): Promise<ChatAttachment | null>;
    readImageAttachmentDataUrl(attachment: ChatAttachment): Promise<string | null>;
    sendPrompt(sessionId: string, prompt: string, skillId?: string, attachments?: ChatAttachment[]): Promise<PromptResult>;
    streamPrompt(sessionId: string, prompt: string, skillId?: string, attachments?: ChatAttachment[]): Promise<ChatStreamPromptResult>;
    onStreamEvent(listener: ChatStreamListener): () => void;
  };
  diagnostics: {
    openControlUi(): Promise<void>;
    exportSnapshot(): Promise<DiagnosticsExportResult>;
  };
}
