@probelabs/probe 0.6.0-rc154 → 0.6.0-rc161

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 (49) hide show
  1. package/README.md +80 -1
  2. package/build/agent/FallbackManager.d.ts +176 -0
  3. package/build/agent/FallbackManager.js +545 -0
  4. package/build/agent/ProbeAgent.d.ts +9 -1
  5. package/build/agent/ProbeAgent.js +218 -10
  6. package/build/agent/RetryManager.d.ts +157 -0
  7. package/build/agent/RetryManager.js +334 -0
  8. package/build/agent/acp/server.js +1 -0
  9. package/build/agent/acp/tools.js +6 -2
  10. package/build/agent/index.js +1814 -355
  11. package/build/agent/probeTool.js +20 -2
  12. package/build/agent/tools.js +16 -0
  13. package/build/delegate.js +326 -201
  14. package/build/downloader.js +46 -17
  15. package/build/extractor.js +12 -12
  16. package/build/index.js +13 -0
  17. package/build/tools/common.js +5 -3
  18. package/build/tools/edit.js +409 -0
  19. package/build/tools/index.js +11 -0
  20. package/build/tools/vercel.js +55 -14
  21. package/build/utils.js +18 -9
  22. package/cjs/agent/ProbeAgent.cjs +2268 -699
  23. package/cjs/index.cjs +75902 -74348
  24. package/package.json +2 -2
  25. package/src/agent/FallbackManager.d.ts +176 -0
  26. package/src/agent/FallbackManager.js +545 -0
  27. package/src/agent/ProbeAgent.d.ts +9 -1
  28. package/src/agent/ProbeAgent.js +218 -10
  29. package/src/agent/RetryManager.d.ts +157 -0
  30. package/src/agent/RetryManager.js +334 -0
  31. package/src/agent/acp/server.js +1 -0
  32. package/src/agent/acp/tools.js +6 -2
  33. package/src/agent/index.js +8 -0
  34. package/src/agent/probeTool.js +20 -2
  35. package/src/agent/tools.js +16 -0
  36. package/src/delegate.js +326 -201
  37. package/src/downloader.js +46 -17
  38. package/src/extractor.js +12 -12
  39. package/src/index.js +13 -0
  40. package/src/tools/common.js +5 -3
  41. package/src/tools/edit.js +409 -0
  42. package/src/tools/index.js +11 -0
  43. package/src/tools/vercel.js +55 -14
  44. package/src/utils.js +18 -9
  45. package/bin/binaries/probe-v0.6.0-rc154-aarch64-apple-darwin.tar.gz +0 -0
  46. package/bin/binaries/probe-v0.6.0-rc154-aarch64-unknown-linux-gnu.tar.gz +0 -0
  47. package/bin/binaries/probe-v0.6.0-rc154-x86_64-apple-darwin.tar.gz +0 -0
  48. package/bin/binaries/probe-v0.6.0-rc154-x86_64-pc-windows-msvc.zip +0 -0
  49. package/bin/binaries/probe-v0.6.0-rc154-x86_64-unknown-linux-gnu.tar.gz +0 -0
package/README.md CHANGED
@@ -131,11 +131,90 @@ export MODEL_NAME=claude-3-5-sonnet-20241022
131
131
  **ProbeAgent Features:**
132
132
  - **Multi-turn conversations** with automatic history management
133
133
  - **Code search integration** - Uses probe's search capabilities transparently
134
- - **Multiple AI providers** - Supports Anthropic Claude, OpenAI GPT, Google Gemini
134
+ - **Multiple AI providers** - Supports Anthropic Claude, OpenAI GPT, Google Gemini, AWS Bedrock
135
+ - **Automatic retry with exponential backoff** - Handles transient API failures gracefully
136
+ - **Provider fallback** - Seamlessly switch between providers if one fails (e.g., Azure Claude → Bedrock Claude → OpenAI)
135
137
  - **Session management** - Maintain conversation context across calls
136
138
  - **Token tracking** - Monitor usage and costs
137
139
  - **Configurable personas** - Engineer, architect, code-review, and more
138
140
 
