@agentknight/sdk 0.9.41 → 0.9.42

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.
@@ -547,11 +547,14 @@ var SessionConfiguration = class {
547
547
  }
548
548
  forget(sessionId) {
549
549
  this.#sessionReasoningEfforts.delete(sessionId);
550
+ this.#pendingModels.delete(sessionId);
550
551
  }
551
552
  clear() {
552
553
  this.#sessionReasoningEfforts.clear();
554
+ this.#pendingModels.clear();
553
555
  }
554
556
  #sessionReasoningEfforts = /* @__PURE__ */ new Map();
557
+ #pendingModels = /* @__PURE__ */ new Map();
555
558
  async serializeSessionConfiguration(sessionId, operation) {
556
559
  const runtime = this.ports.state(sessionId);
557
560
  const previous = runtime.configuration.transition;
@@ -578,15 +581,21 @@ var SessionConfiguration = class {
578
581
  if (agentMode === "autopilot") {
579
582
  await this.ensureAutopilotPermissions(session);
580
583
  }
584
+ const pending = this.#pendingModels.get(sessionId);
585
+ if (pending !== void 0 && model.modelId === pending.modelId && (pending.reasoningEffort === "default" && model.modelId !== pending.previousModelId || model.reasoningEffort === pending.reasoningEffort || pending.reasoningEffort === "default" && model.reasoningEffort !== pending.previousEffort)) {
586
+ this.#pendingModels.delete(sessionId);
587
+ }
588
+ const selected = this.#pendingModels.get(sessionId);
589
+ const selectedModelId = selected?.modelId ?? model.modelId;
581
590
  const reasoningEffort = model.reasoningEffort === void 0 ? this.#sessionReasoningEfforts.get(sessionId) ?? "default" : CurrentReasoningEffortSchema.parse(model.reasoningEffort);
582
591
  const configurableEffort = SessionReasoningEffortSchema.safeParse(reasoningEffort);
583
592
  if (configurableEffort.success) {
584
593
  this.#sessionReasoningEfforts.set(sessionId, configurableEffort.data);
585
594
  }
586
595
  return {
587
- ...model.modelId === void 0 ? {} : { modelId: model.modelId },
596
+ ...selectedModelId === void 0 ? {} : { modelId: selectedModelId },
588
597
  agentMode,
589
- reasoningEffort
598
+ reasoningEffort: selected?.reasoningEffort ?? reasoningEffort
590
599
  };
591
600
  }
592
601
  async setAgentMode(session, mode) {
@@ -671,32 +680,37 @@ var SessionConfiguration = class {
671
680
  this.ports.assertOriginalAction(sessionId);
672
681
  if (options.modelId !== void 0 || options.reasoningEffort !== void 0) {
673
682
  const currentModel = await session.rpc.model.getCurrent();
674
- const modelId = options.modelId ?? currentModel.modelId;
683
+ const pending = this.#pendingModels.get(sessionId);
684
+ const modelId = options.modelId ?? pending?.modelId ?? currentModel.modelId;
675
685
  if (modelId === void 0) {
676
686
  throw new Error(
677
687
  "Copilot did not report the current model for reasoning effort configuration"
678
688
  );
679
689
  }
680
690
  const currentReasoningEffort = currentModel.reasoningEffort ?? this.#sessionReasoningEfforts.get(sessionId) ?? "default";
681
- const reasoningEffort = options.reasoningEffort ?? (modelId === currentModel.modelId ? currentReasoningEffort : "default");
682
- if (modelId !== currentModel.modelId || reasoningEffort !== currentReasoningEffort) {
683
- if ((await session.rpc.metadata?.isProcessing?.())?.processing) {
684
- throw new Error("Copilot session is busy; wait before changing its model");
685
- }
691
+ const reasoningEffort = options.reasoningEffort ?? (modelId === pending?.modelId ? pending.reasoningEffort : modelId === currentModel.modelId ? currentReasoningEffort : "default");
692
+ if (!(pending?.modelId === modelId && pending.reasoningEffort === reasoningEffort) && (modelId !== currentModel.modelId || reasoningEffort !== currentReasoningEffort || pending !== void 0)) {
686
693
  const result = await session.rpc.model.switchTo({
687
694
  modelId,
688
695
  ...reasoningEffort === "default" ? {} : { reasoningEffort },
689
696
  deferIfModelChangeQueued: true
690
697
  });
691
- if (result.deferred) {
692
- throw new Error("Copilot queued the model change; it has not been applied yet");
693
- }
694
- if (result.modelId !== modelId) {
698
+ if (!result.deferred && result.modelId !== modelId) {
695
699
  throw new Error(`Copilot did not apply the requested model: ${modelId}`);
696
700
  }
697
- const parsedEffort = SessionReasoningEffortSchema.safeParse(reasoningEffort);
698
- if (parsedEffort.success) {
699
- this.#sessionReasoningEfforts.set(sessionId, parsedEffort.data);
701
+ if (result.deferred) {
702
+ this.#pendingModels.set(sessionId, {
703
+ modelId,
704
+ reasoningEffort,
705
+ previousModelId: currentModel.modelId,
706
+ previousEffort: currentReasoningEffort
707
+ });
708
+ } else {
709
+ this.#pendingModels.delete(sessionId);
710
+ const parsedEffort = SessionReasoningEffortSchema.safeParse(reasoningEffort);
711
+ if (parsedEffort.success) {
712
+ this.#sessionReasoningEfforts.set(sessionId, parsedEffort.data);
713
+ }
700
714
  }
701
715
  }
702
716
  }
package/dist/index.js CHANGED
@@ -344,7 +344,7 @@ async function createCodingAgentAdapter(config, onDiagnostic, owner) {
344
344
  });
345
345
  }
346
346
  case "copilot": {
347
- const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-FY75OLIU.js");
347
+ const { GithubCopilotAdapter } = await import("./chunks/copilot-adapter-A6QB4RD4.js");
348
348
  if (owner !== void 0) {
349
349
  return new GithubCopilotAdapter(void 0, void 0, void 0, {
350
350
  dataDirectory: config.dataDirectory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentknight/sdk",
3
- "version": "0.9.41",
3
+ "version": "0.9.42",
4
4
  "description": "AgentKnight runtime SDK for local and remote coding sessions",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -49,8 +49,8 @@
49
49
  "esbuild": "0.28.2",
50
50
  "rollup": "4.63.1",
51
51
  "rollup-plugin-dts": "6.3.0",
52
- "@agentknight/protocol": "0.1.0",
53
- "@agentknight/shared": "0.1.0"
52
+ "@agentknight/shared": "0.1.0",
53
+ "@agentknight/protocol": "0.1.0"
54
54
  },
55
55
  "optionalDependencies": {
56
56
  "@earendil-works/pi-ai": "0.85.1",