@falai/agent 0.1.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 (129) hide show
  1. package/README.md +516 -0
  2. package/dist/constants/index.d.ts +5 -0
  3. package/dist/constants/index.d.ts.map +1 -0
  4. package/dist/constants/index.js +5 -0
  5. package/dist/constants/index.js.map +1 -0
  6. package/dist/core/Agent.d.ts +98 -0
  7. package/dist/core/Agent.d.ts.map +1 -0
  8. package/dist/core/Agent.js +248 -0
  9. package/dist/core/Agent.js.map +1 -0
  10. package/dist/core/DomainRegistry.d.ts +26 -0
  11. package/dist/core/DomainRegistry.d.ts.map +1 -0
  12. package/dist/core/DomainRegistry.js +41 -0
  13. package/dist/core/DomainRegistry.js.map +1 -0
  14. package/dist/core/Events.d.ts +19 -0
  15. package/dist/core/Events.d.ts.map +1 -0
  16. package/dist/core/Events.js +79 -0
  17. package/dist/core/Events.js.map +1 -0
  18. package/dist/core/Observation.d.ts +24 -0
  19. package/dist/core/Observation.d.ts.map +1 -0
  20. package/dist/core/Observation.js +35 -0
  21. package/dist/core/Observation.js.map +1 -0
  22. package/dist/core/PromptBuilder.d.ts +121 -0
  23. package/dist/core/PromptBuilder.d.ts.map +1 -0
  24. package/dist/core/PromptBuilder.js +339 -0
  25. package/dist/core/PromptBuilder.js.map +1 -0
  26. package/dist/core/Route.d.ts +46 -0
  27. package/dist/core/Route.d.ts.map +1 -0
  28. package/dist/core/Route.js +113 -0
  29. package/dist/core/Route.js.map +1 -0
  30. package/dist/core/State.d.ts +50 -0
  31. package/dist/core/State.d.ts.map +1 -0
  32. package/dist/core/State.js +110 -0
  33. package/dist/core/State.js.map +1 -0
  34. package/dist/core/Tool.d.ts +31 -0
  35. package/dist/core/Tool.d.ts.map +1 -0
  36. package/dist/core/Tool.js +33 -0
  37. package/dist/core/Tool.js.map +1 -0
  38. package/dist/core/Transition.d.ts +32 -0
  39. package/dist/core/Transition.d.ts.map +1 -0
  40. package/dist/core/Transition.js +59 -0
  41. package/dist/core/Transition.js.map +1 -0
  42. package/dist/index.d.ts +34 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +26 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/providers/GeminiProvider.d.ts +40 -0
  47. package/dist/providers/GeminiProvider.d.ts.map +1 -0
  48. package/dist/providers/GeminiProvider.js +126 -0
  49. package/dist/providers/GeminiProvider.js.map +1 -0
  50. package/dist/providers/OpenAIProvider.d.ts +42 -0
  51. package/dist/providers/OpenAIProvider.d.ts.map +1 -0
  52. package/dist/providers/OpenAIProvider.js +164 -0
  53. package/dist/providers/OpenAIProvider.js.map +1 -0
  54. package/dist/providers/OpenRouterProvider.d.ts +46 -0
  55. package/dist/providers/OpenRouterProvider.d.ts.map +1 -0
  56. package/dist/providers/OpenRouterProvider.js +171 -0
  57. package/dist/providers/OpenRouterProvider.js.map +1 -0
  58. package/dist/types/agent.d.ts +105 -0
  59. package/dist/types/agent.d.ts.map +1 -0
  60. package/dist/types/agent.js +18 -0
  61. package/dist/types/agent.js.map +1 -0
  62. package/dist/types/ai.d.ts +78 -0
  63. package/dist/types/ai.d.ts.map +1 -0
  64. package/dist/types/ai.js +5 -0
  65. package/dist/types/ai.js.map +1 -0
  66. package/dist/types/history.d.ts +112 -0
  67. package/dist/types/history.d.ts.map +1 -0
  68. package/dist/types/history.js +34 -0
  69. package/dist/types/history.js.map +1 -0
  70. package/dist/types/index.d.ts +14 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +7 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/observation.d.ts +25 -0
  75. package/dist/types/observation.d.ts.map +1 -0
  76. package/dist/types/observation.js +5 -0
  77. package/dist/types/observation.js.map +1 -0
  78. package/dist/types/prompt.d.ts +46 -0
  79. package/dist/types/prompt.d.ts.map +1 -0
  80. package/dist/types/prompt.js +16 -0
  81. package/dist/types/prompt.js.map +1 -0
  82. package/dist/types/route.d.ts +59 -0
  83. package/dist/types/route.d.ts.map +1 -0
  84. package/dist/types/route.js +5 -0
  85. package/dist/types/route.js.map +1 -0
  86. package/dist/types/tool.d.ts +46 -0
  87. package/dist/types/tool.d.ts.map +1 -0
  88. package/dist/types/tool.js +5 -0
  89. package/dist/types/tool.js.map +1 -0
  90. package/dist/utils/retry.d.ts +13 -0
  91. package/dist/utils/retry.d.ts.map +1 -0
  92. package/dist/utils/retry.js +70 -0
  93. package/dist/utils/retry.js.map +1 -0
  94. package/docs/API_REFERENCE.md +517 -0
  95. package/docs/CONSTRUCTOR_OPTIONS.md +256 -0
  96. package/docs/CONTRIBUTING.md +481 -0
  97. package/docs/GETTING_STARTED.md +328 -0
  98. package/docs/PROVIDERS.md +472 -0
  99. package/docs/PUBLISHING.md +174 -0
  100. package/docs/README.md +68 -0
  101. package/docs/STRUCTURE.md +32 -0
  102. package/examples/declarative-agent.ts +217 -0
  103. package/examples/healthcare-agent.ts +283 -0
  104. package/examples/openai-agent.ts +167 -0
  105. package/examples/travel-agent.ts +342 -0
  106. package/package.json +73 -0
  107. package/src/constants/index.ts +5 -0
  108. package/src/core/Agent.ts +307 -0
  109. package/src/core/DomainRegistry.ts +50 -0
  110. package/src/core/Events.ts +101 -0
  111. package/src/core/Observation.ts +46 -0
  112. package/src/core/PromptBuilder.ts +511 -0
  113. package/src/core/Route.ts +136 -0
  114. package/src/core/State.ts +153 -0
  115. package/src/core/Tool.ts +54 -0
  116. package/src/core/Transition.ts +66 -0
  117. package/src/index.ts +83 -0
  118. package/src/providers/GeminiProvider.ts +220 -0
  119. package/src/providers/OpenAIProvider.ts +272 -0
  120. package/src/providers/OpenRouterProvider.ts +282 -0
  121. package/src/types/agent.ts +112 -0
  122. package/src/types/ai.ts +85 -0
  123. package/src/types/history.ts +125 -0
  124. package/src/types/index.ts +56 -0
  125. package/src/types/observation.ts +27 -0
  126. package/src/types/prompt.ts +49 -0
  127. package/src/types/route.ts +68 -0
  128. package/src/types/tool.ts +53 -0
  129. package/src/utils/retry.ts +96 -0
