opencode-catpaw-auth 1.2.2 → 1.3.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.
@@ -3,6 +3,10 @@
3
3
  * 配置文件路径: ~/.config/mcopilot-cli/.config.yaml
4
4
  */
5
5
  export declare function loadApiKeyFromConfig(): Promise<string | null>;
6
+ /**
7
+ * 获取工作目录(用户主目录)
8
+ */
9
+ export declare function getWorkingDir(): string;
6
10
  /**
7
11
  * 获取配置文件路径(用于调试)
8
12
  */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBnE;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBnE;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
@@ -30,6 +30,12 @@ export async function loadApiKeyFromConfig() {
30
30
  return null;
31
31
  }
32
32
  }
33
+ /**
34
+ * 获取工作目录(用户主目录)
35
+ */
36
+ export function getWorkingDir() {
37
+ return homedir();
38
+ }
33
39
  /**
34
40
  * 获取配置文件路径(用于调试)
35
41
  */
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Constants for Catpaw Auth plugin
3
+ */
4
+ /**
5
+ * Anthropic API version header
6
+ */
7
+ export declare const ANTHROPIC_API_VERSION = "2023-06-01";
8
+ /**
9
+ * Headers for Anthropic API requests
10
+ */
11
+ export declare const ANTHROPIC_HEADERS: {
12
+ readonly "anthropic-version": "2023-06-01";
13
+ readonly "content-type": "application/json";
14
+ };
15
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Constants for Catpaw Auth plugin
3
+ */
4
+ /**
5
+ * Anthropic API version header
6
+ */
7
+ export const ANTHROPIC_API_VERSION = "2023-06-01";
8
+ /**
9
+ * Headers for Anthropic API requests
10
+ */
11
+ export const ANTHROPIC_HEADERS = {
12
+ "anthropic-version": ANTHROPIC_API_VERSION,
13
+ "content-type": "application/json",
14
+ };
@@ -1,12 +1,12 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
- export declare const CATPAW_PROVIDER_ID = "catpaw";
2
+ export declare const CATPAW_PROVIDER_ID = "anthropic";
3
3
  /**
4
- * CatPaw AI Provider Plugin for OpenCode
4
+ * CatPaw Anthropic Proxy Plugin for OpenCode
5
5
  *
6
- * This plugin automatically:
6
+ * This plugin provides automatic authentication for mcli.sankuai.com:
7
7
  * 1. Loads API key from ~/.config/mcopilot-cli/.config.yaml
8
- * 2. Injects required headers (x-api-key, x-working-dir)
9
- * 3. Supports multiple models: LongCat-Flash-Chat, kimi-k2.5, glm-5, MiniMax-M2.5, claude-sonnet-4.5
8
+ * 2. Injects auth headers to requests to https://mcli.sankuai.com
9
+ * 3. Supports streaming responses
10
10
  */
11
11
  declare const plugin: Plugin;
12
12
  export default plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C;;;;;;;GAOG;AACH,QAAA,MAAM,MAAM,EAAE,MAsIb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAE9C;;;;;;;GAOG;AACH,QAAA,MAAM,MAAM,EAAE,MAoFb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC"}
@@ -1,59 +1,53 @@
1
- import { loadApiKeyFromConfig } from "./config";
2
- import { isCatPawRequest, prepareCatPawRequest } from "./request";
3
- export const CATPAW_PROVIDER_ID = "catpaw";
1
+ import { loadApiKeyFromConfig, getWorkingDir } from "./config";
2
+ import { isTargetRequest, prepareProxyRequest } from "./request";
3
+ export const CATPAW_PROVIDER_ID = "anthropic";
4
4
  /**
5
- * CatPaw AI Provider Plugin for OpenCode
5
+ * CatPaw Anthropic Proxy Plugin for OpenCode
6
6
  *
7
- * This plugin automatically:
7
+ * This plugin provides automatic authentication for mcli.sankuai.com:
8
8
  * 1. Loads API key from ~/.config/mcopilot-cli/.config.yaml
9
- * 2. Injects required headers (x-api-key, x-working-dir)
10
- * 3. Supports multiple models: LongCat-Flash-Chat, kimi-k2.5, glm-5, MiniMax-M2.5, claude-sonnet-4.5
9
+ * 2. Injects auth headers to requests to https://mcli.sankuai.com
10
+ * 3. Supports streaming responses
11
11
  */
