@almadar/integrations 2.22.0 → 2.24.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.
@@ -258,6 +258,15 @@ type LLMIntegrationActions = {
258
258
  keyPoints: string[];
259
259
  };
260
260
  };
261
+ embed: {
262
+ params: {
263
+ texts: string[];
264
+ model?: string;
265
+ };
266
+ result: {
267
+ embeddings: number[][];
268
+ };
269
+ };
261
270
  };
262
271
  type MLActions = {
263
272
  infer: {
@@ -344,6 +353,21 @@ type EmailActions = {
344
353
  };
345
354
  };
346
355
  };
356
+ type WebhookActions = {
357
+ send: {
358
+ params: {
359
+ url: string;
360
+ event: string;
361
+ payload?: Record<string, string>;
362
+ secret?: string;
363
+ };
364
+ result: {
365
+ status: number;
366
+ ok: boolean;
367
+ durationMs: number;
368
+ };
369
+ };
370
+ };
347
371
  type DockerActions = {
348
372
  build: {
349
373
  params: {
@@ -964,6 +988,7 @@ type IntegrationContracts = {
964
988
  youtube: YouTubeActions;
965
989
  twilio: TwilioActions;
966
990
  email: EmailActions;
991
+ webhook: WebhookActions;
967
992
  docker: DockerActions;
968
993
  storage: StorageActions;
969
994
  queue: QueueActions;
@@ -990,4 +1015,4 @@ type IntegrationName = keyof IntegrationContracts;
990
1015
  */
991
1016
  type IntegrationActionName<K extends IntegrationName> = keyof IntegrationContracts[K] & string;
992
1017
 
993
- export type { ArxivActions as A, CLIActions as C, DatabaseActions as D, EmailActions as E, GitHubActions as G, IconifyActions as I, LLMIntegrationActions as L, MLActions as M, OAuthActions as O, QueueActions as Q, RedisActions as R, StorageActions as S, TwilioActions as T, WikimediaActions as W, YouTubeActions as Y, DatabaseDriver as a, DatabaseQueryParamValue as b, DatabaseQueryParams as c, DatabaseQueryResult as d, DatabaseRow as e, DeepAgentActions as f, DockerActions as g, IntegrationActionName as h, IntegrationContracts as i, IntegrationName as j, OtelActions as k, StripeActions as l };
1018
+ export type { ArxivActions as A, CLIActions as C, DatabaseActions as D, EmailActions as E, GitHubActions as G, IconifyActions as I, LLMIntegrationActions as L, MLActions as M, OAuthActions as O, QueueActions as Q, RedisActions as R, StorageActions as S, TwilioActions as T, WebhookActions as W, YouTubeActions as Y, DatabaseDriver as a, DatabaseQueryParamValue as b, DatabaseQueryParams as c, DatabaseQueryResult as d, DatabaseRow as e, DeepAgentActions as f, DockerActions as g, IntegrationActionName as h, IntegrationContracts as i, IntegrationName as j, OtelActions as k, StripeActions as l, WikimediaActions as m };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { c as IntegrationLogger, b as IntegrationErrorCode, I as IntegrationConfig, B as BaseIntegration, e as IntegrationParams, f as IntegrationResult } from './BaseIntegration-MA-b4fh8.js';
2
2
  export { a as IntegrationError, d as IntegrationParamValue, V as ValidationError, g as ValidationResult, v as validateParams } from './BaseIntegration-MA-b4fh8.js';
3
- export { A as ArxivActions, C as CLIActions, D as DatabaseActions, a as DatabaseDriver, b as DatabaseQueryParamValue, c as DatabaseQueryParams, d as DatabaseQueryResult, e as DatabaseRow, f as DeepAgentActions, g as DockerActions, E as EmailActions, G as GitHubActions, I as IconifyActions, h as IntegrationActionName, i as IntegrationContracts, j as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, k as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, l as StripeActions, T as TwilioActions, W as WikimediaActions, Y as YouTubeActions } from './contracts-CYtxZXrR.js';
3
+ export { A as ArxivActions, C as CLIActions, D as DatabaseActions, a as DatabaseDriver, b as DatabaseQueryParamValue, c as DatabaseQueryParams, d as DatabaseQueryResult, e as DatabaseRow, f as DeepAgentActions, g as DockerActions, E as EmailActions, G as GitHubActions, I as IconifyActions, h as IntegrationActionName, i as IntegrationContracts, j as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, k as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, l as StripeActions, T as TwilioActions, W as WebhookActions, m as WikimediaActions, Y as YouTubeActions } from './contracts-Dv9PM_Cz.js';
4
4
  import { LogMeta } from '@almadar/core';
5
5
  export { I as IntegrationFactory, g as getIntegrationFactory, r as resetIntegrationFactory } from './factory-DTdVeyAi.js';
6
6
  export { GitHubIntegration } from './integrations/github/index.js';
@@ -341,17 +341,30 @@ declare class EmailIntegration extends BaseIntegration {
341
341
  private sendViaResend;
342
342
  }
343
343
 
344
+ /**
345
+ * Outbound webhook integration — signed HTTP POST notifications to external endpoints.
346
+ */
347
+ declare class WebhookIntegration extends BaseIntegration {
348
+ private signingSecret;
349
+ private timeoutMs;
350
+ constructor(config: IntegrationConfig);
351
+ execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
352
+ private send;
353
+ }
354
+
344
355
  /**
345
356
  * LLM integration using @almadar/llm
346
357
  *
347
- * Provides 4 actions:
358
+ * Provides 5 actions:
348
359
  * - generate: Generate text content from a prompt
349
360
  * - classify: Classify text into predefined categories
350
361
  * - extract: Extract structured data from text using a schema
351
362
  * - summarize: Summarize long text content
363
+ * - embed: Generate embeddings for an array of texts
352
364
  */
353
365
  declare class LLMIntegration extends BaseIntegration {
354
366
  private client;
367
+ private embeddings;
355
368
  private provider;
356
369
  constructor(config: IntegrationConfig);
357
370
  /**
@@ -359,11 +372,20 @@ declare class LLMIntegration extends BaseIntegration {
359
372
  * The client will throw a clear error when actually used without a key.
360
373
  */
361
374
  private getClient;
375
+ /**
376
+ * Lazily create the embeddings client. Embeddings route through a dedicated
377
+ * embedding model (default OpenRouter `baai/bge-base-en-v1.5`, matching
378
+ * `@almadar/curation-core`), independent of the chat provider/key, because
379
+ * most chat providers do not expose an embeddings endpoint. Override via
380
+ * `EMBEDDING_PROVIDER` / `EMBEDDING_MODEL` / `EMBEDDING_API_KEY`.
381
+ */
382
+ private getEmbeddings;
362
383
  execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
363
384
  private generate;
364
385
  private classify;
365
386
  private extract;
366
387
  private summarize;
388
+ private embed;
367
389
  }
368
390
 
369
391
  declare class MLIntegration extends BaseIntegration {
@@ -636,4 +658,4 @@ declare class ArxivIntegration extends BaseIntegration {
636
658
  private search;
637
659
  }
638
660
 
639
- export { type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, ArxivIntegration, type ArxivResult, BaseIntegration, CLIIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, IconifyIntegration, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationLogger, IntegrationParams, IntegrationResult, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, type RetryConfig, type SqlGuardResult, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, WikimediaIntegration, YouTubeIntegration, assertReadOnlySelect, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, verifyAndParseStripeEvent, withRetry };
661
+ export { type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, ArxivIntegration, type ArxivResult, BaseIntegration, CLIIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, IconifyIntegration, IntegrationConfig, type IntegrationConstructor, IntegrationErrorCode, IntegrationLogger, IntegrationParams, IntegrationResult, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, type RetryConfig, type SqlGuardResult, StorageIntegration, StripeIntegration, type StripePriceMap, TwilioIntegration, type UpdateSubscriptionInput, type VerifyAndParseInput, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, assertReadOnlySelect, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, verifyAndParseStripeEvent, withRetry };
package/dist/index.js CHANGED
@@ -5,7 +5,8 @@ import { google } from 'googleapis';
5
5
  import twilio from 'twilio';
6
6
  import sgMail from '@sendgrid/mail';
7
7
  import { Resend } from 'resend';
8
- import { getAvailableProvider, LLMClient } from '@almadar/llm';
8
+ import { createHmac } from 'crypto';
9
+ import { getAvailableProvider, LLMClient, EmbeddingClient } from '@almadar/llm';
9
10
  import { z } from 'zod';
10
11
  import { execSync, spawn } from 'child_process';
11
12
  import { mkdtempSync, writeFileSync, rmSync, promises } from 'fs';
@@ -993,10 +994,86 @@ var EmailIntegration = class extends BaseIntegration {
993
994
  }
994
995
  };
995
996
  registerIntegration("email", EmailIntegration);
997
+ var WebhookIntegration = class extends BaseIntegration {
998
+ constructor(config) {
999
+ super(config);
1000
+ this.signingSecret = config.env.WEBHOOK_SIGNING_SECRET || "";
1001
+ this.timeoutMs = Number(config.env.WEBHOOK_TIMEOUT_MS) || 1e4;
1002
+ this.logger.info("Webhook integration initialized");
1003
+ }
1004
+ async execute(action, params) {
1005
+ const validation = this.validateParams(action, params);
1006
+ if (!validation.valid) {
1007
+ return {
1008
+ success: false,
1009
+ error: {
1010
+ name: "IntegrationError",
1011
+ message: "Validation failed",
1012
+ code: "VALIDATION_ERROR",
1013
+ details: validation.errors
1014
+ },
1015
+ metadata: this.createMetadata(action, 0)
1016
+ };
1017
+ }
1018
+ const startTime = Date.now();
1019
+ let retries = 0;
1020
+ try {
1021
+ let data;
1022
+ switch (action) {
1023
+ case "send":
1024
+ data = await this.executeWithRetry(() => this.send(params));
1025
+ break;
1026
+ default:
1027
+ throw new Error(`Unknown action: ${action}`);
1028
+ }
1029
+ return {
1030
+ success: true,
1031
+ data,
1032
+ metadata: this.createMetadata(action, Date.now() - startTime, retries)
1033
+ };
1034
+ } catch (error) {
1035
+ return this.handleError(action, error);
1036
+ }
1037
+ }
1038
+ async send(params) {
1039
+ const { url, event, payload, secret } = params;
1040
+ const body = JSON.stringify({
1041
+ event,
1042
+ payload: payload ?? {},
1043
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1044
+ });
1045
+ const headers = {
1046
+ "Content-Type": "application/json",
1047
+ "X-Almadar-Event": event
1048
+ };
1049
+ const signingSecret = secret || this.signingSecret;
1050
+ if (signingSecret) {
1051
+ headers["X-Almadar-Signature"] = "sha256=" + createHmac("sha256", signingSecret).update(body).digest("hex");
1052
+ }
1053
+ this.logger.debug("Sending webhook", { url: String(url), event: String(event) });
1054
+ const startTime = Date.now();
1055
+ const response = await fetch(url, {
1056
+ method: "POST",
1057
+ headers,
1058
+ body,
1059
+ signal: AbortSignal.timeout(this.timeoutMs)
1060
+ });
1061
+ if (response.status >= 500) {
1062
+ throw new Error(`Webhook endpoint returned ${response.status}`);
1063
+ }
1064
+ return {
1065
+ status: response.status,
1066
+ ok: response.ok,
1067
+ durationMs: Date.now() - startTime
1068
+ };
1069
+ }
1070
+ };
1071
+ registerIntegration("webhook", WebhookIntegration);
996
1072
  var LLMIntegration = class extends BaseIntegration {
997
1073
  constructor(config) {
998
1074
  super(config);
999
1075
  this.client = null;
1076
+ this.embeddings = null;
1000
1077
  const configuredProvider = config.env.PROVIDER;
1001
1078
  this.provider = configuredProvider || getAvailableProvider() || "anthropic";
1002
1079
  this.logger.info(`LLM integration initialized (provider: ${this.provider})`);
@@ -1015,6 +1092,23 @@ var LLMIntegration = class extends BaseIntegration {
1015
1092
  }
1016
1093
  return this.client;
1017
1094
  }
1095
+ /**
1096
+ * Lazily create the embeddings client. Embeddings route through a dedicated
1097
+ * embedding model (default OpenRouter `baai/bge-base-en-v1.5`, matching
1098
+ * `@almadar/curation-core`), independent of the chat provider/key, because
1099
+ * most chat providers do not expose an embeddings endpoint. Override via
1100
+ * `EMBEDDING_PROVIDER` / `EMBEDDING_MODEL` / `EMBEDDING_API_KEY`.
1101
+ */
1102
+ getEmbeddings() {
1103
+ if (!this.embeddings) {
1104
+ this.embeddings = new EmbeddingClient({
1105
+ provider: this.config.env.EMBEDDING_PROVIDER ?? "openrouter",
1106
+ model: this.config.env.EMBEDDING_MODEL ?? "baai/bge-base-en-v1.5",
1107
+ apiKey: this.config.env.EMBEDDING_API_KEY
1108
+ });
1109
+ }
1110
+ return this.embeddings;
1111
+ }
1018
1112
  async execute(action, params) {
1019
1113
  const validation = this.validateParams(action, params);
1020
1114
  if (!validation.valid) {
@@ -1045,6 +1139,9 @@ var LLMIntegration = class extends BaseIntegration {
1045
1139
  case "summarize":
1046
1140
  data = await this.executeWithRetry(() => this.summarize(params));
1047
1141
  break;
1142
+ case "embed":
1143
+ data = await this.executeWithRetry(() => this.embed(params));
1144
+ break;
1048
1145
  default:
1049
1146
  throw new Error(`Unknown action: ${action}`);
1050
1147
  }
@@ -1137,6 +1234,15 @@ Return ONLY valid JSON matching the schema.`,
1137
1234
  });
1138
1235
  return result;
1139
1236
  }
1237
+ async embed(params) {
1238
+ const { texts } = params;
1239
+ if (!Array.isArray(texts)) {
1240
+ throw new Error("llm.embed: `texts` must be an array of strings");
1241
+ }
1242
+ this.logger.debug("Embedding texts", { count: texts.length });
1243
+ const batch = await this.getEmbeddings().embedBatch(texts);
1244
+ return { embeddings: batch.embeddings };
1245
+ }
1140
1246
  };
1141
1247
  registerIntegration("llm", LLMIntegration);
1142
1248
 
@@ -3653,6 +3759,6 @@ var ArxivIntegration = class extends BaseIntegration {
3653
3759
  };
3654
3760
  registerIntegration("arxiv", ArxivIntegration);
3655
3761
 
3656
- export { ArxivIntegration, BaseIntegration, CLIIntegration, ConsoleLogger, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IconifyIntegration, IntegrationError, IntegrationFactory, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, WikimediaIntegration, YouTubeIntegration, assertReadOnlySelect, getIntegration, getIntegrationFactory, getRegisteredIntegrations, isKnownIntegration, registerIntegration, resetIntegrationFactory, validateParams, verifyAndParseStripeEvent, withRetry };
3762
+ export { ArxivIntegration, BaseIntegration, CLIIntegration, ConsoleLogger, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IconifyIntegration, IntegrationError, IntegrationFactory, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, WebhookIntegration, WikimediaIntegration, YouTubeIntegration, assertReadOnlySelect, getIntegration, getIntegrationFactory, getRegisteredIntegrations, isKnownIntegration, registerIntegration, resetIntegrationFactory, validateParams, verifyAndParseStripeEvent, withRetry };
3657
3763
  //# sourceMappingURL=index.js.map
3658
3764
  //# sourceMappingURL=index.js.map