xiaodcs-copilot-api-edge 2.3.9-edge.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/LICENSE +21 -0
- package/README.md +888 -0
- package/README.zh-CN.md +940 -0
- package/dist/auth-BiVetBYt.js +446 -0
- package/dist/auth-Bu4MXadr.js +2 -0
- package/dist/config-SytZjLq8.js +544 -0
- package/dist/debug-BFadhEB4.js +90 -0
- package/dist/electron-fetch-BRX-ug5E.js +20 -0
- package/dist/fast-path-BoMnZCVC.js +9 -0
- package/dist/main.js +49 -0
- package/dist/mcp-fpSlKZxK.js +14 -0
- package/dist/mcp-server-BeNu_Edl.js +25 -0
- package/dist/mcp-server-DQ4r-fAy.js +2 -0
- package/dist/models-YMUf33c-.js +88 -0
- package/dist/server-CFQmvoAJ.js +11710 -0
- package/dist/start-FFVCi8su.js +528 -0
- package/dist/tls-Aq1Dd8E2.js +14 -0
- package/dist/token-D9svRIYW.js +1950 -0
- package/dist/tool-search-Ds1vbmGG.js +114 -0
- package/package.json +96 -0
- package/pages/index.html +2257 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as isMcpFastPath } from "./fast-path-BoMnZCVC.js";
|
|
3
|
+
//#region src/main.ts
|
|
4
|
+
if (isMcpFastPath(process.argv)) {
|
|
5
|
+
const { runMcpServer } = await import("./mcp-server-DQ4r-fAy.js");
|
|
6
|
+
await runMcpServer();
|
|
7
|
+
} else {
|
|
8
|
+
const { defineCommand, runMain, parseArgs } = await import("citty");
|
|
9
|
+
const cliArgs = {
|
|
10
|
+
"api-home": {
|
|
11
|
+
type: "string",
|
|
12
|
+
description: "Path to the API home directory."
|
|
13
|
+
},
|
|
14
|
+
"oauth-app": {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "OAuth app identifier."
|
|
17
|
+
},
|
|
18
|
+
"enterprise-url": {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Enterprise URL for GitHub."
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const args = parseArgs(process.argv, cliArgs);
|
|
24
|
+
if (typeof args["api-home"] === "string") process.env.COPILOT_API_HOME = args["api-home"];
|
|
25
|
+
if (typeof args["oauth-app"] === "string") process.env.COPILOT_API_OAUTH_APP = args["oauth-app"];
|
|
26
|
+
if (typeof args["enterprise-url"] === "string") process.env.COPILOT_API_ENTERPRISE_URL = args["enterprise-url"];
|
|
27
|
+
if (process.platform === "win32" && process.stdout.isTTY && !process.env.WT_SESSION) process.env.WT_SESSION = "copilot-api";
|
|
28
|
+
const { bindElectronFetch } = await import("./electron-fetch-BRX-ug5E.js");
|
|
29
|
+
bindElectronFetch();
|
|
30
|
+
const { auth } = await import("./auth-Bu4MXadr.js");
|
|
31
|
+
const { debug } = await import("./debug-BFadhEB4.js");
|
|
32
|
+
const { mcp } = await import("./mcp-fpSlKZxK.js");
|
|
33
|
+
const { start } = await import("./start-FFVCi8su.js");
|
|
34
|
+
await runMain(defineCommand({
|
|
35
|
+
meta: {
|
|
36
|
+
name: "copilot-api",
|
|
37
|
+
description: "A wrapper around GitHub Copilot API to make it OpenAI compatible, making it usable for other tools."
|
|
38
|
+
},
|
|
39
|
+
subCommands: {
|
|
40
|
+
auth,
|
|
41
|
+
start,
|
|
42
|
+
debug,
|
|
43
|
+
mcp
|
|
44
|
+
},
|
|
45
|
+
args: cliArgs
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as runMcpServer } from "./mcp-server-BeNu_Edl.js";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
//#region src/mcp.ts
|
|
4
|
+
const mcp = defineCommand({
|
|
5
|
+
meta: {
|
|
6
|
+
name: "mcp",
|
|
7
|
+
description: "Start the Copilot API MCP tool_search bridge over stdio"
|
|
8
|
+
},
|
|
9
|
+
run() {
|
|
10
|
+
return runMcpServer();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { mcp };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { n as createMcpToolSearchSentinel } from "./tool-search-Ds1vbmGG.js";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/lib/mcp-server.ts
|
|
6
|
+
const SERVER_NAME = "tool_search";
|
|
7
|
+
const SERVER_VERSION = "1.0.0";
|
|
8
|
+
const runMcpServer = async () => {
|
|
9
|
+
const server = new McpServer({
|
|
10
|
+
name: SERVER_NAME,
|
|
11
|
+
version: SERVER_VERSION
|
|
12
|
+
});
|
|
13
|
+
server.registerTool("search", {
|
|
14
|
+
title: "Tool Search Bridge",
|
|
15
|
+
description: "Load deferred tools by exact name through the Copilot API tool_search bridge.",
|
|
16
|
+
inputSchema: { names: z.string().describe("Comma-separated exact deferred tool names to load, for example \"TaskList,TaskGet,mcp__fetch__fetch\".") },
|
|
17
|
+
_meta: { "anthropic/alwaysLoad": true }
|
|
18
|
+
}, ({ names }) => ({ content: [{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: createMcpToolSearchSentinel(names)
|
|
21
|
+
}] }));
|
|
22
|
+
await server.connect(new StdioServerTransport());
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { runMcpServer as t };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { K as state } from "./token-D9svRIYW.js";
|
|
2
|
+
//#region src/lib/models.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Copilot upstream model ID to a client-friendly ID that Claude Code
|
|
5
|
+
* and Claude Desktop recognize (dots in version replaced with hyphens).
|
|
6
|
+
* e.g. "claude-sonnet-4.6" -> "claude-sonnet-4-6"
|
|
7
|
+
* Non-Claude models are returned unchanged.
|
|
8
|
+
*/
|
|
9
|
+
const toClientModelId = (modelId) => {
|
|
10
|
+
const normalized = normalizeSdkModelId(modelId);
|
|
11
|
+
if (!normalized) return modelId;
|
|
12
|
+
const versionHyphenated = normalized.version.replaceAll(".", "-");
|
|
13
|
+
return `claude-${normalized.family}-${versionHyphenated}`;
|
|
14
|
+
};
|
|
15
|
+
const findEndpointModel = (sdkModelId) => {
|
|
16
|
+
const models = state.models?.data ?? [];
|
|
17
|
+
const exactMatch = models.find((m) => m.id === sdkModelId);
|
|
18
|
+
if (exactMatch) return exactMatch;
|
|
19
|
+
const normalized = normalizeSdkModelId(sdkModelId);
|
|
20
|
+
if (!normalized) return;
|
|
21
|
+
const modelName = `claude-${normalized.family}-${normalized.version}`;
|
|
22
|
+
const model = models.find((m) => m.id === modelName);
|
|
23
|
+
if (model) return model;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Finds the latest available model for a given Claude family (e.g. "opus",
|
|
27
|
+
* "sonnet", "haiku") among the models currently cached in `state.models`.
|
|
28
|
+
* "Latest" is determined by the highest semantic version parsed from the model
|
|
29
|
+
* ID. Returns `undefined` when no model of that family is available.
|
|
30
|
+
*/
|
|
31
|
+
const getLatestModelForFamily = (family) => {
|
|
32
|
+
const models = state.models?.data ?? [];
|
|
33
|
+
let best;
|
|
34
|
+
for (const model of models) {
|
|
35
|
+
const normalized = normalizeSdkModelId(model.id);
|
|
36
|
+
if (!normalized || normalized.family !== family) continue;
|
|
37
|
+
const [majorPart, minorPart = "0"] = normalized.version.split(".");
|
|
38
|
+
const major = Number.parseInt(majorPart, 10);
|
|
39
|
+
const minor = Number.parseInt(minorPart, 10);
|
|
40
|
+
if (Number.isNaN(major) || Number.isNaN(minor)) continue;
|
|
41
|
+
if (!best || major > best.major || major === best.major && minor > best.minor) best = {
|
|
42
|
+
model,
|
|
43
|
+
major,
|
|
44
|
+
minor
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return best?.model;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Normalizes an SDK model ID to extract the model family and version.
|
|
51
|
+
* this method from github copilot extension
|
|
52
|
+
* Examples:
|
|
53
|
+
* - "claude-opus-4-5-20251101" -> { family: "opus", version: "4.5" }
|
|
54
|
+
* - "claude-3-5-sonnet-20241022" -> { family: "sonnet", version: "3.5" }
|
|
55
|
+
* - "claude-sonnet-4-20250514" -> { family: "sonnet", version: "4" }
|
|
56
|
+
* - "claude-haiku-3-5-20250514" -> { family: "haiku", version: "3.5" }
|
|
57
|
+
* - "claude-haiku-4.5" -> { family: "haiku", version: "4.5" }
|
|
58
|
+
*/
|
|
59
|
+
const normalizeSdkModelId = (sdkModelId) => {
|
|
60
|
+
const withoutDate = sdkModelId.toLowerCase().replace(/-\d{8}$/, "");
|
|
61
|
+
const pattern1 = withoutDate.match(/^claude-(\w+)-(\d+)\.(\d+)$/);
|
|
62
|
+
if (pattern1) return {
|
|
63
|
+
family: pattern1[1],
|
|
64
|
+
version: `${pattern1[2]}.${pattern1[3]}`
|
|
65
|
+
};
|
|
66
|
+
const pattern2 = withoutDate.match(/^claude-(\w+)-(\d+)-(\d+)$/);
|
|
67
|
+
if (pattern2) return {
|
|
68
|
+
family: pattern2[1],
|
|
69
|
+
version: `${pattern2[2]}.${pattern2[3]}`
|
|
70
|
+
};
|
|
71
|
+
const pattern3 = withoutDate.match(/^claude-(\d+)-(\d+)-(\w+)$/);
|
|
72
|
+
if (pattern3) return {
|
|
73
|
+
family: pattern3[3],
|
|
74
|
+
version: `${pattern3[1]}.${pattern3[2]}`
|
|
75
|
+
};
|
|
76
|
+
const pattern4 = withoutDate.match(/^claude-(\w+)-(\d+)$/);
|
|
77
|
+
if (pattern4) return {
|
|
78
|
+
family: pattern4[1],
|
|
79
|
+
version: pattern4[2]
|
|
80
|
+
};
|
|
81
|
+
const pattern5 = withoutDate.match(/^claude-(\d+)-(\w+)$/);
|
|
82
|
+
if (pattern5) return {
|
|
83
|
+
family: pattern5[2],
|
|
84
|
+
version: pattern5[1]
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
export { toClientModelId as i, getLatestModelForFamily as n, normalizeSdkModelId as r, findEndpointModel as t };
|