141
+ ### Retry and Fallback Support
142
+
143
+ ProbeAgent includes comprehensive retry and fallback capabilities for maximum reliability:
144
+
145
+ ```javascript
146
+ import { ProbeAgent } from '@probelabs/probe';
147
+
148
+ const agent = new ProbeAgent({
149
+ path: '/path/to/your/project',
150
+
151
+ // Configure retry behavior
152
+ retry: {
153
+ maxRetries: 5, // Retry up to 5 times per provider
154
+ initialDelay: 1000, // Start with 1 second delay
155
+ maxDelay: 30000, // Cap delays at 30 seconds
156
+ backoffFactor: 2 // Double the delay each time
157
+ },
158
+
159
+ // Configure provider fallback
160
+ fallback: {
161
+ strategy: 'custom',
162
+ providers: [
163
+ {
164
+ provider: 'anthropic',
165
+ apiKey: process.env.ANTHROPIC_API_KEY,
166
+ model: 'claude-3-7-sonnet-20250219',
167
+ maxRetries: 5 // Can override retry config per provider
168
+ },
169
+ {
170
+ provider: 'bedrock',
171
+ region: 'us-west-2',
172
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
173
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
174
+ model: 'anthropic.claude-sonnet-4-20250514-v1:0'
175
+ },
176
+ {
177
+ provider: 'openai',
178
+ apiKey: process.env.OPENAI_API_KEY,
179
+ model: 'gpt-4o'
180
+ }
181
+ ],
182
+ maxTotalAttempts: 15 // Maximum attempts across all providers
183
+ }
184
+ });
185
+
186
+ // API calls automatically retry on failures and fallback to other providers
187
+ const answer = await agent.answer("Explain this codebase");
188
+ ```
189
+
190
+ **Retry & Fallback Features:**
191
+ - **Exponential backoff** - Intelligently delays retries to avoid overwhelming APIs
192
+ - **Automatic error detection** - Retries on transient errors (Overloaded, 429, 503, timeouts, network errors)
193
+ - **Multi-provider support** - Fallback across Anthropic, OpenAI, Google, and AWS Bedrock
194
+ - **Cross-cloud failover** - Use Azure Claude → Bedrock Claude → OpenAI as fallback chain
195
+ - **Statistics tracking** - Monitor retry attempts and provider usage
196
+ - **Environment variable support** - Configure via env vars for easy deployment
197
+
198
+ **Quick Setup with Auto-Fallback:**
199
+ ```bash
200
+ # Set all your API keys
201
+ export ANTHROPIC_API_KEY=sk-ant-xxx
202
+ export OPENAI_API_KEY=sk-xxx
203
+ export GOOGLE_API_KEY=xxx
204
+ export AUTO_FALLBACK=1 # Enable automatic fallback
205
+ export MAX_RETRIES=5 # Configure retry limit
206
+ ```
207
+
208
+ ```javascript
209
+ // No configuration needed - uses all available providers automatically!
210
+ const agent = new ProbeAgent({
211
+ path: '/path/to/your/project',
212
+ fallback: { auto: true }
213
+ });
214
+ ```
215
+
216
+ See [docs/RETRY_AND_FALLBACK.md](./docs/RETRY_AND_FALLBACK.md) for complete documentation and examples.
217
+
139
218
  ### Using as an MCP Server
140
219
 
141
220
  Probe includes a built-in MCP (Model Context Protocol) server for integration with AI assistants:
