@almadar/agent 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +7 -245
- package/dist/agent/index.js +325 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/{firestore-checkpointer-DxbQ10ve.d.ts → firestore-checkpointer-CkNKXoun.d.ts} +1 -1
- package/dist/index-D-Ahuo6F.d.ts +854 -0
- package/dist/index.d.ts +708 -56
- package/dist/index.js +2070 -4
- package/dist/index.js.map +1 -1
- package/dist/persistence/index.d.ts +2 -2
- package/package.json +17 -16
- package/LICENSE +0 -72
package/dist/index.d.ts
CHANGED
|
@@ -6,16 +6,20 @@ import { DomainContext, OrbitalSchema, Orbital, OrbitalDefinition, FullOrbitalUn
|
|
|
6
6
|
export { DomainDocument, DomainToSchemaResult, ParseError, SchemaToDomainResult, SectionMapping, applySectionUpdate, convertDomainToSchema, convertSchemaToDomain, deleteSection } from '@almadar/core/domain-language';
|
|
7
7
|
import { LLMClient } from '@almadar/llm';
|
|
8
8
|
export { createCompactSystemPrompt, createSystemPrompt } from './prompts/index.js';
|
|
9
|
-
import {
|
|
10
|
-
export { EVENT_BUDGETS, SessionManager, SessionManagerOptions, Skill, SkillAgentOptions, SkillAgentResult, SkillLoader, SkillMeta, SkillRefLoader, createSkillAgent, getBudgetWarningMessage, getEventBudget, getInterruptConfig, resumeSkillAgent } from './
|
|
11
|
-
|
|
9
|
+
import { U as UserPreference, M as MemoryManager, G as GenerationSession } from './index-D-Ahuo6F.js';
|
|
10
|
+
export { C as CheckpointRecord, a as ContextCompactionConfig, D as DEFAULT_COMPACTION_CONFIG, E as EVENT_BUDGETS, I as InterruptRecord, b as MemoryManagerOptions, c as MemoryOrbitalSchema, P as PatternAffinity, d as ProjectContext, S as SessionManager, e as SessionManagerOptions, f as Skill, g as SkillAgentOptions, h as SkillAgentResult, i as SkillLoader, j as SkillMeta, k as SkillRefLoader, T as ToolApprovalPreference, l as UserFeedback, m as createSkillAgent, n as createSummaryPrompt, o as estimateTokens, p as getBudgetWarningMessage, q as getEventBudget, r as getInterruptConfig, s as needsCompaction, t as resumeSkillAgent } from './index-D-Ahuo6F.js';
|
|
11
|
+
import { S as SessionMetadata } from './firestore-checkpointer-CkNKXoun.js';
|
|
12
|
+
export { F as FirestoreCheckpointer, a as FirestoreCheckpointerOptions, b as FirestoreDb, c as FirestoreTimestamp, P as PersistenceMode, d as Session, e as SessionRecord } from './firestore-checkpointer-CkNKXoun.js';
|
|
12
13
|
export { FirestoreSessionStore, FirestoreSessionStoreOptions, FirestoreStore, FirestoreStoreOptions, MemorySessionBackend } from './persistence/index.js';
|
|
13
14
|
export { RawAgentEvent, extractFileOperation, extractInterruptData, hasInterrupt, isFileOperation, isTodoUpdate, transformAgentEvent, transformAgentEventMulti } from './event-transformer/index.js';
|
|
15
|
+
import { EventEmitter } from 'events';
|
|
16
|
+
import { Checkpoint } from '@langchain/langgraph-checkpoint';
|
|
14
17
|
export { Command } from '@langchain/langgraph';
|
|
15
18
|
export { D as DomainOrbitalCompleteCallback, a as DomainOrbitalEventCallback, b as DomainOrbitalSpec, c as DomainOrbitalToolOptions, O as OrbitalCompleteCallback, d as OrbitalRequirements, e as OrbitalSubagentToolOptions, S as SubagentEventCallback, f as createConstructCombinedDomainTool, g as createDomainOrbitalTools, h as createGenerateOrbitalDomainTool, i as createOrbitalSubagentTool, j as createSubagentEventWrapper } from './orbital-subagent-cNfTLdXQ.js';
|
|
16
19
|
import 'zod';
|
|
17
20
|
import '@langchain/core/tools';
|
|
18
|
-
import '@
|
|
21
|
+
import '@almadar/core';
|
|
22
|
+
import '@langchain/core/messages';
|
|
19
23
|
import '@langchain/core/runnables';
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -365,57 +369,6 @@ declare function isCompleteEvent(event: DeepAgentEvent): event is DeepAgentCompl
|
|
|
365
369
|
*/
|
|
366
370
|
declare function isErrorEvent(event: DeepAgentEvent): event is DeepAgentErrorEvent;
|
|
367
371
|
|
|
368
|
-
/**
|
|
369
|
-
* Context Compaction for DeepAgent
|
|
370
|
-
*
|
|
371
|
-
* Provides middleware to manage context length in long-running agent sessions.
|
|
372
|
-
* Uses @langchain/core's trimMessages to keep context within token limits.
|
|
373
|
-
*
|
|
374
|
-
* @packageDocumentation
|
|
375
|
-
*/
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Configuration for context compaction.
|
|
379
|
-
*/
|
|
380
|
-
interface ContextCompactionConfig {
|
|
381
|
-
/**
|
|
382
|
-
* Maximum number of tokens before triggering compaction.
|
|
383
|
-
* Default: 150000 (leaves headroom for Claude's 200K context)
|
|
384
|
-
*/
|
|
385
|
-
maxTokens?: number;
|
|
386
|
-
/**
|
|
387
|
-
* Number of recent messages to always keep.
|
|
388
|
-
* Default: 10
|
|
389
|
-
*/
|
|
390
|
-
keepRecentMessages?: number;
|
|
391
|
-
/**
|
|
392
|
-
* Whether to include the system message in trimming.
|
|
393
|
-
* Default: false (system message is always kept)
|
|
394
|
-
*/
|
|
395
|
-
includeSystem?: boolean;
|
|
396
|
-
/**
|
|
397
|
-
* Strategy for trimming: 'first' keeps first messages, 'last' keeps last messages.
|
|
398
|
-
* Default: 'last'
|
|
399
|
-
*/
|
|
400
|
-
strategy?: 'first' | 'last';
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Default configuration for context compaction.
|
|
404
|
-
*/
|
|
405
|
-
declare const DEFAULT_COMPACTION_CONFIG: Required<ContextCompactionConfig>;
|
|
406
|
-
/**
|
|
407
|
-
* Check if messages need compaction based on estimated token count.
|
|
408
|
-
*/
|
|
409
|
-
declare function needsCompaction(messages: BaseMessage[], threshold?: number): boolean;
|
|
410
|
-
/**
|
|
411
|
-
* Create a message summarizer prompt for compacting old context.
|
|
412
|
-
*/
|
|
413
|
-
declare function createSummaryPrompt(messages: BaseMessage[]): string;
|
|
414
|
-
/**
|
|
415
|
-
* Estimate token count for messages using character-based heuristic.
|
|
416
|
-
*/
|
|
417
|
-
declare function estimateTokens(messages: BaseMessage[]): number;
|
|
418
|
-
|
|
419
372
|
/**
|
|
420
373
|
* Metrics Collection for DeepAgent Evaluation
|
|
421
374
|
*
|
|
@@ -494,4 +447,703 @@ declare function formatSummary(summary: MetricsSummary): string;
|
|
|
494
447
|
*/
|
|
495
448
|
declare function analyzeFailures(failures: GenerationMetrics[]): string[];
|
|
496
449
|
|
|
497
|
-
|
|
450
|
+
/**
|
|
451
|
+
* Preference Learner
|
|
452
|
+
*
|
|
453
|
+
* Uses LLM to infer user preferences from generation sessions.
|
|
454
|
+
* Leverages @almadar/llm for structured output.
|
|
455
|
+
*
|
|
456
|
+
* @packageDocumentation
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
interface PreferenceLearnerOptions {
|
|
460
|
+
/** LLM client for inference */
|
|
461
|
+
llmClient?: LLMClient;
|
|
462
|
+
/** Memory manager for persistence */
|
|
463
|
+
memoryManager: MemoryManager;
|
|
464
|
+
/** Confidence threshold for auto-accepting preferences */
|
|
465
|
+
confidenceThreshold?: number;
|
|
466
|
+
}
|
|
467
|
+
interface InferredPreference {
|
|
468
|
+
/** The preference field being inferred */
|
|
469
|
+
field: keyof Omit<UserPreference, 'id' | 'userId' | 'learnedAt'>;
|
|
470
|
+
/** The inferred value */
|
|
471
|
+
value: unknown;
|
|
472
|
+
/** Confidence level (0-1) */
|
|
473
|
+
confidence: number;
|
|
474
|
+
/** Explanation of why this was inferred */
|
|
475
|
+
reasoning: string;
|
|
476
|
+
}
|
|
477
|
+
interface PreferenceAnalysis {
|
|
478
|
+
/** List of inferred preferences */
|
|
479
|
+
inferences: InferredPreference[];
|
|
480
|
+
/** Whether the inference is high confidence */
|
|
481
|
+
isHighConfidence: boolean;
|
|
482
|
+
}
|
|
483
|
+
declare class PreferenceLearner {
|
|
484
|
+
private llmClient;
|
|
485
|
+
private memoryManager;
|
|
486
|
+
private confidenceThreshold;
|
|
487
|
+
constructor(options: PreferenceLearnerOptions);
|
|
488
|
+
/**
|
|
489
|
+
* Analyze a session and infer user preferences
|
|
490
|
+
*/
|
|
491
|
+
analyzeSession(session: GenerationSession): Promise<PreferenceAnalysis>;
|
|
492
|
+
/**
|
|
493
|
+
* Learn from a session and update preferences if confidence is high
|
|
494
|
+
*/
|
|
495
|
+
learnFromSession(session: GenerationSession): Promise<UserPreference | null>;
|
|
496
|
+
/**
|
|
497
|
+
* Batch learn from multiple sessions
|
|
498
|
+
*/
|
|
499
|
+
batchLearn(sessions: GenerationSession[]): Promise<UserPreference | null>;
|
|
500
|
+
private buildAnalysisPrompt;
|
|
501
|
+
private buildAggregatePrompt;
|
|
502
|
+
private parseAnalysisResponse;
|
|
503
|
+
private isValidNamingConvention;
|
|
504
|
+
private isValidValidationStyle;
|
|
505
|
+
}
|
|
506
|
+
declare function createPreferenceLearner(options: PreferenceLearnerOptions): PreferenceLearner;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Agentic Search - GAP-006
|
|
510
|
+
*
|
|
511
|
+
* Reasoning-based search through memory orbitals.
|
|
512
|
+
* Unlike RAG (vector similarity), this uses agent traversal with understanding
|
|
513
|
+
* of state transitions, patterns, and temporal relationships.
|
|
514
|
+
*
|
|
515
|
+
* @packageDocumentation
|
|
516
|
+
*/
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Search strategy for agentic search
|
|
520
|
+
*/
|
|
521
|
+
type SearchStrategy = 'temporal' | 'semantic' | 'pattern' | 'hybrid';
|
|
522
|
+
/**
|
|
523
|
+
* Search parameters
|
|
524
|
+
*/
|
|
525
|
+
interface AgenticSearchParams {
|
|
526
|
+
/** User to search memory for */
|
|
527
|
+
userId: string;
|
|
528
|
+
/** Natural language query */
|
|
529
|
+
query: string;
|
|
530
|
+
/** Search strategy */
|
|
531
|
+
strategy?: SearchStrategy;
|
|
532
|
+
/** Maximum search depth (levels of traversal) */
|
|
533
|
+
depth?: number;
|
|
534
|
+
/** App/project context to filter by */
|
|
535
|
+
appId?: string;
|
|
536
|
+
/** Maximum results to return */
|
|
537
|
+
limit?: number;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Search result with relevance score
|
|
541
|
+
*/
|
|
542
|
+
interface SearchResult {
|
|
543
|
+
/** Type of memory found */
|
|
544
|
+
type: 'preference' | 'session' | 'project' | 'interrupt' | 'checkpoint' | 'pattern';
|
|
545
|
+
/** The actual data */
|
|
546
|
+
data: unknown;
|
|
547
|
+
/** Relevance score (0-1) */
|
|
548
|
+
relevance: number;
|
|
549
|
+
/** Why this result matched */
|
|
550
|
+
reasoning: string;
|
|
551
|
+
/** Source collection */
|
|
552
|
+
source: string;
|
|
553
|
+
/** Timestamp for temporal sorting */
|
|
554
|
+
timestamp?: Date;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Search result with aggregated insights
|
|
558
|
+
*/
|
|
559
|
+
interface AgenticSearchResponse {
|
|
560
|
+
/** Individual search results */
|
|
561
|
+
results: SearchResult[];
|
|
562
|
+
/** Aggregated insights from results */
|
|
563
|
+
insights: {
|
|
564
|
+
/** Summary of what was found */
|
|
565
|
+
summary: string;
|
|
566
|
+
/** Common patterns identified */
|
|
567
|
+
patterns: string[];
|
|
568
|
+
/** Temporal trends */
|
|
569
|
+
trends: string[];
|
|
570
|
+
/** Suggested next actions */
|
|
571
|
+
suggestions: string[];
|
|
572
|
+
};
|
|
573
|
+
/** Search metadata */
|
|
574
|
+
metadata: {
|
|
575
|
+
strategy: SearchStrategy;
|
|
576
|
+
depth: number;
|
|
577
|
+
duration: number;
|
|
578
|
+
totalResults: number;
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
declare class AgenticSearchEngine {
|
|
582
|
+
private memoryManager;
|
|
583
|
+
constructor(memoryManager: MemoryManager);
|
|
584
|
+
/**
|
|
585
|
+
* Perform agentic search through memory
|
|
586
|
+
*/
|
|
587
|
+
search(params: AgenticSearchParams): Promise<AgenticSearchResponse>;
|
|
588
|
+
/**
|
|
589
|
+
* Temporal search - "What did I do last week?"
|
|
590
|
+
* Navigates memory by time relationships
|
|
591
|
+
*/
|
|
592
|
+
private temporalSearch;
|
|
593
|
+
/**
|
|
594
|
+
* Semantic search - "How did I handle user roles?"
|
|
595
|
+
* Reasoning-based understanding of structure
|
|
596
|
+
*/
|
|
597
|
+
private semanticSearch;
|
|
598
|
+
/**
|
|
599
|
+
* Pattern search - "Show me all list views I've built"
|
|
600
|
+
* Searches for specific patterns and effects
|
|
601
|
+
*/
|
|
602
|
+
private patternSearch;
|
|
603
|
+
/**
|
|
604
|
+
* Hybrid search - combines all strategies
|
|
605
|
+
*/
|
|
606
|
+
private hybridSearch;
|
|
607
|
+
/**
|
|
608
|
+
* Extract semantic concepts from query
|
|
609
|
+
*/
|
|
610
|
+
private extractConcepts;
|
|
611
|
+
/**
|
|
612
|
+
* Extract potential entity names from query
|
|
613
|
+
*/
|
|
614
|
+
private extractEntityNames;
|
|
615
|
+
/**
|
|
616
|
+
* Generate insights from search results
|
|
617
|
+
*/
|
|
618
|
+
private generateInsights;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Create an agentic search engine
|
|
622
|
+
*/
|
|
623
|
+
declare function createAgenticSearchEngine(memoryManager: MemoryManager): AgenticSearchEngine;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Observability - GAP-008
|
|
627
|
+
*
|
|
628
|
+
* Comprehensive observability layer for DeepAgent including:
|
|
629
|
+
* - Event tracking
|
|
630
|
+
* - Session metrics
|
|
631
|
+
* - Performance monitoring
|
|
632
|
+
* - Health checks
|
|
633
|
+
*
|
|
634
|
+
* @packageDocumentation
|
|
635
|
+
*/
|
|
636
|
+
/**
|
|
637
|
+
* Observable event types
|
|
638
|
+
*/
|
|
639
|
+
type ObservableEventType = 'session_start' | 'session_end' | 'tool_call' | 'tool_result' | 'interrupt' | 'checkpoint_save' | 'checkpoint_restore' | 'error' | 'llm_call' | 'memory_sync';
|
|
640
|
+
/**
|
|
641
|
+
* Observable event
|
|
642
|
+
*/
|
|
643
|
+
interface ObservableEvent {
|
|
644
|
+
/** Event type */
|
|
645
|
+
type: ObservableEventType;
|
|
646
|
+
/** Timestamp */
|
|
647
|
+
timestamp: number;
|
|
648
|
+
/** Session/thread ID */
|
|
649
|
+
sessionId: string;
|
|
650
|
+
/** User ID */
|
|
651
|
+
userId?: string;
|
|
652
|
+
/** Event payload */
|
|
653
|
+
payload: Record<string, unknown>;
|
|
654
|
+
/** Duration in ms (if applicable) */
|
|
655
|
+
duration?: number;
|
|
656
|
+
/** Error information */
|
|
657
|
+
error?: {
|
|
658
|
+
message: string;
|
|
659
|
+
code?: string;
|
|
660
|
+
stack?: string;
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Session telemetry
|
|
665
|
+
*/
|
|
666
|
+
interface SessionTelemetry {
|
|
667
|
+
/** Session ID */
|
|
668
|
+
sessionId: string;
|
|
669
|
+
/** User ID */
|
|
670
|
+
userId?: string;
|
|
671
|
+
/** Session start time */
|
|
672
|
+
startedAt: number;
|
|
673
|
+
/** Session end time */
|
|
674
|
+
endedAt?: number;
|
|
675
|
+
/** Number of tool calls */
|
|
676
|
+
toolCallCount: number;
|
|
677
|
+
/** Number of LLM calls */
|
|
678
|
+
llmCallCount: number;
|
|
679
|
+
/** Number of interrupts */
|
|
680
|
+
interruptCount: number;
|
|
681
|
+
/** Number of checkpoints */
|
|
682
|
+
checkpointCount: number;
|
|
683
|
+
/** Total tokens used */
|
|
684
|
+
totalTokens: number;
|
|
685
|
+
/** Errors encountered */
|
|
686
|
+
errors: Array<{
|
|
687
|
+
timestamp: number;
|
|
688
|
+
message: string;
|
|
689
|
+
type: string;
|
|
690
|
+
}>;
|
|
691
|
+
/** Final status */
|
|
692
|
+
status: 'running' | 'completed' | 'failed' | 'interrupted';
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Performance snapshot
|
|
696
|
+
*/
|
|
697
|
+
interface PerformanceSnapshot {
|
|
698
|
+
/** Timestamp */
|
|
699
|
+
timestamp: number;
|
|
700
|
+
/** Active sessions */
|
|
701
|
+
activeSessions: number;
|
|
702
|
+
/** Total sessions (all time) */
|
|
703
|
+
totalSessions: number;
|
|
704
|
+
/** Average session duration */
|
|
705
|
+
avgSessionDuration: number;
|
|
706
|
+
/** Success rate (last 24h) */
|
|
707
|
+
successRate24h: number;
|
|
708
|
+
/** Error rate (last 24h) */
|
|
709
|
+
errorRate24h: number;
|
|
710
|
+
/** Average tokens per session */
|
|
711
|
+
avgTokensPerSession: number;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Health check result
|
|
715
|
+
*/
|
|
716
|
+
interface HealthCheckResult {
|
|
717
|
+
/** Component name */
|
|
718
|
+
component: string;
|
|
719
|
+
/** Health status */
|
|
720
|
+
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
721
|
+
/** Response time in ms */
|
|
722
|
+
responseTime: number;
|
|
723
|
+
/** Last checked timestamp */
|
|
724
|
+
checkedAt: number;
|
|
725
|
+
/** Error message if unhealthy */
|
|
726
|
+
error?: string;
|
|
727
|
+
}
|
|
728
|
+
declare class ObservabilityCollector {
|
|
729
|
+
private events;
|
|
730
|
+
private sessions;
|
|
731
|
+
private maxEvents;
|
|
732
|
+
constructor(options?: {
|
|
733
|
+
maxEvents?: number;
|
|
734
|
+
});
|
|
735
|
+
/**
|
|
736
|
+
* Record an observable event
|
|
737
|
+
*/
|
|
738
|
+
recordEvent(event: Omit<ObservableEvent, 'timestamp'>): void;
|
|
739
|
+
/**
|
|
740
|
+
* Start session tracking
|
|
741
|
+
*/
|
|
742
|
+
startSession(sessionId: string, userId?: string): void;
|
|
743
|
+
/**
|
|
744
|
+
* End session tracking
|
|
745
|
+
*/
|
|
746
|
+
endSession(sessionId: string, status?: SessionTelemetry['status']): void;
|
|
747
|
+
/**
|
|
748
|
+
* Record tool call
|
|
749
|
+
*/
|
|
750
|
+
recordToolCall(sessionId: string, toolName: string, args: Record<string, unknown>, duration?: number): void;
|
|
751
|
+
/**
|
|
752
|
+
* Record LLM call
|
|
753
|
+
*/
|
|
754
|
+
recordLLMCall(sessionId: string, model: string, tokens: {
|
|
755
|
+
input: number;
|
|
756
|
+
output: number;
|
|
757
|
+
}, duration?: number): void;
|
|
758
|
+
/**
|
|
759
|
+
* Record error
|
|
760
|
+
*/
|
|
761
|
+
recordError(sessionId: string, error: Error, context?: Record<string, unknown>): void;
|
|
762
|
+
/**
|
|
763
|
+
* Get events by type
|
|
764
|
+
*/
|
|
765
|
+
getEvents(type?: ObservableEventType, sessionId?: string): ObservableEvent[];
|
|
766
|
+
/**
|
|
767
|
+
* Get session telemetry
|
|
768
|
+
*/
|
|
769
|
+
getSessionTelemetry(sessionId: string): SessionTelemetry | undefined;
|
|
770
|
+
/**
|
|
771
|
+
* Get all active sessions
|
|
772
|
+
*/
|
|
773
|
+
getActiveSessions(): SessionTelemetry[];
|
|
774
|
+
/**
|
|
775
|
+
* Get performance snapshot
|
|
776
|
+
*/
|
|
777
|
+
getPerformanceSnapshot(): PerformanceSnapshot;
|
|
778
|
+
/**
|
|
779
|
+
* Perform health check
|
|
780
|
+
*/
|
|
781
|
+
healthCheck(): Promise<HealthCheckResult[]>;
|
|
782
|
+
/**
|
|
783
|
+
* Export metrics for external systems
|
|
784
|
+
*/
|
|
785
|
+
exportMetrics(): {
|
|
786
|
+
events: ObservableEvent[];
|
|
787
|
+
sessions: SessionTelemetry[];
|
|
788
|
+
snapshot: PerformanceSnapshot;
|
|
789
|
+
health: HealthCheckResult[];
|
|
790
|
+
};
|
|
791
|
+
/**
|
|
792
|
+
* Clear all data
|
|
793
|
+
*/
|
|
794
|
+
clear(): void;
|
|
795
|
+
private updateSessionTelemetry;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Get or create global observability collector
|
|
799
|
+
*/
|
|
800
|
+
declare function getObservabilityCollector(): ObservabilityCollector;
|
|
801
|
+
/**
|
|
802
|
+
* Reset global observability collector
|
|
803
|
+
*/
|
|
804
|
+
declare function resetObservabilityCollector(): void;
|
|
805
|
+
/**
|
|
806
|
+
* Record event to global collector
|
|
807
|
+
*/
|
|
808
|
+
declare function recordEvent(event: Omit<ObservableEvent, 'timestamp'>): void;
|
|
809
|
+
/**
|
|
810
|
+
* Start session in global collector
|
|
811
|
+
*/
|
|
812
|
+
declare function startObservabilitySession(sessionId: string, userId?: string): void;
|
|
813
|
+
/**
|
|
814
|
+
* End session in global collector
|
|
815
|
+
*/
|
|
816
|
+
declare function endObservabilitySession(sessionId: string, status?: SessionTelemetry['status']): void;
|
|
817
|
+
/**
|
|
818
|
+
* Get performance snapshot from global collector
|
|
819
|
+
*/
|
|
820
|
+
declare function getPerformanceSnapshot(): PerformanceSnapshot;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Multi-User Support - GAP-009
|
|
824
|
+
*
|
|
825
|
+
* Provides proper user isolation and session scoping for multi-user environments.
|
|
826
|
+
* Ensures users can only access their own sessions, memory, and data.
|
|
827
|
+
*
|
|
828
|
+
* @packageDocumentation
|
|
829
|
+
*/
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* User context for multi-user operations
|
|
833
|
+
*/
|
|
834
|
+
interface UserContext {
|
|
835
|
+
/** User ID */
|
|
836
|
+
userId: string;
|
|
837
|
+
/** Organization/tenant ID (for multi-tenant) */
|
|
838
|
+
orgId?: string;
|
|
839
|
+
/** User roles/permissions */
|
|
840
|
+
roles?: string[];
|
|
841
|
+
/** Session ID scope (optional) */
|
|
842
|
+
sessionScope?: string[];
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Scoped session metadata with user ownership
|
|
846
|
+
*/
|
|
847
|
+
interface ScopedSessionMetadata extends SessionMetadata {
|
|
848
|
+
/** Owning user ID */
|
|
849
|
+
userId: string;
|
|
850
|
+
/** Organization ID */
|
|
851
|
+
orgId?: string;
|
|
852
|
+
/** Created by (for audit) */
|
|
853
|
+
createdBy: string;
|
|
854
|
+
/** Last accessed by */
|
|
855
|
+
lastAccessedBy?: string;
|
|
856
|
+
/** Access control list */
|
|
857
|
+
acl?: {
|
|
858
|
+
/** Users who can read this session */
|
|
859
|
+
readers?: string[];
|
|
860
|
+
/** Users who can write/modify */
|
|
861
|
+
writers?: string[];
|
|
862
|
+
/** Publicly accessible */
|
|
863
|
+
isPublic?: boolean;
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Access check result
|
|
868
|
+
*/
|
|
869
|
+
interface AccessCheckResult {
|
|
870
|
+
/** Whether access is granted */
|
|
871
|
+
allowed: boolean;
|
|
872
|
+
/** Reason if denied */
|
|
873
|
+
reason?: string;
|
|
874
|
+
/** Required permission level */
|
|
875
|
+
requiredRole?: string;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* User session stats
|
|
879
|
+
*/
|
|
880
|
+
interface UserSessionStats {
|
|
881
|
+
/** User ID */
|
|
882
|
+
userId: string;
|
|
883
|
+
/** Total sessions */
|
|
884
|
+
totalSessions: number;
|
|
885
|
+
/** Active sessions */
|
|
886
|
+
activeSessions: number;
|
|
887
|
+
/** Completed sessions */
|
|
888
|
+
completedSessions: number;
|
|
889
|
+
/** Sessions by skill */
|
|
890
|
+
sessionsBySkill: Record<string, number>;
|
|
891
|
+
/** Last activity timestamp */
|
|
892
|
+
lastActivityAt?: number;
|
|
893
|
+
}
|
|
894
|
+
declare class MultiUserManager {
|
|
895
|
+
private sessionOwnership;
|
|
896
|
+
private userSessions;
|
|
897
|
+
/**
|
|
898
|
+
* Check if a user owns a session
|
|
899
|
+
*/
|
|
900
|
+
isSessionOwner(threadId: string, userId: string): boolean;
|
|
901
|
+
/**
|
|
902
|
+
* Check if a user can access a session
|
|
903
|
+
*/
|
|
904
|
+
canAccessSession(threadId: string, userContext: UserContext): AccessCheckResult;
|
|
905
|
+
/**
|
|
906
|
+
* Assign session ownership
|
|
907
|
+
*/
|
|
908
|
+
assignSessionOwnership(threadId: string, userId: string): void;
|
|
909
|
+
/**
|
|
910
|
+
* Get all sessions for a user
|
|
911
|
+
*/
|
|
912
|
+
getUserSessions(userId: string): string[];
|
|
913
|
+
/**
|
|
914
|
+
* Get session owner
|
|
915
|
+
*/
|
|
916
|
+
getSessionOwner(threadId: string): string | undefined;
|
|
917
|
+
/**
|
|
918
|
+
* Remove session ownership
|
|
919
|
+
*/
|
|
920
|
+
removeSession(threadId: string): void;
|
|
921
|
+
/**
|
|
922
|
+
* Check if user has any sessions
|
|
923
|
+
*/
|
|
924
|
+
hasSessions(userId: string): boolean;
|
|
925
|
+
/**
|
|
926
|
+
* Get user session count
|
|
927
|
+
*/
|
|
928
|
+
getSessionCount(userId: string): number;
|
|
929
|
+
/**
|
|
930
|
+
* Transfer session ownership
|
|
931
|
+
*/
|
|
932
|
+
transferOwnership(threadId: string, fromUserId: string, toUserId: string): AccessCheckResult;
|
|
933
|
+
/**
|
|
934
|
+
* Share session with another user
|
|
935
|
+
*/
|
|
936
|
+
shareSession(threadId: string, ownerId: string, targetUserId: string, permission?: 'read' | 'write'): AccessCheckResult;
|
|
937
|
+
/**
|
|
938
|
+
* Get all user IDs with sessions
|
|
939
|
+
*/
|
|
940
|
+
getAllUsers(): string[];
|
|
941
|
+
/**
|
|
942
|
+
* Clear all data (for testing)
|
|
943
|
+
*/
|
|
944
|
+
clear(): void;
|
|
945
|
+
/**
|
|
946
|
+
* Create scoped session metadata
|
|
947
|
+
*/
|
|
948
|
+
createScopedMetadata(metadata: SessionMetadata, userContext: UserContext): ScopedSessionMetadata;
|
|
949
|
+
/**
|
|
950
|
+
* Validate user context
|
|
951
|
+
*/
|
|
952
|
+
validateUserContext(userContext: unknown): userContext is UserContext;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Get or create global multi-user manager
|
|
956
|
+
*/
|
|
957
|
+
declare function getMultiUserManager(): MultiUserManager;
|
|
958
|
+
/**
|
|
959
|
+
* Reset global multi-user manager
|
|
960
|
+
*/
|
|
961
|
+
declare function resetMultiUserManager(): void;
|
|
962
|
+
/**
|
|
963
|
+
* Create user context from request
|
|
964
|
+
*/
|
|
965
|
+
declare function createUserContext(userId: string, options?: {
|
|
966
|
+
orgId?: string;
|
|
967
|
+
roles?: string[];
|
|
968
|
+
}): UserContext;
|
|
969
|
+
/**
|
|
970
|
+
* Check if user is admin
|
|
971
|
+
*/
|
|
972
|
+
declare function isAdmin(userContext: UserContext): boolean;
|
|
973
|
+
/**
|
|
974
|
+
* Require ownership or throw
|
|
975
|
+
*/
|
|
976
|
+
declare function requireOwnership(threadId: string, userContext: UserContext, manager?: MultiUserManager): void;
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* State Synchronization Support - GAP-010
|
|
980
|
+
*
|
|
981
|
+
* Provides agent-side support for real-time state synchronization.
|
|
982
|
+
* The actual transport (WebSocket/SSE) is handled by @almadar/server.
|
|
983
|
+
*
|
|
984
|
+
* This module provides:
|
|
985
|
+
* - State change notifications
|
|
986
|
+
* - Conflict resolution utilities
|
|
987
|
+
* - State serialization for sync
|
|
988
|
+
* - Event emitters for server integration
|
|
989
|
+
*
|
|
990
|
+
* @packageDocumentation
|
|
991
|
+
*/
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* State change event types
|
|
995
|
+
*/
|
|
996
|
+
type StateChangeType = 'checkpoint_created' | 'checkpoint_updated' | 'session_started' | 'session_ended' | 'tool_executed' | 'memory_updated' | 'interrupt_triggered' | 'interrupt_resolved';
|
|
997
|
+
/**
|
|
998
|
+
* State change event
|
|
999
|
+
*/
|
|
1000
|
+
interface StateChangeEvent {
|
|
1001
|
+
/** Change type */
|
|
1002
|
+
type: StateChangeType;
|
|
1003
|
+
/** Thread/session ID */
|
|
1004
|
+
threadId: string;
|
|
1005
|
+
/** User ID */
|
|
1006
|
+
userId?: string;
|
|
1007
|
+
/** Timestamp */
|
|
1008
|
+
timestamp: number;
|
|
1009
|
+
/** Change payload */
|
|
1010
|
+
payload: Record<string, unknown>;
|
|
1011
|
+
/** Version vector for conflict resolution */
|
|
1012
|
+
version: VersionVector;
|
|
1013
|
+
/** Source client ID */
|
|
1014
|
+
sourceClientId?: string;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Version vector for conflict resolution
|
|
1018
|
+
*/
|
|
1019
|
+
interface VersionVector {
|
|
1020
|
+
/** Logical timestamp */
|
|
1021
|
+
timestamp: number;
|
|
1022
|
+
/** Sequence number */
|
|
1023
|
+
sequence: number;
|
|
1024
|
+
/** Node/client ID */
|
|
1025
|
+
nodeId: string;
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Sync state snapshot
|
|
1029
|
+
*/
|
|
1030
|
+
interface StateSyncSnapshot {
|
|
1031
|
+
/** Thread ID */
|
|
1032
|
+
threadId: string;
|
|
1033
|
+
/** Current checkpoint */
|
|
1034
|
+
checkpoint?: Checkpoint;
|
|
1035
|
+
/** Session metadata */
|
|
1036
|
+
sessionMetadata?: Record<string, unknown>;
|
|
1037
|
+
/** Memory state */
|
|
1038
|
+
memoryState?: Record<string, unknown>;
|
|
1039
|
+
/** Version vector */
|
|
1040
|
+
version: VersionVector;
|
|
1041
|
+
/** Last updated */
|
|
1042
|
+
lastUpdated: number;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Conflict resolution result
|
|
1046
|
+
*/
|
|
1047
|
+
interface ConflictResolution {
|
|
1048
|
+
/** Whether conflict was resolved */
|
|
1049
|
+
resolved: boolean;
|
|
1050
|
+
/** Winning state if resolved */
|
|
1051
|
+
winningState?: StateSyncSnapshot;
|
|
1052
|
+
/** Conflicting changes if not resolved */
|
|
1053
|
+
conflicts?: Array<{
|
|
1054
|
+
clientA: StateChangeEvent;
|
|
1055
|
+
clientB: StateChangeEvent;
|
|
1056
|
+
}>;
|
|
1057
|
+
/** Resolution strategy used */
|
|
1058
|
+
strategy: 'last_write_wins' | 'merge' | 'manual';
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Sync configuration
|
|
1062
|
+
*/
|
|
1063
|
+
interface StateSyncConfig {
|
|
1064
|
+
/** Enable sync */
|
|
1065
|
+
enabled: boolean;
|
|
1066
|
+
/** Conflict resolution strategy */
|
|
1067
|
+
conflictStrategy: 'last_write_wins' | 'merge' | 'manual';
|
|
1068
|
+
/** Throttle interval (ms) */
|
|
1069
|
+
throttleInterval: number;
|
|
1070
|
+
/** Max retry attempts */
|
|
1071
|
+
maxRetries: number;
|
|
1072
|
+
/** Client ID */
|
|
1073
|
+
clientId: string;
|
|
1074
|
+
}
|
|
1075
|
+
declare class StateSyncManager extends EventEmitter {
|
|
1076
|
+
private config;
|
|
1077
|
+
private sequenceNumber;
|
|
1078
|
+
private pendingChanges;
|
|
1079
|
+
private throttleTimer;
|
|
1080
|
+
constructor(config?: Partial<StateSyncConfig>);
|
|
1081
|
+
/**
|
|
1082
|
+
* Notify that state has changed (called by agent internals)
|
|
1083
|
+
*/
|
|
1084
|
+
notifyStateChange(type: StateChangeType, threadId: string, payload: Record<string, unknown>, userId?: string): void;
|
|
1085
|
+
/**
|
|
1086
|
+
* Receive state change from server (called by server transport)
|
|
1087
|
+
*/
|
|
1088
|
+
receiveRemoteChange(event: StateChangeEvent): void;
|
|
1089
|
+
/**
|
|
1090
|
+
* Create sync snapshot for current state
|
|
1091
|
+
*/
|
|
1092
|
+
createSnapshot(threadId: string, state: {
|
|
1093
|
+
checkpoint?: Checkpoint;
|
|
1094
|
+
sessionMetadata?: Record<string, unknown>;
|
|
1095
|
+
memoryState?: Record<string, unknown>;
|
|
1096
|
+
}): StateSyncSnapshot;
|
|
1097
|
+
/**
|
|
1098
|
+
* Compare two version vectors
|
|
1099
|
+
* Returns: -1 if a < b, 0 if concurrent/equal, 1 if a > b
|
|
1100
|
+
*/
|
|
1101
|
+
compareVersions(a: VersionVector, b: VersionVector): number;
|
|
1102
|
+
/**
|
|
1103
|
+
* Check if there are pending changes to sync
|
|
1104
|
+
*/
|
|
1105
|
+
hasPendingChanges(): boolean;
|
|
1106
|
+
/**
|
|
1107
|
+
* Get and clear pending changes
|
|
1108
|
+
*/
|
|
1109
|
+
flushPendingChanges(): StateChangeEvent[];
|
|
1110
|
+
/**
|
|
1111
|
+
* Get sync configuration
|
|
1112
|
+
*/
|
|
1113
|
+
getConfig(): StateSyncConfig;
|
|
1114
|
+
/**
|
|
1115
|
+
* Update sync configuration
|
|
1116
|
+
*/
|
|
1117
|
+
updateConfig(config: Partial<StateSyncConfig>): void;
|
|
1118
|
+
/**
|
|
1119
|
+
* Dispose resources
|
|
1120
|
+
*/
|
|
1121
|
+
dispose(): void;
|
|
1122
|
+
private generateClientId;
|
|
1123
|
+
private createVersionVector;
|
|
1124
|
+
private scheduleSync;
|
|
1125
|
+
private findConflicts;
|
|
1126
|
+
private resolveConflicts;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Get or create global state sync manager
|
|
1130
|
+
*/
|
|
1131
|
+
declare function getStateSyncManager(config?: Partial<StateSyncConfig>): StateSyncManager;
|
|
1132
|
+
/**
|
|
1133
|
+
* Reset global state sync manager
|
|
1134
|
+
*/
|
|
1135
|
+
declare function resetStateSyncManager(): void;
|
|
1136
|
+
/**
|
|
1137
|
+
* Create a synchronized wrapper for session operations
|
|
1138
|
+
*/
|
|
1139
|
+
declare function withSync<T extends (...args: unknown[]) => unknown>(fn: T, syncManager: StateSyncManager, options: {
|
|
1140
|
+
threadId: string;
|
|
1141
|
+
type: StateChangeType;
|
|
1142
|
+
getPayload: (...args: unknown[]) => Record<string, unknown>;
|
|
1143
|
+
}): T;
|
|
1144
|
+
/**
|
|
1145
|
+
* Debounce sync notifications
|
|
1146
|
+
*/
|
|
1147
|
+
declare function debounceSync(syncManager: StateSyncManager, delay?: number): (type: StateChangeType, threadId: string, payload: Record<string, unknown>) => void;
|
|
1148
|
+
|
|
1149
|
+
export { type AccessCheckResult, AgenticSearchEngine, type AgenticSearchParams, type AgenticSearchResponse, type ConflictResolution, type DeepAgentCompleteEvent, type DeepAgentErrorEvent, type DeepAgentEvent, type DeepAgentExecutionEvent, type DeepAgentSchemaEvent, type DeepAgentStartEvent, type GenerationMetrics, GenerationSession, type HealthCheckResult, type InferredPreference, MemoryManager, MetricsCollector, type MetricsSummary, MultiUserManager, ObservabilityCollector, type ObservableEvent, type ObservableEventType, type CombinerOptions as OrbitalCombinerOptions, type CombinerResult as OrbitalCombinerResult, type OrbitalSchemaValidationResult, type PerformanceSnapshot, type PreferenceAnalysis, PreferenceLearner, type PreferenceLearnerOptions, type ScopedSessionMetadata, type SearchResult, type SearchStrategy, SessionMetadata, type SessionTelemetry, type StateChangeEvent, type StateChangeType, type StateSyncConfig, StateSyncManager, type StateSyncSnapshot, SubAgent, type UserContext, UserPreference, type UserSessionStats, type VersionVector, analyzeFailures, combineOrbitals, combineOrbitalsToSchema, createAgenticSearchEngine, createErrorFixerSubagent, createPreferenceLearner, createSchemaGeneratorSubagent, createSubagentConfigs, createSubagents, createTestAnalyzerSubagent, createUserContext, debounceSync, endObservabilitySession, estimateCacheSavings, estimateCombineComplexity, formatSummary, generateFullOrbital, getMultiUserManager, getObservabilityCollector, getPerformanceSnapshot, getStateSyncManager, isAdmin, isCompleteEvent, isErrorEvent, isExecutionEvent, isSchemaEvent, isStartEvent, parseDeepAgentEvent, recordEvent, requireOwnership, resetMultiUserManager, resetObservabilityCollector, resetStateSyncManager, startObservabilitySession, withSync };
|