dsh-github-copilot 0.4.1 → 0.4.2-alpha.3

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/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { c as DiagnosticsViewSchema, d as diagnosticsReason, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, o as DiagnosticsRowSchema, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome } from "./diagnostics-types-FVf6zjob.js";
2
- import { C as providerErrorMessage, D as onSettingsNamespaceUpdated, E as readCopilotCatalog, O as readConfigValue, S as isAbortError, T as isPluginPreviewProvider, _ as sameCandidates, a as COPILOT_HOSTED_SEARCH_PROVIDER_ID, b as currentSearchSelection, c as applyRequestAuth, d as ANTHROPIC_WEB_SEARCH_TOOL_TYPE, f as GITHUB_COPILOT_CREDENTIAL_KEY$1, g as candidatesForRoute, h as WEB_SEARCH_TOOL_TYPE, i as describeSearchBackend, k as readSettingsNamespace, l as normalizeRequestAuth, m as SearchPlan, n as routeSessionSearch, o as GITHUB_COPILOT_HOSTED_SEARCH_PROVIDER_ID, p as RESPONSES_WEB_SEARCH_TOOL_TYPE, r as DescribedSearchFallbackError, s as createTraditionalSearchProvider, t as isCopilotSearchSelection, u as providerRequestHeaders, v as currentChatRoute, w as readBounded, x as abortable$1, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
3
1
  import { a as GITHUB_COPILOT_PREVIEW_PROVIDER_ID, i as GITHUB_COPILOT_CREDENTIAL_KEY, n as GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID, o as GITHUB_COPILOT_PROVIDER_ID, r as GITHUB_COPILOT_AUTO_MODEL_ID, s as autoModelPreference, t as GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID } from "./copilot-identity-DRZY_d2X.js";
2
+ import { _ as normalizeHighCostModelIds, b as normalizeExcludedModelIds, c as DiagnosticsViewSchema, d as diagnosticsReason, f as AutoAllocationDiagnosticsCollector, g as allocateAutoModel, h as AutoAllocationSchema, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, m as AUTO_ALLOCATION_POLICY, o as DiagnosticsRowSchema, p as emptyAutoAllocationDiagnostics, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome, v as ModelExclusionTurns, y as excludedModelSet } from "./diagnostics-types-Bl3QCfR0.js";
3
+ import { C as providerErrorMessage, D as onSettingsNamespaceUpdated, E as readCopilotCatalog, O as readConfigValue, S as isAbortError, T as isPluginPreviewProvider, _ as sameCandidates, a as COPILOT_HOSTED_SEARCH_PROVIDER_ID, b as currentSearchSelection, c as applyRequestAuth, d as ANTHROPIC_WEB_SEARCH_TOOL_TYPE, f as GITHUB_COPILOT_CREDENTIAL_KEY$1, g as candidatesForRoute, h as WEB_SEARCH_TOOL_TYPE, i as describeSearchBackend, k as readSettingsNamespace, l as normalizeRequestAuth, m as SearchPlan, n as routeSessionSearch, o as GITHUB_COPILOT_HOSTED_SEARCH_PROVIDER_ID, p as RESPONSES_WEB_SEARCH_TOOL_TYPE, r as DescribedSearchFallbackError, s as createTraditionalSearchProvider, t as isCopilotSearchSelection, u as providerRequestHeaders, v as currentChatRoute, w as readBounded, x as abortable$1, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
4
4
  import { a as selectCompactionReasoning, i as resolveRequestBudgetPolicy, n as assessRequestBudget, r as calculateRequestBudget, t as DEFAULT_REQUEST_BUDGET_POLICY } from "./request-budget-DLY_aRq0.js";
5
5
  import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
6
6
  import { z } from "zod";
@@ -37,6 +37,7 @@ function emptyDiagnostics() {
37
37
  updatedAt: 0,
38
38
  rows: [],
39
39
  pending: [],
40
+ autoAllocation: emptyAutoAllocationDiagnostics(),
40
41
  dropped: 0,
41
42
  clientDropped: 0,
42
43
  clientUnconfirmed: 0,
@@ -55,16 +56,21 @@ var DiagnosticsCollector = class {
55
56
  data = emptyDiagnostics();
56
57
  live = /* @__PURE__ */ new Set();
57
58
  enabled = false;
59
+ autoAllocationEnabled = false;
58
60
  lastWall = 0;
61
+ autoAllocation;
59
62
  constructor(version, layer, changed = () => {}, wall = Date.now, mono = () => performance.now()) {
60
63
  this.version = version;
61
64
  this.layer = layer;
62
65
  this.changed = changed;
63
66
  this.wall = wall;
64
67
  this.mono = mono;
68
+ this.autoAllocation = new AutoAllocationDiagnosticsCollector(version, changed, wall);
65
69
  }
66
70
  restore(snapshot) {
67
71
  this.data = DiagnosticsSnapshotSchema.parse(snapshot);
72
+ this.autoAllocation.restore(this.data.autoAllocation ?? emptyAutoAllocationDiagnostics());
73
+ this.data.autoAllocation = this.autoAllocation.snapshot();
68
74
  this.lastWall = this.data.updatedAt;
69
75
  for (const pending of this.data.pending) {
70
76
  this.add(pending.operation, pending.stage, "interrupted", "unknown", pending.bucket, pending.count, pending.version);
@@ -97,6 +103,7 @@ var DiagnosticsCollector = class {
97
103
  const epoch = this.data.epoch + 1;
98
104
  if (!Number.isSafeInteger(epoch)) throw new Error("COPILOT_DIAGNOSTICS_EPOCH_LIMIT");
99
105
  this.live.clear();
106
+ this.autoAllocation.clear();
100
107
  this.data = {
101
108
  ...emptyDiagnostics(),
102
109
  epoch
@@ -204,12 +211,14 @@ var DiagnosticsCollector = class {
204
211
  }
205
212
  return DiagnosticsSnapshotSchema.parse({
206
213
  ...this.data,
214
+ autoAllocation: this.autoAllocation.snapshot(),
207
215
  updatedAt: this.wall(),
208
216
  pending
209
217
  });
210
218
  }
211
219
  close() {
212
220
  this.setEnabled(false);
221
+ this.setAutoAllocationEnabled(false);
213
222
  }
214
223
  noteDropped() {
215
224
  if (this.enabled) {
@@ -223,6 +232,30 @@ var DiagnosticsCollector = class {
223
232
  this.increment("clientUnconfirmed", unconfirmed);
224
233
  if (dropped || unconfirmed) this.changed();
225
234
  }
235
+ recordAutoAllocation(explanation) {
236
+ if (!this.autoAllocationEnabled) return;
237
+ if (explanation.method !== "no-fit" && explanation.method !== "weighted-distribution" && explanation.method !== "only-candidate") return;
238
+ if (explanation.method !== "no-fit" && explanation.allocation === void 0) return;
239
+ const before = this.autoAllocation.snapshot();
240
+ this.autoAllocation.record(explanation);
241
+ const next = this.autoAllocation.snapshot();
242
+ const candidate = {
243
+ ...this.data,
244
+ autoAllocation: next
245
+ };
246
+ if (!DiagnosticsSnapshotSchema.safeParse(candidate).success) {
247
+ this.autoAllocation.restore(before, false);
248
+ this.autoAllocation.setEnabled(this.enabled);
249
+ this.data.saturated = Math.min(Number.MAX_SAFE_INTEGER, this.data.saturated + 1);
250
+ this.changed();
251
+ return;
252
+ }
253
+ this.data.autoAllocation = next;
254
+ }
255
+ setAutoAllocationEnabled(enabled) {
256
+ this.autoAllocationEnabled = enabled;
257
+ this.autoAllocation.setEnabled(enabled);
258
+ }
226
259
  mergeClient(rows) {
227
260
  if (!this.enabled) return;
228
261
  const now = this.wall();
@@ -289,6 +322,15 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
289
322
  codec: strictRemoteCodec("dsh-github-copilot#DiagnosticsEnabled", z.boolean())
290
323
  }]
291
324
  },
325
+ {
326
+ method: "setAutoAllocationEnabled",
327
+ parameters: [{
328
+ name: "enabled",
329
+ wire: "enabled",
330
+ source: "json",
331
+ codec: strictRemoteCodec("dsh-github-copilot#AutoAllocationDiagnosticsEnabled", z.boolean())
332
+ }]
333
+ },
292
334
  {
293
335
  method: "recordClient",
294
336
  parameters: [{
@@ -311,12 +353,12 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
311
353
  var package_default = {
312
354
  name: "dsh-github-copilot",
313
355
  description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
314
- version: "0.4.1",
356
+ version: "0.4.2-alpha.3",
315
357
  releaseNotes: "CHANGELOG.md",
316
358
  publishConfig: {
317
359
  "access": "public",
318
360
  "registry": "https://registry.npmjs.org/",
319
- "tag": "latest"
361
+ "tag": "alpha"
320
362
  },
321
363
  packageManager: "pnpm@11.7.0",
322
364
  repository: {
@@ -607,6 +649,7 @@ let DiagnosticsController = (() => {
607
649
  let _instanceExtraInitializers = [];
608
650
  let _get_decorators;
609
651
  let _setEnabled_decorators;
652
+ let _setAutoAllocationEnabled_decorators;
610
653
  let _clear_decorators;
611
654
  let _recordClient_decorators;
612
655
  return class DiagnosticsController extends _classSuper {
@@ -614,6 +657,7 @@ let DiagnosticsController = (() => {
614
657
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
615
658
  _get_decorators = [Remote];
616
659
  _setEnabled_decorators = [Remote];
660
+ _setAutoAllocationEnabled_decorators = [Remote];
617
661
  _clear_decorators = [Remote];
618
662
  _recordClient_decorators = [Remote];
619
663
  __esDecorate$9(this, null, _get_decorators, {
@@ -638,6 +682,17 @@ let DiagnosticsController = (() => {
638
682
  },
639
683
  metadata: _metadata
640
684
  }, null, _instanceExtraInitializers);
685
+ __esDecorate$9(this, null, _setAutoAllocationEnabled_decorators, {
686
+ kind: "method",
687
+ name: "setAutoAllocationEnabled",
688
+ static: false,
689
+ private: false,
690
+ access: {
691
+ has: (obj) => "setAutoAllocationEnabled" in obj,
692
+ get: (obj) => obj.setAutoAllocationEnabled
693
+ },
694
+ metadata: _metadata
695
+ }, null, _instanceExtraInitializers);
641
696
  __esDecorate$9(this, null, _clear_decorators, {
642
697
  kind: "method",
643
698
  name: "clear",
@@ -672,6 +727,7 @@ let DiagnosticsController = (() => {
672
727
  state = "unavailable";
673
728
  problem = "storage-unavailable";
674
729
  enabled = false;
730
+ autoAllocationEnabled = false;
675
731
  dirty = false;
676
732
  persistedAt;
677
733
  revision = 0;
@@ -688,7 +744,9 @@ let DiagnosticsController = (() => {
688
744
  const readEnabled = () => {
689
745
  const value = ctx.get("settings")?.describe({ redactSecrets: true }).find((row) => row.ns === "github-copilot")?.value;
690
746
  this.enabled = typeof value === "object" && value !== null && "diagnosticsEnabled" in value && value.diagnosticsEnabled === true;
747
+ this.autoAllocationEnabled = typeof value === "object" && value !== null && "autoAllocationDiagnosticsEnabled" in value && value.autoAllocationDiagnosticsEnabled === true;
691
748
  this.collector.setEnabled(this.enabled && this.state === "ready");
749
+ this.collector.setAutoAllocationEnabled(this.autoAllocationEnabled && this.state === "ready");
692
750
  if (!this.enabled) this.brackets.clear();
693
751
  };
694
752
  ctx.inject(["settings"], (scope) => {
@@ -718,6 +776,7 @@ let DiagnosticsController = (() => {
718
776
  this.state = "error";
719
777
  this.problem = error instanceof Error && error.message === "COPILOT_DIAGNOSTICS_PROFILE_UNAVAILABLE" ? "profile-unavailable" : typeof error === "object" && error !== null && "code" in error && (error.code === "invalid-record" || error.code === "malformed-medium" || error.code === "version-mismatch") ? "storage-invalid" : "storage-unavailable";
720
778
  this.collector.setEnabled(false);
779
+ this.collector.setAutoAllocationEnabled(false);
721
780
  ctx.logger.warn("[github-copilot] COPILOT_DIAGNOSTICS_STORAGE_UNAVAILABLE");
722
781
  }
723
782
  if (this.closed) return;
@@ -814,6 +873,7 @@ let DiagnosticsController = (() => {
814
873
  get() {
815
874
  return {
816
875
  enabled: this.enabled,
876
+ autoAllocationEnabled: this.autoAllocationEnabled,
817
877
  state: this.state,
818
878
  diagnostic: this.problem,
819
879
  ...this.persistedAt === void 0 ? {} : { persistedAt: this.persistedAt },
@@ -846,6 +906,30 @@ let DiagnosticsController = (() => {
846
906
  this.settingsBusy = false;
847
907
  }
848
908
  }
909
+ async setAutoAllocationEnabled(enabled) {
910
+ if (typeof enabled !== "boolean") throw new Error("COPILOT_DIAGNOSTICS_INVALID_CONTROL");
911
+ if (this.settingsBusy) throw new Error("COPILOT_DIAGNOSTICS_CONTROL_BUSY");
912
+ if (enabled && !this.domain) throw new Error("COPILOT_DIAGNOSTICS_STORAGE_UNAVAILABLE");
913
+ this.settingsBusy = true;
914
+ try {
915
+ const settings = this.ctx.get("settings");
916
+ const row = settings?.describe({ redactSecrets: true }).find((item) => item.ns === "github-copilot");
917
+ if (!settings || !row) throw new Error("COPILOT_DIAGNOSTICS_SETTINGS_UNAVAILABLE");
918
+ await settings.mutate("github-copilot", [{
919
+ op: "set",
920
+ path: ["autoAllocationDiagnosticsEnabled"],
921
+ value: enabled
922
+ }], row.revision);
923
+ const saved = settings.describe({ redactSecrets: true }).find((item) => item.ns === "github-copilot")?.value;
924
+ if (typeof saved !== "object" || saved === null || !("autoAllocationDiagnosticsEnabled" in saved) || saved.autoAllocationDiagnosticsEnabled !== enabled) throw new Error("COPILOT_DIAGNOSTICS_SETTINGS_COMMIT_UNCERTAIN");
925
+ this.autoAllocationEnabled = enabled;
926
+ this.collector.setAutoAllocationEnabled(enabled && this.state === "ready");
927
+ await this.flush();
928
+ return this.get();
929
+ } finally {
930
+ this.settingsBusy = false;
931
+ }
932
+ }
849
933
  async clear() {
850
934
  if (!this.domain) throw new Error("COPILOT_DIAGNOSTICS_STORAGE_UNAVAILABLE");
851
935
  this.collector.clear();
@@ -6899,6 +6983,7 @@ function readInlineConfig(config) {
6899
6983
  return {
6900
6984
  ...config,
6901
6985
  diagnosticsEnabled: readConfigValue(config.diagnosticsEnabled),
6986
+ autoAllocationDiagnosticsEnabled: readConfigValue(config.autoAllocationDiagnosticsEnabled),
6902
6987
  continuationDefaultHistory: defaults === void 0 ? void 0 : Array.from(defaults, (row) => ({
6903
6988
  enabled: row.enabled,
6904
6989
  changedAt: row.changedAt
@@ -6931,6 +7016,7 @@ const MAX_TIMEOUT_MS = 2147483647;
6931
7016
  /** Schema of the plugin's settings section. */
6932
7017
  const Config = z$1.object({
6933
7018
  diagnosticsEnabled: z$1.boolean().default(false).hidden().volatile(),
7019
+ autoAllocationDiagnosticsEnabled: z$1.boolean().default(false).hidden().volatile(),
6934
7020
  enabled: z$1.boolean().default(true),
6935
7021
  providers: z$1.array(z$1.string()).default([]),
6936
7022
  includeSources: z$1.boolean().default(true),
@@ -8951,112 +9037,6 @@ function wholeProfileOwned(snapshot, backup) {
8951
9037
  ...Object.keys(backup.ownedHeaders).length === 0 ? {} : { headers: backup.ownedHeaders }
8952
9038
  });
8953
9039
  }
8954
- const MAX_MODEL_ID_LENGTH = 512;
8955
- /** Admission is bound to the native turn and its request signal, not the global picker. */
8956
- var ModelExclusionTurns = class {
8957
- turns = /* @__PURE__ */ new WeakMap();
8958
- signals = /* @__PURE__ */ new WeakMap();
8959
- admit(owner, turn, model, signal, excluded) {
8960
- const previous = this.turns.get(owner);
8961
- if (signal.aborted || excluded.has(model) && (previous?.turn !== turn || previous.model !== model)) {
8962
- if (previous?.turn !== turn) this.turns.delete(owner);
8963
- return false;
8964
- }
8965
- this.turns.set(owner, {
8966
- turn,
8967
- model
8968
- });
8969
- this.signals.set(signal, {
8970
- owner,
8971
- turn,
8972
- model
8973
- });
8974
- return true;
8975
- }
8976
- permits(signal, model) {
8977
- if (signal === void 0 || signal.aborted) return false;
8978
- const admitted = this.signals.get(signal);
8979
- if (admitted?.model !== model) return false;
8980
- const current = this.turns.get(admitted.owner);
8981
- return current?.turn === admitted.turn && current.model === model;
8982
- }
8983
- end(owner) {
8984
- this.turns.delete(owner);
8985
- }
8986
- };
8987
- function normalizeExcludedModelIds(value) {
8988
- if (value === void 0) return [];
8989
- if (!Array.isArray(value) || value.length > 512) throw new Error("COPILOT_MODEL_EXCLUSIONS_INVALID");
8990
- const ids = /* @__PURE__ */ new Set();
8991
- for (const candidate of value) {
8992
- if (typeof candidate !== "string" || candidate.length === 0 || candidate.length > MAX_MODEL_ID_LENGTH || candidate.trim() !== candidate || autoModelPreference(candidate) !== void 0) throw new Error("COPILOT_MODEL_EXCLUSIONS_INVALID");
8993
- ids.add(candidate);
8994
- }
8995
- return [...ids].toSorted();
8996
- }
8997
- function excludedModelSet(value) {
8998
- return new Set(normalizeExcludedModelIds(value));
8999
- }
9000
- //#endregion
9001
- //#region lib/types/auto-allocation.js
9002
- const AUTO_ALLOCATION_POLICY = "high-cost-v1";
9003
- const AutoAllocationSchema = z.object({
9004
- policyVersion: z.literal(AUTO_ALLOCATION_POLICY),
9005
- selectedModelId: z.string().min(1).max(512),
9006
- candidates: z.array(z.object({
9007
- modelId: z.string().min(1).max(512),
9008
- highCost: z.boolean(),
9009
- previous: z.boolean(),
9010
- weight: z.number().positive().max(1.5),
9011
- expectedShare: z.number().positive().max(1)
9012
- }).strict()).min(1).max(512)
9013
- }).strict().refine((value) => {
9014
- const total = value.candidates.reduce((sum, row) => sum + row.weight, 0);
9015
- return new Set(value.candidates.map((row) => row.modelId)).size === value.candidates.length && value.candidates.some((row) => row.modelId === value.selectedModelId) && value.candidates.filter((row) => row.previous).length <= 1 && value.candidates.every((row) => row.weight === (row.highCost ? 2 : 10) * (row.previous ? 1.5 : 1) / 10 && Math.abs(row.expectedShare - row.weight / total) <= 1e-12);
9016
- }, { message: "Invalid allocation policy evidence" });
9017
- function normalizeHighCostModelIds(value) {
9018
- try {
9019
- return normalizeExcludedModelIds(value);
9020
- } catch (cause) {
9021
- if (cause instanceof Error && cause.message === "COPILOT_MODEL_EXCLUSIONS_INVALID") throw new Error("COPILOT_HIGH_COST_MODELS_INVALID");
9022
- throw cause;
9023
- }
9024
- }
9025
- /** Integer policy units avoid cumulative decimal drift; avalanche sequential turn seeds. */
9026
- function allocateAutoModel(pool, highCostModelIds, previousModelId, seed) {
9027
- if (!Number.isSafeInteger(seed) || pool.length === 0 || pool.length > 512 || normalizeExcludedModelIds(pool.map((model) => model.id)).length !== pool.length) throw new Error("COPILOT_AUTO_ALLOCATION_INVALID");
9028
- const marked = new Set(normalizeHighCostModelIds(highCostModelIds));
9029
- const rows = pool.map((model) => {
9030
- const highCost = marked.has(model.id);
9031
- const previous = model.id === previousModelId;
9032
- const units = (highCost ? 2 : 10) * (previous ? 1.5 : 1);
9033
- return {
9034
- modelId: model.id,
9035
- highCost,
9036
- previous,
9037
- units
9038
- };
9039
- });
9040
- const total = rows.reduce((sum, row) => sum + row.units, 0);
9041
- let hash = seed >>> 0;
9042
- hash = Math.imul(hash ^ hash >>> 16, 2246822507);
9043
- hash = Math.imul(hash ^ hash >>> 13, 3266489909);
9044
- const point = ((hash ^ hash >>> 16) >>> 0) / 4294967296 * total;
9045
- let boundary = 0;
9046
- const selected = rows.find((row) => {
9047
- boundary += row.units;
9048
- return point < boundary;
9049
- });
9050
- return Object.freeze({
9051
- policyVersion: AUTO_ALLOCATION_POLICY,
9052
- selectedModelId: selected.modelId,
9053
- candidates: Object.freeze(rows.map(({ units, ...row }) => Object.freeze({
9054
- ...row,
9055
- weight: units / 10,
9056
- expectedShare: units / total
9057
- })))
9058
- });
9059
- }
9060
9040
  //#endregion
9061
9041
  //#region lib/types/authorization-controller.js
9062
9042
  /**
@@ -11796,8 +11776,12 @@ z.discriminatedUnion("mode", [
11796
11776
  ]);
11797
11777
  /** Ephemeral decision evidence only; never session content, model usage or credentials. */
11798
11778
  var TurnSelectionStore = class {
11779
+ onAutoDecision;
11799
11780
  agents = /* @__PURE__ */ new Map();
11800
11781
  timestamps = /* @__PURE__ */ new WeakMap();
11782
+ constructor(onAutoDecision) {
11783
+ this.onAutoDecision = onAutoDecision;
11784
+ }
11801
11785
  record(agent, turn, selection) {
11802
11786
  if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_TURN_SELECTION_INVALID_TURN");
11803
11787
  let turns = this.agents.get(agent);
@@ -11829,6 +11813,7 @@ var TurnSelectionStore = class {
11829
11813
  })
11830
11814
  }) }
11831
11815
  }));
11816
+ if (explanation !== void 0) this.onAutoDecision?.(explanation);
11832
11817
  }
11833
11818
  if (turns.size > 128) {
11834
11819
  const oldest = turns.keys().next().value;
@@ -12374,7 +12359,13 @@ function actualNotice(agent, model) {
12374
12359
  }
12375
12360
  /** Resolve virtual Auto once per Core turn before request/header persistence. */
12376
12361
  function installAutoModelRouting(ctx, dependencies) {
12377
- const selections = new TurnSelectionStore();
12362
+ const selections = new TurnSelectionStore((explanation) => {
12363
+ try {
12364
+ ctx.get("githubCopilotDiagnostics")?.collector.recordAutoAllocation(explanation);
12365
+ } catch {
12366
+ ctx.logger.warn("[github-copilot] COPILOT_AUTO_ALLOCATION_DIAGNOSTICS_UNAVAILABLE");
12367
+ }
12368
+ });
12378
12369
  new TurnSelectionController(ctx, selections);
12379
12370
  const captured = /* @__PURE__ */ new WeakMap();
12380
12371
  const routed = /* @__PURE__ */ new WeakMap();
@@ -1,5 +1,5 @@
1
- import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-FVf6zjob.js";
2
1
  import "./copilot-identity-DRZY_d2X.js";
2
+ import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-Bl3QCfR0.js";
3
3
  import { i as resolveRequestBudgetPolicy, r as calculateRequestBudget } from "./request-budget-DLY_aRq0.js";
4
4
  import z from "@deepseek-ai/schemastery";
5
5
  import { LlmError, createUserMessage } from "@deepseek-ai/dsh-llm";
package/lib/remote.js CHANGED
@@ -761,6 +761,81 @@ const contribution$2 = {
761
761
  }))
762
762
  };
763
763
  //#endregion
764
+ //#region lib/types/auto-allocation-diagnostics.js
765
+ const AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS = 1024;
766
+ const dayMs = 864e5;
767
+ const integer$1 = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
768
+ const version$1 = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
769
+ const allocationRow = z.object({
770
+ day: integer$1.multipleOf(dayMs),
771
+ version: version$1,
772
+ policyVersion: z.string().min(1).max(64),
773
+ modelId: z.string().min(1).max(512),
774
+ targetCategory: z.enum([
775
+ "powerful",
776
+ "versatile",
777
+ "lightweight"
778
+ ]),
779
+ category: z.enum([
780
+ "powerful",
781
+ "versatile",
782
+ "lightweight",
783
+ "unknown"
784
+ ]),
785
+ demand: z.enum([
786
+ "simple",
787
+ "routine",
788
+ "complex",
789
+ "unknown"
790
+ ]),
791
+ assessmentSource: z.enum(["local", "semantic"]),
792
+ method: z.enum(["weighted-distribution", "only-candidate"]),
793
+ fallback: z.boolean(),
794
+ highCost: z.boolean(),
795
+ previous: z.boolean(),
796
+ weight: z.number().positive().max(1.5),
797
+ opportunities: integer$1.min(1),
798
+ expectedSelections: z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER),
799
+ selections: integer$1
800
+ }).strict();
801
+ const noFitRow = z.object({
802
+ day: integer$1.multipleOf(dayMs),
803
+ version: version$1,
804
+ policyVersion: z.string().min(1).max(64),
805
+ targetCategory: z.enum([
806
+ "powerful",
807
+ "versatile",
808
+ "lightweight"
809
+ ]),
810
+ category: z.enum([
811
+ "powerful",
812
+ "versatile",
813
+ "lightweight",
814
+ "unknown"
815
+ ]),
816
+ demand: z.enum([
817
+ "simple",
818
+ "routine",
819
+ "complex",
820
+ "unknown"
821
+ ]),
822
+ assessmentSource: z.enum(["local", "semantic"]),
823
+ decisions: integer$1.min(1)
824
+ }).strict();
825
+ const AutoAllocationDiagnosticsSchema = z.object({
826
+ status: z.enum(["observed", "not-collected"]),
827
+ rows: z.array(allocationRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
828
+ noFitRows: z.array(noFitRow).max(AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS),
829
+ observationStart: integer$1.nullable(),
830
+ observationEnd: integer$1.nullable(),
831
+ completeHistory: z.literal(false),
832
+ rowsTruncated: z.boolean(),
833
+ dropped: integer$1,
834
+ expired: integer$1,
835
+ saturated: integer$1,
836
+ restarts: integer$1
837
+ }).strict().refine((value) => JSON.stringify(value).length <= 15e5, "Auto allocation diagnostic capacity exceeded").refine((value) => value.rows.length + value.noFitRows.length <= AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS, "Auto allocation row capacity exceeded").refine(({ observationStart, observationEnd }) => observationStart === null ? observationEnd === null : observationEnd !== null && observationEnd >= observationStart, "Auto allocation observation window is inconsistent");
838
+ //#endregion
764
839
  //#region lib/types/diagnostics-types.js
765
840
  const DIAGNOSTICS_OPERATIONS = [
766
841
  "account-global-switch",
@@ -867,6 +942,7 @@ const DiagnosticsSnapshotSchema = z.object({
867
942
  epoch: integer,
868
943
  updatedAt: integer,
869
944
  rows: z.array(DiagnosticsRowSchema).max(DIAGNOSTICS_MAX_ROWS),
945
+ autoAllocation: AutoAllocationDiagnosticsSchema.optional(),
870
946
  pending: z.array(DiagnosticsPendingSchema).max(128),
871
947
  dropped: integer,
872
948
  clientDropped: integer,
@@ -877,6 +953,7 @@ const DiagnosticsSnapshotSchema = z.object({
877
953
  }).strict().refine((value) => value.pending.reduce((sum, row) => sum + row.count, 0) <= 128, "Diagnostics pending capacity exceeded").refine((value) => JSON.stringify(value).length <= DIAGNOSTICS_MAX_BYTES, "Diagnostics capacity exceeded");
878
954
  const DiagnosticsViewSchema = z.object({
879
955
  enabled: z.boolean(),
956
+ autoAllocationEnabled: z.boolean(),
880
957
  state: z.enum([
881
958
  "loading",
882
959
  "ready",
@@ -928,6 +1005,15 @@ const contribution$1 = {
928
1005
  codec: strictRemoteCodec("dsh-github-copilot#DiagnosticsEnabled", z.boolean())
929
1006
  }]
930
1007
  },
1008
+ {
1009
+ method: "setAutoAllocationEnabled",
1010
+ parameters: [{
1011
+ name: "enabled",
1012
+ wire: "enabled",
1013
+ source: "json",
1014
+ codec: strictRemoteCodec("dsh-github-copilot#AutoAllocationDiagnosticsEnabled", z.boolean())
1015
+ }]
1016
+ },
931
1017
  {
932
1018
  method: "recordClient",
933
1019
  parameters: [{
package/lib/routed-web.js CHANGED
@@ -1,5 +1,5 @@
1
- import { T as isPluginPreviewProvider, b as currentSearchSelection, t as isCopilotSearchSelection, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
2
1
  import "./copilot-identity-DRZY_d2X.js";
2
+ import { T as isPluginPreviewProvider, b as currentSearchSelection, t as isCopilotSearchSelection, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
3
3
  import { WebError, WebRuntime } from "@deepseek-ai/dsh-web";
4
4
  //#region lib/types/routed-web.js
5
5
  /**
@@ -0,0 +1,102 @@
1
+ import { z } from 'zod';
2
+ import type { AutoSelectionExplanation } from './auto-model-routing.ts';
3
+ export declare const AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS = 1024;
4
+ export declare const AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS: number;
5
+ export declare const AutoAllocationDiagnosticsSchema: z.ZodObject<{
6
+ status: z.ZodEnum<{
7
+ observed: "observed";
8
+ "not-collected": "not-collected";
9
+ }>;
10
+ rows: z.ZodArray<z.ZodObject<{
11
+ day: z.ZodNumber;
12
+ version: z.ZodString;
13
+ policyVersion: z.ZodString;
14
+ modelId: z.ZodString;
15
+ targetCategory: z.ZodEnum<{
16
+ powerful: "powerful";
17
+ versatile: "versatile";
18
+ lightweight: "lightweight";
19
+ }>;
20
+ category: z.ZodEnum<{
21
+ unknown: "unknown";
22
+ powerful: "powerful";
23
+ versatile: "versatile";
24
+ lightweight: "lightweight";
25
+ }>;
26
+ demand: z.ZodEnum<{
27
+ unknown: "unknown";
28
+ simple: "simple";
29
+ routine: "routine";
30
+ complex: "complex";
31
+ }>;
32
+ assessmentSource: z.ZodEnum<{
33
+ local: "local";
34
+ semantic: "semantic";
35
+ }>;
36
+ method: z.ZodEnum<{
37
+ "weighted-distribution": "weighted-distribution";
38
+ "only-candidate": "only-candidate";
39
+ }>;
40
+ fallback: z.ZodBoolean;
41
+ highCost: z.ZodBoolean;
42
+ previous: z.ZodBoolean;
43
+ weight: z.ZodNumber;
44
+ opportunities: z.ZodNumber;
45
+ expectedSelections: z.ZodNumber;
46
+ selections: z.ZodNumber;
47
+ }, z.core.$strict>>;
48
+ noFitRows: z.ZodArray<z.ZodObject<{
49
+ day: z.ZodNumber;
50
+ version: z.ZodString;
51
+ policyVersion: z.ZodString;
52
+ targetCategory: z.ZodEnum<{
53
+ powerful: "powerful";
54
+ versatile: "versatile";
55
+ lightweight: "lightweight";
56
+ }>;
57
+ category: z.ZodEnum<{
58
+ unknown: "unknown";
59
+ powerful: "powerful";
60
+ versatile: "versatile";
61
+ lightweight: "lightweight";
62
+ }>;
63
+ demand: z.ZodEnum<{
64
+ unknown: "unknown";
65
+ simple: "simple";
66
+ routine: "routine";
67
+ complex: "complex";
68
+ }>;
69
+ assessmentSource: z.ZodEnum<{
70
+ local: "local";
71
+ semantic: "semantic";
72
+ }>;
73
+ decisions: z.ZodNumber;
74
+ }, z.core.$strict>>;
75
+ observationStart: z.ZodNullable<z.ZodNumber>;
76
+ observationEnd: z.ZodNullable<z.ZodNumber>;
77
+ completeHistory: z.ZodLiteral<false>;
78
+ rowsTruncated: z.ZodBoolean;
79
+ dropped: z.ZodNumber;
80
+ expired: z.ZodNumber;
81
+ saturated: z.ZodNumber;
82
+ restarts: z.ZodNumber;
83
+ }, z.core.$strict>;
84
+ export type AutoAllocationDiagnostics = z.infer<typeof AutoAllocationDiagnosticsSchema>;
85
+ export declare function emptyAutoAllocationDiagnostics(): AutoAllocationDiagnostics;
86
+ /** Profile-local rolling aggregates; no per-turn, Session, prompt, or outcome records. */
87
+ export declare class AutoAllocationDiagnosticsCollector {
88
+ private readonly version;
89
+ private readonly changed;
90
+ private readonly wall;
91
+ private data;
92
+ private enabled;
93
+ constructor(version: string, changed?: () => void, wall?: () => number);
94
+ restore(value: unknown, countRestart?: boolean): void;
95
+ setEnabled(enabled: boolean): void;
96
+ clear(): void;
97
+ record(explanation: AutoSelectionExplanation): void;
98
+ snapshot(): AutoAllocationDiagnostics;
99
+ private expire;
100
+ private add;
101
+ }
102
+ //# sourceMappingURL=auto-allocation-diagnostics.d.ts.map
@@ -40,7 +40,7 @@ export declare const compactionContinuationDefinition: {
40
40
  export declare function installCompactionContinuation(ctx: Context, enabled: (agent: Agent) => boolean): {
41
41
  status(agent: Agent): {
42
42
  id: string;
43
- state: "running" | "cancelled" | "failed" | "completed" | "blocked";
43
+ state: "running" | "failed" | "cancelled" | "completed" | "blocked";
44
44
  } | undefined;
45
45
  prepare(request: GenerateOptions): ((payload: unknown) => Promise<unknown>) | undefined;
46
46
  dispose(): void;
@@ -14,6 +14,8 @@ import type { SessionContinuationPreference } from './session-continuation-types
14
14
  export interface InlineConfig {
15
15
  /** Opt-in local aggregate diagnostics; no uploads or scheduled analysis. */
16
16
  diagnosticsEnabled?: boolean;
17
+ /** Independent opt-in persistence of Auto allocation aggregates. */
18
+ autoAllocationDiagnosticsEnabled?: boolean;
17
19
  /** Hosted-search switch; managed chat requests remain enabled. */
18
20
  enabled: boolean;
19
21
  /**
@@ -84,7 +86,7 @@ export interface InlineConfig {
84
86
  /** Internal JSON backup of route leaves temporarily owned by the GPT-6 overlay. */
85
87
  temporaryRouteBackup?: string;
86
88
  }
87
- export type LiveInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'searchModel' | 'searchRouting' | 'temporaryRouteBackup' | 'excludedModelIds' | 'highCostModelIds' | 'parentModelFollow' | 'followParentModel' | 'activeAccountId' | 'sessionAccounts' | 'sessionContinuation' | 'continuationDefaultHistory'> & {
89
+ export type LiveInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'autoAllocationDiagnosticsEnabled' | 'searchModel' | 'searchRouting' | 'temporaryRouteBackup' | 'excludedModelIds' | 'highCostModelIds' | 'parentModelFollow' | 'followParentModel' | 'activeAccountId' | 'sessionAccounts' | 'sessionContinuation' | 'continuationDefaultHistory'> & {
88
90
  continuationDefaultHistory?: InlineConfig['continuationDefaultHistory'] | LiveSetting<ArrayLike<{
89
91
  enabled: boolean;
90
92
  changedAt: number;
@@ -92,6 +94,7 @@ export type LiveInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'search
92
94
  sessionContinuation?: SessionContinuationPreference[] | LiveSetting<ArrayLike<SessionContinuationPreference>>;
93
95
  sessionAccounts?: SessionAccountPreference[] | LiveSetting<ArrayLike<SessionAccountPreference>>;
94
96
  diagnosticsEnabled?: boolean | LiveSetting<boolean>;
97
+ autoAllocationDiagnosticsEnabled?: boolean | LiveSetting<boolean>;
95
98
  activeAccountId?: string | LiveSetting<string | undefined>;
96
99
  followParentModel?: boolean | LiveSetting<boolean>;
97
100
  parentModelFollow?: ParentModelBinding[] | LiveSetting<ArrayLike<ParentModelBinding>>;
@@ -101,8 +104,9 @@ export type LiveInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'search
101
104
  searchRouting?: WebSearchRoutingConfig | LiveSetting<WebSearchRoutingConfig | undefined>;
102
105
  temporaryRouteBackup?: string | LiveSetting<string | undefined>;
103
106
  };
104
- export type ResolvedInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'searchModel' | 'searchRouting' | 'temporaryRouteBackup' | 'excludedModelIds' | 'highCostModelIds' | 'parentModelFollow' | 'followParentModel' | 'activeAccountId' | 'sessionAccounts' | 'sessionContinuation' | 'continuationDefaultHistory'> & {
107
+ export type ResolvedInlineConfig = Omit<InlineConfig, 'diagnosticsEnabled' | 'autoAllocationDiagnosticsEnabled' | 'searchModel' | 'searchRouting' | 'temporaryRouteBackup' | 'excludedModelIds' | 'highCostModelIds' | 'parentModelFollow' | 'followParentModel' | 'activeAccountId' | 'sessionAccounts' | 'sessionContinuation' | 'continuationDefaultHistory'> & {
105
108
  diagnosticsEnabled: LiveSetting<boolean>;
109
+ autoAllocationDiagnosticsEnabled: LiveSetting<boolean>;
106
110
  continuationDefaultHistory: LiveSetting<ArrayLike<{
107
111
  enabled: boolean;
108
112
  changedAt: number;