tracelattice 1.2.9 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -13
- package/dist/ServerConfig.d.ts +60 -0
- package/dist/ServerConfig.d.ts.map +1 -1
- package/dist/ServerConfig.js +27 -1
- package/dist/ServerConfig.js.map +1 -1
- package/dist/__tests__/calibrator/Calibrator.test.d.ts +6 -0
- package/dist/__tests__/calibrator/Calibrator.test.d.ts.map +1 -0
- package/dist/__tests__/compression/CompressionService.test.d.ts +5 -0
- package/dist/__tests__/compression/CompressionService.test.d.ts.map +1 -0
- package/dist/__tests__/compression/DehydrationPolicy.test.d.ts +5 -0
- package/dist/__tests__/compression/DehydrationPolicy.test.d.ts.map +1 -0
- package/dist/__tests__/compression/InMemorySummaryStore.test.d.ts +5 -0
- package/dist/__tests__/compression/InMemorySummaryStore.test.d.ts.map +1 -0
- package/dist/__tests__/config/ConfigLoader.features.test.d.ts +2 -0
- package/dist/__tests__/config/ConfigLoader.features.test.d.ts.map +1 -0
- package/dist/__tests__/core/HistoryManager.dag.test.d.ts +9 -0
- package/dist/__tests__/core/HistoryManager.dag.test.d.ts.map +1 -0
- package/dist/__tests__/core/HistoryManager.edge-persistence.test.d.ts +12 -0
- package/dist/__tests__/core/HistoryManager.edge-persistence.test.d.ts.map +1 -0
- package/dist/__tests__/core/HistoryManager.toolInvocation.test.d.ts +2 -0
- package/dist/__tests__/core/HistoryManager.toolInvocation.test.d.ts.map +1 -0
- package/dist/__tests__/core/ThoughtProcessor.newThoughtTypes.test.d.ts +2 -0
- package/dist/__tests__/core/ThoughtProcessor.newThoughtTypes.test.d.ts.map +1 -0
- package/dist/__tests__/core/ThoughtProcessor.toolInterleave.test.d.ts +2 -0
- package/dist/__tests__/core/ThoughtProcessor.toolInterleave.test.d.ts.map +1 -0
- package/dist/__tests__/core/graph/Edge.test.d.ts +5 -0
- package/dist/__tests__/core/graph/Edge.test.d.ts.map +1 -0
- package/dist/__tests__/core/graph/EdgeStore.test.d.ts +5 -0
- package/dist/__tests__/core/graph/EdgeStore.test.d.ts.map +1 -0
- package/dist/__tests__/core/graph/GraphView.test.d.ts +5 -0
- package/dist/__tests__/core/graph/GraphView.test.d.ts.map +1 -0
- package/dist/__tests__/core/reasoning/OutcomeRecorder.test.d.ts +5 -0
- package/dist/__tests__/core/reasoning/OutcomeRecorder.test.d.ts.map +1 -0
- package/dist/__tests__/core/reasoning/strategies/TreeOfThought.newTypes.test.d.ts +2 -0
- package/dist/__tests__/core/reasoning/strategies/TreeOfThought.newTypes.test.d.ts.map +1 -0
- package/dist/__tests__/core/retraction.test.d.ts +2 -0
- package/dist/__tests__/core/retraction.test.d.ts.map +1 -0
- package/dist/__tests__/core/thought-id.test.d.ts +13 -0
- package/dist/__tests__/core/thought-id.test.d.ts.map +1 -0
- package/dist/__tests__/core/tools/InMemorySuspensionStore.test.d.ts +2 -0
- package/dist/__tests__/core/tools/InMemorySuspensionStore.test.d.ts.map +1 -0
- package/dist/__tests__/eval/fixtures/scenarios.d.ts +37 -0
- package/dist/__tests__/eval/fixtures/scenarios.d.ts.map +1 -0
- package/dist/__tests__/eval/totVsSequential.eval.d.ts +16 -0
- package/dist/__tests__/eval/totVsSequential.eval.d.ts.map +1 -0
- package/dist/__tests__/evaluator/EvaluatorBackwardCompat.test.d.ts +15 -0
- package/dist/__tests__/evaluator/EvaluatorBackwardCompat.test.d.ts.map +1 -0
- package/dist/__tests__/helpers/factories.d.ts +2 -0
- package/dist/__tests__/helpers/factories.d.ts.map +1 -1
- package/dist/__tests__/integration/CompressionAutoTrigger.test.d.ts +11 -0
- package/dist/__tests__/integration/CompressionAutoTrigger.test.d.ts.map +1 -0
- package/dist/__tests__/integration/CompressionPersistence.test.d.ts +17 -0
- package/dist/__tests__/integration/CompressionPersistence.test.d.ts.map +1 -0
- package/dist/__tests__/integration/StrategyIntegration.test.d.ts +10 -0
- package/dist/__tests__/integration/StrategyIntegration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/ToTStrategyIntegration.test.d.ts +18 -0
- package/dist/__tests__/integration/ToTStrategyIntegration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/dag-edges.test.d.ts +17 -0
- package/dist/__tests__/integration/dag-edges.test.d.ts.map +1 -0
- package/dist/__tests__/strategies/SequentialStrategy.test.d.ts +2 -0
- package/dist/__tests__/strategies/SequentialStrategy.test.d.ts.map +1 -0
- package/dist/__tests__/strategies/StrategyContract.test.d.ts +18 -0
- package/dist/__tests__/strategies/StrategyContract.test.d.ts.map +1 -0
- package/dist/__tests__/strategies/TreeOfThoughtStrategy.test.d.ts +9 -0
- package/dist/__tests__/strategies/TreeOfThoughtStrategy.test.d.ts.map +1 -0
- package/dist/__tests__/strategies/plateau.test.d.ts +2 -0
- package/dist/__tests__/strategies/plateau.test.d.ts.map +1 -0
- package/dist/__tests__/strategies/totScoring.test.d.ts +2 -0
- package/dist/__tests__/strategies/totScoring.test.d.ts.map +1 -0
- package/dist/cli.js +9 -9
- package/dist/cli.js.map +1 -1
- package/dist/config/ConfigLoader.d.ts +37 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -1
- package/dist/config/ConfigLoader.js +52 -2
- package/dist/config/ConfigLoader.js.map +1 -1
- package/dist/context/RequestContext.d.ts +2 -46
- package/dist/context/RequestContext.d.ts.map +1 -1
- package/dist/context/RequestContext.js +1 -10
- package/dist/context/RequestContext.js.map +1 -1
- package/dist/contracts/calibrator.d.ts +88 -0
- package/dist/contracts/calibrator.d.ts.map +1 -0
- package/dist/contracts/calibrator.js +1 -0
- package/dist/contracts/index.d.ts +5 -1
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/interfaces.d.ts +114 -35
- package/dist/contracts/interfaces.d.ts.map +1 -1
- package/dist/contracts/strategy.d.ts +106 -0
- package/dist/contracts/strategy.d.ts.map +1 -0
- package/dist/contracts/strategy.js +1 -0
- package/dist/contracts/summary.d.ts +104 -0
- package/dist/contracts/summary.d.ts.map +1 -0
- package/dist/contracts/summary.js +1 -0
- package/dist/contracts/suspension.d.ts +181 -0
- package/dist/contracts/suspension.d.ts.map +1 -0
- package/dist/contracts/suspension.js +1 -0
- package/dist/core/HistoryManager.d.ts +54 -441
- package/dist/core/HistoryManager.d.ts.map +1 -1
- package/dist/core/HistoryManager.js +132 -145
- package/dist/core/HistoryManager.js.map +1 -1
- package/dist/core/IHistoryManager.d.ts +17 -0
- package/dist/core/IHistoryManager.d.ts.map +1 -1
- package/dist/core/InputNormalizer.d.ts.map +1 -1
- package/dist/core/InputNormalizer.js +13 -24
- package/dist/core/InputNormalizer.js.map +1 -1
- package/dist/core/PersistenceBuffer.d.ts +110 -0
- package/dist/core/PersistenceBuffer.d.ts.map +1 -0
- package/dist/core/PersistenceBuffer.js +141 -0
- package/dist/core/PersistenceBuffer.js.map +1 -0
- package/dist/core/SessionManager.d.ts +58 -0
- package/dist/core/SessionManager.d.ts.map +1 -0
- package/dist/core/SessionManager.js +65 -0
- package/dist/core/SessionManager.js.map +1 -0
- package/dist/core/ThoughtEvaluator.d.ts +14 -99
- package/dist/core/ThoughtEvaluator.d.ts.map +1 -1
- package/dist/core/ThoughtEvaluator.js +66 -331
- package/dist/core/ThoughtEvaluator.js.map +1 -1
- package/dist/core/ThoughtFormatter.d.ts.map +1 -1
- package/dist/core/ThoughtFormatter.js +23 -1
- package/dist/core/ThoughtFormatter.js.map +1 -1
- package/dist/core/ThoughtProcessor.d.ts +68 -50
- package/dist/core/ThoughtProcessor.d.ts.map +1 -1
- package/dist/core/ThoughtProcessor.js +159 -7
- package/dist/core/ThoughtProcessor.js.map +1 -1
- package/dist/core/compression/CompressionService.d.ts +74 -0
- package/dist/core/compression/CompressionService.d.ts.map +1 -0
- package/dist/core/compression/CompressionService.js +159 -0
- package/dist/core/compression/CompressionService.js.map +1 -0
- package/dist/core/compression/DehydrationPolicy.d.ts +74 -0
- package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -0
- package/dist/core/compression/DehydrationPolicy.js +45 -0
- package/dist/core/compression/DehydrationPolicy.js.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts +130 -0
- package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -0
- package/dist/core/compression/InMemorySummaryStore.js +55 -0
- package/dist/core/compression/InMemorySummaryStore.js.map +1 -0
- package/dist/core/compression/Summary.d.ts +55 -0
- package/dist/core/compression/Summary.d.ts.map +1 -0
- package/dist/core/compression/Summary.js +1 -0
- package/dist/core/evaluator/Aggregator.d.ts +40 -0
- package/dist/core/evaluator/Aggregator.d.ts.map +1 -0
- package/dist/core/evaluator/Aggregator.js +32 -0
- package/dist/core/evaluator/Aggregator.js.map +1 -0
- package/dist/core/evaluator/Calibrator.d.ts +49 -0
- package/dist/core/evaluator/Calibrator.d.ts.map +1 -0
- package/dist/core/evaluator/Calibrator.js +172 -0
- package/dist/core/evaluator/Calibrator.js.map +1 -0
- package/dist/core/evaluator/PatternDetector.d.ts +69 -0
- package/dist/core/evaluator/PatternDetector.d.ts.map +1 -0
- package/dist/core/evaluator/PatternDetector.js +188 -0
- package/dist/core/evaluator/PatternDetector.js.map +1 -0
- package/dist/core/evaluator/SignalComputer.d.ts +116 -0
- package/dist/core/evaluator/SignalComputer.d.ts.map +1 -0
- package/dist/core/evaluator/SignalComputer.js +106 -0
- package/dist/core/evaluator/SignalComputer.js.map +1 -0
- package/dist/core/evaluator/internals.d.ts +36 -0
- package/dist/core/evaluator/internals.d.ts.map +1 -0
- package/dist/core/evaluator/internals.js +43 -0
- package/dist/core/evaluator/internals.js.map +1 -0
- package/dist/core/graph/Edge.d.ts +51 -0
- package/dist/core/graph/Edge.d.ts.map +1 -0
- package/dist/core/graph/Edge.js +1 -0
- package/dist/core/graph/EdgeEmitter.d.ts +64 -0
- package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
- package/dist/core/graph/EdgeEmitter.js +99 -0
- package/dist/core/graph/EdgeEmitter.js.map +1 -0
- package/dist/core/graph/EdgeStore.d.ts +104 -0
- package/dist/core/graph/EdgeStore.d.ts.map +1 -0
- package/dist/core/graph/EdgeStore.js +78 -0
- package/dist/core/graph/EdgeStore.js.map +1 -0
- package/dist/core/graph/GraphView.d.ts +156 -0
- package/dist/core/graph/GraphView.d.ts.map +1 -0
- package/dist/core/graph/GraphView.js +149 -0
- package/dist/core/graph/GraphView.js.map +1 -0
- package/dist/core/ids.d.ts +33 -0
- package/dist/core/ids.d.ts.map +1 -0
- package/dist/core/ids.js +11 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts +78 -0
- package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -0
- package/dist/core/reasoning/OutcomeRecorder.js +36 -0
- package/dist/core/reasoning/OutcomeRecorder.js.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +54 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js +22 -0
- package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts +25 -0
- package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js +15 -0
- package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +58 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +98 -0
- package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -0
- package/dist/core/reasoning/strategies/plateau.d.ts +18 -0
- package/dist/core/reasoning/strategies/plateau.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/plateau.js +12 -0
- package/dist/core/reasoning/strategies/plateau.js.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts +90 -0
- package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -0
- package/dist/core/reasoning/strategies/totScoring.js +79 -0
- package/dist/core/reasoning/strategies/totScoring.js.map +1 -0
- package/dist/core/reasoning.d.ts +23 -3
- package/dist/core/reasoning.d.ts.map +1 -1
- package/dist/core/thought.d.ts +36 -0
- package/dist/core/thought.d.ts.map +1 -1
- package/dist/core/tools/InMemorySuspensionStore.d.ts +59 -0
- package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -0
- package/dist/core/tools/InMemorySuspensionStore.js +91 -0
- package/dist/core/tools/InMemorySuspensionStore.js.map +1 -0
- package/dist/di/ServiceRegistry.d.ts +14 -0
- package/dist/di/ServiceRegistry.d.ts.map +1 -1
- package/dist/errors.d.ts +117 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +40 -1
- package/dist/errors.js.map +1 -1
- package/dist/health/HealthChecker.d.ts.map +1 -1
- package/dist/health/HealthChecker.js +3 -2
- package/dist/health/HealthChecker.js.map +1 -1
- package/dist/lib.d.ts +0 -5
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +67 -12
- package/dist/lib.js.map +1 -1
- package/dist/persistence/FilePersistence.d.ts +55 -0
- package/dist/persistence/FilePersistence.d.ts.map +1 -1
- package/dist/persistence/FilePersistence.js +120 -1
- package/dist/persistence/FilePersistence.js.map +1 -1
- package/dist/persistence/MemoryPersistence.d.ts +40 -0
- package/dist/persistence/MemoryPersistence.d.ts.map +1 -1
- package/dist/persistence/MemoryPersistence.js +33 -0
- package/dist/persistence/MemoryPersistence.js.map +1 -1
- package/dist/persistence/PersistenceBackend.d.ts +40 -0
- package/dist/persistence/PersistenceBackend.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.d.ts +41 -0
- package/dist/persistence/SqlitePersistence.d.ts.map +1 -1
- package/dist/persistence/SqlitePersistence.js +102 -0
- package/dist/persistence/SqlitePersistence.js.map +1 -1
- package/dist/registry/BaseRegistry.d.ts.map +1 -1
- package/dist/registry/BaseRegistry.js +4 -3
- package/dist/registry/BaseRegistry.js.map +1 -1
- package/dist/registry/SkillRegistry.d.ts +1 -1
- package/dist/registry/SkillRegistry.js.map +1 -1
- package/dist/schema.d.ts +27 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +41 -9
- package/dist/schema.js.map +1 -1
- package/dist/transport/BaseTransport.d.ts +1 -20
- package/dist/transport/BaseTransport.d.ts.map +1 -1
- package/dist/transport/BaseTransport.js +1 -2
- package/dist/transport/BaseTransport.js.map +1 -1
- package/dist/transport/HttpHelpers.d.ts +0 -7
- package/dist/transport/HttpHelpers.d.ts.map +1 -1
- package/dist/transport/HttpHelpers.js +1 -7
- package/dist/transport/HttpHelpers.js.map +1 -1
- package/dist/transport/HttpTransport.d.ts.map +1 -1
- package/dist/transport/HttpTransport.js +2 -1
- package/dist/transport/HttpTransport.js.map +1 -1
- package/dist/transport/StreamableHttpTransport.d.ts +0 -6
- package/dist/transport/StreamableHttpTransport.d.ts.map +1 -1
- package/dist/transport/StreamableHttpTransport.js +4 -13
- package/dist/transport/StreamableHttpTransport.js.map +1 -1
- package/dist/watchers/SkillWatcher.d.ts.map +1 -1
- package/dist/watchers/SkillWatcher.js +3 -2
- package/dist/watchers/SkillWatcher.js.map +1 -1
- package/dist/watchers/ToolWatcher.d.ts.map +1 -1
- package/dist/watchers/ToolWatcher.js +2 -1
- package/dist/watchers/ToolWatcher.js.map +1 -1
- package/package.json +4 -4
- package/dist/__tests__/request-context.test.d.ts +0 -2
- package/dist/__tests__/request-context.test.d.ts.map +0 -1
- package/dist/__tests__/worker-manager-cov.test.d.ts +0 -2
- package/dist/__tests__/worker-manager-cov.test.d.ts.map +0 -1
- package/dist/__tests__/worker-manager.test.d.ts +0 -2
- package/dist/__tests__/worker-manager.test.d.ts.map +0 -1
- package/dist/cluster/WorkerManager.d.ts +0 -166
- package/dist/cluster/WorkerManager.d.ts.map +0 -1
- package/dist/cluster/WorkerManager.js +0 -202
- package/dist/cluster/WorkerManager.js.map +0 -1
- package/dist/cluster/worker.d.ts +0 -11
- package/dist/cluster/worker.d.ts.map +0 -1
- package/dist/cluster/worker.js +0 -36
- package/dist/cluster/worker.js.map +0 -1
- package/dist/telemetry/Telemetry.d.ts +0 -36
- package/dist/telemetry/Telemetry.d.ts.map +0 -1
- package/dist/telemetry/Telemetry.js +0 -68
- package/dist/telemetry/Telemetry.js.map +0 -1
- package/dist/telemetry/__tests__/Telemetry.test.d.ts +0 -2
- package/dist/telemetry/__tests__/Telemetry.test.d.ts.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reasoning Strategy contract — defines how a strategy observes reasoning state
|
|
3
|
+
* and decides the next action (continue, branch, terminate, suspend).
|
|
4
|
+
*
|
|
5
|
+
* Strategies are pluggable policies that drive higher-level reasoning control
|
|
6
|
+
* flow on top of the sequential thinking pipeline. They are pure (no I/O) and
|
|
7
|
+
* receive a snapshot of session state via {@link StrategyContext}.
|
|
8
|
+
*
|
|
9
|
+
* @module contracts/strategy
|
|
10
|
+
*/
|
|
11
|
+
import type { ThoughtData } from '../core/thought.js';
|
|
12
|
+
import type { ReasoningStats } from '../core/reasoning.js';
|
|
13
|
+
import type { GraphView } from '../core/graph/GraphView.js';
|
|
14
|
+
/**
|
|
15
|
+
* Read-only snapshot of session state passed to a reasoning strategy.
|
|
16
|
+
*
|
|
17
|
+
* All fields are immutable references. Strategies MUST NOT mutate the
|
|
18
|
+
* history, graph, or stats — doing so will corrupt downstream consumers.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const ctx: StrategyContext = {
|
|
23
|
+
* sessionId: 'sess_42',
|
|
24
|
+
* history: hm.getHistory('sess_42'),
|
|
25
|
+
* graph: new GraphView(edgeStore, 'sess_42'),
|
|
26
|
+
* stats: evaluator.computeStats(history),
|
|
27
|
+
* currentThought: latestThought,
|
|
28
|
+
* };
|
|
29
|
+
* const decision = strategy.decide(ctx);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface StrategyContext {
|
|
33
|
+
/** Session identifier this context belongs to. */
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
/** Chronological list of thoughts recorded in this session. */
|
|
36
|
+
readonly history: readonly ThoughtData[];
|
|
37
|
+
/** Read-only graph view for traversal (ancestors, descendants, etc.). */
|
|
38
|
+
readonly graph: GraphView;
|
|
39
|
+
/** Aggregated reasoning analytics for the session. */
|
|
40
|
+
readonly stats: ReasoningStats;
|
|
41
|
+
/** The thought that just triggered the strategy decision. */
|
|
42
|
+
readonly currentThought: ThoughtData;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Discriminated union describing the action a strategy wants to take.
|
|
46
|
+
*
|
|
47
|
+
* - `continue` — keep the current chain; optionally hint at next direction.
|
|
48
|
+
* - `branch` — fork a new branch from a prior thought.
|
|
49
|
+
* - `terminate` — stop the reasoning chain; reason is required.
|
|
50
|
+
* - `suspend` — pause the chain; may be resumed after `resumeAfter` ms.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const d: StrategyDecision = { action: 'branch', branchId: 'alt-1', fromThought: 3 };
|
|
55
|
+
* if (d.action === 'branch') console.log(d.branchId);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export type StrategyDecision = {
|
|
59
|
+
action: 'continue';
|
|
60
|
+
reason?: string;
|
|
61
|
+
nextHint?: string;
|
|
62
|
+
} | {
|
|
63
|
+
action: 'branch';
|
|
64
|
+
branchId: string;
|
|
65
|
+
fromThought: number;
|
|
66
|
+
reason?: string;
|
|
67
|
+
} | {
|
|
68
|
+
action: 'terminate';
|
|
69
|
+
reason: string;
|
|
70
|
+
} | {
|
|
71
|
+
action: 'suspend';
|
|
72
|
+
reason: string;
|
|
73
|
+
resumeAfter?: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Pluggable reasoning strategy interface.
|
|
77
|
+
*
|
|
78
|
+
* Implementations are stateless with respect to global state — all input
|
|
79
|
+
* comes from the {@link StrategyContext}. Strategies are registered via DI
|
|
80
|
+
* and selected by name (e.g. `tot`, `cot`, `react`).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* class GreedyStrategy implements IReasoningStrategy {
|
|
85
|
+
* readonly name = 'greedy';
|
|
86
|
+
* decide(ctx: StrategyContext): StrategyDecision {
|
|
87
|
+
* return { action: 'continue' };
|
|
88
|
+
* }
|
|
89
|
+
* shouldBranch(_ctx: StrategyContext): boolean { return false; }
|
|
90
|
+
* shouldTerminate(ctx: StrategyContext): boolean {
|
|
91
|
+
* return ctx.history.length >= 50;
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export interface IReasoningStrategy {
|
|
97
|
+
/** Stable identifier (used for DI lookup and metrics labels). */
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/** Compute the next action given the current state snapshot. */
|
|
100
|
+
decide(ctx: StrategyContext): StrategyDecision;
|
|
101
|
+
/** Predicate: should the chain branch right now? */
|
|
102
|
+
shouldBranch(ctx: StrategyContext): boolean;
|
|
103
|
+
/** Predicate: should the chain terminate right now? */
|
|
104
|
+
shouldTerminate(ctx: StrategyContext): boolean;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../src/contracts/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,yEAAyE;IACzE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC;CACrC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GACzB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5E;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,kBAAkB;IAClC,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,eAAe,GAAG,gBAAgB,CAAC;IAC/C,oDAAoD;IACpD,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC;IAC5C,uDAAuD;IACvD,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Summary store contract — defines the interface for persisting and querying
|
|
3
|
+
* compressed thought summaries produced by the compression subsystem.
|
|
4
|
+
*
|
|
5
|
+
* Implementations must provide per-session isolation: summaries from one
|
|
6
|
+
* session must never appear in queries scoped to another session.
|
|
7
|
+
*
|
|
8
|
+
* @module contracts/summary
|
|
9
|
+
*/
|
|
10
|
+
import type { Summary } from '../core/compression/Summary.js';
|
|
11
|
+
export type { Summary };
|
|
12
|
+
/**
|
|
13
|
+
* Storage and query contract for {@link Summary} records.
|
|
14
|
+
*
|
|
15
|
+
* Implementations are expected to be in-process (no I/O) and synchronous.
|
|
16
|
+
* Persistence backends may wrap this interface in async adapters.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const store: ISummaryStore = new InMemorySummaryStore();
|
|
21
|
+
* store.add(summary);
|
|
22
|
+
* const all = store.forSession('sess_42');
|
|
23
|
+
* const branch = store.forBranch('sess_42', 'alt-1');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface ISummaryStore {
|
|
27
|
+
/**
|
|
28
|
+
* Add a summary to the store.
|
|
29
|
+
*
|
|
30
|
+
* @param summary - The summary record to add
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* store.add({ id: '01HX...', sessionId: 's1', rootThoughtId: 't5', ... });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
add(summary: Summary): void;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve a summary by its unique id.
|
|
40
|
+
*
|
|
41
|
+
* @param id - The summary's unique identifier
|
|
42
|
+
* @returns The summary, or `undefined` if not found
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const s = store.get('01HX...');
|
|
47
|
+
* if (s) console.log(s.topics);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
get(id: string): Summary | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Get all summaries for a session, in insertion order.
|
|
53
|
+
*
|
|
54
|
+
* @param sessionId - Session to query
|
|
55
|
+
* @returns Read-only array of summaries (may be empty)
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* for (const s of store.forSession('sess_42')) {
|
|
60
|
+
* console.log(s.coveredRange);
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
forSession(sessionId: string): readonly Summary[];
|
|
65
|
+
/**
|
|
66
|
+
* Get all summaries for a specific branch within a session.
|
|
67
|
+
*
|
|
68
|
+
* @param sessionId - Session to query
|
|
69
|
+
* @param branchId - Branch identifier to filter by
|
|
70
|
+
* @returns Read-only array of summaries on that branch (may be empty)
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const altSummaries = store.forBranch('sess_42', 'alt-1');
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
forBranch(sessionId: string, branchId: string): readonly Summary[];
|
|
78
|
+
/**
|
|
79
|
+
* Remove all summaries for a session. Other sessions are unaffected.
|
|
80
|
+
*
|
|
81
|
+
* @param sessionId - Session to clear
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* store.clearSession('sess_42');
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
clearSession(sessionId: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Count summaries.
|
|
91
|
+
*
|
|
92
|
+
* @param sessionId - If provided, count for that session only;
|
|
93
|
+
* otherwise return the total across all sessions
|
|
94
|
+
* @returns The number of summaries
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const total = store.size();
|
|
99
|
+
* const perSession = store.size('sess_42');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
size(sessionId?: string): number;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../src/contracts/summary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;;;;;OASG;IACH,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAE5B;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAErC;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAAC;IAElD;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAAC;IAEnE;;;;;;;;;OASG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suspension store contract for tool interleave.
|
|
3
|
+
*
|
|
4
|
+
* Manages pending tool_call thoughts that are awaiting tool execution
|
|
5
|
+
* results. Each suspension is identified by a unique token, has a TTL,
|
|
6
|
+
* and can be resumed (consumed) or peeked (non-destructive lookup).
|
|
7
|
+
*
|
|
8
|
+
* @module contracts/suspension
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A single pending tool-call suspension record.
|
|
12
|
+
*
|
|
13
|
+
* Created when a `tool_call` thought is processed and the system is
|
|
14
|
+
* waiting for the corresponding tool result to be supplied via a
|
|
15
|
+
* follow-up `tool_result` thought.
|
|
16
|
+
*/
|
|
17
|
+
export interface SuspensionRecord {
|
|
18
|
+
/** Opaque token used to resume this suspension. */
|
|
19
|
+
readonly token: string;
|
|
20
|
+
/** Session that owns this suspension. */
|
|
21
|
+
readonly sessionId: string;
|
|
22
|
+
/** Thought number of the originating `tool_call` thought. */
|
|
23
|
+
readonly toolCallThoughtNumber: number;
|
|
24
|
+
/** Name of the tool to invoke. */
|
|
25
|
+
readonly toolName: string;
|
|
26
|
+
/** Arguments supplied to the tool. */
|
|
27
|
+
readonly toolArguments: Record<string, unknown>;
|
|
28
|
+
/** Wall-clock millisecond timestamp when the record was created. */
|
|
29
|
+
readonly createdAt: number;
|
|
30
|
+
/** Wall-clock millisecond timestamp after which the record is expired. */
|
|
31
|
+
readonly expiresAt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Store of pending tool-call suspensions with TTL expiry.
|
|
35
|
+
*
|
|
36
|
+
* Implementations are expected to expire records lazily on access and
|
|
37
|
+
* (optionally) eagerly via a background sweeper started by `start()`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const store: ISuspensionStore = new InMemorySuspensionStore();
|
|
42
|
+
* store.start();
|
|
43
|
+
* const rec = store.suspend({
|
|
44
|
+
* sessionId: 's1',
|
|
45
|
+
* toolCallThoughtNumber: 3,
|
|
46
|
+
* toolName: 'search',
|
|
47
|
+
* toolArguments: { q: 'foo' },
|
|
48
|
+
* expiresAt: Date.now() + 60_000,
|
|
49
|
+
* });
|
|
50
|
+
* const resumed = store.resume(rec.token);
|
|
51
|
+
* store.stop();
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface ISuspensionStore {
|
|
55
|
+
/**
|
|
56
|
+
* Create and store a new suspension record.
|
|
57
|
+
*
|
|
58
|
+
* The implementation generates a unique `token` and `createdAt`
|
|
59
|
+
* timestamp. If `ttlMs` is supplied, `expiresAt` is computed as
|
|
60
|
+
* `Date.now() + ttlMs` and overrides any caller-supplied
|
|
61
|
+
* `expiresAt` value.
|
|
62
|
+
*
|
|
63
|
+
* @param record - Record fields excluding `token` and `createdAt`,
|
|
64
|
+
* with optional `ttlMs` to derive `expiresAt`.
|
|
65
|
+
* @returns The fully-populated stored record.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const rec = store.suspend({
|
|
70
|
+
* sessionId: 's1',
|
|
71
|
+
* toolCallThoughtNumber: 2,
|
|
72
|
+
* toolName: 'search',
|
|
73
|
+
* toolArguments: {},
|
|
74
|
+
* ttlMs: 30_000,
|
|
75
|
+
* expiresAt: 0,
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
suspend(record: Omit<SuspensionRecord, 'token' | 'createdAt'> & {
|
|
80
|
+
ttlMs?: number;
|
|
81
|
+
}): SuspensionRecord;
|
|
82
|
+
/**
|
|
83
|
+
* Consume a suspension by token.
|
|
84
|
+
*
|
|
85
|
+
* Returns `null` for both unknown tokens and expired records;
|
|
86
|
+
* expired records are removed as a side-effect. The caller
|
|
87
|
+
* (typically `ThoughtProcessor`) is expected to distinguish the
|
|
88
|
+
* two cases (e.g. via a prior `peek()`) and throw
|
|
89
|
+
* `SuspensionNotFoundError` or `SuspensionExpiredError`
|
|
90
|
+
* accordingly.
|
|
91
|
+
*
|
|
92
|
+
* @param token - Token returned from {@link suspend}.
|
|
93
|
+
* @returns The record on success, `null` if missing or expired.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const rec = store.resume(token);
|
|
98
|
+
* if (!rec) throw new SuspensionNotFoundError(token);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
resume(token: string): SuspensionRecord | null;
|
|
102
|
+
/**
|
|
103
|
+
* Non-destructive lookup of a suspension by token.
|
|
104
|
+
*
|
|
105
|
+
* Does not remove expired records. Returns `null` if the token is
|
|
106
|
+
* unknown.
|
|
107
|
+
*
|
|
108
|
+
* @param token - Token to inspect.
|
|
109
|
+
* @returns The record if present (even when expired), else `null`.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const rec = store.peek(token);
|
|
114
|
+
* if (rec && rec.expiresAt < Date.now()) {
|
|
115
|
+
* throw new SuspensionExpiredError(token);
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
peek(token: string): SuspensionRecord | null;
|
|
120
|
+
/**
|
|
121
|
+
* Remove all records whose `expiresAt` is at or before `now`.
|
|
122
|
+
*
|
|
123
|
+
* @param now - Wall-clock millisecond timestamp to compare against.
|
|
124
|
+
* @returns Number of records removed.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const removed = store.expireOlderThan(Date.now());
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
expireOlderThan(now: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* Remove all records belonging to a session.
|
|
134
|
+
*
|
|
135
|
+
* @param sessionId - Session whose records should be cleared.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* store.clearSession('session-a');
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
clearSession(sessionId: string): void;
|
|
143
|
+
/**
|
|
144
|
+
* Count stored records.
|
|
145
|
+
*
|
|
146
|
+
* @param sessionId - Optional session filter; when omitted, returns
|
|
147
|
+
* the total count across all sessions.
|
|
148
|
+
* @returns Number of currently stored records (expired-but-not-yet-swept
|
|
149
|
+
* records are included).
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const total = store.size();
|
|
154
|
+
* const perSession = store.size('session-a');
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
size(sessionId?: string): number;
|
|
158
|
+
/**
|
|
159
|
+
* Start the background sweeper, if any.
|
|
160
|
+
*
|
|
161
|
+
* Idempotent — repeated calls have no additional effect.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* store.start();
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
start(): void;
|
|
169
|
+
/**
|
|
170
|
+
* Stop the background sweeper, if any.
|
|
171
|
+
*
|
|
172
|
+
* Idempotent — repeated calls have no additional effect.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* store.stop();
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
stop(): void;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=suspension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspension.d.ts","sourceRoot":"","sources":["../../src/contracts/suspension.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sCAAsC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,oEAAoE;IACpE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CACN,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,WAAW,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACxE,gBAAgB,CAAC;IAEpB;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAE/C;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAE7C;;;;;;;;;;OAUG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;;;;;;;;OASG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEjC;;;;;;;;;OASG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;;;;;;OASG;IACH,IAAI,IAAI,IAAI,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|