@axonflow/sdk 4.1.0 → 4.3.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/adapters/langgraph.d.ts +284 -0
  3. package/dist/cjs/adapters/langgraph.d.ts.map +1 -0
  4. package/dist/cjs/adapters/langgraph.js +364 -0
  5. package/dist/cjs/adapters/langgraph.js.map +1 -0
  6. package/dist/cjs/client.d.ts +148 -2
  7. package/dist/cjs/client.d.ts.map +1 -1
  8. package/dist/cjs/client.js +263 -2
  9. package/dist/cjs/client.js.map +1 -1
  10. package/dist/cjs/index.d.ts +4 -1
  11. package/dist/cjs/index.d.ts.map +1 -1
  12. package/dist/cjs/index.js +6 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/telemetry.js +1 -1
  15. package/dist/cjs/telemetry.js.map +1 -1
  16. package/dist/cjs/types/gateway.d.ts +65 -0
  17. package/dist/cjs/types/gateway.d.ts.map +1 -1
  18. package/dist/cjs/types/index.d.ts +1 -0
  19. package/dist/cjs/types/index.d.ts.map +1 -1
  20. package/dist/cjs/types/index.js +1 -0
  21. package/dist/cjs/types/index.js.map +1 -1
  22. package/dist/cjs/types/simulation.d.ts +79 -0
  23. package/dist/cjs/types/simulation.d.ts.map +1 -0
  24. package/dist/cjs/types/simulation.js +9 -0
  25. package/dist/cjs/types/simulation.js.map +1 -0
  26. package/dist/cjs/version.d.ts +1 -1
  27. package/dist/cjs/version.js +1 -1
  28. package/dist/esm/adapters/langgraph.d.ts +284 -0
  29. package/dist/esm/adapters/langgraph.d.ts.map +1 -0
  30. package/dist/esm/adapters/langgraph.js +358 -0
  31. package/dist/esm/adapters/langgraph.js.map +1 -0
  32. package/dist/esm/client.d.ts +148 -2
  33. package/dist/esm/client.d.ts.map +1 -1
  34. package/dist/esm/client.js +263 -2
  35. package/dist/esm/client.js.map +1 -1
  36. package/dist/esm/index.d.ts +4 -1
  37. package/dist/esm/index.d.ts.map +1 -1
  38. package/dist/esm/index.js +2 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/telemetry.js +1 -1
  41. package/dist/esm/telemetry.js.map +1 -1
  42. package/dist/esm/types/gateway.d.ts +65 -0
  43. package/dist/esm/types/gateway.d.ts.map +1 -1
  44. package/dist/esm/types/index.d.ts +1 -0
  45. package/dist/esm/types/index.d.ts.map +1 -1
  46. package/dist/esm/types/index.js +1 -0
  47. package/dist/esm/types/index.js.map +1 -1
  48. package/dist/esm/types/simulation.d.ts +79 -0
  49. package/dist/esm/types/simulation.d.ts.map +1 -0
  50. package/dist/esm/types/simulation.js +8 -0
  51. package/dist/esm/types/simulation.js.map +1 -0
  52. package/dist/esm/version.d.ts +1 -1
  53. package/dist/esm/version.js +1 -1
  54. package/package.json +1 -1
@@ -153,12 +153,12 @@ export class AxonFlow {
153
153
  * });
