dsh-github-copilot 0.4.0-alpha.64 → 0.4.0-alpha.66
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/AGENTS.md +2 -0
- package/CHANGELOG.md +12 -0
- package/README.md +12 -8
- package/README.zh.md +12 -8
- package/deployment-baseline.json +9 -1
- package/docs/automatic-model-routing.md +122 -7
- package/docs/copilot-compaction.md +4 -0
- package/lib/index.js +321 -90
- package/lib/types/auto-model-host.d.ts +2 -0
- package/lib/types/auto-model-routing.d.ts +5 -3
- package/lib/types/config.d.ts +7 -2
- package/lib/types/parent-model-follow.d.ts +43 -0
- package/lib/types/preview-route.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -191,12 +191,12 @@ function fail$1(reason, creation) {
|
|
|
191
191
|
function creationOf(error) {
|
|
192
192
|
return ownRemoteFailure(error)?.creation ?? "uncertain";
|
|
193
193
|
}
|
|
194
|
-
function object$
|
|
194
|
+
function object$5(value) {
|
|
195
195
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
196
196
|
}
|
|
197
197
|
function api$1(ctx, key, methods) {
|
|
198
198
|
const value = ctx.get(key);
|
|
199
|
-
return object$
|
|
199
|
+
return object$5(value) && methods.every((method) => typeof value[method] === "function") ? value : void 0;
|
|
200
200
|
}
|
|
201
201
|
function revision(value) {
|
|
202
202
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
@@ -221,7 +221,7 @@ const ERROR_REASONS = /* @__PURE__ */ new Set([
|
|
|
221
221
|
/** Remote errors cross bundle/realm boundaries; constructor identity is not a protocol. */
|
|
222
222
|
function ownRemoteFailure(error) {
|
|
223
223
|
try {
|
|
224
|
-
if (!object$
|
|
224
|
+
if (!object$5(error) || error.isDSHRemoteError !== true || error.code !== "copilot/dual-model" || !object$5(error.details)) return void 0;
|
|
225
225
|
const reason = error.details.reason;
|
|
226
226
|
if (typeof reason !== "string" || !ERROR_REASONS.has(reason)) return void 0;
|
|
227
227
|
const creation = error.details.creation;
|
|
@@ -237,7 +237,7 @@ function reasonOf(error, fallback) {
|
|
|
237
237
|
const own = ownRemoteFailure(error);
|
|
238
238
|
if (own) return own.reason;
|
|
239
239
|
try {
|
|
240
|
-
if (object$
|
|
240
|
+
if (object$5(error) && error.code === "SETTINGS_CONFLICT") return "DUAL_MODEL_REVISION_CONFLICT";
|
|
241
241
|
} catch {}
|
|
242
242
|
return fallback;
|
|
243
243
|
}
|
|
@@ -365,7 +365,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
365
365
|
}, { prepend: true });
|
|
366
366
|
ctx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
367
367
|
const candidate = context.scope;
|
|
368
|
-
if (!candidate || !object$
|
|
368
|
+
if (!candidate || !object$5(candidate.session) || !object$5(candidate.session.header) || !dedicatedAddress(candidate)) return next();
|
|
369
369
|
const rehydrating = !this.overlays.has(candidate);
|
|
370
370
|
if (rehydrating) this.restore(candidate);
|
|
371
371
|
const installed = this.overlays.get(candidate);
|
|
@@ -1646,7 +1646,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1646
1646
|
//#endregion
|
|
1647
1647
|
//#region package.json
|
|
1648
1648
|
var name$1 = "dsh-github-copilot";
|
|
1649
|
-
var version = "0.4.0-alpha.
|
|
1649
|
+
var version = "0.4.0-alpha.66";
|
|
1650
1650
|
//#endregion
|
|
1651
1651
|
//#region lib/types/probe.js
|
|
1652
1652
|
/**
|
|
@@ -2068,9 +2068,14 @@ const WebSearchRoutingConfigSchema = z.object({
|
|
|
2068
2068
|
/** Keep native live references at the boundary; request code consumes plain snapshots. */
|
|
2069
2069
|
function readInlineConfig(config) {
|
|
2070
2070
|
const exclusions = readConfigValue(config.excludedModelIds);
|
|
2071
|
+
const bindings = readConfigValue(config.parentModelFollow);
|
|
2071
2072
|
return {
|
|
2072
2073
|
...config,
|
|
2073
2074
|
excludedModelIds: exclusions === void 0 ? void 0 : Array.from(exclusions),
|
|
2075
|
+
parentModelFollow: bindings === void 0 ? void 0 : Array.from(bindings, (binding) => ({
|
|
2076
|
+
childSessionId: binding.childSessionId,
|
|
2077
|
+
parentSessionId: binding.parentSessionId
|
|
2078
|
+
})),
|
|
2074
2079
|
searchModel: readConfigValue(config.searchModel),
|
|
2075
2080
|
searchRouting: readConfigValue(config.searchRouting),
|
|
2076
2081
|
temporaryRouteBackup: readConfigValue(config.temporaryRouteBackup)
|
|
@@ -2090,6 +2095,10 @@ const Config = z.object({
|
|
|
2090
2095
|
accountModelTtlMs: z.number().step(1).min(0).max(MAX_TIMEOUT_MS).default(864e5),
|
|
2091
2096
|
accountModelFailureCooldownMs: z.number().step(1).min(0).max(MAX_TIMEOUT_MS).default(3e5),
|
|
2092
2097
|
excludedModelIds: z.array(z.string()).default([]).hidden().volatile(),
|
|
2098
|
+
parentModelFollow: z.array(z.object({
|
|
2099
|
+
childSessionId: z.string().min(1),
|
|
2100
|
+
parentSessionId: z.string().min(1)
|
|
2101
|
+
})).default([]).volatile(),
|
|
2093
2102
|
requestBudgetSafetyTokens: z.number().step(1).min(0).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_REQUEST_BUDGET_POLICY.safetyTokens),
|
|
2094
2103
|
requestBudgetPressureRatio: z.number().step(.01).min(.01).max(1).default(DEFAULT_REQUEST_BUDGET_POLICY.pressureRatio),
|
|
2095
2104
|
compactionReasoning: z.union(["prefer-low", "preserve"]).default(DEFAULT_REQUEST_BUDGET_POLICY.compactionReasoning),
|
|
@@ -3914,19 +3923,19 @@ var TemporaryRouteConflictError = class extends Error {
|
|
|
3914
3923
|
this.name = "TemporaryRouteConflictError";
|
|
3915
3924
|
}
|
|
3916
3925
|
};
|
|
3917
|
-
function object$
|
|
3926
|
+
function object$4(value) {
|
|
3918
3927
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
3919
3928
|
}
|
|
3920
3929
|
function profileAt(value) {
|
|
3921
|
-
return object$
|
|
3930
|
+
return object$4(object$4(object$4(value)?.providers)?.["github-copilot"]);
|
|
3922
3931
|
}
|
|
3923
3932
|
/** Bounded comparison; never stringify or copy unknown model extras or headers. */
|
|
3924
3933
|
function equalJson(a, b, depth = 0) {
|
|
3925
3934
|
if (a === b) return true;
|
|
3926
3935
|
if (depth > 12) return false;
|
|
3927
3936
|
if (Array.isArray(a) || Array.isArray(b)) return Array.isArray(a) && Array.isArray(b) && a.length <= 512 && a.length === b.length && a.every((value, i) => equalJson(value, b[i], depth + 1));
|
|
3928
|
-
const left = object$
|
|
3929
|
-
const right = object$
|
|
3937
|
+
const left = object$4(a);
|
|
3938
|
+
const right = object$4(b);
|
|
3930
3939
|
if (!left || !right) return false;
|
|
3931
3940
|
const keys = Object.keys(left);
|
|
3932
3941
|
return keys.length <= 512 && keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && equalJson(left[key], right[key], depth + 1));
|
|
@@ -3935,7 +3944,7 @@ const MAX_BACKUP = 131072;
|
|
|
3935
3944
|
function safeModels(value) {
|
|
3936
3945
|
if (!Array.isArray(value) || value.length > 512) throw new TemporaryRouteConflictError();
|
|
3937
3946
|
return value.map((entry) => {
|
|
3938
|
-
const model = object$
|
|
3947
|
+
const model = object$4(entry);
|
|
3939
3948
|
if (!model || typeof model.id !== "string" || !/^[a-zA-Z0-9._:/-]{1,200}$/.test(model.id)) throw new TemporaryRouteConflictError();
|
|
3940
3949
|
const overlay = temporaryGitHubCopilotModel(model.id, /* @__PURE__ */ new Map());
|
|
3941
3950
|
if (overlay && Object.keys(model).some((key) => key !== "id" && key !== "api")) {
|
|
@@ -3966,10 +3975,10 @@ function readBackup(value) {
|
|
|
3966
3975
|
if (value === void 0) return void 0;
|
|
3967
3976
|
if (typeof value !== "string" || value.length > MAX_BACKUP) throw new TemporaryRouteConflictError("TEMPORARY_ROUTE_INVALID_BACKUP");
|
|
3968
3977
|
try {
|
|
3969
|
-
const decoded = object$
|
|
3978
|
+
const decoded = object$4(JSON.parse(value));
|
|
3970
3979
|
if (!decoded) throw new Error();
|
|
3971
3980
|
if (decoded.version === void 0 || decoded.version === 2 && decoded.sourceEpoch === void 0) throw new TemporaryRouteConflictError("TEMPORARY_ROUTE_LEGACY_CONFLICT");
|
|
3972
|
-
if (decoded.version !== 2 || typeof decoded.providerExisted !== "boolean" || typeof decoded.sourceEpoch !== "string" || !/^[a-f0-9-]{36}$/.test(decoded.sourceEpoch) || !Number.isSafeInteger(decoded.sourceRevision) || Number(decoded.sourceRevision) < 0 || !["overlay", "restoring"].includes(String(decoded.phase)) || !object$
|
|
3981
|
+
if (decoded.version !== 2 || typeof decoded.providerExisted !== "boolean" || typeof decoded.sourceEpoch !== "string" || !/^[a-f0-9-]{36}$/.test(decoded.sourceEpoch) || !Number.isSafeInteger(decoded.sourceRevision) || Number(decoded.sourceRevision) < 0 || !["overlay", "restoring"].includes(String(decoded.phase)) || !object$4(decoded.preimage) || !object$4(decoded.postimage) || !object$4(decoded.ownedHeaders) || Object.keys(decoded).some((key) => ![
|
|
3973
3982
|
"version",
|
|
3974
3983
|
"providerExisted",
|
|
3975
3984
|
"preimage",
|
|
@@ -3986,15 +3995,15 @@ function readBackup(value) {
|
|
|
3986
3995
|
decoded.postimage,
|
|
3987
3996
|
...decoded.phase === "restoring" ? [decoded.target] : []
|
|
3988
3997
|
]) {
|
|
3989
|
-
const record = object$
|
|
3998
|
+
const record = object$4(leaf);
|
|
3990
3999
|
if (!record || !equalJson(record, leavesOf(record))) throw new Error();
|
|
3991
4000
|
}
|
|
3992
|
-
const models = object$
|
|
4001
|
+
const models = object$4(decoded.postimage)?.models ?? [];
|
|
3993
4002
|
const knownHeaders = Object.assign({}, ...models.flatMap((model) => {
|
|
3994
4003
|
const overlay = temporaryGitHubCopilotModelFromProfile(model);
|
|
3995
4004
|
return overlay ? [overlay.headers] : [];
|
|
3996
4005
|
}));
|
|
3997
|
-
if (!Object.entries(object$
|
|
4006
|
+
if (!Object.entries(object$4(decoded.ownedHeaders)).every(([name, header]) => knownHeaders[name] === header)) throw new Error();
|
|
3998
4007
|
if (decoded.removeProfile !== void 0 && typeof decoded.removeProfile !== "boolean") throw new Error();
|
|
3999
4008
|
return decoded;
|
|
4000
4009
|
} catch (error) {
|
|
@@ -4020,7 +4029,7 @@ function settingsSnapshot(settings) {
|
|
|
4020
4029
|
hasOwnedSecrets,
|
|
4021
4030
|
routeRevision: route.revision,
|
|
4022
4031
|
markerRevision: marker.revision,
|
|
4023
|
-
backup: readBackup(object$
|
|
4032
|
+
backup: readBackup(object$4(marker.value)?.temporaryRouteBackup)
|
|
4024
4033
|
};
|
|
4025
4034
|
}
|
|
4026
4035
|
function assertOwned(current, backup) {
|
|
@@ -4053,7 +4062,7 @@ function leafOperations(current, target) {
|
|
|
4053
4062
|
}]);
|
|
4054
4063
|
}
|
|
4055
4064
|
function ownedHeaderRemoval(current, backup) {
|
|
4056
|
-
return Object.entries(object$
|
|
4065
|
+
return Object.entries(object$4(current?.headers) ?? {}).flatMap(([name, value]) => Object.entries(backup.ownedHeaders).some(([ownedName, ownedValue]) => name.toLowerCase() === ownedName.toLowerCase() && value === ownedValue) ? [{
|
|
4057
4066
|
op: "unset",
|
|
4058
4067
|
path: [
|
|
4059
4068
|
"providers",
|
|
@@ -4075,7 +4084,7 @@ function wholeProfileOwned(snapshot, backup) {
|
|
|
4075
4084
|
//#endregion
|
|
4076
4085
|
//#region lib/types/migration-status.js
|
|
4077
4086
|
const LIMIT = 1024;
|
|
4078
|
-
function object$
|
|
4087
|
+
function object$3(value) {
|
|
4079
4088
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Invalid evidence");
|
|
4080
4089
|
return value;
|
|
4081
4090
|
}
|
|
@@ -4084,7 +4093,7 @@ function text$1(value) {
|
|
|
4084
4093
|
return value;
|
|
4085
4094
|
}
|
|
4086
4095
|
function selection(value, omitDefaultEffort = false) {
|
|
4087
|
-
const item = object$
|
|
4096
|
+
const item = object$3(value);
|
|
4088
4097
|
const provider = text$1(item.provider), model = text$1(item.model), effort = item.reasoningEffort;
|
|
4089
4098
|
if (effort !== void 0) text$1(effort);
|
|
4090
4099
|
return {
|
|
@@ -4099,7 +4108,7 @@ function array(value) {
|
|
|
4099
4108
|
}
|
|
4100
4109
|
function api(ctx, name, methods) {
|
|
4101
4110
|
try {
|
|
4102
|
-
const candidate = object$
|
|
4111
|
+
const candidate = object$3(ctx.get(name));
|
|
4103
4112
|
return methods.every((key) => typeof candidate[key] === "function") ? candidate : void 0;
|
|
4104
4113
|
} catch {
|
|
4105
4114
|
return;
|
|
@@ -4169,26 +4178,26 @@ function migrationStatus(ctx) {
|
|
|
4169
4178
|
const rows = [], ids = /* @__PURE__ */ new Set();
|
|
4170
4179
|
let complete = projections !== void 0;
|
|
4171
4180
|
for (const candidate of array(call(agents, "list"))) {
|
|
4172
|
-
const agent = object$
|
|
4181
|
+
const agent = object$3(candidate), id = text$1(agent.id), status = agent.status;
|
|
4173
4182
|
if (ids.has(id) || status !== "idle" && status !== "running") throw new Error("Invalid agent inventory");
|
|
4174
4183
|
ids.add(id);
|
|
4175
|
-
const session = object$
|
|
4184
|
+
const session = object$3(agent.session);
|
|
4176
4185
|
if (text$1(session.id) !== id) throw new Error("Invalid agent identity");
|
|
4177
4186
|
const header = call(session, "requestHeader");
|
|
4178
|
-
const request = header === void 0 ? null : selection(object$
|
|
4187
|
+
const request = header === void 0 ? null : selection(object$3(header).config);
|
|
4179
4188
|
let effective = null, source = "unknown";
|
|
4180
4189
|
if (projections) {
|
|
4181
4190
|
const state = call(projections, "stateOf", session, "modelSelection");
|
|
4182
4191
|
if (state !== void 0) {
|
|
4183
|
-
const pending = object$
|
|
4192
|
+
const pending = object$3(state).pending;
|
|
4184
4193
|
if (pending !== null) {
|
|
4185
4194
|
effective = selection(pending);
|
|
4186
4195
|
source = "pending";
|
|
4187
4196
|
} else if (header !== void 0) {
|
|
4188
|
-
const defaults = object$
|
|
4189
|
-
const defaultEffort = defaults === void 0 ? false : object$
|
|
4197
|
+
const defaults = object$3(header).adapterDefaults;
|
|
4198
|
+
const defaultEffort = defaults === void 0 ? false : object$3(defaults).reasoningEffort;
|
|
4190
4199
|
if (defaultEffort !== void 0 && typeof defaultEffort !== "boolean") throw new Error("Invalid adapter defaults");
|
|
4191
|
-
effective = selection(object$
|
|
4200
|
+
effective = selection(object$3(header).config, defaultEffort === true);
|
|
4192
4201
|
source = "request-header";
|
|
4193
4202
|
} else if (result.complete.defaultSelection) {
|
|
4194
4203
|
effective = result.defaultSelection;
|
|
@@ -4212,23 +4221,23 @@ function migrationStatus(ctx) {
|
|
|
4212
4221
|
const descriptors = array(call(settings, "describe", { redactSecrets: true }));
|
|
4213
4222
|
const found = /* @__PURE__ */ new Set();
|
|
4214
4223
|
for (const value of descriptors) {
|
|
4215
|
-
const descriptor = object$
|
|
4224
|
+
const descriptor = object$3(value);
|
|
4216
4225
|
const ns = text$1(descriptor.ns);
|
|
4217
4226
|
if (ns !== "llm-pi-ai" && ns !== "github-copilot") continue;
|
|
4218
4227
|
if (found.has(ns) || !Number.isSafeInteger(descriptor.revision) || descriptor.revision < 0) throw new Error("Invalid settings evidence");
|
|
4219
4228
|
found.add(ns);
|
|
4220
4229
|
}
|
|
4221
4230
|
if (found.size !== 2) throw new Error("Unregistered settings");
|
|
4222
|
-
const config = object$
|
|
4223
|
-
const profile = (config.providers === void 0 ? void 0 : object$
|
|
4224
|
-
if (profile !== void 0) object$
|
|
4231
|
+
const config = object$3(call(settings, "get", "llm-pi-ai"));
|
|
4232
|
+
const profile = (config.providers === void 0 ? void 0 : object$3(config.providers))?.[GITHUB_COPILOT_PROVIDER_ID];
|
|
4233
|
+
if (profile !== void 0) object$3(profile);
|
|
4225
4234
|
result.capabilities.settingsCas = true;
|
|
4226
4235
|
result.routes.nativeConfigured = profile !== void 0;
|
|
4227
4236
|
} catch {}
|
|
4228
4237
|
if (llm) try {
|
|
4229
4238
|
const ids = /* @__PURE__ */ new Set();
|
|
4230
4239
|
for (const value of array(call(llm, "listProviders"))) {
|
|
4231
|
-
const id = text$1(object$
|
|
4240
|
+
const id = text$1(object$3(value).id);
|
|
4232
4241
|
if (ids.has(id)) throw new Error("Invalid registry evidence");
|
|
4233
4242
|
ids.add(id);
|
|
4234
4243
|
}
|
|
@@ -4378,7 +4387,7 @@ function accountModelsView(ctx) {
|
|
|
4378
4387
|
}
|
|
4379
4388
|
}
|
|
4380
4389
|
function modelSelection(value) {
|
|
4381
|
-
const selection = object$
|
|
4390
|
+
const selection = object$4(value);
|
|
4382
4391
|
const provider = selection?.provider;
|
|
4383
4392
|
const model = selection?.model;
|
|
4384
4393
|
return typeof provider === "string" && provider.length > 0 && typeof model === "string" && model.length > 0 ? {
|
|
@@ -4407,16 +4416,16 @@ function selectedFixedModelIds(ctx) {
|
|
|
4407
4416
|
const stateOf = Reflect.get(projections, "stateOf");
|
|
4408
4417
|
if (typeof stateOf !== "function") return void 0;
|
|
4409
4418
|
for (const candidate of rows) {
|
|
4410
|
-
const session = object$
|
|
4419
|
+
const session = object$4(object$4(candidate)?.session);
|
|
4411
4420
|
if (session === void 0) return void 0;
|
|
4412
|
-
const state = object$
|
|
4421
|
+
const state = object$4(Reflect.apply(stateOf, projections, [session, "modelSelection"]));
|
|
4413
4422
|
if (state === void 0 || !("pending" in state)) return void 0;
|
|
4414
4423
|
const pending = state.pending;
|
|
4415
4424
|
if (pending !== null && modelSelection(pending) === void 0) return void 0;
|
|
4416
4425
|
let selected = pending === null ? void 0 : fixedPreviewModel(pending);
|
|
4417
4426
|
if (pending === null) {
|
|
4418
4427
|
const requestHeader = session.requestHeader;
|
|
4419
|
-
const header = typeof requestHeader === "function" ? object$
|
|
4428
|
+
const header = typeof requestHeader === "function" ? object$4(Reflect.apply(requestHeader, session, [])) : void 0;
|
|
4420
4429
|
if (header?.config !== void 0 && modelSelection(header.config) === void 0) return void 0;
|
|
4421
4430
|
selected = fixedPreviewModel(header?.config);
|
|
4422
4431
|
}
|
|
@@ -4448,7 +4457,7 @@ function modelPreferencesView(ctx, accountModels, error) {
|
|
|
4448
4457
|
if (!Number.isSafeInteger(descriptor.revision) || descriptor.revision < 0) return unavailable("COPILOT_MODEL_SETTINGS_INVALID");
|
|
4449
4458
|
let excludedModelIds;
|
|
4450
4459
|
try {
|
|
4451
|
-
const raw = object$
|
|
4460
|
+
const raw = object$4(descriptor.value);
|
|
4452
4461
|
if (raw === void 0) return unavailable("COPILOT_MODEL_SETTINGS_INVALID");
|
|
4453
4462
|
excludedModelIds = normalizeExcludedModelIds(raw.excludedModelIds);
|
|
4454
4463
|
} catch {
|
|
@@ -4566,7 +4575,7 @@ async function repairGitHubCopilotProviderProfile(ctx) {
|
|
|
4566
4575
|
try {
|
|
4567
4576
|
await settings.mutate(namespace, operations, revision);
|
|
4568
4577
|
} catch (error) {
|
|
4569
|
-
if (object$
|
|
4578
|
+
if (object$4(error)?.code === "SETTINGS_CONFLICT") throw new TemporaryRouteConflictError();
|
|
4570
4579
|
throw error;
|
|
4571
4580
|
}
|
|
4572
4581
|
};
|
|
@@ -4977,7 +4986,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4977
4986
|
}], current.revision);
|
|
4978
4987
|
this.modelPreferenceFailure = void 0;
|
|
4979
4988
|
} catch (cause) {
|
|
4980
|
-
const record = object$
|
|
4989
|
+
const record = object$4(cause);
|
|
4981
4990
|
this.modelPreferenceFailure = record?.code === "SETTINGS_CONFLICT" || cause instanceof Error && /conflict/i.test(cause.message) ? "COPILOT_MODEL_EXCLUSION_CONFLICT" : "COPILOT_MODEL_EXCLUSION_SAVE_FAILED";
|
|
4982
4991
|
}
|
|
4983
4992
|
return this.status();
|
|
@@ -5122,7 +5131,7 @@ const levels = [
|
|
|
5122
5131
|
"xhigh",
|
|
5123
5132
|
"max"
|
|
5124
5133
|
];
|
|
5125
|
-
function object$
|
|
5134
|
+
function object$2(value) {
|
|
5126
5135
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
5127
5136
|
}
|
|
5128
5137
|
function unavailable() {
|
|
@@ -5131,18 +5140,18 @@ function unavailable() {
|
|
|
5131
5140
|
/** Resolve only the selected model's declared/native efforts, with the same precedence as Core. */
|
|
5132
5141
|
function resolveCopilotResponsesReasoning(ctx, request, candidate) {
|
|
5133
5142
|
if (request.provider !== "github-copilot" || candidate.protocol !== "openai-responses" || candidate.model !== request.model) return unavailable();
|
|
5134
|
-
const profile = object$
|
|
5143
|
+
const profile = object$2(object$2(object$2(readSettingsNamespace(ctx, "llm-pi-ai"))?.providers)?.["github-copilot"]);
|
|
5135
5144
|
const effort = request.reasoningEffort ?? profile?.reasoning;
|
|
5136
5145
|
if (effort === void 0) return void 0;
|
|
5137
5146
|
const level = levels.find((value) => value === effort);
|
|
5138
5147
|
if (level === void 0 || profile === void 0) return unavailable();
|
|
5139
5148
|
const configured = Array.isArray(profile.models) ? profile.models : [];
|
|
5140
|
-
const entry = configured.length > 0 ? object$
|
|
5149
|
+
const entry = configured.length > 0 ? object$2(configured.find((value) => object$2(value)?.id === request.model)) : object$2(object$2(profile.modelOverrides)?.[request.model]);
|
|
5141
5150
|
if (configured.length > 0 && entry === void 0) return unavailable();
|
|
5142
5151
|
const declared = entry?.reasoningEfforts;
|
|
5143
5152
|
if (declared !== void 0) {
|
|
5144
5153
|
if (declared === false) return level === "off" ? void 0 : unavailable();
|
|
5145
|
-
const mapping = object$
|
|
5154
|
+
const mapping = object$2(declared);
|
|
5146
5155
|
if (mapping === void 0) return unavailable();
|
|
5147
5156
|
const wire = mapping[level];
|
|
5148
5157
|
if (level === "off" && (wire === null || typeof wire === "string" && wire.length > 0)) return void 0;
|
|
@@ -6343,7 +6352,7 @@ function createAccountModelSource(dependencies) {
|
|
|
6343
6352
|
}
|
|
6344
6353
|
//#endregion
|
|
6345
6354
|
//#region lib/types/compaction-pressure.js
|
|
6346
|
-
function object(value) {
|
|
6355
|
+
function object$1(value) {
|
|
6347
6356
|
return typeof value === "object" && value !== null ? value : void 0;
|
|
6348
6357
|
}
|
|
6349
6358
|
/** Optional public services are not dependencies of the retained development baseline. */
|
|
@@ -6374,7 +6383,7 @@ function installCopilotCompactionPressure(ctx, callbacks) {
|
|
|
6374
6383
|
const pressureFailure = (request) => {
|
|
6375
6384
|
if (!isAgentLoopRequest(request) || request.purpose !== void 0 || request.provider !== "github-copilot-preview" || request.sessionId === void 0 || request.signal?.aborted) return void 0;
|
|
6376
6385
|
if (!isPluginPreviewProvider(ctx, request.provider)) return void 0;
|
|
6377
|
-
if (typeof object(ctx.get("agents"))?.currentInitiator !== "function") {
|
|
6386
|
+
if (typeof object$1(ctx.get("agents"))?.currentInitiator !== "function") {
|
|
6378
6387
|
unavailable();
|
|
6379
6388
|
return;
|
|
6380
6389
|
}
|
|
@@ -6388,15 +6397,15 @@ function installCopilotCompactionPressure(ctx, callbacks) {
|
|
|
6388
6397
|
if (header === void 0 || !callConfigEquals(header.config, request)) return void 0;
|
|
6389
6398
|
const budget = callbacks.resolve(request);
|
|
6390
6399
|
if (budget === void 0 || !positiveInteger(budget.inputBudgetTokens)) return void 0;
|
|
6391
|
-
const compaction = object(optionalService(ctx, "compaction"));
|
|
6392
|
-
const config = object(compaction?.config);
|
|
6400
|
+
const compaction = object$1(optionalService(ctx, "compaction"));
|
|
6401
|
+
const config = object$1(compaction?.config);
|
|
6393
6402
|
if (config?.auto === false) return void 0;
|
|
6394
6403
|
if (config?.auto !== true || typeof compaction?.compactIfNeeded !== "function") {
|
|
6395
6404
|
unavailable();
|
|
6396
6405
|
return;
|
|
6397
6406
|
}
|
|
6398
|
-
const retries = (Array.isArray(config.modelPolicies) ? object(config.modelPolicies.find((value) => {
|
|
6399
|
-
const candidate = object(value);
|
|
6407
|
+
const retries = (Array.isArray(config.modelPolicies) ? object$1(config.modelPolicies.find((value) => {
|
|
6408
|
+
const candidate = object$1(value);
|
|
6400
6409
|
return candidate?.provider === request.provider && candidate.model === request.model;
|
|
6401
6410
|
})) : void 0)?.maxOverflowRetries ?? config.maxOverflowRetries;
|
|
6402
6411
|
if (retries === 0) return void 0;
|
|
@@ -6404,12 +6413,12 @@ function installCopilotCompactionPressure(ctx, callbacks) {
|
|
|
6404
6413
|
unavailable();
|
|
6405
6414
|
return;
|
|
6406
6415
|
}
|
|
6407
|
-
const meter = object(optionalService(ctx, "tokenMeter"));
|
|
6416
|
+
const meter = object$1(optionalService(ctx, "tokenMeter"));
|
|
6408
6417
|
if (typeof meter?.measure !== "function") {
|
|
6409
6418
|
unavailable();
|
|
6410
6419
|
return;
|
|
6411
6420
|
}
|
|
6412
|
-
const tokens = object(meter.measure(owner.session))?.totalTokens;
|
|
6421
|
+
const tokens = object$1(meter.measure(owner.session))?.totalTokens;
|
|
6413
6422
|
if (typeof tokens !== "number" || !Number.isSafeInteger(tokens) || tokens < 0) {
|
|
6414
6423
|
unavailable();
|
|
6415
6424
|
return;
|
|
@@ -6518,37 +6527,18 @@ function reasonFor(features) {
|
|
|
6518
6527
|
if (features.taskClass === "strong") return "large-structured-turn";
|
|
6519
6528
|
return "standard-turn";
|
|
6520
6529
|
}
|
|
6521
|
-
function
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
fresh += estimateMessageTokens(message);
|
|
6525
|
-
} catch {}
|
|
6526
|
-
let contextTokens = 0;
|
|
6527
|
-
try {
|
|
6528
|
-
contextTokens = estimateContextTokens(messages).tokens;
|
|
6529
|
-
} catch {}
|
|
6530
|
-
const estimated = Math.max(fresh, contextTokens);
|
|
6531
|
-
if (estimated > 0) return estimated;
|
|
6532
|
-
let charCount = 0;
|
|
6533
|
-
for (const message of messages) if (record$1(message) && Array.isArray(message.content)) {
|
|
6534
|
-
for (const block of message.content) if (record$1(block) && typeof block.text === "string") charCount += block.text.length;
|
|
6535
|
-
}
|
|
6536
|
-
return charCount > 0 ? Math.ceil(charCount / 4) : 0;
|
|
6530
|
+
function validTokenEstimate(value) {
|
|
6531
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new AutoModelRoutingError("COPILOT_AUTO_TOKEN_ESTIMATE_INVALID");
|
|
6532
|
+
return value;
|
|
6537
6533
|
}
|
|
6538
|
-
function
|
|
6534
|
+
function estimateTurnInputTokens(messages, estimateMessage) {
|
|
6535
|
+
if (estimateMessage === void 0) throw new AutoModelRoutingError("COPILOT_AUTO_TOKEN_METER_UNAVAILABLE");
|
|
6536
|
+
return messages.reduce((sum, message) => validTokenEstimate(sum + validTokenEstimate(estimateMessage(message))), 0);
|
|
6537
|
+
}
|
|
6538
|
+
function latestUserTurnTokens(messages, estimateMessage) {
|
|
6539
6539
|
for (let index = messages.length - 1; index >= 0; index--) {
|
|
6540
6540
|
const message = messages[index];
|
|
6541
|
-
if (userMessage(message))
|
|
6542
|
-
try {
|
|
6543
|
-
const est = estimateMessageTokens(message);
|
|
6544
|
-
if (est > 0) return est;
|
|
6545
|
-
} catch {}
|
|
6546
|
-
if (Array.isArray(message.content)) {
|
|
6547
|
-
let chars = 0;
|
|
6548
|
-
for (const block of message.content) if (record$1(block) && typeof block.text === "string") chars += block.text.length;
|
|
6549
|
-
if (chars > 0) return Math.ceil(chars / 4);
|
|
6550
|
-
}
|
|
6551
|
-
}
|
|
6541
|
+
if (userMessage(message)) return validTokenEstimate(estimateMessage(message));
|
|
6552
6542
|
}
|
|
6553
6543
|
return 0;
|
|
6554
6544
|
}
|
|
@@ -6650,7 +6640,9 @@ function selectAutoModel(models, messages, preference = "balance", context) {
|
|
|
6650
6640
|
const features = classifyAutoModelTurn(messages);
|
|
6651
6641
|
const eligible = models.filter((model) => autoModelPreference(model.id) === void 0 && model.input.includes("text") && (!features.requiresImage || model.input.includes("image"))).toSorted(compareCapacity);
|
|
6652
6642
|
if (eligible.length === 0) throw new AutoModelRoutingError("COPILOT_AUTO_NO_ELIGIBLE_MODEL");
|
|
6653
|
-
const
|
|
6643
|
+
const estimateMessage = context?.estimateMessage;
|
|
6644
|
+
if (estimateMessage === void 0) throw new AutoModelRoutingError("COPILOT_AUTO_TOKEN_METER_UNAVAILABLE");
|
|
6645
|
+
const estimatedInputTokens = Math.max(estimateTurnInputTokens(messages, estimateMessage), validTokenEstimate(context?.inputTokenFloor ?? 0));
|
|
6654
6646
|
const requestedMaxTokens = context?.requestedMaxTokens;
|
|
6655
6647
|
const policy = context?.requestBudgetPolicy ?? DEFAULT_REQUEST_BUDGET_POLICY;
|
|
6656
6648
|
const fitting = eligible.filter((model) => {
|
|
@@ -6677,7 +6669,7 @@ function selectAutoModel(models, messages, preference = "balance", context) {
|
|
|
6677
6669
|
}
|
|
6678
6670
|
selectedModel = maxModel;
|
|
6679
6671
|
selectedInputBudget = maxLimit;
|
|
6680
|
-
if (latestUserTurnTokens(messages) > maxLimit) inputFitDiagnostic = "fixed-content-cannot-fit";
|
|
6672
|
+
if (latestUserTurnTokens(messages, estimateMessage) > maxLimit) inputFitDiagnostic = "fixed-content-cannot-fit";
|
|
6681
6673
|
else if (context?.compactionAvailable === false) inputFitDiagnostic = "compaction-unavailable";
|
|
6682
6674
|
else if (context?.hasCompactionSummary === true) inputFitDiagnostic = "attempted-but-still-oversized";
|
|
6683
6675
|
else inputFitDiagnostic = "compaction-eligible";
|
|
@@ -6743,6 +6735,113 @@ var TurnSelectionStore = class {
|
|
|
6743
6735
|
}
|
|
6744
6736
|
};
|
|
6745
6737
|
//#endregion
|
|
6738
|
+
//#region lib/types/parent-model-follow.js
|
|
6739
|
+
const PARENT_MODEL_FOLLOW_PROJECTION = "githubCopilotParentModelFollow";
|
|
6740
|
+
function object(value) {
|
|
6741
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6742
|
+
}
|
|
6743
|
+
function followSelection(value) {
|
|
6744
|
+
if (!object(value) || typeof value.provider !== "string" || !value.provider || typeof value.model !== "string" || !value.model) return void 0;
|
|
6745
|
+
return {
|
|
6746
|
+
provider: value.provider,
|
|
6747
|
+
model: value.model
|
|
6748
|
+
};
|
|
6749
|
+
}
|
|
6750
|
+
function initialFollowState(inherited = 0) {
|
|
6751
|
+
return {
|
|
6752
|
+
inherited,
|
|
6753
|
+
turn: null,
|
|
6754
|
+
started: false,
|
|
6755
|
+
explicit: null,
|
|
6756
|
+
descriptor: false,
|
|
6757
|
+
blocked: false
|
|
6758
|
+
};
|
|
6759
|
+
}
|
|
6760
|
+
/** Fold only the child's own suffix; copied fork selections are not child overrides. */
|
|
6761
|
+
function foldFollowState(state, event) {
|
|
6762
|
+
if (event.seq < state.inherited) return state;
|
|
6763
|
+
if (event.type === "turn/start") {
|
|
6764
|
+
if (!object(event.data) || !Number.isSafeInteger(event.data.turn) || Number(event.data.turn) < 0) return {
|
|
6765
|
+
...state,
|
|
6766
|
+
blocked: true
|
|
6767
|
+
};
|
|
6768
|
+
return {
|
|
6769
|
+
...state,
|
|
6770
|
+
turn: Number(event.data.turn),
|
|
6771
|
+
started: false
|
|
6772
|
+
};
|
|
6773
|
+
}
|
|
6774
|
+
if (event.type === "step/start") return {
|
|
6775
|
+
...state,
|
|
6776
|
+
started: true
|
|
6777
|
+
};
|
|
6778
|
+
if (event.type === "model/selection") {
|
|
6779
|
+
const selection = followSelection(event.data);
|
|
6780
|
+
return selection ? {
|
|
6781
|
+
...state,
|
|
6782
|
+
explicit: selection
|
|
6783
|
+
} : {
|
|
6784
|
+
...state,
|
|
6785
|
+
blocked: true
|
|
6786
|
+
};
|
|
6787
|
+
}
|
|
6788
|
+
if (event.type === "github-copilot/dual-model-policy") return {
|
|
6789
|
+
...state,
|
|
6790
|
+
blocked: true
|
|
6791
|
+
};
|
|
6792
|
+
if (event.type === "subagent/descriptor") {
|
|
6793
|
+
const data = event.data;
|
|
6794
|
+
const valid = object(data) && data.version === 3 && data.provider === "spawn" && (data.mode === "continuable" || data.mode === "one-shot");
|
|
6795
|
+
return {
|
|
6796
|
+
...state,
|
|
6797
|
+
descriptor: valid,
|
|
6798
|
+
blocked: state.blocked || !valid || state.descriptor
|
|
6799
|
+
};
|
|
6800
|
+
}
|
|
6801
|
+
return state;
|
|
6802
|
+
}
|
|
6803
|
+
var ParentModelFollowError = class extends Error {
|
|
6804
|
+
code;
|
|
6805
|
+
constructor(code) {
|
|
6806
|
+
super(code);
|
|
6807
|
+
this.code = code;
|
|
6808
|
+
this.name = "ParentModelFollowError";
|
|
6809
|
+
}
|
|
6810
|
+
};
|
|
6811
|
+
/** Resolve a new turn's intent without changing any Session, setting or descriptor. */
|
|
6812
|
+
function resolveParentModel(child, bindings, lookup) {
|
|
6813
|
+
const matches = bindings.filter((binding) => binding.childSessionId === child.id);
|
|
6814
|
+
if (matches.length === 0) return void 0;
|
|
6815
|
+
const fail = (code) => {
|
|
6816
|
+
throw new ParentModelFollowError(`COPILOT_PARENT_MODEL_${code}`);
|
|
6817
|
+
};
|
|
6818
|
+
if (matches.length !== 1) fail("BINDING_INVALID");
|
|
6819
|
+
if (child.state.blocked || !child.state.descriptor || child.origin !== "subagent") fail("CHILD_UNSUPPORTED");
|
|
6820
|
+
if (!child.parentId || child.parentId !== matches[0]?.parentSessionId) fail("LINEAGE_INVALID");
|
|
6821
|
+
if (child.state.explicit !== null) return void 0;
|
|
6822
|
+
const seen = /* @__PURE__ */ new Set([child.id]);
|
|
6823
|
+
let current = child;
|
|
6824
|
+
while (true) {
|
|
6825
|
+
const parentId = current.parentId;
|
|
6826
|
+
if (!parentId || seen.has(parentId)) return fail("LINEAGE_INVALID");
|
|
6827
|
+
seen.add(parentId);
|
|
6828
|
+
const parent = lookup(parentId);
|
|
6829
|
+
if (!parent) return fail("PARENT_UNAVAILABLE");
|
|
6830
|
+
if (parent.state.blocked) fail("PARENT_UNSUPPORTED");
|
|
6831
|
+
const parentBindings = bindings.filter((binding) => binding.childSessionId === parent.id);
|
|
6832
|
+
if (parentBindings.length > 1) fail("BINDING_INVALID");
|
|
6833
|
+
if (parentBindings.length === 1 && parent.state.explicit === null) {
|
|
6834
|
+
if (!parent.state.descriptor || parent.origin !== "subagent" || parent.parentId !== parentBindings[0]?.parentSessionId) fail("LINEAGE_INVALID");
|
|
6835
|
+
current = parent;
|
|
6836
|
+
continue;
|
|
6837
|
+
}
|
|
6838
|
+
const selection = parent.pending ?? parent.recorded;
|
|
6839
|
+
if (!selection) return fail("SELECTION_UNAVAILABLE");
|
|
6840
|
+
if (selection.provider !== "github-copilot-preview") fail("PROVIDER_UNSUPPORTED");
|
|
6841
|
+
return { ...selection };
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
//#endregion
|
|
6746
6845
|
//#region lib/types/auto-model-host.js
|
|
6747
6846
|
function failure$1(code) {
|
|
6748
6847
|
return new LlmError(code, "INVALID_REQUEST");
|
|
@@ -6759,16 +6858,30 @@ function record(value) {
|
|
|
6759
6858
|
return typeof value === "object" && value !== null;
|
|
6760
6859
|
}
|
|
6761
6860
|
function buildRoutingContext(ctx, agent, turn, messages, budgetPolicyConfig) {
|
|
6861
|
+
const meter = ctx.get("tokenMeter");
|
|
6862
|
+
if (!record(meter) || typeof meter.estimateMessage !== "function" || typeof meter.measure !== "function") throw failure$1("COPILOT_AUTO_TOKEN_METER_UNAVAILABLE");
|
|
6863
|
+
const measured = meter.measure(agent.session);
|
|
6864
|
+
if (!record(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) throw failure$1("COPILOT_AUTO_TOKEN_ESTIMATE_INVALID");
|
|
6865
|
+
const estimate = meter.estimateMessage.bind(meter);
|
|
6866
|
+
const estimateMessage = (message) => {
|
|
6867
|
+
const value = estimate(message);
|
|
6868
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw failure$1("COPILOT_AUTO_TOKEN_ESTIMATE_INVALID");
|
|
6869
|
+
return value;
|
|
6870
|
+
};
|
|
6762
6871
|
const sessionId = typeof agent.session?.id === "string" ? agent.session.id : void 0;
|
|
6763
6872
|
const compaction = ctx.get("compaction");
|
|
6764
6873
|
const compactionConfig = record(compaction) && record(compaction.config) ? compaction.config : void 0;
|
|
6765
6874
|
const compactionAvailable = compaction !== void 0 && compactionConfig?.auto !== false && (typeof compactionConfig?.maxOverflowRetries !== "number" || compactionConfig.maxOverflowRetries > 0);
|
|
6766
|
-
const hasCompactionSummary = messages.some((m) => record(m) && (record(m.source) && m.source.kind === "compaction" || typeof m.surfaceOp === "object"));
|
|
6875
|
+
const hasCompactionSummary = messages.some((m) => record(m) && (record(m.source) && (m.source.kind === "compaction" || m.source.kind === "compact-checkpoint") || typeof m.surfaceOp === "object"));
|
|
6876
|
+
const requestedMaxTokens = (typeof agent.session?.requestHeader === "function" ? agent.session.requestHeader() : void 0)?.config.maxTokens;
|
|
6877
|
+
const requestBudgetPolicy = budgetPolicyConfig ? resolveRequestBudgetPolicy(budgetPolicyConfig) : DEFAULT_REQUEST_BUDGET_POLICY;
|
|
6767
6878
|
return {
|
|
6879
|
+
estimateMessage,
|
|
6880
|
+
inputTokenFloor: measured.totalTokens,
|
|
6768
6881
|
sessionId,
|
|
6769
6882
|
turn,
|
|
6770
|
-
requestedMaxTokens
|
|
6771
|
-
requestBudgetPolicy
|
|
6883
|
+
requestedMaxTokens,
|
|
6884
|
+
requestBudgetPolicy,
|
|
6772
6885
|
compactionAvailable,
|
|
6773
6886
|
hasCompactionSummary
|
|
6774
6887
|
};
|
|
@@ -6811,10 +6924,109 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6811
6924
|
const routed = /* @__PURE__ */ new WeakMap();
|
|
6812
6925
|
const agentDisposers = /* @__PURE__ */ new WeakMap();
|
|
6813
6926
|
const activeDisposers = /* @__PURE__ */ new Set();
|
|
6927
|
+
const followed = /* @__PURE__ */ new WeakMap();
|
|
6928
|
+
const selectionSchema = z$1.object({
|
|
6929
|
+
provider: z$1.string().min(1),
|
|
6930
|
+
model: z$1.string().min(1)
|
|
6931
|
+
}).strict();
|
|
6932
|
+
const followSchema = z$1.object({
|
|
6933
|
+
inherited: z$1.number().int().nonnegative(),
|
|
6934
|
+
turn: z$1.number().int().nonnegative().nullable(),
|
|
6935
|
+
started: z$1.boolean(),
|
|
6936
|
+
explicit: selectionSchema.nullable(),
|
|
6937
|
+
descriptor: z$1.boolean(),
|
|
6938
|
+
blocked: z$1.boolean()
|
|
6939
|
+
}).strict();
|
|
6940
|
+
let removeFollowProjection;
|
|
6941
|
+
const followIntent = (agent) => {
|
|
6942
|
+
const previous = followed.get(agent);
|
|
6943
|
+
if (previous) {
|
|
6944
|
+
const registry = ctx.get("sessionProjections");
|
|
6945
|
+
if (!record(registry) || typeof registry.stateOf !== "function") throw failure$1("COPILOT_PARENT_MODEL_PROJECTIONS_UNAVAILABLE");
|
|
6946
|
+
const state = followSchema.safeParse(registry.stateOf(agent.session, PARENT_MODEL_FOLLOW_PROJECTION));
|
|
6947
|
+
if (!state.success) throw failure$1("COPILOT_PARENT_MODEL_TURN_UNAVAILABLE");
|
|
6948
|
+
if (state.data.turn === previous.turn) return previous.selection;
|
|
6949
|
+
}
|
|
6950
|
+
const bindings = dependencies.parentModelBindings?.() ?? [];
|
|
6951
|
+
if (!bindings.some((binding) => binding.childSessionId === agent.session.id)) return void 0;
|
|
6952
|
+
const projections = ctx.get("sessionProjections");
|
|
6953
|
+
if (!record(projections) || typeof projections.register !== "function" || typeof projections.stateOf !== "function") throw failure$1("COPILOT_PARENT_MODEL_PROJECTIONS_UNAVAILABLE");
|
|
6954
|
+
const stateOf = projections.stateOf;
|
|
6955
|
+
if (!removeFollowProjection) {
|
|
6956
|
+
const remove = projections.register({
|
|
6957
|
+
key: PARENT_MODEL_FOLLOW_PROJECTION,
|
|
6958
|
+
stateVersion: 1,
|
|
6959
|
+
stateSchema: followSchema,
|
|
6960
|
+
init: (_header, inherited = 0) => initialFollowState(inherited),
|
|
6961
|
+
apply: foldFollowState
|
|
6962
|
+
});
|
|
6963
|
+
if (typeof remove !== "function") throw failure$1("COPILOT_PARENT_MODEL_PROJECTIONS_UNAVAILABLE");
|
|
6964
|
+
removeFollowProjection = () => {
|
|
6965
|
+
remove();
|
|
6966
|
+
};
|
|
6967
|
+
}
|
|
6968
|
+
const readSubject = (value) => {
|
|
6969
|
+
if (!record(value) || !record(value.session)) return void 0;
|
|
6970
|
+
const session = value.session;
|
|
6971
|
+
if (typeof session.id !== "string" || !record(session.header) || typeof session.requestHeader !== "function") return void 0;
|
|
6972
|
+
const parsed = followSchema.safeParse(Reflect.apply(stateOf, projections, [session, PARENT_MODEL_FOLLOW_PROJECTION]));
|
|
6973
|
+
const selection = Reflect.apply(stateOf, projections, [session, "modelSelection"]);
|
|
6974
|
+
if (!parsed.success || !record(selection) || !Object.hasOwn(selection, "pending")) throw failure$1("COPILOT_PARENT_MODEL_SELECTION_UNAVAILABLE");
|
|
6975
|
+
const pending = selection.pending === null ? null : followSelection(selection.pending);
|
|
6976
|
+
if (pending === void 0) throw failure$1("COPILOT_PARENT_MODEL_SELECTION_UNAVAILABLE");
|
|
6977
|
+
const header = session.requestHeader();
|
|
6978
|
+
return {
|
|
6979
|
+
id: session.id,
|
|
6980
|
+
parentId: typeof session.header.parentSession === "string" ? session.header.parentSession : void 0,
|
|
6981
|
+
origin: typeof session.header.origin === "string" ? session.header.origin : void 0,
|
|
6982
|
+
state: parsed.data,
|
|
6983
|
+
pending,
|
|
6984
|
+
recorded: record(header) ? followSelection(header.config) : void 0
|
|
6985
|
+
};
|
|
6986
|
+
};
|
|
6987
|
+
const child = readSubject(agent);
|
|
6988
|
+
if (!child || child.state.turn === null) throw failure$1("COPILOT_PARENT_MODEL_TURN_UNAVAILABLE");
|
|
6989
|
+
if (child.state.started) {
|
|
6990
|
+
followed.set(agent, {
|
|
6991
|
+
turn: child.state.turn,
|
|
6992
|
+
selection: void 0
|
|
6993
|
+
});
|
|
6994
|
+
return;
|
|
6995
|
+
}
|
|
6996
|
+
const agents = ctx.get("agents");
|
|
6997
|
+
try {
|
|
6998
|
+
const selection = resolveParentModel(child, bindings, (id) => {
|
|
6999
|
+
if (!record(agents) || typeof agents.get !== "function") return void 0;
|
|
7000
|
+
return readSubject(agents.get(id));
|
|
7001
|
+
});
|
|
7002
|
+
followed.set(agent, {
|
|
7003
|
+
turn: child.state.turn,
|
|
7004
|
+
selection
|
|
7005
|
+
});
|
|
7006
|
+
return selection;
|
|
7007
|
+
} catch (cause) {
|
|
7008
|
+
if (cause instanceof ParentModelFollowError) throw failure$1(cause.code);
|
|
7009
|
+
throw cause;
|
|
7010
|
+
}
|
|
7011
|
+
};
|
|
7012
|
+
const effectiveAuto = (agent) => {
|
|
7013
|
+
const inherited = followIntent(agent);
|
|
7014
|
+
if (inherited !== void 0) return autoModelPreference(inherited.model) !== void 0 ? inherited.model : void 0;
|
|
7015
|
+
return pendingAuto(ctx, agent);
|
|
7016
|
+
};
|
|
6814
7017
|
const installAgent = (agent) => {
|
|
6815
7018
|
if (agentDisposers.has(agent)) return;
|
|
6816
7019
|
const removeAssembly = agent.ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
7020
|
+
const inherited = followIntent(agent);
|
|
6817
7021
|
const assembled = await next();
|
|
7022
|
+
if (inherited !== void 0) return {
|
|
7023
|
+
...assembled,
|
|
7024
|
+
variables: {
|
|
7025
|
+
...assembled.variables,
|
|
7026
|
+
provider: inherited.provider,
|
|
7027
|
+
model: inherited.model
|
|
7028
|
+
}
|
|
7029
|
+
};
|
|
6818
7030
|
const pending = pendingAuto(ctx, agent);
|
|
6819
7031
|
if (pending === void 0) return assembled;
|
|
6820
7032
|
return {
|
|
@@ -6833,8 +7045,17 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6833
7045
|
turn,
|
|
6834
7046
|
messages: entered
|
|
6835
7047
|
});
|
|
6836
|
-
const pending =
|
|
7048
|
+
const pending = effectiveAuto(agent);
|
|
6837
7049
|
const preference = pending === void 0 ? void 0 : autoModelPreference(pending);
|
|
7050
|
+
const inherited = followIntent(agent);
|
|
7051
|
+
if (result.kind === "enter" && !signal.aborted && inherited !== void 0 && preference === void 0) {
|
|
7052
|
+
const filtered = result.messages.filter((message) => !modelSelectionNotice(message));
|
|
7053
|
+
const notice = actualNotice(agent, inherited.model);
|
|
7054
|
+
return {
|
|
7055
|
+
...result,
|
|
7056
|
+
messages: notice === void 0 ? filtered : [...filtered, notice]
|
|
7057
|
+
};
|
|
7058
|
+
}
|
|
6838
7059
|
if (result.kind !== "enter" || signal.aborted || preference === void 0) return result;
|
|
6839
7060
|
let state = routed.get(agent);
|
|
6840
7061
|
if (state?.turn !== turn) {
|
|
@@ -6872,11 +7093,19 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6872
7093
|
agentDisposers.delete(agent);
|
|
6873
7094
|
captured.delete(agent);
|
|
6874
7095
|
routed.delete(agent);
|
|
7096
|
+
followed.delete(agent);
|
|
6875
7097
|
selections.remove(agent);
|
|
6876
7098
|
});
|
|
6877
7099
|
const removeRequest = ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
6878
|
-
|
|
6879
|
-
const
|
|
7100
|
+
installAgent(agent);
|
|
7101
|
+
const native = await next();
|
|
7102
|
+
const inherited = followIntent(agent);
|
|
7103
|
+
const { reasoningEffort: _nativeEffort, ...withoutEffort } = native;
|
|
7104
|
+
const resolved = inherited === void 0 ? native : {
|
|
7105
|
+
...withoutEffort,
|
|
7106
|
+
...inherited
|
|
7107
|
+
};
|
|
7108
|
+
const pending = effectiveAuto(agent);
|
|
6880
7109
|
const virtualPreference = resolved.provider === "github-copilot-preview" ? autoModelPreference(resolved.model) : void 0;
|
|
6881
7110
|
const virtual = virtualPreference !== void 0;
|
|
6882
7111
|
if (!virtual && pending === void 0) {
|
|
@@ -6907,7 +7136,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6907
7136
|
}
|
|
6908
7137
|
if (!state.recorded) {
|
|
6909
7138
|
const projections = ctx.get("sessionProjections");
|
|
6910
|
-
if (virtual && record(projections) && typeof projections.stateOf === "function") {
|
|
7139
|
+
if (inherited === void 0 && virtual && record(projections) && typeof projections.stateOf === "function") {
|
|
6911
7140
|
const selection = projections.stateOf(agent.session, "modelSelection");
|
|
6912
7141
|
if (record(selection) && selection.pending === null && agent.session.requestHeader() === void 0) Reflect.apply(agent.session.append, agent.session, ["model/selection", {
|
|
6913
7142
|
provider: GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
|
|
@@ -6932,6 +7161,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
6932
7161
|
removeCreated();
|
|
6933
7162
|
removeDisposed();
|
|
6934
7163
|
removeRequest();
|
|
7164
|
+
removeFollowProjection?.();
|
|
6935
7165
|
for (const dispose of activeDisposers) dispose();
|
|
6936
7166
|
activeDisposers.clear();
|
|
6937
7167
|
selections.clear();
|
|
@@ -7649,7 +7879,8 @@ function apply$1(ctx, config = {}) {
|
|
|
7649
7879
|
const excluded = excludedModels();
|
|
7650
7880
|
return (await discoverSnapshot({ signal })).models.filter((model) => !excluded.has(model.id));
|
|
7651
7881
|
},
|
|
7652
|
-
budgetPolicy: () => budgetSettings()
|
|
7882
|
+
budgetPolicy: () => budgetSettings(),
|
|
7883
|
+
parentModelBindings: () => cacheSettings().parentModelFollow ?? []
|
|
7653
7884
|
});
|
|
7654
7885
|
const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings));
|
|
7655
7886
|
let exclusionSignature = JSON.stringify([...excludedModels()]);
|