@allen-wei/model-hub-core 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +64 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @allen-wei/model-hub-core
2
+
3
+ 框架无关的 AI 对话核心逻辑:多模型流式调用、限流自动切换、上下文管理、任务检测、会话状态机。不含 UI,key 由调用方注入。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @allen-wei/model-hub-core
9
+ ```
10
+
11
+ 零框架依赖,可在浏览器、Node.js、Worker 等环境运行。
12
+
13
+ ## 核心 API
14
+
15
+ ### createChatStore
16
+
17
+ ```ts
18
+ import { createChatStore } from '@allen-wei/model-hub-core';
19
+
20
+ const store = createChatStore({
21
+ chatEndpoint: '/api/chat', // 服务端代理(推荐)
22
+ // 或直连模式:
23
+ // getEnv: (name) => process.env[name],
24
+ });
25
+
26
+ store.send('你好');
27
+ ```
28
+
29
+ ### chat(低层调用)
30
+
31
+ ```ts
32
+ import { chat } from '@allen-wei/model-hub-core';
33
+
34
+ await chat({
35
+ model: 'zhipu',
36
+ messages: [{ role: 'user', content: '你好' }],
37
+ onDelta: (text) => process.stdout.write(text),
38
+ getEnv: (name) => process.env[name],
39
+ });
40
+ ```
41
+
42
+ ### DEFAULT_MODEL_OPTIONS
43
+
44
+ 内置模型白名单(GLM-4.7-Flash / Xing4.0-29B / GLM-Z1-9B / Qwen2.5-7B):
45
+
46
+ ```ts
47
+ import { DEFAULT_MODEL_OPTIONS, getModel } from '@allen-wei/model-hub-core';
48
+
49
+ const model = getModel('zhipu', DEFAULT_MODEL_OPTIONS);
50
+ // { label: 'GLM-4.7-Flash', contextWindow: 200000, ... }
51
+ ```
52
+
53
+ ## 主要能力
54
+
55
+ - 流式对话(SSE)+ 静默超时检测
56
+ - 多模型 failover 自动切换
57
+ - 指数退避重试(5s / 10s / 20s)
58
+ - 上下文窗口自动截断
59
+ - 任务类型检测(代码 / 数学 / 长文 / 通用)
60
+ - 会话状态机(发送 / 停止 / 重试 / 切换 / 删除)
61
+
62
+ ## License
63
+
64
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allen-wei/model-hub-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "ModelHub 对话核心(框架无关):多模型流式调用、限流自动切换、上下文管理、任务检测、会话状态机。不含 UI,key 由调用方注入。",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",