dsh-github-copilot 0.4.0-alpha.51 → 0.4.0-alpha.53

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
@@ -1622,7 +1622,7 @@ let GitHubCopilotUsageController = (() => {
1622
1622
  //#endregion
1623
1623
  //#region package.json
1624
1624
  var name$1 = "dsh-github-copilot";
1625
- var version = "0.4.0-alpha.51";
1625
+ var version = "0.4.0-alpha.53";
1626
1626
  //#endregion
1627
1627
  //#region lib/types/probe.js
1628
1628
  /**
@@ -6164,22 +6164,180 @@ function reasonFor(features) {
6164
6164
  if (features.taskClass === "strong") return "large-structured-turn";
6165
6165
  return "standard-turn";
6166
6166
  }
6167
+ function estimateTurnInputTokens(messages) {
6168
+ let fresh = 0;
6169
+ for (const message of messages) if (typeof message === "object" && message !== null) try {
6170
+ fresh += estimateMessageTokens(message);
6171
+ } catch {}
6172
+ let contextTokens = 0;
6173
+ try {
6174
+ contextTokens = estimateContextTokens(messages).tokens;
6175
+ } catch {}
6176
+ const estimated = Math.max(fresh, contextTokens);
6177
+ if (estimated > 0) return estimated;
6178
+ let charCount = 0;
6179
+ for (const message of messages) if (record$1(message) && Array.isArray(message.content)) {
6180
+ for (const block of message.content) if (record$1(block) && typeof block.text === "string") charCount += block.text.length;
6181
+ }
6182
+ return charCount > 0 ? Math.ceil(charCount / 4) : 0;
6183
+ }
6184
+ function latestUserTurnTokens(messages) {
6185
+ for (let index = messages.length - 1; index >= 0; index--) {
6186
+ const message = messages[index];
6187
+ if (userMessage(message)) {
6188
+ try {
6189
+ const est = estimateMessageTokens(message);
6190
+ if (est > 0) return est;
6191
+ } catch {}
6192
+ if (Array.isArray(message.content)) {
6193
+ let chars = 0;
6194
+ for (const block of message.content) if (record$1(block) && typeof block.text === "string") chars += block.text.length;
6195
+ if (chars > 0) return Math.ceil(chars / 4);
6196
+ }
6197
+ }
6198
+ }
6199
+ return 0;
6200
+ }
6201
+ function candidateInputLimit(model, requestedMaxTokens, policy = DEFAULT_REQUEST_BUDGET_POLICY) {
6202
+ const result = calculateRequestBudget(model, requestedMaxTokens, policy);
6203
+ return result.ok ? result.budget.hardInputLimit : 0;
6204
+ }
6205
+ function fnv1a(str) {
6206
+ let hash = 2166136261;
6207
+ for (let i = 0; i < str.length; i++) {
6208
+ hash ^= str.charCodeAt(i);
6209
+ hash = Math.imul(hash, 16777619);
6210
+ }
6211
+ return hash >>> 0;
6212
+ }
6213
+ function resolveSeed(messages, context) {
6214
+ if (typeof context?.seed === "number" && Number.isSafeInteger(context.seed)) return Math.abs(context.seed);
6215
+ if (typeof context?.seed === "string" && context.seed.length > 0) return fnv1a(context.seed);
6216
+ if (context?.sessionId !== void 0) return fnv1a(`${context.sessionId}:${context.turn ?? 1}`);
6217
+ let text = "";
6218
+ for (const block of latestUserContent(messages)) if (record$1(block) && typeof block.text === "string") text += block.text;
6219
+ return fnv1a(text || "default-auto-seed");
6220
+ }
6221
+ function pickBandIndex(n, taskClass, preference, seed) {
6222
+ if (n <= 1) return 0;
6223
+ const middle = Math.floor((n - 1) / 2);
6224
+ if (n === 2) {
6225
+ if (taskClass === "fast") return preference === "intelligence" ? 1 : 0;
6226
+ if (taskClass === "strong") return 1;
6227
+ return preference === "efficiency" ? 0 : 1;
6228
+ }
6229
+ let start;
6230
+ let end;
6231
+ let bias;
6232
+ if (taskClass === "fast") {
6233
+ if (preference === "intelligence") {
6234
+ start = Math.max(0, middle - 1);
6235
+ end = Math.min(n - 1, Math.max(1, middle));
6236
+ bias = "high";
6237
+ } else {
6238
+ start = 0;
6239
+ end = 0;
6240
+ bias = "low";
6241
+ }
6242
+ } else if (taskClass === "strong") {
6243
+ if (preference === "efficiency") {
6244
+ start = Math.min(n - 1, Math.max(1, middle));
6245
+ end = start;
6246
+ bias = "center";
6247
+ } else if (preference === "balance") {
6248
+ start = Math.min(n - 1, Math.max(1, middle));
6249
+ end = n - 1;
6250
+ bias = "high";
6251
+ } else {
6252
+ const upperCount = Math.max(2, Math.min(3, Math.ceil(n / 2)));
6253
+ start = Math.max(1, n - upperCount);
6254
+ end = n - 1;
6255
+ bias = "high";
6256
+ }
6257
+ } else if (preference === "efficiency") {
6258
+ const lowerCount = Math.max(1, Math.min(2, Math.floor(n / 3)));
6259
+ start = 0;
6260
+ end = lowerCount - 1;
6261
+ bias = "low";
6262
+ } else if (preference === "intelligence") {
6263
+ const upperCount = Math.max(2, Math.min(3, Math.ceil(n / 2)));
6264
+ start = Math.max(1, n - upperCount);
6265
+ end = n - 1;
6266
+ bias = "high";
6267
+ } else {
6268
+ const spread = n >= 5 ? 1 : 0;
6269
+ start = Math.max(0, middle - spread);
6270
+ end = Math.min(n - 1, middle + spread);
6271
+ bias = "center";
6272
+ }
6273
+ const bandSize = end - start + 1;
6274
+ if (bandSize <= 1) return start;
6275
+ const weights = [];
6276
+ for (let i = 0; i < bandSize; i++) if (bias === "high") weights.push(i + 1);
6277
+ else if (bias === "low") weights.push(bandSize - i);
6278
+ else {
6279
+ const dist = Math.abs(i - Math.floor((bandSize - 1) / 2));
6280
+ weights.push(bandSize - dist);
6281
+ }
6282
+ const offset = seed % weights.reduce((sum, w) => sum + w, 0);
6283
+ let accumulated = 0;
6284
+ for (let i = 0; i < bandSize; i++) {
6285
+ accumulated += weights[i];
6286
+ if (offset < accumulated) return start + i;
6287
+ }
6288
+ return end;
6289
+ }
6167
6290
  /**
6168
- * MVP policy: filter only by account-verified hard capabilities, then choose a
6169
- * deterministic capacity tier. Capacity is not a quality, latency or price claim.
6291
+ * Filter by hard capabilities and input headroom before soft preference.
6292
+ * Soft preferences distribute across capacity bands using in-memory deterministic seeds.
6293
+ * Preserves Core compaction ownership if no candidate currently fits.
6170
6294
  */
6171
- function selectAutoModel(models, messages, preference = "balance") {
6295
+ function selectAutoModel(models, messages, preference = "balance", context) {
6172
6296
  const features = classifyAutoModelTurn(messages);
6173
6297
  const eligible = models.filter((model) => autoModelPreference(model.id) === void 0 && model.input.includes("text") && (!features.requiresImage || model.input.includes("image"))).toSorted(compareCapacity);
6174
6298
  if (eligible.length === 0) throw new AutoModelRoutingError("COPILOT_AUTO_NO_ELIGIBLE_MODEL");
6175
- const middle = Math.floor((eligible.length - 1) / 2);
6176
- const index = features.taskClass === "fast" ? preference === "intelligence" ? middle : 0 : features.taskClass === "strong" ? preference === "efficiency" ? Math.min(eligible.length - 1, Math.max(1, middle)) : eligible.length - 1 : preference === "efficiency" ? 0 : preference === "intelligence" ? eligible.length - 1 : middle;
6299
+ const estimatedInputTokens = estimateTurnInputTokens(messages);
6300
+ const requestedMaxTokens = context?.requestedMaxTokens;
6301
+ const policy = context?.requestBudgetPolicy ?? DEFAULT_REQUEST_BUDGET_POLICY;
6302
+ const fitting = eligible.filter((model) => {
6303
+ const limit = candidateInputLimit(model, requestedMaxTokens, policy);
6304
+ return limit > 0 && estimatedInputTokens <= limit;
6305
+ });
6306
+ const seed = resolveSeed(messages, context);
6307
+ let selectedModel;
6308
+ let inputFitDiagnostic;
6309
+ let selectedInputBudget;
6310
+ if (fitting.length > 0) {
6311
+ selectedModel = fitting[pickBandIndex(fitting.length, features.taskClass, preference, seed)];
6312
+ selectedInputBudget = candidateInputLimit(selectedModel, requestedMaxTokens, policy);
6313
+ inputFitDiagnostic = "fitting-candidate-selected";
6314
+ } else {
6315
+ let maxModel = eligible[0];
6316
+ let maxLimit = candidateInputLimit(maxModel, requestedMaxTokens, policy);
6317
+ for (let i = 1; i < eligible.length; i++) {
6318
+ const limit = candidateInputLimit(eligible[i], requestedMaxTokens, policy);
6319
+ if (limit > maxLimit) {
6320
+ maxLimit = limit;
6321
+ maxModel = eligible[i];
6322
+ }
6323
+ }
6324
+ selectedModel = maxModel;
6325
+ selectedInputBudget = maxLimit;
6326
+ if (latestUserTurnTokens(messages) > maxLimit) inputFitDiagnostic = "fixed-content-cannot-fit";
6327
+ else if (context?.compactionAvailable === false) inputFitDiagnostic = "compaction-unavailable";
6328
+ else if (context?.hasCompactionSummary === true) inputFitDiagnostic = "attempted-but-still-oversized";
6329
+ else inputFitDiagnostic = "compaction-eligible";
6330
+ }
6177
6331
  return Object.freeze({
6178
- model: eligible[index],
6332
+ model: selectedModel,
6179
6333
  preference,
6180
6334
  taskClass: features.taskClass,
6181
6335
  reason: reasonFor(features),
6182
- candidateCount: eligible.length
6336
+ candidateCount: eligible.length,
6337
+ fittingCandidateCount: fitting.length,
6338
+ estimatedInputTokens,
6339
+ selectedInputBudget,
6340
+ inputFitDiagnostic
6183
6341
  });
6184
6342
  }
6185
6343
  function autoModelInputModalities(models) {
@@ -6190,9 +6348,9 @@ function autoModelInputModalities(models) {
6190
6348
  function failure$1(code) {
6191
6349
  return new LlmError(code, "INVALID_REQUEST");
6192
6350
  }
6193
- async function decide(dependencies, signal, messages, preference) {
6351
+ async function decide(dependencies, signal, messages, preference, context) {
6194
6352
  try {
6195
- return selectAutoModel(await dependencies.loadModels(signal), messages, preference);
6353
+ return selectAutoModel(await dependencies.loadModels(signal), messages, preference, context);
6196
6354
  } catch (cause) {
6197
6355
  if (cause instanceof AutoModelRoutingError) throw failure$1(cause.code);
6198
6356
  throw cause;
@@ -6201,6 +6359,21 @@ async function decide(dependencies, signal, messages, preference) {
6201
6359
  function record(value) {
6202
6360
  return typeof value === "object" && value !== null;
6203
6361
  }
6362
+ function buildRoutingContext(ctx, agent, turn, messages, budgetPolicyConfig) {
6363
+ const sessionId = typeof agent.session?.id === "string" ? agent.session.id : void 0;
6364
+ const compaction = ctx.get("compaction");
6365
+ const compactionConfig = record(compaction) && record(compaction.config) ? compaction.config : void 0;
6366
+ const compactionAvailable = compaction !== void 0 && compactionConfig?.auto !== false && (typeof compactionConfig?.maxOverflowRetries !== "number" || compactionConfig.maxOverflowRetries > 0);
6367
+ const hasCompactionSummary = messages.some((m) => record(m) && (record(m.source) && m.source.kind === "compaction" || typeof m.surfaceOp === "object"));
6368
+ return {
6369
+ sessionId,
6370
+ turn,
6371
+ requestedMaxTokens: (typeof agent.session?.requestHeader === "function" ? agent.session.requestHeader() : void 0)?.config.maxTokens,
6372
+ requestBudgetPolicy: budgetPolicyConfig ? resolveRequestBudgetPolicy(budgetPolicyConfig) : DEFAULT_REQUEST_BUDGET_POLICY,
6373
+ compactionAvailable,
6374
+ hasCompactionSummary
6375
+ };
6376
+ }
6204
6377
  function pendingAuto(ctx, agent) {
6205
6378
  const candidate = ctx.get("sessionProjections");
6206
6379
  if (!record(candidate) || typeof candidate.stateOf !== "function") return void 0;
@@ -6269,7 +6442,7 @@ function installAutoModelRouting(ctx, dependencies) {
6269
6442
  if (state?.turn !== turn) {
6270
6443
  state = {
6271
6444
  turn,
6272
- decision: await decide(dependencies, signal, entered, preference),
6445
+ decision: await decide(dependencies, signal, entered, preference, buildRoutingContext(ctx, agent, turn, entered, dependencies.budgetPolicy?.())),
6273
6446
  recorded: false
6274
6447
  };
6275
6448
  routed.set(agent, state);
@@ -6321,9 +6494,10 @@ function installAutoModelRouting(ctx, dependencies) {
6321
6494
  if (input?.turn !== turn) throw failure$1("COPILOT_AUTO_TURN_CONTEXT_UNAVAILABLE");
6322
6495
  const preference = virtualPreference ?? (pending === void 0 ? void 0 : autoModelPreference(pending));
6323
6496
  if (preference === void 0) throw failure$1("COPILOT_AUTO_PREFERENCE_UNAVAILABLE");
6497
+ const routingContext = buildRoutingContext(ctx, agent, turn, input.messages, dependencies.budgetPolicy?.());
6324
6498
  state = {
6325
6499
  turn,
6326
- decision: await decide(dependencies, signal, input.messages, preference),
6500
+ decision: await decide(dependencies, signal, input.messages, preference, routingContext),
6327
6501
  recorded: false
6328
6502
  };
6329
6503
  routed.set(agent, state);
@@ -6345,7 +6519,11 @@ function installAutoModelRouting(ctx, dependencies) {
6345
6519
  preference: state.decision.preference,
6346
6520
  taskClass: state.decision.taskClass,
6347
6521
  reason: state.decision.reason,
6348
- candidateCount: state.decision.candidateCount
6522
+ candidateCount: state.decision.candidateCount,
6523
+ fittingCandidateCount: state.decision.fittingCandidateCount,
6524
+ estimatedInputTokens: state.decision.estimatedInputTokens,
6525
+ selectedInputBudget: state.decision.selectedInputBudget,
6526
+ inputFitDiagnostic: state.decision.inputFitDiagnostic
6349
6527
  });
6350
6528
  state.recorded = true;
6351
6529
  }
@@ -6995,9 +7173,12 @@ function apply$1(ctx, config = {}) {
6995
7173
  resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get("fs")?.processPathFromHostPath(hostPath), ref)
6996
7174
  };
6997
7175
  };
6998
- const removeAutoRoute = installAutoModelRouting(ctx, { async loadModels(signal) {
6999
- return (await discoverSnapshot({ signal })).models;
7000
- } });
7176
+ const removeAutoRoute = installAutoModelRouting(ctx, {
7177
+ async loadModels(signal) {
7178
+ return (await discoverSnapshot({ signal })).models;
7179
+ },
7180
+ budgetPolicy: () => budgetSettings()
7181
+ });
7001
7182
  const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings));
7002
7183
  installCopilotCompactionPressure(ctx, { resolve(request) {
7003
7184
  const snapshot = source.readSnapshot();
@@ -1,7 +1,9 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { AccountModelDescriptor } from './account-model-catalog.ts';
3
+ import type { RequestBudgetPolicy } from './request-budget.ts';
3
4
  export interface AutoModelHostDependencies {
4
5
  loadModels(signal: AbortSignal): Promise<readonly AccountModelDescriptor[]>;
6
+ budgetPolicy?: () => Partial<RequestBudgetPolicy>;
5
7
  }
6
8
  /** Resolve virtual Auto once per Core turn before request/header persistence. */
7
9
  export declare function installAutoModelRouting(ctx: Context, dependencies: AutoModelHostDependencies): () => void;
@@ -8,6 +8,10 @@ export interface AutoModelAttribution {
8
8
  readonly taskClass: 'fast' | 'balanced' | 'strong';
9
9
  readonly reason: 'short-text-turn' | 'standard-turn' | 'large-structured-turn' | 'image-capability';
10
10
  readonly candidateCount: number;
11
+ readonly fittingCandidateCount?: number;
12
+ readonly estimatedInputTokens?: number;
13
+ readonly selectedInputBudget?: number;
14
+ readonly inputFitDiagnostic?: 'fitting-candidate-selected' | 'compaction-eligible' | 'compaction-unavailable' | 'attempted-but-still-oversized' | 'fixed-content-cannot-fit';
11
15
  }
12
16
  interface AttributionState {
13
17
  readonly turn: number;
@@ -38,6 +42,8 @@ export declare const autoModelAttributionDefinition: {
38
42
  }): AttributionState;
39
43
  buildLocationData(context: Context, scope: string, previous: LocationData | null): LocationData | null;
40
44
  };
45
+ /** Inline footer chrome: after the settled clock, hidden until the message is hovered. */
46
+ export declare const AUTO_ATTRIBUTION_STYLE: string;
41
47
  export declare function installAutoModelPresentation(capabilities: {
42
48
  readonly slots: unknown;
43
49
  readonly uiConversation: unknown;
@@ -1,5 +1,6 @@
1
1
  import type { AccountModelDescriptor } from './account-model-catalog.ts';
2
2
  import type { AutoModelPreference } from './copilot-identity.ts';
3
+ import type { RequestBudgetPolicy } from './request-budget.ts';
3
4
  export type AutoModelClass = 'fast' | 'balanced' | 'strong';
4
5
  export interface AutoModelFeatures {
5
6
  readonly taskClass: AutoModelClass;
@@ -7,22 +8,38 @@ export interface AutoModelFeatures {
7
8
  readonly codeFenceCount: number;
8
9
  readonly requiresImage: boolean;
9
10
  }
11
+ export type AutoModelInputFitDiagnostic = 'fitting-candidate-selected' | 'compaction-eligible' | 'compaction-unavailable' | 'attempted-but-still-oversized' | 'fixed-content-cannot-fit';
10
12
  export interface AutoModelDecision {
11
13
  readonly model: AccountModelDescriptor;
12
14
  readonly preference: AutoModelPreference;
13
15
  readonly taskClass: AutoModelClass;
14
16
  readonly reason: 'short-text-turn' | 'standard-turn' | 'large-structured-turn' | 'image-capability';
15
17
  readonly candidateCount: number;
18
+ readonly fittingCandidateCount: number;
19
+ readonly estimatedInputTokens: number;
20
+ readonly selectedInputBudget: number;
21
+ readonly inputFitDiagnostic: AutoModelInputFitDiagnostic;
22
+ }
23
+ export interface AutoModelRoutingContext {
24
+ readonly sessionId?: string;
25
+ readonly turn?: number;
26
+ readonly requestedMaxTokens?: number;
27
+ readonly requestBudgetPolicy?: Readonly<RequestBudgetPolicy>;
28
+ readonly seed?: string | number;
29
+ readonly compactionAvailable?: boolean;
30
+ readonly hasCompactionSummary?: boolean;
16
31
  }
17
32
  export declare class AutoModelRoutingError extends Error {
18
33
  readonly code: 'COPILOT_AUTO_NO_ELIGIBLE_MODEL';
19
34
  constructor(code: 'COPILOT_AUTO_NO_ELIGIBLE_MODEL');
20
35
  }
21
36
  export declare function classifyAutoModelTurn(messages: readonly unknown[]): AutoModelFeatures;
37
+ export declare function estimateTurnInputTokens(messages: readonly unknown[]): number;
22
38
  /**
23
- * MVP policy: filter only by account-verified hard capabilities, then choose a
24
- * deterministic capacity tier. Capacity is not a quality, latency or price claim.
39
+ * Filter by hard capabilities and input headroom before soft preference.
40
+ * Soft preferences distribute across capacity bands using in-memory deterministic seeds.
41
+ * Preserves Core compaction ownership if no candidate currently fits.
25
42
  */
26
- export declare function selectAutoModel(models: readonly AccountModelDescriptor[], messages: readonly unknown[], preference?: AutoModelPreference): AutoModelDecision;
43
+ export declare function selectAutoModel(models: readonly AccountModelDescriptor[], messages: readonly unknown[], preference?: AutoModelPreference, context?: AutoModelRoutingContext): AutoModelDecision;
27
44
  export declare function autoModelInputModalities(models: readonly AccountModelDescriptor[]): readonly ('text' | 'image')[];
28
45
  //# sourceMappingURL=auto-model-routing.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.51",
4
+ "version": "0.4.0-alpha.53",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/",