12
- const plugin = async ({ client, }) => {
12
+ const plugin = async ({ client }) => {
13
+ const apiKey = await loadApiKeyFromConfig();
14
+ const workingDir = getWorkingDir();
13
15
  return {
14
16
  config: async (config) => {
15
- // 配置 CatPaw provider
16
17
  config.provider = config.provider || {};
17
18
  config.provider[CATPAW_PROVIDER_ID] = {
18
- npm: "@ai-sdk/openai-compatible",
19
- name: "CatPaw AI",
19
+ npm: "@ai-sdk/anthropic",
20
+ name: "CatPaw Anthropic Proxy",
20
21
  options: {
21
22
  baseURL: "https://mcli.sankuai.com/v1",
22
23
  },
23
24
  models: {
24
- "LongCat-Flash-Chat": {
25
- name: "LongCat Flash Chat",
26
- limit: {
27
- context: 256000,
28
- output: 8192,
29
- },
30
- },
31
25
  "kimi-k2.5": {
32
26
  name: "Kimi K2.5",
33
27
  limit: {
34
- context: 256000,
35
- output: 8192,
28
+ context: 200000,
29
+ output: 64000,
36
30
  },
37
31
  },
38
32
  "glm-5": {
39
33
  name: "GLM-5",
40
34
  limit: {
41
35
  context: 200000,
42
- output: 8192,
36
+ output: 64000,
43
37
  },
44
38
  },
45
39
  "MiniMax-M2.5": {
46
40
  name: "MiniMax M2.5",
47
41
  limit: {
48
42
  context: 200000,
49
- output: 8192,
43
+ output: 64000,
50
44
  },
51
45
  },
52
46
  "claude-sonnet-4.5": {
53
47
  name: "Claude Sonnet 4.5",
54
48
  limit: {
55
49
  context: 200000,
56
- output: 8192,
50
+ output: 64000,
57
51
  },
58
52
  },
59
53
  },
@@ -62,37 +56,16 @@ const plugin = async ({ client, }) => {
62
56
  auth: {
63
57
  provider: CATPAW_PROVIDER_ID,
64
58
  loader: async (getAuth, provider) => {
65
- // 从配置文件加载 API key
66
- const apiKey = await loadApiKeyFromConfig();
67
- if (!apiKey) {
68
- client.app.log({
69
- body: {
70
- service: "catpaw-auth",
71
- level: "error",
72
- message: "Failed to load API key from ~/.config/mcopilot-cli/.config.yaml",
73
- },
74
- });
75
- return {};
76
- }
77
- const workingDir = process.env.HOME || process.env.USERPROFILE || "/";
78
- client.app.log({
79
- body: {
80
- service: "catpaw-auth",
81
- level: "info",
82
- message: "CatPaw auth loaded successfully",
83
- extra: { workingDir },
84
- },
85
- });
86
59
  return {
87
- apiKey: "", // 使用自定义 fetch,不需要标准 apiKey
60
+ apiKey: "dummy-key",
88
61
  async fetch(input, init) {
89
- // 只处理 CatPaw 相关的请求
90
- if (!isCatPawRequest(input)) {
62
+ if (!isTargetRequest(input)) {
91
63
  return fetch(input, init);
92
64
  }
93
- // 准备请求,注入必要的 headers
94
- const { request, init: requestInit } = prepareCatPawRequest(input, init, apiKey, workingDir);
95
- // 发送请求
65
+ if (!apiKey) {
66
+ throw new Error("CatPaw API key not loaded. Check ~/.config/mcopilot-cli/.config.yaml");
67
+ }
68
+ const { request, init: requestInit } = prepareProxyRequest(input, init, apiKey, workingDir);
96
69
  return fetch(request, requestInit);
97
70
  },
98
71
  };
@@ -102,12 +75,9 @@ const plugin = async ({ client, }) => {
102
75
  type: "api",
103
76
  label: "Auto-config from mcopilot-cli",
104
77
  authorize: async () => {
105
- // 从 mcopilot-cli 配置文件加载 API key
106
- const apiKey = await loadApiKeyFromConfig();
107
78
  if (!apiKey) {
108
79
  return { type: "failed" };
109
80
  }
110
- // 返回成功,使用 apiKey 作为 key
111
81
  return {
112
82
  type: "success",
113
83
  key: apiKey,
@@ -1,11 +1,11 @@
1
1
  /**
2
- * 检查请求是否是 CatPaw API 请求
2
+ * 检查请求是否是发送到目标服务器的请求
3
3
  */
4
- export declare function isCatPawRequest(input: RequestInfo | URL | string): boolean;
4
+ export declare function isTargetRequest(input: RequestInfo | URL | string): boolean;
5
5
  /**
6
- * 准备 CatPaw 请求,注入必要的 headers
6
+ * 准备代理请求,注入认证 headers
7
7
  */
8
- export declare function prepareCatPawRequest(input: RequestInfo | URL | string, init: RequestInit | undefined, apiKey: string, workingDir: string): {
8
+ export declare function prepareProxyRequest(input: RequestInfo | URL | string, init: RequestInit | undefined, apiKey: string, workingDir: string): {
9
9
  request: RequestInfo | URL | string;
10
10
  init: RequestInit;
11
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,CAG1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,EACjC,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB;IAAE,OAAO,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CA8B5D"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,CAQ1E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,EACjC,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB;IAAE,OAAO,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CA2B5D"}
@@ -1,22 +1,25 @@
1
+ const TARGET_BASE_URL = "https://mcli.sankuai.com";
1
2
  /**
2
- * 检查请求是否是 CatPaw API 请求
3
+ * 检查请求是否是发送到目标服务器的请求
3
4
  */
4
- export function isCatPawRequest(input) {
5
- const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
6
- return url.includes("mcli.sankuai.com");
5
+ export function isTargetRequest(input) {
6
+ const url = typeof input === "string"
7
+ ? input
8
+ : input instanceof URL
9
+ ? input.toString()
10
+ : input.url;
11
+ return url.includes(TARGET_BASE_URL);
7
12
  }
8
13
  /**
9
- * 准备 CatPaw 请求,注入必要的 headers
14
+ * 准备代理请求,注入认证 headers
10
15
  */
11
- export function prepareCatPawRequest(input, init, apiKey, workingDir) {
12
- // 解析原始 URL
13
- const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
16
+ export function prepareProxyRequest(input, init, apiKey, workingDir) {
14
17
  // 准备 headers
15
18
  const headers = new Headers(init?.headers);
16
19
  // 移除可能冲突的 headers
17
20
  headers.delete("host");
18
21
  headers.delete("authorization");
19
- // 注入 CatPaw 必需的 headers
22
+ // 注入 CatPaw 必需的认证 headers
20
23
  headers.set("x-api-key", apiKey);
21
24
  headers.set("x-working-dir", workingDir);
22
25
  // 确保 Content-Type 存在
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-catpaw-auth",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "CatPaw AI provider plugin for OpenCode - Auto-auth from mcopilot-cli config",
5
5
  "author": "zu1k",
6
6
  "repository": {