export type InsufficientBalanceDetails = { code: 'INSUFFICIENT_BALANCE'; balanceCents: number; minRechargeCents: number; suggestedTiers: number[]; }; export type PortalUser = { id: string; username: string; slug?: string; email?: string | null; displayName: string; role: 'user' | 'admin'; status: 'active' | 'suspended' | 'disabled'; planType?: 'free' | 'growth' | 'pro' | 'enterprise'; workspaceRoot: string; balanceCents: number; totalCreditCents?: number; tokensUsed: number; spaceQuotaBytes?: number; spaceUsedBytes?: number; spaceReservedBytes?: number; spaceAvailableBytes?: number; publishSlug?: string; publishUrl?: string; publishSkillName?: string; }; export type CapabilityMap = Record; export type PolicyValue = string | boolean; export type PolicyMap = Record; export type SkillMap = Record; export type AuthStatus = { authenticated: boolean; mode?: 'user' | 'legacy' | 'none'; user?: PortalUser | null; capabilities?: CapabilityMap; grantedSkills?: string[]; unrestricted?: boolean; }; export type AdminUserRow = PortalUser & { createdAt: number; updatedAt: number; }; export type CapabilityDefinition = { key: string; label: string; description: string; risk: 'low' | 'medium' | 'high'; category: string; }; export type SkillDefinition = { name: string; dirName: string; label: string; description: string; category: string; requiresPublish?: boolean; }; export type PolicyDefinition = { key: string; label: string; description: string; type: 'select' | 'boolean'; options?: Array<{ value: string; label: string }>; defaultValue: PolicyValue; category: string; risk: 'low' | 'medium' | 'high'; }; export type LlmProviderDefinition = { id: string; label: string; kind?: 'builtin' | 'custom'; apiKeyEnv: string | null; defaultModel: string; models: string[]; }; export type LlmProviderKeyRow = { id: string; providerId: string; providerKind: 'builtin' | 'custom'; providerLabel: string; name: string; defaultModel: string; models: string[]; apiUrl: string | null; basePath: string | null; engine: string; relayProvider: string | null; goosedProviderId: string | null; status: 'active' | 'disabled'; isSelected: boolean; isVisionSelected: boolean; apiKeyMasked: string; createdAt: number; updatedAt: number; }; export type LlmGlobalSettings = { keyId: string | null; keyName: string | null; providerLabel: string | null; globalModel: string | null; availableModels: string[]; }; export type LlmVisionSettings = { keyId: string | null; keyName: string | null; providerLabel: string | null; visionModel: string | null; availableModels: string[]; }; export type LlmConnectionTestResult = { ok: boolean; latencyMs?: number; reply?: string; model?: string; message?: string; }; export type LlmExecutorId = 'goose' | 'aider' | 'openhands'; export type LlmExecutorBinding = { id: string | null; executor: LlmExecutorId; executorLabel: string; executorDescription: string; purpose: string; providerKeyId: string | null; providerName: string | null; providerLabel: string | null; providerId: string | null; model: string; enabled: boolean; availableModels: string[]; createdAt: number | null; updatedAt: number | null; }; export type LlmExecutorRuntime = { ok: boolean; executor: LlmExecutorId; executorLabel?: string; purpose?: string; providerKeyId?: string; providerName?: string; providerKind?: string; providerId?: string; providerLabel?: string; goosedProviderId?: string | null; model?: string; apiUrl?: string | null; apiBaseUrl?: string; apiKeyMasked?: string; env?: Record; message?: string; }; export type LlmExecutorLaunchPlan = { ok: boolean; executor: LlmExecutorId | null; cwd?: string; command?: string; args?: string[]; env?: Record; notes?: string[]; message?: string; }; export type LlmExecutorLaunchState = { executor: LlmExecutorId; purpose: string; pid: number | null; running: boolean; command: string | null; args: string[]; cwd: string | null; logFile: string | null; startedAt: number | null; stoppedAt: number | null; exitReason: string | null; mode: string | null; instruction: string | null; }; export type AssetPluginConfig = { pluginId: string; label: string; description: string; providers: string[]; supportsLlm: boolean; enabled: boolean; provider: string | null; llmProviderKeyId: string | null; llmProviderName: string | null; llmProviderId: string | null; llmModel: string | null; updatedAt: number | null; purposes?: Record; purposeCatalog?: Array<{ id: string; label: string; presetId: string; }>; }; export type AssetGatewayConfig = { enabled: boolean; updatedAt: number | null; plugins: AssetPluginConfig[]; }; export type AdminServiceRestartAction = 'local_restart' | 'pro_restart'; export type AdminServiceRestartResult = { ok: boolean; action: AdminServiceRestartAction; message: string; pid?: number | null; output?: string; logFile?: string | null; }; export type UsageRecord = { id: number; userId: string; username: string; displayName: string; agentSessionId: string; requestId: string | null; inputTokens: number; outputTokens: number; costCents: number; balanceAfterCents: number; createdAt: number; }; export type UsageStatsBucket = { day: string; count: number; inputTokens: number; outputTokens: number; costCents: number; }; export type UsageTotals = { count: number; inputTokens: number; outputTokens: number; costCents: number; }; export type UsageRangeTotals = UsageTotals & { startAt: number; endAt: number; }; export type UsageSummaryResult = { range: UsageRangeTotals | null; allTime: UsageTotals; }; export type UsageStatsResult = { buckets: UsageStatsBucket[]; startAt: number; endAt: number; }; export type LedgerEntry = { id: number; userId: string; username: string; type: 'recharge' | 'deduct' | 'refund' | 'adjust'; amountCents: number; tokens: number; sessionId: string | null; note: string | null; createdAt: number; }; export type WechatAdminSummary = { config: { mpEnabled: boolean; scheduleEnabled: boolean; reminderWorkerEnabled: boolean; appId: string | null; publicBaseUrl: string | null; bindPath: string | null; tokenEndpointConfigured: boolean; customerServiceEndpointConfigured: boolean; scheduleLlmEnabled: boolean; }; counts: { boundUsers: number; routes: { total: number; active: number }; recentMessages: Record; digests: Record; recentDeliveries: Record; }; }; export type WechatScheduleLlmConfig = { scheduleLlmEnabled: boolean; updatedAt: number | null; updatedBy: string | null; }; export type MindSpaceAdminConfig = { publicPageLimit: number; analytics: { enabled: boolean; websiteId: string; analyticsUrl: string; domains: string; idSecretConfigured: boolean; }; }; export type MindSpaceAnalyticsUpdate = { enabled?: boolean; websiteId?: string; analyticsUrl?: string; domains?: string; idSecret?: string; }; export type MemoryV2AdminSection = Record; export type MemoryV2ModelApiType = 'chat' | 'response'; export type MemoryV2AdminConfig = { global: { enabled?: boolean; backend?: string; profileEnabled?: boolean; eventLogEnabled?: boolean; vectorEnabled?: boolean; failOpen?: boolean; }; chatIntentRouter: MemoryV2AdminSection; candidateMemory: MemoryV2AdminSection; runtimeControl: MemoryV2AdminSection; policy: MemoryV2AdminSection; retriever: MemoryV2AdminSection; lifecycle: MemoryV2AdminSection; persona: MemoryV2AdminSection; graph: MemoryV2AdminSection; userMemory: MemoryV2AdminSection; pluginHealth: MemoryV2AdminSection; pgvector: MemoryV2AdminSection; qdrant: MemoryV2AdminSection; weaviate: MemoryV2AdminSection; mem0: MemoryV2AdminSection; letta: MemoryV2AdminSection; neo4j: MemoryV2AdminSection; redisStreams: MemoryV2AdminSection; langgraph: MemoryV2AdminSection; }; export type MemoryV2AdminConfigResponse = { config: MemoryV2AdminConfig; updatedAt: number | null; updatedBy: string | null; }; export type MemoryV2ConfigRuntimeState = { source: string; updatedAt: number | null; updatedBy: string | null; fingerprint?: string; overrides: Record; }; export type MemoryV2RuntimeStatusResponse = { ok: boolean; checkedAt?: number; message?: string; memory?: { enabled?: boolean; backend?: string; selectedBackend?: string | null; configSource?: string; configUpdatedAt?: number | null; personalMemory?: { enabled?: boolean; requestedMode?: string; effectiveMode?: string; autoReviewEnabled?: boolean; phase?: string; injectionEnabled?: boolean; persistence?: string; pendingCandidates?: number; health?: Record; policy?: Record; }; } | null; }; export type PersonalMemoryCandidate = { id: string; userId: string; sessionId: string | null; memoryType: string; content: string; importance: number; confidence: number; status: string; policyReason: string; evidence: Record; reviewedBy: string | null; reviewedAt: number | null; createdAt: number; updatedAt: number; }; export type PersonalMemoryCandidateListResponse = { items: PersonalMemoryCandidate[]; counts: Record; }; export type SkillRuntimeAdminConfig = { router: { v2Enabled: boolean; manifestRoutingEnabled: boolean; }; }; export type SkillRuntimeAdminConfigResponse = { config: SkillRuntimeAdminConfig; updatedAt: number | null; updatedBy: string | null; source?: string; }; export type SkillRuntimeCatalogItem = { name: string; dirName: string; description: string; version: string | null; executors: string[]; hasManifest: boolean; triggerKeywords: string[]; routerPromptKey: string | null; routerPriority: number; }; export type AdminSystemTestStepStatus = 'passed' | 'warning' | 'failed'; export type AdminSystemTestStep = { key: string; label: string; status: AdminSystemTestStepStatus; message: string; details?: Record | null; }; export type AdminSystemTestIssue = { stepKey: string; severity: 'warning' | 'error'; title: string; detail: string; }; export type AdminSystemTestReport = { ok: boolean; startedAt: number; finishedAt: number; portalBaseUrl: string; selectedSkill: string; account: { userId?: string; username: string; displayName?: string | null; }; summary: { passed: number; warnings: number; failed: number; }; steps: AdminSystemTestStep[]; issues: AdminSystemTestIssue[]; }; export type AdminSystemTestAccount = { id: string; label: string; username: string; passwordMasked: string; createdAt: number; updatedAt: number; updatedBy?: string | null; }; export type WechatBinding = { userId: string; username: string; displayName: string; status: string; appId: string | null; openidMasked: string; nickname: string | null; avatarUrl: string | null; lastLoginAt: number; boundAt: number; routeId: string | null; routeStatus: string | null; agentSessionId: string | null; routeUpdatedAt: number | null; }; export type WechatMessage = { appId: string | null; openidMasked: string; msgId: string; status: string; agentSessionId: string | null; createdAt: number; updatedAt: number; userId: string | null; username: string | null; displayName: string | null; }; export type WechatDigestSubscription = { id: string; userId: string; username: string; displayName: string; digestType: string; hour: number; minute: number; timezone: string; channel: string; status: string; nextRunAt: number; lastRunAt: number | null; attempts: number; lastError: string | null; sourceText: string | null; createdAt: number; updatedAt: number; }; export type WechatDeliveryLog = { id: string; reminderId: string | null; subscriptionId: string | null; userId: string; username: string; displayName: string; channel: string; status: string; providerMessageId: string | null; errorCode: string | null; errorMessage: string | null; createdAt: number; digestType: string | null; }; export type WechatWebNotification = { id: string; userId: string; username: string; displayName: string; channel: string; notificationType: string; title: string; body: string; status: string; readAt: number | null; createdAt: number; updatedAt: number; }; export type AdminDashboardSummary = { users: { total: number; active: number; lowBalance: number; totalBalanceCents: number; }; usage24h: { count: number; costCents: number; }; lowBalanceUsers: Array<{ id: string; username: string; displayName: string; balanceCents: number; }>; recentUsage: UsageRecord[]; recentLedger: LedgerEntry[]; llm: { keyCount: number; selectedKeyName: string | null; globalModel: string | null; } | null; }; export type BlockedWord = { id: string; word: string; replacement: string; note: string | null; status: 'active' | 'disabled'; created_at: number; updated_at: number; }; export type PlanDefinition = { planType: string; name: string; priceCents: number; periodDays: number; periodTokens: number; periodImages: number; modelTier: string; overageRate: number; sortOrder: number; isActive: boolean; description: string | null; }; export type PlanSyncResult = { enabled: boolean; ok: boolean; message: string; synced?: number; total?: number; failures?: string[]; }; export type AdminSubscription = { id: string; userId: string; username: string; displayName: string; planType: string; status: 'active' | 'expired' | 'cancelled'; startedAt: number; expiresAt: number; periodTokensLimit: number; periodTokensUsed: number; periodImagesLimit: number; periodImagesUsed: number; note: string | null; createdAt: number; }; export type MindSearchConfig = { enabled: boolean; mode: 'off' | 'shadow' | 'assist'; providers: { searxng: boolean; github: boolean; reader: boolean }; settings: { searxngEndpoint: string; maxResults: number; timeoutMs: number; readerMaxChars: number }; services: MindSearchService[]; routes: MindSearchRoutes; }; export type MindSearchService = { id: string; name: string; kind: 'provider' | 'reader' | 'orchestrator'; adapter: 'searxng' | 'github' | 'reader' | 'research-http'; capabilities: string[]; endpoint: string; healthPath: string; enabled: boolean; timeoutMs: number; priority: number; llmProviderKeyId?: string; llmModel?: string; }; export type MindSearchRoutes = { web: string; news: string; code: string; read: string; research: string; }; export type MindSearchServiceTestResult = { ok: boolean; serviceId: string; adapter: MindSearchService['adapter']; status: number | null; latencyMs: number; resultCount?: number | null; message: string; };