@huyooo/ai-chat-core 0.3.21 → 0.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/model-adapter.d.ts +3 -3
- package/dist/build-chat-integration-export.d.ts +39 -0
- package/dist/chat-catalog-constants.d.ts +23 -0
- package/dist/chat-catalog-types.d.ts +45 -0
- package/dist/chat-runtime-protocol-options.d.ts +5 -0
- package/dist/chat-runtime.d.ts +2 -1
- package/dist/chat-supplier-constants.d.ts +11 -0
- package/dist/compile-chat-model-config.d.ts +25 -0
- package/dist/index.d.ts +16 -5
- package/dist/index.js +9 -21
- package/dist/llm-config.d.ts +22 -18
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/protocol-ids.d.ts +3 -0
- package/dist/protocols/registry.d.ts +38 -0
- package/dist/protocols/types.d.ts +5 -5
- package/dist/server-chat-endpoint.d.ts +22 -0
- package/dist/types.d.ts +3 -1
- package/package.json +1 -1
- package/dist/constants.d.ts +0 -11
- package/dist/model-catalog/adapters.d.ts +0 -2
- package/dist/model-catalog/constants.d.ts +0 -5
- package/dist/model-catalog/providers.d.ts +0 -2
- package/dist/model-catalog/service-entries.d.ts +0 -3
- package/dist/model-catalog/services/huyooo-official.d.ts +0 -2
- package/dist/model-catalog/services/model-proxy.d.ts +0 -3
- package/dist/model-catalog/services/volcengine-coding-plan.d.ts +0 -2
- package/dist/model-catalog.d.ts +0 -69
package/dist/llm-config.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* LLMConfig.models 是模型的唯一真相源:
|
|
5
5
|
* - key = 模型 ID(自定义字符串)
|
|
6
|
-
* - value = ModelConfig
|
|
6
|
+
* - value = ModelConfig(出站端点 + 元数据)
|
|
7
7
|
* - 前端只展示这里配置的模型
|
|
8
8
|
* - 每个模型必须显式指定 family,不做任何隐式推导
|
|
9
9
|
*/
|
|
@@ -11,8 +11,8 @@ import type { ProtocolFactory } from './protocols';
|
|
|
11
11
|
import type { ModelFamilyConfig, ModelFamilyId } from './families';
|
|
12
12
|
/** 运行时可解析的配置值。用于登录态 token、按用户切换的 key 等动态配置。 */
|
|
13
13
|
export type RuntimeConfigValue = string | (() => string | null | undefined);
|
|
14
|
-
/**
|
|
15
|
-
export interface
|
|
14
|
+
/** 单条模型出站端点(与 catalog 的 protocolBaseUrl / protocolPath 编译对齐) */
|
|
15
|
+
export interface ModelEndpoint {
|
|
16
16
|
/** 基础 URL */
|
|
17
17
|
baseUrl: string;
|
|
18
18
|
/** 访问 key(代理 token 或厂商 key) */
|
|
@@ -28,10 +28,10 @@ export interface ModelRoute {
|
|
|
28
28
|
/** 额外请求头。用于官方代理 app-id、OpenRouter HTTP-Referer/X-Title 等。 */
|
|
29
29
|
headers?: Record<string, RuntimeConfigValue>;
|
|
30
30
|
}
|
|
31
|
-
/**
|
|
31
|
+
/** 模型配置(出站端点 + 元数据) */
|
|
32
32
|
export interface ModelConfig {
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/** 该模型的唯一出站端点(与 Mongo offering 编译结果 1:1) */
|
|
34
|
+
endpoint: ModelEndpoint;
|
|
35
35
|
/** 显示名称(不传则从预设库补全,再 fallback 到 modelId) */
|
|
36
36
|
displayName?: string;
|
|
37
37
|
/**
|
|
@@ -65,10 +65,16 @@ export interface CompressionConfig {
|
|
|
65
65
|
}
|
|
66
66
|
/** 完整 LLM 配置 */
|
|
67
67
|
export interface LLMConfig {
|
|
68
|
+
/**
|
|
69
|
+
* 默认模型 ID(接入方配置,调用方未指定 model 时使用)
|
|
70
|
+
*
|
|
71
|
+
* 必须是 models 中已配置的 key。
|
|
72
|
+
*/
|
|
73
|
+
defaultModel: string;
|
|
68
74
|
/**
|
|
69
75
|
* 模型配置(唯一真相源)
|
|
70
76
|
*
|
|
71
|
-
* key = 模型 ID,value =
|
|
77
|
+
* key = 模型 ID,value = 出站端点 + 元数据。
|
|
72
78
|
* 前端模型选择器只展示这里 visible !== false 的模型。
|
|
73
79
|
*/
|
|
74
80
|
models: Record<string, ModelConfig>;
|
|
@@ -76,7 +82,7 @@ export interface LLMConfig {
|
|
|
76
82
|
* 自定义协议工厂(可插拔)
|
|
77
83
|
*
|
|
78
84
|
* key = 自定义 protocolId,value = Protocol 工厂函数。
|
|
79
|
-
*
|
|
85
|
+
* ModelEndpoint.protocol 引用此处的 key 或内置 protocolId。
|
|
80
86
|
*/
|
|
81
87
|
protocols?: Record<string, ProtocolFactory>;
|
|
82
88
|
/**
|
|
@@ -89,13 +95,11 @@ export interface LLMConfig {
|
|
|
89
95
|
/** 压缩模型配置(可选) */
|
|
90
96
|
compression?: CompressionConfig;
|
|
91
97
|
}
|
|
92
|
-
/**
|
|
93
|
-
export declare function
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
*/
|
|
97
|
-
export declare function
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
*/
|
|
101
|
-
export declare function findRouteByProtocol(config: LLMConfig, protocolId: string): ModelRoute | undefined;
|
|
98
|
+
/** 解析对话使用的模型 ID(options.model 优先,否则 LLMConfig.defaultModel) */
|
|
99
|
+
export declare function resolveChatModel(config: LLMConfig, modelId?: string): string;
|
|
100
|
+
/** 解析 endpoint 的完整 API URL */
|
|
101
|
+
export declare function resolveEndpointUrl(endpoint: ModelEndpoint): string;
|
|
102
|
+
/** 获取模型出站端点 */
|
|
103
|
+
export declare function getModelEndpoint(config: LLMConfig, modelId: string): ModelEndpoint | undefined;
|
|
104
|
+
/** 查找第一个使用指定 protocol 的模型出站端点 */
|
|
105
|
+
export declare function findEndpointByProtocol(config: LLMConfig, protocolId: string): ModelEndpoint | undefined;
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
export type { ProtocolId, RawEventType, RawEvent, RawOutputPart, RawToolCall, RawTokenUsage, ProtocolMessage, ProtocolToolDefinition, ProtocolRequestOptions, Protocol, ProtocolConfig, ProtocolAttachment, ProtocolFactory, } from './types';
|
|
20
20
|
export { getBaseProtocol } from './types';
|
|
21
|
+
export { BUILTIN_PROTOCOL_IDS, BUILTIN_PROTOCOL_FACTORIES, getBuiltinProtocolFactories, isRegisteredProtocolId, } from './registry';
|
|
21
22
|
export { ArkProtocol, createArkProtocol } from './ark';
|
|
22
23
|
export { DeepSeekProtocol, createDeepSeekProtocol } from './deepseek';
|
|
23
24
|
export { QwenProtocol, createQwenProtocol, createQwenTextProtocol } from './qwen';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** 内置 Protocol ID 列表(单一真源,ProtocolId 类型由此推导) */
|
|
2
|
+
export declare const BUILTIN_PROTOCOL_IDS: readonly ["ark_v1", "deepseek_v1", "qwen_v1", "qwen_text_v1", "glm_v1", "moonshot_v1", "minimax_v1", "vercel_gateway_v1", "anthropic_v1", "gemini_v1", "openai_v1", "openai_chat_v1", "grok_v1"];
|
|
3
|
+
export type ProtocolId = (typeof BUILTIN_PROTOCOL_IDS)[number];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置 Protocol 注册表(工厂 + ID 白名单,单一真源)
|
|
3
|
+
*/
|
|
4
|
+
import { type ProtocolId } from './protocol-ids';
|
|
5
|
+
import { createArkProtocol } from './ark';
|
|
6
|
+
import { createDeepSeekProtocol } from './deepseek';
|
|
7
|
+
import { createQwenProtocol, createQwenTextProtocol } from './qwen';
|
|
8
|
+
import { createGlmProtocol } from './glm';
|
|
9
|
+
import { createMoonshotProtocol } from './moonshot';
|
|
10
|
+
import { createMiniMaxProtocol } from './minimax';
|
|
11
|
+
import { createVercelGatewayProtocol } from './vercel-gateway';
|
|
12
|
+
import { createAnthropicProtocol } from './anthropic';
|
|
13
|
+
import { createGeminiProtocol } from './gemini';
|
|
14
|
+
import { createOpenAIProtocol } from './openai';
|
|
15
|
+
import { createOpenAIChatProtocol } from './openai-chat';
|
|
16
|
+
import { createGrokProtocol } from './grok';
|
|
17
|
+
import type { Protocol, ProtocolConfig } from './types';
|
|
18
|
+
export { BUILTIN_PROTOCOL_IDS } from './protocol-ids';
|
|
19
|
+
/** 内置协议工厂(ModelAdapter 默认注册) */
|
|
20
|
+
export declare const BUILTIN_PROTOCOL_FACTORIES: {
|
|
21
|
+
ark_v1: typeof createArkProtocol;
|
|
22
|
+
deepseek_v1: typeof createDeepSeekProtocol;
|
|
23
|
+
qwen_v1: typeof createQwenProtocol;
|
|
24
|
+
qwen_text_v1: typeof createQwenTextProtocol;
|
|
25
|
+
glm_v1: typeof createGlmProtocol;
|
|
26
|
+
moonshot_v1: typeof createMoonshotProtocol;
|
|
27
|
+
minimax_v1: typeof createMiniMaxProtocol;
|
|
28
|
+
vercel_gateway_v1: typeof createVercelGatewayProtocol;
|
|
29
|
+
anthropic_v1: typeof createAnthropicProtocol;
|
|
30
|
+
gemini_v1: typeof createGeminiProtocol;
|
|
31
|
+
openai_v1: typeof createOpenAIProtocol;
|
|
32
|
+
openai_chat_v1: typeof createOpenAIChatProtocol;
|
|
33
|
+
grok_v1: typeof createGrokProtocol;
|
|
34
|
+
};
|
|
35
|
+
/** 供 ModelAdapter 合并自定义 protocols 时使用 */
|
|
36
|
+
export declare function getBuiltinProtocolFactories(): Record<string, (config: ProtocolConfig) => Protocol>;
|
|
37
|
+
/** 校验是否为已注册的内置 ProtocolId */
|
|
38
|
+
export declare function isRegisteredProtocolId(value: string): value is ProtocolId;
|
|
@@ -13,11 +13,10 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { ModelFamilyConfig } from '../families';
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* 默认带版本 _v1,当上游 API 有 breaking change 时新增 _v2、_v3 等。
|
|
16
|
+
* 内置协议类型标识(由 protocols/protocol-ids.ts 推导)
|
|
19
17
|
*/
|
|
20
|
-
export type ProtocolId
|
|
18
|
+
export type { ProtocolId } from './protocol-ids';
|
|
19
|
+
export { BUILTIN_PROTOCOL_IDS } from './protocol-ids';
|
|
21
20
|
/** 从 ProtocolId 提取 base 协议(如 anthropic_v1 → anthropic) */
|
|
22
21
|
export declare function getBaseProtocol(protocol: string): string;
|
|
23
22
|
/**
|
|
@@ -121,7 +120,8 @@ export interface ProtocolRequestOptions {
|
|
|
121
120
|
*/
|
|
122
121
|
export interface ProtocolConfig {
|
|
123
122
|
apiKey: string;
|
|
124
|
-
|
|
123
|
+
/** 由 ModelAdapter 从 ModelEndpoint.baseUrl 注入 */
|
|
124
|
+
apiUrl: string;
|
|
125
125
|
headers?: Record<string, string>;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ai-server 平台对话:catalog item → 出站 endpoint(env 注入,策略来自 Mongo supplier)
|
|
3
|
+
*/
|
|
4
|
+
import type { ChatModelCatalogItem } from './chat-catalog-types';
|
|
5
|
+
import type { ModelEndpoint } from './llm-config';
|
|
6
|
+
/** ai-server 编译 endpoint 所需环境变量 */
|
|
7
|
+
export interface ServerChatEnv {
|
|
8
|
+
llmProxyBaseUrl: string;
|
|
9
|
+
llmProxyApiKey?: string;
|
|
10
|
+
supplierApiKeys: {
|
|
11
|
+
'volcengine-doubao'?: string;
|
|
12
|
+
'aliyun-qwen'?: string;
|
|
13
|
+
deepseek?: string;
|
|
14
|
+
'zhipu-glm'?: string;
|
|
15
|
+
'moonshot-kimi'?: string;
|
|
16
|
+
minimax?: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** 服务端出站策略标签(metadata.upstream) */
|
|
20
|
+
export declare function getServerChatUpstream(item: Pick<ChatModelCatalogItem, 'serverUpstream' | 'proxyPathPrefix'>): 'llm-proxy' | 'direct';
|
|
21
|
+
/** 将 catalog 项解析为 ai-server 平台对话 endpoint;Mongo 策略或 env 不完整时返回 null */
|
|
22
|
+
export declare function resolveServerChatEndpoint(item: ChatModelCatalogItem, env: ServerChatEnv): ModelEndpoint | null;
|
package/dist/types.d.ts
CHANGED
|
@@ -61,8 +61,10 @@ export interface ToolExecutionAuditHooks {
|
|
|
61
61
|
}
|
|
62
62
|
/** Agent 配置 */
|
|
63
63
|
export interface AgentConfig {
|
|
64
|
-
/** 统一 LLM
|
|
64
|
+
/** 统一 LLM 配置(每模型单 endpoint) */
|
|
65
65
|
llmConfig: import('./llm-config').LLMConfig;
|
|
66
|
+
/** 基础 system prompt(接入方必填,ask/agent 共用) */
|
|
67
|
+
systemPrompt: string;
|
|
66
68
|
/** 当前工作目录(必传,浏览器安全:不使用 process.cwd()) */
|
|
67
69
|
cwd: string;
|
|
68
70
|
/** 最大模型轮次(可选,默认不限制) */
|
package/package.json
CHANGED
package/dist/constants.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 常量定义
|
|
3
|
-
*
|
|
4
|
-
* 非模型相关的常量。模型数据唯一来源为 LLMConfig。
|
|
5
|
-
*/
|
|
6
|
-
export declare const DEFAULT_ARK_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
|
7
|
-
export declare const DEFAULT_AIMLAPI_URL = "https://api.aimlapi.com/v1";
|
|
8
|
-
/** 默认模型 ID(仅用于应用层未指定时的 fallback,不是唯一真相源) */
|
|
9
|
-
export declare const DEFAULT_MODEL = "doubao-seed-2-0-pro-260215";
|
|
10
|
-
/** agent 模式提示词(核心库通用,不引用具体工具名) */
|
|
11
|
-
export declare const AGENT_MODE_PROMPT = "\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 AI \u52A9\u624B\uFF0C\u5177\u5907\u81EA\u4E3B\u6267\u884C\u590D\u6742\u4EFB\u52A1\u7684\u80FD\u529B\u3002\n\n## \u5DE5\u4F5C\u65B9\u5F0F\n1. **\u5206\u6790\u4EFB\u52A1**\uFF1A\u7406\u89E3\u7528\u6237\u9700\u6C42\uFF0C\u62C6\u89E3\u4E3A\u53EF\u6267\u884C\u7684\u6B65\u9AA4\n2. **\u9010\u6B65\u6267\u884C**\uFF1A\u6309\u6B65\u9AA4\u4F9D\u6B21\u8C03\u7528\u5DE5\u5177\uFF0C\u68C0\u67E5\u6BCF\u6B65\u7ED3\u679C\n3. **\u81EA\u6211\u9A8C\u8BC1**\uFF1A\u5DE5\u5177\u6267\u884C\u540E\u68C0\u67E5\u7ED3\u679C\u662F\u5426\u7B26\u5408\u9884\u671F\n4. **\u81EA\u52A8\u7EA0\u6B63**\uFF1A\u53D1\u73B0\u95EE\u9898\u65F6\u5C1D\u8BD5\u66FF\u4EE3\u65B9\u6848\uFF0C\u4E0D\u8981\u505C\u4E0B\u6765\u95EE\u7528\u6237\n5. **\u603B\u7ED3\u6C47\u62A5**\uFF1A\u6240\u6709\u6B65\u9AA4\u5B8C\u6210\u540E\uFF0C\u7ED9\u51FA\u7B80\u6D01\u7684\u7ED3\u679C\u603B\u7ED3\n\n## \u8F93\u51FA\u89C4\u8303\n- \u4E0D\u4F7F\u7528\u8868\u60C5\u7B26\u53F7\uFF08emoji\uFF09\uFF0C\u9664\u975E\u7528\u6237\u8981\u6C42\n- \u4F7F\u7528 Markdown \u683C\u5F0F\u7EC4\u7EC7\u5185\u5BB9\n- \u4EE3\u7801\u5757\u4F7F\u7528\u6B63\u786E\u7684\u8BED\u8A00\u6807\u8BC6";
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const HUYOOO_AI_BASE_URL = "https://ai.huyooo.com/aiRestfulApi";
|
|
2
|
-
export declare const ARK_CODING_CHAT_BASE_URL = "https://ark.cn-beijing.volces.com/api/coding/v3";
|
|
3
|
-
export declare const ARK_CODING_ANTHROPIC_BASE_URL = "https://ark.cn-beijing.volces.com/api/coding";
|
|
4
|
-
export declare const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
5
|
-
export declare const SILICONFLOW_BASE_URL = "https://api.siliconflow.cn/v1";
|
package/dist/model-catalog.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { ModelFamilyId } from './families';
|
|
2
|
-
import type { ModelConfig, ModelRoute, RuntimeConfigValue } from './llm-config';
|
|
3
|
-
import type { ProtocolId } from './protocols';
|
|
4
|
-
import { MODEL_CATALOG_ADAPTERS } from './model-catalog/adapters';
|
|
5
|
-
import { MODEL_CATALOG_PROVIDERS } from './model-catalog/providers';
|
|
6
|
-
import { MODEL_CATALOG_SERVICE_ENTRIES, MODEL_CATALOG_SERVICE_PLANS } from './model-catalog/service-entries';
|
|
7
|
-
export type ModelServicePlanKind = 'official' | 'provider_api_key' | 'compatible_gateway';
|
|
8
|
-
export interface ModelProviderDefinition {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
description?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ModelServicePlanDefinition {
|
|
14
|
-
id: string;
|
|
15
|
-
providerId: string;
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
18
|
-
kind: ModelServicePlanKind;
|
|
19
|
-
modelTemplateIds: string[];
|
|
20
|
-
}
|
|
21
|
-
export interface ModelAdapterDefinition {
|
|
22
|
-
id: ProtocolId;
|
|
23
|
-
name: string;
|
|
24
|
-
description?: string;
|
|
25
|
-
defaultBaseUrl: string;
|
|
26
|
-
defaultFamily: ModelFamilyId;
|
|
27
|
-
}
|
|
28
|
-
export interface ProviderModelTemplate {
|
|
29
|
-
id: string;
|
|
30
|
-
servicePlanId: string;
|
|
31
|
-
providerId: string;
|
|
32
|
-
displayName: string;
|
|
33
|
-
family: ModelFamilyId;
|
|
34
|
-
protocol: ProtocolId;
|
|
35
|
-
baseUrl: string;
|
|
36
|
-
path?: string;
|
|
37
|
-
providerModelId: string;
|
|
38
|
-
supportsThinking: boolean;
|
|
39
|
-
supportsVision: boolean;
|
|
40
|
-
contextWindowTokens: number;
|
|
41
|
-
maxOutputTokens: number;
|
|
42
|
-
defaultEnabled: boolean;
|
|
43
|
-
status?: 'stable' | 'preview' | 'deprecated';
|
|
44
|
-
}
|
|
45
|
-
export interface CompileModelTemplateOptions {
|
|
46
|
-
accessKey: RuntimeConfigValue;
|
|
47
|
-
modelId?: string;
|
|
48
|
-
headers?: ModelRoute['headers'];
|
|
49
|
-
vendorKey?: RuntimeConfigValue;
|
|
50
|
-
metadata?: Record<string, unknown>;
|
|
51
|
-
}
|
|
52
|
-
export interface ModelServiceCatalogEntry {
|
|
53
|
-
servicePlan: Omit<ModelServicePlanDefinition, 'modelTemplateIds'>;
|
|
54
|
-
modelTemplates: ProviderModelTemplate[];
|
|
55
|
-
}
|
|
56
|
-
export { MODEL_CATALOG_ADAPTERS, MODEL_CATALOG_PROVIDERS, MODEL_CATALOG_SERVICE_ENTRIES, MODEL_CATALOG_SERVICE_PLANS, };
|
|
57
|
-
export declare function getModelAdapter(id: ProtocolId): ModelAdapterDefinition | null;
|
|
58
|
-
export declare function getModelServiceEntry(id: string): ModelServiceCatalogEntry | null;
|
|
59
|
-
export declare function getModelServicePlan(id: string): {
|
|
60
|
-
modelTemplateIds: string[];
|
|
61
|
-
name: string;
|
|
62
|
-
id: string;
|
|
63
|
-
description: string;
|
|
64
|
-
kind: ModelServicePlanKind;
|
|
65
|
-
providerId: string;
|
|
66
|
-
} | null;
|
|
67
|
-
export declare function getModelTemplate(id: string): ProviderModelTemplate | null;
|
|
68
|
-
export declare function listModelTemplatesByServicePlan(servicePlanId: string): ProviderModelTemplate[];
|
|
69
|
-
export declare function compileModelTemplate(template: ProviderModelTemplate, options: CompileModelTemplateOptions): [string, ModelConfig];
|