@almadar/integrations 2.20.0 → 2.22.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.
@@ -885,6 +885,64 @@ type DatabaseActions = {
885
885
  };
886
886
  };
887
887
  };
888
+ type WikimediaActions = {
889
+ getPage: {
890
+ params: {
891
+ title: string;
892
+ };
893
+ result: {
894
+ title?: string;
895
+ description?: string;
896
+ portraitUrl?: string;
897
+ extract?: string;
898
+ };
899
+ };
900
+ };
901
+ type IconifyActions = {
902
+ svgExists: {
903
+ params: {
904
+ path: string;
905
+ };
906
+ result: {
907
+ exists: boolean;
908
+ };
909
+ };
910
+ search: {
911
+ params: {
912
+ query: string;
913
+ limit?: number;
914
+ };
915
+ result: {
916
+ icons: string[];
917
+ };
918
+ };
919
+ getIconBody: {
920
+ params: {
921
+ iconId: string;
922
+ };
923
+ result: {
924
+ body: string | null;
925
+ };
926
+ };
927
+ };
928
+ type ArxivActions = {
929
+ search: {
930
+ params: {
931
+ query: string;
932
+ maxResults?: number;
933
+ };
934
+ result: {
935
+ results: Array<{
936
+ id: string;
937
+ title: string;
938
+ summary: string;
939
+ authors: string[];
940
+ published: string;
941
+ url: string;
942
+ }>;
943
+ };
944
+ };
945
+ };
888
946
  /**
889
947
  * Maps each integration name (as used in `registerIntegration`) to its action
890
948
  * map type. Use with `ServiceContract<IntegrationContracts[K]>` to get a fully
@@ -915,6 +973,9 @@ type IntegrationContracts = {
915
973
  cli: CLIActions;
916
974
  deepagent: DeepAgentActions;
917
975
  database: DatabaseActions;
976
+ wikimedia: WikimediaActions;
977
+ iconify: IconifyActions;
978
+ arxiv: ArxivActions;
918
979
  };
919
980
  /** Integration name literal union. */
920
981
  type IntegrationName = keyof IntegrationContracts;
@@ -929,4 +990,4 @@ type IntegrationName = keyof IntegrationContracts;
929
990
  */
930
991
  type IntegrationActionName<K extends IntegrationName> = keyof IntegrationContracts[K] & string;
931
992
 
932
- export type { CLIActions as C, DatabaseActions as D, EmailActions as E, GitHubActions as G, IntegrationActionName as I, LLMIntegrationActions as L, MLActions as M, OAuthActions as O, QueueActions as Q, RedisActions as R, StorageActions as S, TwilioActions as T, YouTubeActions as Y, DatabaseDriver as a, DatabaseQueryParamValue as b, DatabaseQueryParams as c, DatabaseQueryResult as d, DatabaseRow as e, DeepAgentActions as f, DockerActions as g, IntegrationContracts as h, IntegrationName as i, OtelActions as j, StripeActions as k };
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 };
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 { 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 IntegrationActionName, h as IntegrationContracts, i as IntegrationName, L as LLMIntegrationActions, M as MLActions, O as OAuthActions, j as OtelActions, Q as QueueActions, R as RedisActions, S as StorageActions, k as StripeActions, T as TwilioActions, Y as YouTubeActions } from './contracts-DaVfyPnd.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';
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';
@@ -600,4 +600,40 @@ declare class DatabaseIntegration extends BaseIntegration {
600
600
  private driverFor;
601
601
  }
602
602
 
