opencode-catpaw-auth 1.2.2 → 1.3.0

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,23 @@
1
+ /**
2
+ * Constants for Catpaw Auth plugin
3
+ */
4
+ /**
5
+ * Provider identifier for Catpaw/Quotio
6
+ */
7
+ export declare const CATPAW_PROVIDER_ID = "quotio";
8
+ /**
9
+ * Default base URL for Quotio API
10
+ */
11
+ export declare const QUOTIO_DEFAULT_BASE_URL = "http://127.0.0.1:8317/v1";
12
+ /**
13
+ * Anthropic API version header
14
+ */
15
+ export declare const ANTHROPIC_API_VERSION = "2023-06-01";
16
+ /**
17
+ * Headers for Anthropic API requests
18
+ */
19
+ export declare const ANTHROPIC_HEADERS: {
20
+ readonly "anthropic-version": "2023-06-01";
21
+ readonly "content-type": "application/json";
22
+ };
23
+ //# 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,kBAAkB,WAAW,CAAC;AAE3C;;GAEG;AACH,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Constants for Catpaw Auth plugin
3
+ */
4
+ /**
5
+ * Provider identifier for Catpaw/Quotio
6
+ */
7
+ export const CATPAW_PROVIDER_ID = "quotio";
8
+ /**
9
+ * Default base URL for Quotio API
10
+ */
11
+ export const QUOTIO_DEFAULT_BASE_URL = "http://127.0.0.1:8317/v1";
12
+ /**
13
+ * Anthropic API version header
14
+ */
15
+ export const ANTHROPIC_API_VERSION = "2023-06-01";
16
+ /**
17
+ * Headers for Anthropic API requests
18
+ */
19
+ export const ANTHROPIC_HEADERS = {
20
+ "anthropic-version": ANTHROPIC_API_VERSION,
21
+ "content-type": "application/json",
22
+ };
@@ -1,12 +1,13 @@
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 acts as a proxy to mcli.sankuai.com with automatic authentication:
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. Intercepts requests to localhost:2819
9
+ * 3. Forwards to https://mcli.sankuai.com with auth headers
10
+ * 4. Supports streaming responses
10
11
  */
11
12
  declare const plugin: Plugin;
12
13
  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;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,MAqHb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC"}
@@ -1,59 +1,68 @@
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 acts as a proxy to mcli.sankuai.com with automatic authentication:
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. Intercepts requests to localhost:2819
10
+ * 3. Forwards to https://mcli.sankuai.com with auth headers
11
+ * 4. Supports streaming responses
11
12
  */
