opencode-catpaw-auth 1.1.0 → 1.2.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/package.json +1 -1
- package/src/config.ts +2 -1
- package/src/plugin.ts +16 -1
- package/src/request.ts +5 -5
- package/src/types.ts +6 -3
package/package.json
CHANGED
package/src/config.ts
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -108,8 +108,23 @@ export const CatPawAuthPlugin = async ({ client }: PluginContext): Promise<Plugi
|
|
|
108
108
|
methods: [
|
|
109
109
|
{
|
|
110
110
|
provider: CATPAW_PROVIDER_ID,
|
|
111
|
-
label: "Auto-config from mcopilot-cli",
|
|
112
111
|
type: "api",
|
|
112
|
+
label: "Auto-config from mcopilot-cli",
|
|
113
|
+
authorize: async () => {
|
|
114
|
+
// 从 mcopilot-cli 配置文件加载 API key
|
|
115
|
+
const apiKey = await loadApiKeyFromConfig();
|
|
116
|
+
|
|
117
|
+
if (!apiKey) {
|
|
118
|
+
return { type: "failed" as const };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 返回成功,使用 apiKey 作为 key
|
|
122
|
+
return {
|
|
123
|
+
type: "success" as const,
|
|
124
|
+
key: apiKey,
|
|
125
|
+
provider: CATPAW_PROVIDER_ID,
|
|
126
|
+
};
|
|
127
|
+
},
|
|
113
128
|
},
|
|
114
129
|
],
|
|
115
130
|
},
|
package/src/request.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 检查请求是否是 CatPaw API 请求
|
|
3
3
|
*/
|
|
4
|
-
export function isCatPawRequest(input: RequestInfo): boolean {
|
|
5
|
-
const url = typeof input === "string" ? input : input.url;
|
|
4
|
+
export function isCatPawRequest(input: RequestInfo | URL | string): boolean {
|
|
5
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
6
6
|
return url.includes("mcli.sankuai.com");
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -10,13 +10,13 @@ export function isCatPawRequest(input: RequestInfo): boolean {
|
|
|
10
10
|
* 准备 CatPaw 请求,注入必要的 headers
|
|
11
11
|
*/
|
|
12
12
|
export function prepareCatPawRequest(
|
|
13
|
-
input: RequestInfo,
|
|
13
|
+
input: RequestInfo | URL | string,
|
|
14
14
|
init: RequestInit | undefined,
|
|
15
15
|
apiKey: string,
|
|
16
16
|
workingDir: string
|
|
17
|
-
): { request: RequestInfo; init: RequestInit } {
|
|
17
|
+
): { request: RequestInfo | URL | string; init: RequestInit } {
|
|
18
18
|
// 解析原始 URL
|
|
19
|
-
const url = typeof input === "string" ? input : input.url;
|
|
19
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
20
20
|
|
|
21
21
|
// 准备 headers
|
|
22
22
|
const headers = new Headers(init?.headers);
|
package/src/types.ts
CHANGED
|
@@ -71,15 +71,18 @@ export interface Provider {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
export interface AuthMethod {
|
|
74
|
-
provider
|
|
74
|
+
provider?: string;
|
|
75
75
|
label: string;
|
|
76
76
|
type: "oauth" | "api" | "token";
|
|
77
|
-
authorize?: () => Promise<
|
|
77
|
+
authorize?: (inputs?: Record<string, string>) => Promise<
|
|
78
|
+
| { type: "success"; key: string; provider?: string }
|
|
79
|
+
| { type: "failed" }
|
|
80
|
+
>;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
export type GetAuth = () => Promise<unknown>;
|
|
81
84
|
|
|
82
85
|
export interface LoaderResult {
|
|
83
86
|
apiKey: string;
|
|
84
|
-
fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
87
|
+
fetch: (input: RequestInfo | URL | string, init?: RequestInit) => Promise<Response>;
|
|
85
88
|
}
|