@almadar/integrations 2.22.0 → 2.23.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: {
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 WikimediaActions, Y as YouTubeActions } from './contracts-CLTh6gjT.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';
@@ -344,14 +344,16 @@ declare class EmailIntegration extends BaseIntegration {
344
344
  /**
345
345
  * LLM integration using @almadar/llm
346
346
  *
347
- * Provides 4 actions:
347
+ * Provides 5 actions:
348
348
  * - generate: Generate text content from a prompt
349
349
  * - classify: Classify text into predefined categories
350
350
  * - extract: Extract structured data from text using a schema
351
351
  * - summarize: Summarize long text content
352
+ * - embed: Generate embeddings for an array of texts
352
353
  */
353
354
  declare class LLMIntegration extends BaseIntegration {
354
355
  private client;
356
+ private embeddings;
355
357
  private provider;
356
358
  constructor(config: IntegrationConfig);
357
359
  /**
@@ -359,11 +361,20 @@ declare class LLMIntegration extends BaseIntegration {
359
361
  * The client will throw a clear error when actually used without a key.
360
362
  */
361
363
  private getClient;
364
+ /**
365
+ * Lazily create the embeddings client. Embeddings route through a dedicated
366
+ * embedding model (default OpenRouter `baai/bge-base-en-v1.5`, matching
367
+ * `@almadar/curation-core`), independent of the chat provider/key, because
368
+ * most chat providers do not expose an embeddings endpoint. Override via
369
+ * `EMBEDDING_PROVIDER` / `EMBEDDING_MODEL` / `EMBEDDING_API_KEY`.
370
+ */
371
+ private getEmbeddings;
362
372
  execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
363
373
  private generate;
364
374
  private classify;
365
375
  private extract;
366
376
  private summarize;
377
+ private embed;
367
378
  }
368
379
 
369
380
  declare class MLIntegration extends BaseIntegration {
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ 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 { getAvailableProvider, LLMClient, EmbeddingClient } from '@almadar/llm';
9
9
  import { z } from 'zod';
10
10
  import { execSync, spawn } from 'child_process';
11
11
  import { mkdtempSync, writeFileSync, rmSync, promises } from 'fs';
@@ -997,6 +997,7 @@ var LLMIntegration = class extends BaseIntegration {
997
997
  constructor(config) {
998
998
  super(config);
999
999
  this.client = null;
1000
+ this.embeddings = null;
1000
1001
  const configuredProvider = config.env.PROVIDER;
1001
1002
  this.provider = configuredProvider || getAvailableProvider() || "anthropic";
1002
1003
  this.logger.info(`LLM integration initialized (provider: ${this.provider})`);
@@ -1015,6 +1016,23 @@ var LLMIntegration = class extends BaseIntegration {
1015
1016
  }
1016
1017
  return this.client;
1017
1018
  }
1019
+ /**
1020
+ * Lazily create the embeddings client. Embeddings route through a dedicated
1021
+ * embedding model (default OpenRouter `baai/bge-base-en-v1.5`, matching
1022
+ * `@almadar/curation-core`), independent of the chat provider/key, because
1023
+ * most chat providers do not expose an embeddings endpoint. Override via
1024
+ * `EMBEDDING_PROVIDER` / `EMBEDDING_MODEL` / `EMBEDDING_API_KEY`.
1025
+ */
1026
+ getEmbeddings() {
1027
+ if (!this.embeddings) {
1028
+ this.embeddings = new EmbeddingClient({
1029
+ provider: this.config.env.EMBEDDING_PROVIDER ?? "openrouter",
1030
+ model: this.config.env.EMBEDDING_MODEL ?? "baai/bge-base-en-v1.5",
1031
+ apiKey: this.config.env.EMBEDDING_API_KEY
1032
+ });
1033
+ }
1034
+ return this.embeddings;
1035
+ }
1018
1036
  async execute(action, params) {
1019
1037
  const validation = this.validateParams(action, params);
1020
1038
  if (!validation.valid) {
@@ -1045,6 +1063,9 @@ var LLMIntegration = class extends BaseIntegration {
1045
1063
  case "summarize":
1046
1064
  data = await this.executeWithRetry(() => this.summarize(params));
1047
1065
  break;
1066
+ case "embed":
1067
+ data = await this.executeWithRetry(() => this.embed(params));
1068
+ break;
1048
1069
  default:
1049
1070
  throw new Error(`Unknown action: ${action}`);
1050
1071
  }
@@ -1137,6 +1158,15 @@ Return ONLY valid JSON matching the schema.`,
1137
1158
  });
1138
1159
  return result;
1139
1160
  }
1161
+ async embed(params) {
1162
+ const { texts } = params;
1163
+ if (!Array.isArray(texts)) {
1164
+ throw new Error("llm.embed: `texts` must be an array of strings");
1165
+ }
1166
+ this.logger.debug("Embedding texts", { count: texts.length });
1167
+ const batch = await this.getEmbeddings().embedBatch(texts);
1168
+ return { embeddings: batch.embeddings };
1169
+ }
1140
1170
  };
1141
1171
  registerIntegration("llm", LLMIntegration);
1142
1172