603
- export { type AlmadarCheckoutSession, type AlmadarCustomer, type AlmadarInvoiceFailure, type AlmadarInvoicePayment, type AlmadarPortalSession, type AlmadarStripeEvent, type AlmadarStripeEventOk, type AlmadarSubscription, type AlmadarSubscriptionStatus, type AlmadarTier, BaseIntegration, CLIIntegration, type CancelSubscriptionInput, ConsoleLogger, type CreateCheckoutInput, type CreateCustomerInput, type CreatePortalInput, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, 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, YouTubeIntegration, assertReadOnlySelect, getIntegration, getRegisteredIntegrations, isKnownIntegration, registerIntegration, verifyAndParseStripeEvent, withRetry };
603
+ declare class WikimediaIntegration extends BaseIntegration {
604
+ private readonly userAgent;
605
+ private readonly timeoutMs;
606
+ constructor(config: IntegrationConfig);
607
+ execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
608
+ /** Look up a title on Wikipedia: description, portrait, lead extract. Empty fields on miss. */
609
+ private getPage;
610
+ }
611
+
612
+ declare class IconifyIntegration extends BaseIntegration {
613
+ private readonly userAgent;
614
+ private readonly timeoutMs;
615
+ constructor(config: IntegrationConfig);
616
+ execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
617
+ private svgExists;
618
+ private search;
619
+ private getIconBody;
620
+ private headOk;
621
+ private getJson;
622
+ }
623
+
624
+ interface ArxivResult {
625
+ id: string;
626
+ title: string;
627
+ summary: string;
628
+ authors: string[];
629
+ published: string;
630
+ url: string;
631
+ }
632
+ declare class ArxivIntegration extends BaseIntegration {
633
+ private readonly timeoutMs;
634
+ constructor(config: IntegrationConfig);
635
+ execute(action: string, params: IntegrationParams): Promise<IntegrationResult>;
636
+ private search;
637
+ }
638
+
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 };
package/dist/index.js CHANGED
@@ -3414,6 +3414,245 @@ var DatabaseIntegration = class extends BaseIntegration {
3414
3414
  };
3415
3415
  registerIntegration("database", DatabaseIntegration);
3416
3416
 
