/** * API Container 依赖类型定义 * * 定义容器中注册的所有服务接口 */ import type { ApiServer } from '../ApiServer'; import type { AuthMiddleware } from '../middleware/AuthMiddleware'; import type { Authenticator } from '../auth/Authenticator'; import type { EdgeNodeRepository } from '../../identity/drizzle/EdgeNodeRepository'; import type { ServiceTokenRepositoryPort } from '../../identity/drizzle/ServiceTokenRepository'; import type { VercelChatService } from '../service/VercelChatService'; import type { SubdomainService } from '../../subdomain/SubdomainService'; import type { SubdomainClient } from '../../subdomain/SubdomainClient'; import type { DnsProvider } from '../../dns/DnsProvider'; import type { TunnelProvider } from '../../tunnel/TunnelProvider'; import type { ActiveTunnelProvider, TunnelProfile } from '../../tunnel/TunnelProfiles'; import type { AcmeCertificateManager } from '../../edge/acme/AcmeCertificateManager'; import type { ClusterCertificateManager } from '../../edge/acme/ClusterCertificateManager'; import type { EdgeNodeCertificateCapabilityBridge } from '../../edge/EdgeNodeCertificateCapabilityBridge'; import type { IdentityDatabase } from '../../identity/drizzle/db'; import type { DdnsRepository } from '../../identity/drizzle/DdnsRepository'; import type { PodLookupRepository } from '../../identity/drizzle/PodLookupRepository'; import type { AccountRoleRepository } from '../../identity/drizzle/AccountRoleRepository'; import type { ChatKitService, AiProvider } from '../chatkit'; import type { StoreContext } from '../chatkit/store'; import type { PodChatKitStore } from '../chatkit/pod-store'; import type { RuntimeHost } from '../../runtime/host/types'; import type { ProviderRegistry, EmbeddingService, EmbeddingModelPolicy } from '../../ai/service'; import type { VectorService } from '../service/VectorService'; import type { RdfSearchIndexingService } from '../service/RdfSearchIndexingService'; import type { RdfSearchReconciliationRepository } from '../../search/RdfSearchReconciliationRepository'; import type { RdfSearchReconciliationWorker } from '../service/RdfSearchReconciliationWorker'; import type { RdfStorageStatsService } from '../service/RdfStorageStatsService'; import type { InngestRunExecutionBackend } from '../runs/InngestRunExecutionBackend'; import type { RunContextRetriever } from '../runs/RunExecutionBackend'; import type { EmbeddedInngestRuntimeConfig } from '../runs/EmbeddedInngestService'; import type { RunAuthContextRegistry } from '../runs/RunAuthContextRegistry'; import type { TaskAuthBindingService, TaskService, InngestTaskScheduler } from '../tasks'; import type { PodMatrixStore } from '../matrix'; import type { ClientReconcilerCoordinator, ServerGroupReconcilerService } from '../reconciler'; import type { AuthMode } from '../../authorization/AuthMode'; import type { RdfEngineLike } from '../../storage/rdf'; import type { CredentialVault } from '../ai-gateway/credentials/CredentialVault'; import type { ProviderConnectService } from '../ai-gateway/connect'; import type { ProviderQuotaService } from '../ai-gateway/quota'; import type { ProviderCustomModelsService, ProviderModelsService } from '../ai-gateway/models'; import type { AiGatewayService, GatewayCredentialStore } from '../ai-gateway/AiGatewayService'; import type { ProviderRuntimeRegistry } from '../ai-gateway/providers/ProviderRuntimeRegistry'; import type { ProviderHttpTransport } from '../service/provider-http-transport'; import type { ProviderRegistry as GatewayProviderRegistry } from '../ai-gateway/providers/ProviderRegistry'; import type { SessionAffinityStore } from '../ai-gateway/routing/SessionAffinityStore'; import type { AiConnectionsInvocationKeyIssuer } from '../ai-gateway/auth/AiConnectionsInvocationKeyIssuer'; import type { InvocationTokenCodec } from '../ai-gateway/auth/InvocationTokenCodec'; import type { InternalPodAccessTokenProvider } from '../ai-gateway/pod/HostedPodDataAccess'; import type { GatewayAccessKeyRepository } from '../ai-gateway/auth/GatewayApiKeyAuthenticator'; import type { PodModelSelectionRepository } from '../ai-gateway/models/PodModelSelectionRepository'; import type { ProviderModelSelectionService } from '../ai-gateway/models/ProviderModelSelectionService'; import type { AiClientConfigurationService } from '../service/AiClientConfigurationService'; /** * 容器配置 */ export interface ApiContainerConfig { /** 运行模式: cloud 持有密钥, local 调用远程 */ edition: 'cloud' | 'local'; /** API Server 端口 */ port: number; /** API Server 主机 */ host: string; /** API Server Unix socket 路径 */ socketPath?: string; /** Runtime host implementation */ runtimeHost?: RuntimeHost; /** Solid authorization mode used by CSS and SP-local Pod provisioning. */ authMode: AuthMode; /** RDF term-id index used by CSS LDP structured reads. */ rdfIndexPath?: string; /** 数据库连接 URL */ databaseUrl: string; /** RDF/SPARQL facts database connection URL. */ sparqlEndpoint?: string; /** Route SPARQL reads through an installed native SPARQL provider. */ rdfNativeSparqlEnabled?: boolean; /** Redis connection URL, used by embedded infrastructure such as Inngest in cloud mode. */ redisUrl?: string; /** Embedded Inngest runtime configuration. */ inngest?: { enabled: boolean; mode?: 'managed' | 'spawn'; port?: number; host?: string; baseUrl?: string; eventKey?: string; signingKey?: string; binaryPath?: string; sqliteDir?: string; }; /** Resolved runtime config passed from API bootstrap after starting/locating Inngest. */ inngestRuntimeConfig?: EmbeddedInngestRuntimeConfig; /** CORS 允许的源 */ corsOrigins: string[]; /** CSS Token 端点 */ cssTokenEndpoint: string; solidBaseUrl?: string; /** Stateless AI Connections invocation token signing config. */ aiConnectionInvocationSecret?: string; aiConnectionInvocationKeyId?: string; aiConnectionPreviousInvocationSecrets?: Array<{ kid: string; secret: string; }>; /** Durable Gateway API Key locator signing config. */ gatewayLocatorSecret?: string; gatewayLocatorKeyId?: string; gatewayPreviousLocatorSecrets?: Array<{ kid: string; secret: string; }>; aiGatewaySessionAffinitySecret?: string; /** Runtime-generated secret used only between GatewayProxy and the internal API server for admin ingress evidence. */ gatewayAdminProxyAuthSecret?: string; /** Local filesystem host capability for AI coding-client configuration. Disabled unless explicitly injected. */ aiClientConfiguration?: { enabled: boolean; homeDir: string; backupRoot?: string; authority: 'local-filesystem'; }; /** Platform signing secret for short-lived provider Connect attempts. */ aiGatewayConnectSigningSecret?: string; /** Xpod-issued Kimi OAuth integration. Both values must be server-side configured. */ aiGatewayKimiOAuthIntegrationId?: string; aiGatewayKimiOAuthClientId?: string; /** Override for the models.dev provider catalog endpoint (tests and controlled deployments). */ aiGatewayModelsDevUrl?: string; /** Optional legacy SecretCell reader used only to migrate existing encrypted Pod credentials. */ secretCellCredentialVaultFactory?: () => CredentialVault; /** Explicit provider endpoint overrides for controlled deployments and local E2E fixtures. */ aiGatewayProviderBaseUrls?: Partial>; /** 子域名功能配置 (cloud 模式) */ subdomain?: { /** 节点域名根域名 (如 undefineds.site),有值即启用子域名功能 */ baseStorageDomain?: string; cloudflareAccountId?: string; cloudflareApiToken?: string; tencentDnsSecretId?: string; tencentDnsSecretKey?: string; }; /** Cloud API 端点 (local 托管式,调用 cloud 的子域名 API) */ cloudApiEndpoint?: string; /** 节点 ID (local 托管式) */ nodeId?: string; /** 节点 Token (local 托管式,调用 Cloud API 的认证) */ nodeToken?: string; /** Local SP service token(Cloud 回调 Local、Local 服务级 API 的唯一服务凭据) */ serviceToken?: string; /** 已签发的 provisionCode(Local 首次注册/刷新后持久化恢复) */ provisionCode?: string; /** Local canonical public URL(通常来自 CSS_BASE_URL,也可从 setup 恢复) */ publicUrl?: string; /** Cloud 分配或用户指定的 SP 域名 */ spDomain?: string; /** Local setup/provision 状态文件路径 */ localSetupPath?: string; /** Local setup/provision 状态文件中的 provider key */ localSetupProviderId?: string; /** OIDC Issuer URL (local 托管式,使用 Cloud IdP) */ oidcIssuer?: string; /** Active tunnel provider after resolving profile selection. */ tunnelProvider?: ActiveTunnelProvider; /** Recorded tunnel profiles. Only tunnelActiveProfileId/activeTunnelProfile takes effect at runtime. */ tunnelProfiles?: TunnelProfile[]; /** Selected tunnel profile id. */ tunnelActiveProfileId?: string; /** Selected tunnel profile. */ activeTunnelProfile?: TunnelProfile; /** Cloudflare Tunnel Token (local 托管式/自管式,启动 cloudflared) */ cloudflareTunnelToken?: string; /** SakuraFRP Tunnel Token (SAKURA_TUNNEL_TOKEN;local 托管式/自管式,启动 frpc) */ sakuraTunnelToken?: string; /** ngrok authtoken (local only; not sent to Cloud). */ ngrokAuthToken?: string; /** Fixed ngrok endpoint/custom domain, e.g. https://example.ngrok-free.dev. */ ngrokUrl?: string; /** ngrok executable path. */ ngrokPath?: string; /** frpc executable path (FRPC_BIN); the SakuraFrp build is required, not the generic one. */ frpcPath?: string; /** 是否接受 Edge 节点注册 (cloud 模式) */ edgeNodesEnabled?: boolean; } import { EdgeNodeDnsCoordinator } from '../../edge/EdgeNodeDnsCoordinator'; import { EdgeNodeHealthProbeService } from '../../edge/EdgeNodeHealthProbeService'; import { EdgeNodeCapabilityDetector } from '../../edge/EdgeNodeCapabilityDetector'; import { LocalNetworkManager } from '../../edge/LocalNetworkManager'; import { DdnsManager } from '../../edge/DdnsManager'; /** * 容器中注册的所有服务 */ export interface ApiContainerCradle { config: ApiContainerConfig; db: IdentityDatabase; apiServer: ApiServer; authMiddleware: AuthMiddleware; authenticator: Authenticator; nodeRepo: EdgeNodeRepository; serviceTokenRepo: ServiceTokenRepositoryPort; hostedPodDataAccess: InternalPodAccessTokenProvider; invocationTokenCodec?: InvocationTokenCodec; gatewayAccessKeyRepository?: GatewayAccessKeyRepository; aiConnectionInvocationKeyIssuer?: AiConnectionsInvocationKeyIssuer; aiClientConfigurationService?: AiClientConfigurationService; providerConnectService: ProviderConnectService; providerQuotaService?: ProviderQuotaService; providerModelsService?: ProviderModelsService; podModelSelectionRepository: PodModelSelectionRepository; providerModelSelectionService: ProviderModelSelectionService; providerCustomModelsService?: ProviderCustomModelsService; gatewayProviderRegistry: GatewayProviderRegistry; gatewayCredentialStore: GatewayCredentialStore; gatewayRuntimeRegistry: ProviderRuntimeRegistry; providerHttpTransport: ProviderHttpTransport; gatewaySessionAffinityStore: SessionAffinityStore; aiGatewayService?: AiGatewayService; chatService: VercelChatService; chatKitStore: PodChatKitStore; chatKitAiProvider: AiProvider; inngestRuntimeConfig: EmbeddedInngestRuntimeConfig | undefined; runAuthContextRegistry: RunAuthContextRegistry; rdfEngine: RdfEngineLike | undefined; runContextRetriever: RunContextRetriever | undefined; rdfSearchIndexingService: RdfSearchIndexingService | undefined; rdfSearchReconciliationRepository: RdfSearchReconciliationRepository; rdfSearchReconciliationWorker: RdfSearchReconciliationWorker; runExecutionBackend: InngestRunExecutionBackend; taskAuthBindingService: TaskAuthBindingService; taskService: TaskService; inngestTaskScheduler: InngestTaskScheduler; chatKitService: ChatKitService; matrixStore: PodMatrixStore; clientReconcilerCoordinator: ClientReconcilerCoordinator; serverGroupReconcilerService: ServerGroupReconcilerService; providerRegistry: ProviderRegistry; embeddingService: EmbeddingService; /** Deployment embedding policy: cloud only allows models the gateway catalog provides. */ embeddingModelPolicy: EmbeddingModelPolicy; vectorService: VectorService; rdfStorageStatsService: RdfStorageStatsService; ddnsRepo?: DdnsRepository; podLookupRepo?: PodLookupRepository; accountRoleRepo?: AccountRoleRepository; dnsProvider?: DnsProvider; dnsCoordinator?: EdgeNodeDnsCoordinator; healthProbeService?: EdgeNodeHealthProbeService; capabilityDetector?: EdgeNodeCapabilityDetector; localNetworkManager?: LocalNetworkManager; tunnelProvider?: TunnelProvider; subdomainService?: SubdomainService; subdomainClient?: SubdomainClient; ddnsManager?: DdnsManager; localTunnelProvider?: TunnelProvider; edgeNodeCertificateCapabilityBridge?: EdgeNodeCertificateCapabilityBridge; certificateManager?: unknown; acmeCertificateManager?: AcmeCertificateManager; clusterCertificateManager?: ClusterCertificateManager; }