@42ailab/42plugin 0.1.11 → 0.1.13

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.

Potentially problematic release.


This version of @42ailab/42plugin might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "活水插件",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/api.ts CHANGED
@@ -288,20 +288,37 @@ class ApiClient {
288
288
  }),
289
289
  });
290
290
 
291
- const data = await response.json();
291
+ // 处理 JSON 解析失败
292
+ let data: Record<string, unknown>;
293
+ try {
294
+ data = await response.json();
295
+ } catch {
296
+ return { error: 'invalid_response', errorDescription: 'Invalid response from server' };
297
+ }
298
+
299
+ // 处理空响应
300
+ if (!data) {
301
+ return { error: 'empty_response', errorDescription: 'Empty response from server' };
302
+ }
303
+
304
+ // 如果有错误,直接返回错误信息
305
+ if (data.error) {
306
+ return {
307
+ error: data.error as string,
308
+ errorDescription: data.error_description as string,
309
+ };
310
+ }
292
311
 
293
312
  return {
294
- accessToken: data.access_token,
313
+ accessToken: data.access_token as string,
295
314
  user: data.user
296
315
  ? {
297
- id: data.user.id,
298
- name: data.user.name,
299
- username: data.user.username,
300
- email: data.user.email,
316
+ id: (data.user as Record<string, unknown>).id as string,
317
+ name: (data.user as Record<string, unknown>).name as string,
318
+ username: (data.user as Record<string, unknown>).username as string,
319
+ email: (data.user as Record<string, unknown>).email as string,
301
320
  }
302
321
  : undefined,
303
- error: data.error,
304
- errorDescription: data.error_description,
305
322
  };
306
323
  }
307
324
 
package/src/cli.ts CHANGED
@@ -15,16 +15,32 @@ import {
15
15
  checkCommand,
16
16
  } from './commands';
17
17
 
18
- // 版本号在构建时通过 --define 注入
19
- declare const __VERSION__: string;
20
- const version: string = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.0.0-dev';
18
+ // 版本号处理:
19
+ // - Homebrew(编译后):构建时通过 --define __VERSION__ 注入
20
+ // - npm/dev(源码):fallback package.json
21
+ declare const __VERSION__: string | undefined;
22
+
23
+ function getVersion(): string {
24
+ // 1. 优先使用构建时注入的版本(Homebrew 二进制)
25
+ if (typeof __VERSION__ !== 'undefined') {
26
+ return __VERSION__;
27
+ }
28
+ // 2. 源码运行时从 package.json 读取(npm/dev)
29
+ try {
30
+ return require('../package.json').version;
31
+ } catch {
32
+ return '0.0.0-dev';
33
+ }
34
+ }
35
+
36
+ const VERSION = getVersion();
21
37
 
22
38
  const program = new Command();
23
39
 
24
40
  program
25
41
  .name('42plugin')
26
42
  .description('活水插件 - AI 插件管理工具')
27
- .version(version, '-v, --version', '显示版本号')
43
+ .version(VERSION, '-v, --version', '显示版本号')
28
44
  .option('--verbose', '详细输出')
29
45
  .option('--no-color', '禁用颜色输出');
30
46
 
@@ -44,7 +60,7 @@ program
44
60
  .command('version')
45
61
  .description('显示版本信息')
46
62
  .action(() => {
47
- console.log(`42plugin v${version}`);
63
+ console.log(`42plugin v${VERSION}`);
48
64
  });
49
65
 
50
66
  export { program };
package/src/utils.ts CHANGED
@@ -11,31 +11,58 @@ import { TargetType, type ParsedTarget, type PluginType } from './types';
11
11
  /**
12
12
  * 解析安装目标
13
13
  *
14
- * - Plugin: author/name
15
- * - Kit: author/kit/slug
14
+ * 格式:
15
+ * - Plugin (2段): author/name (e.g., alice/smart-reviewer)
16
+ * - Plugin (3段): author/kit-name/plugin-name (e.g., anthropics/claude-code/create-plugin)
17
+ * - Kit: author/kit/slug (中间必须是 "kit" 关键字)
16
18
  */
17
19
  export function parseTarget(target: string): ParsedTarget {
18
- // Kit: author/kit/slug
19
- if (target.includes('/kit/')) {
20
- const [author, , slug] = target.split('/');
20
+ const parts = target.split('/');
21
+
22
+ // Kit format: author/kit/slug (3段,中间是 "kit" 关键字)
23
+ if (parts.length === 3 && parts[1] === 'kit') {
24
+ const [author, , slug] = parts;
21
25
  if (!author || !slug) {
22
26
  throw new Error(`无效的套包格式: ${target}\n正确格式: author/kit/slug`);
23
27
  }
24
- return { type: TargetType.Kit, fullName: target, author, name: slug };
28
+ return {
29
+ type: TargetType.Kit,
30
+ fullName: target,
31
+ author,
32
+ name: slug,
33
+ };
25
34
  }
26
35
 
27
- // Plugin: author/name
28
- const parts = target.split('/');
29
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
30
- throw new Error(`无效的插件格式: ${target}\n正确格式: author/name`);
36
+ // Plugin format (2段): author/name
37
+ if (parts.length === 2) {
38
+ const [author, name] = parts;
39
+ if (!author || !name) {
40
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/name`);
41
+ }
42
+ return {
43
+ type: TargetType.Plugin,
44
+ fullName: target,
45
+ author,
46
+ name,
47
+ };
48
+ }
49
+
50
+ // Plugin format (3段): author/kit-name/plugin-name
51
+ if (parts.length === 3) {
52
+ const [author, kitName, pluginName] = parts;
53
+ if (!author || !kitName || !pluginName) {
54
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/kit-name/plugin-name`);
55
+ }
56
+ // 将 3 段格式传给 API,API 会处理
57
+ return {
58
+ type: TargetType.Plugin,
59
+ fullName: target,
60
+ author,
61
+ name: `${kitName}/${pluginName}`, // 组合成 API 期望的路径格式
62
+ };
31
63
  }
32
64
 
33
- return {
34
- type: TargetType.Plugin,
35
- fullName: target,
36
- author: parts[0],
37
- name: parts[1],
38
- };
65
+ throw new Error(`无效的安装目标格式: ${target}\n正确格式: author/name 或 author/kit-name/plugin-name 或 author/kit/slug`);
39
66
  }
40
67
 
41
68
  // ============================================================================