@holoscript/framework 6.0.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/ALL-test-results.json +1 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/ROADMAP.md +175 -0
- package/dist/AgentManifest-CB4xM-Ma.d.cts +704 -0
- package/dist/AgentManifest-CB4xM-Ma.d.ts +704 -0
- package/dist/BehaviorTree-BrBFECv5.d.cts +103 -0
- package/dist/BehaviorTree-BrBFECv5.d.ts +103 -0
- package/dist/InvisibleWallet-BB6tFvRA.d.cts +1732 -0
- package/dist/InvisibleWallet-rtRrBOA8.d.ts +1732 -0
- package/dist/OrchestratorAgent-BvWgf9uw.d.cts +798 -0
- package/dist/OrchestratorAgent-Q_CbVTmO.d.ts +798 -0
- package/dist/agents/index.cjs +4790 -0
- package/dist/agents/index.d.cts +1788 -0
- package/dist/agents/index.d.ts +1788 -0
- package/dist/agents/index.js +4695 -0
- package/dist/ai/index.cjs +5347 -0
- package/dist/ai/index.d.cts +1753 -0
- package/dist/ai/index.d.ts +1753 -0
- package/dist/ai/index.js +5244 -0
- package/dist/behavior.cjs +449 -0
- package/dist/behavior.d.cts +130 -0
- package/dist/behavior.d.ts +130 -0
- package/dist/behavior.js +407 -0
- package/dist/economy/index.cjs +3659 -0
- package/dist/economy/index.d.cts +747 -0
- package/dist/economy/index.d.ts +747 -0
- package/dist/economy/index.js +3617 -0
- package/dist/implementations-D9T3un9D.d.cts +236 -0
- package/dist/implementations-D9T3un9D.d.ts +236 -0
- package/dist/index.cjs +24550 -0
- package/dist/index.d.cts +1729 -0
- package/dist/index.d.ts +1729 -0
- package/dist/index.js +24277 -0
- package/dist/learning/index.cjs +219 -0
- package/dist/learning/index.d.cts +104 -0
- package/dist/learning/index.d.ts +104 -0
- package/dist/learning/index.js +189 -0
- package/dist/negotiation/index.cjs +970 -0
- package/dist/negotiation/index.d.cts +610 -0
- package/dist/negotiation/index.d.ts +610 -0
- package/dist/negotiation/index.js +931 -0
- package/dist/skills/index.cjs +1118 -0
- package/dist/skills/index.d.cts +289 -0
- package/dist/skills/index.d.ts +289 -0
- package/dist/skills/index.js +1079 -0
- package/dist/swarm/index.cjs +5268 -0
- package/dist/swarm/index.d.cts +2433 -0
- package/dist/swarm/index.d.ts +2433 -0
- package/dist/swarm/index.js +5221 -0
- package/dist/training/index.cjs +2745 -0
- package/dist/training/index.d.cts +1734 -0
- package/dist/training/index.d.ts +1734 -0
- package/dist/training/index.js +2687 -0
- package/extract-failures.js +10 -0
- package/package.json +82 -0
- package/src/__tests__/bounty-marketplace.test.ts +374 -0
- package/src/__tests__/delegation.test.ts +144 -0
- package/src/__tests__/distributed-claimer.test.ts +147 -0
- package/src/__tests__/done-log-audit.test.ts +342 -0
- package/src/__tests__/framework.test.ts +865 -0
- package/src/__tests__/goal-synthesizer.test.ts +236 -0
- package/src/__tests__/presence.test.ts +223 -0
- package/src/__tests__/protocol-agent.test.ts +254 -0
- package/src/__tests__/revenue-splitter.test.ts +114 -0
- package/src/__tests__/scenario-driven-todo.test.ts +197 -0
- package/src/__tests__/self-improve.test.ts +349 -0
- package/src/__tests__/service-lifecycle.test.ts +237 -0
- package/src/__tests__/skill-router.test.ts +121 -0
- package/src/agents/AgentManifest.ts +493 -0
- package/src/agents/AgentRegistry.ts +475 -0
- package/src/agents/AgentTypes.ts +585 -0
- package/src/agents/AgentWalletRegistry.ts +83 -0
- package/src/agents/AuthenticatedCRDT.ts +388 -0
- package/src/agents/CapabilityMatcher.ts +453 -0
- package/src/agents/CrossRealityHandoff.ts +305 -0
- package/src/agents/CulturalMemory.ts +454 -0
- package/src/agents/FederatedRegistryAdapter.ts +429 -0
- package/src/agents/NormEngine.ts +450 -0
- package/src/agents/OrchestratorAgent.ts +414 -0
- package/src/agents/SkillWorkflowEngine.ts +472 -0
- package/src/agents/TaskDelegationService.ts +551 -0
- package/src/agents/__tests__/AgentManifest.prod.test.ts +134 -0
- package/src/agents/__tests__/AgentManifest.test.ts +182 -0
- package/src/agents/__tests__/AgentModule.test.ts +864 -0
- package/src/agents/__tests__/AgentRegistry.prod.test.ts +125 -0
- package/src/agents/__tests__/AgentRegistry.test.ts +148 -0
- package/src/agents/__tests__/AgentTypes.test.ts +534 -0
- package/src/agents/__tests__/AgentWalletRegistry.test.ts +152 -0
- package/src/agents/__tests__/AuthenticatedCRDT.test.ts +558 -0
- package/src/agents/__tests__/CapabilityMatcher.prod.test.ts +117 -0
- package/src/agents/__tests__/CapabilityMatcher.test.ts +178 -0
- package/src/agents/__tests__/CrossRealityHandoff.test.ts +402 -0
- package/src/agents/__tests__/CulturalMemory.test.ts +200 -0
- package/src/agents/__tests__/FederatedRegistryAdapter.test.ts +409 -0
- package/src/agents/__tests__/NormEngine.test.ts +276 -0
- package/src/agents/__tests__/OrchestratorAgent.test.ts +182 -0
- package/src/agents/__tests__/SkillWorkflowEngine.test.ts +357 -0
- package/src/agents/__tests__/TaskDelegationService.test.ts +446 -0
- package/src/agents/index.ts +107 -0
- package/src/agents/spatial-comms/Layer1RealTime.ts +621 -0
- package/src/agents/spatial-comms/Layer2A2A.ts +661 -0
- package/src/agents/spatial-comms/Layer3MCP.ts +651 -0
- package/src/agents/spatial-comms/ProtocolTypes.ts +543 -0
- package/src/agents/spatial-comms/SpatialCommClient.ts +483 -0
- package/src/agents/spatial-comms/__tests__/performance-benchmark.test.ts +465 -0
- package/src/agents/spatial-comms/examples/multi-agent-world-creation.ts +409 -0
- package/src/agents/spatial-comms/index.ts +66 -0
- package/src/ai/AIAdapter.ts +313 -0
- package/src/ai/AICopilot.ts +331 -0
- package/src/ai/AIOutputValidator.ts +203 -0
- package/src/ai/BTNodes.ts +239 -0
- package/src/ai/BehaviorSelector.ts +135 -0
- package/src/ai/BehaviorTree.ts +153 -0
- package/src/ai/Blackboard.ts +165 -0
- package/src/ai/GenerationAnalytics.ts +461 -0
- package/src/ai/GenerationCache.ts +265 -0
- package/src/ai/GoalPlanner.ts +165 -0
- package/src/ai/HoloScriptGenerator.ts +580 -0
- package/src/ai/InfluenceMap.ts +180 -0
- package/src/ai/NavMesh.ts +168 -0
- package/src/ai/PerceptionSystem.ts +178 -0
- package/src/ai/PromptTemplates.ts +453 -0
- package/src/ai/SemanticSearchService.ts +80 -0
- package/src/ai/StateMachine.ts +196 -0
- package/src/ai/SteeringBehavior.ts +150 -0
- package/src/ai/SteeringBehaviors.ts +244 -0
- package/src/ai/TrainingDataGenerator.ts +1082 -0
- package/src/ai/UtilityAI.ts +145 -0
- package/src/ai/__tests__/AIAdapter.prod.test.ts +259 -0
- package/src/ai/__tests__/AIAdapter.test.ts +109 -0
- package/src/ai/__tests__/AICopilot.prod.test.ts +341 -0
- package/src/ai/__tests__/AICopilot.test.ts +178 -0
- package/src/ai/__tests__/AIOutputValidator.prod.test.ts +226 -0
- package/src/ai/__tests__/AIOutputValidator.test.ts +138 -0
- package/src/ai/__tests__/BTNodes.prod.test.ts +391 -0
- package/src/ai/__tests__/BTNodes.test.ts +263 -0
- package/src/ai/__tests__/BehaviorSelector.prod.test.ts +129 -0
- package/src/ai/__tests__/BehaviorSelector.test.ts +132 -0
- package/src/ai/__tests__/BehaviorTree.prod.test.ts +266 -0
- package/src/ai/__tests__/BehaviorTree.test.ts +216 -0
- package/src/ai/__tests__/Blackboard.prod.test.ts +339 -0
- package/src/ai/__tests__/Blackboard.test.ts +183 -0
- package/src/ai/__tests__/GenerationAnalytics.prod.test.ts +141 -0
- package/src/ai/__tests__/GenerationAnalytics.test.ts +165 -0
- package/src/ai/__tests__/GenerationCache.prod.test.ts +144 -0
- package/src/ai/__tests__/GenerationCache.test.ts +171 -0
- package/src/ai/__tests__/GoalPlanner.prod.test.ts +189 -0
- package/src/ai/__tests__/GoalPlanner.test.ts +137 -0
- package/src/ai/__tests__/GoalPlannerDepth.prod.test.ts +217 -0
- package/src/ai/__tests__/HoloScriptGenerator.test.ts +125 -0
- package/src/ai/__tests__/InfluenceMap.prod.test.ts +146 -0
- package/src/ai/__tests__/InfluenceMap.test.ts +149 -0
- package/src/ai/__tests__/NavMesh.prod.test.ts +141 -0
- package/src/ai/__tests__/NavMesh.test.ts +159 -0
- package/src/ai/__tests__/PerceptionSystem.prod.test.ts +135 -0
- package/src/ai/__tests__/PerceptionSystem.test.ts +250 -0
- package/src/ai/__tests__/PromptTemplates.prod.test.ts +313 -0
- package/src/ai/__tests__/PromptTemplates.test.ts +146 -0
- package/src/ai/__tests__/SemanticSearch.test.ts +37 -0
- package/src/ai/__tests__/StateMachine.prod.test.ts +162 -0
- package/src/ai/__tests__/StateMachine.test.ts +163 -0
- package/src/ai/__tests__/SteeringBehavior.prod.test.ts +251 -0
- package/src/ai/__tests__/SteeringBehavior.test.ts +135 -0
- package/src/ai/__tests__/SteeringBehaviors.prod.test.ts +133 -0
- package/src/ai/__tests__/SteeringBehaviors.test.ts +151 -0
- package/src/ai/__tests__/TrainingDataGenerator.prod.test.ts +286 -0
- package/src/ai/__tests__/TrainingDataGenerator.test.ts +286 -0
- package/src/ai/__tests__/UtilityAI.prod.test.ts +207 -0
- package/src/ai/__tests__/UtilityAI.test.ts +155 -0
- package/src/ai/__tests__/adapters.prod.test.ts +263 -0
- package/src/ai/__tests__/adapters.test.ts +320 -0
- package/src/ai/adapters.ts +1585 -0
- package/src/ai/index.ts +130 -0
- package/src/behavior/BehaviorPresets.ts +140 -0
- package/src/behavior/BehaviorTree.ts +236 -0
- package/src/behavior/StateMachine.ts +176 -0
- package/src/behavior/StateTrait.ts +67 -0
- package/src/behavior/index.ts +8 -0
- package/src/behavior.ts +8 -0
- package/src/board/audit.ts +284 -0
- package/src/board/board-ops.ts +336 -0
- package/src/board/board-types.ts +302 -0
- package/src/board/index.ts +69 -0
- package/src/define-agent.ts +46 -0
- package/src/define-team.ts +33 -0
- package/src/delegation.ts +265 -0
- package/src/distributed-claimer.ts +228 -0
- package/src/economy/AgentBudgetEnforcer.ts +464 -0
- package/src/economy/BountyManager.ts +185 -0
- package/src/economy/CreatorRevenueAggregator.ts +460 -0
- package/src/economy/InvisibleWallet.ts +82 -0
- package/src/economy/KnowledgeMarketplace.ts +193 -0
- package/src/economy/PaymentWebhookService.ts +512 -0
- package/src/economy/RevenueSplitter.ts +156 -0
- package/src/economy/SubscriptionManager.ts +546 -0
- package/src/economy/UnifiedBudgetOptimizer.ts +635 -0
- package/src/economy/UsageMeter.ts +440 -0
- package/src/economy/_core-stubs.ts +219 -0
- package/src/economy/index.ts +100 -0
- package/src/economy/x402-facilitator.ts +1978 -0
- package/src/index.ts +348 -0
- package/src/knowledge/__tests__/knowledge-consolidator.test.ts +444 -0
- package/src/knowledge/__tests__/knowledge-store-vector.test.ts +291 -0
- package/src/knowledge/brain.ts +167 -0
- package/src/knowledge/consolidation.ts +581 -0
- package/src/knowledge/knowledge-consolidator.ts +510 -0
- package/src/knowledge/knowledge-store.ts +616 -0
- package/src/learning/MemoryConsolidator.ts +102 -0
- package/src/learning/MemoryScorer.ts +69 -0
- package/src/learning/ProceduralCompiler.ts +45 -0
- package/src/learning/SemanticClusterer.ts +66 -0
- package/src/learning/index.ts +8 -0
- package/src/llm/llm-adapter.ts +159 -0
- package/src/mesh/index.ts +309 -0
- package/src/negotiation/NegotiationProtocol.ts +694 -0
- package/src/negotiation/NegotiationTypes.ts +473 -0
- package/src/negotiation/VotingMechanisms.ts +691 -0
- package/src/negotiation/index.ts +49 -0
- package/src/protocol/goal-synthesizer.ts +317 -0
- package/src/protocol/implementations.ts +474 -0
- package/src/protocol/micro-phase-decomposer.ts +299 -0
- package/src/protocol/micro-step-decomposer.test.ts +306 -0
- package/src/protocol-agent.test.ts +353 -0
- package/src/protocol-agent.ts +670 -0
- package/src/self-improve/absorb-scanner.ts +252 -0
- package/src/self-improve/evolution-engine.ts +149 -0
- package/src/self-improve/framework-absorber.ts +214 -0
- package/src/self-improve/index.ts +50 -0
- package/src/self-improve/prompt-optimizer.ts +212 -0
- package/src/self-improve/test-generator.ts +175 -0
- package/src/skill-router.ts +186 -0
- package/src/skills/index.ts +5 -0
- package/src/skills/skill-md-bridge.ts +1699 -0
- package/src/swarm/ACOEngine.ts +261 -0
- package/src/swarm/CollectiveIntelligence.ts +383 -0
- package/src/swarm/ContributionSynthesizer.ts +481 -0
- package/src/swarm/LeaderElection.ts +393 -0
- package/src/swarm/PSOEngine.ts +206 -0
- package/src/swarm/QuorumPolicy.ts +173 -0
- package/src/swarm/SwarmCoordinator.ts +335 -0
- package/src/swarm/SwarmManager.ts +442 -0
- package/src/swarm/SwarmMembership.ts +456 -0
- package/src/swarm/VotingRound.ts +255 -0
- package/src/swarm/__tests__/ACOEngine.prod.test.ts +164 -0
- package/src/swarm/__tests__/ACOEngine.test.ts +117 -0
- package/src/swarm/__tests__/CollectiveIntelligence.prod.test.ts +296 -0
- package/src/swarm/__tests__/CollectiveIntelligence.test.ts +457 -0
- package/src/swarm/__tests__/ContributionSynthesizer.prod.test.ts +269 -0
- package/src/swarm/__tests__/ContributionSynthesizer.test.ts +254 -0
- package/src/swarm/__tests__/LeaderElection.prod.test.ts +196 -0
- package/src/swarm/__tests__/LeaderElection.test.ts +151 -0
- package/src/swarm/__tests__/PSOEngine.prod.test.ts +162 -0
- package/src/swarm/__tests__/PSOEngine.test.ts +106 -0
- package/src/swarm/__tests__/QuorumPolicy.prod.test.ts +216 -0
- package/src/swarm/__tests__/QuorumPolicy.test.ts +177 -0
- package/src/swarm/__tests__/SwarmCoordinator.prod.test.ts +186 -0
- package/src/swarm/__tests__/SwarmCoordinator.test.ts +167 -0
- package/src/swarm/__tests__/SwarmManager.prod.test.ts +308 -0
- package/src/swarm/__tests__/SwarmManager.test.ts +373 -0
- package/src/swarm/__tests__/SwarmMembership.prod.test.ts +273 -0
- package/src/swarm/__tests__/SwarmMembership.test.ts +264 -0
- package/src/swarm/__tests__/VotingRound.prod.test.ts +233 -0
- package/src/swarm/__tests__/VotingRound.test.ts +174 -0
- package/src/swarm/analytics/SwarmInspector.ts +476 -0
- package/src/swarm/analytics/SwarmMetrics.ts +449 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.prod.test.ts +366 -0
- package/src/swarm/analytics/__tests__/SwarmInspector.test.ts +454 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.prod.test.ts +254 -0
- package/src/swarm/analytics/__tests__/SwarmMetrics.test.ts +370 -0
- package/src/swarm/analytics/index.ts +7 -0
- package/src/swarm/index.ts +69 -0
- package/src/swarm/messaging/BroadcastChannel.ts +509 -0
- package/src/swarm/messaging/GossipProtocol.ts +565 -0
- package/src/swarm/messaging/SwarmEventBus.ts +443 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.prod.test.ts +331 -0
- package/src/swarm/messaging/__tests__/BroadcastChannel.test.ts +333 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.prod.test.ts +356 -0
- package/src/swarm/messaging/__tests__/GossipProtocol.test.ts +437 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.prod.test.ts +191 -0
- package/src/swarm/messaging/__tests__/SwarmEventBus.test.ts +247 -0
- package/src/swarm/messaging/index.ts +8 -0
- package/src/swarm/spatial/FlockingBehavior.ts +462 -0
- package/src/swarm/spatial/FormationController.ts +500 -0
- package/src/swarm/spatial/Vector3.ts +170 -0
- package/src/swarm/spatial/ZoneClaiming.ts +509 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.prod.test.ts +239 -0
- package/src/swarm/spatial/__tests__/FlockingBehavior.test.ts +298 -0
- package/src/swarm/spatial/__tests__/FormationController.prod.test.ts +240 -0
- package/src/swarm/spatial/__tests__/FormationController.test.ts +297 -0
- package/src/swarm/spatial/__tests__/Vector3.prod.test.ts +283 -0
- package/src/swarm/spatial/__tests__/Vector3.test.ts +224 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.prod.test.ts +246 -0
- package/src/swarm/spatial/__tests__/ZoneClaiming.test.ts +374 -0
- package/src/swarm/spatial/index.ts +28 -0
- package/src/team.ts +1245 -0
- package/src/training/LRScheduler.ts +377 -0
- package/src/training/QualityScoringPipeline.ts +139 -0
- package/src/training/SoftDedup.ts +461 -0
- package/src/training/SparsityMonitor.ts +685 -0
- package/src/training/SparsityMonitorTypes.ts +209 -0
- package/src/training/SpatialTrainingDataGenerator.ts +1526 -0
- package/src/training/SpatialTrainingDataTypes.ts +216 -0
- package/src/training/TrainingPipelineConfig.ts +215 -0
- package/src/training/constants.ts +94 -0
- package/src/training/index.ts +138 -0
- package/src/training/schema.ts +147 -0
- package/src/training/scripts/generate-novel-use-cases-dataset.ts +272 -0
- package/src/training/scripts/generate-spatial-dataset.ts +521 -0
- package/src/training/training/data/novel-use-cases.jsonl +153 -0
- package/src/training/training/data/spatial-reasoning-10k.jsonl +9354 -0
- package/src/training/trainingmonkey/TrainingMonkeyIntegration.ts +477 -0
- package/src/training/trainingmonkey/TrainingMonkeyTypes.ts +230 -0
- package/src/training/trainingmonkey/index.ts +26 -0
- package/src/training/trait-mappings.ts +157 -0
- package/src/types/core-stubs.d.ts +113 -0
- package/src/types.ts +304 -0
- package/test-output.txt +0 -0
- package/test-result.json +1 -0
- package/tsc-errors.txt +4 -0
- package/tsc_output.txt +0 -0
- package/tsconfig.json +14 -0
- package/tsup-learning-esm.config.ts +12 -0
- package/tsup.config.ts +21 -0
- package/typescript-errors-2.txt +0 -0
- package/typescript-errors.txt +22 -0
- package/vitest-log-utf8.txt +268 -0
- package/vitest-log.txt +0 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import { T as TelemetryCollector, R as ResourceCategory, a as ResourceUsageNode } from '../InvisibleWallet-rtRrBOA8.js';
|
|
2
|
+
export { B as Bounty, b as BountyCurrency, c as BountyManager, d as BountyManagerConfig, e as BountyReward, f as BountyStatus, C as CHAIN_IDS, g as CHAIN_ID_TO_NETWORK, h as ClaimResult, i as CompletionProof, j as CreatorEarnings, k as CreatorRevenueAggregator, l as CreditTraitConfig, I as InvisibleWalletStub, K as KnowledgeListing, m as KnowledgeMarketplace, L as LedgerEntry, n as ListingResult, o as ListingStatus, M as MICRO_PAYMENT_THRESHOLD, p as MicroPaymentLedger, P as PaymentGateway, q as PaymentScheme, r as PaymentWebhookService, s as PayoutRecord, t as PayoutResult, u as PluginRevenue, v as PricingFactors, w as PurchaseResult, x as RefundRequest, y as RefundResult, z as RevenueAggregatorConfig, A as RevenueEvent, D as RevenuePeriod, E as RevenueSplitter, S as SettlementChain, F as SettlementEvent, G as SettlementEventListener, H as SettlementEventType, J as SettlementMode, N as SplitBreakdownEntry, O as SplitRecipient, Q as SplitResult, U as USDC_CONTRACTS, V as WalletConfig, W as WalletHexAddress, X as WalletInfo, Y as WebhookEventType, Z as WebhookHandler, _ as WebhookPayload, $ as WebhookProcessingResult, a0 as WebhookProvider, a1 as WebhookServiceConfig, a2 as WebhookVerificationResult, a3 as X402Facilitator, a4 as X402FacilitatorConfig, a5 as X402PaymentOption, a6 as X402PaymentPayload, a7 as X402PaymentRequired, a8 as X402SettlementResult, a9 as X402VerificationResult, aa as X402_VERSION, ab as creditTraitHandler } from '../InvisibleWallet-rtRrBOA8.js';
|
|
3
|
+
import '../implementations-D9T3un9D.js';
|
|
4
|
+
import '@holoscript/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SubscriptionManager — Recurring subscription lifecycle management
|
|
8
|
+
*
|
|
9
|
+
* Manages subscription states: create → renew → cancel → suspend → reactivate.
|
|
10
|
+
* Supports trial periods, grace periods on failed renewal, and links to
|
|
11
|
+
* X402PaymentGateway for recurring authorization.
|
|
12
|
+
*
|
|
13
|
+
* Part of HoloScript v5.8 "Live Economy".
|
|
14
|
+
*
|
|
15
|
+
* @version 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Subscription lifecycle state.
|
|
20
|
+
*/
|
|
21
|
+
type SubscriptionState = 'trial' | 'active' | 'past_due' | 'suspended' | 'cancelled' | 'expired';
|
|
22
|
+
/**
|
|
23
|
+
* Billing interval.
|
|
24
|
+
*/
|
|
25
|
+
type BillingInterval = 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
26
|
+
/**
|
|
27
|
+
* A subscription record.
|
|
28
|
+
*/
|
|
29
|
+
interface Subscription {
|
|
30
|
+
/** Unique subscription ID */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Subscriber (agent or user) ID */
|
|
33
|
+
subscriberId: string;
|
|
34
|
+
/** Plan ID */
|
|
35
|
+
planId: string;
|
|
36
|
+
/** Current state */
|
|
37
|
+
state: SubscriptionState;
|
|
38
|
+
/** Billing amount per period (USDC base units, 6 decimals) */
|
|
39
|
+
amount: number;
|
|
40
|
+
/** Billing interval */
|
|
41
|
+
interval: BillingInterval;
|
|
42
|
+
/** When the subscription was created (ISO 8601) */
|
|
43
|
+
createdAt: string;
|
|
44
|
+
/** Current period start (ISO 8601) */
|
|
45
|
+
currentPeriodStart: string;
|
|
46
|
+
/** Current period end (ISO 8601) */
|
|
47
|
+
currentPeriodEnd: string;
|
|
48
|
+
/** Trial end date (ISO 8601, null if no trial) */
|
|
49
|
+
trialEnd: string | null;
|
|
50
|
+
/** Whether currently in trial */
|
|
51
|
+
inTrial: boolean;
|
|
52
|
+
/** Number of failed renewal attempts */
|
|
53
|
+
failedRenewals: number;
|
|
54
|
+
/** Grace period end (ISO 8601, null if not in grace period) */
|
|
55
|
+
gracePeriodEnd: string | null;
|
|
56
|
+
/** When cancelled (ISO 8601, null if not cancelled) */
|
|
57
|
+
cancelledAt: string | null;
|
|
58
|
+
/** Cancel at period end (vs immediate) */
|
|
59
|
+
cancelAtPeriodEnd: boolean;
|
|
60
|
+
/** Metadata */
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Subscription plan definition.
|
|
65
|
+
*/
|
|
66
|
+
interface SubscriptionPlan {
|
|
67
|
+
/** Plan ID */
|
|
68
|
+
id: string;
|
|
69
|
+
/** Plan name */
|
|
70
|
+
name: string;
|
|
71
|
+
/** Plan description */
|
|
72
|
+
description: string;
|
|
73
|
+
/** Billing amount per period (USDC base units) */
|
|
74
|
+
amount: number;
|
|
75
|
+
/** Billing interval */
|
|
76
|
+
interval: BillingInterval;
|
|
77
|
+
/** Trial duration in days (0 = no trial) */
|
|
78
|
+
trialDays: number;
|
|
79
|
+
/** Features included */
|
|
80
|
+
features: string[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* SubscriptionManager configuration.
|
|
84
|
+
*/
|
|
85
|
+
interface SubscriptionManagerConfig {
|
|
86
|
+
/** Grace period duration in days (default: 3) */
|
|
87
|
+
gracePeriodDays?: number;
|
|
88
|
+
/** Maximum failed renewals before suspension (default: 3) */
|
|
89
|
+
maxFailedRenewals?: number;
|
|
90
|
+
/** Telemetry collector */
|
|
91
|
+
telemetry?: TelemetryCollector;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Renewal result.
|
|
95
|
+
*/
|
|
96
|
+
interface RenewalResult {
|
|
97
|
+
/** Whether renewal succeeded */
|
|
98
|
+
success: boolean;
|
|
99
|
+
/** Updated subscription */
|
|
100
|
+
subscription: Subscription;
|
|
101
|
+
/** Error message if failed */
|
|
102
|
+
error?: string;
|
|
103
|
+
/** Whether grace period was entered */
|
|
104
|
+
enteredGracePeriod?: boolean;
|
|
105
|
+
}
|
|
106
|
+
declare class SubscriptionManager {
|
|
107
|
+
private config;
|
|
108
|
+
private subscriptions;
|
|
109
|
+
private plans;
|
|
110
|
+
private renewalCallback?;
|
|
111
|
+
private subCounter;
|
|
112
|
+
constructor(config?: SubscriptionManagerConfig);
|
|
113
|
+
/**
|
|
114
|
+
* Register a subscription plan.
|
|
115
|
+
*/
|
|
116
|
+
registerPlan(plan: SubscriptionPlan): void;
|
|
117
|
+
/**
|
|
118
|
+
* Get a plan by ID.
|
|
119
|
+
*/
|
|
120
|
+
getPlan(planId: string): SubscriptionPlan | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* List all plans.
|
|
123
|
+
*/
|
|
124
|
+
listPlans(): SubscriptionPlan[];
|
|
125
|
+
/**
|
|
126
|
+
* Create a new subscription.
|
|
127
|
+
*/
|
|
128
|
+
create(subscriberId: string, planId: string, metadata?: Record<string, unknown>): Subscription;
|
|
129
|
+
/**
|
|
130
|
+
* Attempt to renew a subscription.
|
|
131
|
+
*/
|
|
132
|
+
renew(subscriptionId: string): Promise<RenewalResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Cancel a subscription.
|
|
135
|
+
* @param immediate If true, cancel immediately; otherwise cancel at period end.
|
|
136
|
+
*/
|
|
137
|
+
cancel(subscriptionId: string, immediate?: boolean): Subscription;
|
|
138
|
+
/**
|
|
139
|
+
* Suspend a subscription (e.g., after payment failures).
|
|
140
|
+
*/
|
|
141
|
+
suspend(subscriptionId: string): Subscription;
|
|
142
|
+
/**
|
|
143
|
+
* Reactivate a suspended or cancelled subscription.
|
|
144
|
+
*/
|
|
145
|
+
reactivate(subscriptionId: string): Subscription;
|
|
146
|
+
/**
|
|
147
|
+
* Set callback for renewal payment processing.
|
|
148
|
+
* Should return true if payment succeeded.
|
|
149
|
+
*/
|
|
150
|
+
onRenewal(callback: (subscriptionId: string, amount: number) => Promise<boolean>): void;
|
|
151
|
+
/**
|
|
152
|
+
* Get a subscription by ID.
|
|
153
|
+
*/
|
|
154
|
+
getSubscription(id: string): Subscription | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Get all subscriptions for a subscriber.
|
|
157
|
+
*/
|
|
158
|
+
getSubscriberSubscriptions(subscriberId: string): Subscription[];
|
|
159
|
+
/**
|
|
160
|
+
* Get subscriptions by state.
|
|
161
|
+
*/
|
|
162
|
+
getByState(state: SubscriptionState): Subscription[];
|
|
163
|
+
/**
|
|
164
|
+
* Get subscriptions due for renewal.
|
|
165
|
+
*/
|
|
166
|
+
getDueForRenewal(): Subscription[];
|
|
167
|
+
/**
|
|
168
|
+
* Get subscriptions in grace period.
|
|
169
|
+
*/
|
|
170
|
+
getInGracePeriod(): Subscription[];
|
|
171
|
+
/**
|
|
172
|
+
* Check if grace period has expired for past_due subscriptions.
|
|
173
|
+
*/
|
|
174
|
+
processExpiredGracePeriods(): Subscription[];
|
|
175
|
+
/**
|
|
176
|
+
* Get stats.
|
|
177
|
+
*/
|
|
178
|
+
getStats(): {
|
|
179
|
+
total: number;
|
|
180
|
+
byState: Record<string, number>;
|
|
181
|
+
totalMRR: number;
|
|
182
|
+
planCount: number;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Total subscription count.
|
|
186
|
+
*/
|
|
187
|
+
getSubscriptionCount(): number;
|
|
188
|
+
private requireSubscription;
|
|
189
|
+
private computePeriodEnd;
|
|
190
|
+
private normalizeToMonthly;
|
|
191
|
+
private emitTelemetry;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* AgentBudgetEnforcer — Per-agent budget caps with enforcement
|
|
196
|
+
*
|
|
197
|
+
* Tracks spending per agent with configurable enforcement modes
|
|
198
|
+
* (warn, soft, hard) and budget periods. Includes circuit breaker
|
|
199
|
+
* for consecutive failures or overspend.
|
|
200
|
+
*
|
|
201
|
+
* Part of HoloScript v5.8 "Live Economy".
|
|
202
|
+
*
|
|
203
|
+
* @version 1.0.0
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Enforcement mode for budget limits.
|
|
208
|
+
*/
|
|
209
|
+
type EnforcementMode = 'warn' | 'soft' | 'hard';
|
|
210
|
+
/**
|
|
211
|
+
* Budget period type.
|
|
212
|
+
*/
|
|
213
|
+
type BudgetPeriod = 'per-request' | 'per-session' | 'daily' | 'monthly';
|
|
214
|
+
/**
|
|
215
|
+
* Budget configuration for an agent.
|
|
216
|
+
*/
|
|
217
|
+
interface AgentBudget {
|
|
218
|
+
/** Agent ID */
|
|
219
|
+
agentId: string;
|
|
220
|
+
/** Maximum spend per period (USDC base units, 6 decimals) */
|
|
221
|
+
maxSpend: number;
|
|
222
|
+
/** Budget period */
|
|
223
|
+
period: BudgetPeriod;
|
|
224
|
+
/** Enforcement mode */
|
|
225
|
+
mode: EnforcementMode;
|
|
226
|
+
/** Warning threshold (fraction 0-1, e.g. 0.8 = warn at 80%) */
|
|
227
|
+
warnThreshold?: number;
|
|
228
|
+
/** Circuit breaker: max consecutive failures before tripping */
|
|
229
|
+
circuitBreakerThreshold?: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Current budget state for an agent.
|
|
233
|
+
*/
|
|
234
|
+
interface BudgetState {
|
|
235
|
+
/** Agent ID */
|
|
236
|
+
agentId: string;
|
|
237
|
+
/** Amount spent in current period (USDC base units) */
|
|
238
|
+
spent: number;
|
|
239
|
+
/** Budget limit (USDC base units) */
|
|
240
|
+
limit: number;
|
|
241
|
+
/** Budget remaining (USDC base units) */
|
|
242
|
+
remaining: number;
|
|
243
|
+
/** Whether budget is exhausted */
|
|
244
|
+
exhausted: boolean;
|
|
245
|
+
/** Whether warning threshold is reached */
|
|
246
|
+
warning: boolean;
|
|
247
|
+
/** Current enforcement mode */
|
|
248
|
+
mode: EnforcementMode;
|
|
249
|
+
/** Current period */
|
|
250
|
+
period: BudgetPeriod;
|
|
251
|
+
/** Period start (ISO 8601) */
|
|
252
|
+
periodStart: string;
|
|
253
|
+
/** Number of requests in this period */
|
|
254
|
+
requestCount: number;
|
|
255
|
+
/** Circuit breaker state */
|
|
256
|
+
circuitBreaker: CircuitBreakerState;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Circuit breaker state.
|
|
260
|
+
*/
|
|
261
|
+
interface CircuitBreakerState {
|
|
262
|
+
/** Whether the circuit breaker is open (tripped) */
|
|
263
|
+
isOpen: boolean;
|
|
264
|
+
/** Consecutive failure count */
|
|
265
|
+
consecutiveFailures: number;
|
|
266
|
+
/** Maximum consecutive failures */
|
|
267
|
+
threshold: number;
|
|
268
|
+
/** When the circuit breaker was tripped (ISO 8601, null if not tripped) */
|
|
269
|
+
trippedAt: string | null;
|
|
270
|
+
/** When the circuit breaker will reset (ISO 8601, null if not tripped) */
|
|
271
|
+
resetAt: string | null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Result of a spend authorization check.
|
|
275
|
+
*/
|
|
276
|
+
interface SpendAuthorizationResult {
|
|
277
|
+
/** Whether the spend is authorized */
|
|
278
|
+
authorized: boolean;
|
|
279
|
+
/** Reason for denial */
|
|
280
|
+
reason?: string;
|
|
281
|
+
/** Current budget state */
|
|
282
|
+
state: BudgetState;
|
|
283
|
+
/** Whether this is a warning (authorized but near limit) */
|
|
284
|
+
warning?: boolean;
|
|
285
|
+
/** Warning message */
|
|
286
|
+
warningMessage?: string;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* AgentBudgetEnforcer configuration.
|
|
290
|
+
*/
|
|
291
|
+
interface BudgetEnforcerConfig {
|
|
292
|
+
/** Default budget for agents without explicit config */
|
|
293
|
+
defaultBudget?: Partial<AgentBudget>;
|
|
294
|
+
/** Circuit breaker reset timeout (ms, default: 60s) */
|
|
295
|
+
circuitBreakerResetMs?: number;
|
|
296
|
+
/** Telemetry collector */
|
|
297
|
+
telemetry?: TelemetryCollector;
|
|
298
|
+
}
|
|
299
|
+
declare class AgentBudgetEnforcer {
|
|
300
|
+
private trackers;
|
|
301
|
+
private config;
|
|
302
|
+
private sessionCounter;
|
|
303
|
+
constructor(config?: BudgetEnforcerConfig);
|
|
304
|
+
/**
|
|
305
|
+
* Set budget for an agent.
|
|
306
|
+
*/
|
|
307
|
+
setBudget(budget: AgentBudget): void;
|
|
308
|
+
/**
|
|
309
|
+
* Get budget configuration for an agent.
|
|
310
|
+
*/
|
|
311
|
+
getBudget(agentId: string): AgentBudget | undefined;
|
|
312
|
+
/**
|
|
313
|
+
* Remove budget for an agent.
|
|
314
|
+
*/
|
|
315
|
+
removeBudget(agentId: string): boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Check if an agent is authorized to spend a given amount.
|
|
318
|
+
*/
|
|
319
|
+
authorize(agentId: string, amount: number): SpendAuthorizationResult;
|
|
320
|
+
/**
|
|
321
|
+
* Record a spend. Call after a successful tool execution.
|
|
322
|
+
*/
|
|
323
|
+
recordSpend(agentId: string, amount: number): void;
|
|
324
|
+
/**
|
|
325
|
+
* Record a failure. Increments circuit breaker counter.
|
|
326
|
+
*/
|
|
327
|
+
recordFailure(agentId: string): void;
|
|
328
|
+
/**
|
|
329
|
+
* Get current budget state for an agent.
|
|
330
|
+
*/
|
|
331
|
+
getState(agentId: string): BudgetState | undefined;
|
|
332
|
+
/**
|
|
333
|
+
* Get all agent budget states.
|
|
334
|
+
*/
|
|
335
|
+
getAllStates(): BudgetState[];
|
|
336
|
+
/**
|
|
337
|
+
* Get agents that are over budget.
|
|
338
|
+
*/
|
|
339
|
+
getOverBudgetAgents(): BudgetState[];
|
|
340
|
+
/**
|
|
341
|
+
* Reset an agent's period spending.
|
|
342
|
+
*/
|
|
343
|
+
resetSpending(agentId: string): void;
|
|
344
|
+
/**
|
|
345
|
+
* Reset circuit breaker for an agent.
|
|
346
|
+
*/
|
|
347
|
+
resetCircuitBreaker(agentId: string): void;
|
|
348
|
+
private getOrCreateTracker;
|
|
349
|
+
private checkPeriodReset;
|
|
350
|
+
private buildState;
|
|
351
|
+
private emitTelemetry;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* UnifiedBudgetOptimizer — Bridges Economy and Rendering Budgets
|
|
356
|
+
*
|
|
357
|
+
* Oracle Cycle 6 identified that AgentBudgetEnforcer (1D USDC, hard stop)
|
|
358
|
+
* and ResourceBudgetAnalyzer (10D resources, graceful LOD degradation)
|
|
359
|
+
* solve the same optimization problem with zero shared abstractions.
|
|
360
|
+
*
|
|
361
|
+
* This module provides:
|
|
362
|
+
* 1. Trait Utility Function — value per resource cost (enables optimization)
|
|
363
|
+
* 2. Equimarginal LOD Allocation — drop by lowest value/cost ratio, not greedy
|
|
364
|
+
* 3. Resource Cost Floor Pricing — prevents economic denial-of-rendering
|
|
365
|
+
* 4. Unified budget query — single view of both economy + rendering pressure
|
|
366
|
+
*
|
|
367
|
+
* @version 1.0.0
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Trait utility entry — encodes how much value a trait provides per unit cost.
|
|
372
|
+
* Higher utility = keep this trait when budgets are tight.
|
|
373
|
+
*/
|
|
374
|
+
interface TraitUtility {
|
|
375
|
+
/** Trait name (e.g., '@particle', '@gaussian') */
|
|
376
|
+
trait: string;
|
|
377
|
+
/** Base utility score (0-100, higher = more valuable to the experience) */
|
|
378
|
+
baseUtility: number;
|
|
379
|
+
/** Category for grouping (visual, physics, audio, network, ai) */
|
|
380
|
+
category: TraitCategory;
|
|
381
|
+
/** Whether this trait is required (cannot be dropped by LOD) */
|
|
382
|
+
required: boolean;
|
|
383
|
+
/** LOD level at which this trait can start being dropped (0 = never) */
|
|
384
|
+
minLODLevel: number;
|
|
385
|
+
}
|
|
386
|
+
type TraitCategory = 'visual' | 'physics' | 'audio' | 'network' | 'ai' | 'interaction';
|
|
387
|
+
/**
|
|
388
|
+
* Allocation decision for a single trait.
|
|
389
|
+
*/
|
|
390
|
+
interface TraitAllocation {
|
|
391
|
+
/** Trait name */
|
|
392
|
+
trait: string;
|
|
393
|
+
/** Whether to include this trait at current budget level */
|
|
394
|
+
included: boolean;
|
|
395
|
+
/** LOD level applied (0 = full detail) */
|
|
396
|
+
lodLevel: number;
|
|
397
|
+
/** Resource cost at current LOD */
|
|
398
|
+
resourceCost: Partial<Record<ResourceCategory, number>>;
|
|
399
|
+
/** Economic cost (USDC base units, 0 if no marketplace price) */
|
|
400
|
+
economicCost: number;
|
|
401
|
+
/** Computed utility score */
|
|
402
|
+
utility: number;
|
|
403
|
+
/** Value/cost ratio used for allocation decisions */
|
|
404
|
+
valueCostRatio: number;
|
|
405
|
+
/** Reason for exclusion if not included */
|
|
406
|
+
excludeReason?: string;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Resource cost floor for marketplace pricing.
|
|
410
|
+
* Prevents a 1-credit trait from consuming 10K gaussians.
|
|
411
|
+
*/
|
|
412
|
+
interface ResourceCostFloor {
|
|
413
|
+
/** Minimum price per unit of resource consumed */
|
|
414
|
+
perGaussian: number;
|
|
415
|
+
/** Minimum price per draw call */
|
|
416
|
+
perDrawCall: number;
|
|
417
|
+
/** Minimum price per MB memory */
|
|
418
|
+
perMemoryMB: number;
|
|
419
|
+
/** Minimum price per particle */
|
|
420
|
+
perParticle: number;
|
|
421
|
+
/** Minimum price per physics body */
|
|
422
|
+
perPhysicsBody: number;
|
|
423
|
+
/** Base platform fee (USDC base units) */
|
|
424
|
+
baseFee: number;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Unified budget state — single view across economy + rendering.
|
|
428
|
+
*/
|
|
429
|
+
interface UnifiedBudgetState {
|
|
430
|
+
/** Agent ID */
|
|
431
|
+
agentId: string;
|
|
432
|
+
/** Economic pressure (0-1, where 1 = budget exhausted) */
|
|
433
|
+
economicPressure: number;
|
|
434
|
+
/** Resource pressure per category (0-1) */
|
|
435
|
+
resourcePressure: Partial<Record<ResourceCategory, number>>;
|
|
436
|
+
/** Overall pressure (max of economic and worst resource) */
|
|
437
|
+
overallPressure: number;
|
|
438
|
+
/** Suggested LOD level based on combined pressure */
|
|
439
|
+
suggestedLOD: number;
|
|
440
|
+
/** Whether any hard limit is breached */
|
|
441
|
+
hardLimitBreached: boolean;
|
|
442
|
+
/** Traits that should be shed to relieve pressure */
|
|
443
|
+
shedCandidates: TraitAllocation[];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Configuration for the unified optimizer.
|
|
447
|
+
*/
|
|
448
|
+
interface UnifiedOptimizerConfig {
|
|
449
|
+
/** Target platform for resource limits */
|
|
450
|
+
platform: string;
|
|
451
|
+
/** Resource cost floor for marketplace pricing */
|
|
452
|
+
costFloor: ResourceCostFloor;
|
|
453
|
+
/** Custom trait utilities (override defaults) */
|
|
454
|
+
traitUtilities?: Map<string, TraitUtility>;
|
|
455
|
+
/** LOD scaling factors — how much resource cost reduces per LOD level */
|
|
456
|
+
lodScaling?: number[];
|
|
457
|
+
/** Economic budget limit (USDC base units, 0 = no limit) */
|
|
458
|
+
economicBudget?: number;
|
|
459
|
+
/** Economic spend so far (USDC base units) */
|
|
460
|
+
economicSpent?: number;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Default utility scores for common traits.
|
|
464
|
+
* These encode "how much does this trait contribute to the experience?"
|
|
465
|
+
*
|
|
466
|
+
* Scoring guide:
|
|
467
|
+
* - 90-100: Core experience (mesh, material, physics) — never drop
|
|
468
|
+
* - 70-89: Important visual/audio quality (lighting, particles)
|
|
469
|
+
* - 50-69: Enhancement (volumetric, VFX, spatial audio)
|
|
470
|
+
* - 30-49: Nice-to-have (reflections, subsurface, ambisonics)
|
|
471
|
+
* - 10-29: Luxury (ray tracing, global illumination, neural rendering)
|
|
472
|
+
*/
|
|
473
|
+
declare const DEFAULT_TRAIT_UTILITIES: Record<string, Omit<TraitUtility, 'trait'>>;
|
|
474
|
+
/**
|
|
475
|
+
* Default resource cost floor pricing.
|
|
476
|
+
* Prevents marketplace traits from being priced below their GPU cost.
|
|
477
|
+
* Prices in USDC base units (6 decimals, so 1_000_000 = $1.00).
|
|
478
|
+
*/
|
|
479
|
+
/**
|
|
480
|
+
* Platform-specific LOD scaling curves.
|
|
481
|
+
*
|
|
482
|
+
* C6 Layer 2 finding: platform exchange rates are wildly non-uniform (25x
|
|
483
|
+
* price difference for a single @particle between Mobile AR and Desktop VR).
|
|
484
|
+
* A uniform LOD curve means constrained platforms over-degrade while powerful
|
|
485
|
+
* platforms under-utilize. Each platform gets its own perceptual curve.
|
|
486
|
+
*
|
|
487
|
+
* Constrained platforms (mobile_ar, quest3) degrade faster at LOD 1-2.
|
|
488
|
+
* Powerful platforms (desktop-vr) degrade slowly, preserving quality.
|
|
489
|
+
*/
|
|
490
|
+
declare const PLATFORM_LOD_SCALING: Record<string, number[]>;
|
|
491
|
+
/**
|
|
492
|
+
* Default resource cost floor pricing.
|
|
493
|
+
* Prevents marketplace traits from being priced below their GPU cost.
|
|
494
|
+
* Prices in USDC base units (6 decimals, so 1_000_000 = $1.00).
|
|
495
|
+
*/
|
|
496
|
+
declare const DEFAULT_COST_FLOOR: ResourceCostFloor;
|
|
497
|
+
/**
|
|
498
|
+
* Default LOD scaling: how much resource usage decreases per LOD level.
|
|
499
|
+
*
|
|
500
|
+
* Previous geometric scaling [1.0, 0.5, 0.25, 0.1, 0.05] over-degrades
|
|
501
|
+
* the visible mid-range (LOD 1-2). Human perception follows Weber-Fechner
|
|
502
|
+
* (logarithmic), meaning a 50% reduction at LOD 1 is far more noticeable
|
|
503
|
+
* than a 50% reduction at LOD 3.
|
|
504
|
+
*
|
|
505
|
+
* Perceptual curve: each step reduces quality by an amount proportional
|
|
506
|
+
* to the *perceived* difference, not the geometric ratio.
|
|
507
|
+
* LOD 0 = 1.0 (full), LOD 1 = 0.7, LOD 2 = 0.4, LOD 3 = 0.18, LOD 4 = 0.06
|
|
508
|
+
*
|
|
509
|
+
* This preserves more detail in the visually sensitive mid-range while
|
|
510
|
+
* still achieving aggressive reduction at far distances.
|
|
511
|
+
*/
|
|
512
|
+
declare const DEFAULT_LOD_SCALING: number[];
|
|
513
|
+
declare class UnifiedBudgetOptimizer {
|
|
514
|
+
private platform;
|
|
515
|
+
private costFloor;
|
|
516
|
+
private traitUtilities;
|
|
517
|
+
private lodScaling;
|
|
518
|
+
private economicBudget;
|
|
519
|
+
private economicSpent;
|
|
520
|
+
constructor(config: UnifiedOptimizerConfig);
|
|
521
|
+
/**
|
|
522
|
+
* Allocate traits across a resource budget using the equimarginal principle.
|
|
523
|
+
* Instead of greedily dropping the deepest LOD first, this sorts by value/cost
|
|
524
|
+
* ratio and drops traits with the lowest marginal utility first.
|
|
525
|
+
*
|
|
526
|
+
* @param nodes - Resource usage nodes (traits + counts)
|
|
527
|
+
* @param maxLOD - Maximum LOD level to consider (default: 4)
|
|
528
|
+
* @returns Allocation decisions for each trait
|
|
529
|
+
*/
|
|
530
|
+
allocate(nodes: ResourceUsageNode[], maxLOD?: number): TraitAllocation[];
|
|
531
|
+
/**
|
|
532
|
+
* Calculate the minimum marketplace price for a trait based on its resource cost.
|
|
533
|
+
* Prevents economic denial-of-rendering attacks where a cheap marketplace trait
|
|
534
|
+
* consumes massive GPU resources.
|
|
535
|
+
*
|
|
536
|
+
* @param traitName - The trait to price
|
|
537
|
+
* @param instanceCount - How many instances (default: 1)
|
|
538
|
+
* @returns Minimum price in USDC base units (6 decimals)
|
|
539
|
+
*/
|
|
540
|
+
calculateCostFloor(traitName: string, instanceCount?: number): number;
|
|
541
|
+
/**
|
|
542
|
+
* Validate that a marketplace listing price meets the resource cost floor.
|
|
543
|
+
*
|
|
544
|
+
* @param traitName - The trait being listed
|
|
545
|
+
* @param listPrice - Proposed listing price (USDC base units)
|
|
546
|
+
* @param instanceCount - Expected instance count
|
|
547
|
+
* @returns Validation result
|
|
548
|
+
*/
|
|
549
|
+
validateMarketplacePrice(traitName: string, listPrice: number, instanceCount?: number): {
|
|
550
|
+
valid: boolean;
|
|
551
|
+
floor: number;
|
|
552
|
+
deficit: number;
|
|
553
|
+
message: string;
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Get a unified view of budget pressure across economy + rendering.
|
|
557
|
+
*
|
|
558
|
+
* @param agentId - Agent identifier
|
|
559
|
+
* @param nodes - Current resource usage nodes
|
|
560
|
+
* @param economicSpent - Current economic spend (USDC base units)
|
|
561
|
+
* @param economicLimit - Economic budget limit (USDC base units)
|
|
562
|
+
* @returns Unified budget state
|
|
563
|
+
*/
|
|
564
|
+
getUnifiedState(agentId: string, nodes: ResourceUsageNode[], economicSpent?: number, economicLimit?: number): UnifiedBudgetState;
|
|
565
|
+
/**
|
|
566
|
+
* Get the utility score for a trait.
|
|
567
|
+
*/
|
|
568
|
+
getUtility(traitName: string): TraitUtility | undefined;
|
|
569
|
+
/**
|
|
570
|
+
* Set custom utility for a trait.
|
|
571
|
+
*/
|
|
572
|
+
setUtility(utility: TraitUtility): void;
|
|
573
|
+
/**
|
|
574
|
+
* Get the total weighted resource cost of a trait at a given LOD level.
|
|
575
|
+
* Collapses multi-dimensional resource cost into a single scalar
|
|
576
|
+
* using platform limits as normalization weights.
|
|
577
|
+
*/
|
|
578
|
+
getWeightedCost(traitName: string, lodLevel?: number, instanceCount?: number): number;
|
|
579
|
+
/**
|
|
580
|
+
* Compute value/cost ratio for a trait at a given LOD level.
|
|
581
|
+
* Higher = more efficient use of resources.
|
|
582
|
+
*/
|
|
583
|
+
getValueCostRatio(traitName: string, lodLevel?: number, instanceCount?: number): number;
|
|
584
|
+
private flattenToAllocations;
|
|
585
|
+
private buildAllocation;
|
|
586
|
+
private isRequired;
|
|
587
|
+
private canDropAtLOD;
|
|
588
|
+
private computeResourcePressure;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* UsageMeter — Per-tool-call cost tracking and aggregation
|
|
593
|
+
*
|
|
594
|
+
* Tracks usage across agents, tools, and time periods.
|
|
595
|
+
* Supports free-tier allowances and paid overage tracking.
|
|
596
|
+
*
|
|
597
|
+
* Part of HoloScript v5.8 "Live Economy".
|
|
598
|
+
*
|
|
599
|
+
* @version 1.0.0
|
|
600
|
+
*/
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Aggregation period for usage data.
|
|
604
|
+
*/
|
|
605
|
+
type UsagePeriod = 'hourly' | 'daily' | 'monthly';
|
|
606
|
+
/**
|
|
607
|
+
* A single usage event.
|
|
608
|
+
*/
|
|
609
|
+
interface UsageEvent {
|
|
610
|
+
/** Unique event ID */
|
|
611
|
+
id: string;
|
|
612
|
+
/** Agent that made the call */
|
|
613
|
+
agentId: string;
|
|
614
|
+
/** Tool that was called */
|
|
615
|
+
toolId: string;
|
|
616
|
+
/** Cost in USDC base units (6 decimals) */
|
|
617
|
+
cost: number;
|
|
618
|
+
/** Timestamp (ms since epoch) */
|
|
619
|
+
timestamp: number;
|
|
620
|
+
/** Whether this falls under free tier */
|
|
621
|
+
freeTier: boolean;
|
|
622
|
+
/** Additional metadata */
|
|
623
|
+
metadata?: Record<string, unknown>;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Aggregated usage for a specific dimension.
|
|
627
|
+
*/
|
|
628
|
+
interface UsageAggregate {
|
|
629
|
+
/** Total number of calls */
|
|
630
|
+
totalCalls: number;
|
|
631
|
+
/** Total cost in USDC base units */
|
|
632
|
+
totalCost: number;
|
|
633
|
+
/** Free-tier calls */
|
|
634
|
+
freeTierCalls: number;
|
|
635
|
+
/** Free-tier cost (not charged) */
|
|
636
|
+
freeTierCost: number;
|
|
637
|
+
/** Paid calls */
|
|
638
|
+
paidCalls: number;
|
|
639
|
+
/** Paid cost (actually charged) */
|
|
640
|
+
paidCost: number;
|
|
641
|
+
/** Period start (ISO 8601) */
|
|
642
|
+
periodStart: string;
|
|
643
|
+
/** Period end (ISO 8601) */
|
|
644
|
+
periodEnd: string;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Usage summary for an agent.
|
|
648
|
+
*/
|
|
649
|
+
interface AgentUsageSummary {
|
|
650
|
+
/** Agent ID */
|
|
651
|
+
agentId: string;
|
|
652
|
+
/** Per-tool usage breakdown */
|
|
653
|
+
byTool: Map<string, UsageAggregate>;
|
|
654
|
+
/** Total across all tools */
|
|
655
|
+
total: UsageAggregate;
|
|
656
|
+
/** Free-tier remaining allowance */
|
|
657
|
+
freeTierRemaining: number;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Free-tier configuration.
|
|
661
|
+
*/
|
|
662
|
+
interface FreeTierConfig {
|
|
663
|
+
/** Monthly free-tier allowance in USDC base units */
|
|
664
|
+
monthlyAllowance: number;
|
|
665
|
+
/** Per-tool overrides */
|
|
666
|
+
toolOverrides?: Record<string, number>;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* UsageMeter configuration.
|
|
670
|
+
*/
|
|
671
|
+
interface UsageMeterConfig {
|
|
672
|
+
/** Free-tier configuration */
|
|
673
|
+
freeTier?: FreeTierConfig;
|
|
674
|
+
/** Default cost per tool call (USDC base units) */
|
|
675
|
+
defaultToolCost?: number;
|
|
676
|
+
/** Per-tool cost overrides */
|
|
677
|
+
toolCosts?: Record<string, number>;
|
|
678
|
+
/** Maximum events to retain per agent */
|
|
679
|
+
maxEventsPerAgent?: number;
|
|
680
|
+
/** Telemetry collector */
|
|
681
|
+
telemetry?: TelemetryCollector;
|
|
682
|
+
}
|
|
683
|
+
declare class UsageMeter {
|
|
684
|
+
private config;
|
|
685
|
+
/** All usage events keyed by agentId */
|
|
686
|
+
private events;
|
|
687
|
+
/** Free-tier consumption per agent (monthly, USDC base units) */
|
|
688
|
+
private freeTierUsed;
|
|
689
|
+
/** Current month key for free-tier reset */
|
|
690
|
+
private currentMonthKey;
|
|
691
|
+
private eventCounter;
|
|
692
|
+
constructor(config?: UsageMeterConfig);
|
|
693
|
+
/**
|
|
694
|
+
* Record a tool call usage event.
|
|
695
|
+
*/
|
|
696
|
+
recordUsage(agentId: string, toolId: string, metadata?: Record<string, unknown>): UsageEvent;
|
|
697
|
+
/**
|
|
698
|
+
* Get the cost for a specific tool.
|
|
699
|
+
*/
|
|
700
|
+
getToolCost(toolId: string): number;
|
|
701
|
+
/**
|
|
702
|
+
* Set cost for a specific tool.
|
|
703
|
+
*/
|
|
704
|
+
setToolCost(toolId: string, cost: number): void;
|
|
705
|
+
/**
|
|
706
|
+
* Get usage summary for an agent within a time period.
|
|
707
|
+
*/
|
|
708
|
+
getAgentUsage(agentId: string, period?: UsagePeriod): AgentUsageSummary;
|
|
709
|
+
/**
|
|
710
|
+
* Get aggregated usage across all agents for a period.
|
|
711
|
+
*/
|
|
712
|
+
getGlobalUsage(period?: UsagePeriod): UsageAggregate;
|
|
713
|
+
/**
|
|
714
|
+
* Get top tools by usage cost.
|
|
715
|
+
*/
|
|
716
|
+
getTopTools(period?: UsagePeriod, limit?: number): Array<{
|
|
717
|
+
toolId: string;
|
|
718
|
+
calls: number;
|
|
719
|
+
cost: number;
|
|
720
|
+
}>;
|
|
721
|
+
/**
|
|
722
|
+
* Get free-tier remaining for an agent.
|
|
723
|
+
*/
|
|
724
|
+
getFreeTierRemaining(agentId: string): number;
|
|
725
|
+
/**
|
|
726
|
+
* Check if an agent has exceeded their free tier.
|
|
727
|
+
*/
|
|
728
|
+
isOverFreeTier(agentId: string): boolean;
|
|
729
|
+
/**
|
|
730
|
+
* Get all tracked agent IDs.
|
|
731
|
+
*/
|
|
732
|
+
getTrackedAgents(): string[];
|
|
733
|
+
/**
|
|
734
|
+
* Get raw events for an agent.
|
|
735
|
+
*/
|
|
736
|
+
getEvents(agentId: string): UsageEvent[];
|
|
737
|
+
/**
|
|
738
|
+
* Get total number of recorded events.
|
|
739
|
+
*/
|
|
740
|
+
getTotalEventCount(): number;
|
|
741
|
+
private getMonthKey;
|
|
742
|
+
private checkMonthReset;
|
|
743
|
+
private getPeriodBounds;
|
|
744
|
+
private emitTelemetry;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
export { type AgentBudget, AgentBudgetEnforcer, type AgentUsageSummary, type BillingInterval, type BudgetEnforcerConfig, type BudgetPeriod, type BudgetState, type CircuitBreakerState, DEFAULT_COST_FLOOR, DEFAULT_LOD_SCALING, DEFAULT_TRAIT_UTILITIES, type EnforcementMode, type FreeTierConfig, PLATFORM_LOD_SCALING, type RenewalResult, type ResourceCostFloor, type SpendAuthorizationResult, type Subscription, SubscriptionManager, type SubscriptionManagerConfig, type SubscriptionPlan, type SubscriptionState, type TraitAllocation, type TraitCategory, type TraitUtility, UnifiedBudgetOptimizer, type UnifiedBudgetState, type UnifiedOptimizerConfig, type UsageAggregate, type UsageEvent, UsageMeter, type UsageMeterConfig, type UsagePeriod };
|