Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

11.5 KB
Raw Blame
import type { AiFullModelCard } from 'model-bank';
import type { PartialDeep } from 'type-fest';

import type {
  GlobalLLMProviderKey,
  UserDefaultAgent,
  UserImageConfig,
  UserServiceModelConfig,
} from './user/settings';

/**
 * Resolved server feature flags, keyed for the client. The canonical mapping
 * lives in `@lobechat/app-config`'s `mapFeatureFlagsEnvToState`, whose explicit
 * return-type annotation pins it to this interface — add a flag there and the
 * compiler forces the field to be added here (and vice versa).
 *
 * Deliberately a `type` alias: aliases carry an implicit index signature, so
 * existing `as Record<string, unknown>` conversions keep compiling.
 */
export type IFeatureFlagsState = {
  enableAgentOnboarding: boolean | undefined;
  /**
   * Agent Share capability: may this user publish an Agent as a shared link AND
   * open/chat on an already-live shared agent. One allowlist gates both sides.
   */
  enableAgentShare: boolean | undefined;
  enableArtboard: boolean | undefined;
  enableAuthCaptcha: boolean | undefined;
  /**
   * Multi-agent Channels (`channel`). Off by default: the sidebar section and Channel pages are
   * hidden and the Channel APIs answer FORBIDDEN.
   */
  enableChannels: boolean | undefined;
  enableCheckUpdates: boolean | undefined;
  /**
   * Dashboards and the `builtin-dashboard` agent tool (`dashboard`). Off by
   * default: the pages, Portal view, in-chat previews and the tool are hidden
   * and the widget / dashboard APIs answer FORBIDDEN.
   */
  enableDashboard: boolean | undefined;
  enableDevDock: boolean | undefined;
  /**
   * @deprecated The new subscription tiers are always on. Kept as a constant
   * `true` because released desktop clients still read it and fall back to the
   * retired plans when it is missing. Remove once those clients are no longer
   * supported.
   */
  enableNewTierPlans: true;
  /**
   * Rollout gate for buying the new tiers in the mobile app
   * (`mobile_new_tier_sales`).
   */
  enableMobileNewTierSales: boolean | undefined;
  /**
   * @deprecated The `agent_gateway_mux_mobile` flag is retired. Always equals
   * `ENABLE_BUSINESS_FEATURES` (the value Cloud already served) because
   * released LobeHub Mobile clients still read it to pick the v2 gateway
   * socket. Remove once those clients are no longer supported.
   */
  enableGatewayMuxMobile: boolean;
  enableKnowledgeBase: boolean | undefined;
  /**
   * Rollout gate for relaying LLM calls of device-only model providers to the
   * client that started the run (`agent_llm_relay`). The client declares itself
   * as an executor only when this is on; the server checks it again.
   */
  enableLlmRelay: boolean | undefined;
  /** A plain chat send leaves its init to the step-0 worker (`agent_deferred_init`). */
  enableDeferredInit: boolean | undefined;
  /**
   * A plain chat send to a heterogeneous agent on an online device returns
   * before the device dispatch completes (`agent_deferred_hetero_dispatch`).
   */
  enableDeferredHeteroDispatch: boolean | undefined;
  /**
   * Creating managed cloud devices (`managed_cloud_device`). Off by default: the "Create in
   * cloud" entry is hidden and the creation APIs answer FORBIDDEN. Existing managed devices keep
   * working.
   */
  enableManagedCloudDevice: boolean | undefined;
  /**
   * MCP Apps views in the conversation (`mcp_apps`). Off by default: tool results
   * that declare a `ui://` view render as plain results.
   */
  enableMcpApps: boolean | undefined;
  /** Inbound webhooks wake Agents (`webhook`): MCP Events, generic webhooks, Automations. Off by default. */
  enableWebhook: boolean | undefined;
  /**
   * Agent documents move into a dedicated knowledge base at runtime
   * (`agent_knowledge_space`). Off by default.
   */
  enableAgentKnowledgeSpace: boolean | undefined;
  enableOnboardingV2: boolean | undefined;
  enableRAGEval: boolean | undefined;
  enableSTT: boolean | undefined;
  /**
   * Leave copies of the operation tool set (and the deprecated top-level
   * `expertise` mirror) out of the persisted agent state blob and restore them
   * on load (`agent_runtime_slim_state`). Server only;
   * `AGENT_RUNTIME_SLIM_STATE` (`0` / `1`) overrides it.
   */
  enableSlimAgentState: boolean | undefined;
  /** Hover previews of a topic's final answer (`topic_preview`). */
  enableTopicPreview: boolean | undefined;
  /**
   * @deprecated The `voice_dictation` flag is retired: dictation is on wherever
   * business features are. Always equals `ENABLE_BUSINESS_FEATURES` (the value
   * Cloud already served) because released LobeHub Mobile clients still read
   * it. Web reads `serverConfig.enableBusinessFeatures`. Remove once those
   * clients are no longer supported.
   */
  enableVoiceDictation: boolean;
  /**
   * @deprecated The `workspace` flag is retired: workspaces are on wherever
   * business features are. Always equals `ENABLE_BUSINESS_FEATURES` (the value
   * Cloud already served) because released LobeHub Mobile clients still read
   * it. Web reads `serverConfig.enableBusinessFeatures`; the server reads
   * `ENABLE_BUSINESS_FEATURES`. Remove once those clients are no longer
   * supported.
   */
  enableWorkspace: boolean;
  hideDocs: boolean | undefined;
  hideGitHub: boolean | undefined;
  isAgentEditable: boolean | undefined;
  showAiImage: boolean | undefined;
  showApiKeyManage: boolean | undefined;
  showChangelog: boolean | undefined;
  showCloudPromotion: boolean | undefined;
  showMarket: boolean | undefined;
  showOpenAIApiKey: boolean | undefined;
  showOpenAIProxyUrl: boolean | undefined;
  showProvider: boolean | undefined;
  showWelcomeSuggest: boolean | undefined;
};

