copilot-api-plus 1.0.58 → 1.1.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/{error-u36czEGD.js → error-CvwUkoEo.js} +1 -1
- package/dist/{error-u36czEGD.js.map → error-CvwUkoEo.js.map} +1 -1
- package/dist/error-DLqcVQL_.js +2 -0
- package/dist/get-user-BQuwSDT8.js +3 -0
- package/dist/{get-user-BxebJZB6.js → get-user-KT77mH5W.js} +13 -12
- package/dist/get-user-KT77mH5W.js.map +1 -0
- package/dist/main.js +1304 -193
- package/dist/main.js.map +1 -1
- package/dist/{token-DmGYG1Z1.js → token-Bw3H9i2D.js} +36 -22
- package/dist/token-Bw3H9i2D.js.map +1 -0
- package/dist/token-EeI9aJQ3.js +4 -0
- package/package.json +1 -1
- package/dist/error-BfWAfRit.js +0 -2
- package/dist/get-user-BxebJZB6.js.map +0 -1
- package/dist/get-user-D2HfoqjP.js +0 -3
- package/dist/token-DT9ko4dY.js +0 -4
- package/dist/token-DmGYG1Z1.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-
|
|
1
|
+
{"version":3,"file":"error-CvwUkoEo.js","names":[],"sources":["../src/lib/error.ts"],"sourcesContent":["import type { Context } from \"hono\"\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\"\n\nimport consola from \"consola\"\n\nexport class HTTPError extends Error {\n response: Response\n\n constructor(message: string, response: Response) {\n super(message)\n this.response = response\n }\n}\n\nexport async function forwardError(c: Context, error: unknown) {\n if (error instanceof HTTPError) {\n // Try to read error body, but it may already be consumed by the caller\n let errorText: string\n try {\n errorText = await error.response.text()\n } catch {\n // Body already read — fall back to the error message\n errorText = error.message\n }\n\n // 400 errors: concise log, already detailed upstream\n if (error.response.status === 400) {\n // no extra logging, upstream already printed details\n } else {\n let errorJson: unknown\n try {\n errorJson = JSON.parse(errorText)\n } catch {\n errorJson = errorText\n }\n consola.error(\"Error occurred:\", error)\n consola.error(\"HTTP error:\", errorJson)\n }\n\n return c.json(\n {\n error: {\n message: errorText,\n type: \"error\",\n },\n },\n error.response.status as ContentfulStatusCode,\n )\n }\n\n // Network errors (fetch failed, TLS disconnect, etc.) — concise log\n const message = (error as Error).message || String(error)\n const cause = (error as { cause?: Error }).cause\n if (cause) {\n consola.error(`${message}: ${cause.message}`)\n } else {\n consola.error(message)\n }\n return c.json(\n {\n error: {\n message: (error as Error).message,\n type: \"error\",\n },\n },\n 500,\n )\n}\n"],"mappings":";;AAKA,IAAa,YAAb,cAA+B,MAAM;CACnC;CAEA,YAAY,SAAiB,UAAoB;AAC/C,QAAM,QAAQ;AACd,OAAK,WAAW;;;AAIpB,eAAsB,aAAa,GAAY,OAAgB;AAC7D,KAAI,iBAAiB,WAAW;EAE9B,IAAI;AACJ,MAAI;AACF,eAAY,MAAM,MAAM,SAAS,MAAM;UACjC;AAEN,eAAY,MAAM;;AAIpB,MAAI,MAAM,SAAS,WAAW,KAAK,QAE5B;GACL,IAAI;AACJ,OAAI;AACF,gBAAY,KAAK,MAAM,UAAU;WAC3B;AACN,gBAAY;;AAEd,WAAQ,MAAM,mBAAmB,MAAM;AACvC,WAAQ,MAAM,eAAe,UAAU;;AAGzC,SAAO,EAAE,KACP,EACE,OAAO;GACL,SAAS;GACT,MAAM;GACP,EACF,EACD,MAAM,SAAS,OAChB;;CAIH,MAAM,UAAW,MAAgB,WAAW,OAAO,MAAM;CACzD,MAAM,QAAS,MAA4B;AAC3C,KAAI,MACF,SAAQ,MAAM,GAAG,QAAQ,IAAI,MAAM,UAAU;KAE7C,SAAQ,MAAM,QAAQ;AAExB,QAAO,EAAE,KACP,EACE,OAAO;EACL,SAAU,MAAgB;EAC1B,MAAM;EACP,EACF,EACD,IACD"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { t as HTTPError } from "./error-
|
|
1
|
+
import { t as HTTPError } from "./error-CvwUkoEo.js";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
//#region src/lib/state.ts
|
|
4
4
|
const state = {
|
|
5
5
|
accountType: "individual",
|
|
6
6
|
manualApprove: false,
|
|
7
7
|
rateLimitWait: false,
|
|
8
|
-
showToken: false
|
|
8
|
+
showToken: false,
|
|
9
|
+
multiAccountEnabled: false
|
|
9
10
|
};
|
|
10
11
|
//#endregion
|
|
11
12
|
//#region src/lib/api-config.ts
|
|
@@ -17,16 +18,16 @@ const COPILOT_VERSION = "0.26.7";
|
|
|
17
18
|
const EDITOR_PLUGIN_VERSION = `copilot-chat/${COPILOT_VERSION}`;
|
|
18
19
|
const USER_AGENT = `GitHubCopilotChat/${COPILOT_VERSION}`;
|
|
19
20
|
const API_VERSION = "2025-05-01";
|
|
20
|
-
const copilotBaseUrl = (
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
21
|
+
const copilotBaseUrl = (source) => {
|
|
22
|
+
if (source.copilotApiEndpoint) return source.copilotApiEndpoint;
|
|
23
|
+
return source.accountType === "individual" ? "https://api.githubcopilot.com" : `https://api.${source.accountType}.githubcopilot.com`;
|
|
23
24
|
};
|
|
24
|
-
const copilotHeaders = (
|
|
25
|
+
const copilotHeaders = (source, vision = false) => {
|
|
25
26
|
const headers = {
|
|
26
|
-
Authorization: `Bearer ${
|
|
27
|
+
Authorization: `Bearer ${source.copilotToken}`,
|
|
27
28
|
"content-type": standardHeaders()["content-type"],
|
|
28
29
|
"copilot-integration-id": "vscode-chat",
|
|
29
|
-
"editor-version": `vscode/${
|
|
30
|
+
"editor-version": `vscode/${source.vsCodeVersion}`,
|
|
30
31
|
"editor-plugin-version": EDITOR_PLUGIN_VERSION,
|
|
31
32
|
"user-agent": USER_AGENT,
|
|
32
33
|
"openai-intent": "conversation-panel",
|
|
@@ -38,10 +39,10 @@ const copilotHeaders = (state, vision = false) => {
|
|
|
38
39
|
return headers;
|
|
39
40
|
};
|
|
40
41
|
const GITHUB_API_BASE_URL = "https://api.github.com";
|
|
41
|
-
const githubHeaders = (
|
|
42
|
+
const githubHeaders = (source) => ({
|
|
42
43
|
...standardHeaders(),
|
|
43
|
-
authorization: `token ${
|
|
44
|
-
"editor-version": `vscode/${
|
|
44
|
+
authorization: `token ${source.githubToken}`,
|
|
45
|
+
"editor-version": `vscode/${source.vsCodeVersion}`,
|
|
45
46
|
"editor-plugin-version": EDITOR_PLUGIN_VERSION,
|
|
46
47
|
"user-agent": USER_AGENT,
|
|
47
48
|
"x-github-api-version": API_VERSION,
|
|
@@ -63,4 +64,4 @@ async function getGitHubUser() {
|
|
|
63
64
|
//#endregion
|
|
64
65
|
export { GITHUB_CLIENT_ID as a, githubHeaders as c, GITHUB_BASE_URL as i, standardHeaders as l, GITHUB_API_BASE_URL as n, copilotBaseUrl as o, GITHUB_APP_SCOPES as r, copilotHeaders as s, getGitHubUser as t, state as u };
|
|
65
66
|
|
|
66
|
-
//# sourceMappingURL=get-user-
|
|
67
|
+
//# sourceMappingURL=get-user-KT77mH5W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-user-KT77mH5W.js","names":[],"sources":["../src/lib/state.ts","../src/lib/api-config.ts","../src/services/github/get-user.ts"],"sourcesContent":["import type { ModelsResponse } from \"~/services/copilot/get-models\"\n\nexport interface State {\n githubToken?: string\n copilotToken?: string\n copilotApiEndpoint?: string // API endpoint returned by token response\n\n accountType: string\n models?: ModelsResponse\n vsCodeVersion?: string\n\n manualApprove: boolean\n rateLimitWait: boolean\n showToken: boolean\n\n // Rate limiting configuration\n rateLimitSeconds?: number\n lastRequestTimestamp?: number\n\n // API key authentication\n apiKeys?: Array<string>\n\n // Multi-account mode\n multiAccountEnabled: boolean\n}\n\nexport const state: State = {\n accountType: \"individual\",\n manualApprove: false,\n rateLimitWait: false,\n showToken: false,\n multiAccountEnabled: false,\n}\n","import { randomUUID } from \"node:crypto\"\n\nexport const standardHeaders = () => ({\n \"content-type\": \"application/json\",\n accept: \"application/json\",\n})\n\nconst COPILOT_VERSION = \"0.26.7\"\nconst EDITOR_PLUGIN_VERSION = `copilot-chat/${COPILOT_VERSION}`\nconst USER_AGENT = `GitHubCopilotChat/${COPILOT_VERSION}`\n\n// Updated to match latest Zed implementation - 2025-05-01 returns Claude models\nconst API_VERSION = \"2025-05-01\"\n\n/**\n * Common interface for anything that can supply Copilot/GitHub credentials.\n *\n * Both `State` and `Account` satisfy this interface, so all header/URL\n * helpers can accept either without an explicit overload.\n */\nexport interface TokenSource {\n copilotToken?: string\n copilotApiEndpoint?: string\n accountType: string\n githubToken?: string\n vsCodeVersion?: string\n}\n\n// Re-export constants used by other modules for building headers manually\nexport { API_VERSION, EDITOR_PLUGIN_VERSION, USER_AGENT }\n\n// Use the API endpoint from token response if available, otherwise fall back to default\nexport const copilotBaseUrl = (source: TokenSource) => {\n if (source.copilotApiEndpoint) {\n return source.copilotApiEndpoint\n }\n return source.accountType === \"individual\" ?\n \"https://api.githubcopilot.com\"\n : `https://api.${source.accountType}.githubcopilot.com`\n}\nexport const copilotHeaders = (\n source: TokenSource,\n vision: boolean = false,\n) => {\n const headers: Record<string, string> = {\n Authorization: `Bearer ${source.copilotToken}`,\n \"content-type\": standardHeaders()[\"content-type\"],\n \"copilot-integration-id\": \"vscode-chat\",\n \"editor-version\": `vscode/${source.vsCodeVersion}`,\n \"editor-plugin-version\": EDITOR_PLUGIN_VERSION,\n \"user-agent\": USER_AGENT,\n \"openai-intent\": \"conversation-panel\",\n \"x-github-api-version\": API_VERSION,\n \"x-request-id\": randomUUID(),\n \"x-vscode-user-agent-library-version\": \"electron-fetch\",\n }\n\n if (vision) headers[\"copilot-vision-request\"] = \"true\"\n\n return headers\n}\n\nexport const GITHUB_API_BASE_URL = \"https://api.github.com\"\nexport const githubHeaders = (source: TokenSource) => ({\n ...standardHeaders(),\n authorization: `token ${source.githubToken}`,\n \"editor-version\": `vscode/${source.vsCodeVersion}`,\n \"editor-plugin-version\": EDITOR_PLUGIN_VERSION,\n \"user-agent\": USER_AGENT,\n \"x-github-api-version\": API_VERSION,\n \"x-vscode-user-agent-library-version\": \"electron-fetch\",\n})\n\nexport const GITHUB_BASE_URL = \"https://github.com\"\nexport const GITHUB_CLIENT_ID = \"Iv1.b507a08c87ecfe98\"\nexport const GITHUB_APP_SCOPES = [\"read:user\"].join(\" \")\n","import { GITHUB_API_BASE_URL, standardHeaders } from \"~/lib/api-config\"\nimport { HTTPError } from \"~/lib/error\"\nimport { state } from \"~/lib/state\"\n\nexport async function getGitHubUser() {\n const response = await fetch(`${GITHUB_API_BASE_URL}/user`, {\n headers: {\n authorization: `token ${state.githubToken}`,\n ...standardHeaders(),\n },\n })\n\n if (!response.ok) throw new HTTPError(\"Failed to get GitHub user\", response)\n\n return (await response.json()) as GithubUserResponse\n}\n\n// Trimmed for the sake of simplicity\ninterface GithubUserResponse {\n login: string\n}\n"],"mappings":";;;AA0BA,MAAa,QAAe;CAC1B,aAAa;CACb,eAAe;CACf,eAAe;CACf,WAAW;CACX,qBAAqB;CACtB;;;AC9BD,MAAa,yBAAyB;CACpC,gBAAgB;CAChB,QAAQ;CACT;AAED,MAAM,kBAAkB;AACxB,MAAM,wBAAwB,gBAAgB;AAC9C,MAAM,aAAa,qBAAqB;AAGxC,MAAM,cAAc;AAoBpB,MAAa,kBAAkB,WAAwB;AACrD,KAAI,OAAO,mBACT,QAAO,OAAO;AAEhB,QAAO,OAAO,gBAAgB,eAC1B,kCACA,eAAe,OAAO,YAAY;;AAExC,MAAa,kBACX,QACA,SAAkB,UACf;CACH,MAAM,UAAkC;EACtC,eAAe,UAAU,OAAO;EAChC,gBAAgB,iBAAiB,CAAC;EAClC,0BAA0B;EAC1B,kBAAkB,UAAU,OAAO;EACnC,yBAAyB;EACzB,cAAc;EACd,iBAAiB;EACjB,wBAAwB;EACxB,gBAAgB,YAAY;EAC5B,uCAAuC;EACxC;AAED,KAAI,OAAQ,SAAQ,4BAA4B;AAEhD,QAAO;;AAGT,MAAa,sBAAsB;AACnC,MAAa,iBAAiB,YAAyB;CACrD,GAAG,iBAAiB;CACpB,eAAe,SAAS,OAAO;CAC/B,kBAAkB,UAAU,OAAO;CACnC,yBAAyB;CACzB,cAAc;CACd,wBAAwB;CACxB,uCAAuC;CACxC;AAED,MAAa,kBAAkB;AAC/B,MAAa,mBAAmB;AAChC,MAAa,oBAAoB,CAAC,YAAY,CAAC,KAAK,IAAI;;;ACvExD,eAAsB,gBAAgB;CACpC,MAAM,WAAW,MAAM,MAAM,GAAG,oBAAoB,QAAQ,EAC1D,SAAS;EACP,eAAe,SAAS,MAAM;EAC9B,GAAG,iBAAiB;EACrB,EACF,CAAC;AAEF,KAAI,CAAC,SAAS,GAAI,OAAM,IAAI,UAAU,6BAA6B,SAAS;AAE5E,QAAQ,MAAM,SAAS,MAAM"}
|