@agentknight/sdk 0.9.48 → 0.9.50

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SessionAssistantPreviewSchema,
3
3
  SessionUserPreviewSchema
4
- } from "./chunk-BDKVGENQ.js";
4
+ } from "./chunk-BMMKEB6V.js";
5
5
 
6
6
  // src/assistant-preview.ts
7
7
  function isContentfulAssistant(item) {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  CODING_AGENT_IDS
3
- } from "./chunk-R5LSWHRH.js";
3
+ } from "./chunk-4XVACOU5.js";
4
4
  import {
5
5
  SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH
6
- } from "./chunk-BDKVGENQ.js";
6
+ } from "./chunk-BMMKEB6V.js";
7
7
 
8
8
  // src/agent-selection.ts
9
9
  import { z } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionOperationError
3
- } from "./chunk-R5LSWHRH.js";
3
+ } from "./chunk-4XVACOU5.js";
4
4
 
5
5
  // src/adapters/copilot/runtime/session-identity.ts
6
6
  function assertMainSessionId(sessionId) {
@@ -0,0 +1,82 @@
1
+ // src/coding-agent-presentation.ts
2
+ var copilotIcon = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M23.922 16.992c-.861 1.495-5.859 5.023-11.922 5.023-6.063 0-11.061-3.528-11.922-5.023A.641.641 0 0 1 0 16.736v-2.869a.841.841 0 0 1 .053-.22c.372-.935 1.347-2.292 2.605-2.656.167-.429.414-1.055.644-1.517a10.195 10.195 0 0 1-.052-1.086c0-1.331.282-2.499 1.132-3.368.397-.406.89-.717 1.474-.952 1.399-1.136 3.392-2.093 6.122-2.093 2.731 0 4.767.957 6.166 2.093.584.235 1.077.546 1.474.952.85.869 1.132 2.037 1.132 3.368 0 .368-.014.733-.052 1.086.23.462.477 1.088.644 1.517 1.258.364 2.233 1.721 2.605 2.656a.832.832 0 0 1 .053.22v2.869a.641.641 0 0 1-.078.256ZM12.172 11h-.344a4.323 4.323 0 0 1-.355.508C10.703 12.455 9.555 13 7.965 13c-1.725 0-2.989-.359-3.782-1.259a2.005 2.005 0 0 1-.085-.104L4 11.741v6.585c1.435.779 4.514 2.179 8 2.179 3.486 0 6.565-1.4 8-2.179v-6.585l-.098-.104s-.033.045-.085.104c-.793.9-2.057 1.259-3.782 1.259-1.59 0-2.738-.545-3.508-1.492a4.323 4.323 0 0 1-.355-.508h-.016.016Zm.641-2.935c.136 1.057.403 1.913.878 2.497.442.544 1.134.938 2.344.938 1.573 0 2.292-.337 2.657-.751.384-.435.558-1.15.558-2.361 0-1.14-.243-1.847-.705-2.319-.477-.488-1.319-.862-2.824-1.025-1.487-.161-2.192.138-2.533.529-.269.307-.437.808-.438 1.578v.021c0 .265.021.562.063.893Zm-1.626 0c.042-.331.063-.628.063-.894v-.02c-.001-.77-.169-1.271-.438-1.578-.341-.391-1.046-.69-2.533-.529-1.505.163-2.347.537-2.824 1.025-.462.472-.705 1.179-.705 2.319 0 1.211.175 1.926.558 2.361.365.414 1.084.751 2.657.751 1.21 0 1.902-.394 2.344-.938.475-.584.742-1.44.878-2.497Z"/><path fill="currentColor" d="M14.5 14.25a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1Zm-5 0a1 1 0 0 1 1 1v2a1 1 0 0 1-2 0v-2a1 1 0 0 1 1-1Z"/></svg>';
3
+ var piIcon = '<span class="agent-pi-icon" aria-hidden="true">\u03C0</span>';
4
+ var genericIcon = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><g fill="none" stroke="currentColor" stroke-width="2"><rect x="4" y="6" width="16" height="14" rx="3"/><path d="M12 2v4M8 15h8"/><path d="M8 10v2m8-2v2"/></g></svg>';
5
+ var presentations = {
6
+ copilot: { name: "GitHub Copilot", icon: copilotIcon },
7
+ pi: { name: "PI", icon: piIcon },
8
+ codex: { name: "Codex", icon: genericIcon },
9
+ claude: { name: "Claude Code", icon: genericIcon },
10
+ acp: { name: "ACP", icon: genericIcon }
11
+ };
12
+ var fallback = { name: "Agent", icon: genericIcon };
13
+ function codingAgentPresentation(agentId) {
14
+ return Object.hasOwn(presentations, agentId) ? presentations[agentId] : fallback;
15
+ }
16
+
17
+ // src/config.ts
18
+ import { z } from "zod";
19
+ var SessionImagesConfigSchema = z.object({
20
+ allowUnencryptedStorage: z.literal(true),
21
+ storageAccount: z.string().regex(/^[a-z0-9]{3,24}$/u),
22
+ storageContainer: z.string().min(3).max(63).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u)
23
+ }).strict();
24
+ var SessionImageRelayUrlSchema = z.url().refine((value) => {
25
+ const url = new URL(value);
26
+ return /^https:\/\/[^/?#\\@\s\x00-\x1f\x7f]+\/?$/iu.test(value) && url.protocol === "https:" && url.username === "" && url.password === "" && url.pathname === "/" && url.search === "" && url.hash === "";
27
+ }, "Session images require an HTTPS Relay origin without a path, credentials, query or fragment").transform((value) => new URL(value).origin);
28
+
29
+ // src/device-identity.ts
30
+ import { z as z2 } from "zod";
31
+ var DeviceIdentitySchema = z2.object({
32
+ schemaVersion: z2.literal(2),
33
+ machineId: z2.uuid(),
34
+ stableDeviceId: z2.uuid(),
35
+ machineName: z2.string().trim().min(1).max(120),
36
+ createdAt: z2.iso.datetime({ offset: true })
37
+ });
38
+
39
+ // src/relay-authorization.ts
40
+ async function relayRequestToken(config) {
41
+ if (config.relayAuthorization === void 0) return config.relayToken;
42
+ const credential = await config.relayAuthorization.getAccessToken();
43
+ if (!Number.isSafeInteger(credential.expiresAt) || credential.expiresAt <= Date.now() || !/^[\x21-\x7e]{1,32768}$/u.test(credential.token)) {
44
+ throw new Error("Relay authorization expired or is invalid. Sign in again.");
45
+ }
46
+ return credential.token;
47
+ }
48
+
49
+ // src/legacy-client-state.ts
50
+ var LEGACY_CLIENT_STATE_DIRECTORY = Buffer.from("2e626c7565706177", "hex").toString("utf8");
51
+
52
+ export {
53
+ codingAgentPresentation,
54
+ SessionImagesConfigSchema,
55
+ SessionImageRelayUrlSchema,
56
+ DeviceIdentitySchema,
57
+ relayRequestToken,
58
+ LEGACY_CLIENT_STATE_DIRECTORY
59
+ };
60
+ /*!
61
+ * Copilot artwork: https://github.com/primer/octicons
62
+ * MIT License
63
+ * Copyright (c) 2026 GitHub Inc.
64
+ *
65
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
66
+ * of this software and associated documentation files (the "Software"), to deal
67
+ * in the Software without restriction, including without limitation the rights
68
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
69
+ * copies of the Software, and to permit persons to whom the Software is
70
+ * furnished to do so, subject to the following conditions:
71
+ *
72
+ * The above copyright notice and this permission notice shall be included in all
73
+ * copies or substantial portions of the Software.
74
+ *
75
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
76
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
78
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
79
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
80
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
81
+ * SOFTWARE.
82
+ */
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  IdSchema
3
- } from "./chunk-BDKVGENQ.js";
3
+ } from "./chunk-BMMKEB6V.js";
4
4
 
