@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.
- 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 -0
- 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.d.ts +595 -0
- 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 +7 -0
- package/dist/events.d.ts +85 -0
- package/dist/index.d.ts +59 -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/persistence/firestore-checkpointer.d.ts +139 -0
- 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 +10 -0
- 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/tools/domain-orbital.d.ts +997 -0
- 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 -0
- 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 +167 -0
- 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 +38 -0
- 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 +8 -7
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interrupt Configuration
|
|
3
|
+
*
|
|
4
|
+
* Human-in-the-loop configuration for agent tools.
|
|
5
|
+
*
|
|
6
|
+
* Threshold-gated actions (require k-of-n approval):
|
|
7
|
+
*
|
|
8
|
+
* | Action | Risk | Gate |
|
|
9
|
+
* |----------------------------------------------|-----------------------|-------|
|
|
10
|
+
* | pnpm publish / npm publish | Irreversible registry | 2-of-2 |
|
|
11
|
+
* | git push to main / production deploy | Live users affected | 2-of-2 |
|
|
12
|
+
* | rm -rf / destructive file ops | Data loss | 2-of-2 |
|
|
13
|
+
* | Database migration / persist delete-all | Production data | 2-of-2 |
|
|
14
|
+
* | Read/write .env, secrets, service accounts | Credential exposure | 2-of-2 |
|
|
15
|
+
* | Cross-user data operations | Privacy violation | 2-of-2 |
|
|
16
|
+
* | Schema deploy to production orbital | Breaking change risk | 1-of-2 |
|
|
17
|
+
*
|
|
18
|
+
* Routine actions (no gate): compile, validate, read files, npm install.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Skill metadata (minimal interface for interrupt config).
|
|
22
|
+
*/
|
|
23
|
+
export interface SkillMeta {
|
|
24
|
+
name: string;
|
|
25
|
+
allowedTools?: string[];
|
|
26
|
+
}
|
|
27
|
+
/** Risk level of an agent action. */
|
|
28
|
+
export type ActionGate = 'none' | 'sensitive' | 'critical';
|
|
29
|
+
/**
|
|
30
|
+
* Maps tool names / command patterns to their required approval gate.
|
|
31
|
+
* Used by the security layer to decide when ThresholdAuthorizer is needed.
|
|
32
|
+
*/
|
|
33
|
+
export declare const TOOL_GATES: Record<string, ActionGate>;
|
|
34
|
+
/**
|
|
35
|
+
* Command patterns that classify a shell command as critical.
|
|
36
|
+
* Matched against the command string before execution.
|
|
37
|
+
*/
|
|
38
|
+
export declare const CRITICAL_COMMAND_PATTERNS: RegExp[];
|
|
39
|
+
/**
|
|
40
|
+
* Classify a shell command's risk level.
|
|
41
|
+
* Returns 'critical' if the command matches any CRITICAL_COMMAND_PATTERNS,
|
|
42
|
+
* 'sensitive' otherwise.
|
|
43
|
+
*/
|
|
44
|
+
export declare function classifyCommand(command: string): ActionGate;
|
|
45
|
+
/**
|
|
46
|
+
* Get interrupt configuration for a skill.
|
|
47
|
+
*
|
|
48
|
+
* Default: require approval for execute tool.
|
|
49
|
+
* Skills can override via frontmatter (future enhancement).
|
|
50
|
+
*/
|
|
51
|
+
export declare function getInterruptConfig(_skill: SkillMeta): Record<string, boolean>;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Manager
|
|
3
|
+
*
|
|
4
|
+
* Unified session management API with pluggable persistence backends.
|
|
5
|
+
* Supports in-memory (development) and Firestore (production) backends.
|
|
6
|
+
*/
|
|
7
|
+
import type { BaseCheckpointSaver } from '@langchain/langgraph-checkpoint';
|
|
8
|
+
import type { SessionMetadata, SessionRecord, PersistenceMode } from '../persistence/types.js';
|
|
9
|
+
import { type FirestoreDb } from '../persistence/firestore-checkpointer.js';
|
|
10
|
+
import type { MemoryManager } from '../memory/index.js';
|
|
11
|
+
import { type ContextCompactionConfig } from '../context-compaction.js';
|
|
12
|
+
export type { SessionMetadata, SessionRecord, PersistenceMode };
|
|
13
|
+
export interface SessionManagerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Persistence mode.
|
|
16
|
+
* @default 'memory'
|
|
17
|
+
*/
|
|
18
|
+
mode?: PersistenceMode;
|
|
19
|
+
/**
|
|
20
|
+
* Firestore database instance. Required when mode is 'firestore'.
|
|
21
|
+
*/
|
|
22
|
+
firestoreDb?: FirestoreDb;
|
|
23
|
+
/**
|
|
24
|
+
* Memory manager for session-to-memory sync (GAP-002D).
|
|
25
|
+
* When provided, completed sessions are recorded to orbital memory.
|
|
26
|
+
*/
|
|
27
|
+
memoryManager?: MemoryManager;
|
|
28
|
+
/**
|
|
29
|
+
* Context compaction configuration (GAP-005).
|
|
30
|
+
* When provided, enables automatic context length management.
|
|
31
|
+
*/
|
|
32
|
+
compactionConfig?: ContextCompactionConfig;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Unified session management for agent sessions.
|
|
36
|
+
*
|
|
37
|
+
* Handles both session metadata and LangGraph checkpointers.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SessionManager {
|
|
40
|
+
private mode;
|
|
41
|
+
private memoryBackend;
|
|
42
|
+
private memoryCheckpointers;
|
|
43
|
+
private firestoreCheckpointer;
|
|
44
|
+
private firestoreSessionStore;
|
|
45
|
+
private memoryManager;
|
|
46
|
+
private compactionConfig;
|
|
47
|
+
constructor(options?: SessionManagerOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Get the persistence mode.
|
|
50
|
+
*/
|
|
51
|
+
getMode(): PersistenceMode;
|
|
52
|
+
/**
|
|
53
|
+
* Get or create a checkpointer for a session.
|
|
54
|
+
*/
|
|
55
|
+
getCheckpointer(threadId: string): BaseCheckpointSaver<any>;
|
|
56
|
+
/**
|
|
57
|
+
* Store session metadata.
|
|
58
|
+
*/
|
|
59
|
+
store(threadId: string, metadata: SessionMetadata): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get session metadata (sync, memory only).
|
|
62
|
+
*/
|
|
63
|
+
get(threadId: string): SessionMetadata | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Get session metadata (async, supports Firestore).
|
|
66
|
+
*/
|
|
67
|
+
getAsync(threadId: string): Promise<SessionMetadata | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* Clear a session's checkpointer and metadata.
|
|
70
|
+
*/
|
|
71
|
+
clear(threadId: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* List all sessions (sync, memory only).
|
|
74
|
+
*/
|
|
75
|
+
list(): SessionRecord[];
|
|
76
|
+
/**
|
|
77
|
+
* List all sessions (async, supports Firestore).
|
|
78
|
+
*/
|
|
79
|
+
listAsync(): Promise<SessionRecord[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Sync a completed session to orbital memory.
|
|
82
|
+
* This enables the agent to learn from past sessions.
|
|
83
|
+
*
|
|
84
|
+
* @param threadId - The session thread ID
|
|
85
|
+
* @param userId - The user ID for memory association
|
|
86
|
+
* @param sessionData - Additional session data to record
|
|
87
|
+
* @returns Promise that resolves when sync is complete
|
|
88
|
+
*/
|
|
89
|
+
syncSessionToMemory(threadId: string, userId: string, sessionData: {
|
|
90
|
+
appId: string;
|
|
91
|
+
inputDescription: string;
|
|
92
|
+
generatedOrbital?: string;
|
|
93
|
+
patternsUsed?: string[];
|
|
94
|
+
entities?: string[];
|
|
95
|
+
success: boolean;
|
|
96
|
+
errorMessage?: string;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Record an interrupt decision to memory.
|
|
100
|
+
* This enables learning from HITL (Human-in-the-Loop) decisions.
|
|
101
|
+
*
|
|
102
|
+
* @param sessionId - The session thread ID
|
|
103
|
+
* @param userId - The user who made the decision
|
|
104
|
+
* @param interruptData - The interrupt decision data
|
|
105
|
+
* @returns Promise that resolves when sync is complete
|
|
106
|
+
*/
|
|
107
|
+
recordInterruptDecision(sessionId: string, userId: string, interruptData: {
|
|
108
|
+
toolName: string;
|
|
109
|
+
toolArgs: Record<string, unknown>;
|
|
110
|
+
decision: 'approved' | 'rejected' | 'modified';
|
|
111
|
+
modifiedArgs?: Record<string, unknown>;
|
|
112
|
+
reason?: string;
|
|
113
|
+
}): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Get interrupt history for a session.
|
|
116
|
+
*/
|
|
117
|
+
getSessionInterrupts(sessionId: string): Promise<import('../memory/types.js').InterruptRecord[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Check if a tool should be auto-approved for a user.
|
|
120
|
+
*/
|
|
121
|
+
shouldAutoApproveTool(userId: string, toolName: string): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* Record a checkpoint to memory for learning.
|
|
124
|
+
*
|
|
125
|
+
* @param userId - The user who owns this checkpoint
|
|
126
|
+
* @param checkpointData - Checkpoint information
|
|
127
|
+
* @returns Promise that resolves when checkpoint is recorded
|
|
128
|
+
*/
|
|
129
|
+
recordCheckpoint(userId: string, checkpointData: {
|
|
130
|
+
checkpointId: string;
|
|
131
|
+
threadId: string;
|
|
132
|
+
parentCheckpointId?: string;
|
|
133
|
+
metadata?: Record<string, unknown>;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Record a rollback to a checkpoint.
|
|
137
|
+
*
|
|
138
|
+
* @param userId - The user who performed the rollback
|
|
139
|
+
* @param checkpointId - The checkpoint rolled back to
|
|
140
|
+
* @param reason - Optional reason for rollback
|
|
141
|
+
* @returns Promise that resolves when rollback is recorded
|
|
142
|
+
*/
|
|
143
|
+
recordRollback(userId: string, checkpointId: string, reason?: string): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Mark a checkpoint as successful (terminal state).
|
|
146
|
+
*
|
|
147
|
+
* @param userId - The user who owns this checkpoint
|
|
148
|
+
* @param checkpointId - The checkpoint that was successful
|
|
149
|
+
* @returns Promise that resolves when success is recorded
|
|
150
|
+
*/
|
|
151
|
+
markCheckpointSuccessful(userId: string, checkpointId: string): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Get checkpoint history for a thread.
|
|
154
|
+
*
|
|
155
|
+
* @param threadId - The thread to get checkpoints for
|
|
156
|
+
* @returns Array of checkpoint records
|
|
157
|
+
*/
|
|
158
|
+
getThreadCheckpoints(threadId: string): Promise<import('../memory/types.js').CheckpointRecord[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get frequently rolled-back checkpoints (problem areas).
|
|
161
|
+
*
|
|
162
|
+
* @param userId - The user to get problem checkpoints for
|
|
163
|
+
* @param minRollbackCount - Minimum rollback count (default: 2)
|
|
164
|
+
* @returns Array of checkpoint records with rollback issues
|
|
165
|
+
*/
|
|
166
|
+
getProblemCheckpoints(userId: string, minRollbackCount?: number): Promise<import('../memory/types.js').CheckpointRecord[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Get the context compaction configuration.
|
|
169
|
+
* @returns The compaction configuration or null if not configured.
|
|
170
|
+
*/
|
|
171
|
+
getCompactionConfig(): ContextCompactionConfig | null;
|
|
172
|
+
/**
|
|
173
|
+
* Check if a session's messages need compaction based on token count.
|
|
174
|
+
* Uses character-based estimation for quick checks.
|
|
175
|
+
*
|
|
176
|
+
* @param messages - Array of messages to check
|
|
177
|
+
* @returns True if compaction is recommended
|
|
178
|
+
*/
|
|
179
|
+
shouldCompactMessages(messages: {
|
|
180
|
+
content: string | unknown;
|
|
181
|
+
}[]): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Record a compaction event for a session.
|
|
184
|
+
* This helps track when and why compaction occurs.
|
|
185
|
+
*
|
|
186
|
+
* @param threadId - The session thread ID
|
|
187
|
+
* @param originalMessageCount - Number of messages before compaction
|
|
188
|
+
* @param compactedMessageCount - Number of messages after compaction
|
|
189
|
+
* @param reason - Reason for compaction
|
|
190
|
+
*/
|
|
191
|
+
recordCompaction(threadId: string, originalMessageCount: number, compactedMessageCount: number, reason?: string): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Get compaction history for a session.
|
|
194
|
+
*
|
|
195
|
+
* @param threadId - The session thread ID
|
|
196
|
+
* @returns Array of compaction events
|
|
197
|
+
*/
|
|
198
|
+
getCompactionHistory(threadId: string): Array<{
|
|
199
|
+
timestamp: number;
|
|
200
|
+
originalMessageCount: number;
|
|
201
|
+
compactedMessageCount: number;
|
|
202
|
+
reason: string;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill-Based DeepAgent Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates DeepAgent instances that use skills as the primary prompt source.
|
|
5
|
+
* No custom system prompts - all agent behavior is defined through skills.
|
|
6
|
+
*
|
|
7
|
+
* Uses deepagents library primitives:
|
|
8
|
+
* - createDeepAgent() for agent creation
|
|
9
|
+
* - FilesystemBackend for file operations
|
|
10
|
+
*
|
|
11
|
+
* Skill loading is injected via SkillLoader functions, keeping this package
|
|
12
|
+
* independent of any specific skill registry location.
|
|
13
|
+
*/
|
|
14
|
+
import { Command } from '@langchain/langgraph';
|
|
15
|
+
import { type LLMProvider } from '@almadar/llm';
|
|
16
|
+
import { type SubagentEventCallback, type OrbitalCompleteCallback, type DomainOrbitalCompleteCallback } from '../tools/index.js';
|
|
17
|
+
import { SessionManager } from './session-manager.js';
|
|
18
|
+
import { MemoryManager, type UserPreference, type ProjectContext } from '../memory/index.js';
|
|
19
|
+
export { Command };
|
|
20
|
+
/**
|
|
21
|
+
* Skill definition loaded by the consumer.
|
|
22
|
+
*/
|
|
23
|
+
export interface Skill {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
content: string;
|
|
27
|
+
allowedTools?: string[];
|
|
28
|
+
version?: string;
|
|
29
|
+
references: string[];
|
|
30
|
+
path?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Function to load a skill by name.
|
|
34
|
+
*/
|
|
35
|
+
export type SkillLoader = (name: string) => Skill | null;
|
|
36
|
+
/**
|
|
37
|
+
* Function to load a skill reference by skill name and ref name.
|
|
38
|
+
*/
|
|
39
|
+
export type SkillRefLoader = (skillName: string, refName: string) => string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Options for creating a skill agent.
|
|
42
|
+
*/
|
|
43
|
+
export interface SkillAgentOptions {
|
|
44
|
+
/** Required: The skill(s) to use. Can be a single skill or array of skills. */
|
|
45
|
+
skill: string | string[];
|
|
46
|
+
/** Required: Working directory for the agent */
|
|
47
|
+
workDir: string;
|
|
48
|
+
/** Required: Function to load skills */
|
|
49
|
+
skillLoader: SkillLoader;
|
|
50
|
+
/** Optional: Function to load skill references */
|
|
51
|
+
skillRefLoader?: SkillRefLoader;
|
|
52
|
+
/** Optional: Thread ID for session continuity */
|
|
53
|
+
threadId?: string;
|
|
54
|
+
/** Optional: LLM provider for main agent */
|
|
55
|
+
provider?: LLMProvider;
|
|
56
|
+
/** Optional: Model name for main agent */
|
|
57
|
+
model?: string;
|
|
58
|
+
/** Optional: LLM provider for subagents (orbital, trait, domain generation). Defaults to 'anthropic' */
|
|
59
|
+
subagentProvider?: LLMProvider;
|
|
60
|
+
/** Optional: Model name for subagents. Defaults to 'claude-sonnet-4-20250514' */
|
|
61
|
+
subagentModel?: string;
|
|
62
|
+
/** Optional: Enable verbose logging */
|
|
63
|
+
verbose?: boolean;
|
|
64
|
+
/** Optional: Disable human-in-the-loop interrupts (for eval/testing) */
|
|
65
|
+
noInterrupt?: boolean;
|
|
66
|
+
/** Optional: Callback for subagent events (orbital generation) */
|
|
67
|
+
onSubagentEvent?: SubagentEventCallback;
|
|
68
|
+
/** Optional: Session manager instance (shared across requests) */
|
|
69
|
+
sessionManager?: SessionManager;
|
|
70
|
+
/** Optional: Extracted requirements from analysis phase (for orbital skill) */
|
|
71
|
+
requirements?: {
|
|
72
|
+
entities?: string[];
|
|
73
|
+
states?: string[];
|
|
74
|
+
events?: string[];
|
|
75
|
+
guards?: string[];
|
|
76
|
+
pages?: string[];
|
|
77
|
+
effects?: string[];
|
|
78
|
+
rawRequirements?: string[];
|
|
79
|
+
};
|
|
80
|
+
/** Optional: GitHub integration configuration */
|
|
81
|
+
githubConfig?: {
|
|
82
|
+
/** GitHub personal access token */
|
|
83
|
+
token: string;
|
|
84
|
+
/** Repository owner (e.g., 'octocat') */
|
|
85
|
+
owner?: string;
|
|
86
|
+
/** Repository name (e.g., 'hello-world') */
|
|
87
|
+
repo?: string;
|
|
88
|
+
};
|
|
89
|
+
/** Optional: Memory manager for user/project memory (GAP-001) */
|
|
90
|
+
memoryManager?: MemoryManager;
|
|
91
|
+
/** Optional: User ID for memory lookup */
|
|
92
|
+
userId?: string;
|
|
93
|
+
/** Optional: App ID for project context */
|
|
94
|
+
appId?: string;
|
|
95
|
+
/** Optional: Tool wrapper for workflow execution (adds retry, telemetry) */
|
|
96
|
+
toolWrapper?: <T extends {
|
|
97
|
+
name: string;
|
|
98
|
+
invoke: (...args: any[]) => Promise<any>;
|
|
99
|
+
}>(tool: T) => T;
|
|
100
|
+
/** Optional: Use orchestrated generation/fixing with complexity-based routing */
|
|
101
|
+
useOrchestration?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Agent interface with stream method (simplified from DeepAgent)
|
|
105
|
+
*/
|
|
106
|
+
export interface SkillAgent {
|
|
107
|
+
stream: (input: {
|
|
108
|
+
messages: Array<{
|
|
109
|
+
role: string;
|
|
110
|
+
content: string;
|
|
111
|
+
}>;
|
|
112
|
+
}, config: {
|
|
113
|
+
configurable: {
|
|
114
|
+
thread_id: string;
|
|
115
|
+
};
|
|
116
|
+
}) => Promise<AsyncIterable<{
|
|
117
|
+
events?: Array<{
|
|
118
|
+
type: string;
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
}>;
|
|
121
|
+
model_request?: {
|
|
122
|
+
messages?: Array<{
|
|
123
|
+
kwargs?: {
|
|
124
|
+
content?: Array<{
|
|
125
|
+
type: string;
|
|
126
|
+
}>;
|
|
127
|
+
};
|
|
128
|
+
}>;
|
|
129
|
+
};
|
|
130
|
+
}>>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Result from creating a skill agent.
|
|
134
|
+
*/
|
|
135
|
+
export interface SkillAgentResult {
|
|
136
|
+
/** The agent instance (from deepagents library) */
|
|
137
|
+
agent: SkillAgent;
|
|
138
|
+
/** Thread ID for session resumption */
|
|
139
|
+
threadId: string;
|
|
140
|
+
/** The loaded skill(s) - primary skill when single, all skills when multiple */
|
|
141
|
+
skill: Skill;
|
|
142
|
+
/** All loaded skills (same as skill when single) */
|
|
143
|
+
skills: Skill[];
|
|
144
|
+
/** Working directory */
|
|
145
|
+
workDir: string;
|
|
146
|
+
/** Orbital tool setter for wiring SSE callback (if orbital tool enabled) */
|
|
147
|
+
setOrbitalEventCallback?: (callback: SubagentEventCallback) => void;
|
|
148
|
+
/** Orbital tool setter for wiring persistence callback */
|
|
149
|
+
setOrbitalCompleteCallback?: (callback: OrbitalCompleteCallback) => void;
|
|
150
|
+
/** Domain orbital callback for lean skill Firestore persistence */
|
|
151
|
+
setDomainCompleteCallback?: (callback: DomainOrbitalCompleteCallback) => void;
|
|
152
|
+
/** User preferences loaded from memory (GAP-001) */
|
|
153
|
+
userPreferences?: UserPreference | null;
|
|
154
|
+
/** Project context loaded from memory (GAP-001) */
|
|
155
|
+
projectContext?: ProjectContext | null;
|
|
156
|
+
/** Memory manager instance (GAP-001) */
|
|
157
|
+
memoryManager?: MemoryManager;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create a skill-based DeepAgent.
|
|
161
|
+
*
|
|
162
|
+
* Uses the specified skill's content as the system prompt.
|
|
163
|
+
* When multiple skills are provided, the agent sees all skill descriptions
|
|
164
|
+
* and can choose the appropriate one based on the user's request.
|
|
165
|
+
*
|
|
166
|
+
* @throws Error if any skill is not found
|
|
167
|
+
*/
|
|
168
|
+
export declare function createSkillAgent(options: SkillAgentOptions): Promise<SkillAgentResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Resume a skill agent session.
|
|
171
|
+
*
|
|
172
|
+
* Loads the skill from session metadata and creates agent with same threadId.
|
|
173
|
+
*
|
|
174
|
+
* @throws Error if session not found
|
|
175
|
+
*/
|
|
176
|
+
export declare function resumeSkillAgent(threadId: string, options: {
|
|
177
|
+
verbose?: boolean;
|
|
178
|
+
noInterrupt?: boolean;
|
|
179
|
+
skillLoader: SkillLoader;
|
|
180
|
+
skillRefLoader?: SkillRefLoader;
|
|
181
|
+
sessionManager?: SessionManager;
|
|
182
|
+
}): Promise<SkillAgentResult>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Middleware for DeepAgent
|
|
3
|
+
*
|
|
4
|
+
* Wraps tool execution with workflow engine capabilities:
|
|
5
|
+
* - Retry on failure
|
|
6
|
+
* - Parallel execution of independent tools
|
|
7
|
+
* - Per-tool telemetry
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const agent = createDeepAgent({
|
|
12
|
+
* skill: 'kflow-orbitals',
|
|
13
|
+
* middleware: [createWorkflowMiddleware({ maxRetries: 3, enableParallel: true })],
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/** Local middleware interface matching DeepAgent's middleware shape */
|
|
18
|
+
interface AgentMiddleware {
|
|
19
|
+
name: string;
|
|
20
|
+
beforeModel?: (state: Record<string, unknown>) => Promise<{
|
|
21
|
+
state: Record<string, unknown>;
|
|
22
|
+
}>;
|
|
23
|
+
afterModel?: (state: Record<string, unknown>, response: Record<string, unknown>) => Promise<{
|
|
24
|
+
state: Record<string, unknown>;
|
|
25
|
+
response: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
wrapTool?: (tool: {
|
|
28
|
+
name: string;
|
|
29
|
+
invoke: (...args: unknown[]) => Promise<unknown>;
|
|
30
|
+
}) => {
|
|
31
|
+
name: string;
|
|
32
|
+
invoke: (...args: unknown[]) => Promise<unknown>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface WorkflowMiddlewareOptions {
|
|
36
|
+
/** Max retry attempts per tool */
|
|
37
|
+
maxRetries?: number;
|
|
38
|
+
/** Enable parallel execution of independent tools */
|
|
39
|
+
enableParallel?: boolean;
|
|
40
|
+
/** Collect telemetry */
|
|
41
|
+
enableTelemetry?: boolean;
|
|
42
|
+
/** Max execution time per tool (ms) */
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolTelemetry {
|
|
46
|
+
toolName: string;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
retries: number;
|
|
49
|
+
success: boolean;
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create workflow middleware for DeepAgent
|
|
54
|
+
*
|
|
55
|
+
* This middleware intercepts tool calls and executes them through
|
|
56
|
+
* the WorkflowEngine for retry, parallel execution, and telemetry.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createWorkflowMiddleware(options?: WorkflowMiddlewareOptions): AgentMiddleware;
|
|
59
|
+
/**
|
|
60
|
+
* Get telemetry from workflow middleware
|
|
61
|
+
*/
|
|
62
|
+
export declare function getWorkflowTelemetry(_middleware: AgentMiddleware): ToolTelemetry[];
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Tool Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps tool execution with workflow capabilities:
|
|
5
|
+
* - Retry on failure with exponential backoff
|
|
6
|
+
* - Per-tool telemetry (duration, retries, success/failure)
|
|
7
|
+
* - Timeout handling
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const wrapper = createWorkflowToolWrapper({ maxRetries: 3 });
|
|
12
|
+
*
|
|
13
|
+
* const { agent } = await createSkillAgent({
|
|
14
|
+
* skill: 'kflow-orbitals',
|
|
15
|
+
* toolWrapper: wrapper.wrap,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // After execution
|
|
19
|
+
* const telemetry = wrapper.getTelemetry();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface WorkflowToolWrapperOptions {
|
|
23
|
+
/** Max retry attempts per tool (default: 3) */
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/** Enable telemetry collection (default: true) */
|
|
26
|
+
enableTelemetry?: boolean;
|
|
27
|
+
/** Max execution time per tool in ms (default: 60000) */
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
/** Initial backoff in ms (default: 1000) */
|
|
30
|
+
backoffMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ToolTelemetry {
|
|
33
|
+
toolName: string;
|
|
34
|
+
durationMs: number;
|
|
35
|
+
retries: number;
|
|
36
|
+
success: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface WorkflowToolWrapper {
|
|
40
|
+
/** Wrap a tool with retry/telemetry */
|
|
41
|
+
wrap<T extends {
|
|
42
|
+
name: string;
|
|
43
|
+
invoke: (...args: any[]) => Promise<any>;
|
|
44
|
+
}>(tool: T): T;
|
|
45
|
+
/** Get collected telemetry */
|
|
46
|
+
getTelemetry(): ToolTelemetry[];
|
|
47
|
+
/** Reset telemetry */
|
|
48
|
+
resetTelemetry(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a workflow tool wrapper
|
|
52
|
+
*
|
|
53
|
+
* @param options - Wrapper configuration
|
|
54
|
+
* @returns Wrapper with wrap() and getTelemetry() methods
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const workflow = createWorkflowToolWrapper({ maxRetries: 3 });
|
|
59
|
+
*
|
|
60
|
+
* const { agent } = await createSkillAgent({
|
|
61
|
+
* skill: 'kflow-orbitals',
|
|
62
|
+
* toolWrapper: workflow.wrap,
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Run agent...
|
|
66
|
+
*
|
|
67
|
+
* // Get results
|
|
68
|
+
* console.log(workflow.getTelemetry());
|
|
69
|
+
* // [{ toolName: 'generate_orbital', durationMs: 5000, retries: 1, success: true }]
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function createWorkflowToolWrapper(options?: WorkflowToolWrapperOptions): WorkflowToolWrapper;
|
|
73
|
+
/**
|
|
74
|
+
* Create a workflow wrapper specifically for evaluation comparison
|
|
75
|
+
*
|
|
76
|
+
* This wrapper logs telemetry to console for debugging
|
|
77
|
+
*/
|
|
78
|
+
export declare function createEvalWorkflowWrapper(options?: WorkflowToolWrapperOptions): {
|
|
79
|
+
wrap: <T extends {
|
|
80
|
+
name: string;
|
|
81
|
+
invoke: (...args: any[]) => Promise<any>;
|
|
82
|
+
}>(tool: T) => T;
|
|
83
|
+
/** Get collected telemetry */
|
|
84
|
+
getTelemetry(): ToolTelemetry[];
|
|
85
|
+
/** Reset telemetry */
|
|
86
|
+
resetTelemetry(): void;
|
|
87
|
+
};
|