@almadar/agent 2.0.0 → 2.0.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.
Files changed (100) hide show
  1. package/dist/agent/event-budget.d.ts +28 -0
  2. package/dist/agent/experimental/hitl-v2.d.ts +161 -0
  3. package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
  4. package/dist/agent/index.d.ts +14 -0
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/interrupt-config.d.ts +51 -0
  7. package/dist/agent/session-manager.d.ts +204 -0
  8. package/dist/agent/skill-agent.d.ts +182 -0
  9. package/dist/agent/workflow-middleware.d.ts +63 -0
  10. package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
  11. package/dist/api-types.d.ts +595 -0
  12. package/dist/context/compaction.d.ts +191 -0
  13. package/dist/context-compaction.d.ts +55 -0
  14. package/dist/evals/online-sampling.d.ts +114 -0
  15. package/dist/evals/utils/compact-orbital.d.ts +100 -0
  16. package/dist/event-transformer/event-transformer.d.ts +120 -0
  17. package/dist/event-transformer/index.d.ts +7 -0
  18. package/dist/events.d.ts +85 -0
  19. package/dist/index.d.ts +59 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/memory/MemoryManager.d.ts +243 -0
  22. package/dist/memory/PreferenceLearner.d.ts +59 -0
  23. package/dist/memory/agentic-search.d.ts +116 -0
  24. package/dist/memory/index.d.ts +14 -0
  25. package/dist/memory/memory-orbital.d.ts +66 -0
  26. package/dist/memory/types.d.ts +143 -0
  27. package/dist/metrics.d.ts +77 -0
  28. package/dist/multi-user.d.ts +155 -0
  29. package/dist/observability/index.d.ts +14 -0
  30. package/dist/observability/langsmith-integration.d.ts +203 -0
  31. package/dist/observability.d.ts +196 -0
  32. package/dist/orbitals/archive/sanitize.d.ts +24 -0
  33. package/dist/orbitals/batch/batch-generator.d.ts +41 -0
  34. package/dist/orbitals/batch/concurrency.d.ts +54 -0
  35. package/dist/orbitals/batch/index.d.ts +14 -0
  36. package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
  37. package/dist/orbitals/batch/types.d.ts +103 -0
  38. package/dist/orbitals/cache/index.d.ts +11 -0
  39. package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
  40. package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
  41. package/dist/orbitals/cache/structural-templates.d.ts +33 -0
  42. package/dist/orbitals/combiner/index.d.ts +102 -0
  43. package/dist/orbitals/domain-language/index.d.ts +9 -0
  44. package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
  45. package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
  46. package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
  47. package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
  48. package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
  49. package/dist/orbitals/generation/index.d.ts +10 -0
  50. package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
  51. package/dist/orbitals/shared/constants.d.ts +65 -0
  52. package/dist/orbitals/shared/index.d.ts +11 -0
  53. package/dist/orbitals/shared/types.d.ts +187 -0
  54. package/dist/orbitals/shared/utils.d.ts +97 -0
  55. package/dist/orchestration/complexity-classifier.d.ts +38 -0
  56. package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
  57. package/dist/orchestration/index.d.ts +31 -0
  58. package/dist/orchestration/provider-router.d.ts +45 -0
  59. package/dist/persistence/firestore-checkpointer.d.ts +139 -0
  60. package/dist/persistence/firestore-session-store.d.ts +75 -0
  61. package/dist/persistence/firestore-store.d.ts +86 -0
  62. package/dist/persistence/index.d.ts +10 -0
  63. package/dist/persistence/memory-backend.d.ts +33 -0
  64. package/dist/persistence/types.d.ts +40 -0
  65. package/dist/security/audit-log.d.ts +44 -0
  66. package/dist/state-sync.d.ts +171 -0
  67. package/dist/subagents.d.ts +38 -0
  68. package/dist/tools/combine-schemas.d.ts +154 -0
  69. package/dist/tools/composition.d.ts +119 -0
  70. package/dist/tools/domain-orbital.d.ts +997 -0
  71. package/dist/tools/execute.d.ts +38 -0
  72. package/dist/tools/finish-task.d.ts +56 -0
  73. package/dist/tools/generate-schema.d.ts +53 -0
  74. package/dist/tools/github.d.ts +297 -0
  75. package/dist/tools/index.d.ts +1318 -0
  76. package/dist/tools/orbital-batch-subagent.d.ts +85 -0
  77. package/dist/tools/orbital-subagent.d.ts +454 -0
  78. package/dist/tools/orchestrated-fixing.d.ts +74 -0
  79. package/dist/tools/orchestrated-generation.d.ts +75 -0
  80. package/dist/tools/sandbox-executor.d.ts +31 -0
  81. package/dist/tools/schema-chunking.d.ts +117 -0
  82. package/dist/tools/trait-subagent.d.ts +179 -0
  83. package/dist/tools/validate-schema.d.ts +17 -0
  84. package/dist/types.d.ts +167 -0
  85. package/dist/utils/safety/capability-token.d.ts +50 -0
  86. package/dist/utils/safety/circuit-breaker.d.ts +71 -0
  87. package/dist/utils/safety/index.d.ts +19 -0
  88. package/dist/utils/safety/rate-limiter.d.ts +39 -0
  89. package/dist/utils/safety/threshold-auth.d.ts +70 -0
  90. package/dist/workspace/git-client.d.ts +51 -0
  91. package/dist/workspace/index.d.ts +38 -0
  92. package/dist/workspace/memory-files.d.ts +31 -0
  93. package/dist/workspace/sink-manager.d.ts +26 -0
  94. package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
  95. package/dist/workspace/sinks/git-sink.d.ts +47 -0
  96. package/dist/workspace/sinks/index.d.ts +9 -0
  97. package/dist/workspace/templates.d.ts +32 -0
  98. package/dist/workspace/types.d.ts +86 -0
  99. package/dist/workspace/workspace-manager.d.ts +57 -0
  100. package/package.json +7 -6
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Metrics Collection for DeepAgent Evaluation
3
+ *
4
+ * Tracks success rates, iteration counts, token usage, and timing
5
+ * for agent generation tests.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ /**
10
+ * Metrics for a single generation attempt.
11
+ */
12
+ export interface GenerationMetrics {
13
+ testName: string;
14
+ complexity: 'simple' | 'medium' | 'complex';
15
+ success: boolean;
16
+ iterations: number;
17
+ timeMs: number;
18
+ tokenUsage?: {
19
+ input: number;
20
+ output: number;
21
+ total: number;
22
+ };
23
+ error?: string;
24
+ timestamp?: number;
25
+ }
26
+ /**
27
+ * Aggregated metrics summary.
28
+ */
29
+ export interface MetricsSummary {
30
+ total: number;
31
+ passed: number;
32
+ failed: number;
33
+ successRate: number;
34
+ avgIterations: number;
35
+ avgTimeMs: number;
36
+ avgTokens: number;
37
+ byComplexity: {
38
+ simple: {
39
+ total: number;
40
+ passed: number;
41
+ successRate: number;
42
+ };
43
+ medium: {
44
+ total: number;
45
+ passed: number;
46
+ successRate: number;
47
+ };
48
+ complex: {
49
+ total: number;
50
+ passed: number;
51
+ successRate: number;
52
+ };
53
+ };
54
+ }
55
+ /**
56
+ * Collects and aggregates generation metrics.
57
+ */
58
+ export declare class MetricsCollector {
59
+ private metrics;
60
+ record(metrics: GenerationMetrics): void;
61
+ getAll(): GenerationMetrics[];
62
+ getSummary(): MetricsSummary;
63
+ private getComplexitySummary;
64
+ getFailures(): GenerationMetrics[];
65
+ getMultiIterationTests(): GenerationMetrics[];
66
+ clear(): void;
67
+ saveToFile(filePath: string): Promise<void>;
68
+ loadFromFile(filePath: string): Promise<void>;
69
+ }
70
+ /**
71
+ * Format metrics summary as a readable string.
72
+ */
73
+ export declare function formatSummary(summary: MetricsSummary): string;
74
+ /**
75
+ * Analyze failure patterns to suggest prompt improvements.
76
+ */
77
+ export declare function analyzeFailures(failures: GenerationMetrics[]): string[];
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Multi-User Support - GAP-009
3
+ *
4
+ * Provides proper user isolation and session scoping for multi-user environments.
5
+ * Ensures users can only access their own sessions, memory, and data.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { SessionMetadata } from './persistence/types.js';
10
+ /**
11
+ * User context for multi-user operations
12
+ */
13
+ export interface UserContext {
14
+ /** User ID */
15
+ userId: string;
16
+ /** Organization/tenant ID (for multi-tenant) */
17
+ orgId?: string;
18
+ /** User roles/permissions */
19
+ roles?: string[];
20
+ /** Session ID scope (optional) */
21
+ sessionScope?: string[];
22
+ }
23
+ /**
24
+ * Scoped session metadata with user ownership
25
+ */
26
+ export interface ScopedSessionMetadata extends SessionMetadata {
27
+ /** Owning user ID */
28
+ userId: string;
29
+ /** Organization ID */
30
+ orgId?: string;
31
+ /** Created by (for audit) */
32
+ createdBy: string;
33
+ /** Last accessed by */
34
+ lastAccessedBy?: string;
35
+ /** Access control list */
36
+ acl?: {
37
+ /** Users who can read this session */
38
+ readers?: string[];
39
+ /** Users who can write/modify */
40
+ writers?: string[];
41
+ /** Publicly accessible */
42
+ isPublic?: boolean;
43
+ };
44
+ }
45
+ /**
46
+ * Access check result
47
+ */
48
+ export interface AccessCheckResult {
49
+ /** Whether access is granted */
50
+ allowed: boolean;
51
+ /** Reason if denied */
52
+ reason?: string;
53
+ /** Required permission level */
54
+ requiredRole?: string;
55
+ }
56
+ /**
57
+ * User session stats
58
+ */
59
+ export interface UserSessionStats {
60
+ /** User ID */
61
+ userId: string;
62
+ /** Total sessions */
63
+ totalSessions: number;
64
+ /** Active sessions */
65
+ activeSessions: number;
66
+ /** Completed sessions */
67
+ completedSessions: number;
68
+ /** Sessions by skill */
69
+ sessionsBySkill: Record<string, number>;
70
+ /** Last activity timestamp */
71
+ lastActivityAt?: number;
72
+ }
73
+ export declare class MultiUserManager {
74
+ private sessionOwnership;
75
+ private userSessions;
76
+ /**
77
+ * Check if a user owns a session
78
+ */
79
+ isSessionOwner(threadId: string, userId: string): boolean;
80
+ /**
81
+ * Check if a user can access a session
82
+ */
83
+ canAccessSession(threadId: string, userContext: UserContext): AccessCheckResult;
84
+ /**
85
+ * Assign session ownership
86
+ */
87
+ assignSessionOwnership(threadId: string, userId: string): void;
88
+ /**
89
+ * Get all sessions for a user
90
+ */
91
+ getUserSessions(userId: string): string[];
92
+ /**
93
+ * Get session owner
94
+ */
95
+ getSessionOwner(threadId: string): string | undefined;
96
+ /**
97
+ * Remove session ownership
98
+ */
99
+ removeSession(threadId: string): void;
100
+ /**
101
+ * Check if user has any sessions
102
+ */
103
+ hasSessions(userId: string): boolean;
104
+ /**
105
+ * Get user session count
106
+ */
107
+ getSessionCount(userId: string): number;
108
+ /**
109
+ * Transfer session ownership
110
+ */
111
+ transferOwnership(threadId: string, fromUserId: string, toUserId: string): AccessCheckResult;
112
+ /**
113
+ * Share session with another user
114
+ */
115
+ shareSession(threadId: string, ownerId: string, targetUserId: string, permission?: 'read' | 'write'): AccessCheckResult;
116
+ /**
117
+ * Get all user IDs with sessions
118
+ */
119
+ getAllUsers(): string[];
120
+ /**
121
+ * Clear all data (for testing)
122
+ */
123
+ clear(): void;
124
+ /**
125
+ * Create scoped session metadata
126
+ */
127
+ createScopedMetadata(metadata: SessionMetadata, userContext: UserContext): ScopedSessionMetadata;
128
+ /**
129
+ * Validate user context
130
+ */
131
+ validateUserContext(userContext: unknown): userContext is UserContext;
132
+ }
133
+ /**
134
+ * Get or create global multi-user manager
135
+ */
136
+ export declare function getMultiUserManager(): MultiUserManager;
137
+ /**
138
+ * Reset global multi-user manager
139
+ */
140
+ export declare function resetMultiUserManager(): void;
141
+ /**
142
+ * Create user context from request
143
+ */
144
+ export declare function createUserContext(userId: string, options?: {
145
+ orgId?: string;
146
+ roles?: string[];
147
+ }): UserContext;
148
+ /**
149
+ * Check if user is admin
150
+ */
151
+ export declare function isAdmin(userContext: UserContext): boolean;
152
+ /**
153
+ * Require ownership or throw
154
+ */
155
+ export declare function requireOwnership(threadId: string, userContext: UserContext, manager?: MultiUserManager): void;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Observability Module - Phase 1.2 Implementation
3
+ *
4
+ * Enhanced observability with LangSmith integration:
5
+ * - Run tracking with custom metadata
6
+ * - Error classification
7
+ * - Token usage alerts
8
+ * - Business metrics dashboard
9
+ * - Latency SLO monitoring
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ export { LangSmithIntegration, getLangSmithIntegration, resetLangSmithIntegration, type ErrorCategory, type SessionMetadata, type TokenAlertConfig, type TokenAlert, type BusinessMetrics, type LatencySLOConfig, type SLOBreach, } from './langsmith-integration.js';
14
+ export { ObservabilityCollector, getObservabilityCollector, resetObservabilityCollector, recordEvent, startObservabilitySession, endObservabilitySession, getPerformanceSnapshot, type ObservableEvent, type ObservableEventType, type SessionTelemetry, type PerformanceSnapshot, type HealthCheckResult, } from '../observability.js';
@@ -0,0 +1,203 @@
1
+ /**
2
+ * LangSmith Integration for Enhanced Observability
3
+ *
4
+ * Phase 1.2: Observability Enhancements
5
+ * - LangSmith run tracking (session = 1 run)
6
+ * - Custom metadata tags (orbitalCount, provider, success)
7
+ * - Error classification (timeout, schema, validation)
8
+ * - Token usage tracking with alerts
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ import { Client as LangSmithClient, RunTree } from 'langsmith';
13
+ /**
14
+ * Error classification categories
15
+ */
16
+ export type ErrorCategory = 'timeout' | 'schema' | 'validation' | 'parse' | 'memory' | 'network' | 'rate_limit' | 'unknown';
17
+ /**
18
+ * Session metadata for LangSmith
19
+ */
20
+ export interface SessionMetadata {
21
+ /** Number of orbitals in request */
22
+ orbitalCount?: number;
23
+ /** LLM provider used */
24
+ provider?: string;
25
+ /** Model name */
26
+ model?: string;
27
+ /** User ID */
28
+ userId?: string;
29
+ /** Project ID */
30
+ projectId?: string;
31
+ /** Session complexity estimate */
32
+ complexity?: 'simple' | 'medium' | 'complex';
33
+ /** Generation success status */
34
+ success?: boolean;
35
+ /** Approach used: workflow or sequential */
36
+ approach?: 'workflow' | 'sequential';
37
+ /** Error category if failed */
38
+ errorCategory?: ErrorCategory;
39
+ /** Total tokens used */
40
+ totalTokens?: number;
41
+ /** Cost in USD */
42
+ costUsd?: number;
43
+ /** Duration in ms */
44
+ durationMs?: number;
45
+ }
46
+ /**
47
+ * Token usage alert configuration
48
+ */
49
+ export interface TokenAlertConfig {
50
+ /** Threshold for warning (default: 8000) */
51
+ warningThreshold: number;
52
+ /** Threshold for critical (default: 10000) */
53
+ criticalThreshold: number;
54
+ /** Callback when threshold exceeded */
55
+ onAlert?: (alert: TokenAlert) => void;
56
+ }
57
+ /**
58
+ * Token usage alert
59
+ */
60
+ export interface TokenAlert {
61
+ level: 'warning' | 'critical';
62
+ sessionId: string;
63
+ tokenCount: number;
64
+ threshold: number;
65
+ timestamp: number;
66
+ message: string;
67
+ }
68
+ /**
69
+ * Business metrics snapshot
70
+ */
71
+ export interface BusinessMetrics {
72
+ /** Timestamp */
73
+ timestamp: number;
74
+ /** Time window in hours */
75
+ windowHours: number;
76
+ /** Total generations */
77
+ totalGenerations: number;
78
+ /** Successful generations */
79
+ successfulGenerations: number;
80
+ /** Failed generations */
81
+ failedGenerations: number;
82
+ /** Success rate (0-1) */
83
+ successRate: number;
84
+ /** Total cost in USD */
85
+ totalCostUsd: number;
86
+ /** Average cost per generation */
87
+ avgCostPerGeneration: number;
88
+ /** Average latency in ms */
89
+ avgLatencyMs: number;
90
+ /** P95 latency in ms */
91
+ p95LatencyMs: number;
92
+ /** Token usage distribution */
93
+ tokenDistribution: {
94
+ totalInput: number;
95
+ totalOutput: number;
96
+ avgPerGeneration: number;
97
+ };
98
+ /** Provider usage breakdown */
99
+ providerBreakdown: Record<string, {
100
+ count: number;
101
+ cost: number;
102
+ }>;
103
+ }
104
+ /**
105
+ * Latency SLO configuration
106
+ */
107
+ export interface LatencySLOConfig {
108
+ /** Simple apps: P95 < 60s */
109
+ simple: {
110
+ p95Ms: number;
111
+ };
112
+ /** Complex apps: P95 < 300s */
113
+ complex: {
114
+ p95Ms: number;
115
+ };
116
+ /** Callback on SLO breach */
117
+ onBreach?: (breach: SLOBreach) => void;
118
+ }
119
+ /**
120
+ * SLO breach event
121
+ */
122
+ export interface SLOBreach {
123
+ type: 'latency';
124
+ complexity: 'simple' | 'complex';
125
+ actualP95Ms: number;
126
+ thresholdMs: number;
127
+ timestamp: number;
128
+ message: string;
129
+ }
130
+ export declare class LangSmithIntegration {
131
+ private client;
132
+ private projectName;
133
+ private activeRuns;
134
+ private sessionMetadata;
135
+ private tokenAlerts;
136
+ private latencySLO;
137
+ private metricsHistory;
138
+ constructor(options?: {
139
+ apiKey?: string;
140
+ apiUrl?: string;
141
+ projectName?: string;
142
+ tokenAlerts?: Partial<TokenAlertConfig>;
143
+ latencySLO?: Partial<LatencySLOConfig>;
144
+ });
145
+ /**
146
+ * Start a new LangSmith run for a session
147
+ */
148
+ startSessionRun(sessionId: string, inputs: Record<string, unknown>, metadata?: Partial<SessionMetadata>): Promise<RunTree>;
149
+ /**
150
+ * Add metadata to an active session
151
+ */
152
+ addSessionMetadata(sessionId: string, metadata: Partial<SessionMetadata>): void;
153
+ /**
154
+ * Record an LLM call within a session
155
+ */
156
+ recordLLMCall(sessionId: string, options: {
157
+ model: string;
158
+ provider: string;
159
+ input: string;
160
+ output: string;
161
+ tokenCount: {
162
+ input: number;
163
+ output: number;
164
+ };
165
+ durationMs: number;
166
+ costUsd?: number;
167
+ }): Promise<void>;
168
+ /**
169
+ * Record a tool call within a session
170
+ */
171
+ recordToolCall(sessionId: string, toolName: string, inputs: Record<string, unknown>, outputs?: Record<string, unknown>, durationMs?: number): Promise<void>;
172
+ /**
173
+ * End a session run
174
+ */
175
+ endSessionRun(sessionId: string, outputs: Record<string, unknown>, error?: Error): Promise<void>;
176
+ /**
177
+ * Classify an error into categories
178
+ */
179
+ classifyError(error: Error): ErrorCategory;
180
+ /**
181
+ * Check token usage and trigger alerts
182
+ */
183
+ private checkTokenAlert;
184
+ /**
185
+ * Check latency SLO compliance
186
+ */
187
+ private checkLatencySLO;
188
+ /**
189
+ * Get business metrics for a time window
190
+ */
191
+ getBusinessMetrics(windowHours?: number): BusinessMetrics;
192
+ /**
193
+ * Get error breakdown by category
194
+ */
195
+ getErrorBreakdown(windowHours?: number): Record<ErrorCategory, number>;
196
+ /**
197
+ * Clean up old metrics (prevent memory leak)
198
+ */
199
+ pruneMetrics(olderThanHours?: number): void;
200
+ }
201
+ export declare function getLangSmithIntegration(): LangSmithIntegration;
202
+ export declare function resetLangSmithIntegration(): void;
203
+ export type { LangSmithClient, RunTree, };
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Observability - GAP-008
3
+ *
4
+ * Comprehensive observability layer for DeepAgent including:
5
+ * - Event tracking
6
+ * - Session metrics
7
+ * - Performance monitoring
8
+ * - Health checks
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ /**
13
+ * Observable event types
14
+ */
15
+ export type ObservableEventType = 'session_start' | 'session_end' | 'tool_call' | 'tool_result' | 'interrupt' | 'checkpoint_save' | 'checkpoint_restore' | 'error' | 'llm_call' | 'memory_sync';
16
+ /**
17
+ * Observable event
18
+ */
19
+ export interface ObservableEvent {
20
+ /** Event type */
21
+ type: ObservableEventType;
22
+ /** Timestamp */
23
+ timestamp: number;
24
+ /** Session/thread ID */
25
+ sessionId: string;
26
+ /** User ID */
27
+ userId?: string;
28
+ /** Event payload */
29
+ payload: Record<string, unknown>;
30
+ /** Duration in ms (if applicable) */
31
+ duration?: number;
32
+ /** Error information */
33
+ error?: {
34
+ message: string;
35
+ code?: string;
36
+ stack?: string;
37
+ };
38
+ }
39
+ /**
40
+ * Session telemetry
41
+ */
42
+ export interface SessionTelemetry {
43
+ /** Session ID */
44
+ sessionId: string;
45
+ /** User ID */
46
+ userId?: string;
47
+ /** Session start time */
48
+ startedAt: number;
49
+ /** Session end time */
50
+ endedAt?: number;
51
+ /** Number of tool calls */
52
+ toolCallCount: number;
53
+ /** Number of LLM calls */
54
+ llmCallCount: number;
55
+ /** Number of interrupts */
56
+ interruptCount: number;
57
+ /** Number of checkpoints */
58
+ checkpointCount: number;
59
+ /** Total tokens used */
60
+ totalTokens: number;
61
+ /** Errors encountered */
62
+ errors: Array<{
63
+ timestamp: number;
64
+ message: string;
65
+ type: string;
66
+ }>;
67
+ /** Final status */
68
+ status: 'running' | 'completed' | 'failed' | 'interrupted';
69
+ }
70
+ /**
71
+ * Performance snapshot
72
+ */
73
+ export interface PerformanceSnapshot {
74
+ /** Timestamp */
75
+ timestamp: number;
76
+ /** Active sessions */
77
+ activeSessions: number;
78
+ /** Total sessions (all time) */
79
+ totalSessions: number;
80
+ /** Average session duration */
81
+ avgSessionDuration: number;
82
+ /** Success rate (last 24h) */
83
+ successRate24h: number;
84
+ /** Error rate (last 24h) */
85
+ errorRate24h: number;
86
+ /** Average tokens per session */
87
+ avgTokensPerSession: number;
88
+ }
89
+ /**
90
+ * Health check result
91
+ */
92
+ export interface HealthCheckResult {
93
+ /** Component name */
94
+ component: string;
95
+ /** Health status */
96
+ status: 'healthy' | 'degraded' | 'unhealthy';
97
+ /** Response time in ms */
98
+ responseTime: number;
99
+ /** Last checked timestamp */
100
+ checkedAt: number;
101
+ /** Error message if unhealthy */
102
+ error?: string;
103
+ }
104
+ export declare class ObservabilityCollector {
105
+ private events;
106
+ private sessions;
107
+ private maxEvents;
108
+ constructor(options?: {
109
+ maxEvents?: number;
110
+ });
111
+ /**
112
+ * Record an observable event
113
+ */
114
+ recordEvent(event: Omit<ObservableEvent, 'timestamp'>): void;
115
+ /**
116
+ * Start session tracking
117
+ */
118
+ startSession(sessionId: string, userId?: string): void;
119
+ /**
120
+ * End session tracking
121
+ */
122
+ endSession(sessionId: string, status?: SessionTelemetry['status']): void;
123
+ /**
124
+ * Record tool call
125
+ */
126
+ recordToolCall(sessionId: string, toolName: string, args: Record<string, unknown>, duration?: number): void;
127
+ /**
128
+ * Record LLM call
129
+ */
130
+ recordLLMCall(sessionId: string, model: string, tokens: {
131
+ input: number;
132
+ output: number;
133
+ }, duration?: number): void;
134
+ /**
135
+ * Record error
136
+ */
137
+ recordError(sessionId: string, error: Error, context?: Record<string, unknown>): void;
138
+ /**
139
+ * Get events by type
140
+ */
141
+ getEvents(type?: ObservableEventType, sessionId?: string): ObservableEvent[];
142
+ /**
143
+ * Get session telemetry
144
+ */
145
+ getSessionTelemetry(sessionId: string): SessionTelemetry | undefined;
146
+ /**
147
+ * Get all active sessions
148
+ */
149
+ getActiveSessions(): SessionTelemetry[];
150
+ /**
151
+ * Get performance snapshot
152
+ */
153
+ getPerformanceSnapshot(): PerformanceSnapshot;
154
+ /**
155
+ * Perform health check
156
+ */
157
+ healthCheck(): Promise<HealthCheckResult[]>;
158
+ /**
159
+ * Export metrics for external systems
160
+ */
161
+ exportMetrics(): {
162
+ events: ObservableEvent[];
163
+ sessions: SessionTelemetry[];
164
+ snapshot: PerformanceSnapshot;
165
+ health: HealthCheckResult[];
166
+ };
167
+ /**
168
+ * Clear all data
169
+ */
170
+ clear(): void;
171
+ private updateSessionTelemetry;
172
+ }
173
+ /**
174
+ * Get or create global observability collector
175
+ */
176
+ export declare function getObservabilityCollector(): ObservabilityCollector;
177
+ /**
178
+ * Reset global observability collector
179
+ */
180
+ export declare function resetObservabilityCollector(): void;
181
+ /**
182
+ * Record event to global collector
183
+ */
184
+ export declare function recordEvent(event: Omit<ObservableEvent, 'timestamp'>): void;
185
+ /**
186
+ * Start session in global collector
187
+ */
188
+ export declare function startObservabilitySession(sessionId: string, userId?: string): void;
189
+ /**
190
+ * End session in global collector
191
+ */
192
+ export declare function endObservabilitySession(sessionId: string, status?: SessionTelemetry['status']): void;
193
+ /**
194
+ * Get performance snapshot from global collector
195
+ */
196
+ export declare function getPerformanceSnapshot(): PerformanceSnapshot;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Orbital Sanitization
3
+ *
4
+ * Fixes common LLM generation errors in orbital JSON before validation.
5
+ * These are deterministic type coercions for known error patterns:
6
+ *
7
+ * 1. `field.type` as boolean/array instead of string
8
+ * 2. `field.values` as string/boolean instead of string[]
9
+ * 3. `field.required` as string instead of boolean
10
+ * 4. Invalid binding functions like `@count(...)`, `@length(...)`
11
+ * 5. Nested arrays where flat arrays expected
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ /**
16
+ * Sanitize an orbital definition in-place, fixing common LLM type errors.
17
+ * Returns the same object (mutated) for convenience.
18
+ */
19
+ export declare function sanitizeOrbital(orbital: Record<string, unknown>): Record<string, unknown>;
20
+ /**
21
+ * Sanitize a full schema (array of orbitals).
22
+ * Also removes relations to non-existent entities.
23
+ */
24
+ export declare function sanitizeSchema(schema: Record<string, unknown>): Record<string, unknown>;