export type GlobalMemoryLayer = 'activity' | 'context' | 'experience' | 'identity' | 'preference';

export interface MemoryAgentPublicConfig {
  baseURL?: string;
  contextLimit?: number;
  model?: string;
  provider?: string;
}

export interface MemoryLayerExtractorPublicConfig extends MemoryAgentPublicConfig {
  layers?: Partial<Record<GlobalMemoryLayer, string>>;
}

export interface GlobalMemoryExtractionConfig {
  agentGateKeeper: MemoryAgentPublicConfig;
  agentLayerExtractor: MemoryLayerExtractorPublicConfig;
  concurrency?: number;
  embedding?: MemoryAgentPublicConfig;
}

export interface GlobalMemoryConfig {
  userMemory?: GlobalMemoryExtractionConfig;
}

export interface MultimodalUnderstandingConfig {
  model: string;
  provider: string;
}

export interface ServerModelProviderConfig {
  enabled?: boolean;
  enabledModels?: string[];
  fetchOnClient?: boolean;
  /**
   * the model lists defined in server
   */
  serverModelLists?: AiFullModelCard[];
}

export type ServerLanguageModel = Partial<Record<GlobalLLMProviderKey, ServerModelProviderConfig>>;

export interface GlobalServerConfig {
  /**
   * Which Agent Gateway wire protocol this deployment's gateway can serve:
   * `2` when it exposes the per-user multiplexed socket (`/v2/ws`), `1` when
   * it only has the per-operation one (`/ws`). Absent ⇒ 1.
   *
   * A capability, not a rollout switch: the client may only pick the
   * multiplexed transport where the server says it exists, and there is no
   * negotiation on the socket itself — dialing `/v2/ws` on a gateway without
   * it is a 404 with nothing to fall back to until the client gives up.
   */
  agentGatewayProtocol?: 1 | 2;
  /**
   * Agent Gateway URL for WebSocket-based agent execution.
   * When set, the SPA can offload agent execution to the server and receive
   * events via the Gateway instead of running the agent loop client-side.
   */
  agentGatewayUrl?: string;
  /**
   * Agent identity providers this deployment has credentials for
   * (`agent-mail`). Empty means an agent cannot be given an address
   * here, so the identity settings have nothing to offer.
   */
  agentIdentityProviders?: string[];
  aiProvider: ServerLanguageModel;
  defaultAgent?: PartialDeep<UserDefaultAgent>;
  /** Whether the server has DEVICE_GATEWAY_URL configured, independent of its public URL. */
  deviceGatewayConfigured?: boolean;
  /**
   * Public Device Gateway base URL (`DEVICE_GATEWAY_PUBLIC_URL`). Absent when not
   * configured; clients then keep the address they manage themselves.
   */
  deviceGatewayUrl?: string;
  disableEmailPassword?: boolean;
  enableBusinessFeatures?: boolean;
  enableComposio?: boolean;
  /**
   * @deprecated
   */
  enabledOAuthSSO?: boolean;
  enableEmailVerification?: boolean;
  /**
   * Whether Gateway mode is available for app-level agent execution.
   */
  enableGatewayMode?: boolean;
  enableLobehubSkill?: boolean;
  enableMagicLink?: boolean;
  enableMarketTrustedClient?: boolean;
  enableMultimodalUnderstanding?: boolean;
  /** Pages collaborate live through the gateway's document rooms (LobeHub Cloud). */
  enablePageCollab?: boolean;
  enableUploadFileToServer?: boolean;
  /** Workspace pages collaborate live through the gateway's durable rooms (LobeHub Cloud). */
  enableWorkspacePageCollab?: boolean;
  image?: PartialDeep<UserImageConfig>;
  /**
   * Whether the server can relay an LLM call to a browser tab (Agent Gateway
   * with its service token + Redis). The one-shot relay is used only then.
   */
  llmRelayAvailable?: boolean;
  memory?: GlobalMemoryConfig;
  multimodalUnderstanding?: MultimodalUnderstandingConfig;
  oAuthSSOProviders?: string[];
  /**
   * Public issuer of the built-in OIDC provider (`APP_URL` + `/oidc`) — the
   * exact value the provider signs into tokens and discovery. Clients show
   * this to developers instead of their own origin, which differs behind a
   * reverse proxy or on desktop.
   */
  oidcIssuer?: string;
  /**
   * The sandbox the page agent edits pages in: Market (needs the user's Market
   * authorization unless the trusted client is configured), Onlyboxes, or none.
   */
  sandbox?: 'market' | 'onlyboxes' | 'unconfigured';
  systemAgent?: PartialDeep<UserServiceModelConfig>;
  telemetry: {
    langfuse?: boolean;
  };
  /**
   * `TOOL_NAME_MAX_LENGTH`: the length at which a function-call tool name gets
   * compressed to an opaque `MD5HASH_…`, `0` disabling that compression.
   * Exposed to the client because the client-driven chat path builds the tool
   * payload in the browser, where the server env isn't visible — without this
   * the var would only take effect in gateway (server-run) mode.
   * Undefined means "not configured": the default (64) applies.
   */
  toolNameMaxLength?: number;
}

