@autobe/agent 0.8.0 → 0.9.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 (73) hide show
  1. package/lib/AutoBeAgent.d.ts +183 -12
  2. package/lib/AutoBeAgent.js +245 -65
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/constants/AutoBeSystemPromptConstant.d.ts +4 -3
  5. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  6. package/lib/context/AutoBeContext.d.ts +2 -2
  7. package/lib/factory/index.d.ts +0 -1
  8. package/lib/factory/index.js +0 -1
  9. package/lib/factory/index.js.map +1 -1
  10. package/lib/index.mjs +976 -633
  11. package/lib/index.mjs.map +1 -1
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +1 -1
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  14. package/lib/orchestrate/interface/orchestrateInterface.js +1 -1
  15. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  16. package/lib/orchestrate/prisma/orchestratePrisma.js +1 -1
  17. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  18. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +1 -1
  19. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  20. package/lib/orchestrate/test/orchestrateTest.js +4 -8
  21. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  22. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +2 -2
  23. package/lib/orchestrate/test/orchestrateTestCorrect.js +89 -57
  24. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  25. package/lib/orchestrate/test/orchestrateTestProgress.d.ts +3 -2
  26. package/lib/orchestrate/test/orchestrateTestProgress.js +73 -46
  27. package/lib/orchestrate/test/orchestrateTestProgress.js.map +1 -1
  28. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +2 -2
  29. package/lib/orchestrate/test/orchestrateTestScenario.js +616 -237
  30. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  31. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +123 -0
  32. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js +3 -0
  33. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js.map +1 -0
  34. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +2 -1
  35. package/lib/orchestrate/test/transformTestCorrectHistories.js +14 -10
  36. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  37. package/lib/orchestrate/test/transformTestProgressHistories.d.ts +7 -1
  38. package/lib/orchestrate/test/transformTestProgressHistories.js +20 -20
  39. package/lib/orchestrate/test/transformTestProgressHistories.js.map +1 -1
  40. package/lib/orchestrate/test/transformTestScenarioHistories.d.ts +1 -2
  41. package/lib/orchestrate/test/transformTestScenarioHistories.js +1 -77
  42. package/lib/orchestrate/test/transformTestScenarioHistories.js.map +1 -1
  43. package/lib/structures/IAutoBeConfig.d.ts +48 -10
  44. package/lib/structures/IAutoBeProps.d.ts +87 -0
  45. package/lib/structures/IAutoBeVendor.d.ts +64 -22
  46. package/lib/utils/backoffRetry.d.ts +7 -0
  47. package/lib/utils/backoffRetry.js +73 -0
  48. package/lib/utils/backoffRetry.js.map +1 -0
  49. package/lib/utils/types/BackoffOptions.d.ts +12 -0
  50. package/lib/utils/types/BackoffOptions.js +3 -0
  51. package/lib/utils/types/BackoffOptions.js.map +1 -0
  52. package/package.json +4 -4
  53. package/src/AutoBeAgent.ts +248 -52
  54. package/src/constants/AutoBeSystemPromptConstant.ts +4 -3
  55. package/src/context/AutoBeContext.ts +7 -2
  56. package/src/factory/index.ts +0 -1
  57. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +1 -1
  58. package/src/orchestrate/interface/orchestrateInterface.ts +1 -1
  59. package/src/orchestrate/prisma/orchestratePrisma.ts +1 -0
  60. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +4 -2
  61. package/src/orchestrate/test/orchestrateTest.ts +6 -13
  62. package/src/orchestrate/test/orchestrateTestCorrect.ts +125 -72
  63. package/src/orchestrate/test/orchestrateTestProgress.ts +86 -42
  64. package/src/orchestrate/test/orchestrateTestScenario.ts +192 -151
  65. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +132 -0
  66. package/src/orchestrate/test/transformTestCorrectHistories.ts +14 -10
  67. package/src/orchestrate/test/transformTestProgressHistories.ts +25 -22
  68. package/src/orchestrate/test/transformTestScenarioHistories.ts +0 -79
  69. package/src/structures/IAutoBeConfig.ts +48 -10
  70. package/src/structures/IAutoBeProps.ts +91 -0
  71. package/src/structures/IAutoBeVendor.ts +64 -22
  72. package/src/utils/backoffRetry.ts +84 -0
  73. package/src/utils/types/BackoffOptions.ts +15 -0
