@weavelogic/knowledge-graph-agent 0.3.0 → 0.4.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/README.md +290 -3
- package/dist/_virtual/index10.js +2 -2
- package/dist/_virtual/index6.js +2 -2
- package/dist/_virtual/index7.js +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/audit/config.d.ts +150 -0
- package/dist/audit/config.d.ts.map +1 -0
- package/dist/audit/config.js +111 -0
- package/dist/audit/config.js.map +1 -0
- package/dist/audit/index.d.ts +38 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/services/audit-chain.d.ts +276 -0
- package/dist/audit/services/audit-chain.d.ts.map +1 -0
- package/dist/audit/services/audit-chain.js +502 -0
- package/dist/audit/services/audit-chain.js.map +1 -0
- package/dist/audit/services/index.d.ts +11 -0
- package/dist/audit/services/index.d.ts.map +1 -0
- package/dist/audit/services/syndication.d.ts +334 -0
- package/dist/audit/services/syndication.d.ts.map +1 -0
- package/dist/audit/services/syndication.js +589 -0
- package/dist/audit/services/syndication.js.map +1 -0
- package/dist/audit/types.d.ts +453 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/cli/commands/audit.d.ts +21 -0
- package/dist/cli/commands/audit.d.ts.map +1 -0
- package/dist/cli/commands/audit.js +621 -0
- package/dist/cli/commands/audit.js.map +1 -0
- package/dist/cli/commands/vector.d.ts +14 -0
- package/dist/cli/commands/vector.d.ts.map +1 -0
- package/dist/cli/commands/vector.js +429 -0
- package/dist/cli/commands/vector.js.map +1 -0
- package/dist/cli/commands/workflow.d.ts +12 -0
- package/dist/cli/commands/workflow.d.ts.map +1 -0
- package/dist/cli/commands/workflow.js +471 -0
- package/dist/cli/commands/workflow.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +26 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/database/schemas/index.d.ts +85 -0
- package/dist/database/schemas/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/audit/checkpoint.d.ts +58 -0
- package/dist/mcp-server/tools/audit/checkpoint.d.ts.map +1 -0
- package/dist/mcp-server/tools/audit/checkpoint.js +73 -0
- package/dist/mcp-server/tools/audit/checkpoint.js.map +1 -0
- package/dist/mcp-server/tools/audit/index.d.ts +53 -0
- package/dist/mcp-server/tools/audit/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/audit/index.js +12 -0
- package/dist/mcp-server/tools/audit/index.js.map +1 -0
- package/dist/mcp-server/tools/audit/query.d.ts +58 -0
- package/dist/mcp-server/tools/audit/query.d.ts.map +1 -0
- package/dist/mcp-server/tools/audit/query.js +125 -0
- package/dist/mcp-server/tools/audit/query.js.map +1 -0
- package/dist/mcp-server/tools/audit/sync.d.ts +58 -0
- package/dist/mcp-server/tools/audit/sync.d.ts.map +1 -0
- package/dist/mcp-server/tools/audit/sync.js +126 -0
- package/dist/mcp-server/tools/audit/sync.js.map +1 -0
- package/dist/mcp-server/tools/index.d.ts +3 -0
- package/dist/mcp-server/tools/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/registry.js +90 -0
- package/dist/mcp-server/tools/registry.js.map +1 -1
- package/dist/mcp-server/tools/vector/index.d.ts +12 -0
- package/dist/mcp-server/tools/vector/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/vector/index.js +12 -0
- package/dist/mcp-server/tools/vector/index.js.map +1 -0
- package/dist/mcp-server/tools/vector/search.d.ts +41 -0
- package/dist/mcp-server/tools/vector/search.d.ts.map +1 -0
- package/dist/mcp-server/tools/vector/search.js +224 -0
- package/dist/mcp-server/tools/vector/search.js.map +1 -0
- package/dist/mcp-server/tools/vector/trajectory.d.ts +39 -0
- package/dist/mcp-server/tools/vector/trajectory.d.ts.map +1 -0
- package/dist/mcp-server/tools/vector/trajectory.js +170 -0
- package/dist/mcp-server/tools/vector/trajectory.js.map +1 -0
- package/dist/mcp-server/tools/vector/upsert.d.ts +44 -0
- package/dist/mcp-server/tools/vector/upsert.d.ts.map +1 -0
- package/dist/mcp-server/tools/vector/upsert.js +175 -0
- package/dist/mcp-server/tools/vector/upsert.js.map +1 -0
- package/dist/mcp-server/tools/workflow/index.d.ts +29 -0
- package/dist/mcp-server/tools/workflow/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/workflow/index.js +12 -0
- package/dist/mcp-server/tools/workflow/index.js.map +1 -0
- package/dist/mcp-server/tools/workflow/list.d.ts +41 -0
- package/dist/mcp-server/tools/workflow/list.d.ts.map +1 -0
- package/dist/mcp-server/tools/workflow/list.js +195 -0
- package/dist/mcp-server/tools/workflow/list.js.map +1 -0
- package/dist/mcp-server/tools/workflow/start.d.ts +40 -0
- package/dist/mcp-server/tools/workflow/start.d.ts.map +1 -0
- package/dist/mcp-server/tools/workflow/start.js +165 -0
- package/dist/mcp-server/tools/workflow/start.js.map +1 -0
- package/dist/mcp-server/tools/workflow/status.d.ts +38 -0
- package/dist/mcp-server/tools/workflow/status.d.ts.map +1 -0
- package/dist/mcp-server/tools/workflow/status.js +97 -0
- package/dist/mcp-server/tools/workflow/status.js.map +1 -0
- package/dist/node_modules/ajv/dist/compile/index.js +1 -1
- package/dist/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/dist/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/dist/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/vector/config.d.ts +300 -0
- package/dist/vector/config.d.ts.map +1 -0
- package/dist/vector/config.js +124 -0
- package/dist/vector/config.js.map +1 -0
- package/dist/vector/index.d.ts +50 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/services/index.d.ts +13 -0
- package/dist/vector/services/index.d.ts.map +1 -0
- package/dist/vector/services/trajectory-tracker.d.ts +405 -0
- package/dist/vector/services/trajectory-tracker.d.ts.map +1 -0
- package/dist/vector/services/trajectory-tracker.js +445 -0
- package/dist/vector/services/trajectory-tracker.js.map +1 -0
- package/dist/vector/services/vector-store.d.ts +339 -0
- package/dist/vector/services/vector-store.d.ts.map +1 -0
- package/dist/vector/services/vector-store.js +748 -0
- package/dist/vector/services/vector-store.js.map +1 -0
- package/dist/vector/types.d.ts +677 -0
- package/dist/vector/types.d.ts.map +1 -0
- package/dist/workflow/adapters/goap-adapter.d.ts +196 -0
- package/dist/workflow/adapters/goap-adapter.d.ts.map +1 -0
- package/dist/workflow/adapters/goap-adapter.js +706 -0
- package/dist/workflow/adapters/goap-adapter.js.map +1 -0
- package/dist/workflow/adapters/index.d.ts +10 -0
- package/dist/workflow/adapters/index.d.ts.map +1 -0
- package/dist/workflow/config.d.ts +135 -0
- package/dist/workflow/config.d.ts.map +1 -0
- package/dist/workflow/config.js +92 -0
- package/dist/workflow/config.js.map +1 -0
- package/dist/workflow/handlers/index.d.ts +9 -0
- package/dist/workflow/handlers/index.d.ts.map +1 -0
- package/dist/workflow/handlers/webhook-handlers.d.ts +397 -0
- package/dist/workflow/handlers/webhook-handlers.d.ts.map +1 -0
- package/dist/workflow/handlers/webhook-handlers.js +454 -0
- package/dist/workflow/handlers/webhook-handlers.js.map +1 -0
- package/dist/workflow/index.d.ts +42 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/services/index.d.ts +9 -0
- package/dist/workflow/services/index.d.ts.map +1 -0
- package/dist/workflow/services/workflow-service.d.ts +318 -0
- package/dist/workflow/services/workflow-service.d.ts.map +1 -0
- package/dist/workflow/services/workflow-service.js +577 -0
- package/dist/workflow/services/workflow-service.js.map +1 -0
- package/dist/workflow/types.d.ts +470 -0
- package/dist/workflow/types.d.ts.map +1 -0
- package/dist/workflow/workflows/realtime-collab.d.ts +245 -0
- package/dist/workflow/workflows/realtime-collab.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trajectory Tracker
|
|
3
|
+
*
|
|
4
|
+
* Records agent operation sequences for pattern learning.
|
|
5
|
+
* Integrates with the SONA (Self-Optimizing Neural Architecture) engine.
|
|
6
|
+
*
|
|
7
|
+
* The trajectory tracker provides:
|
|
8
|
+
* - Recording of agent operation trajectories
|
|
9
|
+
* - Pattern detection from historical trajectories
|
|
10
|
+
* - Learning records for SONA integration
|
|
11
|
+
* - Success/failure analysis
|
|
12
|
+
* - Recommendations based on learned patterns
|
|
13
|
+
*
|
|
14
|
+
* @module vector/services/trajectory-tracker
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createTrajectoryTracker } from './trajectory-tracker.js';
|
|
19
|
+
*
|
|
20
|
+
* const tracker = createTrajectoryTracker({
|
|
21
|
+
* maxTrajectories: 1000,
|
|
22
|
+
* enableAutoLearning: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Start a new trajectory
|
|
26
|
+
* const trajectoryId = tracker.startTrajectory('agent-1', 'workflow-1');
|
|
27
|
+
*
|
|
28
|
+
* // Add steps as the agent works
|
|
29
|
+
* tracker.addStep(trajectoryId, {
|
|
30
|
+
* action: 'analyze_document',
|
|
31
|
+
* state: { documentId: 'doc-123', status: 'processing' },
|
|
32
|
+
* outcome: 'success',
|
|
33
|
+
* duration: 1500,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Finalize when done
|
|
37
|
+
* tracker.finalizeTrajectory(trajectoryId, { success: true });
|
|
38
|
+
*
|
|
39
|
+
* // Get recommendations for future actions
|
|
40
|
+
* const recommendations = tracker.getRecommendedActions('analyze_document');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
import type { TrajectoryStep, AgentTrajectory, SonaLearningRecord } from '../types.js';
|
|
44
|
+
/**
|
|
45
|
+
* Trajectory tracker configuration
|
|
46
|
+
*
|
|
47
|
+
* @property maxTrajectories - Maximum number of trajectories to keep in memory
|
|
48
|
+
* @property maxStepsPerTrajectory - Maximum steps per trajectory
|
|
49
|
+
* @property enableAutoLearning - Enable auto-learning from successful trajectories
|
|
50
|
+
* @property minSuccessRateForLearning - Minimum success rate to learn from
|
|
51
|
+
* @property patternThreshold - Number of occurrences before pattern is learned
|
|
52
|
+
*/
|
|
53
|
+
export interface TrajectoryTrackerConfig {
|
|
54
|
+
/** Maximum number of trajectories to keep in memory */
|
|
55
|
+
maxTrajectories?: number;
|
|
56
|
+
/** Maximum steps per trajectory */
|
|
57
|
+
maxStepsPerTrajectory?: number;
|
|
58
|
+
/** Enable auto-learning from successful trajectories */
|
|
59
|
+
enableAutoLearning?: boolean;
|
|
60
|
+
/** Minimum success rate to learn from */
|
|
61
|
+
minSuccessRateForLearning?: number;
|
|
62
|
+
/** Pattern extraction threshold */
|
|
63
|
+
patternThreshold?: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Pattern detected from trajectories
|
|
67
|
+
*
|
|
68
|
+
* Represents a sequence of actions that has been observed multiple times
|
|
69
|
+
* and can be used to predict or recommend future actions.
|
|
70
|
+
*/
|
|
71
|
+
export interface DetectedPattern {
|
|
72
|
+
/** Unique identifier for this pattern */
|
|
73
|
+
id: string;
|
|
74
|
+
/** Type of pattern (success, failure, or optimization opportunity) */
|
|
75
|
+
type: 'success' | 'failure' | 'optimization';
|
|
76
|
+
/** Sequence of actions in this pattern */
|
|
77
|
+
actions: string[];
|
|
78
|
+
/** Number of times this pattern has been observed */
|
|
79
|
+
frequency: number;
|
|
80
|
+
/** Average duration of trajectories with this pattern */
|
|
81
|
+
avgDuration: number;
|
|
82
|
+
/** Success rate of trajectories with this pattern */
|
|
83
|
+
successRate: number;
|
|
84
|
+
/** Confidence level in this pattern (0-1) */
|
|
85
|
+
confidence: number;
|
|
86
|
+
/** Additional metadata about the pattern */
|
|
87
|
+
metadata: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Trajectory Tracker class
|
|
91
|
+
*
|
|
92
|
+
* Provides comprehensive tracking and learning from agent operation sequences.
|
|
93
|
+
* This is a core component for the SONA (Self-Optimizing Neural Architecture)
|
|
94
|
+
* system, enabling agents to learn from past experiences and improve over time.
|
|
95
|
+
*
|
|
96
|
+
* Key capabilities:
|
|
97
|
+
* - **Recording**: Track agent operations as trajectories
|
|
98
|
+
* - **Pattern Detection**: Identify recurring action sequences
|
|
99
|
+
* - **Learning**: Create learning records from successful patterns
|
|
100
|
+
* - **Recommendations**: Suggest next actions based on patterns
|
|
101
|
+
* - **Analytics**: Provide statistics on trajectory performance
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const tracker = new TrajectoryTracker({
|
|
106
|
+
* maxTrajectories: 500,
|
|
107
|
+
* enableAutoLearning: true,
|
|
108
|
+
* patternThreshold: 5,
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Use throughout agent lifecycle
|
|
112
|
+
* const id = tracker.startTrajectory('my-agent');
|
|
113
|
+
* tracker.addStep(id, { action: 'step1', outcome: 'success' });
|
|
114
|
+
* tracker.addStep(id, { action: 'step2', outcome: 'success' });
|
|
115
|
+
* const trajectory = tracker.finalizeTrajectory(id, { success: true });
|
|
116
|
+
*
|
|
117
|
+
* // Analyze patterns
|
|
118
|
+
* const patterns = tracker.getPatterns({ minConfidence: 0.8 });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare class TrajectoryTracker {
|
|
122
|
+
private config;
|
|
123
|
+
private activeTrajectories;
|
|
124
|
+
private completedTrajectories;
|
|
125
|
+
private learningRecords;
|
|
126
|
+
private detectedPatterns;
|
|
127
|
+
/**
|
|
128
|
+
* Create a new TrajectoryTracker instance
|
|
129
|
+
*
|
|
130
|
+
* @param config - Configuration options for the tracker
|
|
131
|
+
*/
|
|
132
|
+
constructor(config?: TrajectoryTrackerConfig);
|
|
133
|
+
/**
|
|
134
|
+
* Start a new trajectory for an agent
|
|
135
|
+
*
|
|
136
|
+
* Creates a new trajectory record that will track the agent's operations.
|
|
137
|
+
* The trajectory must be finalized with `finalizeTrajectory` when complete.
|
|
138
|
+
*
|
|
139
|
+
* @param agentId - Unique identifier for the agent
|
|
140
|
+
* @param workflowId - Optional workflow this trajectory belongs to
|
|
141
|
+
* @param metadata - Optional additional metadata
|
|
142
|
+
* @returns The unique trajectory ID for tracking
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const trajectoryId = tracker.startTrajectory(
|
|
147
|
+
* 'researcher-agent-1',
|
|
148
|
+
* 'research-workflow-123',
|
|
149
|
+
* { priority: 'high', source: 'user-request' }
|
|
150
|
+
* );
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
startTrajectory(agentId: string, workflowId?: string, metadata?: Record<string, unknown>): string;
|
|
154
|
+
/**
|
|
155
|
+
* Add a step to an active trajectory
|
|
156
|
+
*
|
|
157
|
+
* Records a single operation/action taken by the agent as part of
|
|
158
|
+
* the trajectory. Steps are added in order and include timing information.
|
|
159
|
+
*
|
|
160
|
+
* @param trajectoryId - The trajectory to add the step to
|
|
161
|
+
* @param step - The step data (timestamp is auto-added)
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* tracker.addStep(trajectoryId, {
|
|
166
|
+
* action: 'analyze_document',
|
|
167
|
+
* state: { documentId: 'doc-123', status: 'processing', progress: 0.5 },
|
|
168
|
+
* outcome: 'success',
|
|
169
|
+
* duration: 2500,
|
|
170
|
+
* metadata: { model: 'claude-3-opus' }
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
addStep(trajectoryId: string, step: Omit<TrajectoryStep, 'timestamp'>): void;
|
|
175
|
+
/**
|
|
176
|
+
* Finalize a trajectory
|
|
177
|
+
*
|
|
178
|
+
* Marks a trajectory as complete, calculates total duration, and
|
|
179
|
+
* optionally triggers pattern learning if auto-learning is enabled.
|
|
180
|
+
*
|
|
181
|
+
* @param trajectoryId - The trajectory to finalize
|
|
182
|
+
* @param options - Finalization options including success status
|
|
183
|
+
* @returns The finalized trajectory, or null if not found
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const trajectory = tracker.finalizeTrajectory(trajectoryId, {
|
|
188
|
+
* success: true,
|
|
189
|
+
* metadata: { finalScore: 0.95 }
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
192
|
+
* if (trajectory) {
|
|
193
|
+
* console.log(`Completed in ${trajectory.totalDuration}ms`);
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
finalizeTrajectory(trajectoryId: string, options: {
|
|
198
|
+
success: boolean;
|
|
199
|
+
metadata?: Record<string, unknown>;
|
|
200
|
+
}): AgentTrajectory | null;
|
|
201
|
+
/**
|
|
202
|
+
* Learn patterns from a successful trajectory
|
|
203
|
+
*
|
|
204
|
+
* Extracts action sequences from the trajectory and updates pattern
|
|
205
|
+
* frequency and confidence metrics. Creates learning records when
|
|
206
|
+
* patterns exceed the configured threshold.
|
|
207
|
+
*
|
|
208
|
+
* @param trajectory - The trajectory to learn from
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
private learnFromTrajectory;
|
|
212
|
+
/**
|
|
213
|
+
* Generate a pattern ID from action sequence
|
|
214
|
+
*
|
|
215
|
+
* Creates a unique identifier for a pattern by joining action names.
|
|
216
|
+
*
|
|
217
|
+
* @param actions - Array of action names
|
|
218
|
+
* @returns Pattern identifier string
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
private generatePatternId;
|
|
222
|
+
/**
|
|
223
|
+
* Get recommended actions based on current state
|
|
224
|
+
*
|
|
225
|
+
* Analyzes detected patterns to suggest the most likely next actions
|
|
226
|
+
* based on the current action being performed.
|
|
227
|
+
*
|
|
228
|
+
* @param currentAction - The action currently being performed
|
|
229
|
+
* @param context - Optional context for more targeted recommendations
|
|
230
|
+
* @returns Array of recommended actions sorted by confidence
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const recommendations = tracker.getRecommendedActions('analyze_document');
|
|
235
|
+
*
|
|
236
|
+
* for (const rec of recommendations) {
|
|
237
|
+
* console.log(`Suggested: ${rec.action} (${rec.confidence.toFixed(2)} confidence)`);
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
getRecommendedActions(currentAction: string, context?: Record<string, unknown>): Array<{
|
|
242
|
+
action: string;
|
|
243
|
+
confidence: number;
|
|
244
|
+
basedOn: string;
|
|
245
|
+
}>;
|
|
246
|
+
/**
|
|
247
|
+
* Get trajectory by ID
|
|
248
|
+
*
|
|
249
|
+
* Retrieves a trajectory from either active or completed trajectories.
|
|
250
|
+
*
|
|
251
|
+
* @param trajectoryId - The trajectory ID to look up
|
|
252
|
+
* @returns The trajectory if found, null otherwise
|
|
253
|
+
*/
|
|
254
|
+
getTrajectory(trajectoryId: string): AgentTrajectory | null;
|
|
255
|
+
/**
|
|
256
|
+
* Get all trajectories for an agent
|
|
257
|
+
*
|
|
258
|
+
* Retrieves all completed trajectories that were executed by a specific agent.
|
|
259
|
+
*
|
|
260
|
+
* @param agentId - The agent ID to filter by
|
|
261
|
+
* @returns Array of trajectories for the agent
|
|
262
|
+
*/
|
|
263
|
+
getAgentTrajectories(agentId: string): AgentTrajectory[];
|
|
264
|
+
/**
|
|
265
|
+
* Get trajectories for a workflow
|
|
266
|
+
*
|
|
267
|
+
* Retrieves all completed trajectories that belong to a specific workflow.
|
|
268
|
+
*
|
|
269
|
+
* @param workflowId - The workflow ID to filter by
|
|
270
|
+
* @returns Array of trajectories for the workflow
|
|
271
|
+
*/
|
|
272
|
+
getWorkflowTrajectories(workflowId: string): AgentTrajectory[];
|
|
273
|
+
/**
|
|
274
|
+
* Get detected patterns
|
|
275
|
+
*
|
|
276
|
+
* Retrieves patterns that have been detected from trajectory analysis,
|
|
277
|
+
* optionally filtered by confidence level or pattern type.
|
|
278
|
+
*
|
|
279
|
+
* @param options - Filter options
|
|
280
|
+
* @returns Array of patterns sorted by confidence
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* // Get high-confidence success patterns
|
|
285
|
+
* const patterns = tracker.getPatterns({
|
|
286
|
+
* minConfidence: 0.8,
|
|
287
|
+
* type: 'success'
|
|
288
|
+
* });
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
getPatterns(options?: {
|
|
292
|
+
minConfidence?: number;
|
|
293
|
+
type?: 'success' | 'failure' | 'optimization';
|
|
294
|
+
}): DetectedPattern[];
|
|
295
|
+
/**
|
|
296
|
+
* Get learning records
|
|
297
|
+
*
|
|
298
|
+
* Retrieves SONA learning records, optionally filtered by pattern ID
|
|
299
|
+
* or time range.
|
|
300
|
+
*
|
|
301
|
+
* @param options - Filter options
|
|
302
|
+
* @returns Array of learning records
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* // Get recent learning records
|
|
307
|
+
* const records = tracker.getLearningRecords({
|
|
308
|
+
* since: new Date(Date.now() - 24 * 60 * 60 * 1000) // Last 24 hours
|
|
309
|
+
* });
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
getLearningRecords(options?: {
|
|
313
|
+
patternId?: string;
|
|
314
|
+
since?: Date;
|
|
315
|
+
}): SonaLearningRecord[];
|
|
316
|
+
/**
|
|
317
|
+
* Get statistics about trajectory tracking
|
|
318
|
+
*
|
|
319
|
+
* Provides aggregate statistics about trajectories, patterns,
|
|
320
|
+
* and learning performance.
|
|
321
|
+
*
|
|
322
|
+
* @returns Statistics object with counts and rates
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const stats = tracker.getStats();
|
|
327
|
+
* console.log(`Success rate: ${(stats.successRate * 100).toFixed(1)}%`);
|
|
328
|
+
* console.log(`Patterns detected: ${stats.detectedPatterns}`);
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
getStats(): {
|
|
332
|
+
activeTrajectories: number;
|
|
333
|
+
completedTrajectories: number;
|
|
334
|
+
detectedPatterns: number;
|
|
335
|
+
learningRecords: number;
|
|
336
|
+
successRate: number;
|
|
337
|
+
avgDuration: number;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Clear all trajectory data
|
|
341
|
+
*
|
|
342
|
+
* Removes all active trajectories, completed trajectories, learning records,
|
|
343
|
+
* and detected patterns. Use with caution as this is irreversible.
|
|
344
|
+
*/
|
|
345
|
+
clear(): void;
|
|
346
|
+
/**
|
|
347
|
+
* Export data for persistence
|
|
348
|
+
*
|
|
349
|
+
* Serializes all trajectory data for storage or transfer.
|
|
350
|
+
* Use with `import()` to restore data.
|
|
351
|
+
*
|
|
352
|
+
* @returns Exportable data object
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* const data = tracker.export();
|
|
357
|
+
* await fs.writeFile('trajectories.json', JSON.stringify(data));
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
export(): {
|
|
361
|
+
trajectories: AgentTrajectory[];
|
|
362
|
+
patterns: DetectedPattern[];
|
|
363
|
+
learningRecords: SonaLearningRecord[];
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Import data from persistence
|
|
367
|
+
*
|
|
368
|
+
* Restores trajectory data from a previous export.
|
|
369
|
+
*
|
|
370
|
+
* @param data - Previously exported data object
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```typescript
|
|
374
|
+
* const data = JSON.parse(await fs.readFile('trajectories.json', 'utf-8'));
|
|
375
|
+
* tracker.import(data);
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
import(data: {
|
|
379
|
+
trajectories?: AgentTrajectory[];
|
|
380
|
+
patterns?: DetectedPattern[];
|
|
381
|
+
learningRecords?: SonaLearningRecord[];
|
|
382
|
+
}): void;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Create a trajectory tracker instance
|
|
386
|
+
*
|
|
387
|
+
* Factory function for creating a TrajectoryTracker with the specified
|
|
388
|
+
* configuration.
|
|
389
|
+
*
|
|
390
|
+
* @param config - Optional configuration options
|
|
391
|
+
* @returns New TrajectoryTracker instance
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* import { createTrajectoryTracker } from './trajectory-tracker.js';
|
|
396
|
+
*
|
|
397
|
+
* const tracker = createTrajectoryTracker({
|
|
398
|
+
* maxTrajectories: 500,
|
|
399
|
+
* enableAutoLearning: true,
|
|
400
|
+
* patternThreshold: 5,
|
|
401
|
+
* });
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
export declare function createTrajectoryTracker(config?: TrajectoryTrackerConfig): TrajectoryTracker;
|
|
405
|
+
//# sourceMappingURL=trajectory-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trajectory-tracker.d.ts","sourceRoot":"","sources":["../../../src/vector/services/trajectory-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAKrB;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mCAAmC;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yCAAyC;IACzC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,mCAAmC;IACnC,gBAAgB,CAAC,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