@qlairoslabs/acp-client 0.7.3 → 0.7.4

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/CONSUMER_GUIDE.md CHANGED
@@ -50,6 +50,7 @@ import {
50
50
  TranscriptReader,
51
51
  formatResponseMessages,
52
52
  type Adapter,
53
+ type AgentSessionOpenStage,
53
54
  type AgentSessionNotification,
54
55
  type PromptHandlers,
55
56
  } from "@qlairoslabs/acp-client";
@@ -143,11 +144,17 @@ async function createSession(adapterId: string): Promise<AgentSession> {
143
144
  persistence: {
144
145
  transcript: { preset: "activity" },
145
146
  },
147
+ onOpenProgress: projectOpenProgress,
146
148
  });
147
149
 
148
150
  liveSessions.set(session.agentSessionId, session);
149
151
  return session;
150
152
  }
153
+
154
+ function projectOpenProgress(event: AgentSessionOpenStage): void {
155
+ // Project this ephemeral event into your own UI/WebSocket protocol.
156
+ console.log(event.stage, event);
157
+ }
151
158
  ```
152
159
 
153
160
  `agentSessionId` and `creationId` are generated when omitted. A consumer that needs
@@ -346,6 +353,7 @@ async function loadSession(agentSessionId: string): Promise<AgentSession> {
346
353
  adapter: resolveAdapter(info.adapterId),
347
354
  adapterId: info.adapterId,
348
355
  defaultPermission: "cancel",
356
+ onOpenProgress: projectOpenProgress,
349
357
  });
350
358
 
351
359
  console.log(opened.continuation);
@@ -359,6 +367,20 @@ async function loadSession(agentSessionId: string): Promise<AgentSession> {
359
367
  }
360
368
  ```
361
369
 
370
+ Managed creation and loading report the same ordered progress vocabulary:
371
+
372
+ ```text
373
+ initializing
374
+ → initialized (ACP capabilities are available)
375
+ → internal_session_acquired (created or resumed)
376
+ → ready (managed persistence is finalized and promptability is known)
377
+ ```
378
+
379
+ The callback exists because the live `AgentSession` is not available for subscription
380
+ until the operation returns. Progress is ephemeral and is not transcript or registry
381
+ authority. A failed operation does not report `ready`, and a retry begins a new sequence.
382
+ Callback failures are logged and do not fail or roll back the managed operation.
383
+
362
384
  Loading never silently creates a replacement provider thread. By default it attempts the
363
385
  persisted `internalSessionId`. If that thread is unavailable, continuation reports the
364
386
  failure and the returned session may be non-promptable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qlairoslabs/acp-client",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Embeddable Agent Client Protocol (ACP) client library with degraded PTY fallback.",
5
5
  "type": "module",
6
6
  "module": "src/index.ts",
@@ -9,7 +9,12 @@
9
9
  // Adapter lives HERE, not on the controller: switching adapter = a new AgentSession (the
10
10
  // agent dies on switch). Mode-swap (degrade/upgrade) stays within one AgentSession.
11
11
 
12
- import { AgentController, type AgentControllerConfig, type AgentMode } from "./controller.ts";
12
+ import {
13
+ AgentController,
14
+ type AgentControllerConfig,
15
+ type AgentControllerStartEvent,
16
+ type AgentMode,
17
+ } from "./controller.ts";
13
18
  import type * as schema from "@agentclientprotocol/sdk";
14
19
  import { join } from "node:path";
15
20
  import { ActivityAggregator, type ActivitySnapshot, type AggregatedRecord } from "./activity.ts";