@@ -1,5 +1,4 @@
1
1
  import { IAgenticaHistoryJson } from "@agentica/core";
2
- import { AutoBeOpenApi } from "@autobe/interface";
3
2
  import { v4 } from "uuid";
4
3
 
5
4
  import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
@@ -7,8 +6,6 @@ import { AutoBeState } from "../../context/AutoBeState";
7
6
 
8
7
  export const transformTestScenarioHistories = (
9
8
  state: AutoBeState,
10
- allEndpoints: AutoBeOpenApi.IEndpoint[],
11
- files: Record<string, string>,
12
9
  ): Array<
13
10
  IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
14
11
  > => {
@@ -87,47 +84,6 @@ export const transformTestScenarioHistories = (
87
84
  type: "systemMessage",
88
85
  text: AutoBeSystemPromptConstant.TEST,
89
86
  },
90
- {
91
- id: v4(),
92
- created_at: new Date().toISOString(),
93
- type: "systemMessage",
94
- text: [
95
- "# Result of Analyze Agent",
96
- "- The following document contains the user requirements that were extracted through conversations with the user by the Analyze Agent.",
97
- "- The database schema was designed based on these requirements, so you may refer to this document when writing test code or reviewing the schema.",
98
- "",
99
- `## User Request`,
100
- "",
101
- `- ${state.analyze.reason}`,
102
- "",
103
- `## Requirement Analysis Report`,
104
- "",
105
- "```json",
106
- JSON.stringify(state.analyze.files),
107
- "```",
108
- ].join("\n"),
109
- },
110
- {
111
- id: v4(),
112
- created_at: new Date().toISOString(),
113
- type: "systemMessage",
114
- text: [
115
- "# Result of Prisma Agent",
116
- "- Given the following database schema and entity-relationship diagram, write appropriate test code to validate the constraints and relationships defined in the schema. For example, if there is a unique column, include a test that ensures its uniqueness.",
117
- "- The test code should strictly adhere to the schema and relationships—no violations of constraints should occur.",
118
- "- Use the information from the schema and diagram to design meaningful and accurate test cases.",
119
- "",
120
- "## Prisma DB Schema",
121
- "```json",
122
- JSON.stringify(state.prisma.schemas),
123
- "```",
124
- "",
125
- "## Entity Relationship Diagrams",
126
- "```json",
127
- JSON.stringify(state.prisma.compiled.diagrams),
128
- "```",
129
- ].join("\n"),
130
- },
131
87
  {
132
88
  id: v4(),
133
89
  created_at: new Date().toISOString(),
@@ -145,40 +101,5 @@ export const transformTestScenarioHistories = (
145
101
  "```",
146
102
  ].join("\n"),
147
103
  },
148
- {
149
- id: v4(),
150
- created_at: new Date().toISOString(),
151
- type: "systemMessage",
152
- text: AutoBeSystemPromptConstant.TEST,
153
- },
154
- {
155
- id: v4(),
156
- created_at: new Date().toISOString(),
157
- type: "systemMessage",
158
- text: [
159
- `This is a description of different APIs.`,
160
- `Different APIs may have to be called to create one.`,
161
- `Check which functions have been developed.`,
162
- "```json",
163
- JSON.stringify(allEndpoints, null, 2),
164
- "```",
165
- ].join("\n"),
166
- },
167
- {
168
- id: v4(),
169
- created_at: new Date().toISOString(),
170
- type: "systemMessage",
171
- text: [
172
- "Below is basically the generated test code,",
173
- "which is a test to verify that the API is simply called and successful.",
174
- "Since there is already an automatically generated API,",
175
- "when a user requests to create a test scenario, two or more APIs must be combined,",
176
- "but a test in which the currently given endpoint is the main must be created.",
177
- '"Input Test Files" should be selected from the list of files here.',
178
- "```json",
179
- JSON.stringify(files, null, 2),
180
- "```",
181
- ].join("\n"),
182
- },
183
104
  ];
184
105
  };
