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.
@@ -0,0 +1,114 @@
1
+ //#region src/lib/tool-search.ts
2
+ const BRIDGE_TOOL_SEARCH_NAME = "mcp__tool_search__search";
3
+ const BRIDGE_TOOL_SEARCH_ALIASES = [
4
+ BRIDGE_TOOL_SEARCH_NAME,
5
+ "tool_search_search",
6
+ "mcp__plugin_tool-search_tool_search__search"
7
+ ];
8
+ const MCP_TOOL_SEARCH_SENTINEL_TYPE = "copilot_api_tool_search";
9
+ const alwaysLoadedToolNameSet = new Set([
10
+ "Agent",
11
+ "AskUserQuestion",
12
+ "Bash",
13
+ "Edit",
14
+ "EnterPlanMode",
15
+ "ExitPlanMode",
16
+ "Glob",
17
+ "Grep",
18
+ "Read",
19
+ "ReportFindings",
20
+ "Skill",
21
+ "TodoWrite",
22
+ "ToolSearch",
23
+ "WebFetch",
24
+ "Workflow",
25
+ "Write",
26
+ "apply_patch",
27
+ "bash",
28
+ "glob",
29
+ "grep",
30
+ "plan_exit",
31
+ "question",
32
+ "read",
33
+ "skill",
34
+ "task",
35
+ "todowrite",
36
+ "webfetch"
37
+ ]);
38
+ const bridgeToolSearchNameSet = new Set(BRIDGE_TOOL_SEARCH_ALIASES);
39
+ const isBridgeToolSearchName = (name) => bridgeToolSearchNameSet.has(name);
40
+ const isAlwaysLoadedToolName = (name) => alwaysLoadedToolNameSet.has(name);
41
+ const isDeferredToolName = (name) => !isBridgeToolSearchName(name) && !isAlwaysLoadedToolName(name);
42
+ const supportsResponsesToolSearchModel = (model) => {
43
+ const match = /^gpt-(\d+)(?:\.(\d+))?/iu.exec(model);
44
+ if (!match) return false;
45
+ const major = Number.parseInt(match[1], 10);
46
+ const minor = match[2] ? Number.parseInt(match[2], 10) : 0;
47
+ return major > 5 || major === 5 && minor >= 4;
48
+ };
49
+ const hasBridgeToolSearchTool = (tools) => Array.isArray(tools) && tools.some((tool) => isBridgeToolSearchName(tool.name));
50
+ const resolveBridgeToolSearchName = (tools) => {
51
+ if (!Array.isArray(tools)) return BRIDGE_TOOL_SEARCH_NAME;
52
+ return tools.find((tool) => isBridgeToolSearchName(tool.name))?.name ?? "mcp__tool_search__search";
53
+ };
54
+ const hasDeferredToolCandidate = (tools) => Array.isArray(tools) && tools.some((tool) => isDeferredToolName(tool.name));
55
+ const shouldEnableResponsesToolSearch = (params) => supportsResponsesToolSearchModel(params.model) && hasBridgeToolSearchTool(params.tools) && hasDeferredToolCandidate(params.tools);
56
+ const listDeferredToolNames = (tools) => [...new Set(tools.filter((tool) => isDeferredToolName(tool.name)).map((tool) => tool.name))];
57
+ const extractDeferredToolNamesSource = (record) => record.names ?? record.query ?? record.paths;
58
+ const parseDeferredToolNames = (names) => {
59
+ let rawNames = [];
60
+ if (typeof names === "string") rawNames = names.split(",");
61
+ else if (Array.isArray(names)) rawNames = names.flatMap((name) => typeof name === "string" ? name.split(",") : []);
62
+ return [...new Set(rawNames.map((name) => name.trim()).filter((name) => name.length > 0))];
63
+ };
64
+ const createMcpToolSearchSentinel = (names) => JSON.stringify({
65
+ type: MCP_TOOL_SEARCH_SENTINEL_TYPE,
66
+ names: parseDeferredToolNames(names)
67
+ });
68
+ const parseMcpToolSearchSentinel = (text) => {
69
+ try {
70
+ const parsed = JSON.parse(text);
71
+ if (!parsed || typeof parsed !== "object") return null;
72
+ const record = parsed;
73
+ if (record.type !== "copilot_api_tool_search") return null;
74
+ const names = parseDeferredToolNames(extractDeferredToolNamesSource(record));
75
+ if (names.length === 0) return null;
76
+ return {
77
+ type: MCP_TOOL_SEARCH_SENTINEL_TYPE,
78
+ names
79
+ };
80
+ } catch {
81
+ return null;
82
+ }
83
+ };
84
+ const normalizeToolSearchBridgeArguments = (argumentsValue) => {
85
+ if (typeof argumentsValue !== "string") {
86
+ const names = parseDeferredToolNames(extractDeferredToolNamesSource(argumentsValue));
87
+ return names.length > 0 ? { names } : {};
88
+ }
89
+ try {
90
+ const parsed = JSON.parse(argumentsValue);
91
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
92
+ const names = parseDeferredToolNames(extractDeferredToolNamesSource(parsed));
93
+ return names.length > 0 ? { names } : {};
94
+ }
95
+ } catch {}
96
+ const names = parseDeferredToolNames(argumentsValue);
97
+ return names.length > 0 ? { names } : {};
98
+ };
99
+ const formatToolSearchBridgeArguments = (argumentsValue) => {
100
+ const names = normalizeToolSearchBridgeArguments(argumentsValue).names;
101
+ if (!Array.isArray(names) || names.length === 0) return {};
102
+ return { names: names.join(",") };
103
+ };
104
+ const selectDeferredToolsByNames = (names, tools) => {
105
+ const requestedNames = parseDeferredToolNames(names);
106
+ if (requestedNames.length === 0) return [];
107
+ const deferredToolByName = new Map(tools.filter((tool) => isDeferredToolName(tool.name)).map((tool) => [tool.name, tool]));
108
+ return requestedNames.flatMap((name) => {
109
+ const tool = deferredToolByName.get(name);
110
+ return tool ? [tool] : [];
111
+ });
112
+ };
113
+ //#endregion
114
+ export { isDeferredToolName as a, parseMcpToolSearchSentinel as c, shouldEnableResponsesToolSearch as d, isBridgeToolSearchName as i, resolveBridgeToolSearchName as l, createMcpToolSearchSentinel as n, listDeferredToolNames as o, formatToolSearchBridgeArguments as r, normalizeToolSearchBridgeArguments as s, BRIDGE_TOOL_SEARCH_NAME as t, selectDeferredToolsByNames as u };
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "xiaodcs-copilot-api-edge",
4
+ "version": "2.3.9-edge.0",
5
+ "description": "XiaoDcs Edge build of copilot-api with the latest Responses recovery and Codex integrations.",
6
+ "keywords": [
7
+ "github-copilot",
8
+ "codex",
9
+ "ai-gateway",
10
+ "opencode",
11
+ "anthropic-compatible"
12
+ ],
13
+ "homepage": "https://www.npmjs.com/package/xiaodcs-copilot-api-edge",
14
+ "bugs": "https://github.com/caozhiyuan/copilot-api/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/XiaoDcs/copilot-api-private.git"
18
+ },
19
+ "license": "MIT",
20
+ "author": "caozhiyuan",
21
+ "type": "module",
22
+ "bin": {
23
+ "copilot-api-edge": "dist/main.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "pages"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "tsdown",
34
+ "build:desktop": "tsdown --config tsdown.desktop.config.ts",
35
+ "dev": "NODE_USE_SYSTEM_CA=1 bun run --watch ./src/main.ts",
36
+ "knip": "knip-bun",
37
+ "lint": "eslint --cache",
38
+ "lint:all": "eslint --cache .",
39
+ "prepack": "bun run build",
40
+ "prepare": "simple-git-hooks",
41
+ "release": "bumpp && bun publish --access public",
42
+ "start": "NODE_USE_SYSTEM_CA=1 NODE_ENV=production bun run ./src/main.ts",
43
+ "test:ci": "bash scripts/test-ci.sh",
44
+ "typecheck": "tsc"
45
+ },
46
+ "simple-git-hooks": {
47
+ "pre-commit": "bunx lint-staged"
48
+ },
49
+ "lint-staged": {
50
+ "*": "bun run lint --fix"
51
+ },
52
+ "overrides": {
53
+ "@hono/node-server": "^1.19.15",
54
+ "rolldown": "1.0.0-rc.18"
55
+ },
56
+ "dependencies": {
57
+ "@modelcontextprotocol/sdk": "^1.29.0",
58
+ "citty": "^0.1.6",
59
+ "clipboardy": "^5.0.0",
60
+ "consola": "^3.4.2",
61
+ "fetch-event-stream": "^0.1.5",
62
+ "fzstd": "^0.1.1",
63
+ "gpt-tokenizer": "^3.0.1",
64
+ "hono": "^4.13.2",
65
+ "proxy-from-env": "^1.1.0",
66
+ "srvx": "^0.11.15",
67
+ "tiny-invariant": "^1.3.3",
68
+ "undici": "^7.29.0",
69
+ "winreg": "^1.2.5",
70
+ "zod": "^4.1.11"
71
+ },
72
+ "devDependencies": {
73
+ "@eslint/js": "^9.37.0",
74
+ "@types/bun": "^1.2.23",
75
+ "@types/proxy-from-env": "^1.0.4",
76
+ "@types/winreg": "^1.2.36",
77
+ "bumpp": "^10.2.3",
78
+ "eslint": "^9.37.0",
79
+ "eslint-config-flat-gitignore": "^2.1.0",
80
+ "eslint-config-prettier": "^10.1.8",
81
+ "eslint-plugin-prettier": "^5.5.4",
82
+ "eslint-plugin-unused-imports": "^4.2.0",
83
+ "globals": "^16.3.0",
84
+ "knip": "^5.64.1",
85
+ "lint-staged": "^16.2.3",
86
+ "prettier": "^3.6.2",
87
+ "prettier-plugin-packagejson": "^2.5.19",
88
+ "simple-git-hooks": "^2.13.1",
89
+ "tsdown": "^0.15.6",
90
+ "typescript": "^5.9.3",
91
+ "typescript-eslint": "^8.41.0"
92
+ },
93
+ "engines": {
94
+ "node": ">=20"
95
+ }
96
+ }