@tangle-network/agent-integrations 0.24.0 → 0.25.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  integrationSpecToConnector,
3
3
  listIntegrationSpecs
4
- } from "./chunk-L6WBPDUP.js";
4
+ } from "./chunk-4JQ754PA.js";
5
5
 
6
6
  // src/index.ts
7
7
  import { createHmac as createHmac4, randomUUID as randomUUID5, timingSafeEqual as timingSafeEqual3 } from "crypto";
@@ -240,7 +240,7 @@ function createCatalogExecutorProvider(options) {
240
240
  },
241
241
  async subscribeTrigger(connection, triggerId, targetUrl) {
242
242
  if (!options.subscribeTrigger) {
243
- throw new IntegrationError(`Provider ${options.id} does not support trigger subscriptions.`, "action_not_found");
243
+ throw new IntegrationError(`Provider ${options.id} does not support trigger subscriptions.`, "trigger_not_found");
244
244
  }
245
245
  const connector = byConnector.get(connection.connectorId);
246
246
  if (!connector) {
@@ -248,7 +248,7 @@ function createCatalogExecutorProvider(options) {
248
248
  }
249
249
  const trigger2 = connector.triggers?.find((candidate) => candidate.id === triggerId);
250
250
  if (!trigger2) {
251
- throw new IntegrationError(`Trigger ${triggerId} is not defined by connector ${connector.id}.`, "action_not_found");
251
+ throw new IntegrationError(`Trigger ${triggerId} is not defined by connector ${connector.id}.`, "trigger_not_found");
252
252
  }
253
253
  return options.subscribeTrigger(connection, trigger2, targetUrl);
254
254
  },
@@ -739,6 +739,38 @@ function listTangleIntegrationCatalogRuntimePackages() {
739
739
  version: entry.version
740
740
  }));
741
741
  }