@@ -1,25 +1,63 @@
1
+ /**
2
+ * Interface defining behavioral configuration for AutoBeAgent localization and
3
+ * context.
4
+ *
5
+ * This interface customizes the agent's communication style, language
6
+ * preferences, and geographical context to provide personalized vibe coding
7
+ * experiences. The configuration enables culturally appropriate interactions
8
+ * and regionally aware development decisions throughout the automated
9
+ * development pipeline.
10
+ *
11
+ * Locale and timezone settings influence not only the language of communication
12
+ * but also contextual understanding of regulatory requirements, business
13
+ * practices, and temporal considerations that may affect requirements analysis,
14
+ * database design, API specifications, and implementation approaches.
15
+ *
16
+ * @author Samchon
17
+ */
1
18
  export interface IAutoBeConfig {
2
19
  /**
3
- * Locale of the A.I. chatbot.
20
+ * Language and cultural locale preference for AI agent communication.
4
21
  *
5
- * If you configure this property, the A.I. chatbot will conversate with the
6
- * given locale. You can get the locale value by
22
+ * Configures the language and cultural context for all AI assistant responses
23
+ * throughout the vibe coding process. When specified, the agent will
24
+ * communicate in the preferred language while respecting cultural conventions
25
+ * and linguistic nuances during requirements gathering, progress updates, and
26
+ * guidance provision.
27
+ *
28
+ * The locale setting also influences the agent's understanding of regional
29
+ * business practices, regulatory considerations, and cultural expectations
30
+ * that may impact software design decisions and implementation approaches.
31
+ *
32
+ * Common formats follow BCP 47 language tags such as "en-US", "ko-KR",
33
+ * "ja-JP", "zh-CN", "de-DE", etc. Platform-specific detection methods:
7
34
  *
8
35
  * - Browser: `navigator.language`
9
- * - NodeJS: `process.env.LANG.split(".")[0]`
36
+ * - Node.js: `process.env.LANG.split(".")[0]`
10
37
  *
11
- * @default your_locale
38
+ * @default System locale or "en" if unavailable
12
39
  */
13
40
  locale?: string;
14
41
 
15
42
  /**
16
- * Timezone of the A.I. chatbot.
43
+ * Geographic timezone for temporal context and time-sensitive operations.
44
+ *
45
+ * Provides timezone awareness for proper handling of time-related
46
+ * considerations during the vibe coding process. This includes scheduling
47
+ * references, temporal business logic requirements, timestamp handling in
48
+ * generated code, and time-based communications that need to be
49
+ * contextualized for the user's local time.
50
+ *
51
+ * Timezone awareness ensures that generated applications properly handle time
52
+ * zones, that scheduling-related requirements are interpreted correctly, and
53
+ * that temporal references in documentation and code comments reflect the
54
+ * user's geographical context.
17
55
  *
18
- * If you configure this property, the A.I. chatbot will consider the given
19
- * timezone. You can get the timezone value by
20
- * `Intl.DateTimeFormat().resolvedOptions().timeZone`.
56
+ * Format follows IANA Time Zone Database identifiers such as
57
+ * "America/New_York", "Asia/Seoul", "Europe/London", "Pacific/Auckland", etc.
58
+ * Platform detection: `Intl.DateTimeFormat().resolvedOptions().timeZone`
21
59
  *
22
- * @default your_timezone
60
+ * @default System timezone or "UTC" if unavailable
23
61
  */
24
62
  timezone?: string;
25
63
  }
@@ -4,10 +4,101 @@ import { ILlmSchema } from "@samchon/openapi";
4
4
  import { IAutoBeConfig } from "./IAutoBeConfig";
5
5
  import { IAutoBeVendor } from "./IAutoBeVendor";
6
6
 
