agent-accelerator 0.3.0 → 0.4.0

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,6 +1,8 @@
1
1
  import type { Message, ContentPart } from "../types/message.ts";
2
2
  import type { ToolCallRecord, ToolResultRecord } from "../types/tool.ts";
3
3
  import { safeStringify } from "../utils/serialization.ts";
4
+ import { clearSessionRouting } from "../providers.ts";
5
+ import { clearInteractionChains } from "../providers/google.ts";
4
6
 
5
7
  const USER_PART_TYPES = new Set(["text", "image", "audio", "video", "file"]);
6
8
 
@@ -159,4 +161,37 @@ export class AgentContext {
159
161
  next.cachedContentId = this.cachedContentId;
160
162
  return next;
161
163
  }
164
+
165
+ /**
166
+ * Captures a JSON snapshot of conversation state for run-level rollback
167
+ * (Q-19). Returns stringified payloads so the checkpoint is detached from
168
+ * live mutation.
169
+ */
170
+ checkpoint(): { messages: string; signatures: string } {
171
+ return {
172
+ messages: JSON.stringify(this.messages),
173
+ signatures: JSON.stringify(this.thoughtSignatures),
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Restores a checkpoint captured by `checkpoint()`. Corrupt checkpoints
179
+ * are ignored (current state kept). When `sessionId` is provided, also
180
+ * clears session-scoped provider state (Q-25) so a rollback never resumes
181
+ * a stale interaction chain.
182
+ */
183
+ rollback(cp: { messages: string; signatures: string }, sessionId?: string): void {
184
+ try {
185
+ const msgs = JSON.parse(cp.messages);
186
+ if (Array.isArray(msgs)) this.messages = msgs;
187
+ } catch {}
188
+ try {
189
+ const sigs = JSON.parse(cp.signatures);
190
+ if (Array.isArray(sigs)) this.thoughtSignatures = sigs;
191
+ } catch {}
192
+ if (sessionId) {
193
+ try { clearInteractionChains(sessionId); } catch {}
194
+ try { clearSessionRouting(sessionId); } catch {}
195
+ }
196
+ }
162
197
  }