@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.
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 +8 -7
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Orbital Generator
3
+ *
4
+ * Provides utilities for generating FullOrbitalUnit definitions from
5
+ * lightweight OrbitalUnit inputs. Designed for SUBAGENT use where each
6
+ * orbital is generated separately for better caching.
7
+ *
8
+ * ## Subagent Caching Pattern
9
+ *
10
+ * When generating multiple orbitals in a subagent pattern:
11
+ * 1. Main agent decomposes request → OrbitalUnit[]
12
+ * 2. For each orbital, subagent calls generateFullOrbital()
13
+ * 3. Each subagent call uses the SAME cached system prompt blocks
14
+ * 4. Anthropic caches at request level → subsequent calls get 90% discount
15
+ *
16
+ * This is MORE efficient than batch generation because:
17
+ * - System prompt is cached and reused across subagent calls
18
+ * - Template guidance is cached per fingerprint
19
+ * - Only the orbital-specific content varies
20
+ *
21
+ * @packageDocumentation
22
+ */
23
+ import type { LLMClient } from '@almadar/llm';
24
+ import { type OrbitalUnit, type OrbitalGenerationOptions as SharedOrbitalGenerationOptions, type OrbitalGenerationResult as SharedOrbitalGenerationResult, type ParallelGenerationOptions as SharedParallelGenerationOptions, type ParallelGenerationResult as SharedParallelGenerationResult, type DecomposeOptions as SharedDecomposeOptions } from '../shared/index.js';
25
+ export { type OrbitalUnit, type GenerationLog, type ExtractedRequirements, } from '../shared/index.js';
26
+ export { PROVIDER_CONCURRENCY_LIMITS } from '../shared/index.js';
27
+ /**
28
+ * Extended options for single orbital generation.
29
+ * @deprecated Use shared OrbitalGenerationOptions instead
30
+ */
31
+ export interface OrbitalGenerationOptions extends SharedOrbitalGenerationOptions {
32
+ }
33
+ /**
34
+ * Extended result for single orbital generation.
35
+ * @deprecated Use shared OrbitalGenerationResult instead
36
+ */
37
+ export interface OrbitalGenerationResult extends SharedOrbitalGenerationResult {
38
+ }
39
+ /**
40
+ * Extended options for parallel generation.
41
+ * @deprecated Use shared ParallelGenerationOptions instead
42
+ */
43
+ export interface ParallelGenerationOptions extends SharedParallelGenerationOptions {
44
+ }
45
+ /**
46
+ * Extended result for parallel generation.
47
+ * @deprecated Use shared ParallelGenerationResult instead
48
+ */
49
+ export interface ParallelGenerationResult extends SharedParallelGenerationResult {
50
+ }
51
+ /**
52
+ * Extended options for decomposition.
53
+ * @deprecated Use shared DecomposeOptions instead
54
+ */
55
+ export interface DecomposeOptions extends SharedDecomposeOptions {
56
+ }
57
+ /**
58
+ * Generate a full orbital unit from a lightweight orbital input.
59
+ *
60
+ * DESIGNED FOR SUBAGENT USE: Call this once per orbital in separate
61
+ * subagent invocations. Caching works across calls because:
62
+ * - System prompt blocks are marked as cacheable
63
+ * - Anthropic caches at the request level
64
+ * - Subsequent calls with same system prompt get cache hits
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // In subagent for each orbital:
69
+ * const result = await generateFullOrbital(client, orbitalUnit, { validate: true });
70
+ * // First call: Cache WRITE: 3500 tokens
71
+ * // Second call: Cache HIT: 3500 tokens (90% discount!)
72
+ * ```
73
+ */
74
+ export declare function generateFullOrbital(client: LLMClient, orbital: OrbitalUnit, options?: OrbitalGenerationOptions): Promise<OrbitalGenerationResult>;
75
+ /**
76
+ * Generate multiple orbitals in parallel with concurrency control.
77
+ *
78
+ * Uses provider-specific concurrency limits to avoid rate limiting.
79
+ * All orbital units are independent, so parallel execution is safe.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Generate all orbitals in parallel (max 3 concurrent for Anthropic)
84
+ * const result = await generateFullOrbitalsParallel(client, orbitals, { validate: true });
85
+ * console.log(`Generated ${result.summary.successful}/${result.summary.total} orbitals`);
86
+ * ```
87
+ */
88
+ export declare function generateFullOrbitalsParallel(client: LLMClient, orbitals: OrbitalUnit[], options?: ParallelGenerationOptions): Promise<ParallelGenerationResult>;
89
+ /**
90
+ * Decompose a user request into OrbitalUnits using LLM.
91
+ *
92
+ * This is typically called by the MAIN AGENT before delegating
93
+ * to subagents for full orbital generation.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Without requirements (existing behavior):
98
+ * const orbitals = await decomposeToOrbitals(client, "Build a task manager");
99
+ *
100
+ * // With requirements (from analysis phase):
101
+ * const orbitals = await decomposeToOrbitals(client, "Build a task manager", {
102
+ * requirements: { entities: ["Task"], guards: ["only admins can delete"], ... }
103
+ * });
104
+ *
105
+ * // Then generate all orbitals in parallel:
106
+ * const result = await generateFullOrbitalsParallel(client, orbitals);
107
+ * ```
108
+ */
109
+ export declare function decomposeToOrbitals(client: LLMClient, userRequest: string, options?: DecomposeOptions): Promise<OrbitalUnit[]>;
110
+ /**
111
+ * Estimate cache savings for a set of orbitals.
112
+ *
113
+ * Use this to predict how much caching will help for a decomposition.
114
+ */
115
+ export declare function estimateCacheSavings(orbitals: OrbitalUnit[]): {
116
+ totalOrbitals: number;
117
+ uniqueFingerprints: number;
118
+ estimatedCacheHits: number;
119
+ estimatedSavingsPercent: number;
120
+ };
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Shared Constants for Orbital Generation
3
+ *
4
+ * Provider limits, defaults, and configuration constants.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { LLMProvider } from '@almadar/llm';
9
+ /**
10
+ * Default concurrency limits per LLM provider.
11
+ * These are conservative defaults to avoid rate limiting.
12
+ */
13
+ export declare const PROVIDER_CONCURRENCY_LIMITS: Record<LLMProvider, number>;
14
+ /**
15
+ * Default batch sizes per provider (max orbitals per LLM call).
16
+ */
17
+ export declare const PROVIDER_BATCH_SIZES: Record<LLMProvider, number>;
18
+ /**
19
+ * Maximum tokens for generation (across all providers).
20
+ */
21
+ export declare const DEFAULT_MAX_TOKENS = 8192;
22
+ /**
23
+ * Maximum tokens for batch generation (higher for multi-orbital).
24
+ */
25
+ export declare const BATCH_MAX_TOKENS = 12000;
26
+ /**
27
+ * Token buffer for prompt overhead.
28
+ */
29
+ export declare const TOKEN_BUFFER = 1000;
30
+ /**
31
+ * Maximum retries for failed generation attempts.
32
+ */
33
+ export declare const MAX_RETRIES = 2;
34
+ /**
35
+ * Delay between retries (ms).
36
+ */
37
+ export declare const RETRY_DELAY_MS = 1000;
38
+ /**
39
+ * Timeout for single orbital generation (ms).
40
+ */
41
+ export declare const SINGLE_GENERATION_TIMEOUT_MS = 120000;
42
+ /**
43
+ * Timeout for batch generation (ms).
44
+ */
45
+ export declare const BATCH_GENERATION_TIMEOUT_MS = 300000;
46
+ /**
47
+ * Default LLM provider.
48
+ */
49
+ export declare const DEFAULT_PROVIDER: LLMProvider;
50
+ /**
51
+ * Default model for generation.
52
+ */
53
+ export declare const DEFAULT_MODEL = "claude-sonnet-4-20250514";
54
+ /**
55
+ * Default model for batch generation.
56
+ */
57
+ export declare const DEFAULT_BATCH_MODEL = "claude-sonnet-4-20250514";
58
+ /**
59
+ * Whether to enable prompt caching by default.
60
+ */
61
+ export declare const DEFAULT_CACHE_ENABLED = true;
62
+ /**
63
+ * Cache TTL in milliseconds (1 hour).
64
+ */
65
+ export declare const CACHE_TTL_MS: number;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared Utilities for Orbital Generation
3
+ *
4
+ * Common types, constants, and utilities used by both sequential
5
+ * and batch generation modules.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export { type OrbitalUnit, type GenerationLog, type ExtractedRequirements, type BaseGenerationOptions, type OrbitalGenerationOptions, type ParallelGenerationOptions, type BatchGenerationOptions, type TokenUsage, type ValidationResult, type OrbitalGenerationResult, type ParallelGenerationResult, type BatchGenerationResult, type DecomposeOptions, type DecomposeResult, type OrbitalBatch, type BatchProgressEvent, } from './types.js';
10
+ export { PROVIDER_CONCURRENCY_LIMITS, PROVIDER_BATCH_SIZES, DEFAULT_MAX_TOKENS, BATCH_MAX_TOKENS, TOKEN_BUFFER, MAX_RETRIES, RETRY_DELAY_MS, SINGLE_GENERATION_TIMEOUT_MS, BATCH_GENERATION_TIMEOUT_MS, DEFAULT_PROVIDER, DEFAULT_MODEL, DEFAULT_BATCH_MODEL, DEFAULT_CACHE_ENABLED, CACHE_TTL_MS, } from './constants.js';
11
+ export { getEntityName, getInlineEntity, getEntityPersistence, getFieldNames, getTraitNames, createLog, createOrbitalLog, buildContextSection, buildConnectivitySection, isValidOrbital, validateOrbitals, chunkArray, groupBy, asyncMapWithConcurrency, measureTime, sleep, getErrorMessage, isRateLimitError, isTimeoutError, } from './utils.js';
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Shared Types for Orbital Generation
3
+ *
4
+ * Common type definitions used by both sequential and batch generation.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { OrbitalDefinition, FullOrbitalUnit } from '@almadar/core/types';
9
+ /** OrbitalUnit in generation context is always a full OrbitalDefinition */
10
+ export type OrbitalUnit = OrbitalDefinition;
11
+ /**
12
+ * A structured log entry from the generation process.
13
+ * Used for debugging and observability of subagent reasoning.
14
+ */
15
+ export interface GenerationLog {
16
+ /** Timestamp of the log entry */
17
+ timestamp: number;
18
+ /** Log level */
19
+ level: 'info' | 'warn' | 'error' | 'debug';
20
+ /** Log message */
21
+ message: string;
22
+ /** Optional structured data */
23
+ data?: Record<string, unknown>;
24
+ }
25
+ /**
26
+ * Extracted requirements from the analysis phase.
27
+ * Matches ExtractedRequirements from agents/orchestrator/shared/requirements.ts
28
+ */
29
+ export interface ExtractedRequirements {
30
+ /** Entity names to create */
31
+ entities?: string[];
32
+ /** State names that should exist */
33
+ states?: string[];
34
+ /** Event/action names */
35
+ events?: string[];
36
+ /** Business rules (become guards) */
37
+ guards?: string[];
38
+ /** Page types needed */
39
+ pages?: string[];
40
+ /** Notifications/side-effects */
41
+ effects?: string[];
42
+ /** Raw requirement statements */
43
+ rawRequirements?: string[];
44
+ }
45
+ /**
46
+ * Common options for all generation modes.
47
+ */
48
+ export interface BaseGenerationOptions {
49
+ /** Maximum tokens for generation */
50
+ maxTokens?: number;
51
+ /** Enable validation after generation */
52
+ validate?: boolean;
53
+ /** Callback for real-time log streaming */
54
+ onLog?: (log: GenerationLog, orbitalName?: string) => void;
55
+ /** Optional requirements relevant to this orbital */
56
+ requirements?: Partial<ExtractedRequirements>;
57
+ }
58
+ /**
59
+ * Options for single orbital generation.
60
+ */
61
+ export interface OrbitalGenerationOptions extends BaseGenerationOptions {
62
+ }
63
+ /**
64
+ * Options for parallel/batch generation.
65
+ */
66
+ export interface ParallelGenerationOptions extends BaseGenerationOptions {
67
+ /** Maximum concurrent generations (default: provider-specific) */
68
+ concurrency?: number;
69
+ /** Progress callback */
70
+ onProgress?: (completed: number, total: number, orbitalName: string) => void;
71
+ }
72
+ /**
73
+ * Token usage statistics.
74
+ */
75
+ export interface TokenUsage {
76
+ promptTokens: number;
77
+ completionTokens: number;
78
+ totalTokens: number;
79
+ }
80
+ /**
81
+ * Validation result for generated orbital.
82
+ */
83
+ export interface ValidationResult {
84
+ valid: boolean;
85
+ errorCount: number;
86
+ warningCount: number;
87
+ }
88
+ /**
89
+ * Result of generating a single orbital.
90
+ */
91
+ export interface OrbitalGenerationResult {
92
+ /** Generated full orbital unit */
93
+ orbital: FullOrbitalUnit;
94
+ /** Fingerprint used for caching */
95
+ fingerprint: string;
96
+ /** Whether template guidance was used */
97
+ usedTemplate: boolean;
98
+ /** Token usage */
99
+ usage?: TokenUsage;
100
+ /** Validation result */
101
+ validation?: ValidationResult;
102
+ /** Structured logs from generation */
103
+ logs: GenerationLog[];
104
+ }
105
+ /**
106
+ * Result of parallel/batch generation.
107
+ */
108
+ export interface ParallelGenerationResult {
109
+ /** Results for each orbital (same order as input) */
110
+ results: OrbitalGenerationResult[];
111
+ /** Total duration in milliseconds */
112
+ totalDurationMs: number;
113
+ /** Aggregate logs from all generations */
114
+ aggregateLogs: GenerationLog[];
115
+ /** Summary statistics */
116
+ summary: {
117
+ total: number;
118
+ successful: number;
119
+ failed: number;
120
+ totalTokens: number;
121
+ };
122
+ }
123
+ /**
124
+ * Result of batch generation (alias for ParallelGenerationResult).
125
+ */
126
+ export type BatchGenerationResult = ParallelGenerationResult;
127
+ /**
128
+ * Options for decomposing a request into orbitals.
129
+ */
130
+ export interface DecomposeOptions {
131
+ /** Maximum tokens for generation */
132
+ maxTokens?: number;
133
+ /** Optional extracted requirements from analysis phase */
134
+ requirements?: Partial<ExtractedRequirements>;
135
+ /** Optional domain context */
136
+ domain?: string;
137
+ /** Optional design hints */
138
+ design?: {
139
+ style?: 'minimal' | 'modern' | 'playful' | 'data-driven' | 'immersive';
140
+ };
141
+ /** Explicit entity list if known */
142
+ entities?: string[];
143
+ }
144
+ /**
145
+ * Result of decomposition.
146
+ */
147
+ export interface DecomposeResult {
148
+ /** Generated orbital units */
149
+ orbitals: OrbitalUnit[];
150
+ /** Extracted requirements */
151
+ requirements?: ExtractedRequirements;
152
+ }
153
+ /**
154
+ * Options for batch generation.
155
+ */
156
+ export interface BatchGenerationOptions extends ParallelGenerationOptions {
157
+ /** Maximum orbitals per batch (default: 3 for Anthropic, 5 for OpenAI) */
158
+ batchSize?: number;
159
+ /** Whether to use single-call batch, parallel individual calls, or adaptive */
160
+ mode?: 'single-call' | 'parallel-individual' | 'adaptive';
161
+ }
162
+ /**
163
+ * A batch of orbitals to generate together.
164
+ */
165
+ export interface OrbitalBatch {
166
+ /** Batch index */
167
+ index: number;
168
+ /** Orbitals in this batch */
169
+ orbitals: OrbitalUnit[];
170
+ /** Shared context for this batch */
171
+ sharedContext?: {
172
+ domainVocabulary?: Record<string, string>;
173
+ designStyle?: string;
174
+ };
175
+ }
176
+ /**
177
+ * Progress event for batch generation.
178
+ */
179
+ export interface BatchProgressEvent {
180
+ type: 'batch_start' | 'orbital_complete' | 'batch_complete' | 'error';
181
+ batchIndex: number;
182
+ orbitalIndex?: number;
183
+ orbitalName?: string;
184
+ completed: number;
185
+ total: number;
186
+ error?: string;
187
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Shared Utilities for Orbital Generation
3
+ *
4
+ * Common utility functions used by both sequential and batch generation.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { EntityRef, Entity } from '@almadar/core/types';
9
+ import type { GenerationLog } from './types.js';
10
+ /**
11
+ * Get entity name safely from EntityRef.
12
+ */
13
+ export declare function getEntityName(entity: EntityRef): string;
14
+ /**
15
+ * Get inline entity for detailed access, or null for references.
16
+ */
17
+ export declare function getInlineEntity(entity: EntityRef): Entity | null;
18
+ /**
19
+ * Get persistence type for an entity.
20
+ */
21
+ export declare function getEntityPersistence(entity: EntityRef): string;
22
+ /**
23
+ * Get field names as comma-separated string.
24
+ */
25
+ export declare function getFieldNames(entity: EntityRef): string;
26
+ /**
27
+ * Get trait names from orbital traits array.
28
+ */
29
+ export declare function getTraitNames(traits: Array<{
30
+ name: string;
31
+ } | string>): string;
32
+ /**
33
+ * Create a generation log entry.
34
+ */
35
+ export declare function createLog(level: GenerationLog['level'], message: string, data?: Record<string, unknown>): GenerationLog;
36
+ /**
37
+ * Log with orbital context.
38
+ */
39
+ export declare function createOrbitalLog(level: GenerationLog['level'], orbitalName: string, message: string, data?: Record<string, unknown>): GenerationLog;
40
+ import type { OrbitalDefinition } from '@almadar/core/types';
41
+ /**
42
+ * Build context section from orbital's domainContext and design fields.
43
+ */
44
+ export declare function buildContextSection(orbital: OrbitalDefinition): string;
45
+ /**
46
+ * Build cross-orbital connectivity section.
47
+ */
48
+ export declare function buildConnectivitySection(orbital: OrbitalDefinition): string;
49
+ /**
50
+ * Check if an orbital has all required fields.
51
+ */
52
+ export declare function isValidOrbital(orbital: unknown): orbital is OrbitalDefinition;
53
+ /**
54
+ * Validate a batch of orbitals.
55
+ */
56
+ export declare function validateOrbitals(orbitals: unknown[]): {
57
+ valid: OrbitalDefinition[];
58
+ invalid: {
59
+ index: number;
60
+ reason: string;
61
+ }[];
62
+ };
63
+ /**
64
+ * Chunk an array into smaller arrays.
65
+ */
66
+ export declare function chunkArray<T>(array: T[], size: number): T[][];
67
+ /**
68
+ * Group array items by a key function.
69
+ */
70
+ export declare function groupBy<T, K>(array: T[], keyFn: (item: T) => K): Map<K, T[]>;
71
+ /**
72
+ * Async map with concurrency limit.
73
+ */
74
+ export declare function asyncMapWithConcurrency<T, R>(items: T[], mapper: (item: T, index: number) => Promise<R>, concurrency: number): Promise<R[]>;
75
+ /**
76
+ * Measure execution time of an async function.
77
+ */
78
+ export declare function measureTime<T>(fn: () => Promise<T>): Promise<{
79
+ result: T;
80
+ durationMs: number;
81
+ }>;
82
+ /**
83
+ * Sleep for a specified duration.
84
+ */
85
+ export declare function sleep(ms: number): Promise<void>;
86
+ /**
87
+ * Get error message from unknown error.
88
+ */
89
+ export declare function getErrorMessage(error: unknown): string;
90
+ /**
91
+ * Check if error is a rate limit error.
92
+ */
93
+ export declare function isRateLimitError(error: unknown): boolean;
94
+ /**
95
+ * Check if error is a timeout error.
96
+ */
97
+ export declare function isTimeoutError(error: unknown): boolean;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Complexity Classifier
3
+ *
4
+ * Determines the complexity of an orbital generation request
5
+ * based on the number of orbitals identified during decomposition.
6
+ */
7
+ export type ComplexityLevel = 'simple' | 'medium' | 'complex';
8
+ export interface ComplexityResult {
9
+ level: ComplexityLevel;
10
+ orbitalCount: number;
11
+ recommendedProvider: 'qwen' | 'multi-provider';
12
+ reasoning: string;
13
+ }
14
+ /**
15
+ * Classify complexity based on orbital count
16
+ *
17
+ * Simple: 1 orbital
18
+ * Medium: 2-3 orbitals
19
+ * Complex: 4+ orbitals
20
+ */
21
+ export declare function classifyComplexity(orbitalCount: number): ComplexityResult;
22
+ /**
23
+ * Quick complexity check without full decomposition
24
+ * Based on keywords and request length heuristics
25
+ */
26
+ export declare function estimateComplexity(prompt: string): {
27
+ estimatedLevel: ComplexityLevel;
28
+ confidence: 'high' | 'medium' | 'low';
29
+ };
30
+ /**
31
+ * Get execution strategy based on complexity
32
+ */
33
+ export declare function getExecutionStrategy(complexity: ComplexityResult): {
34
+ type: 'single' | 'multi-provider';
35
+ provider: string;
36
+ model: string;
37
+ parallelization: number;
38
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Fixing Orchestrator V2 - Enhanced with better prompts and validation
3
+ *
4
+ * Improvements:
5
+ * 1. Error-specific fix prompts with examples
6
+ * 2. Skill context for proper guidance
7
+ * 3. Better validation of fix results
8
+ * 4. More detailed error categorization
9
+ */
10
+ import type { OrbitalSchema } from '@almadar/core';
11
+ import type { ValidationIssue } from '@almadar/core/types';
12
+ export interface FixPlan {
13
+ summary: {
14
+ totalErrors: number;
15
+ criticalErrors: number;
16
+ warningErrors: number;
17
+ affectedOrbitals: string[];
18
+ };
19
+ executionOrder: FixStep[];
20
+ parallelizationStrategy: 'single' | 'multi-provider' | 'chunked';
21
+ }
22
+ export interface FixStep {
23
+ id: string;
24
+ description: string;
25
+ orbitalIndex: number;
26
+ errorIndices: number[];
27
+ provider: string;
28
+ dependencies: string[];
29
+ errorType: 'binding' | 'schema' | 'state-machine' | 'other';
30
+ }
31
+ export interface FixingResult {
32
+ success: boolean;
33
+ fixedSchema: OrbitalSchema | null;
34
+ plan: FixPlan;
35
+ stepsCompleted: number;
36
+ stepsTotal: number;
37
+ remainingErrors: ValidationIssue[];
38
+ timing: {
39
+ planMs: number;
40
+ executeMs: number;
41
+ verifyMs: number;
42
+ totalMs: number;
43
+ };
44
+ }
45
+ export interface FixingConfig {
46
+ maxRetries?: number;
47
+ verbose?: boolean;
48
+ skillContent?: string;
49
+ }
50
+ /**
51
+ * Main fixing orchestrator - Enhanced Version
52
+ */
53
+ export declare function orchestrateFixingV2(schema: OrbitalSchema, config?: FixingConfig): Promise<FixingResult>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Orchestration Module
3
+ *
4
+ * Complexity-based provider routing for generation and fixing workflows.
5
+ *
6
+ * ## Generation Routing
7
+ *
8
+ * ```typescript
9
+ * const result = await routeGeneration(prompt, skillContent, {
10
+ * anthropicApiKey: process.env.ANTHROPIC_API_KEY,
11
+ * deepseekApiKey: process.env.DEEPSEEK_API_KEY,
12
+ * openRouterApiKey: process.env.OPEN_ROUTER_API_KEY,
13
+ * });
14
+ *
15
+ * // result.complexity.level: 'simple' | 'medium' | 'complex'
16
+ * // result.provider: routing decision
17
+ * // result.orbitals: generated orbital definitions
18
+ * ```
19
+ *
20
+ * ## Complexity Classification
21
+ *
22
+ * - **Simple** (1 orbital): Qwen 397B (fastest, cheapest)
23
+ * - **Medium** (2-3 orbitals): Qwen 397B (good speed/cost balance)
24
+ * - **Complex** (4+ orbitals): Multi-provider parallel (DeepSeek + Qwen)
25
+ */
26
+ export { classifyComplexity, estimateComplexity, getExecutionStrategy, } from './complexity-classifier.js';
27
+ export type { ComplexityLevel, ComplexityResult, } from './complexity-classifier.js';
28
+ export { routeGeneration, quickComplexityCheck, } from './provider-router.js';
29
+ export type { RouteConfig, GenerationResult, DecomposedUnit, } from './provider-router.js';
30
+ export { orchestrateFixingV2 as orchestrateFixing, } from './fixing-orchestrator.js';
31
+ export type { FixPlan, FixStep, FixingResult, FixingConfig, } from './fixing-orchestrator.js';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Provider Router
3
+ *
4
+ * Routes generation and fixing requests to the appropriate provider(s)
5
+ * based on complexity analysis.
6
+ */
7
+ import type { OrbitalDefinition } from '@almadar/core';
8
+ import { type ComplexityResult } from './complexity-classifier.js';
9
+ export interface RouteConfig {
10
+ /** Optional: Override default verbosity */
11
+ verbose?: boolean;
12
+ }
13
+ export interface GenerationResult {
14
+ orbitals: OrbitalDefinition[];
15
+ complexity: ComplexityResult;
16
+ timing: {
17
+ decomposeMs: number;
18
+ generateMs: number;
19
+ totalMs: number;
20
+ };
21
+ provider: string;
22
+ }
23
+ export interface DecomposedUnit {
24
+ name: string;
25
+ entity: string;
26
+ traits: string[];
27
+ }
28
+ /**
29
+ * Main routing function for generation
30
+ *
31
+ * 1. Decomposes the request
32
+ * 2. Classifies complexity
33
+ * 3. Routes to appropriate provider(s)
34
+ * 4. Returns combined results
35
+ */
36
+ export declare function routeGeneration(prompt: string, skillContent: string, config?: RouteConfig): Promise<GenerationResult>;
37
+ /**
38
+ * Quick check if a request is likely complex
39
+ * Useful for UI feedback before full decomposition
40
+ */
41
+ export declare function quickComplexityCheck(prompt: string): {
42
+ likelyComplex: boolean;
43
+ confidence: 'high' | 'medium' | 'low';
44
+ estimatedOrbitals: number;
45
+ };