agent-accelerator 0.1.0 → 0.2.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.
Files changed (45) hide show
  1. package/README.md +83 -112
  2. package/{SYSTEM_PROMPT_AGENT.md → examples/prompts/SYSTEM_PROMPT_AGENT.md} +1 -1
  3. package/package.json +14 -9
  4. package/src/agent/agent.ts +191 -71
  5. package/src/agent/context.ts +1 -0
  6. package/src/agent/delegation.ts +61 -12
  7. package/src/agent/loop.ts +71 -48
  8. package/src/data/README.md +6 -6
  9. package/src/index.ts +130 -45
  10. package/src/models/catalog-cache.ts +60 -9
  11. package/src/models/catalog.ts +53 -7
  12. package/src/providers/google.ts +926 -0
  13. package/src/providers/openai-compat.ts +1147 -0
  14. package/src/providers/openai.ts +959 -0
  15. package/src/providers/openrouter-responses.ts +949 -0
  16. package/src/providers/openrouter.ts +1037 -0
  17. package/src/{ai-sdk → providers}/registry.ts +43 -55
  18. package/src/providers.ts +490 -0
  19. package/src/streaming/sse-parser.ts +6 -4
  20. package/src/tools/executor.ts +19 -6
  21. package/src/tools/schema.ts +21 -11
  22. package/src/types/agent.ts +8 -1
  23. package/src/types/core.ts +1 -1
  24. package/src/types/message.ts +5 -0
  25. package/src/types/model.ts +3 -7
  26. package/src/types/provider-payloads.ts +2 -84
  27. package/src/types/tool.ts +6 -0
  28. package/src/update-models.ts +56 -0
  29. package/src/utils/cache.ts +1 -1
  30. package/src/utils/documents.ts +517 -0
  31. package/src/utils/env.ts +0 -7
  32. package/src/{ai-sdk → utils}/errors.ts +61 -2
  33. package/src/utils/headers.ts +10 -20
  34. package/src/utils/media.ts +5 -2
  35. package/src/utils/retry.ts +89 -0
  36. package/src/utils/serialization.ts +15 -0
  37. package/src/ai-sdk/converters.ts +0 -342
  38. package/src/ai-sdk/executor.ts +0 -454
  39. package/src/ai-sdk/index.ts +0 -55
  40. package/src/ai-sdk/model-provider.ts +0 -303
  41. package/src/ai-sdk/options.ts +0 -306
  42. package/src/ai-sdk/provider.ts +0 -415
  43. package/src/tokens/counter.ts +0 -136
  44. /package/{SYSTEM_PROMPT.md → examples/prompts/SYSTEM_PROMPT.md} +0 -0
  45. /package/{SYSTEM_PROMPT_TOOLS.md → examples/prompts/SYSTEM_PROMPT_TOOLS.md} +0 -0
@@ -64,6 +64,11 @@ export interface ToolCallPart {
64
64
  * Optional Gemini thought signature associated with this tool call
65
65
  */
66
66
  thoughtSignature?: string;
67
+ /**
68
+ * Provider pairing identifier (e.g. Responses `call_id`), preserved so
69
+ * history builders can pair results without inventing ids.
70
+ */
71
+ callId?: string;
67
72
  }
68
73
 
69
74
  /** Tool execution result returned to the model context. */
@@ -5,10 +5,10 @@ import type { AssistantMessageEventStream } from "../streaming/event-stream.ts";
5
5
 
6
6
  // ---------------------------------------------------------------------------
7
7
  // Provider identity — battle-tested: matches models.dev provider keys
8
- // Known first-class: google | opencode | openrouter, plus aliases. Allow string for future.
8
+ // Known first-class: google | openrouter | openai, plus aliases. Allow string for future.
9
9
  // ---------------------------------------------------------------------------
10
10
  /** Supported provider IDs plus arbitrary custom prefixes. */
11
- export type ProviderId = "google" | "opencode" | "opencode-go" | "openrouter" | "openai" | (string & {});
11
+ export type ProviderId = "google" | "openrouter" | "openai" | (string & {});
12
12
 
