@agentknight/sdk 0.9.57 → 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-WYDK3PLS.js → acp-adapter-MBYKOCA2.js} +4 -4
  2. package/dist/chunks/{chunk-OOCAIULD.js → chunk-3AMFPDE5.js} +435 -21
  3. package/dist/chunks/{chunk-3LEPYV7Y.js → chunk-7CNBPLNE.js} +2 -2
  4. package/dist/chunks/{chunk-7ZYBES47.js → chunk-7OGTK7KB.js} +1 -1
  5. package/dist/chunks/{chunk-WPVH7HKC.js → chunk-A4YCCQ3I.js} +1 -1
  6. package/dist/chunks/{chunk-EDZPP6SJ.js → chunk-ALUQLM54.js} +2 -3
  7. package/dist/chunks/{chunk-USI66MEF.js → chunk-CHKNC6PD.js} +3 -2
  8. package/dist/chunks/{chunk-ZLKFFKAX.js → chunk-CM5LVXVL.js} +4 -3
  9. package/dist/chunks/{chunk-IPJWNGNK.js → chunk-H4SHMWQ6.js} +1 -1
  10. package/dist/chunks/{chunk-KBI5IWPR.js → chunk-P2PH5KMV.js} +842 -557
  11. package/dist/chunks/{chunk-DAKDVZ7X.js → chunk-SIFCCGXF.js} +7 -5
  12. package/dist/chunks/{chunk-LT5ULDVT.js → chunk-ZNQ2I5EF.js} +1 -1
  13. package/dist/chunks/{claude-adapter-GCH36EZ6.js → claude-adapter-D3JWXMNX.js} +209 -59
  14. package/dist/chunks/{codex-adapter-CXD4SVCE.js → codex-adapter-655KHW7H.js} +4 -4
  15. package/dist/chunks/{copilot-adapter-SYFGOAGE.js → copilot-adapter-EZUXHBE3.js} +155 -25
  16. package/dist/chunks/{managed-agent-adapter-ODCNYYO6.js → managed-agent-adapter-BOJNEJ75.js} +25 -7
  17. package/dist/chunks/{pi-adapter-XLY46UDL.js → pi-adapter-LAD5GOCP.js} +4 -4
  18. package/dist/configuration.js +4 -4
  19. package/dist/index.d.ts +142 -1
  20. package/dist/index.js +1487 -578
  21. package/dist/runtime.js +2 -2
  22. package/dist/session-analytics-worker.js +162 -51
  23. package/package.json +1 -1
@@ -3,11 +3,13 @@ import {
3
3
  NotGitDirectoryError,
4
4
  PromptPreparationError,
5
5
  SESSION_PROJECT_IDENTITY_CONCURRENCY,
6
+ SessionDirectoryLister,
6
7
  SessionProjectIdentityError,
7
8
  SessionProjectIdentityReader,
8
9
  SessionRuntimeRegistry,
9
10
  SessionWorkbenchRuntime,
10
11
  isClosedCopilotConnection,
12
+ isClosedCopilotRuntimeHost,
11
13
  isDisposedCopilotSession,
12
14
  isSessionRestoreFailure,
13
15
  measureOperationStage,
@@ -16,7 +18,7 @@ import {
16
18
  recordTimelineSyncDiagnostic,
17
19
  resolveGitProjectIdentity,
18
20
  sanitizeGitRemoteUrl
19
- } from "./chunk-OOCAIULD.js";
21
+ } from "./chunk-3AMFPDE5.js";
20
22
  import "./chunk-IJPJQF7S.js";
