@jeffreycao/copilot-api 1.3.8 → 1.4.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/{auth-DteTbqnM.js → auth-BF_z8R4h.js} +3 -3
- package/dist/{auth-DteTbqnM.js.map → auth-BF_z8R4h.js.map} +1 -1
- package/dist/{check-usage-Z8fnzZQt.js → check-usage-Bg8l21pI.js} +4 -4
- package/dist/{check-usage-Z8fnzZQt.js.map → check-usage-Bg8l21pI.js.map} +1 -1
- package/dist/{get-copilot-usage-CuVET98U.js → get-copilot-usage-LteGnMt-.js} +2 -2
- package/dist/{get-copilot-usage-CuVET98U.js.map → get-copilot-usage-LteGnMt-.js.map} +1 -1
- package/dist/main.js +3 -3
- package/dist/{server-Cprgkxd_.js → server-BrAyTHBe.js} +17 -20
- package/dist/server-BrAyTHBe.js.map +1 -0
- package/dist/{start-DyiU_Ikg.js → start-IV3N7KCo.js} +5 -4
- package/dist/start-IV3N7KCo.js.map +1 -0
- package/dist/{token-8AyBHdsS.js → token-DDRrlAWy.js} +2 -2
- package/dist/{token-8AyBHdsS.js.map → token-DDRrlAWy.js.map} +1 -1
- package/dist/{utils-DKqD66k9.js → utils-DVmO1EMi.js} +33 -9
- package/dist/utils-DVmO1EMi.js.map +1 -0
- package/package.json +1 -1
- package/dist/server-Cprgkxd_.js.map +0 -1
- package/dist/start-DyiU_Ikg.js.map +0 -1
- package/dist/utils-DKqD66k9.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PATHS, ensurePaths } from "./paths-Cla6y5eD.js";
|
|
2
|
-
import { state } from "./utils-
|
|
3
|
-
import { setupGitHubToken } from "./token-
|
|
2
|
+
import { state } from "./utils-DVmO1EMi.js";
|
|
3
|
+
import { setupGitHubToken } from "./token-DDRrlAWy.js";
|
|
4
4
|
import { defineCommand } from "citty";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
|
|
@@ -43,4 +43,4 @@ const auth = defineCommand({
|
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
45
|
export { auth };
|
|
46
|
-
//# sourceMappingURL=auth-
|
|
46
|
+
//# sourceMappingURL=auth-BF_z8R4h.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-
|
|
1
|
+
{"version":3,"file":"auth-BF_z8R4h.js","names":[],"sources":["../src/auth.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { defineCommand } from \"citty\"\nimport consola from \"consola\"\n\nimport { PATHS, ensurePaths } from \"./lib/paths\"\nimport { state } from \"./lib/state\"\nimport { setupGitHubToken } from \"./lib/token\"\n\ninterface RunAuthOptions {\n verbose: boolean\n showToken: boolean\n}\n\nexport async function runAuth(options: RunAuthOptions): Promise<void> {\n if (options.verbose) {\n consola.level = 5\n consola.info(\"Verbose logging enabled\")\n }\n\n state.showToken = options.showToken\n\n await ensurePaths()\n await setupGitHubToken({ force: true })\n consola.success(\"GitHub token written to\", PATHS.GITHUB_TOKEN_PATH)\n}\n\nexport const auth = defineCommand({\n meta: {\n name: \"auth\",\n description: \"Run GitHub auth flow without running the server\",\n },\n args: {\n verbose: {\n alias: \"v\",\n type: \"boolean\",\n default: false,\n description: \"Enable verbose logging\",\n },\n \"show-token\": {\n type: \"boolean\",\n default: false,\n description: \"Show GitHub token on auth\",\n },\n },\n run({ args }) {\n return runAuth({\n verbose: args.verbose,\n showToken: args[\"show-token\"],\n })\n },\n})\n"],"mappings":";;;;;;;AAcA,eAAsB,QAAQ,SAAwC;AACpE,KAAI,QAAQ,SAAS;AACnB,UAAQ,QAAQ;AAChB,UAAQ,KAAK,0BAA0B;;AAGzC,OAAM,YAAY,QAAQ;AAE1B,OAAM,aAAa;AACnB,OAAM,iBAAiB,EAAE,OAAO,MAAM,CAAC;AACvC,SAAQ,QAAQ,2BAA2B,MAAM,kBAAkB;;AAGrE,MAAa,OAAO,cAAc;CAChC,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM;EACJ,SAAS;GACP,OAAO;GACP,MAAM;GACN,SAAS;GACT,aAAa;GACd;EACD,cAAc;GACZ,MAAM;GACN,SAAS;GACT,aAAa;GACd;EACF;CACD,IAAI,EAAE,QAAQ;AACZ,SAAO,QAAQ;GACb,SAAS,KAAK;GACd,WAAW,KAAK;GACjB,CAAC;;CAEL,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ensurePaths } from "./paths-Cla6y5eD.js";
|
|
2
|
-
import "./utils-
|
|
3
|
-
import { setupGitHubToken } from "./token-
|
|
4
|
-
import { getCopilotUsage } from "./get-copilot-usage-
|
|
2
|
+
import "./utils-DVmO1EMi.js";
|
|
3
|
+
import { setupGitHubToken } from "./token-DDRrlAWy.js";
|
|
4
|
+
import { getCopilotUsage } from "./get-copilot-usage-LteGnMt-.js";
|
|
5
5
|
import { defineCommand } from "citty";
|
|
6
6
|
import consola from "consola";
|
|
7
7
|
|
|
@@ -42,4 +42,4 @@ const checkUsage = defineCommand({
|
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
44
|
export { checkUsage };
|
|
45
|
-
//# sourceMappingURL=check-usage-
|
|
45
|
+
//# sourceMappingURL=check-usage-Bg8l21pI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-usage-
|
|
1
|
+
{"version":3,"file":"check-usage-Bg8l21pI.js","names":[],"sources":["../src/check-usage.ts"],"sourcesContent":["import { defineCommand } from \"citty\"\nimport consola from \"consola\"\n\nimport { ensurePaths } from \"./lib/paths\"\nimport { setupGitHubToken } from \"./lib/token\"\nimport {\n getCopilotUsage,\n type QuotaDetail,\n} from \"./services/github/get-copilot-usage\"\n\nexport const checkUsage = defineCommand({\n meta: {\n name: \"check-usage\",\n description: \"Show current GitHub Copilot usage/quota information\",\n },\n async run() {\n await ensurePaths()\n await setupGitHubToken()\n try {\n const usage = await getCopilotUsage()\n const premium = usage.quota_snapshots.premium_interactions\n const premiumTotal = premium.entitlement\n const premiumUsed = premiumTotal - premium.remaining\n const premiumPercentUsed =\n premiumTotal > 0 ? (premiumUsed / premiumTotal) * 100 : 0\n const premiumPercentRemaining = premium.percent_remaining\n\n // Helper to summarize a quota snapshot\n function summarizeQuota(name: string, snap: QuotaDetail | undefined) {\n if (!snap) return `${name}: N/A`\n const total = snap.entitlement\n const used = total - snap.remaining\n const percentUsed = total > 0 ? (used / total) * 100 : 0\n const percentRemaining = snap.percent_remaining\n return `${name}: ${used}/${total} used (${percentUsed.toFixed(1)}% used, ${percentRemaining.toFixed(1)}% remaining)`\n }\n\n const premiumLine = `Premium: ${premiumUsed}/${premiumTotal} used (${premiumPercentUsed.toFixed(1)}% used, ${premiumPercentRemaining.toFixed(1)}% remaining)`\n const chatLine = summarizeQuota(\"Chat\", usage.quota_snapshots.chat)\n const completionsLine = summarizeQuota(\n \"Completions\",\n usage.quota_snapshots.completions,\n )\n\n consola.box(\n `Copilot Usage (plan: ${usage.copilot_plan})\\n`\n + `Quota resets: ${usage.quota_reset_date}\\n`\n + `\\nQuotas:\\n`\n + ` ${premiumLine}\\n`\n + ` ${chatLine}\\n`\n + ` ${completionsLine}`,\n )\n } catch (err) {\n consola.error(\"Failed to fetch Copilot usage:\", err)\n process.exit(1)\n }\n },\n})\n"],"mappings":";;;;;;;;AAUA,MAAa,aAAa,cAAc;CACtC,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM,MAAM;AACV,QAAM,aAAa;AACnB,QAAM,kBAAkB;AACxB,MAAI;GACF,MAAM,QAAQ,MAAM,iBAAiB;GACrC,MAAM,UAAU,MAAM,gBAAgB;GACtC,MAAM,eAAe,QAAQ;GAC7B,MAAM,cAAc,eAAe,QAAQ;GAC3C,MAAM,qBACJ,eAAe,IAAK,cAAc,eAAgB,MAAM;GAC1D,MAAM,0BAA0B,QAAQ;GAGxC,SAAS,eAAe,MAAc,MAA+B;AACnE,QAAI,CAAC,KAAM,QAAO,GAAG,KAAK;IAC1B,MAAM,QAAQ,KAAK;IACnB,MAAM,OAAO,QAAQ,KAAK;IAC1B,MAAM,cAAc,QAAQ,IAAK,OAAO,QAAS,MAAM;IACvD,MAAM,mBAAmB,KAAK;AAC9B,WAAO,GAAG,KAAK,IAAI,KAAK,GAAG,MAAM,SAAS,YAAY,QAAQ,EAAE,CAAC,UAAU,iBAAiB,QAAQ,EAAE,CAAC;;GAGzG,MAAM,cAAc,YAAY,YAAY,GAAG,aAAa,SAAS,mBAAmB,QAAQ,EAAE,CAAC,UAAU,wBAAwB,QAAQ,EAAE,CAAC;GAChJ,MAAM,WAAW,eAAe,QAAQ,MAAM,gBAAgB,KAAK;GACnE,MAAM,kBAAkB,eACtB,eACA,MAAM,gBAAgB,YACvB;AAED,WAAQ,IACN,wBAAwB,MAAM,aAAa,mBACtB,MAAM,iBAAiB,iBAEnC,YAAY,MACZ,SAAS,MACT,kBACV;WACM,KAAK;AACZ,WAAQ,MAAM,kCAAkC,IAAI;AACpD,WAAQ,KAAK,EAAE;;;CAGpB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTTPError, getGitHubApiBaseUrl, githubHeaders, state } from "./utils-
|
|
1
|
+
import { HTTPError, getGitHubApiBaseUrl, githubHeaders, state } from "./utils-DVmO1EMi.js";
|
|
2
2
|
|
|
3
3
|
//#region src/services/github/get-copilot-usage.ts
|
|
4
4
|
const getCopilotUsage = async () => {
|
|
@@ -9,4 +9,4 @@ const getCopilotUsage = async () => {
|
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
export { getCopilotUsage };
|
|
12
|
-
//# sourceMappingURL=get-copilot-usage-
|
|
12
|
+
//# sourceMappingURL=get-copilot-usage-LteGnMt-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-copilot-usage-
|
|
1
|
+
{"version":3,"file":"get-copilot-usage-LteGnMt-.js","names":[],"sources":["../src/services/github/get-copilot-usage.ts"],"sourcesContent":["import { getGitHubApiBaseUrl, githubHeaders } from \"~/lib/api-config\"\nimport { HTTPError } from \"~/lib/error\"\nimport { state } from \"~/lib/state\"\n\nexport const getCopilotUsage = async (): Promise<CopilotUsageResponse> => {\n const response = await fetch(\n `${getGitHubApiBaseUrl()}/copilot_internal/user`,\n {\n headers: githubHeaders(state),\n },\n )\n\n if (!response.ok) {\n throw new HTTPError(\"Failed to get Copilot usage\", response)\n }\n\n return (await response.json()) as CopilotUsageResponse\n}\n\nexport interface QuotaDetail {\n entitlement: number\n overage_count: number\n overage_permitted: boolean\n percent_remaining: number\n quota_id: string\n quota_remaining: number\n remaining: number\n unlimited: boolean\n}\n\ninterface QuotaSnapshots {\n chat: QuotaDetail\n completions: QuotaDetail\n premium_interactions: QuotaDetail\n}\n\ninterface CopilotUsageResponse {\n access_type_sku: string\n analytics_tracking_id: string\n assigned_date: string\n can_signup_for_limited: boolean\n chat_enabled: boolean\n copilot_plan: string\n organization_login_list: Array<unknown>\n organization_list: Array<unknown>\n quota_reset_date: string\n quota_snapshots: QuotaSnapshots\n}\n"],"mappings":";;;AAIA,MAAa,kBAAkB,YAA2C;CACxE,MAAM,WAAW,MAAM,MACrB,GAAG,qBAAqB,CAAC,yBACzB,EACE,SAAS,cAAc,MAAM,EAC9B,CACF;AAED,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,UAAU,+BAA+B,SAAS;AAG9D,QAAQ,MAAM,SAAS,MAAM"}
|
package/dist/main.js
CHANGED
|
@@ -20,10 +20,10 @@ const args = parseArgs(process.argv, cliArgs);
|
|
|
20
20
|
if (typeof args["api-home"] === "string") process.env.COPILOT_API_HOME = args["api-home"];
|
|
21
21
|
if (typeof args["oauth-app"] === "string") process.env.COPILOT_API_OAUTH_APP = args["oauth-app"];
|
|
22
22
|
if (typeof args["enterprise-url"] === "string") process.env.COPILOT_API_ENTERPRISE_URL = args["enterprise-url"];
|
|
23
|
-
const { auth } = await import("./auth-
|
|
24
|
-
const { checkUsage } = await import("./check-usage-
|
|
23
|
+
const { auth } = await import("./auth-BF_z8R4h.js");
|
|
24
|
+
const { checkUsage } = await import("./check-usage-Bg8l21pI.js");
|
|
25
25
|
const { debug } = await import("./debug-Dx1S6uWG.js");
|
|
26
|
-
const { start } = await import("./start-
|
|
26
|
+
const { start } = await import("./start-IV3N7KCo.js");
|
|
27
27
|
const main = defineCommand({
|
|
28
28
|
meta: {
|
|
29
29
|
name: "copilot-api",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PATHS } from "./paths-Cla6y5eD.js";
|
|
2
|
-
import { HTTPError, cacheModels, copilotBaseUrl, copilotHeaders, forwardError, generateRequestIdFromPayload, getRootSessionId, getUUID, isNullish, prepareForCompact, prepareInteractionHeaders, sleep, state } from "./utils-
|
|
3
|
-
import { getCopilotUsage } from "./get-copilot-usage-
|
|
2
|
+
import { HTTPError, cacheModels, copilotBaseUrl, copilotHeaders, forwardError, generateRequestIdFromPayload, getRootSessionId, getUUID, isNullish, parseUserIdMetadata, prepareForCompact, prepareInteractionHeaders, sleep, state } from "./utils-DVmO1EMi.js";
|
|
3
|
+
import { getCopilotUsage } from "./get-copilot-usage-LteGnMt-.js";
|
|
4
4
|
import { getConfig, getExtraPromptForModel, getProviderConfig, getReasoningEffortForModel, getSmallModel, isMessagesApiEnabled, isResponsesApiContextManagementModel } from "./config-DIqcOsnZ.js";
|
|
5
5
|
import consola from "consola";
|
|
6
6
|
import path from "node:path";
|
|
@@ -759,10 +759,21 @@ function translateAnthropicToolsToOpenAI(anthropicTools) {
|
|
|
759
759
|
function: {
|
|
760
760
|
name: tool.name,
|
|
761
761
|
description: tool.description,
|
|
762
|
-
parameters: tool.input_schema
|
|
762
|
+
parameters: normalizeToolSchema(tool.input_schema)
|
|
763
763
|
}
|
|
764
764
|
}));
|
|
765
765
|
}
|
|
766
|
+
/**
|
|
767
|
+
* Ensures `type: "object"` schema has a `properties` field.
|
|
768
|
+
* OpenAI's API rejects object schemas without it.
|
|
769
|
+
*/
|
|
770
|
+
const normalizeToolSchema = (schema) => {
|
|
771
|
+
if (schema.type === "object" && !schema.properties) return {
|
|
772
|
+
...schema,
|
|
773
|
+
properties: {}
|
|
774
|
+
};
|
|
775
|
+
return schema;
|
|
776
|
+
};
|
|
766
777
|
function translateAnthropicToolChoiceToOpenAI(anthropicToolChoice) {
|
|
767
778
|
if (!anthropicToolChoice) return;
|
|
768
779
|
switch (anthropicToolChoice.type) {
|
|
@@ -911,7 +922,7 @@ const translateAnthropicMessagesToResponsesPayload = (payload) => {
|
|
|
911
922
|
for (const message of payload.messages) input.push(...translateMessage(message, payload.model, applyPhase));
|
|
912
923
|
const translatedTools = convertAnthropicTools(payload.tools);
|
|
913
924
|
const toolChoice = convertAnthropicToolChoice(payload.tool_choice);
|
|
914
|
-
const { safetyIdentifier, promptCacheKey } =
|
|
925
|
+
const { safetyIdentifier, sessionId: promptCacheKey } = parseUserIdMetadata(payload.metadata?.user_id);
|
|
915
926
|
return {
|
|
916
927
|
model: payload.model,
|
|
917
928
|
input,
|
|
@@ -1124,7 +1135,7 @@ const convertAnthropicTools = (tools) => {
|
|
|
1124
1135
|
return tools.map((tool) => ({
|
|
1125
1136
|
type: "function",
|
|
1126
1137
|
name: tool.name,
|
|
1127
|
-
parameters: tool.input_schema,
|
|
1138
|
+
parameters: normalizeToolSchema(tool.input_schema),
|
|
1128
1139
|
strict: false,
|
|
1129
1140
|
...tool.description ? { description: tool.description } : {}
|
|
1130
1141
|
}));
|
|
@@ -1303,20 +1314,6 @@ const mapResponsesUsage = (response) => {
|
|
|
1303
1314
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
1304
1315
|
const isResponseOutputText = (block) => isRecord(block) && "type" in block && block.type === "output_text";
|
|
1305
1316
|
const isResponseOutputRefusal = (block) => isRecord(block) && "type" in block && block.type === "refusal";
|
|
1306
|
-
const parseUserId = (userId) => {
|
|
1307
|
-
if (!userId || typeof userId !== "string") return {
|
|
1308
|
-
safetyIdentifier: null,
|
|
1309
|
-
promptCacheKey: null
|
|
1310
|
-
};
|
|
1311
|
-
const userMatch = userId.match(/user_([^_]+)_account/);
|
|
1312
|
-
const safetyIdentifier = userMatch ? userMatch[1] : null;
|
|
1313
|
-
const sessionMatch = userId.match(/_session_(.+)$/);
|
|
1314
|
-
const promptCacheKey = sessionMatch ? sessionMatch[1] : null;
|
|
1315
|
-
return {
|
|
1316
|
-
safetyIdentifier,
|
|
1317
|
-
promptCacheKey
|
|
1318
|
-
};
|
|
1319
|
-
};
|
|
1320
1317
|
const convertToolResultContent = (content) => {
|
|
1321
1318
|
if (typeof content === "string") return content;
|
|
1322
1319
|
if (Array.isArray(content)) {
|
|
@@ -2880,4 +2877,4 @@ server.route("/:provider/v1/models", providerModelRoutes);
|
|
|
2880
2877
|
|
|
2881
2878
|
//#endregion
|
|
2882
2879
|
export { server };
|
|
2883
|
-
//# sourceMappingURL=server-
|
|
2880
|
+
//# sourceMappingURL=server-BrAyTHBe.js.map
|