@rulvar/core 1.170.0 → 1.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +49 -12
- package/dist/index.js +432 -416
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -764,7 +764,13 @@ interface ProviderCallRecord {
|
|
|
764
764
|
/** The invocation phase that paid the call. */
|
|
765
765
|
role: InvocationRole;
|
|
766
766
|
servedBy: ModelRef;
|
|
767
|
-
/**
|
|
767
|
+
/**
|
|
768
|
+
* 1-based DISPATCHED try number on the serving target; transport
|
|
769
|
+
* retries increment it, a pre-wire quota denial never does (RV1601),
|
|
770
|
+
* so the recorded attempts of one (role, target) series are always
|
|
771
|
+
* dense from 1 and an attempt=2 row proves a prior dispatched try
|
|
772
|
+
* with its own record.
|
|
773
|
+
*/
|
|
768
774
|
attempt: number;
|
|
769
775
|
/**
|
|
770
776
|
* 'ok' = a terminal finish; 'error' = a wire failure after dispatch
|
|
@@ -4067,6 +4073,19 @@ interface EngineQuotaConfig {
|
|
|
4067
4073
|
*/
|
|
4068
4074
|
reserveContinuations?: boolean;
|
|
4069
4075
|
/**
|
|
4076
|
+
* The denial retry budget (RV1601): how many pre-wire quota denials
|
|
4077
|
+
* one dispatch tolerates per serving target before the denial takes
|
|
4078
|
+
* the exhaustion path (failover when the chain names a rate-limit
|
|
4079
|
+
* trigger, else the typed rate-limit terminal). Denials stopped
|
|
4080
|
+
* consuming `RetryPolicy.attempts` in RV1601: that budget counts
|
|
4081
|
+
* DISPATCHED tries only, so a busy window can no longer exhaust the
|
|
4082
|
+
* transport budget before the wire ever opens (the eighteenth
|
|
4083
|
+
* comparison benchmark measured 21 denials riding the transport
|
|
4084
|
+
* namespaces). Each denied turn still waits the limiter's own
|
|
4085
|
+
* `retryAfterMs` first. Default {@link DEFAULT_MAX_QUOTA_DENIALS}.
|
|
4086
|
+
*/
|
|
4087
|
+
maxDenials?: number;
|
|
4088
|
+
/**
|
|
4070
4089
|
* The drift telemetry opt-in (the v1.71 experiment review, P0.5
|
|
4071
4090
|
* resized): the SAME rule declaration `preflightEstimate` takes as
|
|
4072
4091
|
* `quotaRules`, mirrored here so the engine can hold it against what
|
|
@@ -4086,6 +4105,14 @@ interface EngineQuotaConfig {
|
|
|
4086
4105
|
*/
|
|
4087
4106
|
declaredRules?: readonly QuotaRule[];
|
|
4088
4107
|
}
|
|
4108
|
+
/**
|
|
4109
|
+
* The default {@link EngineQuotaConfig.maxDenials}: generous next to the
|
|
4110
|
+
* transport default of 3 tries because a denial is a WAIT, not a
|
|
4111
|
+
* failure signal, yet finite because nothing else bounds the pre-wire
|
|
4112
|
+
* loop (the per-agent timeout is checked between turns, not inside a
|
|
4113
|
+
* dispatch).
|
|
4114
|
+
*/
|
|
4115
|
+
declare const DEFAULT_MAX_QUOTA_DENIALS = 8;
|
|
4089
4116
|
/** The resolved engine-side quota runtime threaded into every run. */
|
|
4090
4117
|
interface EngineQuotaRuntime {
|
|
4091
4118
|
limiter: QuotaLimiter;
|
|
@@ -4093,6 +4120,8 @@ interface EngineQuotaRuntime {
|
|
|
4093
4120
|
onLimiterError: "deny" | "allow";
|
|
4094
4121
|
/** Pre-wire continuation admission (RV1013); see {@link EngineQuotaConfig}. */
|
|
4095
4122
|
reserveContinuations: boolean;
|
|
4123
|
+
/** The per-target denial retry budget (RV1601); see {@link EngineQuotaConfig}. */
|
|
4124
|
+
maxDenials: number;
|
|
4096
4125
|
/** The declared rule mirror for drift telemetry; see {@link EngineQuotaConfig}. */
|
|
4097
4126
|
declaredRules?: readonly QuotaRule[];
|
|
4098
4127
|
}
|
|
@@ -4856,9 +4885,14 @@ interface AgentResult<T> {
|
|
|
4856
4885
|
abortClass?: AbortClass;
|
|
4857
4886
|
/**
|
|
4858
4887
|
* Transport retries across the span's phase activations, present only
|
|
4859
|
-
* when greater than zero.
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
4888
|
+
* when greater than zero. Counts retries of DISPATCHED attempts only
|
|
4889
|
+
* (RV1601): a pre-wire quota denial never increments it, so this
|
|
4890
|
+
* number can be read against the provider ledger without correction
|
|
4891
|
+
* (the eighteenth comparison benchmark exported 21 denials under this
|
|
4892
|
+
* name over an invoice with zero provider error rows). Live telemetry
|
|
4893
|
+
* only: the ctx layer surfaces it as `agent:end` retryCount; it is
|
|
4894
|
+
* never journaled, so a replayed result omits it (absent means "zero
|
|
4895
|
+
* or unknown").
|
|
4862
4896
|
*/
|
|
4863
4897
|
transportRetries?: number;
|
|
4864
4898
|
/**
|
|
@@ -5166,12 +5200,14 @@ interface RunAgentOptions<S extends SchemaSpec = JsonSchema> {
|
|
|
5166
5200
|
* failover takeovers alike, in every phase). A denial becomes a
|
|
5167
5201
|
* synthetic rate-limit-class WireError the retry and failover
|
|
5168
5202
|
* engine treats exactly like a provider 429, except no wire call
|
|
5169
|
-
* was paid: retryAfterMs drives the interruptible backoff,
|
|
5170
|
-
* stay bounded by
|
|
5171
|
-
*
|
|
5172
|
-
*
|
|
5173
|
-
*
|
|
5174
|
-
*
|
|
5203
|
+
* was paid: retryAfterMs drives the interruptible backoff, denied
|
|
5204
|
+
* turns stay bounded by their OWN `maxDenials` budget (RV1601;
|
|
5205
|
+
* RetryPolicy.attempts counts dispatched tries only), and
|
|
5206
|
+
* exhaustion of either budget fails over (the takeover reserves
|
|
5207
|
+
* under its own model). Granted reservations are reconciled with
|
|
5208
|
+
* the attempt's actual usage after the outcome settles. Live-only
|
|
5209
|
+
* by construction: replayed calls never reach this seam, and
|
|
5210
|
+
* nothing here is journaled.
|
|
5175
5211
|
*/
|
|
5176
5212
|
quota?: {
|
|
5177
5213
|
reserve: (request: QuotaReservationRequest) => Promise<QuotaDecision>;
|
|
@@ -5179,7 +5215,8 @@ interface RunAgentOptions<S extends SchemaSpec = JsonSchema> {
|
|
|
5179
5215
|
requests?: number;
|
|
5180
5216
|
}) => Promise<void>; /** Limiter infrastructure failure policy; a denial is unaffected. */
|
|
5181
5217
|
onLimiterError: "deny" | "allow"; /** Pre-wire continuation admission (RV1013); default post-hoc. */
|
|
5182
|
-
reserveContinuations?: boolean; /**
|
|
5218
|
+
reserveContinuations?: boolean; /** The per-target denial retry budget (RV1601); default 8. */
|
|
5219
|
+
maxDenials?: number; /** Cancels an unused admission; absent = window age-out. */
|
|
5183
5220
|
release?: (reservationId: string) => Promise<void>;
|
|
5184
5221
|
};
|
|
5185
5222
|
/** The resolved toolset; absent = no tools declared. */
|
|
@@ -12675,4 +12712,4 @@ interface SandboxBridge {
|
|
|
12675
12712
|
declare const SANDBOX_AGENT_OPT_KEYS: readonly string[];
|
|
12676
12713
|
declare function createSandboxBridge(ctx: Ctx<never>, options: SandboxBridgeOptions): SandboxBridge;
|
|
12677
12714
|
//#endregion
|
|
12678
|
-
export { AWAIT_SCHEMA, AbandonAttempt, AbandonFold, AbandonPayload, AbandonedSpendView, AbortClass, AcceptanceChildSummary, type AdaptiveEvents, AdmissionController, AdmissionDecision, AdmissionRejectedError, AdmissionStatsBefore, AdmitLineage, AdmitRejectReason, AdmitSpec, AdmitVerdict, AgentCallError, AgentError, type AgentEvents, AgentIdentityInput, type AgentInvocationRow, AgentOpts, AgentProfile, AgentProfilePermissions, AgentProfileTemplateOptions, AgentResult, AgentResultMeta, AgentStatus, type AppliedPricingRow, ApproachSignatureInputs, ApprovalDecision, ApprovalIdentityInput, Artifact, AttemptOutcomeClass, AuditCategory, AuditRecord, AuditRunsOptions, BUDGET_ABORT_REASON, BaseAppend, BriefOpts, BudgetAccountView, BudgetDefaults, BudgetExhaustedError, BudgetExhaustionDiagnostics, BudgetHooks, BudgetReserve, type Bytes, CANCEL_AGENT_SCHEMA, CHECKPOINT_FORMAT_V1, CLAIM_STATEMENT_MAX_CHARS, CLAIM_TTL_DAYS, COMPACTION_SUMMARY_PREFIX, CURRENT_HASH_VERSION, CacheHint, CacheTtl, CanUseTool, CanonicalId, CanonicalIdentity, CanonicalLadderSpec, CanonicalModelSpec, ChatEvent, ChatRequest, CheckpointState, ChildArtifactPage, ChildExecutionFacts, ChildIdentityInput, ChildResultPage, CitationTarget, type ClaimClass, ClaimContradictionFinding, type ClaimOp, ClaimPair, ClaimPairOptions, ClaimPairsFold, ClaimPoolReading, type ClaimStatus, ClaimValidationOptions, CollectOpts, CollectedTurn, CompactionConfig, CompiledPermissionChain, CompiledWorkflow, ConfigError, Contradiction, ContradictionClaim, ContradictionOptions, ContradictionSource, type CoreEvents, CostAttribution, CostAttributionFacts, type CostBasis, CostReport, CreateEngineOptions, type CriticalPath, Ctx, DEFAULT_ANCHOR_PATTERN, DEFAULT_ARTIFACT_PATTERN, DEFAULT_CHILD_BUDGET_FRACTION, DEFAULT_CHILD_RESULT_PAGE_CHARS, DEFAULT_CITATION_PATTERN, DEFAULT_CITATION_SAMPLE, DEFAULT_CLAIM_JUDGE_MAX_TURNS, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ESCALATION_LIMITS, DEFAULT_EVIDENCE_CALLS_PER_ENTRY, DEFAULT_EVIDENCE_GRADE_PHRASES, DEFAULT_EVIDENCE_MIN_SHARE, DEFAULT_EVIDENCE_OVERHEAD_CALLS, DEFAULT_FINISH_MAX_REPAIRS, DEFAULT_FLAT_RESERVE_USD, DEFAULT_MAX_CHILDREN_PER_NODE, DEFAULT_MAX_CLAIM_PAIRS, DEFAULT_MAX_CONTRADICTIONS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_EXCERPT_CHARS, DEFAULT_MAX_OSCILLATIONS_PER_KEY, DEFAULT_MAX_PAIR_EXCERPT_CHARS, DEFAULT_MAX_PINNED_WORKTREES, DEFAULT_MAX_POOL_PER_PAIR, DEFAULT_MAX_REVISIONS_PER_RUN, DEFAULT_MAX_TOTAL_SPAWNS, DEFAULT_MAX_TURNS, DEFAULT_MODEL_RETRY_ATTEMPTS, DEFAULT_NO_PROGRESS_TURNS, DEFAULT_PER_RUN_CONCURRENCY, DEFAULT_RETRY_POLICY, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_SYNTHESIS_MAX_TURNS, DEFAULT_SYNTHESIS_NOTE_MAX_TURNS, DataKeyProvider, DebitResult, DeclaredLadder, DedupIndex, DedupNote, DedupedClaims, DerivedKey, DeriverRegistry, type DeterminismConfig, DeterminismError, type DeterminismEvents, type DeterminismMode, DispositionRule, DispositionTable, DocumentedRates, DonorCandidate, DonorRef, DroppedItem, EMIT_RESULT_TOOL, EMPTY_SCHEMA_HASH, EMPTY_TOOLSET_HASH, ESCALATE_TOOL_NAME, ESCALATION_REPORT_SCHEMA, ESCALATION_REQUEST_SCHEMA, EVENT_SEGMENT_STRIDE, EffectiveUsageLimits, Effort, Engine, EngineDefaults, EngineQuotaConfig, EngineQuotaRuntime, EntryBillingFold, EntryBillingUnit, EntryKind, EntryRef, EntryStatus, EnvelopeEncryption, EnvelopeEncryptionOptions, ErrorClass, ErrorCode, ErrorPolicy, EscalatedResult, EscalationDecision, EscalationDecisionAbortedError, EscalationDigest, EscalationKind, EscalationLimits, EscalationOptions, EscalationReport, EscalationRequest, EventBus, EvidenceContract, type EvidenceRef, type ExecKeyDerivation, type ExecutorRegistry, type ExplorationSummary, ExtensionAppendInput, ExtensionDispatchSpec, ExternalIdentityInput, ExternalRegistry, ExtractNecessityInput, FINALIZE_SYNTHESIS_INSTRUCTION, FINISH_SCHEMA, FINISH_SECTIONAL_SCHEMA, FINISH_TOOL_NAME, FailRunError, FailoverTarget, FailoverTrigger, FallbackField, FallbackTrigger, FencedCodeMode, FileModelKnowledgeStore, FileModelKnowledgeStoreOptions, FileTranscriptStore, type FinalizationWindowBudget, FinishContract, FinishContractCitations, FinishContractGoldenReject, FinishContractManifest, FinishInfo, FinishSelfTestFailure, FinishSelfTestFixtures, FinishSelfTestReport, FinishValidationChild, FinishValidationInput, FinishValidationSpec, FinishValidationVerdict, FinishValidator, GET_CHILD_RESULT_SCHEMA, GET_CHILD_RESULT_TOOL_NAME, Gate, GateAudit, type GateRecord, GitWorktreeProvider, GitWorktreeProviderOptions, GraftBoot, HashVersion, HookVerdict, IMPLEMENTATION_PROFILE_LIMITS, INBOX_PROPOSAL_TTL_DAYS, IN_FLIGHT_EXPOSURE_REFUSAL_PREFIX, IdentityInput, InMemoryStore, InMemoryTranscriptStore, InProcessRunner, IncrementalSynthesisResult, InvalidResolutionError, InvocationRole, type InvocationTable, InvoiceCardinality, InvoiceExport, InvoicePricingProvenance, InvoiceReconciliation, InvoiceRow, type IsolatedExecContext, type IsolatedExecRequest, type IsolatedExecutorTag, type IsolationProvider, type IsolationSpec, Issue$1 as Issue, JOURNAL_ENVELOPE_MARKER, JournalCompatSubCode, JournalCompatibilityError, JournalEntry, JournalMatcher, JournalMissError, JournalOperation, JournalOrderViolation, type JournalPricingSnapshot, JournalSerializationContext, JournalSerializationHook, type JournalStore, type Json, JsonSchema, JsonlFileStore, KB_ACTIVE_CLAIMS_CAP, KB_CARD_RENDER_BUDGET_CHARS, type KbProposal, type KbProposalTrigger, KeyDeriver, KeyRing, KeyedLimiter, KnowledgeCasError, type KnowledgeSnapshot, LARGE_VALUE_WARN_BYTES, LEGACY_LTID_PREFIX, LEGACY_SIGNATURE_INPUTS, LINEAGE_SIG_VERSION, LadderSpec, type LeasableStore, type Lease, LeaseHeldError, Ledger, LineageCounters, LineageIndex, LineageRef, LineageRelation, LineageStats, LogicalTaskId, MASKED_SECRET, MAX_CHILD_RESULT_PAGE_CHARS, MAX_DEPTH_CEILING, MAX_RUN_ID_LENGTH, MAX_TIMER_DELAY_MS, MatchResult, McpConfig, McpToolSource, MechanicalGateProfile, MechanicalGateVerdict, MemoryQuotaLimiter, type MetaLookupStore, type ModelCaps, ModelChoice, type ModelClaim, ModelEpochInputs, type ModelKnowledgeHandle, type ModelKnowledgeStore, ModelListConstraint, ModelRef, ModelRetry, ModelSpec, Msg, NoProgressDetector, NodeId, NodeLinkValue, NonSerializableValueError, ORCHESTRATE_WORKFLOW_NAME, OnEscalation, OperationDisposition, OrchestrateAcceptance, OrchestrateClaimConsistency, OrchestrateClaimConsistencyMeta, OrchestrateContradictions, OrchestrateContradictionsMeta, OrchestrateOptions, OrchestrateSynthesis, OrchestrateSynthesisSkipReason, OrchestratorBudgetSpec, OrchestratorCapConfigError, OrchestratorExtension, OrchestratorExtensionIO, OrchestratorRuntime, Out, PARALLEL_AGENTS_SCHEMA, PROGRESS_REPORT_TOOL_NAME, ParallelSiteCounter, Part, PendingExternal, PendingToolTurn, PermissionConfig, PermissionGate, PermissionHook, PermissionPreset, PermissionRule, PermissionVerdict, PersistedTerminalRefusal, PersistedTerminalResult, type PhaseRow, PhaseTarget, type PinnedPricingSegment, PipelineCollected, PipelineOpts, PlanInvariantError, type PostFanInBreakdown, PreflightAdmissionRow, PreflightFinding, PreflightInput, PreflightOrchestratorSpec, PreflightReport, PreflightSpawnReport, PreflightSpawnSpec, PreflightToolCeiling, PriceTable, PricedComponent, PricedComponents, PricedUsage, type Pricing, type PricingTier, ProgressReport, type ProviderAdapter, ProviderCallRecord, QUOTA_WINDOW_MS, QualityFloors, QuotaCounters, type QuotaDecision, type QuotaEstimate, type QuotaLimiter, type QuotaReservationRequest, QuotaRule, QuotaWindowSnapshot, READ_CHILD_ARTIFACT_SCHEMA, READ_CHILD_ARTIFACT_TOOL_NAME, RESEARCH_PROFILE_LIMITS, REVIEW_PROFILE_LIMITS, ROLE_EFFORT_DEFAULTS, ROOT_ACCOUNT, ROOT_SCOPE, RUN_PROFILES, RUN_SETTLE_DECISION_TYPE, RandIdentityInput, RandPayload, RateLimitObservation, ReconcileOptions, ReconcileResult, RefEntryAppender, RefEntryClassification, RefusalInfo, RepeatedClaim, ReplayDisposition, ReplayMode, ReplayPlanHashMismatch, Replayer, RepositoryResearchToolset, RepositoryResearchToolsetOptions, ResearchAgentProfileOptions, ResearchAgentProfileResult, ResearchEvidenceEntry, ResolutionArbiter, ResolutionAttempt, ResolutionBy, ResolutionFold, ResolutionLayer, ResolutionOutcome, ResolutionPayload, ResolvedInvocation, ResolvedToolset, ResumeHandle, ResumeOptions, ResumePreview, ResumeReport, RetryClass, RetryPolicy, ReuseConfig, RiskRuleValue, Role, RulvarError, RulvarErrorCode, RunAgentOptions, RunAuditVerdict, RunBudget, RunEventSink, RunExport, type RunFilter, RunHandle, RunInternals, type RunMeta, RunOptions, RunOutcome, RunProfile, RunStateAudit, RunStatus, RuntimeEventSink, SANDBOX_AGENT_OPT_KEYS, SPAWN_AGENT_SCHEMA, SandboxBridge, SandboxBridgeOptions, SandboxError, SandboxHostToWorker, SandboxMethod, SandboxWorkerToHost, SchemaPair, SchemaSpec, SchemaValidationResult, ScopeSegment, ScriptRejected, ScriptRunner, ScrubNote, SecretMasker, SectionMatchMode, Semaphore, SerializationHook, Settled, SettlementError, ShellPatternRules, ShellSegment, ShellVerdict, SinglePhaseAppend, SpanMinter, SpanRegistry, SpawnAdmissionValue, SpawnAgentParams, SpawnKey, SpawnLineage, SpawnLineageOpt, SpawnOrigin, SpawnRecord, Spend, Stage, type StandardJSONSchemaV1, type StandardSchemaV1, StepIdentityInput, type StreamHooks, StructuredOutputTier, SupersededError, SuspendedAppend, SuspensionState, TOOL_NAME_PATTERN, type TaskClass, TaskDigest, TaskSpec, type TerminalEnvelope, TerminalOutcomeFacts, TerminalPatch, TerminationAccount, TerminationAccountSnapshot, TerminationDeniedValue, TerminationDeniedWriter, TerminationInitValue, TerminationLimits, TerminationResource, type ToolBudgetSummary, ToolCallRequest, ToolChoice, type ToolContext, ToolContextSeed, ToolContract, type ToolDef, type ToolEvents, type ToolExecutor, type ToolExecutorProvider, ToolInit, type ToolRisk, ToolRuntime, type ToolSource, type ToolSourceSession, ToolsOption, ToolsetAttestation, TranscriptSerializationHook, type TranscriptStore, TriggerClass, TtlState, Usage, UsageLimits, UsageSlice, VerifiedRecommendation, WAIT_FOR_EVENTS_SCHEMA, WAIT_FOR_EVENTS_TOOL_NAME, WAKE_SUMMARY_RENDER_BUDGET_CHARS, WakeBudgetBlock, WakeDigest, WakeTrigger, WireError, Workflow, WorkflowCallOpts, type WorkflowEvent, type WorkflowEventBody, WorkflowRegistry, accountSpendFromJournal, admissionReserveUsd, affordableOutputTokens, agentErrorFromWire, agentErrorToWire, agentResultWire, agentScope, applyClaimOps, applyStructuredOutputTier, approachSigCoarse, approachSigOf, archiveDeprecatedModelOps, assertFencedWrites, assertSafeRunId, atCompactionThreshold, attestToolset, auditRun, auditRuns, buildAbandonFold, buildAdapterRegistry, buildCostReport, buildDeriverRegistry, buildOrchestratorTools, buildTerminationInitValue, buildToolContext, canRideLoopTurn, canonicalIsolationTag, canonicalizeLadder, canonicalizeSchema, capIssues, capsHashOf, checkFloors, checkpointRefFor, childCoveragePrefix, citationTargetsValidator, citedValueValidator, claimExpired, claimExpiry, claimIssues, claimOpIssues, classifyAgentError, classifyAttemptOutcome, collectDeclaredLadders, compactMessages, compareRates, compilePermissionChain, compilePermissionPreset, compileSecretMasker, compileVerifiedLayer, constantTimeEqual, costReportFromJournal, countsAgainstLimit, createCanonicalIdMinter, createCtx, createEngine, createEnvelopeEncryption, createSandboxBridge, currentOnlyKeyRing, decodeCheckpoint, dedupeRepeatedClaims, defineWorkflow, deriveContentKey, deriverV1, deriverV2, digestOf, dispatchProjectionReserveUsd, dispositionHook, emptyDigestBlocks, emptyToolset, encodeCheckpoint, enforceToolsetAttestation, entryUsageSlices, escalateTool, evaluatePermission, evaluateReuse, evidenceGradeValidator, evidencePreservedValidator, executeWorkflow, executionFactsOf, exhaustionCodeOf, extractCandidate, failoverTriggerOf, fallbackTriggerOf, filterClaimsForRun, finalizeFires, findContradictions, finishContract, foldLedger, foldTermination, formatCharacterValidator, formatRePrompt, formatScopePath, hasFencedWrites, hasMetaLookup, hashRunArgs, hashRunOutput, hashWorkflowBody, hashWorkflowSource, headingStructureValidator, identityJcs, implementationAgentProfile, invoiceFromJournal, isEscalated, isSchemaPairSpec, isStandardSchemaSpec, isStrictCompatibleSchema, journalPricingSnapshot, kMaxOf, knowledgeHash, ladderLengthOf, ladderRungChoice, lastRunSettle, latestProgressReport, lexShellCommand, liftRetainedParts, lineageWeightOf, localKeyProvider, makeOrchestratorWorkflow, maskSecrets, maskSecretsDeep, maskSecretsJson, matchArgvPattern, matchShellCommand, mcp, memoryQuotaLimiter, mergeQuotaDenial, mergeUsageLimits, metaMatchesFilter, minMatchesValidator, modelEpochOf, modelKnowledgeCard, modelSpecIdentity, needsSeparateExtract, nextFailover, nodeLinkKey, normalizeApproachTag, normalizeEntry, normalizeFallbacks, orchestrate, orchestratorAdmissionEstCostUsd, pairDraftClaims, parallelScope, parseModelRef, parseScopePath, persistedTerminalEnvelope, phiInitialOf, pipelineScope, planNodeScope, preflightEstimate, priceComponentsOf, priceEntryBilling, priceEntryUsage, priceUsdOf, profileCard, profileRegistrySnapshotHash, progressReportTool, projectHistory, projectIdentity, projectToJsonSchema, proposalStatement, providerOf, quotaActualRequestsDelta, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, readRunMeta, readTerminationInit, reconcileRunMeta, reduceAuditTrail, reduceCriticalPath, reduceInvocationTable, registryKeyRing, remeasureQueue, replayDisposition, repositoryResearchToolset, requiredFieldsValidator, requiredSectionsValidator, researchAgentProfile, resolveModelInvocation, resolvePricing, resolveToolset, retryClassOf, retryDelayMs, reviewAgentProfile, roleConfiguredInRouting, roundOneDisposition, runAgent, runProfile, sanitizeTerminalText, sanitizeTokenCount, sanitizeUsage, sanitizeUsageDelta, scanJournalCompatibility, schemaHash, schemaHashOfSpec, sectionCitationsValidator, selectStructuredOutputTier, selfTestFinishValidation, shouldCompact, snapshotQuotaRules, snapshotUsage, spawnDepthOf, spliceSections, stripFencedBlocks, sumUsage, summarizeInstruction, summarizeOutput, terminalEnvelopeOf, terminationConfigDrift, tierWithinCaps, toApprovalDecision, toJournalValue, tool, toolContract, toolContractHash, toolsetHash, ttlState, usageViolations, validateDetachedResolution, validateEditorialCommit, validateEngineQuotaConfig, validateEntryShape, validateEscalationLimits, validateEscalationReport, validateQuotaRules, validateRetryPolicy, validateSchemaSpec, validateTerminationLimits, validateToolsetAttestation, validateUsageLimits, wordCountValidator, workflowScope, workflowSourceRef, wrapJournalStore, wrapTranscriptStore };
|
|
12715
|
+
export { AWAIT_SCHEMA, AbandonAttempt, AbandonFold, AbandonPayload, AbandonedSpendView, AbortClass, AcceptanceChildSummary, type AdaptiveEvents, AdmissionController, AdmissionDecision, AdmissionRejectedError, AdmissionStatsBefore, AdmitLineage, AdmitRejectReason, AdmitSpec, AdmitVerdict, AgentCallError, AgentError, type AgentEvents, AgentIdentityInput, type AgentInvocationRow, AgentOpts, AgentProfile, AgentProfilePermissions, AgentProfileTemplateOptions, AgentResult, AgentResultMeta, AgentStatus, type AppliedPricingRow, ApproachSignatureInputs, ApprovalDecision, ApprovalIdentityInput, Artifact, AttemptOutcomeClass, AuditCategory, AuditRecord, AuditRunsOptions, BUDGET_ABORT_REASON, BaseAppend, BriefOpts, BudgetAccountView, BudgetDefaults, BudgetExhaustedError, BudgetExhaustionDiagnostics, BudgetHooks, BudgetReserve, type Bytes, CANCEL_AGENT_SCHEMA, CHECKPOINT_FORMAT_V1, CLAIM_STATEMENT_MAX_CHARS, CLAIM_TTL_DAYS, COMPACTION_SUMMARY_PREFIX, CURRENT_HASH_VERSION, CacheHint, CacheTtl, CanUseTool, CanonicalId, CanonicalIdentity, CanonicalLadderSpec, CanonicalModelSpec, ChatEvent, ChatRequest, CheckpointState, ChildArtifactPage, ChildExecutionFacts, ChildIdentityInput, ChildResultPage, CitationTarget, type ClaimClass, ClaimContradictionFinding, type ClaimOp, ClaimPair, ClaimPairOptions, ClaimPairsFold, ClaimPoolReading, type ClaimStatus, ClaimValidationOptions, CollectOpts, CollectedTurn, CompactionConfig, CompiledPermissionChain, CompiledWorkflow, ConfigError, Contradiction, ContradictionClaim, ContradictionOptions, ContradictionSource, type CoreEvents, CostAttribution, CostAttributionFacts, type CostBasis, CostReport, CreateEngineOptions, type CriticalPath, Ctx, DEFAULT_ANCHOR_PATTERN, DEFAULT_ARTIFACT_PATTERN, DEFAULT_CHILD_BUDGET_FRACTION, DEFAULT_CHILD_RESULT_PAGE_CHARS, DEFAULT_CITATION_PATTERN, DEFAULT_CITATION_SAMPLE, DEFAULT_CLAIM_JUDGE_MAX_TURNS, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ESCALATION_LIMITS, DEFAULT_EVIDENCE_CALLS_PER_ENTRY, DEFAULT_EVIDENCE_GRADE_PHRASES, DEFAULT_EVIDENCE_MIN_SHARE, DEFAULT_EVIDENCE_OVERHEAD_CALLS, DEFAULT_FINISH_MAX_REPAIRS, DEFAULT_FLAT_RESERVE_USD, DEFAULT_MAX_CHILDREN_PER_NODE, DEFAULT_MAX_CLAIM_PAIRS, DEFAULT_MAX_CONTRADICTIONS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_EXCERPT_CHARS, DEFAULT_MAX_OSCILLATIONS_PER_KEY, DEFAULT_MAX_PAIR_EXCERPT_CHARS, DEFAULT_MAX_PINNED_WORKTREES, DEFAULT_MAX_POOL_PER_PAIR, DEFAULT_MAX_QUOTA_DENIALS, DEFAULT_MAX_REVISIONS_PER_RUN, DEFAULT_MAX_TOTAL_SPAWNS, DEFAULT_MAX_TURNS, DEFAULT_MODEL_RETRY_ATTEMPTS, DEFAULT_NO_PROGRESS_TURNS, DEFAULT_PER_RUN_CONCURRENCY, DEFAULT_RETRY_POLICY, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_SYNTHESIS_MAX_TURNS, DEFAULT_SYNTHESIS_NOTE_MAX_TURNS, DataKeyProvider, DebitResult, DeclaredLadder, DedupIndex, DedupNote, DedupedClaims, DerivedKey, DeriverRegistry, type DeterminismConfig, DeterminismError, type DeterminismEvents, type DeterminismMode, DispositionRule, DispositionTable, DocumentedRates, DonorCandidate, DonorRef, DroppedItem, EMIT_RESULT_TOOL, EMPTY_SCHEMA_HASH, EMPTY_TOOLSET_HASH, ESCALATE_TOOL_NAME, ESCALATION_REPORT_SCHEMA, ESCALATION_REQUEST_SCHEMA, EVENT_SEGMENT_STRIDE, EffectiveUsageLimits, Effort, Engine, EngineDefaults, EngineQuotaConfig, EngineQuotaRuntime, EntryBillingFold, EntryBillingUnit, EntryKind, EntryRef, EntryStatus, EnvelopeEncryption, EnvelopeEncryptionOptions, ErrorClass, ErrorCode, ErrorPolicy, EscalatedResult, EscalationDecision, EscalationDecisionAbortedError, EscalationDigest, EscalationKind, EscalationLimits, EscalationOptions, EscalationReport, EscalationRequest, EventBus, EvidenceContract, type EvidenceRef, type ExecKeyDerivation, type ExecutorRegistry, type ExplorationSummary, ExtensionAppendInput, ExtensionDispatchSpec, ExternalIdentityInput, ExternalRegistry, ExtractNecessityInput, FINALIZE_SYNTHESIS_INSTRUCTION, FINISH_SCHEMA, FINISH_SECTIONAL_SCHEMA, FINISH_TOOL_NAME, FailRunError, FailoverTarget, FailoverTrigger, FallbackField, FallbackTrigger, FencedCodeMode, FileModelKnowledgeStore, FileModelKnowledgeStoreOptions, FileTranscriptStore, type FinalizationWindowBudget, FinishContract, FinishContractCitations, FinishContractGoldenReject, FinishContractManifest, FinishInfo, FinishSelfTestFailure, FinishSelfTestFixtures, FinishSelfTestReport, FinishValidationChild, FinishValidationInput, FinishValidationSpec, FinishValidationVerdict, FinishValidator, GET_CHILD_RESULT_SCHEMA, GET_CHILD_RESULT_TOOL_NAME, Gate, GateAudit, type GateRecord, GitWorktreeProvider, GitWorktreeProviderOptions, GraftBoot, HashVersion, HookVerdict, IMPLEMENTATION_PROFILE_LIMITS, INBOX_PROPOSAL_TTL_DAYS, IN_FLIGHT_EXPOSURE_REFUSAL_PREFIX, IdentityInput, InMemoryStore, InMemoryTranscriptStore, InProcessRunner, IncrementalSynthesisResult, InvalidResolutionError, InvocationRole, type InvocationTable, InvoiceCardinality, InvoiceExport, InvoicePricingProvenance, InvoiceReconciliation, InvoiceRow, type IsolatedExecContext, type IsolatedExecRequest, type IsolatedExecutorTag, type IsolationProvider, type IsolationSpec, Issue$1 as Issue, JOURNAL_ENVELOPE_MARKER, JournalCompatSubCode, JournalCompatibilityError, JournalEntry, JournalMatcher, JournalMissError, JournalOperation, JournalOrderViolation, type JournalPricingSnapshot, JournalSerializationContext, JournalSerializationHook, type JournalStore, type Json, JsonSchema, JsonlFileStore, KB_ACTIVE_CLAIMS_CAP, KB_CARD_RENDER_BUDGET_CHARS, type KbProposal, type KbProposalTrigger, KeyDeriver, KeyRing, KeyedLimiter, KnowledgeCasError, type KnowledgeSnapshot, LARGE_VALUE_WARN_BYTES, LEGACY_LTID_PREFIX, LEGACY_SIGNATURE_INPUTS, LINEAGE_SIG_VERSION, LadderSpec, type LeasableStore, type Lease, LeaseHeldError, Ledger, LineageCounters, LineageIndex, LineageRef, LineageRelation, LineageStats, LogicalTaskId, MASKED_SECRET, MAX_CHILD_RESULT_PAGE_CHARS, MAX_DEPTH_CEILING, MAX_RUN_ID_LENGTH, MAX_TIMER_DELAY_MS, MatchResult, McpConfig, McpToolSource, MechanicalGateProfile, MechanicalGateVerdict, MemoryQuotaLimiter, type MetaLookupStore, type ModelCaps, ModelChoice, type ModelClaim, ModelEpochInputs, type ModelKnowledgeHandle, type ModelKnowledgeStore, ModelListConstraint, ModelRef, ModelRetry, ModelSpec, Msg, NoProgressDetector, NodeId, NodeLinkValue, NonSerializableValueError, ORCHESTRATE_WORKFLOW_NAME, OnEscalation, OperationDisposition, OrchestrateAcceptance, OrchestrateClaimConsistency, OrchestrateClaimConsistencyMeta, OrchestrateContradictions, OrchestrateContradictionsMeta, OrchestrateOptions, OrchestrateSynthesis, OrchestrateSynthesisSkipReason, OrchestratorBudgetSpec, OrchestratorCapConfigError, OrchestratorExtension, OrchestratorExtensionIO, OrchestratorRuntime, Out, PARALLEL_AGENTS_SCHEMA, PROGRESS_REPORT_TOOL_NAME, ParallelSiteCounter, Part, PendingExternal, PendingToolTurn, PermissionConfig, PermissionGate, PermissionHook, PermissionPreset, PermissionRule, PermissionVerdict, PersistedTerminalRefusal, PersistedTerminalResult, type PhaseRow, PhaseTarget, type PinnedPricingSegment, PipelineCollected, PipelineOpts, PlanInvariantError, type PostFanInBreakdown, PreflightAdmissionRow, PreflightFinding, PreflightInput, PreflightOrchestratorSpec, PreflightReport, PreflightSpawnReport, PreflightSpawnSpec, PreflightToolCeiling, PriceTable, PricedComponent, PricedComponents, PricedUsage, type Pricing, type PricingTier, ProgressReport, type ProviderAdapter, ProviderCallRecord, QUOTA_WINDOW_MS, QualityFloors, QuotaCounters, type QuotaDecision, type QuotaEstimate, type QuotaLimiter, type QuotaReservationRequest, QuotaRule, QuotaWindowSnapshot, READ_CHILD_ARTIFACT_SCHEMA, READ_CHILD_ARTIFACT_TOOL_NAME, RESEARCH_PROFILE_LIMITS, REVIEW_PROFILE_LIMITS, ROLE_EFFORT_DEFAULTS, ROOT_ACCOUNT, ROOT_SCOPE, RUN_PROFILES, RUN_SETTLE_DECISION_TYPE, RandIdentityInput, RandPayload, RateLimitObservation, ReconcileOptions, ReconcileResult, RefEntryAppender, RefEntryClassification, RefusalInfo, RepeatedClaim, ReplayDisposition, ReplayMode, ReplayPlanHashMismatch, Replayer, RepositoryResearchToolset, RepositoryResearchToolsetOptions, ResearchAgentProfileOptions, ResearchAgentProfileResult, ResearchEvidenceEntry, ResolutionArbiter, ResolutionAttempt, ResolutionBy, ResolutionFold, ResolutionLayer, ResolutionOutcome, ResolutionPayload, ResolvedInvocation, ResolvedToolset, ResumeHandle, ResumeOptions, ResumePreview, ResumeReport, RetryClass, RetryPolicy, ReuseConfig, RiskRuleValue, Role, RulvarError, RulvarErrorCode, RunAgentOptions, RunAuditVerdict, RunBudget, RunEventSink, RunExport, type RunFilter, RunHandle, RunInternals, type RunMeta, RunOptions, RunOutcome, RunProfile, RunStateAudit, RunStatus, RuntimeEventSink, SANDBOX_AGENT_OPT_KEYS, SPAWN_AGENT_SCHEMA, SandboxBridge, SandboxBridgeOptions, SandboxError, SandboxHostToWorker, SandboxMethod, SandboxWorkerToHost, SchemaPair, SchemaSpec, SchemaValidationResult, ScopeSegment, ScriptRejected, ScriptRunner, ScrubNote, SecretMasker, SectionMatchMode, Semaphore, SerializationHook, Settled, SettlementError, ShellPatternRules, ShellSegment, ShellVerdict, SinglePhaseAppend, SpanMinter, SpanRegistry, SpawnAdmissionValue, SpawnAgentParams, SpawnKey, SpawnLineage, SpawnLineageOpt, SpawnOrigin, SpawnRecord, Spend, Stage, type StandardJSONSchemaV1, type StandardSchemaV1, StepIdentityInput, type StreamHooks, StructuredOutputTier, SupersededError, SuspendedAppend, SuspensionState, TOOL_NAME_PATTERN, type TaskClass, TaskDigest, TaskSpec, type TerminalEnvelope, TerminalOutcomeFacts, TerminalPatch, TerminationAccount, TerminationAccountSnapshot, TerminationDeniedValue, TerminationDeniedWriter, TerminationInitValue, TerminationLimits, TerminationResource, type ToolBudgetSummary, ToolCallRequest, ToolChoice, type ToolContext, ToolContextSeed, ToolContract, type ToolDef, type ToolEvents, type ToolExecutor, type ToolExecutorProvider, ToolInit, type ToolRisk, ToolRuntime, type ToolSource, type ToolSourceSession, ToolsOption, ToolsetAttestation, TranscriptSerializationHook, type TranscriptStore, TriggerClass, TtlState, Usage, UsageLimits, UsageSlice, VerifiedRecommendation, WAIT_FOR_EVENTS_SCHEMA, WAIT_FOR_EVENTS_TOOL_NAME, WAKE_SUMMARY_RENDER_BUDGET_CHARS, WakeBudgetBlock, WakeDigest, WakeTrigger, WireError, Workflow, WorkflowCallOpts, type WorkflowEvent, type WorkflowEventBody, WorkflowRegistry, accountSpendFromJournal, admissionReserveUsd, affordableOutputTokens, agentErrorFromWire, agentErrorToWire, agentResultWire, agentScope, applyClaimOps, applyStructuredOutputTier, approachSigCoarse, approachSigOf, archiveDeprecatedModelOps, assertFencedWrites, assertSafeRunId, atCompactionThreshold, attestToolset, auditRun, auditRuns, buildAbandonFold, buildAdapterRegistry, buildCostReport, buildDeriverRegistry, buildOrchestratorTools, buildTerminationInitValue, buildToolContext, canRideLoopTurn, canonicalIsolationTag, canonicalizeLadder, canonicalizeSchema, capIssues, capsHashOf, checkFloors, checkpointRefFor, childCoveragePrefix, citationTargetsValidator, citedValueValidator, claimExpired, claimExpiry, claimIssues, claimOpIssues, classifyAgentError, classifyAttemptOutcome, collectDeclaredLadders, compactMessages, compareRates, compilePermissionChain, compilePermissionPreset, compileSecretMasker, compileVerifiedLayer, constantTimeEqual, costReportFromJournal, countsAgainstLimit, createCanonicalIdMinter, createCtx, createEngine, createEnvelopeEncryption, createSandboxBridge, currentOnlyKeyRing, decodeCheckpoint, dedupeRepeatedClaims, defineWorkflow, deriveContentKey, deriverV1, deriverV2, digestOf, dispatchProjectionReserveUsd, dispositionHook, emptyDigestBlocks, emptyToolset, encodeCheckpoint, enforceToolsetAttestation, entryUsageSlices, escalateTool, evaluatePermission, evaluateReuse, evidenceGradeValidator, evidencePreservedValidator, executeWorkflow, executionFactsOf, exhaustionCodeOf, extractCandidate, failoverTriggerOf, fallbackTriggerOf, filterClaimsForRun, finalizeFires, findContradictions, finishContract, foldLedger, foldTermination, formatCharacterValidator, formatRePrompt, formatScopePath, hasFencedWrites, hasMetaLookup, hashRunArgs, hashRunOutput, hashWorkflowBody, hashWorkflowSource, headingStructureValidator, identityJcs, implementationAgentProfile, invoiceFromJournal, isEscalated, isSchemaPairSpec, isStandardSchemaSpec, isStrictCompatibleSchema, journalPricingSnapshot, kMaxOf, knowledgeHash, ladderLengthOf, ladderRungChoice, lastRunSettle, latestProgressReport, lexShellCommand, liftRetainedParts, lineageWeightOf, localKeyProvider, makeOrchestratorWorkflow, maskSecrets, maskSecretsDeep, maskSecretsJson, matchArgvPattern, matchShellCommand, mcp, memoryQuotaLimiter, mergeQuotaDenial, mergeUsageLimits, metaMatchesFilter, minMatchesValidator, modelEpochOf, modelKnowledgeCard, modelSpecIdentity, needsSeparateExtract, nextFailover, nodeLinkKey, normalizeApproachTag, normalizeEntry, normalizeFallbacks, orchestrate, orchestratorAdmissionEstCostUsd, pairDraftClaims, parallelScope, parseModelRef, parseScopePath, persistedTerminalEnvelope, phiInitialOf, pipelineScope, planNodeScope, preflightEstimate, priceComponentsOf, priceEntryBilling, priceEntryUsage, priceUsdOf, profileCard, profileRegistrySnapshotHash, progressReportTool, projectHistory, projectIdentity, projectToJsonSchema, proposalStatement, providerOf, quotaActualRequestsDelta, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, readRunMeta, readTerminationInit, reconcileRunMeta, reduceAuditTrail, reduceCriticalPath, reduceInvocationTable, registryKeyRing, remeasureQueue, replayDisposition, repositoryResearchToolset, requiredFieldsValidator, requiredSectionsValidator, researchAgentProfile, resolveModelInvocation, resolvePricing, resolveToolset, retryClassOf, retryDelayMs, reviewAgentProfile, roleConfiguredInRouting, roundOneDisposition, runAgent, runProfile, sanitizeTerminalText, sanitizeTokenCount, sanitizeUsage, sanitizeUsageDelta, scanJournalCompatibility, schemaHash, schemaHashOfSpec, sectionCitationsValidator, selectStructuredOutputTier, selfTestFinishValidation, shouldCompact, snapshotQuotaRules, snapshotUsage, spawnDepthOf, spliceSections, stripFencedBlocks, sumUsage, summarizeInstruction, summarizeOutput, terminalEnvelopeOf, terminationConfigDrift, tierWithinCaps, toApprovalDecision, toJournalValue, tool, toolContract, toolContractHash, toolsetHash, ttlState, usageViolations, validateDetachedResolution, validateEditorialCommit, validateEngineQuotaConfig, validateEntryShape, validateEscalationLimits, validateEscalationReport, validateQuotaRules, validateRetryPolicy, validateSchemaSpec, validateTerminationLimits, validateToolsetAttestation, validateUsageLimits, wordCountValidator, workflowScope, workflowSourceRef, wrapJournalStore, wrapTranscriptStore };
|
package/dist/index.js
CHANGED
|
@@ -9009,123 +9009,446 @@ function compareRates(seed, page) {
|
|
|
9009
9009
|
return findings;
|
|
9010
9010
|
}
|
|
9011
9011
|
//#endregion
|
|
9012
|
-
//#region src/model/
|
|
9013
|
-
/** Normalizes the author-facing ModelChoice.fallbacks list. */
|
|
9014
|
-
function normalizeFallbacks(refs) {
|
|
9015
|
-
return (refs ?? []).map((model) => ({ model }));
|
|
9016
|
-
}
|
|
9012
|
+
//#region src/model/quota.ts
|
|
9017
9013
|
/**
|
|
9018
|
-
*
|
|
9019
|
-
*
|
|
9020
|
-
*
|
|
9014
|
+
* Quota rules and the in-process reference QuotaLimiter (RV-215).
|
|
9015
|
+
* The rule model is shared by every reference implementation
|
|
9016
|
+
* (memoryQuotaLimiter here, SqliteQuotaLimiter in
|
|
9017
|
+
* @rulvar/store-sqlite): fixed one-minute windows aligned to the
|
|
9018
|
+
* epoch, admission at reservation time, reconciliation to actual
|
|
9019
|
+
* usage inside the same window. The hard guarantee is on
|
|
9020
|
+
* `requestsPerMinute` (every wire attempt is exactly one request);
|
|
9021
|
+
* `tokensPerMinute` admits on the heuristic estimate and settles to
|
|
9022
|
+
* actual usage, so token windows are approximate at admission and
|
|
9023
|
+
* exact at settlement.
|
|
9024
|
+
*
|
|
9025
|
+
* Docs: https://docs.rulvar.com/guide/model-routing
|
|
9021
9026
|
*/
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9027
|
+
/**
|
|
9028
|
+
* Captured at module load, before the InProcessRunner's
|
|
9029
|
+
* nondeterminism guard can patch the global: the limiter's clock is
|
|
9030
|
+
* engine infrastructure on the live-only dispatch path and must never
|
|
9031
|
+
* be blamed on workflow code.
|
|
9032
|
+
*/
|
|
9033
|
+
const nativeNow = Date.now;
|
|
9034
|
+
/** The fixed accounting window every PerMinute cap counts over. */
|
|
9035
|
+
const QUOTA_WINDOW_MS = 6e4;
|
|
9036
|
+
/**
|
|
9037
|
+
* Validates a quota rule set as a typed ConfigError before any
|
|
9038
|
+
* limiter can admit under it: a non-array or empty set, a rule
|
|
9039
|
+
* without a cap, a malformed dimension, or a malformed cap all fail
|
|
9040
|
+
* loud at construction. Shared by every reference implementation.
|
|
9041
|
+
*/
|
|
9042
|
+
function validateQuotaRules(rules, site = "quota rules") {
|
|
9043
|
+
const raw = rules;
|
|
9044
|
+
if (!Array.isArray(raw)) throw new ConfigError(`${site} must be an array of QuotaRule objects`);
|
|
9045
|
+
if (raw.length === 0) throw new ConfigError(`${site} must contain at least one rule`);
|
|
9046
|
+
raw.forEach((entry, index) => {
|
|
9047
|
+
const at = `${site}[${String(index)}]`;
|
|
9048
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new ConfigError(`${at} must be a QuotaRule object`);
|
|
9049
|
+
const rule = entry;
|
|
9050
|
+
for (const dimension of [
|
|
9051
|
+
"provider",
|
|
9052
|
+
"model",
|
|
9053
|
+
"tenant"
|
|
9054
|
+
]) {
|
|
9055
|
+
const value = rule[dimension];
|
|
9056
|
+
if (value !== void 0 && (typeof value !== "string" || value === "")) throw new ConfigError(`${at}.${dimension} must be a nonempty string when given`);
|
|
9057
|
+
}
|
|
9058
|
+
if (rule.requestsPerMinute === void 0 && rule.tokensPerMinute === void 0) throw new ConfigError(`${at} must set requestsPerMinute or tokensPerMinute (or both)`);
|
|
9059
|
+
for (const cap of ["requestsPerMinute", "tokensPerMinute"]) if (rule[cap] !== void 0) requirePositiveInteger$2(rule[cap], `${at}.${cap}`);
|
|
9060
|
+
});
|
|
9025
9061
|
}
|
|
9026
9062
|
/**
|
|
9027
|
-
* The
|
|
9028
|
-
*
|
|
9029
|
-
*
|
|
9063
|
+
* The canonical content key of one rule (RV608, promoted from the
|
|
9064
|
+
* store limiters): a fixed-field-order JSON of the rule, identical
|
|
9065
|
+
* across processes and hosts for identical rules. It is the bucket key
|
|
9066
|
+
* of both store references, the input of
|
|
9067
|
+
* `quotaRulesFingerprint`, and the CANONICAL ORDER every reference
|
|
9068
|
+
* limiter folds denials in, so equal rule sets produce byte-identical
|
|
9069
|
+
* refusal objects regardless of array permutation.
|
|
9030
9070
|
*/
|
|
9031
|
-
function
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9071
|
+
function quotaRuleKey(rule) {
|
|
9072
|
+
return JSON.stringify({
|
|
9073
|
+
provider: rule.provider ?? null,
|
|
9074
|
+
model: rule.model ?? null,
|
|
9075
|
+
tenant: rule.tenant ?? null,
|
|
9076
|
+
requestsPerMinute: rule.requestsPerMinute ?? null,
|
|
9077
|
+
tokensPerMinute: rule.tokensPerMinute ?? null
|
|
9078
|
+
});
|
|
9036
9079
|
}
|
|
9037
9080
|
/**
|
|
9038
|
-
*
|
|
9039
|
-
*
|
|
9040
|
-
*
|
|
9041
|
-
*
|
|
9042
|
-
*
|
|
9081
|
+
* Validates a rule set and returns the immutable snapshot every
|
|
9082
|
+
* reference limiter admits under (RV608): a fresh array of fresh
|
|
9083
|
+
* objects carrying ONLY the known rule fields, each frozen, the array
|
|
9084
|
+
* frozen. The caller's array and objects stay untouched and unshared,
|
|
9085
|
+
* so ordinary JavaScript after the constructor (a pushed rule, a
|
|
9086
|
+
* reassigned cap) can no longer change a decision, a bucket key, or a
|
|
9087
|
+
* recorded fingerprint.
|
|
9088
|
+
*
|
|
9089
|
+
* A set containing two rules with the same canonical content key is
|
|
9090
|
+
* refused typed (RV704): the memory reference buckets by rule INDEX
|
|
9091
|
+
* (each copy counts independently, the full cap admits) while the
|
|
9092
|
+
* store references bucket by rule KEY (one shared bucket is debited
|
|
9093
|
+
* once per matching copy, half the cap admits), so the same duplicated
|
|
9094
|
+
* configuration admitted differently per storage. Refusing it at the
|
|
9095
|
+
* shared construction chokepoint is what keeps equal configurations
|
|
9096
|
+
* equal on every storage.
|
|
9043
9097
|
*/
|
|
9044
|
-
function
|
|
9045
|
-
|
|
9046
|
-
|
|
9098
|
+
function snapshotQuotaRules(rules, site = "quota rules") {
|
|
9099
|
+
validateQuotaRules(rules, site);
|
|
9100
|
+
const firstIndexByKey = /* @__PURE__ */ new Map();
|
|
9101
|
+
rules.forEach((rule, index) => {
|
|
9102
|
+
const key = quotaRuleKey(rule);
|
|
9103
|
+
const first = firstIndexByKey.get(key);
|
|
9104
|
+
if (first !== void 0) throw new ConfigError(`${site}[${String(index)}] duplicates ${site}[${String(first)}] (rule key ${key}): identical rules occupy independent buckets in memory but share one key-debited bucket on keyed storage, so one configuration would admit differently per store; delete the duplicate`);
|
|
9105
|
+
firstIndexByKey.set(key, index);
|
|
9106
|
+
});
|
|
9107
|
+
return Object.freeze(rules.map((rule) => Object.freeze({
|
|
9108
|
+
...rule.provider === void 0 ? {} : { provider: rule.provider },
|
|
9109
|
+
...rule.model === void 0 ? {} : { model: rule.model },
|
|
9110
|
+
...rule.tenant === void 0 ? {} : { tenant: rule.tenant },
|
|
9111
|
+
...rule.requestsPerMinute === void 0 ? {} : { requestsPerMinute: rule.requestsPerMinute },
|
|
9112
|
+
...rule.tokensPerMinute === void 0 ? {} : { tokensPerMinute: rule.tokensPerMinute }
|
|
9113
|
+
})));
|
|
9047
9114
|
}
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9115
|
+
/** True when every dimension the rule pins matches the request. */
|
|
9116
|
+
function quotaRuleMatches(rule, request) {
|
|
9117
|
+
return (rule.provider === void 0 || rule.provider === request.provider) && (rule.model === void 0 || rule.model === request.model) && (rule.tenant === void 0 || rule.tenant === request.tenant);
|
|
9118
|
+
}
|
|
9119
|
+
/** The tokens a reservation is admitted under: input estimate plus the output cap. */
|
|
9120
|
+
function quotaEstimateTokens(request) {
|
|
9121
|
+
return request.estimate.inputTokens + (request.estimate.maxOutputTokens ?? 0);
|
|
9122
|
+
}
|
|
9123
|
+
/** The tokens a settled attempt actually consumed. */
|
|
9124
|
+
function quotaActualTokens(usage) {
|
|
9125
|
+
return usage.inputTokens + usage.outputTokens;
|
|
9053
9126
|
}
|
|
9054
9127
|
/**
|
|
9055
|
-
*
|
|
9056
|
-
*
|
|
9057
|
-
*
|
|
9058
|
-
*
|
|
9059
|
-
*
|
|
9128
|
+
* The request-count settlement delta of one reservation (RV905): the
|
|
9129
|
+
* reservation admitted ONE wire request, and `actual.requests` names
|
|
9130
|
+
* how many the attempt actually made (an adapter absorbing
|
|
9131
|
+
* provider-side continuations dispatches several inside one reserved
|
|
9132
|
+
* call). Non-integer, non-positive, or absent actuals settle as the
|
|
9133
|
+
* single reserved request (delta 0); a settlement only ever ADDS, the
|
|
9134
|
+
* calls already happened. Shared by every reference limiter so the
|
|
9135
|
+
* three implementations cannot disagree about the arithmetic.
|
|
9060
9136
|
*/
|
|
9061
|
-
function
|
|
9062
|
-
const
|
|
9063
|
-
|
|
9064
|
-
const parts = msg.parts.filter((part) => part.type !== "provider-raw" || part.provider === targetProvider);
|
|
9065
|
-
if (parts.length === 0 && msg.parts.length > 0) continue;
|
|
9066
|
-
projected.push(parts.length === msg.parts.length ? msg : {
|
|
9067
|
-
...msg,
|
|
9068
|
-
parts
|
|
9069
|
-
});
|
|
9070
|
-
}
|
|
9071
|
-
return projected;
|
|
9137
|
+
function quotaActualRequestsDelta(actual) {
|
|
9138
|
+
const requests = actual?.requests;
|
|
9139
|
+
return typeof requests === "number" && Number.isInteger(requests) && requests > 1 ? requests - 1 : 0;
|
|
9072
9140
|
}
|
|
9073
9141
|
/**
|
|
9074
|
-
*
|
|
9075
|
-
*
|
|
9076
|
-
*
|
|
9077
|
-
*
|
|
9078
|
-
*
|
|
9142
|
+
* One rule's admission verdict against its current-window counters,
|
|
9143
|
+
* the pure decision both reference implementations share. A denial
|
|
9144
|
+
* carries the window remainder as retryAfterMs, except when the
|
|
9145
|
+
* estimate alone can never fit the token cap: that denial says
|
|
9146
|
+
* retryAfterMs 0 (retry immediately), so the caller's bounded
|
|
9147
|
+
* attempts exhaust without waiting and failover gets its chance.
|
|
9079
9148
|
*/
|
|
9080
|
-
function
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9149
|
+
function quotaRuleAdmission(rule, counters, estimate, msUntilWindowEnd) {
|
|
9150
|
+
if (rule.requestsPerMinute !== void 0 && counters.requests + estimate.requests > rule.requestsPerMinute) return {
|
|
9151
|
+
admit: false,
|
|
9152
|
+
retryAfterMs: msUntilWindowEnd,
|
|
9153
|
+
reason: `requestsPerMinute ${String(rule.requestsPerMinute)} exhausted`
|
|
9154
|
+
};
|
|
9155
|
+
if (rule.tokensPerMinute !== void 0) {
|
|
9156
|
+
if (estimate.tokens > rule.tokensPerMinute) return {
|
|
9157
|
+
admit: false,
|
|
9158
|
+
retryAfterMs: 0,
|
|
9159
|
+
reason: `the estimate of ${String(estimate.tokens)} tokens can never fit tokensPerMinute ${String(rule.tokensPerMinute)}`
|
|
9160
|
+
};
|
|
9161
|
+
if (counters.tokens + estimate.tokens > rule.tokensPerMinute) return {
|
|
9162
|
+
admit: false,
|
|
9163
|
+
retryAfterMs: msUntilWindowEnd,
|
|
9164
|
+
reason: `tokensPerMinute ${String(rule.tokensPerMinute)} exhausted`
|
|
9165
|
+
};
|
|
9166
|
+
}
|
|
9167
|
+
return { admit: true };
|
|
9092
9168
|
}
|
|
9093
|
-
//#endregion
|
|
9094
|
-
//#region src/model/retry.ts
|
|
9095
9169
|
/**
|
|
9096
|
-
*
|
|
9097
|
-
*
|
|
9098
|
-
*
|
|
9099
|
-
* (DEF-3), the provider-supplied retryAfterMs replaces the computed
|
|
9100
|
-
* delay, and task-class failures never retry by construction (a
|
|
9101
|
-
* non-retryable WireError has no retry class).
|
|
9102
|
-
*
|
|
9103
|
-
* Full contract: https://docs.rulvar.com/guide/model-routing; the
|
|
9104
|
-
* Appendix A defaults were committed at the M4 entry gate.
|
|
9170
|
+
* Folds one more failing rule into the decision the caller returns:
|
|
9171
|
+
* the wait is the LONGEST failing horizon (every matching rule must
|
|
9172
|
+
* admit), and the FIRST failing rule names the denial.
|
|
9105
9173
|
*/
|
|
9174
|
+
function mergeQuotaDenial(current, next) {
|
|
9175
|
+
if (current === void 0) return {
|
|
9176
|
+
retryAfterMs: next.retryAfterMs,
|
|
9177
|
+
reason: next.reason
|
|
9178
|
+
};
|
|
9179
|
+
return next.retryAfterMs > current.retryAfterMs ? {
|
|
9180
|
+
retryAfterMs: next.retryAfterMs,
|
|
9181
|
+
reason: current.reason
|
|
9182
|
+
} : current;
|
|
9183
|
+
}
|
|
9106
9184
|
/**
|
|
9107
|
-
*
|
|
9108
|
-
*
|
|
9109
|
-
*
|
|
9185
|
+
* The in-process reference QuotaLimiter: fixed epoch-aligned
|
|
9186
|
+
* one-minute windows over the shared rule model. Coordinates every
|
|
9187
|
+
* engine that shares THIS instance inside one process; processes
|
|
9188
|
+
* coordinate through a shared-storage implementation of the same SPI
|
|
9189
|
+
* (SqliteQuotaLimiter in @rulvar/store-sqlite) instead.
|
|
9110
9190
|
*/
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
const
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9191
|
+
function memoryQuotaLimiter(rules, options = {}) {
|
|
9192
|
+
const frozen = snapshotQuotaRules(rules, "memoryQuotaLimiter rules");
|
|
9193
|
+
const ordered = frozen.map((rule, index) => ({
|
|
9194
|
+
rule,
|
|
9195
|
+
index,
|
|
9196
|
+
key: quotaRuleKey(rule)
|
|
9197
|
+
})).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
9198
|
+
const now = options.now ?? (() => nativeNow());
|
|
9199
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
9200
|
+
const reservations = /* @__PURE__ */ new Map();
|
|
9201
|
+
let nextReservation = 0;
|
|
9202
|
+
const windowStartAt = (at) => at - at % QUOTA_WINDOW_MS;
|
|
9203
|
+
const bucketFor = (ruleIndex, windowStart) => {
|
|
9204
|
+
let bucket = buckets.get(ruleIndex);
|
|
9205
|
+
if (bucket === void 0 || bucket.windowStart !== windowStart) {
|
|
9206
|
+
bucket = {
|
|
9207
|
+
windowStart,
|
|
9208
|
+
requests: 0,
|
|
9209
|
+
tokens: 0
|
|
9210
|
+
};
|
|
9211
|
+
buckets.set(ruleIndex, bucket);
|
|
9212
|
+
}
|
|
9213
|
+
return bucket;
|
|
9214
|
+
};
|
|
9215
|
+
const prune = (windowStart) => {
|
|
9216
|
+
for (const [id, reservation] of reservations) if (reservation.windowStart < windowStart) reservations.delete(id);
|
|
9217
|
+
};
|
|
9218
|
+
return {
|
|
9219
|
+
reserve(request) {
|
|
9220
|
+
const at = now();
|
|
9221
|
+
const windowStart = windowStartAt(at);
|
|
9222
|
+
prune(windowStart);
|
|
9223
|
+
const estimateTokens = quotaEstimateTokens(request);
|
|
9224
|
+
const msUntilWindowEnd = windowStart + QUOTA_WINDOW_MS - at;
|
|
9225
|
+
const matched = [];
|
|
9226
|
+
let denial;
|
|
9227
|
+
for (const { rule, index } of ordered) {
|
|
9228
|
+
if (!quotaRuleMatches(rule, request)) continue;
|
|
9229
|
+
matched.push(index);
|
|
9230
|
+
const verdict = quotaRuleAdmission(rule, bucketFor(index, windowStart), {
|
|
9231
|
+
requests: request.estimate.requests,
|
|
9232
|
+
tokens: estimateTokens
|
|
9233
|
+
}, msUntilWindowEnd);
|
|
9234
|
+
if (!verdict.admit) denial = mergeQuotaDenial(denial, verdict);
|
|
9235
|
+
}
|
|
9236
|
+
if (denial !== void 0) return Promise.resolve({
|
|
9237
|
+
granted: false,
|
|
9238
|
+
...denial
|
|
9239
|
+
});
|
|
9240
|
+
for (const index of matched) {
|
|
9241
|
+
const bucket = bucketFor(index, windowStart);
|
|
9242
|
+
bucket.requests += request.estimate.requests;
|
|
9243
|
+
bucket.tokens += estimateTokens;
|
|
9244
|
+
}
|
|
9245
|
+
nextReservation += 1;
|
|
9246
|
+
const reservationId = `mq-${String(nextReservation)}`;
|
|
9247
|
+
reservations.set(reservationId, {
|
|
9248
|
+
windowStart,
|
|
9249
|
+
estimateTokens,
|
|
9250
|
+
requests: request.estimate.requests,
|
|
9251
|
+
ruleIndexes: matched
|
|
9252
|
+
});
|
|
9253
|
+
return Promise.resolve({
|
|
9254
|
+
granted: true,
|
|
9255
|
+
reservationId
|
|
9256
|
+
});
|
|
9257
|
+
},
|
|
9258
|
+
reconcile(reservationId, usage, actual) {
|
|
9259
|
+
const reservation = reservations.get(reservationId);
|
|
9260
|
+
if (reservation === void 0) return Promise.resolve();
|
|
9261
|
+
reservations.delete(reservationId);
|
|
9262
|
+
const windowStart = windowStartAt(now());
|
|
9263
|
+
if (reservation.windowStart !== windowStart) return Promise.resolve();
|
|
9264
|
+
const delta = quotaActualTokens(usage) - reservation.estimateTokens;
|
|
9265
|
+
const requestsDelta = quotaActualRequestsDelta(actual);
|
|
9266
|
+
for (const index of reservation.ruleIndexes) {
|
|
9267
|
+
const bucket = buckets.get(index);
|
|
9268
|
+
if (bucket !== void 0 && bucket.windowStart === windowStart) {
|
|
9269
|
+
bucket.tokens = Math.max(0, bucket.tokens + delta);
|
|
9270
|
+
bucket.requests += requestsDelta;
|
|
9271
|
+
}
|
|
9272
|
+
}
|
|
9273
|
+
return Promise.resolve();
|
|
9274
|
+
},
|
|
9275
|
+
release(reservationId) {
|
|
9276
|
+
const reservation = reservations.get(reservationId);
|
|
9277
|
+
if (reservation === void 0) return Promise.resolve();
|
|
9278
|
+
reservations.delete(reservationId);
|
|
9279
|
+
const windowStart = windowStartAt(now());
|
|
9280
|
+
if (reservation.windowStart !== windowStart) return Promise.resolve();
|
|
9281
|
+
for (const index of reservation.ruleIndexes) {
|
|
9282
|
+
const bucket = buckets.get(index);
|
|
9283
|
+
if (bucket !== void 0 && bucket.windowStart === windowStart) {
|
|
9284
|
+
bucket.requests = Math.max(0, bucket.requests - reservation.requests);
|
|
9285
|
+
bucket.tokens = Math.max(0, bucket.tokens - reservation.estimateTokens);
|
|
9286
|
+
}
|
|
9287
|
+
}
|
|
9288
|
+
return Promise.resolve();
|
|
9289
|
+
},
|
|
9290
|
+
snapshot() {
|
|
9291
|
+
const windowStart = windowStartAt(now());
|
|
9292
|
+
return frozen.map((rule, index) => {
|
|
9293
|
+
const bucket = buckets.get(index);
|
|
9294
|
+
const current = bucket !== void 0 && bucket.windowStart === windowStart;
|
|
9295
|
+
return {
|
|
9296
|
+
rule,
|
|
9297
|
+
windowStart,
|
|
9298
|
+
requests: current ? bucket.requests : 0,
|
|
9299
|
+
tokens: current ? bucket.tokens : 0
|
|
9300
|
+
};
|
|
9301
|
+
});
|
|
9302
|
+
}
|
|
9303
|
+
};
|
|
9304
|
+
}
|
|
9305
|
+
/**
|
|
9306
|
+
* The default {@link EngineQuotaConfig.maxDenials}: generous next to the
|
|
9307
|
+
* transport default of 3 tries because a denial is a WAIT, not a
|
|
9308
|
+
* failure signal, yet finite because nothing else bounds the pre-wire
|
|
9309
|
+
* loop (the per-agent timeout is checked between turns, not inside a
|
|
9310
|
+
* dispatch).
|
|
9311
|
+
*/
|
|
9312
|
+
const DEFAULT_MAX_QUOTA_DENIALS = 8;
|
|
9313
|
+
/**
|
|
9314
|
+
* Validates createEngine's quota config as a typed ConfigError before
|
|
9315
|
+
* any run could dispatch under a malformed limiter (the intake
|
|
9316
|
+
* discipline every engine option follows).
|
|
9317
|
+
*/
|
|
9318
|
+
function validateEngineQuotaConfig(config, site = "createEngine quota") {
|
|
9319
|
+
if (config === void 0) return;
|
|
9320
|
+
const raw = config;
|
|
9321
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ConfigError(`${site} must be an object with a limiter`);
|
|
9322
|
+
const candidate = raw;
|
|
9323
|
+
const limiter = candidate.limiter;
|
|
9324
|
+
if (typeof limiter !== "object" || limiter === null || typeof limiter.reserve !== "function" || typeof limiter.reconcile !== "function") throw new ConfigError(`${site}.limiter must implement QuotaLimiter (reserve and reconcile functions)`);
|
|
9325
|
+
if (candidate.tenant !== void 0 && (typeof candidate.tenant !== "string" || candidate.tenant === "")) throw new ConfigError(`${site}.tenant must be a nonempty string when given`);
|
|
9326
|
+
if (candidate.onLimiterError !== void 0 && candidate.onLimiterError !== "deny" && candidate.onLimiterError !== "allow") throw new ConfigError(`${site}.onLimiterError must be 'deny' or 'allow' when given`);
|
|
9327
|
+
const reserveContinuations = candidate.reserveContinuations;
|
|
9328
|
+
if (reserveContinuations !== void 0 && typeof reserveContinuations !== "boolean") throw new ConfigError(`${site}.reserveContinuations must be a boolean when given`);
|
|
9329
|
+
const maxDenials = candidate.maxDenials;
|
|
9330
|
+
if (maxDenials !== void 0 && (typeof maxDenials !== "number" || !Number.isInteger(maxDenials) || maxDenials < 1)) throw new ConfigError(`${site}.maxDenials must be a positive integer when given`);
|
|
9331
|
+
const declared = candidate.declaredRules;
|
|
9332
|
+
if (declared !== void 0) validateQuotaRules(declared, `${site}.declaredRules`);
|
|
9333
|
+
}
|
|
9334
|
+
//#endregion
|
|
9335
|
+
//#region src/model/failover.ts
|
|
9336
|
+
/** Normalizes the author-facing ModelChoice.fallbacks list. */
|
|
9337
|
+
function normalizeFallbacks(refs) {
|
|
9338
|
+
return (refs ?? []).map((model) => ({ model }));
|
|
9339
|
+
}
|
|
9340
|
+
/**
|
|
9341
|
+
* Maps a retry class to its failover trigger once retries exhaust.
|
|
9342
|
+
* Overloaded (529) is transport-class for failover purposes; a
|
|
9343
|
+
* non-retryable error never fails over.
|
|
9344
|
+
*/
|
|
9345
|
+
function failoverTriggerOf(retryClass) {
|
|
9346
|
+
if (retryClass === void 0) return;
|
|
9347
|
+
return retryClass === "rate-limit" ? "rate-limit" : "transport";
|
|
9348
|
+
}
|
|
9349
|
+
/**
|
|
9350
|
+
* The next target index past `from` that serves `trigger`, or undefined
|
|
9351
|
+
* when the chain is exhausted. Index 0 is the primary; the chain never
|
|
9352
|
+
* moves backwards (sticky failover).
|
|
9353
|
+
*/
|
|
9354
|
+
function nextFailover(targets, trigger, from) {
|
|
9355
|
+
for (let index = from + 1; index < targets.length; index += 1) {
|
|
9356
|
+
const on = targets[index]?.on;
|
|
9357
|
+
if (on === void 0 || on.includes(trigger)) return index;
|
|
9358
|
+
}
|
|
9359
|
+
}
|
|
9360
|
+
/**
|
|
9361
|
+
* Classifies a terminal agent outcome for the degenerate fallback:
|
|
9362
|
+
* schema-mismatch errors are
|
|
9363
|
+
* 'schema-exhausted'; any other error is 'error'; limit terminals (the
|
|
9364
|
+
* no-progress abort included) are 'limit'; cancelled, escalated, and
|
|
9365
|
+
* skipped never trigger.
|
|
9366
|
+
*/
|
|
9367
|
+
function fallbackTriggerOf(outcome) {
|
|
9368
|
+
if (outcome.status === "error") return outcome.error?.kind === "schema-mismatch" ? "schema-exhausted" : "error";
|
|
9369
|
+
if (outcome.status === "limit") return "limit";
|
|
9370
|
+
}
|
|
9371
|
+
//#endregion
|
|
9372
|
+
//#region src/model/projector.ts
|
|
9373
|
+
/** The provider family of an adapter: `provider` when set, else `id`. */
|
|
9374
|
+
function providerOf(adapter) {
|
|
9375
|
+
return adapter.provider ?? adapter.id;
|
|
9376
|
+
}
|
|
9377
|
+
/**
|
|
9378
|
+
* Projects the canonical history into the target provider's view:
|
|
9379
|
+
* provider-raw parts of a DIFFERENT provider are omitted; everything
|
|
9380
|
+
* else (text, images, tool calls, tool results, compaction content)
|
|
9381
|
+
* passes through untouched. Messages whose parts all belong to another
|
|
9382
|
+
* provider vanish entirely rather than ride as empty messages.
|
|
9383
|
+
*/
|
|
9384
|
+
function projectHistory(messages, targetProvider) {
|
|
9385
|
+
const projected = [];
|
|
9386
|
+
for (const msg of messages) {
|
|
9387
|
+
const parts = msg.parts.filter((part) => part.type !== "provider-raw" || part.provider === targetProvider);
|
|
9388
|
+
if (parts.length === 0 && msg.parts.length > 0) continue;
|
|
9389
|
+
projected.push(parts.length === msg.parts.length ? msg : {
|
|
9390
|
+
...msg,
|
|
9391
|
+
parts
|
|
9392
|
+
});
|
|
9393
|
+
}
|
|
9394
|
+
return projected;
|
|
9395
|
+
}
|
|
9396
|
+
/**
|
|
9397
|
+
* Lifts the adapter-shipped retention payload of one finished turn into
|
|
9398
|
+
* provider-raw parts (the retention transport). Reads
|
|
9399
|
+
* providerMetadata[<adapter id>].retainedParts and tags each block with
|
|
9400
|
+
* the adapter's provider family. Returns [] when the adapter shipped
|
|
9401
|
+
* nothing.
|
|
9402
|
+
*/
|
|
9403
|
+
function liftRetainedParts(providerMetadata, adapter) {
|
|
9404
|
+
const namespace = providerMetadata?.[adapter.id];
|
|
9405
|
+
if (typeof namespace !== "object" || namespace === null) return [];
|
|
9406
|
+
const retained = namespace.retainedParts;
|
|
9407
|
+
if (!Array.isArray(retained)) return [];
|
|
9408
|
+
const blocks = retained;
|
|
9409
|
+
const provider = providerOf(adapter);
|
|
9410
|
+
return blocks.map((block) => ({
|
|
9411
|
+
type: "provider-raw",
|
|
9412
|
+
provider,
|
|
9413
|
+
block
|
|
9414
|
+
}));
|
|
9415
|
+
}
|
|
9416
|
+
//#endregion
|
|
9417
|
+
//#region src/model/retry.ts
|
|
9418
|
+
/**
|
|
9419
|
+
* Transport RetryPolicy (M4-T05): retries live UNDER the journal. A
|
|
9420
|
+
* retried-then-successful call is exactly one journal entry with one
|
|
9421
|
+
* usage total, transport retries never count as lineage attempts
|
|
9422
|
+
* (DEF-3), the provider-supplied retryAfterMs replaces the computed
|
|
9423
|
+
* delay, and task-class failures never retry by construction (a
|
|
9424
|
+
* non-retryable WireError has no retry class).
|
|
9425
|
+
*
|
|
9426
|
+
* Full contract: https://docs.rulvar.com/guide/model-routing; the
|
|
9427
|
+
* Appendix A defaults were committed at the M4 entry gate.
|
|
9428
|
+
*/
|
|
9429
|
+
/**
|
|
9430
|
+
* Captured at module load, before the InProcessRunner's nondeterminism
|
|
9431
|
+
* guard can patch the global: the engine's own jitter is journal
|
|
9432
|
+
* invisible and must never be blamed on workflow code.
|
|
9433
|
+
*/
|
|
9434
|
+
const nativeRandom = Math.random;
|
|
9435
|
+
/** Appendix A committed defaults (M4 entry gate, PR #26). */
|
|
9436
|
+
const DEFAULT_RETRY_POLICY = {
|
|
9437
|
+
attempts: 3,
|
|
9438
|
+
backoff: {
|
|
9439
|
+
initialMs: 500,
|
|
9440
|
+
factor: 2,
|
|
9441
|
+
maxMs: 8e3,
|
|
9442
|
+
jitter: true
|
|
9443
|
+
},
|
|
9444
|
+
retryOn: [
|
|
9445
|
+
"transport",
|
|
9446
|
+
"rate-limit",
|
|
9447
|
+
"overloaded"
|
|
9448
|
+
]
|
|
9449
|
+
};
|
|
9450
|
+
/**
|
|
9451
|
+
* Classifies a WireError for the retry engine. Task-class failures are
|
|
9129
9452
|
* never retryable by construction: adapters mark them retryable: false
|
|
9130
9453
|
* and this returns undefined. The kind travels in WireError.data.kind;
|
|
9131
9454
|
* anything retryable without a specific kind is transport.
|
|
@@ -11579,6 +11902,8 @@ async function runAgent(options) {
|
|
|
11579
11902
|
for (;;) {
|
|
11580
11903
|
const target = site.chain[site.cursor.index] ?? site.chain[0];
|
|
11581
11904
|
let tries = 0;
|
|
11905
|
+
let denialTurns = 0;
|
|
11906
|
+
const maxDenials = options.quota?.maxDenials ?? 8;
|
|
11582
11907
|
inner: for (;;) {
|
|
11583
11908
|
let reservationId;
|
|
11584
11909
|
const segmentReservations = [];
|
|
@@ -11819,14 +12144,16 @@ async function runAgent(options) {
|
|
|
11819
12144
|
reportedLimits: limited.reportedLimits
|
|
11820
12145
|
});
|
|
11821
12146
|
}
|
|
11822
|
-
|
|
12147
|
+
if (outcome.quotaDenied === true) denialTurns += 1;
|
|
12148
|
+
else tries += 1;
|
|
11823
12149
|
const retryClass = outcome.aborted === "idle" ? "transport" : outcome.wireError === void 0 ? void 0 : retryClassOf(outcome.wireError);
|
|
11824
12150
|
if (retryClass === void 0) return {
|
|
11825
12151
|
outcome,
|
|
11826
12152
|
target
|
|
11827
12153
|
};
|
|
11828
12154
|
usageApprox = usageApprox || outcome.usageApprox;
|
|
11829
|
-
|
|
12155
|
+
const retryBudgetLeft = outcome.quotaDenied === true ? denialTurns < maxDenials : tries < retryPolicy.attempts;
|
|
12156
|
+
if (retryOn.includes(retryClass) && retryBudgetLeft) {
|
|
11830
12157
|
const abortedBefore = abortKind();
|
|
11831
12158
|
if (abortedBefore !== void 0) return {
|
|
11832
12159
|
outcome: abortedOutcome(abortedBefore),
|
|
@@ -11834,7 +12161,7 @@ async function runAgent(options) {
|
|
|
11834
12161
|
};
|
|
11835
12162
|
const retryAfter = (outcome.wireError?.data)?.retryAfterMs;
|
|
11836
12163
|
if (outcome.wireError !== void 0) {
|
|
11837
|
-
transportRetries += 1;
|
|
12164
|
+
if (outcome.quotaDenied !== true) transportRetries += 1;
|
|
11838
12165
|
events?.emit({
|
|
11839
12166
|
type: "agent:error",
|
|
11840
12167
|
agentType,
|
|
@@ -11843,7 +12170,7 @@ async function runAgent(options) {
|
|
|
11843
12170
|
willRetry: true
|
|
11844
12171
|
});
|
|
11845
12172
|
}
|
|
11846
|
-
await backoffWait(retryDelayMs(retryPolicy, tries - 1, typeof retryAfter === "number" ? retryAfter : void 0, retryRandom));
|
|
12173
|
+
await backoffWait(retryDelayMs(retryPolicy, outcome.quotaDenied === true ? denialTurns - 1 : tries - 1, typeof retryAfter === "number" ? retryAfter : void 0, retryRandom));
|
|
11847
12174
|
const abortedAfter = abortKind();
|
|
11848
12175
|
if (abortedAfter !== void 0) return {
|
|
11849
12176
|
outcome: abortedOutcome(abortedAfter),
|
|
@@ -14356,319 +14683,6 @@ function ladderRungChoice(ladder, index) {
|
|
|
14356
14683
|
};
|
|
14357
14684
|
}
|
|
14358
14685
|
//#endregion
|
|
14359
|
-
//#region src/model/quota.ts
|
|
14360
|
-
/**
|
|
14361
|
-
* Quota rules and the in-process reference QuotaLimiter (RV-215).
|
|
14362
|
-
* The rule model is shared by every reference implementation
|
|
14363
|
-
* (memoryQuotaLimiter here, SqliteQuotaLimiter in
|
|
14364
|
-
* @rulvar/store-sqlite): fixed one-minute windows aligned to the
|
|
14365
|
-
* epoch, admission at reservation time, reconciliation to actual
|
|
14366
|
-
* usage inside the same window. The hard guarantee is on
|
|
14367
|
-
* `requestsPerMinute` (every wire attempt is exactly one request);
|
|
14368
|
-
* `tokensPerMinute` admits on the heuristic estimate and settles to
|
|
14369
|
-
* actual usage, so token windows are approximate at admission and
|
|
14370
|
-
* exact at settlement.
|
|
14371
|
-
*
|
|
14372
|
-
* Docs: https://docs.rulvar.com/guide/model-routing
|
|
14373
|
-
*/
|
|
14374
|
-
/**
|
|
14375
|
-
* Captured at module load, before the InProcessRunner's
|
|
14376
|
-
* nondeterminism guard can patch the global: the limiter's clock is
|
|
14377
|
-
* engine infrastructure on the live-only dispatch path and must never
|
|
14378
|
-
* be blamed on workflow code.
|
|
14379
|
-
*/
|
|
14380
|
-
const nativeNow = Date.now;
|
|
14381
|
-
/** The fixed accounting window every PerMinute cap counts over. */
|
|
14382
|
-
const QUOTA_WINDOW_MS = 6e4;
|
|
14383
|
-
/**
|
|
14384
|
-
* Validates a quota rule set as a typed ConfigError before any
|
|
14385
|
-
* limiter can admit under it: a non-array or empty set, a rule
|
|
14386
|
-
* without a cap, a malformed dimension, or a malformed cap all fail
|
|
14387
|
-
* loud at construction. Shared by every reference implementation.
|
|
14388
|
-
*/
|
|
14389
|
-
function validateQuotaRules(rules, site = "quota rules") {
|
|
14390
|
-
const raw = rules;
|
|
14391
|
-
if (!Array.isArray(raw)) throw new ConfigError(`${site} must be an array of QuotaRule objects`);
|
|
14392
|
-
if (raw.length === 0) throw new ConfigError(`${site} must contain at least one rule`);
|
|
14393
|
-
raw.forEach((entry, index) => {
|
|
14394
|
-
const at = `${site}[${String(index)}]`;
|
|
14395
|
-
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) throw new ConfigError(`${at} must be a QuotaRule object`);
|
|
14396
|
-
const rule = entry;
|
|
14397
|
-
for (const dimension of [
|
|
14398
|
-
"provider",
|
|
14399
|
-
"model",
|
|
14400
|
-
"tenant"
|
|
14401
|
-
]) {
|
|
14402
|
-
const value = rule[dimension];
|
|
14403
|
-
if (value !== void 0 && (typeof value !== "string" || value === "")) throw new ConfigError(`${at}.${dimension} must be a nonempty string when given`);
|
|
14404
|
-
}
|
|
14405
|
-
if (rule.requestsPerMinute === void 0 && rule.tokensPerMinute === void 0) throw new ConfigError(`${at} must set requestsPerMinute or tokensPerMinute (or both)`);
|
|
14406
|
-
for (const cap of ["requestsPerMinute", "tokensPerMinute"]) if (rule[cap] !== void 0) requirePositiveInteger$2(rule[cap], `${at}.${cap}`);
|
|
14407
|
-
});
|
|
14408
|
-
}
|
|
14409
|
-
/**
|
|
14410
|
-
* The canonical content key of one rule (RV608, promoted from the
|
|
14411
|
-
* store limiters): a fixed-field-order JSON of the rule, identical
|
|
14412
|
-
* across processes and hosts for identical rules. It is the bucket key
|
|
14413
|
-
* of both store references, the input of
|
|
14414
|
-
* `quotaRulesFingerprint`, and the CANONICAL ORDER every reference
|
|
14415
|
-
* limiter folds denials in, so equal rule sets produce byte-identical
|
|
14416
|
-
* refusal objects regardless of array permutation.
|
|
14417
|
-
*/
|
|
14418
|
-
function quotaRuleKey(rule) {
|
|
14419
|
-
return JSON.stringify({
|
|
14420
|
-
provider: rule.provider ?? null,
|
|
14421
|
-
model: rule.model ?? null,
|
|
14422
|
-
tenant: rule.tenant ?? null,
|
|
14423
|
-
requestsPerMinute: rule.requestsPerMinute ?? null,
|
|
14424
|
-
tokensPerMinute: rule.tokensPerMinute ?? null
|
|
14425
|
-
});
|
|
14426
|
-
}
|
|
14427
|
-
/**
|
|
14428
|
-
* Validates a rule set and returns the immutable snapshot every
|
|
14429
|
-
* reference limiter admits under (RV608): a fresh array of fresh
|
|
14430
|
-
* objects carrying ONLY the known rule fields, each frozen, the array
|
|
14431
|
-
* frozen. The caller's array and objects stay untouched and unshared,
|
|
14432
|
-
* so ordinary JavaScript after the constructor (a pushed rule, a
|
|
14433
|
-
* reassigned cap) can no longer change a decision, a bucket key, or a
|
|
14434
|
-
* recorded fingerprint.
|
|
14435
|
-
*
|
|
14436
|
-
* A set containing two rules with the same canonical content key is
|
|
14437
|
-
* refused typed (RV704): the memory reference buckets by rule INDEX
|
|
14438
|
-
* (each copy counts independently, the full cap admits) while the
|
|
14439
|
-
* store references bucket by rule KEY (one shared bucket is debited
|
|
14440
|
-
* once per matching copy, half the cap admits), so the same duplicated
|
|
14441
|
-
* configuration admitted differently per storage. Refusing it at the
|
|
14442
|
-
* shared construction chokepoint is what keeps equal configurations
|
|
14443
|
-
* equal on every storage.
|
|
14444
|
-
*/
|
|
14445
|
-
function snapshotQuotaRules(rules, site = "quota rules") {
|
|
14446
|
-
validateQuotaRules(rules, site);
|
|
14447
|
-
const firstIndexByKey = /* @__PURE__ */ new Map();
|
|
14448
|
-
rules.forEach((rule, index) => {
|
|
14449
|
-
const key = quotaRuleKey(rule);
|
|
14450
|
-
const first = firstIndexByKey.get(key);
|
|
14451
|
-
if (first !== void 0) throw new ConfigError(`${site}[${String(index)}] duplicates ${site}[${String(first)}] (rule key ${key}): identical rules occupy independent buckets in memory but share one key-debited bucket on keyed storage, so one configuration would admit differently per store; delete the duplicate`);
|
|
14452
|
-
firstIndexByKey.set(key, index);
|
|
14453
|
-
});
|
|
14454
|
-
return Object.freeze(rules.map((rule) => Object.freeze({
|
|
14455
|
-
...rule.provider === void 0 ? {} : { provider: rule.provider },
|
|
14456
|
-
...rule.model === void 0 ? {} : { model: rule.model },
|
|
14457
|
-
...rule.tenant === void 0 ? {} : { tenant: rule.tenant },
|
|
14458
|
-
...rule.requestsPerMinute === void 0 ? {} : { requestsPerMinute: rule.requestsPerMinute },
|
|
14459
|
-
...rule.tokensPerMinute === void 0 ? {} : { tokensPerMinute: rule.tokensPerMinute }
|
|
14460
|
-
})));
|
|
14461
|
-
}
|
|
14462
|
-
/** True when every dimension the rule pins matches the request. */
|
|
14463
|
-
function quotaRuleMatches(rule, request) {
|
|
14464
|
-
return (rule.provider === void 0 || rule.provider === request.provider) && (rule.model === void 0 || rule.model === request.model) && (rule.tenant === void 0 || rule.tenant === request.tenant);
|
|
14465
|
-
}
|
|
14466
|
-
/** The tokens a reservation is admitted under: input estimate plus the output cap. */
|
|
14467
|
-
function quotaEstimateTokens(request) {
|
|
14468
|
-
return request.estimate.inputTokens + (request.estimate.maxOutputTokens ?? 0);
|
|
14469
|
-
}
|
|
14470
|
-
/** The tokens a settled attempt actually consumed. */
|
|
14471
|
-
function quotaActualTokens(usage) {
|
|
14472
|
-
return usage.inputTokens + usage.outputTokens;
|
|
14473
|
-
}
|
|
14474
|
-
/**
|
|
14475
|
-
* The request-count settlement delta of one reservation (RV905): the
|
|
14476
|
-
* reservation admitted ONE wire request, and `actual.requests` names
|
|
14477
|
-
* how many the attempt actually made (an adapter absorbing
|
|
14478
|
-
* provider-side continuations dispatches several inside one reserved
|
|
14479
|
-
* call). Non-integer, non-positive, or absent actuals settle as the
|
|
14480
|
-
* single reserved request (delta 0); a settlement only ever ADDS, the
|
|
14481
|
-
* calls already happened. Shared by every reference limiter so the
|
|
14482
|
-
* three implementations cannot disagree about the arithmetic.
|
|
14483
|
-
*/
|
|
14484
|
-
function quotaActualRequestsDelta(actual) {
|
|
14485
|
-
const requests = actual?.requests;
|
|
14486
|
-
return typeof requests === "number" && Number.isInteger(requests) && requests > 1 ? requests - 1 : 0;
|
|
14487
|
-
}
|
|
14488
|
-
/**
|
|
14489
|
-
* One rule's admission verdict against its current-window counters,
|
|
14490
|
-
* the pure decision both reference implementations share. A denial
|
|
14491
|
-
* carries the window remainder as retryAfterMs, except when the
|
|
14492
|
-
* estimate alone can never fit the token cap: that denial says
|
|
14493
|
-
* retryAfterMs 0 (retry immediately), so the caller's bounded
|
|
14494
|
-
* attempts exhaust without waiting and failover gets its chance.
|
|
14495
|
-
*/
|
|
14496
|
-
function quotaRuleAdmission(rule, counters, estimate, msUntilWindowEnd) {
|
|
14497
|
-
if (rule.requestsPerMinute !== void 0 && counters.requests + estimate.requests > rule.requestsPerMinute) return {
|
|
14498
|
-
admit: false,
|
|
14499
|
-
retryAfterMs: msUntilWindowEnd,
|
|
14500
|
-
reason: `requestsPerMinute ${String(rule.requestsPerMinute)} exhausted`
|
|
14501
|
-
};
|
|
14502
|
-
if (rule.tokensPerMinute !== void 0) {
|
|
14503
|
-
if (estimate.tokens > rule.tokensPerMinute) return {
|
|
14504
|
-
admit: false,
|
|
14505
|
-
retryAfterMs: 0,
|
|
14506
|
-
reason: `the estimate of ${String(estimate.tokens)} tokens can never fit tokensPerMinute ${String(rule.tokensPerMinute)}`
|
|
14507
|
-
};
|
|
14508
|
-
if (counters.tokens + estimate.tokens > rule.tokensPerMinute) return {
|
|
14509
|
-
admit: false,
|
|
14510
|
-
retryAfterMs: msUntilWindowEnd,
|
|
14511
|
-
reason: `tokensPerMinute ${String(rule.tokensPerMinute)} exhausted`
|
|
14512
|
-
};
|
|
14513
|
-
}
|
|
14514
|
-
return { admit: true };
|
|
14515
|
-
}
|
|
14516
|
-
/**
|
|
14517
|
-
* Folds one more failing rule into the decision the caller returns:
|
|
14518
|
-
* the wait is the LONGEST failing horizon (every matching rule must
|
|
14519
|
-
* admit), and the FIRST failing rule names the denial.
|
|
14520
|
-
*/
|
|
14521
|
-
function mergeQuotaDenial(current, next) {
|
|
14522
|
-
if (current === void 0) return {
|
|
14523
|
-
retryAfterMs: next.retryAfterMs,
|
|
14524
|
-
reason: next.reason
|
|
14525
|
-
};
|
|
14526
|
-
return next.retryAfterMs > current.retryAfterMs ? {
|
|
14527
|
-
retryAfterMs: next.retryAfterMs,
|
|
14528
|
-
reason: current.reason
|
|
14529
|
-
} : current;
|
|
14530
|
-
}
|
|
14531
|
-
/**
|
|
14532
|
-
* The in-process reference QuotaLimiter: fixed epoch-aligned
|
|
14533
|
-
* one-minute windows over the shared rule model. Coordinates every
|
|
14534
|
-
* engine that shares THIS instance inside one process; processes
|
|
14535
|
-
* coordinate through a shared-storage implementation of the same SPI
|
|
14536
|
-
* (SqliteQuotaLimiter in @rulvar/store-sqlite) instead.
|
|
14537
|
-
*/
|
|
14538
|
-
function memoryQuotaLimiter(rules, options = {}) {
|
|
14539
|
-
const frozen = snapshotQuotaRules(rules, "memoryQuotaLimiter rules");
|
|
14540
|
-
const ordered = frozen.map((rule, index) => ({
|
|
14541
|
-
rule,
|
|
14542
|
-
index,
|
|
14543
|
-
key: quotaRuleKey(rule)
|
|
14544
|
-
})).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
14545
|
-
const now = options.now ?? (() => nativeNow());
|
|
14546
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
14547
|
-
const reservations = /* @__PURE__ */ new Map();
|
|
14548
|
-
let nextReservation = 0;
|
|
14549
|
-
const windowStartAt = (at) => at - at % QUOTA_WINDOW_MS;
|
|
14550
|
-
const bucketFor = (ruleIndex, windowStart) => {
|
|
14551
|
-
let bucket = buckets.get(ruleIndex);
|
|
14552
|
-
if (bucket === void 0 || bucket.windowStart !== windowStart) {
|
|
14553
|
-
bucket = {
|
|
14554
|
-
windowStart,
|
|
14555
|
-
requests: 0,
|
|
14556
|
-
tokens: 0
|
|
14557
|
-
};
|
|
14558
|
-
buckets.set(ruleIndex, bucket);
|
|
14559
|
-
}
|
|
14560
|
-
return bucket;
|
|
14561
|
-
};
|
|
14562
|
-
const prune = (windowStart) => {
|
|
14563
|
-
for (const [id, reservation] of reservations) if (reservation.windowStart < windowStart) reservations.delete(id);
|
|
14564
|
-
};
|
|
14565
|
-
return {
|
|
14566
|
-
reserve(request) {
|
|
14567
|
-
const at = now();
|
|
14568
|
-
const windowStart = windowStartAt(at);
|
|
14569
|
-
prune(windowStart);
|
|
14570
|
-
const estimateTokens = quotaEstimateTokens(request);
|
|
14571
|
-
const msUntilWindowEnd = windowStart + QUOTA_WINDOW_MS - at;
|
|
14572
|
-
const matched = [];
|
|
14573
|
-
let denial;
|
|
14574
|
-
for (const { rule, index } of ordered) {
|
|
14575
|
-
if (!quotaRuleMatches(rule, request)) continue;
|
|
14576
|
-
matched.push(index);
|
|
14577
|
-
const verdict = quotaRuleAdmission(rule, bucketFor(index, windowStart), {
|
|
14578
|
-
requests: request.estimate.requests,
|
|
14579
|
-
tokens: estimateTokens
|
|
14580
|
-
}, msUntilWindowEnd);
|
|
14581
|
-
if (!verdict.admit) denial = mergeQuotaDenial(denial, verdict);
|
|
14582
|
-
}
|
|
14583
|
-
if (denial !== void 0) return Promise.resolve({
|
|
14584
|
-
granted: false,
|
|
14585
|
-
...denial
|
|
14586
|
-
});
|
|
14587
|
-
for (const index of matched) {
|
|
14588
|
-
const bucket = bucketFor(index, windowStart);
|
|
14589
|
-
bucket.requests += request.estimate.requests;
|
|
14590
|
-
bucket.tokens += estimateTokens;
|
|
14591
|
-
}
|
|
14592
|
-
nextReservation += 1;
|
|
14593
|
-
const reservationId = `mq-${String(nextReservation)}`;
|
|
14594
|
-
reservations.set(reservationId, {
|
|
14595
|
-
windowStart,
|
|
14596
|
-
estimateTokens,
|
|
14597
|
-
requests: request.estimate.requests,
|
|
14598
|
-
ruleIndexes: matched
|
|
14599
|
-
});
|
|
14600
|
-
return Promise.resolve({
|
|
14601
|
-
granted: true,
|
|
14602
|
-
reservationId
|
|
14603
|
-
});
|
|
14604
|
-
},
|
|
14605
|
-
reconcile(reservationId, usage, actual) {
|
|
14606
|
-
const reservation = reservations.get(reservationId);
|
|
14607
|
-
if (reservation === void 0) return Promise.resolve();
|
|
14608
|
-
reservations.delete(reservationId);
|
|
14609
|
-
const windowStart = windowStartAt(now());
|
|
14610
|
-
if (reservation.windowStart !== windowStart) return Promise.resolve();
|
|
14611
|
-
const delta = quotaActualTokens(usage) - reservation.estimateTokens;
|
|
14612
|
-
const requestsDelta = quotaActualRequestsDelta(actual);
|
|
14613
|
-
for (const index of reservation.ruleIndexes) {
|
|
14614
|
-
const bucket = buckets.get(index);
|
|
14615
|
-
if (bucket !== void 0 && bucket.windowStart === windowStart) {
|
|
14616
|
-
bucket.tokens = Math.max(0, bucket.tokens + delta);
|
|
14617
|
-
bucket.requests += requestsDelta;
|
|
14618
|
-
}
|
|
14619
|
-
}
|
|
14620
|
-
return Promise.resolve();
|
|
14621
|
-
},
|
|
14622
|
-
release(reservationId) {
|
|
14623
|
-
const reservation = reservations.get(reservationId);
|
|
14624
|
-
if (reservation === void 0) return Promise.resolve();
|
|
14625
|
-
reservations.delete(reservationId);
|
|
14626
|
-
const windowStart = windowStartAt(now());
|
|
14627
|
-
if (reservation.windowStart !== windowStart) return Promise.resolve();
|
|
14628
|
-
for (const index of reservation.ruleIndexes) {
|
|
14629
|
-
const bucket = buckets.get(index);
|
|
14630
|
-
if (bucket !== void 0 && bucket.windowStart === windowStart) {
|
|
14631
|
-
bucket.requests = Math.max(0, bucket.requests - reservation.requests);
|
|
14632
|
-
bucket.tokens = Math.max(0, bucket.tokens - reservation.estimateTokens);
|
|
14633
|
-
}
|
|
14634
|
-
}
|
|
14635
|
-
return Promise.resolve();
|
|
14636
|
-
},
|
|
14637
|
-
snapshot() {
|
|
14638
|
-
const windowStart = windowStartAt(now());
|
|
14639
|
-
return frozen.map((rule, index) => {
|
|
14640
|
-
const bucket = buckets.get(index);
|
|
14641
|
-
const current = bucket !== void 0 && bucket.windowStart === windowStart;
|
|
14642
|
-
return {
|
|
14643
|
-
rule,
|
|
14644
|
-
windowStart,
|
|
14645
|
-
requests: current ? bucket.requests : 0,
|
|
14646
|
-
tokens: current ? bucket.tokens : 0
|
|
14647
|
-
};
|
|
14648
|
-
});
|
|
14649
|
-
}
|
|
14650
|
-
};
|
|
14651
|
-
}
|
|
14652
|
-
/**
|
|
14653
|
-
* Validates createEngine's quota config as a typed ConfigError before
|
|
14654
|
-
* any run could dispatch under a malformed limiter (the intake
|
|
14655
|
-
* discipline every engine option follows).
|
|
14656
|
-
*/
|
|
14657
|
-
function validateEngineQuotaConfig(config, site = "createEngine quota") {
|
|
14658
|
-
if (config === void 0) return;
|
|
14659
|
-
const raw = config;
|
|
14660
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ConfigError(`${site} must be an object with a limiter`);
|
|
14661
|
-
const candidate = raw;
|
|
14662
|
-
const limiter = candidate.limiter;
|
|
14663
|
-
if (typeof limiter !== "object" || limiter === null || typeof limiter.reserve !== "function" || typeof limiter.reconcile !== "function") throw new ConfigError(`${site}.limiter must implement QuotaLimiter (reserve and reconcile functions)`);
|
|
14664
|
-
if (candidate.tenant !== void 0 && (typeof candidate.tenant !== "string" || candidate.tenant === "")) throw new ConfigError(`${site}.tenant must be a nonempty string when given`);
|
|
14665
|
-
if (candidate.onLimiterError !== void 0 && candidate.onLimiterError !== "deny" && candidate.onLimiterError !== "allow") throw new ConfigError(`${site}.onLimiterError must be 'deny' or 'allow' when given`);
|
|
14666
|
-
const reserveContinuations = candidate.reserveContinuations;
|
|
14667
|
-
if (reserveContinuations !== void 0 && typeof reserveContinuations !== "boolean") throw new ConfigError(`${site}.reserveContinuations must be a boolean when given`);
|
|
14668
|
-
const declared = candidate.declaredRules;
|
|
14669
|
-
if (declared !== void 0) validateQuotaRules(declared, `${site}.declaredRules`);
|
|
14670
|
-
}
|
|
14671
|
-
//#endregion
|
|
14672
14686
|
//#region src/runtime/usage-limits.ts
|
|
14673
14687
|
/**
|
|
14674
14688
|
* UsageLimits (M1-T06): normative limit vocabulary and the per-spawn merge.
|
|
@@ -16614,7 +16628,8 @@ function createCtx(internals, rootWorkflow) {
|
|
|
16614
16628
|
}),
|
|
16615
16629
|
reconcile: (reservationId, usage, actual) => quota.limiter.reconcile(reservationId, usage, actual),
|
|
16616
16630
|
onLimiterError: quota.onLimiterError,
|
|
16617
|
-
reserveContinuations: quota.reserveContinuations
|
|
16631
|
+
reserveContinuations: quota.reserveContinuations,
|
|
16632
|
+
maxDenials: quota.maxDenials
|
|
16618
16633
|
};
|
|
16619
16634
|
const limiterRelease = quota.limiter.release?.bind(quota.limiter);
|
|
16620
16635
|
if (limiterRelease !== void 0) runAgentOptions.quota.release = limiterRelease;
|
|
@@ -24105,6 +24120,7 @@ function createEngine(options) {
|
|
|
24105
24120
|
...options.quota.tenant === void 0 ? {} : { tenant: options.quota.tenant },
|
|
24106
24121
|
onLimiterError: options.quota.onLimiterError ?? "deny",
|
|
24107
24122
|
reserveContinuations: options.quota.reserveContinuations ?? false,
|
|
24123
|
+
maxDenials: options.quota.maxDenials ?? 8,
|
|
24108
24124
|
...options.quota.declaredRules === void 0 ? {} : { declaredRules: options.quota.declaredRules }
|
|
24109
24125
|
};
|
|
24110
24126
|
const knowledgeStore = options.stores?.modelKnowledge;
|
|
@@ -25130,4 +25146,4 @@ function createSandboxBridge(ctx, options) {
|
|
|
25130
25146
|
};
|
|
25131
25147
|
}
|
|
25132
25148
|
//#endregion
|
|
25133
|
-
export { AWAIT_SCHEMA, AdmissionController, AdmissionRejectedError, AgentCallError, BUDGET_ABORT_REASON, BudgetExhaustedError, CANCEL_AGENT_SCHEMA, CHECKPOINT_FORMAT_V1, CLAIM_STATEMENT_MAX_CHARS, CLAIM_TTL_DAYS, COMPACTION_SUMMARY_PREFIX, CURRENT_HASH_VERSION, ConfigError, DEFAULT_ANCHOR_PATTERN, DEFAULT_ARTIFACT_PATTERN, DEFAULT_CHILD_BUDGET_FRACTION, DEFAULT_CHILD_RESULT_PAGE_CHARS, DEFAULT_CITATION_PATTERN, DEFAULT_CITATION_SAMPLE, DEFAULT_CLAIM_JUDGE_MAX_TURNS, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ESCALATION_LIMITS, DEFAULT_EVIDENCE_CALLS_PER_ENTRY, DEFAULT_EVIDENCE_GRADE_PHRASES, DEFAULT_EVIDENCE_MIN_SHARE, DEFAULT_EVIDENCE_OVERHEAD_CALLS, DEFAULT_FINISH_MAX_REPAIRS, DEFAULT_FLAT_RESERVE_USD, DEFAULT_MAX_CHILDREN_PER_NODE, DEFAULT_MAX_CLAIM_PAIRS, DEFAULT_MAX_CONTRADICTIONS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_EXCERPT_CHARS, DEFAULT_MAX_OSCILLATIONS_PER_KEY, DEFAULT_MAX_PAIR_EXCERPT_CHARS, DEFAULT_MAX_PINNED_WORKTREES, DEFAULT_MAX_POOL_PER_PAIR, DEFAULT_MAX_REVISIONS_PER_RUN, DEFAULT_MAX_TOTAL_SPAWNS, DEFAULT_MAX_TURNS, DEFAULT_MODEL_RETRY_ATTEMPTS, DEFAULT_NO_PROGRESS_TURNS, DEFAULT_PER_RUN_CONCURRENCY, DEFAULT_RETRY_POLICY, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_SYNTHESIS_MAX_TURNS, DEFAULT_SYNTHESIS_NOTE_MAX_TURNS, DedupIndex, DeterminismError, EMIT_RESULT_TOOL, EMPTY_SCHEMA_HASH, EMPTY_TOOLSET_HASH, ESCALATE_TOOL_NAME, ESCALATION_REPORT_SCHEMA, ESCALATION_REQUEST_SCHEMA, EVENT_SEGMENT_STRIDE, EscalationDecisionAbortedError, EventBus, ExternalRegistry, FINALIZE_SYNTHESIS_INSTRUCTION, FINISH_SCHEMA, FINISH_SECTIONAL_SCHEMA, FINISH_TOOL_NAME, FailRunError, FileModelKnowledgeStore, FileTranscriptStore, GET_CHILD_RESULT_SCHEMA, GET_CHILD_RESULT_TOOL_NAME, GitWorktreeProvider, IMPLEMENTATION_PROFILE_LIMITS, INBOX_PROPOSAL_TTL_DAYS, IN_FLIGHT_EXPOSURE_REFUSAL_PREFIX, InMemoryStore, InMemoryTranscriptStore, InProcessRunner, InvalidResolutionError, JOURNAL_ENVELOPE_MARKER, JournalCompatibilityError, JournalMatcher, JournalMissError, JournalOrderViolation, JsonlFileStore, KB_ACTIVE_CLAIMS_CAP, KB_CARD_RENDER_BUDGET_CHARS, KeyedLimiter, KnowledgeCasError, LARGE_VALUE_WARN_BYTES, LEGACY_LTID_PREFIX, LEGACY_SIGNATURE_INPUTS, LINEAGE_SIG_VERSION, LeaseHeldError, LineageIndex, MASKED_SECRET, MAX_CHILD_RESULT_PAGE_CHARS, MAX_DEPTH_CEILING, MAX_RUN_ID_LENGTH, MAX_TIMER_DELAY_MS, ModelRetry, NoProgressDetector, NonSerializableValueError, ORCHESTRATE_WORKFLOW_NAME, OrchestratorCapConfigError, PARALLEL_AGENTS_SCHEMA, PROGRESS_REPORT_TOOL_NAME, ParallelSiteCounter, PlanInvariantError, QUOTA_WINDOW_MS, READ_CHILD_ARTIFACT_SCHEMA, READ_CHILD_ARTIFACT_TOOL_NAME, RESEARCH_PROFILE_LIMITS, REVIEW_PROFILE_LIMITS, ROLE_EFFORT_DEFAULTS, ROOT_ACCOUNT, ROOT_SCOPE, RUN_PROFILES, RUN_SETTLE_DECISION_TYPE, ReplayPlanHashMismatch, Replayer, ResolutionArbiter, ResolutionFold, RulvarError, RunBudget, SANDBOX_AGENT_OPT_KEYS, SPAWN_AGENT_SCHEMA, SandboxError, ScriptRejected, Semaphore, SettlementError, SpanRegistry, SupersededError, TOOL_NAME_PATTERN, TerminationAccount, WAIT_FOR_EVENTS_SCHEMA, WAIT_FOR_EVENTS_TOOL_NAME, WAKE_SUMMARY_RENDER_BUDGET_CHARS, accountSpendFromJournal, admissionReserveUsd, affordableOutputTokens, agentErrorFromWire, agentErrorToWire, agentResultWire, agentScope, applyClaimOps, applyStructuredOutputTier, approachSigCoarse, approachSigOf, archiveDeprecatedModelOps, assertFencedWrites, assertSafeRunId, atCompactionThreshold, attestToolset, auditRun, auditRuns, buildAbandonFold, buildAdapterRegistry, buildCostReport, buildDeriverRegistry, buildOrchestratorTools, buildTerminationInitValue, buildToolContext, canRideLoopTurn, canonicalIsolationTag, canonicalizeLadder, canonicalizeSchema, capIssues, capsHashOf, checkFloors, checkpointRefFor, childCoveragePrefix, citationTargetsValidator, citedValueValidator, claimExpired, claimExpiry, claimIssues, claimOpIssues, classifyAgentError, classifyAttemptOutcome, collectDeclaredLadders, compactMessages, compareRates, compilePermissionChain, compilePermissionPreset, compileSecretMasker, compileVerifiedLayer, constantTimeEqual, costReportFromJournal, countsAgainstLimit, createCanonicalIdMinter, createCtx, createEngine, createEnvelopeEncryption, createSandboxBridge, currentOnlyKeyRing, decodeCheckpoint, dedupeRepeatedClaims, defineWorkflow, deriveContentKey, deriverV1, deriverV2, digestOf, dispatchProjectionReserveUsd, dispositionHook, emptyDigestBlocks, emptyToolset, encodeCheckpoint, enforceToolsetAttestation, entryUsageSlices, escalateTool, evaluatePermission, evaluateReuse, evidenceGradeValidator, evidencePreservedValidator, executeWorkflow, executionFactsOf, exhaustionCodeOf, extractCandidate, failoverTriggerOf, fallbackTriggerOf, filterClaimsForRun, finalizeFires, findContradictions, finishContract, foldLedger, foldTermination, formatCharacterValidator, formatRePrompt, formatScopePath, hasFencedWrites, hasMetaLookup, hashRunArgs, hashRunOutput, hashWorkflowBody, hashWorkflowSource, headingStructureValidator, identityJcs, implementationAgentProfile, invoiceFromJournal, isEscalated, isSchemaPairSpec, isStandardSchemaSpec, isStrictCompatibleSchema, journalPricingSnapshot, kMaxOf, knowledgeHash, ladderLengthOf, ladderRungChoice, lastRunSettle, latestProgressReport, lexShellCommand, liftRetainedParts, lineageWeightOf, localKeyProvider, makeOrchestratorWorkflow, maskSecrets, maskSecretsDeep, maskSecretsJson, matchArgvPattern, matchShellCommand, mcp, memoryQuotaLimiter, mergeQuotaDenial, mergeUsageLimits, metaMatchesFilter, minMatchesValidator, modelEpochOf, modelKnowledgeCard, modelSpecIdentity, needsSeparateExtract, nextFailover, nodeLinkKey, normalizeApproachTag, normalizeEntry, normalizeFallbacks, orchestrate, orchestratorAdmissionEstCostUsd, pairDraftClaims, parallelScope, parseModelRef, parseScopePath, persistedTerminalEnvelope, phiInitialOf, pipelineScope, planNodeScope, preflightEstimate, priceComponentsOf, priceEntryBilling, priceEntryUsage, priceUsdOf, profileCard, profileRegistrySnapshotHash, progressReportTool, projectHistory, projectIdentity, projectToJsonSchema, proposalStatement, providerOf, quotaActualRequestsDelta, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, readRunMeta, readTerminationInit, reconcileRunMeta, reduceAuditTrail, reduceCriticalPath, reduceInvocationTable, registryKeyRing, remeasureQueue, replayDisposition, repositoryResearchToolset, requiredFieldsValidator, requiredSectionsValidator, researchAgentProfile, resolveModelInvocation, resolvePricing, resolveToolset, retryClassOf, retryDelayMs, reviewAgentProfile, roleConfiguredInRouting, roundOneDisposition, runAgent, runProfile, sanitizeTerminalText, sanitizeTokenCount, sanitizeUsage, sanitizeUsageDelta, scanJournalCompatibility, schemaHash, schemaHashOfSpec, sectionCitationsValidator, selectStructuredOutputTier, selfTestFinishValidation, shouldCompact, snapshotQuotaRules, snapshotUsage, spawnDepthOf, spliceSections, stripFencedBlocks, sumUsage, summarizeInstruction, summarizeOutput, terminalEnvelopeOf, terminationConfigDrift, tierWithinCaps, toApprovalDecision, toJournalValue, tool, toolContract, toolContractHash, toolsetHash, ttlState, usageViolations, validateDetachedResolution, validateEditorialCommit, validateEngineQuotaConfig, validateEntryShape, validateEscalationLimits, validateEscalationReport, validateQuotaRules, validateRetryPolicy, validateSchemaSpec, validateTerminationLimits, validateToolsetAttestation, validateUsageLimits, wordCountValidator, workflowScope, workflowSourceRef, wrapJournalStore, wrapTranscriptStore };
|
|
25149
|
+
export { AWAIT_SCHEMA, AdmissionController, AdmissionRejectedError, AgentCallError, BUDGET_ABORT_REASON, BudgetExhaustedError, CANCEL_AGENT_SCHEMA, CHECKPOINT_FORMAT_V1, CLAIM_STATEMENT_MAX_CHARS, CLAIM_TTL_DAYS, COMPACTION_SUMMARY_PREFIX, CURRENT_HASH_VERSION, ConfigError, DEFAULT_ANCHOR_PATTERN, DEFAULT_ARTIFACT_PATTERN, DEFAULT_CHILD_BUDGET_FRACTION, DEFAULT_CHILD_RESULT_PAGE_CHARS, DEFAULT_CITATION_PATTERN, DEFAULT_CITATION_SAMPLE, DEFAULT_CLAIM_JUDGE_MAX_TURNS, DEFAULT_COMPACTION_THRESHOLD, DEFAULT_ESCALATION_LIMITS, DEFAULT_EVIDENCE_CALLS_PER_ENTRY, DEFAULT_EVIDENCE_GRADE_PHRASES, DEFAULT_EVIDENCE_MIN_SHARE, DEFAULT_EVIDENCE_OVERHEAD_CALLS, DEFAULT_FINISH_MAX_REPAIRS, DEFAULT_FLAT_RESERVE_USD, DEFAULT_MAX_CHILDREN_PER_NODE, DEFAULT_MAX_CLAIM_PAIRS, DEFAULT_MAX_CONTRADICTIONS, DEFAULT_MAX_DEPTH, DEFAULT_MAX_EXCERPT_CHARS, DEFAULT_MAX_OSCILLATIONS_PER_KEY, DEFAULT_MAX_PAIR_EXCERPT_CHARS, DEFAULT_MAX_PINNED_WORKTREES, DEFAULT_MAX_POOL_PER_PAIR, DEFAULT_MAX_QUOTA_DENIALS, DEFAULT_MAX_REVISIONS_PER_RUN, DEFAULT_MAX_TOTAL_SPAWNS, DEFAULT_MAX_TURNS, DEFAULT_MODEL_RETRY_ATTEMPTS, DEFAULT_NO_PROGRESS_TURNS, DEFAULT_PER_RUN_CONCURRENCY, DEFAULT_RETRY_POLICY, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_SYNTHESIS_MAX_TURNS, DEFAULT_SYNTHESIS_NOTE_MAX_TURNS, DedupIndex, DeterminismError, EMIT_RESULT_TOOL, EMPTY_SCHEMA_HASH, EMPTY_TOOLSET_HASH, ESCALATE_TOOL_NAME, ESCALATION_REPORT_SCHEMA, ESCALATION_REQUEST_SCHEMA, EVENT_SEGMENT_STRIDE, EscalationDecisionAbortedError, EventBus, ExternalRegistry, FINALIZE_SYNTHESIS_INSTRUCTION, FINISH_SCHEMA, FINISH_SECTIONAL_SCHEMA, FINISH_TOOL_NAME, FailRunError, FileModelKnowledgeStore, FileTranscriptStore, GET_CHILD_RESULT_SCHEMA, GET_CHILD_RESULT_TOOL_NAME, GitWorktreeProvider, IMPLEMENTATION_PROFILE_LIMITS, INBOX_PROPOSAL_TTL_DAYS, IN_FLIGHT_EXPOSURE_REFUSAL_PREFIX, InMemoryStore, InMemoryTranscriptStore, InProcessRunner, InvalidResolutionError, JOURNAL_ENVELOPE_MARKER, JournalCompatibilityError, JournalMatcher, JournalMissError, JournalOrderViolation, JsonlFileStore, KB_ACTIVE_CLAIMS_CAP, KB_CARD_RENDER_BUDGET_CHARS, KeyedLimiter, KnowledgeCasError, LARGE_VALUE_WARN_BYTES, LEGACY_LTID_PREFIX, LEGACY_SIGNATURE_INPUTS, LINEAGE_SIG_VERSION, LeaseHeldError, LineageIndex, MASKED_SECRET, MAX_CHILD_RESULT_PAGE_CHARS, MAX_DEPTH_CEILING, MAX_RUN_ID_LENGTH, MAX_TIMER_DELAY_MS, ModelRetry, NoProgressDetector, NonSerializableValueError, ORCHESTRATE_WORKFLOW_NAME, OrchestratorCapConfigError, PARALLEL_AGENTS_SCHEMA, PROGRESS_REPORT_TOOL_NAME, ParallelSiteCounter, PlanInvariantError, QUOTA_WINDOW_MS, READ_CHILD_ARTIFACT_SCHEMA, READ_CHILD_ARTIFACT_TOOL_NAME, RESEARCH_PROFILE_LIMITS, REVIEW_PROFILE_LIMITS, ROLE_EFFORT_DEFAULTS, ROOT_ACCOUNT, ROOT_SCOPE, RUN_PROFILES, RUN_SETTLE_DECISION_TYPE, ReplayPlanHashMismatch, Replayer, ResolutionArbiter, ResolutionFold, RulvarError, RunBudget, SANDBOX_AGENT_OPT_KEYS, SPAWN_AGENT_SCHEMA, SandboxError, ScriptRejected, Semaphore, SettlementError, SpanRegistry, SupersededError, TOOL_NAME_PATTERN, TerminationAccount, WAIT_FOR_EVENTS_SCHEMA, WAIT_FOR_EVENTS_TOOL_NAME, WAKE_SUMMARY_RENDER_BUDGET_CHARS, accountSpendFromJournal, admissionReserveUsd, affordableOutputTokens, agentErrorFromWire, agentErrorToWire, agentResultWire, agentScope, applyClaimOps, applyStructuredOutputTier, approachSigCoarse, approachSigOf, archiveDeprecatedModelOps, assertFencedWrites, assertSafeRunId, atCompactionThreshold, attestToolset, auditRun, auditRuns, buildAbandonFold, buildAdapterRegistry, buildCostReport, buildDeriverRegistry, buildOrchestratorTools, buildTerminationInitValue, buildToolContext, canRideLoopTurn, canonicalIsolationTag, canonicalizeLadder, canonicalizeSchema, capIssues, capsHashOf, checkFloors, checkpointRefFor, childCoveragePrefix, citationTargetsValidator, citedValueValidator, claimExpired, claimExpiry, claimIssues, claimOpIssues, classifyAgentError, classifyAttemptOutcome, collectDeclaredLadders, compactMessages, compareRates, compilePermissionChain, compilePermissionPreset, compileSecretMasker, compileVerifiedLayer, constantTimeEqual, costReportFromJournal, countsAgainstLimit, createCanonicalIdMinter, createCtx, createEngine, createEnvelopeEncryption, createSandboxBridge, currentOnlyKeyRing, decodeCheckpoint, dedupeRepeatedClaims, defineWorkflow, deriveContentKey, deriverV1, deriverV2, digestOf, dispatchProjectionReserveUsd, dispositionHook, emptyDigestBlocks, emptyToolset, encodeCheckpoint, enforceToolsetAttestation, entryUsageSlices, escalateTool, evaluatePermission, evaluateReuse, evidenceGradeValidator, evidencePreservedValidator, executeWorkflow, executionFactsOf, exhaustionCodeOf, extractCandidate, failoverTriggerOf, fallbackTriggerOf, filterClaimsForRun, finalizeFires, findContradictions, finishContract, foldLedger, foldTermination, formatCharacterValidator, formatRePrompt, formatScopePath, hasFencedWrites, hasMetaLookup, hashRunArgs, hashRunOutput, hashWorkflowBody, hashWorkflowSource, headingStructureValidator, identityJcs, implementationAgentProfile, invoiceFromJournal, isEscalated, isSchemaPairSpec, isStandardSchemaSpec, isStrictCompatibleSchema, journalPricingSnapshot, kMaxOf, knowledgeHash, ladderLengthOf, ladderRungChoice, lastRunSettle, latestProgressReport, lexShellCommand, liftRetainedParts, lineageWeightOf, localKeyProvider, makeOrchestratorWorkflow, maskSecrets, maskSecretsDeep, maskSecretsJson, matchArgvPattern, matchShellCommand, mcp, memoryQuotaLimiter, mergeQuotaDenial, mergeUsageLimits, metaMatchesFilter, minMatchesValidator, modelEpochOf, modelKnowledgeCard, modelSpecIdentity, needsSeparateExtract, nextFailover, nodeLinkKey, normalizeApproachTag, normalizeEntry, normalizeFallbacks, orchestrate, orchestratorAdmissionEstCostUsd, pairDraftClaims, parallelScope, parseModelRef, parseScopePath, persistedTerminalEnvelope, phiInitialOf, pipelineScope, planNodeScope, preflightEstimate, priceComponentsOf, priceEntryBilling, priceEntryUsage, priceUsdOf, profileCard, profileRegistrySnapshotHash, progressReportTool, projectHistory, projectIdentity, projectToJsonSchema, proposalStatement, providerOf, quotaActualRequestsDelta, quotaActualTokens, quotaEstimateTokens, quotaRuleAdmission, quotaRuleKey, quotaRuleMatches, readRunMeta, readTerminationInit, reconcileRunMeta, reduceAuditTrail, reduceCriticalPath, reduceInvocationTable, registryKeyRing, remeasureQueue, replayDisposition, repositoryResearchToolset, requiredFieldsValidator, requiredSectionsValidator, researchAgentProfile, resolveModelInvocation, resolvePricing, resolveToolset, retryClassOf, retryDelayMs, reviewAgentProfile, roleConfiguredInRouting, roundOneDisposition, runAgent, runProfile, sanitizeTerminalText, sanitizeTokenCount, sanitizeUsage, sanitizeUsageDelta, scanJournalCompatibility, schemaHash, schemaHashOfSpec, sectionCitationsValidator, selectStructuredOutputTier, selfTestFinishValidation, shouldCompact, snapshotQuotaRules, snapshotUsage, spawnDepthOf, spliceSections, stripFencedBlocks, sumUsage, summarizeInstruction, summarizeOutput, terminalEnvelopeOf, terminationConfigDrift, tierWithinCaps, toApprovalDecision, toJournalValue, tool, toolContract, toolContractHash, toolsetHash, ttlState, usageViolations, validateDetachedResolution, validateEditorialCommit, validateEngineQuotaConfig, validateEntryShape, validateEscalationLimits, validateEscalationReport, validateQuotaRules, validateRetryPolicy, validateSchemaSpec, validateTerminationLimits, validateToolsetAttestation, validateUsageLimits, wordCountValidator, workflowScope, workflowSourceRef, wrapJournalStore, wrapTranscriptStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.171.0",
|
|
4
4
|
"description": "Rulvar core: L0 contracts, journal kernel, ctx primitives, agent runtime, model router, tool system, dynamic orchestrator, InMemory and JSONL stores, event stream.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|