@hsupu/copilot-api 0.7.3 → 0.7.4
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/README.md +1 -0
- package/dist/main.js +21 -100
- package/dist/main.js.map +1 -1
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -109,6 +109,7 @@ copilot-api start
|
|
|
109
109
|
| `--proxy-env` | Use proxy from environment | false |
|
|
110
110
|
| `--history` | Enable request history UI at `/history` | false |
|
|
111
111
|
| `--history-limit` | Max history entries in memory | 1000 |
|
|
112
|
+
| `--auto-compact` | Auto-compress context when exceeding limits | false |
|
|
112
113
|
|
|
113
114
|
## API Endpoints
|
|
114
115
|
|
package/dist/main.js
CHANGED
|
@@ -12,37 +12,12 @@ import { getProxyForUrl } from "proxy-from-env";
|
|
|
12
12
|
import { Agent, ProxyAgent, setGlobalDispatcher } from "undici";
|
|
13
13
|
import { execSync } from "node:child_process";
|
|
14
14
|
import process$1 from "node:process";
|
|
15
|
+
import pc from "picocolors";
|
|
15
16
|
import { Hono } from "hono";
|
|
16
17
|
import { cors } from "hono/cors";
|
|
17
18
|
import { streamSSE } from "hono/streaming";
|
|
18
19
|
import { events } from "fetch-event-stream";
|
|
19
20
|
|
|
20
|
-
//#region rolldown:runtime
|
|
21
|
-
var __create = Object.create;
|
|
22
|
-
var __defProp = Object.defineProperty;
|
|
23
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
24
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
25
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
26
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
27
|
-
var __commonJS = (cb, mod) => function() {
|
|
28
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
29
|
-
};
|
|
30
|
-
var __copyProps = (to, from, except, desc) => {
|
|
31
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
32
|
-
key = keys[i];
|
|
33
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
34
|
-
get: ((k) => from[k]).bind(null, key),
|
|
35
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return to;
|
|
39
|
-
};
|
|
40
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
41
|
-
value: mod,
|
|
42
|
-
enumerable: true
|
|
43
|
-
}) : target, mod));
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
21
|
//#region src/lib/paths.ts
|
|
47
22
|
const APP_DIR = path.join(os.homedir(), ".local", "share", "copilot-api");
|
|
48
23
|
const GITHUB_TOKEN_PATH = path.join(APP_DIR, "github_token");
|
|
@@ -151,9 +126,24 @@ function formatTokenLimitError(current, limit) {
|
|
|
151
126
|
}
|
|
152
127
|
};
|
|
153
128
|
}
|
|
129
|
+
/** Format Anthropic-compatible error for request too large (413) */
|
|
130
|
+
function formatRequestTooLargeError() {
|
|
131
|
+
return {
|
|
132
|
+
type: "error",
|
|
133
|
+
error: {
|
|
134
|
+
type: "invalid_request_error",
|
|
135
|
+
message: "Request body too large. The HTTP request exceeds the server's size limit. Try reducing the conversation history or removing large content like images."
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
154
139
|
async function forwardError(c, error) {
|
|
155
140
|
consola.error("Error occurred:", error);
|
|
156
141
|
if (error instanceof HTTPError) {
|
|
142
|
+
if (error.status === 413) {
|
|
143
|
+
const formattedError = formatRequestTooLargeError();
|
|
144
|
+
consola.debug("Returning formatted 413 error:", formattedError);
|
|
145
|
+
return c.json(formattedError, 413);
|
|
146
|
+
}
|
|
157
147
|
let errorJson;
|
|
158
148
|
try {
|
|
159
149
|
errorJson = JSON.parse(error.responseText);
|
|
@@ -828,7 +818,7 @@ function initProxyFromEnv() {
|
|
|
828
818
|
//#endregion
|
|
829
819
|
//#region src/lib/shell.ts
|
|
830
820
|
function getShell() {
|
|
831
|
-
const { platform, ppid, env
|
|
821
|
+
const { platform, ppid, env } = process$1;
|
|
832
822
|
if (platform === "win32") {
|
|
833
823
|
try {
|
|
834
824
|
const command = `wmic process get ParentProcessId,Name | findstr "${ppid}"`;
|
|
@@ -838,7 +828,7 @@ function getShell() {
|
|
|
838
828
|
}
|
|
839
829
|
return "cmd";
|
|
840
830
|
} else {
|
|
841
|
-
const shellPath = env
|
|
831
|
+
const shellPath = env.SHELL;
|
|
842
832
|
if (shellPath) {
|
|
843
833
|
if (shellPath.endsWith("zsh")) return "zsh";
|
|
844
834
|
if (shellPath.endsWith("fish")) return "fish";
|
|
@@ -878,78 +868,8 @@ function generateEnvScript(envVars, commandToRun = "") {
|
|
|
878
868
|
return commandBlock || commandToRun;
|
|
879
869
|
}
|
|
880
870
|
|
|
881
|
-
//#endregion
|
|
882
|
-
//#region node_modules/picocolors/picocolors.js
|
|
883
|
-
var require_picocolors = /* @__PURE__ */ __commonJS({ "node_modules/picocolors/picocolors.js": ((exports, module) => {
|
|
884
|
-
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
885
|
-
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
886
|
-
let formatter = (open, close, replace = open) => (input) => {
|
|
887
|
-
let string = "" + input, index = string.indexOf(close, open.length);
|
|
888
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
889
|
-
};
|
|
890
|
-
let replaceClose = (string, close, replace, index) => {
|
|
891
|
-
let result = "", cursor = 0;
|
|
892
|
-
do {
|
|
893
|
-
result += string.substring(cursor, index) + replace;
|
|
894
|
-
cursor = index + close.length;
|
|
895
|
-
index = string.indexOf(close, cursor);
|
|
896
|
-
} while (~index);
|
|
897
|
-
return result + string.substring(cursor);
|
|
898
|
-
};
|
|
899
|
-
let createColors = (enabled = isColorSupported) => {
|
|
900
|
-
let f = enabled ? formatter : () => String;
|
|
901
|
-
return {
|
|
902
|
-
isColorSupported: enabled,
|
|
903
|
-
reset: f("\x1B[0m", "\x1B[0m"),
|
|
904
|
-
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
905
|
-
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
906
|
-
italic: f("\x1B[3m", "\x1B[23m"),
|
|
907
|
-
underline: f("\x1B[4m", "\x1B[24m"),
|
|
908
|
-
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
909
|
-
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
910
|
-
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
911
|
-
black: f("\x1B[30m", "\x1B[39m"),
|
|
912
|
-
red: f("\x1B[31m", "\x1B[39m"),
|
|
913
|
-
green: f("\x1B[32m", "\x1B[39m"),
|
|
914
|
-
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
915
|
-
blue: f("\x1B[34m", "\x1B[39m"),
|
|
916
|
-
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
917
|
-
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
918
|
-
white: f("\x1B[37m", "\x1B[39m"),
|
|
919
|
-
gray: f("\x1B[90m", "\x1B[39m"),
|
|
920
|
-
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
921
|
-
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
922
|
-
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
923
|
-
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
924
|
-
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
925
|
-
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
926
|
-
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
927
|
-
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
928
|
-
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
929
|
-
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
930
|
-
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
931
|
-
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
932
|
-
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
933
|
-
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
934
|
-
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
935
|
-
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
936
|
-
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
937
|
-
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
938
|
-
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
939
|
-
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
940
|
-
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
941
|
-
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
942
|
-
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
943
|
-
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
944
|
-
};
|
|
945
|
-
};
|
|
946
|
-
module.exports = createColors();
|
|
947
|
-
module.exports.createColors = createColors;
|
|
948
|
-
}) });
|
|
949
|
-
|
|
950
871
|
//#endregion
|
|
951
872
|
//#region src/lib/tui/console-renderer.ts
|
|
952
|
-
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
953
873
|
const CLEAR_LINE = "\x1B[2K\r";
|
|
954
874
|
function formatTime(date = /* @__PURE__ */ new Date()) {
|
|
955
875
|
const h = String(date.getHours()).padStart(2, "0");
|
|
@@ -999,7 +919,7 @@ var ConsoleRenderer = class {
|
|
|
999
919
|
const activeCount = this.activeRequests.size;
|
|
1000
920
|
if (activeCount === 0) return "";
|
|
1001
921
|
const plural = activeCount === 1 ? "" : "s";
|
|
1002
|
-
return
|
|
922
|
+
return pc.dim(`[....] ${activeCount} request${plural} in progress...`);
|
|
1003
923
|
}
|
|
1004
924
|
/**
|
|
1005
925
|
* Render footer in-place on current line (no newline)
|
|
@@ -1033,7 +953,7 @@ var ConsoleRenderer = class {
|
|
|
1033
953
|
*/
|
|
1034
954
|
printLog(message, isGray = false) {
|
|
1035
955
|
this.clearFooterForLog();
|
|
1036
|
-
if (isGray) consola.log(
|
|
956
|
+
if (isGray) consola.log(pc.dim(message));
|
|
1037
957
|
else consola.log(message);
|
|
1038
958
|
this.renderFooter();
|
|
1039
959
|
}
|
|
@@ -4389,6 +4309,7 @@ const start = defineCommand({
|
|
|
4389
4309
|
|
|
4390
4310
|
//#endregion
|
|
4391
4311
|
//#region src/main.ts
|
|
4312
|
+
consola.options.formatOptions.date = false;
|
|
4392
4313
|
const main = defineCommand({
|
|
4393
4314
|
meta: {
|
|
4394
4315
|
name: "copilot-api",
|