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.
- 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 +15 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +14 -0
- package/dist/src/plugin.d.ts +5 -5
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +23 -53
- package/dist/src/request.d.ts +4 -4
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +12 -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,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
|
+
};
|
package/dist/src/plugin.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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 provides automatic authentication for mcli.sankuai.com:
|
|
7
7
|
* 1. Loads API key from ~/.config/mcopilot-cli/.config.yaml
|
|
8
|
-
* 2. Injects
|
|
9
|
-
* 3. Supports
|
|
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;
|
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;;;;;;;GAOG;AACH,QAAA,MAAM,MAAM,EAAE,MAoFb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/src/plugin.js
CHANGED
|
@@ -1,59 +1,53 @@
|
|
|
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 provides automatic authentication for mcli.sankuai.com:
|
|
8
8
|
* 1. Loads API key from ~/.config/mcopilot-cli/.config.yaml
|
|
9
|
-
* 2. Injects
|
|
10
|
-
* 3. Supports
|
|
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/
|
|
19
|
-
name: "CatPaw
|
|
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:
|
|
35
|
-
output:
|
|
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:
|
|
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:
|
|
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:
|
|
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: "",
|
|
60
|
+
apiKey: "dummy-key",
|
|
88
61
|
async fetch(input, init) {
|
|
89
|
-
|
|
90
|
-
if (!isCatPawRequest(input)) {
|
|
62
|
+
if (!isTargetRequest(input)) {
|
|
91
63
|
return fetch(input, init);
|
|
92
64
|
}
|
|
93
|
-
|
|
94
|
-
|
|
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,
|
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":"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"}
|
package/dist/src/request.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
+
const TARGET_BASE_URL = "https://mcli.sankuai.com";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* 检查请求是否是发送到目标服务器的请求
|
|
3
4
|
*/
|
|
4
|
-
export function
|
|
5
|
-
const url = typeof input === "string"
|
|
6
|
-
|
|
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
|
-
*
|
|
14
|
+
* 准备代理请求,注入认证 headers
|
|
10
15
|
*/
|
|
11
|
-
export function
|
|
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
|
|
22
|
+
// 注入 CatPaw 必需的认证 headers
|
|
20
23
|
headers.set("x-api-key", apiKey);
|
|
21
24
|
headers.set("x-working-dir", workingDir);
|
|
22
25
|
// 确保 Content-Type 存在
|