154
154
  * ```
155
155
  *
156
- * See: https://docs.getaxonflow.com/sdk/gateway-mode
156
+ * See: https://docs.getaxonflow.com/docs/sdk/gateway-mode
157
157
  */
158
158
  async protect(aiCall) {
159
159
  console.warn('[AxonFlow] protect() is deprecated and will be removed in a future version. ' +
160
160
  'Use Gateway Mode (getPolicyApprovedContext + auditLLMCall) or Proxy Mode (proxyLLMCall) instead. ' +
161
- 'See: https://docs.getaxonflow.com/sdk/gateway-mode');
161
+ 'See: https://docs.getaxonflow.com/docs/sdk/gateway-mode');
162
162
  try {
163
163
  // Extract request details from the AI call
164
164
  const aiRequest = await this.extractRequest(aiCall);
@@ -1495,6 +1495,267 @@ export class AxonFlow {
1495
1495
  };
1496
1496
  }
1497
1497
  // ============================================================================
1498
+ // Circuit Breaker Observability Methods
1499
+ // ============================================================================
1500
+ /**
1501
+ * Get all active circuit breaker circuits.
1502
+ *
1503
+ * Returns the current state of all open/half-open circuits across
1504
+ * the platform, including emergency stop status.
1505
+ *
1506
+ * @returns Promise resolving to circuit breaker status
1507
+ *
1508
+ * @example
1509
+ * ```typescript
1510
+ * const status = await axonflow.getCircuitBreakerStatus();
1511
+ * console.log(`Active circuits: ${status.count}`);
1512
+ * console.log(`Emergency stop: ${status.emergencyStopActive}`);
1513
+ * for (const circuit of status.activeCircuits) {
1514
+ * console.log(`${circuit.scope}/${circuit.scopeId}: ${circuit.state}`);
1515
+ * }
1516
+ * ```
1517
+ */
1518
+ async getCircuitBreakerStatus() {
1519
+ const response = await this.orchestratorRequest('GET', '/api/v1/circuit-breaker/status');
1520
+ const data = response.data;
1521
+ return {
1522
+ activeCircuits: (data.active_circuits || []).map(c => ({
1523
+ id: c.id,
1524
+ scope: c.scope,
1525
+ scopeId: c.scope_id,
1526
+ orgId: c.org_id,
1527
+ state: c.state,
1528
+ tripReason: c.trip_reason,
1529
+ trippedBy: c.tripped_by,
1530
+ trippedAt: c.tripped_at,
1531
+ expiresAt: c.expires_at,
1532
+ errorCount: c.error_count,
1533
+ violationCount: c.violation_count,
1534
+ })),
1535
+ count: data.count,
1536
+ emergencyStopActive: data.emergency_stop_active,
1537
+ };
1538
+ }
1539
+ /**
1540
+ * Get circuit breaker history for audit trail.
1541
+ *
1542
+ * Returns historical circuit breaker events including trips, resets,
1543
+ * and manual interventions. Useful for compliance reporting.
1544
+ *
1545
+ * @param limit - Maximum number of history entries to return
1546
+ * @returns Promise resolving to circuit breaker history
1547
+ *
1548
+ * @example
1549
+ * ```typescript
1550
+ * const history = await axonflow.getCircuitBreakerHistory(50);
1551
+ * for (const entry of history.history) {
1552
+ * console.log(`${entry.trippedAt}: ${entry.scope}/${entry.scopeId} - ${entry.state}`);
1553
+ * }
1554
+ * ```
1555
+ */
1556
+ async getCircuitBreakerHistory(limit) {
1557
+ const params = new URLSearchParams();
1558
+ if (limit !== undefined)
1559
+ params.set('limit', String(limit));
1560
+ const queryString = params.toString();
1561
+ const path = `/api/v1/circuit-breaker/history${queryString ? `?${queryString}` : ''}`;
1562
+ const response = await this.orchestratorRequest('GET', path);
1563
+ const data = response.data;
1564
+ return {
1565
+ history: (data.history || []).map(h => ({
1566
+ id: h.id,
1567
+ orgId: h.org_id,
1568
+ scope: h.scope,
1569
+ scopeId: h.scope_id,
1570
+ state: h.state,
1571
+ tripReason: h.trip_reason,
1572
+ trippedBy: h.tripped_by,
1573
+ trippedByEmail: h.tripped_by_email,
1574
+ tripComment: h.trip_comment,
1575
+ trippedAt: h.tripped_at,
1576
+ expiresAt: h.expires_at,
1577
+ resetBy: h.reset_by,
1578
+ resetAt: h.reset_at,
1579
+ errorCount: h.error_count,
1580
+ violationCount: h.violation_count,
1581
+ })),
1582
+ count: data.count,
1583
+ };
1584
+ }
1585
+ /**
1586
+ * Get circuit breaker config (global or tenant-specific).
1587
+ *
1588
+ * Returns the effective circuit breaker configuration, including
1589
+ * any tenant-specific overrides.
1590
+ *
1591
+ * @param tenantId - Optional tenant ID to get tenant-specific config
1592
+ * @returns Promise resolving to circuit breaker config
1593
+ *
1594
+ * @example
1595
+ * ```typescript
1596
+ * // Get global config
1597
+ * const globalConfig = await axonflow.getCircuitBreakerConfig();
1598
+ * console.log(`Error threshold: ${globalConfig.errorThreshold}`);
1599
+ *
1600
+ * // Get tenant-specific config
1601
+ * const tenantConfig = await axonflow.getCircuitBreakerConfig('tenant-123');
1602
+ * ```
1603
+ */
1604
+ async getCircuitBreakerConfig(tenantId) {
1605
+ const params = new URLSearchParams();
1606
+ if (tenantId !== undefined)
1607
+ params.set('tenant_id', tenantId);
1608
+ const queryString = params.toString();
1609
+ const path = `/api/v1/circuit-breaker/config${queryString ? `?${queryString}` : ''}`;
1610
+ const response = await this.orchestratorRequest('GET', path);
1611
+ const data = response.data;
1612
+ return {
1613
+ source: data.source,
1614
+ errorThreshold: data.error_threshold,
1615
+ violationThreshold: data.violation_threshold,
1616
+ windowSeconds: data.window_seconds,
1617
+ defaultTimeoutSeconds: data.default_timeout_seconds,
1618
+ maxTimeoutSeconds: data.max_timeout_seconds,
1619
+ enableAutoRecovery: data.enable_auto_recovery,
1620
+ tenantId: data.tenant_id,
1621
+ overrides: data.overrides,
1622
+ };
1623
+ }
1624
+ /**
1625
+ * Update per-tenant circuit breaker config.
1626
+ *
1627
+ * Allows customizing circuit breaker thresholds for a specific tenant.
1628
+ * Only provided fields will be updated; others retain their current values.
1629
+ *
1630
+ * @param config - Configuration update with tenant ID and fields to change
1631
+ * @returns Promise resolving to confirmation with tenant ID and message
1632
+ *
1633
+ * @example
1634
+ * ```typescript
1635
+ * const result = await axonflow.updateCircuitBreakerConfig({
1636
+ * tenantId: 'tenant-123',
1637
+ * errorThreshold: 10,
1638
+ * windowSeconds: 120,
1639
+ * });
1640
+ * console.log(result.message); // "config updated"
1641
+ * ```
1642
+ */
1643
+ async updateCircuitBreakerConfig(config) {
1644
+ if (!config.tenantId) {
1645
+ throw new ConfigurationError('tenantId is required');
1646
+ }
1647
+ const body = {
1648
+ tenant_id: config.tenantId,
1649
+ };
1650
+ if (config.errorThreshold !== undefined)
1651
+ body.error_threshold = config.errorThreshold;
1652
+ if (config.violationThreshold !== undefined)
1653
+ body.violation_threshold = config.violationThreshold;
1654
+ if (config.windowSeconds !== undefined)
1655
+ body.window_seconds = config.windowSeconds;
1656
+ if (config.defaultTimeoutSeconds !== undefined)
1657
+ body.default_timeout_seconds = config.defaultTimeoutSeconds;
1658
+ if (config.maxTimeoutSeconds !== undefined)
1659
+ body.max_timeout_seconds = config.maxTimeoutSeconds;
1660
+ if (config.enableAutoRecovery !== undefined)
1661
+ body.enable_auto_recovery = config.enableAutoRecovery;
1662
+ const response = await this.orchestratorRequest('PUT', '/api/v1/circuit-breaker/config', body);
1663
+ return {
1664
+ tenantId: response.data.tenant_id,
1665
+ message: response.data.message,
1666
+ };
1667
+ }
1668
+ // ============================================================================
1669
+ // Policy Simulation Methods (Evaluation Tier+)
1670
+ // ============================================================================
1671
+ /**
1672
+ * Simulate policy evaluation against a hypothetical request.
1673
+ *
1674
+ * Dry-run policy evaluation that shows which policies would match and what
1675
+ * actions would be taken, without affecting live traffic. Available on
1676
+ * Evaluation tier and above.
1677
+ *
1678
+ * @param request - The simulated request to evaluate against policies
1679
+ * @returns Promise resolving to simulation results
1680
+ *
1681
+ * @example
1682
+ * ```typescript
1683
+ * const result = await axonflow.simulatePolicies({
1684
+ * query: 'Show me all customer SSNs',
1685
+ * request_type: 'chat',
1686
+ * user: { role: 'analyst', department: 'support' },
1687
+ * });
1688
+ * console.log(`Allowed: ${result.allowed}`);
1689
+ * console.log(`Policies matched: ${result.applied_policies.join(', ')}`);
1690
+ * console.log(`Risk score: ${result.risk_score}`);
1691
+ * ```
1692
+ */
1693
+ async simulatePolicies(request) {
1694
+ const body = { query: request.query };
1695
+ if (request.request_type !== undefined)
1696
+ body.request_type = request.request_type;
1697
+ if (request.user !== undefined)
1698
+ body.user = request.user;
1699
+ if (request.client !== undefined)
1700
+ body.client = request.client;
1701
+ if (request.context !== undefined)
1702
+ body.context = request.context;
1703
+ return this.orchestratorRequest('POST', '/api/v1/policies/simulate', body);
1704
+ }
1705
+ /**
1706
+ * Generate a policy impact report for a specific policy against sample inputs.
1707
+ *
1708
+ * Tests a policy against multiple sample inputs to understand its match rate,
1709
+ * block rate, and per-input behavior. Useful for tuning policy configurations
1710
+ * before deploying to production.
1711
+ *
1712
+ * @param policyId - The ID of the policy to evaluate
1713
+ * @param inputs - Array of sample inputs to test against the policy
1714
+ * @returns Promise resolving to the impact report
1715
+ *
1716
+ * @example
1717
+ * ```typescript
1718
+ * const report = await axonflow.getPolicyImpactReport('policy-123', [
1719
+ * { query: 'Show me all customer SSNs', request_type: 'chat' },
1720
+ * { query: 'What is the weather today?', request_type: 'chat' },
1721
+ * { query: 'Delete all user records', request_type: 'chat' },
1722
+ * ]);
1723
+ * console.log(`Match rate: ${report.match_rate}`);
1724
+ * console.log(`Block rate: ${report.block_rate}`);
1725
+ * ```
1726
+ */
1727
+ async getPolicyImpactReport(policyId, inputs) {
1728
+ return this.orchestratorRequest('POST', '/api/v1/policies/impact-report', {
1729
+ policy_id: policyId,
1730
+ inputs,
1731
+ });
1732
+ }
1733
+ /**
1734
+ * Detect conflicts between policies.
1735
+ *
1736
+ * Analyzes policies for overlapping rules, contradictory actions, or
1737
+ * other conflict patterns. Optionally scoped to a specific policy.
1738
+ *
1739
+ * @param policyId - Optional policy ID to check conflicts for a specific policy
1740
+ * @returns Promise resolving to detected conflicts
1741
+ *
1742
+ * @example
1743
+ * ```typescript
1744
+ * // Check all policies for conflicts
1745
+ * const allConflicts = await axonflow.detectPolicyConflicts();
1746
+ * console.log(`Found ${allConflicts.conflict_count} conflicts`);
1747
+ *
1748
+ * // Check conflicts for a specific policy
1749
+ * const policyConflicts = await axonflow.detectPolicyConflicts('policy-123');
1750
+ * ```
1751
+ */
1752
+ async detectPolicyConflicts(policyId) {
1753
+ const body = {};
1754
+ if (policyId !== undefined)
1755
+ body.policy_id = policyId;
1756
+ return this.orchestratorRequest('POST', '/api/v1/policies/conflicts', body);
1757
+ }
1758
+ // ============================================================================
1498
1759
  // Audit Log Read Methods
1499
1760
  // ============================================================================
1500
1761
  /**