@almadar/integrations 2.0.0 → 2.0.1

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.
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Core types for Almadar integrations
3
+ */
4
+ /**
5
+ * Configuration for an integration instance
6
+ */
7
+ interface IntegrationConfig {
8
+ /** Integration name (matches registry) */
9
+ name: string;
10
+ /** Environment variables (API keys, secrets) */
11
+ env: Record<string, string>;
12
+ /** Optional logger */
13
+ logger?: IntegrationLogger;
14
+ /** Optional rate limiting config */
15
+ rateLimit?: {
16
+ requestsPerSecond: number;
17
+ burstSize: number;
18
+ };
19
+ /** Optional timeout (ms) */
20
+ timeout?: number;
21
+ /** Optional retry config */
22
+ retry?: {
23
+ maxAttempts: number;
24
+ backoffMs: number;
25
+ maxBackoffMs?: number;
26
+ };
27
+ }
28
+ /**
29
+ * Result of an integration action call
30
+ */
31
+ interface IntegrationResult<T = unknown> {
32
+ /** Success flag */
33
+ success: boolean;
34
+ /** Response data (on success) */
35
+ data?: T;
36
+ /** Error (on failure) */
37
+ error?: IntegrationError;
38
+ /** Metadata (timing, retries, etc.) */
39
+ metadata: {
40
+ integration: string;
41
+ action: string;
42
+ duration: number;
43
+ retries: number;
44
+ timestamp: number;
45
+ };
46
+ }
47
+ /**
48
+ * Integration error codes
49
+ */
50
+ type IntegrationErrorCode = 'VALIDATION_ERROR' | 'AUTH_ERROR' | 'RATE_LIMIT_ERROR' | 'TIMEOUT_ERROR' | 'NETWORK_ERROR' | 'SERVICE_ERROR' | 'UNKNOWN_ERROR';
51
+ /**
52
+ * Integration error
53
+ */
54
+ declare class IntegrationError extends Error {
55
+ code: IntegrationErrorCode;
56
+ integration?: string;
57
+ action?: string;
58
+ details?: unknown;
59
+ constructor(message: string, code?: IntegrationErrorCode, details?: unknown);
60
+ toJSON(): {
61
+ name: string;
62
+ message: string;
63
+ code: IntegrationErrorCode;
64
+ integration: string | undefined;
65
+ action: string | undefined;
66
+ details: unknown;
67
+ };
68
+ }
69
+ /**
70
+ * Logger interface
71
+ */
72
+ interface IntegrationLogger {
73
+ debug(message: string, meta?: Record<string, unknown>): void;
74
+ info(message: string, meta?: Record<string, unknown>): void;
75
+ warn(message: string, meta?: Record<string, unknown>): void;
76
+ error(message: string, meta?: Record<string, unknown>): void;
77
+ }
78
+ /**
79
+ * Validation result
80
+ */
81
+ interface ValidationResult {
82
+ valid: boolean;
83
+ errors: ValidationError[];
84
+ }
85
+ /**
86
+ * Validation error
87
+ */
88
+ interface ValidationError {
89
+ param: string;
90
+ message: string;
91
+ }
92
+
93
+ /**
94
+ * Validate action params against registry schema
95
+ */
96
+ declare function validateParams(integration: string, action: string, params: Record<string, unknown>): ValidationResult;
97
+
98
+ /**
99
+ * Base class for all integrations
100
+ */
101
+ declare abstract class BaseIntegration {
102
+ protected config: IntegrationConfig;
103
+ protected logger: IntegrationLogger;
104
+ constructor(config: IntegrationConfig);
105
+ /**
106
+ * Execute an action
107
+ */
108
+ abstract execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
109
+ /**
110
+ * Validate action params against registry
111
+ */
112
+ protected validateParams(action: string, params: Record<string, unknown>): ReturnType<typeof validateParams>;
113
+ /**
114
+ * Handle errors uniformly
115
+ */
116
+ protected handleError(action: string, error: unknown): IntegrationResult;
117
+ /**
118
+ * Create metadata for result
119
+ */
120
+ protected createMetadata(action: string, duration: number, retries?: number): IntegrationResult['metadata'];
121
+ /**
122
+ * Execute with retry logic
123
+ */
124
+ protected executeWithRetry<T>(fn: () => Promise<T>): Promise<T>;
125
+ }
126
+
127
+ /**
128
+ * Factory for creating and managing integration instances
129
+ */
130
+ declare class IntegrationFactory {
131
+ private instances;
132
+ private configs;
133
+ /**
134
+ * Configure an integration (doesn't instantiate yet)
135
+ */
136
+ configure(name: string, config: Omit<IntegrationConfig, 'name'>): void;
137
+ /**
138
+ * Get or create an integration instance
139
+ */
140
+ get(name: string): BaseIntegration;
141
+ /**
142
+ * Execute an action on an integration
143
+ */
144
+ execute(integration: string, action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
145
+ /**
146
+ * Check if integration is configured
147
+ */
148
+ isConfigured(name: string): boolean;
149
+ /**
150
+ * Clear all instances (useful for testing)
151
+ */
152
+ clear(): void;
153
+ /**
154
+ * Clear all instances and configs
155
+ */
156
+ reset(): void;
157
+ }
158
+
159
+ export { BaseIntegration as B, type IntegrationLogger as I, type ValidationError as V, type IntegrationErrorCode as a, type IntegrationConfig as b, type IntegrationResult as c, IntegrationError as d, IntegrationFactory as e, type ValidationResult as f, validateParams as v };
@@ -0,0 +1,368 @@
1
+ import { I as IntegrationLogger, a as IntegrationErrorCode, b as IntegrationConfig, B as BaseIntegration, c as IntegrationResult } from './factory-rMujCO3M.js';
2
+ export { d as IntegrationError, e as IntegrationFactory, V as ValidationError, f as ValidationResult, v as validateParams } from './factory-rMujCO3M.js';
3
+
4
+ /**
5
+ * Console-based logger implementation
6
+ */
7
+ declare class ConsoleLogger implements IntegrationLogger {
8
+ private level;
9
+ constructor(level?: 'debug' | 'info' | 'warn' | 'error');
10
+ debug(message: string, meta?: Record<string, unknown>): void;
11
+ info(message: string, meta?: Record<string, unknown>): void;
12
+ warn(message: string, meta?: Record<string, unknown>): void;
13
+ error(message: string, meta?: Record<string, unknown>): void;
14
+ private shouldLog;
15
+ }
16
+
17
+ /**
18
+ * Retry configuration
19
+ */
20
+ interface RetryConfig {
21
+ maxAttempts: number;
22
+ backoffMs: number;
23
+ maxBackoffMs?: number;
24
+ retryableErrors?: IntegrationErrorCode[];
25
+ }
26
+ /**
27
+ * Execute a function with retry logic
28
+ */
29
+ declare function withRetry<T>(fn: () => Promise<T>, config: RetryConfig): Promise<T>;
30
+
31
+ /**
32
+ * Integration constructor type
33
+ */
34
+ type IntegrationConstructor = new (config: IntegrationConfig) => BaseIntegration;
35
+ /**
36
+ * Register an integration
37
+ */
38
+ declare function registerIntegration(name: string, constructor: IntegrationConstructor): void;
39
+ /**
40
+ * Get integration constructor by name
41
+ */
42
+ declare function getIntegration(name: string): IntegrationConstructor | undefined;
43
+ /**
44
+ * Check if integration is known
45
+ */
46
+ declare function isKnownIntegration(name: string): boolean;
47
+ /**
48
+ * Get all registered integration names
49
+ */
50
+ declare function getRegisteredIntegrations(): string[];
51
+
52
+ /**
53
+ * Stripe integration for payment processing
54
+ */
55
+ declare class StripeIntegration extends BaseIntegration {
56
+ private client;
57
+ constructor(config: IntegrationConfig);
58
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
59
+ private createPaymentIntent;
60
+ private confirmPayment;
61
+ private refund;
62
+ }
63
+
64
+ /**
65
+ * YouTube Data API integration
66
+ */
67
+ declare class YouTubeIntegration extends BaseIntegration {
68
+ private client;
69
+ constructor(config: IntegrationConfig);
70
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
71
+ private search;
72
+ private getVideo;
73
+ private getChannel;
74
+ }
75
+
76
+ /**
77
+ * Twilio messaging integration
78
+ */
79
+ declare class TwilioIntegration extends BaseIntegration {
80
+ private client;
81
+ private phoneNumber;
82
+ constructor(config: IntegrationConfig);
83
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
84
+ private sendSMS;
85
+ private sendWhatsApp;
86
+ }
87
+
88
+ /**
89
+ * Email integration (SendGrid/Resend)
90
+ */
91
+ declare class EmailIntegration extends BaseIntegration {
92
+ private provider;
93
+ private fromEmail;
94
+ private resendClient?;
95
+ constructor(config: IntegrationConfig);
96
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
97
+ private send;
98
+ private sendViaSendGrid;
99
+ private sendViaResend;
100
+ }
101
+
102
+ /**
103
+ * LLM integration using @almadar/llm
104
+ *
105
+ * Provides 4 actions:
106
+ * - generate: Generate text content from a prompt
107
+ * - classify: Classify text into predefined categories
108
+ * - extract: Extract structured data from text using a schema
109
+ * - summarize: Summarize long text content
110
+ */
111
+ declare class LLMIntegration extends BaseIntegration {
112
+ private client;
113
+ private provider;
114
+ constructor(config: IntegrationConfig);
115
+ /**
116
+ * Lazily create client — avoids throwing on construction if API key is missing.
117
+ * The client will throw a clear error when actually used without a key.
118
+ */
119
+ private getClient;
120
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
121
+ private generate;
122
+ private classify;
123
+ private extract;
124
+ private summarize;
125
+ }
126
+
127
+ /**
128
+ * DeepAgent integration for AI code generation
129
+ */
130
+ declare class DeepAgentIntegration extends BaseIntegration {
131
+ private apiUrl;
132
+ private apiKey;
133
+ constructor(config: IntegrationConfig);
134
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
135
+ private sendMessage;
136
+ private cancelGeneration;
137
+ private validateSchema;
138
+ private compileSchema;
139
+ private getThreadHistory;
140
+ private request;
141
+ }
142
+
143
+ /**
144
+ * GitHub Integration for Almadar
145
+ * Provides git operations and GitHub API access for the agent
146
+ */
147
+
148
+ /**
149
+ * GitHub integration class
150
+ */
151
+ declare class GitHubIntegration extends BaseIntegration {
152
+ private token;
153
+ private owner;
154
+ private repo;
155
+ private workDir;
156
+ constructor(config: IntegrationConfig);
157
+ /**
158
+ * Execute a GitHub action
159
+ */
160
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
161
+ /**
162
+ * Clone a repository
163
+ */
164
+ private cloneRepo;
165
+ /**
166
+ * Create a branch
167
+ */
168
+ private createBranch;
169
+ /**
170
+ * Commit changes
171
+ */
172
+ private commit;
173
+ /**
174
+ * Push branch
175
+ */
176
+ private push;
177
+ /**
178
+ * Create a pull request
179
+ */
180
+ private createPR;
181
+ /**
182
+ * Get PR comments
183
+ */
184
+ private getPRComments;
185
+ /**
186
+ * List issues
187
+ */
188
+ private listIssues;
189
+ /**
190
+ * Get issue details
191
+ */
192
+ private getIssue;
193
+ /**
194
+ * Get API config for GitHub API calls
195
+ */
196
+ private getAPIConfig;
197
+ }
198
+
199
+ /**
200
+ * CLI integration for Almadar CLI commands.
201
+ *
202
+ * Wraps `@almadar/cli` commands (validate, compile) as integration actions.
203
+ * This runs server-side and executes CLI commands as child processes.
204
+ *
205
+ * Actions:
206
+ * - validate: Validate an orbital schema and return structured results
207
+ */
208
+ declare class CLIIntegration extends BaseIntegration {
209
+ constructor(config: IntegrationConfig);
210
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
211
+ private validate;
212
+ }
213
+
214
+ /**
215
+ * Redis / Cache integration with in-memory default backend.
216
+ *
217
+ * When `REDIS_URL` is provided in `config.env`, a warning is logged and the
218
+ * integration falls back to the in-memory store (real Redis client support is
219
+ * not yet implemented). When `REDIS_URL` is absent the in-memory store is
220
+ * used silently — this is the expected development mode.
221
+ */
222
+ declare class RedisIntegration extends BaseIntegration {
223
+ private store;
224
+ private locks;
225
+ private channels;
226
+ constructor(config: IntegrationConfig);
227
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
228
+ /** Remove expired entries on access and return whether a key is alive. */
229
+ private isAlive;
230
+ /** Generate a unique lock identifier. */
231
+ private generateLockId;
232
+ private getKey;
233
+ private setKey;
234
+ private deleteKey;
235
+ private acquireLock;
236
+ private releaseLock;
237
+ private incrementKey;
238
+ private expireKey;
239
+ private publishMessage;
240
+ private subscribeChannel;
241
+ }
242
+
243
+ /**
244
+ * Queue integration with in-memory backend.
245
+ *
246
+ * Provides job queue semantics: enqueue, dequeue, status tracking,
247
+ * completion, failure, cancellation, and size queries.
248
+ */
249
+ declare class QueueIntegration extends BaseIntegration {
250
+ /** Map from queue name to ordered list of job IDs */
251
+ private queues;
252
+ /** Map from job ID to job data */
253
+ private jobs;
254
+ constructor(config: IntegrationConfig);
255
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
256
+ /** Generate a unique job identifier. */
257
+ private generateJobId;
258
+ /** Get or create the queue array for a given queue name. */
259
+ private getQueue;
260
+ private enqueue;
261
+ private dequeue;
262
+ private status;
263
+ private complete;
264
+ private failJob;
265
+ private cancel;
266
+ private size;
267
+ }
268
+
269
+ /**
270
+ * OpenTelemetry integration with in-memory backend.
271
+ *
272
+ * Tracks spans and metrics internally for development and testing purposes.
273
+ * No actual OpenTelemetry SDK dependency is required.
274
+ */
275
+ declare class OtelIntegration extends BaseIntegration {
276
+ private spans;
277
+ private metrics;
278
+ constructor(config: IntegrationConfig);
279
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
280
+ private startSpan;
281
+ private endSpan;
282
+ private addEvent;
283
+ private recordMetric;
284
+ private getSpan;
285
+ private getAllMetrics;
286
+ }
287
+
288
+ /**
289
+ * OAuth2/OIDC integration with in-memory mock backend.
290
+ *
291
+ * This is a development/mock implementation. No actual OAuth library is used.
292
+ * State tokens, access tokens, and refresh tokens are generated in-memory and
293
+ * tracked via Maps. Useful for testing OAuth flows without external providers.
294
+ */
295
+ declare class OAuthIntegration extends BaseIntegration {
296
+ /** Maps state token -> provider for pending authorization flows */
297
+ private states;
298
+ /** Maps access token -> token set */
299
+ private tokens;
300
+ /** Maps refresh token -> access token for refresh lookups */
301
+ private refreshIndex;
302
+ /** Maps access token -> mock user session */
303
+ private sessions;
304
+ constructor(config: IntegrationConfig);
305
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
306
+ /** Generate a random hex token of the given byte length. */
307
+ private generateToken;
308
+ /** Generate a mock user profile from a provider and access token. */
309
+ private generateMockUser;
310
+ private authorize;
311
+ private token;
312
+ private refresh;
313
+ private revoke;
314
+ private userinfo;
315
+ }
316
+
317
+ /**
318
+ * Storage integration with in-memory backend for development/testing.
319
+ *
320
+ * Provides S3-compatible object storage operations (upload, download, list,
321
+ * delete, getSignedUrl) backed by an in-memory Map. No cloud SDK dependencies
322
+ * are required.
323
+ */
324
+ declare class StorageIntegration extends BaseIntegration {
325
+ private objects;
326
+ constructor(config: IntegrationConfig);
327
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
328
+ /** Build a composite key from bucket and object key. */
329
+ private compositeKey;
330
+ /** Generate a deterministic etag from content. */
331
+ private generateEtag;
332
+ /** Compute the byte size of content. */
333
+ private computeSize;
334
+ private upload;
335
+ private download;
336
+ private list;
337
+ private deleteObject;
338
+ private getSignedUrl;
339
+ }
340
+
341
+ /**
342
+ * Docker/Container integration with in-memory backend for development/testing.
343
+ *
344
+ * Provides container lifecycle operations (build, run, stop, remove, logs,
345
+ * status, list) backed by an in-memory Map. No Docker SDK or daemon connection
346
+ * is required.
347
+ */
348
+ declare class DockerIntegration extends BaseIntegration {
349
+ private containers;
350
+ private images;
351
+ constructor(config: IntegrationConfig);
352
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
353
+ /** Generate a random hex container/image ID. */
354
+ private generateId;
355
+ /** Find a container by ID (prefix match supported). */
356
+ private findContainer;
357
+ /** Generate realistic log lines for a container. */
358
+ private generateLogLines;
359
+ private build;
360
+ private run;
361
+ private stop;
362
+ private removeContainer;
363
+ private logs;
364
+ private status;
365
+ private list;
366
+ }
367
+
368
+ export { BaseIntegration, CLIIntegration, ConsoleLogger, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationLogger, IntegrationResult, LLMIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, type RetryConfig, StorageIntegration, StripeIntegration, TwilioIntegration, YouTubeIntegration, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, withRetry };
@@ -0,0 +1,50 @@
1
+ import { B as BaseIntegration, b as IntegrationConfig, c as IntegrationResult, e as IntegrationFactory } from '../factory-rMujCO3M.js';
2
+
3
+ /**
4
+ * Mock integration for testing
5
+ */
6
+ declare class MockIntegration extends BaseIntegration {
7
+ private responses;
8
+ private calls;
9
+ constructor(config: IntegrationConfig);
10
+ /**
11
+ * Set mock response for an action
12
+ */
13
+ setResponse(action: string, data: unknown): void;
14
+ /**
15
+ * Get all calls made to this integration
16
+ */
17
+ getCalls(): Array<{
18
+ action: string;
19
+ params: Record<string, unknown>;
20
+ }>;
21
+ /**
22
+ * Clear all calls
23
+ */
24
+ clearCalls(): void;
25
+ execute(action: string, params: Record<string, unknown>): Promise<IntegrationResult>;
26
+ }
27
+
28
+ /**
29
+ * Mock integration factory for testing
30
+ */
31
+ declare class MockIntegrationFactory extends IntegrationFactory {
32
+ constructor();
33
+ /**
34
+ * Set mock response for an integration action
35
+ */
36
+ setMockResponse(integration: string, action: string, data: unknown): void;
37
+ /**
38
+ * Get calls made to an integration
39
+ */
40
+ getMockCalls(integration: string): Array<{
41
+ action: string;
42
+ params: Record<string, unknown>;
43
+ }>;
44
+ /**
45
+ * Clear calls for an integration
46
+ */
47
+ clearMockCalls(integration: string): void;
48
+ }
49
+
50
+ export { MockIntegration, MockIntegrationFactory };
@@ -0,0 +1,29 @@
1
+ import { e as IntegrationFactory } from '../factory-rMujCO3M.js';
2
+
3
+ /**
4
+ * Runtime integration manager
5
+ * Auto-configures integrations from environment variables
6
+ */
7
+ declare class RuntimeIntegrationManager {
8
+ private factory;
9
+ constructor();
10
+ /**
11
+ * Configure from environment variables
12
+ */
13
+ configureFromEnv(): void;
14
+ /**
15
+ * Get effect handler for runtime
16
+ */
17
+ getCallServiceHandler(): (service: string, action: string, params: Record<string, unknown> | undefined) => Promise<unknown>;
18
+ /**
19
+ * Get factory (for advanced usage)
20
+ */
21
+ getFactory(): IntegrationFactory;
22
+ }
23
+
24
+ /**
25
+ * Create a callService effect handler for @almadar/runtime
26
+ */
27
+ declare function createCallServiceHandler(factory: IntegrationFactory): (service: string, action: string, params: Record<string, unknown> | undefined) => Promise<unknown>;
28
+
29
+ export { RuntimeIntegrationManager, createCallServiceHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/integrations",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "External service integrations for Almadar applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",