@@ -0,0 +1,176 @@
1
+ /**
2
+ * TypeScript type definitions for FallbackManager
3
+ */
4
+
5
+ /**
6
+ * Fallback strategies
7
+ */
8
+ export const FALLBACK_STRATEGIES: {
9
+ /** Try same model on different providers */
10
+ SAME_MODEL: 'same-model';
11
+ /** Try different models on same provider */
12
+ SAME_PROVIDER: 'same-provider';
13
+ /** Try any available provider/model */
14
+ ANY: 'any';
15
+ /** Use custom provider list */
16
+ CUSTOM: 'custom';
17
+ };
18
+
19
+ export type FallbackStrategy =
20
+ | 'same-model'
21
+ | 'same-provider'
22
+ | 'any'
23
+ | 'custom';
24
+
25
+ /**
26
+ * Provider configuration
27
+ */
28
+ export interface ProviderConfig {
29
+ /** Provider name */
30
+ provider: 'anthropic' | 'openai' | 'google' | 'bedrock';
31
+ /** Model name (uses provider default if omitted) */
32
+ model?: string;
33
+ /** API key for the provider */
34
+ apiKey?: string;
35
+ /** Custom API endpoint */
36
+ baseURL?: string;
37
+ /** Max retries for this provider (overrides global) */
38
+ maxRetries?: number;
39
+
40
+ // AWS Bedrock specific
41
+ /** AWS region (for Bedrock) */
42
+ region?: string;
43
+ /** AWS access key ID (for Bedrock) */
44
+ accessKeyId?: string;
45
+ /** AWS secret access key (for Bedrock) */
46
+ secretAccessKey?: string;
47
+ /** AWS session token (for Bedrock) */
48
+ sessionToken?: string;
49
+ }
50
+
51
+ /**
52
+ * Fallback configuration options
53
+ */
54
+ export interface FallbackOptions {
55
+ /** Fallback strategy */
56
+ strategy?: FallbackStrategy;
57
+ /** List of models for same-provider fallback */
58
+ models?: string[];
59
+ /** List of provider configurations for custom fallback */
60
+ providers?: ProviderConfig[];
61
+ /** Stop on first successful response */
62
+ stopOnSuccess?: boolean;
63
+ /** Continue to fallback on non-retryable errors */
64
+ continueOnNonRetryableError?: boolean;
65
+ /** Maximum total attempts across all providers (1-100) */
66
+ maxTotalAttempts?: number;
67
+ /** Enable debug logging */
68
+ debug?: boolean;
69
+ }
70
+
71
+ /**
72
+ * Fallback statistics
73
+ */
74
+ export interface FallbackStats {
75
+ /** Total number of provider attempts */
76
+ totalAttempts: number;
77
+ /** Number of attempts per provider */
78
+ providerAttempts: Record<string, number>;
79
+ /** Name of the successful provider */
80
+ successfulProvider: string | null;
81
+ /** List of failed providers with error details */
82
+ failedProviders: Array<{
83
+ provider: string;
84
+ error: {
85
+ message: string;
86
+ type: string;
87
+ statusCode?: number;
88
+ };
89
+ }>;
90
+ }
91
+
92
+ /**
93
+ * Auto-fallback provider build options
94
+ */
95
+ export interface BuildFallbackOptions {
96
+ /** Primary provider to try first */
97
+ primaryProvider?: string;
98
+ /** Primary model to use */
99
+ primaryModel?: string;
100
+ }
101
+
102
+ /**
103
+ * FallbackManager class for handling provider and model fallback
104
+ */
105
+ export class FallbackManager {
106
+ /** Fallback strategy */
107
+ strategy: FallbackStrategy;
108
+ /** List of models for same-provider fallback */
109
+ models: string[];
110
+ /** List of provider configurations */
111
+ providers: ProviderConfig[];
112
+ /** Stop on first success */
113
+ stopOnSuccess: boolean;
114
+ /** Continue on non-retryable errors */
115
+ continueOnNonRetryableError: boolean;
116
+ /** Maximum total attempts */
117
+ maxTotalAttempts: number;
118
+ /** Debug logging enabled */
119
+ debug: boolean;
120
+ /** Fallback statistics */
121
+ stats: FallbackStats;
122
+
123
+ /**
124
+ * Create a new FallbackManager
125
+ * @param options - Fallback configuration options
126
+ */
127
+ constructor(options?: FallbackOptions);
128
+
129
+ /**
130
+ * Execute a function with fallback support
131
+ * @param fn - Function that takes (provider, model, config) and returns a Promise
132
+ * @returns Result from the function
133
+ * @throws Error if all fallbacks are exhausted
134
+ */
135
+ executeWithFallback<T>(
136
+ fn: (
137
+ provider: any,
138
+ model: string,
139
+ config: ProviderConfig
140
+ ) => Promise<T>
141
+ ): Promise<T>;
142
+
143
+ /**
144
+ * Get fallback statistics
145
+ * @returns Statistics object (copy)
146
+ */
147
+ getStats(): FallbackStats;
148
+
149
+ /**
150
+ * Reset statistics
151
+ */
152
+ resetStats(): void;
153
+ }
154
+
155
+ /**
156
+ * Create a FallbackManager from environment variables
157
+ * @param debug - Enable debug logging
158
+ * @returns Configured FallbackManager instance or null if no config found
159
+ */
160
+ export function createFallbackManagerFromEnv(
161
+ debug?: boolean
162
+ ): FallbackManager | null;
163
+
164
+ /**
165
+ * Build a fallback provider list from current environment
166
+ * @param options - Options for building the list
167
+ * @returns List of provider configurations
168
+ */
169
+ export function buildFallbackProvidersFromEnv(
170
+ options?: BuildFallbackOptions
171
+ ): ProviderConfig[];
172
+
173
+ /**
174
+ * Default model mappings for each provider
175
+ */
176
+ export const DEFAULT_MODELS: Record<string, string>;