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.
- package/dist/src/config.d.ts +4 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +6 -0
- package/dist/src/constants.d.ts +23 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +22 -0
- package/dist/src/plugin.d.ts +6 -5
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +50 -62
- package/dist/src/request.d.ts +4 -4
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +21 -9
- package/package.json +1 -1
package/dist/src/config.d.ts
CHANGED
package/dist/src/config.d.ts.map
CHANGED
|
@@ -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"}
|
package/dist/src/config.js
CHANGED
|
@@ -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
|
+
};
|
package/dist/src/plugin.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
|
-
export declare const CATPAW_PROVIDER_ID = "
|
|
2
|
+
export declare const CATPAW_PROVIDER_ID = "anthropic";
|
|
3
3
|
/**
|
|
4
|
-
* CatPaw
|
|
4
|
+
* CatPaw Anthropic Proxy Plugin for OpenCode
|
|
5
5
|
*
|
|
6
|
-
* This plugin
|
|
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.
|
|
9
|
-
* 3.
|
|
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;
|
package/dist/src/plugin.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/src/plugin.js
CHANGED
|
@@ -1,59 +1,68 @@
|
|
|
1
|
-
import { loadApiKeyFromConfig } from "./config";
|
|
2
|
-
import {
|
|
3
|
-
export const CATPAW_PROVIDER_ID = "
|
|
1
|
+
import { loadApiKeyFromConfig, getWorkingDir } from "./config";
|
|
2
|
+
import { isTargetRequest, prepareProxyRequest } from "./request";
|
|
3
|
+
export const CATPAW_PROVIDER_ID = "anthropic";
|
|
4
4
|
/**
|
|
5
|
-
* CatPaw
|
|
5
|
+
* CatPaw Anthropic Proxy Plugin for OpenCode
|
|
6
6
|
*
|
|
7
|
-
* This plugin
|
|
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.
|
|
10
|
-
* 3.
|
|
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
|
-
// 配置
|
|
38
|
+
// 配置 anthropic provider,指向本地代理
|
|
16
39
|
config.provider = config.provider || {};
|
|
17
40
|
config.provider[CATPAW_PROVIDER_ID] = {
|
|
18
|
-
npm: "@ai-sdk/
|
|
19
|
-
name: "CatPaw
|
|
41
|
+
npm: "@ai-sdk/anthropic",
|
|
42
|
+
name: "CatPaw Anthropic Proxy",
|
|
20
43
|
options: {
|
|
21
|
-
baseURL: "
|
|
44
|
+
baseURL: "http://127.0.0.1:2819/v1",
|
|
22
45
|
},
|
|
23
46
|
models: {
|
|
24
|
-
"
|
|
25
|
-
name: "
|
|
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
|
-
"
|
|
46
|
-
name: "
|
|
54
|
+
"claude-haiku-4.5": {
|
|
55
|
+
name: "Claude Haiku 4.5",
|
|
47
56
|
limit: {
|
|
48
57
|
context: 200000,
|
|
49
|
-
output:
|
|
58
|
+
output: 64000,
|
|
50
59
|
},
|
|
51
60
|
},
|
|
52
|
-
"claude-
|
|
53
|
-
name: "Claude
|
|
61
|
+
"claude-opus-4.5": {
|
|
62
|
+
name: "Claude Opus 4.5",
|
|
54
63
|
limit: {
|
|
55
64
|
context: 200000,
|
|
56
|
-
output:
|
|
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
|
|
75
|
+
apiKey: "dummy-key", // 使用自定义 fetch,这里只需要一个非空值
|
|
88
76
|
async fetch(input, init) {
|
|
89
|
-
//
|
|
90
|
-
if (!
|
|
77
|
+
// 检查是否是目标请求(发送到 localhost:2819)
|
|
78
|
+
if (!isTargetRequest(input)) {
|
|
91
79
|
return fetch(input, init);
|
|
92
80
|
}
|
|
93
|
-
|
|
94
|
-
|
|
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,
|
package/dist/src/request.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 检查请求是否是发送到代理服务器的请求
|
|
3
3
|
*/
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function isTargetRequest(input: RequestInfo | URL | string): boolean;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* 准备代理请求,转发到目标服务器并注入认证 headers
|
|
7
7
|
*/
|
|
8
|
-
export declare function
|
|
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":"
|
|
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"}
|
package/dist/src/request.js
CHANGED
|
@@ -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
|
-
*
|
|
4
|
+
* 检查请求是否是发送到代理服务器的请求
|
|
3
5
|
*/
|
|
4
|
-
export function
|
|
5
|
-
const url = typeof input === "string"
|
|
6
|
-
|
|
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
|
-
*
|
|
15
|
+
* 准备代理请求,转发到目标服务器并注入认证 headers
|
|
10
16
|
*/
|
|
11
|
-
export function
|
|
17
|
+
export function prepareProxyRequest(input, init, apiKey, workingDir) {
|
|
12
18
|
// 解析原始 URL
|
|
13
|
-
const
|
|
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
|
|
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:
|
|
44
|
+
request: targetUrl,
|
|
33
45
|
init: requestInit,
|
|
34
46
|
};
|
|
35
47
|
}
|