742
+ function buildTangleCatalogRuntimePackageManifest(options = {}) {
743
+ const dependencies = {};
744
+ if (options.includeAgentIntegrationsPackage ?? true) {
745
+ dependencies["@tangle-network/agent-integrations"] = options.agentIntegrationsVersion ?? "latest";
746
+ }
747
+ for (const pkg of listTangleIntegrationCatalogRuntimePackages()) {
748
+ dependencies[pkg.packageName] = pkg.version ?? "latest";
749
+ }
750
+ Object.assign(dependencies, options.additionalDependencies);
751
+ return {
752
+ name: options.name ?? "@tangle-network/agent-integrations-runtime-bundle",
753
+ private: true,
754
+ type: "module",
755
+ dependencies: Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b))),
756
+ tangle: {
757
+ integrationContracts: listTangleIntegrationContracts().length,
758
+ packageRuntimeBackends: listTangleIntegrationContracts().filter((contract) => contract.implementation.kind === "package_runtime").length,
759
+ generatedFrom: TANGLE_INTEGRATIONS_CATALOG_SOURCE
760
+ }
761
+ };
762
+ }
763
+ function renderTangleCatalogRuntimePnpmAddCommand(options = {}) {
764
+ const manifest = buildTangleCatalogRuntimePackageManifest({
765
+ includeAgentIntegrationsPackage: options.includeAgentIntegrationsPackage,
766
+ agentIntegrationsVersion: options.agentIntegrationsVersion
767
+ });
768
+ return [
769
+ "pnpm",
770
+ "add",
771
+ ...Object.entries(manifest.dependencies).map(([name, version]) => `${name}@${version}`)
772
+ ].join(" ");
773
+ }
742
774
  function buildTangleIntegrationCatalogConnectors(options = {}) {
743
775
  const providerId = options.providerId ?? TANGLE_INTEGRATIONS_CATALOG_PROVIDER_ID;
744
776
  return buildActivepiecesConnectors({
@@ -773,6 +805,7 @@ function createTangleCatalogExecutorProvider(options) {
773
805
  catalogEntry: sanitizeEntry(importedEntry),
774
806
  piece: {
775
807
  id: importedEntry.id,
808
+ packageName: importedEntry.npmPackage,
776
809
  version: importedEntry.version,
777
810
  actionId: action.id,
778
811
  upstreamActionName: catalogAction?.upstreamName
@@ -794,6 +827,7 @@ function createTangleCatalogExecutorProvider(options) {
794
827
  targetUrl,
795
828
  piece: {
796
829
  id: importedEntry.id,
830
+ packageName: importedEntry.npmPackage,
797
831
  version: importedEntry.version,
798
832
  triggerId: trigger2.id,
799
833
  upstreamTriggerName: catalogTrigger?.upstreamName
@@ -1679,7 +1713,7 @@ function statusForCode(code) {
1679
1713
  if (code === "approval_denied") return 403;
1680
1714
  if (code === "connection_revoked" || code === "connection_expired" || code === "provider_auth_failed") return 401;
1681
1715
  if (code === "scope_missing" || code === "action_denied" || code === "passthrough_disabled") return 403;
1682
- if (code === "action_not_found" || code === "manifest_invalid" || code === "input_invalid") return 400;
1716
+ if (code === "action_not_found" || code === "trigger_not_found" || code === "manifest_invalid" || code === "input_invalid") return 400;
1683
1717
  if (code === "provider_rate_limited") return 429;
1684
1718
  if (code === "provider_unavailable") return 503;
1685
1719
  if (code === "capability_expired" || code === "capability_invalid") return 401;
@@ -6340,6 +6374,9 @@ function createTangleCatalogRuntimeHandler(options) {
6340
6374
  const parsed = parseRuntimeRequest(serialized);
6341
6375
  if (!parsed.ok) return parsed.response;
6342
6376
  const request = parsed.request;
6377
+ if (request.providerId !== request.connection.providerId) {
6378
+ return errorResponse(400, request.action.id, "provider_mismatch", "Request providerId does not match connection providerId.");
6379
+ }
6343
6380
  const connector = byConnector.get(request.connector.id);
6344
6381
  if (!connector) {
6345
6382
  return errorResponse(404, request.action.id, "connector_not_found", `Connector ${request.connector.id} is not in the Tangle catalog runtime.`);
@@ -6378,6 +6415,13 @@ function createTangleCatalogInstalledPackageExecutor(options = {}) {
6378
6415
  if (!packageName) {
6379
6416
  return runtimeFailure(invocation.action.id, "runtime_not_available", `No installed runtime package is known for connector ${invocation.connector.id}.`);
6380
6417
  }
6418
+ if (invocation.request.piece.packageName && invocation.request.piece.packageName !== packageName) {
6419
+ return runtimeFailure(
6420
+ invocation.action.id,
6421
+ "runtime_package_mismatch",
6422
+ `Runtime package ${invocation.request.piece.packageName} does not match catalog package ${packageName}.`
6423
+ );
6424
+ }
6381
6425
  const loaded = await loadRuntimeModule(packageName, options.moduleLoader, moduleCache);
6382
6426
  if (!loaded.ok) {
6383
6427
  return runtimeFailure(invocation.action.id, "runtime_not_installed", loaded.message);
@@ -6386,7 +6430,7 @@ function createTangleCatalogInstalledPackageExecutor(options = {}) {
6386
6430
  if (!piece) {
6387
6431
  return runtimeFailure(invocation.action.id, "runtime_invalid", `Runtime package ${packageName} does not export a recognizable piece for ${invocation.connector.id}.`);
6388
6432
  }
6389
- const action = findRuntimeAction(piece, invocation, options.actionAliases);
6433
+ const action = findRuntimeAction(piece, invocation, options.actionAliases, options.allowFuzzyActionMatch ?? false);
6390
6434
  if (!action?.run) {
6391
6435
  return runtimeFailure(invocation.action.id, "action_not_implemented", `Runtime package ${packageName} does not expose executable action ${invocation.action.id}.`);
6392
6436
  }
@@ -6412,6 +6456,56 @@ function createTangleCatalogInstalledPackageExecutor(options = {}) {
6412
6456
  }
6413
6457
  };
6414
6458
  }
6459
+ async function auditTangleCatalogRuntimePackages(options = {}) {
6460
+ const only = options.connectorIds ? new Set(options.connectorIds) : void 0;
6461
+ const rows = [];
6462
+ const moduleCache = /* @__PURE__ */ new Map();
6463
+ const entries = listActivepiecesCatalogEntries().filter((entry) => entry.npmPackage && (!only || only.has(entry.id)));
6464
+ for (const entry of entries) {
6465
+ const packageName = entry.npmPackage;
6466
+ const base = {
6467
+ connectorId: entry.id,
6468
+ packageName,
6469
+ actionMappingsTotal: entry.actions.length,
6470
+ triggerMappingsTotal: entry.triggers.length
6471
+ };
6472
+ const loaded = await loadRuntimeModule(packageName, options.moduleLoader, moduleCache);
6473
+ if (!loaded.ok) {
6474
+ rows.push({
6475
+ ...base,
6476
+ packageInstalled: false,
6477
+ packageLoads: false,
6478
+ pieceExportFound: false,
6479
+ actionMappingsVerified: 0,
6480
+ triggerMappingsFound: 0,
6481
+ triggerHostingSupported: false,
6482
+ error: loaded.message
6483
+ });
6484
+ continue;
6485
+ }
6486
+ const piece = findPieceExport(loaded.module, entry.id);
6487
+ const actions = piece?.actions ?? [];
6488
+ const triggers = piece?.triggers ?? [];
6489
+ rows.push({
6490
+ ...base,
6491
+ packageInstalled: true,
6492
+ packageLoads: true,
6493
+ pieceExportFound: Boolean(piece),
6494
+ actionMappingsVerified: entry.actions.filter((action) => hasRuntimeName(actions, [
6495
+ action.id,
6496
+ action.title,
6497
+ action.upstreamName
6498
+ ])).length,
6499
+ triggerMappingsFound: entry.triggers.filter((trigger2) => hasRuntimeName(triggers, [
6500
+ trigger2.id,
6501
+ trigger2.title,
6502
+ trigger2.upstreamName
6503
+ ])).length,
6504
+ triggerHostingSupported: entry.triggers.length === 0 || triggers.length > 0
6505
+ });
6506
+ }
6507
+ return rows;
6508
+ }
6415
6509
  function createTangleCatalogCredentialAuthResolver(options) {
6416
6510
  return async function resolveTangleCatalogAuth(connection) {
6417
6511
  if (!connection.secretRef) return void 0;
@@ -6498,7 +6592,11 @@ function findPieceExport(moduleValue, connectorId) {
6498
6592
  ];
6499
6593
  return values.find((value) => Boolean(value) && typeof value === "object" && Array.isArray(value.actions));
6500
6594
  }
6501
- function findRuntimeAction(piece, invocation, aliases = {}) {
6595
+ function hasRuntimeName(values, candidates) {
6596
+ const expected = new Set(candidates.filter((value) => Boolean(value)));
6597
+ return values.filter((value) => Boolean(value) && typeof value === "object").some((value) => [value.name, value.displayName].some((name) => typeof name === "string" && expected.has(name)));
6598
+ }
6599
+ function findRuntimeAction(piece, invocation, aliases = {}, allowFuzzyActionMatch = false) {
6502
6600
  const actions = (piece.actions ?? []).filter((action) => Boolean(action) && typeof action === "object");
6503
6601
  const explicit = aliases[invocation.connector.id]?.[invocation.action.id];
6504
6602
  const candidates = new Set([
@@ -6510,7 +6608,7 @@ function findRuntimeAction(piece, invocation, aliases = {}) {
6510
6608
  for (const action of actions) {
6511
6609
  const names = [action.name, action.displayName].filter((value) => Boolean(value));
6512
6610
  if (names.some((name) => candidates.has(name))) return action;
6513
- if (names.some((name) => [...candidates].some((candidate) => comparable(name) === comparable(candidate)))) return action;
6611
+ if (allowFuzzyActionMatch && names.some((name) => [...candidates].some((candidate) => comparable(name) === comparable(candidate)))) return action;
6514
6612
  }
6515
6613
  return void 0;
6516
6614
  }
@@ -7097,7 +7195,7 @@ var IntegrationHub = class {
7097
7195
  const provider = this.requireProvider(connection.providerId);
7098
7196
  const connector = await this.requireConnector(provider, connection.connectorId);
7099
7197
  const spec = connector.triggers?.find((candidate) => candidate.id === trigger2);
7100
- if (!spec) throw new IntegrationError(`Trigger ${trigger2} is not defined by connector ${connector.id}.`, "action_not_found");
7198
+ if (!spec) throw new IntegrationError(`Trigger ${trigger2} is not defined by connector ${connector.id}.`, "trigger_not_found");
7101
7199
  assertScopes(connection, spec.requiredScopes);
7102
7200
  if (!provider.subscribeTrigger) {
7103
7201
  throw new IntegrationError(`Provider ${provider.id} does not support triggers.`, "auth_not_supported");
@@ -7318,6 +7416,8 @@ export {
7318
7416
  listTangleIntegrationCatalogEntries,
7319
7417
  listTangleIntegrationContracts,
7320
7418
  listTangleIntegrationCatalogRuntimePackages,
7419
+ buildTangleCatalogRuntimePackageManifest,
7420
+ renderTangleCatalogRuntimePnpmAddCommand,
7321
7421
  buildTangleIntegrationCatalogConnectors,
7322
7422
  createTangleCatalogExecutorProvider,
7323
7423
  extractExternalCatalogPublicCount,
@@ -7432,6 +7532,7 @@ export {
7432
7532
  normalizeGatewayCatalog,
7433
7533
  createTangleCatalogRuntimeHandler,
7434
7534
  createTangleCatalogInstalledPackageExecutor,
7535
+ auditTangleCatalogRuntimePackages,
7435
7536
  createTangleCatalogCredentialAuthResolver,
7436
7537
  createTangleCatalogHttpAuthResolver,
7437
7538
  tangleCatalogAuthValue,
@@ -7452,4 +7553,4 @@ export {
7452
7553
  signCapability,
7453
7554
  verifyCapabilityToken
7454
7555
  };
7455
- //# sourceMappingURL=chunk-6SSYWA3J.js.map
7556
+ //# sourceMappingURL=chunk-VJ57GPYO.js.map