@almadar/agent 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/event-budget.d.ts +28 -0
- package/dist/agent/experimental/hitl-v2.d.ts +161 -0
- package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/interrupt-config.d.ts +51 -0
- package/dist/agent/session-manager.d.ts +204 -0
- package/dist/agent/skill-agent.d.ts +182 -0
- package/dist/agent/workflow-middleware.d.ts +63 -0
- package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
- package/dist/api-types.d.ts +595 -0
- package/dist/context/compaction.d.ts +191 -0
- package/dist/context-compaction.d.ts +55 -0
- package/dist/evals/online-sampling.d.ts +114 -0
- package/dist/evals/utils/compact-orbital.d.ts +100 -0
- package/dist/event-transformer/event-transformer.d.ts +120 -0
- package/dist/event-transformer/index.d.ts +7 -0
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryManager.d.ts +243 -0
- package/dist/memory/PreferenceLearner.d.ts +59 -0
- package/dist/memory/agentic-search.d.ts +116 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/memory-orbital.d.ts +66 -0
- package/dist/memory/types.d.ts +143 -0
- package/dist/metrics.d.ts +77 -0
- package/dist/multi-user.d.ts +155 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/langsmith-integration.d.ts +203 -0
- package/dist/observability.d.ts +196 -0
- package/dist/orbitals/archive/sanitize.d.ts +24 -0
- package/dist/orbitals/batch/batch-generator.d.ts +41 -0
- package/dist/orbitals/batch/concurrency.d.ts +54 -0
- package/dist/orbitals/batch/index.d.ts +14 -0
- package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
- package/dist/orbitals/batch/types.d.ts +103 -0
- package/dist/orbitals/cache/index.d.ts +11 -0
- package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
- package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
- package/dist/orbitals/cache/structural-templates.d.ts +33 -0
- package/dist/orbitals/combiner/index.d.ts +102 -0
- package/dist/orbitals/domain-language/index.d.ts +9 -0
- package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
- package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
- package/dist/orbitals/generation/index.d.ts +10 -0
- package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
- package/dist/orbitals/shared/constants.d.ts +65 -0
- package/dist/orbitals/shared/index.d.ts +11 -0
- package/dist/orbitals/shared/types.d.ts +187 -0
- package/dist/orbitals/shared/utils.d.ts +97 -0
- package/dist/orchestration/complexity-classifier.d.ts +38 -0
- package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
- package/dist/orchestration/index.d.ts +31 -0
- package/dist/orchestration/provider-router.d.ts +45 -0
- package/dist/persistence/firestore-checkpointer.d.ts +139 -0
- package/dist/persistence/firestore-session-store.d.ts +75 -0
- package/dist/persistence/firestore-store.d.ts +86 -0
- package/dist/persistence/index.d.ts +10 -0
- package/dist/persistence/memory-backend.d.ts +33 -0
- package/dist/persistence/types.d.ts +40 -0
- package/dist/security/audit-log.d.ts +44 -0
- package/dist/state-sync.d.ts +171 -0
- package/dist/subagents.d.ts +38 -0
- package/dist/tools/combine-schemas.d.ts +154 -0
- package/dist/tools/composition.d.ts +119 -0
- package/dist/tools/domain-orbital.d.ts +997 -0
- package/dist/tools/execute.d.ts +38 -0
- package/dist/tools/finish-task.d.ts +56 -0
- package/dist/tools/generate-schema.d.ts +53 -0
- package/dist/tools/github.d.ts +297 -0
- package/dist/tools/index.d.ts +1318 -0
- package/dist/tools/orbital-batch-subagent.d.ts +85 -0
- package/dist/tools/orbital-subagent.d.ts +454 -0
- package/dist/tools/orchestrated-fixing.d.ts +74 -0
- package/dist/tools/orchestrated-generation.d.ts +75 -0
- package/dist/tools/sandbox-executor.d.ts +31 -0
- package/dist/tools/schema-chunking.d.ts +117 -0
- package/dist/tools/trait-subagent.d.ts +179 -0
- package/dist/tools/validate-schema.d.ts +17 -0
- package/dist/types.d.ts +167 -0
- package/dist/utils/safety/capability-token.d.ts +50 -0
- package/dist/utils/safety/circuit-breaker.d.ts +71 -0
- package/dist/utils/safety/index.d.ts +19 -0
- package/dist/utils/safety/rate-limiter.d.ts +39 -0
- package/dist/utils/safety/threshold-auth.d.ts +70 -0
- package/dist/workspace/git-client.d.ts +51 -0
- package/dist/workspace/index.d.ts +38 -0
- package/dist/workspace/memory-files.d.ts +31 -0
- package/dist/workspace/sink-manager.d.ts +26 -0
- package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
- package/dist/workspace/sinks/git-sink.d.ts +47 -0
- package/dist/workspace/sinks/index.d.ts +9 -0
- package/dist/workspace/templates.d.ts +32 -0
- package/dist/workspace/types.d.ts +86 -0
- package/dist/workspace/workspace-manager.d.ts +57 -0
- package/package.json +8 -7
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Manager - GAP-001: Orbital Memory System
|
|
3
|
+
*
|
|
4
|
+
* Manages user memory and preferences using Firestore persistence.
|
|
5
|
+
* Provides the foundation for personalized AI assistance by learning
|
|
6
|
+
* from user interactions and feedback.
|
|
7
|
+
*/
|
|
8
|
+
import type { UserPreference, GenerationSession, ProjectContext } from './memory-orbital.js';
|
|
9
|
+
import type { UserFeedback, PatternAffinity, InterruptRecord, ToolApprovalPreference, CheckpointRecord } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Minimal Firestore interface to avoid importing firebase-admin.
|
|
12
|
+
* These match the interfaces defined in firestore-checkpointer.ts
|
|
13
|
+
*/
|
|
14
|
+
interface FirestoreDb {
|
|
15
|
+
collection(path: string): FirestoreCollectionRef;
|
|
16
|
+
batch(): FirestoreBatch;
|
|
17
|
+
}
|
|
18
|
+
interface FirestoreCollectionRef {
|
|
19
|
+
doc(id: string): FirestoreDocRef;
|
|
20
|
+
where(field: string, op: string, value: unknown): FirestoreQuery;
|
|
21
|
+
orderBy(field: string, direction?: string): FirestoreQuery;
|
|
22
|
+
limit(n: number): FirestoreQuery;
|
|
23
|
+
}
|
|
24
|
+
interface FirestoreDocRef {
|
|
25
|
+
set(data: unknown): Promise<unknown>;
|
|
26
|
+
get(): Promise<FirestoreDocSnapshot>;
|
|
27
|
+
update(data: unknown): Promise<unknown>;
|
|
28
|
+
delete(): Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
interface FirestoreDocSnapshot {
|
|
31
|
+
exists: boolean;
|
|
32
|
+
data(): Record<string, unknown> | undefined;
|
|
33
|
+
}
|
|
34
|
+
interface FirestoreQuery {
|
|
35
|
+
where(field: string, op: string, value: unknown): FirestoreQuery;
|
|
36
|
+
orderBy(field: string, direction?: string): FirestoreQuery;
|
|
37
|
+
limit(n: number): FirestoreQuery;
|
|
38
|
+
startAfter(doc: unknown): FirestoreQuery;
|
|
39
|
+
get(): Promise<FirestoreQuerySnapshot>;
|
|
40
|
+
}
|
|
41
|
+
interface FirestoreQuerySnapshot {
|
|
42
|
+
empty: boolean;
|
|
43
|
+
docs: FirestoreQueryDocSnapshot[];
|
|
44
|
+
size: number;
|
|
45
|
+
}
|
|
46
|
+
interface FirestoreQueryDocSnapshot {
|
|
47
|
+
data(): Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
interface FirestoreBatch {
|
|
50
|
+
set(ref: unknown, data: unknown): void;
|
|
51
|
+
delete(ref: unknown): void;
|
|
52
|
+
commit(): Promise<unknown>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Options for MemoryManager
|
|
56
|
+
*/
|
|
57
|
+
export interface MemoryManagerOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Firestore database instance (injected)
|
|
60
|
+
*/
|
|
61
|
+
db: FirestoreDb;
|
|
62
|
+
/**
|
|
63
|
+
* Collection name for user preferences
|
|
64
|
+
* @default 'agent_memory_users'
|
|
65
|
+
*/
|
|
66
|
+
usersCollection?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Collection name for generation sessions
|
|
69
|
+
* @default 'agent_memory_generations'
|
|
70
|
+
*/
|
|
71
|
+
generationsCollection?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Collection name for project context
|
|
74
|
+
* @default 'agent_memory_projects'
|
|
75
|
+
*/
|
|
76
|
+
projectsCollection?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Collection name for pattern affinity
|
|
79
|
+
* @default 'agent_memory_patterns'
|
|
80
|
+
*/
|
|
81
|
+
patternsCollection?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Collection name for user feedback
|
|
84
|
+
* @default 'agent_memory_feedback'
|
|
85
|
+
*/
|
|
86
|
+
feedbackCollection?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Collection name for interrupt records
|
|
89
|
+
* @default 'agent_memory_interrupts'
|
|
90
|
+
*/
|
|
91
|
+
interruptsCollection?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Collection name for tool approval preferences
|
|
94
|
+
* @default 'agent_memory_tool_preferences'
|
|
95
|
+
*/
|
|
96
|
+
toolPreferencesCollection?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Collection name for checkpoint records
|
|
99
|
+
* @default 'agent_memory_checkpoints'
|
|
100
|
+
*/
|
|
101
|
+
checkpointsCollection?: string;
|
|
102
|
+
}
|
|
103
|
+
export declare class MemoryManager {
|
|
104
|
+
private db;
|
|
105
|
+
private usersCollection;
|
|
106
|
+
private generationsCollection;
|
|
107
|
+
private projectsCollection;
|
|
108
|
+
private patternsCollection;
|
|
109
|
+
private feedbackCollection;
|
|
110
|
+
private interruptsCollection;
|
|
111
|
+
private toolPreferencesCollection;
|
|
112
|
+
private checkpointsCollection;
|
|
113
|
+
constructor(options: MemoryManagerOptions);
|
|
114
|
+
/**
|
|
115
|
+
* Get user preferences with defaults
|
|
116
|
+
*/
|
|
117
|
+
getUserPreferences(userId: string): Promise<UserPreference | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Update user preferences
|
|
120
|
+
*/
|
|
121
|
+
updateUserPreferences(userId: string, preferences: Partial<Omit<UserPreference, 'id' | 'userId' | 'learnedAt'>>): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Record a new generation session
|
|
124
|
+
*/
|
|
125
|
+
recordGeneration(userId: string, session: Omit<GenerationSession, 'id' | 'userId' | 'createdAt'>): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Get a specific generation session
|
|
128
|
+
*/
|
|
129
|
+
getGenerationSession(sessionId: string): Promise<GenerationSession | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Get generation history for a user
|
|
132
|
+
*/
|
|
133
|
+
getUserGenerationHistory(userId: string, limit?: number): Promise<GenerationSession[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Update generation session status
|
|
136
|
+
*/
|
|
137
|
+
updateGenerationStatus(sessionId: string, status: GenerationSession['success'], validationResult?: GenerationSession['validationResult']): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Get project context
|
|
140
|
+
*/
|
|
141
|
+
getProjectContext(appId: string): Promise<ProjectContext | null>;
|
|
142
|
+
/**
|
|
143
|
+
* Update project context with new information
|
|
144
|
+
*/
|
|
145
|
+
updateProjectContext(appId: string, update: Partial<Omit<ProjectContext, 'id' | 'appId'>>): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Update pattern affinity based on usage
|
|
148
|
+
*/
|
|
149
|
+
updatePatternAffinity(userId: string, patternId: string, outcome: 'success' | 'failure' | 'partial', context?: {
|
|
150
|
+
entityType?: string;
|
|
151
|
+
useCase?: string;
|
|
152
|
+
}): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Get pattern affinity for a user
|
|
155
|
+
*/
|
|
156
|
+
getPatternAffinity(userId: string, patternId: string): Promise<PatternAffinity | null>;
|
|
157
|
+
/**
|
|
158
|
+
* Get all patterns used by a user
|
|
159
|
+
*/
|
|
160
|
+
getUserPatterns(userId: string): Promise<PatternAffinity[]>;
|
|
161
|
+
/**
|
|
162
|
+
* Record user feedback on a generation
|
|
163
|
+
*/
|
|
164
|
+
recordFeedback(sessionId: string, feedback: Omit<UserFeedback, 'feedbackId' | 'sessionId' | 'timestamp'>): Promise<void>;
|
|
165
|
+
/**
|
|
166
|
+
* Get feedback for a session
|
|
167
|
+
*/
|
|
168
|
+
getSessionFeedback(sessionId: string): Promise<UserFeedback[]>;
|
|
169
|
+
private parsePreference;
|
|
170
|
+
private serializePreference;
|
|
171
|
+
private parseSession;
|
|
172
|
+
private serializeSession;
|
|
173
|
+
private parseContext;
|
|
174
|
+
private serializeContext;
|
|
175
|
+
/**
|
|
176
|
+
* Record an interrupt decision for learning
|
|
177
|
+
*/
|
|
178
|
+
recordInterruptDecision(sessionId: string, userId: string, interruptData: {
|
|
179
|
+
toolName: string;
|
|
180
|
+
toolArgs: Record<string, unknown>;
|
|
181
|
+
decision: 'approved' | 'rejected' | 'modified';
|
|
182
|
+
modifiedArgs?: Record<string, unknown>;
|
|
183
|
+
reason?: string;
|
|
184
|
+
}): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Get interrupt history for a session
|
|
187
|
+
*/
|
|
188
|
+
getSessionInterrupts(sessionId: string): Promise<InterruptRecord[]>;
|
|
189
|
+
/**
|
|
190
|
+
* Get interrupt history for a user
|
|
191
|
+
*/
|
|
192
|
+
getUserInterrupts(userId: string, limit?: number): Promise<InterruptRecord[]>;
|
|
193
|
+
/**
|
|
194
|
+
* Get tool approval preference for a user
|
|
195
|
+
*/
|
|
196
|
+
getToolApprovalPreference(userId: string, toolName: string): Promise<ToolApprovalPreference | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Update tool approval preference based on interrupt decisions
|
|
199
|
+
*/
|
|
200
|
+
private updateToolApprovalPreference;
|
|
201
|
+
/**
|
|
202
|
+
* Get all tool approval preferences for a user
|
|
203
|
+
*/
|
|
204
|
+
getUserToolPreferences(userId: string): Promise<ToolApprovalPreference[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Check if a tool should be auto-approved for a user
|
|
207
|
+
*/
|
|
208
|
+
shouldAutoApproveTool(userId: string, toolName: string): Promise<boolean>;
|
|
209
|
+
/**
|
|
210
|
+
* Record a checkpoint for learning
|
|
211
|
+
*/
|
|
212
|
+
recordCheckpoint(userId: string, checkpointData: {
|
|
213
|
+
checkpointId: string;
|
|
214
|
+
threadId: string;
|
|
215
|
+
parentCheckpointId?: string;
|
|
216
|
+
metadata?: Record<string, unknown>;
|
|
217
|
+
}): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Record a rollback to a checkpoint
|
|
220
|
+
*/
|
|
221
|
+
recordRollback(userId: string, checkpointId: string, reason?: string): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Mark a checkpoint as successful (terminal state)
|
|
224
|
+
*/
|
|
225
|
+
markCheckpointSuccessful(userId: string, checkpointId: string): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Get checkpoint history for a user
|
|
228
|
+
*/
|
|
229
|
+
getUserCheckpoints(userId: string, limit?: number): Promise<CheckpointRecord[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Get checkpoints for a thread
|
|
232
|
+
*/
|
|
233
|
+
getThreadCheckpoints(threadId: string): Promise<CheckpointRecord[]>;
|
|
234
|
+
/**
|
|
235
|
+
* Get frequently rolled-back checkpoints (problem areas)
|
|
236
|
+
*/
|
|
237
|
+
getProblemCheckpoints(userId: string, minRollbackCount?: number): Promise<CheckpointRecord[]>;
|
|
238
|
+
/**
|
|
239
|
+
* Get successful checkpoint patterns for learning
|
|
240
|
+
*/
|
|
241
|
+
getSuccessfulCheckpoints(userId: string, limit?: number): Promise<CheckpointRecord[]>;
|
|
242
|
+
}
|
|
243
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preference Learner
|
|
3
|
+
*
|
|
4
|
+
* Uses LLM to infer user preferences from generation sessions.
|
|
5
|
+
* Leverages @almadar/llm for structured output.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { LLMClient } from '@almadar/llm';
|
|
10
|
+
import type { GenerationSession, UserPreference } from './memory-orbital.js';
|
|
11
|
+
import { MemoryManager } from './MemoryManager.js';
|
|
12
|
+
export interface PreferenceLearnerOptions {
|
|
13
|
+
/** LLM client for inference */
|
|
14
|
+
llmClient?: LLMClient;
|
|
15
|
+
/** Memory manager for persistence */
|
|
16
|
+
memoryManager: MemoryManager;
|
|
17
|
+
/** Confidence threshold for auto-accepting preferences */
|
|
18
|
+
confidenceThreshold?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface InferredPreference {
|
|
21
|
+
/** The preference field being inferred */
|
|
22
|
+
field: keyof Omit<UserPreference, 'id' | 'userId' | 'learnedAt'>;
|
|
23
|
+
/** The inferred value */
|
|
24
|
+
value: unknown;
|
|
25
|
+
/** Confidence level (0-1) */
|
|
26
|
+
confidence: number;
|
|
27
|
+
/** Explanation of why this was inferred */
|
|
28
|
+
reasoning: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PreferenceAnalysis {
|
|
31
|
+
/** List of inferred preferences */
|
|
32
|
+
inferences: InferredPreference[];
|
|
33
|
+
/** Whether the inference is high confidence */
|
|
34
|
+
isHighConfidence: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare class PreferenceLearner {
|
|
37
|
+
private llmClient;
|
|
38
|
+
private memoryManager;
|
|
39
|
+
private confidenceThreshold;
|
|
40
|
+
constructor(options: PreferenceLearnerOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Analyze a session and infer user preferences
|
|
43
|
+
*/
|
|
44
|
+
analyzeSession(session: GenerationSession): Promise<PreferenceAnalysis>;
|
|
45
|
+
/**
|
|
46
|
+
* Learn from a session and update preferences if confidence is high
|
|
47
|
+
*/
|
|
48
|
+
learnFromSession(session: GenerationSession): Promise<UserPreference | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Batch learn from multiple sessions
|
|
51
|
+
*/
|
|
52
|
+
batchLearn(sessions: GenerationSession[]): Promise<UserPreference | null>;
|
|
53
|
+
private buildAnalysisPrompt;
|
|
54
|
+
private buildAggregatePrompt;
|
|
55
|
+
private parseAnalysisResponse;
|
|
56
|
+
private isValidNamingConvention;
|
|
57
|
+
private isValidValidationStyle;
|
|
58
|
+
}
|
|
59
|
+
export declare function createPreferenceLearner(options: PreferenceLearnerOptions): PreferenceLearner;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic Search - GAP-006
|
|
3
|
+
*
|
|
4
|
+
* Reasoning-based search through memory orbitals.
|
|
5
|
+
* Unlike RAG (vector similarity), this uses agent traversal with understanding
|
|
6
|
+
* of state transitions, patterns, and temporal relationships.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import type { MemoryManager } from './MemoryManager.js';
|
|
11
|
+
/**
|
|
12
|
+
* Search strategy for agentic search
|
|
13
|
+
*/
|
|
14
|
+
export type SearchStrategy = 'temporal' | 'semantic' | 'pattern' | 'hybrid';
|
|
15
|
+
/**
|
|
16
|
+
* Search parameters
|
|
17
|
+
*/
|
|
18
|
+
export interface AgenticSearchParams {
|
|
19
|
+
/** User to search memory for */
|
|
20
|
+
userId: string;
|
|
21
|
+
/** Natural language query */
|
|
22
|
+
query: string;
|
|
23
|
+
/** Search strategy */
|
|
24
|
+
strategy?: SearchStrategy;
|
|
25
|
+
/** Maximum search depth (levels of traversal) */
|
|
26
|
+
depth?: number;
|
|
27
|
+
/** App/project context to filter by */
|
|
28
|
+
appId?: string;
|
|
29
|
+
/** Maximum results to return */
|
|
30
|
+
limit?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Search result with relevance score
|
|
34
|
+
*/
|
|
35
|
+
export interface SearchResult {
|
|
36
|
+
/** Type of memory found */
|
|
37
|
+
type: 'preference' | 'session' | 'project' | 'interrupt' | 'checkpoint' | 'pattern';
|
|
38
|
+
/** The actual data */
|
|
39
|
+
data: unknown;
|
|
40
|
+
/** Relevance score (0-1) */
|
|
41
|
+
relevance: number;
|
|
42
|
+
/** Why this result matched */
|
|
43
|
+
reasoning: string;
|
|
44
|
+
/** Source collection */
|
|
45
|
+
source: string;
|
|
46
|
+
/** Timestamp for temporal sorting */
|
|
47
|
+
timestamp?: Date;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Search result with aggregated insights
|
|
51
|
+
*/
|
|
52
|
+
export interface AgenticSearchResponse {
|
|
53
|
+
/** Individual search results */
|
|
54
|
+
results: SearchResult[];
|
|
55
|
+
/** Aggregated insights from results */
|
|
56
|
+
insights: {
|
|
57
|
+
/** Summary of what was found */
|
|
58
|
+
summary: string;
|
|
59
|
+
/** Common patterns identified */
|
|
60
|
+
patterns: string[];
|
|
61
|
+
/** Temporal trends */
|
|
62
|
+
trends: string[];
|
|
63
|
+
/** Suggested next actions */
|
|
64
|
+
suggestions: string[];
|
|
65
|
+
};
|
|
66
|
+
/** Search metadata */
|
|
67
|
+
metadata: {
|
|
68
|
+
strategy: SearchStrategy;
|
|
69
|
+
depth: number;
|
|
70
|
+
duration: number;
|
|
71
|
+
totalResults: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export declare class AgenticSearchEngine {
|
|
75
|
+
private memoryManager;
|
|
76
|
+
constructor(memoryManager: MemoryManager);
|
|
77
|
+
/**
|
|
78
|
+
* Perform agentic search through memory
|
|
79
|
+
*/
|
|
80
|
+
search(params: AgenticSearchParams): Promise<AgenticSearchResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Temporal search - "What did I do last week?"
|
|
83
|
+
* Navigates memory by time relationships
|
|
84
|
+
*/
|
|
85
|
+
private temporalSearch;
|
|
86
|
+
/**
|
|
87
|
+
* Semantic search - "How did I handle user roles?"
|
|
88
|
+
* Reasoning-based understanding of structure
|
|
89
|
+
*/
|
|
90
|
+
private semanticSearch;
|
|
91
|
+
/**
|
|
92
|
+
* Pattern search - "Show me all list views I've built"
|
|
93
|
+
* Searches for specific patterns and effects
|
|
94
|
+
*/
|
|
95
|
+
private patternSearch;
|
|
96
|
+
/**
|
|
97
|
+
* Hybrid search - combines all strategies
|
|
98
|
+
*/
|
|
99
|
+
private hybridSearch;
|
|
100
|
+
/**
|
|
101
|
+
* Extract semantic concepts from query
|
|
102
|
+
*/
|
|
103
|
+
private extractConcepts;
|
|
104
|
+
/**
|
|
105
|
+
* Extract potential entity names from query
|
|
106
|
+
*/
|
|
107
|
+
private extractEntityNames;
|
|
108
|
+
/**
|
|
109
|
+
* Generate insights from search results
|
|
110
|
+
*/
|
|
111
|
+
private generateInsights;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create an agentic search engine
|
|
115
|
+
*/
|
|
116
|
+
export declare function createAgenticSearchEngine(memoryManager: MemoryManager): AgenticSearchEngine;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory System - GAP-001: Orbital Memory System
|
|
3
|
+
*
|
|
4
|
+
* Revolutionary memory storage using `.orb` files instead of RAG/vector DB.
|
|
5
|
+
* Memory is structured as orbital schemas with temporal state machines.
|
|
6
|
+
*/
|
|
7
|
+
export { MemoryOrbitalSchema, UserPreferenceEntity, GenerationSessionEntity, ProjectContextEntity, type UserPreference, type GenerationSession, type ProjectContext, } from './memory-orbital.js';
|
|
8
|
+
export { MemoryManager, type MemoryManagerOptions, } from './MemoryManager.js';
|
|
9
|
+
export { PreferenceLearner, createPreferenceLearner, type PreferenceLearnerOptions, type InferredPreference, type PreferenceAnalysis, } from './PreferenceLearner.js';
|
|
10
|
+
export { AgenticSearchEngine, createAgenticSearchEngine, type SearchStrategy, type AgenticSearchParams, type SearchResult, type AgenticSearchResponse, } from './agentic-search.js';
|
|
11
|
+
export { ObservabilityCollector, getObservabilityCollector, resetObservabilityCollector, recordEvent, startObservabilitySession, endObservabilitySession, getPerformanceSnapshot, type ObservableEventType, type ObservableEvent, type SessionTelemetry, type PerformanceSnapshot, type HealthCheckResult, } from '../observability.js';
|
|
12
|
+
export { MultiUserManager, getMultiUserManager, resetMultiUserManager, createUserContext, isAdmin, requireOwnership, type UserContext, type ScopedSessionMetadata, type AccessCheckResult, type UserSessionStats, } from '../multi-user.js';
|
|
13
|
+
export { StateSyncManager, getStateSyncManager, resetStateSyncManager, withSync, debounceSync, type StateChangeType, type StateChangeEvent, type VersionVector, type StateSyncSnapshot, type ConflictResolution, type StateSyncConfig, } from '../state-sync.js';
|
|
14
|
+
export type { UserFeedback, PatternAffinity, InterruptRecord, ToolApprovalPreference, CheckpointRecord, } from './types.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Orbital Schema
|
|
3
|
+
*
|
|
4
|
+
* Defines the structure for agent memory using Orbital types.
|
|
5
|
+
* This is an OrbitalSchema that represents user memory, preferences,
|
|
6
|
+
* and generation history.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import type { OrbitalSchema, Entity } from '@almadar/core';
|
|
11
|
+
/**
|
|
12
|
+
* User preference entity - stores learned or explicit preferences
|
|
13
|
+
*/
|
|
14
|
+
export declare const UserPreferenceEntity: Entity;
|
|
15
|
+
/**
|
|
16
|
+
* Generation session entity - stores history of generations
|
|
17
|
+
*/
|
|
18
|
+
export declare const GenerationSessionEntity: Entity;
|
|
19
|
+
/**
|
|
20
|
+
* Project context entity - stores project-specific conventions
|
|
21
|
+
*/
|
|
22
|
+
export declare const ProjectContextEntity: Entity;
|
|
23
|
+
/**
|
|
24
|
+
* The complete Memory Orbital Schema
|
|
25
|
+
* This defines the structure for storing agent memory
|
|
26
|
+
*/
|
|
27
|
+
export declare const MemoryOrbitalSchema: OrbitalSchema;
|
|
28
|
+
export type UserPreference = {
|
|
29
|
+
id: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
namingConvention: 'PascalCase' | 'camelCase' | 'snake_case';
|
|
32
|
+
validationStyle: 'strict' | 'minimal' | 'none';
|
|
33
|
+
preferredPatterns: string[];
|
|
34
|
+
commonEntities: string[];
|
|
35
|
+
commonTraits: string[];
|
|
36
|
+
learnedAt: Date;
|
|
37
|
+
confidence: number;
|
|
38
|
+
};
|
|
39
|
+
export type GenerationSession = {
|
|
40
|
+
id: string;
|
|
41
|
+
userId: string;
|
|
42
|
+
threadId: string;
|
|
43
|
+
prompt: string;
|
|
44
|
+
skill: string;
|
|
45
|
+
generatedSchema?: Record<string, unknown>;
|
|
46
|
+
entities: string[];
|
|
47
|
+
patterns: string[];
|
|
48
|
+
validationResult?: {
|
|
49
|
+
valid: boolean;
|
|
50
|
+
errors: unknown[];
|
|
51
|
+
};
|
|
52
|
+
createdAt: Date;
|
|
53
|
+
completedAt?: Date;
|
|
54
|
+
success: boolean;
|
|
55
|
+
};
|
|
56
|
+
export type ProjectContext = {
|
|
57
|
+
id: string;
|
|
58
|
+
appId: string;
|
|
59
|
+
userId: string;
|
|
60
|
+
projectName?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
existingEntities: string[];
|
|
63
|
+
conventions: string[];
|
|
64
|
+
domain: 'business' | 'ecommerce' | 'cms' | 'dashboard' | 'workflow';
|
|
65
|
+
lastUpdatedAt: Date;
|
|
66
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory System Types
|
|
3
|
+
*
|
|
4
|
+
* Additional types for the memory system beyond the core orbital types.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* User feedback on a generation session
|
|
8
|
+
*/
|
|
9
|
+
export interface UserFeedback {
|
|
10
|
+
/** Unique feedback ID */
|
|
11
|
+
feedbackId: string;
|
|
12
|
+
/** Session this feedback is for */
|
|
13
|
+
sessionId: string;
|
|
14
|
+
/** User who gave the feedback */
|
|
15
|
+
userId: string;
|
|
16
|
+
/** Type of feedback */
|
|
17
|
+
type: 'positive' | 'negative' | 'correction' | 'suggestion';
|
|
18
|
+
/** Optional comment */
|
|
19
|
+
comment?: string;
|
|
20
|
+
/** Suggested correction or improvement */
|
|
21
|
+
suggestion?: string;
|
|
22
|
+
/** Timestamp of feedback */
|
|
23
|
+
timestamp: Date;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Pattern affinity - tracks how well patterns work for a user
|
|
27
|
+
*/
|
|
28
|
+
export interface PatternAffinity {
|
|
29
|
+
/** User ID */
|
|
30
|
+
userId: string;
|
|
31
|
+
/** Pattern ID */
|
|
32
|
+
patternId: string;
|
|
33
|
+
/** How many times used */
|
|
34
|
+
usageCount: number;
|
|
35
|
+
/** Successful uses */
|
|
36
|
+
successCount: number;
|
|
37
|
+
/** Failed uses */
|
|
38
|
+
failureCount: number;
|
|
39
|
+
/** Contexts where this pattern was used */
|
|
40
|
+
contexts?: {
|
|
41
|
+
entityType?: string;
|
|
42
|
+
useCase?: string;
|
|
43
|
+
}[];
|
|
44
|
+
/** Last time this pattern was used */
|
|
45
|
+
lastUsedAt: Date;
|
|
46
|
+
/** When tracking started */
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generation record - summary of a generation for history
|
|
51
|
+
*/
|
|
52
|
+
export interface GenerationRecord {
|
|
53
|
+
/** Unique session ID */
|
|
54
|
+
sessionId: string;
|
|
55
|
+
/** User who initiated */
|
|
56
|
+
userId: string;
|
|
57
|
+
/** App/project context */
|
|
58
|
+
appId: string;
|
|
59
|
+
/** Input description/prompt */
|
|
60
|
+
inputDescription: string;
|
|
61
|
+
/** Resulting orbital name */
|
|
62
|
+
generatedOrbital: string;
|
|
63
|
+
/** Patterns that were used */
|
|
64
|
+
patternsUsed: string[];
|
|
65
|
+
/** Generation status */
|
|
66
|
+
status: 'pending' | 'completed' | 'error' | 'revised';
|
|
67
|
+
/** When generation started */
|
|
68
|
+
startedAt: Date;
|
|
69
|
+
/** When generation completed */
|
|
70
|
+
completedAt?: Date;
|
|
71
|
+
/** Number of revisions */
|
|
72
|
+
revisionCount: number;
|
|
73
|
+
/** Error message if failed */
|
|
74
|
+
errorMessage?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checkpoint record - tracks checkpoint history for learning
|
|
78
|
+
*/
|
|
79
|
+
export interface CheckpointRecord {
|
|
80
|
+
/** Unique checkpoint ID */
|
|
81
|
+
checkpointId: string;
|
|
82
|
+
/** Thread/session ID */
|
|
83
|
+
threadId: string;
|
|
84
|
+
/** User who owns this checkpoint */
|
|
85
|
+
userId: string;
|
|
86
|
+
/** Parent checkpoint ID (for rollback tracking) */
|
|
87
|
+
parentCheckpointId?: string;
|
|
88
|
+
/** Checkpoint metadata */
|
|
89
|
+
metadata: {
|
|
90
|
+
step?: number;
|
|
91
|
+
skill?: string;
|
|
92
|
+
status?: string;
|
|
93
|
+
[key: string]: unknown;
|
|
94
|
+
};
|
|
95
|
+
/** When checkpoint was created */
|
|
96
|
+
createdAt: Date;
|
|
97
|
+
/** Number of times rolled back to this checkpoint */
|
|
98
|
+
rollbackCount: number;
|
|
99
|
+
/** Whether this checkpoint was a successful outcome */
|
|
100
|
+
wasSuccessful: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Interrupt record - tracks human-in-the-loop decisions
|
|
104
|
+
*/
|
|
105
|
+
export interface InterruptRecord {
|
|
106
|
+
/** Unique interrupt ID */
|
|
107
|
+
interruptId: string;
|
|
108
|
+
/** Session this interrupt occurred in */
|
|
109
|
+
sessionId: string;
|
|
110
|
+
/** User who made the decision */
|
|
111
|
+
userId: string;
|
|
112
|
+
/** Tool that was interrupted */
|
|
113
|
+
toolName: string;
|
|
114
|
+
/** Tool arguments that were being executed */
|
|
115
|
+
toolArgs: Record<string, unknown>;
|
|
116
|
+
/** User's decision: approved, rejected, or modified */
|
|
117
|
+
decision: 'approved' | 'rejected' | 'modified';
|
|
118
|
+
/** Modified arguments if decision was 'modified' */
|
|
119
|
+
modifiedArgs?: Record<string, unknown>;
|
|
120
|
+
/** Reason for the decision */
|
|
121
|
+
reason?: string;
|
|
122
|
+
/** Timestamp of the interrupt */
|
|
123
|
+
timestamp: Date;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Tool approval preferences - learned from interrupt history
|
|
127
|
+
*/
|
|
128
|
+
export interface ToolApprovalPreference {
|
|
129
|
+
/** User ID */
|
|
130
|
+
userId: string;
|
|
131
|
+
/** Tool name */
|
|
132
|
+
toolName: string;
|
|
133
|
+
/** Auto-approve this tool in the future */
|
|
134
|
+
autoApprove: boolean;
|
|
135
|
+
/** Confidence in this preference (0-1) */
|
|
136
|
+
confidence: number;
|
|
137
|
+
/** Number of times this tool has been approved */
|
|
138
|
+
approvedCount: number;
|
|
139
|
+
/** Number of times this tool has been rejected */
|
|
140
|
+
rejectedCount: number;
|
|
141
|
+
/** Last decision timestamp */
|
|
142
|
+
lastDecisionAt: Date;
|
|
143
|
+
}
|