@myagentroam/agent 0.11.25 → 0.11.26

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.
@@ -2,6 +2,7 @@ import type { MarAgentImageMetadata } from '../runtime/contracts.js';
2
2
  import type { MarAgentEvent } from '../runtime/events.js';
3
3
  import type { SessionStore } from './store/contracts.js';
4
4
  import type { SessionListInput, SessionSource } from './types.js';
5
+ import type { MarAgentSessionRollbackInput } from './rollback.js';
5
6
  export interface MarAgentSessionSummary {
6
7
  id: string;
7
8
  title: string;
@@ -82,9 +83,7 @@ export interface MarAgentSessionCatalog {
82
83
  readonly boundaryTurnId: string | null;
83
84
  readonly title: string;
84
85
  }): Promise<MarAgentSessionSummary>;
85
- rollback(sessionId: string, input: {
86
- readonly boundaryTurnId: string | null;
87
- }): Promise<MarAgentSessionSummary>;
86
+ rollback(sessionId: string, input: MarAgentSessionRollbackInput): Promise<MarAgentSessionSummary>;
88
87
  clear(sessionId: string): Promise<MarAgentSessionSummary>;
89
88
  delete(sessionId: string): Promise<MarAgentSessionDeleteResult>;
90
89
  close(): Promise<void>;
@@ -0,0 +1,13 @@
1
+ import type { SessionRecord } from './store/types.js';
2
+ export type MarAgentSessionRollbackInput = {
3
+ readonly boundaryTurnId: string | null;
4
+ readonly beforeInput?: never;
5
+ } | {
6
+ readonly boundaryTurnId?: never;
7
+ readonly beforeInput: {
8
+ readonly turnId: string;
9
+ readonly clientMessageId: string;
10
+ };
11
+ };
12
+ /** Resolve the retained prefix only from records read under the Session maintenance lease. */
13
+ export declare function rollbackBoundaryIndex(records: readonly SessionRecord[], input: MarAgentSessionRollbackInput): number;
@@ -0,0 +1,46 @@
1
+ import { MarAgentError } from '../error.js';
2
+ /** Resolve the retained prefix only from records read under the Session maintenance lease. */
3
+ export function rollbackBoundaryIndex(records, input) {
4
+ const invalid = () => new MarAgentError('MAR_AGENT_ROLLBACK_TARGET_INVALID', 'Session rollback target was not found or is ambiguous.');
5
+ if (input.beforeInput !== undefined) {
6
+ const target = input.beforeInput;
7
+ if (input.boundaryTurnId !== undefined ||
8
+ target === null ||
9
+ typeof target !== 'object' ||
10
+ typeof target.turnId !== 'string' ||
11
+ !target.turnId.trim() ||
12
+ typeof target.clientMessageId !== 'string' ||
13
+ !target.clientMessageId.trim())
14
+ throw invalid();
15
+ let firstInput = -1;
16
+ let selected = -1;
17
+ for (const [index, record] of records.entries()) {
18
+ if (record.type !== 'turn.user' || record.turnId !== target.turnId)
19
+ continue;
20
+ if (firstInput < 0)
21
+ firstInput = index;
22
+ const payload = record.payload;
23
+ if (payload === null || typeof payload !== 'object' || Array.isArray(payload))
24
+ continue;
25
+ if (payload.clientMessageId !== target.clientMessageId)
26
+ continue;
27
+ if (selected >= 0)
28
+ throw invalid();
29
+ selected = index;
30
+ }
31
+ if (selected < 0)
32
+ throw invalid();
33
+ // The initial input owns execution-start records; subsequent inputs own only their tail.
34
+ return ((selected === firstInput
35
+ ? records.findIndex((record) => record.turnId === target.turnId)
36
+ : selected) - 1);
37
+ }
38
+ if (input.boundaryTurnId === null)
39
+ return 0;
40
+ if (typeof input.boundaryTurnId !== 'string' || !input.boundaryTurnId.trim())
41
+ throw invalid();
42
+ const index = records.findLastIndex((record) => record.turnId === input.boundaryTurnId);
43
+ if (index < 0)
44
+ throw invalid();
45
+ return index;
46
+ }
@@ -7,6 +7,7 @@ import type { MarAgentSessionPage, MarAgentSessionSummary } from '../catalog.js'
7
7
  import type { ContextGcCheckpointDraft } from '../context-gc-checkpoint.js';
8
8
  import type { ToolResultResourceInput, ToolResultResourcePage } from '../tool-result-resources.js';
