@tangle-network/agent-integrations 0.4.1 → 0.5.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.
package/README.md CHANGED
@@ -58,7 +58,10 @@ The SDK surface for that flow is:
58
58
  - `toMcpTools` for MCP-compatible tool export.
59
59
  - `IntegrationHub.issueCapability` for scoped sandbox handoff.
60
60
  - `createDefaultIntegrationPolicyEngine` for allow / approval / deny decisions.
61
- - `buildIntegrationInvocationEnvelope` for sandbox-safe tool calls.
61
+ - `buildIntegrationInvocationEnvelope` and
62
+ `validateIntegrationInvocationEnvelope` for sandbox-safe tool calls with
63
+ action/tool consistency, idempotency-key, metadata-shape, known-tool, and
64
+ input-size checks.
62
65
  - `createConnectorAdapterProvider` to run first-party adapters through the hub.
63
66
 
64
67
  ```ts
@@ -143,6 +146,7 @@ without changing agent code.
143
146
  - Capability tokens contain no provider credential.
144
147
  - Secret refs are redacted from public telemetry.
145
148
  - Write/destructive actions can be policy-gated.
149
+ - Sandbox invocation envelopes are validated before conversion to hub requests.
146
150
  - Action invocation checks connection ownership, status, scopes, allowed
147
151
  actions, and expiration.
148
152
  - Optional `IntegrationActionGuard` wraps every action invocation for
package/dist/index.d.ts CHANGED
@@ -1027,6 +1027,11 @@ interface IntegrationInvocationEnvelope {
1027
1027
  dryRun?: boolean;
1028
1028
  metadata?: Record<string, unknown>;
1029
1029
  }
1030
+ interface IntegrationInvocationEnvelopeValidationOptions {
1031
+ connectors?: IntegrationConnector[];
1032
+ maxInputBytes?: number;
1033
+ requireKnownTool?: boolean;
1034
+ }
1030
1035
  type NormalizedIntegrationResult = {
1031
1036
  status: 'ok';
1032
1037
  action: string;
@@ -1052,6 +1057,7 @@ declare function buildIntegrationInvocationEnvelope(input: {
1052
1057
  metadata?: Record<string, unknown>;
1053
1058
  }): IntegrationInvocationEnvelope;
1054
1059
  declare function invocationRequestFromEnvelope(envelope: IntegrationInvocationEnvelope): InvokeWithCapabilityRequest;
1060
+ declare function validateIntegrationInvocationEnvelope(envelope: IntegrationInvocationEnvelope, options?: IntegrationInvocationEnvelopeValidationOptions): void;
1055
1061
  declare function redactInvocationEnvelope(envelope: IntegrationInvocationEnvelope): Omit<IntegrationInvocationEnvelope, 'capabilityToken'> & {
1056
1062
  capabilityToken: '[REDACTED]';
1057
1063
  };
@@ -1418,4 +1424,4 @@ declare function createHttpIntegrationProvider(options: HttpIntegrationProviderO
1418
1424
  declare function signCapability(capability: IntegrationCapability, secret: string): string;
1419
1425
  declare function verifyCapabilityToken(token: string, secret: string): IntegrationCapability;
1420
1426
 
1421
- export { type AuthSpec, type CASStrategy, type Capability, type CapabilityClass, type CapabilityMutation, type CapabilityMutationResult, type CapabilityParameterSchema, type CapabilityRead, type CapabilityReadResult, type CompleteAuthRequest, type ConnectorAdapter, type ConnectorAdapterProviderOptions, type ConnectorCredentials, type ConnectorInvocation, type ConnectorManifest, type ConnectorManifestValidationIssue, type ConnectorManifestValidationResult, type ConsistencyModel, CredentialsExpired, DEFAULT_SIGNATURE_TOLERANCE_SECONDS, type DataSourceMetadata, type EventHandlerResult, type ExchangeCodeInput, type GenericHmacVerifyOptions, type GoogleCalendarOptions, type GoogleSheetsOptions, type GraphqlOperationSpec, type HttpIntegrationProviderOptions, type HubSpotOptions, type ImportCatalogOptions, InMemoryConnectionStore, InMemoryOAuthFlowStore, type InboundEvent, type IntegrationActionGuard, type IntegrationActionRequest, type IntegrationActionResult, type IntegrationActionRisk, type IntegrationActor, type IntegrationApprovalRequest, type IntegrationApprovalResolution, type IntegrationCapability, type IntegrationConnection, type IntegrationConnectionStore, type IntegrationConnector, type IntegrationConnectorAction, type IntegrationConnectorCategory, type IntegrationConnectorTrigger, type IntegrationDataClass, IntegrationError, type IntegrationGuardContext, IntegrationHub, type IntegrationHubOptions, type IntegrationInvocationEnvelope, type IntegrationPolicyDecision, type IntegrationPolicyEffect, type IntegrationPolicyEngine, type IntegrationPolicyRule, type IntegrationProvider, type IntegrationProviderKind, type IntegrationToolDefinition, type IntegrationToolSearchFilters, type IntegrationToolSearchResult, type IntegrationTriggerEvent, type IntegrationTriggerSubscription, type InvokeWithCapabilityRequest, type IssueCapabilityRequest, type IssuedIntegrationCapability, type McpCatalog, type McpCatalogTool, type McpToolDefinition, type MicrosoftCalendarOptions, type NormalizedIntegrationResult, type NotionDatabaseOptions, type OAuthFlowStore, type OAuthTokens, type OpenApiDocument, type OpenApiOperation, type ParsedStripeSignatureHeader, type PendingOAuthFlow, type RateLimitSpec, type RefreshInput, type ResolvedDataSource, ResourceContention, type SecretRef, type SlackOptions, type SlackVerifyOptions, type StartAuthRequest, type StartAuthResult, type StartOAuthInput, type StartOAuthOutput, StaticIntegrationPolicyEngine, type StaticIntegrationPolicyOptions, type StripeVerifyOptions, type TwilioVerifyOptions, _resetPendingFlowsForTests, assertValidConnectorManifest, buildApprovalRequest, buildIntegrationInvocationEnvelope, buildIntegrationToolCatalog, consumePendingFlow, createConnectorAdapterProvider, createDefaultIntegrationPolicyEngine, createHttpIntegrationProvider, createMockIntegrationProvider, exchangeAuthorizationCode, firstHeader, googleCalendar, googleSheets, hubspot, importGraphqlConnector, importMcpConnector, importOpenApiConnector, integrationToolName, invocationRequestFromEnvelope, manifestToConnector, microsoftCalendar, normalizeIntegrationResult, notionDatabase, parseIntegrationToolName, parseStripeSignatureHeader, redactApprovalRequest, redactCapability, redactInvocationEnvelope, refreshAccessToken, sanitizeConnection, searchIntegrationTools, signCapability, slack, slackEventsConnector, startOAuthFlow, stripePackConnector, stripeWebhookReceiverConnector, toMcpTools, twilioSmsConnector, validateConnectorManifest, verifyCapabilityToken, verifyHmacSignature, verifySlackSignature, verifyStripeSignature, verifyTwilioSignature, webhookConnector };
1427
+ export { type AuthSpec, type CASStrategy, type Capability, type CapabilityClass, type CapabilityMutation, type CapabilityMutationResult, type CapabilityParameterSchema, type CapabilityRead, type CapabilityReadResult, type CompleteAuthRequest, type ConnectorAdapter, type ConnectorAdapterProviderOptions, type ConnectorCredentials, type ConnectorInvocation, type ConnectorManifest, type ConnectorManifestValidationIssue, type ConnectorManifestValidationResult, type ConsistencyModel, CredentialsExpired, DEFAULT_SIGNATURE_TOLERANCE_SECONDS, type DataSourceMetadata, type EventHandlerResult, type ExchangeCodeInput, type GenericHmacVerifyOptions, type GoogleCalendarOptions, type GoogleSheetsOptions, type GraphqlOperationSpec, type HttpIntegrationProviderOptions, type HubSpotOptions, type ImportCatalogOptions, InMemoryConnectionStore, InMemoryOAuthFlowStore, type InboundEvent, type IntegrationActionGuard, type IntegrationActionRequest, type IntegrationActionResult, type IntegrationActionRisk, type IntegrationActor, type IntegrationApprovalRequest, type IntegrationApprovalResolution, type IntegrationCapability, type IntegrationConnection, type IntegrationConnectionStore, type IntegrationConnector, type IntegrationConnectorAction, type IntegrationConnectorCategory, type IntegrationConnectorTrigger, type IntegrationDataClass, IntegrationError, type IntegrationGuardContext, IntegrationHub, type IntegrationHubOptions, type IntegrationInvocationEnvelope, type IntegrationInvocationEnvelopeValidationOptions, type IntegrationPolicyDecision, type IntegrationPolicyEffect, type IntegrationPolicyEngine, type IntegrationPolicyRule, type IntegrationProvider, type IntegrationProviderKind, type IntegrationToolDefinition, type IntegrationToolSearchFilters, type IntegrationToolSearchResult, type IntegrationTriggerEvent, type IntegrationTriggerSubscription, type InvokeWithCapabilityRequest, type IssueCapabilityRequest, type IssuedIntegrationCapability, type McpCatalog, type McpCatalogTool, type McpToolDefinition, type MicrosoftCalendarOptions, type NormalizedIntegrationResult, type NotionDatabaseOptions, type OAuthFlowStore, type OAuthTokens, type OpenApiDocument, type OpenApiOperation, type ParsedStripeSignatureHeader, type PendingOAuthFlow, type RateLimitSpec, type RefreshInput, type ResolvedDataSource, ResourceContention, type SecretRef, type SlackOptions, type SlackVerifyOptions, type StartAuthRequest, type StartAuthResult, type StartOAuthInput, type StartOAuthOutput, StaticIntegrationPolicyEngine, type StaticIntegrationPolicyOptions, type StripeVerifyOptions, type TwilioVerifyOptions, _resetPendingFlowsForTests, assertValidConnectorManifest, buildApprovalRequest, buildIntegrationInvocationEnvelope, buildIntegrationToolCatalog, consumePendingFlow, createConnectorAdapterProvider, createDefaultIntegrationPolicyEngine, createHttpIntegrationProvider, createMockIntegrationProvider, exchangeAuthorizationCode, firstHeader, googleCalendar, googleSheets, hubspot, importGraphqlConnector, importMcpConnector, importOpenApiConnector, integrationToolName, invocationRequestFromEnvelope, manifestToConnector, microsoftCalendar, normalizeIntegrationResult, notionDatabase, parseIntegrationToolName, parseStripeSignatureHeader, redactApprovalRequest, redactCapability, redactInvocationEnvelope, refreshAccessToken, sanitizeConnection, searchIntegrationTools, signCapability, slack, slackEventsConnector, startOAuthFlow, stripePackConnector, stripeWebhookReceiverConnector, toMcpTools, twilioSmsConnector, validateConnectorManifest, validateIntegrationInvocationEnvelope, verifyCapabilityToken, verifyHmacSignature, verifySlackSignature, verifyStripeSignature, verifyTwilioSignature, webhookConnector };
package/dist/index.js CHANGED
@@ -2757,10 +2757,10 @@ function tokenize(value) {
2757
2757
  return value.toLowerCase().split(/[^a-z0-9]+/g).map((part) => part.trim()).filter(Boolean);
2758
2758
  }
2759
2759
  function encodeToolPart(value) {
2760
- return Buffer.from(value, "utf8").toString("base64url");
2760
+ return Buffer.from(value, "utf8").toString("base64url").replace(/_/g, ".");
2761
2761
  }
2762
2762
  function decodeToolPart(value) {
2763
- return Buffer.from(value, "base64url").toString("utf8");
2763
+ return Buffer.from(value.replace(/\./g, "_"), "base64url").toString("utf8");
2764
2764
  }
2765
2765
  function unique(values) {
2766
2766
  return [...new Set(values)];
@@ -2869,7 +2869,7 @@ function redactUnknown(value) {
2869
2869
  // src/sandbox.ts
2870
2870
  function buildIntegrationInvocationEnvelope(input) {
2871
2871
  const parsed = parseIntegrationToolName(input.toolName);
2872
- return {
2872
+ const envelope = {
2873
2873
  kind: "integration.invocation",
2874
2874
  capabilityToken: input.capabilityToken,
2875
2875
  toolName: input.toolName,
@@ -2879,8 +2879,11 @@ function buildIntegrationInvocationEnvelope(input) {
2879
2879
  dryRun: input.dryRun,
2880
2880
  metadata: input.metadata
2881
2881
  };
2882
+ validateIntegrationInvocationEnvelope(envelope);
2883
+ return envelope;
2882
2884
  }
2883
2885
  function invocationRequestFromEnvelope(envelope) {
2886
+ validateIntegrationInvocationEnvelope(envelope);
2884
2887
  return {
2885
2888
  action: envelope.action,
2886
2889
  input: envelope.input,
@@ -2889,6 +2892,34 @@ function invocationRequestFromEnvelope(envelope) {
2889
2892
  metadata: envelope.metadata
2890
2893
  };
2891
2894
  }
2895
+ function validateIntegrationInvocationEnvelope(envelope, options = {}) {
2896
+ if (!envelope || typeof envelope !== "object") throw new Error("Integration invocation envelope is required.");
2897
+ if (envelope.kind !== "integration.invocation") throw new Error("Invalid integration invocation envelope kind.");
2898
+ if (!isNonEmptyString(envelope.capabilityToken)) throw new Error("Integration invocation envelope is missing capabilityToken.");
2899
+ if (!isNonEmptyString(envelope.toolName)) throw new Error("Integration invocation envelope is missing toolName.");
2900
+ if (!isNonEmptyString(envelope.action)) throw new Error("Integration invocation envelope is missing action.");
2901
+ if (!isNonEmptyString(envelope.idempotencyKey)) throw new Error("Integration invocation envelope is missing idempotencyKey.");
2902
+ if (envelope.metadata !== void 0 && !isPlainRecord(envelope.metadata)) {
2903
+ throw new Error("Integration invocation envelope metadata must be an object.");
2904
+ }
2905
+ const parsed = parseIntegrationToolName(envelope.toolName);
2906
+ if (parsed.actionId !== envelope.action) {
2907
+ throw new Error(`Integration invocation action ${envelope.action} does not match tool ${parsed.actionId}.`);
2908
+ }
2909
+ const inputBytes = Buffer.byteLength(JSON.stringify(envelope.input ?? null), "utf8");
2910
+ const maxInputBytes = options.maxInputBytes ?? 256 * 1024;
2911
+ if (inputBytes > maxInputBytes) {
2912
+ throw new Error(`Integration invocation input exceeds ${maxInputBytes} bytes.`);
2913
+ }
2914
+ if (options.requireKnownTool || options.connectors) {
2915
+ if (!options.connectors) throw new Error("connectors are required when requireKnownTool is true.");
2916
+ const connector = options.connectors.find(
2917
+ (candidate) => candidate.providerId === parsed.providerId && candidate.id === parsed.connectorId
2918
+ );
2919
+ const action = connector?.actions.find((candidate) => candidate.id === parsed.actionId);
2920
+ if (!connector || !action) throw new Error(`Unknown integration tool ${envelope.toolName}.`);
2921
+ }
2922
+ }
2892
2923
  function redactInvocationEnvelope(envelope) {
2893
2924
  return {
2894
2925
  ...envelope,
@@ -2940,6 +2971,12 @@ function redactUnknown2(value) {
2940
2971
  }
2941
2972
  return out;
2942
2973
  }
2974
+ function isNonEmptyString(value) {
2975
+ return typeof value === "string" && value.trim().length > 0;
2976
+ }
2977
+ function isPlainRecord(value) {
2978
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2979
+ }
2943
2980
 
2944
2981
  // src/adapter-provider.ts
2945
2982
  function createConnectorAdapterProvider(options) {
@@ -3566,6 +3603,7 @@ export {
3566
3603
  toMcpTools,
3567
3604
  twilioSmsConnector,
3568
3605
  validateConnectorManifest,
3606
+ validateIntegrationInvocationEnvelope,
3569
3607
  verifyCapabilityToken,
3570
3608
  verifyHmacSignature,
3571
3609
  verifySlackSignature,