macro-agent 0.0.15 → 0.0.16

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/src/acp/types.ts CHANGED
@@ -630,10 +630,44 @@ export interface ResumeAgentResponse {
630
630
  /** The resumed agent's ID */
631
631
  agentId: AgentId;
632
632
 
633
- /** The agent's session ID */
633
+ /** The agent's session ID (from resume) */
634
634
  sessionId: string;
635
635
  }
636
636
 
637
+ // ─────────────────────────────────────────────────────────────────
638
+ // History Extension Types
639
+ // ─────────────────────────────────────────────────────────────────
640
+
641
+ /**
642
+ * A historical turn in a session conversation
643
+ */
644
+ export interface HistoryTurn {
645
+ /** Turn role */
646
+ role: "user" | "assistant";
647
+ /** Timestamp of the turn */
648
+ timestamp: number;
649
+ /** Turn content — plain text for user, structured parts for assistant */
650
+ content: unknown;
651
+ }
652
+
653
+ /**
654
+ * Request for _macro/getHistory extension
655
+ */
656
+ export interface GetHistoryRequest {
657
+ /** ACP session ID to get history for */
658
+ sessionId: string;
659
+ /** Maximum number of turns to return */
660
+ limit?: number;
661
+ }
662
+
663
+ /**
664
+ * Response for _macro/getHistory extension
665
+ */
666
+ export interface GetHistoryResponse {
667
+ /** Conversation turns in chronological order */
668
+ turns: HistoryTurn[];
669
+ }
670
+
637
671
  // ─────────────────────────────────────────────────────────────────
638
672
  // Extension Method Types (Union)
639
673
  // ─────────────────────────────────────────────────────────────────
@@ -657,7 +691,8 @@ export type ACPExtensionMethod =
657
691
  | "_macro/checkCapability"
658
692
  | "_macro/respondToPermission"
659
693
  | "_macro/cancelPermission"
660
- | "_macro/resume";
694
+ | "_macro/resume"
695
+ | "_macro/getHistory";
661
696
 