13
13
  // ---------------------------------------------------------------------------
14
14
  // Raw models.dev shapes — battle-tested, 1:1 with https://models.dev/api.json
@@ -189,7 +189,7 @@ export interface ProviderGenerateResult {
189
189
  durationMs: number;
190
190
  }
191
191
 
192
- /** Provider contract implemented by the AI-SDK transport layer. */
192
+ /** Provider contract implemented by native REST transports. */
193
193
  export interface Provider {
194
194
  id: ProviderId;
195
195
  name: string;
@@ -205,8 +205,4 @@ export interface Provider {
205
205
  context: ProviderContext,
206
206
  options?: ProviderRequestOptions
207
207
  ): AssistantMessageEventStream;
208
- countTokens(
209
- model: string | ModelSpec,
210
- context: ProviderContext
211
- ): Promise<number>;
212
208
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Provider wire payload and schema types for complete backwards compatibility.
3
- * All providers use Vercel AI SDK under the hood, but these types allow existing
4
- * applications and tests to type-check requests and responses seamlessly.
3
+ * These types allow existing applications and tests to type-check requests
4
+ * and responses seamlessly.
5
5
  */
6
6
 
7
7
  // ============================================================================
@@ -105,88 +105,6 @@ export interface GoogleGenerateContentResponse {
105
105
  modelVersion?: string;
106
106
  }
107
107
 
108
- // ============================================================================
109
- // OpenCode Payload Types
110
- // ============================================================================
111
-
112
- export type OpenCodeReasoningEffort = "low" | "medium" | "high";
113
- export type OpenCodePromptCacheRetention = "none" | "1h" | "24h";
114
-
115
- export interface OpenCodeCacheControl {
116
- type: "ephemeral";
117
- ttl?: "1h";
118
- }
119
-
120
- export interface OpenCodeUsage {
121
- prompt_tokens?: number;
122
- completion_tokens?: number;
123
- total_tokens?: number;
124
- prompt_tokens_details?: {
125
- cached_tokens?: number;
126
- cache_read?: number;
127
- cache_creation?: number;
128
- };
129
- }
130
-
131
- export interface OpenCodeChatRequest {
132
- model: string;
133
- messages: any[];
134
- tools?: any[];
135
- tool_choice?: any;
136
- temperature?: number;
137
- top_p?: number;
138
- max_tokens?: number;
139
- stop?: string | string[];
140
- stream?: boolean;
141
- reasoning_effort?: OpenCodeReasoningEffort;
142
- prompt_cache_retention?: OpenCodePromptCacheRetention;
143
- session_id?: string;
144
- }
145
-
146
- export interface OpenCodeChatResponse {
147
- id?: string;
148
- object?: string;
149
- created?: number;
150
- model?: string;
151
- choices?: Array<{
152
- index?: number;
153
- message?: any;
154
- delta?: any;
155
- finish_reason?: string;
156
- }>;
157
- usage?: OpenCodeUsage;
158
- }
159
-
160
- export interface OpenCodeResponsesInputItem {
161
- role: string;
162
- content: any;
163
- cache_control?: OpenCodeCacheControl;
164
- }
165
-
166
- export interface OpenCodeResponsesOutputItem {
167
- id?: string;
168
- type?: string;
169
- status?: string;
170
- content?: any;
171
- name?: string;
172
- call_id?: string;
173
- arguments?: string;
174
- }
175
-
176
- export interface OpenCodeResponsesRequest {
177
- model: string;
178
- input: OpenCodeResponsesInputItem[];
179
- tools?: any[];
180
- parameters?: Record<string, unknown>;
181
- session_id?: string;
182
- }
183
-
184
- export interface OpenCodeResponsesResponse {
185
- id?: string;
186
- output?: OpenCodeResponsesOutputItem[];
187
- usage?: OpenCodeUsage;
188
- }
189
-
190
108
  // ============================================================================
191
109
  // OpenRouter Payload Types
192
110
  // ============================================================================
package/src/types/tool.ts CHANGED
@@ -50,6 +50,12 @@ export interface ToolCallRecord {
50
50
  arguments: Record<string, unknown>;
51
51
  rawArguments?: string;
52
52
  thoughtSignature?: string;
53
+ /**
54
+ * Provider pairing identifier, distinct from the item `id` when the
55
+ * provider uses both (e.g. Responses `call_id` alongside the `fc_…` item
56
+ * id). Tool results pair against this when present.
57
+ */
58
+ callId?: string;
53
59
  }
54
60
 
55
61
  export interface ToolResultRecord {
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Developer script to manually download and refresh the models.dev catalog.
4
+ *
5
+ * Usage:
6
+ * bun src/update-models.ts
7
+ * bun src/update-models.ts --force
8
+ * bun src/update-models.ts --ttl=24h
9
+ */
10
+
11
+ import { refreshModelCatalog, getCatalogStatus } from "./index.ts";
12
+
13
+ const args = process.argv.slice(2);
14
+ const force = args.includes("--force") || !args.some((a) => a.startsWith("--ttl"));
15
+
16
+ let customTtlMs: number | undefined;
17
+ for (const arg of args) {
18
+ if (arg.startsWith("--ttl=")) {
19
+ const val = arg.slice(6);
20
+ if (val.endsWith("h")) {
21
+ customTtlMs = parseFloat(val) * 60 * 60 * 1000;
22
+ } else if (val.endsWith("m")) {
23
+ customTtlMs = parseFloat(val) * 60 * 1000;
24
+ } else {
25
+ customTtlMs = parseFloat(val);
26
+ }
27
+ }
28
+ }
29
+
30
+ console.log("\x1b[36m[Agent Accelerator]\x1b[0m Checking models catalog from https://models.dev/api.json...");
31
+ const startTime = Date.now();
32
+
33
+ try {
34
+ const result = await refreshModelCatalog({ force, ttlMs: customTtlMs });
35
+ const duration = ((Date.now() - startTime) / 1000).toFixed(2);
36
+ const ttlHours = (result.ttlMs / (1000 * 60 * 60)).toFixed(1);
37
+
38
+ if (result.fromCache) {
39
+ console.log(
40
+ `\x1b[32m✓\x1b[0m Models catalog is already fresh (within ${ttlHours}h TTL).`
41
+ );
42
+ } else {
43
+ console.log(
44
+ `\x1b[32m✓\x1b[0m Successfully downloaded and cached \x1b[1m${result.modelCount.toLocaleString()}\x1b[0m models ` +
45
+ `across \x1b[1m${result.providerCount}\x1b[0m providers in ${duration}s.`
46
+ );
47
+ }
48
+ console.log(` \x1b[90mCache location: ${result.cachePath}\x1b[0m`);
49
+ console.log(` \x1b[90mTTL: ${ttlHours} hours\x1b[0m`);
50
+ if (result.expiresAt) {
51
+ console.log(` \x1b[90mNext refresh after: ${new Date(result.expiresAt).toLocaleString()}\x1b[0m`);
52
+ }
53
+ } catch (error: any) {
54
+ console.error(`\x1b[31m✖ Failed to refresh model catalog:\x1b[0m`, error.message || error);
55
+ process.exit(1);
56
+ }
@@ -31,7 +31,7 @@ export function retentionToTtlSeconds(retention?: CacheRetention, ttlSeconds?: n
31
31
  return undefined;
32
32
  }
33
33
 
34
- /** Maps retention settings to OpenCode/OpenRouter prompt-cache TTL values. */
34
+ /** Maps retention settings to OpenRouter prompt-cache TTL values. */
35
35
  export function getPromptCacheRetention(retention?: CacheRetention, supportsLong = true): "24h" | "1h" | undefined {
36
36
  if (!retention || retention === "implicit") return undefined;
37
37
  if (retention === "long" && supportsLong) return "24h";