@kjerneverk/agentic 1.0.5-dev.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/.kodrdriv-test-cache.json +6 -0
- package/LICENSE +18 -0
- package/README.md +167 -0
- package/SECURITY.md +94 -0
- package/dist/index.d.ts +770 -0
- package/dist/index.js +1822 -0
- package/dist/index.js.map +1 -0
- package/output/kodrdriv/260110-1207-commit-message.md +1 -0
- package/output/kodrdriv/260110-1208-commit-message.md +1 -0
- package/output/kodrdriv/260110-1210-release-notes.md +27 -0
- package/output/kodrdriv/260110-1232-commit-message.md +1 -0
- package/output/kodrdriv/260110-1234-release-notes.md +46 -0
- package/output/kodrdriv/260110-1308-release-notes.md +20 -0
- package/output/kodrdriv/260112-2155-commit-message.md +1 -0
- package/output/kodrdriv/260112-2156-release-notes.md +33 -0
- package/output/kodrdriv/260112-2340-commit-message.md +1 -0
- package/output/kodrdriv/260113-0017-commit-message.md +1 -0
- package/output/kodrdriv/260113-0017-release-notes.md +53 -0
- package/output/kodrdriv/260115-0616-commit-message.md +4 -0
- package/output/kodrdriv/260115-0739-commit-message.md +1 -0
- package/output/kodrdriv/260115-0746-commit-message.md +1 -0
- package/output/kodrdriv/260115-0747-release-notes.md +91 -0
- package/output/kodrdriv/260126-0851-commit-message.md +1 -0
- package/output/kodrdriv/260128-0900-commit-message.md +1 -0
- package/output/kodrdriv/260128-0900-release-notes.md +29 -0
- package/output/kodrdriv/260128-0905-commit-message.md +1 -0
- package/output/kodrdriv/260128-0913-commit-message.md +1 -0
- package/output/kodrdriv/260128-0913-release-notes.md +23 -0
- package/output/kodrdriv/260128-0919-commit-message.md +1 -0
- package/output/kodrdriv/260128-0919-release-notes.md +21 -0
- package/output/kodrdriv/260130-1642-commit-message.md +1 -0
- package/output/kodrdriv/260130-1642-release-notes.md +29 -0
- package/output/kodrdriv/RELEASE_NOTES.md +27 -0
- package/output/kodrdriv/RELEASE_TITLE.md +1 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-10T19-18-11-913Z.md +187 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-10T20-03-27-409Z.md +121 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-10T20-07-27-813Z.md +114 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-10T20-08-06-279Z.md +97 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-10T20-32-25-791Z.md +114 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-13T05-55-30-733Z.md +97 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-13T07-40-28-878Z.md +97 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-13T08-17-22-230Z.md +114 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-14T14-55-10-122Z.md +177 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-15T14-16-05-605Z.md +100 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-15T15-39-32-200Z.md +97 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-15T15-46-32-840Z.md +114 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-26T16-51-00-446Z.md +152 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-31T00-38-59-868Z.md +236 -0
- package/output/kodrdriv/agentic-reflection-commit-2026-01-31T00-42-31-993Z.md +152 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-10T20-10-49-531Z.md +329 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-10T20-34-32-038Z.md +319 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-10T21-08-36-314Z.md +168 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-13T05-56-04-802Z.md +264 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-13T08-17-56-556Z.md +255 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-15T15-47-32-509Z.md +460 -0
- package/output/kodrdriv/agentic-reflection-release-2026-01-31T00-42-59-683Z.md +400 -0
- package/package.json +59 -0
- package/package.json~ +58 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic Package
|
|
3
|
+
*
|
|
4
|
+
* Components for building agentic AI workflows:
|
|
5
|
+
* - Tool registry and execution
|
|
6
|
+
* - Context management
|
|
7
|
+
* - Conversation state tracking
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { ZodSchema } from 'zod';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Anthropic-compatible tool format
|
|
16
|
+
*/
|
|
17
|
+
export declare interface AnthropicTool {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
input_schema: {
|
|
21
|
+
type: 'object';
|
|
22
|
+
properties: Record<string, any>;
|
|
23
|
+
required?: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Compression statistics
|
|
29
|
+
*/
|
|
30
|
+
export declare interface CompressionStats {
|
|
31
|
+
messagesBefore: number;
|
|
32
|
+
messagesAfter: number;
|
|
33
|
+
tokensBefore: number;
|
|
34
|
+
tokensAfter: number;
|
|
35
|
+
tokensSaved: number;
|
|
36
|
+
strategy: CompressionStrategy;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compression strategy
|
|
41
|
+
*/
|
|
42
|
+
export declare type CompressionStrategy = 'priority-based' | 'fifo' | 'summarize' | 'adaptive';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ContextManager tracks and manages dynamically injected context.
|
|
46
|
+
*/
|
|
47
|
+
export declare class ContextManager {
|
|
48
|
+
private items;
|
|
49
|
+
private hashes;
|
|
50
|
+
private logger;
|
|
51
|
+
constructor(logger?: Logger);
|
|
52
|
+
/**
|
|
53
|
+
* Track a context item
|
|
54
|
+
*/
|
|
55
|
+
track(item: DynamicContentItem, position: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Check if context with given ID exists
|
|
58
|
+
*/
|
|
59
|
+
hasContext(id: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check if content with given hash exists
|
|
62
|
+
*/
|
|
63
|
+
hasContentHash(content: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Check if similar content exists (fuzzy match)
|
|
66
|
+
*/
|
|
67
|
+
hasSimilarContent(content: string, similarityThreshold?: number): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Get context item by ID
|
|
70
|
+
*/
|
|
71
|
+
get(id: string): TrackedContextItem | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get all tracked context items
|
|
74
|
+
*/
|
|
75
|
+
getAll(): TrackedContextItem[];
|
|
76
|
+
/**
|
|
77
|
+
* Get context items by category
|
|
78
|
+
*/
|
|
79
|
+
getByCategory(category: string): TrackedContextItem[];
|
|
80
|
+
/**
|
|
81
|
+
* Get context items by priority
|
|
82
|
+
*/
|
|
83
|
+
getByPriority(priority: 'high' | 'medium' | 'low'): TrackedContextItem[];
|
|
84
|
+
/**
|
|
85
|
+
* Get context items by source
|
|
86
|
+
*/
|
|
87
|
+
getBySource(source: string): TrackedContextItem[];
|
|
88
|
+
/**
|
|
89
|
+
* Get all categories
|
|
90
|
+
*/
|
|
91
|
+
getCategories(): string[];
|
|
92
|
+
/**
|
|
93
|
+
* Get context statistics
|
|
94
|
+
*/
|
|
95
|
+
getStats(): ContextStats;
|
|
96
|
+
/**
|
|
97
|
+
* Remove context item by ID
|
|
98
|
+
*/
|
|
99
|
+
remove(id: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Clear all tracked context
|
|
102
|
+
*/
|
|
103
|
+
clear(): void;
|
|
104
|
+
private generateId;
|
|
105
|
+
private hashContent;
|
|
106
|
+
private normalizeContent;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Context statistics
|
|
111
|
+
*/
|
|
112
|
+
export declare interface ContextStats {
|
|
113
|
+
totalItems: number;
|
|
114
|
+
byCategory: Map<string, number>;
|
|
115
|
+
byPriority: Map<string, number>;
|
|
116
|
+
bySource: Map<string, number>;
|
|
117
|
+
oldestTimestamp?: Date;
|
|
118
|
+
newestTimestamp?: Date;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export declare interface ConversationMessage {
|
|
122
|
+
role: 'system' | 'user' | 'assistant' | 'tool' | 'developer';
|
|
123
|
+
content: string | null;
|
|
124
|
+
name?: string;
|
|
125
|
+
tool_calls?: ToolCall[];
|
|
126
|
+
tool_call_id?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Create a security-wrapped version of a tool
|
|
131
|
+
*/
|
|
132
|
+
export declare function createSecureTool(tool: Tool, sandbox: ToolSandbox, guard: ToolGuard): Tool;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Default logger - silent by default to prevent information disclosure
|
|
136
|
+
*
|
|
137
|
+
* Enable logging by setting one of:
|
|
138
|
+
* - AGENTIC_LOGGING=true
|
|
139
|
+
* - DEBUG=*agentic*
|
|
140
|
+
* - NODE_ENV=development
|
|
141
|
+
*/
|
|
142
|
+
export declare const DEFAULT_LOGGER: Logger;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Dynamic content item with enhanced tracking and lifecycle
|
|
146
|
+
*/
|
|
147
|
+
export declare interface DynamicContentItem {
|
|
148
|
+
content: string;
|
|
149
|
+
title?: string;
|
|
150
|
+
weight?: number;
|
|
151
|
+
id?: string;
|
|
152
|
+
category?: string;
|
|
153
|
+
source?: string;
|
|
154
|
+
priority?: 'high' | 'medium' | 'low';
|
|
155
|
+
timestamp?: Date;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Options for injecting context
|
|
160
|
+
*/
|
|
161
|
+
export declare interface InjectOptions {
|
|
162
|
+
position?: 'end' | 'before-last' | 'after-system' | number;
|
|
163
|
+
format?: 'structured' | 'inline' | 'reference';
|
|
164
|
+
deduplicate?: boolean;
|
|
165
|
+
deduplicateBy?: 'id' | 'content' | 'hash';
|
|
166
|
+
priority?: 'high' | 'medium' | 'low';
|
|
167
|
+
weight?: number;
|
|
168
|
+
category?: string;
|
|
169
|
+
source?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Insight discovered during execution
|
|
174
|
+
*/
|
|
175
|
+
export declare interface Insight {
|
|
176
|
+
source: string;
|
|
177
|
+
content: string;
|
|
178
|
+
confidence: number;
|
|
179
|
+
relatedTo?: string[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Action to take after iteration
|
|
184
|
+
*/
|
|
185
|
+
export declare type IterationAction = 'continue' | 'stop' | 'next-phase';
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Agentic Package - Logger
|
|
189
|
+
*
|
|
190
|
+
* Shared logging infrastructure backed by @fjell/logging for
|
|
191
|
+
* comprehensive sensitive data masking and structured logging.
|
|
192
|
+
*/
|
|
193
|
+
export declare const LIBRARY_NAME = "agentic";
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* LLM client interface (generic, provider-agnostic)
|
|
197
|
+
*/
|
|
198
|
+
export declare interface LLMClient {
|
|
199
|
+
complete(messages: ConversationMessage[], tools?: any[]): Promise<{
|
|
200
|
+
content: string | null;
|
|
201
|
+
tool_calls?: ToolCall[];
|
|
202
|
+
}>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Log configuration
|
|
207
|
+
*/
|
|
208
|
+
export declare interface LogConfig {
|
|
209
|
+
enabled: boolean;
|
|
210
|
+
outputPath?: string;
|
|
211
|
+
format?: LogFormat;
|
|
212
|
+
filenameTemplate?: string;
|
|
213
|
+
includeMetadata?: boolean;
|
|
214
|
+
includePrompt?: boolean;
|
|
215
|
+
redactSensitive?: boolean;
|
|
216
|
+
redactPatterns?: RegExp[];
|
|
217
|
+
onSaved?: (path: string) => void;
|
|
218
|
+
onError?: (error: Error) => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Log format
|
|
223
|
+
*/
|
|
224
|
+
export declare type LogFormat = 'json' | 'markdown' | 'jsonl';
|
|
225
|
+
|
|
226
|
+
export declare interface Logger {
|
|
227
|
+
name: string;
|
|
228
|
+
debug: (message: string, ...args: any[]) => void;
|
|
229
|
+
info: (message: string, ...args: any[]) => void;
|
|
230
|
+
warn: (message: string, ...args: any[]) => void;
|
|
231
|
+
error: (message: string, ...args: any[]) => void;
|
|
232
|
+
verbose: (message: string, ...args: any[]) => void;
|
|
233
|
+
silly: (message: string, ...args: any[]) => void;
|
|
234
|
+
/** Get a child logger for a component */
|
|
235
|
+
get?: (...components: string[]) => Logger;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Agentic Package - Types
|
|
240
|
+
*
|
|
241
|
+
* Core type definitions for agentic workflows.
|
|
242
|
+
*/
|
|
243
|
+
export declare type Model = string;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* OpenAI-compatible tool format
|
|
247
|
+
*/
|
|
248
|
+
export declare interface OpenAITool {
|
|
249
|
+
type: 'function';
|
|
250
|
+
function: {
|
|
251
|
+
name: string;
|
|
252
|
+
description: string;
|
|
253
|
+
parameters: {
|
|
254
|
+
type: 'object';
|
|
255
|
+
properties: Record<string, any>;
|
|
256
|
+
required?: string[];
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Result of a phase
|
|
263
|
+
*/
|
|
264
|
+
export declare interface PhaseResult {
|
|
265
|
+
name: string;
|
|
266
|
+
iterations: number;
|
|
267
|
+
toolCalls: number;
|
|
268
|
+
success: boolean;
|
|
269
|
+
insights?: Insight[];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Extended context with sandbox restrictions
|
|
274
|
+
*/
|
|
275
|
+
export declare interface SandboxedContext extends ToolContext {
|
|
276
|
+
readonly sandbox: {
|
|
277
|
+
allowedOperations: Set<string>;
|
|
278
|
+
maxOutputSize: number;
|
|
279
|
+
executionId: string;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Options for sandbox execution
|
|
285
|
+
*/
|
|
286
|
+
export declare interface SandboxOptions {
|
|
287
|
+
maxExecutionTime: number;
|
|
288
|
+
maxOutputSize: number;
|
|
289
|
+
allowedOperations?: string[];
|
|
290
|
+
onBeforeExecution?: (tool: Tool, params: unknown) => void | Promise<void>;
|
|
291
|
+
onAfterExecution?: (tool: Tool, result: unknown, error?: Error) => void | Promise<void>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Current state of strategy execution
|
|
296
|
+
*/
|
|
297
|
+
export declare interface StrategyState {
|
|
298
|
+
phase: string | number;
|
|
299
|
+
iteration: number;
|
|
300
|
+
toolCallsExecuted: number;
|
|
301
|
+
startTime: number;
|
|
302
|
+
insights: Insight[];
|
|
303
|
+
findings: any[];
|
|
304
|
+
errors: Error[];
|
|
305
|
+
toolFailures: Map<string, number>;
|
|
306
|
+
[key: string]: any;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Token budget configuration
|
|
311
|
+
*/
|
|
312
|
+
export declare interface TokenBudgetConfig {
|
|
313
|
+
max: number;
|
|
314
|
+
reserveForResponse: number;
|
|
315
|
+
warningThreshold?: number;
|
|
316
|
+
strategy: CompressionStrategy;
|
|
317
|
+
onBudgetExceeded: 'compress' | 'error' | 'warn' | 'truncate';
|
|
318
|
+
preserveRecent?: number;
|
|
319
|
+
preserveSystem?: boolean;
|
|
320
|
+
preserveHighPriority?: boolean;
|
|
321
|
+
onWarning?: (usage: TokenUsage) => void;
|
|
322
|
+
onCompression?: (stats: CompressionStats) => void;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Token usage information
|
|
327
|
+
*/
|
|
328
|
+
export declare interface TokenUsage {
|
|
329
|
+
used: number;
|
|
330
|
+
max: number;
|
|
331
|
+
remaining: number;
|
|
332
|
+
percentage: number;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Tool definition
|
|
337
|
+
*/
|
|
338
|
+
export declare interface Tool {
|
|
339
|
+
name: string;
|
|
340
|
+
description: string;
|
|
341
|
+
parameters: {
|
|
342
|
+
type: 'object';
|
|
343
|
+
properties: Record<string, ToolParameter>;
|
|
344
|
+
required?: string[];
|
|
345
|
+
};
|
|
346
|
+
execute: (params: any, context?: ToolContext) => Promise<any>;
|
|
347
|
+
category?: string;
|
|
348
|
+
cost?: ToolCost;
|
|
349
|
+
examples?: ToolExample[];
|
|
350
|
+
/** Optional Zod schema for parameter validation */
|
|
351
|
+
schema?: ZodSchema<any>;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export declare interface ToolCall {
|
|
355
|
+
id: string;
|
|
356
|
+
type: 'function';
|
|
357
|
+
function: {
|
|
358
|
+
name: string;
|
|
359
|
+
arguments: string;
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Action to take for tool call
|
|
365
|
+
*/
|
|
366
|
+
export declare type ToolCallAction = 'execute' | 'skip' | 'defer';
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Context provided to tool execution
|
|
370
|
+
*/
|
|
371
|
+
export declare interface ToolContext {
|
|
372
|
+
workingDirectory?: string;
|
|
373
|
+
storage?: any;
|
|
374
|
+
logger?: Logger;
|
|
375
|
+
conversationState?: any;
|
|
376
|
+
[key: string]: any;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Cost hint for tool execution
|
|
381
|
+
*/
|
|
382
|
+
export declare type ToolCost = 'cheap' | 'moderate' | 'expensive';
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Tool definition for export
|
|
386
|
+
*/
|
|
387
|
+
export declare interface ToolDefinition {
|
|
388
|
+
name: string;
|
|
389
|
+
description: string;
|
|
390
|
+
parameters: Tool['parameters'];
|
|
391
|
+
category?: string;
|
|
392
|
+
cost?: ToolCost;
|
|
393
|
+
examples?: ToolExample[];
|
|
394
|
+
schema?: ZodSchema<any>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Example usage of a tool
|
|
399
|
+
*/
|
|
400
|
+
export declare interface ToolExample {
|
|
401
|
+
scenario: string;
|
|
402
|
+
params: any;
|
|
403
|
+
expectedResult: string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Tool execution result
|
|
408
|
+
*/
|
|
409
|
+
export declare interface ToolExecutionResult {
|
|
410
|
+
success: boolean;
|
|
411
|
+
result?: any;
|
|
412
|
+
error?: string;
|
|
413
|
+
duration?: number;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* ToolGuard provides security validation for tool execution.
|
|
418
|
+
*
|
|
419
|
+
* Features:
|
|
420
|
+
* - Schema-based parameter validation with Zod
|
|
421
|
+
* - Prototype pollution detection
|
|
422
|
+
* - Tool allow/deny lists
|
|
423
|
+
* - Event callbacks for security monitoring
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const guard = new ToolGuard({ deniedTools: ['dangerous_tool'] });
|
|
428
|
+
*
|
|
429
|
+
* // Validate parameters
|
|
430
|
+
* const schema = z.object({ path: z.string() });
|
|
431
|
+
* const result = guard.validateParams('read_file', { path: '/test' }, schema);
|
|
432
|
+
*
|
|
433
|
+
* // Check if tool is allowed
|
|
434
|
+
* if (guard.isToolAllowed('my_tool')) {
|
|
435
|
+
* // execute tool
|
|
436
|
+
* }
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
export declare class ToolGuard {
|
|
440
|
+
private config;
|
|
441
|
+
private logger;
|
|
442
|
+
private events;
|
|
443
|
+
constructor(config?: Partial<ToolSecurityConfig>, logger?: Logger, events?: ToolGuardEvents);
|
|
444
|
+
/**
|
|
445
|
+
* Validate tool parameters against a Zod schema
|
|
446
|
+
*/
|
|
447
|
+
validateParams<T>(toolName: string, params: unknown, schema: ZodSchema<T>): ToolValidationResult<T>;
|
|
448
|
+
/**
|
|
449
|
+
* Safely parse JSON tool arguments
|
|
450
|
+
*/
|
|
451
|
+
parseToolArguments(toolName: string, jsonString: string): ToolValidationResult<Record<string, unknown>>;
|
|
452
|
+
/**
|
|
453
|
+
* Check if a tool is allowed to execute
|
|
454
|
+
*/
|
|
455
|
+
isToolAllowed(toolName: string): boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Get current configuration
|
|
458
|
+
*/
|
|
459
|
+
getConfig(): Readonly<ToolSecurityConfig>;
|
|
460
|
+
/**
|
|
461
|
+
* Update configuration
|
|
462
|
+
*/
|
|
463
|
+
updateConfig(config: Partial<ToolSecurityConfig>): void;
|
|
464
|
+
/**
|
|
465
|
+
* Add a tool to the deny list
|
|
466
|
+
*/
|
|
467
|
+
denyTool(toolName: string): void;
|
|
468
|
+
/**
|
|
469
|
+
* Remove a tool from the deny list
|
|
470
|
+
*/
|
|
471
|
+
allowTool(toolName: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* Check if security is enabled
|
|
474
|
+
*/
|
|
475
|
+
isEnabled(): boolean;
|
|
476
|
+
/**
|
|
477
|
+
* Enable or disable security
|
|
478
|
+
*/
|
|
479
|
+
setEnabled(enabled: boolean): void;
|
|
480
|
+
/**
|
|
481
|
+
* Detect prototype pollution attempts
|
|
482
|
+
*/
|
|
483
|
+
private hasPrototypePollution;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Event handlers for security events
|
|
488
|
+
*/
|
|
489
|
+
export declare interface ToolGuardEvents {
|
|
490
|
+
onValidationFailed?: (toolName: string, message: string) => void;
|
|
491
|
+
onExecutionBlocked?: (toolName: string, reason: string) => void;
|
|
492
|
+
onPrototypePollution?: (toolName: string) => void;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Parameter definition for a tool
|
|
497
|
+
*/
|
|
498
|
+
export declare interface ToolParameter {
|
|
499
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
500
|
+
description: string;
|
|
501
|
+
items?: ToolParameter;
|
|
502
|
+
properties?: Record<string, ToolParameter>;
|
|
503
|
+
required?: string[];
|
|
504
|
+
enum?: string[];
|
|
505
|
+
default?: any;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* ToolRegistry manages tool definitions and execution.
|
|
510
|
+
*/
|
|
511
|
+
export declare class ToolRegistry {
|
|
512
|
+
private tools;
|
|
513
|
+
private context;
|
|
514
|
+
private logger;
|
|
515
|
+
private usageStats;
|
|
516
|
+
private toolGuard?;
|
|
517
|
+
private toolSandbox?;
|
|
518
|
+
private constructor();
|
|
519
|
+
/**
|
|
520
|
+
* Create a new ToolRegistry instance
|
|
521
|
+
*/
|
|
522
|
+
static create(context?: ToolContext, logger?: Logger): ToolRegistry;
|
|
523
|
+
/**
|
|
524
|
+
* Configure security guard for tool execution
|
|
525
|
+
*/
|
|
526
|
+
withSecurity(guard: ToolGuard): this;
|
|
527
|
+
/**
|
|
528
|
+
* Get the configured security guard
|
|
529
|
+
*/
|
|
530
|
+
getSecurityGuard(): ToolGuard | undefined;
|
|
531
|
+
/**
|
|
532
|
+
* Configure sandbox for tool execution
|
|
533
|
+
*/
|
|
534
|
+
withSandbox(sandbox: ToolSandbox): this;
|
|
535
|
+
/**
|
|
536
|
+
* Get the configured sandbox
|
|
537
|
+
*/
|
|
538
|
+
getSandbox(): ToolSandbox | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Register a single tool
|
|
541
|
+
*/
|
|
542
|
+
register(tool: Tool): void;
|
|
543
|
+
/**
|
|
544
|
+
* Register multiple tools at once
|
|
545
|
+
*/
|
|
546
|
+
registerAll(tools: Tool[]): void;
|
|
547
|
+
/**
|
|
548
|
+
* Get a tool by name
|
|
549
|
+
*/
|
|
550
|
+
get(name: string): Tool | undefined;
|
|
551
|
+
/**
|
|
552
|
+
* Get all registered tools
|
|
553
|
+
*/
|
|
554
|
+
getAll(): Tool[];
|
|
555
|
+
/**
|
|
556
|
+
* Get tools by category
|
|
557
|
+
*/
|
|
558
|
+
getByCategory(category: string): Tool[];
|
|
559
|
+
/**
|
|
560
|
+
* Check if a tool is registered
|
|
561
|
+
*/
|
|
562
|
+
has(name: string): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Get number of registered tools
|
|
565
|
+
*/
|
|
566
|
+
count(): number;
|
|
567
|
+
/**
|
|
568
|
+
* Execute a tool by name
|
|
569
|
+
*/
|
|
570
|
+
execute(name: string, params: any): Promise<any>;
|
|
571
|
+
/**
|
|
572
|
+
* Safely parse and execute a tool from JSON arguments
|
|
573
|
+
*/
|
|
574
|
+
executeFromJSON(name: string, jsonArgs: string): Promise<any>;
|
|
575
|
+
/**
|
|
576
|
+
* Execute multiple tools in sequence
|
|
577
|
+
*/
|
|
578
|
+
executeBatch(calls: Array<{
|
|
579
|
+
name: string;
|
|
580
|
+
params: any;
|
|
581
|
+
}>): Promise<any[]>;
|
|
582
|
+
/**
|
|
583
|
+
* Export tools in OpenAI format
|
|
584
|
+
*/
|
|
585
|
+
toOpenAIFormat(): OpenAITool[];
|
|
586
|
+
/**
|
|
587
|
+
* Export tools in Anthropic format
|
|
588
|
+
*/
|
|
589
|
+
toAnthropicFormat(): AnthropicTool[];
|
|
590
|
+
/**
|
|
591
|
+
* Get tool definitions (without execute function)
|
|
592
|
+
*/
|
|
593
|
+
getDefinitions(): ToolDefinition[];
|
|
594
|
+
/**
|
|
595
|
+
* Get usage statistics for all tools
|
|
596
|
+
*/
|
|
597
|
+
getUsageStats(): Map<string, ToolUsageStats>;
|
|
598
|
+
/**
|
|
599
|
+
* Get most frequently used tools
|
|
600
|
+
*/
|
|
601
|
+
getMostUsed(limit?: number): Tool[];
|
|
602
|
+
/**
|
|
603
|
+
* Get list of all categories
|
|
604
|
+
*/
|
|
605
|
+
getCategories(): string[];
|
|
606
|
+
/**
|
|
607
|
+
* Update execution context
|
|
608
|
+
*/
|
|
609
|
+
updateContext(context: Partial<ToolContext>): void;
|
|
610
|
+
/**
|
|
611
|
+
* Get current context
|
|
612
|
+
*/
|
|
613
|
+
getContext(): ToolContext;
|
|
614
|
+
/**
|
|
615
|
+
* Clear all tools
|
|
616
|
+
*/
|
|
617
|
+
clear(): void;
|
|
618
|
+
/**
|
|
619
|
+
* Unregister a specific tool
|
|
620
|
+
*/
|
|
621
|
+
unregister(name: string): boolean;
|
|
622
|
+
/**
|
|
623
|
+
* Reset usage statistics
|
|
624
|
+
*/
|
|
625
|
+
resetStats(): void;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Result of tool execution
|
|
630
|
+
*/
|
|
631
|
+
export declare interface ToolResult {
|
|
632
|
+
callId: string;
|
|
633
|
+
toolName: string;
|
|
634
|
+
result: any;
|
|
635
|
+
error?: Error;
|
|
636
|
+
duration: number;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* ToolSandbox provides capability-based sandboxing for tool execution.
|
|
641
|
+
*
|
|
642
|
+
* Features:
|
|
643
|
+
* - Execution timeout enforcement
|
|
644
|
+
* - Concurrent execution limits
|
|
645
|
+
* - Output size limits
|
|
646
|
+
* - Pre/post execution hooks
|
|
647
|
+
* - Cancellation support
|
|
648
|
+
*
|
|
649
|
+
* Note: This provides capability-based restrictions, not true process isolation.
|
|
650
|
+
* For maximum security, consider running untrusted tools in separate processes.
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* const sandbox = new ToolSandbox({
|
|
655
|
+
* maxExecutionTime: 5000,
|
|
656
|
+
* maxConcurrentCalls: 5,
|
|
657
|
+
* });
|
|
658
|
+
*
|
|
659
|
+
* const result = await sandbox.execute(tool, params, context);
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
export declare class ToolSandbox {
|
|
663
|
+
private config;
|
|
664
|
+
private logger;
|
|
665
|
+
private events;
|
|
666
|
+
private activeExecutions;
|
|
667
|
+
private executionCount;
|
|
668
|
+
constructor(config?: Partial<ToolSecurityConfig>, logger?: Logger, events?: ToolSandboxEvents);
|
|
669
|
+
/**
|
|
670
|
+
* Execute a tool with sandbox restrictions
|
|
671
|
+
*/
|
|
672
|
+
execute<T>(tool: Tool, params: unknown, baseContext: ToolContext, options?: Partial<SandboxOptions>): Promise<T>;
|
|
673
|
+
/**
|
|
674
|
+
* Cancel all active executions
|
|
675
|
+
*/
|
|
676
|
+
cancelAll(): void;
|
|
677
|
+
/**
|
|
678
|
+
* Cancel a specific execution by ID
|
|
679
|
+
*/
|
|
680
|
+
cancel(executionId: string): boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Get active execution count
|
|
683
|
+
*/
|
|
684
|
+
getActiveCount(): number;
|
|
685
|
+
/**
|
|
686
|
+
* Get list of active execution IDs
|
|
687
|
+
*/
|
|
688
|
+
getActiveExecutionIds(): string[];
|
|
689
|
+
/**
|
|
690
|
+
* Check if sandbox is enabled
|
|
691
|
+
*/
|
|
692
|
+
isEnabled(): boolean;
|
|
693
|
+
/**
|
|
694
|
+
* Get current configuration
|
|
695
|
+
*/
|
|
696
|
+
getConfig(): Readonly<ToolSecurityConfig>;
|
|
697
|
+
/**
|
|
698
|
+
* Update configuration
|
|
699
|
+
*/
|
|
700
|
+
updateConfig(config: Partial<ToolSecurityConfig>): void;
|
|
701
|
+
private executeWithTimeout;
|
|
702
|
+
private estimateSize;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Event handlers for sandbox events
|
|
707
|
+
*/
|
|
708
|
+
export declare interface ToolSandboxEvents {
|
|
709
|
+
onConcurrencyExceeded?: (toolName: string, activeCount: number) => void;
|
|
710
|
+
onTimeout?: (toolName: string, timeoutMs: number) => void;
|
|
711
|
+
onOutputSizeExceeded?: (toolName: string, size: number, maxSize: number) => void;
|
|
712
|
+
onCancelled?: (executionId: string) => void;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Configuration for tool security
|
|
717
|
+
*/
|
|
718
|
+
export declare interface ToolSecurityConfig {
|
|
719
|
+
enabled: boolean;
|
|
720
|
+
validateParams: boolean;
|
|
721
|
+
sandboxExecution: boolean;
|
|
722
|
+
maxExecutionTime: number;
|
|
723
|
+
maxConcurrentCalls: number;
|
|
724
|
+
deniedTools: string[];
|
|
725
|
+
allowedTools?: string[];
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Tool usage policy for a phase
|
|
730
|
+
*/
|
|
731
|
+
export declare type ToolUsagePolicy = 'required' | 'encouraged' | 'optional' | 'forbidden';
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Usage statistics for a tool
|
|
735
|
+
*/
|
|
736
|
+
export declare interface ToolUsageStats {
|
|
737
|
+
calls: number;
|
|
738
|
+
failures: number;
|
|
739
|
+
successRate: number;
|
|
740
|
+
averageDuration?: number;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Result of tool parameter validation
|
|
745
|
+
*/
|
|
746
|
+
export declare interface ToolValidationResult<T> {
|
|
747
|
+
success: boolean;
|
|
748
|
+
data?: T;
|
|
749
|
+
error?: string;
|
|
750
|
+
violations?: string[];
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Tracked context item with metadata
|
|
755
|
+
*/
|
|
756
|
+
export declare interface TrackedContextItem extends DynamicContentItem {
|
|
757
|
+
id: string;
|
|
758
|
+
hash: string;
|
|
759
|
+
position: number;
|
|
760
|
+
injectedAt: Date;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Package version
|
|
765
|
+
*/
|
|
766
|
+
export declare const VERSION = "0.0.1";
|
|
767
|
+
|
|
768
|
+
export declare function wrapLogger(toWrap: Logger, name?: string): Logger;
|
|
769
|
+
|
|
770
|
+
export { }
|