5
5
  // src/data-directory.ts
6
6
  import { randomUUID } from "node:crypto";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  AgentSessionRenameError,
3
3
  validateSessionName
4
- } from "./chunk-R5LSWHRH.js";
4
+ } from "./chunk-4XVACOU5.js";
5
5
  import {
6
6
  ConversationItemSchema,
7
7
  GroupChatInfoSchema,
8
8
  GroupChatParticipantSchema,
9
9
  SESSION_TIMELINE_PAGE_SIZE,
10
10
  SessionSummarySchema
11
- } from "./chunk-BDKVGENQ.js";
11
+ } from "./chunk-BMMKEB6V.js";
12
12
 
13
13
  // src/group-chat.ts
14
14
  import { createHash, randomUUID } from "node:crypto";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  isContentfulAssistant
3
- } from "./chunk-6VEMXJW4.js";
3
+ } from "./chunk-FEH4GODE.js";
4
4
  import {
5
5
  SessionOperationError
6
- } from "./chunk-R5LSWHRH.js";
6
+ } from "./chunk-4XVACOU5.js";
7
7
  import {
8
8
  CONVERSATION_SOURCE_ID_LIMIT,
9
9
  SESSION_DIRECTORY_LIST_OPERATION,
@@ -23,7 +23,7 @@ import {
23
23
  WorkbenchInsightsSchema,
24
24
  WorkbenchQueueMutationResultSchema,
25
25
  WorkbenchQueueSnapshotSchema
26
- } from "./chunk-BDKVGENQ.js";
26
+ } from "./chunk-BMMKEB6V.js";
27
27
 