@@ -105,6 +110,7 @@ import {
105
110
  import type { PersistenceRepair, SessionRecoveryStatus } from "./persistence/reducer.ts";
106
111
  import type { StagedContinuationState } from "./persistence/registry.ts";
107
112
  import type { SessionLogWriterLock } from "./persistence/session-log-writer.ts";
113
+ import type { ManagedOpenProgressReporter } from "./persistence/managed-open-progress.ts";
108
114
 
109
115
  interface PromptQueueItem {
110
116
  kind: "prompt";
@@ -582,6 +588,7 @@ interface AgentSessionOpenBootstrap {
582
588
  readonly transcript: PersistenceStateRuntime;
583
589
  readonly transcriptPath: string;
584
590
  readonly stageContinuation?: (state: StagedContinuationState) => Promise<StagedContinuationState>;
591
+ readonly onOpenProgress?: ManagedOpenProgressReporter;
585
592
  }
586
593
 
587
594
  /** @internal Transaction hooks supplied only by SessionManager managed creation. */
@@ -590,6 +597,7 @@ export interface ManagedAgentSessionCreationBootstrap {
590
597
  readonly transcriptLock?: SessionLogWriterLock;
591
598
  readonly auditLogLock?: SessionLogWriterLock;
592
599
  readonly stageContinuation: (state: StagedContinuationState) => Promise<StagedContinuationState>;
600
+ readonly onOpenProgress?: ManagedOpenProgressReporter;
593
601
  }
594
602
 
595
603
  export interface ManagedAgentSessionPersistenceSnapshot {
@@ -653,11 +661,14 @@ export class AgentSession implements AgentClient, Bridgeable {
653
661
  private readonly managedCreation: ManagedAgentSessionCreationBootstrap | null;
654
662
  private managedPersistenceHealthy = true;
655
663
  private managedAuditLog: AuditLogIdentity | null = null;
664
+ private readonly managedOpenProgress?: ManagedOpenProgressReporter;
665
+ private managedInitializationReported = false;
656
666
 
657
667
  private constructor(
658
668
  config: AgentSessionConfig,
659
669
  openBootstrap: AgentSessionOpenBootstrap | null = null,
660
670
  managedCreation: ManagedAgentSessionCreationBootstrap | null = null,
671
+ managedOpenProgress?: ManagedOpenProgressReporter,
661
672
  ) {
662
673
  if (config.transcriptPath && config.transcriptDir) {
663
674
  throw new Error("AgentSessionConfig cannot specify both transcriptPath and transcriptDir");
@@ -703,6 +714,9 @@ export class AgentSession implements AgentClient, Bridgeable {
703
714
  this.creationId = config.creationId ?? crypto.randomUUID();
704
715
  this.openBootstrap = openBootstrap;
705
716
  this.managedCreation = managedCreation;
717
+ this.managedOpenProgress = managedOpenProgress
718
+ ?? managedCreation?.onOpenProgress
719
+ ?? openBootstrap?.onOpenProgress;
706
720
  this._transcriptPath =
707
721
  config.transcriptPath ??
708
722
  (config.transcriptDir
@@ -766,6 +780,18 @@ export class AgentSession implements AgentClient, Bridgeable {
766
780
  });
767
781
  }
768
782
 
783
+ private reportManagedControllerProgress(event: AgentControllerStartEvent): void {
784
+ if (!this.managedOpenProgress) return;
785
+ // A continuation policy may restart the same adapter after a failed load. The
786
+ // managed lifecycle reports capability discovery once, while the successful
787
+ // provider-thread acquisition is reported when it actually occurs.
788
+ if (event.stage === "initialized") {
789
+ if (this.managedInitializationReported) return;
790
+ this.managedInitializationReported = true;
791
+ }
792
+ this.managedOpenProgress(event);
793
+ }
794
+
769
795
  /**
770
796
  * Open a logical conversation. `agentSessionId` selects stable identity;
771
797
  * `providerSession` independently selects a new or existing provider thread; transcript
@@ -822,8 +848,15 @@ export class AgentSession implements AgentClient, Bridgeable {
822
848
  transcriptLock?: SessionLogWriterLock,
823
849
  audit?: AuditPersistenceRuntime,
824
850
  stageContinuation?: (state: StagedContinuationState) => Promise<StagedContinuationState>,
851
+ onOpenProgress?: ManagedOpenProgressReporter,
825
852
  ): Promise<AgentSessionOpenResult> {
826
- return await AgentSession.openWithLock(config, transcriptLock, audit, stageContinuation);
853
+ return await AgentSession.openWithLock(
854
+ config,
855
+ transcriptLock,
856
+ audit,
857
+ stageContinuation,
858
+ onOpenProgress,
859
+ );
827
860
  }
828
861
 
829
862
  /** @internal Restore a registry-authoritative session without a transcript reader. */
@@ -832,6 +865,7 @@ export class AgentSession implements AgentClient, Bridgeable {
832
865
  history: readonly InternalSessionHistoryEntry[],
833
866
  audit?: AuditPersistenceRuntime,
834
867
  stageContinuation?: (state: StagedContinuationState) => Promise<StagedContinuationState>,
868
+ onOpenProgress?: ManagedOpenProgressReporter,
835
869
  ): Promise<AgentSessionOpenResult> {
836
870
  const checkpoint = config.checkpoint;
837
871
  if (!checkpoint || checkpoint.transcript !== null) {
@@ -856,12 +890,12 @@ export class AgentSession implements AgentClient, Bridgeable {
856
890
  onFailure: "error",
857
891
  },
858
892
  metering: { ...config.metering, initialState: checkpoint.metering },
859
- });
893
+ }, null, null, onOpenProgress);
860
894
  const primary = new RegistryPersistenceRuntime(checkpoint, history);
861
895
  session.v2Transcript = audit ? new AuditedPersistenceRuntime(primary, audit) : primary;
862
896
  session.managedAuditLog = audit?.identity ?? null;
863
897
  try {
864
- const result = await session.controller.start();
898
+ const result = await session.controller.start((event) => session.reportManagedControllerProgress(event));
865
899
  if (!result.resumed || !result.sessionId) {
866
900
  throw new Error("adapter did not confirm loading the recorded internal session");
867
901
  }
@@ -897,6 +931,7 @@ export class AgentSession implements AgentClient, Bridgeable {
897
931
  transcriptLock?: SessionLogWriterLock,
898
932
  audit?: AuditPersistenceRuntime,
899
933
  stageContinuation?: (state: StagedContinuationState) => Promise<StagedContinuationState>,
934
+ onOpenProgress?: ManagedOpenProgressReporter,
900
935
  ): Promise<AgentSessionOpenResult> {
901
936
  const strategies = normalizeContinuationStrategies(config.continuation);
902
937
  const persistence = resolveDirectPersistence(config.persistence);
@@ -955,7 +990,12 @@ export class AgentSession implements AgentClient, Bridgeable {
955
990
  ...config.metering,
956
991
  initialState: checkpoint.metering,
957
992
  },
958
- }, { transcript, transcriptPath: paths.transcriptPath, stageContinuation });
993
+ }, {
994
+ transcript,
995
+ transcriptPath: paths.transcriptPath,
996
+ stageContinuation,
997
+ onOpenProgress,
998
+ });
959
999
  session.managedAuditLog = audit?.identity ?? null;
960
1000
 
961
1001
  try {
@@ -1013,7 +1053,7 @@ export class AgentSession implements AgentClient, Bridgeable {
1013
1053
  this.v2Transcript = this.openBootstrap.transcript;
1014
1054
  this.v2TranscriptPath = this.openBootstrap.transcriptPath;
1015
1055
  this._recovery = this.v2Transcript.recovery;
1016
- const result = await this.controller.start();
1056
+ const result = await this.controller.start((event) => this.reportManagedControllerProgress(event));
1017
1057
  if (!result.resumed || !result.sessionId) {
1018
1058
  throw new Error("adapter did not confirm loading the recorded internal session");
1019
1059
  }
@@ -1051,7 +1091,7 @@ export class AgentSession implements AgentClient, Bridgeable {
1051
1091
  }
1052
1092
  if (!paths.transcriptPath || persistence.transcript === false) {
1053
1093
  try {
1054
- const result = await this.controller.start();
1094
+ const result = await this.controller.start((event) => this.reportManagedControllerProgress(event));
1055
1095
  this.setInternalSessionId(result.sessionId || this._internalSessionId, !result.resumed);
1056
1096
  if (this.managedCreation) {
1057
1097
  const now = new Date().toISOString();
@@ -1122,7 +1162,7 @@ export class AgentSession implements AgentClient, Bridgeable {
1122
1162
  header,
1123
1163
  writerLock: this.managedCreation?.transcriptLock,
1124
1164
  initializeCheckpoint: async () => {
1125
- const result = await this.controller.start();
1165
+ const result = await this.controller.start((event) => this.reportManagedControllerProgress(event));
1126
1166
  this.setInternalSessionId(result.sessionId || this._internalSessionId, !result.resumed);
1127
1167
  const now = new Date().toISOString();
1128
1168
  const sessionConfiguration = snapshotSessionConfiguration({
@@ -1218,7 +1258,7 @@ export class AgentSession implements AgentClient, Bridgeable {
1218
1258
  continue;
1219
1259
  }
1220
1260
  try {
1221
- const loaded = await this.controller.start();
1261
+ const loaded = await this.controller.start((event) => this.reportManagedControllerProgress(event));
1222
1262
  if (!loaded.resumed || !loaded.sessionId) {
1223
1263
  throw new Error("adapter did not confirm loading the recorded internal session");
1224
1264
  }
@@ -1297,7 +1337,7 @@ export class AgentSession implements AgentClient, Bridgeable {
1297
1337
  reasonCode: "continuation_reconstruction",
1298
1338
  });
1299
1339
  try {
1300
- const created = await this.controller.startFresh();
1340
+ const created = await this.controller.startFresh((event) => this.reportManagedControllerProgress(event));
1301
1341
  if (!created.sessionId) throw new Error("harness returned no session id for reconstructed continuation");
1302
1342
  if (created.sessionId === checkpoint.internalSessionId && checkpoint.adapterId === this.adapterId) {
1303
1343
  throw new Error("harness did not create a replacement internal session");
package/src/controller.ts CHANGED
@@ -64,6 +64,15 @@ export interface AgentControllerConfig {
64
64
  wire?: (entry: WireEntry) => void;
65
65
  }
66
66
 
67
+ /** @internal Startup observations used by the managed AgentSession coordinator. */
68
+ export type AgentControllerStartEvent =
69
+ | { readonly stage: "initialized"; readonly capabilities: Capabilities }
70
+ | {
71
+ readonly stage: "internal_session_acquired";
72
+ readonly internalSessionId: string;
73
+ readonly disposition: "created" | "resumed";
74
+ };
75
+
67
76
  export type ControllerCommandId =
68
77
  | "caps"
69
78
  | "session"
@@ -177,11 +186,11 @@ export class AgentController implements AgentClient {
177
186
  return () => this.usageUpdateListeners.delete(listener);
178
187
  }
179
188
 
180
- async start(): Promise<ConnectResult> {
189
+ async start(onProgress?: (event: AgentControllerStartEvent) => void): Promise<ConnectResult> {
181
190
  if (this.current) {
182
191
  return { sessionId: this.currentSessionId ?? "", resumed: this.acp?.hasSession ?? false };
183
192
  }
184
- const brought = await this.bringUp(this.mode, this.config.sessionId);
193
+ const brought = await this.bringUp(this.mode, this.config.sessionId, onProgress);
185
194
  this.current = brought.client;
186
195
  this.acp = brought.acp;
187
196
  this.attachAvailableCommandSource();
@@ -189,12 +198,12 @@ export class AgentController implements AgentClient {
189
198
  }
190
199
 
191
200
  /** Explicitly create a fresh provider thread, ignoring any startup load target. */
192
- async startFresh(): Promise<ConnectResult> {
201
+ async startFresh(onProgress?: (event: AgentControllerStartEvent) => void): Promise<ConnectResult> {
193
202
  if (this.current) {
194
203
  if (!this.acp) throw new Error("fresh provider sessions require ACP normal mode");
195
204
  return await this.newSession();
196
205
  }
197
- const brought = await this.bringUp(this.mode);
206
+ const brought = await this.bringUp(this.mode, undefined, onProgress);
198
207
  this.current = brought.client;
199
208
  this.acp = brought.acp;
200
209
  this.attachAvailableCommandSource();
@@ -447,6 +456,7 @@ export class AgentController implements AgentClient {
447
456
  private async bringUp(
448
457
  mode: AgentMode,
449
458
  sessionId?: string,
459
+ onProgress?: (event: AgentControllerStartEvent) => void,
450
460
  ): Promise<{ client: AgentClient; acp: AcpClient | null; result: ConnectResult }> {
451
461
  const adapter = this.config.adapter;
452
462
  if (mode === "degraded") {
@@ -487,7 +497,8 @@ export class AgentController implements AgentClient {
487
497
  // unauthenticated agent may refuse session/new, but we keep the connection up so the
488
498
  // user can /login and then create a session. (Auth state is opaque — see SPEC.)
489
499
  try {
490
- await client.connect();
500
+ const capabilities = await client.connect();
501
+ this.reportStartProgress(onProgress, { stage: "initialized", capabilities });
491
502
  } catch (err) {
492
503
  await client.stop();
493
504
  throw err;
@@ -506,9 +517,30 @@ export class AgentController implements AgentClient {
506
517
  this.config.logger?.warn("session_start_failed", { error: String(err) });
507
518
  result = { sessionId: "", resumed: false };
508
519
  }
520
+ if (result.sessionId) {
521
+ this.reportStartProgress(onProgress, {
522
+ stage: "internal_session_acquired",
523
+ internalSessionId: result.sessionId,
524
+ disposition: result.resumed ? "resumed" : "created",
525
+ });
526
+ }
509
527
  return { client, acp: client, result };
510
528
  }
511
529
 
530
+ private reportStartProgress(
531
+ listener: ((event: AgentControllerStartEvent) => void) | undefined,
532
+ event: AgentControllerStartEvent,
533
+ ): void {
534
+ if (!listener) return;
535
+ try {
536
+ listener(event);
537
+ } catch (error) {
538
+ this.config.logger?.warn("controller_start_progress_listener_failed", {
539
+ error: String(error),
540
+ });
541
+ }
542
+ }
543
+
512
544
  private requireCurrent(): AgentClient {
513
545
  if (!this.current) throw new NotConnectedError("AgentController is not started — call start() first");
514
546
  return this.current;
package/src/index.ts CHANGED
@@ -135,6 +135,10 @@ export {
135
135
  ManagedAgentSessionNotFoundError,
136
136
  } from "./persistence/managed-load.ts";
137
137
  export type { ManagedAgentSessionLoadConfig } from "./persistence/managed-load.ts";
138
+ export type {
139
+ AgentSessionOpenStage,
140
+ AgentSessionOpenProgressListener,
141
+ } from "./persistence/managed-open-progress.ts";
138
142
  export type {
139
143
  GetAgentSessionCheckpointOptions,
140
144
  ResolvedAgentSessionCheckpoint,
@@ -27,6 +27,10 @@ import {
27
27
  } from "./session-log-writer.ts";
28
28
  import { attachManagedRegistryPublisher } from "./managed-registry.ts";
29
29
  import { AuditPersistenceRuntime } from "./audit-runtime.ts";
30
+ import {
31
+ createManagedOpenProgressReporter,
32
+ type AgentSessionOpenProgressListener,
33
+ } from "./managed-open-progress.ts";
30
34
 
31
35
  // Retain the former module-level export while the canonical error now applies to every
32
36
  // maintenance kind and lives with the shared registry contract.
@@ -50,6 +54,8 @@ export interface ManagedAgentSessionCreateConfig extends Omit<
50
54
  readonly creationId?: string;
51
55
  readonly mode?: "normal";
52
56
  readonly persistence?: ManagedSessionPersistenceOptions;
57
+ /** Observe ephemeral managed-open progress before the AgentSession is returned. */
58
+ readonly onOpenProgress?: AgentSessionOpenProgressListener;
53
59
  }
54
60
 
55
61
  export class ManagedAgentSessionCreationError extends Error {
@@ -74,6 +80,10 @@ export async function createManagedAgentSession(
74
80
  }
75
81
  const agentSessionId = nonblankOrGenerated(config.agentSessionId, "agentSessionId");
76
82
  const creationId = nonblankOrGenerated(config.creationId, "creationId");
83
+ const reportOpenProgress = createManagedOpenProgressReporter(
84
+ config.onOpenProgress,
85
+ config.logger,
86
+ );
77
87
  const paths = await resolveSessionLogPaths(context.persistence, agentSessionId);
78
88
  const transcriptPath = paths.transcriptPath;
79
89
  const requestDigest = sha256CanonicalJson({
@@ -158,20 +168,22 @@ export async function createManagedAgentSession(
158
168
  })
159
169
  : undefined;
160
170
  lockTransferred = true;
171
+ reportOpenProgress({ stage: "initializing" });
161
172
  const opened = active.details.stagedRecord.transcript
162
173
  ? await AgentSession.openManaged({
163
174
  ...runtimeConfig(config),
164
175
  agentSessionId,
165
176
  persistence: directPersistence(context.persistence, transcriptPath),
166
177
  checkpoint: active.details.stagedRecord.checkpoint,
167
- }, transcriptLock, audit)
178
+ }, transcriptLock, audit, undefined, reportOpenProgress)
168
179
  : await AgentSession.openManagedRegistry({
169
180
  ...runtimeConfig(config),
170
181
  agentSessionId,
171
182
  persistence: directPersistence(context.persistence, null),
172
183
  checkpoint: active.details.stagedRecord.checkpoint,
173
- }, active.details.stagedRecord.internalSessionHistory, audit);
184
+ }, active.details.stagedRecord.internalSessionHistory, audit, undefined, reportOpenProgress);
174
185
  attachManagedRegistryPublisher(opened.session, context.store);
186
+ reportOpenProgress({ stage: "ready", promptability: opened.session.promptability });
175
187
  return opened.session;
176
188
  }
177
189
 
@@ -191,6 +203,7 @@ export async function createManagedAgentSession(
191
203
  }
192
204
  const stagedContinuation = active.details.stagedContinuation;
193
205
  lockTransferred = true;
206
+ reportOpenProgress({ stage: "initializing" });
194
207
  session = await AgentSession.createManaged({
195
208
  ...runtimeConfig(config),
196
209
  agentSessionId,
@@ -224,6 +237,7 @@ export async function createManagedAgentSession(
224
237
  active = update;
225
238
  return state;
226
239
  },
240
+ onOpenProgress: reportOpenProgress,
227
241
  });
228
242
 
229
243
  const snapshot = session.getManagedPersistenceSnapshot();
@@ -246,6 +260,7 @@ export async function createManagedAgentSession(
246
260
  { save: record },
247
261
  );
248
262
  attachManagedRegistryPublisher(session, context.store);
263
+ reportOpenProgress({ stage: "ready", promptability: session.promptability });
249
264
  return session;
250
265
  } catch (error) {
251
266
  await session?.stop().catch(() => undefined);
@@ -266,6 +281,7 @@ function runtimeConfig(config: ManagedAgentSessionCreateConfig): Omit<
266
281
  creationId: _creationId,
267
282
  persistence: _persistence,
268
283
  mode: _mode,
284
+ onOpenProgress: _onOpenProgress,
269
285
  ...runtime
270
286
  } = config;
271
287
  return runtime;
@@ -16,11 +16,18 @@ import {
16
16
  projectManagedAgentSessionRecord,
17
17
  } from "./managed-registry.ts";
18
18
  import { AuditPersistenceRuntime } from "./audit-runtime.ts";
19
+ import {
20
+ createManagedOpenProgressReporter,
21
+ type AgentSessionOpenProgressListener,
22
+ } from "./managed-open-progress.ts";
19
23
 
20
24
  export interface ManagedAgentSessionLoadConfig extends Omit<
21
25
  AgentSessionOpenConfig,
22
26
  "agentSessionId" | "persistence" | "checkpoint"
23
- > {}
27
+ > {
28
+ /** Observe ephemeral managed-open progress before the open result is returned. */
29
+ readonly onOpenProgress?: AgentSessionOpenProgressListener;
30
+ }
24
31
 
25
32
  export class ManagedAgentSessionNotFoundError extends Error {
26
33
  constructor(readonly agentSessionId: string) {
@@ -49,6 +56,10 @@ export async function loadManagedAgentSession(
49
56
  agentSessionId: string,
50
57
  config: ManagedAgentSessionLoadConfig,
51
58
  ): Promise<AgentSessionOpenResult> {
59
+ const reportOpenProgress = createManagedOpenProgressReporter(
60
+ config.onOpenProgress,
61
+ config.logger,
62
+ );
52
63
  const [record, maintenance] = await Promise.all([
53
64
  store.getAgentSessionRecord(agentSessionId),
54
65
  store.getMaintenance(agentSessionId),
@@ -62,6 +73,8 @@ export async function loadManagedAgentSession(
62
73
  if (record.adapterId !== config.adapterId && !hasReconstructionStrategy(config)) {
63
74
  throw new AdapterMismatchError(record.adapterId, config.adapterId);
64
75
  }
76
+ const { onOpenProgress: _onOpenProgress, ...openConfig } = config;
77
+ reportOpenProgress({ stage: "initializing" });
65
78
 
66
79
  const audit = record.auditLog
67
80
  ? await AuditPersistenceRuntime.resume({
@@ -75,12 +88,12 @@ export async function loadManagedAgentSession(
75
88
  try {
76
89
  opened = record.transcript
77
90
  ? await AgentSession.openManaged({
78
- ...config,
91
+ ...openConfig,
79
92
  agentSessionId,
80
93
  persistence: persistenceFromManagedRecord(record),
81
- }, undefined, audit)
94
+ }, undefined, audit, undefined, reportOpenProgress)
82
95
  : await AgentSession.openManagedRegistry({
83
- ...config,
96
+ ...openConfig,
84
97
  agentSessionId,
85
98
  checkpoint: record.checkpoint,
86
99
  persistence: {
@@ -88,7 +101,7 @@ export async function loadManagedAgentSession(
88
101
  auditLog: false,
89
102
  sessionConfiguration: record.sessionConfigurationPersistence ?? { values: "typed" },
90
103
  },
91
- }, record.internalSessionHistory, audit);
104
+ }, record.internalSessionHistory, audit, undefined, reportOpenProgress);
92
105
  } catch (error) {
93
106
  await audit?.close().catch(() => undefined);
94
107
  throw error;
@@ -118,6 +131,7 @@ export async function loadManagedAgentSession(
118
131
  expectedIncarnationId: current.incarnationId,
119
132
  });
120
133
  attachManagedRegistryPublisher(opened.session, store);
134
+ reportOpenProgress({ stage: "ready", promptability: opened.promptability });
121
135
  return opened;
122
136
  } catch (error) {
123
137
  await opened.session.stop().catch(() => undefined);
@@ -0,0 +1,54 @@
1
+ import type { Capabilities } from "../capabilities.ts";
2
+ import type { AgentSessionPromptability } from "../agent-session.ts";
3
+ import type { Logger } from "../logger.ts";
4
+
5
+ /** Ephemeral progress reported while a managed logical session is becoming usable. */
6
+ export type AgentSessionOpenStage =
7
+ | { readonly stage: "initializing" }
8
+ | { readonly stage: "initialized"; readonly capabilities: Capabilities }
9
+ | {
10
+ readonly stage: "internal_session_acquired";
11
+ readonly internalSessionId: string;
12
+ readonly disposition: "created" | "resumed";
13
+ }
14
+ | {
15
+ readonly stage: "ready";
16
+ readonly promptability: AgentSessionPromptability;
17
+ };
18
+
19
+ /**
20
+ * A presentation hook, not a persistence or transaction hook.
21
+ *
22
+ * Calls are made in lifecycle order. A retry starts a new sequence, and a failed open
23
+ * does not report `ready`. Listener failures are logged and never fail the managed open.
24
+ */
25
+ export type AgentSessionOpenProgressListener = (event: AgentSessionOpenStage) => void;
26
+
27
+ /** @internal A listener with failure isolation already applied by the managed coordinator. */
28
+ export type ManagedOpenProgressReporter = (event: AgentSessionOpenStage) => void;
29
+
30
+ /** @internal */
31
+ export function createManagedOpenProgressReporter(
32
+ listener: AgentSessionOpenProgressListener | undefined,
33
+ logger: Logger | undefined,
34
+ ): ManagedOpenProgressReporter {
35
+ if (!listener) return () => undefined;
36
+ return (event) => {
37
+ try {
38
+ const returned: unknown = listener(event);
39
+ if (isPromiseLike(returned)) {
40
+ void Promise.resolve(returned).catch((error) => {
41
+ logger?.warn("managed_open_progress_listener_failed", { error: String(error) });
42
+ });
43
+ }
44
+ } catch (error) {
45
+ logger?.warn("managed_open_progress_listener_failed", { error: String(error) });
46
+ }
47
+ };
48
+ }
49
+
50
+ function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
51
+ return typeof value === "object"
52
+ && value !== null
53
+ && typeof (value as { then?: unknown }).then === "function";
54
+ }
@@ -19,6 +19,8 @@ interface TranscriptPresentationItemBase {
19
19
  readonly revision: number;
20
20
  /** Physical transcript sequence containing this revision. */
21
21
  readonly recordSequence: number;
22
+ /** Unix epoch milliseconds from the persisted record envelope. */
23
+ readonly timestamp: number;
22
24
  readonly operationId: string;
23
25
  readonly transcriptId: string;
24
26
  readonly generation: number;
@@ -64,6 +66,7 @@ export function presentationItemFromRecord(
64
66
  position: presentation.position,
65
67
  revision: presentation.revision,
66
68
  recordSequence: record.seq,
69
+ timestamp: record.ts,
67
70
  operationId: record.operationId,
68
71
  transcriptId: record.transcriptId,
69
72
  generation: record.generation,