7
+ /**
8
+ * Configuration properties for initializing an AutoBeAgent instance.
9
+ *
10
+ * This interface defines all the essential parameters required to create and
11
+ * configure an AutoBeAgent for vibe coding operations. The properties establish
12
+ * the AI model capabilities, vendor connectivity, compilation infrastructure,
13
+ * behavioral context, and optional session continuity through conversation
14
+ * histories.
15
+ *
16
+ * The configuration enables type-safe AI function calling through
17
+ * model-specific schema generation, ensures compatibility with various AI
18
+ * service providers, and provides the compilation tools necessary for the
19
+ * sophisticated AST-based development pipeline that transforms conversations
20
+ * into working software.
21
+ *
22
+ * @author Samchon
23
+ */
7
24
  export interface IAutoBeProps<Model extends ILlmSchema.Model> {
25
+ /**
26
+ * AI model type specification for type-safe function calling schema
27
+ * generation.
28
+ *
29
+ * Determines the specific AI model schema used for generating function
30
+ * calling interfaces through
31
+ * [`typia.llm.application()`](https://typia.io/docs/llm/application). This
32
+ * type parameter ensures compile-time type safety and enables model-specific
33
+ * optimizations in the AI function calling interface generation process.
34
+ *
35
+ * Common values include "chatgpt" for OpenAI models, "claude" for Anthropic
36
+ * models, "deepseek" for DeepSeek models, and "llama" for Meta Llama models.
37
+ * The choice affects function calling capabilities, parameter limitations,
38
+ * and schema requirements throughout the vibe coding pipeline.
39
+ *
40
+ * Note that Google Gemini ("gemini") is not supported due to its lack of
41
+ * reference types and union types support required for OpenAPI document
42
+ * composition in the vibe coding process.
43
+ */
8
44
  model: Model;
45
+
46
+ /**
47
+ * AI vendor configuration for service provider integration.
48
+ *
49
+ * Defines the complete AI service connection including the OpenAI SDK
50
+ * instance, model identifier, request options, and concurrency controls. This
51
+ * configuration enables the AutoBeAgent to connect with various AI providers
52
+ * while maintaining consistent functionality across the entire automated
53
+ * development workflow.
54
+ *
55
+ * The vendor settings determine the AI capabilities available for
56
+ * requirements analysis, database design, API specification, testing, and
57
+ * implementation phases of the vibe coding process.
58
+ */
9
59
  vendor: IAutoBeVendor;
60
+
61
+ /**
62
+ * Compilation infrastructure for TypeScript, Prisma, and OpenAPI operations.
63
+ *
64
+ * Provides the essential compilation tools required for the sophisticated
65
+ * AST-based development pipeline. The compiler handles validation,
66
+ * transformation, and code generation across all development phases including
67
+ * Prisma schema compilation, OpenAPI document validation, and TypeScript code
68
+ * compilation.
69
+ *
70
+ * For high-performance scenarios with multiple concurrent users, the compiler
71
+ * can be separated into dedicated worker processes to prevent blocking the
72
+ * main agent during computationally intensive compilation operations.
73
+ */
10
74
  compiler: IAutoBeCompiler;
75
+
76
+ /**
77
+ * Optional conversation and development histories for session continuation.
78
+ *
79
+ * Enables resuming previous vibe coding sessions by providing the
80
+ * chronological record of past conversations, development activities, and
81
+ * generated artifacts. When provided, the agent reconstructs its internal
82
+ * state from these histories, allowing seamless continuation of development
83
+ * work.
84
+ *
85
+ * This capability supports iterative development workflows where users can
86
+ * return to modify, enhance, or extend previously generated applications
87
+ * while maintaining full context of earlier decisions and implementations.
88
+ */
11
89
  histories?: AutoBeHistory[] | undefined;
90
+
91
+ /**
92
+ * Optional behavioral configuration for localization and context.
93
+ *
94
+ * Customizes the agent's communication style, language preferences, and
95
+ * geographical context to provide personalized vibe coding experiences.
96
+ * Configuration includes locale settings for internationalized responses and
97
+ * timezone information for temporal context awareness.
98
+ *
99
+ * These settings influence how the agent communicates with users, interprets
100
+ * regional requirements (such as regulatory considerations), and handles
101
+ * time-sensitive operations throughout the development process.
102
+ */
12
103
  config?: IAutoBeConfig | undefined;
13
104
  }
@@ -1,47 +1,89 @@
1
1
  import OpenAI from "openai";
2
2
 
