dsh-github-copilot 0.4.0-alpha.45 → 0.4.0-alpha.48
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/CHANGELOG.md +16 -0
- package/README.md +12 -8
- package/README.zh.md +12 -8
- package/deployment-baseline.json +1 -1
- package/docs/automatic-model-routing.md +2 -0
- package/docs/copilot-usage.md +2 -0
- package/lib/client.js +16 -9
- package/lib/client.js.map +1 -1
- package/lib/index.js +68 -23
- package/lib/remote.js +1 -0
- package/lib/types/copilot-usage-remote.d.ts +1 -0
- package/lib/types/copilot-usage-types.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1293,6 +1293,14 @@ const REFRESH_INTERVAL_MS = 1e4;
|
|
|
1293
1293
|
const FAILURE_COOLDOWN_MS = 3e4;
|
|
1294
1294
|
const TIMEOUT_MS = 1e4;
|
|
1295
1295
|
const MAX_BODY_BYTES = 262144;
|
|
1296
|
+
const CERTIFICATE_FAILURES = /* @__PURE__ */ new Set([
|
|
1297
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
1298
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
1299
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
1300
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
1301
|
+
"CERT_HAS_EXPIRED",
|
|
1302
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
1303
|
+
]);
|
|
1296
1304
|
var UsageFailure = class extends Error {
|
|
1297
1305
|
diagnostic;
|
|
1298
1306
|
constructor(diagnostic) {
|
|
@@ -1303,6 +1311,11 @@ var UsageFailure = class extends Error {
|
|
|
1303
1311
|
function failure$3(diagnostic) {
|
|
1304
1312
|
throw new UsageFailure(diagnostic);
|
|
1305
1313
|
}
|
|
1314
|
+
function certificateFailure(error) {
|
|
1315
|
+
if (!(error instanceof TypeError) || !("cause" in error)) return false;
|
|
1316
|
+
const cause = error.cause;
|
|
1317
|
+
return typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" && CERTIFICATE_FAILURES.has(cause.code);
|
|
1318
|
+
}
|
|
1306
1319
|
async function readBody(response, signal) {
|
|
1307
1320
|
const length = response.headers.get("content-length");
|
|
1308
1321
|
if (length !== null && (!/^\d+$/u.test(length) || Number(length) > MAX_BODY_BYTES)) {
|
|
@@ -1453,17 +1466,23 @@ var CopilotUsageSource = class {
|
|
|
1453
1466
|
}
|
|
1454
1467
|
}
|
|
1455
1468
|
async fetchQuota(auth, abort) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1469
|
+
let response;
|
|
1470
|
+
try {
|
|
1471
|
+
response = await this.fetcher(COPILOT_USAGE_ENDPOINT, {
|
|
1472
|
+
method: "GET",
|
|
1473
|
+
redirect: "error",
|
|
1474
|
+
signal: abort.signal,
|
|
1475
|
+
cache: "no-store",
|
|
1476
|
+
headers: {
|
|
1477
|
+
Authorization: `token ${auth.grant.refresh}`,
|
|
1478
|
+
Accept: "application/json",
|
|
1479
|
+
"X-GitHub-Api-Version": "2025-04-01"
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
} catch (error) {
|
|
1483
|
+
if (certificateFailure(error)) failure$3("COPILOT_USAGE_TLS");
|
|
1484
|
+
throw error;
|
|
1485
|
+
}
|
|
1467
1486
|
if (response.redirected || response.status >= 300 && response.status < 400) {
|
|
1468
1487
|
response.body?.cancel().catch(() => void 0);
|
|
1469
1488
|
failure$3("COPILOT_USAGE_REDIRECT");
|
|
@@ -1516,6 +1535,7 @@ var CopilotUsageSource = class {
|
|
|
1516
1535
|
}
|
|
1517
1536
|
const staleAllowed = [
|
|
1518
1537
|
"COPILOT_USAGE_NETWORK",
|
|
1538
|
+
"COPILOT_USAGE_TLS",
|
|
1519
1539
|
"COPILOT_USAGE_TIMEOUT",
|
|
1520
1540
|
"COPILOT_USAGE_HTTP_ERROR",
|
|
1521
1541
|
"COPILOT_USAGE_RATE_LIMITED"
|
|
@@ -1602,7 +1622,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1602
1622
|
//#endregion
|
|
1603
1623
|
//#region package.json
|
|
1604
1624
|
var name$1 = "dsh-github-copilot";
|
|
1605
|
-
var version = "0.4.0-alpha.
|
|
1625
|
+
var version = "0.4.0-alpha.48";
|
|
1606
1626
|
//#endregion
|
|
1607
1627
|
//#region lib/types/probe.js
|
|
1608
1628
|
/**
|
|
@@ -6179,16 +6199,12 @@ async function decide(dependencies, signal, messages) {
|
|
|
6179
6199
|
function record(value) {
|
|
6180
6200
|
return typeof value === "object" && value !== null;
|
|
6181
6201
|
}
|
|
6182
|
-
function
|
|
6202
|
+
function pendingAuto(ctx, agent) {
|
|
6183
6203
|
const candidate = ctx.get("sessionProjections");
|
|
6184
6204
|
if (!record(candidate) || typeof candidate.stateOf !== "function") return false;
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
return state.pending.provider === "github-copilot-preview" && state.pending.model === "auto";
|
|
6189
|
-
} catch {
|
|
6190
|
-
return false;
|
|
6191
|
-
}
|
|
6205
|
+
const state = candidate.stateOf(agent.session, "modelSelection");
|
|
6206
|
+
if (!record(state)) return false;
|
|
6207
|
+
return record(state.pending) && state.pending.provider === "github-copilot-preview" && state.pending.model === "auto";
|
|
6192
6208
|
}
|
|
6193
6209
|
function modelSelectionNotice(value) {
|
|
6194
6210
|
return record(value) && record(value.source) && value.source.kind === "model-selection";
|
|
@@ -6224,14 +6240,26 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6224
6240
|
const activeDisposers = /* @__PURE__ */ new Set();
|
|
6225
6241
|
const installAgent = (agent) => {
|
|
6226
6242
|
if (agentDisposers.has(agent)) return;
|
|
6227
|
-
const
|
|
6243
|
+
const removeAssembly = agent.ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
6244
|
+
const assembled = await next();
|
|
6245
|
+
if (!pendingAuto(ctx, agent)) return assembled;
|
|
6246
|
+
return {
|
|
6247
|
+
...assembled,
|
|
6248
|
+
variables: {
|
|
6249
|
+
...assembled.variables,
|
|
6250
|
+
provider: GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
|
|
6251
|
+
model: GITHUB_COPILOT_AUTO_MODEL_ID
|
|
6252
|
+
}
|
|
6253
|
+
};
|
|
6254
|
+
}, { prepend: true });
|
|
6255
|
+
const removePreStep = agent.ctx.on("agent/pre-step", async ({ messages, turn, step, signal }, next) => {
|
|
6228
6256
|
const result = await next();
|
|
6229
6257
|
const entered = result.kind === "enter" ? result.messages : messages;
|
|
6230
6258
|
captured.set(agent, {
|
|
6231
6259
|
turn,
|
|
6232
6260
|
messages: entered
|
|
6233
6261
|
});
|
|
6234
|
-
if (result.kind !== "enter" || signal.aborted || !
|
|
6262
|
+
if (result.kind !== "enter" || signal.aborted || !pendingAuto(ctx, agent)) return result;
|
|
6235
6263
|
let state = routed.get(agent);
|
|
6236
6264
|
if (state?.turn !== turn) {
|
|
6237
6265
|
state = {
|
|
@@ -6251,6 +6279,10 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6251
6279
|
messages: [...filtered, notice]
|
|
6252
6280
|
};
|
|
6253
6281
|
}, { prepend: true });
|
|
6282
|
+
const dispose = () => {
|
|
6283
|
+
removeAssembly();
|
|
6284
|
+
removePreStep();
|
|
6285
|
+
};
|
|
6254
6286
|
agentDisposers.set(agent, dispose);
|
|
6255
6287
|
activeDisposers.add(dispose);
|
|
6256
6288
|
};
|
|
@@ -6267,7 +6299,12 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6267
6299
|
});
|
|
6268
6300
|
const removeRequest = ctx.on("agent/request", async ({ agent, turn, step, signal }, next) => {
|
|
6269
6301
|
const resolved = await next();
|
|
6270
|
-
|
|
6302
|
+
const virtual = resolved.provider === "github-copilot-preview" && resolved.model === "auto";
|
|
6303
|
+
if (!virtual && !pendingAuto(ctx, agent)) {
|
|
6304
|
+
routed.delete(agent);
|
|
6305
|
+
return resolved;
|
|
6306
|
+
}
|
|
6307
|
+
if (resolved.provider !== "github-copilot-preview") {
|
|
6271
6308
|
routed.delete(agent);
|
|
6272
6309
|
return resolved;
|
|
6273
6310
|
}
|
|
@@ -6283,6 +6320,14 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6283
6320
|
routed.set(agent, state);
|
|
6284
6321
|
}
|
|
6285
6322
|
if (!state.recorded) {
|
|
6323
|
+
const projections = ctx.get("sessionProjections");
|
|
6324
|
+
if (virtual && record(projections) && typeof projections.stateOf === "function") {
|
|
6325
|
+
const selection = projections.stateOf(agent.session, "modelSelection");
|
|
6326
|
+
if (record(selection) && selection.pending === null && agent.session.requestHeader() === void 0) Reflect.apply(agent.session.append, agent.session, ["model/selection", {
|
|
6327
|
+
provider: GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
|
|
6328
|
+
model: GITHUB_COPILOT_AUTO_MODEL_ID
|
|
6329
|
+
}]);
|
|
6330
|
+
}
|
|
6286
6331
|
appendAutoModelDecision(agent, {
|
|
6287
6332
|
turn,
|
|
6288
6333
|
step,
|
package/lib/remote.js
CHANGED
|
@@ -118,6 +118,7 @@ const COPILOT_USAGE_DIAGNOSTICS = [
|
|
|
118
118
|
"COPILOT_USAGE_POOLED_EXHAUSTED",
|
|
119
119
|
"COPILOT_USAGE_NO_ALLOCATION",
|
|
120
120
|
"COPILOT_USAGE_NETWORK",
|
|
121
|
+
"COPILOT_USAGE_TLS",
|
|
121
122
|
"COPILOT_USAGE_TIMEOUT",
|
|
122
123
|
"COPILOT_USAGE_BODY_TOO_LARGE",
|
|
123
124
|
"COPILOT_USAGE_REDIRECT",
|
|
@@ -47,6 +47,7 @@ export declare const CopilotUsageViewSchema: z.ZodObject<{
|
|
|
47
47
|
COPILOT_USAGE_POOLED_EXHAUSTED: "COPILOT_USAGE_POOLED_EXHAUSTED";
|
|
48
48
|
COPILOT_USAGE_NO_ALLOCATION: "COPILOT_USAGE_NO_ALLOCATION";
|
|
49
49
|
COPILOT_USAGE_NETWORK: "COPILOT_USAGE_NETWORK";
|
|
50
|
+
COPILOT_USAGE_TLS: "COPILOT_USAGE_TLS";
|
|
50
51
|
COPILOT_USAGE_TIMEOUT: "COPILOT_USAGE_TIMEOUT";
|
|
51
52
|
COPILOT_USAGE_BODY_TOO_LARGE: "COPILOT_USAGE_BODY_TOO_LARGE";
|
|
52
53
|
COPILOT_USAGE_REDIRECT: "COPILOT_USAGE_REDIRECT";
|
|
@@ -14,6 +14,6 @@ export interface CopilotUsageView {
|
|
|
14
14
|
}
|
|
15
15
|
export declare const COPILOT_USAGE_MAX_AMOUNT = 1000000000000;
|
|
16
16
|
export declare const COPILOT_USAGE_MAX_TIMESTAMP = 253402300799999;
|
|
17
|
-
export declare const COPILOT_USAGE_DIAGNOSTICS: readonly ["COPILOT_USAGE_SIGNED_OUT", "COPILOT_USAGE_INVALID_GRANT", "COPILOT_USAGE_CREDENTIALS_UNAVAILABLE", "COPILOT_USAGE_ENTERPRISE_UNSUPPORTED", "COPILOT_USAGE_ACCOUNT_CHANGED", "COPILOT_USAGE_DISPOSED", "COPILOT_USAGE_BILLING_UNKNOWN", "COPILOT_USAGE_SNAPSHOT_MISSING", "COPILOT_USAGE_INVALID_RESPONSE", "COPILOT_USAGE_POOLED_UNAVAILABLE", "COPILOT_USAGE_POOLED_EXHAUSTED", "COPILOT_USAGE_NO_ALLOCATION", "COPILOT_USAGE_NETWORK", "COPILOT_USAGE_TIMEOUT", "COPILOT_USAGE_BODY_TOO_LARGE", "COPILOT_USAGE_REDIRECT", "COPILOT_USAGE_AUTH_REJECTED", "COPILOT_USAGE_HTTP_ERROR", "COPILOT_USAGE_RATE_LIMITED"];
|
|
17
|
+
export declare const COPILOT_USAGE_DIAGNOSTICS: readonly ["COPILOT_USAGE_SIGNED_OUT", "COPILOT_USAGE_INVALID_GRANT", "COPILOT_USAGE_CREDENTIALS_UNAVAILABLE", "COPILOT_USAGE_ENTERPRISE_UNSUPPORTED", "COPILOT_USAGE_ACCOUNT_CHANGED", "COPILOT_USAGE_DISPOSED", "COPILOT_USAGE_BILLING_UNKNOWN", "COPILOT_USAGE_SNAPSHOT_MISSING", "COPILOT_USAGE_INVALID_RESPONSE", "COPILOT_USAGE_POOLED_UNAVAILABLE", "COPILOT_USAGE_POOLED_EXHAUSTED", "COPILOT_USAGE_NO_ALLOCATION", "COPILOT_USAGE_NETWORK", "COPILOT_USAGE_TLS", "COPILOT_USAGE_TIMEOUT", "COPILOT_USAGE_BODY_TOO_LARGE", "COPILOT_USAGE_REDIRECT", "COPILOT_USAGE_AUTH_REJECTED", "COPILOT_USAGE_HTTP_ERROR", "COPILOT_USAGE_RATE_LIMITED"];
|
|
18
18
|
export type CopilotUsageDiagnostic = typeof COPILOT_USAGE_DIAGNOSTICS[number];
|
|
19
19
|
//# sourceMappingURL=copilot-usage-types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-github-copilot",
|
|
3
3
|
"description": "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
4
|
-
"version": "0.4.0-alpha.
|
|
4
|
+
"version": "0.4.0-alpha.48",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"registry": "https://registry.npmjs.org/",
|