@cloudwarriors-ai/rlm 0.1.5
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/README.md +208 -0
- package/dist/application/index.d.ts +4 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +4 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/query-handler.d.ts +49 -0
- package/dist/application/query-handler.d.ts.map +1 -0
- package/dist/application/query-handler.js +311 -0
- package/dist/application/query-handler.js.map +1 -0
- package/dist/application/rlm-service.d.ts +68 -0
- package/dist/application/rlm-service.d.ts.map +1 -0
- package/dist/application/rlm-service.js +132 -0
- package/dist/application/rlm-service.js.map +1 -0
- package/dist/application/session-manager.d.ts +70 -0
- package/dist/application/session-manager.d.ts.map +1 -0
- package/dist/application/session-manager.js +237 -0
- package/dist/application/session-manager.js.map +1 -0
- package/dist/cli/commands/config.d.ts +34 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +157 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/index.d.ts +4 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +4 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/query.d.ts +26 -0
- package/dist/cli/commands/query.d.ts.map +1 -0
- package/dist/cli/commands/query.js +90 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/session.d.ts +40 -0
- package/dist/cli/commands/session.d.ts.map +1 -0
- package/dist/cli/commands/session.js +55 -0
- package/dist/cli/commands/session.js.map +1 -0
- package/dist/cli/config-loader.d.ts +63 -0
- package/dist/cli/config-loader.d.ts.map +1 -0
- package/dist/cli/config-loader.js +94 -0
- package/dist/cli/config-loader.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +120 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/output/formatter.d.ts +24 -0
- package/dist/cli/output/formatter.d.ts.map +1 -0
- package/dist/cli/output/formatter.js +196 -0
- package/dist/cli/output/formatter.js.map +1 -0
- package/dist/cli/output/index.d.ts +3 -0
- package/dist/cli/output/index.d.ts.map +1 -0
- package/dist/cli/output/index.js +3 -0
- package/dist/cli/output/index.js.map +1 -0
- package/dist/cli/output/progress.d.ts +60 -0
- package/dist/cli/output/progress.d.ts.map +1 -0
- package/dist/cli/output/progress.js +142 -0
- package/dist/cli/output/progress.js.map +1 -0
- package/dist/domain/errors/base-error.d.ts +17 -0
- package/dist/domain/errors/base-error.d.ts.map +1 -0
- package/dist/domain/errors/base-error.js +29 -0
- package/dist/domain/errors/base-error.js.map +1 -0
- package/dist/domain/errors/execution-error.d.ts +61 -0
- package/dist/domain/errors/execution-error.d.ts.map +1 -0
- package/dist/domain/errors/execution-error.js +86 -0
- package/dist/domain/errors/execution-error.js.map +1 -0
- package/dist/domain/errors/index.d.ts +14 -0
- package/dist/domain/errors/index.d.ts.map +1 -0
- package/dist/domain/errors/index.js +26 -0
- package/dist/domain/errors/index.js.map +1 -0
- package/dist/domain/errors/limit-exceeded.d.ts +38 -0
- package/dist/domain/errors/limit-exceeded.d.ts.map +1 -0
- package/dist/domain/errors/limit-exceeded.js +71 -0
- package/dist/domain/errors/limit-exceeded.js.map +1 -0
- package/dist/domain/errors/llm-error.d.ts +60 -0
- package/dist/domain/errors/llm-error.d.ts.map +1 -0
- package/dist/domain/errors/llm-error.js +92 -0
- package/dist/domain/errors/llm-error.js.map +1 -0
- package/dist/domain/errors/validation-error.d.ts +58 -0
- package/dist/domain/errors/validation-error.d.ts.map +1 -0
- package/dist/domain/errors/validation-error.js +81 -0
- package/dist/domain/errors/validation-error.js.map +1 -0
- package/dist/domain/interfaces/code-executor.d.ts +98 -0
- package/dist/domain/interfaces/code-executor.d.ts.map +1 -0
- package/dist/domain/interfaces/code-executor.js +2 -0
- package/dist/domain/interfaces/code-executor.js.map +1 -0
- package/dist/domain/interfaces/event-emitter.d.ts +137 -0
- package/dist/domain/interfaces/event-emitter.d.ts.map +1 -0
- package/dist/domain/interfaces/event-emitter.js +2 -0
- package/dist/domain/interfaces/event-emitter.js.map +1 -0
- package/dist/domain/interfaces/index.d.ts +5 -0
- package/dist/domain/interfaces/index.d.ts.map +1 -0
- package/dist/domain/interfaces/index.js +2 -0
- package/dist/domain/interfaces/index.js.map +1 -0
- package/dist/domain/interfaces/llm-provider.d.ts +64 -0
- package/dist/domain/interfaces/llm-provider.d.ts.map +1 -0
- package/dist/domain/interfaces/llm-provider.js +2 -0
- package/dist/domain/interfaces/llm-provider.js.map +1 -0
- package/dist/domain/interfaces/session-store.d.ts +65 -0
- package/dist/domain/interfaces/session-store.d.ts.map +1 -0
- package/dist/domain/interfaces/session-store.js +2 -0
- package/dist/domain/interfaces/session-store.js.map +1 -0
- package/dist/domain/services/context-chunker.d.ts +43 -0
- package/dist/domain/services/context-chunker.d.ts.map +1 -0
- package/dist/domain/services/context-chunker.js +152 -0
- package/dist/domain/services/context-chunker.js.map +1 -0
- package/dist/domain/services/cost-calculator.d.ts +63 -0
- package/dist/domain/services/cost-calculator.d.ts.map +1 -0
- package/dist/domain/services/cost-calculator.js +121 -0
- package/dist/domain/services/cost-calculator.js.map +1 -0
- package/dist/domain/services/index.d.ts +5 -0
- package/dist/domain/services/index.d.ts.map +1 -0
- package/dist/domain/services/index.js +9 -0
- package/dist/domain/services/index.js.map +1 -0
- package/dist/domain/services/limit-checker.d.ts +54 -0
- package/dist/domain/services/limit-checker.d.ts.map +1 -0
- package/dist/domain/services/limit-checker.js +146 -0
- package/dist/domain/services/limit-checker.js.map +1 -0
- package/dist/domain/services/result-aggregator.d.ts +49 -0
- package/dist/domain/services/result-aggregator.d.ts.map +1 -0
- package/dist/domain/services/result-aggregator.js +131 -0
- package/dist/domain/services/result-aggregator.js.map +1 -0
- package/dist/domain/types/config.d.ts +41 -0
- package/dist/domain/types/config.d.ts.map +1 -0
- package/dist/domain/types/config.js +22 -0
- package/dist/domain/types/config.js.map +1 -0
- package/dist/domain/types/context.d.ts +64 -0
- package/dist/domain/types/context.d.ts.map +1 -0
- package/dist/domain/types/context.js +20 -0
- package/dist/domain/types/context.js.map +1 -0
- package/dist/domain/types/index.d.ts +5 -0
- package/dist/domain/types/index.d.ts.map +1 -0
- package/dist/domain/types/index.js +9 -0
- package/dist/domain/types/index.js.map +1 -0
- package/dist/domain/types/result.d.ts +137 -0
- package/dist/domain/types/result.d.ts.map +1 -0
- package/dist/domain/types/result.js +27 -0
- package/dist/domain/types/result.js.map +1 -0
- package/dist/domain/types/session.d.ts +74 -0
- package/dist/domain/types/session.d.ts.map +1 -0
- package/dist/domain/types/session.js +31 -0
- package/dist/domain/types/session.js.map +1 -0
- package/dist/factory/create-rlm.d.ts +77 -0
- package/dist/factory/create-rlm.d.ts.map +1 -0
- package/dist/factory/create-rlm.js +82 -0
- package/dist/factory/create-rlm.js.map +1 -0
- package/dist/factory/default-config.d.ts +27 -0
- package/dist/factory/default-config.d.ts.map +1 -0
- package/dist/factory/default-config.js +98 -0
- package/dist/factory/default-config.js.map +1 -0
- package/dist/factory/index.d.ts +3 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +3 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/events/event-types.d.ts +35 -0
- package/dist/infrastructure/events/event-types.d.ts.map +1 -0
- package/dist/infrastructure/events/event-types.js +44 -0
- package/dist/infrastructure/events/event-types.js.map +1 -0
- package/dist/infrastructure/events/index.d.ts +3 -0
- package/dist/infrastructure/events/index.d.ts.map +1 -0
- package/dist/infrastructure/events/index.js +3 -0
- package/dist/infrastructure/events/index.js.map +1 -0
- package/dist/infrastructure/events/node-emitter.d.ts +72 -0
- package/dist/infrastructure/events/node-emitter.d.ts.map +1 -0
- package/dist/infrastructure/events/node-emitter.js +125 -0
- package/dist/infrastructure/events/node-emitter.js.map +1 -0
- package/dist/infrastructure/llm/index.d.ts +3 -0
- package/dist/infrastructure/llm/index.d.ts.map +1 -0
- package/dist/infrastructure/llm/index.js +3 -0
- package/dist/infrastructure/llm/index.js.map +1 -0
- package/dist/infrastructure/llm/openrouter-provider.d.ts +35 -0
- package/dist/infrastructure/llm/openrouter-provider.d.ts.map +1 -0
- package/dist/infrastructure/llm/openrouter-provider.js +158 -0
- package/dist/infrastructure/llm/openrouter-provider.js.map +1 -0
- package/dist/infrastructure/llm/prompts/code-gen-prompt.d.ts +21 -0
- package/dist/infrastructure/llm/prompts/code-gen-prompt.d.ts.map +1 -0
- package/dist/infrastructure/llm/prompts/code-gen-prompt.js +78 -0
- package/dist/infrastructure/llm/prompts/code-gen-prompt.js.map +1 -0
- package/dist/infrastructure/llm/prompts/error-recovery-prompt.d.ts +24 -0
- package/dist/infrastructure/llm/prompts/error-recovery-prompt.d.ts.map +1 -0
- package/dist/infrastructure/llm/prompts/error-recovery-prompt.js +70 -0
- package/dist/infrastructure/llm/prompts/error-recovery-prompt.js.map +1 -0
- package/dist/infrastructure/llm/prompts/index.d.ts +4 -0
- package/dist/infrastructure/llm/prompts/index.d.ts.map +1 -0
- package/dist/infrastructure/llm/prompts/index.js +4 -0
- package/dist/infrastructure/llm/prompts/index.js.map +1 -0
- package/dist/infrastructure/llm/prompts/system-prompt.d.ts +12 -0
- package/dist/infrastructure/llm/prompts/system-prompt.d.ts.map +1 -0
- package/dist/infrastructure/llm/prompts/system-prompt.js +96 -0
- package/dist/infrastructure/llm/prompts/system-prompt.js.map +1 -0
- package/dist/infrastructure/persistence/index.d.ts +3 -0
- package/dist/infrastructure/persistence/index.d.ts.map +1 -0
- package/dist/infrastructure/persistence/index.js +3 -0
- package/dist/infrastructure/persistence/index.js.map +1 -0
- package/dist/infrastructure/persistence/memory-store.d.ts +24 -0
- package/dist/infrastructure/persistence/memory-store.d.ts.map +1 -0
- package/dist/infrastructure/persistence/memory-store.js +71 -0
- package/dist/infrastructure/persistence/memory-store.js.map +1 -0
- package/dist/infrastructure/persistence/schema.d.ts +120 -0
- package/dist/infrastructure/persistence/schema.d.ts.map +1 -0
- package/dist/infrastructure/persistence/schema.js +130 -0
- package/dist/infrastructure/persistence/schema.js.map +1 -0
- package/dist/infrastructure/sandbox/ast-validator.d.ts +23 -0
- package/dist/infrastructure/sandbox/ast-validator.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/ast-validator.js +249 -0
- package/dist/infrastructure/sandbox/ast-validator.js.map +1 -0
- package/dist/infrastructure/sandbox/index.d.ts +4 -0
- package/dist/infrastructure/sandbox/index.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/index.js +4 -0
- package/dist/infrastructure/sandbox/index.js.map +1 -0
- package/dist/infrastructure/sandbox/prelude/rlm_prelude.py +376 -0
- package/dist/infrastructure/sandbox/process-manager.d.ts +98 -0
- package/dist/infrastructure/sandbox/process-manager.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/process-manager.js +186 -0
- package/dist/infrastructure/sandbox/process-manager.js.map +1 -0
- package/dist/infrastructure/sandbox/python-executor.d.ts +29 -0
- package/dist/infrastructure/sandbox/python-executor.d.ts.map +1 -0
- package/dist/infrastructure/sandbox/python-executor.js +182 -0
- package/dist/infrastructure/sandbox/python-executor.js.map +1 -0
- package/package.json +65 -0
- package/src/infrastructure/sandbox/prelude/rlm_prelude.py +376 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Known model pricing (as of early 2025)
|
|
3
|
+
* These should be updated periodically
|
|
4
|
+
*/
|
|
5
|
+
export const MODEL_PRICING = {
|
|
6
|
+
'anthropic/claude-sonnet-4': {
|
|
7
|
+
inputCostPer1M: 3.0,
|
|
8
|
+
outputCostPer1M: 15.0,
|
|
9
|
+
},
|
|
10
|
+
'anthropic/claude-3.5-sonnet': {
|
|
11
|
+
inputCostPer1M: 3.0,
|
|
12
|
+
outputCostPer1M: 15.0,
|
|
13
|
+
},
|
|
14
|
+
'anthropic/claude-3-haiku': {
|
|
15
|
+
inputCostPer1M: 0.25,
|
|
16
|
+
outputCostPer1M: 1.25,
|
|
17
|
+
},
|
|
18
|
+
'anthropic/claude-3-opus': {
|
|
19
|
+
inputCostPer1M: 15.0,
|
|
20
|
+
outputCostPer1M: 75.0,
|
|
21
|
+
},
|
|
22
|
+
'openai/gpt-4-turbo': {
|
|
23
|
+
inputCostPer1M: 10.0,
|
|
24
|
+
outputCostPer1M: 30.0,
|
|
25
|
+
},
|
|
26
|
+
'openai/gpt-4o': {
|
|
27
|
+
inputCostPer1M: 5.0,
|
|
28
|
+
outputCostPer1M: 15.0,
|
|
29
|
+
},
|
|
30
|
+
'openai/gpt-4o-mini': {
|
|
31
|
+
inputCostPer1M: 0.15,
|
|
32
|
+
outputCostPer1M: 0.6,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Default pricing for unknown models
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_PRICING = {
|
|
39
|
+
inputCostPer1M: 5.0,
|
|
40
|
+
outputCostPer1M: 15.0,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Get pricing for a model
|
|
44
|
+
*/
|
|
45
|
+
export function getModelPricing(model) {
|
|
46
|
+
// Try exact match first
|
|
47
|
+
const exactMatch = MODEL_PRICING[model];
|
|
48
|
+
if (exactMatch) {
|
|
49
|
+
return exactMatch;
|
|
50
|
+
}
|
|
51
|
+
// Try partial match (e.g., "anthropic/claude-3.5-sonnet:latest")
|
|
52
|
+
for (const [key, pricing] of Object.entries(MODEL_PRICING)) {
|
|
53
|
+
if (model.startsWith(key)) {
|
|
54
|
+
return pricing;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return DEFAULT_PRICING;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Calculate cost for token usage
|
|
61
|
+
*/
|
|
62
|
+
export function calculateCost(usage, model) {
|
|
63
|
+
const pricing = getModelPricing(model);
|
|
64
|
+
const inputCost = (usage.promptTokens / 1_000_000) * pricing.inputCostPer1M;
|
|
65
|
+
const outputCost = (usage.completionTokens / 1_000_000) * pricing.outputCostPer1M;
|
|
66
|
+
return inputCost + outputCost;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Estimate session cost based on context size
|
|
70
|
+
* This is a rough heuristic based on typical usage patterns
|
|
71
|
+
*/
|
|
72
|
+
export function estimateSessionCost(config, contextTokens) {
|
|
73
|
+
const pricing = getModelPricing(config.model);
|
|
74
|
+
// Estimate number of calls based on context size and depth
|
|
75
|
+
// Assume each level processes ~10% of context
|
|
76
|
+
const callsPerLevel = Math.ceil(contextTokens / 100_000); // Roughly 100k tokens per call
|
|
77
|
+
const estimatedCalls = Math.min(callsPerLevel * config.maxRecursionDepth, config.maxRecursionDepth * 10 // Cap at reasonable number
|
|
78
|
+
);
|
|
79
|
+
// Average tokens per call (input + output)
|
|
80
|
+
const avgInputTokens = contextTokens / estimatedCalls;
|
|
81
|
+
const avgOutputTokens = 2000; // Typical code + explanation
|
|
82
|
+
const costPerCall = (avgInputTokens / 1_000_000) * pricing.inputCostPer1M +
|
|
83
|
+
(avgOutputTokens / 1_000_000) * pricing.outputCostPer1M;
|
|
84
|
+
const expectedCost = costPerCall * estimatedCalls;
|
|
85
|
+
return {
|
|
86
|
+
minCostUsd: expectedCost * 0.5,
|
|
87
|
+
maxCostUsd: Math.min(expectedCost * 2, config.maxCostUsd),
|
|
88
|
+
expectedCostUsd: expectedCost,
|
|
89
|
+
estimatedCalls,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Format cost for display
|
|
94
|
+
*/
|
|
95
|
+
export function formatCost(costUsd) {
|
|
96
|
+
if (costUsd < 0.01) {
|
|
97
|
+
return `$${(costUsd * 100).toFixed(2)}¢`;
|
|
98
|
+
}
|
|
99
|
+
return `$${costUsd.toFixed(4)}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if cost is within budget
|
|
103
|
+
*/
|
|
104
|
+
export function isWithinBudget(currentCost, maxCost) {
|
|
105
|
+
return currentCost < maxCost;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Calculate remaining budget
|
|
109
|
+
*/
|
|
110
|
+
export function remainingBudget(currentCost, maxCost) {
|
|
111
|
+
return Math.max(0, maxCost - currentCost);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Calculate percentage of budget used
|
|
115
|
+
*/
|
|
116
|
+
export function budgetUsedPercent(currentCost, maxCost) {
|
|
117
|
+
if (maxCost === 0)
|
|
118
|
+
return 100;
|
|
119
|
+
return Math.min(100, (currentCost / maxCost) * 100);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=cost-calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-calculator.js","sourceRoot":"","sources":["../../../src/domain/services/cost-calculator.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAiC;IACzD,2BAA2B,EAAE;QAC3B,cAAc,EAAE,GAAG;QACnB,eAAe,EAAE,IAAI;KACtB;IACD,6BAA6B,EAAE;QAC7B,cAAc,EAAE,GAAG;QACnB,eAAe,EAAE,IAAI;KACtB;IACD,0BAA0B,EAAE;QAC1B,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE,IAAI;KACtB;IACD,yBAAyB,EAAE;QACzB,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE,IAAI;KACtB;IACD,oBAAoB,EAAE;QACpB,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE,IAAI;KACtB;IACD,eAAe,EAAE;QACf,cAAc,EAAE,GAAG;QACnB,eAAe,EAAE,IAAI;KACtB;IACD,oBAAoB,EAAE;QACpB,cAAc,EAAE,IAAI;QACpB,eAAe,EAAE,GAAG;KACrB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,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GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type ChunkStrategy, type ChunkOptions, type TokenEstimator, chunkByTokens, chunkByLines, chunkByDelimiter, chunkByParagraphs, chunkSmart, } from './context-chunker.js';
|
|
2
|
+
export { type ModelPricing, type CostEstimate, MODEL_PRICING, DEFAULT_PRICING, getModelPricing, calculateCost, estimateSessionCost, formatCost, isWithinBudget, remainingBudget, budgetUsedPercent, } from './cost-calculator.js';
|
|
3
|
+
export { type AggregationStrategy, type AggregationOptions, concatenateResults, mergeJsonResults, aggregateResults, aggregateTokenUsage, aggregateResourceUsage, flattenRecursiveResults, totalUsageFromTree, maxDepthInTree, } from './result-aggregator.js';
|
|
4
|
+
export { type LimitType, type LimitCheckResult, type ExceededLimit, type LimitWarning, checkLimits, shouldTerminate, canRecurse, getRemainingCapacity, getUsagePercentage, formatLimitStatus, } from './limit-checker.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/services/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,WAAW,EACX,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Context chunking
|
|
2
|
+
export { chunkByTokens, chunkByLines, chunkByDelimiter, chunkByParagraphs, chunkSmart, } from './context-chunker.js';
|
|
3
|
+
// Cost calculation
|
|
4
|
+
export { MODEL_PRICING, DEFAULT_PRICING, getModelPricing, calculateCost, estimateSessionCost, formatCost, isWithinBudget, remainingBudget, budgetUsedPercent, } from './cost-calculator.js';
|
|
5
|
+
// Result aggregation
|
|
6
|
+
export { concatenateResults, mergeJsonResults, aggregateResults, aggregateTokenUsage, aggregateResourceUsage, flattenRecursiveResults, totalUsageFromTree, maxDepthInTree, } from './result-aggregator.js';
|
|
7
|
+
// Limit checking
|
|
8
|
+
export { checkLimits, shouldTerminate, canRecurse, getRemainingCapacity, getUsagePercentage, formatLimitStatus, } from './limit-checker.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/domain/services/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAIL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAE9B,mBAAmB;AACnB,OAAO,EAGL,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAE9B,qBAAqB;AACrB,OAAO,EAGL,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC,iBAAiB;AACjB,OAAO,EAKL,WAAW,EACX,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RLMConfig } from '../types/config.js';
|
|
2
|
+
import type { SessionState } from '../types/session.js';
|
|
3
|
+
/**
|
|
4
|
+
* Type of limit
|
|
5
|
+
*/
|
|
6
|
+
export type LimitType = 'depth' | 'tokens' | 'cost' | 'time';
|
|
7
|
+
/**
|
|
8
|
+
* Result of a limit check
|
|
9
|
+
*/
|
|
10
|
+
export interface LimitCheckResult {
|
|
11
|
+
/** Whether all limits are within bounds */
|
|
12
|
+
readonly withinLimits: boolean;
|
|
13
|
+
/** Limits that are exceeded */
|
|
14
|
+
readonly exceededLimits: readonly ExceededLimit[];
|
|
15
|
+
/** Limits that are approaching threshold (>80%) */
|
|
16
|
+
readonly warningLimits: readonly LimitWarning[];
|
|
17
|
+
}
|
|
18
|
+
export interface ExceededLimit {
|
|
19
|
+
readonly type: LimitType;
|
|
20
|
+
readonly current: number;
|
|
21
|
+
readonly max: number;
|
|
22
|
+
readonly message: string;
|
|
23
|
+
}
|
|
24
|
+
export interface LimitWarning {
|
|
25
|
+
readonly type: LimitType;
|
|
26
|
+
readonly current: number;
|
|
27
|
+
readonly max: number;
|
|
28
|
+
readonly percentage: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Check all limits against current state
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkLimits(state: SessionState, config: RLMConfig): LimitCheckResult;
|
|
34
|
+
/**
|
|
35
|
+
* Check if session should terminate
|
|
36
|
+
*/
|
|
37
|
+
export declare function shouldTerminate(state: SessionState, config: RLMConfig): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if we can make another recursive call
|
|
40
|
+
*/
|
|
41
|
+
export declare function canRecurse(state: SessionState, config: RLMConfig): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get remaining capacity for a limit type
|
|
44
|
+
*/
|
|
45
|
+
export declare function getRemainingCapacity(state: SessionState, config: RLMConfig, limitType: LimitType): number;
|
|
46
|
+
/**
|
|
47
|
+
* Get usage percentage for a limit type
|
|
48
|
+
*/
|
|
49
|
+
export declare function getUsagePercentage(state: SessionState, config: RLMConfig, limitType: LimitType): number;
|
|
50
|
+
/**
|
|
51
|
+
* Format limit status for display
|
|
52
|
+
*/
|
|
53
|
+
export declare function formatLimitStatus(state: SessionState, config: RLMConfig): string;
|
|
54
|
+
//# sourceMappingURL=limit-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit-checker.d.ts","sourceRoot":"","sources":["../../../src/domain/services/limit-checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B,+BAA+B;IAC/B,QAAQ,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;IAElD,mDAAmD;IACnD,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;CACjD;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAOD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,gBAAgB,CA8EpF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAO/E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAE1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,SAAS,GACnB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,SAAS,GACnB,MAAM,CAWR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAahF"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warning threshold percentage
|
|
3
|
+
*/
|
|
4
|
+
const WARNING_THRESHOLD = 0.8;
|
|
5
|
+
/**
|
|
6
|
+
* Check all limits against current state
|
|
7
|
+
*/
|
|
8
|
+
export function checkLimits(state, config) {
|
|
9
|
+
const exceededLimits = [];
|
|
10
|
+
const warningLimits = [];
|
|
11
|
+
// Check recursion depth
|
|
12
|
+
if (state.currentDepth >= config.maxRecursionDepth) {
|
|
13
|
+
exceededLimits.push({
|
|
14
|
+
type: 'depth',
|
|
15
|
+
current: state.currentDepth,
|
|
16
|
+
max: config.maxRecursionDepth,
|
|
17
|
+
message: `Maximum recursion depth (${config.maxRecursionDepth}) reached`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (state.currentDepth >= config.maxRecursionDepth * WARNING_THRESHOLD) {
|
|
21
|
+
warningLimits.push({
|
|
22
|
+
type: 'depth',
|
|
23
|
+
current: state.currentDepth,
|
|
24
|
+
max: config.maxRecursionDepth,
|
|
25
|
+
percentage: (state.currentDepth / config.maxRecursionDepth) * 100,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Check token usage
|
|
29
|
+
if (state.totalTokens >= config.maxTokens) {
|
|
30
|
+
exceededLimits.push({
|
|
31
|
+
type: 'tokens',
|
|
32
|
+
current: state.totalTokens,
|
|
33
|
+
max: config.maxTokens,
|
|
34
|
+
message: `Maximum tokens (${config.maxTokens.toLocaleString()}) exceeded`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else if (state.totalTokens >= config.maxTokens * WARNING_THRESHOLD) {
|
|
38
|
+
warningLimits.push({
|
|
39
|
+
type: 'tokens',
|
|
40
|
+
current: state.totalTokens,
|
|
41
|
+
max: config.maxTokens,
|
|
42
|
+
percentage: (state.totalTokens / config.maxTokens) * 100,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Check cost
|
|
46
|
+
if (state.totalCostUsd >= config.maxCostUsd) {
|
|
47
|
+
exceededLimits.push({
|
|
48
|
+
type: 'cost',
|
|
49
|
+
current: state.totalCostUsd,
|
|
50
|
+
max: config.maxCostUsd,
|
|
51
|
+
message: `Maximum cost ($${config.maxCostUsd.toFixed(2)}) exceeded`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (state.totalCostUsd >= config.maxCostUsd * WARNING_THRESHOLD) {
|
|
55
|
+
warningLimits.push({
|
|
56
|
+
type: 'cost',
|
|
57
|
+
current: state.totalCostUsd,
|
|
58
|
+
max: config.maxCostUsd,
|
|
59
|
+
percentage: (state.totalCostUsd / config.maxCostUsd) * 100,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// Check time
|
|
63
|
+
const elapsedMs = Date.now() - state.startTime;
|
|
64
|
+
if (elapsedMs >= config.timeoutMs) {
|
|
65
|
+
exceededLimits.push({
|
|
66
|
+
type: 'time',
|
|
67
|
+
current: elapsedMs,
|
|
68
|
+
max: config.timeoutMs,
|
|
69
|
+
message: `Timeout (${config.timeoutMs / 1000}s) exceeded`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (elapsedMs >= config.timeoutMs * WARNING_THRESHOLD) {
|
|
73
|
+
warningLimits.push({
|
|
74
|
+
type: 'time',
|
|
75
|
+
current: elapsedMs,
|
|
76
|
+
max: config.timeoutMs,
|
|
77
|
+
percentage: (elapsedMs / config.timeoutMs) * 100,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
withinLimits: exceededLimits.length === 0,
|
|
82
|
+
exceededLimits,
|
|
83
|
+
warningLimits,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if session should terminate
|
|
88
|
+
*/
|
|
89
|
+
export function shouldTerminate(state, config) {
|
|
90
|
+
if (state.cancellationRequested) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
const result = checkLimits(state, config);
|
|
94
|
+
return !result.withinLimits;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if we can make another recursive call
|
|
98
|
+
*/
|
|
99
|
+
export function canRecurse(state, config) {
|
|
100
|
+
return state.currentDepth < config.maxRecursionDepth && !shouldTerminate(state, config);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get remaining capacity for a limit type
|
|
104
|
+
*/
|
|
105
|
+
export function getRemainingCapacity(state, config, limitType) {
|
|
106
|
+
switch (limitType) {
|
|
107
|
+
case 'depth':
|
|
108
|
+
return Math.max(0, config.maxRecursionDepth - state.currentDepth);
|
|
109
|
+
case 'tokens':
|
|
110
|
+
return Math.max(0, config.maxTokens - state.totalTokens);
|
|
111
|
+
case 'cost':
|
|
112
|
+
return Math.max(0, config.maxCostUsd - state.totalCostUsd);
|
|
113
|
+
case 'time':
|
|
114
|
+
return Math.max(0, config.timeoutMs - (Date.now() - state.startTime));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get usage percentage for a limit type
|
|
119
|
+
*/
|
|
120
|
+
export function getUsagePercentage(state, config, limitType) {
|
|
121
|
+
switch (limitType) {
|
|
122
|
+
case 'depth':
|
|
123
|
+
return (state.currentDepth / config.maxRecursionDepth) * 100;
|
|
124
|
+
case 'tokens':
|
|
125
|
+
return (state.totalTokens / config.maxTokens) * 100;
|
|
126
|
+
case 'cost':
|
|
127
|
+
return (state.totalCostUsd / config.maxCostUsd) * 100;
|
|
128
|
+
case 'time':
|
|
129
|
+
return ((Date.now() - state.startTime) / config.timeoutMs) * 100;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Format limit status for display
|
|
134
|
+
*/
|
|
135
|
+
export function formatLimitStatus(state, config) {
|
|
136
|
+
const lines = [];
|
|
137
|
+
lines.push(`Depth: ${state.currentDepth}/${config.maxRecursionDepth}`);
|
|
138
|
+
lines.push(`Tokens: ${state.totalTokens.toLocaleString()}/${config.maxTokens.toLocaleString()}`);
|
|
139
|
+
lines.push(`Cost: $${state.totalCostUsd.toFixed(4)}/$${config.maxCostUsd.toFixed(2)}`);
|
|
140
|
+
const elapsedMs = Date.now() - state.startTime;
|
|
141
|
+
const elapsedSec = (elapsedMs / 1000).toFixed(1);
|
|
142
|
+
const maxSec = (config.timeoutMs / 1000).toFixed(0);
|
|
143
|
+
lines.push(`Time: ${elapsedSec}s/${maxSec}s`);
|
|
144
|
+
return lines.join('\n');
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=limit-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limit-checker.js","sourceRoot":"","sources":["../../../src/domain/services/limit-checker.ts"],"names":[],"mappings":"AAoCA;;GAEG;AACH,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAmB,EAAE,MAAiB;IAChE,MAAM,cAAc,GAAoB,EAAE,CAAC;IAC3C,MAAM,aAAa,GAAmB,EAAE,CAAC;IAEzC,wBAAwB;IACxB,IAAI,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QACnD,cAAc,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,KAAK,CAAC,YAAY;YAC3B,GAAG,EAAE,MAAM,CAAC,iBAAiB;YAC7B,OAAO,EAAE,4BAA4B,MAAM,CAAC,iBAAiB,WAAW;SACzE,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;QAC9E,aAAa,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,KAAK,CAAC,YAAY;YAC3B,GAAG,EAAE,MAAM,CAAC,iBAAiB;YAC7B,UAAU,EAAE,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,iBAAiB,CAAC,GAAG,GAAG;SAClE,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;IACpB,IAAI,KAAK,CAAC,WAAW,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QAC1C,cAAc,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,KAAK,CAAC,WAAW;YAC1B,GAAG,EAAE,MAAM,CAAC,SAAS;YACrB,OAAO,EAAE,mBAAmB,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY;SAC1E,CAAC,C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CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IACjG,KAAK,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAEvF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC;IAC/C,MAAM,UAAU,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACpD,KAAK,CAAC,IAAI,CAAC,SAAS,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC;IAE9C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RecursiveCallResult, ResourceUsage, TokenUsage } from '../types/result.js';
|
|
2
|
+
/**
|
|
3
|
+
* Strategy for aggregating results
|
|
4
|
+
*/
|
|
5
|
+
export type AggregationStrategy = 'concatenate' | 'summarize' | 'merge_json' | 'first' | 'last';
|
|
6
|
+
/**
|
|
7
|
+
* Options for result aggregation
|
|
8
|
+
*/
|
|
9
|
+
export interface AggregationOptions {
|
|
10
|
+
/** Strategy to use */
|
|
11
|
+
readonly strategy: AggregationStrategy;
|
|
12
|
+
/** Separator for concatenation */
|
|
13
|
+
readonly separator?: string;
|
|
14
|
+
/** Maximum length for combined result */
|
|
15
|
+
readonly maxLength?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Concatenate multiple results with separator
|
|
19
|
+
*/
|
|
20
|
+
export declare function concatenateResults(results: readonly string[], separator?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Merge JSON results (arrays or objects)
|
|
23
|
+
*/
|
|
24
|
+
export declare function mergeJsonResults(results: readonly string[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* Aggregate results using specified strategy
|
|
27
|
+
*/
|
|
28
|
+
export declare function aggregateResults(results: readonly string[], options?: AggregationOptions): string;
|
|
29
|
+
/**
|
|
30
|
+
* Aggregate token usage from multiple calls
|
|
31
|
+
*/
|
|
32
|
+
export declare function aggregateTokenUsage(usages: readonly TokenUsage[]): TokenUsage;
|
|
33
|
+
/**
|
|
34
|
+
* Aggregate resource usage from multiple calls
|
|
35
|
+
*/
|
|
36
|
+
export declare function aggregateResourceUsage(usages: readonly ResourceUsage[]): ResourceUsage;
|
|
37
|
+
/**
|
|
38
|
+
* Flatten recursive call tree to list of answers
|
|
39
|
+
*/
|
|
40
|
+
export declare function flattenRecursiveResults(result: RecursiveCallResult): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Calculate total usage from recursive call tree
|
|
43
|
+
*/
|
|
44
|
+
export declare function totalUsageFromTree(result: RecursiveCallResult): TokenUsage;
|
|
45
|
+
/**
|
|
46
|
+
* Find maximum depth in recursive call tree
|
|
47
|
+
*/
|
|
48
|
+
export declare function maxDepthInTree(result: RecursiveCallResult): number;
|
|
49
|
+
//# sourceMappingURL=result-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-aggregator.d.ts","sourceRoot":"","sources":["../../../src/domain/services/result-aggregator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,WAAW,GACX,YAAY,GACZ,OAAO,GACP,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sBAAsB;IACtB,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IAEvC,kCAAkC;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,SAAS,SAAgB,GACxB,MAAM,CAER;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CA6BnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,GAAE,kBAAgD,GACxD,MAAM,CA4CR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAS7E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,CAmBtF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAQ7E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAG1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAOlE"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concatenate multiple results with separator
|
|
3
|
+
*/
|
|
4
|
+
export function concatenateResults(results, separator = '\n\n---\n\n') {
|
|
5
|
+
return results.filter((r) => r.trim().length > 0).join(separator);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Merge JSON results (arrays or objects)
|
|
9
|
+
*/
|
|
10
|
+
export function mergeJsonResults(results) {
|
|
11
|
+
const parsed = [];
|
|
12
|
+
for (const result of results) {
|
|
13
|
+
try {
|
|
14
|
+
const obj = JSON.parse(result);
|
|
15
|
+
parsed.push(obj);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// If not valid JSON, skip
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (parsed.length === 0) {
|
|
22
|
+
return '[]';
|
|
23
|
+
}
|
|
24
|
+
// If all results are arrays, flatten
|
|
25
|
+
if (parsed.every(Array.isArray)) {
|
|
26
|
+
return JSON.stringify(parsed.flat(), null, 2);
|
|
27
|
+
}
|
|
28
|
+
// If all results are objects, merge keys
|
|
29
|
+
if (parsed.every((p) => typeof p === 'object' && p !== null && !Array.isArray(p))) {
|
|
30
|
+
const merged = Object.assign({}, ...parsed);
|
|
31
|
+
return JSON.stringify(merged, null, 2);
|
|
32
|
+
}
|
|
33
|
+
// Otherwise, return as array
|
|
34
|
+
return JSON.stringify(parsed, null, 2);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Aggregate results using specified strategy
|
|
38
|
+
*/
|
|
39
|
+
export function aggregateResults(results, options = { strategy: 'concatenate' }) {
|
|
40
|
+
if (results.length === 0) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
if (results.length === 1) {
|
|
44
|
+
return results[0] ?? '';
|
|
45
|
+
}
|
|
46
|
+
let aggregated;
|
|
47
|
+
switch (options.strategy) {
|
|
48
|
+
case 'concatenate':
|
|
49
|
+
aggregated = concatenateResults(results, options.separator);
|
|
50
|
+
break;
|
|
51
|
+
case 'merge_json':
|
|
52
|
+
aggregated = mergeJsonResults(results);
|
|
53
|
+
break;
|
|
54
|
+
case 'first':
|
|
55
|
+
aggregated = results[0] ?? '';
|
|
56
|
+
break;
|
|
57
|
+
case 'last':
|
|
58
|
+
aggregated = results[results.length - 1] ?? '';
|
|
59
|
+
break;
|
|
60
|
+
case 'summarize':
|
|
61
|
+
// Summarize is a special case - just concatenate for now
|
|
62
|
+
// The actual summarization should be done by the LLM
|
|
63
|
+
aggregated = concatenateResults(results, options.separator);
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
aggregated = concatenateResults(results, options.separator);
|
|
67
|
+
}
|
|
68
|
+
// Apply max length if specified
|
|
69
|
+
if (options.maxLength && aggregated.length > options.maxLength) {
|
|
70
|
+
aggregated = aggregated.slice(0, options.maxLength) + '\n\n[Truncated...]';
|
|
71
|
+
}
|
|
72
|
+
return aggregated;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Aggregate token usage from multiple calls
|
|
76
|
+
*/
|
|
77
|
+
export function aggregateTokenUsage(usages) {
|
|
78
|
+
return usages.reduce((acc, usage) => ({
|
|
79
|
+
promptTokens: acc.promptTokens + usage.promptTokens,
|
|
80
|
+
completionTokens: acc.completionTokens + usage.completionTokens,
|
|
81
|
+
totalTokens: acc.totalTokens + usage.totalTokens,
|
|
82
|
+
}), { promptTokens: 0, completionTokens: 0, totalTokens: 0 });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Aggregate resource usage from multiple calls
|
|
86
|
+
*/
|
|
87
|
+
export function aggregateResourceUsage(usages) {
|
|
88
|
+
return usages.reduce((acc, usage) => ({
|
|
89
|
+
totalTokens: acc.totalTokens + usage.totalTokens,
|
|
90
|
+
costUsd: acc.costUsd + usage.costUsd,
|
|
91
|
+
llmCalls: acc.llmCalls + usage.llmCalls,
|
|
92
|
+
recursiveCalls: acc.recursiveCalls + usage.recursiveCalls,
|
|
93
|
+
maxDepthReached: Math.max(acc.maxDepthReached, usage.maxDepthReached),
|
|
94
|
+
executionTimeMs: acc.executionTimeMs + usage.executionTimeMs,
|
|
95
|
+
}), {
|
|
96
|
+
totalTokens: 0,
|
|
97
|
+
costUsd: 0,
|
|
98
|
+
llmCalls: 0,
|
|
99
|
+
recursiveCalls: 0,
|
|
100
|
+
maxDepthReached: 0,
|
|
101
|
+
executionTimeMs: 0,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Flatten recursive call tree to list of answers
|
|
106
|
+
*/
|
|
107
|
+
export function flattenRecursiveResults(result) {
|
|
108
|
+
const answers = [result.answer];
|
|
109
|
+
for (const child of result.children) {
|
|
110
|
+
answers.push(...flattenRecursiveResults(child));
|
|
111
|
+
}
|
|
112
|
+
return answers;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Calculate total usage from recursive call tree
|
|
116
|
+
*/
|
|
117
|
+
export function totalUsageFromTree(result) {
|
|
118
|
+
const childUsages = result.children.map(totalUsageFromTree);
|
|
119
|
+
return aggregateTokenUsage([result.usage, ...childUsages]);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Find maximum depth in recursive call tree
|
|
123
|
+
*/
|
|
124
|
+
export function maxDepthInTree(result) {
|
|
125
|
+
if (result.children.length === 0) {
|
|
126
|
+
return result.depth;
|
|
127
|
+
}
|
|
128
|
+
const childDepths = result.children.map(maxDepthInTree);
|
|
129
|
+
return Math.max(...childDepths);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=result-aggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-aggregator.js","sourceRoot":"","sources":["../../../src/domain/services/result-aggregator.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAA0B,EAC1B,SAAS,GAAG,aAAa;IAEzB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,MAAM,MAAM,GAAc,EAAE,CAAC;IAE7B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,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K,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAA2B;IACxD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for RLM execution - immutable after creation
|
|
3
|
+
*/
|
|
4
|
+
export interface RLMConfig {
|
|
5
|
+
/** Maximum recursion depth (default: 5, max: 10) */
|
|
6
|
+
readonly maxRecursionDepth: number;
|
|
7
|
+
/** Maximum total tokens across all LLM calls */
|
|
8
|
+
readonly maxTokens: number;
|
|
9
|
+
/** Maximum cost in USD for the session */
|
|
10
|
+
readonly maxCostUsd: number;
|
|
11
|
+
/** Timeout for the entire session in milliseconds */
|
|
12
|
+
readonly timeoutMs: number;
|
|
13
|
+
/** LLM model to use (e.g., 'anthropic/claude-sonnet-4') */
|
|
14
|
+
readonly model: string;
|
|
15
|
+
/** Temperature for LLM generation */
|
|
16
|
+
readonly temperature: number;
|
|
17
|
+
/** Sandbox mode: 'strict' | 'permissive' | 'disabled' */
|
|
18
|
+
readonly sandboxMode: SandboxMode;
|
|
19
|
+
}
|
|
20
|
+
export type SandboxMode = 'strict' | 'permissive' | 'disabled';
|
|
21
|
+
/**
|
|
22
|
+
* Partial config for user overrides (mutable for building up)
|
|
23
|
+
*/
|
|
24
|
+
export interface RLMConfigInput {
|
|
25
|
+
maxRecursionDepth?: number;
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
maxCostUsd?: number;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
model?: string;
|
|
30
|
+
temperature?: number;
|
|
31
|
+
sandboxMode?: SandboxMode;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default configuration values
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_CONFIG: RLMConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Create a complete config by merging input with defaults
|
|
39
|
+
*/
|
|
40
|
+
export declare function createConfig(input?: RLMConfigInput): RLMConfig;
|
|
41
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/domain/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,0CAA0C;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,SAQnB,CAAC;AAEX;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAK9D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default configuration values
|
|
3
|
+
*/
|
|
4
|
+
export const DEFAULT_CONFIG = {
|
|
5
|
+
maxRecursionDepth: 5,
|
|
6
|
+
maxTokens: 1_000_000,
|
|
7
|
+
maxCostUsd: 10,
|
|
8
|
+
timeoutMs: 300_000, // 5 minutes
|
|
9
|
+
model: 'anthropic/claude-sonnet-4',
|
|
10
|
+
temperature: 0.3,
|
|
11
|
+
sandboxMode: 'strict',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Create a complete config by merging input with defaults
|
|
15
|
+
*/
|
|
16
|
+
export function createConfig(input) {
|
|
17
|
+
return {
|
|
18
|
+
...DEFAULT_CONFIG,
|
|
19
|
+
...input,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/domain/types/config.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAc;IACvC,iBAAiB,EAAE,CAAC;IACpB,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,EAAE;IACd,SAAS,EAAE,OAAO,EAAE,YAAY;IAChC,KAAK,EAAE,2BAA2B;IAClC,WAAW,EAAE,GAAG;IAChB,WAAW,EAAE,QAAQ;CACb,CAAC;AAEX;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAsB;IACjD,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,KAAK;KACT,CAAC;AACJ,CAAC"}
|