3417
- export { BaseIntegration, CLIIntegration, ConsoleLogger, DatabaseIntegration, DeepAgentIntegration, DockerIntegration, EmailIntegration, GitHubIntegration, IntegrationError, IntegrationFactory, LLMIntegration, MLIntegration, OAuthIntegration, OtelIntegration, QueueIntegration, RedisIntegration, StorageIntegration, StripeIntegration, TwilioIntegration, YouTubeIntegration, assertReadOnlySelect, getIntegration, getIntegrationFactory, getRegisteredIntegrations, isKnownIntegration, registerIntegration, resetIntegrationFactory, validateParams, verifyAndParseStripeEvent, withRetry };
3417
+ // src/integrations/wikimedia/index.ts
3418
+ var WIKI_ENDPOINT = "https://en.wikipedia.org/w/api.php";
3419
+ var DEFAULT_UA = "Almadar/1.0 (https://almadar.dev)";
3420
+ var DEFAULT_TIMEOUT_MS2 = 6e3;
3421
+ var EXTRACT_CHAR_CAP = 2e3;
3422
+ var WikimediaIntegration = class extends BaseIntegration {
3423
+ constructor(config) {
3424
+ super(config);
3425
+ this.userAgent = config.env?.WIKIMEDIA_USER_AGENT ?? DEFAULT_UA;
3426
+ this.timeoutMs = Number(config.env?.WIKIMEDIA_TIMEOUT_MS ?? DEFAULT_TIMEOUT_MS2);
3427
+ this.logger.info("Wikimedia integration initialized");
3428
+ }
3429
+ async execute(action, params) {
3430
+ const validation = this.validateParams(action, params);
3431
+ if (!validation.valid) {
3432
+ return {
3433
+ success: false,
3434
+ error: {
3435
+ name: "IntegrationError",
3436
+ message: "Validation failed",
3437
+ code: "VALIDATION_ERROR",
3438
+ details: validation.errors
3439
+ },
3440
+ metadata: this.createMetadata(action, 0)
3441
+ };
3442
+ }
3443
+ const startTime = Date.now();
3444
+ try {
3445
+ let data;
3446
+ switch (action) {
3447
+ case "getPage":
3448
+ data = await this.executeWithRetry(() => this.getPage(params));
3449
+ break;
3450
+ default:
3451
+ throw new Error(`Unknown action: ${action}`);
3452
+ }
3453
+ return { success: true, data, metadata: this.createMetadata(action, Date.now() - startTime) };
3454
+ } catch (error) {
3455
+ return this.handleError(action, error);
3456
+ }
3457
+ }
3458
+ /** Look up a title on Wikipedia: description, portrait, lead extract. Empty fields on miss. */
3459
+ async getPage(params) {
3460
+ const title = String(params.title ?? "").trim();
3461
+ if (!title) return {};
3462
+ const url = `${WIKI_ENDPOINT}?action=query&format=json&redirects=1&prop=pageimages|description|extracts&explaintext=1&exintro=1&piprop=thumbnail&pithumbsize=240&titles=${encodeURIComponent(title)}`;
3463
+ const ctrl = new AbortController();
3464
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
3465
+ try {
3466
+ const res = await fetch(url, { headers: { "User-Agent": this.userAgent }, signal: ctrl.signal });
3467
+ if (!res.ok) return {};
3468
+ const data = await res.json();
3469
+ const pages = data.query?.pages;
3470
+ if (!pages) return {};
3471
+ const page = Object.values(pages)[0];
3472
+ if (!page || page.missing !== void 0) return {};
3473
+ const extract = typeof page.extract === "string" ? page.extract.slice(0, EXTRACT_CHAR_CAP).trim() : void 0;
3474
+ return {
3475
+ title: page.title,
3476
+ description: page.description ?? (typeof page.extract === "string" ? page.extract.split(".")[0] : void 0),
3477
+ portraitUrl: page.thumbnail?.source,
3478
+ extract
3479
+ };
3480
+ } finally {
3481
+ clearTimeout(timer);
3482
+ }
3483
+ }
3484
+ };
3485
+ registerIntegration("wikimedia", WikimediaIntegration);
3486
+
3487
+ // src/integrations/iconify/index.ts
3488
+ var ICONIFY_API = "https://api.iconify.design";
3489
+ var DEFAULT_UA2 = "Almadar/1.0 (https://almadar.dev)";
3490
+ var DEFAULT_TIMEOUT_MS3 = 6e3;
3491
+ var IconifyIntegration = class extends BaseIntegration {
3492
+ constructor(config) {
3493
+ super(config);
3494
+ this.userAgent = config.env?.ICONIFY_USER_AGENT ?? DEFAULT_UA2;
3495
+ this.timeoutMs = Number(config.env?.ICONIFY_TIMEOUT_MS ?? DEFAULT_TIMEOUT_MS3);
3496
+ this.logger.info("Iconify integration initialized");
3497
+ }
3498
+ async execute(action, params) {
3499
+ const validation = this.validateParams(action, params);
3500
+ if (!validation.valid) {
3501
+ return {
3502
+ success: false,
3503
+ error: {
3504
+ name: "IntegrationError",
3505
+ message: "Validation failed",
3506
+ code: "VALIDATION_ERROR",
3507
+ details: validation.errors
3508
+ },
3509
+ metadata: this.createMetadata(action, 0)
3510
+ };
3511
+ }
3512
+ const startTime = Date.now();
3513
+ try {
3514
+ let data;
3515
+ switch (action) {
3516
+ case "svgExists":
3517
+ data = await this.executeWithRetry(() => this.svgExists(params));
3518
+ break;
3519
+ case "search":
3520
+ data = await this.executeWithRetry(() => this.search(params));
3521
+ break;
3522
+ case "getIconBody":
3523
+ data = await this.executeWithRetry(() => this.getIconBody(params));
3524
+ break;
3525
+ default:
3526
+ throw new Error(`Unknown action: ${action}`);
3527
+ }
3528
+ return { success: true, data, metadata: this.createMetadata(action, Date.now() - startTime) };
3529
+ } catch (error) {
3530
+ return this.handleError(action, error);
3531
+ }
3532
+ }
3533
+ async svgExists(params) {
3534
+ const path = String(params.path ?? "");
3535
+ if (!path) return { exists: false };
3536
+ return { exists: await this.headOk(`${ICONIFY_API}/${path}`) };
3537
+ }
3538
+ async search(params) {
3539
+ const query = String(params.query ?? "");
3540
+ if (!query) return { icons: [] };
3541
+ const limit = Number(params.limit ?? 1);
3542
+ const data = await this.getJson(`${ICONIFY_API}/search?query=${encodeURIComponent(query)}&limit=${limit}`);
3543
+ return { icons: data?.icons ?? [] };
3544
+ }
3545
+ async getIconBody(params) {
3546
+ const iconId = String(params.iconId ?? "");
3547
+ const [prefix, name] = iconId.split(":");
3548
+ if (!prefix || !name) return { body: null };
3549
+ const data = await this.getJson(`${ICONIFY_API}/${prefix}.json?icons=${encodeURIComponent(name)}`);
3550
+ return { body: data?.icons?.[name]?.body ?? data?.aliases?.[name]?.body ?? null };
3551
+ }
3552
+ async headOk(url) {
3553
+ const ctrl = new AbortController();
3554
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
3555
+ try {
3556
+ const res = await fetch(url, { method: "GET", headers: { "User-Agent": this.userAgent }, signal: ctrl.signal });
3557
+ return res.ok;
3558
+ } catch {
3559
+ return false;
3560
+ } finally {
3561
+ clearTimeout(timer);
3562
+ }
3563
+ }
3564
+ async getJson(url) {
3565
+ const ctrl = new AbortController();
3566
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
3567
+ try {
3568
+ const res = await fetch(url, { headers: { "User-Agent": this.userAgent }, signal: ctrl.signal });
3569
+ if (!res.ok) return null;
3570
+ return await res.json();
3571
+ } catch {
3572
+ return null;
3573
+ } finally {
3574
+ clearTimeout(timer);
3575
+ }
3576
+ }
3577
+ };
3578
+ registerIntegration("iconify", IconifyIntegration);
3579
+
3580
+ // src/integrations/arxiv/index.ts
3581
+ var ARXIV_ENDPOINT = "https://export.arxiv.org/api/query";
3582
+ var DEFAULT_TIMEOUT_MS4 = 1e4;
3583
+ var DEFAULT_MAX_RESULTS = 8;
3584
+ function parseAtom(xml) {
3585
+ const entries = [];
3586
+ for (const block of xml.split("<entry>").slice(1)) {
3587
+ const grab = (tag) => {
3588
+ const m = block.match(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, "i"));
3589
+ return m ? m[1].replace(/<[^>]+>/g, "").trim() : "";
3590
+ };
3591
+ const id = grab("id");
3592
+ const title = grab("title").replace(/\s+/g, " ");
3593
+ const summary = grab("summary").replace(/\s+/g, " ");
3594
+ const published = grab("published");
3595
+ const authors = Array.from(block.matchAll(/<author>\s*<name>([^<]+)<\/name>/g)).map((m) => m[1].trim());
3596
+ const linkMatch = block.match(/<link[^>]*rel="alternate"[^>]*href="([^"]+)"/i);
3597
+ const url = linkMatch ? linkMatch[1] : id;
3598
+ if (id || title) entries.push({ id, title, summary, authors, published, url });
3599
+ }
3600
+ return entries;
3601
+ }
3602
+ var ArxivIntegration = class extends BaseIntegration {
3603
+ constructor(config) {
3604
+ super(config);
3605
+ this.timeoutMs = Number(config.env?.ARXIV_TIMEOUT_MS ?? DEFAULT_TIMEOUT_MS4);
3606
+ this.logger.info("arXiv integration initialized");
3607
+ }
3608
+ async execute(action, params) {
3609
+ const validation = this.validateParams(action, params);
3610
+ if (!validation.valid) {
3611
+ return {
3612
+ success: false,
3613
+ error: {
3614
+ name: "IntegrationError",
3615
+ message: "Validation failed",
3616
+ code: "VALIDATION_ERROR",
3617
+ details: validation.errors
3618
+ },
3619
+ metadata: this.createMetadata(action, 0)
3620
+ };
3621
+ }
3622
+ const startTime = Date.now();
3623
+ try {
3624
+ let data;
3625
+ switch (action) {
3626
+ case "search":
3627
+ data = await this.executeWithRetry(() => this.search(params));
3628
+ break;
3629
+ default:
3630
+ throw new Error(`Unknown action: ${action}`);
3631
+ }
3632
+ return { success: true, data, metadata: this.createMetadata(action, Date.now() - startTime) };
3633
+ } catch (error) {
3634
+ return this.handleError(action, error);
3635
+ }
3636
+ }
3637
+ async search(params) {
3638
+ const query = String(params.query ?? "").trim();
3639
+ if (!query) return { results: [] };
3640
+ const maxResults = Number(params.maxResults ?? DEFAULT_MAX_RESULTS);
3641
+ const url = `${ARXIV_ENDPOINT}?search_query=${encodeURIComponent(`all:${query}`)}&start=0&max_results=${maxResults}&sortBy=relevance`;
3642
+ const ctrl = new AbortController();
3643
+ const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
3644
+ try {
3645
+ const res = await fetch(url, { headers: { "Accept": "application/atom+xml" }, signal: ctrl.signal });
3646
+ if (!res.ok) return { results: [] };
3647
+ const xml = await res.text();
3648
+ return { results: parseAtom(xml) };
3649
+ } finally {
3650
+ clearTimeout(timer);
3651
+ }
3652
+ }
3653
+ };
3654
+ registerIntegration("arxiv", ArxivIntegration);
3655
+
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 };
3418
3657
  //# sourceMappingURL=index.js.map
3419
3658
  //# sourceMappingURL=index.js.map