🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(desktop): compile against the real @lobechat/types, drop the types stub (#17436)
Arvin Xuf8365500c2ff
diff --git a/.github/workflows/pr-build-desktop.yml b/.github/workflows/pr-build-desktop.ymlindex 4c1322be46d..b176b686766 100644--- a/.github/workflows/pr-build-desktop.yml+++ b/.github/workflows/pr-build-desktop.yml@@ -40,6 +40,19 @@ jobs:env:NODE_OPTIONS: --max-old-space-size=8192+ # the desktop app is an isolated pnpm workspace that compiles the real+ # @lobechat/* package sources — type-check it with its own install so+ # regressions in those packages surface here instead of at release time+ - name: Install desktop deps+ run: pnpm install --no-frozen-lockfile+ working-directory: apps/desktop+ env:+ NODE_OPTIONS: --max-old-space-size=8192++ - name: Desktop type-check+ run: bun run type-check+ working-directory: apps/desktop+version:name: Determine version# 与 test job 相同的触发条件diff --git a/apps/desktop/pnpm-workspace.yaml b/apps/desktop/pnpm-workspace.yamlindex 5e4edc4cf4a..f8c368559b0 100644--- a/apps/desktop/pnpm-workspace.yaml+++ b/apps/desktop/pnpm-workspace.yaml@@ -15,7 +15,8 @@ packages:- '../../packages/tool-runtime'- '../../packages/prompts'- './stubs/business-const'- - './stubs/types'+ - '../../packages/types'+ - '../../packages/model-bank'- '.'allowBuilds:electron: set this to true or falsediff --git a/apps/desktop/stubs/business-const/src/index.ts b/apps/desktop/stubs/business-const/src/index.tsindex 7a2cdef7fa8..191935b1c78 100644--- a/apps/desktop/stubs/business-const/src/index.ts+++ b/apps/desktop/stubs/business-const/src/index.ts@@ -8,3 +8,6 @@ export const DEFAULT_ONBOARDING_MODEL = 'gemini-3-flash-preview';export const DEFAULT_ONBOARDING_PROVIDER = 'google';export const DEFAULT_PROVIDER = 'deepseek';export const ORG_NAME = 'LobeHub';+// mirrored from packages/business/const — model-bank gates the LobeHub+// provider entry on this flag; the OSS desktop build keeps it off+export const ENABLE_BUSINESS_FEATURES = false;diff --git a/apps/desktop/stubs/types/package.json b/apps/desktop/stubs/types/package.jsondeleted file mode 100644index 5d0b4403338..00000000000--- a/apps/desktop/stubs/types/package.json+++ /dev/null@@ -1,13 +0,0 @@-{- "name": "@lobechat/types",- "version": "0.0.0",- "private": true,- "exports": {- ".": "./src/index.ts"- },- "main": "./src/index.ts",- "dependencies": {- "ajv": "^8.20.0",- "zod": "^3.25.76"- }-}diff --git a/apps/desktop/stubs/types/src/graph.ts b/apps/desktop/stubs/types/src/graph.tsdeleted file mode 100644index ac62e3a8340..00000000000--- a/apps/desktop/stubs/types/src/graph.ts+++ /dev/null@@ -1,319 +0,0 @@-import Ajv from 'ajv';-import { z } from 'zod';--/**- * Runtime mirror of `packages/types/src/agent/graph.ts` for the isolated desktop- * workspace. Keep the validation behavior in sync with the canonical schema.- */--export const AGENT_GRAPH_ROOT_NODE_ID = '__root__';--/**- * Serializable reasoning graph snapshot stored on agent config.- * Kept package-local so shared config types don't depend on runtime packages.- */-export type AgentGraphNode =- | {- allowedToolApiNames?: string[];- maxAgentSteps?: number;- type: 'agent';- }- | {- type: 'llm';- };--export interface AgentGraphField {- desc: string;- schema: Record<string, any>;-}--export interface AgentGraphFieldRef {- desc?: string;- field: string;- required?: boolean;-}--export interface AgentGraphInputField extends AgentGraphFieldRef {- from: string;-}--export type AgentGraphOutputField = AgentGraphFieldRef;--export interface AgentGraphEdge {- /**- * JSON Schema evaluated against the current node output.- * If omitted, the edge is treated as the default edge for its source node.- */- condition?: Record<string, unknown>;- from: string;- input?: {- fields?: AgentGraphInputField[];- };- instruction: string;- maxTraversals?: number;- output?: {- fields?: AgentGraphOutputField[];- instruction?: string;- };- to: string;-}--export interface ReasoningGraph {- description?: string;- edges: AgentGraphEdge[];- fields: Record<string, AgentGraphField>;- maxInstructionCount?: number;- name: string;- nodes: Record<string, AgentGraphNode>;- terminal: string;-}--const AgentGraphNodeSchema = z.discriminatedUnion('type', [- z.object({- allowedToolApiNames: z.array(z.string().min(1)).optional(),- maxAgentSteps: z.number().int().positive().optional(),- type: z.literal('agent'),- }),- z.object({- type: z.literal('llm'),- }),-]);--const AgentGraphFieldSchema = z.object({- desc: z.string().min(1),- schema: z.record(z.unknown()),-});--const AgentGraphFieldRefSchema = z.object({- desc: z.string().min(1).optional(),- field: z.string().min(1),- required: z.boolean().optional(),-});--const AgentGraphInputFieldSchema = AgentGraphFieldRefSchema.extend({- from: z.string().min(1),-});--const AgentGraphOutputFieldSchema = AgentGraphFieldRefSchema;--const AgentGraphEdgeSchema = z.object({- condition: z.record(z.unknown()).optional(),- from: z.string(),- input: z- .object({- fields: z.array(AgentGraphInputFieldSchema).optional(),- })- .optional(),- output: z- .object({- fields: z.array(AgentGraphOutputFieldSchema).optional(),- instruction: z.string().min(1).optional(),- })- .optional(),- instruction: z.string().min(1),- maxTraversals: z.number().int().nonnegative().optional(),- to: z.string(),-});--const findSchemaDescriptionPath = (- value: unknown,- path: (number | string)[],-): (number | string)[] | undefined => {- if (!value || typeof value !== 'object') return;-- if (Array.isArray(value)) {- for (const [index, item] of value.entries()) {- const found = findSchemaDescriptionPath(item, [...path, index]);- if (found) return found;- }-- return;- }-- const record = value as Record<string, unknown>;- if (Object.hasOwn(record, 'description') && path.at(-1) !== 'properties') {- return [...path, 'description'];- }-- for (const [key, item] of Object.entries(record)) {- const found = findSchemaDescriptionPath(item, [...path, key]);- if (found) return found;- }-};--export const ReasoningGraphSchema = z- .object({- description: z.string().optional(),- fields: z.record(AgentGraphFieldSchema),- maxInstructionCount: z.number().int().positive().optional(),- name: z.string().min(1),- nodes: z.record(AgentGraphNodeSchema),- terminal: z.string().min(1),- edges: z.array(AgentGraphEdgeSchema),- })- .superRefine((graph, ctx) => {- const outputSchemaAjv = new Ajv({ allErrors: false, strict: false });- const conditionSchemaAjv = new Ajv({ allErrors: false, strict: true });- const fieldIds = new Set(Object.keys(graph.fields));- const nodeIds = new Set(Object.keys(graph.nodes));- const sourceNodeIds = new Set([AGENT_GRAPH_ROOT_NODE_ID, ...nodeIds]);-- for (const [fieldId, field] of Object.entries(graph.fields)) {- const descriptionPath = findSchemaDescriptionPath(field.schema, [- 'fields',- fieldId,- 'schema',- ]);- if (descriptionPath) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message:- `Graph field "${fieldId}" schema must not contain "description"; ` +- 'field schemas are only for validation. Use the graph field desc or edge field desc instead.',- path: descriptionPath,- });- }-- try {- outputSchemaAjv.compile(field.schema);- } catch (error) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message:- `Graph field "${fieldId}" schema must be a valid JSON Schema: ` +- (error instanceof Error ? error.message : String(error)),- path: ['fields', fieldId, 'schema'],- });- }- }-- if (nodeIds.size === 0) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: 'Graph must define at least one node',- path: ['nodes'],- });- return;- }-- if (!nodeIds.has(graph.terminal)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: 'Graph terminal must reference an existing node',- path: ['terminal'],- });- }-- const rootEdges = graph.edges.filter((edge) => edge.from === AGENT_GRAPH_ROOT_NODE_ID);- if (rootEdges.length !== 1) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Graph must define exactly one "${AGENT_GRAPH_ROOT_NODE_ID}" outgoing edge`,- path: ['edges'],- });- }-- const defaultEdgeBySource = new Map<string, number>();- graph.edges.forEach((edge, index) => {- if (edge.condition) {- try {- conditionSchemaAjv.compile(edge.condition);- } catch (error) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message:- `Edge condition must be a valid JSON Schema: ` +- (error instanceof Error ? error.message : String(error)),- path: ['edges', index, 'condition'],- });- }- }-- if (!edge.condition) {- const previousIndex = defaultEdgeBySource.get(edge.from);- if (previousIndex !== undefined) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Only one default edge without condition is allowed from "${edge.from}"`,- path: ['edges', index, 'condition'],- });- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Only one default edge without condition is allowed from "${edge.from}"`,- path: ['edges', previousIndex, 'condition'],- });- }- defaultEdgeBySource.set(edge.from, index);- }-- if (edge.from !== AGENT_GRAPH_ROOT_NODE_ID && !nodeIds.has(edge.from)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge from must reference an existing node or "${AGENT_GRAPH_ROOT_NODE_ID}"`,- path: ['edges', index, 'from'],- });- }-- if (!nodeIds.has(edge.to)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: 'Edge to must reference an existing node',- path: ['edges', index, 'to'],- });- }-- const inputFields = edge.input?.fields;- if (inputFields && inputFields.length > 0) {- const names = new Set<string>();- inputFields.forEach((field, fieldIndex) => {- if (names.has(field.field)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge input field "${field.field}" is duplicated`,- path: ['edges', index, 'input', 'fields', fieldIndex, 'field'],- });- }- names.add(field.field);-- if (!fieldIds.has(field.field)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge input field "${field.field}" must reference a registered graph field`,- path: ['edges', index, 'input', 'fields', fieldIndex, 'field'],- });- }-- if (!sourceNodeIds.has(field.from)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge input source node "${field.from}" must reference an existing node or "${AGENT_GRAPH_ROOT_NODE_ID}"`,- path: ['edges', index, 'input', 'fields', fieldIndex, 'from'],- });- }- });- }-- const outputFields = edge.output?.fields;- if (outputFields && outputFields.length > 0) {- const names = new Set<string>();- outputFields.forEach((field, fieldIndex) => {- if (names.has(field.field)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge output field "${field.field}" is duplicated`,- path: ['edges', index, 'output', 'fields', fieldIndex, 'field'],- });- }- names.add(field.field);-- if (!fieldIds.has(field.field)) {- ctx.addIssue({- code: z.ZodIssueCode.custom,- message: `Edge output field "${field.field}" must reference a registered graph field`,- path: ['edges', index, 'output', 'fields', fieldIndex, 'field'],- });- }- });- }- });- });diff --git a/apps/desktop/stubs/types/src/index.ts b/apps/desktop/stubs/types/src/index.tsdeleted file mode 100644index b34dc3ffeff..00000000000--- a/apps/desktop/stubs/types/src/index.ts+++ /dev/null@@ -1,67 +0,0 @@-/**- * Desktop isolated workspace stub.- *- * Most `@lobechat/types` consumers in the isolated desktop workspace only use- * type imports. Runtime exports required by workspace packages must be- * explicitly mirrored inside this package so a clean isolated install remains- * self-contained.- */--export { ReasoningGraphSchema } from './graph';--export type DesktopHotkeyId = 'openSettings' | 'quickChat' | 'quickComposer' | 'showApp';--export interface DesktopHotkeyItem {- id: DesktopHotkeyId;- keys: string;- nonEditable?: boolean;-}--export type DesktopHotkeyConfig = Record<DesktopHotkeyId, string>;--export type HeterogeneousAgentModelCatalogErrorCode =- 'cli_not_found' | 'command_failed' | 'device_unavailable' | 'timeout' | 'unsupported_client';--export interface HeterogeneousAgentModel {- id: string;- modelId: string;- providerId: string;-}--export interface ListHeterogeneousAgentModelsParams {- command?: string;- cwd?: string;- env?: Record<string, string>;- type: 'opencode';-}--export interface HeterogeneousAgentModelCatalogSuccess {- models: HeterogeneousAgentModel[];- status: 'success';- updatedAt: number;-}--export interface HeterogeneousAgentModelCatalogFailure {- error: {- code: HeterogeneousAgentModelCatalogErrorCode;- message: string;- };- status: 'error';- updatedAt: number;-}--export type HeterogeneousAgentModelCatalog =- HeterogeneousAgentModelCatalogFailure | HeterogeneousAgentModelCatalogSuccess;--/**- * Mirror of `@lobechat/types`' `BuiltinServerRuntimeOutput`. Reached by- * `@lobechat/tool-runtime` (the runtime the gateway controller reuses) via- * `import type`, so only the shape is needed. Keep in sync with- * `packages/types/src/tool/builtin.ts`.- */-export interface BuiltinServerRuntimeOutput {- content: string;- error?: unknown;- state?: unknown;- success: boolean;-}diff --git a/packages/app-config/package.json b/packages/app-config/package.jsonindex 15623bc7f7d..65abf035f8a 100644--- a/packages/app-config/package.json+++ b/packages/app-config/package.json@@ -11,6 +11,7 @@},"dependencies": {"@lobechat/database": "workspace:*",+ "@lobechat/types": "workspace:*","@lobechat/utils": "workspace:*","@t3-oss/env-nextjs": "^0.13.11","debug": "^4.4.3",diff --git a/packages/app-config/src/featureFlags/schema.ts b/packages/app-config/src/featureFlags/schema.tsindex 2d4783b6027..1fb9852b4d5 100644--- a/packages/app-config/src/featureFlags/schema.ts+++ b/packages/app-config/src/featureFlags/schema.ts@@ -1,3 +1,4 @@+import type { IFeatureFlagsState } from '@lobechat/types';import { z } from 'zod';// Define a union type for feature flag values: either boolean or array of user IDs@@ -100,7 +101,13 @@ export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {commercial_hide_docs: false,};-export const mapFeatureFlagsEnvToState = (config: IFeatureFlags, userId?: string) => {+// The explicit return type pins this mapping to the canonical shared interface:+// adding a flag here without updating `IFeatureFlagsState` (or vice versa) is a+// compile error, so the two can never drift apart.+export const mapFeatureFlagsEnvToState = (+ config: IFeatureFlags,+ userId?: string,+): IFeatureFlagsState => {return {isAgentEditable: evaluateFeatureFlag(config.edit_agent, userId),showProvider: evaluateFeatureFlag(config.provider_settings, userId),@@ -134,4 +141,4 @@ export const mapFeatureFlagsEnvToState = (config: IFeatureFlags, userId?: string};};-export type IFeatureFlagsState = ReturnType<typeof mapFeatureFlagsEnvToState>;+export type { IFeatureFlagsState };diff --git a/packages/const/src/global.d.ts b/packages/const/src/global.d.tsnew file mode 100644index 00000000000..d32563ef0d5--- /dev/null+++ b/packages/const/src/global.d.ts@@ -0,0 +1,12 @@+/**+ * Build-time defines this package reads. The app builds inject them via Vite+ * `define`; declaring them here (instead of only in the app's global.d.ts)+ * keeps the package compilable from any workspace — e.g. the desktop isolated+ * workspace, whose tsconfig never sees the app's ambient declarations.+ */+declare global {+ /** Vite define: current bundle is the Electron desktop variant */+ const __ELECTRON__: boolean | undefined;+}++export {};diff --git a/packages/const/src/version.ts b/packages/const/src/version.tsindex a23b4bfaef9..d468fe52068 100644--- a/packages/const/src/version.ts+++ b/packages/const/src/version.ts@@ -1,6 +1,9 @@import { BRANDING_NAME, ORG_NAME } from '@lobechat/business-const';import pkg from '../../../package.json';+// type-only: loads ./global.d.ts so `__ELECTRON__` exists even when this+// package is compiled from a workspace without the app's ambient declarations+import type {} from './global';export const CURRENT_VERSION = pkg.version;diff --git a/packages/model-bank/src/const/modelProvider.ts b/packages/model-bank/src/const/modelProvider.tsindex a2c766a54fd..641872f585c 100644--- a/packages/model-bank/src/const/modelProvider.ts+++ b/packages/model-bank/src/const/modelProvider.ts@@ -83,3 +83,6 @@ export enum ModelProvider {ZeroOne = 'zeroone',ZhiPu = 'zhipu',}++/** lowercase key union of the ModelProvider enum, e.g. 'openai' | 'anthropic' | … */+export type ModelProviderKey = Lowercase<keyof typeof ModelProvider>;diff --git a/packages/model-runtime/src/core/ModelRuntime.ts b/packages/model-runtime/src/core/ModelRuntime.tsindex 0b612ff214c..4f64a2e90b0 100644--- a/packages/model-runtime/src/core/ModelRuntime.ts+++ b/packages/model-runtime/src/core/ModelRuntime.ts@@ -513,8 +513,10 @@ export class ModelRuntime {>,hooks?: ModelRuntimeHooks,) {- // @ts-expect-error runtime map not include vertex so it will be undefined- const providerAI = providerRuntimeMap[provider] ?? LobeOpenAI;+ // runtime map does not include every provider id (e.g. vertex), so index loosely+ const runtimeMap: Partial<Record<string, new (params: any) => LobeRuntimeAI>> =+ providerRuntimeMap;+ const providerAI = runtimeMap[provider] ?? LobeOpenAI;const runtimeModel: LobeRuntimeAI = new providerAI(params);diff --git a/packages/model-runtime/src/core/streams/protocol.ts b/packages/model-runtime/src/core/streams/protocol.tsindex 541c173184b..b52be84f7a2 100644--- a/packages/model-runtime/src/core/streams/protocol.ts+++ b/packages/model-runtime/src/core/streams/protocol.ts@@ -99,7 +99,8 @@ export const setOpenAIChatCompletionUsageMissingDiagnostics = (export interface StreamProtocolChunk {data: any;id?: string;- type: // pure text+ type:+ // pure text| 'text'// base64 format image| 'base64_image'@@ -339,7 +340,7 @@ export const convertIterableToStream = <T>(// copy from https://github.com/vercel/ai/blob/d3aa5486529e3d1a38b30e3972b4f4c63ea4ae9a/packages/ai/streams/ai-stream.ts#L284// and add an error handle- const it = iterable[Symbol.asyncIterator]();+ const it: AsyncIterator<T> = iterable[Symbol.asyncIterator]();return new ReadableStream<T>({async cancel(reason) {diff --git a/packages/model-runtime/src/providers/google/createVideo.ts b/packages/model-runtime/src/providers/google/createVideo.tsindex bd470172e57..be9acefb100 100644--- a/packages/model-runtime/src/providers/google/createVideo.ts+++ b/packages/model-runtime/src/providers/google/createVideo.ts@@ -64,7 +64,7 @@ export async function createGoogleVideo(const config: GenerateVideosConfig = {...(aspectRatio && { aspectRatio }),...(duration && { durationSeconds: duration }),- ...(endImageUrl && { lastFrame: await imageToGoogleImageFormat(endImageUrl) }),+ ...(endImageUrl ? { lastFrame: await imageToGoogleImageFormat(endImageUrl) } : {}),...(generateAudio && { generateAudio }),...(resolution && { resolution }),...(seed !== undefined && seed !== null && { seed }),@@ -73,7 +73,7 @@ export async function createGoogleVideo(const requestParams: any = {model,prompt,- ...(imageUrl && { image: await imageToGoogleImageFormat(imageUrl) }),+ ...(imageUrl ? { image: await imageToGoogleImageFormat(imageUrl) } : {}),...(config && { config }),};diff --git a/packages/model-runtime/src/providers/google/index.ts b/packages/model-runtime/src/providers/google/index.tsindex 54a7a56a486..ad2c69ef870 100644--- a/packages/model-runtime/src/providers/google/index.ts+++ b/packages/model-runtime/src/providers/google/index.ts@@ -152,10 +152,12 @@ export class LobeGoogleAI implements LobeRuntimeAI {shouldOmitDeprecatedGoogleGenerationParams(requestModel);// https://ai.google.dev/gemini-api/docs/thinking#set-budget+ // GoogleThinkingLevel uses the REST-style lowercase literals while the SDK+ // enum is uppercase; the API accepts both, so bridge the nominal gapconst thinkingConfig = resolveGoogleThinkingConfig(requestModel, {thinkingBudget: shouldOmitDeprecatedGenerationParams ? undefined : thinkingBudget,thinkingLevel,- }) as ThinkingConfig;+ }) as unknown as ThinkingConfig;const contents = await buildGoogleMessages(payload.messages, { model: requestModel });if (shouldOmitDeprecatedGenerationParams) {diff --git a/packages/model-runtime/src/providers/volcengine/index.ts b/packages/model-runtime/src/providers/volcengine/index.tsindex 8bf31308e73..eea77e5ba3d 100644--- a/packages/model-runtime/src/providers/volcengine/index.ts+++ b/packages/model-runtime/src/providers/volcengine/index.ts@@ -1,8 +1,7 @@import { ModelProvider } from 'model-bank';-import type { ChatStreamPayload } from '@/types/index';-import { createOpenAICompatibleRuntime } from '../../core/openaiCompatibleFactory';+import type { ChatStreamPayload } from '../../types';import { createVolcengineImage } from './createImage';import { createVolcengineVideo } from './video/createVideo';import { handleVolcengineVideoWebhook } from './video/handleCreateVideoWebhook';diff --git a/packages/model-runtime/src/types/type.ts b/packages/model-runtime/src/types/type.tsindex eaeb40963a3..10a4f050d25 100644--- a/packages/model-runtime/src/types/type.ts+++ b/packages/model-runtime/src/types/type.ts@@ -1,5 +1,4 @@import type { ErrorType } from '@lobechat/types';-import type { ModelProvider } from 'model-bank';import type OpenAI from 'openai';import type { ChatStreamPayload } from './chat';@@ -30,4 +29,5 @@ export interface CreateChatCompletionOptions {payload: ChatStreamPayload;}-export type ModelProviderKey = Lowercase<keyof typeof ModelProvider>;+// canonical definition lives next to the ModelProvider enum in model-bank+export type { ModelProviderKey } from 'model-bank';diff --git a/packages/types/src/plugins/mcp.ts b/packages/types/src/plugins/mcp.tsindex a74ec6478e6..922a8168971 100644--- a/packages/types/src/plugins/mcp.ts+++ b/packages/types/src/plugins/mcp.ts@@ -1,11 +1,21 @@import type { PluginQueryParams, SystemDependency } from '@lobehub/market-sdk';import { z } from 'zod';-import type { MCPErrorType } from '@/libs/mcp';-import type { McpConnectionType } from '../discover/mcp';import type { CustomPluginMetadata } from '../tool/plugin';+/**+ * MCP client error categories. Owned here so shared packages don't reach into+ * the app-layer MCP lib; `src/libs/mcp` re-exports this for its own consumers.+ */+export type MCPErrorType =+ | 'CONNECTION_FAILED'+ | 'PROCESS_SPAWN_ERROR'+ | 'INITIALIZATION_TIMEOUT'+ | 'VALIDATION_ERROR'+ | 'UNKNOWN_ERROR'+ | 'AUTHORIZATION_ERROR';+export enum MCPInstallStep {CHECKING_INSTALLATION = 'CHECKING_INSTALLATION',COMPLETED = 'COMPLETED',diff --git a/packages/types/src/serverConfig.ts b/packages/types/src/serverConfig.tsindex 8d3416e7cdf..35b49c6b837 100644--- a/packages/types/src/serverConfig.ts+++ b/packages/types/src/serverConfig.ts@@ -1,7 +1,5 @@import type { PartialDeep } from 'type-fest';-import type { IFeatureFlagsState } from '@/config/featureFlags';-import type { ChatModelCard } from './llm';import type {GlobalLLMProviderKey,@@ -10,6 +8,39 @@ import type {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;+ enableAgentSelfIteration: boolean | undefined;+ enableAuthCaptcha: boolean | undefined;+ enableCheckUpdates: boolean | undefined;+ enableKnowledgeBase: boolean | undefined;+ enableRAGEval: boolean | undefined;+ enableSTT: boolean | undefined;+ enableStorageOverage: boolean | undefined;+ enableWorkspace: boolean | undefined;+ 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 {diff --git a/packages/types/src/understanding.ts b/packages/types/src/understanding.tsindex 15172185a09..42b53539114 100644--- a/packages/types/src/understanding.ts+++ b/packages/types/src/understanding.ts@@ -1,5 +1,7 @@import { z } from 'zod';+import type { StrictOnly } from './zodStrict';+export const MAX_COLLECTION_COUNT = 1_000_000;export const MAX_COLLECTION_ERRORS = 16;export const MAX_DIAGNOSTIC_CODE_LENGTH = 64;@@ -229,7 +231,7 @@ export const UnderstandingAnalysisSchema = z}).strict(),})- .strict() satisfies z.ZodType<UnderstandingAnalysis>;+ .strict() satisfies z.ZodType<StrictOnly<UnderstandingAnalysis>>;export const OnboardingUnderstandingMessageMetadataSchema = z.object({@@ -240,7 +242,7 @@ export const OnboardingUnderstandingMessageMetadataSchema = zresultId: z.string(),sourceFingerprint: z.string(),})- .strict() satisfies z.ZodType<OnboardingUnderstandingMessageMetadata>;+ .strict() satisfies z.ZodType<StrictOnly<OnboardingUnderstandingMessageMetadata>>;export const UnderstandingProviderStateSchema = z.object({diff --git a/packages/types/src/user/settings/modelProvider.ts b/packages/types/src/user/settings/modelProvider.tsindex 47fc96cccfb..8ae138a0f66 100644--- a/packages/types/src/user/settings/modelProvider.ts+++ b/packages/types/src/user/settings/modelProvider.ts@@ -1,5 +1,4 @@-import type { ModelProviderKey } from '@lobechat/model-runtime';-import type { AiFullModelCard } from 'model-bank';+import type { AiFullModelCard, ModelProviderKey } from 'model-bank';import type { ChatModelCard } from '../../llm';diff --git a/packages/types/src/userMemory/tools.ts b/packages/types/src/userMemory/tools.tsindex 124cd30644e..e7128e5721e 100644--- a/packages/types/src/userMemory/tools.ts+++ b/packages/types/src/userMemory/tools.ts@@ -1,5 +1,6 @@import { z } from 'zod';+import type { StrictOnly } from '../zodStrict';import type { UserMemoryIdentity } from './identity';import type {UserMemoryActivity,@@ -96,7 +97,7 @@ const searchMemoryYearIntentSchema = z.object({const searchMemoryLegacyRelativeDayAnchorSchema = z.enum(['today', 'yesterday']);-const searchMemoryTimeIntentSchema: z.ZodType<SearchMemoryTimeIntent> = z.lazy(() =>+const searchMemoryTimeIntentSchema: z.ZodType<StrictOnly<SearchMemoryTimeIntent>> = z.lazy(() =>z.union([z.object({selector: searchMemoryPresetTimeSelectorSchema,diff --git a/packages/types/src/zodStrict.ts b/packages/types/src/zodStrict.tsnew file mode 100644index 00000000000..8d7f19ccde0--- /dev/null+++ b/packages/types/src/zodStrict.ts@@ -0,0 +1,10 @@+/**+ * zod 4's type inference requires `strictNullChecks`: without it, object keys+ * behind `ZodPipe` / `ZodLazy` all degrade to optional, so structural guards+ * like `satisfies z.ZodType<T>` report false mismatches. This alias keeps the+ * guard intact in strict projects (the repo root) and relaxes it to `any` for+ * non-strict consumers that compile these sources (e.g. the desktop main+ * tsconfig). `undefined extends string` is true exactly when+ * `strictNullChecks` is off.+ */+export type StrictOnly<T> = undefined extends string ? any : T;diff --git a/src/libs/mcp/types.ts b/src/libs/mcp/types.tsindex 715e0e70528..24a3849b738 100644--- a/src/libs/mcp/types.ts+++ b/src/libs/mcp/types.ts@@ -1,3 +1,5 @@+import type { MCPErrorType } from '@lobechat/types';+interface InputSchema {[k: string]: unknown;@@ -82,11 +84,7 @@ export interface ResourceLinkContent {}export type ToolCallContent =- | TextContent- | ImageContent- | AudioContent- | ResourceContent- | ResourceLinkContent;+ TextContent | ImageContent | AudioContent | ResourceContent | ResourceLinkContent;export interface ToolCallResult {content: ToolCallContent[];@@ -159,13 +157,8 @@ export interface CloudMCPParams {export type MCPClientParams = HttpMCPClientParams | StdioMCPParams;-export type MCPErrorType =- | 'CONNECTION_FAILED'- | 'PROCESS_SPAWN_ERROR'- | 'INITIALIZATION_TIMEOUT'- | 'VALIDATION_ERROR'- | 'UNKNOWN_ERROR'- | 'AUTHORIZATION_ERROR';+// canonical definition lives with the shared MCP plugin types+export type { MCPErrorType };export interface MCPErrorData {message: string;/**