28
28
  // src/operation-diagnostics.ts
29
29
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -3,18 +3,18 @@ import {
3
3
  } from "./chunk-T6226JFS.js";
4
4
  import {
5
5
  latestPreviewItems
6
- } from "./chunk-6VEMXJW4.js";
6
+ } from "./chunk-FEH4GODE.js";
7
7
  import {
8
8
  UnsupportedAgentOperationError,
9
9
  validateSessionName
10
- } from "./chunk-R5LSWHRH.js";
10
+ } from "./chunk-4XVACOU5.js";
11
11
  import {
12
12
  ConversationItemSchema,
13
13
  InteractionRequestSchema,
14
14
  InteractionResponseSchema,
15
15
  SESSION_TIMELINE_PAGE_SIZE,
16
16
  SessionSummarySchema
17
- } from "./chunk-BDKVGENQ.js";
17
+ } from "./chunk-BMMKEB6V.js";
18
18
 
19
19
  // src/claude-adapter.ts
20
20
  import { randomUUID as randomUUID2 } from "node:crypto";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  latestPreviewItems
3
- } from "./chunk-6VEMXJW4.js";
3
+ } from "./chunk-FEH4GODE.js";
4
4
  import {
5
5
  UnsupportedAgentOperationError
6
- } from "./chunk-R5LSWHRH.js";
6
+ } from "./chunk-4XVACOU5.js";
7
7
  import {
8
8
  ConversationItemSchema,
9
9
  InteractionRequestSchema,
10
10
  SESSION_TIMELINE_PAGE_SIZE,
11
11
  SessionSummarySchema
12
- } from "./chunk-BDKVGENQ.js";
12
+ } from "./chunk-BMMKEB6V.js";
13
13
 
14
14
  // src/codex-adapter.ts
15
15
  import { randomUUID } from "node:crypto";
@@ -285,6 +285,40 @@ var CodexRpc = class {
285
285
  // src/adapters/codex/protocol.ts
286
286
  import { z as z3 } from "zod";
287
287
  var NativeId = z3.string().min(1).max(256);
288
+ var NativeEffort = z3.string().min(1).max(64);
289
+ var CollaborationMode = z3.object({
290
+ mode: NativeId,
291
+ settings: z3.object({
292
+ model: NativeId,
293
+ reasoning_effort: NativeEffort.nullable(),
294
+ developer_instructions: z3.string().nullable()
295
+ })
296
+ });
297
+ var ModelList = z3.object({
298
+ data: z3.array(z3.object({
299
+ model: NativeId,
300
+ displayName: z3.string().min(1).max(260),
301
+ hidden: z3.boolean().optional(),
302
+ isDefault: z3.boolean().optional(),
303
+ supportedReasoningEfforts: z3.array(z3.object({ reasoningEffort: NativeEffort })).max(99).optional(),
304
+ defaultReasoningEffort: NativeEffort.optional()
305
+ })),
306
+ nextCursor: z3.string().nullable()
307
+ });
308
+ var CollaborationModes = z3.object({
309
+ data: z3.array(z3.object({
310
+ name: z3.string().min(1).max(260),
311
+ mode: NativeId.nullable()
312
+ })).max(100)
313
+ });
314
+ var SettingsUpdated = z3.object({
315
+ threadId: NativeId,
316
+ threadSettings: z3.object({
317
+ model: NativeId,
318
+ effort: NativeEffort.nullable(),
319
+ collaborationMode: CollaborationMode
320
+ })
321
+ });
288
322
  var NativeItem = z3.object({
289
323
  id: NativeId,
290
324
  type: z3.string(),
@@ -308,7 +342,10 @@ var ThreadResult = z3.object({
308
342
  id: NativeId,
309
343
  status: z3.object({ type: z3.enum(["notLoaded", "idle", "active", "systemError"]) }),
310
344
  turns: z3.array(NativeTurn)
311
- })
345
+ }),
346
+ model: NativeId.optional(),
347
+ reasoningEffort: NativeEffort.nullable().optional(),
348
+ collaborationMode: CollaborationMode.nullable().optional()
312
349
  });
