@sudocode-ai/local-server 0.1.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.
Files changed (130) hide show
  1. package/README.md +19 -0
  2. package/dist/cli.d.ts +7 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +105 -0
  5. package/dist/cli.js.map +7 -0
  6. package/dist/execution/engine/engine.d.ts +103 -0
  7. package/dist/execution/engine/engine.d.ts.map +1 -0
  8. package/dist/execution/engine/simple-engine.d.ts +190 -0
  9. package/dist/execution/engine/simple-engine.d.ts.map +1 -0
  10. package/dist/execution/engine/types.d.ts +116 -0
  11. package/dist/execution/engine/types.d.ts.map +1 -0
  12. package/dist/execution/output/ag-ui-adapter.d.ts +176 -0
  13. package/dist/execution/output/ag-ui-adapter.d.ts.map +1 -0
  14. package/dist/execution/output/ag-ui-integration.d.ts +96 -0
  15. package/dist/execution/output/ag-ui-integration.d.ts.map +1 -0
  16. package/dist/execution/output/claude-code-output-processor.d.ts +321 -0
  17. package/dist/execution/output/claude-code-output-processor.d.ts.map +1 -0
  18. package/dist/execution/output/index.d.ts +18 -0
  19. package/dist/execution/output/index.d.ts.map +1 -0
  20. package/dist/execution/output/types.d.ts +421 -0
  21. package/dist/execution/output/types.d.ts.map +1 -0
  22. package/dist/execution/process/builders/claude.d.ts +86 -0
  23. package/dist/execution/process/builders/claude.d.ts.map +1 -0
  24. package/dist/execution/process/index.d.ts +15 -0
  25. package/dist/execution/process/index.d.ts.map +1 -0
  26. package/dist/execution/process/manager.d.ts +133 -0
  27. package/dist/execution/process/manager.d.ts.map +1 -0
  28. package/dist/execution/process/simple-manager.d.ts +102 -0
  29. package/dist/execution/process/simple-manager.d.ts.map +1 -0
  30. package/dist/execution/process/types.d.ts +105 -0
  31. package/dist/execution/process/types.d.ts.map +1 -0
  32. package/dist/execution/process/utils.d.ts +53 -0
  33. package/dist/execution/process/utils.d.ts.map +1 -0
  34. package/dist/execution/resilience/circuit-breaker.d.ts +170 -0
  35. package/dist/execution/resilience/circuit-breaker.d.ts.map +1 -0
  36. package/dist/execution/resilience/executor.d.ts +109 -0
  37. package/dist/execution/resilience/executor.d.ts.map +1 -0
  38. package/dist/execution/resilience/index.d.ts +14 -0
  39. package/dist/execution/resilience/index.d.ts.map +1 -0
  40. package/dist/execution/resilience/resilient-executor.d.ts +86 -0
  41. package/dist/execution/resilience/resilient-executor.d.ts.map +1 -0
  42. package/dist/execution/resilience/retry.d.ts +161 -0
  43. package/dist/execution/resilience/retry.d.ts.map +1 -0
  44. package/dist/execution/resilience/types.d.ts +226 -0
  45. package/dist/execution/resilience/types.d.ts.map +1 -0
  46. package/dist/execution/transport/event-buffer.d.ts +119 -0
  47. package/dist/execution/transport/event-buffer.d.ts.map +1 -0
  48. package/dist/execution/transport/index.d.ts +10 -0
  49. package/dist/execution/transport/index.d.ts.map +1 -0
  50. package/dist/execution/transport/sse-transport.d.ts +146 -0
  51. package/dist/execution/transport/sse-transport.d.ts.map +1 -0
  52. package/dist/execution/transport/transport-manager.d.ts +176 -0
  53. package/dist/execution/transport/transport-manager.d.ts.map +1 -0
  54. package/dist/execution/workflow/index.d.ts +13 -0
  55. package/dist/execution/workflow/index.d.ts.map +1 -0
  56. package/dist/execution/workflow/linear-orchestrator.d.ts +216 -0
  57. package/dist/execution/workflow/linear-orchestrator.d.ts.map +1 -0
  58. package/dist/execution/workflow/memory-storage.d.ts +54 -0
  59. package/dist/execution/workflow/memory-storage.d.ts.map +1 -0
  60. package/dist/execution/workflow/orchestrator.d.ts +158 -0
  61. package/dist/execution/workflow/orchestrator.d.ts.map +1 -0
  62. package/dist/execution/workflow/types.d.ts +172 -0
  63. package/dist/execution/workflow/types.d.ts.map +1 -0
  64. package/dist/execution/workflow/utils.d.ts +89 -0
  65. package/dist/execution/workflow/utils.d.ts.map +1 -0
  66. package/dist/execution/worktree/config.d.ts +74 -0
  67. package/dist/execution/worktree/config.d.ts.map +1 -0
  68. package/dist/execution/worktree/git-cli.d.ts +151 -0
  69. package/dist/execution/worktree/git-cli.d.ts.map +1 -0
  70. package/dist/execution/worktree/index.d.ts +16 -0
  71. package/dist/execution/worktree/index.d.ts.map +1 -0
  72. package/dist/execution/worktree/manager.d.ts +184 -0
  73. package/dist/execution/worktree/manager.d.ts.map +1 -0
  74. package/dist/execution/worktree/types.d.ts +90 -0
  75. package/dist/execution/worktree/types.d.ts.map +1 -0
  76. package/dist/index.d.ts +8 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +104 -0
  79. package/dist/index.js.map +7 -0
  80. package/dist/public/assets/index-C4SmlXoo.js +568 -0
  81. package/dist/public/assets/index-C4SmlXoo.js.map +1 -0
  82. package/dist/public/assets/index-DE59j7ti.css +1 -0
  83. package/dist/public/assets/react-vendor-LX0UoTxg.js +60 -0
  84. package/dist/public/assets/react-vendor-LX0UoTxg.js.map +1 -0
  85. package/dist/public/assets/ui-vendor-_cxVHaqZ.js +54 -0
  86. package/dist/public/assets/ui-vendor-_cxVHaqZ.js.map +1 -0
  87. package/dist/public/favicon.ico +0 -0
  88. package/dist/public/index.html +16 -0
  89. package/dist/public/logo.png +0 -0
  90. package/dist/routes/executions-stream.d.ts +24 -0
  91. package/dist/routes/executions-stream.d.ts.map +1 -0
  92. package/dist/routes/executions.d.ts +19 -0
  93. package/dist/routes/executions.d.ts.map +1 -0
  94. package/dist/routes/feedback.d.ts +7 -0
  95. package/dist/routes/feedback.d.ts.map +1 -0
  96. package/dist/routes/issues.d.ts +7 -0
  97. package/dist/routes/issues.d.ts.map +1 -0
  98. package/dist/routes/relationships.d.ts +7 -0
  99. package/dist/routes/relationships.d.ts.map +1 -0
  100. package/dist/routes/specs.d.ts +7 -0
  101. package/dist/routes/specs.d.ts.map +1 -0
  102. package/dist/services/db.d.ts +33 -0
  103. package/dist/services/db.d.ts.map +1 -0
  104. package/dist/services/execution-lifecycle.d.ts +108 -0
  105. package/dist/services/execution-lifecycle.d.ts.map +1 -0
  106. package/dist/services/execution-service.d.ts +185 -0
  107. package/dist/services/execution-service.d.ts.map +1 -0
  108. package/dist/services/executions.d.ts +59 -0
  109. package/dist/services/executions.d.ts.map +1 -0
  110. package/dist/services/export.d.ts +24 -0
  111. package/dist/services/export.d.ts.map +1 -0
  112. package/dist/services/feedback.d.ts +40 -0
  113. package/dist/services/feedback.d.ts.map +1 -0
  114. package/dist/services/issues.d.ts +27 -0
  115. package/dist/services/issues.d.ts.map +1 -0
  116. package/dist/services/prompt-template-engine.d.ts +108 -0
  117. package/dist/services/prompt-template-engine.d.ts.map +1 -0
  118. package/dist/services/prompt-templates.d.ts +97 -0
  119. package/dist/services/prompt-templates.d.ts.map +1 -0
  120. package/dist/services/relationships.d.ts +35 -0
  121. package/dist/services/relationships.d.ts.map +1 -0
  122. package/dist/services/specs.d.ts +27 -0
  123. package/dist/services/specs.d.ts.map +1 -0
  124. package/dist/services/watcher.d.ts +50 -0
  125. package/dist/services/watcher.d.ts.map +1 -0
  126. package/dist/services/websocket.d.ts +127 -0
  127. package/dist/services/websocket.d.ts.map +1 -0
  128. package/dist/utils/sudocode-dir.d.ts +6 -0
  129. package/dist/utils/sudocode-dir.d.ts.map +1 -0
  130. package/package.json +74 -0
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Retry Logic and Backoff Strategies
3
+ *
4
+ * Implements retry logic with various backoff strategies including
5
+ * exponential, linear, and fixed delays with optional jitter.
6
+ *
7
+ * @module execution/resilience/retry
8
+ */
9
+ import type { RetryPolicy, ExecutionAttempt } from './types.js';
10
+ import type { ExecutionResult } from '../engine/types.js';
11
+ /**
12
+ * Calculate backoff delay for a given attempt
13
+ *
14
+ * Supports multiple backoff strategies:
15
+ * - Exponential: baseDelay * 2^(attempt-1) - e.g., 1s, 2s, 4s, 8s, 16s
16
+ * - Linear: baseDelay * attempt - e.g., 1s, 2s, 3s, 4s, 5s
17
+ * - Fixed: constant baseDelay - e.g., 1s, 1s, 1s, 1s, 1s
18
+ *
19
+ * Applies maxDelay cap and optional jitter to prevent thundering herd.
20
+ *
21
+ * @param attempt - Attempt number (1-indexed)
22
+ * @param config - Backoff configuration from retry policy
23
+ * @returns Delay in milliseconds
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Exponential backoff with jitter
28
+ * const delay = calculateBackoff(3, {
29
+ * type: 'exponential',
30
+ * baseDelayMs: 1000,
31
+ * maxDelayMs: 30000,
32
+ * jitter: true,
33
+ * });
34
+ * // Returns ~4000ms ± 10% jitter
35
+ * ```
36
+ */
37
+ export declare function calculateBackoff(attempt: number, config: RetryPolicy['backoff']): number;
38
+ /**
39
+ * Check if an error should trigger a retry
40
+ *
41
+ * Matches error message against the list of retryable error patterns
42
+ * defined in the retry policy.
43
+ *
44
+ * @param error - Error that occurred
45
+ * @param policy - Retry policy with retryable error patterns
46
+ * @returns True if error should be retried
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const error = new Error('Connection timeout');
51
+ * const shouldRetry = isRetryableError(error, {
52
+ * retryableErrors: ['timeout', 'ECONNREFUSED'],
53
+ * // ... other policy fields
54
+ * });
55
+ * // Returns true
56
+ * ```
57
+ */
58
+ export declare function isRetryableError(error: Error, policy: RetryPolicy): boolean;
59
+ /**
60
+ * Check if an exit code should trigger a retry
61
+ *
62
+ * Matches exit code against the list of retryable exit codes
63
+ * defined in the retry policy.
64
+ *
65
+ * @param exitCode - Process exit code
66
+ * @param policy - Retry policy with retryable exit codes
67
+ * @returns True if exit code should be retried
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const shouldRetry = isRetryableExitCode(1, {
72
+ * retryableExitCodes: [1, 137],
73
+ * // ... other policy fields
74
+ * });
75
+ * // Returns true
76
+ * ```
77
+ */
78
+ export declare function isRetryableExitCode(exitCode: number, policy: RetryPolicy): boolean;
79
+ /**
80
+ * Check if an execution result should trigger a retry
81
+ *
82
+ * Checks both the exit code and error message (if present) to determine
83
+ * if the execution should be retried.
84
+ *
85
+ * @param result - Execution result from task execution
86
+ * @param policy - Retry policy
87
+ * @returns True if execution should be retried
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const result: ExecutionResult = {
92
+ * taskId: 'task-1',
93
+ * executionId: 'proc-123',
94
+ * success: false,
95
+ * exitCode: 1,
96
+ * error: 'Connection timeout',
97
+ * // ... other fields
98
+ * };
99
+ *
100
+ * const shouldRetry = isRetryableResult(result, policy);
101
+ * // Returns true if exitCode is retryable OR error contains retryable pattern
102
+ * ```
103
+ */
104
+ export declare function isRetryableResult(result: ExecutionResult, policy: RetryPolicy): boolean;
105
+ /**
106
+ * Promise-based sleep utility
107
+ *
108
+ * Returns a promise that resolves after the specified delay.
109
+ * Useful for implementing retry backoff.
110
+ *
111
+ * @param ms - Delay in milliseconds
112
+ * @returns Promise that resolves after delay
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * console.log('Starting...');
117
+ * await sleep(1000);
118
+ * console.log('1 second later');
119
+ * ```
120
+ */
121
+ export declare function sleep(ms: number): Promise<void>;
122
+ /**
123
+ * Create an execution attempt record
124
+ *
125
+ * Helper function to create a properly structured ExecutionAttempt object.
126
+ *
127
+ * @param attemptNumber - Attempt number (1-indexed)
128
+ * @param success - Whether the attempt succeeded
129
+ * @param options - Optional fields for the attempt
130
+ * @returns ExecutionAttempt object
131
+ */
132
+ export declare function createAttempt(attemptNumber: number, success: boolean, options?: {
133
+ error?: Error;
134
+ exitCode?: number;
135
+ duration?: number;
136
+ willRetry?: boolean;
137
+ nextRetryAt?: Date;
138
+ }): ExecutionAttempt;
139
+ /**
140
+ * Calculate total delay from all retry attempts
141
+ *
142
+ * Sums up all the backoff delays that would be applied for a given
143
+ * number of retry attempts. Useful for timeout calculations.
144
+ *
145
+ * @param maxAttempts - Maximum number of attempts
146
+ * @param backoffConfig - Backoff configuration
147
+ * @returns Total delay in milliseconds
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const totalDelay = calculateTotalRetryDelay(3, {
152
+ * type: 'exponential',
153
+ * baseDelayMs: 1000,
154
+ * maxDelayMs: 30000,
155
+ * jitter: false,
156
+ * });
157
+ * // Returns 7000ms (1s + 2s + 4s)
158
+ * ```
159
+ */
160
+ export declare function calculateTotalRetryDelay(maxAttempts: number, backoffConfig: RetryPolicy['backoff']): number;
161
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,GAC7B,MAAM,CAyCR;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAW3E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,WAAW,GAClB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,WAAW,GAClB,OAAO,CAiBT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,IAAI,CAAC;CACf,GACL,gBAAgB,CAclB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,WAAW,CAAC,SAAS,CAAC,GACpC,MAAM,CASR"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Resilience Layer Types
3
+ *
4
+ * Core types for the Resilience Layer (Layer 3) that adds retry logic,
5
+ * circuit breakers, and fault tolerance to task execution.
6
+ *
7
+ * @module execution/resilience/types
8
+ */
9
+ import type { ExecutionResult } from '../engine/types.js';
10
+ /**
11
+ * RetryPolicy - Configuration for retry behavior
12
+ */
13
+ export interface RetryPolicy {
14
+ /**
15
+ * Maximum number of retry attempts (0 = no retry)
16
+ */
17
+ maxAttempts: number;
18
+ /**
19
+ * Backoff strategy configuration
20
+ */
21
+ backoff: {
22
+ /**
23
+ * Type of backoff strategy
24
+ * - exponential: delay = baseDelay * 2^(attempt-1)
25
+ * - linear: delay = baseDelay * attempt
26
+ * - fixed: delay = baseDelay (constant)
27
+ */
28
+ type: 'exponential' | 'linear' | 'fixed';
29
+ /**
30
+ * Initial delay in milliseconds
31
+ */
32
+ baseDelayMs: number;
33
+ /**
34
+ * Maximum delay cap in milliseconds
35
+ */
36
+ maxDelayMs: number;
37
+ /**
38
+ * Add randomness to prevent thundering herd
39
+ * Adds ±10% jitter to delay
40
+ */
41
+ jitter: boolean;
42
+ };
43
+ /**
44
+ * Error types/messages that should trigger a retry
45
+ * Examples: 'ECONNREFUSED', 'timeout', 'network'
46
+ */
47
+ retryableErrors: string[];
48
+ /**
49
+ * Exit codes that should trigger a retry
50
+ * Examples: [1, 137] for generic error and SIGKILL
51
+ */
52
+ retryableExitCodes: number[];
53
+ /**
54
+ * Optional callback to determine if circuit breaker should open
55
+ */
56
+ shouldOpenCircuit?: (error: Error, attempts: number) => boolean;
57
+ }
58
+ /**
59
+ * CircuitState - State of a circuit breaker
60
+ */
61
+ export type CircuitState = 'closed' | 'open' | 'half-open';
62
+ /**
63
+ * CircuitBreaker - Circuit breaker for preventing cascading failures
64
+ */
65
+ export interface CircuitBreaker {
66
+ /**
67
+ * Unique name for this circuit breaker
68
+ * Typically matches the task type (e.g., 'issue', 'spec', 'custom')
69
+ */
70
+ name: string;
71
+ /**
72
+ * Current state of the circuit
73
+ * - closed: Normal operation, requests pass through
74
+ * - open: Too many failures, requests rejected
75
+ * - half-open: Testing if service recovered, limited requests allowed
76
+ */
77
+ state: CircuitState;
78
+ /**
79
+ * Circuit breaker configuration
80
+ */
81
+ config: {
82
+ /**
83
+ * Number of consecutive failures before opening circuit
84
+ */
85
+ failureThreshold: number;
86
+ /**
87
+ * Number of consecutive successes in half-open to close circuit
88
+ */
89
+ successThreshold: number;
90
+ /**
91
+ * Time to wait before transitioning from open to half-open (ms)
92
+ */
93
+ timeout: number;
94
+ };
95
+ /**
96
+ * Circuit breaker metrics
97
+ */
98
+ metrics: {
99
+ /**
100
+ * Total requests processed
101
+ */
102
+ totalRequests: number;
103
+ /**
104
+ * Total failed requests
105
+ */
106
+ failedRequests: number;
107
+ /**
108
+ * Total successful requests
109
+ */
110
+ successfulRequests: number;
111
+ /**
112
+ * Timestamp of last failure
113
+ */
114
+ lastFailureTime?: Date;
115
+ /**
116
+ * Timestamp of last success
117
+ */
118
+ lastSuccessTime?: Date;
119
+ };
120
+ }
121
+ /**
122
+ * ExecutionAttempt - Record of a single execution attempt
123
+ */
124
+ export interface ExecutionAttempt {
125
+ /**
126
+ * Attempt number (1-indexed)
127
+ */
128
+ attemptNumber: number;
129
+ /**
130
+ * When this attempt started
131
+ */
132
+ startedAt: Date;
133
+ /**
134
+ * When this attempt completed (if finished)
135
+ */
136
+ completedAt?: Date;
137
+ /**
138
+ * Duration of this attempt in milliseconds
139
+ */
140
+ duration?: number;
141
+ /**
142
+ * Whether this attempt succeeded
143
+ */
144
+ success: boolean;
145
+ /**
146
+ * Error that occurred during this attempt
147
+ */
148
+ error?: Error;
149
+ /**
150
+ * Exit code from this attempt
151
+ */
152
+ exitCode?: number;
153
+ /**
154
+ * Whether another retry will be attempted after this
155
+ */
156
+ willRetry: boolean;
157
+ /**
158
+ * When the next retry will occur (if willRetry is true)
159
+ */
160
+ nextRetryAt?: Date;
161
+ }
162
+ /**
163
+ * ResilientExecutionResult - Enhanced execution result with retry information
164
+ *
165
+ * Extends the base ExecutionResult with detailed retry tracking
166
+ */
167
+ export interface ResilientExecutionResult extends ExecutionResult {
168
+ /**
169
+ * All execution attempts made for this task
170
+ */
171
+ attempts: ExecutionAttempt[];
172
+ /**
173
+ * Total number of attempts made
174
+ */
175
+ totalAttempts: number;
176
+ /**
177
+ * The final attempt (may be success or failure)
178
+ */
179
+ finalAttempt: ExecutionAttempt;
180
+ /**
181
+ * Human-readable reason for failure (if failed)
182
+ */
183
+ failureReason?: string;
184
+ /**
185
+ * Whether the circuit breaker prevented execution
186
+ */
187
+ circuitBreakerTriggered?: boolean;
188
+ }
189
+ /**
190
+ * RetryMetrics - Aggregate metrics for retry behavior
191
+ */
192
+ export interface RetryMetrics {
193
+ /**
194
+ * Total number of retries attempted across all tasks
195
+ */
196
+ totalRetries: number;
197
+ /**
198
+ * Number of retries that eventually succeeded
199
+ */
200
+ successfulRetries: number;
201
+ /**
202
+ * Number of retries that ultimately failed
203
+ */
204
+ failedRetries: number;
205
+ /**
206
+ * Average number of attempts needed for successful tasks
207
+ */
208
+ averageAttemptsToSuccess: number;
209
+ /**
210
+ * Circuit breakers by name
211
+ */
212
+ circuitBreakers: Map<string, CircuitBreaker>;
213
+ }
214
+ /**
215
+ * RetryAttemptHandler - Callback for retry attempt events
216
+ */
217
+ export type RetryAttemptHandler = (taskId: string, attempt: ExecutionAttempt) => void;
218
+ /**
219
+ * CircuitOpenHandler - Callback for circuit breaker open events
220
+ */
221
+ export type CircuitOpenHandler = (circuitName: string, breaker: CircuitBreaker) => void;
222
+ /**
223
+ * Default retry policy for resilient execution
224
+ */
225
+ export declare const DEFAULT_RETRY_POLICY: RetryPolicy;
226
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE;QACP;;;;;WAKG;QACH,IAAI,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC;QAEzC;;WAEG;QACH,WAAW,EAAE,MAAM,CAAC;QAEpB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;QAEnB;;;WAGG;QACH,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IAEF;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAE1B;;;OAGG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAE7B;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CACjE;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;OAKG;IACH,KAAK,EAAE,YAAY,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE;QACN;;WAEG;QACH,gBAAgB,EAAE,MAAM,CAAC;QAEzB;;WAEG;QACH,gBAAgB,EAAE,MAAM,CAAC;QAEzB;;WAEG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE;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EG;IACH,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,KACtB,IAAI,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,KACpB,IAAI,CAAC;AAEV;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAiBlC,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Execution Event Buffer
3
+ *
4
+ * Stores AG-UI events for executions so they can be replayed to late-joining clients
5
+ * or retrieved for historical display.
6
+ *
7
+ * @module execution/transport/event-buffer
8
+ */
9
+ import type { AgUiEvent } from "./transport-manager.js";
10
+ /**
11
+ * Buffered event with metadata
12
+ */
13
+ export interface BufferedEvent {
14
+ /** The AG-UI event */
15
+ event: AgUiEvent;
16
+ /** When the event was buffered */
17
+ timestamp: number;
18
+ /** Event sequence number within the execution */
19
+ sequenceNumber: number;
20
+ }
21
+ /**
22
+ * Event buffer for a single execution
23
+ */
24
+ export interface ExecutionEventBuffer {
25
+ /** Execution/run ID */
26
+ executionId: string;
27
+ /** Buffered events in order */
28
+ events: BufferedEvent[];
29
+ /** Next sequence number */
30
+ nextSequence: number;
31
+ /** When the buffer was created */
32
+ createdAt: number;
33
+ /** When the buffer was last updated */
34
+ lastUpdatedAt: number;
35
+ }
36
+ /**
37
+ * EventBuffer - In-memory storage for execution events
38
+ *
39
+ * Stores events for active executions and allows replay when clients connect.
40
+ * Events are automatically pruned after executions complete to prevent memory leaks.
41
+ */
42
+ export declare class EventBuffer {
43
+ private buffers;
44
+ private readonly MAX_EVENTS_PER_EXECUTION;
45
+ private readonly RETENTION_MS;
46
+ /**
47
+ * Add an event to the buffer for an execution
48
+ *
49
+ * @param executionId - Execution ID
50
+ * @param event - AG-UI event to buffer
51
+ */
52
+ addEvent(executionId: string, event: AgUiEvent): void;
53
+ /**
54
+ * Get all buffered events for an execution
55
+ *
56
+ * @param executionId - Execution ID
57
+ * @param fromSequence - Optional: only return events >= this sequence number
58
+ * @returns Array of buffered events, or empty array if no buffer exists
59
+ */
60
+ getEvents(executionId: string, fromSequence?: number): BufferedEvent[];
61
+ /**
62
+ * Check if a buffer exists for an execution
63
+ *
64
+ * @param executionId - Execution ID
65
+ * @returns true if buffer exists
66
+ */
67
+ hasBuffer(executionId: string): boolean;
68
+ /**
69
+ * Get buffer metadata without events
70
+ *
71
+ * @param executionId - Execution ID
72
+ * @returns Buffer metadata or null if not found
73
+ */
74
+ getBufferInfo(executionId: string): Omit<ExecutionEventBuffer, "events"> | null;
75
+ /**
76
+ * Remove a buffer for an execution
77
+ *
78
+ * @param executionId - Execution ID
79
+ * @returns true if buffer was removed, false if it didn't exist
80
+ */
81
+ removeBuffer(executionId: string): boolean;
82
+ /**
83
+ * Clear all buffers
84
+ */
85
+ clearAll(): void;
86
+ /**
87
+ * Prune stale buffers that haven't been updated recently
88
+ *
89
+ * Should be called periodically to prevent memory leaks.
90
+ *
91
+ * @returns Number of buffers pruned
92
+ */
93
+ pruneStale(): number;
94
+ /**
95
+ * Get total number of buffers
96
+ *
97
+ * @returns Number of active buffers
98
+ */
99
+ getBufferCount(): number;
100
+ /**
101
+ * Get total number of events across all buffers
102
+ *
103
+ * @returns Total event count
104
+ */
105
+ getTotalEventCount(): number;
106
+ /**
107
+ * Get statistics about buffer usage
108
+ *
109
+ * @returns Buffer statistics
110
+ */
111
+ getStats(): {
112
+ bufferCount: number;
113
+ totalEvents: number;
114
+ avgEventsPerBuffer: number;
115
+ oldestBuffer: number | null;
116
+ newestBuffer: number | null;
117
+ };
118
+ }
119
+ //# sourceMappingURL=event-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-buffer.d.ts","sourceRoot":"","sources":["../../../src/execution/transport/event-buffer.ts"],"names":[],"mappings":"AA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M;IAIxB;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;IAQ5B;;;;OAIG;IACH,QAAQ,IAAI;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;KAC7B;CAwBF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Transport Layer
3
+ *
4
+ * Exports transport implementations for streaming AG-UI events to clients.
5
+ *
6
+ * @module execution/transport
7
+ */
8
+ export { SseTransport } from './sse-transport.js';
9
+ export { TransportManager } from './transport-manager.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/execution/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Server-Sent Events (SSE) Transport Layer
3
+ *
4
+ * Provides real-time streaming of AG-UI events to frontend clients using SSE.
5
+ * Supports connection management, heartbeat, and run-specific event filtering.
6
+ *
7
+ * @module execution/transport/sse-transport
8
+ */
9
+ import type { Response } from "express";
10
+ /**
11
+ * SSE Event to send to clients
12
+ *
13
+ * Follows the SSE specification format
14
+ */
15
+ interface SseEvent {
16
+ /** Event type (optional, defaults to 'message') */
17
+ event?: string;
18
+ /** Event data (will be JSON stringified) */
19
+ data: any;
20
+ /** Event ID (optional) */
21
+ id?: string;
22
+ }
23
+ /**
24
+ * SseTransport - Server-Sent Events transport for AG-UI events
25
+ *
26
+ * Manages SSE connections and streams AG-UI protocol events to connected clients.
27
+ * Supports multiple concurrent connections, heartbeat mechanism, and run-specific filtering.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const transport = new SseTransport();
32
+ *
33
+ * // Handle new connection
34
+ * app.get('/api/events', (req, res) => {
35
+ * const clientId = req.query.clientId as string;
36
+ * const runId = req.query.runId as string | undefined;
37
+ * transport.handleConnection(clientId, res, runId);
38
+ * });
39
+ *
40
+ * // Send event to specific client
41
+ * transport.sendToClient('client-123', {
42
+ * event: 'TOOL_CALL_START',
43
+ * data: { type: 'TOOL_CALL_START', toolCallId: 'tool-1' }
44
+ * });
45
+ *
46
+ * // Broadcast to all clients watching a specific run
47
+ * transport.broadcastToRun('run-123', {
48
+ * event: 'RUN_FINISHED',
49
+ * data: { type: 'RUN_FINISHED', runId: 'run-123' }
50
+ * });
51
+ * ```
52
+ */
53
+ export declare class SseTransport {
54
+ private clients;
55
+ private heartbeatInterval;
56
+ private readonly HEARTBEAT_INTERVAL_MS;
57
+ /**
58
+ * Create a new SSE transport instance
59
+ */
60
+ constructor();
61
+ /**
62
+ * Handle a new SSE connection from a client
63
+ *
64
+ * Sets up proper SSE headers, registers the client, and handles cleanup on disconnect.
65
+ *
66
+ * @param clientId - Unique identifier for this client
67
+ * @param res - Express response object
68
+ * @param runId - Optional run ID to filter events
69
+ * @param replayEvents - Optional: buffered events to replay to this client
70
+ */
71
+ handleConnection(clientId: string, res: Response, runId?: string, replayEvents?: Array<{
72
+ event: string;
73
+ data: any;
74
+ }>): void;
75
+ /**
76
+ * Send an event to a specific client
77
+ *
78
+ * @param clientId - Target client ID
79
+ * @param event - Event to send
80
+ * @returns true if sent successfully, false if client not found
81
+ */
82
+ sendToClient(clientId: string, event: SseEvent): boolean;
83
+ /**
84
+ * Broadcast an event to all connected clients
85
+ *
86
+ * @param event - Event to broadcast
87
+ * @returns Number of clients that received the event
88
+ */
89
+ broadcast(event: SseEvent): number;
90
+ /**
91
+ * Broadcast an event to all clients watching a specific run
92
+ *
93
+ * @param runId - Target run ID
94
+ * @param event - Event to send
95
+ * @returns Number of clients that received the event
96
+ */
97
+ broadcastToRun(runId: string, event: SseEvent): number;
98
+ /**
99
+ * Remove a client connection
100
+ *
101
+ * @param clientId - Client to remove
102
+ * @returns true if client was removed, false if not found
103
+ */
104
+ removeClient(clientId: string): boolean;
105
+ /**
106
+ * Get the number of active connections
107
+ *
108
+ * @returns Number of connected clients
109
+ */
110
+ getClientCount(): number;
111
+ /**
112
+ * Get the number of clients watching a specific run
113
+ *
114
+ * @param runId - Run ID to check
115
+ * @returns Number of clients watching this run
116
+ */
117
+ getRunClientCount(runId: string): number;
118
+ /**
119
+ * Get all active client IDs
120
+ *
121
+ * @returns Array of client IDs
122
+ */
123
+ getClientIds(): string[];
124
+ /**
125
+ * Shutdown the transport and close all connections
126
+ */
127
+ shutdown(): void;
128
+ /**
129
+ * Write an event to a client connection
130
+ *
131
+ * Formats the event according to SSE specification and writes it to the response.
132
+ *
133
+ * @param client - Target client
134
+ * @param event - Event to write
135
+ * @returns true if successful, false if write failed
136
+ */
137
+ private writeEvent;
138
+ /**
139
+ * Start the heartbeat mechanism
140
+ *
141
+ * Sends periodic ping events to keep connections alive
142
+ */
143
+ private startHeartbeat;
144
+ }
145
+ export {};
146
+ //# sourceMappingURL=sse-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-transport.d.ts","sourceRoot":"","sources":["../../../src/execution/transport/sse-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAoBxC;;;;GAIG;AACH,UAAU,QAAQ;IAChB,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,IAAI,EAAE,GAAG,CAAC;IACV,0BAA0B;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC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