3
3
  /**
4
- * LLM service vendor for Agentica Chat.
4
+ * Interface representing AI vendor configuration for the AutoBeAgent.
5
5
  *
6
- * `IAgenticaVendor` is a type represents an LLM (Large Language Model) vendor
7
- * of the {@link AutoBeAgent}.
6
+ * Defines the connection parameters and settings required to integrate with AI
7
+ * service providers that power the vibe coding pipeline. While utilizing the
8
+ * OpenAI SDK as the connection interface, this configuration supports various
9
+ * LLM vendors beyond OpenAI through flexible endpoint and authentication
10
+ * configuration, enabling integration with Claude, DeepSeek, Meta Llama, and
11
+ * other providers that follow OpenAI-compatible API patterns.
8
12
  *
9
- * Currently, {@link AutoBeAgent} supports OpenAI SDK. However, it does not mean
10
- * that you can use only OpenAI's GPT model in the {@link AutoBeAgent}. The
11
- * OpenAI SDK is just a connection tool to the LLM vendor's API, and you can use
12
- * other LLM vendors by configuring its `baseURL` and API key.
13
+ * The vendor configuration determines the AI capabilities available throughout
14
+ * the entire automated development workflow, from requirements analysis and
15
+ * database design through API specification, testing, and final implementation.
16
+ * Different vendors may offer varying performance characteristics, cost
17
+ * structures, and feature support that can be optimized for specific vibe
18
+ * coding needs.
13
19
  *
14
- * Therefore, if you want to use another LLM vendor like Claude or Gemini,
15
- * please configure the `baseURL` to the {@link api}, and set
16
- * {@link IAutoBeProps.model schema model} as "cluade" or "gemini".
20
+ * Concurrent request management is built-in to prevent API rate limiting and
21
+ * optimize resource utilization across multiple development phases and parallel
22
+ * operations within the vibe coding pipeline.
17
23
  *
18
24
  * @author Samchon
19
25
  */