@@ -0,0 +1,472 @@
1
+ # AI Providers Guide
2
+
3
+ This guide covers the available AI providers and how to configure them for optimal performance.
4
+
5
+ ## Overview
6
+
7
+ `@falai/agent` uses a **strategy pattern** for AI providers, allowing you to:
8
+
9
+ - ✅ Switch between different AI providers easily
10
+ - ✅ Configure provider-specific settings
11
+ - ✅ Use backup models for failover
12
+ - ✅ Customize retry logic and timeouts
13
+
14
+ ---
15
+
16
+ ## Available Providers
17
+
18
+ ### 🌐 OpenRouter (Multi-Model Access)
19
+
20
+ **Package:** `openai` (OpenRouter uses OpenAI-compatible API)
21
+
22
+ #### Overview
23
+
24
+ OpenRouter provides access to 200+ AI models through a single unified API, including models from OpenAI, Anthropic, Google, Meta, and more. Perfect for:
25
+
26
+ - Access to multiple model providers
27
+ - Cost optimization through model selection
28
+ - Fallback across different providers
29
+ - Comparing model performance
30
+
31
+ #### Installation
32
+
33
+ ```bash
34
+ bun add openai
35
+ # or
36
+ npm install openai
37
+ ```
38
+
39
+ #### Basic Usage
40
+
41
+ ```typescript
42
+ import { OpenRouterProvider } from "@falai/agent";
43
+
44
+ const provider = new OpenRouterProvider({
45
+ apiKey: process.env.OPENROUTER_API_KEY!,
46
+ model: "openai/gpt-5", // Required - specify your model
47
+ siteUrl: "https://yourapp.com", // Optional: for rankings
48
+ siteName: "Your App Name", // Optional: for rankings
49
+ });
50
+ ```
51
+
52
+ #### Configuration Options
53
+
54
+ All models are specified by the user - see https://openrouter.ai/models for the full list.
55
+
56
+ ```typescript
57
+ const provider = new OpenRouterProvider({
58
+ // Required
59
+ apiKey: string;
60
+ model: string; // e.g., "openai/gpt-5", "anthropic/claude-sonnet-4.5", etc.
61
+
62
+ // Optional
63
+ backupModels?: string[]; // Default: []
64
+ siteUrl?: string; // Your app URL for OpenRouter rankings
65
+ siteName?: string; // Your app name for OpenRouter rankings
66
+ config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>; // Uses openai package types
67
+ retryConfig?: {
68
+ timeout?: number; // Default: 60000ms (60s)
69
+ retries?: number; // Default: 3
70
+ };
71
+ });
72
+ ```
73
+
74
+ #### Example: Custom Configuration
75
+
76
+ ```typescript
77
+ const provider = new OpenRouterProvider({
78
+ apiKey: process.env.OPENROUTER_API_KEY!,
79
+ model: "anthropic/claude-sonnet-4.5",
80
+ backupModels: ["openai/gpt-5", "google/gemini-2.5-flash"],
81
+ siteUrl: "https://myapp.com",
82
+ siteName: "My AI Agent",
83
+ config: {
84
+ temperature: 0.7,
85
+ max_tokens: 2048,
86
+ top_p: 0.9,
87
+ },
88
+ retryConfig: {
89
+ timeout: 45000,
90
+ retries: 2,
91
+ },
92
+ });
93
+ ```
94
+
95
+ ---
96
+
97
+ ### 🤖 Gemini (Google AI)
98
+
99
+ **Package:** `@google/genai`
100
+
101
+ #### Installation
102
+
103
+ ```bash
104
+ bun add @google/genai
105
+ # or
106
+ npm install @google/genai
107
+ ```
108
+
109
+ #### Basic Usage
110
+
111
+ ```typescript
112
+ import { GeminiProvider } from "@falai/agent";
113
+
114
+ const provider = new GeminiProvider({
115
+ apiKey: process.env.GEMINI_API_KEY!,
116
+ model: "models/gemini-2.5-pro", // Required - specify your model
117
+ });
118
+ ```
119
+
120
+ #### Configuration Options
121
+
122
+ All models are specified by the user - check [Google AI Studio](https://ai.google.dev/) for available models.
123
+
124
+ ```typescript
125
+ const provider = new GeminiProvider({
126
+ // Required
127
+ apiKey: string;
128
+ model: string; // e.g., "models/gemini-2.5-pro", "models/gemini-2.5-flash", etc.
129
+
130
+ // Optional
131
+ backupModels?: string[]; // Default: []
132
+ config?: Partial<GenerateContentConfig>; // Uses @google/genai package types
133
+ retryConfig?: {
134
+ timeout?: number; // Default: 60000ms (60s)
135
+ retries?: number; // Default: 3
136
+ };
137
+ });
138
+ ```
139
+
140
+ #### Example: Advanced Configuration
141
+
142
+ ```typescript
143
+ const provider = new GeminiProvider({
144
+ apiKey: process.env.GEMINI_API_KEY!,
145
+ model: "models/gemini-2.5-pro",
146
+ backupModels: ["models/gemini-2.5-flash"],
147
+ config: {
148
+ thinkingConfig: {
149
+ includeThoughts: false,
150
+ thinkingBudget: 8192,
151
+ },
152
+ },
153
+ retryConfig: {
154
+ timeout: 45000,
155
+ retries: 2,
156
+ },
157
+ });
158
+ ```
159
+
160
+ ---
161
+
162
+ ### 🧠 OpenAI
163
+
164
+ **Package:** `openai`
165
+
166
+ #### Installation
167
+
168
+ ```bash
169
+ bun add openai
170
+ # or
171
+ npm install openai
172
+ ```
173
+
174
+ #### Basic Usage
175
+
176
+ ```typescript
177
+ import { OpenAIProvider } from "@falai/agent";
178
+
179
+ const provider = new OpenAIProvider({
180
+ apiKey: process.env.OPENAI_API_KEY!,
181
+ model: "gpt-5", // Required - specify your model
182
+ });
183
+ ```
184
+
185
+ #### Configuration Options
186
+
187
+ All models are specified by the user - see [OpenAI Models](https://platform.openai.com/docs/models) for available options.
188
+
189
+ ```typescript
190
+ const provider = new OpenAIProvider({
191
+ // Required
192
+ apiKey: string;
193
+ model: string; // e.g., "gpt-5", "gpt-5-mini", etc.
194
+
195
+ // Optional
196
+ organization?: string;
197
+ backupModels?: string[]; // Default: []
198
+ config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>; // Uses openai package types
199
+ retryConfig?: {
200
+ timeout?: number; // Default: 60000ms (60s)
201
+ retries?: number; // Default: 3
202
+ };
203
+ });
204
+ ```
205
+
206
+ #### Example: Advanced Configuration
207
+
208
+ ```typescript
209
+ const provider = new OpenAIProvider({
210
+ apiKey: process.env.OPENAI_API_KEY!,
211
+ model: "gpt-5",
212
+ backupModels: ["gpt-5-mini"],
213
+ config: {
214
+ temperature: 0.7,
215
+ max_tokens: 2048,
216
+ top_p: 0.9,
217
+ },
218
+ retryConfig: {
219
+ timeout: 45000,
220
+ retries: 2,
221
+ },
222
+ });
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Retry & Backup Logic
228
+
229
+ Both providers implement **robust retry logic** with:
230
+
231
+ ### Automatic Retries
232
+
233
+ - ⏱️ Exponential backoff between retries
234
+ - ⚙️ Configurable timeout and retry count
235
+ - 🔄 Automatic fallback to backup models
236
+
237
+ ### When Backup Models Are Used
238
+
239
+ Backup models are automatically tried when:
240
+
241
+ - ❌ Primary model returns 500 (Internal Server Error)
242
+ - ❌ Primary model returns 503 (Service Unavailable)
243
+ - ❌ Primary model returns 429 (Rate Limit)
244
+ - ❌ Model is overloaded or unavailable
245
+ - ❌ Request times out
246
+
247
+ ### Example: Backup Flow
248
+
249
+ ```typescript
250
+ const provider = new OpenAIProvider({
251
+ apiKey: process.env.OPENAI_API_KEY!,
252
+ model: "gpt-5", // Primary
253
+ backupModels: [
254
+ "gpt-5-mini", // Try first
255
+ "gpt-5-nano", // Try second
256
+ ],
257
+ retryConfig: {
258
+ timeout: 30000,
259
+ retries: 2,
260
+ },
261
+ });
262
+
263
+ // If gpt-5 fails with 500 error:
264
+ // 1. Retry gpt-5 (up to 2 times with exponential backoff)
265
+ // 2. If still failing, try gpt-5-mini
266
+ // 3. If that fails, try gpt-5-nano
267
+ // 4. If all fail, throw error
268
+ ```
269
+
270
+ ---
271
+
272
+ ## Switching Providers
273
+
274
+ You can easily switch between providers:
275
+
276
+ ```typescript
277
+ import { Agent, GeminiProvider, OpenAIProvider } from "@falai/agent";
278
+
279
+ // Use Gemini
280
+ const geminiAgent = new Agent({
281
+ name: "Gemini Assistant",
282
+ ai: new GeminiProvider({
283
+ apiKey: process.env.GEMINI_API_KEY!,
284
+ }),
285
+ });
286
+
287
+ // Use OpenAI
288
+ const openaiAgent = new Agent({
289
+ name: "OpenAI Assistant",
290
+ ai: new OpenAIProvider({
291
+ apiKey: process.env.OPENAI_API_KEY!,
292
+ }),
293
+ });
294
+
295
+ // Both agents have the same interface!
296
+ ```
297
+
298
+ ---
299
+
300
+ ## Environment Variables
301
+
302
+ It's recommended to store API keys in environment variables:
303
+
304
+ ```bash
305
+ # .env
306
+ GEMINI_API_KEY=your-gemini-api-key-here
307
+ OPENAI_API_KEY=your-openai-api-key-here
308
+ ```
309
+
310
+ Then load them:
311
+
312
+ ```typescript
313
+ import { config } from "dotenv";
314
+ config();
315
+
316
+ const geminiProvider = new GeminiProvider({
317
+ apiKey: process.env.GEMINI_API_KEY!,
318
+ });
319
+
320
+ const openaiProvider = new OpenAIProvider({
321
+ apiKey: process.env.OPENAI_API_KEY!,
322
+ });
323
+ ```
324
+
325
+ ---
326
+
327
+ ## Custom Providers
328
+
329
+ Want to add a custom provider? Implement the `AiProvider` interface:
330
+
331
+ ```typescript
332
+ import {
333
+ AiProvider,
334
+ GenerateMessageInput,
335
+ GenerateMessageOutput,
336
+ } from "@falai/agent";
337
+
338
+ export class CustomProvider implements AiProvider {
339
+ public readonly name = "custom";
340
+
341
+ async generateMessage<TContext = unknown>(
342
+ input: GenerateMessageInput<TContext>
343
+ ): Promise<GenerateMessageOutput> {
344
+ // Your implementation here
345
+ const response = await yourApiCall(input.prompt);
346
+
347
+ return {
348
+ message: response.text,
349
+ metadata: {
350
+ model: "your-model",
351
+ tokensUsed: response.tokens,
352
+ },
353
+ };
354
+ }
355
+ }
356
+ ```
357
+
358
+ See the [API Reference](./API_REFERENCE.md) for the full `AiProvider` interface definition.
359
+
360
+ ---
361
+
362
+ ## Best Practices
363
+
364
+ ### 1. Use Environment-Specific Configs
365
+
366
+ ```typescript
367
+ const isDev = process.env.NODE_ENV === "development";
368
+
369
+ const provider = new GeminiProvider({
370
+ apiKey: process.env.GEMINI_API_KEY!,
371
+ model: isDev ? "models/gemini-2.5-flash" : "models/gemini-2.5-pro",
372
+ retryConfig: {
373
+ timeout: isDev ? 10000 : 60000,
374
+ retries: isDev ? 1 : 3,
375
+ },
376
+ });
377
+ ```
378
+
379
+ ### 2. Configure Backup Models by Use Case
380
+
381
+ ```typescript
382
+ // For critical production apps
383
+ const productionProvider = new OpenAIProvider({
384
+ apiKey: process.env.OPENAI_API_KEY!,
385
+ model: "gpt-5-pro",
386
+ backupModels: ["gpt-5", "gpt-5-mini"], // More capable backups
387
+ });
388
+
389
+ // For high-volume, low-cost
390
+ const volumeProvider = new OpenAIProvider({
391
+ apiKey: process.env.OPENAI_API_KEY!,
392
+ model: "gpt-5-mini",
393
+ backupModels: ["gpt-5-nano"], // Faster, cheaper model
394
+ });
395
+ ```
396
+
397
+ ### 3. Monitor Provider Performance
398
+
399
+ ```typescript
400
+ const response = await agent.generateMessage(input);
401
+
402
+ console.log(`Model used: ${response.metadata?.model}`);
403
+ console.log(`Tokens used: ${response.metadata?.tokensUsed}`);
404
+ console.log(`Finish reason: ${response.metadata?.finishReason}`);
405
+ ```
406
+
407
+ ---
408
+
409
+ ## Troubleshooting
410
+
411
+ ### API Key Not Found
412
+
413
+ ```
414
+ Error: apiKey is required
415
+ ```
416
+
417
+ **Solution:** Ensure your environment variable is set correctly:
418
+
419
+ ```typescript
420
+ if (!process.env.GEMINI_API_KEY) {
421
+ throw new Error("GEMINI_API_KEY environment variable is required");
422
+ }
423
+ ```
424
+
425
+ ### Rate Limit Errors
426
+
427
+ ```
428
+ Error: 429 Too Many Requests
429
+ ```
430
+
431
+ **Solution:** Configure retry logic and backup models:
432
+
433
+ ```typescript
434
+ const provider = new OpenAIProvider({
435
+ apiKey: process.env.OPENAI_API_KEY!,
436
+ model: "gpt-5",
437
+ backupModels: ["gpt-5-mini"], // Fallback to cheaper model
438
+ retryConfig: {
439
+ retries: 5, // More retries
440
+ timeout: 90000, // Longer timeout
441
+ },
442
+ });
443
+ ```
444
+
445
+ ### Timeout Errors
446
+
447
+ ```
448
+ Error: Operation timed out after 60000ms
449
+ ```
450
+
451
+ **Solution:** Increase timeout or reduce max tokens:
452
+
453
+ ```typescript
454
+ const provider = new GeminiProvider({
455
+ apiKey: process.env.GEMINI_API_KEY!,
456
+ model: "models/gemini-2.5-pro",
457
+ config: {
458
+ // No max_tokens parameter needed for Gemini
459
+ },
460
+ retryConfig: {
461
+ timeout: 120000, // 2 minutes
462
+ },
463
+ });
464
+ ```
465
+
466
+ ---
467
+
468
+ ## Next Steps
469
+
470
+ - 📖 [Getting Started](./GETTING_STARTED.md) - Build your first agent
471
+ - 🔧 [API Reference](./API_REFERENCE.md) - Full API documentation
472
+ - 📝 [Examples](../examples/) - Real-world examples
@@ -0,0 +1,174 @@
1
+ # Publishing Guide
2
+
3
+ ## Pre-publish Checklist
4
+
5
+ ### 1. Build and Test
6
+ ```bash
7
+ # Clean previous builds
8
+ rm -rf dist/
9
+
10
+ # Build the package
11
+ bun run build
12
+
13
+ # Verify types and linting
14
+ bun typecheck
15
+ bun lint
16
+
17
+ # Test the build (optional - create a test project)
18
+ npm pack
19
+ # This creates a .tgz file you can test locally
20
+ ```
21
+
22
+ ### 2. Version Management
23
+
24
+ Update version in `package.json`:
25
+ ```json
26
+ {
27
+ "version": "0.1.0" // Follow semver: major.minor.patch
28
+ }
29
+ ```
30
+
31
+ **Semver Guidelines:**
32
+ - **Patch** (0.1.X): Bug fixes, documentation updates
33
+ - **Minor** (0.X.0): New features, backwards compatible
34
+ - **Major** (X.0.0): Breaking changes
35
+
36
+ ### 3. Verify Package Contents
37
+
38
+ ```bash
39
+ # Dry run to see what will be published
40
+ npm publish --dry-run
41
+
42
+ # Check the files that will be included
43
+ npm pack --dry-run
44
+ ```
45
+
46
+ Should include:
47
+ - ✅ `dist/` - Compiled JavaScript + type definitions
48
+ - ✅ `docs/` - Documentation
49
+ - ✅ `examples/` - Example files
50
+ - ✅ `README.md` - Package documentation
51
+ - ✅ `LICENSE` - MIT license
52
+
53
+ Should NOT include:
54
+ - ❌ `src/*.ts` source files (only .d.ts)
55
+ - ❌ `node_modules/`
56
+ - ❌ Development configs
57
+
58
+ ## Publishing to npm
59
+
60
+ ### First Time Setup
61
+
62
+ ```bash
63
+ # Login to npm (one time)
64
+ npm login
65
+ # Enter your npm credentials
66
+ ```
67
+
68
+ ### Publish
69
+
70
+ ```bash
71
+ # Make sure you're on main/master
72
+ git checkout main
73
+ git pull
74
+
75
+ # Ensure everything is committed
76
+ git status
77
+
78
+ # Build
79
+ bun run build
80
+
81
+ # Publish to npm with public access
82
+ npm publish --access public
83
+
84
+ # Or if you want to test first, use a tag
85
+ npm publish --tag beta --access public
86
+ ```
87
+
88
+ ### After Publishing
89
+
90
+ ```bash
91
+ # Tag the release in git
92
+ git tag v0.1.0
93
+ git push origin v0.1.0
94
+
95
+ # Verify on npm
96
+ npm view @falai/agent
97
+ ```
98
+
99
+ ## Post-Publish
100
+
101
+ 1. **Update GitHub Release**
102
+ - Go to https://github.com/gusnips/falai/releases
103
+ - Create a new release for the tag
104
+ - Add release notes
105
+
106
+ 2. **Verify Installation**
107
+ ```bash
108
+ # In a new project
109
+ npm install @falai/agent
110
+ # or
111
+ bun add @falai/agent
112
+ ```
113
+
114
+ 3. **Test the Published Package**
115
+ ```bash
116
+ # Create test project
117
+ mkdir test-agent && cd test-agent
118
+ bun init -y
119
+ bun add @falai/agent
120
+
121
+ # Try importing
122
+ echo 'import { Agent } from "@falai/agent"; console.log(Agent);' > test.ts
123
+ bun run test.ts
124
+ ```
125
+
126
+ ## Troubleshooting
127
+
128
+ ### "You do not have permission to publish"
129
+ - Make sure you're logged in: `npm whoami`
130
+ - Verify you have access to the `@falai` scope
131
+ - Contact scope owner if needed
132
+
133
+ ### "Package already exists"
134
+ - You can't republish the same version
135
+ - Bump version in `package.json` and try again
136
+
137
+ ### "Missing required files"
138
+ - Check `package.json` `files` field
139
+ - Ensure `dist/` exists after build
140
+ - Run `npm pack --dry-run` to preview
141
+
142
+ ### Types not working
143
+ - Verify `types` field in `package.json`
144
+ - Ensure `.d.ts` files are in `dist/`
145
+ - Check `tsconfig.json` has `"declaration": true`
146
+
147
+ ## Version History
148
+
149
+ - **0.1.0** - Initial release
150
+ - Core agent framework
151
+ - Route DSL
152
+ - Gemini provider
153
+ - Full TypeScript support
154
+ - Declarative configuration
155
+
156
+ ## Useful Commands
157
+
158
+ ```bash
159
+ # Check what version is published
160
+ npm view @falai/agent version
161
+
162
+ # See all published versions
163
+ npm view @falai/agent versions
164
+
165
+ # Unpublish a version (within 24 hours, use carefully!)
166
+ npm unpublish @falai/agent@0.1.0
167
+
168
+ # Deprecate a version (preferred over unpublish)
169
+ npm deprecate @falai/agent@0.1.0 "This version has been deprecated. Please upgrade to 0.2.0"
170
+ ```
171
+
172
+ ---
173
+
174
+ **Made with ❤️ for the community**
package/docs/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Documentation
2
+
3
+ Welcome to the `@falai/agent` documentation!
4
+
5
+ ## 📖 Documentation Structure
6
+
7
+ ### Getting Started
8
+
9
+ - **[Getting Started Guide](./GETTING_STARTED.md)** - Build your first agent in 5 minutes
10
+
11
+ ### Core Concepts
12
+
13
+ - **[Constructor Options](./CONSTRUCTOR_OPTIONS.md)** - Comprehensive guide to declarative vs fluent configuration
14
+ - **[Package Structure](./STRUCTURE.md)** - Architecture and design principles
15
+
16
+ ### Reference
17
+
18
+ - **[API Reference](./API_REFERENCE.md)** - Complete API documentation for all classes, methods, and types
19
+ - **[AI Providers Guide](./PROVIDERS.md)** - Gemini, OpenAI, and custom providers
20
+ - **[Contributing Guide](./CONTRIBUTING.md)** - How to contribute to the project
21
+ - **[Publishing Guide](./PUBLISHING.md)** - How to publish updates to npm
22
+
23
+ ## 🎯 Quick Links
24
+
25
+ ### By Use Case
26
+
27
+ **First time here?**
28
+ → Start with [Getting Started](./GETTING_STARTED.md)
29
+
30
+ **Building a complex agent?**
31
+ → Check [Constructor Options](./CONSTRUCTOR_OPTIONS.md)
32
+
33
+ **Need specific API details?**
34
+ → Browse the [API Reference](./API_REFERENCE.md)
35
+
36
+ **Understanding the codebase?**
37
+ → Read [Package Structure](./STRUCTURE.md)
38
+
39
+ ### By Topic
40
+
41
+ - **Agent Configuration**: [Constructor Options](./CONSTRUCTOR_OPTIONS.md)
42
+ - **Conversation Flows**: [API Reference - Routes](./API_REFERENCE.md#route)
43
+ - **Tools & Functions**: [API Reference - Tools](./API_REFERENCE.md#definetool)
44
+ - **Disambiguation**: [API Reference - Observations](./API_REFERENCE.md#observation)
45
+ - **AI Providers**: [API Reference - GeminiProvider](./API_REFERENCE.md#geminiprovider)
46
+
47
+ ## 💡 Examples
48
+
49
+ Check out the [`examples/`](../examples/) directory for complete, runnable examples:
50
+
51
+ - **[Declarative Agent](../examples/declarative-agent.ts)** - Full constructor-based configuration
52
+ - **[Travel Agent](../examples/travel-agent.ts)** - Complex multi-route travel booking system
53
+ - **[Healthcare Agent](../examples/healthcare-agent.ts)** - Disambiguation with observations
54
+
55
+ ## 🤝 Contributing
56
+
57
+ Found an error in the docs? Want to add examples? See our [**Contributing Guide**](./CONTRIBUTING.md) for:
58
+
59
+ - How to set up your development environment
60
+ - Code style guidelines
61
+ - Pull request process
62
+ - Ways you can help
63
+
64
+ We welcome all contributions - from typo fixes to new features!
65
+
66
+ ---
67
+
68
+ **Made with ❤️ for the community**