21
23
  import {
22
24
  AnalyticsIndexResultSchema,
@@ -26,29 +28,29 @@ import {
26
28
  readSessionUpdatePage,
27
29
  resolveCopilotSessionDirectory,
28
30
  resumeWithCopilotSessionCompatibility
29
- } from "./chunk-ZLKFFKAX.js";
31
+ } from "./chunk-CM5LVXVL.js";
30
32
  import {
31
33
  ConversationNormalizer,
32
34
  isDisplayableHumanMessage
33
- } from "./chunk-LT5ULDVT.js";
35
+ } from "./chunk-ZNQ2I5EF.js";
34
36
  import {
35
37
  assertMainSessionId,
36
38
  isResearchSessionId
37
- } from "./chunk-WPVH7HKC.js";
39
+ } from "./chunk-A4YCCQ3I.js";
38
40
  import {
39
41
  GroupChatError,
40
42
  GroupChatMessageSchema,
41
43
  GroupChatRuntime
42
- } from "./chunk-EDZPP6SJ.js";
43
- import "./chunk-IPJWNGNK.js";
44
+ } from "./chunk-ALUQLM54.js";
45
+ import "./chunk-H4SHMWQ6.js";
44
46
  import {
45
47
  AgentSessionRenameError,
46
48
  TimelinePageBudgetError,
47
49
  validateSessionName
48
- } from "./chunk-3LEPYV7Y.js";
50
+ } from "./chunk-7CNBPLNE.js";
49
51
  import {
50
52
  SessionOperationError
51
- } from "./chunk-7ZYBES47.js";
53
+ } from "./chunk-7OGTK7KB.js";
52
54
  import {
53
55
  ConversationItemSchema,
54
56
  CopilotModelOptionSchema,
@@ -60,6 +62,7 @@ import {
60
62
  SESSION_TIMELINE_PAGE_SIZE,
61
63
  SessionAnalyticsResultSchema,
62
64
  SessionAvatarPersonaSchema,
65
+ SessionContextTierSchema,
63
66
  SessionReasoningEffortSchema,
64
67
  SessionRemoteStatusSchema,
65
68
  SessionSkillInfoSchema,
@@ -69,14 +72,16 @@ import {
69
72
  WorkbenchScheduleDraftSchema,
70
73
  WorkbenchScheduleEntrySchema,
71
74
  WorkbenchScheduleProposalSchema,
72
- WorkbenchScheduleSnapshotSchema
73
- } from "./chunk-KBI5IWPR.js";
75
+ WorkbenchScheduleSnapshotSchema,
76
+ WorkbenchTelemetrySchema
77
+ } from "./chunk-P2PH5KMV.js";
74
78
 
75
79
  // src/copilot-adapter.ts
76
80
  import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
81
+ import { existsSync, statSync } from "node:fs";
77
82
  import { readFile as readFile2, realpath as realpath2, stat } from "node:fs/promises";
78
83
  import { createRequire } from "node:module";
79
- import { basename as basename2, extname, isAbsolute, relative, resolve } from "node:path";
84
+ import { basename as basename2, dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve } from "node:path";
80
85
 
81
86
  // src/adapters/copilot/runtime/client-runtime.ts
82
87
  var CopilotClientRuntime = class {
@@ -181,7 +186,7 @@ var CopilotClientRuntime = class {
181
186
  }
182
187
  return result;
183
188
  } catch (error) {
184
- if (!isClosedCopilotConnection(error)) {
189
+ if (!isClosedCopilotConnection(error) && !isClosedCopilotRuntimeHost(error)) {
185
190
  throw error;
186
191
  }
187
192
  await measureOperationStage("runtime-recovery", () => this.recoverRuntime(client, error));
@@ -271,7 +276,7 @@ var CopilotClientRuntime = class {
271
276
  return;
272
277
  }
273
278
  const errors = (await client.stop()).filter(
274
- (error) => !isClosedCopilotConnection(error) && !isDisposedCopilotSession(error)
279
+ (error) => !isClosedCopilotConnection(error) && !isDisposedCopilotSession(error) && !isClosedCopilotRuntimeHost(error)
275
280
  );
276
281
  if (errors.length > 0) {
277
282
  throw new AggregateError(errors, "Copilot runtime cleanup failed");
@@ -325,7 +330,7 @@ var SessionConfiguration = class {
325
330
  await this.ensureAutopilotPermissions(session);
326
331
  }
327
332
  const pending = this.#pendingModels.get(sessionId);
328
- 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)) {
329
334
  this.#pendingModels.delete(sessionId);
330
335
  }
331
336
  const selected = this.#pendingModels.get(sessionId);
@@ -338,7 +343,8 @@ var SessionConfiguration = class {
338
343
  return {
339
344
  ...selectedModelId === void 0 ? {} : { modelId: selectedModelId },
340
345
  agentMode,
341
- reasoningEffort: selected?.reasoningEffort ?? reasoningEffort
346
+ reasoningEffort: selected?.reasoningEffort ?? reasoningEffort,
347
+ ...(selected?.contextTier ?? model.contextTier) === void 0 ? {} : { contextTier: selected?.contextTier ?? model.contextTier }
342
348
  };
343
349
  }
344
350
  async setAgentMode(session, mode) {
@@ -421,23 +427,38 @@ var SessionConfiguration = class {
421
427
  const session = await this.ports.getSession(sessionId);
422
428
  return await this.serializeSessionConfiguration(sessionId, async () => {
423
429
  this.ports.assertOriginalAction(sessionId);
424
- if (options.modelId !== void 0 || options.reasoningEffort !== void 0) {
430
+ if (options.modelId !== void 0 || options.reasoningEffort !== void 0 || options.contextTier !== void 0) {
425
431
  const currentModel = await session.rpc.model.getCurrent();
426
432
  const pending = this.#pendingModels.get(sessionId);
427
433
  const modelId = options.modelId ?? pending?.modelId ?? currentModel.modelId;
428
434
  if (modelId === void 0) {
429
435
  throw new Error(
430
- "Copilot did not report the current model for reasoning effort configuration"
436
+ "Copilot did not report the current model for configuration"
431
437
  );
432
438
  }
433
439
  const currentReasoningEffort = currentModel.reasoningEffort ?? this.#sessionReasoningEfforts.get(sessionId) ?? "default";
434
440
  const reasoningEffort = options.reasoningEffort ?? (modelId === pending?.modelId ? pending.reasoningEffort : modelId === currentModel.modelId ? currentReasoningEffort : "default");
435
- 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)) {
436
453
  const result = await session.rpc.model.switchTo({
437
454
  modelId,
438
455
  ...reasoningEffort === "default" ? {} : { reasoningEffort },
456
+ ...contextTier === void 0 ? {} : { contextTier },
439
457
  deferIfModelChangeQueued: true
440
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
+ }
441
462
  if (!result.deferred && result.modelId !== modelId) {
442
463
  throw new Error(`Copilot did not apply the requested model: ${modelId}`);
443
464
  }
@@ -446,7 +467,8 @@ var SessionConfiguration = class {
446
467
  modelId,
447
468
  reasoningEffort,
448
469
  previousModelId: currentModel.modelId,
449
- previousEffort: currentReasoningEffort
470
+ previousEffort: currentReasoningEffort,
471
+ ...contextTier === void 0 ? {} : { contextTier }
450
472
  });
451
473
  } else {
452
474
  this.#pendingModels.delete(sessionId);
@@ -454,6 +476,9 @@ var SessionConfiguration = class {
454
476
  if (parsedEffort.success) {
455
477
  this.#sessionReasoningEfforts.set(sessionId, parsedEffort.data);
456
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
+ }
457
482
  }
458
483
  }
459
484
  }
@@ -2313,7 +2338,7 @@ var SessionAnalytics = class {
2313
2338
  }
2314
2339
  observe(sessionId, event) {
2315
2340
  if (this.#closed || this.#removed.has(sessionId)) return;
2316
- if (event.type !== "assistant.usage" && event.type !== "user.message" && event.type !== "assistant.message" && event.type !== "session.skills_loaded") return;
2341
+ if (event.type !== "assistant.usage" && event.type !== "user.message" && event.type !== "assistant.message" && event.type !== "session.skills_loaded" && event.type !== "session.usage_info" && event.type !== "session.compaction_complete") return;
2317
2342
  if (event.agentId !== void 0 && event.type !== "assistant.usage") return;
2318
2343
  let data;
2319
2344
  let bytes = 1024 + (sessionId.length + event.id.length + event.timestamp.length + (event.agentId?.length ?? 0)) * 2;
@@ -2341,6 +2366,27 @@ var SessionAnalytics = class {
2341
2366
  }));
2342
2367
  data = { skills };
2343
2368
  bytes += skills.reduce((size, skill) => size + (skill.name.length + (skill.description?.length ?? 0) + skill.source.length + (skill.commandName?.length ?? 0)) * 2 + 256, 0);
2369
+ } else if (event.type === "session.usage_info") {
2370
+ data = {
2371
+ currentTokens: event.data.currentTokens,
2372
+ tokenLimit: event.data.tokenLimit,
2373
+ messagesLength: event.data.messagesLength
2374
+ };
2375
+ } else if (event.type === "session.compaction_complete") {
2376
+ data = {
2377
+ success: event.data.success,
2378
+ preCompactionTokens: event.data.preCompactionTokens,
2379
+ postCompactionTokens: event.data.postCompactionTokens,
2380
+ tokensRemoved: event.data.tokensRemoved,
2381
+ messagesRemoved: event.data.messagesRemoved,
2382
+ trigger: event.data.trigger,
2383
+ tokenAccountingBasis: event.data.tokenAccountingBasis,
2384
+ compactionTokensUsed: event.data.compactionTokensUsed === void 0 ? void 0 : {
2385
+ duration: event.data.compactionTokensUsed.duration,
2386
+ inputTokens: event.data.compactionTokensUsed.inputTokens,
2387
+ outputTokens: event.data.compactionTokensUsed.outputTokens
2388
+ }
2389
+ };
2344
2390
  } else {
2345
2391
  const accounting = event.data.accounting;
2346
2392
  data = {
@@ -2349,6 +2395,10 @@ var SessionAnalytics = class {
2349
2395
  outputTokens: event.data.outputTokens,
2350
2396
  cacheReadTokens: event.data.cacheReadTokens,
2351
2397
  apiCallId: event.data.apiCallId,
2398
+ requestBodyBytes: event.data.requestBodyBytes,
2399
+ requestBodyWireBytes: event.data.requestBodyWireBytes,
2400
+ duration: event.data.duration,
2401
+ outputTtftMs: event.data.outputTtftMs,
2352
2402
  accounting: accounting === void 0 ? void 0 : { sourceSessionId: accounting.sourceSessionId, usageId: accounting.usageId }
2353
2403
  };
2354
2404
  bytes += (event.data.model.length + (event.data.apiCallId?.length ?? 0) + (accounting?.sourceSessionId.length ?? 0) + (accounting?.usageId.length ?? 0)) * 2;
@@ -2498,6 +2548,19 @@ var SessionAnalytics = class {
2498
2548
  });
2499
2549
  return SessionAnalyticsResultSchema.parse(result);
2500
2550
  }
2551
+ async telemetry(sessionId, allowMissingEventLog = false) {
2552
+ if (this.#removed.has(sessionId)) throw new SessionOperationError("ANALYTICS_UNAVAILABLE", "Session analytics were deleted");
2553
+ await this.flush();
2554
+ if (this.#failures.has(sessionId)) {
2555
+ throw new SessionOperationError("ANALYTICS_UNAVAILABLE", "Analytics recording failed", { cause: this.#failures.get(sessionId) });
2556
+ }
2557
+ return WorkbenchTelemetrySchema.parse(await this.#request({
2558
+ operation: "telemetry",
2559
+ sessionId,
2560
+ environment: this.#environment(process.env),
2561
+ allowMissingEventLog
2562
+ }));
2563
+ }
2501
2564
  };
2502
2565
 
2503
2566
  // src/adapters/copilot/interactions/interaction-broker.ts
@@ -3675,8 +3738,45 @@ var require2 = createRequire(import.meta.url);
3675
3738
  function resolveCopilotRuntimePath(environment = process.env) {
3676
3739
  return environment["COPILOT_CLI_PATH"] ?? require2.resolve("@github/copilot/npm-loader.js");
3677
3740
  }
3741
+ function assertCopilotInProcessRuntime() {
3742
+ try {
3743
+ const entrypoint = process.env["COPILOT_CLI_PATH"];
3744
+ let platform = process.platform;
3745
+ if (platform === "linux") {
3746
+ const report = process.report?.getReport();
3747
+ const header = z5.object({ header: z5.object({ glibcVersionRuntime: z5.string().optional() }) }).safeParse(report);
3748
+ const musl = entrypoint?.includes(`copilot-linuxmusl-${process.arch}`) || !entrypoint?.includes(`copilot-linux-${process.arch}`) && (!header.success || header.data.header.glibcVersionRuntime === void 0);
3749
+ if (musl) platform = "linuxmusl";
3750
+ }
3751
+ const target = `${platform}-${process.arch}`;
3752
+ const files = [];
3753
+ if (entrypoint) {
3754
+ const directory = dirname2(resolve(entrypoint));
3755
+ const adjacent = join3(directory, "runtime.node");
3756
+ files.push(existsSync(adjacent) ? adjacent : join3(directory, "prebuilds", target, "runtime.node"));
3757
+ } else {
3758
+ const sdkRequire = createRequire(require2.resolve("@github/copilot-sdk"));
3759
+ const directory = dirname2(sdkRequire.resolve(`@github/copilot-sdk-${target}/package.json`));
3760
+ const prebuild = join3(directory, "prebuilds", target);
3761
+ files.push(
3762
+ join3(prebuild, "runtime.node"),
3763
+ join3(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3764
+ );
3765
+ }
3766
+ for (const path of files) {
3767
+ const file = statSync(path);
3768
+ if (!file.isFile() || file.size === 0) throw new Error(`Missing Copilot native runtime file: ${path}`);
3769
+ }
3770
+ } catch (error) {
3771
+ throw new Error(
3772
+ "Copilot inprocess runtime is unavailable. Unset COPILOT_SDK_DEFAULT_CONNECTION or set it to stdio to use the bundled CLI; inprocess requires a full SDK installation with its platform runtime, or COPILOT_CLI_PATH with an adjacent native runtime.",
3773
+ { cause: error }
3774
+ );
3775
+ }
3776
+ }
3678
3777
  function createCopilotClient() {
3679
- const defaultConnection = process.env["COPILOT_SDK_DEFAULT_CONNECTION"]?.toLowerCase();
3778
+ const defaultConnection = process.env["COPILOT_SDK_DEFAULT_CONNECTION"]?.toLowerCase() || void 0;
3779
+ if (defaultConnection === "inprocess") assertCopilotInProcessRuntime();
3680
3780
  const client = defaultConnection !== void 0 && defaultConnection !== "stdio" ? new CopilotClient({ mode: "copilot-cli" }) : new CopilotClient({
3681
3781
  mode: "copilot-cli",
3682
3782
  connection: RuntimeConnection.forStdio({
@@ -3839,7 +3939,8 @@ var GithubCopilotAdapter = class {
3839
3939
  state: (sessionId) => this.#sessions.getOrCreate(sessionId),
3840
3940
  getSession: (sessionId) => this.#sessions.getSession(sessionId),
3841
3941
  isDeleted: (sessionId) => this.#deletingSessions.has(sessionId) || this.#deletedSessions.has(sessionId),
3842
- assertOriginalAction: (sessionId) => this.#assertOriginalGroupAction(sessionId)
3942
+ assertOriginalAction: (sessionId) => this.#assertOriginalGroupAction(sessionId),
3943
+ listModels: () => this.listModels()
3843
3944
  });
3844
3945
  #sessions = new SessionConnections({
3845
3946
  runtime: () => this.#runtime,
@@ -3942,6 +4043,7 @@ var GithubCopilotAdapter = class {
3942
4043
  sdkVersion = "1.0.26";
3943
4044
  agentModes = ["interactive", "plan", "autopilot"];
3944
4045
  supportsReasoningEffort = true;
4046
+ supportsContextTier = true;
3945
4047
  #upgradeSessionIds = /* @__PURE__ */ new Set();
3946
4048
  #upgradeRevision = 0;
3947
4049
  #activeWorkbenchOperations = 0;
@@ -3960,6 +4062,12 @@ var GithubCopilotAdapter = class {
3960
4062
  #callbacks;
3961
4063
  #workbench = new SessionWorkbenchRuntime({
3962
4064
  getSession: (sessionId) => this.#sessions.getSession(sessionId),
4065
+ currentSession: (sessionId) => this.#sessions.current(sessionId),
4066
+ telemetry: (sessionId) => this.#analytics?.telemetry(
4067
+ sessionId,
4068
+ this.#provisionalSessions.get(sessionId)?.allowMissingEventLog === true
4069
+ ) ?? Promise.resolve(void 0),
4070
+ storage: (sessionId) => this.#sessionStorage.storage(sessionId),
3963
4071
  getRuntime: (sessionId) => this.#sessions.getOrCreate(sessionId),
3964
4072
  assertAvailable: (sessionId) => {
3965
4073
  assertMainSessionId(sessionId);
@@ -3992,7 +4100,9 @@ var GithubCopilotAdapter = class {
3992
4100
  });
3993
4101
  #schedules;
3994
4102
  #analytics;
4103
+ #sessionStorage = new SessionDirectoryLister((id) => this.getSessionDirectoryMetadata(id));
3995
4104
  workbench = {
4105
+ reasoning: (id, request) => this.#withWorkbenchOperation(() => this.#workbench.reasoning(id, request)),
3996
4106
  ask: (id, question) => this.#withWorkbenchOperation(() => this.#workbench.ask(id, question)),
3997
4107
  commands: (id) => this.#withWorkbenchOperation(() => this.#workbench.commands(id)),
3998
4108
  invokeCommand: (id, name, input) => this.#withWorkbenchOperation(() => this.#workbench.invokeCommand(id, name, input)),
@@ -4128,6 +4238,7 @@ var GithubCopilotAdapter = class {
4128
4238
  return {
4129
4239
  agentModes: group ? ["interactive"] : this.agentModes,
4130
4240
  supportsReasoningEffort: !group,
4241
+ supportsContextTier: !group,
4131
4242
  supportsFileAttachments: !group && this.supportsFileAttachments
4132
4243
  };
4133
4244
  }
@@ -4178,6 +4289,12 @@ var GithubCopilotAdapter = class {
4178
4289
  throw new GroupChatError("GROUP_CHAT_PARTICIPANT_BUSY", "Wait for the group-owned turn to stop before using its participant independently");
4179
4290
  }
4180
4291
  }
4292
+ assertPeerSession(sessionId) {
4293
+ assertMainSessionId(sessionId);
4294
+ if (!this.peerChatEnabled || this.#groups?.has(sessionId)) {
4295
+ throw new GroupChatError("GROUP_CHAT_PARTICIPANT_UNSUPPORTED", "Choose an ordinary peer-enabled Copilot session");
4296
+ }
4297
+ }
4181
4298
  runPeerTurn(sessionId, prompt, options) {
4182
4299
  try {
4183
4300
  assertMainSessionId(sessionId);
@@ -4459,7 +4576,10 @@ var GithubCopilotAdapter = class {
4459
4576
  throw new Error("Copilot returned metadata for a different session");
4460
4577
  }
4461
4578
  const workingDirectory = "workingDirectory" in metadata ? metadata.workingDirectory : metadata.context?.workingDirectory;
4462
- return workingDirectory === void 0 ? {} : { workingDirectory };
4579
+ return {
4580
+ ...workingDirectory === void 0 ? {} : { workingDirectory },
4581
+ ...this.supportsFileAttachments && !metadata.isRemote && "workspacePath" in metadata && metadata.workspacePath !== null ? { sessionStateDirectory: metadata.workspacePath } : {}
4582
+ };
4463
4583
  }
4464
4584
  #projectIdentity = new SessionProjectIdentityReader(
4465
4585
  (sessionId) => this.getSessionDirectoryMetadata(sessionId)
@@ -4577,8 +4697,18 @@ var GithubCopilotAdapter = class {
4577
4697
  return models.map((model, index) => {
4578
4698
  const { supportedReasoningEfforts, defaultReasoningEffort, ...option } = NativeCopilotModelOptionSchema.parse({ ...model, isDefault: index === 0 });
4579
4699
  const defaultEffort = ReasoningEffortSchema.safeParse(defaultReasoningEffort);
4580
- 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({
4581
4710
  ...option,
4711
+ ...contextTiers.length > 1 ? { contextTiers } : {},
4582
4712
  ...supportedReasoningEfforts === void 0 ? {} : {
4583
4713
  supportedReasoningEfforts: supportedReasoningEfforts.flatMap((effort) => {
4584
4714
  const parsed = ReasoningEffortSchema.safeParse(effort);
@@ -4586,7 +4716,7 @@ var GithubCopilotAdapter = class {
4586
4716
  })
4587
4717
  },
4588
4718
  ...defaultEffort.success ? { defaultReasoningEffort: defaultEffort.data } : {}
4589
- };
4719
+ });
4590
4720
  });
4591
4721
  }
4592
4722
  async getSessionConfiguration(sessionId) {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  AgentSelectionSchema,
3
3
  assertSelectionSnapshotFits
4
- } from "./chunk-DAKDVZ7X.js";
4
+ } from "./chunk-SIFCCGXF.js";
5
5
  import {
6
6
  isResearchSessionId
7
- } from "./chunk-WPVH7HKC.js";
7
+ } from "./chunk-A4YCCQ3I.js";
8
8
  import {
9
9
  GroupChatError
10
- } from "./chunk-EDZPP6SJ.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-3LEPYV7Y.js";
18
+ } from "./chunk-7CNBPLNE.js";
19
19
  import {
20
20
  SessionOperationError
21
- } from "./chunk-7ZYBES47.js";
21
+ } from "./chunk-7OGTK7KB.js";
22
22
  import {
23
23
  InteractionResponseSchema,
24
24
  SessionSummarySchema
25
- } from "./chunk-KBI5IWPR.js";
25
+ } from "./chunk-P2PH5KMV.js";
26
26
 
27
27
  // src/managed-agent-adapter.ts
28
28
  import { createHash, randomUUID } from "node:crypto";
@@ -166,6 +166,12 @@ var ManagedCodingAgentAdapter = class {
166
166
  queue: (id) => this.#withWorkbench(id, (runtime, native) => runtime.queue(native)),
167
167
  mutateQueue: (id, request) => this.#withWorkbench(id, (runtime, native) => runtime.mutateQueue(native, request)),
168
168
  insights: (id) => this.#withWorkbench(id, (runtime, native) => runtime.insights(native)),
169
+ reasoning: (id, request) => this.#withWorkbench(id, (runtime, native) => {
170
+ if (runtime.reasoning === void 0) {
171
+ throw new SessionOperationError("AGENT_OPERATION_UNSUPPORTED", "This agent does not expose thinking history");
172
+ }
173
+ return runtime.reasoning(native, request);
174
+ }, false),
169
175
  analytics: (id, request) => this.#withWorkbench(id, (runtime, native) => {
170
176
  if (runtime.analytics === void 0) {
171
177
  throw new SessionOperationError("ANALYTICS_UNSUPPORTED", "This agent does not expose passive analytics");
@@ -332,6 +338,14 @@ var ManagedCodingAgentAdapter = class {
332
338
  this.#inventoryChanged();
333
339
  }
334
340
  }
341
+ assertPeerSession(id) {
342
+ const route = this.#route(id);
343
+ if (!this.#peerChatPreference || route.provider.candidate.id !== "copilot" || route.runtime.runPeerTurn === void 0 || isResearchSessionId(route.nativeId) || route.provider.sessions.get(id)?.groupChat !== void 0) {
344
+ throw new UnsupportedAgentOperationError(route.provider.candidate.id, "peer session turns");
345
+ }
346
+ this.#assertRoute(route);
347
+ route.runtime.assertPeerSession?.(route.nativeId);
348
+ }
335
349
  async runPeerTurn(id, prompt, options) {
336
350
  if (!this.#peerChatPreference) throw new Error("Peer chat is disabled");
337
351
  options.signal.throwIfAborted();
@@ -381,7 +395,8 @@ var ManagedCodingAgentAdapter = class {
381
395
  supportsFileAttachments: route.runtime.supportsFileAttachments === true,
382
396
  ...route.runtime.getSessionCapabilities?.(route.nativeId) ?? {
383
397
  agentModes: route.runtime.agentModes,
384
- supportsReasoningEffort: route.runtime.supportsReasoningEffort
398
+ supportsReasoningEffort: route.runtime.supportsReasoningEffort,
399
+ supportsContextTier: route.runtime.supportsContextTier === true
385
400
  },
386
401
  agentName: route.provider.candidate.name
387
402
  };
@@ -664,6 +679,9 @@ var ManagedCodingAgentAdapter = class {
664
679
  }
665
680
  configureSession(id, options) {
666
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
+ }
667
685
  const nativeModelId = options.modelId === void 0 ? void 0 : route.provider.models.get(options.modelId);
668
686
  if (options.modelId !== void 0 && nativeModelId === void 0) {
669
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-IPJWNGNK.js";
3
+ } from "./chunk-H4SHMWQ6.js";
4
4
  import {
5
5
  AgentSessionRenameError,
6
6
  UnsupportedAgentOperationError,
7
7
  validateSessionName
8
- } from "./chunk-3LEPYV7Y.js";
9
- import "./chunk-7ZYBES47.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-KBI5IWPR.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-DAKDVZ7X.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-3LEPYV7Y.js";
16
- import "./chunks/chunk-7ZYBES47.js";
17
- import "./chunks/chunk-KBI5IWPR.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,