@next-open-ai/openbot 0.1.6 → 0.1.8

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.
@@ -10,6 +10,8 @@ export interface AgentConfigItem {
10
10
  workspace: string;
11
11
  provider?: string;
12
12
  model?: string;
13
+ /** 匹配 config.configuredModels 中的 modelItemCode,优先于 provider/model */
14
+ modelItemCode?: string;
13
15
  /** 是否为系统缺省智能体(主智能体),不可删除 */
14
16
  isDefault?: boolean;
15
17
  }
@@ -29,6 +31,20 @@ export declare class AgentConfigService {
29
31
  name: string;
30
32
  workspace: string;
31
33
  }): Promise<AgentConfigItem>;
32
- updateAgent(id: string, updates: Partial<Pick<AgentConfigItem, 'name' | 'provider' | 'model'>>): Promise<AgentConfigItem>;
34
+ updateAgent(id: string, updates: Partial<Pick<AgentConfigItem, 'name' | 'provider' | 'model' | 'modelItemCode'>>): Promise<AgentConfigItem>;
33
35
  deleteAgent(id: string): Promise<void>;
36
+ /**
37
+ * 根据 config 的 defaultProvider / defaultModel / defaultModelItemCode 及 configuredModels 同步 agents.json 中缺省智能体的 provider、model、modelItemCode。
38
+ * 在桌面保存配置(如修改默认模型)后调用,保证 agents 与 config 一致。
39
+ */
40
+ syncDefaultAgentFromConfig(config: {
41
+ defaultProvider?: string;
42
+ defaultModel?: string;
43
+ defaultModelItemCode?: string;
44
+ configuredModels?: Array<{
45
+ provider: string;
46
+ modelId: string;
47
+ modelItemCode?: string;
48
+ }>;
49
+ }): Promise<void>;
34
50
  }
@@ -148,6 +148,8 @@ let AgentConfigService = class AgentConfigService {
148
148
  agent.provider = updates.provider;
149
149
  if (updates.model !== undefined)
150
150
  agent.model = updates.model;
151
+ if (updates.modelItemCode !== undefined)
152
+ agent.modelItemCode = updates.modelItemCode;
151
153
  await this.writeAgentsFile(file);
152
154
  return { ...agent, isDefault: agent.id === DEFAULT_AGENT_ID };
153
155
  }
@@ -163,6 +165,44 @@ let AgentConfigService = class AgentConfigService {
163
165
  file.agents.splice(idx, 1);
164
166
  await this.writeAgentsFile(file);
165
167
  }
168
+ /**
169
+ * 根据 config 的 defaultProvider / defaultModel / defaultModelItemCode 及 configuredModels 同步 agents.json 中缺省智能体的 provider、model、modelItemCode。
170
+ * 在桌面保存配置(如修改默认模型)后调用,保证 agents 与 config 一致。
171
+ */
172
+ async syncDefaultAgentFromConfig(config) {
173
+ const list = config.configuredModels ?? [];
174
+ let provider = config.defaultProvider?.trim();
175
+ let model = config.defaultModel?.trim();
176
+ let modelItemCode = config.defaultModelItemCode?.trim();
177
+ if (modelItemCode && list.length) {
178
+ const item = list.find((m) => m.modelItemCode === modelItemCode);
179
+ if (item) {
180
+ provider = item.provider;
181
+ model = item.modelId;
182
+ }
183
+ }
184
+ if (!provider || !model)
185
+ return;
186
+ if (!modelItemCode && list.length) {
187
+ const item = list.find((m) => m.provider === provider && m.modelId === model);
188
+ if (item?.modelItemCode)
189
+ modelItemCode = item.modelItemCode;
190
+ }
191
+ await this.ensureDefaultWorkspace();
192
+ const file = await this.readAgentsFile();
193
+ let idx = file.agents.findIndex((a) => a.id === DEFAULT_AGENT_ID);
194
+ if (idx < 0) {
195
+ file.agents.unshift(this.defaultAgent({ provider, model, modelItemCode }));
196
+ idx = 0;
197
+ }
198
+ else {
199
+ const agent = file.agents[idx];
200
+ agent.provider = provider;
201
+ agent.model = model;
202
+ agent.modelItemCode = modelItemCode;
203
+ }
204
+ await this.writeAgentsFile(file);
205
+ }
166
206
  };
