dsh-github-copilot 0.4.0-alpha.113 → 0.4.0-alpha.115

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
@@ -2998,7 +2998,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
2998
2998
  var package_default = {
2999
2999
  name: "dsh-github-copilot",
3000
3000
  description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
3001
- version: "0.4.0-alpha.113",
3001
+ version: "0.4.0-alpha.115",
3002
3002
  publishConfig: {
3003
3003
  "access": "public",
3004
3004
  "registry": "https://registry.npmjs.org/",
@@ -12338,7 +12338,20 @@ function apply$1(ctx, config = {}) {
12338
12338
  getView: () => disposed ? initial.preview.getView() : currentRuntime().preview.getView(),
12339
12339
  refresh: async () => currentRuntime().preview.refresh(),
12340
12340
  discover: (options) => currentRuntime(options?.signal).preview.discover(options),
12341
- recoveryLimits: (model) => currentRuntime().preview.recoveryLimits(model),
12341
+ recoveryLimits: (model, agent) => {
12342
+ const accounts = ctx.get("githubCopilotSessionAccounts");
12343
+ const binding = agent !== void 0 && accounts !== void 0 ? accounts.bindingForAccount((accounts.turns.current(agent.session) ?? accounts.selected(agent)).accountId) : requestBinding();
12344
+ const lease = runtimeFor(binding).preview.recoveryLimits(model);
12345
+ if (lease === void 0) return void 0;
12346
+ return {
12347
+ ...lease,
12348
+ assertCurrent: () => {
12349
+ binding?.assertCurrent();
12350
+ if (agent !== void 0 && accounts !== void 0 && (accounts.turns.current(agent.session) ?? accounts.selected(agent)).accountId !== binding?.accountId) throw new Error("COPILOT_MANUAL_RECOVERY_ACCOUNT_PROOF_CHANGED");
12351
+ lease.assertCurrent();
12352
+ }
12353
+ };
12354
+ },
12342
12355
  routeFacts: (model) => currentRuntime().preview.routeFacts(model),
12343
12356
  captureSearchProof: () => currentRuntime().preview.captureSearchProof(),
12344
12357
  resolveRequestAuth: (model, signal) => currentRuntime(signal).preview.resolveRequestAuth(model, signal)
@@ -1,6 +1,7 @@
1
1
  import "./copilot-identity-DRZY_d2X.js";
2
2
  import { i as resolveRequestBudgetPolicy, r as calculateRequestBudget } from "./request-budget-DLY_aRq0.js";
3
- import { createUserMessage } from "@deepseek-ai/dsh-llm";
3
+ import z from "@deepseek-ai/schemastery";
4
+ import { LlmError, createUserMessage } from "@deepseek-ai/dsh-llm";
4
5
  import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
5
6
  import { CommandDefinitionId } from "@deepseek-ai/dsh-commands/brand";
6
7
  //#region lib/types/background-compaction.js
@@ -169,7 +170,7 @@ function sumUsage(usages) {
169
170
  };
170
171
  }
171
172
  /**
172
- * Bounded, explicit manual-only map/fold. The native engine still owns the only
173
+ * Bounded map/fold. The native engine still owns the only
173
174
  * durable transaction, source-stability check, shrink check and cancellation.
174
175
  */
175
176
  async function summarizeOversizedManualInput(options) {
@@ -244,9 +245,14 @@ async function summarizeOversizedManualInput(options) {
244
245
  * mount both: Cordis compaction is a singleton, not an overridable service.
245
246
  */
246
247
  var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine {
248
+ static Config = z.intersect([BasicCompactionEngine.Config, z.object({ automaticRecovery: z.boolean().default(true) })]);
247
249
  manual = /* @__PURE__ */ new WeakMap();
250
+ automaticRecovery;
248
251
  constructor(ctx, config = {}) {
249
- super(ctx, config);
252
+ const { automaticRecovery = true, ...nativeConfig } = config;
253
+ if (typeof automaticRecovery !== "boolean") throw recoverError("INVALID_POLICY");
254
+ super(ctx, nativeConfig);
255
+ this.automaticRecovery = automaticRecovery;
250
256
  ctx.inject(["commands", "jobs"], (scope) => {
251
257
  installBackgroundCompaction(scope, (agent, signal) => this.compactNow(agent, signal));
252
258
  });
@@ -263,7 +269,8 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
263
269
  }
264
270
  async summarize(input, agent, signal) {
265
271
  const routed = agent.session.requestHeader()?.config;
266
- const policy = this.config.modelPolicies.find((item) => item.provider === routed?.provider && item.model === routed.model);
272
+ const target = routed?.provider && routed.model ? routed : agent.options;
273
+ const policy = this.config.modelPolicies.find((item) => item.provider === target.provider && item.model === target.model);
267
274
  const configuredProvider = policy?.summarizationProvider ?? this.config.summarizationProvider;
268
275
  const configuredModel = policy?.summarizationModel ?? this.config.summarizationModel;
269
276
  const selected = configuredProvider.length > 0 ? {
@@ -275,23 +282,40 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
275
282
  };
276
283
  const summaryProvider = selected.provider;
277
284
  const summaryModel = selected.model;
278
- if (!this.manual.has(agent) || summaryProvider !== "github-copilot-preview" || !summaryModel) return super.summarize(input, agent, signal);
279
- const lease = this.ctx.get("githubCopilotPreview")?.recoveryLimits(summaryModel);
285
+ if (!this.manual.has(agent) && !this.automaticRecovery || summaryProvider !== "github-copilot-preview" || !summaryModel) return super.summarize(input, agent, signal);
286
+ const lease = this.ctx.get("githubCopilotPreview")?.recoveryLimits(summaryModel, agent);
280
287
  if (lease === void 0) throw recoverError("ACCOUNT_PROOF_UNAVAILABLE");
288
+ const agents = this.ctx.get("agents");
289
+ if (this.ctx.get("githubCopilotSessionAccounts") !== void 0 && agents === void 0) throw recoverError("INITIATOR_UNAVAILABLE");
290
+ const summarize = (candidate) => agents === void 0 ? super.summarize(candidate, agent, signal) : agents.withInitiator(agent, () => super.summarize(candidate, agent, signal));
281
291
  const maxTokens = policy?.maxTokens ?? this.config.maxTokens;
282
292
  const budget = calculateRequestBudget(lease.limits, maxTokens, resolveRequestBudgetPolicy(lease.policy));
283
293
  if (!budget.ok) throw recoverError(budget.code);
284
294
  const toolHistoryBytes = Buffer.byteLength(JSON.stringify(agent.session.toolHistory()), "utf8");
285
- const inputLimit = budget.budget.hardInputLimit - 4096 - toolHistoryBytes;
295
+ let inputLimit = budget.budget.hardInputLimit - 4096 - toolHistoryBytes;
286
296
  if (inputLimit <= 0) throw recoverError("FIXED_PREFIX");
287
297
  const operationSignal = signal ?? new AbortController().signal;
288
298
  const estimate = (candidate) => Buffer.byteLength(JSON.stringify(candidate), "utf8");
289
- if (estimate(input) <= inputLimit) return super.summarize(input, agent, signal);
290
- return summarizeOversizedManualInput({
299
+ operationSignal.throwIfAborted();
300
+ lease.assertCurrent();
301
+ const originalSize = estimate(input);
302
+ let failedAttempt = false;
303
+ if (originalSize <= inputLimit) try {
304
+ return await summarize(input);
305
+ } catch (error) {
306
+ operationSignal.throwIfAborted();
307
+ if (!(error instanceof LlmError) || error.code !== "CONTEXT_WINDOW_EXCEEDED") throw error;
308
+ lease.assertCurrent();
309
+ inputLimit = Math.min(inputLimit, Math.floor(originalSize / 2));
310
+ failedAttempt = true;
311
+ }
312
+ this.ctx.logger.info("[github-copilot] Segmented compaction recovery started; up to %d additional model calls.", failedAttempt ? 15 : 16);
313
+ const result = await summarizeOversizedManualInput({
291
314
  input,
292
315
  inputLimit,
293
316
  signal: operationSignal,
294
317
  estimate,
318
+ maxCalls: failedAttempt ? 15 : 16,
295
319
  assertCurrent: lease.assertCurrent,
296
320
  makeCheckpoint: (summary) => createUserMessage({
297
321
  source: { kind: "user" },
@@ -307,8 +331,13 @@ var CopilotManualRecoveryCompactionEngine = class extends BasicCompactionEngine
307
331
  }
308
332
  ]
309
333
  }),
310
- summarize: (candidate) => super.summarize(candidate, agent, signal)
334
+ summarize
311
335
  });
336
+ if (failedAttempt) {
337
+ const { usage: _usage, ...unaccounted } = result;
338
+ return unaccounted;
339
+ }
340
+ return result;
312
341
  }
313
342
  };
314
343
  //#endregion
@@ -25,7 +25,6 @@ export interface CopilotUsageCardProps {
25
25
  /** Changes revoke every in-flight read, including switches between Copilot routes. */
26
26
  contextKey: string;
27
27
  locale?: string;
28
- accountActions?: ReactElement;
29
28
  continuation?: ReactElement;
30
29
  onManage?: () => void;
31
30
  /** Parent-owned consent; check the request signal after awaits and dismiss on abort. */
@@ -1,6 +1,8 @@
1
1
  import type { Agent } from '@deepseek-ai/dsh-agent';
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
+ import type { BasicCompactionConfig } from '@deepseek-ai/dsh-compaction-basic';
5
+ import z from '@deepseek-ai/schemastery';
4
6
  import type { ContentBlock, Message, TokenUsage, ToolSchema } from '@deepseek-ai/dsh-llm';
5
7
  import type { CommandId } from '@deepseek-ai/dsh-commands/brand';
6
8
  import type { CompactionResult } from '@deepseek-ai/dsh-compaction';
@@ -34,7 +36,7 @@ interface RecoveryOptions<M extends RecoveryMessage, R extends RecoveryResult> {
34
36
  readonly assertCurrent?: () => void;
35
37
  }
36
38
  /**
37
- * Bounded, explicit manual-only map/fold. The native engine still owns the only
39
+ * Bounded map/fold. The native engine still owns the only
38
40
  * durable transaction, source-stability check, shrink check and cancellation.
39
41
  */
40
42
  export declare function summarizeOversizedManualInput<M extends RecoveryMessage, R extends RecoveryResult>(options: RecoveryOptions<M, R>): Promise<RecoveryResult>;
@@ -43,10 +45,21 @@ export declare function summarizeOversizedManualInput<M extends RecoveryMessage,
43
45
  * mount both: Cordis compaction is a singleton, not an overridable service.
44
46
  */
45
47
  export declare class CopilotManualRecoveryCompactionEngine extends BasicCompactionEngine {
48
+ static Config: z<BasicCompactionConfig & {
49
+ automaticRecovery?: boolean;
50
+ }>;
46
51
  private readonly manual;
47
- constructor(ctx: Context, config?: ConstructorParameters<typeof BasicCompactionEngine>[1]);
52
+ private readonly automaticRecovery;
53
+ constructor(ctx: Context, config?: BasicCompactionConfig & {
54
+ automaticRecovery?: boolean;
55
+ });
48
56
  compactNow(agent: Agent, signal: AbortSignal, sourceCommandId?: CommandId): Promise<CompactionResult | null>;
49
- protected summarize(input: RecoveryInput<Message>, agent: Agent, signal?: AbortSignal): Promise<RecoveryResult>;
57
+ protected summarize(input: RecoveryInput<Message>, agent: Agent, signal?: AbortSignal): Promise<RecoveryResult | {
58
+ summary: ContentBlock[];
59
+ provider: string;
60
+ model: string;
61
+ maxTokens?: number;
62
+ }>;
50
63
  }
51
64
  export default CopilotManualRecoveryCompactionEngine;
52
65
  //# sourceMappingURL=manual-compaction-recovery.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
3
  import type { PiAiProviderProfile } from '@deepseek-ai/dsh-llm-pi-ai';
3
4
  import { GITHUB_COPILOT_PREVIEW_PROVIDER_ID } from './copilot-identity.ts';
4
5
  import type { AccountModelLoadOptions } from './account-model-source.ts';
@@ -34,8 +35,8 @@ export interface GitHubCopilotPreviewView {
34
35
  }
35
36
  export interface GitHubCopilotPreview {
36
37
  getView(): GitHubCopilotPreviewView;
37
- /** Synchronous, account-proven capacities for an explicit manual summary; never triggers discovery. */
38
- recoveryLimits(modelId: string): {
38
+ /** Synchronous, account-proven summary capacities for the initiating Agent; never triggers discovery. */
39
+ recoveryLimits(modelId: string, agent?: Agent): {
39
40
  readonly limits: Pick<AccountModelDescriptor, 'contextWindow' | 'maxInputTokens' | 'maxTokens'>;
40
41
  readonly policy: Partial<RequestBudgetPolicy>;
41
42
  readonly assertCurrent: () => void;
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.113",
4
+ "version": "0.4.0-alpha.115",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/",