9
9
  import type { SessionListInput, SessionSource, SessionTitleUpdateInput } from '../types.js';
10
+ import type { MarAgentSessionRollbackInput } from '../rollback.js';
10
11
  import type { CompactHistoryMessage, RestoredSessionInputImage, SessionExecutionState, SessionInputImage, SessionInputImageData, SessionInputImageMetadata, SessionRecord } from './types.js';
11
12
  export type { CompactHistoryMessage, CompactUserInput, RestoredSessionInputImage, SessionExecutionState, SessionInputImage, SessionInputImageData, SessionInputImageMetadata, SessionRecord } from './types.js';
12
13
  export type { CodeModeStateEntry } from '../../tools/code-mode/state.js';
@@ -147,9 +148,7 @@ export interface SessionStore {
147
148
  readonly boundaryTurnId: string | null;
148
149
  readonly title: string;
149
150
  }): Promise<SessionStoreSession>;
150
- rollbackSession(sessionId: string, input: {
151
- readonly boundaryTurnId: string | null;
152
- }): Promise<MarAgentSessionSummary>;
151
+ rollbackSession(sessionId: string, input: MarAgentSessionRollbackInput): Promise<MarAgentSessionSummary>;
153
152
  clearSession(sessionId: string, maintenance?: SessionStoreMaintenance): Promise<MarAgentSessionSummary>;
154
153
  delete(sessionId: string, maintenance?: SessionStoreMaintenance): Promise<{
155
154
  readonly deleted: boolean;
@@ -1,3 +1,4 @@
1
+ import { type MarAgentSessionRollbackInput } from '../rollback.js';
1
2
  import type { SessionStore, SessionStoreMaintenance, SessionRecordInput, SessionStoreCompactInput } from './contracts.js';
2
3
  import { type CoreCheckpoint, type CoreJsonValue } from '../../extensions/data.js';
3
4
  import { type CodeModeStateEntry } from '../../tools/code-mode/state.js';
@@ -53,9 +54,7 @@ export declare class JsonlSessionStore implements SessionStore {
53
54
  source: SessionSource | undefined;
54
55
  }>;
55
56
  /** Replace history under a journal; the indexed transaction ID decides the commit side. */
56
- rollbackSession(sessionId: string, input: {
57
- readonly boundaryTurnId: string | null;
58
- }): Promise<{
57
+ rollbackSession(sessionId: string, input: MarAgentSessionRollbackInput): Promise<{
59
58
  id: string;
60
59
  title: string;
61
60
  workspace: string;
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { rollbackBoundaryIndex } from '../rollback.js';
2
3
  import { inlineMediaHistory } from '../inline-media.js';
3
4
  import { lstat, mkdir, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
4
5
  import { basename, join } from 'node:path';
@@ -730,11 +731,7 @@ export class JsonlSessionStore {
730
731
  const records = await this.read(sessionId);
731
732
  if (records[0]?.type !== 'session.created')
732
733
  throw new MarAgentError('MAR_AGENT_SESSION_CORRUPT', 'Session history is corrupt.');
733
- const boundaryIndex = input.boundaryTurnId === null
734
- ? 0
735
- : records.findLastIndex((record) => record.turnId === input.boundaryTurnId);
736
- if (input.boundaryTurnId !== null && boundaryIndex < 0)
737
- throw new MarAgentError('MAR_AGENT_ROLLBACK_TARGET_INVALID', 'Session rollback target was not found.');
734
+ const boundaryIndex = rollbackBoundaryIndex(records, input);
738
735
  const retained = records
739
736
  .slice(0, boundaryIndex + 1)
740
737
  .filter((record) => record.type !== 'responses.continuation');
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { MarAgentError } from './agent-core/error.js';
2
+ export type { MarAgentSessionRollbackInput } from './agent-core/session/rollback.js';
2
3
  export { MAR_AGENT_HOST_API_VERSION, negotiateHost, type HostDescription, type MarAgentHostCapability } from './agent-core/host/contracts.js';
3
4
  export type { PermissionMode, ToolApprovalRequest, ToolApprovalDecision, ToolApprovalHandler, ToolPermission, PermissionStop } from './agent-core/tools/permissions.js';
4
5
  export type { ToolResultExtension, FileChangeEvidence } from './agent-core/tools/result-extensions.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/agent",
3
- "version": "0.11.25",
3
+ "version": "0.11.26",
4
4
  "description": "Embeddable MAR coding agent SDK and CLI.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",