313
350
  var EventContext = z3.object({ threadId: NativeId, turnId: NativeId });
314
351
  var ItemEvent = EventContext.extend({ item: NativeItem });
@@ -391,12 +428,16 @@ function projectItem(threadId, turnId, item, completed, timestamp) {
391
428
 
392
429
  // src/codex-adapter.ts
393
430
  var CODEX_DEFAULT_MODEL_ID = "codex:agent-default";
431
+ var EFFORT_OPTION = "codex:reasoning-effort";
432
+ var MODE_OPTION = "codex:collaboration-mode";
394
433
  var StoredSession = z4.object({
395
434
  summary: SessionSummarySchema,
396
435
  modelId: z4.string(),
397
436
  items: z4.array(ConversationItemSchema),
398
437
  uncertain: z4.boolean(),
399
- native: z4.boolean().optional()
438
+ native: z4.boolean().optional(),
439
+ reasoningEffort: NativeEffort.nullable().optional(),
440
+ collaborationMode: CollaborationMode.optional()
400
441
  });
401
442
  var Inventory = z4.object({
402
443
  version: z4.literal(1),
@@ -407,6 +448,7 @@ var CodexCodingAgentAdapter = class {
407
448
  agentId = "codex";
408
449
  sdkVersion = "app-server-v2 (rust-v0.160.0)";
409
450
  agentModes = ["interactive"];
451
+ // Codex reasoning values use opaque configOptions, not the legacy Copilot enum.
410
452
  supportsReasoningEffort = false;
411
453
  supportsFileAttachments = false;
412
454
  supportsSessionDelete = false;
@@ -431,6 +473,8 @@ var CodexCodingAgentAdapter = class {
431
473
  #saveRunning;
432
474
  #saveVersion = 0;
433
475
  #operations = 0;
476
+ #models = /* @__PURE__ */ new Map();
477
+ #modes;
434
478
  constructor(options) {
435
479
  for (const limit of [options.requestTimeoutMs, options.interactionTimeoutMs, options.maxFrameBytes]) {
436
480
  if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 1)) throw new RangeError("Codex limits must be positive integers");
@@ -532,6 +576,8 @@ var CodexCodingAgentAdapter = class {
532
576
  throw this.#fatal;
533
577
  }
534
578
  this.#rpc = void 0;
579
+ this.#modes = void 0;
580
+ this.#models.clear();
535
581
  this.#sessions.clear();
536
582
  this.#discovered.clear();
537
583
  this.#retiredSessions.clear();
@@ -615,12 +661,14 @@ var CodexCodingAgentAdapter = class {
615
661
  const snapshot = JSON.stringify({
616
662
  version: 1,
617
663
  identity: this.#identity,
618
- sessions: [...this.#sessions.values()].map(({ summary, modelId, items, uncertain, native }) => ({
664
+ sessions: [...this.#sessions.values()].map(({ summary, modelId, items, uncertain, native, reasoningEffort, collaborationMode }) => ({
619
665
  summary,
620
666
  modelId,
621
667
  items,
622
668
  uncertain,
623
- ...native === void 0 ? {} : { native }
669
+ ...native === void 0 ? {} : { native },
670
+ ...reasoningEffort === void 0 ? {} : { reasoningEffort },
671
+ ...collaborationMode === void 0 ? {} : { collaborationMode }
624
672
  }))
625
673
  });
626
674
  const staging = join2(this.#directory, `inventory-${randomUUID()}.tmp`);
@@ -786,20 +834,17 @@ var CodexCodingAgentAdapter = class {
786
834
  const models = /* @__PURE__ */ new Map([
787
835
  [CODEX_DEFAULT_MODEL_ID, { id: CODEX_DEFAULT_MODEL_ID, name: "Codex default", isDefault: true }]
788
836
  ]);
837
+ const catalog = /* @__PURE__ */ new Map();
789
838
  let cursor = null;
790
839
  const seen = /* @__PURE__ */ new Set();
791
840
  do {
792
- const result = z4.object({
793
- data: z4.array(z4.object({
794
- model: z4.string().min(1).max(256),
795
- displayName: z4.string().min(1).max(260),
796
- hidden: z4.boolean().optional()
797
- })),
798
- nextCursor: z4.string().nullable()
799
- }).parse(await rpc.request("model/list", { cursor, limit: 100 }));
841
+ const result = ModelList.parse(await rpc.request("model/list", { cursor, limit: 100 }));
800
842
  this.#ready();
801
843
  for (const model of result.data) {
802
- if (!model.hidden) models.set(model.model, { id: model.model, name: model.displayName, isDefault: false });
844
+ if (!model.hidden) {
845
+ models.set(model.model, { id: model.model, name: model.displayName, isDefault: false });
846
+ catalog.set(model.model, model);
847
+ }
803
848
  }
804
849
  cursor = result.nextCursor;
805
850
  if (cursor !== null) {
@@ -807,6 +852,7 @@ var CodexCodingAgentAdapter = class {
807
852
  seen.add(cursor);
808
853
  }
809
854
  } while (cursor !== null);
855
+ this.#models = catalog;
810
856
  return [...models.values()];
811
857
  } finally {
812
858
  this.#operations--;
@@ -853,6 +899,7 @@ var CodexCodingAgentAdapter = class {
853
899
  items: [],
854
900
  uncertain: result.thread.status.type !== "idle" || result.thread.turns.some((turn) => turn.status === "inProgress")
855
901
  });
902
+ this.#acceptConfiguration(session, result);
856
903
  session.loaded = true;
857
904
  this.#sessions.set(summary.sessionId, session);
858
905
  await this.#save();
@@ -863,13 +910,126 @@ var CodexCodingAgentAdapter = class {
863
910
  }
864
911
  }
865
912
  async getSessionConfiguration(id) {
866
- return { modelId: this.#known(id).modelId, agentMode: "interactive", reasoningEffort: "default" };
913
+ const session = this.#known(id);
914
+ return this.#locked(session, async () => {
915
+ if (!session.loaded) this.#checkConfigure(session);
916
+ await this.#load(session, true);
917
+ await this.listModels(id);
918
+ return this.#configuration(session);
919
+ });
867
920
  }
868
921
  async configureSession(id, options) {
869
922
  const session = this.#known(id);
870
- this.#validate(options);
871
- if (options.modelId !== void 0 && options.modelId !== session.modelId) this.#unsupported("changing a session model");
872
- return this.getSessionConfiguration(id);
923
+ if (options.agentMode !== void 0 && options.agentMode !== "interactive") this.#unsupported("agent modes");
924
+ if (options.configOption && ![EFFORT_OPTION, MODE_OPTION].includes(options.configOption.id)) {
925
+ this.#unsupported("native configuration option");
926
+ }
927
+ this.#checkConfigure(session);
928
+ return this.#locked(session, async () => {
929
+ this.#checkConfigure(session);
930
+ await this.listModels(id);
931
+ const modes = await this.#listModes();
932
+ const requestedModel = options.modelId === CODEX_DEFAULT_MODEL_ID ? [...this.#models.values()].find((model2) => model2.isDefault)?.model : options.modelId;
933
+ if (options.modelId !== void 0 && (requestedModel === void 0 || !this.#models.has(requestedModel))) {
934
+ throw new Error("Model is not advertised by Codex");
935
+ }
936
+ const requestedMode = options.configOption?.id === MODE_OPTION ? options.configOption.value : void 0;
937
+ if (requestedMode !== void 0 && !modes.some((mode) => mode.mode === requestedMode)) {
938
+ throw new Error("Mode is not advertised by Codex");
939
+ }
940
+ await this.#load(session);
941
+ this.#checkConfigure(session);
942
+ const model = requestedModel ?? session.modelId;
943
+ const catalog = this.#models.get(model);
944
+ const requestedEffort = options.configOption?.id === EFFORT_OPTION ? options.configOption.value : options.reasoningEffort;
945
+ if (requestedModel === void 0 && requestedEffort === void 0 && requestedMode === void 0) {
946
+ return this.#configuration(session);
947
+ }
948
+ const effort = requestedEffort === "default" ? catalog?.defaultReasoningEffort : requestedEffort ?? (requestedModel === void 0 ? session.reasoningEffort : catalog?.defaultReasoningEffort);
949
+ if ((requestedEffort !== void 0 || requestedModel !== void 0) && (effort === void 0 || !catalog?.supportedReasoningEfforts?.some((entry) => entry.reasoningEffort === effort))) {
950
+ if (requestedEffort !== void 0 || effort !== void 0) throw new Error("Reasoning effort is not advertised for this Codex model");
951
+ }
952
+ const rpc = await this.#native();
953
+ this.#checkConfigure(session);
954
+ const params = {
955
+ threadId: id,
956
+ ...requestedModel === void 0 ? {} : { model },
957
+ ...effort == null ? {} : { effort },
958
+ ...requestedMode === void 0 ? {} : { collaborationMode: {
959
+ mode: requestedMode,
960
+ settings: { model, reasoning_effort: effort ?? null, developer_instructions: null }
961
+ } }
962
+ };
963
+ let applied = false;
964
+ try {
965
+ z4.object({}).parse(await rpc.request("thread/settings/update", params));
966
+ applied = true;
967
+ const result = ThreadResult.required({ model: true, reasoningEffort: true }).parse(await rpc.request("thread/resume", { threadId: id }));
968
+ this.#known(id);
969
+ if (result.thread.id !== id || result.thread.status.type !== "idle" || requestedModel !== void 0 && result.model !== model || effort != null && result.reasoningEffort !== effort || requestedMode !== void 0 && result.collaborationMode?.mode !== requestedMode) {
970
+ throw new Error("Codex did not confirm the requested session configuration");
971
+ }
972
+ this.#acceptConfiguration(session, result);
973
+ await this.#save();
974
+ return this.#configuration(session);
975
+ } catch (error) {
976
+ if (applied || !(error instanceof CodexRpcError)) {
977
+ session.uncertain = true;
978
+ await this.#save();
979
+ }
980
+ throw error;
981
+ }
982
+ });
983
+ }
984
+ #checkConfigure(session) {
985
+ this.#known(session.summary.sessionId);
986
+ if (this.#fatal) throw this.#fatal;
987
+ if (session.active || session.sending || session.aborting || session.uncertain || session.queue.length || [...this.#pending.values()].some((pending) => pending.session === session)) {
988
+ throw new Error("Codex session is busy or its outcome is unknown; wait for it to become idle before changing settings");
989
+ }
990
+ }
991
+ #listModes() {
992
+ return this.#modes ??= (async () => {
993
+ try {
994
+ return CollaborationModes.parse(await (await this.#native()).request("collaborationMode/list", {})).data;
995
+ } catch (error) {
996
+ if (error instanceof CodexRpcError && error.code === -32601) return [];
997
+ this.#modes = void 0;
998
+ throw error;
999
+ }
1000
+ })();
1001
+ }
1002
+ async #configuration(session) {
1003
+ const configOptions = [];
1004
+ const model = this.#models.get(session.modelId);
1005
+ const efforts = model?.supportedReasoningEfforts;
1006
+ if (efforts?.length) configOptions.push({
1007
+ id: EFFORT_OPTION,
1008
+ name: "Reasoning",
1009
+ value: session.reasoningEffort ?? "default",
1010
+ options: [...efforts.some((entry) => entry.reasoningEffort === model?.defaultReasoningEffort) ? [{ value: "default", name: "Default" }] : [], ...efforts.map(({ reasoningEffort }) => ({
1011
+ value: reasoningEffort,
1012
+ name: reasoningEffort
1013
+ }))]
1014
+ });
1015
+ const modes = (await this.#listModes()).flatMap(({ mode, name }) => mode === null ? [] : [{ value: mode, name }]);
1016
+ if (modes.length && session.collaborationMode) configOptions.push({
1017
+ id: MODE_OPTION,
1018
+ name: "Mode",
1019
+ value: session.collaborationMode.mode,
1020
+ options: modes
1021
+ });
1022
+ return {
1023
+ modelId: session.modelId,
1024
+ agentMode: "interactive",
1025
+ reasoningEffort: session.reasoningEffort ?? "default",
1026
+ configOptions
1027
+ };
1028
+ }
1029
+ #acceptConfiguration(session, result) {
1030
+ if (result.model !== void 0) session.modelId = result.model;
1031
+ if (result.reasoningEffort !== void 0) session.reasoningEffort = result.reasoningEffort;
1032
+ if (result.collaborationMode != null) session.collaborationMode = result.collaborationMode;
873
1033
  }
874
1034
  async getSessionDirectoryMetadata(id) {
875
1035
  const cwd = this.#known(id).summary.workingDirectory;
@@ -972,8 +1132,12 @@ var CodexCodingAgentAdapter = class {
972
1132
  });
973
1133
  return work;
974
1134
  }
975
- async #load(session) {
976
- if (session.loaded) return;
1135
+ async #load(session, readConfiguration = false) {
1136
+ if (session.loaded) {
1137
+ if (!readConfiguration || session.collaborationMode !== void 0 || session.active || session.sending || session.aborting || session.uncertain || session.queue.length) return;
1138
+ if (!(await this.#listModes()).length) return;
1139
+ this.#checkConfigure(session);
1140
+ }
977
1141
  const rpc = await this.#native();
978
1142
  const threadId = session.summary.sessionId;
979
1143
  const read = ThreadResult.parse(await rpc.request("thread/read", { threadId, includeTurns: true }));
@@ -992,11 +1156,7 @@ var CodexCodingAgentAdapter = class {
992
1156
  await this.#save();
993
1157
  }
994
1158
  const resumed = ThreadResult.parse(await rpc.request("thread/resume", {
995
- threadId,
996
- cwd: session.summary.workingDirectory,
997
- approvalPolicy: "on-request",
998
- approvalsReviewer: "user",
999
- sandbox: "workspace-write"
1159
+ threadId
1000
1160
  }));
1001
1161
  if (resumed.thread.id !== threadId || resumed.thread.status.type !== "idle") {
1002
1162
  session.uncertain = true;
@@ -1004,6 +1164,7 @@ var CodexCodingAgentAdapter = class {
1004
1164
  throw new Error("Codex resume did not confirm an idle owned thread");
1005
1165
  }
1006
1166
  this.#importHistory(session, resumed.thread.turns, true);
1167
+ this.#acceptConfiguration(session, resumed);
1007
1168
  session.loaded = true;
1008
1169
  await this.#save();
1009
1170
  }
@@ -1152,6 +1313,17 @@ var CodexCodingAgentAdapter = class {
1152
1313
  const context = z4.object({ threadId: NativeId }).safeParse(params);
1153
1314
  if (!context.success) return;
1154
1315
  const session = this.#sessions.get(context.data.threadId);
1316
+ if (session?.loaded && method === "thread/settings/updated") {
1317
+ const { threadSettings } = SettingsUpdated.parse(params);
1318
+ this.#acceptConfiguration(session, {
1319
+ model: threadSettings.model,
1320
+ reasoningEffort: threadSettings.effort,
1321
+ collaborationMode: threadSettings.collaborationMode
1322
+ });
1323
+ void this.#save().catch(() => {
1324
+ });
1325
+ return;
1326
+ }
1155
1327
  if (session && method === "serverRequest/resolved") {
1156
1328
  const resolved = z4.object({ requestId: z4.union([z4.string(), z4.number().int()]) }).parse(params);
1157
1329
  for (const [id, pending] of this.#pending) {
@@ -18,25 +18,25 @@ import {
18
18
  recordTimelineSyncDiagnostic,
19
19
  resolveGitProjectIdentity,
20
20
  sanitizeGitRemoteUrl
21
- } from "./chunk-RX7VGB3T.js";
21
+ } from "./chunk-ZVPUOCY5.js";
22
22
  import {
23
23
  assertMainSessionId,
24
24
  isResearchSessionId
25
- } from "./chunk-2QHOQXOR.js";
25
+ } from "./chunk-LDF3XNVN.js";
26
26
  import {
27
27
  GroupChatError,
28
28
  GroupChatMessageSchema,
29
29
  GroupChatRuntime
30
- } from "./chunk-H6FG5CCS.js";
30
+ } from "./chunk-UXIZLEZV.js";
31
31
  import {
32
32
  isContentfulAssistant
33
- } from "./chunk-6VEMXJW4.js";
33
+ } from "./chunk-FEH4GODE.js";
34
34
  import {
35
35
  AgentSessionRenameError,
36
36
  SessionOperationError,
37
37
  TimelinePageBudgetError,
38
38
  validateSessionName
39
- } from "./chunk-R5LSWHRH.js";
39
+ } from "./chunk-4XVACOU5.js";
40
40
  import {
41
41
  ConversationItemSchema,
42
42
  CopilotModelOptionSchema,
@@ -57,7 +57,7 @@ import {
57
57
  WorkbenchScheduleEntrySchema,
58
58
  WorkbenchScheduleProposalSchema,
59
59
  WorkbenchScheduleSnapshotSchema
60
- } from "./chunk-BDKVGENQ.js";
60
+ } from "./chunk-BMMKEB6V.js";
61
61
 
