dsh-github-copilot 0.4.0-alpha.98 → 0.4.0-alpha.99

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
@@ -1833,7 +1833,7 @@ function installContextEvidence(ctx) {
1833
1833
  //#endregion
1834
1834
  //#region package.json
1835
1835
  var name$1 = "dsh-github-copilot";
1836
- var version = "0.4.0-alpha.98";
1836
+ var version = "0.4.0-alpha.99";
1837
1837
  //#endregion
1838
1838
  //#region lib/types/probe.js
1839
1839
  /**
@@ -6510,6 +6510,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
6510
6510
  } : options.onPayload;
6511
6511
  const fetch = options.fetch ?? globalThis.fetch;
6512
6512
  const observeResponse = async (input, init) => {
6513
+ guard.requestCheckpoint?.();
6513
6514
  guard.onRequestBodyTimeout?.(void 0);
6514
6515
  liveness?.beginRequest(typeof init?.body === "string" ? init.body : void 0);
6515
6516
  const replayHeaders = responses && init?.headers !== void 0 ? new Headers(init.headers) : void 0;
@@ -7725,13 +7726,24 @@ async function assessAutoTask(messages, dependencies) {
7725
7726
  diagnostic: "unavailable"
7726
7727
  };
7727
7728
  }
7729
+ const classify = dependencies.classify;
7728
7730
  const budgetMs = dependencies.timeoutMs ?? 8e3;
7731
+ const deadline = performance.now() + budgetMs;
7729
7732
  const evidence = assessmentEvidence(budgetMs);
7730
- const timeout = AbortSignal.timeout(budgetMs);
7731
- const signal = AbortSignal.any([dependencies.signal, timeout]);
7732
- const input = assessmentInput(messages);
7733
+ const timeout = new AbortController();
7734
+ const expire = () => timeout.abort(new DOMException("Auto assessment deadline exceeded", "TimeoutError"));
7735
+ const timer = setTimeout(expire, budgetMs);
7736
+ const signal = AbortSignal.any([dependencies.signal, timeout.signal]);
7737
+ const checkpoint = () => {
7738
+ if (dependencies.signal.aborted) throw dependencies.signal.reason;
7739
+ if (performance.now() >= deadline) expire();
7740
+ if (signal.aborted) throw signal.reason;
7741
+ };
7733
7742
  let remove = () => {};
7743
+ let settled = false;
7734
7744
  try {
7745
+ const input = assessmentInput(messages);
7746
+ checkpoint();
7735
7747
  const aborted = new Promise((_resolve, reject) => {
7736
7748
  const abort = () => reject(signal.reason);
7737
7749
  signal.addEventListener("abort", abort, { once: true });
@@ -7739,10 +7751,16 @@ async function assessAutoTask(messages, dependencies) {
7739
7751
  if (signal.aborted) abort();
7740
7752
  });
7741
7753
  const observe = (observation) => {
7742
- if (!signal.aborted) evidence.observe(observation);
7754
+ if (settled || signal.aborted) return;
7755
+ checkpoint();
7756
+ evidence.observe(observation);
7743
7757
  };
7744
- const output = await Promise.race([dependencies.classify(input, signal, observe), aborted]);
7745
- if (dependencies.signal.aborted) throw dependencies.signal.reason;
7758
+ const classification = Promise.resolve().then(() => {
7759
+ checkpoint();
7760
+ return classify(input, signal, observe, checkpoint);
7761
+ });
7762
+ const output = await Promise.race([classification, aborted]);
7763
+ checkpoint();
7746
7764
  if (output.length > 2048) throw new Error("INVALID_RESULT");
7747
7765
  let raw;
7748
7766
  try {
@@ -7751,6 +7769,7 @@ async function assessAutoTask(messages, dependencies) {
7751
7769
  throw new Error("INVALID_RESULT");
7752
7770
  }
7753
7771
  const parsed = TaskAssessmentSchema.safeParse(raw);
7772
+ checkpoint();
7754
7773
  if (!parsed.success) throw new Error("INVALID_RESULT");
7755
7774
  if (input.omitted && (parsed.data.demand === "simple" || parsed.data.demand === "routine")) {
7756
7775
  dependencies.diagnostic("COPILOT_AUTO_ASSESSMENT_CONTEXT_OMITTED");
@@ -7770,7 +7789,7 @@ async function assessAutoTask(messages, dependencies) {
7770
7789
  } catch (cause) {
7771
7790
  if (dependencies.signal.aborted) throw dependencies.signal.reason;
7772
7791
  if (cause instanceof TaskAssessmentRevokedError) throw cause.cause;
7773
- const code = timeout.aborted ? "timeout" : cause instanceof Error && cause.message === "INVALID_RESULT" ? "invalid-result" : cause instanceof Error && cause.message === "COPILOT_AUTO_CLASSIFIER_UNAVAILABLE" ? "unavailable" : "failed";
7792
+ const code = timeout.signal.aborted || performance.now() >= deadline ? "timeout" : cause instanceof Error && cause.message === "INVALID_RESULT" ? "invalid-result" : cause instanceof Error && cause.message === "COPILOT_AUTO_CLASSIFIER_UNAVAILABLE" ? "unavailable" : "failed";
7774
7793
  dependencies.diagnostic(`COPILOT_AUTO_ASSESSMENT_${code.toUpperCase().replace("-", "_")}`);
7775
7794
  return {
7776
7795
  ...local,
@@ -7778,6 +7797,8 @@ async function assessAutoTask(messages, dependencies) {
7778
7797
  semantic: evidence.finish(code === "invalid-result" ? "invalid" : "not-validated")
7779
7798
  };
7780
7799
  } finally {
7800
+ settled = true;
7801
+ clearTimeout(timer);
7781
7802
  remove();
7782
7803
  }
7783
7804
  }
@@ -8753,13 +8774,14 @@ function installAutoModelRouting(ctx, dependencies) {
8753
8774
  };
8754
8775
  }
8755
8776
  function taskClassifierModel(models) {
8756
- return models.filter((model) => model.category === "lightweight" && model.input.includes("text")).toSorted((left, right) => left.id.localeCompare(right.id, "en")).find((model) => {
8777
+ return models.filter((model) => model.category === "lightweight" && model.input.includes("text")).toSorted((left, right) => Number(right.reasoning.advertisedEfforts.includes("off")) - Number(left.reasoning.advertisedEfforts.includes("off")) || left.id.localeCompare(right.id, "en")).find((model) => {
8757
8778
  const budget = calculateRequestBudget(model, 128);
8758
8779
  return budget.ok && budget.budget.hardInputLimit >= 12e3;
8759
8780
  });
8760
8781
  }
8761
8782
  /** One auxiliary concrete-model call; no Auto recursion, tools, history writes or retry loop. */
8762
- async function classifyTaskWithAdapter(model, input, signal, stream, observe, reasoningOffSupported = false) {
8783
+ async function classifyTaskWithAdapter(model, input, signal, stream, observe, reasoningOffSupported = false, checkpoint) {
8784
+ checkpoint?.();
8763
8785
  if (signal.aborted) throw signal.reason;
8764
8786
  let output = "";
8765
8787
  let finished = false;
@@ -8782,6 +8804,8 @@ async function classifyTaskWithAdapter(model, input, signal, stream, observe, re
8782
8804
  maxTokens: 128,
8783
8805
  ...reasoningOffSupported && model.reasoning.advertisedEfforts.includes("off") ? { reasoningEffort: ReasoningEffortId("off") } : {}
8784
8806
  })) {
8807
+ checkpoint?.();
8808
+ checkpoint?.();
8785
8809
  if (signal.aborted) throw signal.reason;
8786
8810
  if (chunk.type === "text-delta") {
8787
8811
  output += chunk.text;
@@ -9097,7 +9121,8 @@ var PreviewAdapter = class extends PiAiAdapter {
9097
9121
  requestBudgetSettings;
9098
9122
  accountModelSettings;
9099
9123
  replayRecovery;
9100
- constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery) {
9124
+ requestCheckpoint;
9125
+ constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery, requestCheckpoint) {
9101
9126
  super(optionsFor());
9102
9127
  this.lifetime = lifetime;
9103
9128
  this.optionsFor = optionsFor;
@@ -9106,6 +9131,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9106
9131
  this.requestBudgetSettings = requestBudgetSettings;
9107
9132
  this.accountModelSettings = accountModelSettings;
9108
9133
  this.replayRecovery = replayRecovery;
9134
+ this.requestCheckpoint = requestCheckpoint;
9109
9135
  }
9110
9136
  async listModels(provider) {
9111
9137
  owned(provider);
@@ -9167,13 +9193,18 @@ var PreviewAdapter = class extends PiAiAdapter {
9167
9193
  return this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).resolveModel(provider, model, signal));
9168
9194
  }
9169
9195
  async prepareCall(provider, model, signal) {
9196
+ this.requestCheckpoint?.();
9170
9197
  owned(provider);
9171
9198
  if (autoModelPreference(model) !== void 0) throw failure("COPILOT_AUTO_ROUTE_UNRESOLVED", "INVALID_REQUEST");
9172
9199
  const cached = this.lifetime.source.readSnapshot();
9173
9200
  const snapshot = await this.discoverSnapshot({ signal });
9201
+ this.requestCheckpoint?.();
9174
9202
  const lease = await this.lease(snapshot, model, signal, cached === snapshot);
9203
+ this.requestCheckpoint?.();
9204
+ const prepared = await this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).prepareCall(provider, model, signal));
9205
+ this.requestCheckpoint?.();
9175
9206
  return {
9176
- model: (await this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).prepareCall(provider, model, signal))).model,
9207
+ model: prepared.model,
9177
9208
  stream: (options) => this.guardedStream(lease, options)
