@nuvin/nuvin-core 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.
- package/LICENSE +202 -0
- package/dist/VERSION +4 -0
- package/dist/index.d.ts +1452 -0
- package/dist/index.js +5822 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1452 @@
|
|
|
1
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Template - defines a pre-configured specialist agent
|
|
5
|
+
* Only systemPrompt is required; all other fields have sensible defaults
|
|
6
|
+
*/
|
|
7
|
+
type AgentTemplate = {
|
|
8
|
+
systemPrompt: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
tools?: string[];
|
|
13
|
+
provider?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
temperature?: number;
|
|
17
|
+
maxTokens?: number;
|
|
18
|
+
topP?: number;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
shareContext?: boolean;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Specialist Agent Configuration (Internal - used by AgentManager)
|
|
25
|
+
*/
|
|
26
|
+
type SpecialistAgentConfig = {
|
|
27
|
+
agentId: string;
|
|
28
|
+
agentName: string;
|
|
29
|
+
taskDescription: string;
|
|
30
|
+
systemPrompt: string;
|
|
31
|
+
tools: string[];
|
|
32
|
+
provider?: string;
|
|
33
|
+
model?: string;
|
|
34
|
+
temperature?: number;
|
|
35
|
+
maxTokens?: number;
|
|
36
|
+
topP?: number;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
shareContext?: boolean;
|
|
39
|
+
delegatingMemory?: Message[];
|
|
40
|
+
delegationDepth: number;
|
|
41
|
+
conversationId?: string;
|
|
42
|
+
messageId?: string;
|
|
43
|
+
toolCallId?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Specialist Agent Result
|
|
47
|
+
*/
|
|
48
|
+
type SpecialistAgentResult = {
|
|
49
|
+
status: 'success' | 'error' | 'timeout';
|
|
50
|
+
result: string;
|
|
51
|
+
metadata: {
|
|
52
|
+
agentId: string;
|
|
53
|
+
tokensUsed?: number;
|
|
54
|
+
toolCallsExecuted: number;
|
|
55
|
+
executionTimeMs: number;
|
|
56
|
+
conversationHistory?: Message[];
|
|
57
|
+
events?: AgentEvent[];
|
|
58
|
+
errorMessage?: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* AssignTool Parameters (what LLM provides)
|
|
63
|
+
*/
|
|
64
|
+
type AssignParams = {
|
|
65
|
+
agent: string;
|
|
66
|
+
task: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
interface AgentFilePersistenceOptions {
|
|
70
|
+
agentsDir: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* AgentFilePersistence - handles loading and saving agents to YAML files
|
|
74
|
+
*/
|
|
75
|
+
declare class AgentFilePersistence {
|
|
76
|
+
private agentsDir;
|
|
77
|
+
constructor(options: AgentFilePersistenceOptions);
|
|
78
|
+
/**
|
|
79
|
+
* Ensure agents directory exists
|
|
80
|
+
*/
|
|
81
|
+
private ensureAgentsDir;
|
|
82
|
+
/**
|
|
83
|
+
* Load all agents from the agents directory
|
|
84
|
+
*/
|
|
85
|
+
loadAll(): Promise<AgentTemplate[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Load a single agent from a YAML file
|
|
88
|
+
*/
|
|
89
|
+
load(filename: string): Promise<AgentTemplate | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Save an agent to a YAML file
|
|
92
|
+
*/
|
|
93
|
+
save(agent: AgentTemplate): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete an agent file
|
|
96
|
+
*/
|
|
97
|
+
delete(agentId: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Check if an agent file exists
|
|
100
|
+
*/
|
|
101
|
+
exists(agentId: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Sanitize filename to kebab-case and remove invalid characters
|
|
104
|
+
*/
|
|
105
|
+
private sanitizeFilename;
|
|
106
|
+
/**
|
|
107
|
+
* Get the agents directory path
|
|
108
|
+
*/
|
|
109
|
+
getAgentsDir(): string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* AgentRegistry - manages registered specialist agent configurations
|
|
114
|
+
*/
|
|
115
|
+
declare class AgentRegistry {
|
|
116
|
+
private agents;
|
|
117
|
+
private defaultAgentIds;
|
|
118
|
+
private persistence?;
|
|
119
|
+
private filePersistence?;
|
|
120
|
+
private loadingPromise?;
|
|
121
|
+
constructor(options?: {
|
|
122
|
+
persistence?: MemoryPort<AgentTemplate>;
|
|
123
|
+
filePersistence?: AgentFilePersistence;
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* Load agents from both persistence and files
|
|
127
|
+
*/
|
|
128
|
+
private loadAgents;
|
|
129
|
+
/**
|
|
130
|
+
* Wait for all agents to finish loading
|
|
131
|
+
*/
|
|
132
|
+
waitForLoad(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Apply defaults to a partial agent template
|
|
135
|
+
* Only systemPrompt is required; all other fields get defaults
|
|
136
|
+
*/
|
|
137
|
+
applyDefaults(partial: Partial<AgentTemplate> & {
|
|
138
|
+
systemPrompt: string;
|
|
139
|
+
}): AgentTemplate;
|
|
140
|
+
/**
|
|
141
|
+
* Load agents from memory persistence
|
|
142
|
+
*/
|
|
143
|
+
private loadFromPersistence;
|
|
144
|
+
/**
|
|
145
|
+
* Load agents from file system
|
|
146
|
+
*/
|
|
147
|
+
private loadFromFiles;
|
|
148
|
+
/**
|
|
149
|
+
* Save current agents to persistence
|
|
150
|
+
*/
|
|
151
|
+
private saveToPersistence;
|
|
152
|
+
/**
|
|
153
|
+
* Validate agent template (only systemPrompt required)
|
|
154
|
+
*/
|
|
155
|
+
private validateTemplate;
|
|
156
|
+
/**
|
|
157
|
+
* Register a new agent template
|
|
158
|
+
*/
|
|
159
|
+
register(agent: Partial<AgentTemplate> & {
|
|
160
|
+
systemPrompt: string;
|
|
161
|
+
}): void;
|
|
162
|
+
/**
|
|
163
|
+
* Save agent to file
|
|
164
|
+
*/
|
|
165
|
+
saveToFile(agent: AgentTemplate): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Delete agent from file
|
|
168
|
+
*/
|
|
169
|
+
deleteFromFile(agentId: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Check if an agent is a default agent
|
|
172
|
+
*/
|
|
173
|
+
isDefault(agentId: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Unregister an agent template
|
|
176
|
+
*/
|
|
177
|
+
unregister(agentId: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Get an agent template by ID
|
|
180
|
+
*/
|
|
181
|
+
get(agentId: string): AgentTemplate | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* List all registered agent templates
|
|
184
|
+
*/
|
|
185
|
+
list(): AgentTemplate[];
|
|
186
|
+
/**
|
|
187
|
+
* Check if an agent exists
|
|
188
|
+
*/
|
|
189
|
+
exists(agentId: string): boolean;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type ToolCall = {
|
|
193
|
+
id: string;
|
|
194
|
+
type: 'function';
|
|
195
|
+
function: {
|
|
196
|
+
name: string;
|
|
197
|
+
arguments: string;
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
type TextContentPart = {
|
|
201
|
+
type: 'text';
|
|
202
|
+
text: string;
|
|
203
|
+
};
|
|
204
|
+
type ImageContentPart = {
|
|
205
|
+
type: 'image';
|
|
206
|
+
mimeType: string;
|
|
207
|
+
data: string;
|
|
208
|
+
altText?: string;
|
|
209
|
+
source?: string;
|
|
210
|
+
name?: string;
|
|
211
|
+
};
|
|
212
|
+
type MessageContentPart = TextContentPart | ImageContentPart;
|
|
213
|
+
type MessageContent = string | null | {
|
|
214
|
+
type: 'parts';
|
|
215
|
+
parts: MessageContentPart[];
|
|
216
|
+
};
|
|
217
|
+
type ProviderContentPart = {
|
|
218
|
+
type: 'text';
|
|
219
|
+
text: string;
|
|
220
|
+
cache_control?: {
|
|
221
|
+
type: 'ephemeral';
|
|
222
|
+
};
|
|
223
|
+
} | {
|
|
224
|
+
type: 'image_url';
|
|
225
|
+
image_url: {
|
|
226
|
+
url: string;
|
|
227
|
+
detail?: 'auto' | 'low' | 'high';
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
type ChatMessage = {
|
|
231
|
+
role: typeof MessageRoles.System | typeof MessageRoles.User | typeof MessageRoles.Assistant | typeof MessageRoles.Tool;
|
|
232
|
+
content: string | null | ProviderContentPart[];
|
|
233
|
+
tool_calls?: ToolCall[];
|
|
234
|
+
tool_call_id?: string;
|
|
235
|
+
name?: string;
|
|
236
|
+
};
|
|
237
|
+
type CompletionParams = {
|
|
238
|
+
messages: ChatMessage[];
|
|
239
|
+
model: string;
|
|
240
|
+
temperature: number;
|
|
241
|
+
topP: number;
|
|
242
|
+
maxTokens?: number;
|
|
243
|
+
tools?: Array<{
|
|
244
|
+
type: 'function';
|
|
245
|
+
function: {
|
|
246
|
+
name: string;
|
|
247
|
+
description: string;
|
|
248
|
+
parameters: object;
|
|
249
|
+
};
|
|
250
|
+
}>;
|
|
251
|
+
tool_choice?: 'auto' | 'none' | {
|
|
252
|
+
type: 'function';
|
|
253
|
+
function: {
|
|
254
|
+
name: string;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
reasoning?: {
|
|
258
|
+
effort: string;
|
|
259
|
+
};
|
|
260
|
+
usage?: {
|
|
261
|
+
include?: boolean;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
type UsageData = {
|
|
265
|
+
prompt_tokens?: number;
|
|
266
|
+
completion_tokens?: number;
|
|
267
|
+
total_tokens?: number;
|
|
268
|
+
reasoning_tokens?: number;
|
|
269
|
+
prompt_tokens_details?: {
|
|
270
|
+
cached_tokens?: number;
|
|
271
|
+
audio_tokens?: number;
|
|
272
|
+
};
|
|
273
|
+
completion_tokens_details?: {
|
|
274
|
+
reasoning_tokens?: number;
|
|
275
|
+
};
|
|
276
|
+
cost?: number;
|
|
277
|
+
cost_details?: {
|
|
278
|
+
upstream_inference_cost?: number;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
type CompletionResult = {
|
|
282
|
+
content: string;
|
|
283
|
+
tool_calls?: ToolCall[];
|
|
284
|
+
usage?: UsageData;
|
|
285
|
+
};
|
|
286
|
+
type Message = {
|
|
287
|
+
id: string;
|
|
288
|
+
role: typeof MessageRoles.User | typeof MessageRoles.Assistant | typeof MessageRoles.Tool;
|
|
289
|
+
content: MessageContent;
|
|
290
|
+
timestamp?: string;
|
|
291
|
+
tool_calls?: ToolCall[];
|
|
292
|
+
tool_call_id?: string;
|
|
293
|
+
name?: string;
|
|
294
|
+
};
|
|
295
|
+
type MessageResponse = {
|
|
296
|
+
id: string;
|
|
297
|
+
content: string;
|
|
298
|
+
role: typeof MessageRoles.Assistant | typeof MessageRoles.Tool;
|
|
299
|
+
timestamp: string;
|
|
300
|
+
metadata?: {
|
|
301
|
+
model?: string;
|
|
302
|
+
provider?: string;
|
|
303
|
+
agentId?: string;
|
|
304
|
+
promptTokens?: number;
|
|
305
|
+
completionTokens?: number;
|
|
306
|
+
totalTokens?: number;
|
|
307
|
+
estimatedCost?: number;
|
|
308
|
+
responseTime?: number;
|
|
309
|
+
toolCalls?: number;
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
type SendMessageOptions = {
|
|
313
|
+
conversationId?: string;
|
|
314
|
+
stream?: boolean;
|
|
315
|
+
signal?: AbortSignal;
|
|
316
|
+
retry?: boolean;
|
|
317
|
+
};
|
|
318
|
+
type UserAttachment = ImageContentPart & {
|
|
319
|
+
token?: string;
|
|
320
|
+
};
|
|
321
|
+
type UserMessagePayload = string | {
|
|
322
|
+
text: string;
|
|
323
|
+
displayText?: string;
|
|
324
|
+
attachments?: UserAttachment[];
|
|
325
|
+
};
|
|
326
|
+
interface LLMPort {
|
|
327
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
328
|
+
streamCompletion?(params: CompletionParams, handlers?: {
|
|
329
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
330
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
331
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
332
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
333
|
+
}
|
|
334
|
+
type ToolDefinition = {
|
|
335
|
+
type: 'function';
|
|
336
|
+
function: {
|
|
337
|
+
name: string;
|
|
338
|
+
description: string;
|
|
339
|
+
parameters: object;
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
type ToolInvocation = {
|
|
343
|
+
id: string;
|
|
344
|
+
name: string;
|
|
345
|
+
parameters: Record<string, any>;
|
|
346
|
+
};
|
|
347
|
+
type ToolExecutionResult = {
|
|
348
|
+
id: string;
|
|
349
|
+
name: string;
|
|
350
|
+
status: 'success' | 'error';
|
|
351
|
+
type: 'text' | 'json';
|
|
352
|
+
result: string | object;
|
|
353
|
+
metadata?: Record<string, unknown>;
|
|
354
|
+
durationMs?: number;
|
|
355
|
+
};
|
|
356
|
+
interface ToolPort {
|
|
357
|
+
getToolDefinitions(enabledTools: string[]): ToolDefinition[];
|
|
358
|
+
executeToolCalls(calls: ToolInvocation[], context?: Record<string, unknown>, maxConcurrent?: number, signal?: AbortSignal): Promise<ToolExecutionResult[]>;
|
|
359
|
+
setEnabledAgents?(enabledAgents: Record<string, boolean>): void;
|
|
360
|
+
getAgentRegistry?(): AgentRegistry | undefined;
|
|
361
|
+
setOrchestrator?(config: AgentConfig, llm: LLMPort, tools: ToolPort): void;
|
|
362
|
+
}
|
|
363
|
+
type MemorySnapshot<T = unknown> = Record<string, T[]>;
|
|
364
|
+
interface MemoryPersistence<T = unknown> {
|
|
365
|
+
load(): Promise<MemorySnapshot<T>>;
|
|
366
|
+
save(snapshot: MemorySnapshot<T>): Promise<void>;
|
|
367
|
+
}
|
|
368
|
+
interface MemoryPort<T = unknown> {
|
|
369
|
+
get(key: string): Promise<T[]>;
|
|
370
|
+
set(key: string, items: T[]): Promise<void>;
|
|
371
|
+
append(key: string, items: T[]): Promise<void>;
|
|
372
|
+
delete(key: string): Promise<void>;
|
|
373
|
+
keys(): Promise<string[]>;
|
|
374
|
+
clear(): Promise<void>;
|
|
375
|
+
exportSnapshot(): Promise<MemorySnapshot<T>>;
|
|
376
|
+
importSnapshot(snapshot: MemorySnapshot<T>): Promise<void>;
|
|
377
|
+
}
|
|
378
|
+
interface MetadataPort<T> {
|
|
379
|
+
get(key: string): Promise<T | null>;
|
|
380
|
+
set(key: string, metadata: T): Promise<void>;
|
|
381
|
+
delete(key: string): Promise<void>;
|
|
382
|
+
keys(): Promise<string[]>;
|
|
383
|
+
clear(): Promise<void>;
|
|
384
|
+
exportSnapshot(): Promise<Record<string, T>>;
|
|
385
|
+
importSnapshot(snapshot: Record<string, T>): Promise<void>;
|
|
386
|
+
}
|
|
387
|
+
interface ContextBuilder {
|
|
388
|
+
toProviderMessages(history: Message[], systemPrompt: string, newUserContent: MessageContent[]): ChatMessage[];
|
|
389
|
+
}
|
|
390
|
+
interface RemindersPort {
|
|
391
|
+
enhance(content: string, opts: {
|
|
392
|
+
conversationId?: string;
|
|
393
|
+
}): string[];
|
|
394
|
+
}
|
|
395
|
+
interface IdGenerator$1 {
|
|
396
|
+
uuid(): string;
|
|
397
|
+
}
|
|
398
|
+
interface Clock {
|
|
399
|
+
now(): number;
|
|
400
|
+
iso(dateMs?: number): string;
|
|
401
|
+
}
|
|
402
|
+
interface CostCalculator {
|
|
403
|
+
estimate(model: string, usage?: UsageData): number | undefined;
|
|
404
|
+
}
|
|
405
|
+
type AgentConfig = {
|
|
406
|
+
id: string;
|
|
407
|
+
systemPrompt: string;
|
|
408
|
+
topP: number;
|
|
409
|
+
model: string;
|
|
410
|
+
temperature: number;
|
|
411
|
+
maxTokens?: number;
|
|
412
|
+
enabledTools?: string[];
|
|
413
|
+
maxToolConcurrency?: number;
|
|
414
|
+
requireToolApproval?: boolean;
|
|
415
|
+
reasoningEffort?: string;
|
|
416
|
+
};
|
|
417
|
+
declare const MessageRoles: {
|
|
418
|
+
readonly System: "system";
|
|
419
|
+
readonly User: "user";
|
|
420
|
+
readonly Assistant: "assistant";
|
|
421
|
+
readonly Tool: "tool";
|
|
422
|
+
};
|
|
423
|
+
declare const AgentEventTypes: {
|
|
424
|
+
readonly MessageStarted: "message_started";
|
|
425
|
+
readonly ToolCalls: "tool_calls";
|
|
426
|
+
readonly ToolApprovalRequired: "tool_approval_required";
|
|
427
|
+
readonly ToolApprovalResponse: "tool_approval_response";
|
|
428
|
+
readonly ToolResult: "tool_result";
|
|
429
|
+
readonly AssistantChunk: "assistant_chunk";
|
|
430
|
+
readonly AssistantMessage: "assistant_message";
|
|
431
|
+
readonly StreamFinish: "stream_finish";
|
|
432
|
+
readonly MemoryAppended: "memory_appended";
|
|
433
|
+
readonly Done: "done";
|
|
434
|
+
readonly Error: "error";
|
|
435
|
+
readonly MCPStderr: "mcp_stderr";
|
|
436
|
+
readonly SubAgentStarted: "sub_agent_started";
|
|
437
|
+
readonly SubAgentToolCall: "sub_agent_tool_call";
|
|
438
|
+
readonly SubAgentToolResult: "sub_agent_tool_result";
|
|
439
|
+
readonly SubAgentCompleted: "sub_agent_completed";
|
|
440
|
+
};
|
|
441
|
+
type ToolApprovalDecision = 'approve' | 'deny' | 'approve_all';
|
|
442
|
+
type AgentEvent = {
|
|
443
|
+
type: typeof AgentEventTypes.MessageStarted;
|
|
444
|
+
conversationId: string;
|
|
445
|
+
messageId: string;
|
|
446
|
+
userContent: string;
|
|
447
|
+
enhanced: string[];
|
|
448
|
+
toolNames: string[];
|
|
449
|
+
} | {
|
|
450
|
+
type: typeof AgentEventTypes.ToolCalls;
|
|
451
|
+
conversationId: string;
|
|
452
|
+
messageId: string;
|
|
453
|
+
toolCalls: ToolCall[];
|
|
454
|
+
} | {
|
|
455
|
+
type: typeof AgentEventTypes.ToolApprovalRequired;
|
|
456
|
+
conversationId: string;
|
|
457
|
+
messageId: string;
|
|
458
|
+
toolCalls: ToolCall[];
|
|
459
|
+
approvalId: string;
|
|
460
|
+
} | {
|
|
461
|
+
type: typeof AgentEventTypes.ToolApprovalResponse;
|
|
462
|
+
conversationId: string;
|
|
463
|
+
messageId: string;
|
|
464
|
+
approvalId: string;
|
|
465
|
+
decision: ToolApprovalDecision;
|
|
466
|
+
approvedCalls?: ToolCall[];
|
|
467
|
+
} | {
|
|
468
|
+
type: typeof AgentEventTypes.ToolResult;
|
|
469
|
+
conversationId: string;
|
|
470
|
+
messageId: string;
|
|
471
|
+
result: ToolExecutionResult;
|
|
472
|
+
} | {
|
|
473
|
+
type: typeof AgentEventTypes.AssistantChunk;
|
|
474
|
+
conversationId: string;
|
|
475
|
+
messageId: string;
|
|
476
|
+
delta: string;
|
|
477
|
+
usage?: UsageData;
|
|
478
|
+
} | {
|
|
479
|
+
type: typeof AgentEventTypes.AssistantMessage;
|
|
480
|
+
conversationId: string;
|
|
481
|
+
messageId: string;
|
|
482
|
+
content: string | null;
|
|
483
|
+
usage?: UsageData;
|
|
484
|
+
} | {
|
|
485
|
+
type: typeof AgentEventTypes.StreamFinish;
|
|
486
|
+
conversationId: string;
|
|
487
|
+
messageId: string;
|
|
488
|
+
finishReason?: string;
|
|
489
|
+
usage?: UsageData;
|
|
490
|
+
} | {
|
|
491
|
+
type: typeof AgentEventTypes.MemoryAppended;
|
|
492
|
+
conversationId: string;
|
|
493
|
+
delta: Message[];
|
|
494
|
+
} | {
|
|
495
|
+
type: typeof AgentEventTypes.Done;
|
|
496
|
+
conversationId: string;
|
|
497
|
+
messageId: string;
|
|
498
|
+
responseTimeMs: number;
|
|
499
|
+
usage?: UsageData;
|
|
500
|
+
} | {
|
|
501
|
+
type: typeof AgentEventTypes.Error;
|
|
502
|
+
conversationId: string;
|
|
503
|
+
messageId?: string;
|
|
504
|
+
error: string;
|
|
505
|
+
} | {
|
|
506
|
+
type: typeof AgentEventTypes.MCPStderr;
|
|
507
|
+
conversationId: string;
|
|
508
|
+
serverId: string;
|
|
509
|
+
serverName?: string;
|
|
510
|
+
data: string;
|
|
511
|
+
timestamp: string;
|
|
512
|
+
} | {
|
|
513
|
+
type: typeof AgentEventTypes.SubAgentStarted;
|
|
514
|
+
conversationId: string;
|
|
515
|
+
messageId: string;
|
|
516
|
+
agentId: string;
|
|
517
|
+
agentName: string;
|
|
518
|
+
toolCallId: string;
|
|
519
|
+
} | {
|
|
520
|
+
type: typeof AgentEventTypes.SubAgentToolCall;
|
|
521
|
+
conversationId: string;
|
|
522
|
+
messageId: string;
|
|
523
|
+
agentId: string;
|
|
524
|
+
toolCallId: string;
|
|
525
|
+
toolName: string;
|
|
526
|
+
toolArguments?: string;
|
|
527
|
+
} | {
|
|
528
|
+
type: typeof AgentEventTypes.SubAgentToolResult;
|
|
529
|
+
conversationId: string;
|
|
530
|
+
messageId: string;
|
|
531
|
+
agentId: string;
|
|
532
|
+
toolCallId: string;
|
|
533
|
+
toolName: string;
|
|
534
|
+
durationMs: number;
|
|
535
|
+
status: 'success' | 'error';
|
|
536
|
+
} | {
|
|
537
|
+
type: typeof AgentEventTypes.SubAgentCompleted;
|
|
538
|
+
conversationId: string;
|
|
539
|
+
messageId: string;
|
|
540
|
+
agentId: string;
|
|
541
|
+
agentName: string;
|
|
542
|
+
status: 'success' | 'error' | 'timeout';
|
|
543
|
+
resultMessage: string;
|
|
544
|
+
totalDurationMs: number;
|
|
545
|
+
};
|
|
546
|
+
interface EventPort {
|
|
547
|
+
emit(event: AgentEvent): void | Promise<void>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
declare class AgentOrchestrator {
|
|
551
|
+
private cfg;
|
|
552
|
+
private deps;
|
|
553
|
+
private pendingApprovals;
|
|
554
|
+
constructor(cfg: AgentConfig, deps: {
|
|
555
|
+
memory: MemoryPort<Message>;
|
|
556
|
+
llm: LLMPort;
|
|
557
|
+
tools: ToolPort;
|
|
558
|
+
context: ContextBuilder;
|
|
559
|
+
ids: IdGenerator$1;
|
|
560
|
+
clock: Clock;
|
|
561
|
+
cost: CostCalculator;
|
|
562
|
+
reminders: RemindersPort;
|
|
563
|
+
events?: EventPort;
|
|
564
|
+
});
|
|
565
|
+
/**
|
|
566
|
+
* Updates the agent configuration dynamically after initialization.
|
|
567
|
+
* This allows for runtime changes to model, provider, and other settings.
|
|
568
|
+
*/
|
|
569
|
+
updateConfig(newConfig: Partial<AgentConfig>): void;
|
|
570
|
+
/**
|
|
571
|
+
* Updates the LLM provider without reinitializing the entire orchestrator.
|
|
572
|
+
* This preserves conversation history, MCP connections, and other state.
|
|
573
|
+
*/
|
|
574
|
+
setLLM(newLLM: LLMPort): void;
|
|
575
|
+
/**
|
|
576
|
+
* Updates the tool port without reinitializing the entire orchestrator.
|
|
577
|
+
* This preserves conversation history and other state while adding/removing tools.
|
|
578
|
+
*/
|
|
579
|
+
setTools(newTools: ToolPort): void;
|
|
580
|
+
/**
|
|
581
|
+
* Gets the current tool port.
|
|
582
|
+
*/
|
|
583
|
+
getTools(): ToolPort;
|
|
584
|
+
/**
|
|
585
|
+
* Gets the current LLM port.
|
|
586
|
+
*/
|
|
587
|
+
getLLM(): LLMPort;
|
|
588
|
+
/**
|
|
589
|
+
* Gets the current agent configuration.
|
|
590
|
+
*/
|
|
591
|
+
getConfig(): AgentConfig;
|
|
592
|
+
/**
|
|
593
|
+
* Updates the memory port without reinitializing the entire orchestrator.
|
|
594
|
+
* This allows starting a new conversation session while preserving LLM connections,
|
|
595
|
+
* MCP servers, and other state.
|
|
596
|
+
*/
|
|
597
|
+
setMemory(newMemory: MemoryPort<Message>): void;
|
|
598
|
+
/**
|
|
599
|
+
* Updates the event port without reinitializing the entire orchestrator.
|
|
600
|
+
* This is useful when switching to a new session with a different event log file.
|
|
601
|
+
*/
|
|
602
|
+
setEvents(newEvents: EventPort): void;
|
|
603
|
+
/**
|
|
604
|
+
* Determines if a tool should bypass approval requirements.
|
|
605
|
+
* Read-only tools and todo management tools are auto-approved.
|
|
606
|
+
*/
|
|
607
|
+
private shouldBypassApproval;
|
|
608
|
+
private handleToolDenial;
|
|
609
|
+
private processToolApproval;
|
|
610
|
+
send(content: UserMessagePayload, opts?: SendMessageOptions): Promise<MessageResponse>;
|
|
611
|
+
private waitForToolApproval;
|
|
612
|
+
handleToolApproval(approvalId: string, decision: ToolApprovalDecision, approvedCalls?: ToolCall[]): void;
|
|
613
|
+
private toInvocations;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
declare class SimpleContextBuilder implements ContextBuilder {
|
|
617
|
+
toProviderMessages(history: Message[], systemPrompt: string, newUserContent: MessageContent[]): ChatMessage[];
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
type RuntimeEnvInfo = {
|
|
621
|
+
cwd: string;
|
|
622
|
+
platform: string;
|
|
623
|
+
arch: string;
|
|
624
|
+
today: string;
|
|
625
|
+
tempDir: string;
|
|
626
|
+
workspaceDir: string;
|
|
627
|
+
};
|
|
628
|
+
type RuntimeEnvOptions = {
|
|
629
|
+
appName?: string;
|
|
630
|
+
};
|
|
631
|
+
declare class RuntimeEnv {
|
|
632
|
+
private appName;
|
|
633
|
+
private _workspaceDir;
|
|
634
|
+
constructor(opts?: RuntimeEnvOptions);
|
|
635
|
+
get workspaceDir(): string;
|
|
636
|
+
init(sessionId?: string): void;
|
|
637
|
+
info(): RuntimeEnvInfo;
|
|
638
|
+
resolveInWorkspace(...segments: string[]): string;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
type TemplateVars = Record<string, string | number | boolean | null | undefined>;
|
|
642
|
+
declare function renderTemplate(template: string, vars: TemplateVars): string;
|
|
643
|
+
type InjectedSystemParams = {
|
|
644
|
+
today: string;
|
|
645
|
+
platform: string;
|
|
646
|
+
arch: string;
|
|
647
|
+
tempDir: string;
|
|
648
|
+
workspaceDir: string;
|
|
649
|
+
availableAgents?: Array<{
|
|
650
|
+
id: string;
|
|
651
|
+
name: string;
|
|
652
|
+
description: string;
|
|
653
|
+
}>;
|
|
654
|
+
folderTree?: string;
|
|
655
|
+
};
|
|
656
|
+
declare function buildInjectedSystem(p: InjectedSystemParams, { withSubAgent }?: {
|
|
657
|
+
withSubAgent?: boolean;
|
|
658
|
+
}): string;
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* System prompt for the agent creation LLM
|
|
662
|
+
* This prompt guides the LLM to generate specialist agent configurations
|
|
663
|
+
*/
|
|
664
|
+
declare const AGENT_CREATOR_SYSTEM_PROMPT = "You are an elite AI agent architect. Your job is to translate user requirements into a precise, reliable agent specification and final system prompt that downstream systems can use directly.\n\n### Context you may receive\n- Project materials (e.g., CLAUDE.md), coding standards, project structure, and custom requirements. Inherit these patterns explicitly in your design.\n\n### Your high-level objective\n- Produce a complete, self-sufficient agent spec that includes: a concise identifier, a clear \"when to use\" description with examples, and a robust system prompt that governs behavior.\n\n### Operating principles (follow in order)\n1) **Extract Core Intent**\n - Identify purpose, scope, users, inputs, outputs, success criteria, constraints, and any implicit needs.\n - If code-review is requested, default scope to *recently written or changed code* unless the user explicitly requests a full-repo review.\n2) **Design Expert Persona**\n - Define a domain-specific role (e.g., senior code reviewer, API docs writer), decision style, and domain heuristics.\n - Assume the role of a recognized domain expert with deep mastery of relevant concepts, methodologies, and best practices. Let this expertise guide your decision-making through nuanced understanding, authoritative judgment, and strategic thinking that anticipates challenges and recognizes proven patterns.\n - Communicate with professional confidence while acknowledging uncertainty when appropriate.\n1) **Decompose the Task**\n - Lay out a short pipeline (PLAN \u2192 EXECUTE \u2192 VERIFY \u2192 OUTPUT). Keep steps concrete and checklist-driven. (Structured, decomposed prompts improve reliability.)\n2) **Specify Inputs, Tools, and Boundaries**\n - Name required inputs; state assumptions if missing.\n - List allowed tools/APIs and how to invoke them; define fallback behavior if tools fail.\n - Include stop conditions and escalation rules (when to ask the user for clarification, when to return partial results).\n3) **Quality & Reliability**\n - Build in self-checks: requirement coverage, constraint adherence, formatting validation.\n - Where applicable, instruct the agent to generate and verify reasoning internally, then present only the final, concise result.\n - Encourage evidence/verification for factual claims when sources are available.\n4) **Output Contract**\n - Define exact output formats (schemas, sections, or bullet checklists) so downstream consumers are deterministic.\n\n### System-prompt structure you must generate (use this template)\n\n# Role\nYou are <expert-persona>. You optimize for correctness, clarity, and adherence to project standards.\n\n# Goals\n- <bullet list of concrete goals>\n\n# Inputs\n- <required inputs>\n- Assumptions if missing: <rules to infer or request>\n\n# Process\n- PLAN: <brief checklist>\n- EXECUTE: <methods, frameworks, heuristics>\n- VERIFY: <self-checks, requirement coverage, constraint audit>\n- OUTPUT: <exact sections / schema>\n\n# Policies & Boundaries\n- Follow project coding standards from CLAUDE.md if provided.\n- Review only recent changes unless told otherwise.\n- If information is insufficient, ask precisely targeted questions (max 3) before proceeding; otherwise proceed with clearly stated assumptions.\n- Stop and escalate if safety, legal, or data-governance risks are detected.\n\n# Quality Bar\n- Ensure: correctness > completeness > speed.\n- Run a final \"Spec QA\" checklist before responding:\n 1) All user requirements mapped to sections?\n 2) Output format matches the contract exactly?\n 3) Edge cases addressed?\n 4) Examples included when helpful?\n\"\"\"\n\n### What to return\n- A **JSON object** with exactly these fields:\n - 'id': short, kebab-case, descriptive (2\u20134 words), no generic terms like 'helper' or 'assistant'.\n - 'description': starts with \"Use this agent when...\" and includes at least two concrete examples showing tool invocation (not direct replies). Include proactive triggers if implied.\n - 'systemPrompt': the final second-person system prompt built from the template above.\n\n### Additional guidance\n- Prefer explicit instructions over prohibitions; say what to do. (Specific, structured prompts improve outcomes.)\n- Use few-shot examples when they clarify behavior.\n- Be concise but complete\u2014every line should add execution value.\n- If constraints conflict, state the trade-off and your resolution.\n- Only include optional advanced reasoning guidance when beneficial; keep the final user-visible output clean.\n\n\n### REQUIRED OUTPUT: You MUST return a JSON object with at least the 'systemPrompt' field.\n\n**OPTIONAL FIELDS**: You may also include any of these fields (they have defaults if omitted):\n- 'id': A kebab-case identifier (e.g., \"security-auditor\", \"data-analyzer\")\n- 'name': A human-readable name (e.g., \"Security Auditor\", \"Data Analyzer\")\n- 'description': A brief description of when to use this agent\n- 'tools': An array of tool names the agent should have access to\n- 'temperature': A number between 0 and 1 (default: 0.7)\n\nExample outputs:\n\n{\n \"id\": \"security-auditor\",\n \"name\": \"Security Auditor\",\n \"description\": \"Use this agent when you need to perform a security audit on a codebase or application. For example, you might invoke this agent when you want to check for vulnerabilities in a web application or when you need to ensure compliance with security best practices.\",\n \"systemPrompt\": \"\n You are a security auditing specialist. Your role is to analyze code for security vulnerabilities, including SQL injection, XSS, CSRF, authentication issues, and insecure dependencies.\n\n Approach:\n 1. Read and analyze the codebase systematically\n 2. Check for common vulnerability patterns\n 3. Review dependencies for known CVEs\n 4. Provide specific, actionable remediation steps\n\n Always prioritize critical security issues and explain the potential impact.\",\n \"tools\": [\"file_read\", \"web_search\", \"bash_tool\"],\n \"temperature\": 0.3\n}\n\n{\n \"systemPrompt\": \"You are a helpful specialist agent that assists with general programming tasks. You can read files, search for information, and provide clear explanations.\"\n}\n\nRemember: 'systemPrompt' is REQUIRED. All other fields are optional and will have defaults applied if omitted.\nIMPORTANT: Return ONLY the JSON object as your response. Do NOT include any additional text or explanation.\n";
|
|
665
|
+
/**
|
|
666
|
+
* Generate a user prompt for agent creation
|
|
667
|
+
*/
|
|
668
|
+
declare function buildAgentCreationPrompt(userDescription: string): string;
|
|
669
|
+
|
|
670
|
+
type FolderTreeOptions = {
|
|
671
|
+
maxDepth?: number;
|
|
672
|
+
maxFiles?: number;
|
|
673
|
+
includeHidden?: boolean;
|
|
674
|
+
};
|
|
675
|
+
declare function generateFolderTree(rootDir: string, options?: FolderTreeOptions): Promise<string>;
|
|
676
|
+
|
|
677
|
+
declare class InMemoryMemory<T = unknown> implements MemoryPort<T> {
|
|
678
|
+
private store;
|
|
679
|
+
get(key: string): Promise<T[]>;
|
|
680
|
+
set(key: string, items: T[]): Promise<void>;
|
|
681
|
+
append(key: string, items: T[]): Promise<void>;
|
|
682
|
+
delete(key: string): Promise<void>;
|
|
683
|
+
keys(): Promise<string[]>;
|
|
684
|
+
clear(): Promise<void>;
|
|
685
|
+
exportSnapshot(): Promise<MemorySnapshot<T>>;
|
|
686
|
+
importSnapshot(snapshot: MemorySnapshot<T>): Promise<void>;
|
|
687
|
+
}
|
|
688
|
+
declare class JsonFileMemoryPersistence<T = unknown> implements MemoryPersistence<T> {
|
|
689
|
+
private filename;
|
|
690
|
+
constructor(filename?: string);
|
|
691
|
+
load(): Promise<MemorySnapshot<T>>;
|
|
692
|
+
save(snapshot: MemorySnapshot<T>): Promise<void>;
|
|
693
|
+
}
|
|
694
|
+
declare class PersistedMemory<T = unknown> implements MemoryPort<T> {
|
|
695
|
+
private persistence;
|
|
696
|
+
private inner;
|
|
697
|
+
private initialized;
|
|
698
|
+
constructor(persistence: MemoryPersistence<T>);
|
|
699
|
+
private ensureInitialized;
|
|
700
|
+
private save;
|
|
701
|
+
get(key: string): Promise<T[]>;
|
|
702
|
+
set(key: string, items: T[]): Promise<void>;
|
|
703
|
+
append(key: string, items: T[]): Promise<void>;
|
|
704
|
+
delete(key: string): Promise<void>;
|
|
705
|
+
keys(): Promise<string[]>;
|
|
706
|
+
clear(): Promise<void>;
|
|
707
|
+
exportSnapshot(): Promise<MemorySnapshot<T>>;
|
|
708
|
+
importSnapshot(snapshot: MemorySnapshot<T>): Promise<void>;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
declare class MemoryPortMetadataAdapter<T> implements MetadataPort<T> {
|
|
712
|
+
private memory;
|
|
713
|
+
private prefix;
|
|
714
|
+
constructor(memory: MemoryPort<unknown>, prefix?: string);
|
|
715
|
+
private getKey;
|
|
716
|
+
get(key: string): Promise<T | null>;
|
|
717
|
+
set(key: string, metadata: T): Promise<void>;
|
|
718
|
+
delete(key: string): Promise<void>;
|
|
719
|
+
keys(): Promise<string[]>;
|
|
720
|
+
clear(): Promise<void>;
|
|
721
|
+
exportSnapshot(): Promise<Record<string, T>>;
|
|
722
|
+
importSnapshot(snapshot: Record<string, T>): Promise<void>;
|
|
723
|
+
}
|
|
724
|
+
declare class InMemoryMetadata<T> implements MetadataPort<T> {
|
|
725
|
+
private store;
|
|
726
|
+
get(key: string): Promise<T | null>;
|
|
727
|
+
set(key: string, metadata: T): Promise<void>;
|
|
728
|
+
delete(key: string): Promise<void>;
|
|
729
|
+
keys(): Promise<string[]>;
|
|
730
|
+
clear(): Promise<void>;
|
|
731
|
+
exportSnapshot(): Promise<Record<string, T>>;
|
|
732
|
+
importSnapshot(snapshot: Record<string, T>): Promise<void>;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
type TokenUsage = {
|
|
736
|
+
promptTokens?: number;
|
|
737
|
+
completionTokens?: number;
|
|
738
|
+
totalTokens?: number;
|
|
739
|
+
};
|
|
740
|
+
type ConversationMetadata = {
|
|
741
|
+
topic?: string;
|
|
742
|
+
createdAt?: string;
|
|
743
|
+
updatedAt?: string;
|
|
744
|
+
messageCount?: number;
|
|
745
|
+
totalTokens?: number;
|
|
746
|
+
promptTokens?: number;
|
|
747
|
+
completionTokens?: number;
|
|
748
|
+
contextWindow?: TokenUsage;
|
|
749
|
+
};
|
|
750
|
+
type Conversation = {
|
|
751
|
+
messages: Message[];
|
|
752
|
+
metadata: ConversationMetadata;
|
|
753
|
+
};
|
|
754
|
+
type ConversationSnapshot = Record<string, Conversation>;
|
|
755
|
+
declare class ConversationStore {
|
|
756
|
+
private memory;
|
|
757
|
+
private metadataMemory;
|
|
758
|
+
constructor(memory: MemoryPort<Message>, metadataMemory?: MetadataPort<ConversationMetadata>);
|
|
759
|
+
getConversation(conversationId: string): Promise<Conversation>;
|
|
760
|
+
setConversation(conversationId: string, conversation: Conversation): Promise<void>;
|
|
761
|
+
appendMessages(conversationId: string, messages: Message[]): Promise<void>;
|
|
762
|
+
updateMetadata(conversationId: string, updates: Partial<ConversationMetadata>): Promise<void>;
|
|
763
|
+
incrementTokens(conversationId: string, tokenUsage: TokenUsage): Promise<void>;
|
|
764
|
+
updateTopic(conversationId: string, topic: string): Promise<void>;
|
|
765
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
766
|
+
listConversations(): Promise<{
|
|
767
|
+
id: string;
|
|
768
|
+
metadata: ConversationMetadata;
|
|
769
|
+
}[]>;
|
|
770
|
+
exportSnapshot(): Promise<ConversationSnapshot>;
|
|
771
|
+
importSnapshot(snapshot: ConversationSnapshot): Promise<void>;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
declare class ConversationContext {
|
|
775
|
+
private activeConversationId;
|
|
776
|
+
getActiveConversationId(): string;
|
|
777
|
+
setActiveConversationId(id: string): void;
|
|
778
|
+
createConversationId(topic?: string): string;
|
|
779
|
+
private slugify;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
declare class SimpleId implements IdGenerator$1 {
|
|
783
|
+
uuid(): string;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
declare class SystemClock implements Clock {
|
|
787
|
+
now(): number;
|
|
788
|
+
iso(dateMs?: number): string;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
declare class SimpleCost implements CostCalculator {
|
|
792
|
+
estimate(_model: string, _usage?: UsageData): number | undefined;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
declare class NoopReminders implements RemindersPort {
|
|
796
|
+
enhance(content: string, _opts: {
|
|
797
|
+
conversationId?: string;
|
|
798
|
+
}): string[];
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
type TodoStatus = 'pending' | 'in_progress' | 'completed';
|
|
802
|
+
type TodoPriority = 'high' | 'medium' | 'low';
|
|
803
|
+
type TodoItem = {
|
|
804
|
+
id: string;
|
|
805
|
+
content: string;
|
|
806
|
+
status: TodoStatus;
|
|
807
|
+
priority: TodoPriority;
|
|
808
|
+
conversationId?: string;
|
|
809
|
+
createdAt?: string;
|
|
810
|
+
updatedAt?: string;
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
declare class ToolRegistry implements ToolPort {
|
|
814
|
+
private tools;
|
|
815
|
+
private toolsMemory?;
|
|
816
|
+
private agentRegistry;
|
|
817
|
+
private assignTool?;
|
|
818
|
+
private enabledAgentsConfig;
|
|
819
|
+
constructor(opts?: {
|
|
820
|
+
todoMemory?: MemoryPort<TodoItem>;
|
|
821
|
+
toolsMemory?: MemoryPort<string>;
|
|
822
|
+
agentRegistry?: AgentRegistry;
|
|
823
|
+
});
|
|
824
|
+
private persistToolNames;
|
|
825
|
+
listRegisteredTools(): Promise<string[]>;
|
|
826
|
+
getToolDefinitions(enabledTools: string[]): ToolDefinition[];
|
|
827
|
+
/**
|
|
828
|
+
* Initialize AssignTool with orchestrator dependencies (lazy initialization)
|
|
829
|
+
*/
|
|
830
|
+
setOrchestrator(config: AgentConfig, llm: LLMPort, tools: ToolPort): void;
|
|
831
|
+
/**
|
|
832
|
+
* Get the agent registry
|
|
833
|
+
*/
|
|
834
|
+
getAgentRegistry(): AgentRegistry;
|
|
835
|
+
/**
|
|
836
|
+
* Update the enabled agents configuration for AssignTool
|
|
837
|
+
*/
|
|
838
|
+
setEnabledAgents(enabledAgents: Record<string, boolean>): void;
|
|
839
|
+
executeToolCalls(calls: ToolInvocation[], context?: Record<string, unknown>, maxConcurrent?: number, signal?: AbortSignal): Promise<ToolExecutionResult[]>;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
declare class CompositeToolPort implements ToolPort {
|
|
843
|
+
private ports;
|
|
844
|
+
constructor(ports: ToolPort[]);
|
|
845
|
+
getToolDefinitions(enabledTools: string[]): ToolDefinition[];
|
|
846
|
+
executeToolCalls(calls: ToolInvocation[], context?: Record<string, unknown>, maxConcurrent?: number, signal?: AbortSignal): Promise<ToolExecutionResult[]>;
|
|
847
|
+
setEnabledAgents(enabledAgents: Record<string, boolean>): void;
|
|
848
|
+
getAgentRegistry(): AgentRegistry | undefined;
|
|
849
|
+
listRegisteredTools(): Promise<string[]>;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
type ExecResult = Omit<ToolExecutionResult, 'id' | 'name'>;
|
|
853
|
+
type ToolExecutionContext = {
|
|
854
|
+
conversationId?: string;
|
|
855
|
+
agentId?: string;
|
|
856
|
+
sessionId?: string;
|
|
857
|
+
workspaceDir?: string;
|
|
858
|
+
delegationDepth?: number;
|
|
859
|
+
messageId?: string;
|
|
860
|
+
eventPort?: EventPort;
|
|
861
|
+
signal?: AbortSignal;
|
|
862
|
+
} & Record<string, unknown>;
|
|
863
|
+
interface FunctionTool<P = Record<string, unknown>, C = ToolExecutionContext> {
|
|
864
|
+
name: string;
|
|
865
|
+
parameters: object;
|
|
866
|
+
definition(): ToolDefinition['function'];
|
|
867
|
+
execute(params: P, context?: C): Promise<ExecResult> | ExecResult;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
type BashParams = {
|
|
871
|
+
cmd: string;
|
|
872
|
+
cwd?: string;
|
|
873
|
+
timeoutMs?: number;
|
|
874
|
+
};
|
|
875
|
+
declare class BashTool implements FunctionTool<BashParams, ToolExecutionContext> {
|
|
876
|
+
name: "bash_tool";
|
|
877
|
+
parameters: {
|
|
878
|
+
readonly type: "object";
|
|
879
|
+
readonly properties: {
|
|
880
|
+
readonly description: {
|
|
881
|
+
readonly type: "string";
|
|
882
|
+
readonly description: "Explanation of what this command will do (e.g., \"Get git commit log\")";
|
|
883
|
+
};
|
|
884
|
+
readonly cmd: {
|
|
885
|
+
readonly type: "string";
|
|
886
|
+
readonly description: "Shell command to run.";
|
|
887
|
+
};
|
|
888
|
+
readonly cwd: {
|
|
889
|
+
readonly type: "string";
|
|
890
|
+
readonly description: "Working directory.";
|
|
891
|
+
};
|
|
892
|
+
readonly timeoutMs: {
|
|
893
|
+
readonly type: "integer";
|
|
894
|
+
readonly minimum: 1;
|
|
895
|
+
readonly description: "Timeout in ms. Default: 30000.";
|
|
896
|
+
};
|
|
897
|
+
};
|
|
898
|
+
readonly required: readonly ["cmd"];
|
|
899
|
+
};
|
|
900
|
+
definition(): ToolDefinition['function'];
|
|
901
|
+
execute(p: BashParams, ctx?: ToolExecutionContext): Promise<ExecResult>;
|
|
902
|
+
private execOnce;
|
|
903
|
+
private defaultShell;
|
|
904
|
+
private shellExists;
|
|
905
|
+
private shellArgs;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* AgentManager - coordinates specialist agent execution for task delegation
|
|
910
|
+
*/
|
|
911
|
+
declare class AgentManager {
|
|
912
|
+
private delegatingConfig;
|
|
913
|
+
private delegatingLLM;
|
|
914
|
+
private delegatingTools;
|
|
915
|
+
private eventCallback?;
|
|
916
|
+
private activeAgents;
|
|
917
|
+
private eventCollectors;
|
|
918
|
+
constructor(delegatingConfig: AgentConfig, delegatingLLM: LLMPort, delegatingTools: ToolPort, eventCallback?: (event: AgentEvent) => void);
|
|
919
|
+
/**
|
|
920
|
+
* Create and execute a specialist agent for a specific task
|
|
921
|
+
*/
|
|
922
|
+
executeTask(config: SpecialistAgentConfig, signal?: AbortSignal): Promise<SpecialistAgentResult>;
|
|
923
|
+
/**
|
|
924
|
+
* Resolve which LLM to use (reuse delegating LLM or create new one)
|
|
925
|
+
*/
|
|
926
|
+
private resolveLLM;
|
|
927
|
+
/**
|
|
928
|
+
* Execute agent task with timeout
|
|
929
|
+
*/
|
|
930
|
+
private executeWithTimeout;
|
|
931
|
+
/**
|
|
932
|
+
* Get active specialist agent count
|
|
933
|
+
*/
|
|
934
|
+
getActiveAgentCount(): number;
|
|
935
|
+
/**
|
|
936
|
+
* Get events for a specific specialist agent
|
|
937
|
+
*/
|
|
938
|
+
getAgentEvents(agentId: string): AgentEvent[] | undefined;
|
|
939
|
+
/**
|
|
940
|
+
* Cleanup all active agents (emergency stop)
|
|
941
|
+
*/
|
|
942
|
+
cleanup(): void;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
interface AgentCatalog {
|
|
946
|
+
list(): AgentTemplate[];
|
|
947
|
+
get(agentId: string): AgentTemplate | undefined;
|
|
948
|
+
}
|
|
949
|
+
interface DelegationPolicyInput {
|
|
950
|
+
agent: AgentTemplate;
|
|
951
|
+
enabledAgents: Record<string, boolean>;
|
|
952
|
+
params: AssignParams;
|
|
953
|
+
context?: ToolExecutionContext;
|
|
954
|
+
}
|
|
955
|
+
interface PolicyDecision {
|
|
956
|
+
allowed: boolean;
|
|
957
|
+
reason?: string;
|
|
958
|
+
}
|
|
959
|
+
interface DelegationPolicy {
|
|
960
|
+
evaluate(input: DelegationPolicyInput): PolicyDecision;
|
|
961
|
+
}
|
|
962
|
+
interface SpecialistAgentFactoryInput {
|
|
963
|
+
template: AgentTemplate;
|
|
964
|
+
params: AssignParams;
|
|
965
|
+
context?: ToolExecutionContext;
|
|
966
|
+
currentDepth: number;
|
|
967
|
+
}
|
|
968
|
+
interface SpecialistAgentFactory {
|
|
969
|
+
create(input: SpecialistAgentFactoryInput): SpecialistAgentConfig;
|
|
970
|
+
}
|
|
971
|
+
interface AgentCommandRunner {
|
|
972
|
+
run(config: SpecialistAgentConfig, context?: ToolExecutionContext): Promise<SpecialistAgentResult>;
|
|
973
|
+
}
|
|
974
|
+
interface DelegationResult {
|
|
975
|
+
success: boolean;
|
|
976
|
+
summary?: string;
|
|
977
|
+
metadata?: Record<string, unknown>;
|
|
978
|
+
error?: string;
|
|
979
|
+
}
|
|
980
|
+
interface DelegationResultFormatter {
|
|
981
|
+
formatSuccess(agentId: string, result: SpecialistAgentResult): Pick<DelegationResult, 'summary' | 'metadata'>;
|
|
982
|
+
formatError(error: unknown): string;
|
|
983
|
+
}
|
|
984
|
+
interface DelegationService {
|
|
985
|
+
setEnabledAgents(enabledAgents: Record<string, boolean>): void;
|
|
986
|
+
listEnabledAgents(): AgentTemplate[];
|
|
987
|
+
delegate(params: AssignParams, context?: ToolExecutionContext): Promise<DelegationResult>;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Default policy checks whether the agent is enabled (if explicitly configured).
|
|
992
|
+
*/
|
|
993
|
+
declare class DefaultDelegationPolicy implements DelegationPolicy {
|
|
994
|
+
evaluate(input: DelegationPolicyInput): PolicyDecision;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
type SystemContext = {
|
|
998
|
+
timeISO: string;
|
|
999
|
+
platform: NodeJS.Platform;
|
|
1000
|
+
arch: string;
|
|
1001
|
+
tempDir: string;
|
|
1002
|
+
workspaceDir: string;
|
|
1003
|
+
};
|
|
1004
|
+
type AgentInfo = {
|
|
1005
|
+
id: string;
|
|
1006
|
+
name: string;
|
|
1007
|
+
description: string;
|
|
1008
|
+
};
|
|
1009
|
+
type SystemContextProvider = () => SystemContext;
|
|
1010
|
+
type AgentListProvider = () => AgentInfo[];
|
|
1011
|
+
type IdGenerator = (baseId: string) => string;
|
|
1012
|
+
declare class DefaultSpecialistAgentFactory implements SpecialistAgentFactory {
|
|
1013
|
+
private readonly options?;
|
|
1014
|
+
constructor(options?: {
|
|
1015
|
+
systemContextProvider?: SystemContextProvider;
|
|
1016
|
+
agentListProvider?: AgentListProvider;
|
|
1017
|
+
idGenerator?: IdGenerator;
|
|
1018
|
+
});
|
|
1019
|
+
create(input: SpecialistAgentFactoryInput): SpecialistAgentConfig;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
declare class AgentManagerCommandRunner implements AgentCommandRunner {
|
|
1023
|
+
private readonly delegatingConfig;
|
|
1024
|
+
private readonly delegatingLLM;
|
|
1025
|
+
private readonly delegatingTools;
|
|
1026
|
+
constructor(delegatingConfig: AgentConfig, delegatingLLM: LLMPort, delegatingTools: ToolPort);
|
|
1027
|
+
run(config: Parameters<AgentManager['executeTask']>[0], context?: ToolExecutionContext): Promise<SpecialistAgentResult>;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
declare class DefaultDelegationService implements DelegationService {
|
|
1031
|
+
private readonly catalog;
|
|
1032
|
+
private readonly policy;
|
|
1033
|
+
private readonly factory;
|
|
1034
|
+
private readonly runner;
|
|
1035
|
+
private readonly formatter;
|
|
1036
|
+
private enabledAgents;
|
|
1037
|
+
constructor(catalog: AgentCatalog, policy: DelegationPolicy, factory: SpecialistAgentFactory, runner: AgentCommandRunner, formatter: DelegationResultFormatter);
|
|
1038
|
+
setEnabledAgents(enabledAgents: Record<string, boolean>): void;
|
|
1039
|
+
listEnabledAgents(): AgentTemplate[];
|
|
1040
|
+
delegate(params: AssignParams, context?: ToolExecutionContext): Promise<DelegationResult>;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
declare class DefaultDelegationResultFormatter implements DelegationResultFormatter {
|
|
1044
|
+
formatSuccess(agentId: string, result: SpecialistAgentResult): {
|
|
1045
|
+
summary: string;
|
|
1046
|
+
metadata: {
|
|
1047
|
+
agentId: string;
|
|
1048
|
+
status: "success" | "error" | "timeout";
|
|
1049
|
+
executionTimeMs: number;
|
|
1050
|
+
toolCallsExecuted: number;
|
|
1051
|
+
tokensUsed: number;
|
|
1052
|
+
};
|
|
1053
|
+
};
|
|
1054
|
+
formatError(error: unknown): string;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
declare class EchoLLM implements LLMPort {
|
|
1058
|
+
generateCompletion(params: CompletionParams): Promise<CompletionResult>;
|
|
1059
|
+
private hasTool;
|
|
1060
|
+
private id;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
1064
|
+
type LogFormat = 'json' | 'structured';
|
|
1065
|
+
type PersistOptions = {
|
|
1066
|
+
persistFile?: string;
|
|
1067
|
+
logLevel?: LogLevel;
|
|
1068
|
+
logFormat?: LogFormat;
|
|
1069
|
+
maxFileSize?: number;
|
|
1070
|
+
enableConsoleLog?: boolean;
|
|
1071
|
+
captureResponseBody?: boolean;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
type HttpHeaders = Record<string, string>;
|
|
1075
|
+
interface TransportResponse {
|
|
1076
|
+
ok: boolean;
|
|
1077
|
+
status: number;
|
|
1078
|
+
json<T>(): Promise<T>;
|
|
1079
|
+
text(): Promise<string>;
|
|
1080
|
+
}
|
|
1081
|
+
interface HttpTransport {
|
|
1082
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1083
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1084
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1085
|
+
}
|
|
1086
|
+
declare class FetchTransport implements HttpTransport {
|
|
1087
|
+
private opts;
|
|
1088
|
+
private logger;
|
|
1089
|
+
constructor(opts?: PersistOptions);
|
|
1090
|
+
private getRequestSize;
|
|
1091
|
+
private getResponseSize;
|
|
1092
|
+
private headersToRecord;
|
|
1093
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1094
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1095
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
declare class GithubAuthTransport implements HttpTransport {
|
|
1099
|
+
private apiKey?;
|
|
1100
|
+
private accessToken?;
|
|
1101
|
+
private dynamicApiUrl?;
|
|
1102
|
+
private readonly baseUrl;
|
|
1103
|
+
private readonly inner;
|
|
1104
|
+
constructor(inner: FetchTransport, opts: {
|
|
1105
|
+
apiKey?: string;
|
|
1106
|
+
accessToken?: string;
|
|
1107
|
+
baseUrl?: string;
|
|
1108
|
+
});
|
|
1109
|
+
private exchangeToken;
|
|
1110
|
+
private buildFullUrl;
|
|
1111
|
+
private hasVisionPayload;
|
|
1112
|
+
private makeAuthHeaders;
|
|
1113
|
+
private determineInitiator;
|
|
1114
|
+
private generateRequestId;
|
|
1115
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1116
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1117
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
declare class OpenRouterAuthTransport implements HttpTransport {
|
|
1121
|
+
private readonly inner;
|
|
1122
|
+
private readonly apiKey?;
|
|
1123
|
+
private readonly baseUrl;
|
|
1124
|
+
constructor(inner: FetchTransport, apiKey?: string, baseUrl?: string);
|
|
1125
|
+
private buildFullUrl;
|
|
1126
|
+
private makeAuthHeaders;
|
|
1127
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1128
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1129
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
declare class DeepInfraAuthTransport implements HttpTransport {
|
|
1133
|
+
private readonly inner;
|
|
1134
|
+
private readonly apiKey?;
|
|
1135
|
+
private readonly baseUrl;
|
|
1136
|
+
constructor(inner: FetchTransport, apiKey?: string, baseUrl?: string);
|
|
1137
|
+
private buildFullUrl;
|
|
1138
|
+
private makeAuthHeaders;
|
|
1139
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1140
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1141
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
declare class ZAIAuthTransport implements HttpTransport {
|
|
1145
|
+
private readonly inner;
|
|
1146
|
+
private readonly apiKey?;
|
|
1147
|
+
private readonly baseUrl;
|
|
1148
|
+
constructor(inner: FetchTransport, apiKey?: string, baseUrl?: string);
|
|
1149
|
+
private buildFullUrl;
|
|
1150
|
+
private makeAuthHeaders;
|
|
1151
|
+
get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1152
|
+
postJson(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
|
|
1153
|
+
postStream(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
declare class LLMError extends Error {
|
|
1157
|
+
readonly statusCode?: number;
|
|
1158
|
+
readonly isRetryable: boolean;
|
|
1159
|
+
constructor(message: string, statusCode?: number, isRetryable?: boolean, cause?: unknown);
|
|
1160
|
+
}
|
|
1161
|
+
declare abstract class BaseLLM implements LLMPort {
|
|
1162
|
+
protected transport: HttpTransport | null;
|
|
1163
|
+
protected apiUrl: string;
|
|
1164
|
+
protected enablePromptCaching: boolean;
|
|
1165
|
+
constructor(apiUrl: string, options?: {
|
|
1166
|
+
enablePromptCaching?: boolean;
|
|
1167
|
+
});
|
|
1168
|
+
protected abstract createTransport(): HttpTransport;
|
|
1169
|
+
private getTransport;
|
|
1170
|
+
protected applyCacheControl(params: CompletionParams): CompletionParams;
|
|
1171
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1172
|
+
streamCompletion(params: CompletionParams, handlers?: {
|
|
1173
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
1174
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
1175
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
1176
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
type GithubOptions = {
|
|
1180
|
+
apiKey?: string;
|
|
1181
|
+
accessToken?: string;
|
|
1182
|
+
apiUrl?: string;
|
|
1183
|
+
httpLogFile?: string;
|
|
1184
|
+
};
|
|
1185
|
+
declare class GithubLLM extends BaseLLM implements LLMPort {
|
|
1186
|
+
private readonly opts;
|
|
1187
|
+
constructor(opts?: GithubOptions);
|
|
1188
|
+
protected createTransport(): GithubAuthTransport;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
type OpenRouterOptions = {
|
|
1192
|
+
apiKey?: string;
|
|
1193
|
+
apiUrl?: string;
|
|
1194
|
+
httpLogFile?: string;
|
|
1195
|
+
enablePromptCaching?: boolean;
|
|
1196
|
+
includeUsage?: boolean;
|
|
1197
|
+
};
|
|
1198
|
+
type OpenRouterModel = {
|
|
1199
|
+
id: string;
|
|
1200
|
+
canonical_slug: string;
|
|
1201
|
+
hugging_face_id: string;
|
|
1202
|
+
name: string;
|
|
1203
|
+
created: number;
|
|
1204
|
+
description: string;
|
|
1205
|
+
context_length: number;
|
|
1206
|
+
architecture: {
|
|
1207
|
+
modality: string;
|
|
1208
|
+
input_modalities: string[];
|
|
1209
|
+
output_modalities: string[];
|
|
1210
|
+
tokenizer: string;
|
|
1211
|
+
instruct_type: string | null;
|
|
1212
|
+
};
|
|
1213
|
+
pricing: {
|
|
1214
|
+
prompt: string;
|
|
1215
|
+
completion: string;
|
|
1216
|
+
request: string;
|
|
1217
|
+
image: string;
|
|
1218
|
+
web_search: string;
|
|
1219
|
+
internal_reasoning: string;
|
|
1220
|
+
input_cache_read: string;
|
|
1221
|
+
};
|
|
1222
|
+
top_provider: {
|
|
1223
|
+
context_length: number;
|
|
1224
|
+
max_completion_tokens: number | null;
|
|
1225
|
+
is_moderated: boolean;
|
|
1226
|
+
};
|
|
1227
|
+
per_request_limits: {
|
|
1228
|
+
prompt_tokens: string;
|
|
1229
|
+
completion_tokens: string;
|
|
1230
|
+
} | null;
|
|
1231
|
+
supported_parameters: string[];
|
|
1232
|
+
default_parameters: {
|
|
1233
|
+
temperature: number | null;
|
|
1234
|
+
top_p: number | null;
|
|
1235
|
+
frequency_penalty: number | null;
|
|
1236
|
+
};
|
|
1237
|
+
};
|
|
1238
|
+
declare class OpenRouterLLM extends BaseLLM implements LLMPort {
|
|
1239
|
+
private readonly includeUsage;
|
|
1240
|
+
constructor(opts?: OpenRouterOptions);
|
|
1241
|
+
private readonly opts;
|
|
1242
|
+
protected createTransport(): OpenRouterAuthTransport;
|
|
1243
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1244
|
+
streamCompletion(params: CompletionParams, handlers?: {
|
|
1245
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
1246
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
1247
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
1248
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1249
|
+
getModels(signal?: AbortSignal): Promise<OpenRouterModel[]>;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
type DeepInfraOptions = {
|
|
1253
|
+
apiKey?: string;
|
|
1254
|
+
apiUrl?: string;
|
|
1255
|
+
httpLogFile?: string;
|
|
1256
|
+
};
|
|
1257
|
+
type DeepInfraModel = {
|
|
1258
|
+
id: string;
|
|
1259
|
+
object: string;
|
|
1260
|
+
created: number;
|
|
1261
|
+
owned_by: string;
|
|
1262
|
+
root: string;
|
|
1263
|
+
parent: string | null;
|
|
1264
|
+
metadata: {
|
|
1265
|
+
description: string;
|
|
1266
|
+
context_length: number;
|
|
1267
|
+
max_tokens: number;
|
|
1268
|
+
pricing: {
|
|
1269
|
+
input_tokens: number;
|
|
1270
|
+
output_tokens: number;
|
|
1271
|
+
cache_read_tokens?: number;
|
|
1272
|
+
};
|
|
1273
|
+
tags: string[];
|
|
1274
|
+
};
|
|
1275
|
+
};
|
|
1276
|
+
declare class DeepInfraLLM extends BaseLLM implements LLMPort {
|
|
1277
|
+
private readonly opts;
|
|
1278
|
+
constructor(opts?: DeepInfraOptions);
|
|
1279
|
+
protected createTransport(): DeepInfraAuthTransport;
|
|
1280
|
+
getModels(signal?: AbortSignal): Promise<DeepInfraModel[]>;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
type ZaiOptions = {
|
|
1284
|
+
apiKey?: string;
|
|
1285
|
+
apiUrl?: string;
|
|
1286
|
+
httpLogFile?: string;
|
|
1287
|
+
};
|
|
1288
|
+
declare class ZaiLLM extends BaseLLM implements LLMPort {
|
|
1289
|
+
private readonly opts;
|
|
1290
|
+
constructor(opts?: ZaiOptions);
|
|
1291
|
+
protected createTransport(): ZAIAuthTransport;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
type AnthropicOptions = {
|
|
1295
|
+
apiKey?: string;
|
|
1296
|
+
oauth?: {
|
|
1297
|
+
type: 'oauth';
|
|
1298
|
+
access: string;
|
|
1299
|
+
refresh: string;
|
|
1300
|
+
expires: number;
|
|
1301
|
+
};
|
|
1302
|
+
apiUrl?: string;
|
|
1303
|
+
httpLogFile?: string;
|
|
1304
|
+
};
|
|
1305
|
+
declare class AnthropicLLM {
|
|
1306
|
+
private transport;
|
|
1307
|
+
private readonly opts;
|
|
1308
|
+
private readonly apiUrl;
|
|
1309
|
+
constructor(opts?: AnthropicOptions);
|
|
1310
|
+
private getTransport;
|
|
1311
|
+
private transformToAnthropicMessages;
|
|
1312
|
+
private transformTools;
|
|
1313
|
+
private transformToolChoice;
|
|
1314
|
+
private transformResponse;
|
|
1315
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1316
|
+
streamCompletion(params: CompletionParams, handlers?: {
|
|
1317
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
1318
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
1319
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
1320
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
type AnthropicAISDKOptions = {
|
|
1324
|
+
apiKey?: string;
|
|
1325
|
+
oauth?: {
|
|
1326
|
+
type: 'oauth';
|
|
1327
|
+
access: string;
|
|
1328
|
+
refresh: string;
|
|
1329
|
+
expires: number;
|
|
1330
|
+
};
|
|
1331
|
+
apiUrl?: string;
|
|
1332
|
+
baseURL?: string;
|
|
1333
|
+
httpLogFile?: string;
|
|
1334
|
+
onTokenUpdate?: (newCredentials: {
|
|
1335
|
+
access: string;
|
|
1336
|
+
refresh: string;
|
|
1337
|
+
expires: number;
|
|
1338
|
+
}) => void;
|
|
1339
|
+
};
|
|
1340
|
+
declare class AnthropicAISDKLLM {
|
|
1341
|
+
private readonly opts;
|
|
1342
|
+
private provider?;
|
|
1343
|
+
private refreshPromise;
|
|
1344
|
+
constructor(opts?: AnthropicAISDKOptions);
|
|
1345
|
+
private refreshAccessToken;
|
|
1346
|
+
private updateCredentials;
|
|
1347
|
+
private ensureValidToken;
|
|
1348
|
+
private createFetchWithRetry;
|
|
1349
|
+
private getProvider;
|
|
1350
|
+
private getModel;
|
|
1351
|
+
private transformMessages;
|
|
1352
|
+
private transformTools;
|
|
1353
|
+
private transformToolChoice;
|
|
1354
|
+
private handleError;
|
|
1355
|
+
generateCompletion(params: CompletionParams, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1356
|
+
streamCompletion(params: CompletionParams, handlers?: {
|
|
1357
|
+
onChunk?: (delta: string, usage?: UsageData) => void;
|
|
1358
|
+
onToolCallDelta?: (tc: ToolCall) => void;
|
|
1359
|
+
onStreamFinish?: (finishReason?: string, usage?: UsageData) => void;
|
|
1360
|
+
}, signal?: AbortSignal): Promise<CompletionResult>;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
type MCPHttpOptions = {
|
|
1364
|
+
type: 'http';
|
|
1365
|
+
url: string;
|
|
1366
|
+
headers?: Record<string, string>;
|
|
1367
|
+
};
|
|
1368
|
+
type MCPStdioOptions = {
|
|
1369
|
+
type: 'stdio';
|
|
1370
|
+
command: string;
|
|
1371
|
+
args?: string[];
|
|
1372
|
+
env?: Record<string, string>;
|
|
1373
|
+
stderr?: StdioServerParameters['stderr'];
|
|
1374
|
+
cwd?: string;
|
|
1375
|
+
};
|
|
1376
|
+
type MCPOptions = MCPHttpOptions | MCPStdioOptions;
|
|
1377
|
+
type MCPToolSchema = {
|
|
1378
|
+
name: string;
|
|
1379
|
+
description?: string;
|
|
1380
|
+
inputSchema: Record<string, unknown>;
|
|
1381
|
+
};
|
|
1382
|
+
type MCPToolCall = {
|
|
1383
|
+
name: string;
|
|
1384
|
+
arguments?: Record<string, any>;
|
|
1385
|
+
};
|
|
1386
|
+
type MCPCallResult = {
|
|
1387
|
+
content?: Array<unknown>;
|
|
1388
|
+
isError?: boolean;
|
|
1389
|
+
};
|
|
1390
|
+
declare class CoreMCPClient {
|
|
1391
|
+
private opts;
|
|
1392
|
+
private timeoutMs;
|
|
1393
|
+
private client;
|
|
1394
|
+
private transport;
|
|
1395
|
+
private connected;
|
|
1396
|
+
private tools;
|
|
1397
|
+
constructor(opts: MCPOptions, timeoutMs?: number);
|
|
1398
|
+
connect(): Promise<void>;
|
|
1399
|
+
isConnected(): boolean;
|
|
1400
|
+
disconnect(): Promise<void>;
|
|
1401
|
+
refreshTools(): Promise<MCPToolSchema[]>;
|
|
1402
|
+
getTools(): MCPToolSchema[];
|
|
1403
|
+
callTool(call: MCPToolCall): Promise<MCPCallResult>;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
declare class MCPToolPort implements ToolPort {
|
|
1407
|
+
private client;
|
|
1408
|
+
private map;
|
|
1409
|
+
private toolSchemas;
|
|
1410
|
+
private prefix;
|
|
1411
|
+
constructor(client: CoreMCPClient, opts?: {
|
|
1412
|
+
prefix?: string;
|
|
1413
|
+
});
|
|
1414
|
+
init(): Promise<void>;
|
|
1415
|
+
getExposedToolNames(): string[];
|
|
1416
|
+
getToolDefinitions(enabledTools: string[]): ToolDefinition[];
|
|
1417
|
+
executeToolCalls(calls: ToolInvocation[], _context?: Record<string, unknown>, maxConcurrent?: number, signal?: AbortSignal): Promise<ToolExecutionResult[]>;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
type MCPServerConfig = {
|
|
1421
|
+
command?: string;
|
|
1422
|
+
args?: string[];
|
|
1423
|
+
env?: Record<string, string>;
|
|
1424
|
+
transport?: 'stdio' | 'http';
|
|
1425
|
+
url?: string;
|
|
1426
|
+
headers?: Record<string, string>;
|
|
1427
|
+
prefix?: string;
|
|
1428
|
+
timeoutMs?: number;
|
|
1429
|
+
};
|
|
1430
|
+
type MCPConfig = {
|
|
1431
|
+
mcpServers: Record<string, MCPServerConfig>;
|
|
1432
|
+
};
|
|
1433
|
+
declare function loadMCPConfig(filePath?: string): Promise<MCPConfig | null>;
|
|
1434
|
+
|
|
1435
|
+
declare class PersistingConsoleEventPort implements EventPort {
|
|
1436
|
+
private memory;
|
|
1437
|
+
private maxPerConversation;
|
|
1438
|
+
constructor(opts?: {
|
|
1439
|
+
memory?: MemoryPort<AgentEvent>;
|
|
1440
|
+
filename?: string;
|
|
1441
|
+
maxPerConversation?: number;
|
|
1442
|
+
});
|
|
1443
|
+
emit(event: AgentEvent): Promise<void>;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
declare function normalizeNewlines(s: string): string;
|
|
1447
|
+
declare function resolveCarriageReturns(s: string): string;
|
|
1448
|
+
declare function resolveBackspaces(s: string): string;
|
|
1449
|
+
declare function stripAnsiAndControls(s: string): string;
|
|
1450
|
+
declare function canonicalizeTerminalPaste(raw: string): string;
|
|
1451
|
+
|
|
1452
|
+
export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, AnthropicLLM, type AssignParams, BashTool, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DeepInfraLLM, type DeepInfraModel, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, EchoLLM, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, JsonFileMemoryPersistence, LLMError, type LLMPort, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, NoopReminders, OpenRouterLLM, type OpenRouterModel, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UserAttachment, type UserMessagePayload, ZaiLLM, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, generateFolderTree, loadMCPConfig, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls };
|