62
62
  // src/copilot-adapter.ts
63
63
  import { createHash as createHash4, randomUUID as randomUUID6 } from "node:crypto";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  AgentSelectionSchema,
3
3
  assertSelectionSnapshotFits
4
- } from "./chunk-YFLDTX2W.js";
4
+ } from "./chunk-HHI2UYWK.js";
5
5
  import {
6
6
  isResearchSessionId
7
- } from "./chunk-2QHOQXOR.js";
7
+ } from "./chunk-LDF3XNVN.js";
8
8
  import {
9
9
  GroupChatError
10
- } from "./chunk-H6FG5CCS.js";
10
+ } from "./chunk-UXIZLEZV.js";
11
11
  import {
12
12
  AgentModelListingError,
13
13
  AgentSessionRenameError,
@@ -16,11 +16,11 @@ import {
16
16
  UnsupportedAgentOperationError,
17
17
  captureWorkbenchAccess,
18
18
  validateSessionName
19
- } from "./chunk-R5LSWHRH.js";
19
+ } from "./chunk-4XVACOU5.js";
20
20
  import {
21
21
  InteractionResponseSchema,
22
22
  SessionSummarySchema
23
- } from "./chunk-BDKVGENQ.js";
23
+ } from "./chunk-BMMKEB6V.js";
24
24
 