662
697
  /**
663
698
  * Map of extension methods to their request types
@@ -679,6 +714,7 @@ export interface ACPExtensionRequests {
679
714
  "_macro/respondToPermission": RespondToPermissionRequest;
680
715
  "_macro/cancelPermission": CancelPermissionRequest;
681
716
  "_macro/resume": ResumeAgentRequest;
717
+ "_macro/getHistory": GetHistoryRequest;
682
718
  }
683
719
 
684
720
  /**
@@ -701,6 +737,7 @@ export interface ACPExtensionResponses {
701
737
  "_macro/respondToPermission": RespondToPermissionResponse;
702
738
  "_macro/cancelPermission": CancelPermissionResponse;
703
739
  "_macro/resume": ResumeAgentResponse;
740
+ "_macro/getHistory": GetHistoryResponse;
704
741
  }
705
742
 
706
743
  // ─────────────────────────────────────────────────────────────────
@@ -117,11 +117,11 @@ export class ACPOverMAPHandler {
117
117
  break;
118
118
 
119
119
  case "session/new":
120
- result = await this.handleNewSession(streamState, acp.params);
120
+ result = await this.handleNewSession(streamState, acp.params, emitNotification);
121
121
  break;
122
122
 
123
123
  case "session/load":
124
- result = await this.handleLoadSession(streamState, acp.params);
124
+ result = await this.handleLoadSession(streamState, acp.params, emitNotification);
125
125
  break;
126
126
 
127
127
  case "authenticate":
@@ -201,6 +201,7 @@ export class ACPOverMAPHandler {
201
201
  private async handleNewSession(
202
202
  streamState: StreamState,
203
203
  params: unknown,
204
+ emitNotification?: ACPNotificationEmitter,
204
205
  ): Promise<unknown> {
205
206
  if (!streamState.initialized) {
206
207
  throw new Error("Must call initialize before newSession");
@@ -224,12 +225,16 @@ export class ACPOverMAPHandler {
224
225
 
225
226
  console.error(`[ACP-over-MAP] Created session ${sessionId} -> agent ${spawned.id}`);
226
227
 
228
+ // Emit session_info_update so client has title/timestamps
229
+ this.emitSessionInfo(streamState, sessionId, emitNotification);
230
+
227
231
  return { sessionId };
228
232
  }
229
233
 
230
234
  private async handleLoadSession(
231
235
  streamState: StreamState,
232
236
  params: unknown,
237
+ emitNotification?: ACPNotificationEmitter,
233
238
  ): Promise<unknown> {
234
239
  if (!streamState.initialized) {
235
240
  throw new Error("Must call initialize before loadSession");
@@ -271,6 +276,7 @@ export class ACPOverMAPHandler {
271
276
  streamState.sessionId = sessionId;
272
277
  streamState.agentId = existing.id;
273
278
  this.sessionMapper.createMapping(sessionId as ACPSessionId, existing.id);
279
+ this.emitSessionInfo(streamState, sessionId, emitNotification);
274
280
  return {};
275
281
  }
276
282
 
@@ -280,6 +286,7 @@ export class ACPOverMAPHandler {
280
286
  streamState.sessionId = sessionId;
281
287
  streamState.agentId = spawned.id;
282
288
  this.sessionMapper.createMapping(sessionId as ACPSessionId, spawned.id);
289
+ this.emitSessionInfo(streamState, sessionId, emitNotification);
283
290
  return {};
284
291
  }
285
292
 
@@ -293,6 +300,7 @@ export class ACPOverMAPHandler {
293
300
  streamState.sessionId = sessionId;
294
301
  streamState.agentId = spawned.id;
295
302
  this.sessionMapper.createMapping(sessionId as ACPSessionId, spawned.id);
303
+ this.emitSessionInfo(streamState, sessionId, emitNotification);
296
304
 
297
305
  return {};
298
306
  }
@@ -388,6 +396,9 @@ export class ACPOverMAPHandler {
388
396
 
389
397
  console.error(`[ACP-over-MAP] Prompt completed for agent ${agentId}, ${updateCount} updates`);
390
398
 
399
+ // Emit updated session info after prompt completes
400
+ this.emitSessionInfo(streamState, sessionId, emitNotification);
401
+
391
402
  return { stopReason: "end_turn" };
392
403
  } catch (error) {
393
404
  console.error(`[ACP-over-MAP] Prompt error:`, error);
@@ -532,6 +543,50 @@ export class ACPOverMAPHandler {
532
543
  }
533
544
  }
534
545
 
546
+ // ─────────────────────────────────────────────────────────────────
547
+ // Session Info
548
+ // ─────────────────────────────────────────────────────────────────
549
+
550
+ /**
551
+ * Emit a session_info_update notification with title and timestamps.
552
+ * Uses agent task as title and session mapping timestamps.
553
+ */
554
+ private emitSessionInfo(
555
+ streamState: StreamState,
556
+ sessionId: string,
557
+ emitNotification?: ACPNotificationEmitter,
558
+ ): void {
559
+ if (!emitNotification) return;
560
+
561
+ const mapping = this.sessionMapper.getMapping(sessionId as ACPSessionId);
562
+ const agentId = streamState.agentId;
563
+ const agent = agentId ? this.eventStore.getAgent(agentId as AgentId) : null;
564
+
565
+ const title = agent?.task ?? null;
566
+ const updatedAt = new Date(mapping?.updatedAt ?? Date.now()).toISOString();
567
+
568
+ const notification: ACPEnvelope = {
569
+ acp: {
570
+ jsonrpc: "2.0",
571
+ method: "session/update",
572
+ params: {
573
+ sessionId,
574
+ update: {
575
+ sessionUpdate: "session_info_update",
576
+ title,
577
+ updatedAt,
578
+ },
579
+ },
580
+ },
581
+ acpContext: {
582
+ streamId: streamState.streamId,
583
+ sessionId,
584
+ direction: "agent-to-client",
585
+ },
586
+ };
587
+ emitNotification(notification);
588
+ }
589
+
535
590
  // ─────────────────────────────────────────────────────────────────
536
591
  // Cleanup
537
592
  // ─────────────────────────────────────────────────────────────────