20
26
  export interface IAutoBeVendor {
21
- /** OpenAI API instance. */
27
+ /**
28
+ * OpenAI SDK instance configured for the target AI vendor.
29
+ *
30
+ * Provides the API connection interface used by the AutoBeAgent to
31
+ * communicate with AI services. While this uses the OpenAI SDK, it can be
32
+ * configured to connect with various LLM providers by setting the appropriate
33
+ * `baseURL` and authentication credentials. The SDK serves as a universal
34
+ * connector that abstracts the underlying API communication protocols.
35
+ *
36
+ * For non-OpenAI vendors, configure the SDK with the vendor's API endpoint
37
+ * and authentication requirements to enable seamless integration with the
38
+ * vibe coding system.
39
+ */
22
40
  api: OpenAI;
23
41
 
24
42
  /**
25
- * Chat model to be used.
43
+ * Specific model identifier to use for AI operations.
44
+ *
45
+ * Specifies the exact model name or identifier that should be used for vibe
46
+ * coding tasks. Supports both official OpenAI chat models and custom model
47
+ * identifiers for third-party hosting services, cloud providers, or
48
+ * alternative LLM vendors. The model choice significantly impacts the
49
+ * quality, performance, and cost of the automated development process.
26
50
  *
27
- * `({}) & string` means to support third party hosting cloud(eg. openRouter,
28
- * aws)
51
+ * Examples include "gpt-4", "gpt-3.5-turbo" for OpenAI, or vendor-specific
52
+ * identifiers like "claude-3-sonnet", "deepseek-chat-v3", "llama3.3-70b" when
53
+ * using alternative providers through compatible APIs.
29
54
  */
30
55
  model: OpenAI.ChatModel | ({} & string);
31
56
 
32
- /** Options for the request. */
57
+ /**
58
+ * Optional request configuration for API calls.
59
+ *
60
+ * Additional request options that will be applied to all API calls made
61
+ * through the OpenAI SDK. This can include custom headers, timeouts, retry
62
+ * policies, or other HTTP client configuration that may be required for
63
+ * specific vendor integrations or enterprise environments.
64
+ *
65
+ * These options provide fine-grained control over the API communication
66
+ * behavior and can be used to optimize performance or meet specific
67
+ * infrastructure requirements.
68
+ */
33
69
  options?: OpenAI.RequestOptions | undefined;
34
70
 
35
71
  /**
36
- * Number of concurrent requests allowed.
72
+ * Maximum number of concurrent API requests allowed.
73
+ *
74
+ * Controls the concurrency level for AI API calls to prevent rate limiting,
75
+ * manage resource consumption, and optimize system performance. The vibe
76
+ * coding pipeline may make multiple parallel requests during development
77
+ * phases, and this setting ensures controlled resource utilization.
37
78
  *
38
- * If you configure this property, {@link AutoBeAgent} will constrain the
39
- * number of concurrent requests to the LLM vendor. If you want to share the
40
- * semaphore instance with other agents, you can directly assign the
41
- * {@link Semaphore} instance to this property.
79
+ * A reasonable default provides balanced performance while respecting typical
80
+ * API rate limits. Lower values reduce resource consumption but may slow
81
+ * development progress, while higher values can improve performance but risk
82
+ * hitting rate limits or overwhelming the AI service.
42
83
  *
43
- * Otherwise, it will not limit the number of concurrent requests, and the
44
- * {@link AutoBeAgent} will send requests asynchronously without any limit.
84
+ * Set to undefined to disable concurrency limiting, allowing unlimited
85
+ * parallel requests (use with caution based on your API limits and
86
+ * infrastructure capacity).
45
87
  *
46
88
  * @default 16
47
89
  */
@@ -0,0 +1,84 @@
1
+ import { RetryOptions } from "./types/BackoffOptions";
2
+
3
+ /**
4
+ * @param fn Function to Apply the retry logic.
5
+ * @param maxRetries How many time to try. Max Retry is 5.
6
+ * @returns
7
+ */
8
+ export async function randomBackoffRetry<T>(
9
+ fn: () => Promise<T>,
10
+ options: Partial<RetryOptions> = {},
11
+ ): Promise<T> {
12
+ const {
13
+ maxRetries = 5,
14
+ baseDelay = 4_000,
15
+ maxDelay = 60_000,
16
+ jitter = 0.8,
17
+ handleError = isRetryError,
18
+ } = options;
19
+
20
+ let lastError: unknown;
21
+
22
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
23
+ try {
24
+ return await fn();
25
+ } catch (err) {
26
+ lastError = err;
27
+
28
+ if (attempt === maxRetries - 1) throw err;
29
+
30
+ if (!handleError(err)) throw err;
31
+
32
+ const tempDelay = Math.min(baseDelay * 2 ** attempt, maxDelay);
33
+ const delay = tempDelay * (1 + Math.random() * jitter);
34
+
35
+ await new Promise((res) => setTimeout(res, delay));
36
+ }
37
+ }
38
+
39
+ throw lastError;
40
+ }
41
+
42
+ function isRetryError(error: any): boolean {
43
+ // 1) Quota exceeded → No retry
44
+ if (
45
+ error?.code === "insufficient_quota" ||
46
+ error?.error?.type === "insufficient_quota"
47
+ ) {
48
+ return false;
49
+ }
50
+
51
+ // 2) 5xx / server_error → Retry
52
+ if (
53
+ (typeof error?.status === "number" && error.status >= 500) ||
54
+ error?.error?.type === "server_error"
55
+ ) {
56
+ return true;
57
+ }
58
+
59
+ // 3) HTTP 429
60
+ if (error?.status === 429) {
61
+ return true;
62
+ }
63
+
64
+ // 4) undici / network related
65
+ const code = error?.code || error?.cause?.code;
66
+ if (
67
+ [
68
+ "UND_ERR_SOCKET",
69
+ "UND_ERR_CONNECT_TIMEOUT",
70
+ "ETIMEDOUT",
71
+ "ECONNRESET",
72
+ "EPIPE",
73
+ ].includes(code)
74
+ ) {
75
+ return true;
76
+ }
77
+
78
+ // 5) fetch abort
79
+ if (error?.message === "terminated" || error?.name === "AbortError") {
80
+ return true;
81
+ }
82
+
83
+ return false;
84
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Random exponential backoff retry utility for handling rate limits
3
+ */
4
+ export interface RetryOptions {
5
+ /** Maximum number of retry attempts (default: 5) */
6
+ maxRetries: number;
7
+ /** Base delay in milliseconds (default: 2000) */
8
+ baseDelay: number;
9
+ /** Maximum delay in milliseconds (default: 60_000) */
10
+ maxDelay: number;
11
+ /** Jitter factor for randomization (0-1, default: 0.3) */
12
+ jitter: number;
13
+ /** Function to determine if error should trigger retry (default: isRetryError) */
14
+ handleError: (error: any) => boolean;
15
+ }