@almadar/agent 1.6.4 → 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.
- package/LICENSE +21 -72
- package/README.md +25 -0
- package/dist/agent/event-budget.d.ts +28 -0
- package/dist/agent/experimental/hitl-v2.d.ts +161 -0
- package/dist/agent/experimental/hitl-workflow-integration.d.ts +182 -0
- package/dist/agent/index.d.ts +14 -13
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/interrupt-config.d.ts +51 -0
- package/dist/agent/session-manager.d.ts +204 -0
- package/dist/agent/skill-agent.d.ts +182 -0
- package/dist/agent/workflow-middleware.d.ts +63 -0
- package/dist/agent/workflow-tool-wrapper.d.ts +87 -0
- package/dist/{api-types-CXrq-fts.d.ts → api-types.d.ts} +85 -51
- package/dist/context/compaction.d.ts +191 -0
- package/dist/context-compaction.d.ts +55 -0
- package/dist/evals/online-sampling.d.ts +114 -0
- package/dist/evals/utils/compact-orbital.d.ts +100 -0
- package/dist/event-transformer/event-transformer.d.ts +120 -0
- package/dist/event-transformer/index.d.ts +4 -122
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +58 -1678
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryManager.d.ts +243 -0
- package/dist/memory/PreferenceLearner.d.ts +59 -0
- package/dist/memory/agentic-search.d.ts +116 -0
- package/dist/memory/index.d.ts +14 -0
- package/dist/memory/memory-orbital.d.ts +66 -0
- package/dist/memory/types.d.ts +143 -0
- package/dist/metrics.d.ts +77 -0
- package/dist/multi-user.d.ts +155 -0
- package/dist/observability/index.d.ts +14 -0
- package/dist/observability/langsmith-integration.d.ts +203 -0
- package/dist/observability.d.ts +196 -0
- package/dist/orbitals/archive/sanitize.d.ts +24 -0
- package/dist/orbitals/batch/batch-generator.d.ts +41 -0
- package/dist/orbitals/batch/concurrency.d.ts +54 -0
- package/dist/orbitals/batch/index.d.ts +14 -0
- package/dist/orbitals/batch/prompt-assembler.d.ts +92 -0
- package/dist/orbitals/batch/types.d.ts +103 -0
- package/dist/orbitals/cache/index.d.ts +11 -0
- package/dist/orbitals/cache/orbital-fingerprint.d.ts +37 -0
- package/dist/orbitals/cache/prompt-assembler.d.ts +65 -0
- package/dist/orbitals/cache/structural-templates.d.ts +33 -0
- package/dist/orbitals/combiner/index.d.ts +102 -0
- package/dist/orbitals/domain-language/index.d.ts +9 -0
- package/dist/orbitals/domain-language/prompts/index.d.ts +11 -0
- package/dist/orbitals/domain-language/prompts/odl-examples.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-patterns.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-syntax.d.ts +8 -0
- package/dist/orbitals/domain-language/prompts/odl-to-schema.d.ts +8 -0
- package/dist/orbitals/generation/index.d.ts +10 -0
- package/dist/orbitals/generation/orbital-generator.d.ts +120 -0
- package/dist/orbitals/shared/constants.d.ts +65 -0
- package/dist/orbitals/shared/index.d.ts +11 -0
- package/dist/orbitals/shared/types.d.ts +187 -0
- package/dist/orbitals/shared/utils.d.ts +97 -0
- package/dist/orchestration/complexity-classifier.d.ts +38 -0
- package/dist/orchestration/fixing-orchestrator.d.ts +53 -0
- package/dist/orchestration/index.d.ts +31 -0
- package/dist/orchestration/provider-router.d.ts +45 -0
- package/dist/{firestore-checkpointer-CkNKXoun.d.ts → persistence/firestore-checkpointer.d.ts} +13 -58
- package/dist/persistence/firestore-session-store.d.ts +75 -0
- package/dist/persistence/firestore-store.d.ts +86 -0
- package/dist/persistence/index.d.ts +7 -198
- package/dist/persistence/memory-backend.d.ts +33 -0
- package/dist/persistence/types.d.ts +40 -0
- package/dist/security/audit-log.d.ts +44 -0
- package/dist/state-sync.d.ts +171 -0
- package/dist/subagents.d.ts +38 -0
- package/dist/tools/combine-schemas.d.ts +154 -0
- package/dist/tools/composition.d.ts +119 -0
- package/dist/{orbital-subagent-BdFuf77p.d.ts → tools/domain-orbital.d.ts} +22 -461
- package/dist/tools/execute.d.ts +38 -0
- package/dist/tools/finish-task.d.ts +56 -0
- package/dist/tools/generate-schema.d.ts +53 -0
- package/dist/tools/github.d.ts +297 -0
- package/dist/tools/index.d.ts +1318 -8
- package/dist/tools/orbital-batch-subagent.d.ts +85 -0
- package/dist/tools/orbital-subagent.d.ts +454 -0
- package/dist/tools/orchestrated-fixing.d.ts +74 -0
- package/dist/tools/orchestrated-generation.d.ts +75 -0
- package/dist/tools/sandbox-executor.d.ts +31 -0
- package/dist/tools/schema-chunking.d.ts +117 -0
- package/dist/tools/trait-subagent.d.ts +179 -0
- package/dist/tools/validate-schema.d.ts +17 -0
- package/dist/types.d.ts +14 -17
- package/dist/utils/safety/capability-token.d.ts +50 -0
- package/dist/utils/safety/circuit-breaker.d.ts +71 -0
- package/dist/utils/safety/index.d.ts +19 -0
- package/dist/utils/safety/rate-limiter.d.ts +39 -0
- package/dist/utils/safety/threshold-auth.d.ts +70 -0
- package/dist/workspace/git-client.d.ts +51 -0
- package/dist/workspace/index.d.ts +29 -346
- package/dist/workspace/index.js +39 -0
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/memory-files.d.ts +31 -0
- package/dist/workspace/sink-manager.d.ts +26 -0
- package/dist/workspace/sinks/firestore-sink.d.ts +41 -0
- package/dist/workspace/sinks/git-sink.d.ts +47 -0
- package/dist/workspace/sinks/index.d.ts +9 -0
- package/dist/workspace/templates.d.ts +32 -0
- package/dist/workspace/types.d.ts +86 -0
- package/dist/workspace/workspace-manager.d.ts +57 -0
- package/package.json +12 -10
- package/dist/index-DW3F-Ihx.d.ts +0 -2501
- package/dist/index-DZn69no8.d.ts +0 -1014
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* DeepAgent API Types
|
|
5
3
|
*
|
|
@@ -8,12 +6,12 @@ import { z } from 'zod';
|
|
|
8
6
|
*
|
|
9
7
|
* @packageDocumentation
|
|
10
8
|
*/
|
|
11
|
-
|
|
9
|
+
import { z } from 'zod';
|
|
12
10
|
/**
|
|
13
11
|
* Extracted requirements schema - from analysis phase.
|
|
14
12
|
* Used to provide more precise generation guidance.
|
|
15
13
|
*/
|
|
16
|
-
declare const ExtractedRequirementsSchema: z.ZodObject<{
|
|
14
|
+
export declare const ExtractedRequirementsSchema: z.ZodObject<{
|
|
17
15
|
/** Entity names to create */
|
|
18
16
|
entities: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
19
17
|
/** State names that should exist */
|
|
@@ -45,11 +43,11 @@ declare const ExtractedRequirementsSchema: z.ZodObject<{
|
|
|
45
43
|
effects?: string[] | undefined;
|
|
46
44
|
rawRequirements?: string[] | undefined;
|
|
47
45
|
}>;
|
|
48
|
-
type ExtractedRequirementsInput = z.infer<typeof ExtractedRequirementsSchema>;
|
|
46
|
+
export type ExtractedRequirementsInput = z.infer<typeof ExtractedRequirementsSchema>;
|
|
49
47
|
/**
|
|
50
48
|
* Generate request schema - skills only, no custom prompts.
|
|
51
49
|
*/
|
|
52
|
-
declare const GenerateRequestSchema: z.ZodObject<{
|
|
50
|
+
export declare const GenerateRequestSchema: z.ZodObject<{
|
|
53
51
|
/** Required: The skill(s) to use for this generation */
|
|
54
52
|
skill: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
|
|
55
53
|
/** The user's task/message */
|
|
@@ -167,11 +165,11 @@ declare const GenerateRequestSchema: z.ZodObject<{
|
|
|
167
165
|
} | undefined;
|
|
168
166
|
useOrchestration?: boolean | undefined;
|
|
169
167
|
}>;
|
|
170
|
-
type GenerateRequest = z.infer<typeof GenerateRequestSchema>;
|
|
168
|
+
export type GenerateRequest = z.infer<typeof GenerateRequestSchema>;
|
|
171
169
|
/**
|
|
172
170
|
* Resume request schema - for resuming after interrupt.
|
|
173
171
|
*/
|
|
174
|
-
declare const ResumeRequestSchema: z.ZodObject<{
|
|
172
|
+
export declare const ResumeRequestSchema: z.ZodObject<{
|
|
175
173
|
/** Required: Thread ID to resume */
|
|
176
174
|
threadId: z.ZodString;
|
|
177
175
|
/** Required: Decisions for pending interrupts */
|
|
@@ -202,11 +200,18 @@ declare const ResumeRequestSchema: z.ZodObject<{
|
|
|
202
200
|
}[];
|
|
203
201
|
approveAll?: boolean | undefined;
|
|
204
202
|
}>;
|
|
205
|
-
type ResumeRequest = z.infer<typeof ResumeRequestSchema>;
|
|
203
|
+
export type ResumeRequest = z.infer<typeof ResumeRequestSchema>;
|
|
204
|
+
/**
|
|
205
|
+
* Decision type for interrupt responses.
|
|
206
|
+
*/
|
|
207
|
+
export interface Decision {
|
|
208
|
+
type: 'approve' | 'edit' | 'reject';
|
|
209
|
+
args?: Record<string, unknown>;
|
|
210
|
+
}
|
|
206
211
|
/**
|
|
207
212
|
* Continue request schema - for multi-turn conversation.
|
|
208
213
|
*/
|
|
209
|
-
declare const ContinueRequestSchema: z.ZodObject<{
|
|
214
|
+
export declare const ContinueRequestSchema: z.ZodObject<{
|
|
210
215
|
/** Required: Thread ID to continue */
|
|
211
216
|
threadId: z.ZodString;
|
|
212
217
|
/** Required: Follow-up message */
|
|
@@ -218,22 +223,22 @@ declare const ContinueRequestSchema: z.ZodObject<{
|
|
|
218
223
|
message: string;
|
|
219
224
|
threadId: string;
|
|
220
225
|
}>;
|
|
221
|
-
type ContinueRequest = z.infer<typeof ContinueRequestSchema>;
|
|
226
|
+
export type ContinueRequest = z.infer<typeof ContinueRequestSchema>;
|
|
222
227
|
/**
|
|
223
228
|
* All possible SSE event types.
|
|
224
229
|
*/
|
|
225
|
-
type SSEEventType = 'start' | 'message' | 'tool_call' | 'tool_result' | 'todo_update' | 'todo_detail' | 'file_operation' | 'schema_update' | 'generation_log' | 'subagent_event' | 'interrupt' | 'error' | 'complete' | 'cancelled' | 'app_created' | 'schema_phase_validated' | 'schema_phase_update' | 'orbital_added' | 'orbital_schema_complete' | 'changeset_recorded' | 'snapshot_created';
|
|
230
|
+
export type SSEEventType = 'start' | 'message' | 'tool_call' | 'tool_result' | 'todo_update' | 'todo_detail' | 'file_operation' | 'schema_update' | 'generation_log' | 'subagent_event' | 'interrupt' | 'error' | 'complete' | 'cancelled' | 'app_created' | 'schema_phase_validated' | 'schema_phase_update' | 'orbital_added' | 'orbital_schema_complete' | 'changeset_recorded' | 'snapshot_created';
|
|
226
231
|
/**
|
|
227
232
|
* Base SSE event structure.
|
|
228
233
|
*/
|
|
229
|
-
interface SSEEventBase {
|
|
234
|
+
export interface SSEEventBase {
|
|
230
235
|
type: SSEEventType;
|
|
231
236
|
timestamp: number;
|
|
232
237
|
}
|
|
233
238
|
/**
|
|
234
239
|
* Start event - sent when streaming begins.
|
|
235
240
|
*/
|
|
236
|
-
interface StartEvent extends SSEEventBase {
|
|
241
|
+
export interface StartEvent extends SSEEventBase {
|
|
237
242
|
type: 'start';
|
|
238
243
|
data: {
|
|
239
244
|
threadId: string;
|
|
@@ -244,7 +249,7 @@ interface StartEvent extends SSEEventBase {
|
|
|
244
249
|
/**
|
|
245
250
|
* Message event - agent text output.
|
|
246
251
|
*/
|
|
247
|
-
interface MessageEvent extends SSEEventBase {
|
|
252
|
+
export interface MessageEvent extends SSEEventBase {
|
|
248
253
|
type: 'message';
|
|
249
254
|
data: {
|
|
250
255
|
content: string;
|
|
@@ -255,7 +260,7 @@ interface MessageEvent extends SSEEventBase {
|
|
|
255
260
|
/**
|
|
256
261
|
* Tool call event - when agent invokes a tool.
|
|
257
262
|
*/
|
|
258
|
-
interface ToolCallEvent extends SSEEventBase {
|
|
263
|
+
export interface ToolCallEvent extends SSEEventBase {
|
|
259
264
|
type: 'tool_call';
|
|
260
265
|
data: {
|
|
261
266
|
tool: string;
|
|
@@ -265,7 +270,7 @@ interface ToolCallEvent extends SSEEventBase {
|
|
|
265
270
|
/**
|
|
266
271
|
* Tool result event - tool execution result.
|
|
267
272
|
*/
|
|
268
|
-
interface ToolResultEvent extends SSEEventBase {
|
|
273
|
+
export interface ToolResultEvent extends SSEEventBase {
|
|
269
274
|
type: 'tool_result';
|
|
270
275
|
data: {
|
|
271
276
|
tool: string;
|
|
@@ -276,7 +281,7 @@ interface ToolResultEvent extends SSEEventBase {
|
|
|
276
281
|
/**
|
|
277
282
|
* Todo update event - task progress.
|
|
278
283
|
*/
|
|
279
|
-
interface TodoUpdateEvent extends SSEEventBase {
|
|
284
|
+
export interface TodoUpdateEvent extends SSEEventBase {
|
|
280
285
|
type: 'todo_update';
|
|
281
286
|
data: {
|
|
282
287
|
todos: Array<{
|
|
@@ -289,11 +294,11 @@ interface TodoUpdateEvent extends SSEEventBase {
|
|
|
289
294
|
/**
|
|
290
295
|
* Activity type for todo details.
|
|
291
296
|
*/
|
|
292
|
-
type TodoActivityType = 'thinking' | 'tool_call' | 'tool_result' | 'code_change';
|
|
297
|
+
export type TodoActivityType = 'thinking' | 'tool_call' | 'tool_result' | 'code_change';
|
|
293
298
|
/**
|
|
294
299
|
* Todo detail event - shows LLM activity for a specific todo.
|
|
295
300
|
*/
|
|
296
|
-
interface TodoDetailEvent extends SSEEventBase {
|
|
301
|
+
export interface TodoDetailEvent extends SSEEventBase {
|
|
297
302
|
type: 'todo_detail';
|
|
298
303
|
data: {
|
|
299
304
|
todoId: string;
|
|
@@ -309,7 +314,7 @@ interface TodoDetailEvent extends SSEEventBase {
|
|
|
309
314
|
/**
|
|
310
315
|
* File operation event.
|
|
311
316
|
*/
|
|
312
|
-
interface FileOperationEvent extends SSEEventBase {
|
|
317
|
+
export interface FileOperationEvent extends SSEEventBase {
|
|
313
318
|
type: 'file_operation';
|
|
314
319
|
data: {
|
|
315
320
|
operation: 'ls' | 'read_file' | 'write_file' | 'edit_file';
|
|
@@ -320,7 +325,7 @@ interface FileOperationEvent extends SSEEventBase {
|
|
|
320
325
|
/**
|
|
321
326
|
* Schema update event.
|
|
322
327
|
*/
|
|
323
|
-
interface SchemaUpdateEvent extends SSEEventBase {
|
|
328
|
+
export interface SchemaUpdateEvent extends SSEEventBase {
|
|
324
329
|
type: 'schema_update';
|
|
325
330
|
data: {
|
|
326
331
|
appId: string;
|
|
@@ -334,7 +339,7 @@ interface SchemaUpdateEvent extends SSEEventBase {
|
|
|
334
339
|
/**
|
|
335
340
|
* Generation log event.
|
|
336
341
|
*/
|
|
337
|
-
interface GenerationLogEvent extends SSEEventBase {
|
|
342
|
+
export interface GenerationLogEvent extends SSEEventBase {
|
|
338
343
|
type: 'generation_log';
|
|
339
344
|
data: {
|
|
340
345
|
level: 'info' | 'warn' | 'error' | 'debug';
|
|
@@ -346,7 +351,7 @@ interface GenerationLogEvent extends SSEEventBase {
|
|
|
346
351
|
/**
|
|
347
352
|
* Interrupt event - awaiting human decision.
|
|
348
353
|
*/
|
|
349
|
-
interface InterruptEvent extends SSEEventBase {
|
|
354
|
+
export interface InterruptEvent extends SSEEventBase {
|
|
350
355
|
type: 'interrupt';
|
|
351
356
|
data: {
|
|
352
357
|
threadId: string;
|
|
@@ -361,7 +366,7 @@ interface InterruptEvent extends SSEEventBase {
|
|
|
361
366
|
/**
|
|
362
367
|
* Error event.
|
|
363
368
|
*/
|
|
364
|
-
interface ErrorEvent extends SSEEventBase {
|
|
369
|
+
export interface ErrorEvent extends SSEEventBase {
|
|
365
370
|
type: 'error';
|
|
366
371
|
data: {
|
|
367
372
|
error: string;
|
|
@@ -371,7 +376,7 @@ interface ErrorEvent extends SSEEventBase {
|
|
|
371
376
|
/**
|
|
372
377
|
* Cancelled event.
|
|
373
378
|
*/
|
|
374
|
-
interface CancelledEvent extends SSEEventBase {
|
|
379
|
+
export interface CancelledEvent extends SSEEventBase {
|
|
375
380
|
type: 'cancelled';
|
|
376
381
|
data: {
|
|
377
382
|
threadId: string;
|
|
@@ -381,7 +386,7 @@ interface CancelledEvent extends SSEEventBase {
|
|
|
381
386
|
/**
|
|
382
387
|
* Complete event - when generation finishes.
|
|
383
388
|
*/
|
|
384
|
-
interface CompleteEvent extends SSEEventBase {
|
|
389
|
+
export interface CompleteEvent extends SSEEventBase {
|
|
385
390
|
type: 'complete';
|
|
386
391
|
data: {
|
|
387
392
|
threadId: string;
|
|
@@ -399,7 +404,7 @@ interface CompleteEvent extends SSEEventBase {
|
|
|
399
404
|
/**
|
|
400
405
|
* Subagent event - forwards events from nested agent.
|
|
401
406
|
*/
|
|
402
|
-
interface SubagentEvent extends SSEEventBase {
|
|
407
|
+
export interface SubagentEvent extends SSEEventBase {
|
|
403
408
|
type: 'subagent_event';
|
|
404
409
|
data: {
|
|
405
410
|
orbitalName: string;
|
|
@@ -415,7 +420,7 @@ interface SubagentEvent extends SSEEventBase {
|
|
|
415
420
|
/**
|
|
416
421
|
* App created event.
|
|
417
422
|
*/
|
|
418
|
-
interface AppCreatedEvent extends SSEEventBase {
|
|
423
|
+
export interface AppCreatedEvent extends SSEEventBase {
|
|
419
424
|
type: 'app_created';
|
|
420
425
|
data: {
|
|
421
426
|
appId: string;
|
|
@@ -427,7 +432,7 @@ interface AppCreatedEvent extends SSEEventBase {
|
|
|
427
432
|
/**
|
|
428
433
|
* Schema phase validated event.
|
|
429
434
|
*/
|
|
430
|
-
interface SchemaPhaseValidatedEvent extends SSEEventBase {
|
|
435
|
+
export interface SchemaPhaseValidatedEvent extends SSEEventBase {
|
|
431
436
|
type: 'schema_phase_validated';
|
|
432
437
|
data: {
|
|
433
438
|
appId: string;
|
|
@@ -438,14 +443,14 @@ interface SchemaPhaseValidatedEvent extends SSEEventBase {
|
|
|
438
443
|
/**
|
|
439
444
|
* Schema phase update event.
|
|
440
445
|
*/
|
|
441
|
-
interface SchemaPhaseUpdateEvent extends SSEEventBase {
|
|
446
|
+
export interface SchemaPhaseUpdateEvent extends SSEEventBase {
|
|
442
447
|
type: 'schema_phase_update';
|
|
443
448
|
data: Record<string, unknown>;
|
|
444
449
|
}
|
|
445
450
|
/**
|
|
446
451
|
* Orbital added event.
|
|
447
452
|
*/
|
|
448
|
-
interface OrbitalAddedEvent extends SSEEventBase {
|
|
453
|
+
export interface OrbitalAddedEvent extends SSEEventBase {
|
|
449
454
|
type: 'orbital_added';
|
|
450
455
|
data: {
|
|
451
456
|
appId: string;
|
|
@@ -459,7 +464,7 @@ interface OrbitalAddedEvent extends SSEEventBase {
|
|
|
459
464
|
/**
|
|
460
465
|
* Orbital schema complete event.
|
|
461
466
|
*/
|
|
462
|
-
interface OrbitalSchemaCompleteEvent extends SSEEventBase {
|
|
467
|
+
export interface OrbitalSchemaCompleteEvent extends SSEEventBase {
|
|
463
468
|
type: 'orbital_schema_complete';
|
|
464
469
|
data: {
|
|
465
470
|
appId: string;
|
|
@@ -470,7 +475,7 @@ interface OrbitalSchemaCompleteEvent extends SSEEventBase {
|
|
|
470
475
|
/**
|
|
471
476
|
* Changeset recorded event.
|
|
472
477
|
*/
|
|
473
|
-
interface ChangesetRecordedEvent extends SSEEventBase {
|
|
478
|
+
export interface ChangesetRecordedEvent extends SSEEventBase {
|
|
474
479
|
type: 'changeset_recorded';
|
|
475
480
|
data: {
|
|
476
481
|
appId: string;
|
|
@@ -488,7 +493,7 @@ interface ChangesetRecordedEvent extends SSEEventBase {
|
|
|
488
493
|
/**
|
|
489
494
|
* Snapshot created event.
|
|
490
495
|
*/
|
|
491
|
-
interface SnapshotCreatedEvent extends SSEEventBase {
|
|
496
|
+
export interface SnapshotCreatedEvent extends SSEEventBase {
|
|
492
497
|
type: 'snapshot_created';
|
|
493
498
|
data: {
|
|
494
499
|
appId: string;
|
|
@@ -500,11 +505,42 @@ interface SnapshotCreatedEvent extends SSEEventBase {
|
|
|
500
505
|
/**
|
|
501
506
|
* Union of all SSE event types.
|
|
502
507
|
*/
|
|
503
|
-
type SSEEvent = StartEvent | MessageEvent | ToolCallEvent | ToolResultEvent | TodoUpdateEvent | TodoDetailEvent | FileOperationEvent | SchemaUpdateEvent | GenerationLogEvent | SubagentEvent | InterruptEvent | ErrorEvent | CancelledEvent | CompleteEvent | AppCreatedEvent | SchemaPhaseValidatedEvent | SchemaPhaseUpdateEvent | OrbitalAddedEvent | OrbitalSchemaCompleteEvent | ChangesetRecordedEvent | SnapshotCreatedEvent;
|
|
508
|
+
export type SSEEvent = StartEvent | MessageEvent | ToolCallEvent | ToolResultEvent | TodoUpdateEvent | TodoDetailEvent | FileOperationEvent | SchemaUpdateEvent | GenerationLogEvent | SubagentEvent | InterruptEvent | ErrorEvent | CancelledEvent | CompleteEvent | AppCreatedEvent | SchemaPhaseValidatedEvent | SchemaPhaseUpdateEvent | OrbitalAddedEvent | OrbitalSchemaCompleteEvent | ChangesetRecordedEvent | SnapshotCreatedEvent;
|
|
509
|
+
/**
|
|
510
|
+
* List skills response.
|
|
511
|
+
*/
|
|
512
|
+
export interface ListSkillsResponse {
|
|
513
|
+
available: Array<{
|
|
514
|
+
name: string;
|
|
515
|
+
description: string;
|
|
516
|
+
allowedTools?: string[];
|
|
517
|
+
}>;
|
|
518
|
+
installed: Array<{
|
|
519
|
+
name: string;
|
|
520
|
+
description: string;
|
|
521
|
+
allowedTools?: string[];
|
|
522
|
+
}>;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Session info response.
|
|
526
|
+
*/
|
|
527
|
+
export interface SessionInfo {
|
|
528
|
+
threadId: string;
|
|
529
|
+
skill: string;
|
|
530
|
+
workDir: string;
|
|
531
|
+
createdAt: number;
|
|
532
|
+
lastActivityAt: number;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* List sessions response.
|
|
536
|
+
*/
|
|
537
|
+
export interface ListSessionsResponse {
|
|
538
|
+
sessions: SessionInfo[];
|
|
539
|
+
}
|
|
504
540
|
/**
|
|
505
541
|
* Create an SSE event with timestamp.
|
|
506
542
|
*/
|
|
507
|
-
declare function createSSEEvent<T extends SSEEventType>(type: T, data: Extract<SSEEvent, {
|
|
543
|
+
export declare function createSSEEvent<T extends SSEEventType>(type: T, data: Extract<SSEEvent, {
|
|
508
544
|
type: T;
|
|
509
545
|
}>['data']): Extract<SSEEvent, {
|
|
510
546
|
type: T;
|
|
@@ -512,50 +548,48 @@ declare function createSSEEvent<T extends SSEEventType>(type: T, data: Extract<S
|
|
|
512
548
|
/**
|
|
513
549
|
* Format an SSE event for transmission.
|
|
514
550
|
*/
|
|
515
|
-
declare function formatSSEEvent(event: SSEEvent): string;
|
|
551
|
+
export declare function formatSSEEvent(event: SSEEvent): string;
|
|
516
552
|
/**
|
|
517
553
|
* Parse an SSE event from a data string.
|
|
518
554
|
*/
|
|
519
|
-
declare function parseSSEEvent(data: string): SSEEvent;
|
|
555
|
+
export declare function parseSSEEvent(data: string): SSEEvent;
|
|
520
556
|
/**
|
|
521
557
|
* Type guard for SSE start events.
|
|
522
558
|
*/
|
|
523
|
-
declare function isSSEStartEvent(event: SSEEvent): event is StartEvent;
|
|
559
|
+
export declare function isSSEStartEvent(event: SSEEvent): event is StartEvent;
|
|
524
560
|
/**
|
|
525
561
|
* Type guard for SSE message events.
|
|
526
562
|
*/
|
|
527
|
-
declare function isSSEMessageEvent(event: SSEEvent): event is MessageEvent;
|
|
563
|
+
export declare function isSSEMessageEvent(event: SSEEvent): event is MessageEvent;
|
|
528
564
|
/**
|
|
529
565
|
* Type guard for SSE interrupt events.
|
|
530
566
|
*/
|
|
531
|
-
declare function isSSEInterruptEvent(event: SSEEvent): event is InterruptEvent;
|
|
567
|
+
export declare function isSSEInterruptEvent(event: SSEEvent): event is InterruptEvent;
|
|
532
568
|
/**
|
|
533
569
|
* Type guard for SSE complete events.
|
|
534
570
|
*/
|
|
535
|
-
declare function isSSECompleteEvent(event: SSEEvent): event is CompleteEvent;
|
|
571
|
+
export declare function isSSECompleteEvent(event: SSEEvent): event is CompleteEvent;
|
|
536
572
|
/**
|
|
537
573
|
* Type guard for SSE error events.
|
|
538
574
|
*/
|
|
539
|
-
declare function isSSEErrorEvent(event: SSEEvent): event is ErrorEvent;
|
|
575
|
+
export declare function isSSEErrorEvent(event: SSEEvent): event is ErrorEvent;
|
|
540
576
|
/**
|
|
541
577
|
* Type guard for SSE tool call events.
|
|
542
578
|
*/
|
|
543
|
-
declare function isSSEToolCallEvent(event: SSEEvent): event is ToolCallEvent;
|
|
579
|
+
export declare function isSSEToolCallEvent(event: SSEEvent): event is ToolCallEvent;
|
|
544
580
|
/**
|
|
545
581
|
* Type guard for SSE todo update events.
|
|
546
582
|
*/
|
|
547
|
-
declare function isSSETodoUpdateEvent(event: SSEEvent): event is TodoUpdateEvent;
|
|
583
|
+
export declare function isSSETodoUpdateEvent(event: SSEEvent): event is TodoUpdateEvent;
|
|
548
584
|
/**
|
|
549
585
|
* Type guard for SSE todo detail events.
|
|
550
586
|
*/
|
|
551
|
-
declare function isSSETodoDetailEvent(event: SSEEvent): event is TodoDetailEvent;
|
|
587
|
+
export declare function isSSETodoDetailEvent(event: SSEEvent): event is TodoDetailEvent;
|
|
552
588
|
/**
|
|
553
589
|
* Type guard for SSE subagent events.
|
|
554
590
|
*/
|
|
555
|
-
declare function isSSESubagentEvent(event: SSEEvent): event is SubagentEvent;
|
|
591
|
+
export declare function isSSESubagentEvent(event: SSEEvent): event is SubagentEvent;
|
|
556
592
|
/**
|
|
557
593
|
* Type guard for SSE generation log events.
|
|
558
594
|
*/
|
|
559
|
-
declare function isSSEGenerationLogEvent(event: SSEEvent): event is GenerationLogEvent;
|
|
560
|
-
|
|
561
|
-
export { type CompleteEvent as C, type ErrorEvent as E, type GenerateRequest as G, type InterruptEvent as I, type MessageEvent as M, type ResumeRequest as R, type SSEEventType as S, type TodoUpdateEvent as T, type SSEEvent as a, type ContinueRequest as b, ContinueRequestSchema as c, type ExtractedRequirementsInput as d, ExtractedRequirementsSchema as e, GenerateRequestSchema as f, type GenerationLogEvent as g, ResumeRequestSchema as h, type StartEvent as i, type SubagentEvent as j, type ToolCallEvent as k, type ToolResultEvent as l, createSSEEvent as m, formatSSEEvent as n, isSSECompleteEvent as o, isSSEErrorEvent as p, isSSEGenerationLogEvent as q, isSSEInterruptEvent as r, isSSEMessageEvent as s, isSSEStartEvent as t, isSSESubagentEvent as u, isSSETodoDetailEvent as v, isSSETodoUpdateEvent as w, isSSEToolCallEvent as x, parseSSEEvent as y };
|
|
595
|
+
export declare function isSSEGenerationLogEvent(event: SSEEvent): event is GenerationLogEvent;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Compaction - Phase 1.4 Implementation
|
|
3
|
+
*
|
|
4
|
+
* Handle long conversations without token overflow by:
|
|
5
|
+
* - Summarizing old tool results
|
|
6
|
+
* - Extracting key user decisions
|
|
7
|
+
* - Enforcing token limits (80% threshold)
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Message type for context compaction.
|
|
13
|
+
* Defines the minimal shape needed for token estimation and compaction.
|
|
14
|
+
*/
|
|
15
|
+
export interface Message {
|
|
16
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
17
|
+
content: string | Array<string | {
|
|
18
|
+
text: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compaction strategy
|
|
24
|
+
*/
|
|
25
|
+
export type CompactionStrategy = 'summarize' | 'truncate' | 'extract' | 'hybrid';
|
|
26
|
+
/**
|
|
27
|
+
* Compaction configuration
|
|
28
|
+
*/
|
|
29
|
+
export interface CompactionConfig {
|
|
30
|
+
/** Maximum tokens allowed (default: 8000) */
|
|
31
|
+
maxTokens: number;
|
|
32
|
+
/** Trigger compaction at this percentage (default: 0.8 = 80%) */
|
|
33
|
+
triggerThreshold: number;
|
|
34
|
+
/** Strategy for compaction */
|
|
35
|
+
strategy: CompactionStrategy;
|
|
36
|
+
/** Number of recent messages to always preserve */
|
|
37
|
+
preserveRecent: number;
|
|
38
|
+
/** Minimum messages before compaction */
|
|
39
|
+
minMessages: number;
|
|
40
|
+
/** Max summary length in tokens */
|
|
41
|
+
maxSummaryTokens: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Token count for a message
|
|
45
|
+
*/
|
|
46
|
+
export interface MessageTokenCount {
|
|
47
|
+
messageId: string;
|
|
48
|
+
tokens: number;
|
|
49
|
+
content: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Context state
|
|
53
|
+
*/
|
|
54
|
+
export interface ContextState {
|
|
55
|
+
/** Messages in context */
|
|
56
|
+
messages: Message[];
|
|
57
|
+
/** Total token count */
|
|
58
|
+
totalTokens: number;
|
|
59
|
+
/** Token limit */
|
|
60
|
+
maxTokens: number;
|
|
61
|
+
/** Whether compaction was performed */
|
|
62
|
+
wasCompacted: boolean;
|
|
63
|
+
/** Compaction history */
|
|
64
|
+
compactionHistory: CompactionRecord[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Compaction record
|
|
68
|
+
*/
|
|
69
|
+
export interface CompactionRecord {
|
|
70
|
+
/** When compaction occurred */
|
|
71
|
+
timestamp: number;
|
|
72
|
+
/** Strategy used */
|
|
73
|
+
strategy: CompactionStrategy;
|
|
74
|
+
/** Messages before compaction */
|
|
75
|
+
messagesBefore: number;
|
|
76
|
+
/** Messages after compaction */
|
|
77
|
+
messagesAfter: number;
|
|
78
|
+
/** Tokens before compaction */
|
|
79
|
+
tokensBefore: number;
|
|
80
|
+
/** Tokens after compaction */
|
|
81
|
+
tokensAfter: number;
|
|
82
|
+
/** Summary generated (if any) */
|
|
83
|
+
summary?: string;
|
|
84
|
+
/** Key decisions extracted */
|
|
85
|
+
keyDecisions?: string[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Extracted decision
|
|
89
|
+
*/
|
|
90
|
+
export interface ExtractedDecision {
|
|
91
|
+
/** Decision ID */
|
|
92
|
+
id: string;
|
|
93
|
+
/** What was decided */
|
|
94
|
+
decision: string;
|
|
95
|
+
/** Context around the decision */
|
|
96
|
+
context: string;
|
|
97
|
+
/** Who made the decision (user/assistant) */
|
|
98
|
+
actor: 'user' | 'assistant';
|
|
99
|
+
/** When it was made */
|
|
100
|
+
timestamp: number;
|
|
101
|
+
/** Impact level */
|
|
102
|
+
impact: 'high' | 'medium' | 'low';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Estimate token count for text
|
|
106
|
+
* Rough approximation: ~4 characters per token for English
|
|
107
|
+
*/
|
|
108
|
+
export declare function estimateTokens(text: string): number;
|
|
109
|
+
/**
|
|
110
|
+
* Estimate tokens for a message
|
|
111
|
+
*/
|
|
112
|
+
export declare function estimateMessageTokens(message: Message): number;
|
|
113
|
+
export declare class ContextCompactionEngine {
|
|
114
|
+
private config;
|
|
115
|
+
private compactionHistory;
|
|
116
|
+
constructor(config?: Partial<CompactionConfig>);
|
|
117
|
+
/**
|
|
118
|
+
* Check if compaction is needed
|
|
119
|
+
*/
|
|
120
|
+
shouldCompact(messages: Message[]): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Get current context state
|
|
123
|
+
*/
|
|
124
|
+
getContextState(messages: Message[]): ContextState;
|
|
125
|
+
/**
|
|
126
|
+
* Compact context using configured strategy
|
|
127
|
+
*/
|
|
128
|
+
compact(messages: Message[]): Promise<{
|
|
129
|
+
messages: Message[];
|
|
130
|
+
record: CompactionRecord;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Summarize old messages, keep recent ones intact
|
|
134
|
+
*/
|
|
135
|
+
private summarizeStrategy;
|
|
136
|
+
/**
|
|
137
|
+
* Truncate oldest messages
|
|
138
|
+
*/
|
|
139
|
+
private truncateStrategy;
|
|
140
|
+
/**
|
|
141
|
+
* Extract key decisions, discard rest
|
|
142
|
+
*/
|
|
143
|
+
private extractStrategy;
|
|
144
|
+
/**
|
|
145
|
+
* Hybrid: Summarize + extract key decisions
|
|
146
|
+
*/
|
|
147
|
+
private hybridStrategy;
|
|
148
|
+
/**
|
|
149
|
+
* Generate summary of messages (simplified version)
|
|
150
|
+
* In production, this would call an LLM
|
|
151
|
+
*/
|
|
152
|
+
private generateSummary;
|
|
153
|
+
/**
|
|
154
|
+
* Extract decisions from messages
|
|
155
|
+
*/
|
|
156
|
+
private extractDecisions;
|
|
157
|
+
/**
|
|
158
|
+
* Extract topics from messages
|
|
159
|
+
*/
|
|
160
|
+
private extractTopics;
|
|
161
|
+
/**
|
|
162
|
+
* Convert message to text
|
|
163
|
+
*/
|
|
164
|
+
private messageToText;
|
|
165
|
+
/**
|
|
166
|
+
* Get compaction statistics
|
|
167
|
+
*/
|
|
168
|
+
getStatistics(): {
|
|
169
|
+
totalCompactions: number;
|
|
170
|
+
averageReduction: number;
|
|
171
|
+
averageTokenReduction: number;
|
|
172
|
+
strategiesUsed: Record<CompactionStrategy, number>;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Update configuration
|
|
176
|
+
*/
|
|
177
|
+
updateConfig(config: Partial<CompactionConfig>): void;
|
|
178
|
+
/**
|
|
179
|
+
* Get current configuration
|
|
180
|
+
*/
|
|
181
|
+
getConfig(): CompactionConfig;
|
|
182
|
+
}
|
|
183
|
+
export declare function createContextCompactionEngine(config?: Partial<CompactionConfig>): ContextCompactionEngine;
|
|
184
|
+
/**
|
|
185
|
+
* Auto-compact context if needed
|
|
186
|
+
*/
|
|
187
|
+
export declare function autoCompact(messages: Message[], config?: Partial<CompactionConfig>): Promise<{
|
|
188
|
+
messages: Message[];
|
|
189
|
+
wasCompacted: boolean;
|
|
190
|
+
record?: CompactionRecord;
|
|
191
|
+
}>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Compaction for DeepAgent
|
|
3
|
+
*
|
|
4
|
+
* Provides middleware to manage context length in long-running agent sessions.
|
|
5
|
+
* Uses @langchain/core's trimMessages to keep context within token limits.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { type BaseMessage } from '@langchain/core/messages';
|
|
10
|
+
import type { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for context compaction.
|
|
13
|
+
*/
|
|
14
|
+
export interface ContextCompactionConfig {
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of tokens before triggering compaction.
|
|
17
|
+
* Default: 150000 (leaves headroom for Claude's 200K context)
|
|
18
|
+
*/
|
|
19
|
+
maxTokens?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Number of recent messages to always keep.
|
|
22
|
+
* Default: 10
|
|
23
|
+
*/
|
|
24
|
+
keepRecentMessages?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to include the system message in trimming.
|
|
27
|
+
* Default: false (system message is always kept)
|
|
28
|
+
*/
|
|
29
|
+
includeSystem?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Strategy for trimming: 'first' keeps first messages, 'last' keeps last messages.
|
|
32
|
+
* Default: 'last'
|
|
33
|
+
*/
|
|
34
|
+
strategy?: 'first' | 'last';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Default configuration for context compaction.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_COMPACTION_CONFIG: Required<ContextCompactionConfig>;
|
|
40
|
+
/**
|
|
41
|
+
* Compact messages to fit within token limit.
|
|
42
|
+
*/
|
|
43
|
+
export declare function compactMessages(messages: BaseMessage[], model: BaseLanguageModel, config?: ContextCompactionConfig): Promise<BaseMessage[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if messages need compaction based on estimated token count.
|
|
46
|
+
*/
|
|
47
|
+
export declare function needsCompaction(messages: BaseMessage[], threshold?: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Create a message summarizer prompt for compacting old context.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createSummaryPrompt(messages: BaseMessage[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* Estimate token count for messages using character-based heuristic.
|
|
54
|
+
*/
|
|
55
|
+
export declare function estimateTokens(messages: BaseMessage[]): number;
|