@everworker/oneringai 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 +21 -0
- package/README.md +1228 -0
- package/dist/IProvider-BP49c93d.d.cts +22 -0
- package/dist/IProvider-BP49c93d.d.ts +22 -0
- package/dist/ImageModel-B-uH3JEz.d.cts +763 -0
- package/dist/ImageModel-C7EyUfU0.d.ts +763 -0
- package/dist/capabilities/agents/index.cjs +408 -0
- package/dist/capabilities/agents/index.cjs.map +1 -0
- package/dist/capabilities/agents/index.d.cts +3 -0
- package/dist/capabilities/agents/index.d.ts +3 -0
- package/dist/capabilities/agents/index.js +405 -0
- package/dist/capabilities/agents/index.js.map +1 -0
- package/dist/capabilities/images/index.cjs +3583 -0
- package/dist/capabilities/images/index.cjs.map +1 -0
- package/dist/capabilities/images/index.d.cts +2 -0
- package/dist/capabilities/images/index.d.ts +2 -0
- package/dist/capabilities/images/index.js +3556 -0
- package/dist/capabilities/images/index.js.map +1 -0
- package/dist/index-BmOYeqU7.d.ts +1338 -0
- package/dist/index-DCzFlLoN.d.cts +1338 -0
- package/dist/index.cjs +49257 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12263 -0
- package/dist/index.d.ts +12263 -0
- package/dist/index.js +48953 -0
- package/dist/index.js.map +1 -0
- package/package.json +162 -0
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
import { I as IProvider } from './IProvider-BP49c93d.cjs';
|
|
2
|
+
import { EventEmitter } from 'eventemitter3';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Memory entities for WorkingMemory
|
|
6
|
+
*
|
|
7
|
+
* This module provides a GENERIC memory system that works across all agent types:
|
|
8
|
+
* - Basic Agent: Simple session/persistent scoping with static priority
|
|
9
|
+
* - TaskAgent: Task-aware scoping with dynamic priority based on task states
|
|
10
|
+
* - UniversalAgent: Mode-aware, switches strategy based on current mode
|
|
11
|
+
*
|
|
12
|
+
* The key abstraction is PriorityCalculator - a pluggable strategy that
|
|
13
|
+
* determines entry priority for eviction decisions.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Simple scope for basic agents - just a lifecycle label
|
|
17
|
+
*/
|
|
18
|
+
type SimpleScope = 'session' | 'persistent';
|
|
19
|
+
/**
|
|
20
|
+
* Task-aware scope for TaskAgent/UniversalAgent
|
|
21
|
+
*/
|
|
22
|
+
type TaskAwareScope = {
|
|
23
|
+
type: 'task';
|
|
24
|
+
taskIds: string[];
|
|
25
|
+
} | {
|
|
26
|
+
type: 'plan';
|
|
27
|
+
} | {
|
|
28
|
+
type: 'persistent';
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Union type - memory system accepts both
|
|
32
|
+
*/
|
|
33
|
+
type MemoryScope = SimpleScope | TaskAwareScope;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard: is this a task-aware scope?
|
|
36
|
+
*/
|
|
37
|
+
declare function isTaskAwareScope(scope: MemoryScope): scope is TaskAwareScope;
|
|
38
|
+
/**
|
|
39
|
+
* Type guard: is this a simple scope?
|
|
40
|
+
*/
|
|
41
|
+
declare function isSimpleScope(scope: MemoryScope): scope is SimpleScope;
|
|
42
|
+
/**
|
|
43
|
+
* Compare two scopes for equality
|
|
44
|
+
* Handles both simple scopes (string comparison) and task-aware scopes (deep comparison)
|
|
45
|
+
*/
|
|
46
|
+
declare function scopeEquals(a: MemoryScope, b: MemoryScope): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a scope matches a filter scope
|
|
49
|
+
* More flexible than scopeEquals - supports partial matching for task scopes
|
|
50
|
+
*/
|
|
51
|
+
declare function scopeMatches(entryScope: MemoryScope, filterScope: MemoryScope): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Priority determines eviction order (lower priority evicted first)
|
|
54
|
+
*
|
|
55
|
+
* - critical: Never evicted (pinned, or actively in use)
|
|
56
|
+
* - high: Important data, evicted only when necessary
|
|
57
|
+
* - normal: Default priority
|
|
58
|
+
* - low: Candidate for eviction (stale data, completed task data)
|
|
59
|
+
*/
|
|
60
|
+
type MemoryPriority = 'critical' | 'high' | 'normal' | 'low';
|
|
61
|
+
/**
|
|
62
|
+
* Priority values for comparison (higher = more important, less likely to evict)
|
|
63
|
+
*/
|
|
64
|
+
declare const MEMORY_PRIORITY_VALUES: Record<MemoryPriority, number>;
|
|
65
|
+
/**
|
|
66
|
+
* Memory tier for hierarchical data management
|
|
67
|
+
*
|
|
68
|
+
* The tier system provides a structured approach to managing research/analysis data:
|
|
69
|
+
* - raw: Original data, low priority, first to be evicted
|
|
70
|
+
* - summary: Processed summaries, normal priority
|
|
71
|
+
* - findings: Final conclusions/insights, high priority, kept longest
|
|
72
|
+
*
|
|
73
|
+
* Workflow: raw → summary → findings (data gets more refined, priority increases)
|
|
74
|
+
*/
|
|
75
|
+
type MemoryTier = 'raw' | 'summary' | 'findings';
|
|
76
|
+
/**
|
|
77
|
+
* Context passed to priority calculator - varies by agent type
|
|
78
|
+
*/
|
|
79
|
+
interface PriorityContext {
|
|
80
|
+
/** For TaskAgent: map of taskId → current status */
|
|
81
|
+
taskStates?: Map<string, TaskStatusForMemory>;
|
|
82
|
+
/** For UniversalAgent: current mode */
|
|
83
|
+
mode?: 'interactive' | 'planning' | 'executing';
|
|
84
|
+
/** Custom context for extensions */
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Task status values for priority calculation
|
|
89
|
+
*/
|
|
90
|
+
type TaskStatusForMemory = 'pending' | 'in_progress' | 'completed' | 'failed' | 'skipped' | 'cancelled';
|
|
91
|
+
/**
|
|
92
|
+
* Check if a task status is terminal (task will not progress further)
|
|
93
|
+
*/
|
|
94
|
+
declare function isTerminalMemoryStatus(status: TaskStatusForMemory): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Priority calculator function type.
|
|
97
|
+
* Given an entry and optional context, returns the effective priority.
|
|
98
|
+
*/
|
|
99
|
+
type PriorityCalculator = (entry: MemoryEntry, context?: PriorityContext) => MemoryPriority;
|
|
100
|
+
/**
|
|
101
|
+
* Reason why an entry became stale
|
|
102
|
+
*/
|
|
103
|
+
type StaleReason = 'task_completed' | 'task_failed' | 'unused' | 'scope_cleared';
|
|
104
|
+
/**
|
|
105
|
+
* Information about a stale entry for LLM notification
|
|
106
|
+
*/
|
|
107
|
+
interface StaleEntryInfo {
|
|
108
|
+
key: string;
|
|
109
|
+
description: string;
|
|
110
|
+
reason: StaleReason;
|
|
111
|
+
previousPriority: MemoryPriority;
|
|
112
|
+
newPriority: MemoryPriority;
|
|
113
|
+
taskIds?: string[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Single memory entry stored in working memory
|
|
117
|
+
*/
|
|
118
|
+
interface MemoryEntry {
|
|
119
|
+
key: string;
|
|
120
|
+
description: string;
|
|
121
|
+
value: unknown;
|
|
122
|
+
sizeBytes: number;
|
|
123
|
+
scope: MemoryScope;
|
|
124
|
+
basePriority: MemoryPriority;
|
|
125
|
+
pinned: boolean;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
lastAccessedAt: number;
|
|
128
|
+
accessCount: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Index entry (lightweight, always in context)
|
|
132
|
+
*/
|
|
133
|
+
interface MemoryIndexEntry {
|
|
134
|
+
key: string;
|
|
135
|
+
description: string;
|
|
136
|
+
size: string;
|
|
137
|
+
scope: MemoryScope;
|
|
138
|
+
effectivePriority: MemoryPriority;
|
|
139
|
+
pinned: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Full memory index with metadata
|
|
143
|
+
*/
|
|
144
|
+
interface MemoryIndex {
|
|
145
|
+
entries: MemoryIndexEntry[];
|
|
146
|
+
totalSizeBytes: number;
|
|
147
|
+
totalSizeHuman: string;
|
|
148
|
+
limitBytes: number;
|
|
149
|
+
limitHuman: string;
|
|
150
|
+
utilizationPercent: number;
|
|
151
|
+
/** Total entry count (before any truncation for display) */
|
|
152
|
+
totalEntryCount: number;
|
|
153
|
+
/** Number of entries omitted from display due to maxIndexEntries limit */
|
|
154
|
+
omittedCount: number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Configuration for working memory
|
|
158
|
+
*/
|
|
159
|
+
interface WorkingMemoryConfig {
|
|
160
|
+
/** Max memory size in bytes. If not set, calculated from model context */
|
|
161
|
+
maxSizeBytes?: number;
|
|
162
|
+
/** Max number of entries in the memory index. Excess entries are auto-evicted via LRU. Default: 30 */
|
|
163
|
+
maxIndexEntries?: number;
|
|
164
|
+
/** Max description length */
|
|
165
|
+
descriptionMaxLength: number;
|
|
166
|
+
/** Percentage at which to warn agent */
|
|
167
|
+
softLimitPercent: number;
|
|
168
|
+
/** Percentage of model context to allocate to memory */
|
|
169
|
+
contextAllocationPercent: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Input for creating a memory entry
|
|
173
|
+
*/
|
|
174
|
+
interface MemoryEntryInput {
|
|
175
|
+
key: string;
|
|
176
|
+
description: string;
|
|
177
|
+
value: unknown;
|
|
178
|
+
/** Scope - defaults to 'session' for basic agents */
|
|
179
|
+
scope?: MemoryScope;
|
|
180
|
+
/** Base priority - may be overridden by dynamic calculation */
|
|
181
|
+
priority?: MemoryPriority;
|
|
182
|
+
/** If true, entry is never evicted */
|
|
183
|
+
pinned?: boolean;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a task-scoped memory entry input
|
|
187
|
+
*/
|
|
188
|
+
declare function forTasks(key: string, description: string, value: unknown, taskIds: string[], options?: {
|
|
189
|
+
priority?: MemoryPriority;
|
|
190
|
+
pinned?: boolean;
|
|
191
|
+
}): MemoryEntryInput;
|
|
192
|
+
/**
|
|
193
|
+
* Create a plan-scoped memory entry input
|
|
194
|
+
*/
|
|
195
|
+
declare function forPlan(key: string, description: string, value: unknown, options?: {
|
|
196
|
+
priority?: MemoryPriority;
|
|
197
|
+
pinned?: boolean;
|
|
198
|
+
}): MemoryEntryInput;
|
|
199
|
+
/**
|
|
200
|
+
* Default configuration values
|
|
201
|
+
*/
|
|
202
|
+
declare const DEFAULT_MEMORY_CONFIG: WorkingMemoryConfig;
|
|
203
|
+
/**
|
|
204
|
+
* Calculate the size of a value in bytes (JSON serialization)
|
|
205
|
+
* Uses Buffer.byteLength for accurate UTF-8 byte count
|
|
206
|
+
*/
|
|
207
|
+
declare function calculateEntrySize(value: unknown): number;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Tool context interface - passed to tools during execution
|
|
211
|
+
*
|
|
212
|
+
* This is a SIMPLE interface. Tools receive only what they need:
|
|
213
|
+
* - agentId: For logging/tracing
|
|
214
|
+
* - taskId: For task-aware operations
|
|
215
|
+
* - memory: For storing/retrieving data
|
|
216
|
+
* - signal: For cancellation
|
|
217
|
+
*
|
|
218
|
+
* Plugins and context management are NOT exposed to tools.
|
|
219
|
+
* Tools should be self-contained and not depend on framework internals.
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Limited memory access for tools
|
|
224
|
+
*
|
|
225
|
+
* This interface is designed to work with all agent types:
|
|
226
|
+
* - Basic agents: Use simple scopes ('session', 'persistent')
|
|
227
|
+
* - TaskAgent: Use task-aware scopes ({ type: 'task', taskIds: [...] })
|
|
228
|
+
* - UniversalAgent: Switches between simple and task-aware based on mode
|
|
229
|
+
*/
|
|
230
|
+
interface WorkingMemoryAccess {
|
|
231
|
+
get(key: string): Promise<unknown>;
|
|
232
|
+
/**
|
|
233
|
+
* Store a value in memory
|
|
234
|
+
*
|
|
235
|
+
* @param key - Unique key for the entry
|
|
236
|
+
* @param description - Short description (max 150 chars)
|
|
237
|
+
* @param value - Data to store
|
|
238
|
+
* @param options - Optional scope, priority, and pinning
|
|
239
|
+
*/
|
|
240
|
+
set(key: string, description: string, value: unknown, options?: {
|
|
241
|
+
/** Scope determines lifecycle - defaults to 'session' */
|
|
242
|
+
scope?: MemoryScope;
|
|
243
|
+
/** Base priority for eviction ordering */
|
|
244
|
+
priority?: MemoryPriority;
|
|
245
|
+
/** If true, entry is never evicted */
|
|
246
|
+
pinned?: boolean;
|
|
247
|
+
}): Promise<void>;
|
|
248
|
+
delete(key: string): Promise<void>;
|
|
249
|
+
has(key: string): Promise<boolean>;
|
|
250
|
+
/**
|
|
251
|
+
* List all memory entries
|
|
252
|
+
* Returns key, description, and computed priority info
|
|
253
|
+
*/
|
|
254
|
+
list(): Promise<Array<{
|
|
255
|
+
key: string;
|
|
256
|
+
description: string;
|
|
257
|
+
effectivePriority?: MemoryPriority;
|
|
258
|
+
pinned?: boolean;
|
|
259
|
+
}>>;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Context passed to tool execute function
|
|
263
|
+
*
|
|
264
|
+
* Simple and clean - only what tools actually need.
|
|
265
|
+
*/
|
|
266
|
+
interface ToolContext {
|
|
267
|
+
/** Agent ID (for logging/tracing) */
|
|
268
|
+
agentId?: string;
|
|
269
|
+
/** Task ID (if running in TaskAgent) */
|
|
270
|
+
taskId?: string;
|
|
271
|
+
/** Working memory access (if agent has memory feature enabled) */
|
|
272
|
+
memory?: WorkingMemoryAccess;
|
|
273
|
+
/** Abort signal for cancellation */
|
|
274
|
+
signal?: AbortSignal;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Tool entities with blocking/non-blocking execution support
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
interface JSONSchema {
|
|
282
|
+
type: string;
|
|
283
|
+
properties?: Record<string, any>;
|
|
284
|
+
required?: string[];
|
|
285
|
+
[key: string]: any;
|
|
286
|
+
}
|
|
287
|
+
interface FunctionToolDefinition {
|
|
288
|
+
type: 'function';
|
|
289
|
+
function: {
|
|
290
|
+
name: string;
|
|
291
|
+
description?: string;
|
|
292
|
+
parameters?: JSONSchema;
|
|
293
|
+
strict?: boolean;
|
|
294
|
+
};
|
|
295
|
+
blocking?: boolean;
|
|
296
|
+
timeout?: number;
|
|
297
|
+
}
|
|
298
|
+
interface BuiltInTool {
|
|
299
|
+
type: 'web_search' | 'file_search' | 'computer_use' | 'code_interpreter';
|
|
300
|
+
blocking?: boolean;
|
|
301
|
+
}
|
|
302
|
+
type Tool = FunctionToolDefinition | BuiltInTool;
|
|
303
|
+
declare enum ToolCallState {
|
|
304
|
+
PENDING = "pending",// Tool call identified, not yet executed
|
|
305
|
+
EXECUTING = "executing",// Currently executing
|
|
306
|
+
COMPLETED = "completed",// Successfully completed
|
|
307
|
+
FAILED = "failed",// Execution failed
|
|
308
|
+
TIMEOUT = "timeout"
|
|
309
|
+
}
|
|
310
|
+
interface ToolCall {
|
|
311
|
+
id: string;
|
|
312
|
+
type: 'function';
|
|
313
|
+
function: {
|
|
314
|
+
name: string;
|
|
315
|
+
arguments: string;
|
|
316
|
+
};
|
|
317
|
+
blocking: boolean;
|
|
318
|
+
state: ToolCallState;
|
|
319
|
+
startTime?: Date;
|
|
320
|
+
endTime?: Date;
|
|
321
|
+
error?: string;
|
|
322
|
+
}
|
|
323
|
+
interface ToolResult {
|
|
324
|
+
tool_use_id: string;
|
|
325
|
+
tool_name?: string;
|
|
326
|
+
tool_args?: Record<string, unknown>;
|
|
327
|
+
content: any;
|
|
328
|
+
error?: string;
|
|
329
|
+
executionTime?: number;
|
|
330
|
+
state: ToolCallState;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Tool execution context - tracks all tool calls in a generation
|
|
334
|
+
*/
|
|
335
|
+
interface ToolExecutionContext {
|
|
336
|
+
executionId: string;
|
|
337
|
+
toolCalls: Map<string, ToolCall>;
|
|
338
|
+
pendingNonBlocking: Set<string>;
|
|
339
|
+
completedResults: Map<string, ToolResult>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Output handling hints for context management
|
|
343
|
+
*/
|
|
344
|
+
interface ToolOutputHints {
|
|
345
|
+
expectedSize?: 'small' | 'medium' | 'large' | 'variable';
|
|
346
|
+
summarize?: (output: unknown) => string;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Idempotency configuration for tool caching
|
|
350
|
+
*/
|
|
351
|
+
interface ToolIdempotency {
|
|
352
|
+
/**
|
|
353
|
+
* @deprecated Use 'cacheable' instead. Will be removed in a future version.
|
|
354
|
+
* If true, tool is naturally idempotent (e.g., read-only) and doesn't need caching.
|
|
355
|
+
* If false, tool results should be cached based on arguments.
|
|
356
|
+
*/
|
|
357
|
+
safe?: boolean;
|
|
358
|
+
/**
|
|
359
|
+
* If true, tool results can be cached based on arguments.
|
|
360
|
+
* Use this for tools that return deterministic results for the same inputs.
|
|
361
|
+
* Takes precedence over the deprecated 'safe' field.
|
|
362
|
+
* @default false
|
|
363
|
+
*/
|
|
364
|
+
cacheable?: boolean;
|
|
365
|
+
keyFn?: (args: Record<string, unknown>) => string;
|
|
366
|
+
ttlMs?: number;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Permission configuration for a tool
|
|
370
|
+
*
|
|
371
|
+
* Controls when approval is required for tool execution.
|
|
372
|
+
* Used by the ToolPermissionManager.
|
|
373
|
+
*/
|
|
374
|
+
interface ToolPermissionConfig {
|
|
375
|
+
/**
|
|
376
|
+
* When approval is required.
|
|
377
|
+
* - 'once' - Require approval for each call
|
|
378
|
+
* - 'session' - Approve once per session
|
|
379
|
+
* - 'always' - Auto-approve (no prompts)
|
|
380
|
+
* - 'never' - Always blocked
|
|
381
|
+
* @default 'once'
|
|
382
|
+
*/
|
|
383
|
+
scope?: 'once' | 'session' | 'always' | 'never';
|
|
384
|
+
/**
|
|
385
|
+
* Risk level classification.
|
|
386
|
+
* @default 'low'
|
|
387
|
+
*/
|
|
388
|
+
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
389
|
+
/**
|
|
390
|
+
* Custom message shown in approval UI.
|
|
391
|
+
*/
|
|
392
|
+
approvalMessage?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Argument names that should be highlighted as sensitive.
|
|
395
|
+
*/
|
|
396
|
+
sensitiveArgs?: string[];
|
|
397
|
+
/**
|
|
398
|
+
* TTL for session approvals (milliseconds).
|
|
399
|
+
*/
|
|
400
|
+
sessionTTLMs?: number;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* User-provided tool function
|
|
404
|
+
*/
|
|
405
|
+
interface ToolFunction<TArgs = any, TResult = any> {
|
|
406
|
+
definition: FunctionToolDefinition;
|
|
407
|
+
execute: (args: TArgs, context?: ToolContext) => Promise<TResult>;
|
|
408
|
+
idempotency?: ToolIdempotency;
|
|
409
|
+
output?: ToolOutputHints;
|
|
410
|
+
/** Permission settings for this tool. If not set, defaults are used. */
|
|
411
|
+
permission?: ToolPermissionConfig;
|
|
412
|
+
/**
|
|
413
|
+
* Dynamic description generator for the tool.
|
|
414
|
+
* If provided, this function is called when tool definitions are serialized for the LLM,
|
|
415
|
+
* allowing the description to reflect current state (e.g., available connectors).
|
|
416
|
+
*
|
|
417
|
+
* The returned string replaces definition.function.description when sending to LLM.
|
|
418
|
+
* The static description in definition.function.description serves as a fallback.
|
|
419
|
+
*
|
|
420
|
+
* @returns The current tool description
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* // Tool with dynamic connector list:
|
|
424
|
+
* descriptionFactory: () => {
|
|
425
|
+
* const connectors = Connector.listAll();
|
|
426
|
+
* return `Execute API calls. Available connectors: ${connectors.map(c => c.name).join(', ')}`;
|
|
427
|
+
* }
|
|
428
|
+
*/
|
|
429
|
+
descriptionFactory?: () => string;
|
|
430
|
+
/**
|
|
431
|
+
* Returns a human-readable description of a tool call.
|
|
432
|
+
* Used for logging, UI display, and debugging.
|
|
433
|
+
*
|
|
434
|
+
* @param args - The arguments passed to the tool
|
|
435
|
+
* @returns A concise description (e.g., "reading /path/to/file.ts")
|
|
436
|
+
*
|
|
437
|
+
* If not implemented, use `defaultDescribeCall()` as a fallback.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* // For read_file tool:
|
|
441
|
+
* describeCall: (args) => args.file_path
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* // For bash tool:
|
|
445
|
+
* describeCall: (args) => args.command.length > 50
|
|
446
|
+
* ? args.command.slice(0, 47) + '...'
|
|
447
|
+
* : args.command
|
|
448
|
+
*/
|
|
449
|
+
describeCall?: (args: TArgs) => string;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Default implementation for describeCall.
|
|
453
|
+
* Shows the first meaningful argument value.
|
|
454
|
+
*
|
|
455
|
+
* @param args - Tool arguments object
|
|
456
|
+
* @param maxLength - Maximum length before truncation (default: 60)
|
|
457
|
+
* @returns Human-readable description
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* defaultDescribeCall({ file_path: '/path/to/file.ts' })
|
|
461
|
+
* // Returns: '/path/to/file.ts'
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* defaultDescribeCall({ query: 'search term', limit: 10 })
|
|
465
|
+
* // Returns: 'search term'
|
|
466
|
+
*/
|
|
467
|
+
declare function defaultDescribeCall(args: Record<string, unknown>, maxLength?: number): string;
|
|
468
|
+
/**
|
|
469
|
+
* Get a human-readable description of a tool call.
|
|
470
|
+
* Uses the tool's describeCall method if available, otherwise falls back to default.
|
|
471
|
+
*
|
|
472
|
+
* @param tool - The tool function
|
|
473
|
+
* @param args - The arguments passed to the tool
|
|
474
|
+
* @returns Human-readable description
|
|
475
|
+
*/
|
|
476
|
+
declare function getToolCallDescription<TArgs>(tool: ToolFunction<TArgs>, args: TArgs): string;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Content types based on OpenAI Responses API format
|
|
480
|
+
*/
|
|
481
|
+
declare enum ContentType {
|
|
482
|
+
INPUT_TEXT = "input_text",
|
|
483
|
+
INPUT_IMAGE_URL = "input_image_url",
|
|
484
|
+
INPUT_FILE = "input_file",
|
|
485
|
+
OUTPUT_TEXT = "output_text",
|
|
486
|
+
TOOL_USE = "tool_use",
|
|
487
|
+
TOOL_RESULT = "tool_result"
|
|
488
|
+
}
|
|
489
|
+
interface BaseContent {
|
|
490
|
+
type: ContentType;
|
|
491
|
+
}
|
|
492
|
+
interface InputTextContent extends BaseContent {
|
|
493
|
+
type: ContentType.INPUT_TEXT;
|
|
494
|
+
text: string;
|
|
495
|
+
}
|
|
496
|
+
interface InputImageContent extends BaseContent {
|
|
497
|
+
type: ContentType.INPUT_IMAGE_URL;
|
|
498
|
+
image_url: {
|
|
499
|
+
url: string;
|
|
500
|
+
detail?: 'auto' | 'low' | 'high';
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
interface InputFileContent extends BaseContent {
|
|
504
|
+
type: ContentType.INPUT_FILE;
|
|
505
|
+
file_id: string;
|
|
506
|
+
}
|
|
507
|
+
interface OutputTextContent extends BaseContent {
|
|
508
|
+
type: ContentType.OUTPUT_TEXT;
|
|
509
|
+
text: string;
|
|
510
|
+
annotations?: any[];
|
|
511
|
+
}
|
|
512
|
+
interface ToolUseContent extends BaseContent {
|
|
513
|
+
type: ContentType.TOOL_USE;
|
|
514
|
+
id: string;
|
|
515
|
+
name: string;
|
|
516
|
+
arguments: string;
|
|
517
|
+
}
|
|
518
|
+
interface ToolResultContent extends BaseContent {
|
|
519
|
+
type: ContentType.TOOL_RESULT;
|
|
520
|
+
tool_use_id: string;
|
|
521
|
+
content: string | any;
|
|
522
|
+
error?: string;
|
|
523
|
+
}
|
|
524
|
+
type Content = InputTextContent | InputImageContent | InputFileContent | OutputTextContent | ToolUseContent | ToolResultContent;
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Message entity based on OpenAI Responses API format
|
|
528
|
+
*/
|
|
529
|
+
|
|
530
|
+
declare enum MessageRole {
|
|
531
|
+
USER = "user",
|
|
532
|
+
ASSISTANT = "assistant",
|
|
533
|
+
DEVELOPER = "developer"
|
|
534
|
+
}
|
|
535
|
+
interface Message {
|
|
536
|
+
type: 'message';
|
|
537
|
+
id?: string;
|
|
538
|
+
role: MessageRole;
|
|
539
|
+
content: Content[];
|
|
540
|
+
}
|
|
541
|
+
interface CompactionItem {
|
|
542
|
+
type: 'compaction';
|
|
543
|
+
id: string;
|
|
544
|
+
encrypted_content: string;
|
|
545
|
+
}
|
|
546
|
+
interface ReasoningItem {
|
|
547
|
+
type: 'reasoning';
|
|
548
|
+
id: string;
|
|
549
|
+
effort?: 'low' | 'medium' | 'high';
|
|
550
|
+
summary?: string;
|
|
551
|
+
encrypted_content?: string;
|
|
552
|
+
}
|
|
553
|
+
type InputItem = Message | CompactionItem;
|
|
554
|
+
type OutputItem = Message | CompactionItem | ReasoningItem;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* LLM Response entity based on OpenAI Responses API format
|
|
558
|
+
*/
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Token usage statistics
|
|
562
|
+
*/
|
|
563
|
+
interface TokenUsage {
|
|
564
|
+
input_tokens: number;
|
|
565
|
+
output_tokens: number;
|
|
566
|
+
total_tokens: number;
|
|
567
|
+
output_tokens_details?: {
|
|
568
|
+
reasoning_tokens: number;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
interface LLMResponse {
|
|
572
|
+
id: string;
|
|
573
|
+
object: 'response';
|
|
574
|
+
created_at: number;
|
|
575
|
+
status: 'completed' | 'failed' | 'in_progress' | 'cancelled' | 'queued' | 'incomplete';
|
|
576
|
+
model: string;
|
|
577
|
+
output: OutputItem[];
|
|
578
|
+
output_text?: string;
|
|
579
|
+
usage: TokenUsage;
|
|
580
|
+
error?: {
|
|
581
|
+
type: string;
|
|
582
|
+
message: string;
|
|
583
|
+
};
|
|
584
|
+
metadata?: Record<string, string>;
|
|
585
|
+
}
|
|
586
|
+
type AgentResponse = LLMResponse;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Streaming event types for real-time LLM responses
|
|
590
|
+
* Based on OpenAI Responses API event format as the internal standard
|
|
591
|
+
*/
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Stream event type enum
|
|
595
|
+
*/
|
|
596
|
+
declare enum StreamEventType {
|
|
597
|
+
RESPONSE_CREATED = "response.created",
|
|
598
|
+
RESPONSE_IN_PROGRESS = "response.in_progress",
|
|
599
|
+
OUTPUT_TEXT_DELTA = "response.output_text.delta",
|
|
600
|
+
OUTPUT_TEXT_DONE = "response.output_text.done",
|
|
601
|
+
TOOL_CALL_START = "response.tool_call.start",
|
|
602
|
+
TOOL_CALL_ARGUMENTS_DELTA = "response.tool_call_arguments.delta",
|
|
603
|
+
TOOL_CALL_ARGUMENTS_DONE = "response.tool_call_arguments.done",
|
|
604
|
+
TOOL_EXECUTION_START = "response.tool_execution.start",
|
|
605
|
+
TOOL_EXECUTION_DONE = "response.tool_execution.done",
|
|
606
|
+
ITERATION_COMPLETE = "response.iteration.complete",
|
|
607
|
+
RESPONSE_COMPLETE = "response.complete",
|
|
608
|
+
ERROR = "response.error"
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Base interface for all stream events
|
|
612
|
+
*/
|
|
613
|
+
interface BaseStreamEvent {
|
|
614
|
+
type: StreamEventType;
|
|
615
|
+
response_id: string;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Response created - first event in stream
|
|
619
|
+
*/
|
|
620
|
+
interface ResponseCreatedEvent extends BaseStreamEvent {
|
|
621
|
+
type: StreamEventType.RESPONSE_CREATED;
|
|
622
|
+
model: string;
|
|
623
|
+
created_at: number;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Response in progress
|
|
627
|
+
*/
|
|
628
|
+
interface ResponseInProgressEvent extends BaseStreamEvent {
|
|
629
|
+
type: StreamEventType.RESPONSE_IN_PROGRESS;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Text delta - incremental text output
|
|
633
|
+
*/
|
|
634
|
+
interface OutputTextDeltaEvent extends BaseStreamEvent {
|
|
635
|
+
type: StreamEventType.OUTPUT_TEXT_DELTA;
|
|
636
|
+
item_id: string;
|
|
637
|
+
output_index: number;
|
|
638
|
+
content_index: number;
|
|
639
|
+
delta: string;
|
|
640
|
+
sequence_number: number;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Text output complete for this item
|
|
644
|
+
*/
|
|
645
|
+
interface OutputTextDoneEvent extends BaseStreamEvent {
|
|
646
|
+
type: StreamEventType.OUTPUT_TEXT_DONE;
|
|
647
|
+
item_id: string;
|
|
648
|
+
output_index: number;
|
|
649
|
+
text: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Tool call detected and starting
|
|
653
|
+
*/
|
|
654
|
+
interface ToolCallStartEvent extends BaseStreamEvent {
|
|
655
|
+
type: StreamEventType.TOOL_CALL_START;
|
|
656
|
+
item_id: string;
|
|
657
|
+
tool_call_id: string;
|
|
658
|
+
tool_name: string;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Tool call arguments delta - incremental JSON
|
|
662
|
+
*/
|
|
663
|
+
interface ToolCallArgumentsDeltaEvent extends BaseStreamEvent {
|
|
664
|
+
type: StreamEventType.TOOL_CALL_ARGUMENTS_DELTA;
|
|
665
|
+
item_id: string;
|
|
666
|
+
tool_call_id: string;
|
|
667
|
+
tool_name: string;
|
|
668
|
+
delta: string;
|
|
669
|
+
sequence_number: number;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Tool call arguments complete
|
|
673
|
+
*/
|
|
674
|
+
interface ToolCallArgumentsDoneEvent extends BaseStreamEvent {
|
|
675
|
+
type: StreamEventType.TOOL_CALL_ARGUMENTS_DONE;
|
|
676
|
+
tool_call_id: string;
|
|
677
|
+
tool_name: string;
|
|
678
|
+
arguments: string;
|
|
679
|
+
incomplete?: boolean;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Tool execution starting
|
|
683
|
+
*/
|
|
684
|
+
interface ToolExecutionStartEvent extends BaseStreamEvent {
|
|
685
|
+
type: StreamEventType.TOOL_EXECUTION_START;
|
|
686
|
+
tool_call_id: string;
|
|
687
|
+
tool_name: string;
|
|
688
|
+
arguments: any;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Tool execution complete
|
|
692
|
+
*/
|
|
693
|
+
interface ToolExecutionDoneEvent extends BaseStreamEvent {
|
|
694
|
+
type: StreamEventType.TOOL_EXECUTION_DONE;
|
|
695
|
+
tool_call_id: string;
|
|
696
|
+
tool_name: string;
|
|
697
|
+
result: any;
|
|
698
|
+
execution_time_ms: number;
|
|
699
|
+
error?: string;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Iteration complete - end of agentic loop iteration
|
|
703
|
+
*/
|
|
704
|
+
interface IterationCompleteEvent$1 extends BaseStreamEvent {
|
|
705
|
+
type: StreamEventType.ITERATION_COMPLETE;
|
|
706
|
+
iteration: number;
|
|
707
|
+
tool_calls_count: number;
|
|
708
|
+
has_more_iterations: boolean;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Response complete - final event
|
|
712
|
+
*/
|
|
713
|
+
interface ResponseCompleteEvent extends BaseStreamEvent {
|
|
714
|
+
type: StreamEventType.RESPONSE_COMPLETE;
|
|
715
|
+
status: 'completed' | 'incomplete' | 'failed';
|
|
716
|
+
usage: TokenUsage;
|
|
717
|
+
iterations: number;
|
|
718
|
+
duration_ms?: number;
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Error event
|
|
722
|
+
*/
|
|
723
|
+
interface ErrorEvent extends BaseStreamEvent {
|
|
724
|
+
type: StreamEventType.ERROR;
|
|
725
|
+
error: {
|
|
726
|
+
type: string;
|
|
727
|
+
message: string;
|
|
728
|
+
code?: string;
|
|
729
|
+
};
|
|
730
|
+
recoverable: boolean;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Union type of all stream events
|
|
734
|
+
* Discriminated by 'type' field for type narrowing
|
|
735
|
+
*/
|
|
736
|
+
type StreamEvent = ResponseCreatedEvent | ResponseInProgressEvent | OutputTextDeltaEvent | OutputTextDoneEvent | ToolCallStartEvent | ToolCallArgumentsDeltaEvent | ToolCallArgumentsDoneEvent | ToolExecutionStartEvent | ToolExecutionDoneEvent | IterationCompleteEvent$1 | ResponseCompleteEvent | ErrorEvent;
|
|
737
|
+
/**
|
|
738
|
+
* Type guard to check if event is a specific type
|
|
739
|
+
*/
|
|
740
|
+
declare function isStreamEvent<T extends StreamEvent>(event: StreamEvent, type: StreamEventType): event is T;
|
|
741
|
+
/**
|
|
742
|
+
* Type guards for specific events
|
|
743
|
+
*/
|
|
744
|
+
declare function isOutputTextDelta(event: StreamEvent): event is OutputTextDeltaEvent;
|
|
745
|
+
declare function isToolCallStart(event: StreamEvent): event is ToolCallStartEvent;
|
|
746
|
+
declare function isToolCallArgumentsDelta(event: StreamEvent): event is ToolCallArgumentsDeltaEvent;
|
|
747
|
+
declare function isToolCallArgumentsDone(event: StreamEvent): event is ToolCallArgumentsDoneEvent;
|
|
748
|
+
declare function isResponseComplete(event: StreamEvent): event is ResponseCompleteEvent;
|
|
749
|
+
declare function isErrorEvent(event: StreamEvent): event is ErrorEvent;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Text generation provider interface
|
|
753
|
+
*/
|
|
754
|
+
|
|
755
|
+
interface TextGenerateOptions {
|
|
756
|
+
model: string;
|
|
757
|
+
input: string | InputItem[];
|
|
758
|
+
instructions?: string;
|
|
759
|
+
tools?: Tool[];
|
|
760
|
+
tool_choice?: 'auto' | 'required' | {
|
|
761
|
+
type: 'function';
|
|
762
|
+
function: {
|
|
763
|
+
name: string;
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
temperature?: number;
|
|
767
|
+
max_output_tokens?: number;
|
|
768
|
+
response_format?: {
|
|
769
|
+
type: 'text' | 'json_object' | 'json_schema';
|
|
770
|
+
json_schema?: any;
|
|
771
|
+
};
|
|
772
|
+
parallel_tool_calls?: boolean;
|
|
773
|
+
previous_response_id?: string;
|
|
774
|
+
metadata?: Record<string, string>;
|
|
775
|
+
/** Vendor-specific options (e.g., Google's thinkingLevel, OpenAI's reasoning_effort) */
|
|
776
|
+
vendorOptions?: Record<string, any>;
|
|
777
|
+
}
|
|
778
|
+
interface ModelCapabilities {
|
|
779
|
+
supportsTools: boolean;
|
|
780
|
+
supportsVision: boolean;
|
|
781
|
+
supportsJSON: boolean;
|
|
782
|
+
supportsJSONSchema: boolean;
|
|
783
|
+
maxTokens: number;
|
|
784
|
+
maxInputTokens?: number;
|
|
785
|
+
maxOutputTokens?: number;
|
|
786
|
+
}
|
|
787
|
+
interface ITextProvider extends IProvider {
|
|
788
|
+
/**
|
|
789
|
+
* Generate text response
|
|
790
|
+
*/
|
|
791
|
+
generate(options: TextGenerateOptions): Promise<LLMResponse>;
|
|
792
|
+
/**
|
|
793
|
+
* Stream text response with real-time events
|
|
794
|
+
* Returns an async iterator of streaming events
|
|
795
|
+
*/
|
|
796
|
+
streamGenerate(options: TextGenerateOptions): AsyncIterableIterator<StreamEvent>;
|
|
797
|
+
/**
|
|
798
|
+
* Get model capabilities
|
|
799
|
+
*/
|
|
800
|
+
getModelCapabilities(model: string): ModelCapabilities;
|
|
801
|
+
/**
|
|
802
|
+
* List available models
|
|
803
|
+
*/
|
|
804
|
+
listModels?(): Promise<string[]>;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Execution context - tracks state, metrics, and history for agent execution
|
|
809
|
+
* Includes memory safety (circular buffers) and resource limits
|
|
810
|
+
*/
|
|
811
|
+
|
|
812
|
+
type HistoryMode = 'none' | 'summary' | 'full';
|
|
813
|
+
interface ExecutionContextConfig {
|
|
814
|
+
maxHistorySize?: number;
|
|
815
|
+
historyMode?: HistoryMode;
|
|
816
|
+
maxAuditTrailSize?: number;
|
|
817
|
+
}
|
|
818
|
+
interface IterationRecord {
|
|
819
|
+
iteration: number;
|
|
820
|
+
request: TextGenerateOptions;
|
|
821
|
+
response: AgentResponse;
|
|
822
|
+
toolCalls: ToolCall[];
|
|
823
|
+
toolResults: ToolResult[];
|
|
824
|
+
startTime: Date;
|
|
825
|
+
endTime: Date;
|
|
826
|
+
}
|
|
827
|
+
interface IterationSummary {
|
|
828
|
+
iteration: number;
|
|
829
|
+
tokens: number;
|
|
830
|
+
toolCount: number;
|
|
831
|
+
duration: number;
|
|
832
|
+
timestamp: Date;
|
|
833
|
+
}
|
|
834
|
+
interface ExecutionMetrics {
|
|
835
|
+
totalDuration: number;
|
|
836
|
+
llmDuration: number;
|
|
837
|
+
toolDuration: number;
|
|
838
|
+
hookDuration: number;
|
|
839
|
+
iterationCount: number;
|
|
840
|
+
toolCallCount: number;
|
|
841
|
+
toolSuccessCount: number;
|
|
842
|
+
toolFailureCount: number;
|
|
843
|
+
toolTimeoutCount: number;
|
|
844
|
+
inputTokens: number;
|
|
845
|
+
outputTokens: number;
|
|
846
|
+
totalTokens: number;
|
|
847
|
+
errors: Array<{
|
|
848
|
+
type: string;
|
|
849
|
+
message: string;
|
|
850
|
+
timestamp: Date;
|
|
851
|
+
}>;
|
|
852
|
+
}
|
|
853
|
+
interface AuditEntry {
|
|
854
|
+
timestamp: Date;
|
|
855
|
+
type: 'hook_executed' | 'tool_modified' | 'tool_skipped' | 'execution_paused' | 'execution_resumed' | 'tool_approved' | 'tool_rejected' | 'tool_blocked' | 'tool_permission_approved';
|
|
856
|
+
hookName?: string;
|
|
857
|
+
toolName?: string;
|
|
858
|
+
details: any;
|
|
859
|
+
}
|
|
860
|
+
declare class ExecutionContext {
|
|
861
|
+
readonly executionId: string;
|
|
862
|
+
readonly startTime: Date;
|
|
863
|
+
iteration: number;
|
|
864
|
+
readonly toolCalls: Map<string, ToolCall>;
|
|
865
|
+
readonly toolResults: Map<string, ToolResult>;
|
|
866
|
+
paused: boolean;
|
|
867
|
+
pauseReason?: string;
|
|
868
|
+
cancelled: boolean;
|
|
869
|
+
cancelReason?: string;
|
|
870
|
+
readonly metadata: Map<string, any>;
|
|
871
|
+
private readonly config;
|
|
872
|
+
private readonly iterations;
|
|
873
|
+
private readonly iterationSummaries;
|
|
874
|
+
readonly metrics: ExecutionMetrics;
|
|
875
|
+
private readonly auditTrail;
|
|
876
|
+
constructor(executionId: string, config?: ExecutionContextConfig);
|
|
877
|
+
/**
|
|
878
|
+
* Add iteration to history (memory-safe)
|
|
879
|
+
*/
|
|
880
|
+
addIteration(record: IterationRecord): void;
|
|
881
|
+
/**
|
|
882
|
+
* Get iteration history
|
|
883
|
+
*/
|
|
884
|
+
getHistory(): IterationRecord[] | IterationSummary[];
|
|
885
|
+
/**
|
|
886
|
+
* Add audit entry
|
|
887
|
+
*/
|
|
888
|
+
audit(type: AuditEntry['type'], details: any, hookName?: string, toolName?: string): void;
|
|
889
|
+
/**
|
|
890
|
+
* Get audit trail
|
|
891
|
+
*/
|
|
892
|
+
getAuditTrail(): readonly AuditEntry[];
|
|
893
|
+
/**
|
|
894
|
+
* Update metrics
|
|
895
|
+
*/
|
|
896
|
+
updateMetrics(update: Partial<ExecutionMetrics>): void;
|
|
897
|
+
/**
|
|
898
|
+
* Add tool call to tracking
|
|
899
|
+
*/
|
|
900
|
+
addToolCall(toolCall: ToolCall): void;
|
|
901
|
+
/**
|
|
902
|
+
* Add tool result to tracking
|
|
903
|
+
*/
|
|
904
|
+
addToolResult(result: ToolResult): void;
|
|
905
|
+
/**
|
|
906
|
+
* Check resource limits
|
|
907
|
+
*/
|
|
908
|
+
checkLimits(limits?: {
|
|
909
|
+
maxExecutionTime?: number;
|
|
910
|
+
maxToolCalls?: number;
|
|
911
|
+
maxContextSize?: number;
|
|
912
|
+
}): void;
|
|
913
|
+
/**
|
|
914
|
+
* Estimate memory usage (rough approximation)
|
|
915
|
+
*/
|
|
916
|
+
private estimateSize;
|
|
917
|
+
/**
|
|
918
|
+
* Cleanup resources and release memory
|
|
919
|
+
* Clears all internal arrays and maps to allow garbage collection
|
|
920
|
+
*/
|
|
921
|
+
cleanup(): void;
|
|
922
|
+
/**
|
|
923
|
+
* Get execution summary
|
|
924
|
+
*/
|
|
925
|
+
getSummary(): {
|
|
926
|
+
executionId: string;
|
|
927
|
+
startTime: Date;
|
|
928
|
+
currentIteration: number;
|
|
929
|
+
paused: boolean;
|
|
930
|
+
cancelled: boolean;
|
|
931
|
+
metrics: {
|
|
932
|
+
totalDuration: number;
|
|
933
|
+
llmDuration: number;
|
|
934
|
+
toolDuration: number;
|
|
935
|
+
hookDuration: number;
|
|
936
|
+
iterationCount: number;
|
|
937
|
+
toolCallCount: number;
|
|
938
|
+
toolSuccessCount: number;
|
|
939
|
+
toolFailureCount: number;
|
|
940
|
+
toolTimeoutCount: number;
|
|
941
|
+
inputTokens: number;
|
|
942
|
+
outputTokens: number;
|
|
943
|
+
totalTokens: number;
|
|
944
|
+
errors: Array<{
|
|
945
|
+
type: string;
|
|
946
|
+
message: string;
|
|
947
|
+
timestamp: Date;
|
|
948
|
+
}>;
|
|
949
|
+
};
|
|
950
|
+
totalDuration: number;
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Event types for agent execution
|
|
956
|
+
* These events are emitted asynchronously for notifications (UI updates, logging, etc.)
|
|
957
|
+
*/
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Minimal config type for execution start events.
|
|
961
|
+
* This captures the essential info without importing full AgentConfig.
|
|
962
|
+
*/
|
|
963
|
+
interface ExecutionConfig {
|
|
964
|
+
model: string;
|
|
965
|
+
instructions?: string;
|
|
966
|
+
temperature?: number;
|
|
967
|
+
maxIterations?: number;
|
|
968
|
+
}
|
|
969
|
+
interface ExecutionStartEvent {
|
|
970
|
+
executionId: string;
|
|
971
|
+
config: ExecutionConfig;
|
|
972
|
+
timestamp: Date;
|
|
973
|
+
}
|
|
974
|
+
interface ExecutionCompleteEvent {
|
|
975
|
+
executionId: string;
|
|
976
|
+
response: AgentResponse;
|
|
977
|
+
timestamp: Date;
|
|
978
|
+
duration: number;
|
|
979
|
+
}
|
|
980
|
+
interface ExecutionErrorEvent {
|
|
981
|
+
executionId: string;
|
|
982
|
+
error: Error;
|
|
983
|
+
timestamp: Date;
|
|
984
|
+
}
|
|
985
|
+
interface ExecutionPausedEvent {
|
|
986
|
+
executionId: string;
|
|
987
|
+
reason?: string;
|
|
988
|
+
timestamp: Date;
|
|
989
|
+
}
|
|
990
|
+
interface ExecutionResumedEvent {
|
|
991
|
+
executionId: string;
|
|
992
|
+
timestamp: Date;
|
|
993
|
+
}
|
|
994
|
+
interface ExecutionCancelledEvent {
|
|
995
|
+
executionId: string;
|
|
996
|
+
reason?: string;
|
|
997
|
+
timestamp: Date;
|
|
998
|
+
}
|
|
999
|
+
interface ExecutionMaxIterationsEvent {
|
|
1000
|
+
executionId: string;
|
|
1001
|
+
iteration: number;
|
|
1002
|
+
maxIterations: number;
|
|
1003
|
+
timestamp: Date;
|
|
1004
|
+
}
|
|
1005
|
+
interface IterationStartEvent {
|
|
1006
|
+
executionId: string;
|
|
1007
|
+
iteration: number;
|
|
1008
|
+
timestamp: Date;
|
|
1009
|
+
}
|
|
1010
|
+
interface IterationCompleteEvent {
|
|
1011
|
+
executionId: string;
|
|
1012
|
+
iteration: number;
|
|
1013
|
+
response: AgentResponse;
|
|
1014
|
+
timestamp: Date;
|
|
1015
|
+
duration: number;
|
|
1016
|
+
}
|
|
1017
|
+
interface LLMRequestEvent {
|
|
1018
|
+
executionId: string;
|
|
1019
|
+
iteration: number;
|
|
1020
|
+
options: TextGenerateOptions;
|
|
1021
|
+
timestamp: Date;
|
|
1022
|
+
}
|
|
1023
|
+
interface LLMResponseEvent {
|
|
1024
|
+
executionId: string;
|
|
1025
|
+
iteration: number;
|
|
1026
|
+
response: AgentResponse;
|
|
1027
|
+
timestamp: Date;
|
|
1028
|
+
duration: number;
|
|
1029
|
+
}
|
|
1030
|
+
interface LLMErrorEvent {
|
|
1031
|
+
executionId: string;
|
|
1032
|
+
iteration: number;
|
|
1033
|
+
error: Error;
|
|
1034
|
+
timestamp: Date;
|
|
1035
|
+
}
|
|
1036
|
+
interface ToolDetectedEvent {
|
|
1037
|
+
executionId: string;
|
|
1038
|
+
iteration: number;
|
|
1039
|
+
toolCalls: ToolCall[];
|
|
1040
|
+
timestamp: Date;
|
|
1041
|
+
}
|
|
1042
|
+
interface ToolStartEvent {
|
|
1043
|
+
executionId: string;
|
|
1044
|
+
iteration: number;
|
|
1045
|
+
toolCall: ToolCall;
|
|
1046
|
+
timestamp: Date;
|
|
1047
|
+
}
|
|
1048
|
+
interface ToolCompleteEvent {
|
|
1049
|
+
executionId: string;
|
|
1050
|
+
iteration: number;
|
|
1051
|
+
toolCall: ToolCall;
|
|
1052
|
+
result: ToolResult;
|
|
1053
|
+
timestamp: Date;
|
|
1054
|
+
}
|
|
1055
|
+
interface ToolErrorEvent {
|
|
1056
|
+
executionId: string;
|
|
1057
|
+
iteration: number;
|
|
1058
|
+
toolCall: ToolCall;
|
|
1059
|
+
error: Error;
|
|
1060
|
+
timestamp: Date;
|
|
1061
|
+
}
|
|
1062
|
+
interface ToolTimeoutEvent {
|
|
1063
|
+
executionId: string;
|
|
1064
|
+
iteration: number;
|
|
1065
|
+
toolCall: ToolCall;
|
|
1066
|
+
timeout: number;
|
|
1067
|
+
timestamp: Date;
|
|
1068
|
+
}
|
|
1069
|
+
interface HookErrorEvent {
|
|
1070
|
+
executionId: string;
|
|
1071
|
+
hookName: string;
|
|
1072
|
+
error: Error;
|
|
1073
|
+
timestamp: Date;
|
|
1074
|
+
}
|
|
1075
|
+
interface CircuitOpenedEvent {
|
|
1076
|
+
executionId: string;
|
|
1077
|
+
breakerName: string;
|
|
1078
|
+
failureCount: number;
|
|
1079
|
+
lastError: string;
|
|
1080
|
+
nextRetryTime: number;
|
|
1081
|
+
timestamp: Date;
|
|
1082
|
+
}
|
|
1083
|
+
interface CircuitHalfOpenEvent {
|
|
1084
|
+
executionId: string;
|
|
1085
|
+
breakerName: string;
|
|
1086
|
+
timestamp: Date;
|
|
1087
|
+
}
|
|
1088
|
+
interface CircuitClosedEvent {
|
|
1089
|
+
executionId: string;
|
|
1090
|
+
breakerName: string;
|
|
1091
|
+
successCount: number;
|
|
1092
|
+
timestamp: Date;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Map of all event names to their payload types
|
|
1096
|
+
*/
|
|
1097
|
+
interface AgenticLoopEvents {
|
|
1098
|
+
'execution:start': ExecutionStartEvent;
|
|
1099
|
+
'execution:complete': ExecutionCompleteEvent;
|
|
1100
|
+
'execution:error': ExecutionErrorEvent;
|
|
1101
|
+
'execution:paused': ExecutionPausedEvent;
|
|
1102
|
+
'execution:resumed': ExecutionResumedEvent;
|
|
1103
|
+
'execution:cancelled': ExecutionCancelledEvent;
|
|
1104
|
+
'execution:maxIterations': ExecutionMaxIterationsEvent;
|
|
1105
|
+
'iteration:start': IterationStartEvent;
|
|
1106
|
+
'iteration:complete': IterationCompleteEvent;
|
|
1107
|
+
'llm:request': LLMRequestEvent;
|
|
1108
|
+
'llm:response': LLMResponseEvent;
|
|
1109
|
+
'llm:error': LLMErrorEvent;
|
|
1110
|
+
'tool:detected': ToolDetectedEvent;
|
|
1111
|
+
'tool:start': ToolStartEvent;
|
|
1112
|
+
'tool:complete': ToolCompleteEvent;
|
|
1113
|
+
'tool:error': ToolErrorEvent;
|
|
1114
|
+
'tool:timeout': ToolTimeoutEvent;
|
|
1115
|
+
'hook:error': HookErrorEvent;
|
|
1116
|
+
'circuit:opened': CircuitOpenedEvent;
|
|
1117
|
+
'circuit:half-open': CircuitHalfOpenEvent;
|
|
1118
|
+
'circuit:closed': CircuitClosedEvent;
|
|
1119
|
+
}
|
|
1120
|
+
type AgenticLoopEventName = keyof AgenticLoopEvents;
|
|
1121
|
+
/**
|
|
1122
|
+
* Agent events - alias for AgenticLoopEvents for cleaner API
|
|
1123
|
+
* This is the preferred export name going forward.
|
|
1124
|
+
*/
|
|
1125
|
+
type AgentEvents = AgenticLoopEvents;
|
|
1126
|
+
type AgentEventName = AgenticLoopEventName;
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Hook types for agent execution
|
|
1130
|
+
* Hooks can modify execution flow synchronously or asynchronously
|
|
1131
|
+
*/
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Base hook function type
|
|
1135
|
+
*/
|
|
1136
|
+
type Hook<TContext, TResult = any> = (context: TContext) => TResult | Promise<TResult>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Hook that can modify data
|
|
1139
|
+
*/
|
|
1140
|
+
type ModifyingHook<TContext, TModification> = Hook<TContext, TModification>;
|
|
1141
|
+
interface BeforeExecutionContext {
|
|
1142
|
+
executionId: string;
|
|
1143
|
+
config: ExecutionConfig;
|
|
1144
|
+
timestamp: Date;
|
|
1145
|
+
}
|
|
1146
|
+
interface AfterExecutionContext {
|
|
1147
|
+
executionId: string;
|
|
1148
|
+
response: AgentResponse;
|
|
1149
|
+
context: ExecutionContext;
|
|
1150
|
+
timestamp: Date;
|
|
1151
|
+
duration: number;
|
|
1152
|
+
}
|
|
1153
|
+
interface BeforeLLMContext {
|
|
1154
|
+
executionId: string;
|
|
1155
|
+
iteration: number;
|
|
1156
|
+
options: TextGenerateOptions;
|
|
1157
|
+
context: ExecutionContext;
|
|
1158
|
+
timestamp: Date;
|
|
1159
|
+
}
|
|
1160
|
+
interface AfterLLMContext {
|
|
1161
|
+
executionId: string;
|
|
1162
|
+
iteration: number;
|
|
1163
|
+
response: AgentResponse;
|
|
1164
|
+
context: ExecutionContext;
|
|
1165
|
+
timestamp: Date;
|
|
1166
|
+
duration: number;
|
|
1167
|
+
}
|
|
1168
|
+
interface BeforeToolContext {
|
|
1169
|
+
executionId: string;
|
|
1170
|
+
iteration: number;
|
|
1171
|
+
toolCall: ToolCall;
|
|
1172
|
+
context: ExecutionContext;
|
|
1173
|
+
timestamp: Date;
|
|
1174
|
+
}
|
|
1175
|
+
interface AfterToolContext {
|
|
1176
|
+
executionId: string;
|
|
1177
|
+
iteration: number;
|
|
1178
|
+
toolCall: ToolCall;
|
|
1179
|
+
result: ToolResult;
|
|
1180
|
+
context: ExecutionContext;
|
|
1181
|
+
timestamp: Date;
|
|
1182
|
+
}
|
|
1183
|
+
interface ApproveToolContext {
|
|
1184
|
+
executionId: string;
|
|
1185
|
+
iteration: number;
|
|
1186
|
+
toolCall: ToolCall;
|
|
1187
|
+
context: ExecutionContext;
|
|
1188
|
+
timestamp: Date;
|
|
1189
|
+
}
|
|
1190
|
+
interface PauseCheckContext {
|
|
1191
|
+
executionId: string;
|
|
1192
|
+
iteration: number;
|
|
1193
|
+
context: ExecutionContext;
|
|
1194
|
+
timestamp: Date;
|
|
1195
|
+
}
|
|
1196
|
+
interface LLMModification {
|
|
1197
|
+
modified?: Partial<TextGenerateOptions>;
|
|
1198
|
+
skip?: boolean;
|
|
1199
|
+
reason?: string;
|
|
1200
|
+
}
|
|
1201
|
+
interface ToolModification {
|
|
1202
|
+
modified?: Partial<ToolCall>;
|
|
1203
|
+
skip?: boolean;
|
|
1204
|
+
mockResult?: any;
|
|
1205
|
+
reason?: string;
|
|
1206
|
+
}
|
|
1207
|
+
interface ToolResultModification {
|
|
1208
|
+
modified?: Partial<ToolResult>;
|
|
1209
|
+
retry?: boolean;
|
|
1210
|
+
reason?: string;
|
|
1211
|
+
}
|
|
1212
|
+
interface ApprovalResult {
|
|
1213
|
+
approved: boolean;
|
|
1214
|
+
reason?: string;
|
|
1215
|
+
modifiedArgs?: any;
|
|
1216
|
+
}
|
|
1217
|
+
interface PauseDecision {
|
|
1218
|
+
shouldPause: boolean;
|
|
1219
|
+
reason?: string;
|
|
1220
|
+
}
|
|
1221
|
+
interface HookConfig {
|
|
1222
|
+
'before:execution'?: Hook<BeforeExecutionContext, void>;
|
|
1223
|
+
'after:execution'?: Hook<AfterExecutionContext, void>;
|
|
1224
|
+
'before:llm'?: ModifyingHook<BeforeLLMContext, LLMModification>;
|
|
1225
|
+
'after:llm'?: ModifyingHook<AfterLLMContext, {}>;
|
|
1226
|
+
'before:tool'?: ModifyingHook<BeforeToolContext, ToolModification>;
|
|
1227
|
+
'after:tool'?: ModifyingHook<AfterToolContext, ToolResultModification>;
|
|
1228
|
+
'approve:tool'?: Hook<ApproveToolContext, ApprovalResult>;
|
|
1229
|
+
'pause:check'?: Hook<PauseCheckContext, PauseDecision>;
|
|
1230
|
+
hookTimeout?: number;
|
|
1231
|
+
parallelHooks?: boolean;
|
|
1232
|
+
}
|
|
1233
|
+
type HookName = keyof Omit<HookConfig, 'hookTimeout' | 'parallelHooks'>;
|
|
1234
|
+
/**
|
|
1235
|
+
* Map of hook names to their context and result types
|
|
1236
|
+
*/
|
|
1237
|
+
interface HookSignatures {
|
|
1238
|
+
'before:execution': {
|
|
1239
|
+
context: BeforeExecutionContext;
|
|
1240
|
+
result: void;
|
|
1241
|
+
};
|
|
1242
|
+
'after:execution': {
|
|
1243
|
+
context: AfterExecutionContext;
|
|
1244
|
+
result: void;
|
|
1245
|
+
};
|
|
1246
|
+
'before:llm': {
|
|
1247
|
+
context: BeforeLLMContext;
|
|
1248
|
+
result: LLMModification;
|
|
1249
|
+
};
|
|
1250
|
+
'after:llm': {
|
|
1251
|
+
context: AfterLLMContext;
|
|
1252
|
+
result: {};
|
|
1253
|
+
};
|
|
1254
|
+
'before:tool': {
|
|
1255
|
+
context: BeforeToolContext;
|
|
1256
|
+
result: ToolModification;
|
|
1257
|
+
};
|
|
1258
|
+
'after:tool': {
|
|
1259
|
+
context: AfterToolContext;
|
|
1260
|
+
result: ToolResultModification;
|
|
1261
|
+
};
|
|
1262
|
+
'approve:tool': {
|
|
1263
|
+
context: ApproveToolContext;
|
|
1264
|
+
result: ApprovalResult;
|
|
1265
|
+
};
|
|
1266
|
+
'pause:check': {
|
|
1267
|
+
context: PauseCheckContext;
|
|
1268
|
+
result: PauseDecision;
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Hook manager - handles hook registration and execution
|
|
1274
|
+
* Includes error isolation, timeouts, and optional parallel execution
|
|
1275
|
+
*/
|
|
1276
|
+
|
|
1277
|
+
declare class HookManager {
|
|
1278
|
+
private hooks;
|
|
1279
|
+
private timeout;
|
|
1280
|
+
private parallel;
|
|
1281
|
+
private hookErrorCounts;
|
|
1282
|
+
private disabledHooks;
|
|
1283
|
+
private maxConsecutiveErrors;
|
|
1284
|
+
private emitter;
|
|
1285
|
+
constructor(config: HookConfig | undefined, emitter: EventEmitter, errorHandling?: {
|
|
1286
|
+
maxConsecutiveErrors?: number;
|
|
1287
|
+
});
|
|
1288
|
+
/**
|
|
1289
|
+
* Register hooks from configuration
|
|
1290
|
+
*/
|
|
1291
|
+
private registerFromConfig;
|
|
1292
|
+
/**
|
|
1293
|
+
* Register a hook
|
|
1294
|
+
*/
|
|
1295
|
+
register(name: HookName, hook: Hook<any, any>): void;
|
|
1296
|
+
/**
|
|
1297
|
+
* Execute hooks for a given name
|
|
1298
|
+
*/
|
|
1299
|
+
executeHooks<K extends HookName>(name: K, context: HookSignatures[K]['context'], defaultResult: HookSignatures[K]['result']): Promise<HookSignatures[K]['result']>;
|
|
1300
|
+
/**
|
|
1301
|
+
* Execute hooks sequentially
|
|
1302
|
+
*/
|
|
1303
|
+
private executeHooksSequential;
|
|
1304
|
+
/**
|
|
1305
|
+
* Execute hooks in parallel
|
|
1306
|
+
*/
|
|
1307
|
+
private executeHooksParallel;
|
|
1308
|
+
/**
|
|
1309
|
+
* Generate unique key for a hook
|
|
1310
|
+
*/
|
|
1311
|
+
private getHookKey;
|
|
1312
|
+
/**
|
|
1313
|
+
* Execute single hook with error isolation and timeout (with per-hook error tracking)
|
|
1314
|
+
*/
|
|
1315
|
+
private executeHookSafely;
|
|
1316
|
+
/**
|
|
1317
|
+
* Check if there are any hooks registered
|
|
1318
|
+
*/
|
|
1319
|
+
hasHooks(name: HookName): boolean;
|
|
1320
|
+
/**
|
|
1321
|
+
* Get hook count
|
|
1322
|
+
*/
|
|
1323
|
+
getHookCount(name?: HookName): number;
|
|
1324
|
+
/**
|
|
1325
|
+
* Clear all hooks and reset error tracking
|
|
1326
|
+
*/
|
|
1327
|
+
clear(): void;
|
|
1328
|
+
/**
|
|
1329
|
+
* Re-enable a disabled hook
|
|
1330
|
+
*/
|
|
1331
|
+
enableHook(hookKey: string): void;
|
|
1332
|
+
/**
|
|
1333
|
+
* Get list of disabled hooks
|
|
1334
|
+
*/
|
|
1335
|
+
getDisabledHooks(): string[];
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
export { type OutputTextContent as $, type AgentEvents as A, type SimpleScope as B, type Content as C, DEFAULT_MEMORY_CONFIG as D, ExecutionContext as E, type FunctionToolDefinition as F, forTasks as G, type HookConfig as H, type InputItem as I, forPlan as J, scopeEquals as K, type LLMResponse as L, type MemoryEntry as M, scopeMatches as N, type OutputItem as O, type PriorityCalculator as P, isSimpleScope as Q, isTaskAwareScope as R, type StreamEvent as S, type Tool as T, isTerminalMemoryStatus as U, calculateEntrySize as V, type WorkingMemoryConfig as W, MEMORY_PRIORITY_VALUES as X, ContentType as Y, type InputTextContent as Z, type InputImageContent as _, type ToolFunction as a, type ToolUseContent as a0, type ToolResultContent as a1, type Message as a2, type CompactionItem as a3, type ReasoningItem as a4, ToolCallState as a5, defaultDescribeCall as a6, getToolCallDescription as a7, type BuiltInTool as a8, type ToolExecutionContext as a9, type Hook as aA, type ModifyingHook as aB, type BeforeToolContext as aC, type AfterToolContext as aD, type ApproveToolContext as aE, type ToolModification as aF, type ApprovalResult as aG, type ExecutionStartEvent as aH, type ExecutionCompleteEvent as aI, type ToolStartEvent as aJ, type ToolCompleteEvent as aK, type LLMRequestEvent as aL, type LLMResponseEvent as aM, type JSONSchema as aa, type ResponseCreatedEvent as ab, type ResponseInProgressEvent as ac, type OutputTextDeltaEvent as ad, type OutputTextDoneEvent as ae, type ToolCallStartEvent as af, type ToolCallArgumentsDeltaEvent as ag, type ToolCallArgumentsDoneEvent as ah, type ToolExecutionStartEvent as ai, type ToolExecutionDoneEvent as aj, type IterationCompleteEvent$1 as ak, type ResponseCompleteEvent as al, type ErrorEvent as am, isStreamEvent as an, isOutputTextDelta as ao, isToolCallStart as ap, isToolCallArgumentsDelta as aq, isToolCallArgumentsDone as ar, isResponseComplete as as, isErrorEvent as at, HookManager as au, type AgentEventName as av, type ExecutionConfig as aw, type AgenticLoopEvents as ax, type AgenticLoopEventName as ay, type HookName as az, type ToolContext as b, type ToolPermissionConfig as c, type ToolCall as d, type MemoryScope as e, type MemoryPriority as f, type MemoryTier as g, type ToolResult as h, type ITextProvider as i, type HistoryMode as j, type AgentResponse as k, type ExecutionMetrics as l, type AuditEntry as m, type StaleEntryInfo as n, type PriorityContext as o, type MemoryIndex as p, type TaskStatusForMemory as q, type WorkingMemoryAccess as r, type TokenUsage as s, StreamEventType as t, type TextGenerateOptions as u, type ModelCapabilities as v, MessageRole as w, type MemoryEntryInput as x, type MemoryIndexEntry as y, type TaskAwareScope as z };
|