@robota-sdk/agent-core 3.0.0-beta.63 → 3.0.0-beta.65
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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dist/browser/index.d.ts +3050 -3066
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +11 -12
- package/dist/browser/index.js.map +1 -0
- package/dist/node/index.cjs +10 -12
- package/dist/node/index.d.ts +3050 -3066
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +11 -12
- package/dist/node/index.js.map +1 -0
- package/package.json +5 -5
- package/dist/browser/builtin-templates.json +0 -107
- package/dist/node/builtin-templates.json +0 -107
- package/dist/node/index.d.cts +0 -4675
package/dist/node/index.d.cts
DELETED
|
@@ -1,4675 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Message Contracts (Single Source of Truth)
|
|
3
|
-
*
|
|
4
|
-
* IMPORTANT:
|
|
5
|
-
* - This module is owned by the `interfaces` layer.
|
|
6
|
-
* - All message types used across the SDK must be defined here to avoid drift.
|
|
7
|
-
* - Runtime values (variables/classes/objects) and compile-time types can share the same name in TypeScript.
|
|
8
|
-
* Prefixing type aliases (`T*`) and interfaces (`I*`) reduces value/type name collision risk and review overhead.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Universal message role type - provider-independent neutral role.
|
|
12
|
-
*/
|
|
13
|
-
type TUniversalMessageRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
14
|
-
/**
|
|
15
|
-
* Message metadata used across conversation history and provider adapters.
|
|
16
|
-
*/
|
|
17
|
-
type TUniversalMessageMetadata = Record<string, string | number | boolean | Date | string[] | number[] | Record<string, number>>;
|
|
18
|
-
/**
|
|
19
|
-
* Universal multimodal message part contracts.
|
|
20
|
-
*/
|
|
21
|
-
interface ITextMessagePart {
|
|
22
|
-
type: 'text';
|
|
23
|
-
text: string;
|
|
24
|
-
}
|
|
25
|
-
interface IInlineImageMessagePart {
|
|
26
|
-
type: 'image_inline';
|
|
27
|
-
mimeType: string;
|
|
28
|
-
data: string;
|
|
29
|
-
}
|
|
30
|
-
interface IUriImageMessagePart {
|
|
31
|
-
type: 'image_uri';
|
|
32
|
-
uri: string;
|
|
33
|
-
mimeType?: string;
|
|
34
|
-
}
|
|
35
|
-
type TUniversalMessagePart = ITextMessagePart | IInlineImageMessagePart | IUriImageMessagePart;
|
|
36
|
-
/**
|
|
37
|
-
* Tool call (OpenAI tool calling format).
|
|
38
|
-
*/
|
|
39
|
-
interface IToolCall {
|
|
40
|
-
id: string;
|
|
41
|
-
type: 'function';
|
|
42
|
-
function: {
|
|
43
|
-
name: string;
|
|
44
|
-
arguments: string;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/** State of a message in conversation history */
|
|
48
|
-
type TMessageState = 'complete' | 'interrupted';
|
|
49
|
-
/**
|
|
50
|
-
* Base message contract shared by all message variants.
|
|
51
|
-
*/
|
|
52
|
-
interface IBaseMessage {
|
|
53
|
-
/** Unique message identifier */
|
|
54
|
-
id: string;
|
|
55
|
-
/** Message creation timestamp */
|
|
56
|
-
timestamp: Date;
|
|
57
|
-
/** Whether this message is complete or was interrupted */
|
|
58
|
-
state: TMessageState;
|
|
59
|
-
/** Additional metadata */
|
|
60
|
-
metadata?: TUniversalMessageMetadata;
|
|
61
|
-
}
|
|
62
|
-
interface IUserMessage extends IBaseMessage {
|
|
63
|
-
role: 'user';
|
|
64
|
-
content: string;
|
|
65
|
-
parts?: TUniversalMessagePart[];
|
|
66
|
-
name?: string;
|
|
67
|
-
}
|
|
68
|
-
interface IAssistantMessage extends IBaseMessage {
|
|
69
|
-
role: 'assistant';
|
|
70
|
-
/** Assistant response content (can be null when making tool calls) */
|
|
71
|
-
content: string | null;
|
|
72
|
-
parts?: TUniversalMessagePart[];
|
|
73
|
-
toolCalls?: IToolCall[];
|
|
74
|
-
}
|
|
75
|
-
interface ISystemMessage extends IBaseMessage {
|
|
76
|
-
role: 'system';
|
|
77
|
-
content: string;
|
|
78
|
-
parts?: TUniversalMessagePart[];
|
|
79
|
-
name?: string;
|
|
80
|
-
}
|
|
81
|
-
interface IToolMessage extends IBaseMessage {
|
|
82
|
-
role: 'tool';
|
|
83
|
-
content: string;
|
|
84
|
-
parts?: TUniversalMessagePart[];
|
|
85
|
-
toolCallId: string;
|
|
86
|
-
name?: string;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Universal message union used across the SDK as the canonical contract.
|
|
90
|
-
* Used for AI provider communication. Extracted from IHistoryEntry[] via filtering.
|
|
91
|
-
*/
|
|
92
|
-
type TUniversalMessage = IUserMessage | IAssistantMessage | ISystemMessage | IToolMessage;
|
|
93
|
-
/**
|
|
94
|
-
* Universal history entry — the base type for all records in conversation history.
|
|
95
|
-
*
|
|
96
|
-
* History is a universal timeline that records everything: AI chat messages,
|
|
97
|
-
* system events, skill invocations, permission decisions, etc.
|
|
98
|
-
* AI provider receives only chat entries (filtered and converted to TUniversalMessage).
|
|
99
|
-
* TUI can render any range of entries.
|
|
100
|
-
*
|
|
101
|
-
* - append-only, read-only
|
|
102
|
-
* - category + type for classification (free-form strings, no pre-defined enum)
|
|
103
|
-
* - data holds type-specific structured content
|
|
104
|
-
*/
|
|
105
|
-
interface IHistoryEntry<T = unknown> {
|
|
106
|
-
/** Unique entry identifier */
|
|
107
|
-
id: string;
|
|
108
|
-
/** Entry creation timestamp */
|
|
109
|
-
timestamp: Date;
|
|
110
|
-
/** Top-level classification: 'chat', 'event', etc. */
|
|
111
|
-
category: string;
|
|
112
|
-
/** Sub-classification within category. Free-form, not pre-defined. */
|
|
113
|
-
type: string;
|
|
114
|
-
/** Type-specific structured data */
|
|
115
|
-
data?: T;
|
|
116
|
-
}
|
|
117
|
-
/** Check if a history entry is a chat message (for AI provider filtering). */
|
|
118
|
-
declare function isChatEntry(entry: IHistoryEntry): boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Convert a chat history entry to TUniversalMessage for AI provider consumption.
|
|
121
|
-
* Only call on entries where isChatEntry() returns true.
|
|
122
|
-
*/
|
|
123
|
-
declare function chatEntryToMessage(entry: IHistoryEntry): TUniversalMessage;
|
|
124
|
-
/**
|
|
125
|
-
* Convert a TUniversalMessage to an IHistoryEntry for storage.
|
|
126
|
-
*/
|
|
127
|
-
declare function messageToHistoryEntry(message: TUniversalMessage): IHistoryEntry;
|
|
128
|
-
/**
|
|
129
|
-
* Filter history entries and convert chat entries to TUniversalMessage[].
|
|
130
|
-
* Used when passing conversation to AI provider.
|
|
131
|
-
*/
|
|
132
|
-
declare function getMessagesForAPI(history: IHistoryEntry[]): TUniversalMessage[];
|
|
133
|
-
/**
|
|
134
|
-
* Type guards for the canonical TUniversalMessage union.
|
|
135
|
-
*
|
|
136
|
-
* NOTE:
|
|
137
|
-
* - These guards are owned by the `interfaces` layer and must not depend on managers/services.
|
|
138
|
-
* - Call sites should use these guards instead of importing from manager layers.
|
|
139
|
-
*/
|
|
140
|
-
declare function isUserMessage(message: TUniversalMessage): message is IUserMessage;
|
|
141
|
-
declare function isAssistantMessage(message: TUniversalMessage): message is IAssistantMessage;
|
|
142
|
-
declare function isSystemMessage(message: TUniversalMessage): message is ISystemMessage;
|
|
143
|
-
declare function isToolMessage(message: TUniversalMessage): message is IToolMessage;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Agent-specific type definitions
|
|
147
|
-
* Local types for agent functionality - not forced to use base types unless needed for cross-connections
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Primitive value types - foundation for all other types
|
|
152
|
-
* Extended to include null/undefined for agent contexts
|
|
153
|
-
*/
|
|
154
|
-
type TPrimitiveValue = string | number | boolean | null | undefined;
|
|
155
|
-
/**
|
|
156
|
-
* Universal value type axis (recursive, JSON-like + Date).
|
|
157
|
-
*
|
|
158
|
-
* IMPORTANT:
|
|
159
|
-
* - This axis is the single source of truth for payload/context/result values.
|
|
160
|
-
* - It must support nested objects/arrays without `any`/`unknown`.
|
|
161
|
-
*/
|
|
162
|
-
type TUniversalValue = TPrimitiveValue | Date | TUniversalArrayValue | IUniversalObjectValue;
|
|
163
|
-
type TUniversalArrayValue = TUniversalValue[];
|
|
164
|
-
interface IUniversalObjectValue {
|
|
165
|
-
[key: string]: TUniversalValue;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Metadata type - consistent across agent components
|
|
169
|
-
*/
|
|
170
|
-
type TMetadataValue = TPrimitiveValue | TUniversalArrayValue | Date;
|
|
171
|
-
type TMetadata = Record<string, TMetadataValue>;
|
|
172
|
-
/**
|
|
173
|
-
* Context data type - for execution contexts
|
|
174
|
-
*/
|
|
175
|
-
type TContextData = Record<string, TUniversalValue>;
|
|
176
|
-
/**
|
|
177
|
-
* Logger data type - for logging contexts
|
|
178
|
-
*/
|
|
179
|
-
type TLoggerData = Record<string, TUniversalValue | Date | Error>;
|
|
180
|
-
/**
|
|
181
|
-
* Configuration types - for agent configuration
|
|
182
|
-
*/
|
|
183
|
-
type TComplexConfigValue = Record<string, TPrimitiveValue | TUniversalArrayValue | IUniversalObjectValue>;
|
|
184
|
-
type TConfigValue = TPrimitiveValue | TUniversalArrayValue | IUniversalObjectValue | Array<TComplexConfigValue> | Array<Record<string, TPrimitiveValue | TUniversalArrayValue | IUniversalObjectValue>> | Array<TComplexConfigValue> | TComplexConfigValue;
|
|
185
|
-
type TConfigData = Record<string, TConfigValue>;
|
|
186
|
-
/**
|
|
187
|
-
* Tool parameter value type - specific for tool parameters
|
|
188
|
-
*/
|
|
189
|
-
type TToolParameters = Record<string, TUniversalValue>;
|
|
190
|
-
/**
|
|
191
|
-
* Tool result data type - for tool execution results
|
|
192
|
-
*/
|
|
193
|
-
/**
|
|
194
|
-
* Plugin context type - for plugin execution contexts
|
|
195
|
-
*/
|
|
196
|
-
interface IPluginContext {
|
|
197
|
-
input?: string;
|
|
198
|
-
response?: string;
|
|
199
|
-
messages?: TUniversalMessage[];
|
|
200
|
-
responseMessage?: TUniversalMessage;
|
|
201
|
-
metadata?: TMetadata;
|
|
202
|
-
error?: Error;
|
|
203
|
-
executionContext?: TContextData;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Type utility functions for safe type checking and validation
|
|
207
|
-
* @internal
|
|
208
|
-
*/
|
|
209
|
-
declare const TypeUtils: {
|
|
210
|
-
isPrimitive: (value: TUniversalValue) => value is TPrimitiveValue;
|
|
211
|
-
isArray: (value: TUniversalValue) => value is TUniversalArrayValue;
|
|
212
|
-
isObject: (value: TUniversalValue) => value is IUniversalObjectValue;
|
|
213
|
-
isUniversalValue: (value: TUniversalValue) => value is TUniversalValue;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
interface IProviderFunctionCallingCapability {
|
|
217
|
-
supported: boolean;
|
|
218
|
-
reason?: string;
|
|
219
|
-
}
|
|
220
|
-
interface IProviderNativeWebToolCapability {
|
|
221
|
-
supported: boolean;
|
|
222
|
-
enabled: boolean;
|
|
223
|
-
source?: string;
|
|
224
|
-
reason?: string;
|
|
225
|
-
}
|
|
226
|
-
interface IProviderNativeWebToolCapabilities {
|
|
227
|
-
webSearch: IProviderNativeWebToolCapability;
|
|
228
|
-
webFetch: IProviderNativeWebToolCapability;
|
|
229
|
-
}
|
|
230
|
-
interface IProviderCapabilities {
|
|
231
|
-
functionCalling: IProviderFunctionCallingCapability;
|
|
232
|
-
nativeWebTools: IProviderNativeWebToolCapabilities;
|
|
233
|
-
}
|
|
234
|
-
interface IProviderNativeWebToolRequest {
|
|
235
|
-
webSearch?: boolean;
|
|
236
|
-
webFetch?: boolean;
|
|
237
|
-
}
|
|
238
|
-
declare function createDefaultProviderCapabilities(functionCallingSupported: boolean): IProviderCapabilities;
|
|
239
|
-
declare function getProviderCapabilities(provider: IAIProvider): IProviderCapabilities;
|
|
240
|
-
declare function assertProviderNativeWebToolsAvailable(providerName: string, capabilities: IProviderCapabilities, request: IProviderNativeWebToolRequest | undefined): void;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Reusable type definitions for provider layer
|
|
244
|
-
*/
|
|
245
|
-
/**
|
|
246
|
-
* Provider configuration value type
|
|
247
|
-
* Used for storing provider-specific configuration values
|
|
248
|
-
*/
|
|
249
|
-
type TProviderConfigValue = string | number | boolean;
|
|
250
|
-
/**
|
|
251
|
-
* JSON Schema parameter default value type
|
|
252
|
-
* Used for default values in parameter schemas
|
|
253
|
-
*/
|
|
254
|
-
type TParameterDefaultValue = string | number | boolean | null;
|
|
255
|
-
/**
|
|
256
|
-
* JSON Schema primitive types
|
|
257
|
-
*/
|
|
258
|
-
type TJSONSchemaKind = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
|
|
259
|
-
/**
|
|
260
|
-
* JSON Schema enum values
|
|
261
|
-
*/
|
|
262
|
-
type TJSONSchemaEnum = string[] | number[] | boolean[] | (string | number | boolean)[];
|
|
263
|
-
/**
|
|
264
|
-
* Tool schema definition
|
|
265
|
-
*/
|
|
266
|
-
interface IToolSchema {
|
|
267
|
-
name: string;
|
|
268
|
-
description: string;
|
|
269
|
-
parameters: {
|
|
270
|
-
type: 'object';
|
|
271
|
-
properties: Record<string, IParameterSchema>;
|
|
272
|
-
required?: string[];
|
|
273
|
-
additionalProperties?: boolean | IParameterSchema;
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Parameter schema for tools
|
|
278
|
-
*/
|
|
279
|
-
interface IParameterSchema {
|
|
280
|
-
type: TJSONSchemaKind;
|
|
281
|
-
description?: string;
|
|
282
|
-
enum?: TJSONSchemaEnum;
|
|
283
|
-
items?: IParameterSchema;
|
|
284
|
-
properties?: Record<string, IParameterSchema>;
|
|
285
|
-
additionalProperties?: IParameterSchema;
|
|
286
|
-
minimum?: number;
|
|
287
|
-
maximum?: number;
|
|
288
|
-
pattern?: string;
|
|
289
|
-
format?: string;
|
|
290
|
-
default?: TParameterDefaultValue;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Token usage statistics
|
|
294
|
-
*/
|
|
295
|
-
interface ITokenUsage {
|
|
296
|
-
promptTokens: number;
|
|
297
|
-
completionTokens: number;
|
|
298
|
-
totalTokens: number;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Raw provider response interface
|
|
302
|
-
*/
|
|
303
|
-
interface IRawProviderResponse {
|
|
304
|
-
content: string | null;
|
|
305
|
-
toolCalls?: IToolCall[];
|
|
306
|
-
usage?: ITokenUsage;
|
|
307
|
-
finishReason?: string;
|
|
308
|
-
model?: string;
|
|
309
|
-
metadata?: Record<string, TProviderConfigValue>;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Provider request payload
|
|
313
|
-
*/
|
|
314
|
-
interface IProviderRequest {
|
|
315
|
-
messages: TUniversalMessage[];
|
|
316
|
-
model?: string;
|
|
317
|
-
temperature?: number;
|
|
318
|
-
maxTokens?: number;
|
|
319
|
-
tools?: IToolSchema[];
|
|
320
|
-
systemMessage?: string;
|
|
321
|
-
metadata?: Record<string, string | number | boolean>;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Provider-specific configuration options
|
|
325
|
-
*/
|
|
326
|
-
interface IProviderSpecificOptions {
|
|
327
|
-
/** OpenAI specific options */
|
|
328
|
-
openai?: {
|
|
329
|
-
organization?: string;
|
|
330
|
-
user?: string;
|
|
331
|
-
stop?: string | string[];
|
|
332
|
-
presencePenalty?: number;
|
|
333
|
-
frequencyPenalty?: number;
|
|
334
|
-
logitBias?: Record<string, number>;
|
|
335
|
-
topP?: number;
|
|
336
|
-
n?: number;
|
|
337
|
-
stream?: boolean;
|
|
338
|
-
suffix?: string;
|
|
339
|
-
echo?: boolean;
|
|
340
|
-
bestOf?: number;
|
|
341
|
-
logprobs?: number;
|
|
342
|
-
};
|
|
343
|
-
/** Anthropic specific options */
|
|
344
|
-
anthropic?: {
|
|
345
|
-
stopSequences?: string[];
|
|
346
|
-
topP?: number;
|
|
347
|
-
topK?: number;
|
|
348
|
-
metadata?: {
|
|
349
|
-
userId?: string;
|
|
350
|
-
};
|
|
351
|
-
};
|
|
352
|
-
/** Google specific options */
|
|
353
|
-
google?: {
|
|
354
|
-
candidateCount?: number;
|
|
355
|
-
stopSequences?: string[];
|
|
356
|
-
safetySettings?: Array<{
|
|
357
|
-
category: string;
|
|
358
|
-
threshold: string;
|
|
359
|
-
}>;
|
|
360
|
-
responseModalities?: Array<'TEXT' | 'IMAGE'>;
|
|
361
|
-
topP?: number;
|
|
362
|
-
topK?: number;
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Callback for receiving text deltas during streaming.
|
|
367
|
-
* Called for each text chunk as the model generates output.
|
|
368
|
-
*/
|
|
369
|
-
type TTextDeltaCallback = (delta: string) => void;
|
|
370
|
-
type TProviderNativeRawPayloadKind = 'request' | 'response' | 'stream_event';
|
|
371
|
-
type TProviderNativeRawPayload = string | number | boolean | object | null | undefined;
|
|
372
|
-
interface IProviderNativeRawPayloadEvent {
|
|
373
|
-
provider: string;
|
|
374
|
-
apiSurface?: string;
|
|
375
|
-
payloadKind: TProviderNativeRawPayloadKind;
|
|
376
|
-
payload: TProviderNativeRawPayload;
|
|
377
|
-
sequence?: number;
|
|
378
|
-
metadata?: Record<string, TProviderConfigValue>;
|
|
379
|
-
}
|
|
380
|
-
type TProviderNativeRawPayloadCallback = (event: IProviderNativeRawPayloadEvent) => void;
|
|
381
|
-
/**
|
|
382
|
-
* Options for AI provider chat requests
|
|
383
|
-
*/
|
|
384
|
-
interface IChatOptions extends IProviderSpecificOptions {
|
|
385
|
-
/** Tool schemas to provide to the AI provider */
|
|
386
|
-
tools?: IToolSchema[];
|
|
387
|
-
/** Maximum number of tokens to generate */
|
|
388
|
-
maxTokens?: number;
|
|
389
|
-
/** Temperature for response randomness (0-1) */
|
|
390
|
-
temperature?: number;
|
|
391
|
-
/** Model to use for the request */
|
|
392
|
-
model?: string;
|
|
393
|
-
/** Callback for text deltas during streaming. When provided, the provider
|
|
394
|
-
* should use streaming internally and call this for each text chunk,
|
|
395
|
-
* while still returning the complete assembled message. */
|
|
396
|
-
onTextDelta?: TTextDeltaCallback;
|
|
397
|
-
/** Callback for provider-owned native SDK request/response/stream payload capture. */
|
|
398
|
-
onProviderNativeRawPayload?: TProviderNativeRawPayloadCallback;
|
|
399
|
-
/** AbortSignal for cancelling the provider call */
|
|
400
|
-
signal?: AbortSignal;
|
|
401
|
-
/** Provider-native hosted web tools requested for this call */
|
|
402
|
-
nativeWebTools?: IProviderNativeWebToolRequest;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Provider-agnostic AI Provider interface
|
|
406
|
-
* This interface uses only TUniversalMessage types and avoids provider-specific types
|
|
407
|
-
*/
|
|
408
|
-
interface IAIProvider {
|
|
409
|
-
/** Provider identifier */
|
|
410
|
-
readonly name: string;
|
|
411
|
-
/** Provider version */
|
|
412
|
-
readonly version: string;
|
|
413
|
-
/**
|
|
414
|
-
* Generate response from AI model using TUniversalMessage
|
|
415
|
-
* @param messages - Array of TUniversalMessage from conversation history
|
|
416
|
-
* @param options - Chat options including tools, model settings, etc.
|
|
417
|
-
* @returns Promise resolving to a TUniversalMessage response
|
|
418
|
-
*/
|
|
419
|
-
chat(messages: TUniversalMessage[], options?: IChatOptions): Promise<TUniversalMessage>;
|
|
420
|
-
/**
|
|
421
|
-
* Generate streaming response from AI model using TUniversalMessage
|
|
422
|
-
* @param messages - Array of TUniversalMessage from conversation history
|
|
423
|
-
* @param options - Chat options including tools, model settings, etc.
|
|
424
|
-
* @returns AsyncIterable of TUniversalMessage chunks
|
|
425
|
-
*/
|
|
426
|
-
chatStream?(messages: TUniversalMessage[], options?: IChatOptions): AsyncIterable<TUniversalMessage>;
|
|
427
|
-
/**
|
|
428
|
-
* Generate response from AI model (raw provider response)
|
|
429
|
-
* @param payload - Provider request payload
|
|
430
|
-
* @returns Promise resolving to raw provider response
|
|
431
|
-
*/
|
|
432
|
-
generateResponse(payload: IProviderRequest): Promise<IRawProviderResponse>;
|
|
433
|
-
/**
|
|
434
|
-
* Generate streaming response from AI model (raw provider response)
|
|
435
|
-
* @param payload - Provider request payload
|
|
436
|
-
* @returns AsyncIterable of raw provider response chunks
|
|
437
|
-
*/
|
|
438
|
-
generateStreamingResponse?(payload: IProviderRequest): AsyncIterable<IRawProviderResponse>;
|
|
439
|
-
/**
|
|
440
|
-
* Check if the provider supports tool calling
|
|
441
|
-
* @returns true if tool calling is supported
|
|
442
|
-
*/
|
|
443
|
-
supportsTools(): boolean;
|
|
444
|
-
/**
|
|
445
|
-
* Report provider-neutral capability state.
|
|
446
|
-
* Providers without native web support can omit this and use default capability helpers.
|
|
447
|
-
*/
|
|
448
|
-
getCapabilities?(): IProviderCapabilities;
|
|
449
|
-
/**
|
|
450
|
-
* Optional generic hook for enabling provider-native hosted web behavior.
|
|
451
|
-
*/
|
|
452
|
-
configureNativeWebTools?(request: IProviderNativeWebToolRequest): IProviderCapabilities;
|
|
453
|
-
/**
|
|
454
|
-
* Validate provider configuration
|
|
455
|
-
* @returns true if configuration is valid
|
|
456
|
-
*/
|
|
457
|
-
validateConfig(): boolean;
|
|
458
|
-
/**
|
|
459
|
-
* Clean up resources when provider is no longer needed
|
|
460
|
-
*/
|
|
461
|
-
dispose?(): Promise<void>;
|
|
462
|
-
/**
|
|
463
|
-
* Close provider connections and cleanup resources
|
|
464
|
-
*/
|
|
465
|
-
close?(): Promise<void>;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Provider options interface
|
|
469
|
-
*/
|
|
470
|
-
interface IProviderOptions {
|
|
471
|
-
apiKey?: string;
|
|
472
|
-
baseURL?: string;
|
|
473
|
-
timeout?: number;
|
|
474
|
-
retries?: number;
|
|
475
|
-
maxConcurrentRequests?: number;
|
|
476
|
-
defaultModel?: string;
|
|
477
|
-
organization?: string;
|
|
478
|
-
project?: string;
|
|
479
|
-
/** Additional provider-specific configuration */
|
|
480
|
-
extra?: Record<string, TProviderConfigValue>;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Base union for provider option values.
|
|
484
|
-
*
|
|
485
|
-
* Purpose:
|
|
486
|
-
* - Enable provider packages to compose their own option value unions without redefining the primitives.
|
|
487
|
-
* - Keep the shared axis in @robota-sdk/agent-core (SSOT).
|
|
488
|
-
*
|
|
489
|
-
* Note:
|
|
490
|
-
* - Provider packages may extend this with provider-specific runtime objects (e.g., OpenAI/Anthropic clients).
|
|
491
|
-
*/
|
|
492
|
-
type TProviderOptionValueBase = string | number | boolean | undefined | null | TProviderOptionValueBase[] | {
|
|
493
|
-
[key: string]: TProviderOptionValueBase;
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* @fileoverview Event service interface definitions.
|
|
498
|
-
*
|
|
499
|
-
* These interfaces are the single source of truth for event-related contracts
|
|
500
|
-
* within @robota-sdk/agent-core.
|
|
501
|
-
*/
|
|
502
|
-
/**
|
|
503
|
-
* Primitive value types for event payloads.
|
|
504
|
-
*/
|
|
505
|
-
type TEventPrimitiveValue = string | number | boolean | null | undefined;
|
|
506
|
-
/**
|
|
507
|
-
* Recursive universal value type for event payloads (JSON-like + Date).
|
|
508
|
-
*/
|
|
509
|
-
type TEventUniversalValue = TEventPrimitiveValue | Date | TEventUniversalValue[] | IEventObjectValue;
|
|
510
|
-
interface IEventObjectValue {
|
|
511
|
-
[key: string]: TEventUniversalValue;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Logger data type for event metadata.
|
|
515
|
-
*/
|
|
516
|
-
type TEventLoggerData = Record<string, TEventUniversalValue | Date | Error>;
|
|
517
|
-
/**
|
|
518
|
-
* A single segment in an explicit ownerPath.
|
|
519
|
-
*
|
|
520
|
-
* Path-only rule:
|
|
521
|
-
* - Relationships must be derived from these explicit segments, not from parsing IDs.
|
|
522
|
-
*/
|
|
523
|
-
interface IOwnerPathSegment {
|
|
524
|
-
type: string;
|
|
525
|
-
id: string;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Event context that accompanies an emitted event.
|
|
529
|
-
* This is the single source of truth for deterministic linking in subscribers.
|
|
530
|
-
*/
|
|
531
|
-
interface IEventContext {
|
|
532
|
-
ownerType: string;
|
|
533
|
-
ownerId: string;
|
|
534
|
-
ownerPath: IOwnerPathSegment[];
|
|
535
|
-
/** Depth of the current execution in the hierarchy (0 = root) */
|
|
536
|
-
depth?: number;
|
|
537
|
-
/** Unique span identifier for distributed tracing correlation */
|
|
538
|
-
spanId?: string;
|
|
539
|
-
/** Optional structured metadata for debugging/observability */
|
|
540
|
-
metadata?: TEventLoggerData;
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* Allowed extension values for event payloads.
|
|
544
|
-
*/
|
|
545
|
-
type TEventExtensionValue = TEventUniversalValue | TEventLoggerData | Error | IEventContext | IOwnerPathSegment[];
|
|
546
|
-
/**
|
|
547
|
-
* Base event payload shape.
|
|
548
|
-
* Emitters may add additional fields, but MUST keep linkage information explicit.
|
|
549
|
-
*/
|
|
550
|
-
interface IBaseEventData {
|
|
551
|
-
/** Timestamp when the event was emitted. This is required for deterministic ordering. */
|
|
552
|
-
timestamp: Date;
|
|
553
|
-
/** Optional structured metadata */
|
|
554
|
-
metadata?: TEventLoggerData;
|
|
555
|
-
/** Extensible fields for event-specific payloads */
|
|
556
|
-
[key: string]: TEventExtensionValue | undefined;
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Execution-related event payload.
|
|
560
|
-
*/
|
|
561
|
-
interface IExecutionEventData extends IBaseEventData {
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Tool-related event payload.
|
|
565
|
-
*/
|
|
566
|
-
interface IToolEventData extends IBaseEventData {
|
|
567
|
-
toolName?: string;
|
|
568
|
-
parameters?: Record<string, TEventUniversalValue>;
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Agent-related event payload.
|
|
572
|
-
*/
|
|
573
|
-
interface IAgentEventData extends IBaseEventData {
|
|
574
|
-
agentId?: string;
|
|
575
|
-
}
|
|
576
|
-
type TEventListener = (eventType: string, data: IBaseEventData, context?: IEventContext) => void;
|
|
577
|
-
/**
|
|
578
|
-
* Minimal EventService contract for emitting events.
|
|
579
|
-
*/
|
|
580
|
-
interface IEventService {
|
|
581
|
-
emit(eventType: string, data: IBaseEventData, context?: IEventContext): void;
|
|
582
|
-
subscribe(listener: TEventListener): void;
|
|
583
|
-
unsubscribe(listener: TEventListener): void;
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Explicit owner binding information used for scoped event emission.
|
|
587
|
-
*/
|
|
588
|
-
interface IEventServiceOwnerBinding {
|
|
589
|
-
ownerType: string;
|
|
590
|
-
ownerId: string;
|
|
591
|
-
ownerPath: IOwnerPathSegment[];
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* Abstract base for event services.
|
|
596
|
-
* Concrete implementations decide how events are delivered.
|
|
597
|
-
*/
|
|
598
|
-
declare abstract class AbstractEventService implements IEventService {
|
|
599
|
-
private listeners;
|
|
600
|
-
abstract emit(eventType: string, data: IBaseEventData, context?: IEventContext): void;
|
|
601
|
-
subscribe(listener: TEventListener): void;
|
|
602
|
-
unsubscribe(listener: TEventListener): void;
|
|
603
|
-
protected notifyListeners(eventType: string, data: IBaseEventData, context?: IEventContext): void;
|
|
604
|
-
}
|
|
605
|
-
/**
|
|
606
|
-
* Default no-op event service (production-safe).
|
|
607
|
-
* When injected, emit() intentionally does nothing.
|
|
608
|
-
*/
|
|
609
|
-
declare class DefaultEventService extends AbstractEventService {
|
|
610
|
-
emit(_eventType: string, _data: IBaseEventData, _context?: IEventContext): void;
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Singleton default event service instance.
|
|
614
|
-
*/
|
|
615
|
-
declare const DEFAULT_ABSTRACT_EVENT_SERVICE: IEventService;
|
|
616
|
-
/**
|
|
617
|
-
* Check if a given service is the default no-op implementation.
|
|
618
|
-
*/
|
|
619
|
-
declare function isDefaultEventService(service: IEventService): boolean;
|
|
620
|
-
/**
|
|
621
|
-
* Compose a full event name from owner prefix and local name.
|
|
622
|
-
* Local names must not contain dots.
|
|
623
|
-
*/
|
|
624
|
-
declare function composeEventName(ownerType: string, localName: string): string;
|
|
625
|
-
/**
|
|
626
|
-
* A scoped event service that always emits with an owner binding applied.
|
|
627
|
-
*/
|
|
628
|
-
declare class StructuredEventService extends AbstractEventService {
|
|
629
|
-
private readonly base;
|
|
630
|
-
private readonly binding;
|
|
631
|
-
constructor(base: IEventService, binding: IEventServiceOwnerBinding);
|
|
632
|
-
emit(eventType: string, data: IBaseEventData, context?: IEventContext): void;
|
|
633
|
-
subscribe(listener: TEventListener): void;
|
|
634
|
-
unsubscribe(listener: TEventListener): void;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Bind an EventService to an explicit owner path.
|
|
638
|
-
* This is the standard entry point for scoped emission (path-only architecture).
|
|
639
|
-
*/
|
|
640
|
-
declare function bindWithOwnerPath(base: IEventService, binding: IEventServiceOwnerBinding): IEventService;
|
|
641
|
-
/**
|
|
642
|
-
* Alias for bindWithOwnerPath for historical call sites.
|
|
643
|
-
* Intentionally forwards to the single authoritative implementation.
|
|
644
|
-
*/
|
|
645
|
-
declare function bindEventServiceOwner(base: IEventService, binding: IEventServiceOwnerBinding): IEventService;
|
|
646
|
-
/**
|
|
647
|
-
* Observable EventService that notifies subscribed listeners.
|
|
648
|
-
*/
|
|
649
|
-
declare class ObservableEventService extends AbstractEventService {
|
|
650
|
-
emit(eventType: string, data: IBaseEventData, context?: IEventContext): void;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
declare const TASK_EVENTS: {
|
|
654
|
-
readonly ASSIGNED: "assigned";
|
|
655
|
-
readonly COMPLETED: "completed";
|
|
656
|
-
};
|
|
657
|
-
declare const TASK_EVENT_PREFIX: "task";
|
|
658
|
-
|
|
659
|
-
declare const USER_EVENTS: {
|
|
660
|
-
readonly MESSAGE: "message";
|
|
661
|
-
readonly INPUT: "input";
|
|
662
|
-
};
|
|
663
|
-
declare const USER_EVENT_PREFIX: "user";
|
|
664
|
-
type TUserEvent = (typeof USER_EVENTS)[keyof typeof USER_EVENTS];
|
|
665
|
-
|
|
666
|
-
type TToolContextExtensionValue = TUniversalValue | Date | Error | TLoggerData | TContextData | TToolParameters | TToolMetadata;
|
|
667
|
-
/**
|
|
668
|
-
* Tool metadata structure - specific type definition
|
|
669
|
-
*/
|
|
670
|
-
type TToolMetadata = Record<string, string | number | boolean | string[] | number[] | boolean[] | TToolParameters>;
|
|
671
|
-
/**
|
|
672
|
-
* Tool execution data - domain payload for tool results.
|
|
673
|
-
*
|
|
674
|
-
* IMPORTANT:
|
|
675
|
-
* - This must support structured tool outputs without resorting to `any`.
|
|
676
|
-
* - Prefer `ToolResultData` (derived from the canonical `UniversalValue` axis).
|
|
677
|
-
*/
|
|
678
|
-
/**
|
|
679
|
-
* Tool execution result - extended for ToolExecutionData compatibility
|
|
680
|
-
*/
|
|
681
|
-
interface IToolResult {
|
|
682
|
-
success: boolean;
|
|
683
|
-
data?: TUniversalValue;
|
|
684
|
-
error?: string;
|
|
685
|
-
metadata?: TToolMetadata;
|
|
686
|
-
[key: string]: TToolContextExtensionValue | undefined;
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Enhanced tool execution result with additional metadata
|
|
690
|
-
*/
|
|
691
|
-
interface IToolExecutionResult {
|
|
692
|
-
/** Whether execution was successful */
|
|
693
|
-
success: boolean;
|
|
694
|
-
/** Tool name that was executed */
|
|
695
|
-
toolName?: string;
|
|
696
|
-
/** Execution result or data */
|
|
697
|
-
result?: TUniversalValue;
|
|
698
|
-
/** Error message if execution failed */
|
|
699
|
-
error?: string;
|
|
700
|
-
/** Execution duration in milliseconds */
|
|
701
|
-
duration?: number;
|
|
702
|
-
/** Unique execution ID */
|
|
703
|
-
executionId?: string;
|
|
704
|
-
/** Additional metadata */
|
|
705
|
-
metadata?: TToolMetadata;
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Tool execution context - type-safe context for tool execution
|
|
709
|
-
* Enhanced with hierarchical execution tracking support
|
|
710
|
-
*/
|
|
711
|
-
interface IToolExecutionContext {
|
|
712
|
-
toolName: string;
|
|
713
|
-
parameters: TToolParameters;
|
|
714
|
-
executionId?: string;
|
|
715
|
-
userId?: string;
|
|
716
|
-
sessionId?: string;
|
|
717
|
-
metadata?: TToolMetadata;
|
|
718
|
-
/** Parent execution ID for hierarchical tool execution tracking */
|
|
719
|
-
parentExecutionId?: string;
|
|
720
|
-
/** Root execution ID (Team/Agent level) for complete execution tree tracking */
|
|
721
|
-
rootExecutionId?: string;
|
|
722
|
-
/** Execution depth level (0: Team, 1: Agent, 2: Tool, etc.) */
|
|
723
|
-
executionLevel?: number;
|
|
724
|
-
/** Execution path array showing the complete execution hierarchy */
|
|
725
|
-
executionPath?: string[];
|
|
726
|
-
/** Real-time execution data for accurate tracking (no simulation) */
|
|
727
|
-
realTimeData?: {
|
|
728
|
-
/** Actual execution start time */
|
|
729
|
-
startTime: Date;
|
|
730
|
-
/** Actual input parameters passed to the tool */
|
|
731
|
-
actualParameters: TToolParameters;
|
|
732
|
-
/** Tool-provided estimated duration (optional) */
|
|
733
|
-
estimatedDuration?: number;
|
|
734
|
-
};
|
|
735
|
-
/**
|
|
736
|
-
* Additional tool execution context extensions.
|
|
737
|
-
*
|
|
738
|
-
* IMPORTANT:
|
|
739
|
-
* - Avoid ad-hoc top-level fields to keep the contract stable.
|
|
740
|
-
* - Use this map for forward-compatible extra data with constrained value types.
|
|
741
|
-
*/
|
|
742
|
-
extensions?: Record<string, TToolContextExtensionValue>;
|
|
743
|
-
/** Owner context propagated from EventService */
|
|
744
|
-
ownerType?: string;
|
|
745
|
-
ownerId?: string;
|
|
746
|
-
ownerPath?: IOwnerPathSegment[];
|
|
747
|
-
sourceId?: string;
|
|
748
|
-
/**
|
|
749
|
-
* Tool-call scoped EventService instance.
|
|
750
|
-
* Caller (ExecutionService/ToolExecutionService) is responsible for providing
|
|
751
|
-
* an ownerPath-bound EventService for this tool call.
|
|
752
|
-
*/
|
|
753
|
-
eventService?: IEventService;
|
|
754
|
-
/**
|
|
755
|
-
* Unbound base EventService instance.
|
|
756
|
-
*
|
|
757
|
-
* Required when a tool needs to create another owner-bound EventService
|
|
758
|
-
* for a different owner (e.g., creating an agent from a tool call).
|
|
759
|
-
*
|
|
760
|
-
* NOTE: Do not wrap an already owner-bound EventService to bind a different owner.
|
|
761
|
-
* Owner-bound instances must not be layered across different owners.
|
|
762
|
-
*/
|
|
763
|
-
baseEventService?: IEventService;
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Parameter validation result
|
|
767
|
-
*/
|
|
768
|
-
interface IParameterValidationResult {
|
|
769
|
-
/** Whether parameters are valid */
|
|
770
|
-
isValid: boolean;
|
|
771
|
-
/** Validation error messages */
|
|
772
|
-
errors: string[];
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* Generic tool executor function
|
|
776
|
-
*/
|
|
777
|
-
type TToolExecutor<TParams = TToolParameters, TResult = TUniversalValue> = (parameters: TParams, context?: IToolExecutionContext) => Promise<TResult>;
|
|
778
|
-
/**
|
|
779
|
-
* Base tool interface
|
|
780
|
-
*/
|
|
781
|
-
interface ITool {
|
|
782
|
-
/** Tool schema */
|
|
783
|
-
schema: IToolSchema;
|
|
784
|
-
/**
|
|
785
|
-
* Execute the tool with given parameters
|
|
786
|
-
*/
|
|
787
|
-
execute(parameters: TToolParameters, context?: IToolExecutionContext): Promise<IToolResult>;
|
|
788
|
-
/**
|
|
789
|
-
* Validate tool parameters
|
|
790
|
-
*/
|
|
791
|
-
validate(parameters: TToolParameters): boolean;
|
|
792
|
-
/**
|
|
793
|
-
* Validate tool parameters with detailed result
|
|
794
|
-
*/
|
|
795
|
-
validateParameters(parameters: TToolParameters): IParameterValidationResult;
|
|
796
|
-
/**
|
|
797
|
-
* Get tool description
|
|
798
|
-
*/
|
|
799
|
-
getDescription(): string;
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Function tool implementation
|
|
803
|
-
*/
|
|
804
|
-
interface IFunctionTool extends ITool {
|
|
805
|
-
/** Function to execute */
|
|
806
|
-
fn: TToolExecutor;
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Tool registry interface
|
|
810
|
-
*/
|
|
811
|
-
interface IToolRegistry {
|
|
812
|
-
/**
|
|
813
|
-
* Register a tool
|
|
814
|
-
*/
|
|
815
|
-
register(tool: ITool): void;
|
|
816
|
-
/**
|
|
817
|
-
* Unregister a tool
|
|
818
|
-
*/
|
|
819
|
-
unregister(name: string): void;
|
|
820
|
-
/**
|
|
821
|
-
* Get tool by name
|
|
822
|
-
*/
|
|
823
|
-
get(name: string): ITool | undefined;
|
|
824
|
-
/**
|
|
825
|
-
* Get all registered tools
|
|
826
|
-
*/
|
|
827
|
-
getAll(): ITool[];
|
|
828
|
-
/**
|
|
829
|
-
* Get tool schemas
|
|
830
|
-
*/
|
|
831
|
-
getSchemas(): IToolSchema[];
|
|
832
|
-
/**
|
|
833
|
-
* Check if tool exists
|
|
834
|
-
*/
|
|
835
|
-
has(name: string): boolean;
|
|
836
|
-
/**
|
|
837
|
-
* Clear all tools
|
|
838
|
-
*/
|
|
839
|
-
clear(): void;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
declare const EXECUTION_EVENT_NAMES: {
|
|
843
|
-
readonly START: "execution.start";
|
|
844
|
-
readonly COMPLETE: "execution.complete";
|
|
845
|
-
readonly ERROR: "execution.error";
|
|
846
|
-
};
|
|
847
|
-
declare const TOOL_EVENT_NAMES: {
|
|
848
|
-
readonly CALL_START: "tool.call_start";
|
|
849
|
-
readonly CALL_COMPLETE: "tool.call_complete";
|
|
850
|
-
readonly CALL_ERROR: "tool.call_error";
|
|
851
|
-
};
|
|
852
|
-
declare const AGENT_EVENT_NAMES: {
|
|
853
|
-
readonly EXECUTION_START: "agent.execution_start";
|
|
854
|
-
readonly EXECUTION_COMPLETE: "agent.execution_complete";
|
|
855
|
-
readonly EXECUTION_ERROR: "agent.execution_error";
|
|
856
|
-
readonly CREATED: "agent.created";
|
|
857
|
-
};
|
|
858
|
-
type TExecutionEventName = (typeof EXECUTION_EVENT_NAMES)[keyof typeof EXECUTION_EVENT_NAMES];
|
|
859
|
-
type TToolEventName = (typeof TOOL_EVENT_NAMES)[keyof typeof TOOL_EVENT_NAMES];
|
|
860
|
-
type TAgentEventName = (typeof AGENT_EVENT_NAMES)[keyof typeof AGENT_EVENT_NAMES];
|
|
861
|
-
/**
|
|
862
|
-
* Event types that can be emitted.
|
|
863
|
-
*
|
|
864
|
-
* IMPORTANT:
|
|
865
|
-
* - Do not use string literals for event names outside this module.
|
|
866
|
-
* - Import and use EVENT_EMITTER_EVENTS instead.
|
|
867
|
-
*/
|
|
868
|
-
declare const EVENT_EMITTER_EVENTS: {
|
|
869
|
-
readonly EXECUTION_START: "execution.start";
|
|
870
|
-
readonly EXECUTION_COMPLETE: "execution.complete";
|
|
871
|
-
readonly EXECUTION_ERROR: "execution.error";
|
|
872
|
-
readonly TOOL_BEFORE_EXECUTE: "tool.beforeExecute";
|
|
873
|
-
readonly TOOL_AFTER_EXECUTE: "tool.afterExecute";
|
|
874
|
-
readonly TOOL_SUCCESS: "tool.success";
|
|
875
|
-
readonly TOOL_ERROR: "tool.call_error";
|
|
876
|
-
readonly CONVERSATION_START: "conversation.start";
|
|
877
|
-
readonly CONVERSATION_COMPLETE: "conversation.complete";
|
|
878
|
-
readonly CONVERSATION_ERROR: "conversation.error";
|
|
879
|
-
readonly AGENT_EXECUTION_START: "agent.execution_start";
|
|
880
|
-
readonly AGENT_EXECUTION_COMPLETE: "agent.execution_complete";
|
|
881
|
-
readonly AGENT_EXECUTION_ERROR: "agent.execution_error";
|
|
882
|
-
readonly AGENT_CREATED: "agent.created";
|
|
883
|
-
readonly AGENT_DESTROYED: "agent.destroyed";
|
|
884
|
-
readonly PLUGIN_LOADED: "plugin.loaded";
|
|
885
|
-
readonly PLUGIN_UNLOADED: "plugin.unloaded";
|
|
886
|
-
readonly PLUGIN_ERROR: "plugin.error";
|
|
887
|
-
readonly ERROR_OCCURRED: "error.occurred";
|
|
888
|
-
readonly WARNING_OCCURRED: "warning.occurred";
|
|
889
|
-
readonly MODULE_INITIALIZE_START: "module.initialize.start";
|
|
890
|
-
readonly MODULE_INITIALIZE_COMPLETE: "module.initialize.complete";
|
|
891
|
-
readonly MODULE_INITIALIZE_ERROR: "module.initialize.error";
|
|
892
|
-
readonly MODULE_EXECUTION_START: "module.execution.start";
|
|
893
|
-
readonly MODULE_EXECUTION_COMPLETE: "module.execution.complete";
|
|
894
|
-
readonly MODULE_EXECUTION_ERROR: "module.execution.error";
|
|
895
|
-
readonly MODULE_DISPOSE_START: "module.dispose.start";
|
|
896
|
-
readonly MODULE_DISPOSE_COMPLETE: "module.dispose.complete";
|
|
897
|
-
readonly MODULE_DISPOSE_ERROR: "module.dispose.error";
|
|
898
|
-
readonly MODULE_REGISTERED: "module.registered";
|
|
899
|
-
readonly MODULE_UNREGISTERED: "module.unregistered";
|
|
900
|
-
readonly EXECUTION_HIERARCHY: "execution.hierarchy";
|
|
901
|
-
readonly EXECUTION_REALTIME: "execution.realtime";
|
|
902
|
-
readonly TOOL_REALTIME: "tool.realtime";
|
|
903
|
-
readonly CUSTOM: "custom";
|
|
904
|
-
};
|
|
905
|
-
type TEventName = TExecutionEventName | TToolEventName | TAgentEventName | 'tool.beforeExecute' | 'tool.afterExecute' | 'tool.success' | 'conversation.start' | 'conversation.complete' | 'conversation.error' | 'agent.destroyed' | 'plugin.loaded' | 'plugin.unloaded' | 'plugin.error' | 'error.occurred' | 'warning.occurred' | 'module.initialize.start' | 'module.initialize.complete' | 'module.initialize.error' | 'module.execution.start' | 'module.execution.complete' | 'module.execution.error' | 'module.dispose.start' | 'module.dispose.complete' | 'module.dispose.error' | 'module.registered' | 'module.unregistered' | 'execution.hierarchy' | 'execution.realtime' | 'tool.realtime' | 'custom';
|
|
906
|
-
/**
|
|
907
|
-
* Valid event data value types
|
|
908
|
-
*/
|
|
909
|
-
type TEventDataValue = string | number | boolean | Date | null | undefined | TEventDataValue[] | {
|
|
910
|
-
[key: string]: TEventDataValue;
|
|
911
|
-
};
|
|
912
|
-
/**
|
|
913
|
-
* Event data structure
|
|
914
|
-
*/
|
|
915
|
-
interface IEventEmitterEventData {
|
|
916
|
-
type: TEventName;
|
|
917
|
-
timestamp: Date;
|
|
918
|
-
executionId?: string;
|
|
919
|
-
sessionId?: string;
|
|
920
|
-
userId?: string;
|
|
921
|
-
data?: Record<string, TEventDataValue>;
|
|
922
|
-
error?: Error;
|
|
923
|
-
metadata?: Record<string, TEventDataValue>;
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Event listener function
|
|
927
|
-
*/
|
|
928
|
-
type TEventEmitterListener = (event: IEventEmitterEventData) => void | Promise<void>;
|
|
929
|
-
/**
|
|
930
|
-
* Console-like interface for the EventEmitterPlugin.
|
|
931
|
-
*
|
|
932
|
-
* Use this interface for typing instead of the concrete EventEmitterPlugin class.
|
|
933
|
-
*/
|
|
934
|
-
interface IEventEmitterPlugin {
|
|
935
|
-
on(eventType: TEventName, listener: TEventEmitterListener, options?: {
|
|
936
|
-
once?: boolean;
|
|
937
|
-
filter?: (event: IEventEmitterEventData) => boolean;
|
|
938
|
-
}): string;
|
|
939
|
-
once(eventType: TEventName, listener: TEventEmitterListener, filter?: (event: IEventEmitterEventData) => boolean): string;
|
|
940
|
-
off(eventType: TEventName, handlerIdOrListener: string | TEventEmitterListener): boolean;
|
|
941
|
-
emit(eventType: TEventName, eventData?: Partial<IEventEmitterEventData>): Promise<void>;
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
/**
|
|
945
|
-
* Reusable type definitions for logger utility
|
|
946
|
-
*/
|
|
947
|
-
/**
|
|
948
|
-
* Log levels for the logger
|
|
949
|
-
*/
|
|
950
|
-
type TUtilLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
951
|
-
/**
|
|
952
|
-
* Log entry structure
|
|
953
|
-
*/
|
|
954
|
-
interface IUtilLogEntry {
|
|
955
|
-
timestamp: string;
|
|
956
|
-
level: TUtilLogLevel;
|
|
957
|
-
message: string;
|
|
958
|
-
context?: TLoggerData;
|
|
959
|
-
packageName?: string;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Logger interface
|
|
963
|
-
*/
|
|
964
|
-
interface ILogger {
|
|
965
|
-
debug(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
966
|
-
info(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
967
|
-
warn(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
968
|
-
error(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
969
|
-
log(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
970
|
-
group?(label?: string): void;
|
|
971
|
-
groupEnd?(): void;
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Silent logger that does nothing (Null Object Pattern)
|
|
975
|
-
*
|
|
976
|
-
* IMPORTANT:
|
|
977
|
-
* - This library must not write to stdio by default.
|
|
978
|
-
* - Inject a real logger explicitly if you want output.
|
|
979
|
-
*/
|
|
980
|
-
declare const SilentLogger: ILogger;
|
|
981
|
-
/**
|
|
982
|
-
* Console logger implementation
|
|
983
|
-
* @internal
|
|
984
|
-
*/
|
|
985
|
-
declare class ConsoleLogger implements ILogger {
|
|
986
|
-
private level?;
|
|
987
|
-
private packageName;
|
|
988
|
-
private sinkLogger;
|
|
989
|
-
constructor(packageName: string, logger?: ILogger);
|
|
990
|
-
debug(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
991
|
-
info(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
992
|
-
warn(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
993
|
-
error(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
994
|
-
log(...args: Array<TUniversalValue | TLoggerData | Error>): void;
|
|
995
|
-
private getLevel;
|
|
996
|
-
private shouldLog;
|
|
997
|
-
private forward;
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Create a named logger instance for a package or module.
|
|
1001
|
-
* Use this to create loggers with a specific name prefix for easy log filtering.
|
|
1002
|
-
*/
|
|
1003
|
-
declare function createLogger(packageName: string, logger?: ILogger): ILogger;
|
|
1004
|
-
/**
|
|
1005
|
-
* Set global log level for all loggers
|
|
1006
|
-
*/
|
|
1007
|
-
declare function setGlobalLogLevel(level: TUtilLogLevel): void;
|
|
1008
|
-
/**
|
|
1009
|
-
* Get global log level
|
|
1010
|
-
*/
|
|
1011
|
-
declare function getGlobalLogLevel(): TUtilLogLevel;
|
|
1012
|
-
/**
|
|
1013
|
-
* Default logger for the agents package
|
|
1014
|
-
*/
|
|
1015
|
-
declare const logger: ILogger;
|
|
1016
|
-
|
|
1017
|
-
/**
|
|
1018
|
-
* Type definitions for AbstractPlugin.
|
|
1019
|
-
*
|
|
1020
|
-
* Extracted from abstract-plugin.ts to keep each file under 300 lines.
|
|
1021
|
-
*/
|
|
1022
|
-
|
|
1023
|
-
/** Plugin categories for classification */
|
|
1024
|
-
declare enum PluginCategory {
|
|
1025
|
-
MONITORING = "monitoring",
|
|
1026
|
-
LOGGING = "logging",
|
|
1027
|
-
STORAGE = "storage",
|
|
1028
|
-
NOTIFICATION = "notification",
|
|
1029
|
-
SECURITY = "security",
|
|
1030
|
-
PERFORMANCE = "performance",
|
|
1031
|
-
ERROR_HANDLING = "error_handling",
|
|
1032
|
-
LIMITS = "limits",
|
|
1033
|
-
EVENT_PROCESSING = "event_processing",
|
|
1034
|
-
CUSTOM = "custom"
|
|
1035
|
-
}
|
|
1036
|
-
/** Plugin priority levels */
|
|
1037
|
-
declare enum PluginPriority {
|
|
1038
|
-
CRITICAL = 1000,
|
|
1039
|
-
HIGH = 800,
|
|
1040
|
-
NORMAL = 500,
|
|
1041
|
-
LOW = 200,
|
|
1042
|
-
MINIMAL = 100
|
|
1043
|
-
}
|
|
1044
|
-
/** Plugin execution context for all plugins */
|
|
1045
|
-
interface IPluginExecutionContext {
|
|
1046
|
-
executionId?: string;
|
|
1047
|
-
sessionId?: string;
|
|
1048
|
-
userId?: string;
|
|
1049
|
-
messages?: TUniversalMessage[];
|
|
1050
|
-
config?: Record<string, string | number | boolean>;
|
|
1051
|
-
metadata?: Record<string, string | number | boolean | Date>;
|
|
1052
|
-
[key: string]: string | number | boolean | Date | string[] | number[] | boolean[] | TUniversalMessage[] | Record<string, string | number | boolean> | Record<string, string | number | boolean | Date> | undefined;
|
|
1053
|
-
}
|
|
1054
|
-
/** Plugin execution result for all plugins */
|
|
1055
|
-
interface IPluginExecutionResult {
|
|
1056
|
-
response?: string;
|
|
1057
|
-
content?: string;
|
|
1058
|
-
duration?: number;
|
|
1059
|
-
tokensUsed?: number;
|
|
1060
|
-
toolsExecuted?: number;
|
|
1061
|
-
success?: boolean;
|
|
1062
|
-
usage?: {
|
|
1063
|
-
totalTokens?: number;
|
|
1064
|
-
promptTokens?: number;
|
|
1065
|
-
completionTokens?: number;
|
|
1066
|
-
};
|
|
1067
|
-
toolCalls?: Array<{
|
|
1068
|
-
id?: string;
|
|
1069
|
-
name?: string;
|
|
1070
|
-
arguments?: Record<string, string | number | boolean>;
|
|
1071
|
-
result?: string | number | boolean | null;
|
|
1072
|
-
}>;
|
|
1073
|
-
results?: Array<{
|
|
1074
|
-
id?: string;
|
|
1075
|
-
type?: string;
|
|
1076
|
-
data?: string | number | boolean | null;
|
|
1077
|
-
success?: boolean;
|
|
1078
|
-
}>;
|
|
1079
|
-
error?: Error;
|
|
1080
|
-
metadata?: Record<string, string | number | boolean | Date>;
|
|
1081
|
-
}
|
|
1082
|
-
/** Error context for plugin error handling */
|
|
1083
|
-
interface IPluginErrorContext {
|
|
1084
|
-
action: string;
|
|
1085
|
-
tool?: string;
|
|
1086
|
-
parameters?: TToolParameters;
|
|
1087
|
-
result?: IToolExecutionResult;
|
|
1088
|
-
error?: Error;
|
|
1089
|
-
executionId?: string;
|
|
1090
|
-
sessionId?: string;
|
|
1091
|
-
userId?: string;
|
|
1092
|
-
timestamp?: Date;
|
|
1093
|
-
attempt?: number;
|
|
1094
|
-
stack?: string;
|
|
1095
|
-
metadata?: Record<string, string | number | boolean>;
|
|
1096
|
-
}
|
|
1097
|
-
/** Plugin configuration interface */
|
|
1098
|
-
interface IPluginConfig extends IPluginOptions {
|
|
1099
|
-
options?: Record<string, string | number | boolean>;
|
|
1100
|
-
}
|
|
1101
|
-
/** Plugin options that all plugin options should extend */
|
|
1102
|
-
interface IPluginOptions {
|
|
1103
|
-
enabled?: boolean;
|
|
1104
|
-
category?: PluginCategory;
|
|
1105
|
-
priority?: PluginPriority | number;
|
|
1106
|
-
moduleEvents?: TEventName[];
|
|
1107
|
-
subscribeToAllModuleEvents?: boolean;
|
|
1108
|
-
}
|
|
1109
|
-
/** Plugin data interface */
|
|
1110
|
-
interface IPluginData {
|
|
1111
|
-
name: string;
|
|
1112
|
-
version: string;
|
|
1113
|
-
enabled: boolean;
|
|
1114
|
-
category: PluginCategory;
|
|
1115
|
-
priority: number;
|
|
1116
|
-
subscribedEvents: TEventName[];
|
|
1117
|
-
metadata?: Record<string, string | number | boolean>;
|
|
1118
|
-
}
|
|
1119
|
-
/** Type-safe plugin interface with specific type parameters */
|
|
1120
|
-
interface IPluginContract<TOptions extends IPluginOptions = IPluginOptions, TStats = IPluginStats> {
|
|
1121
|
-
name: string;
|
|
1122
|
-
version: string;
|
|
1123
|
-
enabled: boolean;
|
|
1124
|
-
category: PluginCategory;
|
|
1125
|
-
priority: number;
|
|
1126
|
-
initialize(options?: TOptions): Promise<void>;
|
|
1127
|
-
cleanup?(): Promise<void>;
|
|
1128
|
-
getData?(): IPluginData;
|
|
1129
|
-
getStats?(): TStats;
|
|
1130
|
-
subscribeToModuleEvents?(eventEmitter: IEventEmitterPlugin): Promise<void>;
|
|
1131
|
-
unsubscribeFromModuleEvents?(eventEmitter: IEventEmitterPlugin): Promise<void>;
|
|
1132
|
-
onModuleEvent?(eventName: TEventName, eventData: IEventEmitterEventData): Promise<void> | void;
|
|
1133
|
-
}
|
|
1134
|
-
/** Plugin statistics base interface with common metrics */
|
|
1135
|
-
interface IPluginStats {
|
|
1136
|
-
enabled: boolean;
|
|
1137
|
-
calls: number;
|
|
1138
|
-
errors: number;
|
|
1139
|
-
lastActivity?: Date;
|
|
1140
|
-
moduleEventsReceived?: number;
|
|
1141
|
-
[key: string]: string | number | boolean | Date | string[] | number[] | boolean[] | Record<string, string | number | boolean | Date> | undefined;
|
|
1142
|
-
}
|
|
1143
|
-
/** Plugin interface extending IPluginContract */
|
|
1144
|
-
interface IPlugin extends IPluginContract<IPluginConfig, IPluginStats> {
|
|
1145
|
-
}
|
|
1146
|
-
/** Plugin lifecycle hooks */
|
|
1147
|
-
interface IPluginHooks {
|
|
1148
|
-
beforeRun?(input: string, options?: IRunOptions): Promise<void> | void;
|
|
1149
|
-
afterRun?(input: string, response: string, options?: IRunOptions): Promise<void> | void;
|
|
1150
|
-
beforeExecution?(context: IPluginExecutionContext): Promise<void> | void;
|
|
1151
|
-
afterExecution?(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void> | void;
|
|
1152
|
-
beforeConversation?(context: IPluginExecutionContext): Promise<void> | void;
|
|
1153
|
-
afterConversation?(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void> | void;
|
|
1154
|
-
beforeToolCall?(toolName: string, parameters: TToolParameters): Promise<void> | void;
|
|
1155
|
-
beforeToolExecution?(context: IPluginExecutionContext, toolData: IToolExecutionContext): Promise<void> | void;
|
|
1156
|
-
afterToolCall?(toolName: string, parameters: TToolParameters, result: IToolExecutionResult): Promise<void> | void;
|
|
1157
|
-
afterToolExecution?(context: IPluginExecutionContext, toolResults: IPluginExecutionResult): Promise<void> | void;
|
|
1158
|
-
beforeProviderCall?(messages: TUniversalMessage[]): Promise<void> | void;
|
|
1159
|
-
afterProviderCall?(messages: TUniversalMessage[], response: TUniversalMessage): Promise<void> | void;
|
|
1160
|
-
onStreamingChunk?(chunk: TUniversalMessage): Promise<void> | void;
|
|
1161
|
-
onError?(error: Error, context?: IPluginErrorContext): Promise<void> | void;
|
|
1162
|
-
onMessageAdded?(message: TUniversalMessage): Promise<void> | void;
|
|
1163
|
-
onModuleEvent?(eventName: TEventName, eventData: IEventEmitterEventData): Promise<void> | void;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* Abstract class for all plugins with type parameter support.
|
|
1168
|
-
*
|
|
1169
|
-
* Type definitions live in ./abstract-plugin-types.ts.
|
|
1170
|
-
*/
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* Abstract class for all plugins with type parameter support.
|
|
1174
|
-
* Provides plugin lifecycle management and common functionality.
|
|
1175
|
-
* @template TOptions - Plugin options type that extends IPluginOptions
|
|
1176
|
-
* @template TStats - Plugin statistics type
|
|
1177
|
-
*/
|
|
1178
|
-
declare abstract class AbstractPlugin<TOptions extends IPluginOptions = IPluginOptions, TStats extends IPluginStats = IPluginStats> implements IPluginContract<TOptions, TStats>, IPluginHooks {
|
|
1179
|
-
abstract readonly name: string;
|
|
1180
|
-
abstract readonly version: string;
|
|
1181
|
-
enabled: boolean;
|
|
1182
|
-
category: PluginCategory;
|
|
1183
|
-
priority: number;
|
|
1184
|
-
protected options: TOptions | undefined;
|
|
1185
|
-
protected eventEmitter: IEventEmitterPlugin | undefined;
|
|
1186
|
-
protected subscribedEvents: TEventName[];
|
|
1187
|
-
protected eventHandlers: Map<TEventName, string[]>;
|
|
1188
|
-
protected readonly pluginLogger: ILogger;
|
|
1189
|
-
protected stats: {
|
|
1190
|
-
calls: number;
|
|
1191
|
-
errors: number;
|
|
1192
|
-
moduleEventsReceived: number;
|
|
1193
|
-
lastActivity: Date | undefined;
|
|
1194
|
-
};
|
|
1195
|
-
initialize(options?: TOptions): Promise<void>;
|
|
1196
|
-
subscribeToModuleEvents(eventEmitter: IEventEmitterPlugin): Promise<void>;
|
|
1197
|
-
unsubscribeFromModuleEvents(eventEmitter: IEventEmitterPlugin): Promise<void>;
|
|
1198
|
-
dispose(): Promise<void>;
|
|
1199
|
-
enable(): void;
|
|
1200
|
-
disable(): void;
|
|
1201
|
-
isEnabled(): boolean;
|
|
1202
|
-
getConfig(): IPluginConfig;
|
|
1203
|
-
updateConfig(_config: IPluginConfig): void;
|
|
1204
|
-
getData(): IPluginData;
|
|
1205
|
-
clearData?(): void;
|
|
1206
|
-
getStatus(): {
|
|
1207
|
-
name: string;
|
|
1208
|
-
version: string;
|
|
1209
|
-
enabled: boolean;
|
|
1210
|
-
initialized: boolean;
|
|
1211
|
-
category: PluginCategory;
|
|
1212
|
-
priority: number;
|
|
1213
|
-
subscribedEventsCount: number;
|
|
1214
|
-
hasEventEmitter: boolean;
|
|
1215
|
-
};
|
|
1216
|
-
getStats(): TStats;
|
|
1217
|
-
protected updateCallStats(): void;
|
|
1218
|
-
protected updateErrorStats(): void;
|
|
1219
|
-
beforeRun?(input: string, options?: IRunOptions): Promise<void>;
|
|
1220
|
-
afterRun?(input: string, response: string, options?: IRunOptions): Promise<void>;
|
|
1221
|
-
beforeExecution?(context: IPluginExecutionContext): Promise<void>;
|
|
1222
|
-
afterExecution?(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void>;
|
|
1223
|
-
beforeConversation?(context: IPluginExecutionContext): Promise<void>;
|
|
1224
|
-
afterConversation?(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void>;
|
|
1225
|
-
beforeToolCall?(toolName: string, parameters: TToolParameters): Promise<void>;
|
|
1226
|
-
beforeToolExecution?(context: IPluginExecutionContext, toolData: IToolExecutionContext): Promise<void>;
|
|
1227
|
-
afterToolCall?(toolName: string, parameters: TToolParameters, result: IToolExecutionResult): Promise<void>;
|
|
1228
|
-
afterToolExecution?(context: IPluginExecutionContext, toolResults: IPluginExecutionResult): Promise<void>;
|
|
1229
|
-
beforeProviderCall?(messages: TUniversalMessage[]): Promise<void>;
|
|
1230
|
-
afterProviderCall?(messages: TUniversalMessage[], response: TUniversalMessage): Promise<void>;
|
|
1231
|
-
onStreamingChunk?(chunk: TUniversalMessage): Promise<void>;
|
|
1232
|
-
onError?(error: Error, context?: IPluginErrorContext): Promise<void>;
|
|
1233
|
-
onMessageAdded?(message: TUniversalMessage): Promise<void>;
|
|
1234
|
-
onModuleEvent?(eventName: TEventName, eventData: IEventEmitterEventData): Promise<void>;
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* Type definitions, interfaces, and enums for the module system.
|
|
1239
|
-
*
|
|
1240
|
-
* Extracted from abstract-module.ts to keep each file under 300 lines.
|
|
1241
|
-
*/
|
|
1242
|
-
|
|
1243
|
-
/** Module execution context */
|
|
1244
|
-
interface IModuleExecutionContext {
|
|
1245
|
-
executionId?: string;
|
|
1246
|
-
sessionId?: string;
|
|
1247
|
-
userId?: string;
|
|
1248
|
-
agentName?: string;
|
|
1249
|
-
metadata?: Record<string, string | number | boolean | Date>;
|
|
1250
|
-
[key: string]: string | number | boolean | Date | Record<string, string | number | boolean | Date> | undefined;
|
|
1251
|
-
}
|
|
1252
|
-
/** Module execution result */
|
|
1253
|
-
interface IModuleExecutionResult {
|
|
1254
|
-
success: boolean;
|
|
1255
|
-
data?: IModuleResultData;
|
|
1256
|
-
error?: Error;
|
|
1257
|
-
duration?: number;
|
|
1258
|
-
metadata?: Record<string, string | number | boolean | Date>;
|
|
1259
|
-
}
|
|
1260
|
-
/** Module result data */
|
|
1261
|
-
interface IModuleResultData {
|
|
1262
|
-
[key: string]: string | number | boolean | Record<string, string | number | boolean> | undefined;
|
|
1263
|
-
}
|
|
1264
|
-
/** Base module options */
|
|
1265
|
-
interface IBaseModuleOptions {
|
|
1266
|
-
enabled?: boolean;
|
|
1267
|
-
config?: Record<string, string | number | boolean>;
|
|
1268
|
-
}
|
|
1269
|
-
/** Module capabilities */
|
|
1270
|
-
interface IModuleCapabilities {
|
|
1271
|
-
capabilities: string[];
|
|
1272
|
-
dependencies?: string[];
|
|
1273
|
-
optionalDependencies?: string[];
|
|
1274
|
-
}
|
|
1275
|
-
/** Module type descriptor */
|
|
1276
|
-
interface IModuleDescriptor {
|
|
1277
|
-
type: string;
|
|
1278
|
-
category: ModuleCategory;
|
|
1279
|
-
layer: ModuleLayer;
|
|
1280
|
-
dependencies?: string[];
|
|
1281
|
-
capabilities?: string[];
|
|
1282
|
-
}
|
|
1283
|
-
/** Module categories */
|
|
1284
|
-
declare enum ModuleCategory {
|
|
1285
|
-
CORE = "core",
|
|
1286
|
-
STORAGE = "storage",
|
|
1287
|
-
PROCESSING = "processing",
|
|
1288
|
-
INTEGRATION = "integration",
|
|
1289
|
-
INTERFACE = "interface",
|
|
1290
|
-
CAPABILITY = "capability"
|
|
1291
|
-
}
|
|
1292
|
-
/** Module layers */
|
|
1293
|
-
declare enum ModuleLayer {
|
|
1294
|
-
INFRASTRUCTURE = "infrastructure",
|
|
1295
|
-
CORE = "core",
|
|
1296
|
-
APPLICATION = "application",
|
|
1297
|
-
DOMAIN = "domain",
|
|
1298
|
-
PRESENTATION = "presentation"
|
|
1299
|
-
}
|
|
1300
|
-
/** Module data for introspection */
|
|
1301
|
-
interface IModuleData {
|
|
1302
|
-
name: string;
|
|
1303
|
-
version: string;
|
|
1304
|
-
type: string;
|
|
1305
|
-
enabled: boolean;
|
|
1306
|
-
initialized: boolean;
|
|
1307
|
-
capabilities: IModuleCapabilities;
|
|
1308
|
-
metadata?: Record<string, string | number | boolean>;
|
|
1309
|
-
}
|
|
1310
|
-
/** Module statistics */
|
|
1311
|
-
interface IModuleStats {
|
|
1312
|
-
enabled: boolean;
|
|
1313
|
-
initialized: boolean;
|
|
1314
|
-
executionCount: number;
|
|
1315
|
-
errorCount: number;
|
|
1316
|
-
lastActivity?: Date;
|
|
1317
|
-
averageExecutionTime?: number;
|
|
1318
|
-
[key: string]: string | number | boolean | Date | undefined;
|
|
1319
|
-
}
|
|
1320
|
-
/** Type-safe module interface */
|
|
1321
|
-
interface IModule<TOptions extends IBaseModuleOptions = IBaseModuleOptions, TStats = IModuleStats> {
|
|
1322
|
-
name: string;
|
|
1323
|
-
version: string;
|
|
1324
|
-
enabled: boolean;
|
|
1325
|
-
initialize(options?: TOptions, eventEmitter?: IEventEmitterPlugin): Promise<void>;
|
|
1326
|
-
dispose?(): Promise<void>;
|
|
1327
|
-
execute?(context: IModuleExecutionContext): Promise<IModuleExecutionResult>;
|
|
1328
|
-
getModuleType(): IModuleDescriptor;
|
|
1329
|
-
getCapabilities(): IModuleCapabilities;
|
|
1330
|
-
getData?(): IModuleData;
|
|
1331
|
-
getStats?(): TStats;
|
|
1332
|
-
isEnabled(): boolean;
|
|
1333
|
-
isInitialized(): boolean;
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
/**
|
|
1337
|
-
* @fileoverview Abstract Tool Base Class
|
|
1338
|
-
*
|
|
1339
|
-
* 🎯 ABSTRACT CLASS - DO NOT DEPEND ON CONCRETE IMPLEMENTATIONS
|
|
1340
|
-
*
|
|
1341
|
-
* This is a pure abstract base class that defines the interface and common behavior
|
|
1342
|
-
* for all tools. It follows strict architectural principles:
|
|
1343
|
-
*
|
|
1344
|
-
* - Depends ONLY on interfaces (EventService interface, not concrete implementations)
|
|
1345
|
-
* - Does NOT import concrete classes
|
|
1346
|
-
* - Uses Dependency Injection for all dependencies
|
|
1347
|
-
* - Handles undefined dependencies gracefully (Null Object Pattern)
|
|
1348
|
-
*
|
|
1349
|
-
* Concrete implementations should be handled
|
|
1350
|
-
* by the caller who creates the tool instance, not by this abstract class.
|
|
1351
|
-
*
|
|
1352
|
-
* @example
|
|
1353
|
-
* ```typescript
|
|
1354
|
-
* // ✅ CORRECT: Caller prepares an owner-bound EventService and injects it
|
|
1355
|
-
* // (Example: bind to the current tool call identity and ownerPath.)
|
|
1356
|
-
* const toolEventService = bindWithOwnerPath(baseEventService, {
|
|
1357
|
-
* ownerType: 'tool',
|
|
1358
|
-
* ownerId: toolCallId,
|
|
1359
|
-
* ownerPath,
|
|
1360
|
-
* });
|
|
1361
|
-
* const tool = new MyTool({ eventService: toolEventService });
|
|
1362
|
-
*
|
|
1363
|
-
* // ❌ WRONG: AbstractTool creates concrete EventService
|
|
1364
|
-
* // This violates Dependency Inversion Principle
|
|
1365
|
-
* ```
|
|
1366
|
-
*/
|
|
1367
|
-
|
|
1368
|
-
/**
|
|
1369
|
-
* Options for AbstractTool construction
|
|
1370
|
-
*/
|
|
1371
|
-
interface IAbstractToolOptions {
|
|
1372
|
-
/**
|
|
1373
|
-
* Optional logger for tool operations
|
|
1374
|
-
* Defaults to SilentLogger if not provided
|
|
1375
|
-
*/
|
|
1376
|
-
logger?: ILogger;
|
|
1377
|
-
/**
|
|
1378
|
-
* Optional event service for unified event emission
|
|
1379
|
-
* If not provided, tool will operate silently without emitting events
|
|
1380
|
-
*
|
|
1381
|
-
* The caller should provide an EventService configured with appropriate settings
|
|
1382
|
-
* (e.g., ownerPrefix='tool' for tool events)
|
|
1383
|
-
*
|
|
1384
|
-
* @since 2.1.0
|
|
1385
|
-
*/
|
|
1386
|
-
eventService?: IEventService;
|
|
1387
|
-
}
|
|
1388
|
-
/**
|
|
1389
|
-
* Tool execution function type with proper parameter constraints
|
|
1390
|
-
*/
|
|
1391
|
-
type TToolExecutionFunction<TParams = TToolParameters, TResult = IToolResult> = (parameters: TParams) => Promise<TResult> | TResult;
|
|
1392
|
-
/**
|
|
1393
|
-
* Abstract tool interface with type parameters for enhanced type safety
|
|
1394
|
-
*
|
|
1395
|
-
* @template TParams - Tool parameters type (defaults to AbstractToolParameters for backward compatibility)
|
|
1396
|
-
* @template TResult - Tool result type (defaults to ToolResult for backward compatibility)
|
|
1397
|
-
*/
|
|
1398
|
-
interface IAbstractTool<TParams = TToolParameters, TResult = IToolResult> {
|
|
1399
|
-
name: string;
|
|
1400
|
-
description: string;
|
|
1401
|
-
parameters: IToolSchema['parameters'];
|
|
1402
|
-
execute: TToolExecutionFunction<TParams, TResult>;
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Type-safe tool interface with type parameters
|
|
1406
|
-
*
|
|
1407
|
-
* @template TParameters - Tool parameters type (defaults to AbstractToolParameters for backward compatibility)
|
|
1408
|
-
* @template TResult - Tool result type (defaults to ToolResult for backward compatibility)
|
|
1409
|
-
*/
|
|
1410
|
-
interface IToolContract<TParameters = TToolParameters, TResult = IToolResult> {
|
|
1411
|
-
readonly schema: IToolSchema;
|
|
1412
|
-
execute(parameters: TParameters, context: IToolExecutionContext): Promise<TResult>;
|
|
1413
|
-
validate(parameters: TParameters): boolean;
|
|
1414
|
-
validateParameters(parameters: TParameters): IParameterValidationResult;
|
|
1415
|
-
getDescription(): string;
|
|
1416
|
-
getName(): string;
|
|
1417
|
-
}
|
|
1418
|
-
/**
|
|
1419
|
-
* Runtime tool instance contract used by Robota internals.
|
|
1420
|
-
*
|
|
1421
|
-
* Tools passed into Agent configuration must support EventService injection
|
|
1422
|
-
* so Robota can emit unified tool lifecycle events.
|
|
1423
|
-
*/
|
|
1424
|
-
interface IToolWithEventService<TParameters = TToolParameters, TResult = IToolResult> extends IToolContract<TParameters, TResult> {
|
|
1425
|
-
setEventService(eventService: IEventService | undefined): void;
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Abstract base class for tools with type parameter support
|
|
1429
|
-
* Provides type-safe parameter handling and result processing
|
|
1430
|
-
*
|
|
1431
|
-
* 🎯 ARCHITECTURAL PRINCIPLES:
|
|
1432
|
-
* - Pure abstract class - depends only on interfaces
|
|
1433
|
-
* - No concrete class dependencies (EventService interface only)
|
|
1434
|
-
* - Dependency Injection for all external dependencies
|
|
1435
|
-
* - Graceful degradation (undefined dependencies = silent operation)
|
|
1436
|
-
*
|
|
1437
|
-
* @template TParameters - Tool parameters type (defaults to TToolParameters)
|
|
1438
|
-
* @template TResult - Tool result type (defaults to ToolResult for backward compatibility)
|
|
1439
|
-
*/
|
|
1440
|
-
declare abstract class AbstractTool<TParameters = TToolParameters, TResult = IToolResult> implements IToolWithEventService<TParameters, TResult> {
|
|
1441
|
-
abstract readonly schema: IToolSchema;
|
|
1442
|
-
/**
|
|
1443
|
-
* Logger for tool operations
|
|
1444
|
-
*/
|
|
1445
|
-
protected readonly logger: ILogger;
|
|
1446
|
-
/**
|
|
1447
|
-
* EventService for direct event emission (optional)
|
|
1448
|
-
* If undefined, tool operates silently without emitting events
|
|
1449
|
-
*/
|
|
1450
|
-
private eventService;
|
|
1451
|
-
/**
|
|
1452
|
-
* Constructor with simplified options
|
|
1453
|
-
*
|
|
1454
|
-
* 🎯 DEPENDENCY INJECTION:
|
|
1455
|
-
* All dependencies are injected via options parameter
|
|
1456
|
-
* No concrete classes are instantiated within this constructor
|
|
1457
|
-
*
|
|
1458
|
-
* @param options - Configuration options for the tool
|
|
1459
|
-
*/
|
|
1460
|
-
constructor(options?: IAbstractToolOptions);
|
|
1461
|
-
/**
|
|
1462
|
-
* Set EventService for post-construction injection
|
|
1463
|
-
*
|
|
1464
|
-
* 🎯 DEPENDENCY INJECTION:
|
|
1465
|
-
* Accepts EventService as-is without transformation
|
|
1466
|
-
* Caller is responsible for providing properly configured EventService
|
|
1467
|
-
*
|
|
1468
|
-
* @param eventService - EventService instance to use for event emission (or undefined for silent operation)
|
|
1469
|
-
*/
|
|
1470
|
-
setEventService(eventService: IEventService | undefined): void;
|
|
1471
|
-
/**
|
|
1472
|
-
* Get current EventService (for testing/inspection)
|
|
1473
|
-
*/
|
|
1474
|
-
protected getEventService(): IEventService | undefined;
|
|
1475
|
-
/**
|
|
1476
|
-
* Emit event through EventService (if available)
|
|
1477
|
-
* If EventService is not available, silently ignores the event (Null Object Pattern)
|
|
1478
|
-
*
|
|
1479
|
-
* @param eventType - Type of event to emit
|
|
1480
|
-
* @param data - Event data
|
|
1481
|
-
*/
|
|
1482
|
-
protected emitEvent(eventType: string, data: IBaseEventData): void;
|
|
1483
|
-
/**
|
|
1484
|
-
* Execute tool with simplified lifecycle
|
|
1485
|
-
* @param parameters - Tool parameters
|
|
1486
|
-
* @param context - Optional execution context
|
|
1487
|
-
* @returns Promise resolving to tool result
|
|
1488
|
-
*/
|
|
1489
|
-
execute(parameters: TParameters, context: IToolExecutionContext): Promise<TResult>;
|
|
1490
|
-
/**
|
|
1491
|
-
* Concrete implementation of tool execution
|
|
1492
|
-
* This method should be implemented by subclasses to provide actual tool logic
|
|
1493
|
-
*
|
|
1494
|
-
* @param parameters - Tool parameters
|
|
1495
|
-
* @param context - Optional execution context
|
|
1496
|
-
* @returns Promise resolving to tool result
|
|
1497
|
-
*/
|
|
1498
|
-
protected abstract executeImpl(parameters: TParameters, context: IToolExecutionContext): Promise<TResult>;
|
|
1499
|
-
validate(parameters: TParameters): boolean;
|
|
1500
|
-
/**
|
|
1501
|
-
* Validate tool parameters with detailed result (default implementation)
|
|
1502
|
-
*/
|
|
1503
|
-
validateParameters(parameters: TParameters): IParameterValidationResult;
|
|
1504
|
-
getDescription(): string;
|
|
1505
|
-
getName(): string;
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
/**
|
|
1509
|
-
* Cache key identifying a unique LLM execution request
|
|
1510
|
-
*/
|
|
1511
|
-
interface ICacheKey {
|
|
1512
|
-
/** SHA-256 hash of the serialized request */
|
|
1513
|
-
hash: string;
|
|
1514
|
-
/** Model identifier */
|
|
1515
|
-
model: string;
|
|
1516
|
-
/** Provider name */
|
|
1517
|
-
provider: string;
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Cached LLM response entry
|
|
1521
|
-
*/
|
|
1522
|
-
interface ICacheEntry {
|
|
1523
|
-
/** Cache key that produced this entry */
|
|
1524
|
-
key: ICacheKey;
|
|
1525
|
-
/** Cached response content */
|
|
1526
|
-
response: string;
|
|
1527
|
-
/** When the entry was cached */
|
|
1528
|
-
timestamp: number;
|
|
1529
|
-
/** SHA-256 integrity hash of the response */
|
|
1530
|
-
integrityHash: string;
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Cache storage interface for pluggable backends
|
|
1534
|
-
*/
|
|
1535
|
-
interface ICacheStorage {
|
|
1536
|
-
/** Retrieve a cached entry by key hash */
|
|
1537
|
-
get(hash: string): ICacheEntry | undefined;
|
|
1538
|
-
/** Store a cache entry */
|
|
1539
|
-
set(entry: ICacheEntry): void;
|
|
1540
|
-
/** Delete a cached entry by key hash */
|
|
1541
|
-
delete(hash: string): boolean;
|
|
1542
|
-
/** Clear all cached entries */
|
|
1543
|
-
clear(): void;
|
|
1544
|
-
/** Get cache statistics */
|
|
1545
|
-
getStats(): ICacheStats;
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Cache performance statistics
|
|
1549
|
-
*/
|
|
1550
|
-
interface ICacheStats {
|
|
1551
|
-
/** Number of cache hits */
|
|
1552
|
-
hits: number;
|
|
1553
|
-
/** Number of cache misses */
|
|
1554
|
-
misses: number;
|
|
1555
|
-
/** Current number of cached entries */
|
|
1556
|
-
entries: number;
|
|
1557
|
-
/** Hit rate (hits / (hits + misses)), 0 if no lookups */
|
|
1558
|
-
hitRate: number;
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Configuration options for execution caching
|
|
1562
|
-
*/
|
|
1563
|
-
interface ICacheOptions {
|
|
1564
|
-
/** Whether caching is enabled */
|
|
1565
|
-
enabled: boolean;
|
|
1566
|
-
/** Maximum number of cached entries */
|
|
1567
|
-
maxEntries: number;
|
|
1568
|
-
/** Time-to-live in milliseconds */
|
|
1569
|
-
ttlMs: number;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
/**
|
|
1573
|
-
* IExecutionContextInjection
|
|
1574
|
-
*
|
|
1575
|
-
* Minimal context payload used to inject an existing ownerPath into a new agent instance
|
|
1576
|
-
* (e.g., when a tool creates an agent and must preserve absolute ownerPath semantics).
|
|
1577
|
-
*
|
|
1578
|
-
* NOTE: This is intentionally NOT ToolExecutionContext. ToolExecutionContext is for tool calls
|
|
1579
|
-
* and requires toolName/parameters; agent creation only needs ownerPath and execution linkage.
|
|
1580
|
-
*/
|
|
1581
|
-
interface IExecutionContextInjection {
|
|
1582
|
-
ownerPath?: IOwnerPathSegment[];
|
|
1583
|
-
parentExecutionId?: string;
|
|
1584
|
-
rootExecutionId?: string;
|
|
1585
|
-
executionLevel?: number;
|
|
1586
|
-
sourceId?: string;
|
|
1587
|
-
}
|
|
1588
|
-
/**
|
|
1589
|
-
* Provider-specific configuration
|
|
1590
|
-
*/
|
|
1591
|
-
interface IAgentProviderConfig {
|
|
1592
|
-
openai?: {
|
|
1593
|
-
apiKey?: string;
|
|
1594
|
-
baseURL?: string;
|
|
1595
|
-
organization?: string;
|
|
1596
|
-
[key: string]: TProviderConfigValue | undefined;
|
|
1597
|
-
};
|
|
1598
|
-
anthropic?: {
|
|
1599
|
-
apiKey?: string;
|
|
1600
|
-
baseURL?: string;
|
|
1601
|
-
[key: string]: TProviderConfigValue | undefined;
|
|
1602
|
-
};
|
|
1603
|
-
google?: {
|
|
1604
|
-
apiKey?: string;
|
|
1605
|
-
projectId?: string;
|
|
1606
|
-
location?: string;
|
|
1607
|
-
[key: string]: TProviderConfigValue | undefined;
|
|
1608
|
-
};
|
|
1609
|
-
[provider: string]: Record<string, TProviderConfigValue | undefined> | undefined;
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Agent configuration options - New design with aiProviders array and defaultModel
|
|
1613
|
-
*/
|
|
1614
|
-
interface IAgentConfig {
|
|
1615
|
-
id?: string;
|
|
1616
|
-
name: string;
|
|
1617
|
-
aiProviders: IAIProvider[];
|
|
1618
|
-
defaultModel: {
|
|
1619
|
-
provider: string;
|
|
1620
|
-
model: string;
|
|
1621
|
-
temperature?: number;
|
|
1622
|
-
maxTokens?: number;
|
|
1623
|
-
topP?: number;
|
|
1624
|
-
systemMessage?: string;
|
|
1625
|
-
};
|
|
1626
|
-
tools?: Array<IToolWithEventService>;
|
|
1627
|
-
plugins?: Array<IPluginContract<IPluginOptions, IPluginStats>>;
|
|
1628
|
-
modules?: IModule[];
|
|
1629
|
-
systemMessage?: string;
|
|
1630
|
-
systemPrompt?: string;
|
|
1631
|
-
conversationId?: string;
|
|
1632
|
-
sessionId?: string;
|
|
1633
|
-
userId?: string;
|
|
1634
|
-
metadata?: TUniversalMessageMetadata;
|
|
1635
|
-
context?: Record<string, TConfigValue>;
|
|
1636
|
-
logging?: {
|
|
1637
|
-
level?: TUtilLogLevel;
|
|
1638
|
-
enabled?: boolean;
|
|
1639
|
-
format?: string;
|
|
1640
|
-
destination?: string;
|
|
1641
|
-
};
|
|
1642
|
-
providerConfig?: IAgentProviderConfig;
|
|
1643
|
-
stream?: boolean;
|
|
1644
|
-
toolChoice?: 'auto' | 'none' | string;
|
|
1645
|
-
responseFormat?: IResponseFormatConfig;
|
|
1646
|
-
safetySettings?: ISafetySetting[];
|
|
1647
|
-
timeout?: number;
|
|
1648
|
-
maxExecutionRounds?: number;
|
|
1649
|
-
retryAttempts?: number;
|
|
1650
|
-
rateLimiting?: {
|
|
1651
|
-
enabled?: boolean;
|
|
1652
|
-
maxRequests?: number;
|
|
1653
|
-
windowMs?: number;
|
|
1654
|
-
};
|
|
1655
|
-
eventService?: IEventService;
|
|
1656
|
-
executionContext?: IExecutionContextInjection;
|
|
1657
|
-
cache?: ICacheOptions;
|
|
1658
|
-
}
|
|
1659
|
-
/**
|
|
1660
|
-
* Agent template interface
|
|
1661
|
-
*/
|
|
1662
|
-
interface IAgentTemplate {
|
|
1663
|
-
id: string;
|
|
1664
|
-
name: string;
|
|
1665
|
-
description?: string;
|
|
1666
|
-
category?: string;
|
|
1667
|
-
tags?: string[];
|
|
1668
|
-
config: IAgentConfig;
|
|
1669
|
-
version?: string;
|
|
1670
|
-
author?: string;
|
|
1671
|
-
createdAt?: Date;
|
|
1672
|
-
updatedAt?: Date;
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Agent run options - type-safe interface for all agent execution options
|
|
1676
|
-
*/
|
|
1677
|
-
interface IRunOptions {
|
|
1678
|
-
temperature?: number;
|
|
1679
|
-
maxTokens?: number;
|
|
1680
|
-
stream?: boolean;
|
|
1681
|
-
toolChoice?: 'auto' | 'none' | string;
|
|
1682
|
-
sessionId?: string;
|
|
1683
|
-
userId?: string;
|
|
1684
|
-
metadata?: TMetadata;
|
|
1685
|
-
/** AbortSignal for cancelling execution */
|
|
1686
|
-
signal?: AbortSignal;
|
|
1687
|
-
/** Per-run streaming text callback. Prefer this over mutating provider callback state. */
|
|
1688
|
-
onTextDelta?: TTextDeltaCallback;
|
|
1689
|
-
/** Per-run replay event callback for provider/tool execution boundaries. */
|
|
1690
|
-
onExecutionEvent?: TExecutionEventCallback;
|
|
1691
|
-
/**
|
|
1692
|
-
* Maximum model/tool rounds for this run.
|
|
1693
|
-
* Use 0 for no core round cap.
|
|
1694
|
-
*/
|
|
1695
|
-
maxExecutionRounds?: number;
|
|
1696
|
-
}
|
|
1697
|
-
type TExecutionEventData = Record<string, unknown>;
|
|
1698
|
-
type TExecutionEventCallback = (event: string, data: TExecutionEventData) => void;
|
|
1699
|
-
/**
|
|
1700
|
-
* Generic agent interface with type parameters for enhanced type safety
|
|
1701
|
-
*
|
|
1702
|
-
* @template TConfig - Agent configuration type (defaults to IAgentConfig for backward compatibility)
|
|
1703
|
-
* @template TContext - Execution context type (defaults to IRunOptions for backward compatibility)
|
|
1704
|
-
* @template TUniversalMessage - Message type (defaults to TUniversalMessage for backward compatibility)
|
|
1705
|
-
*/
|
|
1706
|
-
interface IAgent<TConfig = IAgentConfig, TContext = IRunOptions, TMessage = TUniversalMessage> {
|
|
1707
|
-
/**
|
|
1708
|
-
* Configure the agent with type-safe configuration
|
|
1709
|
-
*/
|
|
1710
|
-
configure?(config: TConfig): Promise<void>;
|
|
1711
|
-
/**
|
|
1712
|
-
* Run agent with user input and type-safe context
|
|
1713
|
-
*/
|
|
1714
|
-
run(input: string, context?: TContext): Promise<string>;
|
|
1715
|
-
/**
|
|
1716
|
-
* Run agent with streaming response and type-safe context
|
|
1717
|
-
*/
|
|
1718
|
-
runStream(input: string, context?: TContext): AsyncGenerator<string, void, never>;
|
|
1719
|
-
/**
|
|
1720
|
-
* Get conversation history with type-safe messages
|
|
1721
|
-
*/
|
|
1722
|
-
getHistory(): TMessage[];
|
|
1723
|
-
/**
|
|
1724
|
-
* Clear conversation history
|
|
1725
|
-
*/
|
|
1726
|
-
clearHistory(): void;
|
|
1727
|
-
}
|
|
1728
|
-
/**
|
|
1729
|
-
* Response format configuration
|
|
1730
|
-
*/
|
|
1731
|
-
interface IResponseFormatConfig {
|
|
1732
|
-
type?: 'text' | 'json_object';
|
|
1733
|
-
schema?: Record<string, TConfigValue>;
|
|
1734
|
-
}
|
|
1735
|
-
/**
|
|
1736
|
-
* Safety setting configuration
|
|
1737
|
-
*/
|
|
1738
|
-
interface ISafetySetting {
|
|
1739
|
-
category: string;
|
|
1740
|
-
threshold: string;
|
|
1741
|
-
[key: string]: TConfigValue;
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
interface IProviderConfig$1 {
|
|
1745
|
-
name: string;
|
|
1746
|
-
model: string;
|
|
1747
|
-
apiKey?: string;
|
|
1748
|
-
baseURL?: string;
|
|
1749
|
-
timeout?: number;
|
|
1750
|
-
options?: Record<string, TUniversalValue>;
|
|
1751
|
-
}
|
|
1752
|
-
interface IProviderProfileDefaults {
|
|
1753
|
-
model?: string;
|
|
1754
|
-
apiKey?: string;
|
|
1755
|
-
baseURL?: string;
|
|
1756
|
-
timeout?: number;
|
|
1757
|
-
options?: Record<string, TUniversalValue>;
|
|
1758
|
-
}
|
|
1759
|
-
interface IProviderProfileConfig {
|
|
1760
|
-
type?: string;
|
|
1761
|
-
model?: string;
|
|
1762
|
-
apiKey?: string;
|
|
1763
|
-
baseURL?: string;
|
|
1764
|
-
timeout?: number;
|
|
1765
|
-
options?: Record<string, TUniversalValue>;
|
|
1766
|
-
}
|
|
1767
|
-
interface IProviderProbeResult {
|
|
1768
|
-
ok: boolean;
|
|
1769
|
-
message: string;
|
|
1770
|
-
models?: string[];
|
|
1771
|
-
}
|
|
1772
|
-
type TProviderCredentialField = 'apiKey';
|
|
1773
|
-
type TProviderSetupField = 'baseURL' | 'model' | TProviderCredentialField;
|
|
1774
|
-
type TProviderSetupHelpLinkKind = 'api-key' | 'console' | 'official';
|
|
1775
|
-
interface IProviderCredentialRequirement {
|
|
1776
|
-
anyOf: readonly TProviderCredentialField[];
|
|
1777
|
-
}
|
|
1778
|
-
interface IProviderSetupHelpLink {
|
|
1779
|
-
kind: TProviderSetupHelpLinkKind;
|
|
1780
|
-
label: string;
|
|
1781
|
-
url: string;
|
|
1782
|
-
sourceUrl?: string;
|
|
1783
|
-
lastVerifiedAt?: string;
|
|
1784
|
-
}
|
|
1785
|
-
type TProviderModelCatalogStatus = 'live' | 'generated' | 'fallback' | 'unavailable';
|
|
1786
|
-
type TProviderModelLifecycle = 'active' | 'preview' | 'deprecated' | 'unavailable';
|
|
1787
|
-
type TProviderModelCapability = 'tools' | 'vision' | 'json_schema' | 'reasoning' | 'native_web' | 'streaming';
|
|
1788
|
-
interface IProviderModelCatalogEntry {
|
|
1789
|
-
id: string;
|
|
1790
|
-
displayName: string;
|
|
1791
|
-
aliases?: readonly string[];
|
|
1792
|
-
contextWindow?: number;
|
|
1793
|
-
capabilities?: readonly TProviderModelCapability[];
|
|
1794
|
-
lifecycle?: TProviderModelLifecycle;
|
|
1795
|
-
lastVerifiedAt?: string;
|
|
1796
|
-
sourceUrl?: string;
|
|
1797
|
-
}
|
|
1798
|
-
interface IProviderModelCatalog {
|
|
1799
|
-
status: TProviderModelCatalogStatus;
|
|
1800
|
-
entries?: readonly IProviderModelCatalogEntry[];
|
|
1801
|
-
lastVerifiedAt?: string;
|
|
1802
|
-
sourceUrl?: string;
|
|
1803
|
-
message?: string;
|
|
1804
|
-
}
|
|
1805
|
-
interface IProviderModelCatalogRefreshOptions {
|
|
1806
|
-
profile: IProviderProfileConfig;
|
|
1807
|
-
}
|
|
1808
|
-
type TProviderModelCatalogRefresh = (options: IProviderModelCatalogRefreshOptions) => Promise<IProviderModelCatalog>;
|
|
1809
|
-
interface IProviderSetupStepDefinition {
|
|
1810
|
-
key: TProviderSetupField;
|
|
1811
|
-
title: string;
|
|
1812
|
-
defaultValue?: string;
|
|
1813
|
-
required?: boolean;
|
|
1814
|
-
masked?: boolean;
|
|
1815
|
-
}
|
|
1816
|
-
interface IProviderDefinition {
|
|
1817
|
-
type: string;
|
|
1818
|
-
aliases?: readonly string[];
|
|
1819
|
-
displayName?: string;
|
|
1820
|
-
description?: string;
|
|
1821
|
-
defaults?: IProviderProfileDefaults;
|
|
1822
|
-
modelCatalog?: IProviderModelCatalog;
|
|
1823
|
-
refreshModelCatalog?: TProviderModelCatalogRefresh;
|
|
1824
|
-
setupHelpLinks?: readonly IProviderSetupHelpLink[];
|
|
1825
|
-
setupSteps?: readonly IProviderSetupStepDefinition[];
|
|
1826
|
-
credentialRequirement?: IProviderCredentialRequirement;
|
|
1827
|
-
requiresApiKey?: boolean;
|
|
1828
|
-
createProvider: (config: IProviderConfig$1) => IAIProvider;
|
|
1829
|
-
probeProfile?: (profile: IProviderProfileConfig) => Promise<IProviderProbeResult>;
|
|
1830
|
-
}
|
|
1831
|
-
declare function findProviderDefinition(definitions: readonly IProviderDefinition[], type: string): IProviderDefinition | undefined;
|
|
1832
|
-
declare function formatSupportedProviderTypes(definitions: readonly IProviderDefinition[]): string;
|
|
1833
|
-
declare function getProviderCredentialRequirement(definition: IProviderDefinition | undefined): IProviderCredentialRequirement | undefined;
|
|
1834
|
-
|
|
1835
|
-
/**
|
|
1836
|
-
* Provider-agnostic media output reference.
|
|
1837
|
-
* Providers must not return raw binary payloads in this contract.
|
|
1838
|
-
*/
|
|
1839
|
-
interface IMediaOutputRef {
|
|
1840
|
-
kind: 'asset' | 'uri';
|
|
1841
|
-
assetId?: string;
|
|
1842
|
-
uri?: string;
|
|
1843
|
-
mimeType?: string;
|
|
1844
|
-
bytes?: number;
|
|
1845
|
-
}
|
|
1846
|
-
interface IProviderMediaError {
|
|
1847
|
-
code: 'PROVIDER_AUTH_ERROR' | 'PROVIDER_RATE_LIMITED' | 'PROVIDER_TIMEOUT' | 'PROVIDER_INVALID_REQUEST' | 'PROVIDER_UPSTREAM_ERROR' | 'PROVIDER_JOB_NOT_FOUND' | 'PROVIDER_JOB_NOT_CANCELLABLE';
|
|
1848
|
-
message: string;
|
|
1849
|
-
details?: Record<string, TUniversalValue>;
|
|
1850
|
-
}
|
|
1851
|
-
type TProviderMediaResult<TValue> = {
|
|
1852
|
-
ok: true;
|
|
1853
|
-
value: TValue;
|
|
1854
|
-
} | {
|
|
1855
|
-
ok: false;
|
|
1856
|
-
error: IProviderMediaError;
|
|
1857
|
-
};
|
|
1858
|
-
interface IInlineImageInputSource {
|
|
1859
|
-
kind: 'inline';
|
|
1860
|
-
mimeType: string;
|
|
1861
|
-
data: string;
|
|
1862
|
-
}
|
|
1863
|
-
interface IUriImageInputSource {
|
|
1864
|
-
kind: 'uri';
|
|
1865
|
-
uri: string;
|
|
1866
|
-
mimeType?: string;
|
|
1867
|
-
}
|
|
1868
|
-
type TImageInputSource = IInlineImageInputSource | IUriImageInputSource;
|
|
1869
|
-
interface IImageGenerationRequest {
|
|
1870
|
-
prompt: string;
|
|
1871
|
-
model: string;
|
|
1872
|
-
}
|
|
1873
|
-
interface IImageEditRequest {
|
|
1874
|
-
image: TImageInputSource;
|
|
1875
|
-
prompt: string;
|
|
1876
|
-
model: string;
|
|
1877
|
-
}
|
|
1878
|
-
interface IImageComposeRequest {
|
|
1879
|
-
images: TImageInputSource[];
|
|
1880
|
-
prompt: string;
|
|
1881
|
-
model: string;
|
|
1882
|
-
}
|
|
1883
|
-
interface IImageGenerationResult {
|
|
1884
|
-
outputs: IMediaOutputRef[];
|
|
1885
|
-
model: string;
|
|
1886
|
-
}
|
|
1887
|
-
interface IImageGenerationProvider {
|
|
1888
|
-
generateImage(request: IImageGenerationRequest): Promise<TProviderMediaResult<IImageGenerationResult>>;
|
|
1889
|
-
editImage?(request: IImageEditRequest): Promise<TProviderMediaResult<IImageGenerationResult>>;
|
|
1890
|
-
composeImage?(request: IImageComposeRequest): Promise<TProviderMediaResult<IImageGenerationResult>>;
|
|
1891
|
-
}
|
|
1892
|
-
interface IVideoGenerationRequest {
|
|
1893
|
-
prompt: string;
|
|
1894
|
-
model: string;
|
|
1895
|
-
durationSeconds?: number;
|
|
1896
|
-
aspectRatio?: string;
|
|
1897
|
-
seed?: number;
|
|
1898
|
-
inputImages?: TImageInputSource[];
|
|
1899
|
-
}
|
|
1900
|
-
interface IVideoJobAccepted {
|
|
1901
|
-
jobId: string;
|
|
1902
|
-
status: 'queued' | 'running';
|
|
1903
|
-
createdAt: string;
|
|
1904
|
-
}
|
|
1905
|
-
interface IVideoJobSnapshot {
|
|
1906
|
-
jobId: string;
|
|
1907
|
-
status: 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled';
|
|
1908
|
-
output?: IMediaOutputRef;
|
|
1909
|
-
error?: IProviderMediaError;
|
|
1910
|
-
updatedAt: string;
|
|
1911
|
-
}
|
|
1912
|
-
interface IVideoGenerationProvider {
|
|
1913
|
-
createVideo(request: IVideoGenerationRequest): Promise<TProviderMediaResult<IVideoJobAccepted>>;
|
|
1914
|
-
getVideoJob(jobId: string): Promise<TProviderMediaResult<IVideoJobSnapshot>>;
|
|
1915
|
-
cancelVideoJob(jobId: string): Promise<TProviderMediaResult<IVideoJobSnapshot>>;
|
|
1916
|
-
}
|
|
1917
|
-
declare function isImageGenerationProvider(provider: object): provider is IImageGenerationProvider;
|
|
1918
|
-
declare function isVideoGenerationProvider(provider: object): provider is IVideoGenerationProvider;
|
|
1919
|
-
|
|
1920
|
-
/**
|
|
1921
|
-
* Reusable type definitions for manager layer
|
|
1922
|
-
*/
|
|
1923
|
-
/**
|
|
1924
|
-
* Agent creation metadata type
|
|
1925
|
-
* Used for storing additional information about agent creation and configuration
|
|
1926
|
-
*/
|
|
1927
|
-
type TAgentCreationMetadata = Record<string, string | number | boolean | Date>;
|
|
1928
|
-
/**
|
|
1929
|
-
* Tool execution parameters for manager operations
|
|
1930
|
-
* Used for tool parameter validation and execution in manager context
|
|
1931
|
-
*/
|
|
1932
|
-
type TManagerToolParameters = Record<string, string | number | boolean | string[] | number[] | boolean[]>;
|
|
1933
|
-
/**
|
|
1934
|
-
* Configuration validation result
|
|
1935
|
-
*/
|
|
1936
|
-
interface IConfigValidationResult {
|
|
1937
|
-
isValid: boolean;
|
|
1938
|
-
errors: string[];
|
|
1939
|
-
warnings?: string[];
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* AI Provider Manager interface for provider registration and selection
|
|
1943
|
-
*/
|
|
1944
|
-
interface IAIProviderManager {
|
|
1945
|
-
/**
|
|
1946
|
-
* Register an AI provider
|
|
1947
|
-
*/
|
|
1948
|
-
addProvider(name: string, provider: IAIProvider): void;
|
|
1949
|
-
/**
|
|
1950
|
-
* Remove an AI provider
|
|
1951
|
-
*/
|
|
1952
|
-
removeProvider(name: string): void;
|
|
1953
|
-
/**
|
|
1954
|
-
* Get registered provider by name
|
|
1955
|
-
*/
|
|
1956
|
-
getProvider(name: string): IAIProvider | undefined;
|
|
1957
|
-
/**
|
|
1958
|
-
* Get all registered providers
|
|
1959
|
-
*/
|
|
1960
|
-
getProviders(): Record<string, IAIProvider>;
|
|
1961
|
-
/**
|
|
1962
|
-
* Set current provider and model
|
|
1963
|
-
*/
|
|
1964
|
-
setCurrentProvider(name: string, model: string): void;
|
|
1965
|
-
/**
|
|
1966
|
-
* Get current provider and model
|
|
1967
|
-
*/
|
|
1968
|
-
getCurrentProvider(): {
|
|
1969
|
-
provider: string;
|
|
1970
|
-
model: string;
|
|
1971
|
-
} | undefined;
|
|
1972
|
-
/**
|
|
1973
|
-
* Check if provider is configured
|
|
1974
|
-
*/
|
|
1975
|
-
isConfigured(): boolean;
|
|
1976
|
-
/**
|
|
1977
|
-
* Get available models for a provider
|
|
1978
|
-
*/
|
|
1979
|
-
getAvailableModels(providerName: string): string[];
|
|
1980
|
-
}
|
|
1981
|
-
/**
|
|
1982
|
-
* Tool Manager interface for tool registration and management
|
|
1983
|
-
*/
|
|
1984
|
-
interface IToolManager {
|
|
1985
|
-
/**
|
|
1986
|
-
* Register a tool
|
|
1987
|
-
*/
|
|
1988
|
-
addTool(schema: IToolSchema, executor: TToolExecutor): void;
|
|
1989
|
-
/**
|
|
1990
|
-
* Remove a tool by name
|
|
1991
|
-
*/
|
|
1992
|
-
removeTool(name: string): void;
|
|
1993
|
-
/**
|
|
1994
|
-
* Get tool interface by name
|
|
1995
|
-
*/
|
|
1996
|
-
getTool(name: string): ITool | undefined;
|
|
1997
|
-
/**
|
|
1998
|
-
* Get tool schema by name
|
|
1999
|
-
*/
|
|
2000
|
-
getToolSchema(name: string): IToolSchema | undefined;
|
|
2001
|
-
/**
|
|
2002
|
-
* Get all registered tools
|
|
2003
|
-
*/
|
|
2004
|
-
getTools(): IToolSchema[];
|
|
2005
|
-
/**
|
|
2006
|
-
* Execute a tool
|
|
2007
|
-
*/
|
|
2008
|
-
executeTool(name: string, parameters: TToolParameters, context?: IToolExecutionContext): Promise<TUniversalValue>;
|
|
2009
|
-
/**
|
|
2010
|
-
* Check if tool exists
|
|
2011
|
-
*/
|
|
2012
|
-
hasTool(name: string): boolean;
|
|
2013
|
-
/**
|
|
2014
|
-
* Set allowed tools (for filtering)
|
|
2015
|
-
*/
|
|
2016
|
-
setAllowedTools(tools: string[]): void;
|
|
2017
|
-
/**
|
|
2018
|
-
* Get allowed tools
|
|
2019
|
-
*/
|
|
2020
|
-
getAllowedTools(): string[] | undefined;
|
|
2021
|
-
}
|
|
2022
|
-
/**
|
|
2023
|
-
* Agent creation options
|
|
2024
|
-
*/
|
|
2025
|
-
interface IAgentCreationOptions {
|
|
2026
|
-
/** Override default configuration */
|
|
2027
|
-
overrides?: Partial<IAgentConfig>;
|
|
2028
|
-
/** Validation options */
|
|
2029
|
-
validation?: {
|
|
2030
|
-
strict?: boolean;
|
|
2031
|
-
skipOptional?: boolean;
|
|
2032
|
-
};
|
|
2033
|
-
/** Additional metadata */
|
|
2034
|
-
metadata?: TAgentCreationMetadata;
|
|
2035
|
-
}
|
|
2036
|
-
/**
|
|
2037
|
-
* Agent Factory interface for agent creation and configuration
|
|
2038
|
-
*/
|
|
2039
|
-
interface IAgentFactory {
|
|
2040
|
-
/**
|
|
2041
|
-
* Create agent instance
|
|
2042
|
-
*/
|
|
2043
|
-
createAgent(config: IAgentConfig, options?: IAgentCreationOptions): IAgent<IAgentConfig>;
|
|
2044
|
-
/**
|
|
2045
|
-
* Validate agent configuration
|
|
2046
|
-
*/
|
|
2047
|
-
validateConfig(config: IAgentConfig): IConfigValidationResult;
|
|
2048
|
-
/**
|
|
2049
|
-
* Get default configuration
|
|
2050
|
-
*/
|
|
2051
|
-
getDefaultConfig(): IAgentConfig;
|
|
2052
|
-
/**
|
|
2053
|
-
* Merge configurations
|
|
2054
|
-
*/
|
|
2055
|
-
mergeConfig(base: IAgentConfig, override: Partial<IAgentConfig>): IAgentConfig;
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
/**
|
|
2059
|
-
* OpenAPI specification configuration
|
|
2060
|
-
*/
|
|
2061
|
-
interface IOpenAPIToolConfig {
|
|
2062
|
-
/** OpenAPI 3.0 specification */
|
|
2063
|
-
spec: {
|
|
2064
|
-
openapi: string;
|
|
2065
|
-
info: {
|
|
2066
|
-
title: string;
|
|
2067
|
-
version: string;
|
|
2068
|
-
description?: string;
|
|
2069
|
-
};
|
|
2070
|
-
servers?: Array<{
|
|
2071
|
-
url: string;
|
|
2072
|
-
description?: string;
|
|
2073
|
-
}>;
|
|
2074
|
-
paths: Record<string, Record<string, string | number | boolean | Record<string, string | number | boolean>>>;
|
|
2075
|
-
components?: Record<string, Record<string, string | number | boolean>>;
|
|
2076
|
-
};
|
|
2077
|
-
/** Operation ID from the OpenAPI spec */
|
|
2078
|
-
operationId: string;
|
|
2079
|
-
/** Base URL for API calls */
|
|
2080
|
-
baseURL: string;
|
|
2081
|
-
/** Authentication configuration */
|
|
2082
|
-
auth?: {
|
|
2083
|
-
type: 'bearer' | 'apiKey' | 'basic';
|
|
2084
|
-
token?: string;
|
|
2085
|
-
apiKey?: string;
|
|
2086
|
-
header?: string;
|
|
2087
|
-
username?: string;
|
|
2088
|
-
password?: string;
|
|
2089
|
-
};
|
|
2090
|
-
}
|
|
2091
|
-
/**
|
|
2092
|
-
* MCP (Model Context Protocol) configuration
|
|
2093
|
-
*/
|
|
2094
|
-
interface IMCPToolConfig {
|
|
2095
|
-
/** MCP server endpoint */
|
|
2096
|
-
endpoint: string;
|
|
2097
|
-
/** Protocol version */
|
|
2098
|
-
version?: string;
|
|
2099
|
-
/** Authentication configuration */
|
|
2100
|
-
auth?: {
|
|
2101
|
-
type: 'bearer' | 'apiKey';
|
|
2102
|
-
token: string;
|
|
2103
|
-
};
|
|
2104
|
-
/** Tool-specific configuration */
|
|
2105
|
-
toolConfig?: Record<string, string | number | boolean>;
|
|
2106
|
-
/** Timeout in milliseconds */
|
|
2107
|
-
timeout?: number;
|
|
2108
|
-
}
|
|
2109
|
-
/**
|
|
2110
|
-
* Tool factory interface
|
|
2111
|
-
*/
|
|
2112
|
-
interface IToolFactory {
|
|
2113
|
-
/**
|
|
2114
|
-
* Create function tool from schema and function
|
|
2115
|
-
*/
|
|
2116
|
-
createFunctionTool(schema: IToolSchema, fn: TToolExecutor): IFunctionTool;
|
|
2117
|
-
/**
|
|
2118
|
-
* Create tool from OpenAPI specification
|
|
2119
|
-
*/
|
|
2120
|
-
createOpenAPITool(config: IOpenAPIToolConfig): ITool;
|
|
2121
|
-
/**
|
|
2122
|
-
* Create MCP tool
|
|
2123
|
-
*/
|
|
2124
|
-
createMCPTool(config: IMCPToolConfig): ITool;
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
/**
|
|
2128
|
-
* Execution step definition for tools that support step-by-step progress reporting
|
|
2129
|
-
*/
|
|
2130
|
-
interface IToolExecutionStep {
|
|
2131
|
-
/** Unique identifier for this step */
|
|
2132
|
-
id: string;
|
|
2133
|
-
/** Human-readable name of the step */
|
|
2134
|
-
name: string;
|
|
2135
|
-
/** Tool-provided estimated duration for this step in milliseconds */
|
|
2136
|
-
estimatedDuration: number;
|
|
2137
|
-
/** Optional description of what this step does */
|
|
2138
|
-
description?: string;
|
|
2139
|
-
}
|
|
2140
|
-
/**
|
|
2141
|
-
* Progress callback function type for real-time progress updates
|
|
2142
|
-
*/
|
|
2143
|
-
type TToolProgressCallback = (step: string, progress: number) => void;
|
|
2144
|
-
/**
|
|
2145
|
-
* 🆕 IProgressReportingTool - Optional interface for tools that can provide their own progress information
|
|
2146
|
-
*
|
|
2147
|
-
* This interface extends the standard ITool to allow tools to optionally provide:
|
|
2148
|
-
* - Estimated execution duration
|
|
2149
|
-
* - Step-by-step execution plans
|
|
2150
|
-
* - Real-time progress callbacks
|
|
2151
|
-
*
|
|
2152
|
-
* Benefits:
|
|
2153
|
-
* - Tools can provide accurate progress information based on their internal knowledge
|
|
2154
|
-
* - No simulation or fake progress - only real tool-provided estimates
|
|
2155
|
-
* - Completely optional - existing tools work unchanged
|
|
2156
|
-
* - Tools can self-report progress for better user experience
|
|
2157
|
-
*/
|
|
2158
|
-
interface IProgressReportingTool extends ITool {
|
|
2159
|
-
/**
|
|
2160
|
-
* Get estimated execution duration for given parameters (optional)
|
|
2161
|
-
*
|
|
2162
|
-
* Tools can implement this to provide accurate time estimates based on:
|
|
2163
|
-
* - Parameter complexity (e.g., search query length, file size)
|
|
2164
|
-
* - Historical execution data
|
|
2165
|
-
* - Internal optimization knowledge
|
|
2166
|
-
*
|
|
2167
|
-
* @param parameters - The parameters that will be passed to execute()
|
|
2168
|
-
* @returns Estimated duration in milliseconds, or undefined if not available
|
|
2169
|
-
*/
|
|
2170
|
-
getEstimatedDuration?(parameters: TToolParameters): number;
|
|
2171
|
-
/**
|
|
2172
|
-
* Get execution steps for given parameters (optional)
|
|
2173
|
-
*
|
|
2174
|
-
* Tools can implement this to provide step-by-step execution plans:
|
|
2175
|
-
* - webSearch: [query processing, API call, result parsing, filtering]
|
|
2176
|
-
* - fileSearch: [file scanning, content reading, pattern matching, result formatting]
|
|
2177
|
-
* - github-mcp: [authentication, API request, response processing, data transformation]
|
|
2178
|
-
*
|
|
2179
|
-
* @param parameters - The parameters that will be passed to execute()
|
|
2180
|
-
* @returns Array of execution steps, or undefined if not available
|
|
2181
|
-
*/
|
|
2182
|
-
getExecutionSteps?(parameters: TToolParameters): IToolExecutionStep[];
|
|
2183
|
-
/**
|
|
2184
|
-
* Set progress callback for real-time updates (optional)
|
|
2185
|
-
*
|
|
2186
|
-
* Tools can implement this to provide real-time progress updates during execution:
|
|
2187
|
-
* - Called when each step starts/completes
|
|
2188
|
-
* - Progress value between 0-100 representing completion percentage
|
|
2189
|
-
* - Step name helps users understand what's currently happening
|
|
2190
|
-
*
|
|
2191
|
-
* @param callback - Function to call with progress updates
|
|
2192
|
-
*/
|
|
2193
|
-
setProgressCallback?(callback: TToolProgressCallback): void;
|
|
2194
|
-
}
|
|
2195
|
-
/**
|
|
2196
|
-
* Type guard to check if a tool implements progress reporting
|
|
2197
|
-
*/
|
|
2198
|
-
declare function isProgressReportingTool(tool: ITool): tool is IProgressReportingTool;
|
|
2199
|
-
/**
|
|
2200
|
-
* Helper function to safely get estimated duration from any tool
|
|
2201
|
-
*/
|
|
2202
|
-
declare function getToolEstimatedDuration(tool: ITool, parameters: TToolParameters): number | undefined;
|
|
2203
|
-
/**
|
|
2204
|
-
* Helper function to safely get execution steps from any tool
|
|
2205
|
-
*/
|
|
2206
|
-
declare function getToolExecutionSteps(tool: ITool, parameters: TToolParameters): IToolExecutionStep[] | undefined;
|
|
2207
|
-
/**
|
|
2208
|
-
* Helper function to safely set progress callback on any tool
|
|
2209
|
-
*/
|
|
2210
|
-
declare function setToolProgressCallback(tool: ITool, callback: TToolProgressCallback): boolean;
|
|
2211
|
-
|
|
2212
|
-
/**
|
|
2213
|
-
* Service layer interfaces for the agents package
|
|
2214
|
-
* Defines contracts for stateless service implementations
|
|
2215
|
-
*/
|
|
2216
|
-
|
|
2217
|
-
/**
|
|
2218
|
-
* Reusable type definitions for service layer
|
|
2219
|
-
*/
|
|
2220
|
-
/**
|
|
2221
|
-
* Metadata type for conversation and execution context
|
|
2222
|
-
* Used for storing additional information about conversations, responses, and execution
|
|
2223
|
-
*/
|
|
2224
|
-
type TConversationContextMetadata = Record<string, string | number | boolean | Date>;
|
|
2225
|
-
/**
|
|
2226
|
-
* Tool execution parameters type
|
|
2227
|
-
* Used for passing parameters to tool execution methods
|
|
2228
|
-
*/
|
|
2229
|
-
type TToolExecutionParameters = Record<string, string | number | boolean | string[] | number[] | boolean[]>;
|
|
2230
|
-
/**
|
|
2231
|
-
* Execution metadata type
|
|
2232
|
-
* Used for storing metadata about execution processes and options
|
|
2233
|
-
*/
|
|
2234
|
-
type TExecutionMetadata = Record<string, string | number | boolean | Date>;
|
|
2235
|
-
/**
|
|
2236
|
-
* Response metadata type
|
|
2237
|
-
* Used for storing metadata about AI provider responses and streaming chunks
|
|
2238
|
-
*/
|
|
2239
|
-
type TResponseMetadata = Record<string, string | number | boolean | Date>;
|
|
2240
|
-
/**
|
|
2241
|
-
* Tool call data structure for function calls
|
|
2242
|
-
*/
|
|
2243
|
-
/**
|
|
2244
|
-
* Tool execution request
|
|
2245
|
-
*/
|
|
2246
|
-
interface IToolExecutionRequest {
|
|
2247
|
-
toolName: string;
|
|
2248
|
-
parameters: TToolParameters;
|
|
2249
|
-
executionId?: string;
|
|
2250
|
-
metadata?: TToolMetadata;
|
|
2251
|
-
ownerType?: string;
|
|
2252
|
-
ownerId?: string;
|
|
2253
|
-
ownerPath?: IOwnerPathSegment[];
|
|
2254
|
-
eventService?: IEventService;
|
|
2255
|
-
baseEventService?: IEventService;
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Conversation context containing messages and metadata
|
|
2259
|
-
*/
|
|
2260
|
-
interface IConversationContext {
|
|
2261
|
-
/** All messages in the conversation */
|
|
2262
|
-
messages: TUniversalMessage[];
|
|
2263
|
-
/** System message for the conversation */
|
|
2264
|
-
systemMessage?: string;
|
|
2265
|
-
/** Model to use for generation */
|
|
2266
|
-
model: string;
|
|
2267
|
-
/** Provider to use for generation */
|
|
2268
|
-
provider: string;
|
|
2269
|
-
/** Temperature for generation */
|
|
2270
|
-
temperature?: number;
|
|
2271
|
-
/** Maximum tokens to generate */
|
|
2272
|
-
maxTokens?: number;
|
|
2273
|
-
/** Available tools */
|
|
2274
|
-
tools?: IToolSchema[];
|
|
2275
|
-
/** Additional metadata */
|
|
2276
|
-
metadata?: TConversationContextMetadata;
|
|
2277
|
-
}
|
|
2278
|
-
/**
|
|
2279
|
-
* Response from AI provider
|
|
2280
|
-
*/
|
|
2281
|
-
interface IConversationResponse {
|
|
2282
|
-
/** Generated content */
|
|
2283
|
-
content: string;
|
|
2284
|
-
/** Tool calls if any */
|
|
2285
|
-
toolCalls?: IToolCall[];
|
|
2286
|
-
/** Usage statistics */
|
|
2287
|
-
usage?: {
|
|
2288
|
-
promptTokens: number;
|
|
2289
|
-
completionTokens: number;
|
|
2290
|
-
totalTokens: number;
|
|
2291
|
-
};
|
|
2292
|
-
/** Response metadata */
|
|
2293
|
-
metadata?: TResponseMetadata;
|
|
2294
|
-
/** Finish reason */
|
|
2295
|
-
finishReason?: string;
|
|
2296
|
-
}
|
|
2297
|
-
/**
|
|
2298
|
-
* Streaming response chunk
|
|
2299
|
-
*/
|
|
2300
|
-
interface IStreamingChunk {
|
|
2301
|
-
/** Content delta */
|
|
2302
|
-
delta: string;
|
|
2303
|
-
/** Whether this is the final chunk */
|
|
2304
|
-
done: boolean;
|
|
2305
|
-
/** Tool calls if any */
|
|
2306
|
-
toolCalls?: IToolCall[];
|
|
2307
|
-
/** Usage statistics (only in final chunk) */
|
|
2308
|
-
usage?: {
|
|
2309
|
-
promptTokens: number;
|
|
2310
|
-
completionTokens: number;
|
|
2311
|
-
totalTokens: number;
|
|
2312
|
-
};
|
|
2313
|
-
}
|
|
2314
|
-
/**
|
|
2315
|
-
* Service options for conversation operations
|
|
2316
|
-
*/
|
|
2317
|
-
interface IConversationServiceOptions {
|
|
2318
|
-
/** Maximum conversation history length */
|
|
2319
|
-
maxHistoryLength?: number;
|
|
2320
|
-
/** Whether to automatically retry on failure */
|
|
2321
|
-
enableRetry?: boolean;
|
|
2322
|
-
/** Maximum number of retries */
|
|
2323
|
-
maxRetries?: number;
|
|
2324
|
-
/** Retry delay in milliseconds */
|
|
2325
|
-
retryDelay?: number;
|
|
2326
|
-
/** Request timeout in milliseconds */
|
|
2327
|
-
timeout?: number;
|
|
2328
|
-
}
|
|
2329
|
-
/**
|
|
2330
|
-
* Context options for conversation preparation
|
|
2331
|
-
*/
|
|
2332
|
-
interface IContextOptions {
|
|
2333
|
-
systemMessage?: string;
|
|
2334
|
-
temperature?: number;
|
|
2335
|
-
maxTokens?: number;
|
|
2336
|
-
tools?: IToolSchema[];
|
|
2337
|
-
metadata?: TConversationContextMetadata;
|
|
2338
|
-
}
|
|
2339
|
-
/**
|
|
2340
|
-
* Execution service options
|
|
2341
|
-
*/
|
|
2342
|
-
interface IExecutionServiceOptions {
|
|
2343
|
-
/** Maximum number of tool execution rounds */
|
|
2344
|
-
maxToolRounds?: number;
|
|
2345
|
-
/** Tool execution timeout */
|
|
2346
|
-
toolTimeout?: number;
|
|
2347
|
-
/** Whether to enable parallel tool execution */
|
|
2348
|
-
enableParallelExecution?: boolean;
|
|
2349
|
-
/** Additional execution metadata */
|
|
2350
|
-
metadata?: TExecutionMetadata;
|
|
2351
|
-
}
|
|
2352
|
-
/**
|
|
2353
|
-
* Interface for conversation service operations
|
|
2354
|
-
* All methods should be stateless and pure functions
|
|
2355
|
-
*/
|
|
2356
|
-
interface IConversationService {
|
|
2357
|
-
/**
|
|
2358
|
-
* Prepare conversation context from messages and configuration
|
|
2359
|
-
* Pure function that transforms inputs to context object
|
|
2360
|
-
*/
|
|
2361
|
-
prepareContext(messages: TUniversalMessage[], model: string, provider: string, contextOptions?: IContextOptions, serviceOptions?: IConversationServiceOptions): IConversationContext;
|
|
2362
|
-
/**
|
|
2363
|
-
* Generate a response using the AI provider
|
|
2364
|
-
* Stateless operation that handles the full request-response cycle
|
|
2365
|
-
*/
|
|
2366
|
-
generateResponse(provider: IAIProvider, context: IConversationContext, serviceOptions?: IConversationServiceOptions): Promise<IConversationResponse>;
|
|
2367
|
-
/**
|
|
2368
|
-
* Generate streaming response using the AI provider
|
|
2369
|
-
* Stateless streaming operation
|
|
2370
|
-
*/
|
|
2371
|
-
generateStreamingResponse(provider: IAIProvider, context: IConversationContext, serviceOptions?: IConversationServiceOptions): AsyncGenerator<IStreamingChunk, void, never>;
|
|
2372
|
-
/**
|
|
2373
|
-
* Validate conversation context
|
|
2374
|
-
* Pure validation function
|
|
2375
|
-
*/
|
|
2376
|
-
validateContext(context: IConversationContext): {
|
|
2377
|
-
isValid: boolean;
|
|
2378
|
-
errors: string[];
|
|
2379
|
-
};
|
|
2380
|
-
}
|
|
2381
|
-
/**
|
|
2382
|
-
* Interface for tool execution service operations
|
|
2383
|
-
*/
|
|
2384
|
-
interface IToolExecutionService {
|
|
2385
|
-
/**
|
|
2386
|
-
* Execute a single tool
|
|
2387
|
-
*/
|
|
2388
|
-
executeTool(toolName: string, parameters: TToolParameters): Promise<TUniversalValue>;
|
|
2389
|
-
/**
|
|
2390
|
-
* Execute multiple tools in parallel
|
|
2391
|
-
*/
|
|
2392
|
-
executeToolsParallel(toolCalls: IToolExecutionRequest[]): Promise<TUniversalValue[]>;
|
|
2393
|
-
/**
|
|
2394
|
-
* Execute multiple tools sequentially
|
|
2395
|
-
*/
|
|
2396
|
-
executeToolsSequential(toolCalls: IToolExecutionRequest[]): Promise<TUniversalValue[]>;
|
|
2397
|
-
}
|
|
2398
|
-
/**
|
|
2399
|
-
* Interface for execution service operations
|
|
2400
|
-
*/
|
|
2401
|
-
interface IExecutionService {
|
|
2402
|
-
/**
|
|
2403
|
-
* Execute complete agent pipeline
|
|
2404
|
-
*/
|
|
2405
|
-
execute(input: string, context: IConversationContext, options?: IExecutionServiceOptions): Promise<string>;
|
|
2406
|
-
/**
|
|
2407
|
-
* Execute streaming agent pipeline
|
|
2408
|
-
*/
|
|
2409
|
-
executeStream(input: string, context: IConversationContext, options?: IExecutionServiceOptions): AsyncGenerator<string, void, never>;
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
/**
|
|
2413
|
-
* Request for executing a streaming chat completion through an executor
|
|
2414
|
-
*/
|
|
2415
|
-
interface IChatExecutionRequest {
|
|
2416
|
-
/** Array of messages in the conversation */
|
|
2417
|
-
messages: TUniversalMessage[];
|
|
2418
|
-
/** Chat options including model, temperature, etc. */
|
|
2419
|
-
options?: IChatOptions;
|
|
2420
|
-
/** Available tools for the AI to use */
|
|
2421
|
-
tools?: IToolSchema[];
|
|
2422
|
-
/** Target AI provider (e.g., 'openai', 'anthropic', 'google') */
|
|
2423
|
-
provider: string;
|
|
2424
|
-
/** Specific model to use */
|
|
2425
|
-
model: string;
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Request for executing a streaming chat completion through an executor
|
|
2429
|
-
*/
|
|
2430
|
-
interface IStreamExecutionRequest extends IChatExecutionRequest {
|
|
2431
|
-
/** Indicates this is a streaming request */
|
|
2432
|
-
stream: true;
|
|
2433
|
-
}
|
|
2434
|
-
/**
|
|
2435
|
-
* Interface for executing AI provider operations
|
|
2436
|
-
*
|
|
2437
|
-
* Executors abstract the execution mechanism, allowing providers to work
|
|
2438
|
-
* with either local API calls or remote server calls transparently.
|
|
2439
|
-
*
|
|
2440
|
-
* Implementation patterns:
|
|
2441
|
-
* - LocalExecutor: Direct API calls using provider SDKs
|
|
2442
|
-
* - RemoteExecutor: HTTP/WebSocket calls to remote server
|
|
2443
|
-
* - CacheExecutor: Cached responses with explicit error propagation
|
|
2444
|
-
* - HybridExecutor: Conditional local/remote execution
|
|
2445
|
-
*/
|
|
2446
|
-
interface IExecutor {
|
|
2447
|
-
/**
|
|
2448
|
-
* Execute a chat completion request
|
|
2449
|
-
*
|
|
2450
|
-
* @param request - Chat execution request with messages, options, and tools
|
|
2451
|
-
* @returns Promise resolving to assistant message response
|
|
2452
|
-
*
|
|
2453
|
-
* @example
|
|
2454
|
-
* ```typescript
|
|
2455
|
-
* const response = await executor.executeChat({
|
|
2456
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
2457
|
-
* options: { model: 'gpt-4', temperature: 0.7 },
|
|
2458
|
-
* provider: 'openai',
|
|
2459
|
-
* model: 'gpt-4'
|
|
2460
|
-
* });
|
|
2461
|
-
* ```
|
|
2462
|
-
*/
|
|
2463
|
-
executeChat(request: IChatExecutionRequest): Promise<IAssistantMessage>;
|
|
2464
|
-
/**
|
|
2465
|
-
* Execute a streaming chat completion request
|
|
2466
|
-
*
|
|
2467
|
-
* @param request - Streaming chat execution request
|
|
2468
|
-
* @returns AsyncIterable of message chunks
|
|
2469
|
-
*
|
|
2470
|
-
* @example
|
|
2471
|
-
* ```typescript
|
|
2472
|
-
* for await (const chunk of executor.executeChatStream({
|
|
2473
|
-
* messages: [{ role: 'user', content: 'Tell me a story' }],
|
|
2474
|
-
* options: { model: 'gpt-4' },
|
|
2475
|
-
* provider: 'openai',
|
|
2476
|
-
* model: 'gpt-4',
|
|
2477
|
-
* stream: true
|
|
2478
|
-
* })) {
|
|
2479
|
-
* console.log(chunk.content);
|
|
2480
|
-
* }
|
|
2481
|
-
* ```
|
|
2482
|
-
*/
|
|
2483
|
-
executeChatStream?(request: IStreamExecutionRequest): AsyncIterable<TUniversalMessage>;
|
|
2484
|
-
/**
|
|
2485
|
-
* Check if the executor supports tool calling
|
|
2486
|
-
* @returns true if tool calling is supported
|
|
2487
|
-
*/
|
|
2488
|
-
supportsTools(): boolean;
|
|
2489
|
-
/**
|
|
2490
|
-
* Validate executor configuration
|
|
2491
|
-
* @returns true if configuration is valid
|
|
2492
|
-
*/
|
|
2493
|
-
validateConfig(): boolean;
|
|
2494
|
-
/**
|
|
2495
|
-
* Clean up resources when executor is no longer needed
|
|
2496
|
-
*/
|
|
2497
|
-
dispose?(): Promise<void>;
|
|
2498
|
-
/**
|
|
2499
|
-
* Get executor name/identifier
|
|
2500
|
-
*/
|
|
2501
|
-
readonly name: string;
|
|
2502
|
-
/**
|
|
2503
|
-
* Get executor version
|
|
2504
|
-
*/
|
|
2505
|
-
readonly version: string;
|
|
2506
|
-
}
|
|
2507
|
-
/**
|
|
2508
|
-
* Configuration options for local executor
|
|
2509
|
-
*/
|
|
2510
|
-
interface ILocalExecutorConfig {
|
|
2511
|
-
/** Timeout for API requests in milliseconds */
|
|
2512
|
-
timeout?: number;
|
|
2513
|
-
/** Maximum number of retry attempts */
|
|
2514
|
-
maxRetries?: number;
|
|
2515
|
-
/** Base delay between retries in milliseconds */
|
|
2516
|
-
retryDelay?: number;
|
|
2517
|
-
/** Whether to enable request/response logging */
|
|
2518
|
-
enableLogging?: boolean;
|
|
2519
|
-
}
|
|
2520
|
-
/**
|
|
2521
|
-
* Configuration options for remote executor
|
|
2522
|
-
*/
|
|
2523
|
-
interface IRemoteExecutorConfig {
|
|
2524
|
-
/** Remote server URL */
|
|
2525
|
-
serverUrl: string;
|
|
2526
|
-
/** User authentication token */
|
|
2527
|
-
userApiKey: string;
|
|
2528
|
-
/** Timeout for HTTP requests in milliseconds */
|
|
2529
|
-
timeout?: number;
|
|
2530
|
-
/** Maximum number of retry attempts */
|
|
2531
|
-
maxRetries?: number;
|
|
2532
|
-
/** Whether to enable WebSocket for streaming */
|
|
2533
|
-
enableWebSocket?: boolean;
|
|
2534
|
-
/** Custom headers to include in requests */
|
|
2535
|
-
headers?: Record<string, string>;
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
interface IEventHistoryRecord {
|
|
2539
|
-
eventName: string;
|
|
2540
|
-
sequenceId: number;
|
|
2541
|
-
timestamp: Date;
|
|
2542
|
-
eventData: IBaseEventData;
|
|
2543
|
-
context: IEventContext;
|
|
2544
|
-
}
|
|
2545
|
-
interface IEventHistorySnapshot {
|
|
2546
|
-
lastSequenceId: number;
|
|
2547
|
-
createdAt: Date;
|
|
2548
|
-
}
|
|
2549
|
-
interface IEventHistoryModule {
|
|
2550
|
-
append(record: IEventHistoryRecord): void;
|
|
2551
|
-
read(fromSequenceId: number, toSequenceId?: number): IEventHistoryRecord[];
|
|
2552
|
-
readStream(fromSequenceId: number, toSequenceId?: number): AsyncIterable<IEventHistoryRecord>;
|
|
2553
|
-
getSnapshot?(): IEventHistorySnapshot | undefined;
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
/**
|
|
2557
|
-
* Terminal output abstraction — port interface for components that need I/O.
|
|
2558
|
-
* Owned by agent-core as a domain port. Implemented by agent-cli.
|
|
2559
|
-
*/
|
|
2560
|
-
interface ISpinner {
|
|
2561
|
-
stop(): void;
|
|
2562
|
-
update(message: string): void;
|
|
2563
|
-
}
|
|
2564
|
-
interface ITerminalOutput {
|
|
2565
|
-
write(text: string): void;
|
|
2566
|
-
writeLine(text: string): void;
|
|
2567
|
-
writeMarkdown(md: string): void;
|
|
2568
|
-
writeError(text: string): void;
|
|
2569
|
-
prompt(question: string): Promise<string>;
|
|
2570
|
-
select(options: string[], initialIndex?: number): Promise<number>;
|
|
2571
|
-
spinner(message: string): ISpinner;
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
/**
|
|
2575
|
-
* Minimal session abstraction shared across contract layers.
|
|
2576
|
-
* Lives in agent-core (Domain) so interface-level packages can reference it
|
|
2577
|
-
* without depending on agent-sessions (Session services layer).
|
|
2578
|
-
*/
|
|
2579
|
-
interface ISession {
|
|
2580
|
-
readonly sessionId: string;
|
|
2581
|
-
}
|
|
2582
|
-
|
|
2583
|
-
/**
|
|
2584
|
-
* @fileoverview Abstract Agent Base Class
|
|
2585
|
-
*
|
|
2586
|
-
* 🎯 ABSTRACT CLASS - DO NOT DEPEND ON CONCRETE IMPLEMENTATIONS
|
|
2587
|
-
*
|
|
2588
|
-
* This class defines the foundational lifecycle for agent implementations.
|
|
2589
|
-
* Subclasses provide provider/tool-specific behavior while inheriting the
|
|
2590
|
-
* shared guarantees around initialization, history, and disposal.
|
|
2591
|
-
*/
|
|
2592
|
-
|
|
2593
|
-
declare abstract class AbstractAgent<TConfig = IAgentConfig, TContext = IRunOptions, TMessage = TUniversalMessage> implements IAgent<TConfig, TContext, TMessage> {
|
|
2594
|
-
protected history: TMessage[];
|
|
2595
|
-
protected isInitialized: boolean;
|
|
2596
|
-
protected config?: TConfig;
|
|
2597
|
-
/**
|
|
2598
|
-
* Initialize the agent (subclass responsibility)
|
|
2599
|
-
*/
|
|
2600
|
-
protected abstract initialize(): Promise<void>;
|
|
2601
|
-
/**
|
|
2602
|
-
* Configure the agent with type-safe configuration
|
|
2603
|
-
*/
|
|
2604
|
-
configure(config: TConfig): Promise<void>;
|
|
2605
|
-
/**
|
|
2606
|
-
* Run agent with user input and type-safe context
|
|
2607
|
-
*/
|
|
2608
|
-
abstract run(input: string, context?: TContext): Promise<string>;
|
|
2609
|
-
/**
|
|
2610
|
-
* Run agent with streaming response and type-safe context
|
|
2611
|
-
*/
|
|
2612
|
-
abstract runStream(input: string, context?: TContext): AsyncGenerator<string, void, never>;
|
|
2613
|
-
/**
|
|
2614
|
-
* Get conversation history with type-safe messages
|
|
2615
|
-
*/
|
|
2616
|
-
getHistory(): TMessage[];
|
|
2617
|
-
/**
|
|
2618
|
-
* Clear conversation history
|
|
2619
|
-
*/
|
|
2620
|
-
clearHistory(): void;
|
|
2621
|
-
/**
|
|
2622
|
-
* Add message to history
|
|
2623
|
-
*/
|
|
2624
|
-
protected addMessage(message: TMessage): void;
|
|
2625
|
-
/**
|
|
2626
|
-
* Validate user input
|
|
2627
|
-
*/
|
|
2628
|
-
protected validateInput(input: string): void;
|
|
2629
|
-
/**
|
|
2630
|
-
* Ensure agent is initialized before running
|
|
2631
|
-
*/
|
|
2632
|
-
protected ensureInitialized(): Promise<void>;
|
|
2633
|
-
/**
|
|
2634
|
-
* Cleanup resources
|
|
2635
|
-
*/
|
|
2636
|
-
dispose(): Promise<void>;
|
|
2637
|
-
}
|
|
2638
|
-
|
|
2639
|
-
/**
|
|
2640
|
-
* @fileoverview Abstract Manager Base Class
|
|
2641
|
-
*
|
|
2642
|
-
* 🎯 ABSTRACT CLASS - DO NOT IMPORT CONCRETE IMPLEMENTATIONS
|
|
2643
|
-
*
|
|
2644
|
-
* This class defines the common lifecycle contract for all manager implementations.
|
|
2645
|
-
* It enforces explicit initialization/disposal semantics so that subclasses can
|
|
2646
|
-
* provide their own resource management logic while sharing guard rails.
|
|
2647
|
-
*
|
|
2648
|
-
* Architectural rules:
|
|
2649
|
-
* - Depends only on abstractions (no concrete manager implementations)
|
|
2650
|
-
* - Provides finalize hooks (`doInitialize`, `doDispose`) for subclasses
|
|
2651
|
-
* - Guards public APIs via `ensureInitialized`
|
|
2652
|
-
*/
|
|
2653
|
-
declare abstract class AbstractManager {
|
|
2654
|
-
protected initialized: boolean;
|
|
2655
|
-
/**
|
|
2656
|
-
* Initialize the manager (idempotent)
|
|
2657
|
-
*/
|
|
2658
|
-
initialize(): Promise<void>;
|
|
2659
|
-
/**
|
|
2660
|
-
* Subclass-specific initialization logic
|
|
2661
|
-
*/
|
|
2662
|
-
protected abstract doInitialize(): Promise<void>;
|
|
2663
|
-
/**
|
|
2664
|
-
* Dispose manager resources (idempotent)
|
|
2665
|
-
*/
|
|
2666
|
-
dispose(): Promise<void>;
|
|
2667
|
-
/**
|
|
2668
|
-
* Subclass-specific disposal logic
|
|
2669
|
-
*/
|
|
2670
|
-
protected abstract doDispose(): Promise<void>;
|
|
2671
|
-
/**
|
|
2672
|
-
* Whether the manager completed initialization
|
|
2673
|
-
*/
|
|
2674
|
-
isInitialized(): boolean;
|
|
2675
|
-
/**
|
|
2676
|
-
* Ensure manager is initialized before performing operations
|
|
2677
|
-
*/
|
|
2678
|
-
protected ensureInitialized(): void;
|
|
2679
|
-
}
|
|
2680
|
-
|
|
2681
|
-
/**
|
|
2682
|
-
* @fileoverview Abstract AI Provider Base Class
|
|
2683
|
-
*
|
|
2684
|
-
* 🎯 ABSTRACT CLASS - DO NOT DEPEND ON CONCRETE IMPLEMENTATIONS
|
|
2685
|
-
*
|
|
2686
|
-
* Defines the shared contract and helper utilities for all AI provider implementations.
|
|
2687
|
-
* Concrete providers should extend this class and inject their own dependencies.
|
|
2688
|
-
*/
|
|
2689
|
-
|
|
2690
|
-
/**
|
|
2691
|
-
* Provider logging data type
|
|
2692
|
-
* Used for storing logging information in provider operations
|
|
2693
|
-
*/
|
|
2694
|
-
type TProviderLoggingData = Record<string, string | number | boolean | Date | string[]>;
|
|
2695
|
-
/**
|
|
2696
|
-
* Provider configuration base interface
|
|
2697
|
-
*/
|
|
2698
|
-
interface IProviderConfig {
|
|
2699
|
-
apiKey?: string;
|
|
2700
|
-
baseUrl?: string;
|
|
2701
|
-
timeout?: number;
|
|
2702
|
-
[key: string]: string | number | boolean | undefined;
|
|
2703
|
-
}
|
|
2704
|
-
/**
|
|
2705
|
-
* Enhanced provider configuration that supports executor injection
|
|
2706
|
-
*/
|
|
2707
|
-
interface IExecutorAwareProviderConfig {
|
|
2708
|
-
apiKey?: string;
|
|
2709
|
-
baseUrl?: string;
|
|
2710
|
-
timeout?: number;
|
|
2711
|
-
/**
|
|
2712
|
-
* Optional executor for handling AI requests
|
|
2713
|
-
* When provided, the provider will delegate all chat operations to this executor
|
|
2714
|
-
* instead of making direct API calls. This enables remote execution capabilities.
|
|
2715
|
-
*/
|
|
2716
|
-
executor?: IExecutor;
|
|
2717
|
-
[key: string]: string | number | boolean | IExecutor | undefined;
|
|
2718
|
-
}
|
|
2719
|
-
/**
|
|
2720
|
-
* Base AI provider implementation with proper type constraints.
|
|
2721
|
-
* All AI providers should extend this class.
|
|
2722
|
-
*
|
|
2723
|
-
* Subclasses MUST: extend this class, use override keyword, call super() in constructor,
|
|
2724
|
-
* not redefine types that exist in agent-core, handle null message content correctly.
|
|
2725
|
-
*
|
|
2726
|
-
* @template TConfig - Provider configuration type
|
|
2727
|
-
*/
|
|
2728
|
-
declare abstract class AbstractAIProvider<TConfig = IProviderConfig> implements IAIProvider {
|
|
2729
|
-
abstract readonly name: string;
|
|
2730
|
-
abstract readonly version: string;
|
|
2731
|
-
protected config?: TConfig;
|
|
2732
|
-
protected executor?: IExecutor;
|
|
2733
|
-
protected readonly logger: ILogger;
|
|
2734
|
-
constructor(logger?: ILogger);
|
|
2735
|
-
/**
|
|
2736
|
-
* Configure the provider with type-safe configuration
|
|
2737
|
-
*/
|
|
2738
|
-
configure(config: TConfig): Promise<void>;
|
|
2739
|
-
private hasExecutor;
|
|
2740
|
-
/**
|
|
2741
|
-
* Each provider must implement chat using their own native SDK types internally
|
|
2742
|
-
* @param messages - Array of messages from conversation history
|
|
2743
|
-
* @param options - Chat options including tools, model settings, etc.
|
|
2744
|
-
* @returns Promise resolving to a response
|
|
2745
|
-
*/
|
|
2746
|
-
abstract chat(messages: TUniversalMessage[], options?: IChatOptions): Promise<TUniversalMessage>;
|
|
2747
|
-
/**
|
|
2748
|
-
* Wrap an async iterable to yield to the macrotask queue periodically.
|
|
2749
|
-
* Providers MUST use this when iterating over streaming events to ensure
|
|
2750
|
-
* the main thread event loop stays responsive (ESC abort, Ctrl+C, etc.).
|
|
2751
|
-
*
|
|
2752
|
-
* Usage in provider:
|
|
2753
|
-
* for await (const event of this.streamWithAbort(stream, signal)) { ... }
|
|
2754
|
-
*/
|
|
2755
|
-
protected streamWithAbort<T>(source: AsyncIterable<T>, signal?: AbortSignal): AsyncGenerator<T>;
|
|
2756
|
-
/**
|
|
2757
|
-
* Each provider must implement streaming chat using their own native SDK types internally
|
|
2758
|
-
* @param messages - Array of messages from conversation history
|
|
2759
|
-
* @param options - Chat options including tools, model settings, etc.
|
|
2760
|
-
* @returns AsyncIterable of response chunks
|
|
2761
|
-
*/
|
|
2762
|
-
chatStream?(messages: TUniversalMessage[], options?: IChatOptions): AsyncIterable<TUniversalMessage>;
|
|
2763
|
-
/**
|
|
2764
|
-
* Provider-agnostic raw response API.
|
|
2765
|
-
*
|
|
2766
|
-
* This is the canonical "raw payload" entrypoint required by the AIProvider contract.
|
|
2767
|
-
* The default implementation delegates to `chat()` and adapts the result into a
|
|
2768
|
-
* RawProviderResponse shape.
|
|
2769
|
-
*/
|
|
2770
|
-
generateResponse(payload: IProviderRequest): Promise<IRawProviderResponse>;
|
|
2771
|
-
/**
|
|
2772
|
-
* Provider-agnostic raw streaming API.
|
|
2773
|
-
*
|
|
2774
|
-
* If a provider does not implement chatStream, it does not support streaming.
|
|
2775
|
-
*/
|
|
2776
|
-
generateStreamingResponse(payload: IProviderRequest): AsyncIterable<IRawProviderResponse>;
|
|
2777
|
-
/**
|
|
2778
|
-
* Default implementation - most modern providers support tools
|
|
2779
|
-
* @returns true if tool calling is supported
|
|
2780
|
-
*/
|
|
2781
|
-
supportsTools(): boolean;
|
|
2782
|
-
getCapabilities(): IProviderCapabilities;
|
|
2783
|
-
/**
|
|
2784
|
-
* Default implementation - providers can override for specific validation
|
|
2785
|
-
* @returns true if configuration is valid
|
|
2786
|
-
*/
|
|
2787
|
-
validateConfig(): boolean;
|
|
2788
|
-
/** Validate that messages is a non-empty array with valid roles. */
|
|
2789
|
-
protected validateMessages(messages: TUniversalMessage[]): void;
|
|
2790
|
-
/** Validate tool schemas. No-ops if tools is undefined. */
|
|
2791
|
-
protected validateTools(tools?: IToolSchema[]): void;
|
|
2792
|
-
protected validateNativeWebTools(request?: IProviderNativeWebToolRequest): void;
|
|
2793
|
-
/**
|
|
2794
|
-
* Execute chat via executor.
|
|
2795
|
-
* Subclasses should call this only when an executor is configured.
|
|
2796
|
-
*/
|
|
2797
|
-
protected executeViaExecutorOrDirect(messages: TUniversalMessage[], options?: IChatOptions): Promise<TUniversalMessage>;
|
|
2798
|
-
/**
|
|
2799
|
-
* Execute streaming chat via executor.
|
|
2800
|
-
* Subclasses should call this only when an executor is configured.
|
|
2801
|
-
*/
|
|
2802
|
-
protected executeStreamViaExecutorOrDirect(messages: TUniversalMessage[], options?: IChatOptions): AsyncIterable<TUniversalMessage>;
|
|
2803
|
-
/**
|
|
2804
|
-
* Clean up resources when provider is no longer needed
|
|
2805
|
-
* Override this method in subclasses for additional cleanup
|
|
2806
|
-
*/
|
|
2807
|
-
dispose(): Promise<void>;
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
/**
|
|
2811
|
-
* @fileoverview Abstract Executor Base Class
|
|
2812
|
-
*
|
|
2813
|
-
* 🎯 ABSTRACT CLASS - DO NOT DEPEND ON CONCRETE IMPLEMENTATIONS
|
|
2814
|
-
*
|
|
2815
|
-
* Provides shared execution helpers (retry, timeout, validation, logging) for all
|
|
2816
|
-
* executor implementations. Concrete executors should extend this class and inject
|
|
2817
|
-
* their own logger implementation if they need custom logging behavior.
|
|
2818
|
-
*
|
|
2819
|
-
* @example
|
|
2820
|
-
* ```typescript
|
|
2821
|
-
* export class MyCustomExecutor extends AbstractExecutor {
|
|
2822
|
-
* async executeChat(request: IChatExecutionRequest): Promise<AssistantMessage> {
|
|
2823
|
-
* return this.withRetry(() => this.performChat(request));
|
|
2824
|
-
* }
|
|
2825
|
-
* }
|
|
2826
|
-
* ```
|
|
2827
|
-
*/
|
|
2828
|
-
declare abstract class AbstractExecutor implements IExecutor {
|
|
2829
|
-
/**
|
|
2830
|
-
* Logger injected via constructor (defaults to abstract logger)
|
|
2831
|
-
*/
|
|
2832
|
-
protected readonly logger: ILogger;
|
|
2833
|
-
constructor(logger?: ILogger);
|
|
2834
|
-
abstract readonly name: string;
|
|
2835
|
-
abstract readonly version: string;
|
|
2836
|
-
/**
|
|
2837
|
-
* Execute a chat completion request
|
|
2838
|
-
* Must be implemented by concrete executor classes
|
|
2839
|
-
*/
|
|
2840
|
-
abstract executeChat(request: IChatExecutionRequest): Promise<IAssistantMessage>;
|
|
2841
|
-
/**
|
|
2842
|
-
* Execute a streaming chat completion request
|
|
2843
|
-
* Optional - can be implemented by concrete executor classes
|
|
2844
|
-
*/
|
|
2845
|
-
abstract executeChatStream?(request: IStreamExecutionRequest): AsyncIterable<TUniversalMessage>;
|
|
2846
|
-
/**
|
|
2847
|
-
* Check if the executor supports tool calling
|
|
2848
|
-
* Default implementation returns false, can be overridden
|
|
2849
|
-
*/
|
|
2850
|
-
supportsTools(): boolean;
|
|
2851
|
-
/**
|
|
2852
|
-
* Validate executor configuration
|
|
2853
|
-
* Default implementation returns true, can be overridden
|
|
2854
|
-
*/
|
|
2855
|
-
validateConfig(): boolean;
|
|
2856
|
-
/**
|
|
2857
|
-
* Clean up resources when executor is no longer needed
|
|
2858
|
-
* Default implementation does nothing, can be overridden
|
|
2859
|
-
*/
|
|
2860
|
-
dispose?(): Promise<void>;
|
|
2861
|
-
/**
|
|
2862
|
-
* Execute function with retry logic
|
|
2863
|
-
*
|
|
2864
|
-
* @param fn - Function to execute with retries
|
|
2865
|
-
* @param maxRetries - Maximum number of retry attempts (default: 3)
|
|
2866
|
-
* @param retryDelay - Delay between retries in milliseconds (default: 1000)
|
|
2867
|
-
* @returns Promise resolving to function result
|
|
2868
|
-
*/
|
|
2869
|
-
protected withRetry<T>(fn: () => Promise<T>, maxRetries?: number, retryDelay?: number): Promise<T>;
|
|
2870
|
-
/**
|
|
2871
|
-
* Execute function with timeout
|
|
2872
|
-
*
|
|
2873
|
-
* @param promise - Promise to execute with timeout
|
|
2874
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
2875
|
-
* @returns Promise resolving to function result
|
|
2876
|
-
*/
|
|
2877
|
-
protected withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
|
|
2878
|
-
/**
|
|
2879
|
-
* Delay execution for specified milliseconds
|
|
2880
|
-
*
|
|
2881
|
-
* @param ms - Milliseconds to delay
|
|
2882
|
-
* @returns Promise that resolves after the delay
|
|
2883
|
-
*/
|
|
2884
|
-
protected delay(ms: number): Promise<void>;
|
|
2885
|
-
/**
|
|
2886
|
-
* Log debug information (only if logging is enabled)
|
|
2887
|
-
*
|
|
2888
|
-
* @param message - Log message
|
|
2889
|
-
* @param data - Optional data to log
|
|
2890
|
-
*/
|
|
2891
|
-
protected logDebug(message: string, data?: TLoggerData): void;
|
|
2892
|
-
/**
|
|
2893
|
-
* Log error information
|
|
2894
|
-
*
|
|
2895
|
-
* @param message - Log message
|
|
2896
|
-
* @param error - Error object
|
|
2897
|
-
* @param data - Optional additional data
|
|
2898
|
-
*/
|
|
2899
|
-
protected logError(message: string, error: Error, data?: TLoggerData): void;
|
|
2900
|
-
/**
|
|
2901
|
-
* Validate that request has required fields
|
|
2902
|
-
*
|
|
2903
|
-
* @param request - Chat execution request to validate
|
|
2904
|
-
* @throws Error if validation fails
|
|
2905
|
-
*/
|
|
2906
|
-
protected validateRequest(request: IChatExecutionRequest): void;
|
|
2907
|
-
/**
|
|
2908
|
-
* Validate that response is properly formatted
|
|
2909
|
-
*
|
|
2910
|
-
* @param response - Response to validate
|
|
2911
|
-
* @throws Error if validation fails
|
|
2912
|
-
*/
|
|
2913
|
-
protected validateResponse(response: TUniversalMessage): void;
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
/**
|
|
2917
|
-
* Provider message format type.
|
|
2918
|
-
*
|
|
2919
|
-
* Provider packages own concrete message shapes. Core only carries the generic
|
|
2920
|
-
* conversion hook and never branches on provider names.
|
|
2921
|
-
*/
|
|
2922
|
-
type TProviderMessage = TUniversalMessage | IUniversalObjectValue;
|
|
2923
|
-
type TMessageFormatConverter<TMessage extends TProviderMessage = TProviderMessage> = (messages: readonly TUniversalMessage[]) => TMessage[];
|
|
2924
|
-
type TMessageConverterRegistry = Readonly<Record<string, TMessageFormatConverter>>;
|
|
2925
|
-
/**
|
|
2926
|
-
* Universal message converter utility
|
|
2927
|
-
*
|
|
2928
|
-
* The converter is registry-based so provider-specific message conversion is
|
|
2929
|
-
* injected by provider packages or callers instead of being hardcoded in core.
|
|
2930
|
-
*/
|
|
2931
|
-
declare class MessageConverter {
|
|
2932
|
-
/**
|
|
2933
|
-
* Convert messages using an injected converter or converter registry.
|
|
2934
|
-
*/
|
|
2935
|
-
static toProviderFormat(messages: TUniversalMessage[], converter?: TMessageFormatConverter | string, registry?: TMessageConverterRegistry): TProviderMessage[];
|
|
2936
|
-
/**
|
|
2937
|
-
* Convert to universal format (no conversion)
|
|
2938
|
-
*/
|
|
2939
|
-
private static toUniversalFormat;
|
|
2940
|
-
/**
|
|
2941
|
-
* Extract system message from messages
|
|
2942
|
-
*/
|
|
2943
|
-
static extractSystemMessage(messages: TUniversalMessage[]): string | undefined;
|
|
2944
|
-
/**
|
|
2945
|
-
* Filter non-system messages
|
|
2946
|
-
*/
|
|
2947
|
-
static filterNonSystemMessages(messages: TUniversalMessage[]): TUniversalMessage[];
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
/**
|
|
2951
|
-
* Validation result interface
|
|
2952
|
-
*/
|
|
2953
|
-
interface ISimpleValidationResult {
|
|
2954
|
-
isValid: boolean;
|
|
2955
|
-
errors: string[];
|
|
2956
|
-
warnings?: string[];
|
|
2957
|
-
}
|
|
2958
|
-
/**
|
|
2959
|
-
* Validation utility class
|
|
2960
|
-
*/
|
|
2961
|
-
declare class Validator {
|
|
2962
|
-
/**
|
|
2963
|
-
* Validate agent configuration
|
|
2964
|
-
*/
|
|
2965
|
-
static validateAgentConfig(config: Partial<IAgentConfig>): ISimpleValidationResult;
|
|
2966
|
-
/**
|
|
2967
|
-
* Validate user input string
|
|
2968
|
-
*/
|
|
2969
|
-
static validateUserInput(input: string): ISimpleValidationResult;
|
|
2970
|
-
/**
|
|
2971
|
-
* Validate provider name
|
|
2972
|
-
*/
|
|
2973
|
-
static validateProviderName(name: string): ISimpleValidationResult;
|
|
2974
|
-
/**
|
|
2975
|
-
* Validate model name
|
|
2976
|
-
*/
|
|
2977
|
-
static validateModelName(name: string): ISimpleValidationResult;
|
|
2978
|
-
/**
|
|
2979
|
-
* Validate API key format (basic check)
|
|
2980
|
-
*/
|
|
2981
|
-
static validateApiKey(apiKey: string): ISimpleValidationResult;
|
|
2982
|
-
}
|
|
2983
|
-
declare const validateAgentConfig: typeof Validator.validateAgentConfig;
|
|
2984
|
-
declare const validateUserInput: typeof Validator.validateUserInput;
|
|
2985
|
-
declare const validateProviderName: typeof Validator.validateProviderName;
|
|
2986
|
-
declare const validateModelName: typeof Validator.validateModelName;
|
|
2987
|
-
declare const validateApiKey: typeof Validator.validateApiKey;
|
|
2988
|
-
|
|
2989
|
-
/**
|
|
2990
|
-
* Reusable type definitions for error utilities
|
|
2991
|
-
*/
|
|
2992
|
-
/**
|
|
2993
|
-
* Error context data type
|
|
2994
|
-
* Used for storing contextual information in error instances
|
|
2995
|
-
*/
|
|
2996
|
-
type TErrorContextData = Record<string, string | number | boolean | Date | Error | string[] | undefined>;
|
|
2997
|
-
/**
|
|
2998
|
-
* Error external input type
|
|
2999
|
-
* Used for handling external errors from unknown sources
|
|
3000
|
-
*/
|
|
3001
|
-
type TErrorExternalInput = Error | string | Record<string, string | number | boolean> | null | undefined;
|
|
3002
|
-
/**
|
|
3003
|
-
* Base error class for all Robota errors
|
|
3004
|
-
*/
|
|
3005
|
-
declare abstract class RobotaError extends Error {
|
|
3006
|
-
readonly context?: TErrorContextData | undefined;
|
|
3007
|
-
abstract readonly code: string;
|
|
3008
|
-
abstract readonly category: 'user' | 'system' | 'provider';
|
|
3009
|
-
abstract readonly recoverable: boolean;
|
|
3010
|
-
constructor(message: string, context?: TErrorContextData | undefined);
|
|
3011
|
-
}
|
|
3012
|
-
/**
|
|
3013
|
-
* Configuration related errors
|
|
3014
|
-
*/
|
|
3015
|
-
declare class ConfigurationError extends RobotaError {
|
|
3016
|
-
readonly code = "CONFIGURATION_ERROR";
|
|
3017
|
-
readonly category: "user";
|
|
3018
|
-
readonly recoverable = false;
|
|
3019
|
-
constructor(message: string, context?: TErrorContextData);
|
|
3020
|
-
}
|
|
3021
|
-
/**
|
|
3022
|
-
* Input validation errors
|
|
3023
|
-
*/
|
|
3024
|
-
declare class ValidationError extends RobotaError {
|
|
3025
|
-
readonly field?: string | undefined;
|
|
3026
|
-
readonly code = "VALIDATION_ERROR";
|
|
3027
|
-
readonly category: "user";
|
|
3028
|
-
readonly recoverable = false;
|
|
3029
|
-
constructor(message: string, field?: string | undefined, context?: TErrorContextData);
|
|
3030
|
-
}
|
|
3031
|
-
/**
|
|
3032
|
-
* Provider related errors
|
|
3033
|
-
*/
|
|
3034
|
-
declare class ProviderError extends RobotaError {
|
|
3035
|
-
readonly provider: string;
|
|
3036
|
-
readonly originalError?: Error | undefined;
|
|
3037
|
-
readonly code = "PROVIDER_ERROR";
|
|
3038
|
-
readonly category: "provider";
|
|
3039
|
-
readonly recoverable = true;
|
|
3040
|
-
constructor(message: string, provider: string, originalError?: Error | undefined, context?: TErrorContextData);
|
|
3041
|
-
}
|
|
3042
|
-
/**
|
|
3043
|
-
* Authentication errors
|
|
3044
|
-
*/
|
|
3045
|
-
declare class AuthenticationError extends RobotaError {
|
|
3046
|
-
readonly provider?: string | undefined;
|
|
3047
|
-
readonly code = "AUTHENTICATION_ERROR";
|
|
3048
|
-
readonly category: "user";
|
|
3049
|
-
readonly recoverable = false;
|
|
3050
|
-
constructor(message: string, provider?: string | undefined, context?: TErrorContextData);
|
|
3051
|
-
}
|
|
3052
|
-
/**
|
|
3053
|
-
* Rate limit errors
|
|
3054
|
-
*/
|
|
3055
|
-
declare class RateLimitError extends RobotaError {
|
|
3056
|
-
readonly retryAfter?: number | undefined;
|
|
3057
|
-
readonly provider?: string | undefined;
|
|
3058
|
-
readonly code = "RATE_LIMIT_ERROR";
|
|
3059
|
-
readonly category: "provider";
|
|
3060
|
-
readonly recoverable = true;
|
|
3061
|
-
constructor(message: string, retryAfter?: number | undefined, provider?: string | undefined, context?: TErrorContextData);
|
|
3062
|
-
}
|
|
3063
|
-
/**
|
|
3064
|
-
* Network/connectivity errors
|
|
3065
|
-
*/
|
|
3066
|
-
declare class NetworkError extends RobotaError {
|
|
3067
|
-
readonly originalError?: Error | undefined;
|
|
3068
|
-
readonly code = "NETWORK_ERROR";
|
|
3069
|
-
readonly category: "system";
|
|
3070
|
-
readonly recoverable = true;
|
|
3071
|
-
constructor(message: string, originalError?: Error | undefined, context?: TErrorContextData);
|
|
3072
|
-
}
|
|
3073
|
-
/**
|
|
3074
|
-
* Tool execution errors
|
|
3075
|
-
*/
|
|
3076
|
-
declare class ToolExecutionError extends RobotaError {
|
|
3077
|
-
readonly toolName: string;
|
|
3078
|
-
readonly originalError?: Error | undefined;
|
|
3079
|
-
readonly code = "TOOL_EXECUTION_ERROR";
|
|
3080
|
-
readonly category: "system";
|
|
3081
|
-
readonly recoverable = false;
|
|
3082
|
-
constructor(message: string, toolName: string, originalError?: Error | undefined, context?: TErrorContextData);
|
|
3083
|
-
}
|
|
3084
|
-
/**
|
|
3085
|
-
* Model not available errors
|
|
3086
|
-
*/
|
|
3087
|
-
declare class ModelNotAvailableError extends RobotaError {
|
|
3088
|
-
readonly availableModels?: string[] | undefined;
|
|
3089
|
-
readonly code = "MODEL_NOT_AVAILABLE";
|
|
3090
|
-
readonly category: "user";
|
|
3091
|
-
readonly recoverable = false;
|
|
3092
|
-
constructor(model: string, provider: string, availableModels?: string[] | undefined, context?: TErrorContextData);
|
|
3093
|
-
}
|
|
3094
|
-
/**
|
|
3095
|
-
* Circuit breaker open error
|
|
3096
|
-
*/
|
|
3097
|
-
declare class CircuitBreakerOpenError extends RobotaError {
|
|
3098
|
-
readonly code = "CIRCUIT_BREAKER_OPEN";
|
|
3099
|
-
readonly category: "system";
|
|
3100
|
-
readonly recoverable = true;
|
|
3101
|
-
constructor(message?: string, context?: TErrorContextData);
|
|
3102
|
-
}
|
|
3103
|
-
/**
|
|
3104
|
-
* Plugin errors
|
|
3105
|
-
*/
|
|
3106
|
-
declare class PluginError extends RobotaError {
|
|
3107
|
-
readonly pluginName: string;
|
|
3108
|
-
readonly code = "PLUGIN_ERROR";
|
|
3109
|
-
readonly category: "system";
|
|
3110
|
-
readonly recoverable = false;
|
|
3111
|
-
constructor(message: string, pluginName: string, context?: TErrorContextData);
|
|
3112
|
-
}
|
|
3113
|
-
/**
|
|
3114
|
-
* Storage related errors
|
|
3115
|
-
*/
|
|
3116
|
-
declare class StorageError extends RobotaError {
|
|
3117
|
-
readonly code = "STORAGE_ERROR";
|
|
3118
|
-
readonly category: "system";
|
|
3119
|
-
readonly recoverable = true;
|
|
3120
|
-
constructor(message: string, context?: TErrorContextData);
|
|
3121
|
-
}
|
|
3122
|
-
/**
|
|
3123
|
-
* Cache integrity validation errors
|
|
3124
|
-
*/
|
|
3125
|
-
declare class CacheIntegrityError extends RobotaError {
|
|
3126
|
-
readonly code = "CACHE_INTEGRITY_ERROR";
|
|
3127
|
-
readonly category: "system";
|
|
3128
|
-
readonly recoverable = false;
|
|
3129
|
-
constructor(message: string, context?: TErrorContextData);
|
|
3130
|
-
}
|
|
3131
|
-
/**
|
|
3132
|
-
* Error utility functions
|
|
3133
|
-
*/
|
|
3134
|
-
declare class ErrorUtils {
|
|
3135
|
-
/**
|
|
3136
|
-
* Check if error is recoverable
|
|
3137
|
-
*/
|
|
3138
|
-
static isRecoverable(error: Error): boolean;
|
|
3139
|
-
/**
|
|
3140
|
-
* Extract error code from any error
|
|
3141
|
-
*/
|
|
3142
|
-
static getErrorCode(error: Error): string;
|
|
3143
|
-
/**
|
|
3144
|
-
* Create error from unknown value
|
|
3145
|
-
*/
|
|
3146
|
-
static fromUnknown(error: TErrorExternalInput, defaultMessage?: string): RobotaError;
|
|
3147
|
-
/**
|
|
3148
|
-
* Wrap external errors
|
|
3149
|
-
*/
|
|
3150
|
-
static wrapProviderError(error: TErrorExternalInput, provider: string, operation: string): ProviderError;
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
interface IPeriodicTaskOptions {
|
|
3154
|
-
name: string;
|
|
3155
|
-
intervalMs: number;
|
|
3156
|
-
}
|
|
3157
|
-
/**
|
|
3158
|
-
* Start a periodic async task with consistent error logging.
|
|
3159
|
-
* SSOT helper to avoid duplicating setInterval(async () => ...) patterns.
|
|
3160
|
-
*/
|
|
3161
|
-
declare function startPeriodicTask(logger: ILogger, options: IPeriodicTaskOptions, task: () => Promise<void>): TTimerId;
|
|
3162
|
-
declare function stopPeriodicTask(timer: TTimerId | undefined): void;
|
|
3163
|
-
|
|
3164
|
-
/**
|
|
3165
|
-
* Cross-platform timer identifier type
|
|
3166
|
-
* Works in both Node.js and browser environments
|
|
3167
|
-
*/
|
|
3168
|
-
type TTimerId = ReturnType<typeof setTimeout>;
|
|
3169
|
-
|
|
3170
|
-
/** Create a user message. */
|
|
3171
|
-
declare function createUserMessage(content: string, options?: {
|
|
3172
|
-
name?: string;
|
|
3173
|
-
metadata?: TUniversalMessageMetadata;
|
|
3174
|
-
parts?: TUniversalMessagePart[];
|
|
3175
|
-
}): IUserMessage;
|
|
3176
|
-
/** Create an assistant message. */
|
|
3177
|
-
declare function createAssistantMessage(content: string | null, options?: {
|
|
3178
|
-
toolCalls?: IToolCall[];
|
|
3179
|
-
metadata?: TUniversalMessageMetadata;
|
|
3180
|
-
parts?: TUniversalMessagePart[];
|
|
3181
|
-
state?: TMessageState;
|
|
3182
|
-
}): IAssistantMessage;
|
|
3183
|
-
/** Create a system message. */
|
|
3184
|
-
declare function createSystemMessage(content: string, options?: {
|
|
3185
|
-
name?: string;
|
|
3186
|
-
metadata?: TUniversalMessageMetadata;
|
|
3187
|
-
parts?: TUniversalMessagePart[];
|
|
3188
|
-
}): ISystemMessage;
|
|
3189
|
-
/** Create a tool message. */
|
|
3190
|
-
declare function createToolMessage(content: string, options: {
|
|
3191
|
-
toolCallId: string;
|
|
3192
|
-
name?: string;
|
|
3193
|
-
metadata?: TUniversalMessageMetadata;
|
|
3194
|
-
parts?: TUniversalMessagePart[];
|
|
3195
|
-
}): IToolMessage;
|
|
3196
|
-
|
|
3197
|
-
/** API message format for provider consumption */
|
|
3198
|
-
interface IProviderApiMessage {
|
|
3199
|
-
role: string;
|
|
3200
|
-
content: string | null;
|
|
3201
|
-
tool_calls?: Array<{
|
|
3202
|
-
id: string;
|
|
3203
|
-
type: 'function';
|
|
3204
|
-
function: {
|
|
3205
|
-
name: string;
|
|
3206
|
-
arguments: string;
|
|
3207
|
-
};
|
|
3208
|
-
}>;
|
|
3209
|
-
tool_call_id?: string;
|
|
3210
|
-
}
|
|
3211
|
-
/**
|
|
3212
|
-
* Conversation store with duplicate prevention and API format conversion.
|
|
3213
|
-
* @public
|
|
3214
|
-
*/
|
|
3215
|
-
declare class ConversationStore implements IConversationHistory {
|
|
3216
|
-
private history;
|
|
3217
|
-
private pendingAssistant;
|
|
3218
|
-
constructor(maxMessages?: number);
|
|
3219
|
-
addMessage(message: TUniversalMessage): void;
|
|
3220
|
-
addUserMessage(content: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3221
|
-
addAssistantMessage(content: string | null, toolCalls?: IToolCall[], metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3222
|
-
addSystemMessage(content: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3223
|
-
addToolMessage(content: string, toolCallId: string, toolName?: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3224
|
-
addToolMessageWithId(content: string, toolCallId: string, toolName: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3225
|
-
/** Add a raw history entry (events, etc.) */
|
|
3226
|
-
addEntry(entry: IHistoryEntry): void;
|
|
3227
|
-
/** Get all history entries (universal timeline) */
|
|
3228
|
-
getHistory(): IHistoryEntry[];
|
|
3229
|
-
getMessages(): TUniversalMessage[];
|
|
3230
|
-
getMessagesByRole(role: TUniversalMessageRole): TUniversalMessage[];
|
|
3231
|
-
getRecentMessages(count: number): TUniversalMessage[];
|
|
3232
|
-
getMessageCount(): number;
|
|
3233
|
-
/** Begin a new assistant response. Must be called before provider call.
|
|
3234
|
-
* Ensures pendingAssistant exists so commitAssistant always has data to save. */
|
|
3235
|
-
beginAssistant(): void;
|
|
3236
|
-
/** Append streaming text delta to pending assistant response */
|
|
3237
|
-
appendStreaming(delta: string): void;
|
|
3238
|
-
/** Append a tool call to pending assistant response (deduplicates by id) */
|
|
3239
|
-
appendToolCall(toolCall: IToolCall): void;
|
|
3240
|
-
/**
|
|
3241
|
-
* Commit pending assistant response to history.
|
|
3242
|
-
* Precondition: beginAssistant() must have been called before the provider call.
|
|
3243
|
-
* History is append-only — this always adds a message.
|
|
3244
|
-
*/
|
|
3245
|
-
commitAssistant(state: TMessageState, metadata?: TUniversalMessageMetadata): void;
|
|
3246
|
-
/** Discard pending assistant response without saving */
|
|
3247
|
-
discardPending(): void;
|
|
3248
|
-
/** Returns true if there is accumulated pending assistant state (streaming or tool calls) */
|
|
3249
|
-
hasPendingAssistant(): boolean;
|
|
3250
|
-
/** Get pending assistant content (empty string if no content streamed yet) */
|
|
3251
|
-
getPendingContent(): string;
|
|
3252
|
-
getMessagesForAPI(): IProviderApiMessage[];
|
|
3253
|
-
clear(): void;
|
|
3254
|
-
}
|
|
3255
|
-
|
|
3256
|
-
/** Interface for managing conversation history. @public */
|
|
3257
|
-
interface IConversationHistory {
|
|
3258
|
-
addMessage(message: TUniversalMessage): void;
|
|
3259
|
-
addUserMessage(content: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3260
|
-
addAssistantMessage(content: string | null, toolCalls?: IToolCall[], metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3261
|
-
addSystemMessage(content: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3262
|
-
addToolMessageWithId(content: string, toolCallId: string, toolName: string, metadata?: TUniversalMessageMetadata, parts?: TUniversalMessagePart[]): void;
|
|
3263
|
-
addEntry(entry: IHistoryEntry): void;
|
|
3264
|
-
getHistory(): IHistoryEntry[];
|
|
3265
|
-
getMessages(): TUniversalMessage[];
|
|
3266
|
-
getMessagesByRole(role: TUniversalMessageRole): TUniversalMessage[];
|
|
3267
|
-
getRecentMessages(count: number): TUniversalMessage[];
|
|
3268
|
-
clear(): void;
|
|
3269
|
-
getMessageCount(): number;
|
|
3270
|
-
}
|
|
3271
|
-
/** Configuration options for ConversationHistory manager */
|
|
3272
|
-
interface IConversationHistoryOptions {
|
|
3273
|
-
maxMessagesPerConversation?: number;
|
|
3274
|
-
maxConversations?: number;
|
|
3275
|
-
}
|
|
3276
|
-
/** Multi-session conversation history manager. @public */
|
|
3277
|
-
declare class ConversationHistory {
|
|
3278
|
-
private conversations;
|
|
3279
|
-
private logger;
|
|
3280
|
-
private readonly maxMessagesPerConversation;
|
|
3281
|
-
private readonly maxConversations;
|
|
3282
|
-
constructor(options?: IConversationHistoryOptions);
|
|
3283
|
-
getConversationStore(conversationId: string): ConversationStore;
|
|
3284
|
-
hasConversation(conversationId: string): boolean;
|
|
3285
|
-
removeConversation(conversationId: string): boolean;
|
|
3286
|
-
clearAll(): void;
|
|
3287
|
-
getStats(): {
|
|
3288
|
-
totalConversations: number;
|
|
3289
|
-
conversationIds: string[];
|
|
3290
|
-
totalMessages: number;
|
|
3291
|
-
};
|
|
3292
|
-
/** @internal */
|
|
3293
|
-
private cleanupOldConversations;
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
/**
|
|
3297
|
-
* Local executor that directly delegates to AI provider instances
|
|
3298
|
-
*
|
|
3299
|
-
* This executor maintains a registry of AI provider instances and delegates
|
|
3300
|
-
* chat execution requests to the appropriate provider based on the provider
|
|
3301
|
-
* name in the request. This is the "traditional" execution mode where
|
|
3302
|
-
* API calls are made directly from the client.
|
|
3303
|
-
*
|
|
3304
|
-
* @example
|
|
3305
|
-
* ```typescript
|
|
3306
|
-
* import { LocalExecutor } from '@robota-sdk/agent-core';
|
|
3307
|
-
* import { OpenAIProvider } from '@robota-sdk/agent-provider-openai';
|
|
3308
|
-
*
|
|
3309
|
-
* const executor = new LocalExecutor();
|
|
3310
|
-
* executor.registerProvider('openai', new OpenAIProvider({ apiKey: 'sk-...' }));
|
|
3311
|
-
*
|
|
3312
|
-
* const response = await executor.executeChat({
|
|
3313
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
3314
|
-
* provider: 'openai',
|
|
3315
|
-
* model: 'gpt-4'
|
|
3316
|
-
* });
|
|
3317
|
-
* ```
|
|
3318
|
-
*/
|
|
3319
|
-
declare class LocalExecutor extends AbstractExecutor {
|
|
3320
|
-
readonly name = "local";
|
|
3321
|
-
readonly version = "1.0.0";
|
|
3322
|
-
private providers;
|
|
3323
|
-
private config;
|
|
3324
|
-
constructor(config?: ILocalExecutorConfig);
|
|
3325
|
-
/**
|
|
3326
|
-
* Register an AI provider instance for use with this executor
|
|
3327
|
-
*
|
|
3328
|
-
* @param name - Provider name (e.g., 'openai', 'anthropic', 'google')
|
|
3329
|
-
* @param provider - Provider instance that implements the required chat methods
|
|
3330
|
-
*/
|
|
3331
|
-
registerProvider(name: string, provider: IAIProviderInstance): void;
|
|
3332
|
-
/**
|
|
3333
|
-
* Unregister an AI provider
|
|
3334
|
-
*
|
|
3335
|
-
* @param name - Provider name to remove
|
|
3336
|
-
*/
|
|
3337
|
-
unregisterProvider(name: string): void;
|
|
3338
|
-
/**
|
|
3339
|
-
* Get registered provider instance
|
|
3340
|
-
*
|
|
3341
|
-
* @param name - Provider name
|
|
3342
|
-
* @returns Provider instance or undefined if not registered
|
|
3343
|
-
*/
|
|
3344
|
-
getProvider(name: string): IAIProviderInstance | undefined;
|
|
3345
|
-
/**
|
|
3346
|
-
* Execute a chat completion request by delegating to the appropriate provider
|
|
3347
|
-
*/
|
|
3348
|
-
executeChat(request: IChatExecutionRequest): Promise<IAssistantMessage>;
|
|
3349
|
-
/**
|
|
3350
|
-
* Execute a streaming chat completion request
|
|
3351
|
-
*/
|
|
3352
|
-
executeChatStream(request: IStreamExecutionRequest): AsyncIterable<TUniversalMessage>;
|
|
3353
|
-
/**
|
|
3354
|
-
* Check if any registered providers support tools
|
|
3355
|
-
*/
|
|
3356
|
-
supportsTools(): boolean;
|
|
3357
|
-
/**
|
|
3358
|
-
* Validate executor configuration and all registered providers
|
|
3359
|
-
*/
|
|
3360
|
-
validateConfig(): boolean;
|
|
3361
|
-
/**
|
|
3362
|
-
* Clean up all registered providers
|
|
3363
|
-
*/
|
|
3364
|
-
dispose(): Promise<void>;
|
|
3365
|
-
}
|
|
3366
|
-
/**
|
|
3367
|
-
* Interface that AI provider instances must implement to work with LocalExecutor
|
|
3368
|
-
*
|
|
3369
|
-
* This interface represents the subset of AI provider methods that LocalExecutor
|
|
3370
|
-
* needs to delegate to. It's designed to be compatible with existing BaseAIProvider
|
|
3371
|
-
* implementations from @robota-sdk packages.
|
|
3372
|
-
*/
|
|
3373
|
-
interface IAIProviderInstance {
|
|
3374
|
-
/** Provider name */
|
|
3375
|
-
readonly name?: string;
|
|
3376
|
-
/** Chat completion method */
|
|
3377
|
-
chat?(messages: TUniversalMessage[], options?: IChatOptions): Promise<TUniversalMessage>;
|
|
3378
|
-
/** Streaming chat completion method */
|
|
3379
|
-
chatStream?(messages: TUniversalMessage[], options?: IChatOptions): AsyncIterable<TUniversalMessage>;
|
|
3380
|
-
/** Check if provider supports tools */
|
|
3381
|
-
supportsTools?(): boolean;
|
|
3382
|
-
/** Validate provider configuration */
|
|
3383
|
-
validateConfig?(): boolean;
|
|
3384
|
-
/** Clean up provider resources */
|
|
3385
|
-
dispose?(): Promise<void>;
|
|
3386
|
-
}
|
|
3387
|
-
|
|
3388
|
-
interface IEventEmitterMetricsSnapshot {
|
|
3389
|
-
totalEmitted: number;
|
|
3390
|
-
totalErrors: number;
|
|
3391
|
-
}
|
|
3392
|
-
interface IEventEmitterMetrics {
|
|
3393
|
-
incrementEmitted(): void;
|
|
3394
|
-
incrementErrors(): void;
|
|
3395
|
-
getSnapshot(): IEventEmitterMetricsSnapshot;
|
|
3396
|
-
}
|
|
3397
|
-
declare class InMemoryEventEmitterMetrics implements IEventEmitterMetrics {
|
|
3398
|
-
private totalEmitted;
|
|
3399
|
-
private totalErrors;
|
|
3400
|
-
incrementEmitted(): void;
|
|
3401
|
-
incrementErrors(): void;
|
|
3402
|
-
getSnapshot(): IEventEmitterMetricsSnapshot;
|
|
3403
|
-
}
|
|
3404
|
-
|
|
3405
|
-
/**
|
|
3406
|
-
* Type definitions for EventEmitterPlugin.
|
|
3407
|
-
*
|
|
3408
|
-
* Extracted from event-emitter-plugin.ts to keep each file under 300 lines.
|
|
3409
|
-
*/
|
|
3410
|
-
|
|
3411
|
-
/** Enhanced event data for hierarchical execution tracking */
|
|
3412
|
-
interface IEventEmitterHierarchicalEventData extends IEventEmitterEventData {
|
|
3413
|
-
parentExecutionId?: string;
|
|
3414
|
-
rootExecutionId?: string;
|
|
3415
|
-
executionLevel: number;
|
|
3416
|
-
executionPath: string[];
|
|
3417
|
-
realTimeData?: {
|
|
3418
|
-
startTime: Date;
|
|
3419
|
-
actualDuration?: number;
|
|
3420
|
-
actualParameters?: TToolParameters;
|
|
3421
|
-
actualResult?: IToolResult;
|
|
3422
|
-
};
|
|
3423
|
-
}
|
|
3424
|
-
/** Event emitter configuration */
|
|
3425
|
-
interface IEventEmitterPluginOptions extends IPluginOptions {
|
|
3426
|
-
events?: TEventName[];
|
|
3427
|
-
maxListeners?: number;
|
|
3428
|
-
async?: boolean;
|
|
3429
|
-
catchErrors?: boolean;
|
|
3430
|
-
filters?: Record<TEventName, (event: IEventEmitterEventData) => boolean>;
|
|
3431
|
-
buffer?: {
|
|
3432
|
-
enabled: boolean;
|
|
3433
|
-
maxSize: number;
|
|
3434
|
-
flushInterval: number;
|
|
3435
|
-
};
|
|
3436
|
-
metrics?: IEventEmitterMetrics;
|
|
3437
|
-
}
|
|
3438
|
-
/** Event emitter plugin statistics */
|
|
3439
|
-
interface IEventEmitterPluginStats extends IPluginStats {
|
|
3440
|
-
eventTypes: TEventName[];
|
|
3441
|
-
listenerCounts: Partial<Record<TEventName, number>>;
|
|
3442
|
-
totalListeners: number;
|
|
3443
|
-
bufferedEvents: number;
|
|
3444
|
-
totalEmitted: number;
|
|
3445
|
-
totalErrors: number;
|
|
3446
|
-
}
|
|
3447
|
-
|
|
3448
|
-
/**
|
|
3449
|
-
* Provides pub/sub event coordination during the agent execution lifecycle.
|
|
3450
|
-
* @extends AbstractPlugin
|
|
3451
|
-
* @see IEventEmitterPluginOptions
|
|
3452
|
-
* @see EVENT_EMITTER_EVENTS
|
|
3453
|
-
*/
|
|
3454
|
-
declare class EventEmitterPlugin extends AbstractPlugin<IEventEmitterPluginOptions, IEventEmitterPluginStats> {
|
|
3455
|
-
name: string;
|
|
3456
|
-
version: string;
|
|
3457
|
-
private pluginOptions;
|
|
3458
|
-
private logger;
|
|
3459
|
-
private handlers;
|
|
3460
|
-
private eventBuffer;
|
|
3461
|
-
private nextHandlerId;
|
|
3462
|
-
private bufferTimer?;
|
|
3463
|
-
private metrics;
|
|
3464
|
-
constructor(options?: IEventEmitterPluginOptions);
|
|
3465
|
-
beforeExecution(context: IPluginExecutionContext): Promise<void>;
|
|
3466
|
-
afterExecution(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void>;
|
|
3467
|
-
beforeConversation(context: IPluginExecutionContext): Promise<void>;
|
|
3468
|
-
afterConversation(context: IPluginExecutionContext, result: IPluginExecutionResult): Promise<void>;
|
|
3469
|
-
beforeToolExecution(context: IPluginExecutionContext, toolData: IToolExecutionContext): Promise<void>;
|
|
3470
|
-
afterToolExecution(context: IPluginExecutionContext, toolResults: IPluginExecutionResult): Promise<void>;
|
|
3471
|
-
onError(error: Error, context?: IPluginErrorContext): Promise<void>;
|
|
3472
|
-
on(eventType: TEventName, listener: TEventEmitterListener, options?: {
|
|
3473
|
-
once?: boolean;
|
|
3474
|
-
filter?: (event: IEventEmitterEventData) => boolean;
|
|
3475
|
-
}): string;
|
|
3476
|
-
once(eventType: TEventName, listener: TEventEmitterListener, filter?: (event: IEventEmitterEventData) => boolean): string;
|
|
3477
|
-
off(eventType: TEventName, handlerIdOrListener: string | TEventEmitterListener): boolean;
|
|
3478
|
-
emit(eventType: TEventName, eventData?: Partial<IEventEmitterEventData>): Promise<void>;
|
|
3479
|
-
private processEvent;
|
|
3480
|
-
flushBuffer(): Promise<void>;
|
|
3481
|
-
getStats(): IEventEmitterPluginStats;
|
|
3482
|
-
clearAllListeners(): void;
|
|
3483
|
-
destroy(): Promise<void>;
|
|
3484
|
-
}
|
|
3485
|
-
|
|
3486
|
-
/**
|
|
3487
|
-
* Configuration and tool management delegate for the Robota agent.
|
|
3488
|
-
*
|
|
3489
|
-
* Extracted from robota.ts to keep the main class under 300 lines.
|
|
3490
|
-
*/
|
|
3491
|
-
|
|
3492
|
-
/** Agent statistics metadata type */
|
|
3493
|
-
type TAgentStatsMetadata = Record<string, string | number | boolean | Date | string[]>;
|
|
3494
|
-
|
|
3495
|
-
/** Shared model configuration shape used in setModel / getModel. */
|
|
3496
|
-
type TModelConfig = {
|
|
3497
|
-
provider: string;
|
|
3498
|
-
model: string;
|
|
3499
|
-
temperature?: number;
|
|
3500
|
-
maxTokens?: number;
|
|
3501
|
-
topP?: number;
|
|
3502
|
-
systemMessage?: string;
|
|
3503
|
-
};
|
|
3504
|
-
/** Return shape of getConfiguration(). */
|
|
3505
|
-
type TConfigurationSnapshot = {
|
|
3506
|
-
version: number;
|
|
3507
|
-
tools: Array<{
|
|
3508
|
-
name: string;
|
|
3509
|
-
parameters?: string[];
|
|
3510
|
-
}>;
|
|
3511
|
-
updatedAt: number;
|
|
3512
|
-
};
|
|
3513
|
-
/** Return shape of getModuleStats(). */
|
|
3514
|
-
type TModuleStats = {
|
|
3515
|
-
totalExecutions: number;
|
|
3516
|
-
successfulExecutions: number;
|
|
3517
|
-
failedExecutions: number;
|
|
3518
|
-
averageExecutionTime: number;
|
|
3519
|
-
lastExecutionTime?: Date;
|
|
3520
|
-
} | undefined;
|
|
3521
|
-
/** Shorthand for the plugin contract type used throughout this class. */
|
|
3522
|
-
type TPlugin = IPluginContract<IPluginOptions, IPluginStats> & IPluginHooks;
|
|
3523
|
-
/**
|
|
3524
|
-
* Core AI agent integrating multiple AI providers, tools, and plugins
|
|
3525
|
-
* into a unified conversational interface.
|
|
3526
|
-
* @public
|
|
3527
|
-
*/
|
|
3528
|
-
declare class Robota extends AbstractAgent<IAgentConfig, IRunOptions, TUniversalMessage> implements IAgent<IAgentConfig, IRunOptions, TUniversalMessage> {
|
|
3529
|
-
readonly name: string;
|
|
3530
|
-
readonly version: string;
|
|
3531
|
-
private aiProviders;
|
|
3532
|
-
private tools;
|
|
3533
|
-
private agentFactory;
|
|
3534
|
-
private conversationHistory;
|
|
3535
|
-
private moduleRegistry;
|
|
3536
|
-
private eventEmitter;
|
|
3537
|
-
private executionService;
|
|
3538
|
-
private eventService;
|
|
3539
|
-
private agentEventService;
|
|
3540
|
-
protected config: IAgentConfig;
|
|
3541
|
-
private conversationId;
|
|
3542
|
-
private logger;
|
|
3543
|
-
private initializationPromise?;
|
|
3544
|
-
private isFullyInitialized;
|
|
3545
|
-
private startTime;
|
|
3546
|
-
private configVersion;
|
|
3547
|
-
private configUpdatedAt;
|
|
3548
|
-
private moduleManager;
|
|
3549
|
-
private pluginManager;
|
|
3550
|
-
private configManager;
|
|
3551
|
-
constructor(config: IAgentConfig);
|
|
3552
|
-
run(input: string, options?: IRunOptions): Promise<string>;
|
|
3553
|
-
runStream(input: string, options?: IRunOptions): AsyncGenerator<string, void, undefined>;
|
|
3554
|
-
private executionDeps;
|
|
3555
|
-
getHistory(): TUniversalMessage[];
|
|
3556
|
-
getFullHistory(): IHistoryEntry[];
|
|
3557
|
-
addHistoryEntry(entry: IHistoryEntry): void;
|
|
3558
|
-
clearHistory(): void;
|
|
3559
|
-
injectMessage(role: 'user' | 'assistant' | 'system' | 'tool', content: string, options?: {
|
|
3560
|
-
toolCallId?: string;
|
|
3561
|
-
name?: string;
|
|
3562
|
-
}): void;
|
|
3563
|
-
updateTools(next: Array<IToolWithEventService>): Promise<{
|
|
3564
|
-
version: number;
|
|
3565
|
-
}>;
|
|
3566
|
-
updateConfiguration(patch: Partial<IAgentConfig>): Promise<{
|
|
3567
|
-
version: number;
|
|
3568
|
-
}>;
|
|
3569
|
-
getConfiguration(): Promise<TConfigurationSnapshot>;
|
|
3570
|
-
setModel(mc: TModelConfig): void;
|
|
3571
|
-
getModel(): TModelConfig;
|
|
3572
|
-
registerTool(tool: AbstractTool): void;
|
|
3573
|
-
unregisterTool(toolName: string): void;
|
|
3574
|
-
getConfig(): IAgentConfig;
|
|
3575
|
-
addPlugin(plugin: TPlugin): void;
|
|
3576
|
-
removePlugin(pluginName: string): boolean;
|
|
3577
|
-
getPlugin(pluginName: string): TPlugin | undefined;
|
|
3578
|
-
getPlugins(): TPlugin[];
|
|
3579
|
-
getPluginNames(): string[];
|
|
3580
|
-
registerModule(module: IModule, options?: {
|
|
3581
|
-
autoInitialize?: boolean;
|
|
3582
|
-
validateDependencies?: boolean;
|
|
3583
|
-
}): Promise<void>;
|
|
3584
|
-
unregisterModule(moduleName: string): Promise<boolean>;
|
|
3585
|
-
getModule(moduleName: string): IModule | undefined;
|
|
3586
|
-
getModulesByType(moduleType: string): IModule[];
|
|
3587
|
-
getModules(): IModule[];
|
|
3588
|
-
getModuleNames(): string[];
|
|
3589
|
-
hasModule(moduleName: string): boolean;
|
|
3590
|
-
executeModule(moduleName: string, context: {
|
|
3591
|
-
executionId?: string;
|
|
3592
|
-
sessionId?: string;
|
|
3593
|
-
userId?: string;
|
|
3594
|
-
metadata?: Record<string, string | number | boolean | Date>;
|
|
3595
|
-
}): Promise<{
|
|
3596
|
-
success: boolean;
|
|
3597
|
-
data?: IModuleResultData;
|
|
3598
|
-
error?: Error;
|
|
3599
|
-
duration?: number;
|
|
3600
|
-
}>;
|
|
3601
|
-
getModuleStats(moduleName: string): TModuleStats;
|
|
3602
|
-
getStats(): {
|
|
3603
|
-
name: string;
|
|
3604
|
-
version: string;
|
|
3605
|
-
conversationId: string;
|
|
3606
|
-
providers: string[];
|
|
3607
|
-
currentProvider: string | null;
|
|
3608
|
-
tools: string[];
|
|
3609
|
-
plugins: string[];
|
|
3610
|
-
modules: string[];
|
|
3611
|
-
historyLength: number;
|
|
3612
|
-
historyStats: TAgentStatsMetadata;
|
|
3613
|
-
uptime: number;
|
|
3614
|
-
};
|
|
3615
|
-
destroy(): Promise<void>;
|
|
3616
|
-
protected initialize(): Promise<void>;
|
|
3617
|
-
private ensureFullyInitialized;
|
|
3618
|
-
private doAsyncInit;
|
|
3619
|
-
private emitAgentEvent;
|
|
3620
|
-
}
|
|
3621
|
-
|
|
3622
|
-
/**
|
|
3623
|
-
* Template application result
|
|
3624
|
-
*/
|
|
3625
|
-
interface ITemplateApplicationResult {
|
|
3626
|
-
/** Applied configuration */
|
|
3627
|
-
config: IAgentConfig;
|
|
3628
|
-
/** Template that was applied */
|
|
3629
|
-
template: IAgentTemplate;
|
|
3630
|
-
/** Any warnings during application */
|
|
3631
|
-
warnings: string[];
|
|
3632
|
-
/** Whether config was modified during application */
|
|
3633
|
-
modified: boolean;
|
|
3634
|
-
}
|
|
3635
|
-
/**
|
|
3636
|
-
* Agent Templates implementation
|
|
3637
|
-
* Manages agent templates for AgentFactory
|
|
3638
|
-
* Instance-based for isolated template management
|
|
3639
|
-
*/
|
|
3640
|
-
declare class AgentTemplates {
|
|
3641
|
-
private templates;
|
|
3642
|
-
private logger;
|
|
3643
|
-
constructor();
|
|
3644
|
-
/**
|
|
3645
|
-
* Register a template
|
|
3646
|
-
*/
|
|
3647
|
-
registerTemplate(template: IAgentTemplate): void;
|
|
3648
|
-
/**
|
|
3649
|
-
* Unregister a template
|
|
3650
|
-
*/
|
|
3651
|
-
unregisterTemplate(templateId: string): boolean;
|
|
3652
|
-
/**
|
|
3653
|
-
* Get all templates
|
|
3654
|
-
*/
|
|
3655
|
-
getTemplates(): IAgentTemplate[];
|
|
3656
|
-
/**
|
|
3657
|
-
* Get template by ID
|
|
3658
|
-
*/
|
|
3659
|
-
getTemplate(templateId: string): IAgentTemplate | undefined;
|
|
3660
|
-
/**
|
|
3661
|
-
* Find templates by criteria
|
|
3662
|
-
*/
|
|
3663
|
-
findTemplates(criteria: {
|
|
3664
|
-
category?: string;
|
|
3665
|
-
tags?: string[];
|
|
3666
|
-
provider?: string;
|
|
3667
|
-
model?: string;
|
|
3668
|
-
}): IAgentTemplate[];
|
|
3669
|
-
/**
|
|
3670
|
-
* Apply template to configuration
|
|
3671
|
-
*/
|
|
3672
|
-
applyTemplate(template: IAgentTemplate, overrides?: Partial<IAgentConfig>): ITemplateApplicationResult;
|
|
3673
|
-
/**
|
|
3674
|
-
* Check if template exists
|
|
3675
|
-
*/
|
|
3676
|
-
hasTemplate(templateId: string): boolean;
|
|
3677
|
-
/**
|
|
3678
|
-
* Get template count
|
|
3679
|
-
*/
|
|
3680
|
-
getTemplateCount(): number;
|
|
3681
|
-
/**
|
|
3682
|
-
* Clear all templates
|
|
3683
|
-
*/
|
|
3684
|
-
clearAll(): void;
|
|
3685
|
-
/**
|
|
3686
|
-
* Get template statistics
|
|
3687
|
-
*/
|
|
3688
|
-
getStats(): {
|
|
3689
|
-
totalTemplates: number;
|
|
3690
|
-
categories: string[];
|
|
3691
|
-
tags: string[];
|
|
3692
|
-
providers: string[];
|
|
3693
|
-
models: string[];
|
|
3694
|
-
};
|
|
3695
|
-
}
|
|
3696
|
-
|
|
3697
|
-
/**
|
|
3698
|
-
* Configuration options for AgentFactory
|
|
3699
|
-
*/
|
|
3700
|
-
interface IAgentFactoryOptions {
|
|
3701
|
-
/** Default model to use if not specified in config */
|
|
3702
|
-
defaultModel?: string;
|
|
3703
|
-
/** Default provider to use if not specified in config */
|
|
3704
|
-
defaultProvider?: string;
|
|
3705
|
-
/** Maximum number of concurrent agents */
|
|
3706
|
-
maxConcurrentAgents?: number;
|
|
3707
|
-
/** Default system message for agents */
|
|
3708
|
-
defaultSystemMessage?: string;
|
|
3709
|
-
/** Enable strict configuration validation */
|
|
3710
|
-
strictValidation?: boolean;
|
|
3711
|
-
}
|
|
3712
|
-
/**
|
|
3713
|
-
* Agent creation statistics
|
|
3714
|
-
*/
|
|
3715
|
-
interface IAgentCreationStats {
|
|
3716
|
-
/** Total number of agents created */
|
|
3717
|
-
totalCreated: number;
|
|
3718
|
-
/** Number of currently active agents */
|
|
3719
|
-
activeCount: number;
|
|
3720
|
-
/** Number of agents created from templates */
|
|
3721
|
-
fromTemplates: number;
|
|
3722
|
-
/** Number of custom configured agents */
|
|
3723
|
-
customConfigured: number;
|
|
3724
|
-
/** Template vs custom creation ratio (fromTemplates / totalCreated) */
|
|
3725
|
-
templateUsageRatio: number;
|
|
3726
|
-
}
|
|
3727
|
-
/**
|
|
3728
|
-
* Agent lifecycle events
|
|
3729
|
-
*/
|
|
3730
|
-
interface IAgentLifecycleEvents {
|
|
3731
|
-
/** Called before agent creation */
|
|
3732
|
-
beforeCreate?: (config: IAgentConfig) => Promise<void> | void;
|
|
3733
|
-
/** Called after successful agent creation */
|
|
3734
|
-
afterCreate?: (agent: IAgent<IAgentConfig>, config: IAgentConfig) => Promise<void> | void;
|
|
3735
|
-
/** Called when agent creation fails */
|
|
3736
|
-
onCreateError?: (error: Error, config: IAgentConfig) => Promise<void> | void;
|
|
3737
|
-
/** Called when agent is destroyed */
|
|
3738
|
-
onDestroy?: (agentId: string) => Promise<void> | void;
|
|
3739
|
-
}
|
|
3740
|
-
|
|
3741
|
-
/**
|
|
3742
|
-
* Agent Factory for creating and managing agents
|
|
3743
|
-
* Instance-based for isolated agent factory management
|
|
3744
|
-
*/
|
|
3745
|
-
declare class AgentFactory {
|
|
3746
|
-
private agentTemplates;
|
|
3747
|
-
private initialized;
|
|
3748
|
-
private logger;
|
|
3749
|
-
private options;
|
|
3750
|
-
private activeAgents;
|
|
3751
|
-
private creationStats;
|
|
3752
|
-
private lifecycleEvents;
|
|
3753
|
-
constructor(options?: IAgentFactoryOptions, lifecycleEvents?: IAgentLifecycleEvents);
|
|
3754
|
-
/**
|
|
3755
|
-
* Initialize the factory
|
|
3756
|
-
*/
|
|
3757
|
-
initialize(): Promise<void>;
|
|
3758
|
-
/**
|
|
3759
|
-
* Create a new agent instance
|
|
3760
|
-
*/
|
|
3761
|
-
createAgent(AgentClass: new (config: IAgentConfig) => IAgent<IAgentConfig>, config: Partial<IAgentConfig>, fromTemplate?: boolean): Promise<IAgent<IAgentConfig>>;
|
|
3762
|
-
/**
|
|
3763
|
-
* Create agent from template
|
|
3764
|
-
*/
|
|
3765
|
-
createFromTemplate(AgentClass: new (config: IAgentConfig) => IAgent<IAgentConfig>, templateId: string, overrides?: Partial<IAgentConfig>): Promise<IAgent<IAgentConfig>>;
|
|
3766
|
-
/**
|
|
3767
|
-
* Register a template
|
|
3768
|
-
*/
|
|
3769
|
-
registerTemplate(template: IAgentTemplate): void;
|
|
3770
|
-
/**
|
|
3771
|
-
* Unregister a template
|
|
3772
|
-
*/
|
|
3773
|
-
unregisterTemplate(templateId: string): boolean;
|
|
3774
|
-
/**
|
|
3775
|
-
* Get all templates
|
|
3776
|
-
*/
|
|
3777
|
-
getTemplates(): IAgentTemplate[];
|
|
3778
|
-
/**
|
|
3779
|
-
* Get template by ID
|
|
3780
|
-
*/
|
|
3781
|
-
getTemplate(templateId: string): IAgentTemplate | undefined;
|
|
3782
|
-
/**
|
|
3783
|
-
* Find templates by criteria
|
|
3784
|
-
*/
|
|
3785
|
-
findTemplates(criteria: {
|
|
3786
|
-
category?: string;
|
|
3787
|
-
tags?: string[];
|
|
3788
|
-
provider?: string;
|
|
3789
|
-
model?: string;
|
|
3790
|
-
}): IAgentTemplate[];
|
|
3791
|
-
/**
|
|
3792
|
-
* Apply template to configuration
|
|
3793
|
-
*/
|
|
3794
|
-
applyTemplate(template: IAgentTemplate, overrides?: Partial<IAgentConfig>): ITemplateApplicationResult;
|
|
3795
|
-
/**
|
|
3796
|
-
* Destroy an agent
|
|
3797
|
-
*/
|
|
3798
|
-
destroyAgent(agentId: string): Promise<boolean>;
|
|
3799
|
-
/**
|
|
3800
|
-
* Get creation statistics
|
|
3801
|
-
*/
|
|
3802
|
-
getCreationStats(): IAgentCreationStats;
|
|
3803
|
-
/**
|
|
3804
|
-
* Get all active agents
|
|
3805
|
-
*/
|
|
3806
|
-
getActiveAgents(): Map<string, IAgent<IAgentConfig>>;
|
|
3807
|
-
/**
|
|
3808
|
-
* Validate agent configuration
|
|
3809
|
-
*/
|
|
3810
|
-
validateConfiguration(config: Partial<IAgentConfig>): {
|
|
3811
|
-
isValid: boolean;
|
|
3812
|
-
errors: string[];
|
|
3813
|
-
};
|
|
3814
|
-
}
|
|
3815
|
-
|
|
3816
|
-
interface IAssistantUsageMetadata {
|
|
3817
|
-
inputTokens: number;
|
|
3818
|
-
outputTokens: number;
|
|
3819
|
-
usage: {
|
|
3820
|
-
totalTokens: number;
|
|
3821
|
-
inputTokens: number;
|
|
3822
|
-
outputTokens: number;
|
|
3823
|
-
};
|
|
3824
|
-
}
|
|
3825
|
-
declare function collectAssistantUsageMetadata(message: TUniversalMessage): IAssistantUsageMetadata | undefined;
|
|
3826
|
-
|
|
3827
|
-
declare class EventHistoryModule implements IEventHistoryModule {
|
|
3828
|
-
private readonly store;
|
|
3829
|
-
private readonly listener;
|
|
3830
|
-
private sequenceId;
|
|
3831
|
-
constructor(store: IEventHistoryModule, eventService: IEventService);
|
|
3832
|
-
append(record: IEventHistoryRecord): void;
|
|
3833
|
-
read(fromSequenceId: number, toSequenceId?: number): IEventHistoryRecord[];
|
|
3834
|
-
readStream(fromSequenceId: number, toSequenceId?: number): AsyncIterable<IEventHistoryRecord>;
|
|
3835
|
-
getSnapshot(): IEventHistorySnapshot | undefined;
|
|
3836
|
-
detach(eventService: IEventService): void;
|
|
3837
|
-
private nextSequenceId;
|
|
3838
|
-
}
|
|
3839
|
-
|
|
3840
|
-
/**
|
|
3841
|
-
* ExecutionService owned events.
|
|
3842
|
-
* Local event names only (no dots). Full names are composed at emit time.
|
|
3843
|
-
*/
|
|
3844
|
-
declare const EXECUTION_EVENTS: {
|
|
3845
|
-
readonly START: "start";
|
|
3846
|
-
readonly COMPLETE: "complete";
|
|
3847
|
-
readonly ERROR: "error";
|
|
3848
|
-
readonly ASSISTANT_MESSAGE_START: "assistant_message_start";
|
|
3849
|
-
readonly ASSISTANT_MESSAGE_COMPLETE: "assistant_message_complete";
|
|
3850
|
-
readonly USER_MESSAGE: "user_message";
|
|
3851
|
-
readonly TOOL_RESULTS_TO_LLM: "tool_results_to_llm";
|
|
3852
|
-
readonly TOOL_RESULTS_READY: "tool_results_ready";
|
|
3853
|
-
};
|
|
3854
|
-
declare const EXECUTION_EVENT_PREFIX: "execution";
|
|
3855
|
-
|
|
3856
|
-
/**
|
|
3857
|
-
* ToolExecutionService owned events
|
|
3858
|
-
* Local event names only (no dots). Full names are composed at emit time.
|
|
3859
|
-
*/
|
|
3860
|
-
declare const TOOL_EVENTS: {
|
|
3861
|
-
readonly CALL_START: "call_start";
|
|
3862
|
-
readonly CALL_COMPLETE: "call_complete";
|
|
3863
|
-
readonly CALL_ERROR: "call_error";
|
|
3864
|
-
readonly CALL_RESPONSE_READY: "call_response_ready";
|
|
3865
|
-
};
|
|
3866
|
-
declare const TOOL_EVENT_PREFIX: "tool";
|
|
3867
|
-
|
|
3868
|
-
/**
|
|
3869
|
-
* Agent event constants
|
|
3870
|
-
*
|
|
3871
|
-
* Events emitted by Agent instances themselves.
|
|
3872
|
-
* Event names are local (no dots) and must be used via constants (no string literals).
|
|
3873
|
-
*/
|
|
3874
|
-
declare const AGENT_EVENTS: {
|
|
3875
|
-
/** Agent instance has been created and initialized */
|
|
3876
|
-
readonly CREATED: "created";
|
|
3877
|
-
/** Agent execution lifecycle - start */
|
|
3878
|
-
readonly EXECUTION_START: "execution_start";
|
|
3879
|
-
/** Agent execution lifecycle - complete */
|
|
3880
|
-
readonly EXECUTION_COMPLETE: "execution_complete";
|
|
3881
|
-
/** Agent execution lifecycle - error */
|
|
3882
|
-
readonly EXECUTION_ERROR: "execution_error";
|
|
3883
|
-
/** Agent aggregation process completed */
|
|
3884
|
-
readonly AGGREGATION_COMPLETE: "aggregation_complete";
|
|
3885
|
-
/** Agent configuration (e.g., tools) has been updated by the agent */
|
|
3886
|
-
readonly CONFIG_UPDATED: "config_updated";
|
|
3887
|
-
};
|
|
3888
|
-
declare const AGENT_EVENT_PREFIX: "agent";
|
|
3889
|
-
|
|
3890
|
-
/**
|
|
3891
|
-
* Workflow Converter Interface
|
|
3892
|
-
*
|
|
3893
|
-
* Defines the contract for all workflow converters in the Robota SDK.
|
|
3894
|
-
* Follows Interface Segregation Principle by providing minimal, focused interface.
|
|
3895
|
-
*
|
|
3896
|
-
* @template TInput - Input workflow data type
|
|
3897
|
-
* @template TOutput - Output workflow data type
|
|
3898
|
-
*/
|
|
3899
|
-
|
|
3900
|
-
/**
|
|
3901
|
-
* Workflow configuration - uses base type for cross-converter compatibility
|
|
3902
|
-
* Step 1: ❌ Can't assign number/boolean to config value type directly (index signature conflict)
|
|
3903
|
-
* Step 2: ✅ TConfigValue already includes primitive types (number, boolean)
|
|
3904
|
-
* Step 3: ✅ Fix index signature to allow optional properties
|
|
3905
|
-
* Step 4: ✅ Use proper intersection type for compatibility
|
|
3906
|
-
*/
|
|
3907
|
-
interface IWorkflowConfig {
|
|
3908
|
-
timeout?: number;
|
|
3909
|
-
retries?: number;
|
|
3910
|
-
validateInput?: boolean;
|
|
3911
|
-
validateOutput?: boolean;
|
|
3912
|
-
[key: string]: TConfigValue | undefined;
|
|
3913
|
-
}
|
|
3914
|
-
/**
|
|
3915
|
-
* Workflow metadata - uses base type for cross-converter compatibility
|
|
3916
|
-
* Step 1: ❌ Can't assign Date/number/string to metadata value type directly (index signature conflict)
|
|
3917
|
-
* Step 2: ✅ TMetadataValue already includes Date, primitive types
|
|
3918
|
-
* Step 3: ✅ Fix index signature to allow optional properties
|
|
3919
|
-
* Step 4: ✅ Use proper intersection type for compatibility
|
|
3920
|
-
*/
|
|
3921
|
-
interface IWorkflowMetadata {
|
|
3922
|
-
convertedAt?: Date;
|
|
3923
|
-
processingTime?: number;
|
|
3924
|
-
executionId?: string;
|
|
3925
|
-
[key: string]: TMetadataValue | undefined;
|
|
3926
|
-
}
|
|
3927
|
-
/**
|
|
3928
|
-
* Base workflow data constraint with flexible typing
|
|
3929
|
-
* All workflow data must extend this interface for type safety
|
|
3930
|
-
*/
|
|
3931
|
-
interface IWorkflowData {
|
|
3932
|
-
readonly __workflowType?: string;
|
|
3933
|
-
[key: string]: TUniversalValue | undefined;
|
|
3934
|
-
}
|
|
3935
|
-
/**
|
|
3936
|
-
* Conversion options for workflow transformations
|
|
3937
|
-
* Step 1: ❌ Can't assign IWorkflowConversionOptions to metadata value type (missing index signature)
|
|
3938
|
-
* Step 2: ✅ Add index signature to make it compatible with MetadataValue
|
|
3939
|
-
* Step 3: ✅ Maintain type safety while allowing metadata storage
|
|
3940
|
-
* Step 4: ✅ Use MetadataValue compatibility for dynamic properties
|
|
3941
|
-
*/
|
|
3942
|
-
interface IWorkflowConversionOptions {
|
|
3943
|
-
/** Include debug information in output */
|
|
3944
|
-
includeDebug?: boolean;
|
|
3945
|
-
/** Validate input before conversion */
|
|
3946
|
-
validateInput?: boolean;
|
|
3947
|
-
/** Validate output after conversion */
|
|
3948
|
-
validateOutput?: boolean;
|
|
3949
|
-
/** Custom logger for conversion process */
|
|
3950
|
-
logger?: ILogger;
|
|
3951
|
-
/** Additional metadata to include */
|
|
3952
|
-
metadata?: IWorkflowMetadata;
|
|
3953
|
-
/** Platform-specific options */
|
|
3954
|
-
platformOptions?: IWorkflowConfig;
|
|
3955
|
-
/** Additional dynamic options compatible with TUniversalValue */
|
|
3956
|
-
[key: string]: TUniversalValue | ILogger | IWorkflowMetadata | IWorkflowConfig | undefined;
|
|
3957
|
-
}
|
|
3958
|
-
/**
|
|
3959
|
-
* Conversion result with metadata and validation info
|
|
3960
|
-
*/
|
|
3961
|
-
interface IWorkflowConversionResult<TOutput> {
|
|
3962
|
-
/** Converted workflow data */
|
|
3963
|
-
data: TOutput;
|
|
3964
|
-
/** Conversion success status */
|
|
3965
|
-
success: boolean;
|
|
3966
|
-
/** Validation errors (if any) */
|
|
3967
|
-
errors: string[];
|
|
3968
|
-
/** Validation warnings (if any) */
|
|
3969
|
-
warnings: string[];
|
|
3970
|
-
/** Conversion metadata */
|
|
3971
|
-
metadata: IWorkflowConversionResultMetadata;
|
|
3972
|
-
}
|
|
3973
|
-
/**
|
|
3974
|
-
* Workflow conversion metadata.
|
|
3975
|
-
*
|
|
3976
|
-
* IMPORTANT:
|
|
3977
|
-
* - Do NOT intersect this object with `TMetadata`.
|
|
3978
|
-
* - `TMetadata` has an index signature with a restricted value axis (`TMetadataValue`),
|
|
3979
|
-
* which would force every property on this object to be assignable to `TMetadataValue`.
|
|
3980
|
-
* - Keep structured fields here, and store additional key/value pairs under `extensions`.
|
|
3981
|
-
*/
|
|
3982
|
-
interface IWorkflowConversionResultMetadata {
|
|
3983
|
-
/** Conversion timestamp */
|
|
3984
|
-
convertedAt: Date;
|
|
3985
|
-
/** Processing time in milliseconds */
|
|
3986
|
-
processingTime: number;
|
|
3987
|
-
/** Input data statistics */
|
|
3988
|
-
inputStats: {
|
|
3989
|
-
nodeCount: number;
|
|
3990
|
-
edgeCount: number;
|
|
3991
|
-
};
|
|
3992
|
-
/** Output data statistics */
|
|
3993
|
-
outputStats: {
|
|
3994
|
-
nodeCount: number;
|
|
3995
|
-
edgeCount: number;
|
|
3996
|
-
};
|
|
3997
|
-
/** Converter name */
|
|
3998
|
-
converter: string;
|
|
3999
|
-
/** Converter version */
|
|
4000
|
-
version: string;
|
|
4001
|
-
/** Conversion options (optional, typically gated by includeDebug) */
|
|
4002
|
-
options?: IWorkflowConversionOptions;
|
|
4003
|
-
/**
|
|
4004
|
-
* Additional key/value metadata (SSOT axis).
|
|
4005
|
-
* Use this for dynamic metadata, not top-level ad-hoc fields.
|
|
4006
|
-
*/
|
|
4007
|
-
extensions?: TMetadata;
|
|
4008
|
-
}
|
|
4009
|
-
/**
|
|
4010
|
-
* Workflow Converter Interface
|
|
4011
|
-
*
|
|
4012
|
-
* Core interface for converting between different workflow representations.
|
|
4013
|
-
* All workflow converters must implement this interface.
|
|
4014
|
-
*
|
|
4015
|
-
* @template TInput - Input workflow data type
|
|
4016
|
-
* @template TOutput - Output workflow data type
|
|
4017
|
-
*/
|
|
4018
|
-
interface IWorkflowConverter<TInput extends IWorkflowData, TOutput extends IWorkflowData> {
|
|
4019
|
-
/** Converter name for identification */
|
|
4020
|
-
readonly name: string;
|
|
4021
|
-
/** Converter version */
|
|
4022
|
-
readonly version: string;
|
|
4023
|
-
/** Source format that this converter accepts */
|
|
4024
|
-
readonly sourceFormat: string;
|
|
4025
|
-
/** Target format that this converter produces */
|
|
4026
|
-
readonly targetFormat: string;
|
|
4027
|
-
/**
|
|
4028
|
-
* Convert workflow data from input format to output format
|
|
4029
|
-
*
|
|
4030
|
-
* @param input - Input workflow data
|
|
4031
|
-
* @param options - Conversion options
|
|
4032
|
-
* @returns Promise resolving to conversion result
|
|
4033
|
-
*/
|
|
4034
|
-
convert(input: TInput, options?: IWorkflowConversionOptions): Promise<IWorkflowConversionResult<TOutput>>;
|
|
4035
|
-
/**
|
|
4036
|
-
* Validate input data before conversion
|
|
4037
|
-
*
|
|
4038
|
-
* @param input - Input workflow data
|
|
4039
|
-
* @returns Promise resolving to validation result
|
|
4040
|
-
*/
|
|
4041
|
-
validateInput(input: TInput): Promise<{
|
|
4042
|
-
isValid: boolean;
|
|
4043
|
-
errors: string[];
|
|
4044
|
-
warnings: string[];
|
|
4045
|
-
}>;
|
|
4046
|
-
/**
|
|
4047
|
-
* Validate output data after conversion
|
|
4048
|
-
*
|
|
4049
|
-
* @param output - Output workflow data
|
|
4050
|
-
* @returns Promise resolving to validation result
|
|
4051
|
-
*/
|
|
4052
|
-
validateOutput(output: TOutput): Promise<{
|
|
4053
|
-
isValid: boolean;
|
|
4054
|
-
errors: string[];
|
|
4055
|
-
warnings: string[];
|
|
4056
|
-
}>;
|
|
4057
|
-
/**
|
|
4058
|
-
* Check if this converter supports the given input format
|
|
4059
|
-
*
|
|
4060
|
-
* @param input - Input data to check
|
|
4061
|
-
* @returns True if converter can handle this input
|
|
4062
|
-
*/
|
|
4063
|
-
canConvert(input: IWorkflowData): input is TInput;
|
|
4064
|
-
/**
|
|
4065
|
-
* Get conversion statistics and metrics
|
|
4066
|
-
*
|
|
4067
|
-
* @returns Converter performance metrics
|
|
4068
|
-
*/
|
|
4069
|
-
getStats(): {
|
|
4070
|
-
totalConversions: number;
|
|
4071
|
-
successfulConversions: number;
|
|
4072
|
-
failedConversions: number;
|
|
4073
|
-
averageProcessingTime: number;
|
|
4074
|
-
lastConversionAt?: Date;
|
|
4075
|
-
};
|
|
4076
|
-
/**
|
|
4077
|
-
* Reset converter statistics
|
|
4078
|
-
*/
|
|
4079
|
-
resetStats(): void;
|
|
4080
|
-
}
|
|
4081
|
-
|
|
4082
|
-
/**
|
|
4083
|
-
* Workflow Validator Interface
|
|
4084
|
-
*
|
|
4085
|
-
* Defines the contract for workflow validation systems in the Robota SDK.
|
|
4086
|
-
* Follows Single Responsibility Principle by focusing only on validation logic.
|
|
4087
|
-
*/
|
|
4088
|
-
|
|
4089
|
-
/**
|
|
4090
|
-
* Validation severity levels
|
|
4091
|
-
*/
|
|
4092
|
-
declare enum ValidationSeverity {
|
|
4093
|
-
ERROR = "error",
|
|
4094
|
-
WARNING = "warning",
|
|
4095
|
-
INFO = "info"
|
|
4096
|
-
}
|
|
4097
|
-
/**
|
|
4098
|
-
* Individual validation issue
|
|
4099
|
-
*/
|
|
4100
|
-
interface IValidationIssue {
|
|
4101
|
-
/** Unique identifier for this issue */
|
|
4102
|
-
id: string;
|
|
4103
|
-
/** Issue severity level */
|
|
4104
|
-
severity: ValidationSeverity;
|
|
4105
|
-
/** Human-readable message */
|
|
4106
|
-
message: string;
|
|
4107
|
-
/** Technical details or suggestion */
|
|
4108
|
-
details?: string;
|
|
4109
|
-
/** Location where issue was found */
|
|
4110
|
-
location?: {
|
|
4111
|
-
nodeId?: string;
|
|
4112
|
-
edgeId?: string;
|
|
4113
|
-
field?: string;
|
|
4114
|
-
line?: number;
|
|
4115
|
-
column?: number;
|
|
4116
|
-
};
|
|
4117
|
-
/** Rule that triggered this issue */
|
|
4118
|
-
rule: string;
|
|
4119
|
-
/** Suggested fix (if available) */
|
|
4120
|
-
suggestedFix?: {
|
|
4121
|
-
description: string;
|
|
4122
|
-
action: 'modify' | 'remove' | 'add';
|
|
4123
|
-
target?: IWorkflowConfig;
|
|
4124
|
-
};
|
|
4125
|
-
/** Timestamp when issue was detected */
|
|
4126
|
-
detectedAt: Date;
|
|
4127
|
-
}
|
|
4128
|
-
/**
|
|
4129
|
-
* Validation options
|
|
4130
|
-
*/
|
|
4131
|
-
interface IValidationOptions {
|
|
4132
|
-
/** Validation strictness level */
|
|
4133
|
-
strict?: boolean;
|
|
4134
|
-
/** Skip specific validation rules */
|
|
4135
|
-
skipRules?: string[];
|
|
4136
|
-
/** Include only specific validation rules */
|
|
4137
|
-
includeRules?: string[];
|
|
4138
|
-
/** Maximum number of errors to collect */
|
|
4139
|
-
maxErrors?: number;
|
|
4140
|
-
/** Include warnings in results */
|
|
4141
|
-
includeWarnings?: boolean;
|
|
4142
|
-
/** Include info messages in results */
|
|
4143
|
-
includeInfo?: boolean;
|
|
4144
|
-
/** Custom logger for validation process */
|
|
4145
|
-
logger?: ILogger;
|
|
4146
|
-
/** Additional validation context */
|
|
4147
|
-
context?: IWorkflowMetadata;
|
|
4148
|
-
/** Enable auto-recovery suggestions */
|
|
4149
|
-
enableAutoRecovery?: boolean;
|
|
4150
|
-
}
|
|
4151
|
-
/**
|
|
4152
|
-
* Validation result
|
|
4153
|
-
*/
|
|
4154
|
-
interface IValidationResult {
|
|
4155
|
-
/** Overall validation success status */
|
|
4156
|
-
isValid: boolean;
|
|
4157
|
-
/** All validation issues found */
|
|
4158
|
-
issues: IValidationIssue[];
|
|
4159
|
-
/** Summary by severity */
|
|
4160
|
-
summary: {
|
|
4161
|
-
errorCount: number;
|
|
4162
|
-
warningCount: number;
|
|
4163
|
-
infoCount: number;
|
|
4164
|
-
totalIssues: number;
|
|
4165
|
-
};
|
|
4166
|
-
/** Validation metadata */
|
|
4167
|
-
metadata: {
|
|
4168
|
-
/** Validation timestamp */
|
|
4169
|
-
validatedAt: Date;
|
|
4170
|
-
/** Processing time in milliseconds */
|
|
4171
|
-
processingTime: number;
|
|
4172
|
-
/** Validator used */
|
|
4173
|
-
validator: string;
|
|
4174
|
-
/** Validation rules applied */
|
|
4175
|
-
rulesApplied: string[];
|
|
4176
|
-
/** Data statistics */
|
|
4177
|
-
dataStats: Record<string, string | number | boolean>;
|
|
4178
|
-
/** Version */
|
|
4179
|
-
version?: string;
|
|
4180
|
-
/** Options */
|
|
4181
|
-
options?: string | number | boolean | string[] | Date;
|
|
4182
|
-
/** Additional metrics */
|
|
4183
|
-
[key: string]: string | number | boolean | Date | string[] | Record<string, string | number | boolean> | undefined;
|
|
4184
|
-
};
|
|
4185
|
-
/** Auto-recovery suggestions (if enabled) */
|
|
4186
|
-
recoveryOptions?: Array<{
|
|
4187
|
-
description: string;
|
|
4188
|
-
confidence: number;
|
|
4189
|
-
action: () => Promise<IWorkflowConfig>;
|
|
4190
|
-
}>;
|
|
4191
|
-
}
|
|
4192
|
-
/**
|
|
4193
|
-
* Workflow Validator Interface
|
|
4194
|
-
*
|
|
4195
|
-
* Core interface for validating workflow data structures.
|
|
4196
|
-
* All workflow validators must implement this interface.
|
|
4197
|
-
*
|
|
4198
|
-
* @template TWorkflowData - Type of workflow data to validate
|
|
4199
|
-
*/
|
|
4200
|
-
interface IWorkflowValidator<TWorkflowData extends IWorkflowData> {
|
|
4201
|
-
/** Validator name for identification */
|
|
4202
|
-
readonly name: string;
|
|
4203
|
-
/** Validator version */
|
|
4204
|
-
readonly version: string;
|
|
4205
|
-
/** Data format that this validator handles */
|
|
4206
|
-
readonly dataFormat: string;
|
|
4207
|
-
/** Available validation rules */
|
|
4208
|
-
readonly availableRules: string[];
|
|
4209
|
-
/**
|
|
4210
|
-
* Validate workflow data
|
|
4211
|
-
*
|
|
4212
|
-
* @param data - Workflow data to validate
|
|
4213
|
-
* @param options - Validation options
|
|
4214
|
-
* @returns Promise resolving to validation result
|
|
4215
|
-
*/
|
|
4216
|
-
validate(data: TWorkflowData, options?: IValidationOptions): Promise<IValidationResult>;
|
|
4217
|
-
/**
|
|
4218
|
-
* Validate specific aspect of workflow data
|
|
4219
|
-
*
|
|
4220
|
-
* @param data - Workflow data to validate
|
|
4221
|
-
* @param rule - Specific rule to apply
|
|
4222
|
-
* @param options - Validation options
|
|
4223
|
-
* @returns Promise resolving to validation result for this rule
|
|
4224
|
-
*/
|
|
4225
|
-
validateRule(data: TWorkflowData, rule: string, options?: IValidationOptions): Promise<IValidationResult>;
|
|
4226
|
-
/**
|
|
4227
|
-
* Check if validator can handle the given data format
|
|
4228
|
-
*
|
|
4229
|
-
* @param data - Data to check
|
|
4230
|
-
* @returns True if validator can handle this data
|
|
4231
|
-
*/
|
|
4232
|
-
canValidate(data: IWorkflowData): data is TWorkflowData;
|
|
4233
|
-
/**
|
|
4234
|
-
* Get available validation rules with descriptions
|
|
4235
|
-
*
|
|
4236
|
-
* @returns Map of rule names to descriptions
|
|
4237
|
-
*/
|
|
4238
|
-
getRuleDescriptions(): Map<string, {
|
|
4239
|
-
description: string;
|
|
4240
|
-
severity: ValidationSeverity;
|
|
4241
|
-
category: string;
|
|
4242
|
-
enabled: boolean;
|
|
4243
|
-
}>;
|
|
4244
|
-
/**
|
|
4245
|
-
* Enable or disable specific validation rules
|
|
4246
|
-
*
|
|
4247
|
-
* @param rules - Map of rule names to enabled status
|
|
4248
|
-
*/
|
|
4249
|
-
configureRules(rules: Map<string, boolean>): void;
|
|
4250
|
-
/**
|
|
4251
|
-
* Perform automatic recovery for validation issues
|
|
4252
|
-
*
|
|
4253
|
-
* @param data - Original workflow data
|
|
4254
|
-
* @param issues - Validation issues to recover from
|
|
4255
|
-
* @returns Promise resolving to recovered data and recovery result
|
|
4256
|
-
*/
|
|
4257
|
-
autoRecover(data: TWorkflowData, issues: IValidationIssue[]): Promise<{
|
|
4258
|
-
recoveredData: TWorkflowData;
|
|
4259
|
-
recoveryResult: {
|
|
4260
|
-
success: boolean;
|
|
4261
|
-
issuesFixed: IValidationIssue[];
|
|
4262
|
-
remainingIssues: IValidationIssue[];
|
|
4263
|
-
appliedFixes: string[];
|
|
4264
|
-
};
|
|
4265
|
-
}>;
|
|
4266
|
-
/**
|
|
4267
|
-
* Get validator statistics and metrics
|
|
4268
|
-
*
|
|
4269
|
-
* @returns Validator performance metrics
|
|
4270
|
-
*/
|
|
4271
|
-
getStats(): {
|
|
4272
|
-
totalValidations: number;
|
|
4273
|
-
successfulValidations: number;
|
|
4274
|
-
failedValidations: number;
|
|
4275
|
-
averageProcessingTime: number;
|
|
4276
|
-
averageIssueCount: number;
|
|
4277
|
-
mostCommonIssues: Array<{
|
|
4278
|
-
rule: string;
|
|
4279
|
-
count: number;
|
|
4280
|
-
severity: ValidationSeverity;
|
|
4281
|
-
}>;
|
|
4282
|
-
lastValidationAt?: Date;
|
|
4283
|
-
};
|
|
4284
|
-
/**
|
|
4285
|
-
* Reset validator statistics
|
|
4286
|
-
*/
|
|
4287
|
-
resetStats(): void;
|
|
4288
|
-
}
|
|
4289
|
-
|
|
4290
|
-
/**
|
|
4291
|
-
* Configuration for execution proxy
|
|
4292
|
-
*/
|
|
4293
|
-
interface IExecutionProxyConfig {
|
|
4294
|
-
eventService: IEventService;
|
|
4295
|
-
sourceType: 'agent' | 'team' | 'tool';
|
|
4296
|
-
sourceId: string;
|
|
4297
|
-
enabledEvents?: {
|
|
4298
|
-
execution?: boolean;
|
|
4299
|
-
toolCall?: boolean;
|
|
4300
|
-
task?: boolean;
|
|
4301
|
-
};
|
|
4302
|
-
}
|
|
4303
|
-
/** Internal target shape for proxy interception */
|
|
4304
|
-
type TExecutionProxyTarget = Record<string, TUniversalValue>;
|
|
4305
|
-
/** Internal args shape for proxy interception */
|
|
4306
|
-
type TExecutionProxyArgs = TUniversalValue[];
|
|
4307
|
-
/**
|
|
4308
|
-
* Metadata extractor function type
|
|
4309
|
-
*/
|
|
4310
|
-
type TMetadataExtractor = (target: TExecutionProxyTarget, methodName: string, args: TExecutionProxyArgs) => Record<string, TUniversalValue>;
|
|
4311
|
-
/**
|
|
4312
|
-
* Method configuration for proxy
|
|
4313
|
-
*/
|
|
4314
|
-
interface IMethodConfig {
|
|
4315
|
-
startEvent?: string;
|
|
4316
|
-
completeEvent?: string;
|
|
4317
|
-
errorEvent?: string;
|
|
4318
|
-
extractMetadata?: TMetadataExtractor;
|
|
4319
|
-
extractResult?: (result: TUniversalValue) => Record<string, TUniversalValue>;
|
|
4320
|
-
}
|
|
4321
|
-
|
|
4322
|
-
/**
|
|
4323
|
-
* ExecutionProxy - Automatic event emission using Proxy pattern
|
|
4324
|
-
*
|
|
4325
|
-
* This class wraps target objects and automatically emits events
|
|
4326
|
-
* around method execution without modifying business logic.
|
|
4327
|
-
*
|
|
4328
|
-
* Benefits:
|
|
4329
|
-
* - Zero business logic pollution
|
|
4330
|
-
* - Automatic event emission
|
|
4331
|
-
* - Configurable per method
|
|
4332
|
-
* - AOP (Aspect-Oriented Programming) pattern
|
|
4333
|
-
*/
|
|
4334
|
-
declare class ExecutionProxy<T extends object = object> {
|
|
4335
|
-
private config;
|
|
4336
|
-
private methodConfigs;
|
|
4337
|
-
constructor(config: IExecutionProxyConfig);
|
|
4338
|
-
/**
|
|
4339
|
-
* Configure specific methods for event emission
|
|
4340
|
-
*/
|
|
4341
|
-
configureMethod(methodName: string, config: IMethodConfig): this;
|
|
4342
|
-
/**
|
|
4343
|
-
* Configure multiple methods with standard patterns
|
|
4344
|
-
*/
|
|
4345
|
-
configureStandardMethods(): this;
|
|
4346
|
-
/**
|
|
4347
|
-
* Create a proxy wrapper around the target object
|
|
4348
|
-
*/
|
|
4349
|
-
wrap(target: T): T;
|
|
4350
|
-
/**
|
|
4351
|
-
* Emit event with standard ServiceEventData format
|
|
4352
|
-
*/
|
|
4353
|
-
private emitEvent;
|
|
4354
|
-
/**
|
|
4355
|
-
* Generate unique execution ID
|
|
4356
|
-
*/
|
|
4357
|
-
private generateExecutionId;
|
|
4358
|
-
}
|
|
4359
|
-
/**
|
|
4360
|
-
* Factory function to create execution proxy with standard configuration
|
|
4361
|
-
*/
|
|
4362
|
-
declare function createExecutionProxy<T extends object>(target: T, config: IExecutionProxyConfig): T;
|
|
4363
|
-
/**
|
|
4364
|
-
* Decorator function for automatic event emission
|
|
4365
|
-
* Usage: @withEventEmission(eventService, 'agent', 'agent-id')
|
|
4366
|
-
*/
|
|
4367
|
-
declare function withEventEmission(eventService: IEventService, sourceType: 'agent' | 'team' | 'tool', sourceId: string): <T extends object>(target: T) => T;
|
|
4368
|
-
|
|
4369
|
-
/**
|
|
4370
|
-
* Permission system types — Claude Code compatible permission model.
|
|
4371
|
-
*/
|
|
4372
|
-
/**
|
|
4373
|
-
* Permission modes (Claude Code compatible)
|
|
4374
|
-
* - plan: read-only tools only
|
|
4375
|
-
* - default: reads auto, writes/bash need approval
|
|
4376
|
-
* - acceptEdits: reads + writes auto, bash needs approval
|
|
4377
|
-
* - bypassPermissions: all tools auto
|
|
4378
|
-
*/
|
|
4379
|
-
type TPermissionMode = 'plan' | 'default' | 'acceptEdits' | 'bypassPermissions';
|
|
4380
|
-
/**
|
|
4381
|
-
* Friendly trust level aliases
|
|
4382
|
-
* - safe → plan
|
|
4383
|
-
* - moderate → default
|
|
4384
|
-
* - full → acceptEdits
|
|
4385
|
-
*/
|
|
4386
|
-
type TTrustLevel = 'safe' | 'moderate' | 'full';
|
|
4387
|
-
declare const TRUST_TO_MODE: Record<TTrustLevel, TPermissionMode>;
|
|
4388
|
-
/**
|
|
4389
|
-
* Outcome of a permission evaluation
|
|
4390
|
-
* - auto: proceed without prompting
|
|
4391
|
-
* - approve: prompt user for approval
|
|
4392
|
-
* - deny: block the action
|
|
4393
|
-
*/
|
|
4394
|
-
type TPermissionDecision = 'auto' | 'approve' | 'deny';
|
|
4395
|
-
|
|
4396
|
-
/**
|
|
4397
|
-
* Permission gate — evaluates whether a tool call is auto-approved, needs user approval, or denied.
|
|
4398
|
-
*
|
|
4399
|
-
* Three-step deterministic policy (in order of precedence):
|
|
4400
|
-
* 1. Deny list match → deny
|
|
4401
|
-
* 2. Allow list match → auto
|
|
4402
|
-
* 3. Mode policy lookup
|
|
4403
|
-
*
|
|
4404
|
-
* Pattern syntax (same as Claude Code):
|
|
4405
|
-
* - `Bash(pnpm *)` — Bash tool whose command starts with "pnpm "
|
|
4406
|
-
* - `Read(/src/**)` — Read tool whose filePath is under /src/
|
|
4407
|
-
* - `Write(*)` — Write tool with any argument
|
|
4408
|
-
* - `ToolName` — match any invocation of that tool
|
|
4409
|
-
*/
|
|
4410
|
-
|
|
4411
|
-
/**
|
|
4412
|
-
* Tool arguments passed from the LLM invocation.
|
|
4413
|
-
* The values relevant to permission matching are strings.
|
|
4414
|
-
*/
|
|
4415
|
-
type TToolArgs = Record<string, string | number | boolean | object>;
|
|
4416
|
-
/**
|
|
4417
|
-
* Permission list entries (allow / deny).
|
|
4418
|
-
* Each entry is a pattern string such as "Bash(pnpm *)" or "Read(/src/**)".
|
|
4419
|
-
*/
|
|
4420
|
-
interface IPermissionLists {
|
|
4421
|
-
allow?: string[];
|
|
4422
|
-
deny?: string[];
|
|
4423
|
-
}
|
|
4424
|
-
/**
|
|
4425
|
-
* Evaluate whether a tool invocation should be auto-approved, require user approval, or be denied.
|
|
4426
|
-
*
|
|
4427
|
-
* @param toolName Name of the tool being invoked (e.g. "Bash", "Write")
|
|
4428
|
-
* @param toolArgs Arguments provided by the LLM
|
|
4429
|
-
* @param mode Active permission mode
|
|
4430
|
-
* @param permissions Optional allow/deny lists from config
|
|
4431
|
-
*/
|
|
4432
|
-
declare function evaluatePermission(toolName: string, toolArgs: TToolArgs, mode: TPermissionMode, permissions?: IPermissionLists): TPermissionDecision;
|
|
4433
|
-
|
|
4434
|
-
/**
|
|
4435
|
-
* Permission mode definitions for Robota CLI
|
|
4436
|
-
*
|
|
4437
|
-
* Matches Claude Code-compatible permission modes:
|
|
4438
|
-
* - plan: read-only tools only (Read, Glob, Grep, WebFetch, WebSearch auto; Write, Edit, Bash denied)
|
|
4439
|
-
* - default: safe reads auto, writes and bash need approval
|
|
4440
|
-
* - acceptEdits: reads + writes auto, bash needs approval
|
|
4441
|
-
* - bypassPermissions: all tools auto
|
|
4442
|
-
*/
|
|
4443
|
-
|
|
4444
|
-
/**
|
|
4445
|
-
* Tool names known to the permission system
|
|
4446
|
-
*/
|
|
4447
|
-
type TKnownToolName = 'Bash' | 'Read' | 'Write' | 'Edit' | 'Glob' | 'Grep' | 'WebFetch' | 'WebSearch';
|
|
4448
|
-
/**
|
|
4449
|
-
* Permission mode → tool policy matrix
|
|
4450
|
-
* Maps each mode to a decision for each known tool.
|
|
4451
|
-
*/
|
|
4452
|
-
declare const MODE_POLICY: Record<TPermissionMode, Record<TKnownToolName, TPermissionDecision>>;
|
|
4453
|
-
/**
|
|
4454
|
-
* Fallback decision when a tool name is not in the policy matrix.
|
|
4455
|
-
* Unknown tools are treated as requiring approval (fail-safe).
|
|
4456
|
-
*/
|
|
4457
|
-
declare const UNKNOWN_TOOL_FALLBACK: Record<TPermissionMode, TPermissionDecision>;
|
|
4458
|
-
|
|
4459
|
-
/**
|
|
4460
|
-
* Context window tracking types.
|
|
4461
|
-
*
|
|
4462
|
-
* These types are used by agent-sessions (and downstream packages) to
|
|
4463
|
-
* track token usage and context window state across conversation turns.
|
|
4464
|
-
*/
|
|
4465
|
-
/** Token usage from a single API call (Anthropic-style granularity) */
|
|
4466
|
-
interface IContextTokenUsage {
|
|
4467
|
-
inputTokens: number;
|
|
4468
|
-
outputTokens: number;
|
|
4469
|
-
cacheCreationTokens?: number;
|
|
4470
|
-
cacheReadTokens?: number;
|
|
4471
|
-
}
|
|
4472
|
-
/** Context window state snapshot */
|
|
4473
|
-
interface IContextWindowState {
|
|
4474
|
-
/** Max tokens for the current model */
|
|
4475
|
-
maxTokens: number;
|
|
4476
|
-
/** Current estimated token usage (input + cache, excludes output) */
|
|
4477
|
-
usedTokens: number;
|
|
4478
|
-
/** Usage percentage (0-100) */
|
|
4479
|
-
usedPercentage: number;
|
|
4480
|
-
/** Remaining percentage (0-100) */
|
|
4481
|
-
remainingPercentage: number;
|
|
4482
|
-
}
|
|
4483
|
-
|
|
4484
|
-
declare const CONTEXT_ESTIMATE_CHARS_PER_TOKEN = 4;
|
|
4485
|
-
interface IContextTokenEstimateOptions {
|
|
4486
|
-
readonly usageFloorTokens?: number;
|
|
4487
|
-
}
|
|
4488
|
-
interface IContextTokenEstimate {
|
|
4489
|
-
readonly usedTokens: number;
|
|
4490
|
-
readonly serializedTokens: number;
|
|
4491
|
-
readonly providerTokens?: number;
|
|
4492
|
-
readonly usageFloorTokens?: number;
|
|
4493
|
-
}
|
|
4494
|
-
declare function estimateSerializedContextTokens(messages: readonly TUniversalMessage[]): number;
|
|
4495
|
-
declare function estimateContextTokensFromMessages(messages: readonly TUniversalMessage[], options?: IContextTokenEstimateOptions): IContextTokenEstimate;
|
|
4496
|
-
|
|
4497
|
-
interface IMessageTokenUsage {
|
|
4498
|
-
readonly inputTokens: number;
|
|
4499
|
-
readonly outputTokens: number;
|
|
4500
|
-
readonly totalTokens?: number;
|
|
4501
|
-
}
|
|
4502
|
-
/** Read normalized provider usage from a universal message when present. */
|
|
4503
|
-
declare function readTokenUsageFromMessage(message: TUniversalMessage): IMessageTokenUsage | undefined;
|
|
4504
|
-
declare function readTokenUsageFromMetadata(metadata: TUniversalMessageMetadata | undefined): IMessageTokenUsage | undefined;
|
|
4505
|
-
|
|
4506
|
-
/**
|
|
4507
|
-
* Claude model definitions — SSOT for model metadata.
|
|
4508
|
-
* Source: https://platform.claude.com/docs/en/about-claude/models/overview
|
|
4509
|
-
*/
|
|
4510
|
-
interface IModelDefinition {
|
|
4511
|
-
/** Human-readable model name */
|
|
4512
|
-
name: string;
|
|
4513
|
-
/** API model identifier */
|
|
4514
|
-
id: string;
|
|
4515
|
-
/** Context window size in tokens */
|
|
4516
|
-
contextWindow: number;
|
|
4517
|
-
/** Maximum output tokens */
|
|
4518
|
-
maxOutput: number;
|
|
4519
|
-
}
|
|
4520
|
-
/**
|
|
4521
|
-
* Known Claude models (4.5+).
|
|
4522
|
-
* Keyed by API model ID for fast lookup.
|
|
4523
|
-
*/
|
|
4524
|
-
declare const CLAUDE_MODELS: Record<string, IModelDefinition>;
|
|
4525
|
-
declare const DEFAULT_CONTEXT_WINDOW = 200000;
|
|
4526
|
-
/** Get context window size for a model ID. Falls back to DEFAULT_CONTEXT_WINDOW. */
|
|
4527
|
-
declare function getModelContextWindow(modelId: string): number;
|
|
4528
|
-
declare const DEFAULT_MAX_OUTPUT = 16384;
|
|
4529
|
-
/** Get max output tokens for a model ID. Falls back to DEFAULT_MAX_OUTPUT. */
|
|
4530
|
-
declare function getModelMaxOutput(modelId: string): number;
|
|
4531
|
-
/** Get human-readable model name for a model ID. Falls back to the ID itself. */
|
|
4532
|
-
declare function getModelName(modelId: string): string;
|
|
4533
|
-
/** Format token count as human-readable (e.g., 200K, 1M, 1.2M). Minimum unit is K. */
|
|
4534
|
-
declare function formatTokenCount(tokens: number): string;
|
|
4535
|
-
|
|
4536
|
-
/**
|
|
4537
|
-
* Hook system types — Claude Code compatible event/hook model.
|
|
4538
|
-
*/
|
|
4539
|
-
/** Hook lifecycle events */
|
|
4540
|
-
type THookEvent = 'PreToolUse' | 'PostToolUse' | 'SessionStart' | 'SessionEnd' | 'Stop' | 'StopFailure' | 'PreCompact' | 'PostCompact' | 'UserPromptSubmit' | 'SubagentStart' | 'SubagentStop' | 'WorktreeCreate' | 'WorktreeRemove';
|
|
4541
|
-
/** Claude Code compatible session end reasons. */
|
|
4542
|
-
type TSessionEndReason = 'clear' | 'resume' | 'logout' | 'prompt_input_exit' | 'bypass_permissions_disabled' | 'other';
|
|
4543
|
-
/** Command hook — executes a shell command */
|
|
4544
|
-
interface ICommandHookDefinition {
|
|
4545
|
-
type: 'command';
|
|
4546
|
-
command: string;
|
|
4547
|
-
timeout?: number;
|
|
4548
|
-
}
|
|
4549
|
-
/** HTTP hook — sends an HTTP request */
|
|
4550
|
-
interface IHttpHookDefinition {
|
|
4551
|
-
type: 'http';
|
|
4552
|
-
url: string;
|
|
4553
|
-
headers?: Record<string, string>;
|
|
4554
|
-
timeout?: number;
|
|
4555
|
-
}
|
|
4556
|
-
/** Prompt hook — evaluates a prompt via an AI model */
|
|
4557
|
-
interface IPromptHookDefinition {
|
|
4558
|
-
type: 'prompt';
|
|
4559
|
-
prompt: string;
|
|
4560
|
-
model?: string;
|
|
4561
|
-
}
|
|
4562
|
-
/** Agent hook — delegates to a sub-agent */
|
|
4563
|
-
interface IAgentHookDefinition {
|
|
4564
|
-
type: 'agent';
|
|
4565
|
-
agent: string;
|
|
4566
|
-
maxTurns?: number;
|
|
4567
|
-
timeout?: number;
|
|
4568
|
-
}
|
|
4569
|
-
/** Discriminated union of all hook definition types */
|
|
4570
|
-
type IHookDefinition = ICommandHookDefinition | IHttpHookDefinition | IPromptHookDefinition | IAgentHookDefinition;
|
|
4571
|
-
/** A hook group — matcher + array of hook definitions */
|
|
4572
|
-
interface IHookGroup {
|
|
4573
|
-
/** Regex pattern to match tool name (empty string = match all) */
|
|
4574
|
-
matcher: string;
|
|
4575
|
-
hooks: IHookDefinition[];
|
|
4576
|
-
/** Environment variables injected into hook child processes for this group */
|
|
4577
|
-
env?: Record<string, string>;
|
|
4578
|
-
}
|
|
4579
|
-
/** Complete hooks configuration: event → array of hook groups */
|
|
4580
|
-
type THooksConfig = Partial<Record<THookEvent, IHookGroup[]>>;
|
|
4581
|
-
/** Input passed to hook commands via stdin */
|
|
4582
|
-
interface IHookInput {
|
|
4583
|
-
session_id: string;
|
|
4584
|
-
cwd: string;
|
|
4585
|
-
hook_event_name: THookEvent;
|
|
4586
|
-
tool_name?: string;
|
|
4587
|
-
tool_input?: Record<string, string | number | boolean | object>;
|
|
4588
|
-
tool_output?: string;
|
|
4589
|
-
/** Compaction trigger source (PreCompact/PostCompact only) */
|
|
4590
|
-
trigger?: 'auto' | 'manual';
|
|
4591
|
-
/** Compaction summary text (PostCompact only) */
|
|
4592
|
-
compact_summary?: string;
|
|
4593
|
-
/** User message text (UserPromptSubmit only) */
|
|
4594
|
-
user_message?: string;
|
|
4595
|
-
/** User prompt text — Claude Code compatible alias for user_message (UserPromptSubmit only) */
|
|
4596
|
-
prompt?: string;
|
|
4597
|
-
/** Assistant response text (Stop only) */
|
|
4598
|
-
response?: string;
|
|
4599
|
-
/** Last assistant message text (StopFailure only) */
|
|
4600
|
-
last_assistant_message?: string;
|
|
4601
|
-
/** Stop hook recursion guard (Stop/StopFailure only) */
|
|
4602
|
-
stop_hook_active?: boolean;
|
|
4603
|
-
/** Session end reason (SessionEnd only) */
|
|
4604
|
-
reason?: TSessionEndReason | string;
|
|
4605
|
-
/** Session transcript path when available (SessionEnd/SubagentStop only) */
|
|
4606
|
-
transcript_path?: string;
|
|
4607
|
-
/** Subagent identifier (SubagentStart/SubagentStop only) */
|
|
4608
|
-
agent_id?: string;
|
|
4609
|
-
/** Subagent type/name (SubagentStart/SubagentStop only) */
|
|
4610
|
-
agent_type?: string;
|
|
4611
|
-
/** Subagent transcript path when available (SubagentStop only) */
|
|
4612
|
-
agent_transcript_path?: string;
|
|
4613
|
-
/** Claude Code permission mode at time of event (e.g. "default", "plan", "acceptEdits", "bypassPermissions") */
|
|
4614
|
-
permission_mode?: string;
|
|
4615
|
-
/** Additional environment variables to pass to hook child processes */
|
|
4616
|
-
env?: Record<string, string>;
|
|
4617
|
-
}
|
|
4618
|
-
/** Hook execution result */
|
|
4619
|
-
interface IHookResult {
|
|
4620
|
-
/** 0 = allow/proceed, 2 = block/deny, other = proceed with warning */
|
|
4621
|
-
exitCode: number;
|
|
4622
|
-
stdout: string;
|
|
4623
|
-
stderr: string;
|
|
4624
|
-
}
|
|
4625
|
-
/** Strategy interface for hook type executors */
|
|
4626
|
-
interface IHookTypeExecutor {
|
|
4627
|
-
/** The hook type this executor handles */
|
|
4628
|
-
type: IHookDefinition['type'];
|
|
4629
|
-
/** Execute a hook definition with the given input */
|
|
4630
|
-
execute(definition: IHookDefinition, input: IHookInput): Promise<IHookResult>;
|
|
4631
|
-
}
|
|
4632
|
-
|
|
4633
|
-
/**
|
|
4634
|
-
* Hook runner — executes hooks for lifecycle events using the strategy pattern.
|
|
4635
|
-
*
|
|
4636
|
-
* Dispatches to registered IHookTypeExecutor implementations by definition type.
|
|
4637
|
-
* Default executors: CommandExecutor (shell), HttpExecutor (HTTP POST).
|
|
4638
|
-
*
|
|
4639
|
-
* Exit code semantics:
|
|
4640
|
-
* - 0: allow/proceed
|
|
4641
|
-
* - 2: block/deny (stderr contains reason)
|
|
4642
|
-
* - other: proceed (logged as warning)
|
|
4643
|
-
*
|
|
4644
|
-
* stdout JSON semantics (Claude Code compatible):
|
|
4645
|
-
* - { continue: false } → block, regardless of exit code
|
|
4646
|
-
* - PreToolUse: { hookSpecificOutput: { permissionDecision, updatedInput } }
|
|
4647
|
-
* - UserPromptSubmit: { decision: "block" } → block; hookSpecificOutput.additionalContext → injected into stdout
|
|
4648
|
-
*/
|
|
4649
|
-
|
|
4650
|
-
/** Result of running hooks for an event. */
|
|
4651
|
-
interface IRunHooksResult {
|
|
4652
|
-
blocked: boolean;
|
|
4653
|
-
reason?: string;
|
|
4654
|
-
/** Collected stdout from all successful hooks (exit code 0). */
|
|
4655
|
-
stdout: string;
|
|
4656
|
-
/** Parsed updatedInput from PreToolUse hookSpecificOutput (PreToolUse only). */
|
|
4657
|
-
updatedInput?: Record<string, unknown>;
|
|
4658
|
-
/** Highest-priority permissionDecision from PreToolUse hooks (PreToolUse only). */
|
|
4659
|
-
permissionDecision?: 'allow' | 'deny' | 'ask' | 'defer';
|
|
4660
|
-
}
|
|
4661
|
-
/**
|
|
4662
|
-
* Run all hooks for a given event.
|
|
4663
|
-
*
|
|
4664
|
-
* For PreToolUse: if any hook returns exit code 2 or JSON deny, the tool call is blocked.
|
|
4665
|
-
* JSON stdout responses are parsed and applied per Claude Code spec.
|
|
4666
|
-
* Returns { blocked: true, reason } if blocked, otherwise { blocked: false, stdout }.
|
|
4667
|
-
*
|
|
4668
|
-
* @param config - Hooks configuration mapping events to hook groups
|
|
4669
|
-
* @param event - The lifecycle event being fired
|
|
4670
|
-
* @param input - Hook input data passed to executors
|
|
4671
|
-
* @param executors - Optional array of hook type executors (defaults to command + http)
|
|
4672
|
-
*/
|
|
4673
|
-
declare function runHooks(config: THooksConfig | undefined, event: THookEvent, input: IHookInput, executors?: IHookTypeExecutor[]): Promise<IRunHooksResult>;
|
|
4674
|
-
|
|
4675
|
-
export { AGENT_EVENTS, AGENT_EVENT_PREFIX, AbstractAIProvider, AbstractAgent, AbstractEventService, AbstractExecutor, AbstractManager, AbstractPlugin, AbstractTool, AgentFactory, AgentTemplates, AuthenticationError, CLAUDE_MODELS, CONTEXT_ESTIMATE_CHARS_PER_TOKEN, CacheIntegrityError, CircuitBreakerOpenError, ConfigurationError, ConsoleLogger, ConversationHistory, ConversationStore, DEFAULT_ABSTRACT_EVENT_SERVICE, DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_OUTPUT, DefaultEventService, EVENT_EMITTER_EVENTS, EXECUTION_EVENTS, EXECUTION_EVENT_PREFIX, ErrorUtils, EventEmitterPlugin, EventHistoryModule, ExecutionProxy, type IAIProvider, type IAIProviderInstance, type IAIProviderManager, type IAbstractTool, type IAbstractToolOptions, type IAgent, type IAgentConfig, type IAgentCreationOptions, type IAgentCreationStats, type IAgentEventData, type IAgentFactory, type IAgentFactoryOptions, type IAgentHookDefinition, type IAgentLifecycleEvents, type IAgentTemplate, type IAssistantMessage, type IAssistantUsageMetadata, type IBaseEventData, type IBaseMessage, type ICacheEntry, type ICacheKey, type ICacheOptions, type ICacheStats, type ICacheStorage, type IChatExecutionRequest, type IChatOptions, type ICommandHookDefinition, type IConfigValidationResult, type IContextOptions, type IContextTokenEstimate, type IContextTokenEstimateOptions, type IContextTokenUsage, type IContextWindowState, type IConversationContext, type IConversationResponse, type IConversationService, type IConversationServiceOptions, type IEventContext, type IEventEmitterEventData, type IEventEmitterHierarchicalEventData, type IEventEmitterMetrics, type IEventEmitterMetricsSnapshot, type IEventEmitterPlugin, type IEventEmitterPluginOptions, type IEventHistoryModule, type IEventHistoryRecord, type IEventHistorySnapshot, type IEventObjectValue, type IEventService, type IEventServiceOwnerBinding, type IExecutionEventData, type IExecutionService, type IExecutionServiceOptions, type IExecutor, type IExecutorAwareProviderConfig, type IFunctionTool, type IHistoryEntry, type IHookDefinition, type IHookGroup, type IHookInput, type IHookResult, type IHookTypeExecutor, type IHttpHookDefinition, type IImageComposeRequest, type IImageEditRequest, type IImageGenerationProvider, type IImageGenerationRequest, type IImageGenerationResult, type IInlineImageInputSource, type IInlineImageMessagePart, type ILocalExecutorConfig, type ILogger, type IMCPToolConfig, type IMediaOutputRef, type IMessageTokenUsage, type IModelDefinition, type IOpenAPIToolConfig, type IOwnerPathSegment, type IParameterSchema, type IParameterValidationResult, type IPermissionLists, type IPlugin, type IPluginConfig, type IPluginContext, type IPluginContract, type IPluginData, type IPluginErrorContext, type IPluginExecutionContext, type IPluginExecutionResult, type IPluginHooks, type IPluginOptions, type IPluginStats, type IProgressReportingTool, type IPromptHookDefinition, type IProviderCapabilities, type IProviderConfig$1 as IProviderConfig, type IProviderCredentialRequirement, type IProviderDefinition, type IProviderFunctionCallingCapability, type IProviderMediaError, type IProviderModelCatalog, type IProviderModelCatalogEntry, type IProviderModelCatalogRefreshOptions, type IProviderNativeRawPayloadEvent, type IProviderNativeWebToolCapabilities, type IProviderNativeWebToolCapability, type IProviderNativeWebToolRequest, type IProviderOptions, type IProviderProbeResult, type IProviderProfileConfig, type IProviderProfileDefaults, type IProviderRequest, type IProviderSetupHelpLink, type IProviderSetupStepDefinition, type IProviderSpecificOptions, type IRawProviderResponse, type IRemoteExecutorConfig, type IRunOptions, type ISession, type ISimpleValidationResult, type ISpinner, type IStreamExecutionRequest, type IStreamingChunk, type ISystemMessage, type ITemplateApplicationResult, type ITerminalOutput, type ITextMessagePart, type ITokenUsage, type ITool, type IToolCall, type IToolContract, type IToolEventData, type IToolExecutionContext, type IToolExecutionRequest, type IToolExecutionResult, type IToolExecutionService, type IToolExecutionStep, type IToolFactory, type IToolManager, type IToolMessage, type IToolRegistry, type IToolResult, type IToolSchema, type IToolWithEventService, type IUniversalObjectValue, type IUriImageInputSource, type IUriImageMessagePart, type IUserMessage, type IUtilLogEntry, type IValidationIssue, type IValidationOptions, type IValidationResult, type IVideoGenerationProvider, type IVideoGenerationRequest, type IVideoJobAccepted, type IVideoJobSnapshot, type IWorkflowConfig, type IWorkflowConversionOptions, type IWorkflowConversionResult, type IWorkflowConverter, type IWorkflowData, type IWorkflowMetadata, type IWorkflowValidator, InMemoryEventEmitterMetrics, LocalExecutor, MODE_POLICY, MessageConverter, ModelNotAvailableError, NetworkError, ObservableEventService, PluginCategory, PluginError, PluginPriority, ProviderError, RateLimitError, Robota, RobotaError, SilentLogger, StorageError, StructuredEventService, TASK_EVENTS, TASK_EVENT_PREFIX, type TAgentCreationMetadata, type TComplexConfigValue, type TConfigData, type TConfigValue, type TContextData, type TConversationContextMetadata, type TErrorContextData, type TErrorExternalInput, type TEventEmitterListener, type TEventExtensionValue, type TEventListener, type TEventLoggerData, type TEventName, type TEventUniversalValue, type TExecutionEventCallback, type TExecutionEventData, type TExecutionEventName, type TExecutionMetadata, type THookEvent, type THooksConfig, type TImageInputSource, type TJSONSchemaEnum, type TJSONSchemaKind, type TKnownToolName, type TLoggerData, type TManagerToolParameters, type TMessageConverterRegistry, type TMessageFormatConverter, type TMessageState, type TMetadata, type TMetadataValue, TOOL_EVENTS, TOOL_EVENT_PREFIX, type TParameterDefaultValue, type TPermissionDecision, type TPermissionMode, type TPrimitiveValue, type TProviderConfigValue, type TProviderCredentialField, type TProviderLoggingData, type TProviderMediaResult, type TProviderMessage, type TProviderModelCapability, type TProviderModelCatalogRefresh, type TProviderModelCatalogStatus, type TProviderModelLifecycle, type TProviderNativeRawPayload, type TProviderNativeRawPayloadCallback, type TProviderNativeRawPayloadKind, type TProviderOptionValueBase, type TProviderSetupField, type TProviderSetupHelpLinkKind, TRUST_TO_MODE, type TResponseMetadata, type TSessionEndReason, type TTextDeltaCallback, type TTimerId, type TToolArgs, type TToolExecutionFunction, type TToolExecutionParameters, type TToolExecutor, type TToolMetadata, type TToolParameters, type TToolProgressCallback, type TTrustLevel, type TUniversalArrayValue, type TUniversalMessage, type TUniversalMessageMetadata, type TUniversalMessagePart, type TUniversalMessageRole, type TUniversalValue, type TUserEvent, type TUtilLogLevel, ToolExecutionError, TypeUtils, UNKNOWN_TOOL_FALLBACK, USER_EVENTS, USER_EVENT_PREFIX, ValidationError, ValidationSeverity, Validator, assertProviderNativeWebToolsAvailable, bindEventServiceOwner, bindWithOwnerPath, chatEntryToMessage, collectAssistantUsageMetadata, composeEventName, createAssistantMessage, createDefaultProviderCapabilities, createExecutionProxy, createLogger, createSystemMessage, createToolMessage, createUserMessage, estimateContextTokensFromMessages, estimateSerializedContextTokens, evaluatePermission, findProviderDefinition, formatSupportedProviderTypes, formatTokenCount, getGlobalLogLevel, getMessagesForAPI, getModelContextWindow, getModelMaxOutput, getModelName, getProviderCapabilities, getProviderCredentialRequirement, getToolEstimatedDuration, getToolExecutionSteps, isAssistantMessage, isChatEntry, isDefaultEventService, isImageGenerationProvider, isProgressReportingTool, isSystemMessage, isToolMessage, isUserMessage, isVideoGenerationProvider, logger, messageToHistoryEntry, readTokenUsageFromMessage, readTokenUsageFromMetadata, runHooks, setGlobalLogLevel, setToolProgressCallback, startPeriodicTask, stopPeriodicTask, validateAgentConfig, validateApiKey, validateModelName, validateProviderName, validateUserInput, withEventEmission };
|