@agentknight/sdk 0.9.59 → 0.9.61

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.
Files changed (23) hide show
  1. package/dist/chunks/{acp-adapter-OGD5QSNI.js → acp-adapter-MBYKOCA2.js} +4 -4
  2. package/dist/chunks/{chunk-LWJNDBIM.js → chunk-3AMFPDE5.js} +8 -4
  3. package/dist/chunks/{chunk-5DVJ7Y5W.js → chunk-7CNBPLNE.js} +2 -2
  4. package/dist/chunks/{chunk-3OIHMMDF.js → chunk-7OGTK7KB.js} +1 -1
  5. package/dist/chunks/{chunk-2MERNOK6.js → chunk-A4YCCQ3I.js} +1 -1
  6. package/dist/chunks/{chunk-X3ZG6WMN.js → chunk-ALUQLM54.js} +2 -2
  7. package/dist/chunks/{chunk-AREU4R62.js → chunk-CHKNC6PD.js} +1 -1
  8. package/dist/chunks/{chunk-DP5KVGWF.js → chunk-CM5LVXVL.js} +3 -3
  9. package/dist/chunks/{chunk-NDEJOXSX.js → chunk-H4SHMWQ6.js} +1 -1
  10. package/dist/chunks/{chunk-LO4ZRE77.js → chunk-P2PH5KMV.js} +101 -50
  11. package/dist/chunks/{chunk-FDUJP3WA.js → chunk-SIFCCGXF.js} +7 -5
  12. package/dist/chunks/{chunk-ZDKBJFA2.js → chunk-ZNQ2I5EF.js} +1 -1
  13. package/dist/chunks/{claude-adapter-DGZBZSWJ.js → claude-adapter-D3JWXMNX.js} +4 -4
  14. package/dist/chunks/{codex-adapter-2W7RRER3.js → codex-adapter-655KHW7H.js} +4 -4
  15. package/dist/chunks/{copilot-adapter-ZEHU6CFQ.js → copilot-adapter-EZUXHBE3.js} +55 -20
  16. package/dist/chunks/{managed-agent-adapter-CGJPJZ2Z.js → managed-agent-adapter-BOJNEJ75.js} +11 -7
  17. package/dist/chunks/{pi-adapter-WOVSWBGG.js → pi-adapter-LAD5GOCP.js} +4 -4
  18. package/dist/configuration.js +4 -4
  19. package/dist/index.d.ts +16 -0
  20. package/dist/index.js +63 -39
  21. package/dist/runtime.js +2 -2
  22. package/dist/session-analytics-worker.js +5 -5
  23. package/package.json +1 -1
@@ -9,6 +9,7 @@ import {
9
9
  SessionRuntimeRegistry,
10
10
  SessionWorkbenchRuntime,
11
11
  isClosedCopilotConnection,
12
+ isClosedCopilotRuntimeHost,
12
13
  isDisposedCopilotSession,
13
14
  isSessionRestoreFailure,
14
15
  measureOperationStage,
@@ -17,7 +18,7 @@ import {
17
18
  recordTimelineSyncDiagnostic,
18
19
  resolveGitProjectIdentity,
19
20
  sanitizeGitRemoteUrl
20
- } from "./chunk-LWJNDBIM.js";
21
+ } from "./chunk-3AMFPDE5.js";
21
22
  import "./chunk-IJPJQF7S.js";