25
25
  // src/managed-agent-adapter.ts
26
26
  import { createHash, randomUUID } from "node:crypto";
@@ -722,6 +722,22 @@ var ManagedCodingAgentAdapter = class {
722
722
  return { ...page, items: page.items.map((item) => this.#item(route, item)) };
723
723
  });
724
724
  }
725
+ async readLocalSessionTimelinePage(id, options) {
726
+ this.#assertStarted();
727
+ const provider = this.#owner(id);
728
+ const native = provider?.sessions.get(id);
729
+ const runtime = provider?.runtime;
730
+ if (!provider?.available || !native || !runtime || this.#deleted.has(id)) {
731
+ throw new Error("Local session is no longer available");
732
+ }
733
+ const route = { provider, runtime, sessionId: id, nativeId: native.sessionId, epoch: this.#epoch(id) };
734
+ const page = await runtime.readSessionTimelinePage(native.sessionId, options);
735
+ this.#assertStarted();
736
+ if (provider.runtime !== runtime || !provider.available || !provider.sessions.has(id) || this.#deleted.has(id) || this.#epoch(id) !== route.epoch) {
737
+ throw new Error("Local session changed during the history read");
738
+ }
739
+ return { ...page, items: page.items.map((item) => this.#item(route, item)) };
740
+ }
725
741
  readSessionPlan(id) {
726
742
  return this.#withSession(id, async (route) => {
727
743
  if (route.runtime.readSessionPlan) {
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  latestPreviewItems
3
- } from "./chunk-6VEMXJW4.js";
3
+ } from "./chunk-FEH4GODE.js";
4
4
  import {
5
5
  AgentSessionRenameError,
6
6
  UnsupportedAgentOperationError,
7
7
  validateSessionName
8
- } from "./chunk-R5LSWHRH.js";
8
+ } from "./chunk-4XVACOU5.js";
9
9
  import {
10
10
  InteractionRequestSchema,
11
11
  REASONING_EFFORTS,
12
12
  SESSION_TIMELINE_PAGE_SIZE
13
- } from "./chunk-BDKVGENQ.js";
13
+ } from "./chunk-BMMKEB6V.js";
14
14
 
15
15
  // src/pi-adapter.ts
16
16
  import { createHash as createHash2, randomUUID } from "node:crypto";
@@ -0,0 +1,8 @@
1
+ export { SessionImagesConfigSchema, SessionImageRelayUrlSchema } from "./index.js";
2
+ export { DeviceIdentitySchema, type DeviceIdentity } from "./index.js";
3
+ export { CODING_AGENT_IDS } from "./index.js";
4
+ export { AgentSelectionSchema } from "./index.js";
5
+ export type { AgentSelection, AgentSelectionProvider } from "./index.js";
6
+ export { codingAgentPresentation } from "./index.js";
7
+ export { LEGACY_CLIENT_STATE_DIRECTORY } from "./index.js";
8
+ export { relayRequestToken } from "./index.js";