agent-accelerator 0.3.0 → 0.4.5
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/package.json +1 -1
- package/src/agent/agent.ts +845 -116
- package/src/agent/context.ts +35 -0
- package/src/agent/delegation.ts +390 -36
- package/src/agent/loop.ts +785 -110
- package/src/agent/subagent.ts +59 -0
- package/src/index.ts +173 -59
- package/src/models/catalog-cache.ts +68 -25
- package/src/models/catalog.ts +123 -18
- package/src/providers/google.ts +152 -43
- package/src/providers/openai-compat.ts +246 -96
- package/src/providers/openai.ts +274 -79
- package/src/providers/openrouter.ts +191 -82
- package/src/providers/registry.ts +16 -12
- package/src/providers/shared.ts +190 -0
- package/src/providers.ts +259 -9
- package/src/session/store.ts +521 -33
- package/src/streaming/event-stream.ts +156 -41
- package/src/tools/executor.ts +248 -15
- package/src/tools/tool.ts +147 -3
- package/src/types/agent.ts +244 -2
- package/src/types/errors.ts +133 -0
- package/src/types/model.ts +22 -1
- package/src/types/response.ts +133 -3
- package/src/types/tool.ts +69 -0
- package/src/update-models.ts +8 -2
- package/src/utils/cache.ts +68 -1
- package/src/utils/env.ts +23 -13
- package/src/utils/errors.ts +15 -1
- package/src/utils/headers.ts +153 -19
- package/src/utils/retry.ts +27 -13
- package/src/utils/session.ts +284 -0
- package/src/providers/openrouter-responses.ts +0 -949
- package/src/types/provider-payloads.ts +0 -352
package/src/agent/context.ts
CHANGED
|
@@ -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
|
}
|