9178
9209
  };
9179
9210
  }
@@ -9207,6 +9238,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9207
9238
  guardedStream(lease, options) {
9208
9239
  const owner = this;
9209
9240
  return (async function* () {
9241
+ owner.requestCheckpoint?.();
9210
9242
  owner.lifetime.start(lease);
9211
9243
  owned(options.provider);
9212
9244
  if (options.model !== lease.descriptor.id) throw failure("COPILOT_PREVIEW_MODEL_MISMATCH");
@@ -9224,6 +9256,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9224
9256
  let bodyTimeout;
9225
9257
  let liveness;
9226
9258
  const inspectRequest = (_model, context, nativeOptions) => {
9259
+ owner.requestCheckpoint?.();
9227
9260
  if (signal.aborted) throw abortFailure(signal);
9228
9261
  const imageFailure = imageInputFailure(lease.descriptor, context.messages);
9229
9262
  if (imageFailure !== void 0) {
@@ -9242,10 +9275,12 @@ var PreviewAdapter = class extends PiAiAdapter {
9242
9275
  requestFailure = budgetFailure(admitted);
9243
9276
  throw requestFailure;
9244
9277
  }
9278
+ owner.requestCheckpoint?.();
9245
9279
  };
9246
9280
  try {
9247
9281
  const native = new PiAiAdapter(owner.optionsFor(lease, {
9248
9282
  inspectRequest,
9283
+ requestCheckpoint: owner.requestCheckpoint,
9249
9284
  ...recovery === void 0 ? {} : {
9250
9285
  recoverReplay: recovery.transform,
9251
9286
  onReplayScopeRejected: recovery.rejected
@@ -9267,6 +9302,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9267
9302
  }
9268
9303
  }));
9269
9304
  const prepared = await native.prepareCall(options.provider, options.model, signal);
9305
+ owner.requestCheckpoint?.();
9270
9306
  const suppliedEffort = options.reasoningEffort ?? prepared.model.reasoning?.defaultEffort;
9271
9307
  const effort = options.purpose === "compaction" ? selectCompactionReasoning(getSupportedThinkingLevels(model), suppliedEffort, policy.compactionReasoning) : suppliedEffort;
9272
9308
  const request = {
@@ -9275,6 +9311,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9275
9311
  ...effort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(effort) }
9276
9312
  };
9277
9313
  for await (const chunk of native.stream(request)) {
9314
+ owner.requestCheckpoint?.();
9278
9315
  let delivered = chunk;
9279
9316
  if (requestFailure !== void 0 && chunk.type === "finish") {
9280
9317
  if (signal.aborted) throw abortFailure(signal);
@@ -9596,8 +9633,10 @@ function apply$1(ctx, config = {}) {
9596
9633
  followParentModel: () => cacheSettings().followParentModel === true,
9597
9634
  semanticAssessment: () => cacheSettings().autoSemanticAssessment ?? true,
9598
9635
  assessmentDiagnostic: (code) => ctx.logger.warn(code),
9599
- async classifyTask(input, signal, observe) {
9636
+ async classifyTask(input, signal, observe, checkpoint) {
9637
+ checkpoint?.();
9600
9638
  const snapshot = await discoverSnapshot({ signal });
9639
+ checkpoint?.();
9601
9640
  const model = taskClassifierModel(snapshot.models.filter((model) => !excludedModels().has(model.id)));
9602
9641
  if (model === void 0) throw failure("COPILOT_AUTO_CLASSIFIER_UNAVAILABLE");
9603
9642
  observe?.({
@@ -9605,11 +9644,12 @@ function apply$1(ctx, config = {}) {
9605
9644
  modelId: model.id
9606
9645
  });
9607
9646
  const revision = lifetime.revision;
9608
- const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings);
9647
+ const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, void 0, checkpoint);
9609
9648
  try {
9610
9649
  const prepared = await adapter.prepareCall(GITHUB_COPILOT_PREVIEW_PROVIDER_ID, model.id, signal);
9650
+ checkpoint?.();
9611
9651
  if (signal.aborted) throw signal.reason;
9612
- return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true);
9652
+ return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true, checkpoint);
9613
9653
  } finally {
9614
9654
  if (!lifetime.isCurrent(revision) || source.readSnapshot() !== snapshot || proofFor(snapshot) === void 0) throw new TaskAssessmentRevokedError(failure("COPILOT_PREVIEW_METADATA_STALE", "ABORTED"));
9615
9655
  }
@@ -33,7 +33,7 @@ export declare function assessmentInput(messages: readonly unknown[]): Assessmen
33
33
  export interface TaskAssessmentDependencies {
34
34
  enabled: boolean;
35
35
  signal: AbortSignal;
36
- classify?: (input: AssessmentInput, signal: AbortSignal, observe?: TaskClassifierObserver) => Promise<string>;
36
+ classify?: (input: AssessmentInput, signal: AbortSignal, observe?: TaskClassifierObserver, checkpoint?: () => void) => Promise<string>;
37
37
  diagnostic: (code: string) => void;
38
38
  timeoutMs?: number;
39
39
  }
@@ -5,5 +5,5 @@ import type { TaskClassifierObserver } from './auto-assessment-evidence.ts';
5
5
  export declare const TASK_CLASSIFIER_MAX_TOKENS = 128;
6
6
  export declare function taskClassifierModel(models: readonly AccountModelDescriptor[]): AccountModelDescriptor | undefined;
7
7
  /** One auxiliary concrete-model call; no Auto recursion, tools, history writes or retry loop. */
8
- export declare function classifyTaskWithAdapter(model: AccountModelDescriptor, input: AssessmentInput, signal: AbortSignal, stream: (request: GenerateOptions) => AsyncIterable<StreamChunk>, observe?: TaskClassifierObserver, reasoningOffSupported?: boolean): Promise<string>;
8
+ export declare function classifyTaskWithAdapter(model: AccountModelDescriptor, input: AssessmentInput, signal: AbortSignal, stream: (request: GenerateOptions) => AsyncIterable<StreamChunk>, observe?: TaskClassifierObserver, reasoningOffSupported?: boolean, checkpoint?: () => void): Promise<string>;
9
9
  //# sourceMappingURL=auto-task-classifier.d.ts.map
@@ -44,6 +44,8 @@ export interface AccountProviderGuard extends PreviewProviderGuard {
44
44
  readonly retrySignal?: AbortSignal;
45
45
  /** Per-dispatch admission after native context conversion, before starting a model wire. */
46
46
  inspectRequest?(model: Model<Api>, context: TranscriptContext, options?: StreamOptions): void;
47
+ /** Optional auxiliary-call deadline fence immediately before native Fetch dispatch. */
48
+ requestCheckpoint?(): void;
47
49
  assertEntitled(credential: GitHubCopilotOAuthCredential, modelId: string): void;
48
50
  }
49
51
  /** The independent prompt limit is retained for the route's budget guard, not folded into context capacity. */
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.98",
4
+ "version": "0.4.0-alpha.99",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/",