167
207
  AgentConfigService = __decorate([
168
208
  Injectable(),
@@ -9,6 +9,7 @@ export declare class ConfigController {
9
9
  gatewayUrl: string;
10
10
  defaultProvider: string;
11
11
  defaultModel: string;
12
+ defaultModelItemCode?: string;
12
13
  defaultAgentId?: string;
13
14
  theme: "light" | "dark";
14
15
  maxAgentSessions?: number;
@@ -21,6 +22,10 @@ export declare class ConfigController {
21
22
  };
22
23
  };
23
24
  configuredModels?: import("./config.service.js").ConfiguredModelItem[];
25
+ rag?: {
26
+ embeddingProvider?: string;
27
+ embeddingModel?: string;
28
+ };
24
29
  };
25
30
  }>;
26
31
  updateConfig(updates: Partial<AppConfig>): Promise<{
@@ -30,6 +35,7 @@ export declare class ConfigController {
30
35
  gatewayUrl: string;
31
36
  defaultProvider: string;
32
37
  defaultModel: string;
38
+ defaultModelItemCode?: string;
33
39
  defaultAgentId?: string;
34
40
  theme: "light" | "dark";
35
41
  maxAgentSessions?: number;
@@ -42,6 +48,10 @@ export declare class ConfigController {
42
48
  };
43
49
  };
44
50
  configuredModels?: import("./config.service.js").ConfiguredModelItem[];
51
+ rag?: {
52
+ embeddingProvider?: string;
53
+ embeddingModel?: string;
54
+ };
45
55
  };
46
56
  }>;
47
57
  getProviders(): Promise<{
@@ -7,10 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Module } from '@nestjs/common';
8
8
  import { ConfigController } from './config.controller.js';
9
9
  import { ConfigService } from './config.service.js';
10
+ import { AgentConfigModule } from '../agent-config/agent-config.module.js';
10
11
  let ConfigModule = class ConfigModule {
11
12
  };