22
23
  import {
23
24
  AnalyticsIndexResultSchema,
@@ -27,29 +28,29 @@ import {
27
28
  readSessionUpdatePage,
28
29
  resolveCopilotSessionDirectory,
29
30
  resumeWithCopilotSessionCompatibility
30
- } from "./chunk-DP5KVGWF.js";
31
+ } from "./chunk-CM5LVXVL.js";
31
32
  import {
32
33
  ConversationNormalizer,
33
34
  isDisplayableHumanMessage
34
- } from "./chunk-ZDKBJFA2.js";
35
+ } from "./chunk-ZNQ2I5EF.js";
35
36
  import {
36
37
  assertMainSessionId,
37
38
  isResearchSessionId
38
- } from "./chunk-2MERNOK6.js";
39
+ } from "./chunk-A4YCCQ3I.js";
39
40
  import {
40
41
  GroupChatError,
41
42
  GroupChatMessageSchema,
42
43
  GroupChatRuntime
43
- } from "./chunk-X3ZG6WMN.js";
44
- import "./chunk-NDEJOXSX.js";
44
+ } from "./chunk-ALUQLM54.js";
45
+ import "./chunk-H4SHMWQ6.js";
45
46
  import {
46
47
  AgentSessionRenameError,
47
48
  TimelinePageBudgetError,
48
49
  validateSessionName
49
- } from "./chunk-5DVJ7Y5W.js";
50
+ } from "./chunk-7CNBPLNE.js";
50
51
  import {
51
52
  SessionOperationError
52
- } from "./chunk-3OIHMMDF.js";
53
+ } from "./chunk-7OGTK7KB.js";
53
54
  import {
54
55
  ConversationItemSchema,
55
56
  CopilotModelOptionSchema,
@@ -61,6 +62,7 @@ import {
61
62
  SESSION_TIMELINE_PAGE_SIZE,
62
63
  SessionAnalyticsResultSchema,
63
64
  SessionAvatarPersonaSchema,
65
+ SessionContextTierSchema,
64
66
  SessionReasoningEffortSchema,
65
67
  SessionRemoteStatusSchema,
66
68
  SessionSkillInfoSchema,
@@ -72,7 +74,7 @@ import {
72
74
  WorkbenchScheduleProposalSchema,
73
75
  WorkbenchScheduleSnapshotSchema,
74
76
  WorkbenchTelemetrySchema
75
- } from "./chunk-LO4ZRE77.js";
77
+ } from "./chunk-P2PH5KMV.js";
76
78
 
77
79
  // src/copilot-adapter.ts
78
80
  import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
@@ -184,7 +186,7 @@ var CopilotClientRuntime = class {
184
186
  }
185
187
  return result;
186
188
  } catch (error) {
187
- if (!isClosedCopilotConnection(error)) {
189
+ if (!isClosedCopilotConnection(error) && !isClosedCopilotRuntimeHost(error)) {
188
190
  throw error;
189
191
  }
190
192
  await measureOperationStage("runtime-recovery", () => this.recoverRuntime(client, error));
@@ -274,7 +276,7 @@ var CopilotClientRuntime = class {
274
276
  return;
275
277
  }
276
278
  const errors = (await client.stop()).filter(
277
- (error) => !isClosedCopilotConnection(error) && !isDisposedCopilotSession(error)
279
+ (error) => !isClosedCopilotConnection(error) && !isDisposedCopilotSession(error) && !isClosedCopilotRuntimeHost(error)
278
280
  );
279
281
  if (errors.length > 0) {
280
282
  throw new AggregateError(errors, "Copilot runtime cleanup failed");
@@ -328,7 +330,7 @@ var SessionConfiguration = class {
328
330
  await this.ensureAutopilotPermissions(session);
329
331
  }
330
332
  const pending = this.#pendingModels.get(sessionId);
331
- 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)) {
333
+ if (pending !== void 0 && model.modelId === pending.modelId && (pending.contextTier === void 0 || model.contextTier === pending.contextTier) && (pending.reasoningEffort === "default" && model.modelId !== pending.previousModelId || pending.reasoningEffort === "default" && model.reasoningEffort === void 0 || model.reasoningEffort === pending.reasoningEffort || pending.reasoningEffort === "default" && model.reasoningEffort !== pending.previousEffort)) {
332
334
  this.#pendingModels.delete(sessionId);
333
335
  }
334
336
  const selected = this.#pendingModels.get(sessionId);
@@ -341,7 +343,8 @@ var SessionConfiguration = class {
341
343
  return {
342
344
  ...selectedModelId === void 0 ? {} : { modelId: selectedModelId },
343
345
  agentMode,
344
- reasoningEffort: selected?.reasoningEffort ?? reasoningEffort
346
+ reasoningEffort: selected?.reasoningEffort ?? reasoningEffort,
347
+ ...(selected?.contextTier ?? model.contextTier) === void 0 ? {} : { contextTier: selected?.contextTier ?? model.contextTier }
345
348
  };
346
349
  }
347
350
  async setAgentMode(session, mode) {
@@ -424,23 +427,38 @@ var SessionConfiguration = class {
424
427
  const session = await this.ports.getSession(sessionId);
425
428
  return await this.serializeSessionConfiguration(sessionId, async () => {
426
429
  this.ports.assertOriginalAction(sessionId);
427
- if (options.modelId !== void 0 || options.reasoningEffort !== void 0) {
430
+ if (options.modelId !== void 0 || options.reasoningEffort !== void 0 || options.contextTier !== void 0) {
428
431
  const currentModel = await session.rpc.model.getCurrent();
429
432
  const pending = this.#pendingModels.get(sessionId);
430
433
  const modelId = options.modelId ?? pending?.modelId ?? currentModel.modelId;
431
434
  if (modelId === void 0) {
432
435
  throw new Error(
433
- "Copilot did not report the current model for reasoning effort configuration"
436
+ "Copilot did not report the current model for configuration"
434
437
  );
435
438
  }
436
439
  const currentReasoningEffort = currentModel.reasoningEffort ?? this.#sessionReasoningEfforts.get(sessionId) ?? "default";
437
440
  const reasoningEffort = options.reasoningEffort ?? (modelId === pending?.modelId ? pending.reasoningEffort : modelId === currentModel.modelId ? currentReasoningEffort : "default");
438
- if (!(pending?.modelId === modelId && pending.reasoningEffort === reasoningEffort) && (modelId !== currentModel.modelId || reasoningEffort !== currentReasoningEffort || pending !== void 0)) {
441
+ let contextTier = options.contextTier ?? pending?.contextTier ?? currentModel.contextTier;
442
+ if (options.contextTier !== void 0 || options.modelId !== void 0 && modelId !== (pending?.modelId ?? currentModel.modelId) && contextTier === "long_context") {
443
+ const model = (await this.ports.listModels()).find((candidate) => candidate.id === modelId);
444
+ if (options.contextTier !== void 0 && !model?.contextTiers?.some((tier) => tier.id === options.contextTier)) {
445
+ throw new Error(`Copilot context tier is not available for ${modelId}: ${options.contextTier}`);
446
+ }
447
+ if (contextTier === "long_context" && !model?.contextTiers?.some((tier) => tier.id === contextTier)) {
448
+ contextTier = "default";
449
+ }
450
+ this.ports.assertOriginalAction(sessionId);
451
+ }
452
+ if (!(pending?.modelId === modelId && pending.reasoningEffort === reasoningEffort && pending.contextTier === contextTier) && (modelId !== currentModel.modelId || reasoningEffort !== currentReasoningEffort || contextTier !== currentModel.contextTier || pending !== void 0)) {
439
453
  const result = await session.rpc.model.switchTo({
440
454
  modelId,
441
455
  ...reasoningEffort === "default" ? {} : { reasoningEffort },
456
+ ...contextTier === void 0 ? {} : { contextTier },
442
457
  deferIfModelChangeQueued: true
443
458
  });
459
+ if (result.confirmation !== void 0 || result.persistenceError !== void 0) {
460
+ throw new Error(result.persistenceError ?? "Copilot requires confirmation before changing context size");
461
+ }
444
462
  if (!result.deferred && result.modelId !== modelId) {
445
463
  throw new Error(`Copilot did not apply the requested model: ${modelId}`);
446
464
  }
@@ -449,7 +467,8 @@ var SessionConfiguration = class {
449
467
  modelId,
450
468
  reasoningEffort,
451
469
  previousModelId: currentModel.modelId,
452
- previousEffort: currentReasoningEffort
470
+ previousEffort: currentReasoningEffort,
471
+ ...contextTier === void 0 ? {} : { contextTier }
453
472
  });
454
473
  } else {
455
474
  this.#pendingModels.delete(sessionId);
@@ -457,6 +476,9 @@ var SessionConfiguration = class {
457
476
  if (parsedEffort.success) {
458
477
  this.#sessionReasoningEfforts.set(sessionId, parsedEffort.data);
459
478
  }
479
+ if (contextTier !== void 0 && (await session.rpc.model.getCurrent()).contextTier !== contextTier) {
480
+ throw new Error(`Copilot did not apply the requested context tier: ${contextTier}`);
481
+ }
460
482
  }
461
483
  }
462
484
  }
@@ -3917,7 +3939,8 @@ var GithubCopilotAdapter = class {
3917
3939
  state: (sessionId) => this.#sessions.getOrCreate(sessionId),
3918
3940
  getSession: (sessionId) => this.#sessions.getSession(sessionId),
3919
3941
  isDeleted: (sessionId) => this.#deletingSessions.has(sessionId) || this.#deletedSessions.has(sessionId),
3920
- assertOriginalAction: (sessionId) => this.#assertOriginalGroupAction(sessionId)
3942
+ assertOriginalAction: (sessionId) => this.#assertOriginalGroupAction(sessionId),
3943
+ listModels: () => this.listModels()
3921
3944
  });
3922
3945
  #sessions = new SessionConnections({
3923
3946
  runtime: () => this.#runtime,
@@ -4020,6 +4043,7 @@ var GithubCopilotAdapter = class {
4020
4043
  sdkVersion = "1.0.26";
4021
4044
  agentModes = ["interactive", "plan", "autopilot"];
4022
4045
  supportsReasoningEffort = true;
4046
+ supportsContextTier = true;
4023
4047
  #upgradeSessionIds = /* @__PURE__ */ new Set();
4024
4048
  #upgradeRevision = 0;
4025
4049
  #activeWorkbenchOperations = 0;
@@ -4214,6 +4238,7 @@ var GithubCopilotAdapter = class {
4214
4238
  return {
4215
4239
  agentModes: group ? ["interactive"] : this.agentModes,
4216
4240
  supportsReasoningEffort: !group,
4241
+ supportsContextTier: !group,
4217
4242
  supportsFileAttachments: !group && this.supportsFileAttachments
4218
4243
  };
4219
4244
  }
@@ -4672,8 +4697,18 @@ var GithubCopilotAdapter = class {
4672
4697
  return models.map((model, index) => {
4673
4698
  const { supportedReasoningEfforts, defaultReasoningEffort, ...option } = NativeCopilotModelOptionSchema.parse({ ...model, isDefault: index === 0 });
4674
4699
  const defaultEffort = ReasoningEffortSchema.safeParse(defaultReasoningEffort);
4675
- return {
4700
+ const prices = model.billing?.tokenPrices;
4701
+ const tiers = prices?.longContext !== void 0 ? ["default", "long_context"] : model.supportedContextTiers ?? [];
4702
+ const contextTiers = [...new Set(tiers)].flatMap((tier) => {
4703
+ const parsed = SessionContextTierSchema.safeParse(tier);
4704
+ if (!parsed.success) return [];
4705
+ const budget = parsed.data === "default" ? prices : prices?.longContext;
4706
+ const maxPromptTokens = budget?.maxPromptTokens ?? budget?.contextMax;
4707
+ return [{ id: parsed.data, ...maxPromptTokens === void 0 ? {} : { maxPromptTokens } }];
4708
+ });
4709
+ return CopilotModelOptionSchema.parse({
4676
4710
  ...option,
4711
+ ...contextTiers.length > 1 ? { contextTiers } : {},
4677
4712
  ...supportedReasoningEfforts === void 0 ? {} : {
4678
4713
  supportedReasoningEfforts: supportedReasoningEfforts.flatMap((effort) => {
4679
4714
  const parsed = ReasoningEffortSchema.safeParse(effort);
@@ -4681,7 +4716,7 @@ var GithubCopilotAdapter = class {
4681
4716
  })
4682
4717
  },
4683
4718
  ...defaultEffort.success ? { defaultReasoningEffort: defaultEffort.data } : {}
4684
- };
4719
+ });
4685
4720
  });
4686
4721
  }
4687
4722
  async getSessionConfiguration(sessionId) {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  AgentSelectionSchema,
3
3
  assertSelectionSnapshotFits
4
- } from "./chunk-FDUJP3WA.js";
4
+ } from "./chunk-SIFCCGXF.js";
5
5
  import {
6
6
  isResearchSessionId
7
- } from "./chunk-2MERNOK6.js";
7
+ } from "./chunk-A4YCCQ3I.js";
8
8
  import {
9
9
  GroupChatError
10
- } from "./chunk-X3ZG6WMN.js";
10
+ } from "./chunk-ALUQLM54.js";
11
11
  import {
12
12
  AgentModelListingError,
13
13
  AgentSessionRenameError,
@@ -15,14 +15,14 @@ import {
15
15
  UnsupportedAgentOperationError,
16
16
  captureWorkbenchAccess,
17
17
  validateSessionName
18
- } from "./chunk-5DVJ7Y5W.js";
18
+ } from "./chunk-7CNBPLNE.js";
19
19
  import {
20
20
  SessionOperationError
21
- } from "./chunk-3OIHMMDF.js";
21
+ } from "./chunk-7OGTK7KB.js";
22
22
  import {
23
23
  InteractionResponseSchema,
24
24
  SessionSummarySchema
25
- } from "./chunk-LO4ZRE77.js";
25
+ } from "./chunk-P2PH5KMV.js";
26
26
 
27
27
  // src/managed-agent-adapter.ts
28
28
  import { createHash, randomUUID } from "node:crypto";
@@ -395,7 +395,8 @@ var ManagedCodingAgentAdapter = class {
395
395
  supportsFileAttachments: route.runtime.supportsFileAttachments === true,
396
396
  ...route.runtime.getSessionCapabilities?.(route.nativeId) ?? {
397
397
  agentModes: route.runtime.agentModes,
398
- supportsReasoningEffort: route.runtime.supportsReasoningEffort
398
+ supportsReasoningEffort: route.runtime.supportsReasoningEffort,
399
+ supportsContextTier: route.runtime.supportsContextTier === true
399
400
  },
400
401
  agentName: route.provider.candidate.name
401
402
  };
@@ -678,6 +679,9 @@ var ManagedCodingAgentAdapter = class {
678
679
  }
679
680
  configureSession(id, options) {
680
681
  return this.#withSession(id, async (route) => {
682
+ if (options.contextTier !== void 0 && !(route.runtime.getSessionCapabilities?.(route.nativeId) ?? route.runtime).supportsContextTier) {
683
+ throw new UnsupportedAgentOperationError(route.provider.candidate.id, "context tier configuration");
684
+ }
681
685
  const nativeModelId = options.modelId === void 0 ? void 0 : route.provider.models.get(options.modelId);
682
686
  if (options.modelId !== void 0 && nativeModelId === void 0) {
683
687
  throw new Error("Model is unavailable or belongs to another managed agent");
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  latestPreviewItems
3
- } from "./chunk-NDEJOXSX.js";
3
+ } from "./chunk-H4SHMWQ6.js";
4
4
  import {
5
5
  AgentSessionRenameError,
6
6
  UnsupportedAgentOperationError,
7
7
  validateSessionName
8
- } from "./chunk-5DVJ7Y5W.js";
9
- import "./chunk-3OIHMMDF.js";
8
+ } from "./chunk-7CNBPLNE.js";
9
+ import "./chunk-7OGTK7KB.js";
10
10
  import {
11
11
  InteractionRequestSchema,
12
12
  REASONING_EFFORTS,
13
13
  SESSION_TIMELINE_PAGE_SIZE
14
- } from "./chunk-LO4ZRE77.js";
14
+ } from "./chunk-P2PH5KMV.js";
15
15
 
16
16
  // src/pi-adapter.ts
17
17
  import { createHash as createHash2, randomUUID } from "node:crypto";
@@ -5,16 +5,16 @@ import {
5
5
  } from "./chunks/chunk-XPHAIOKN.js";
6
6
  import {
7
7
  AgentSelectionSchema
8
- } from "./chunks/chunk-FDUJP3WA.js";
8
+ } from "./chunks/chunk-SIFCCGXF.js";
9
9
  import {
10
10
  SessionImageRelayUrlSchema,
11
11
  SessionImagesConfigSchema
12
12
  } from "./chunks/chunk-IJPJQF7S.js";
