@fulcrum-governance/sdk 0.1.0 → 0.1.3
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/CHANGELOG.md +42 -1
- package/README.md +299 -6
- package/dist/__tests__/clients.test.d.ts +1 -0
- package/dist/__tests__/clients.test.js +847 -0
- package/dist/clients/agent.d.ts +70 -0
- package/dist/clients/agent.js +127 -0
- package/dist/clients/approval.d.ts +67 -0
- package/dist/clients/approval.js +103 -0
- package/dist/clients/budget.d.ts +221 -0
- package/dist/clients/budget.js +181 -0
- package/dist/clients/checkpoint.d.ts +191 -0
- package/dist/clients/checkpoint.js +195 -0
- package/dist/clients/envelope.d.ts +73 -0
- package/dist/clients/envelope.js +95 -0
- package/dist/clients/eventstore.d.ts +87 -0
- package/dist/clients/eventstore.js +113 -0
- package/dist/clients/index.d.ts +15 -0
- package/dist/clients/index.js +35 -0
- package/dist/clients/metrics.d.ts +126 -0
- package/dist/clients/metrics.js +162 -0
- package/dist/clients/policy.d.ts +83 -0
- package/dist/clients/policy.js +102 -0
- package/dist/clients/tenant.d.ts +66 -0
- package/dist/clients/tenant.js +92 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -3
- package/dist/instrumentation/__tests__/autoGovern.test.d.ts +6 -0
- package/dist/instrumentation/__tests__/autoGovern.test.js +416 -0
- package/dist/instrumentation/__tests__/evaluator.test.d.ts +6 -0
- package/dist/instrumentation/__tests__/evaluator.test.js +712 -0
- package/dist/instrumentation/autoGovern.d.ts +57 -0
- package/dist/instrumentation/autoGovern.js +319 -0
- package/dist/instrumentation/evaluator.d.ts +50 -0
- package/dist/instrumentation/evaluator.js +218 -0
- package/dist/instrumentation/index.d.ts +28 -0
- package/dist/instrumentation/index.js +34 -0
- package/dist/instrumentation/types.d.ts +105 -0
- package/dist/instrumentation/types.js +20 -0
- package/package.json +5 -4
- package/proto/fulcrum/agent/v1/agent_service.proto +170 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,8 +9,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
- Comprehensive test suite with >90% coverage target
|
|
12
|
+
|
|
13
|
+
## [0.1.3] - 2026-01-22
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- AgentClient for agent management operations
|
|
17
|
+
- Support for creating, listing, updating, and deleting agents
|
|
18
|
+
- Agent filtering by status, environment, and team
|
|
19
|
+
- Full TypeScript type definitions for all agent operations
|
|
20
|
+
- Pagination support for agent listing with page tokens
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Enhanced SDK with complete agent management capabilities
|
|
24
|
+
- Improved documentation with agent client usage examples
|
|
25
|
+
|
|
26
|
+
## [0.1.2] - 2026-01-21
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- EventStoreClient for event management operations
|
|
30
|
+
- EnvelopeClient for execution envelope lifecycle management
|
|
31
|
+
- TenantClient for API key and tenant management
|
|
32
|
+
- Support for querying events by execution, envelope, workflow, and type
|
|
33
|
+
- Batch event publishing capability
|
|
34
|
+
- Envelope status tracking and updates
|
|
35
|
+
- API key creation, listing, and revocation
|
|
36
|
+
- Full TypeScript type definitions for all new services
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
- Expanded REST client coverage from 30% to 100% of core services
|
|
40
|
+
- Enhanced type safety across all new service clients
|
|
41
|
+
- Improved SDK documentation with comprehensive examples
|
|
42
|
+
|
|
43
|
+
## [0.1.1] - 2026-01-06
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
- Updated package metadata and documentation
|
|
12
47
|
- Improved error messages and stack traces
|
|
13
48
|
|
|
49
|
+
### Fixed
|
|
50
|
+
- Minor bug fixes and improvements
|
|
51
|
+
|
|
14
52
|
## [0.1.0] - 2026-01-01
|
|
15
53
|
|
|
16
54
|
### Added
|
|
@@ -46,6 +84,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
46
84
|
- Basic gRPC-web connectivity
|
|
47
85
|
- Policy evaluation stub
|
|
48
86
|
|
|
49
|
-
[Unreleased]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.1.
|
|
87
|
+
[Unreleased]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.1.3...HEAD
|
|
88
|
+
[0.1.3]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.1.2...sdk/typescript/v0.1.3
|
|
89
|
+
[0.1.2]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.1.1...sdk/typescript/v0.1.2
|
|
90
|
+
[0.1.1]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.1.0...sdk/typescript/v0.1.1
|
|
50
91
|
[0.1.0]: https://github.com/fulcrum-dev/fulcrum/compare/sdk/typescript/v0.0.1...sdk/typescript/v0.1.0
|
|
51
92
|
[0.0.1]: https://github.com/fulcrum-dev/fulcrum/releases/tag/sdk/typescript/v0.0.1
|
package/README.md
CHANGED
|
@@ -357,20 +357,313 @@ interface Checkpoint {
|
|
|
357
357
|
}
|
|
358
358
|
```
|
|
359
359
|
|
|
360
|
+
## REST Clients
|
|
361
|
+
|
|
362
|
+
The SDK includes REST-based clients for managing Fulcrum resources through the Dashboard API. These clients are ideal for administrative tasks, dashboards, and browser environments.
|
|
363
|
+
|
|
364
|
+
### PolicyClient
|
|
365
|
+
|
|
366
|
+
Manage governance policies programmatically:
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
import { PolicyClient } from '@fulcrum-governance/sdk';
|
|
370
|
+
|
|
371
|
+
const policyClient = new PolicyClient({
|
|
372
|
+
baseUrl: 'https://your-fulcrum-dashboard.com',
|
|
373
|
+
apiKey: 'your-api-key',
|
|
374
|
+
timeoutMs: 5000 // optional, default: 5000
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// List all policies
|
|
378
|
+
const policies = await policyClient.list();
|
|
379
|
+
|
|
380
|
+
// List with filters
|
|
381
|
+
const activePolicies = await policyClient.list({
|
|
382
|
+
status: 'active',
|
|
383
|
+
priority: 'high'
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// Get a specific policy
|
|
387
|
+
const policy = await policyClient.get('policy-id');
|
|
388
|
+
|
|
389
|
+
// Create a new policy
|
|
390
|
+
const newPolicy = await policyClient.create({
|
|
391
|
+
name: 'No PII in Responses',
|
|
392
|
+
description: 'Prevents sensitive data exposure',
|
|
393
|
+
rules: [{ type: 'semantic', pattern: 'pii_detection' }],
|
|
394
|
+
priority: 1,
|
|
395
|
+
enabled: true
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// Update a policy
|
|
399
|
+
const updated = await policyClient.update('policy-id', {
|
|
400
|
+
name: 'Updated Policy Name',
|
|
401
|
+
priority: 2
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Enable/disable policies
|
|
405
|
+
await policyClient.setEnabled('policy-id', false);
|
|
406
|
+
|
|
407
|
+
// Delete a policy
|
|
408
|
+
await policyClient.delete('policy-id');
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### ApprovalClient
|
|
412
|
+
|
|
413
|
+
Manage human-in-the-loop approval workflows:
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import { ApprovalClient } from '@fulcrum-governance/sdk';
|
|
417
|
+
|
|
418
|
+
const approvalClient = new ApprovalClient({
|
|
419
|
+
baseUrl: 'https://your-fulcrum-dashboard.com',
|
|
420
|
+
apiKey: 'your-api-key'
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// List all pending approvals
|
|
424
|
+
const pending = await approvalClient.listPending();
|
|
425
|
+
|
|
426
|
+
// List with filters
|
|
427
|
+
const approvals = await approvalClient.list({
|
|
428
|
+
status: 'pending',
|
|
429
|
+
workflow_id: 'customer-support-bot'
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// Get approval details
|
|
433
|
+
const approval = await approvalClient.get('approval-id');
|
|
434
|
+
|
|
435
|
+
// Approve a request
|
|
436
|
+
await approvalClient.approve('approval-id', 'Looks safe to proceed');
|
|
437
|
+
|
|
438
|
+
// Deny a request
|
|
439
|
+
await approvalClient.deny('approval-id', 'Contains sensitive information');
|
|
440
|
+
|
|
441
|
+
// Generic decision method
|
|
442
|
+
await approvalClient.decide('approval-id', {
|
|
443
|
+
decision: 'approved', // or 'denied'
|
|
444
|
+
comment: 'Reviewed and approved'
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### BudgetClient
|
|
449
|
+
|
|
450
|
+
Manage AI spending budgets and limits:
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
import { BudgetClient } from '@fulcrum-governance/sdk';
|
|
454
|
+
|
|
455
|
+
const budgetClient = new BudgetClient({
|
|
456
|
+
baseUrl: 'https://your-fulcrum-dashboard.com',
|
|
457
|
+
apiKey: 'your-api-key'
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// List all budgets with summary
|
|
461
|
+
const { budgets, summary } = await budgetClient.list();
|
|
462
|
+
console.log(`Total budgets: ${summary.total}`);
|
|
463
|
+
console.log(`Active: ${summary.active}, Exceeded: ${summary.exceeded}`);
|
|
464
|
+
|
|
465
|
+
// Filter by scope or status
|
|
466
|
+
const tenantBudgets = await budgetClient.listBudgets({ scope: 'TENANT' });
|
|
467
|
+
const exceededBudgets = await budgetClient.getExceeded();
|
|
468
|
+
const warningBudgets = await budgetClient.getWarnings();
|
|
469
|
+
|
|
470
|
+
// Get a specific budget
|
|
471
|
+
const budget = await budgetClient.get('budget-id');
|
|
472
|
+
|
|
473
|
+
// Create a new budget
|
|
474
|
+
const newBudget = await budgetClient.create({
|
|
475
|
+
name: 'Marketing Team Monthly',
|
|
476
|
+
scope: 'TENANT', // GLOBAL, TENANT, WORKFLOW, MODEL
|
|
477
|
+
scope_id: 'tenant-123',
|
|
478
|
+
limit_amount: 1000, // in dollars
|
|
479
|
+
period: 'MONTHLY', // DAILY, WEEKLY, MONTHLY, QUARTERLY
|
|
480
|
+
action: 'SOFT_LIMIT', // WARN, SOFT_LIMIT, HARD_LIMIT
|
|
481
|
+
alert_thresholds: [50, 75, 90]
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// Update budget
|
|
485
|
+
await budgetClient.update('budget-id', {
|
|
486
|
+
limit_amount: 1500,
|
|
487
|
+
alert_thresholds: [60, 80, 95]
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// Helper methods
|
|
491
|
+
const percentage = budgetClient.calculatePercentage(budget);
|
|
492
|
+
const isNearLimit = budgetClient.isAtThreshold(budget, 80);
|
|
493
|
+
|
|
494
|
+
// Delete a budget
|
|
495
|
+
await budgetClient.delete('budget-id');
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### MetricsClient
|
|
499
|
+
|
|
500
|
+
Access platform metrics and audit logs:
|
|
501
|
+
|
|
502
|
+
```typescript
|
|
503
|
+
import { MetricsClient } from '@fulcrum-governance/sdk';
|
|
504
|
+
|
|
505
|
+
const metricsClient = new MetricsClient({
|
|
506
|
+
baseUrl: 'https://your-fulcrum-dashboard.com',
|
|
507
|
+
apiKey: 'your-api-key' // optional for public metrics
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
// Public metrics (no auth required)
|
|
511
|
+
const metrics = await metricsClient.getPublicMetrics();
|
|
512
|
+
console.log(`Policies evaluated (24h): ${metrics.policiesEvaluated24h}`);
|
|
513
|
+
console.log(`Avg latency: ${metrics.avgLatencyMs}ms`);
|
|
514
|
+
console.log(`Blocked requests: ${metrics.blockedRequests24h}`);
|
|
515
|
+
|
|
516
|
+
// Cognitive layer metrics
|
|
517
|
+
const cognitive = await metricsClient.getCognitiveMetrics();
|
|
518
|
+
console.log(`Semantic Judge violations: ${cognitive.semanticJudgeViolations}`);
|
|
519
|
+
console.log(`Oracle savings: $${cognitive.oracleSavings}`);
|
|
520
|
+
|
|
521
|
+
// Audit logs (auth required)
|
|
522
|
+
const { logs, pagination, actors } = await metricsClient.getAuditLogs({
|
|
523
|
+
resource_type: 'Policy',
|
|
524
|
+
start_date: '2026-01-01',
|
|
525
|
+
end_date: '2026-01-31',
|
|
526
|
+
page: 1,
|
|
527
|
+
page_size: 50
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// Convenience methods for audit logs
|
|
531
|
+
const policyLogs = await metricsClient.getLogsByResourceType('Policy');
|
|
532
|
+
const userLogs = await metricsClient.getLogsByUser('user-id');
|
|
533
|
+
const recentLogs = await metricsClient.getLogsByDateRange(
|
|
534
|
+
new Date('2026-01-01'),
|
|
535
|
+
new Date('2026-01-31')
|
|
536
|
+
);
|
|
537
|
+
const searchResults = await metricsClient.searchAuditLogs('budget exceeded');
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### REST Client Types
|
|
541
|
+
|
|
542
|
+
```typescript
|
|
543
|
+
// Policy types
|
|
544
|
+
interface Policy {
|
|
545
|
+
id: string;
|
|
546
|
+
org_id: string;
|
|
547
|
+
name: string;
|
|
548
|
+
description: string;
|
|
549
|
+
rules: PolicyRule[];
|
|
550
|
+
priority: number;
|
|
551
|
+
enabled: boolean;
|
|
552
|
+
status: 'active' | 'inactive' | 'draft';
|
|
553
|
+
created_at: string;
|
|
554
|
+
updated_at: string;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Approval types
|
|
558
|
+
interface Approval {
|
|
559
|
+
id: string;
|
|
560
|
+
envelope_id: string;
|
|
561
|
+
workflow_id: string;
|
|
562
|
+
action_name: string;
|
|
563
|
+
input_text: string;
|
|
564
|
+
status: 'pending' | 'approved' | 'denied' | 'expired';
|
|
565
|
+
requested_at: string;
|
|
566
|
+
decided_at?: string;
|
|
567
|
+
decided_by?: string;
|
|
568
|
+
comment?: string;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Budget types
|
|
572
|
+
type BudgetScope = 'GLOBAL' | 'TENANT' | 'WORKFLOW' | 'MODEL';
|
|
573
|
+
type BudgetPeriod = 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'QUARTERLY';
|
|
574
|
+
type BudgetAction = 'WARN' | 'SOFT_LIMIT' | 'HARD_LIMIT';
|
|
575
|
+
type BudgetStatus = 'active' | 'warning' | 'exceeded' | 'disabled';
|
|
576
|
+
|
|
577
|
+
interface Budget {
|
|
578
|
+
id: string;
|
|
579
|
+
name: string;
|
|
580
|
+
scope: BudgetScope;
|
|
581
|
+
scope_id: string | null;
|
|
582
|
+
limit_amount: number;
|
|
583
|
+
current_spend: number;
|
|
584
|
+
period: BudgetPeriod;
|
|
585
|
+
action: BudgetAction;
|
|
586
|
+
status: BudgetStatus;
|
|
587
|
+
percentage: number;
|
|
588
|
+
alert_thresholds: number[];
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Metrics types
|
|
592
|
+
interface PublicMetrics {
|
|
593
|
+
lastUpdated: string;
|
|
594
|
+
policiesEvaluated24h: number;
|
|
595
|
+
avgLatencyMs: number;
|
|
596
|
+
budgetAlerts24h: number;
|
|
597
|
+
activeTenants: number;
|
|
598
|
+
blockedRequests24h: number;
|
|
599
|
+
cognitiveLayer: CognitiveLayerMetrics;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
interface CognitiveLayerMetrics {
|
|
603
|
+
semanticJudgeRequests: number;
|
|
604
|
+
semanticJudgeViolations: number;
|
|
605
|
+
oraclePredictions: number;
|
|
606
|
+
oracleSavings: number;
|
|
607
|
+
immunePoliciesGenerated: number;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
type ResourceType = 'User' | 'Policy' | 'Budget' | 'APIKey' | 'Workflow' | 'Envelope' | 'Approval';
|
|
611
|
+
|
|
612
|
+
interface AuditLogEntry {
|
|
613
|
+
id: string;
|
|
614
|
+
timestamp: string;
|
|
615
|
+
actor_id: string;
|
|
616
|
+
actor_email: string;
|
|
617
|
+
action: string;
|
|
618
|
+
resource_type: ResourceType;
|
|
619
|
+
resource_id?: string;
|
|
620
|
+
resource_name?: string;
|
|
621
|
+
status: 'success' | 'failure';
|
|
622
|
+
changes?: Record<string, { old: unknown; new: unknown }>;
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Error Handling for REST Clients
|
|
627
|
+
|
|
628
|
+
Each REST client has its own error class:
|
|
629
|
+
|
|
630
|
+
```typescript
|
|
631
|
+
import {
|
|
632
|
+
PolicyClient,
|
|
633
|
+
PolicyClientError,
|
|
634
|
+
ApprovalClient,
|
|
635
|
+
ApprovalClientError,
|
|
636
|
+
BudgetClient,
|
|
637
|
+
BudgetClientError,
|
|
638
|
+
MetricsClient,
|
|
639
|
+
MetricsClientError
|
|
640
|
+
} from '@fulcrum-governance/sdk';
|
|
641
|
+
|
|
642
|
+
try {
|
|
643
|
+
const policy = await policyClient.get('invalid-id');
|
|
644
|
+
} catch (error) {
|
|
645
|
+
if (error instanceof PolicyClientError) {
|
|
646
|
+
console.log(`Error: ${error.message}`);
|
|
647
|
+
console.log(`Status: ${error.statusCode}`); // e.g., 404, 401, 500
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
```
|
|
651
|
+
|
|
360
652
|
## Browser Support
|
|
361
653
|
|
|
362
|
-
For browser environments, use the REST
|
|
654
|
+
For browser environments, use the REST clients which work with the standard `fetch` API:
|
|
363
655
|
|
|
364
656
|
```typescript
|
|
365
|
-
import {
|
|
657
|
+
import { PolicyClient, BudgetClient, MetricsClient } from '@fulcrum-governance/sdk';
|
|
366
658
|
|
|
367
|
-
|
|
368
|
-
|
|
659
|
+
// REST clients work in browsers
|
|
660
|
+
const policyClient = new PolicyClient({
|
|
661
|
+
baseUrl: 'https://your-fulcrum-dashboard.com',
|
|
369
662
|
apiKey: 'your-api-key'
|
|
370
663
|
});
|
|
371
664
|
|
|
372
|
-
//
|
|
373
|
-
|
|
665
|
+
// For real-time governance (gRPC), use the REST envelope wrapper
|
|
666
|
+
// (Coming soon)
|
|
374
667
|
```
|
|
375
668
|
|
|
376
669
|
## Documentation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|