12
13
  const plugin = async ({ client, }) => {
14
+ // 预加载配置
15
+ const apiKey = await loadApiKeyFromConfig();
16
+ const workingDir = getWorkingDir();
17
+ if (!apiKey) {
18
+ client.app.log({
19
+ body: {
20
+ service: "catpaw-auth",
21
+ level: "error",
22
+ message: "Failed to load API key from ~/.config/mcopilot-cli/.config.yaml",
23
+ },
24
+ });
25
+ }
26
+ else {
27
+ client.app.log({
28
+ body: {
29
+ service: "catpaw-auth",
30
+ level: "info",
31
+ message: "CatPaw proxy loaded successfully",
32
+ extra: { workingDir, apiKeyPrefix: apiKey.slice(0, 8) + "..." },
33
+ },
34
+ });
35
+ }
13
36
  return {
14
37
  config: async (config) => {
15
- // 配置 CatPaw provider
38
+ // 配置 anthropic provider,指向本地代理
16
39
  config.provider = config.provider || {};
17
40
  config.provider[CATPAW_PROVIDER_ID] = {
18
- npm: "@ai-sdk/openai-compatible",
19
- name: "CatPaw AI",
41
+ npm: "@ai-sdk/anthropic",
42
+ name: "CatPaw Anthropic Proxy",
20
43
  options: {
21
- baseURL: "https://mcli.sankuai.com/v1",
44
+ baseURL: "http://127.0.0.1:2819/v1",
22
45
  },
23
46
  models: {
24
- "LongCat-Flash-Chat": {
25
- name: "LongCat Flash Chat",
26
- limit: {
27
- context: 256000,
28
- output: 8192,
29
- },
30
- },
31
- "kimi-k2.5": {
32
- name: "Kimi K2.5",
33
- limit: {
34
- context: 256000,
35
- output: 8192,
36
- },
37
- },
38
- "glm-5": {
39
- name: "GLM-5",
47
+ "claude-sonnet-4.5": {
48
+ name: "Claude Sonnet 4.5",
40
49
  limit: {
41
50
  context: 200000,
42
51
  output: 8192,
43
52
  },
44
53
  },
45
- "MiniMax-M2.5": {
46
- name: "MiniMax M2.5",
54
+ "claude-haiku-4.5": {
55
+ name: "Claude Haiku 4.5",
47
56
  limit: {
48
57
  context: 200000,
49
- output: 8192,
58
+ output: 64000,
50
59
  },
51
60
  },
52
- "claude-sonnet-4.5": {
53
- name: "Claude Sonnet 4.5",
61
+ "claude-opus-4.5": {
62
+ name: "Claude Opus 4.5",
54
63
  limit: {
55
64
  context: 200000,
56
- output: 8192,
65
+ output: 64000,
57
66
  },
58
67
  },
59
68
  },
@@ -62,36 +71,18 @@ const plugin = async ({ client, }) => {
62
71
  auth: {
63
72
  provider: CATPAW_PROVIDER_ID,
64
73
  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
74
  return {
87
- apiKey: "", // 使用自定义 fetch,不需要标准 apiKey
75
+ apiKey: "dummy-key", // 使用自定义 fetch,这里只需要一个非空值
88
76
  async fetch(input, init) {
89
- // 只处理 CatPaw 相关的请求
90
- if (!isCatPawRequest(input)) {
77
+ // 检查是否是目标请求(发送到 localhost:2819)
78
+ if (!isTargetRequest(input)) {
91
79
  return fetch(input, init);
92
80
  }
93
- // 准备请求,注入必要的 headers
94
- const { request, init: requestInit } = prepareCatPawRequest(input, init, apiKey, workingDir);
81
+ if (!apiKey) {
82
+ throw new Error("CatPaw API key not loaded. Check ~/.config/mcopilot-cli/.config.yaml");
83
+ }
84
+ // 准备代理请求,转发到目标服务器
85
+ const { request, init: requestInit } = prepareProxyRequest(input, init, apiKey, workingDir);
95
86
  // 发送请求
96
87
  return fetch(request, requestInit);
97
88
  },
@@ -102,12 +93,9 @@ const plugin = async ({ client, }) => {
102
93
  type: "api",
103
94
  label: "Auto-config from mcopilot-cli",
104
95
  authorize: async () => {
105
- // 从 mcopilot-cli 配置文件加载 API key
106
- const apiKey = await loadApiKeyFromConfig();
107
96
  if (!apiKey) {
108
97
  return { type: "failed" };
109
98
  }
110
- // 返回成功,使用 apiKey 作为 key
111
99
  return {
112
100
  type: "success",
113
101
  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":"AAGA;;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,CAwC5D"}
@@ -1,22 +1,34 @@
1
+ const TARGET_BASE_URL = "https://mcli.sankuai.com";
2
+ const PROXY_HOST = "127.0.0.1:2819";
1
3
  /**
2
- * 检查请求是否是 CatPaw API 请求
4
+ * 检查请求是否是发送到代理服务器的请求
3
5
  */
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");
6
+ export function isTargetRequest(input) {
7
+ const url = typeof input === "string"
8
+ ? input
9
+ : input instanceof URL
10
+ ? input.toString()
11
+ : input.url;
12
+ return url.includes(PROXY_HOST);
7
13
  }
8
14
  /**
9
- * 准备 CatPaw 请求,注入必要的 headers
15
+ * 准备代理请求,转发到目标服务器并注入认证 headers
10
16
  */
11
- export function prepareCatPawRequest(input, init, apiKey, workingDir) {
17
+ export function prepareProxyRequest(input, init, apiKey, workingDir) {
12
18
  // 解析原始 URL
13
- const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
19
+ const originalUrl = typeof input === "string"
20
+ ? input
21
+ : input instanceof URL
22
+ ? input.toString()
23
+ : input.url;
24
+ // 将 localhost:2819 替换为目标服务器
25
+ const targetUrl = originalUrl.replace(/http:\/\/127\.0\.0\.1:2819/, TARGET_BASE_URL);
14
26
  // 准备 headers
15
27
  const headers = new Headers(init?.headers);
16
28
  // 移除可能冲突的 headers
17
29
  headers.delete("host");
18
30
  headers.delete("authorization");
19
- // 注入 CatPaw 必需的 headers
31
+ // 注入 CatPaw 必需的认证 headers
20
32
  headers.set("x-api-key", apiKey);
21
33
  headers.set("x-working-dir", workingDir);
22
34
  // 确保 Content-Type 存在
@@ -29,7 +41,7 @@ export function prepareCatPawRequest(input, init, apiKey, workingDir) {
29
41
  headers,
30
42
  };
31
43
  return {
32
- request: input,
44
+ request: targetUrl,
33
45
  init: requestInit,
34
46
  };
35
47
  }
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.0",
4
4
  "description": "CatPaw AI provider plugin for OpenCode - Auto-auth from mcopilot-cli config",
5
5
  "author": "zu1k",
6
6
  "repository": {