@hex4c59/pi-ext-copilot-auto 0.1.0 → 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -21
- package/README.md +316 -316
- package/docs/PROTOCOL.md +801 -801
- package/lib/client.ts +12 -4
- package/package.json +46 -42
package/lib/client.ts
CHANGED
|
@@ -74,6 +74,14 @@ async function describeFailure(response: Response): Promise<string> {
|
|
|
74
74
|
return `${response.status} ${trimmed.slice(0, 200)}`
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
const DEFAULT_FETCH_TIMEOUT_MS = 15_000
|
|
78
|
+
|
|
79
|
+
/** 为未自带超时的辅助请求统一附加超时,并与外部取消信号合并。 */
|
|
80
|
+
function withFetchTimeout(signal?: AbortSignal, timeoutMs = DEFAULT_FETCH_TIMEOUT_MS): AbortSignal {
|
|
81
|
+
const timeout = AbortSignal.timeout(timeoutMs)
|
|
82
|
+
return signal === undefined ? timeout : AbortSignal.any([signal, timeout])
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
/**
|
|
78
86
|
* 拉取模型目录。
|
|
79
87
|
*
|
|
@@ -86,7 +94,7 @@ export async function fetchCatalog(target: RequestTarget): Promise<CatalogEntry[
|
|
|
86
94
|
const response = await fetch(`${target.baseUrl}/models`, {
|
|
87
95
|
method: 'GET',
|
|
88
96
|
headers: headers(target, { Accept: 'application/json', 'X-GitHub-Api-Version': AUTO_API_VERSION }),
|
|
89
|
-
|
|
97
|
+
signal: withFetchTimeout(target.signal),
|
|
90
98
|
})
|
|
91
99
|
if (!response.ok) throw new Error(`Copilot 模型目录获取失败: ${await describeFailure(response)}`)
|
|
92
100
|
const body = (await response.json()) as CatalogResponse
|
|
@@ -439,7 +447,7 @@ export async function fetchAccount(githubToken: string, signal?: AbortSignal): P
|
|
|
439
447
|
Accept: 'application/json',
|
|
440
448
|
...CLIENT_HEADERS,
|
|
441
449
|
},
|
|
442
|
-
|
|
450
|
+
signal: withFetchTimeout(signal),
|
|
443
451
|
})
|
|
444
452
|
if (!response.ok) throw new Error(`Copilot 账号信息获取失败: ${await describeFailure(response)}`)
|
|
445
453
|
return (await response.json()) as CopilotAccount
|
|
@@ -464,7 +472,7 @@ export async function resolveApiBase(
|
|
|
464
472
|
Accept: 'application/json',
|
|
465
473
|
...CLIENT_HEADERS,
|
|
466
474
|
},
|
|
467
|
-
|
|
475
|
+
signal: withFetchTimeout(signal),
|
|
468
476
|
})
|
|
469
477
|
if (!response.ok) return undefined
|
|
470
478
|
const body = (await response.json()) as CopilotUserResponse
|
|
@@ -495,7 +503,7 @@ export async function refreshAccessToken(
|
|
|
495
503
|
Accept: 'application/json',
|
|
496
504
|
...CLIENT_HEADERS,
|
|
497
505
|
},
|
|
498
|
-
|
|
506
|
+
signal: withFetchTimeout(signal),
|
|
499
507
|
})
|
|
500
508
|
if (!response.ok) return undefined
|
|
501
509
|
const body = (await response.json()) as { token?: unknown; expires_at?: unknown }
|
package/package.json
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hex4c59/pi-ext-copilot-auto",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "GitHub Copilot Auto routing for pi: an `auto` virtual model routed via /auto plus authorized models via /models/session, each with its own session-token scope",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/Hex4C59/my-pi-extensions",
|
|
9
|
-
"directory": "copilot-auto"
|
|
10
|
-
},
|
|
11
|
-
"type": "module",
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@hex4c59/pi-ext-copilot-auto",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "GitHub Copilot Auto routing for pi: an `auto` virtual model routed via /auto plus authorized models via /models/session, each with its own session-token scope",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Hex4C59/my-pi-extensions",
|
|
9
|
+
"directory": "copilot-auto"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.19.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
21
|
+
"@earendil-works/pi-ai": "*"
|
|
22
|
+
},
|
|
23
|
+
"pi": {
|
|
24
|
+
"extensions": [
|
|
25
|
+
"./extensions/copilot-auto.ts"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
30
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
31
|
+
"@types/node": "^22.19.0",
|
|
32
|
+
"typescript": "^6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "node --experimental-strip-types tests/offline.ts"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"extensions",
|
|
40
|
+
"lib",
|
|
41
|
+
"docs",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE",
|
|
44
|
+
"CHANGELOG.md"
|
|
45
|
+
]
|
|
46
|
+
}
|