@h-ai/cli 0.1.0-alpha.24 → 0.1.0-alpha.25

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@h-ai/cli",
3
3
  "type": "module",
4
- "version": "0.1.0-alpha.24",
4
+ "version": "0.1.0-alpha.25",
5
5
  "description": "Hai Framework CLI for project scaffolding and code generation.",
6
6
  "license": "Apache-2.0",
7
7
  "keywords": [
@@ -34,7 +34,7 @@
34
34
  "ora": "^9.1.0",
35
35
  "prompts": "^2.4.2",
36
36
  "yaml": "^2.7.0",
37
- "@h-ai/core": "0.1.0-alpha.24"
37
+ "@h-ai/core": "0.1.0-alpha.25"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/fs-extra": "^11.0.4",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "{{projectName}}",
3
- "version": "0.1.0-alpha.24",
3
+ "version": "0.1.0-alpha.25",
4
4
  "private": true,
5
5
  "description": "{{#if_eq appType 'admin'}}Enterprise management system built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'website'}}Enterprise website built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'h5'}}Mobile H5 app built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'api'}}REST API service built with hai Agent Framework{{/if_eq}}{{#if_eq appType 'mobile-app'}}Mobile app built with hai Agent Framework{{/if_eq}}",
6
6
  "keywords": ["hai", {{#unless isSvelteOnlyApp}}"sveltekit", {{/unless}}"svelte5", "{{appType}}"],
@@ -50,6 +50,7 @@ llm:
50
50
  baseUrl: ${HAI_AI_LLM_BASE_URL:https://api.openai.com/v1}
51
51
  model: ${HAI_AI_LLM_MODEL:gpt-4o-mini}
52
52
  timeout: 60000
53
+ tempModelCacheTtl: 600000 # 临时模型客户端缓存 TTL(毫秒,默认 10 分钟)
53
54
  scenarios:
54
55
  chat: fast
55
56
  reasoning: strong
@@ -76,6 +77,7 @@ knowledge:
76
77
  | --- | --- | --- |
77
78
  | 非流式对话 | `ai.llm.chat({ messages })` | OpenAI 兼容 Chat Completion |
78
79
  | 流式对话 | `ai.llm.chatStream({ messages })` | 返回 `AsyncIterable` |
80
+ | 临时模型 | `ai.llm.chat({ messages, tempModel })` | 单次请求级临时端点,客户端按 TTL 缓存 |
79
81
  | 工具定义 | `ai.tools.define(...)` | Zod schema 转 JSON Schema |
80
82
  | 工具执行 | `registry.executeAll(toolCalls)` | 支持并行执行 |
81
83
  | MCP 服务 | `createMcpServer(...)` | 按需连接 HTTP/SSE/Stdio transport |
@@ -124,6 +126,30 @@ for await (const chunk of ai.llm.chatStream({ messages })) {
124
126
  const message = processor.toAssistantMessage()
125
127
  ```
126
128
 
129
+ ## 临时模型(tempModel)
130
+
131
+ 单次请求级别绕过配置注册模型,直接指定端点与凭据;适用于运行时动态切换模型、多租户各带凭据。
132
+ `chat` / `chatStream` / `ask` / `askStream` 均支持。未指定字段回退全局 LLM 配置 / 环境变量;
133
+ 请求显式 `max_tokens` / `temperature` 优先于 `tempModel.maxTokens` / `temperature`。
134
+ 临时客户端按 `apiKey+baseUrl+timeout` 缓存,TTL 默认 10 分钟(`llm.tempModelCacheTtl` 毫秒,可配置),与常驻模型客户端隔离。
135
+
136
+ ```ts
137
+ const result = await ai.llm.chat({
138
+ messages: [{ role: 'user', content: '你好' }],
139
+ tempModel: {
140
+ model: 'claude-3-5-sonnet',
141
+ apiKey: 'sk-temp-xxx',
142
+ baseUrl: 'https://temp.endpoint/v1',
143
+ maxTokens: 2048, // 可选
144
+ temperature: 0.3, // 可选
145
+ timeout: 30000, // 可选
146
+ },
147
+ })
148
+
149
+ // ask 便捷方法同样支持
150
+ await ai.llm.ask('翻译这段话', { tempModel: { model: 'gpt-4o', apiKey: 'sk-xxx' } })
151
+ ```
152
+
127
153
  ## MCP 服务器
128
154
 
129
155
  ```ts