13
13
  import {
14
14
  CODING_AGENT_IDS
15
- } from "./chunks/chunk-5DVJ7Y5W.js";
16
- import "./chunks/chunk-3OIHMMDF.js";
17
- import "./chunks/chunk-LO4ZRE77.js";
15
+ } from "./chunks/chunk-7CNBPLNE.js";
16
+ import "./chunks/chunk-7OGTK7KB.js";
17
+ import "./chunks/chunk-P2PH5KMV.js";
18
18
  export {
19
19
  AgentSelectionSchema,
20
20
  CODING_AGENT_IDS,
package/dist/index.d.ts CHANGED
@@ -571,6 +571,11 @@ declare const AgentConfigurationChangeSchema: z.ZodObject<{
571
571
  value: z.ZodString;
572
572
  }, z.core.$strict>;
573
573
  type AgentConfigurationChange = z.infer<typeof AgentConfigurationChangeSchema>;
574
+ declare const SessionContextTierSchema: z.ZodEnum<{
575
+ default: "default";
576
+ long_context: "long_context";
577
+ }>;
578
+ type SessionContextTier = z.infer<typeof SessionContextTierSchema>;
574
579
  declare const CopilotModelOptionSchema: z.ZodObject<{
575
580
  id: z.ZodString;
576
581
  name: z.ZodString;
@@ -589,6 +594,13 @@ declare const CopilotModelOptionSchema: z.ZodObject<{
589
594
  medium: "medium";
590
595
  xhigh: "xhigh";
591
596
  }>>;
597
+ contextTiers: z.ZodOptional<z.ZodArray<z.ZodObject<{
598
+ id: z.ZodEnum<{
599
+ default: "default";
600
+ long_context: "long_context";
601
+ }>;
602
+ maxPromptTokens: z.ZodOptional<z.ZodNumber>;
603
+ }, z.core.$strict>>>;
592
604
  creation: z.ZodOptional<z.ZodObject<{
593
605
  agentId: z.ZodString;
594
606
  agentName: z.ZodString;
@@ -1862,6 +1874,7 @@ interface AgentSessionConfiguration {
1862
1874
  modelId?: string;
1863
1875
  agentMode: SessionAgentMode;
1864
1876
  reasoningEffort: CurrentReasoningEffort;
1877
+ contextTier?: SessionContextTier;
1865
1878
  configOptions?: AgentConfigurationOption[];
1866
1879
  }
1867
1880
  interface AgentSessionCreateOptions {
@@ -1876,6 +1889,7 @@ interface AgentSessionConfigureOptions {
1876
1889
  modelId?: string;
1877
1890
  agentMode?: SessionAgentMode;
1878
1891
  reasoningEffort?: SessionReasoningEffort;
1892
+ contextTier?: SessionContextTier;
1879
1893
  configOption?: AgentConfigurationChange;
1880
1894
  }
1881
1895
  interface PeerTurnOptions {
@@ -1920,6 +1934,7 @@ interface CodingAgentAdapter {
1920
1934
  readonly sdkVersion: string;
1921
1935
  readonly agentModes: readonly SessionAgentMode[];
1922
1936
  readonly supportsReasoningEffort: boolean;
1937
+ readonly supportsContextTier?: boolean;
1923
1938
  readonly supportsSessionListUpdates?: boolean;
1924
1939
  readonly supportsAssistantPreview?: boolean;
1925
1940
  readonly supportsSessionDelete?: boolean;
@@ -1940,6 +1955,7 @@ interface CodingAgentAdapter {
1940
1955
  getSessionCapabilities?(sessionId?: string): {
1941
1956
  readonly agentModes: readonly SessionAgentMode[];
1942
1957
  readonly supportsReasoningEffort: boolean;
1958
+ readonly supportsContextTier?: boolean;
1943
1959
  readonly supportsFileAttachments?: boolean;
1944
1960
  readonly agentName?: string;
1945
1961
  readonly supportsPlanRead?: boolean;