ai-world-sdk 1.5.2 → 1.5.6

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.
@@ -88,7 +88,7 @@ function parseUserIdsList(raw) {
88
88
  });
89
89
  }
90
90
  function registerAdminCommands(program) {
91
- const admin = program.command('admin');
91
+ const admin = program.command('admin').description('管理员功能(用户 / 角色 / 数据库)');
92
92
  const user = admin.command('user');
93
93
  user
94
94
  .command('list')
@@ -61,7 +61,7 @@ function parsePositiveInt(raw, flag) {
61
61
  return n;
62
62
  }
63
63
  function registerChromeCommands(program) {
64
- const chrome = program.command('chrome');
64
+ const chrome = program.command('chrome').description('Chrome 扩展管理');
65
65
  chrome
66
66
  .command('list')
67
67
  .option('--page <n>', '页码')
@@ -19,6 +19,10 @@ function parseEntries(entries) {
19
19
  }
20
20
  function registerConfigCommands(program) {
21
21
  const cfg = program.command('config');
22
+ cfg.command('file').action(() => {
23
+ const path = config_1.CONFIG_FILE;
24
+ (0, output_1.output)({ path }, 'json');
25
+ });
22
26
  cfg
23
27
  .command('set')
24
28
  .argument('<entries...>', 'key=value pairs')
@@ -41,9 +45,17 @@ function registerConfigCommands(program) {
41
45
  if (!(0, config_1.isValidKey)(key)) {
42
46
  throw new Error(`Invalid config key: ${key}. Valid keys: ${(0, config_1.getValidKeys)().join(', ')}`);
43
47
  }
44
- const value = (0, config_1.getConfigValue)(key);
48
+ const saved = (0, config_1.getConfigValue)(key);
49
+ const effective = (0, config_1.getEffectiveValue)(key);
45
50
  const format = (0, utils_1.getFormat)(program);
46
- (0, output_1.output)({ key, value: value ?? null }, format);
51
+ const result = { key, value: effective };
52
+ if (saved !== undefined && saved === effective) {
53
+ result.source = 'config';
54
+ }
55
+ else if (saved === undefined && effective !== null) {
56
+ result.source = 'default';
57
+ }
58
+ (0, output_1.output)(result, format);
47
59
  }
48
60
  catch (e) {
49
61
  (0, utils_1.handleError)(e, 'config get');
@@ -52,12 +64,28 @@ function registerConfigCommands(program) {
52
64
  cfg.command('list').action(() => {
53
65
  try {
54
66
  const format = (0, utils_1.getFormat)(program);
55
- const data = (0, config_1.readConfig)();
67
+ const saved = (0, config_1.readConfig)();
68
+ const effective = (0, config_1.getEffectiveConfig)();
69
+ const merged = {};
70
+ for (const [key, val] of Object.entries(effective)) {
71
+ const hasSaved = saved[key] !== undefined;
72
+ merged[key] = {
73
+ value: val,
74
+ source: key === 'token'
75
+ ? (saved.token ? 'config' : (process.env.DEBUG_TOKEN ? 'env' : 'none'))
76
+ : (hasSaved ? 'config' : (val !== null ? 'default' : 'none')),
77
+ };
78
+ }
56
79
  if (format === 'table') {
57
- (0, output_1.output)(data, 'table');
80
+ const rows = Object.entries(merged).map(([k, v]) => ({
81
+ key: k,
82
+ value: k === 'token' && v.value ? v.value.slice(0, 20) + '...' : (v.value ?? ''),
83
+ source: v.source,
84
+ }));
85
+ (0, output_1.output)(rows, 'table');
58
86
  }
59
87
  else {
60
- (0, output_1.outputJSON)(data);
88
+ (0, output_1.outputJSON)(merged);
61
89
  }
62
90
  }
63
91
  catch (e) {
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerHelpCommand(program: Command): void;
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerHelpCommand = registerHelpCommand;
4
+ const COMMAND_DETAILS = {
5
+ login: {
6
+ desc: '登录 AI World 平台(浏览器 OAuth 或直接设置 token)',
7
+ usage: 'ai-world login [--token <jwt>] [--timeout <ms>]',
8
+ examples: [
9
+ 'ai-world login # 浏览器 OAuth 登录',
10
+ 'ai-world login --token eyJhbG... # 直接设置 token',
11
+ ],
12
+ },
13
+ logout: {
14
+ desc: '退出登录,清除本地缓存的 token',
15
+ usage: 'ai-world logout',
16
+ },
17
+ me: {
18
+ desc: '查看当前登录用户信息(ID、姓名、邮箱、角色等)',
19
+ usage: 'ai-world me [--format table]',
20
+ },
21
+ status: {
22
+ desc: '检查当前认证状态,显示 token 是否有效',
23
+ usage: 'ai-world status',
24
+ },
25
+ version: {
26
+ desc: '显示当前 CLI 版本号,并检查是否有新版本可用',
27
+ usage: 'ai-world version',
28
+ examples: [
29
+ 'ai-world version',
30
+ '# 输出: {"current":"1.5.3","latest":"1.5.3","updateAvailable":false}',
31
+ ],
32
+ },
33
+ config: {
34
+ desc: '管理 CLI 默认配置(base-url / provider / endpoint / model 等)',
35
+ usage: 'ai-world config <set|get|list|reset>',
36
+ examples: [
37
+ 'ai-world config set base-url=https://aiworld.local:8000',
38
+ 'ai-world config set provider=volcengine endpoint=doubao model=doubao-1-5-pro-32k-250115',
39
+ 'ai-world config get provider',
40
+ 'ai-world config list',
41
+ 'ai-world config reset # 重置所有配置',
42
+ 'ai-world config reset provider # 重置单个配置项',
43
+ ],
44
+ },
45
+ text: {
46
+ desc: '文本生成 —— 调用 LLM 进行对话或流式输出',
47
+ usage: 'ai-world text <generate|stream>',
48
+ examples: [
49
+ 'ai-world text generate --prompt "介绍 AI World"',
50
+ 'ai-world text stream --prompt "讲个故事" --provider volcengine --endpoint doubao --model doubao-1-5-pro-32k-250115',
51
+ ],
52
+ },
53
+ model: {
54
+ desc: '检查指定模型在给定 provider/endpoint 下是否可用',
55
+ usage: 'ai-world model check --model <id> --provider <name> --endpoint <type>',
56
+ examples: [
57
+ 'ai-world model check --model doubao-1-5-pro-32k-250115 --provider volcengine --endpoint doubao',
58
+ ],
59
+ },
60
+ image: {
61
+ desc: '图像生成 —— 支持 doubao / gemini / openai 三种提供商',
62
+ usage: 'ai-world image generate --provider <name> --prompt <text> [--output <file>]',
63
+ examples: [
64
+ 'ai-world image generate --provider doubao --prompt "一只可爱的猫" --output cat.png',
65
+ 'ai-world image generate --provider gemini --prompt "sunset" --output sunset.png',
66
+ 'ai-world image generate --provider openai --prompt "abstract art" --model dall-e-3',
67
+ ],
68
+ },
69
+ video: {
70
+ desc: '视频生成、状态查询、下载和视频理解',
71
+ usage: 'ai-world video <generate|status|download|understand>',
72
+ examples: [
73
+ 'ai-world video generate --provider doubao --prompt "猫在走路"',
74
+ 'ai-world video status <taskId> --provider doubao',
75
+ 'ai-world video download <taskId> --output video.mp4',
76
+ 'ai-world video understand --model <id> --video-url <url> --prompt "描述这个视频"',
77
+ ],
78
+ },
79
+ resource: {
80
+ desc: '资源管理(带 ACL 访问控制)—— 上传、下载、分享、权限设置',
81
+ usage: 'ai-world resource <upload|list|get|download|share|unshare|set-access|delete>',
82
+ examples: [
83
+ 'ai-world resource upload ./file.pdf /docs/file.pdf --access public',
84
+ 'ai-world resource list --scope my',
85
+ 'ai-world resource download 42 --output ./local.pdf',
86
+ 'ai-world resource share 42 --users 1,2,3',
87
+ ],
88
+ },
89
+ versioned: {
90
+ desc: '版本化资源管理 —— 带版本号的文件存储',
91
+ usage: 'ai-world versioned <upload|list|versions|get|download|delete>',
92
+ examples: [
93
+ 'ai-world versioned upload ./model.bin --name my-model --version 1.0.0',
94
+ 'ai-world versioned list',
95
+ 'ai-world versioned versions my-model',
96
+ 'ai-world versioned download my-model latest --output ./model.bin',
97
+ ],
98
+ },
99
+ skill: {
100
+ desc: 'Agent 技能管理 —— 上传、下载、查看技能包',
101
+ usage: 'ai-world skill <list|get|upload|download|delete|md>',
102
+ examples: [
103
+ 'ai-world skill list',
104
+ 'ai-world skill get my-skill',
105
+ 'ai-world skill md my-skill # 查看 SKILL.md 内容',
106
+ 'ai-world skill upload my-skill ./skill.zip',
107
+ 'ai-world skill download my-skill -o skill.zip',
108
+ ],
109
+ },
110
+ plugin: {
111
+ desc: '插件管理 —— 部署、启用/禁用、重启、查看日志',
112
+ usage: 'ai-world plugin <list|get|ids|create|enable|disable|reload|restart|logs|status|delete>',
113
+ examples: [
114
+ 'ai-world plugin list',
115
+ 'ai-world plugin ids --enabled-only',
116
+ 'ai-world plugin get my-plugin',
117
+ 'ai-world plugin enable my-plugin',
118
+ 'ai-world plugin logs my-plugin --lines 50',
119
+ 'ai-world plugin create ./dist.zip --plugin-id my-plugin --name "我的插件"',
120
+ ],
121
+ },
122
+ admin: {
123
+ desc: '管理员功能 —— 用户管理、角色权限、数据库操作',
124
+ usage: 'ai-world admin <user|role|db>',
125
+ examples: [
126
+ 'ai-world admin user list',
127
+ 'ai-world admin user set-role 2 --role-id 1',
128
+ 'ai-world admin role list',
129
+ 'ai-world admin db tables',
130
+ 'ai-world admin db schema users',
131
+ 'ai-world admin db exec-sql --sql "SELECT COUNT(*) FROM users"',
132
+ ],
133
+ },
134
+ stats: {
135
+ desc: '统计与数据看板 —— 调用量、趋势、插件访问',
136
+ usage: 'ai-world stats <dashboard|plugin-access|ai-calls|ai-trend|...>',
137
+ examples: [
138
+ 'ai-world stats dashboard',
139
+ 'ai-world stats ai-calls --provider volcengine',
140
+ 'ai-world stats ai-trend --period weekly --days 30',
141
+ 'ai-world stats plugin-access-summary',
142
+ ],
143
+ },
144
+ shared: {
145
+ desc: '共享资源 —— 全平台可见的公共文件',
146
+ usage: 'ai-world shared <upload|list|get|download|update|delete>',
147
+ examples: [
148
+ 'ai-world shared upload ./data.csv --name "示例数据"',
149
+ 'ai-world shared list --search "模型"',
150
+ 'ai-world shared download 10 --output ./out.csv',
151
+ ],
152
+ },
153
+ chrome: {
154
+ desc: 'Chrome 扩展管理 —— 上传、下载、查看浏览器插件',
155
+ usage: 'ai-world chrome <list|get|create|download|delete>',
156
+ examples: [
157
+ 'ai-world chrome list',
158
+ 'ai-world chrome create --extension-id my-ext --name "扩展" --zip ./ext.zip',
159
+ 'ai-world chrome download my-ext --output ext.zip',
160
+ ],
161
+ },
162
+ };
163
+ function printFullHelp(program) {
164
+ const ver = program.version();
165
+ console.log(`
166
+ AI World CLI v${ver}
167
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
168
+
169
+ 用法: ai-world [全局选项] <命令> [子命令] [参数]
170
+
171
+ 全局选项:
172
+ --base-url <url> 后端地址(默认从配置读取)
173
+ --token <token> JWT 认证 token
174
+ --plugin-id <id> 插件 ID(默认 user_{user_id})
175
+ --format <fmt> 输出格式: json(默认)| table
176
+ --debug 启用调试输出
177
+ -V, --version 显示版本号
178
+ -h, --help 显示帮助
179
+
180
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
181
+ 命令列表:
182
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
183
+
184
+ 认证:
185
+ login 登录 AI World(浏览器 OAuth / token)
186
+ logout 退出登录
187
+ me 查看当前用户信息
188
+ status 检查认证状态
189
+
190
+ 配置:
191
+ config 管理默认配置(set / get / list / reset)
192
+ version 显示版本号并检查更新
193
+
194
+ AI 能力:
195
+ text 文本生成(对话、流式输出)
196
+ model 模型可用性检查
197
+ image 图像生成(doubao / gemini / openai)
198
+ video 视频生成、查询、下载、理解
199
+
200
+ 平台管理:
201
+ resource 资源管理(带 ACL 访问控制)
202
+ versioned 版本化资源管理
203
+ skill Agent 技能管理
204
+ plugin 插件管理(部署 / 启停 / 日志)
205
+ shared 共享资源
206
+ chrome Chrome 扩展管理
207
+
208
+ 管理员:
209
+ admin 用户 / 角色 / 数据库管理
210
+ stats 统计与数据看板
211
+
212
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
213
+ 提示: 使用 "ai-world help <命令>" 查看具体命令详情
214
+ 使用 "ai-world <命令> --help" 查看子命令帮助
215
+ `);
216
+ }
217
+ function printCommandHelp(cmdName, program) {
218
+ const detail = COMMAND_DETAILS[cmdName];
219
+ if (!detail) {
220
+ const sub = program.commands.find((c) => c.name() === cmdName);
221
+ if (sub) {
222
+ sub.outputHelp();
223
+ }
224
+ else {
225
+ console.error(`未知命令: ${cmdName}\n运行 "ai-world help" 查看所有可用命令`);
226
+ process.exitCode = 1;
227
+ }
228
+ return;
229
+ }
230
+ console.log(`
231
+ 命令: ${cmdName}
232
+ 描述: ${detail.desc}
233
+ 用法: ${detail.usage}
234
+ `);
235
+ if (detail.examples && detail.examples.length > 0) {
236
+ console.log('示例:');
237
+ for (const ex of detail.examples) {
238
+ console.log(` ${ex}`);
239
+ }
240
+ console.log('');
241
+ }
242
+ console.log(`运行 "ai-world ${cmdName} --help" 查看完整参数列表`);
243
+ }
244
+ function registerHelpCommand(program) {
245
+ program
246
+ .command('help')
247
+ .description('显示帮助信息')
248
+ .argument('[command]', '要查看的命令名称')
249
+ .action((cmdName) => {
250
+ if (!cmdName) {
251
+ printFullHelp(program);
252
+ }
253
+ else {
254
+ printCommandHelp(cmdName, program);
255
+ }
256
+ });
257
+ }
@@ -64,7 +64,7 @@ function stripB64ForLog(obj) {
64
64
  return copy;
65
65
  }
66
66
  function registerImageCommands(program) {
67
- const image = program.command('image');
67
+ const image = program.command('image').description('图像生成(doubao / gemini / openai)');
68
68
  image
69
69
  .command('generate')
70
70
  .requiredOption('--provider <name>', 'doubao, gemini, or openai')
@@ -17,7 +17,7 @@ function collectOpts(cmd) {
17
17
  return o;
18
18
  }
19
19
  function registerModelCommands(program) {
20
- const modelCmd = program.command('model');
20
+ const modelCmd = program.command('model').description('模型可用性检查');
21
21
  modelCmd
22
22
  .command('check')
23
23
  .requiredOption('--model <id>', 'Model id')
@@ -17,7 +17,7 @@ function collectOpts(cmd) {
17
17
  return o;
18
18
  }
19
19
  function registerPluginCommands(program) {
20
- const plugin = program.command('plugin');
20
+ const plugin = program.command('plugin').description('插件管理(启用 / 禁用 / 部署 / 日志)');
21
21
  plugin
22
22
  .command('list')
23
23
  .option('--page <n>', '', (v) => parseInt(v, 10))
@@ -61,7 +61,7 @@ function registerPluginCommands(program) {
61
61
  plugin
62
62
  .command('get')
63
63
  .argument('<plugin-id>')
64
- .action(async (pluginId, cmd) => {
64
+ .action(async (pluginId, _opts, cmd) => {
65
65
  const commandName = 'plugin get';
66
66
  try {
67
67
  const o = collectOpts(cmd);
@@ -109,7 +109,7 @@ function registerPluginCommands(program) {
109
109
  plugin
110
110
  .command(subName)
111
111
  .argument('<plugin-id>')
112
- .action(async (pluginId, cmd) => {
112
+ .action(async (pluginId, _opts, cmd) => {
113
113
  const commandName = `plugin ${subName}`;
114
114
  try {
115
115
  const o = collectOpts(cmd);
@@ -131,7 +131,7 @@ function registerPluginCommands(program) {
131
131
  plugin
132
132
  .command('restart')
133
133
  .argument('<plugin-id>')
134
- .action(async (pluginId, cmd) => {
134
+ .action(async (pluginId, _opts, cmd) => {
135
135
  const commandName = 'plugin restart';
136
136
  try {
137
137
  const o = collectOpts(cmd);
@@ -216,7 +216,7 @@ function registerPluginCommands(program) {
216
216
  plugin
217
217
  .command('delete')
218
218
  .argument('<plugin-id>')
219
- .action(async (pluginId, cmd) => {
219
+ .action(async (pluginId, _opts, cmd) => {
220
220
  const commandName = 'plugin delete';
221
221
  try {
222
222
  const o = collectOpts(cmd);
@@ -237,7 +237,7 @@ function registerPluginCommands(program) {
237
237
  plugin
238
238
  .command('status')
239
239
  .argument('<plugin-id>')
240
- .action(async (pluginId, cmd) => {
240
+ .action(async (pluginId, _opts, cmd) => {
241
241
  const commandName = 'plugin status';
242
242
  try {
243
243
  const o = collectOpts(cmd);
@@ -81,7 +81,7 @@ function parsePositiveInt(raw, flag) {
81
81
  return n;
82
82
  }
83
83
  function registerSharedCommands(program) {
84
- const shared = program.command('shared');
84
+ const shared = program.command('shared').description('共享资源(上传 / 下载 / 搜索)');
85
85
  shared
86
86
  .command('upload')
87
87
  .argument('<local-file>', '本地文件路径')
@@ -51,7 +51,7 @@ function collectOpts(cmd) {
51
51
  return o;
52
52
  }
53
53
  function registerSkillCommands(program) {
54
- const skill = program.command('skill');
54
+ const skill = program.command('skill').description('Agent 技能管理(上传 / 下载 / 查看)');
55
55
  skill
56
56
  .command('list')
57
57
  .option('--page <n>', '', (v) => parseInt(v, 10))
@@ -88,7 +88,7 @@ function registerSkillCommands(program) {
88
88
  skill
89
89
  .command('get')
90
90
  .argument('<skill-name>')
91
- .action(async (skillName, cmd) => {
91
+ .action(async (skillName, _opts, cmd) => {
92
92
  const commandName = 'skill get';
93
93
  try {
94
94
  const o = collectOpts(cmd);
@@ -165,7 +165,7 @@ function registerSkillCommands(program) {
165
165
  skill
166
166
  .command('delete')
167
167
  .argument('<skill-name>')
168
- .action(async (skillName, cmd) => {
168
+ .action(async (skillName, _opts, cmd) => {
169
169
  const commandName = 'skill delete';
170
170
  try {
171
171
  const o = collectOpts(cmd);
@@ -186,7 +186,7 @@ function registerSkillCommands(program) {
186
186
  skill
187
187
  .command('md')
188
188
  .argument('<skill-name>')
189
- .action(async (skillName, cmd) => {
189
+ .action(async (skillName, _opts, cmd) => {
190
190
  const commandName = 'skill md';
191
191
  try {
192
192
  const o = collectOpts(cmd);
@@ -37,7 +37,7 @@ function parsePeriod(raw) {
37
37
  throw err;
38
38
  }
39
39
  function registerStatsCommands(program) {
40
- const stats = program.command('stats');
40
+ const stats = program.command('stats').description('统计与数据看板');
41
41
  stats
42
42
  .command('plugin-access')
43
43
  .option('--user-id <n>', '用户 ID', (v) => parseInt(v, 10))
@@ -47,7 +47,7 @@ async function prepareContext(program, cmd) {
47
47
  };
48
48
  }
49
49
  function registerTextCommands(program) {
50
- const text = program.command('text');
50
+ const text = program.command('text').description('文本生成(对话、流式输出)');
51
51
  text
52
52
  .command('generate')
53
53
  .requiredOption('--prompt <text>', 'Prompt text')
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerVersionCommand = registerVersionCommand;
4
- const child_process_1 = require("child_process");
5
4
  const output_1 = require("../output");
6
5
  const utils_1 = require("../utils");
7
- function getLatestVersion() {
6
+ const config_1 = require("../config");
7
+ async function getLatestVersion(baseUrl) {
8
8
  try {
9
- return (0, child_process_1.execSync)('npm view ai-world-sdk version', {
10
- encoding: 'utf-8',
11
- timeout: 10000,
12
- stdio: ['pipe', 'pipe', 'pipe'],
13
- }).trim();
9
+ const response = await fetch(`${baseUrl}/api/sdk/latest-version`);
10
+ if (!response.ok)
11
+ return null;
12
+ const data = await response.json();
13
+ return data.version || null;
14
14
  }
15
15
  catch {
16
16
  return null;
@@ -31,10 +31,11 @@ function registerVersionCommand(program) {
31
31
  program
32
32
  .command('version')
33
33
  .description('显示版本号并检查更新')
34
- .action(() => {
34
+ .action(async () => {
35
35
  try {
36
36
  const currentVersion = require('../../../package.json').version;
37
- const latest = getLatestVersion();
37
+ const auth = (0, config_1.resolveAuth)({});
38
+ const latest = await getLatestVersion(auth.baseUrl);
38
39
  const result = {
39
40
  current: currentVersion,
40
41
  };
@@ -53,7 +53,7 @@ function collectOpts(cmd) {
53
53
  return o;
54
54
  }
55
55
  function registerVideoCommands(program) {
56
- const video = program.command('video');
56
+ const video = program.command('video').description('视频生成、状态查询、下载、理解');
57
57
  video
58
58
  .command('generate')
59
59
  .requiredOption('--provider <name>', 'doubao or openai')
@@ -1,3 +1,5 @@
1
+ export declare const CONFIG_DIR: string;
2
+ export declare const CONFIG_FILE: string;
1
3
  declare const VALID_KEYS: readonly ["base-url", "token", "plugin-id", "provider", "endpoint", "model", "format"];
2
4
  export type ConfigKey = (typeof VALID_KEYS)[number];
3
5
  export interface CLIConfig {
@@ -13,7 +15,9 @@ export declare function isValidKey(key: string): key is ConfigKey;
13
15
  export declare function getValidKeys(): readonly string[];
14
16
  export declare function readConfig(): CLIConfig;
15
17
  export declare function writeConfig(config: CLIConfig): void;
18
+ export declare function getEffectiveConfig(): Record<string, string | null>;
16
19
  export declare function getConfigValue(key: ConfigKey): string | undefined;
20
+ export declare function getEffectiveValue(key: ConfigKey): string | null;
17
21
  export declare function setConfigValues(entries: Record<string, string>): void;
18
22
  export declare function resetConfig(key?: string): void;
19
23
  export interface ResolvedAuth {
@@ -33,11 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.CONFIG_FILE = exports.CONFIG_DIR = void 0;
36
37
  exports.isValidKey = isValidKey;
37
38
  exports.getValidKeys = getValidKeys;
38
39
  exports.readConfig = readConfig;
39
40
  exports.writeConfig = writeConfig;
41
+ exports.getEffectiveConfig = getEffectiveConfig;
40
42
  exports.getConfigValue = getConfigValue;
43
+ exports.getEffectiveValue = getEffectiveValue;
41
44
  exports.setConfigValues = setConfigValues;
42
45
  exports.resetConfig = resetConfig;
43
46
  exports.resolveAuth = resolveAuth;
@@ -45,8 +48,8 @@ exports.resolveDefaults = resolveDefaults;
45
48
  const fs = __importStar(require("fs"));
46
49
  const path = __importStar(require("path"));
47
50
  const os = __importStar(require("os"));
48
- const CONFIG_DIR = path.join(os.homedir(), '.ai-world');
49
- const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
51
+ exports.CONFIG_DIR = path.join(os.homedir(), '.ai-world');
52
+ exports.CONFIG_FILE = path.join(exports.CONFIG_DIR, 'config.json');
50
53
  const VALID_KEYS = [
51
54
  'base-url',
52
55
  'token',
@@ -64,8 +67,8 @@ function getValidKeys() {
64
67
  }
65
68
  function readConfig() {
66
69
  try {
67
- if (fs.existsSync(CONFIG_FILE)) {
68
- return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
70
+ if (fs.existsSync(exports.CONFIG_FILE)) {
71
+ return JSON.parse(fs.readFileSync(exports.CONFIG_FILE, 'utf-8'));
69
72
  }
70
73
  }
71
74
  catch {
@@ -74,14 +77,42 @@ function readConfig() {
74
77
  return {};
75
78
  }
76
79
  function writeConfig(config) {
77
- if (!fs.existsSync(CONFIG_DIR)) {
78
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
80
+ if (!fs.existsSync(exports.CONFIG_DIR)) {
81
+ fs.mkdirSync(exports.CONFIG_DIR, { recursive: true });
79
82
  }
80
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
83
+ fs.writeFileSync(exports.CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8');
84
+ }
85
+ const DEFAULTS = {
86
+ 'base-url': 'https://aiworld.local:8000',
87
+ 'plugin-id': 'cli',
88
+ provider: 'kunpo',
89
+ endpoint: 'openai',
90
+ model: 'deepseek/deepseek-v4-pro',
91
+ format: 'json',
92
+ };
93
+ function getEffectiveConfig() {
94
+ const config = readConfig();
95
+ const result = {};
96
+ for (const key of VALID_KEYS) {
97
+ if (key === 'token') {
98
+ result[key] = config.token || process.env.DEBUG_TOKEN || null;
99
+ }
100
+ else {
101
+ result[key] = config[key] || DEFAULTS[key] || null;
102
+ }
103
+ }
104
+ return result;
81
105
  }
82
106
  function getConfigValue(key) {
83
107
  return readConfig()[key];
84
108
  }
109
+ function getEffectiveValue(key) {
110
+ const config = readConfig();
111
+ if (key === 'token') {
112
+ return config.token || process.env.DEBUG_TOKEN || null;
113
+ }
114
+ return config[key] || DEFAULTS[key] || null;
115
+ }
85
116
  function setConfigValues(entries) {
86
117
  const config = readConfig();
87
118
  for (const [key, value] of Object.entries(entries)) {
@@ -119,15 +150,15 @@ function resolveAuth(opts) {
119
150
  pluginId: opts.pluginId ||
120
151
  process.env.PLUGIN_ID ||
121
152
  config['plugin-id'] ||
122
- null,
153
+ 'cli',
123
154
  };
124
155
  }
125
156
  function resolveDefaults(opts) {
126
157
  const config = readConfig();
127
158
  return {
128
- provider: opts.provider || config.provider,
129
- endpoint: opts.endpoint || config.endpoint,
130
- model: opts.model || config.model,
159
+ provider: opts.provider || config.provider || 'kunpo',
160
+ endpoint: opts.endpoint || config.endpoint || 'openai',
161
+ model: opts.model || config.model || 'deepseek/deepseek-v4-pro',
131
162
  format: opts.format || config.format || 'json',
132
163
  };
133
164
  }