@umpledger/sdk 2.0.0-alpha.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.
@@ -0,0 +1,839 @@
1
+ type AgentType = 'HUMAN' | 'ORGANIZATION' | 'AI_AGENT' | 'SERVICE' | 'COMPOSITE';
2
+ type AgentStatus = 'ACTIVE' | 'SUSPENDED' | 'REVOKED' | 'EXPIRED';
3
+ interface AuthorityScope {
4
+ maxPerTransaction: number;
5
+ maxPerDay: number;
6
+ maxPerMonth: number;
7
+ allowedServices?: string[];
8
+ allowedCounterparties?: string[];
9
+ requiresApprovalAbove?: number;
10
+ autoRevokeAfter?: number;
11
+ }
12
+ interface VerificationProof {
13
+ publicKey: string;
14
+ issuingAuthority: string;
15
+ expiresAt: Date;
16
+ revocationEndpoint?: string;
17
+ }
18
+ interface AgentIdentity {
19
+ agentId: string;
20
+ agentType: AgentType;
21
+ parentId: string | null;
22
+ displayName: string;
23
+ capabilities: string[];
24
+ authorityScope: AuthorityScope;
25
+ verification: VerificationProof;
26
+ metadata: Record<string, unknown>;
27
+ status: AgentStatus;
28
+ createdAt: Date;
29
+ updatedAt: Date;
30
+ }
31
+ interface CreateAgentOptions {
32
+ name: string;
33
+ type: AgentType;
34
+ parentId?: string;
35
+ capabilities?: string[];
36
+ authority: Partial<AuthorityScope> & {
37
+ maxPerTransaction: number | string;
38
+ maxPerDay: number | string;
39
+ };
40
+ metadata?: Record<string, unknown>;
41
+ }
42
+ type ValueUnitType = 'FIAT' | 'AI_TOKEN' | 'COMPUTE_CREDIT' | 'OUTCOME_SCORE' | 'PLATFORM_CREDIT' | 'ENVIRONMENTAL';
43
+ interface Balance {
44
+ valueUnitType: ValueUnitType;
45
+ currency?: string;
46
+ amount: number;
47
+ reserved: number;
48
+ available: number;
49
+ }
50
+ interface FundingConfig {
51
+ type: 'LINKED_BANK' | 'PARENT_DRAWDOWN' | 'PREPAID';
52
+ sourceId: string;
53
+ autoTopup?: AutoTopupRule;
54
+ }
55
+ interface AutoTopupRule {
56
+ threshold: number;
57
+ amount: number;
58
+ maxPerDay: number;
59
+ }
60
+ interface LedgerEntry {
61
+ entryId: string;
62
+ timestamp: Date;
63
+ type: 'DEBIT' | 'CREDIT' | 'RESERVE' | 'RELEASE' | 'TOPUP';
64
+ amount: number;
65
+ valueUnitType: ValueUnitType;
66
+ currency?: string;
67
+ counterpartyAgentId?: string;
68
+ transactionId?: string;
69
+ description: string;
70
+ balanceAfter: number;
71
+ }
72
+ interface Wallet {
73
+ walletId: string;
74
+ ownerAgentId: string;
75
+ balances: Balance[];
76
+ fundingSource?: FundingConfig;
77
+ frozen: boolean;
78
+ createdAt: Date;
79
+ }
80
+ interface FundWalletOptions {
81
+ amount: number | string;
82
+ source?: string;
83
+ valueUnitType?: ValueUnitType;
84
+ currency?: string;
85
+ }
86
+ type PricingPrimitive = 'FIXED' | 'UNIT_RATE' | 'TIERED' | 'PERCENTAGE' | 'THRESHOLD' | 'TIME_WINDOW' | 'CONDITIONAL' | 'COMPOSITE';
87
+ type CompositeOperator = 'ADD' | 'MAX' | 'MIN' | 'FIRST_MATCH';
88
+ interface PricingRuleBase {
89
+ ruleId: string;
90
+ name: string;
91
+ description?: string;
92
+ primitive: PricingPrimitive;
93
+ }
94
+ interface FixedRule extends PricingRuleBase {
95
+ primitive: 'FIXED';
96
+ amount: number;
97
+ period?: 'PER_EVENT' | 'HOURLY' | 'DAILY' | 'MONTHLY' | 'YEARLY';
98
+ }
99
+ interface UnitRateRule extends PricingRuleBase {
100
+ primitive: 'UNIT_RATE';
101
+ rate: number;
102
+ unit: string;
103
+ }
104
+ interface TierBand {
105
+ from: number;
106
+ to: number | null;
107
+ rate: number;
108
+ }
109
+ interface TieredRule extends PricingRuleBase {
110
+ primitive: 'TIERED';
111
+ tiers: TierBand[];
112
+ mode: 'GRADUATED' | 'VOLUME';
113
+ }
114
+ interface PercentageRule extends PricingRuleBase {
115
+ primitive: 'PERCENTAGE';
116
+ percentage: number;
117
+ referenceField: string;
118
+ min?: number;
119
+ max?: number;
120
+ }
121
+ interface ThresholdRule extends PricingRuleBase {
122
+ primitive: 'THRESHOLD';
123
+ threshold: number;
124
+ belowRate: number;
125
+ aboveRate: number;
126
+ }
127
+ interface TimeWindowBand {
128
+ dayOfWeek?: number[];
129
+ startHour: number;
130
+ endHour: number;
131
+ rate: number;
132
+ label?: string;
133
+ }
134
+ interface TimeWindowRule extends PricingRuleBase {
135
+ primitive: 'TIME_WINDOW';
136
+ windows: TimeWindowBand[];
137
+ defaultRate: number;
138
+ timezone: string;
139
+ }
140
+ interface ConditionalBranch {
141
+ condition: string;
142
+ rule: PricingRule;
143
+ }
144
+ interface ConditionalRule extends PricingRuleBase {
145
+ primitive: 'CONDITIONAL';
146
+ field: string;
147
+ branches: ConditionalBranch[];
148
+ fallback?: PricingRule;
149
+ }
150
+ interface CompositeRule extends PricingRuleBase {
151
+ primitive: 'COMPOSITE';
152
+ operator: CompositeOperator;
153
+ rules: PricingRule[];
154
+ }
155
+ type PricingRule = FixedRule | UnitRateRule | TieredRule | PercentageRule | ThresholdRule | TimeWindowRule | ConditionalRule | CompositeRule;
156
+ type ContractMode = 'PRE_NEGOTIATED' | 'TEMPLATE' | 'DYNAMIC';
157
+ type ContractStatus = 'DRAFT' | 'PROPOSED' | 'ACTIVE' | 'EXPIRED' | 'TERMINATED';
158
+ interface Contract {
159
+ contractId: string;
160
+ mode: ContractMode;
161
+ status: ContractStatus;
162
+ parties: {
163
+ sourceAgentId: string;
164
+ targetAgentId: string;
165
+ };
166
+ pricingRules: PricingRule[];
167
+ effectiveFrom: Date;
168
+ effectiveUntil?: Date;
169
+ metadata: Record<string, unknown>;
170
+ createdAt: Date;
171
+ }
172
+ interface CreateContractOptions {
173
+ mode?: ContractMode;
174
+ targetAgentId: string;
175
+ pricingRules: Omit<PricingRule, 'ruleId'>[];
176
+ effectiveFrom?: Date;
177
+ effectiveUntil?: Date;
178
+ metadata?: Record<string, unknown>;
179
+ }
180
+ interface UsageEvent {
181
+ eventId: string;
182
+ sourceAgentId: string;
183
+ targetAgentId: string;
184
+ contractId: string;
185
+ serviceId: string;
186
+ timestamp: Date;
187
+ quantity: number;
188
+ unit: string;
189
+ dimensions: Record<string, string | number>;
190
+ outcome?: OutcomeAttestation;
191
+ signature?: string;
192
+ }
193
+ type OutcomeType = 'TASK_COMPLETION' | 'METRIC_IMPROVEMENT' | 'REVENUE_GENERATED' | 'COST_SAVED' | 'CUSTOM';
194
+ type VerificationMethod = 'SELF_REPORTED' | 'BILATERAL_AGREEMENT' | 'THIRD_PARTY_ORACLE' | 'AUTOMATED_TEST';
195
+ type AttestationStatus = 'CLAIMED' | 'VERIFIED' | 'DISPUTED' | 'EXPIRED';
196
+ interface OutcomeAttestation {
197
+ outcomeId: string;
198
+ outcomeType: OutcomeType;
199
+ claimedBy: string;
200
+ evidence: Evidence[];
201
+ verificationMethod: VerificationMethod;
202
+ verifiedBy?: string;
203
+ confidenceScore: number;
204
+ attestationStatus: AttestationStatus;
205
+ disputeWindow: number;
206
+ }
207
+ interface Evidence {
208
+ type: 'LOG' | 'METRIC' | 'SCREENSHOT' | 'THIRD_PARTY' | 'TEST_RESULT';
209
+ uri: string;
210
+ hash: string;
211
+ description?: string;
212
+ }
213
+ type SettlementPattern = 'INSTANT_DRAWDOWN' | 'ESCROW_RELEASE' | 'WATERFALL_SPLIT' | 'NET_SETTLEMENT' | 'CONDITIONAL_RELEASE' | 'CROSS_CURRENCY_ATOMIC';
214
+ type SettlementStatus = 'PENDING' | 'PROCESSING' | 'SETTLED' | 'FAILED' | 'REVERSED';
215
+ interface RatedRecord {
216
+ ratedRecordId: string;
217
+ usageEventId: string;
218
+ contractId: string;
219
+ pricingRuleId: string;
220
+ quantity: number;
221
+ rate: number;
222
+ amount: number;
223
+ currency: string;
224
+ ratedAt: Date;
225
+ }
226
+ interface Settlement {
227
+ settlementId: string;
228
+ pattern: SettlementPattern;
229
+ status: SettlementStatus;
230
+ sourceAgentId: string;
231
+ targetAgentId: string;
232
+ ratedRecords: RatedRecord[];
233
+ totalAmount: number;
234
+ currency: string;
235
+ settledAt?: Date;
236
+ auditId: string;
237
+ }
238
+ interface TransactOptions {
239
+ from: string;
240
+ to: string;
241
+ service: string;
242
+ payload?: Record<string, unknown>;
243
+ maxCost?: number | string;
244
+ }
245
+ interface TransactionResult {
246
+ transactionId: string;
247
+ cost: number;
248
+ currency: string;
249
+ outcome?: OutcomeAttestation;
250
+ auditId: string;
251
+ settledAt: Date;
252
+ duration: number;
253
+ }
254
+ interface AuditRecord {
255
+ auditId: string;
256
+ what: {
257
+ operation: string;
258
+ entityType: string;
259
+ entityId: string;
260
+ amount?: number;
261
+ };
262
+ who: {
263
+ sourceAgentId: string;
264
+ targetAgentId: string;
265
+ humanOwnerId?: string;
266
+ };
267
+ when: Date;
268
+ why: {
269
+ contractId?: string;
270
+ pricingRuleId?: string;
271
+ justification?: string;
272
+ };
273
+ how: {
274
+ policiesEvaluated: string[];
275
+ policiesPassed: string[];
276
+ overrides?: string[];
277
+ };
278
+ result: {
279
+ balanceBefore?: number;
280
+ balanceAfter?: number;
281
+ settlementAmount?: number;
282
+ status: string;
283
+ };
284
+ }
285
+ type DisputeStage = 'AUTOMATED_RECONCILIATION' | 'AGENT_NEGOTIATION' | 'ARBITRATION_ORACLE' | 'HUMAN_ESCALATION';
286
+ type DisputeStatus = 'OPEN' | 'IN_PROGRESS' | 'RESOLVED' | 'ESCALATED' | 'CLOSED';
287
+ interface Dispute {
288
+ disputeId: string;
289
+ transactionId: string;
290
+ openedBy: string;
291
+ respondent: string;
292
+ stage: DisputeStage;
293
+ status: DisputeStatus;
294
+ reason: string;
295
+ evidence: Evidence[];
296
+ amount: number;
297
+ resolution?: {
298
+ outcome: 'UPHELD' | 'REJECTED' | 'PARTIAL';
299
+ adjustedAmount: number;
300
+ };
301
+ openedAt: Date;
302
+ resolvedAt?: Date;
303
+ }
304
+ type PolicyType = 'SPENDING_LIMIT' | 'COUNTERPARTY_ALLOWLIST' | 'SERVICE_ALLOWLIST' | 'RATE_REASONABLENESS' | 'OUTCOME_VERIFICATION' | 'COMPLIANCE' | 'ANOMALY_DETECTION' | 'BUDGET_ALLOCATION';
305
+ type ViolationAction = 'HARD_BLOCK' | 'SOFT_BLOCK' | 'ALERT' | 'LOG';
306
+ interface Policy {
307
+ policyId: string;
308
+ type: PolicyType;
309
+ agentId: string;
310
+ config: Record<string, unknown>;
311
+ violationAction: ViolationAction;
312
+ enabled: boolean;
313
+ }
314
+ interface UMPConfig {
315
+ apiKey: string;
316
+ baseUrl?: string;
317
+ timeout?: number;
318
+ retries?: number;
319
+ onAudit?: (record: AuditRecord) => void;
320
+ }
321
+
322
+ /**
323
+ * AgentManager — Layer 1 primitive
324
+ *
325
+ * Manages Agent Identity lifecycle: creation, verification,
326
+ * authority scope enforcement, hierarchical revocation.
327
+ */
328
+ declare class AgentManager {
329
+ private agents;
330
+ /**
331
+ * Register a new Agent Identity with authority scope.
332
+ */
333
+ create(options: CreateAgentOptions): AgentIdentity;
334
+ /**
335
+ * Retrieve an agent by ID.
336
+ */
337
+ get(agentId: string): AgentIdentity;
338
+ /**
339
+ * Update authority scope (tightening is always allowed; loosening requires parent).
340
+ */
341
+ updateAuthority(agentId: string, newScope: Partial<AuthorityScope>): AgentIdentity;
342
+ /**
343
+ * Revoke an agent and cascade to all children.
344
+ */
345
+ revoke(agentId: string): string[];
346
+ /**
347
+ * Verify that an agent's identity is valid and active.
348
+ */
349
+ verify(agentId: string): {
350
+ valid: boolean;
351
+ reason?: string;
352
+ };
353
+ /**
354
+ * Check if a transaction amount is within the agent's authority scope.
355
+ */
356
+ checkAuthority(agentId: string, amount: number, counterpartyId?: string, serviceId?: string): {
357
+ allowed: boolean;
358
+ reason?: string;
359
+ requiresApproval?: boolean;
360
+ };
361
+ /**
362
+ * List all agents, optionally filtered.
363
+ */
364
+ list(filter?: {
365
+ parentId?: string;
366
+ type?: AgentType;
367
+ status?: AgentStatus;
368
+ }): AgentIdentity[];
369
+ }
370
+
371
+ /**
372
+ * WalletManager — Layer 1 primitive
373
+ *
374
+ * Manages wallets, balances, reserves, and the immutable spending ledger.
375
+ * Every financial operation is recorded as a LedgerEntry.
376
+ */
377
+ declare class WalletManager {
378
+ private wallets;
379
+ private ledgers;
380
+ /**
381
+ * Create a wallet for an agent.
382
+ */
383
+ create(ownerAgentId: string): Wallet;
384
+ /**
385
+ * Get wallet by ID.
386
+ */
387
+ get(walletId: string): Wallet;
388
+ /**
389
+ * Get wallet by owner agent ID.
390
+ */
391
+ getByAgent(agentId: string): Wallet;
392
+ /**
393
+ * Fund a wallet (add money).
394
+ */
395
+ fund(walletId: string, options: FundWalletOptions): LedgerEntry;
396
+ /**
397
+ * Reserve funds for a pending transaction (escrow pattern).
398
+ */
399
+ reserve(walletId: string, amount: number, counterpartyAgentId: string, transactionId: string): LedgerEntry;
400
+ /**
401
+ * Debit wallet (immediate drawdown).
402
+ */
403
+ debit(walletId: string, amount: number, counterpartyAgentId: string, transactionId: string): LedgerEntry;
404
+ /**
405
+ * Credit wallet (receive payment).
406
+ */
407
+ credit(walletId: string, amount: number, counterpartyAgentId: string, transactionId: string): LedgerEntry;
408
+ /**
409
+ * Release reserved funds (escrow release after outcome).
410
+ */
411
+ releaseReservation(walletId: string, amount: number, transactionId: string): LedgerEntry;
412
+ /**
413
+ * Emergency freeze — blocks all transactions.
414
+ */
415
+ freeze(walletId: string): void;
416
+ /**
417
+ * Unfreeze wallet.
418
+ */
419
+ unfreeze(walletId: string): void;
420
+ /**
421
+ * Get immutable ledger entries for a wallet.
422
+ */
423
+ getLedger(walletId: string, limit?: number, offset?: number): LedgerEntry[];
424
+ /**
425
+ * Get real-time balance summary.
426
+ */
427
+ getBalance(walletId: string): Balance[];
428
+ private getPrimaryBalance;
429
+ private getOrCreateBalance;
430
+ private appendLedger;
431
+ }
432
+
433
+ /**
434
+ * AuditTrail — Layer 3 primitive
435
+ *
436
+ * Immutable append-only log of every UMP operation.
437
+ * Captures 6 dimensions: WHAT, WHO, WHEN, WHY, HOW, RESULT.
438
+ */
439
+ declare class AuditTrail {
440
+ private records;
441
+ private onAudit?;
442
+ constructor(onAudit?: (record: AuditRecord) => void);
443
+ /**
444
+ * Record an audit entry. Returns the audit ID.
445
+ */
446
+ record(data: Omit<AuditRecord, 'auditId' | 'when'>): string;
447
+ /**
448
+ * Query audit records with filters.
449
+ */
450
+ query(filters?: {
451
+ agentId?: string;
452
+ operation?: string;
453
+ fromDate?: Date;
454
+ toDate?: Date;
455
+ minAmount?: number;
456
+ contractId?: string;
457
+ }, limit?: number, offset?: number): AuditRecord[];
458
+ /**
459
+ * Get a specific audit record by ID.
460
+ */
461
+ get(auditId: string): AuditRecord | undefined;
462
+ /**
463
+ * Get total count of records.
464
+ */
465
+ count(): number;
466
+ }
467
+
468
+ /**
469
+ * Context passed into the rating engine for each usage event.
470
+ * Contains the event data plus any external dimensions needed
471
+ * for conditional evaluation.
472
+ */
473
+ interface RatingContext {
474
+ event: UsageEvent;
475
+ cumulativeQuantity?: number;
476
+ referenceAmount?: number;
477
+ currentTime?: Date;
478
+ attributes?: Record<string, string | number | boolean>;
479
+ }
480
+ /**
481
+ * PricingEngine — Layer 2 primitive
482
+ *
483
+ * Evaluates the 8 atomic pricing primitives and their compositions.
484
+ * Takes usage events + pricing rules → rated records (billable amounts).
485
+ */
486
+ declare class PricingEngine {
487
+ /**
488
+ * Rate a single usage event against a pricing rule.
489
+ * Returns the calculated amount.
490
+ */
491
+ rate(rule: PricingRule, context: RatingContext): RatedRecord;
492
+ /**
493
+ * Rate multiple usage events against a pricing rule.
494
+ */
495
+ rateBatch(rule: PricingRule, events: UsageEvent[]): RatedRecord[];
496
+ /**
497
+ * Simulate: calculate projected cost without creating rated records.
498
+ */
499
+ simulate(rule: PricingRule, quantity: number, dimensions?: Record<string, string | number>): number;
500
+ /**
501
+ * Human-readable breakdown of how a price was calculated.
502
+ */
503
+ explain(rule: PricingRule, context: RatingContext): string;
504
+ private evaluate;
505
+ /**
506
+ * FIXED: flat amount per event or period.
507
+ */
508
+ private evalFixed;
509
+ /**
510
+ * UNIT_RATE: rate × quantity.
511
+ */
512
+ private evalUnitRate;
513
+ /**
514
+ * TIERED: different rates at different consumption levels.
515
+ * Supports GRADUATED (each unit at its tier's rate) and VOLUME (all units at qualifying tier).
516
+ */
517
+ private evalTiered;
518
+ /**
519
+ * PERCENTAGE: fraction of a reference amount.
520
+ */
521
+ private evalPercentage;
522
+ /**
523
+ * THRESHOLD: binary trigger — different rates above/below threshold.
524
+ */
525
+ private evalThreshold;
526
+ /**
527
+ * TIME_WINDOW: rate varies by when consumption occurs.
528
+ */
529
+ private evalTimeWindow;
530
+ /**
531
+ * CONDITIONAL: price depends on an attribute or outcome.
532
+ */
533
+ private evalConditional;
534
+ /**
535
+ * COMPOSITE: combines multiple rules with an operator.
536
+ */
537
+ private evalComposite;
538
+ private evaluateCondition;
539
+ private buildExplanation;
540
+ }
541
+
542
+ /**
543
+ * ContractManager — Layer 1/2 bridge
544
+ *
545
+ * Manages commercial agreements between agents.
546
+ * Supports pre-negotiated, template-based, and dynamic negotiation.
547
+ */
548
+ declare class ContractManager {
549
+ private contracts;
550
+ /**
551
+ * Create a new contract between two agents.
552
+ */
553
+ create(sourceAgentId: string, options: CreateContractOptions): Contract;
554
+ /**
555
+ * Get contract by ID.
556
+ */
557
+ get(contractId: string): Contract;
558
+ /**
559
+ * Find active contract between two agents.
560
+ */
561
+ findActive(sourceAgentId: string, targetAgentId: string): Contract | undefined;
562
+ /**
563
+ * Dynamic negotiation: propose terms.
564
+ * Returns a DRAFT contract that the counterparty can accept or counter.
565
+ */
566
+ propose(sourceAgentId: string, options: CreateContractOptions): Contract;
567
+ /**
568
+ * Accept a proposed contract — transitions to ACTIVE.
569
+ */
570
+ accept(contractId: string): Contract;
571
+ /**
572
+ * Counter-propose: create a new proposal based on an existing one with modified terms.
573
+ */
574
+ counter(contractId: string, counterAgentId: string, modifiedRules: Omit<PricingRule, 'ruleId'>[]): Contract;
575
+ /**
576
+ * Terminate a contract.
577
+ */
578
+ terminate(contractId: string): Contract;
579
+ /**
580
+ * List contracts for an agent.
581
+ */
582
+ listByAgent(agentId: string, status?: ContractStatus): Contract[];
583
+ }
584
+
585
+ /**
586
+ * MeteringEngine — Layer 2 primitive
587
+ *
588
+ * Captures usage events with cryptographic integrity.
589
+ * Supports idempotent event submission, deduplication, and
590
+ * outcome attestation for result-based billing.
591
+ */
592
+ declare class MeteringEngine {
593
+ private events;
594
+ private seenIds;
595
+ /**
596
+ * Record a usage event.
597
+ * Idempotent: resubmitting the same eventId is a no-op.
598
+ */
599
+ record(event: Omit<UsageEvent, 'eventId' | 'timestamp'> & {
600
+ eventId?: string;
601
+ }): UsageEvent;
602
+ /**
603
+ * Record a batch of usage events.
604
+ */
605
+ recordBatch(events: Array<Omit<UsageEvent, 'eventId' | 'timestamp'>>): UsageEvent[];
606
+ /**
607
+ * Create an outcome attestation for result-based billing.
608
+ */
609
+ attestOutcome(data: {
610
+ outcomeType: OutcomeAttestation['outcomeType'];
611
+ claimedBy: string;
612
+ evidence: OutcomeAttestation['evidence'];
613
+ verificationMethod: OutcomeAttestation['verificationMethod'];
614
+ confidenceScore: number;
615
+ disputeWindow?: number;
616
+ }): OutcomeAttestation;
617
+ /**
618
+ * Get events for a contract within a time range.
619
+ */
620
+ getByContract(contractId: string, from?: Date, to?: Date): UsageEvent[];
621
+ /**
622
+ * Get events for a specific agent (as source or target).
623
+ */
624
+ getByAgent(agentId: string, limit?: number): UsageEvent[];
625
+ /**
626
+ * Get a specific event by ID.
627
+ */
628
+ get(eventId: string): UsageEvent | undefined;
629
+ /**
630
+ * Get total metered quantity for a contract.
631
+ */
632
+ totalQuantity(contractId: string): number;
633
+ }
634
+
635
+ interface SettlementResult {
636
+ settlement: Settlement;
637
+ auditId: string;
638
+ }
639
+ /**
640
+ * SettlementBus — Layer 3 primitive
641
+ *
642
+ * Executes real-time settlement between agent wallets.
643
+ * Supports 6 patterns: instant drawdown, escrow, waterfall,
644
+ * net settlement, conditional release, cross-currency atomic.
645
+ */
646
+ declare class SettlementBus {
647
+ private wallets;
648
+ private audit;
649
+ private pricingEngine;
650
+ private settlements;
651
+ private escrows;
652
+ constructor(wallets: WalletManager, audit: AuditTrail, pricingEngine: PricingEngine);
653
+ /**
654
+ * Execute a full transaction: meter → rate → settle in one call.
655
+ * This is the high-level "transact" method from the Quick Start.
656
+ */
657
+ transact(sourceAgentId: string, targetAgentId: string, event: UsageEvent, rule: PricingRule): Promise<SettlementResult>;
658
+ /**
659
+ * INSTANT_DRAWDOWN: Debit source, credit target atomically.
660
+ * Used for per-token, per-inference micro-transactions.
661
+ */
662
+ settleInstant(sourceAgentId: string, targetAgentId: string, ratedRecords: RatedRecord[], _startTime?: number): SettlementResult;
663
+ /**
664
+ * ESCROW_RELEASE: Reserve funds, release upon outcome attestation.
665
+ * Used for outcome-based pricing and milestone payments.
666
+ */
667
+ createEscrow(sourceAgentId: string, targetAgentId: string, amount: number, transactionId: string): string;
668
+ /**
669
+ * Release escrowed funds to the target (full or partial).
670
+ */
671
+ releaseEscrow(escrowId: string, releaseAmount?: number): SettlementResult;
672
+ /**
673
+ * WATERFALL_SPLIT: Distribute payment across multiple parties.
674
+ * Used for marketplace commissions and multi-party revenue share.
675
+ */
676
+ settleWaterfall(sourceAgentId: string, splits: Array<{
677
+ agentId: string;
678
+ amount: number;
679
+ }>, ratedRecords: RatedRecord[]): SettlementResult[];
680
+ /**
681
+ * Get settlement by ID.
682
+ */
683
+ get(settlementId: string): Settlement | undefined;
684
+ /**
685
+ * List settlements for an agent.
686
+ */
687
+ listByAgent(agentId: string, limit?: number): Settlement[];
688
+ }
689
+
690
+ /**
691
+ * Pre-built pricing rule templates for common AI-era models.
692
+ * These are convenience factories — all decompose into the 8 atomic primitives.
693
+ */
694
+ declare const PricingTemplates: {
695
+ /**
696
+ * Per-Token LLM pricing (separate input/output rates).
697
+ * Example: GPT-4 at $30/M input, $60/M output tokens.
698
+ */
699
+ perToken(inputRatePerMillion: number, outputRatePerMillion: number): PricingRule;
700
+ /**
701
+ * Per-Inference pricing with volume tiers.
702
+ * Example: $0.01/call for first 10K, $0.005/call after.
703
+ */
704
+ perInference(tiers: Array<{
705
+ upTo: number | null;
706
+ rate: number;
707
+ }>): PricingRule;
708
+ /**
709
+ * Per-Resolution / outcome-based pricing.
710
+ * Charges only on successful outcome + percentage of value.
711
+ */
712
+ perResolution(successFee: number, valuePct: number): PricingRule;
713
+ /**
714
+ * Subscription + Usage hybrid.
715
+ * Base monthly fee + per-unit overage above included units.
716
+ */
717
+ subscriptionPlusUsage(monthlyBase: number, includedUnits: number, overageRate: number): PricingRule;
718
+ /**
719
+ * Credit pool with per-unit drawdown.
720
+ */
721
+ creditPool(creditCost: number): PricingRule;
722
+ /**
723
+ * Spot compute pricing with peak/off-peak rates.
724
+ */
725
+ computeSpot(peakRate: number, offPeakRate: number, peakHours?: [number, number]): PricingRule;
726
+ /**
727
+ * Marketplace commission (percentage take rate with floor and cap).
728
+ */
729
+ marketplaceCommission(takeRate: number, minFee: number, maxFee: number): PricingRule;
730
+ /**
731
+ * Agent-to-agent task pricing (fixed per-task + outcome bonus).
732
+ */
733
+ agentTask(basePerTask: number, bonusOnSuccess: number): PricingRule;
734
+ };
735
+
736
+ /**
737
+ * UMP Error Hierarchy
738
+ * All SDK errors extend UMPError for easy catch-all handling.
739
+ */
740
+ declare class UMPError extends Error {
741
+ readonly code: string;
742
+ constructor(message: string, code: string);
743
+ }
744
+ declare class AuthorityExceededError extends UMPError {
745
+ readonly limit: number;
746
+ readonly attempted: number;
747
+ constructor(limitType: string, limit: number, attempted: number);
748
+ }
749
+ declare class InsufficientFundsError extends UMPError {
750
+ readonly available: number;
751
+ readonly required: number;
752
+ constructor(available: number, required: number);
753
+ }
754
+ declare class WalletFrozenError extends UMPError {
755
+ constructor(walletId: string);
756
+ }
757
+ declare class AgentNotFoundError extends UMPError {
758
+ constructor(agentId: string);
759
+ }
760
+ declare class AgentRevokedError extends UMPError {
761
+ constructor(agentId: string);
762
+ }
763
+ declare class ContractNotFoundError extends UMPError {
764
+ constructor(contractId: string);
765
+ }
766
+ declare class PolicyViolationError extends UMPError {
767
+ readonly policyType: string;
768
+ readonly action: string;
769
+ constructor(policyType: string, action: string, details: string);
770
+ }
771
+ declare class DisputeError extends UMPError {
772
+ constructor(message: string);
773
+ }
774
+
775
+ /**
776
+ * ═══════════════════════════════════════════════════════════════
777
+ * @ump/sdk — Universal Monetization Protocol v2.0
778
+ *
779
+ * The payment rail for the autonomous economy.
780
+ * When AI agents transact with AI agents, UMP governs
781
+ * how value flows between them.
782
+ *
783
+ * Quick Start:
784
+ * const ump = new UMP({ apiKey: "ump_sk_..." });
785
+ * const agent = ump.agents.create({ name: "my-agent", type: "AI_AGENT", authority: { maxPerTransaction: "$50", maxPerDay: "$500" } });
786
+ * await ump.transact({ from: agent.agentId, to: "agent_target", service: "code_review" });
787
+ *
788
+ * Architecture: 3 layers
789
+ * L1: Identity & Value (AgentManager, WalletManager)
790
+ * L2: Terms & Metering (ContractManager, MeteringEngine, PricingEngine)
791
+ * L3: Settlement & Gov (SettlementBus, AuditTrail)
792
+ *
793
+ * © 2026 UMPLedger — Apache 2.0 License
794
+ * ═══════════════════════════════════════════════════════════════
795
+ */
796
+
797
+ /**
798
+ * Convenience wrapper: an agent + its wallet in one object.
799
+ */
800
+ interface AgentHandle {
801
+ id: string;
802
+ agent: AgentIdentity;
803
+ wallet: {
804
+ fund: (options: FundWalletOptions) => void;
805
+ balance: () => number;
806
+ freeze: () => void;
807
+ unfreeze: () => void;
808
+ };
809
+ }
810
+ /**
811
+ * UMP — Main SDK Entry Point
812
+ *
813
+ * Orchestrates all three protocol layers through a clean API.
814
+ */
815
+ declare class UMP {
816
+ readonly agents: AgentManager;
817
+ readonly wallets: WalletManager;
818
+ readonly contracts: ContractManager;
819
+ readonly metering: MeteringEngine;
820
+ readonly pricing: PricingEngine;
821
+ readonly settlement: SettlementBus;
822
+ readonly audit: AuditTrail;
823
+ constructor(config: UMPConfig);
824
+ /**
825
+ * High-level: Register an agent and create its wallet.
826
+ * Returns an AgentHandle with convenience methods.
827
+ */
828
+ registerAgent(options: CreateAgentOptions): AgentHandle;
829
+ /**
830
+ * High-level: Execute a priced transaction between two agents.
831
+ *
832
+ * This is the "10 lines of code" Quick Start method.
833
+ * It finds or creates a contract, meters the event, rates it,
834
+ * settles payment, and returns the result — all in one call.
835
+ */
836
+ transact(options: TransactOptions): Promise<TransactionResult>;
837
+ }
838
+
839
+ export { type AgentHandle, type AgentIdentity, AgentManager, AgentNotFoundError, AgentRevokedError, type AgentStatus, type AgentType, type AttestationStatus, type AuditRecord, AuditTrail, AuthorityExceededError, type AuthorityScope, type AutoTopupRule, type Balance, type CompositeOperator, type CompositeRule, type ConditionalBranch, type ConditionalRule, type Contract, ContractManager, type ContractMode, ContractNotFoundError, type ContractStatus, type CreateAgentOptions, type CreateContractOptions, type Dispute, DisputeError, type DisputeStage, type DisputeStatus, type Evidence, type FixedRule, type FundWalletOptions, type FundingConfig, InsufficientFundsError, type LedgerEntry, MeteringEngine, type OutcomeAttestation, type OutcomeType, type PercentageRule, type Policy, type PolicyType, PolicyViolationError, PricingEngine, type PricingPrimitive, type PricingRule, type PricingRuleBase, PricingTemplates, type RatedRecord, type RatingContext, type Settlement, SettlementBus, type SettlementPattern, type SettlementResult, type SettlementStatus, type ThresholdRule, type TierBand, type TieredRule, type TimeWindowBand, type TimeWindowRule, type TransactOptions, type TransactionResult, UMP, type UMPConfig, UMPError, type UnitRateRule, type UsageEvent, type ValueUnitType, type VerificationMethod, type VerificationProof, type ViolationAction, type Wallet, WalletFrozenError, WalletManager };