export interface GlobalBillboardItemLocaleFields {
  description?: string;
  linkLabel?: string;
  title?: string;
}

export interface GlobalBillboardItem {
  /**
   * In-app action enum as delivered by the platform (unvalidated string).
   * The client narrows it at runtime against the registry in
   * `src/features/Billboard/actions.ts`; unrecognized values fall back to `linkUrl`.
   */
  action?: string | null;
  cover?: string | null;
  description: string;
  /**
   * Override copy per locale. Falls back to the default fields when the locale or a field within it is missing.
   */
  i18n?: Record<string, GlobalBillboardItemLocaleFields>;
  id: number;
  linkLabel?: string | null;
  linkUrl?: string | null;
  title: string;
}

export interface GlobalBillboardLocaleFields {
  title?: string;
}

export interface GlobalBillboard {
  endAt: string;
  /**
   * Override billboard-level fields per locale (currently only title). Falls back to the default title when missing.
   */
  i18n?: Record<string, GlobalBillboardLocaleFields>;
  id: number;
  items: GlobalBillboardItem[];
  slug: string;
  startAt: string;
  title: string;
}

export interface GlobalRuntimeConfig {
  billboard?: GlobalBillboard | null;
  serverConfig: GlobalServerConfig;
  serverFeatureFlags: IFeatureFlagsState;
}