12
13
  ConfigModule = __decorate([
13
14
  Module({
15
+ imports: [AgentConfigModule],
14
16
  controllers: [ConfigController],
15
17
  providers: [ConfigService],
16
18
  exports: [ConfigService],
@@ -1,3 +1,4 @@
1
+ import { AgentConfigService } from '../agent-config/agent-config.service.js';
1
2
  /** 模型 cost 配置,写入 models.json;缺省均为 0 */
2
3
  export interface ModelCost {
3
4
  input?: number;
@@ -13,6 +14,8 @@ export interface ConfiguredModelItem {
13
14
  type: 'llm' | 'embedding' | 'image';
14
15
  /** 显示用别名,缺省用模型名;重名时自动加后缀区分 */
15
16
  alias?: string;
17
+ /** 唯一编码,供界面与 agent.modelItemCode 匹配已设好的模型 */
18
+ modelItemCode?: string;
16
19
  /** 是否推理模型,缺省 false;写入 models.json */
17
20
  reasoning?: boolean;
18
21
  /** 成本配置,缺省均为 0;写入 models.json */
@@ -26,6 +29,8 @@ export interface AppConfig {
26
29
  gatewayUrl: string;
27
30
  defaultProvider: string;
28
31
  defaultModel: string;
32
+ /** 缺省模型在 configuredModels 中的唯一标识(defaultModelItemCode),与 defaultProvider/defaultModel 一起确定缺省模型 */
33
+ defaultModelItemCode?: string;
29
34
  /** 缺省智能体 id */
30
35
  defaultAgentId?: string;
31
36
  theme: 'light' | 'dark';
@@ -45,15 +50,22 @@ export interface AppConfig {
45
50
  };
46
51
  /** 已配置的模型列表(备用),从该列表中选一个为缺省模型 */
47
52
  configuredModels?: ConfiguredModelItem[];
53
+ /** RAG 知识库:embedding 使用该 provider+model,未配置时基于 RAG 的长记忆空转 */
54
+ rag?: {
55
+ embeddingProvider?: string;
56
+ embeddingModel?: string;
57
+ };
48
58
  }
49
59
  export declare class ConfigService {
60
+ private readonly agentConfigService;
50
61
  private configPath;
51
62
  private config;
52
- constructor();
63
+ constructor(agentConfigService: AgentConfigService);
53
64
  private getDefaultConfig;
54
65
  /** 当前缺省智能体 id */
55
66
  getDefaultAgentId(config?: AppConfig): string;
56
67
  private loadConfig;
68
+ /** 每次获取前从磁盘重新读取,保证打开配置界面时显示最新(含 CLI 写入的配置) */
57
69
  getConfig(): Promise<AppConfig>;
58
70
  updateConfig(updates: Partial<AppConfig>): Promise<AppConfig>;
59
71
  private saveConfig;
@@ -12,10 +12,13 @@ import { readFile, writeFile, mkdir } from 'fs/promises';
12
12
  import { join } from 'path';
13
13
  import { existsSync } from 'fs';
14
14
  import { getProviderSupport, syncDesktopConfigToModelsJson } from '../../config/desktop-config.js';
15
+ import { AgentConfigService } from '../agent-config/agent-config.service.js';
15
16
  let ConfigService = class ConfigService {
17
+ agentConfigService;
16
18
  configPath;
17
19
  config;
18
- constructor() {
20
+ constructor(agentConfigService) {
21
+ this.agentConfigService = agentConfigService;
19
22
  const homeDir = process.env.HOME || process.env.USERPROFILE || '';
20
23
  const configDir = join(homeDir, '.openbot', 'desktop');
21
24
  this.configPath = join(configDir, 'config.json');
@@ -36,6 +39,7 @@ let ConfigService = class ConfigService {
36
39
  maxAgentSessions: 5,
37
40
  providers: {},
38
41
  configuredModels: [],
42
+ rag: undefined,
39
43
  };
40
44
  }
41
45
  /** 当前缺省智能体 id */
@@ -55,13 +59,24 @@ let ConfigService = class ConfigService {
55
59
  console.error('Error loading config:', error);
56
60
  }
57
61
  }
62
+ /** 每次获取前从磁盘重新读取,保证打开配置界面时显示最新(含 CLI 写入的配置) */
58
63
  async getConfig() {
64
+ await this.loadConfig();
59
65
  return this.config;
60
66
  }
61
67
  async updateConfig(updates) {
62
68
  this.config = { ...this.config, ...updates };
63
69
  this.config.defaultAgentId = this.getDefaultAgentId(this.config);
70
+ const p = this.config.defaultProvider;
71
+ const m = this.config.defaultModel;
72
+ const list = this.config.configuredModels ?? [];
73
+ if (p && m && list.length) {
74
+ const item = list.find((x) => x.provider === p && x.modelId === m);
75
+ if (item?.modelItemCode)
76
+ this.config.defaultModelItemCode = item.modelItemCode;
77
+ }
64
78
  await this.saveConfig();
79
+ await this.agentConfigService.syncDefaultAgentFromConfig(this.config).catch((err) => console.warn('[ConfigService] syncDefaultAgentFromConfig failed', err));
65
80
  await syncDesktopConfigToModelsJson().catch((err) => console.warn('[ConfigService] syncDesktopConfigToModelsJson failed', err));
66
81
  return this.config;
67
82
  }
@@ -103,6 +118,6 @@ let ConfigService = class ConfigService {
103
118
  };
104
119
  ConfigService = __decorate([
105
120
  Injectable(),
106
- __metadata("design:paramtypes", [])
121
+ __metadata("design:paramtypes", [AgentConfigService])
107
122
  ], ConfigService);
108
123
  export { ConfigService };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.6",
6
+ "version": "0.1.8",
7
7
  "description": "CLI and library to run prompts with skill paths (Agent Skills style). Use as npm package or openbot CLI.",
8
8
  "type": "module",
9
9
  "main": "dist/index.js",
@@ -35,7 +35,6 @@
35
35
  "@nestjs/platform-socket.io": "^10.3.0",
36
36
  "@nestjs/websockets": "^10.3.0",
37
37
  "@sinclair/typebox": "^0.34.41",
38
- "@xenova/transformers": "^2.17.2",
39
38
  "agent-browser": "^0.8.5",
40
39
  "commander": "^14.0.2",
41
40
  "reflect-metadata": "^0.2.1",