art-framework 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { z } from 'zod';
2
+
1
3
  type UnsubscribeFunction = () => void;
2
4
  interface Subscription<DataType, FilterType> {
3
5
  id: string;
@@ -11,7 +13,7 @@ interface Subscription<DataType, FilterType> {
11
13
  * A generic class for implementing a publish/subscribe pattern with filtering capabilities.
12
14
  * Designed for decoupling components, particularly UI updates from backend events.
13
15
  */
14
- declare class TypedSocket$1<DataType, FilterType = any> {
16
+ declare class TypedSocket<DataType, FilterType = any> {
15
17
  protected subscriptions: Map<string, Subscription<DataType, FilterType>>;
16
18
  constructor();
17
19
  /**
@@ -88,6 +90,306 @@ interface IProviderManager {
88
90
  getAdapter(config: RuntimeProviderConfig): Promise<ManagedAdapterAccessor>;
89
91
  }
90
92
 
93
+ /**
94
+ * Defines the available logging levels, ordered from most verbose to least verbose.
95
+ */
96
+ declare enum LogLevel {
97
+ /** Detailed debugging information, useful for development. */
98
+ DEBUG = 0,
99
+ /** General informational messages about application flow. */
100
+ INFO = 1,
101
+ /** Potential issues or unexpected situations that don't prevent execution. */
102
+ WARN = 2,
103
+ /** Errors that indicate a failure or problem. */
104
+ ERROR = 3
105
+ }
106
+ /**
107
+ * Configuration options for the static Logger class.
108
+ */
109
+ interface LoggerConfig {
110
+ /** The minimum log level to output messages for. Messages below this level will be ignored. */
111
+ level: LogLevel;
112
+ /** An optional prefix string to prepend to all log messages (e.g., '[MyApp]'). Defaults to '[ART]'. */
113
+ prefix?: string;
114
+ }
115
+ /**
116
+ * A simple static logger class for outputting messages to the console at different levels.
117
+ * Configuration is global via the static `configure` method.
118
+ */
119
+ declare class Logger {
120
+ private static config;
121
+ /**
122
+ * Configures the static logger settings.
123
+ * @param config - A partial `LoggerConfig` object. Provided settings will override defaults.
124
+ */
125
+ static configure(config: Partial<LoggerConfig>): void;
126
+ /**
127
+ * Logs a message at the DEBUG level.
128
+ * Only outputs if the configured log level is DEBUG.
129
+ * @param message - The main log message string.
130
+ * @param args - Additional arguments to include in the console output (e.g., objects, arrays).
131
+ */
132
+ static debug(message: string, ...args: any[]): void;
133
+ /**
134
+ * Logs a message at the INFO level.
135
+ * Outputs if the configured log level is INFO or DEBUG.
136
+ * @param message - The main log message string.
137
+ * @param args - Additional arguments to include in the console output.
138
+ */
139
+ static info(message: string, ...args: any[]): void;
140
+ /**
141
+ * Logs a message at the WARN level.
142
+ * Outputs if the configured log level is WARN, INFO, or DEBUG.
143
+ * @param message - The main log message string.
144
+ * @param args - Additional arguments to include in the console output.
145
+ */
146
+ static warn(message: string, ...args: any[]): void;
147
+ /**
148
+ * Logs a message at the ERROR level.
149
+ * Outputs if the configured log level is ERROR, WARN, INFO, or DEBUG.
150
+ * @param message - The main log message string.
151
+ * @param args - Additional arguments to include in the console output (often an error object).
152
+ */
153
+ static error(message: string, ...args: any[]): void;
154
+ }
155
+
156
+ /**
157
+ * Defines standard error codes for the ART framework.
158
+ */
159
+ declare enum ErrorCode {
160
+ INVALID_CONFIG = "INVALID_CONFIG",
161
+ MISSING_API_KEY = "MISSING_API_KEY",
162
+ STORAGE_ERROR = "STORAGE_ERROR",
163
+ THREAD_NOT_FOUND = "THREAD_NOT_FOUND",
164
+ SAVE_FAILED = "SAVE_FAILED",
165
+ LLM_PROVIDER_ERROR = "LLM_PROVIDER_ERROR",
166
+ PROMPT_GENERATION_FAILED = "PROMPT_GENERATION_FAILED",
167
+ OUTPUT_PARSING_FAILED = "OUTPUT_PARSING_FAILED",
168
+ PROMPT_ASSEMBLY_FAILED = "PROMPT_ASSEMBLY_FAILED",// Error during prompt template rendering or initial structure creation (legacy, might be removed)
169
+ PROMPT_FRAGMENT_NOT_FOUND = "PROMPT_FRAGMENT_NOT_FOUND",// Requested prompt fragment does not exist
170
+ PROMPT_VALIDATION_FAILED = "PROMPT_VALIDATION_FAILED",// Constructed prompt object failed schema validation
171
+ PROMPT_TRANSLATION_FAILED = "PROMPT_TRANSLATION_FAILED",// Added for Adapter translation
172
+ TOOL_NOT_FOUND = "TOOL_NOT_FOUND",
173
+ TOOL_SCHEMA_VALIDATION_FAILED = "TOOL_SCHEMA_VALIDATION_FAILED",
174
+ TOOL_EXECUTION_ERROR = "TOOL_EXECUTION_ERROR",// Generic tool execution error
175
+ TOOL_DISABLED = "TOOL_DISABLED",
176
+ PLANNING_FAILED = "PLANNING_FAILED",
177
+ TOOL_EXECUTION_FAILED = "TOOL_EXECUTION_FAILED",// Error within the ToolSystem execution loop
178
+ SYNTHESIS_FAILED = "SYNTHESIS_FAILED",
179
+ AGENT_PROCESSING_ERROR = "AGENT_PROCESSING_ERROR",// General error during agent.process
180
+ NETWORK_ERROR = "NETWORK_ERROR",
181
+ TIMEOUT_ERROR = "TIMEOUT_ERROR",
182
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
183
+ UNKNOWN_PROVIDER = "UNKNOWN_PROVIDER",// Checklist item 4.7
184
+ LOCAL_PROVIDER_CONFLICT = "LOCAL_PROVIDER_CONFLICT",// Checklist item 4.7
185
+ LOCAL_INSTANCE_BUSY = "LOCAL_INSTANCE_BUSY",// Checklist item 4.7
186
+ API_QUEUE_TIMEOUT = "API_QUEUE_TIMEOUT",// Checklist item 4.7 (optional)
187
+ ADAPTER_INSTANTIATION_ERROR = "ADAPTER_INSTANTIATION_ERROR"
188
+ }
189
+ /**
190
+ * Custom error class for ART framework specific errors.
191
+ */
192
+ declare class ARTError extends Error {
193
+ readonly code: ErrorCode;
194
+ readonly originalError?: Error;
195
+ constructor(message: string, code: ErrorCode, originalError?: Error);
196
+ toString(): string;
197
+ }
198
+ declare class UnknownProviderError extends ARTError {
199
+ constructor(providerName: string);
200
+ }
201
+ declare class LocalProviderConflictError extends ARTError {
202
+ constructor(requestedProvider: string, activeProvider: string);
203
+ }
204
+ declare class LocalInstanceBusyError extends ARTError {
205
+ constructor(providerName: string, modelId: string);
206
+ }
207
+ declare class ApiQueueTimeoutError extends ARTError {
208
+ constructor(providerName: string);
209
+ }
210
+ declare class AdapterInstantiationError extends ARTError {
211
+ constructor(providerName: string, originalError: Error);
212
+ }
213
+
214
+ /**
215
+ * Zod schema for validating a single ArtStandardMessage object.
216
+ */
217
+ declare const ArtStandardMessageSchema: z.ZodEffects<z.ZodObject<{
218
+ role: z.ZodType<ArtStandardMessageRole, z.ZodTypeDef, ArtStandardMessageRole>;
219
+ content: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>;
220
+ name: z.ZodOptional<z.ZodString>;
221
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
222
+ id: z.ZodString;
223
+ type: z.ZodLiteral<"function">;
224
+ function: z.ZodObject<{
225
+ name: z.ZodString;
226
+ arguments: z.ZodString;
227
+ }, "strip", z.ZodTypeAny, {
228
+ name: string;
229
+ arguments: string;
230
+ }, {
231
+ name: string;
232
+ arguments: string;
233
+ }>;
234
+ }, "strip", z.ZodTypeAny, {
235
+ function: {
236
+ name: string;
237
+ arguments: string;
238
+ };
239
+ type: "function";
240
+ id: string;
241
+ }, {
242
+ function: {
243
+ name: string;
244
+ arguments: string;
245
+ };
246
+ type: "function";
247
+ id: string;
248
+ }>, "many">>;
249
+ tool_call_id: z.ZodOptional<z.ZodString>;
250
+ }, "strict", z.ZodTypeAny, {
251
+ role: ArtStandardMessageRole;
252
+ content: string | Record<string, any> | null;
253
+ name?: string | undefined;
254
+ tool_calls?: {
255
+ function: {
256
+ name: string;
257
+ arguments: string;
258
+ };
259
+ type: "function";
260
+ id: string;
261
+ }[] | undefined;
262
+ tool_call_id?: string | undefined;
263
+ }, {
264
+ role: ArtStandardMessageRole;
265
+ content: string | Record<string, any> | null;
266
+ name?: string | undefined;
267
+ tool_calls?: {
268
+ function: {
269
+ name: string;
270
+ arguments: string;
271
+ };
272
+ type: "function";
273
+ id: string;
274
+ }[] | undefined;
275
+ tool_call_id?: string | undefined;
276
+ }>, {
277
+ role: ArtStandardMessageRole;
278
+ content: string | Record<string, any> | null;
279
+ name?: string | undefined;
280
+ tool_calls?: {
281
+ function: {
282
+ name: string;
283
+ arguments: string;
284
+ };
285
+ type: "function";
286
+ id: string;
287
+ }[] | undefined;
288
+ tool_call_id?: string | undefined;
289
+ }, {
290
+ role: ArtStandardMessageRole;
291
+ content: string | Record<string, any> | null;
292
+ name?: string | undefined;
293
+ tool_calls?: {
294
+ function: {
295
+ name: string;
296
+ arguments: string;
297
+ };
298
+ type: "function";
299
+ id: string;
300
+ }[] | undefined;
301
+ tool_call_id?: string | undefined;
302
+ }>;
303
+ /**
304
+ * Zod schema for validating an entire ArtStandardPrompt (an array of messages).
305
+ */
306
+ declare const ArtStandardPromptSchema: z.ZodArray<z.ZodEffects<z.ZodObject<{
307
+ role: z.ZodType<ArtStandardMessageRole, z.ZodTypeDef, ArtStandardMessageRole>;
308
+ content: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>;
309
+ name: z.ZodOptional<z.ZodString>;
310
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
311
+ id: z.ZodString;
312
+ type: z.ZodLiteral<"function">;
313
+ function: z.ZodObject<{
314
+ name: z.ZodString;
315
+ arguments: z.ZodString;
316
+ }, "strip", z.ZodTypeAny, {
317
+ name: string;
318
+ arguments: string;
319
+ }, {
320
+ name: string;
321
+ arguments: string;
322
+ }>;
323
+ }, "strip", z.ZodTypeAny, {
324
+ function: {
325
+ name: string;
326
+ arguments: string;
327
+ };
328
+ type: "function";
329
+ id: string;
330
+ }, {
331
+ function: {
332
+ name: string;
333
+ arguments: string;
334
+ };
335
+ type: "function";
336
+ id: string;
337
+ }>, "many">>;
338
+ tool_call_id: z.ZodOptional<z.ZodString>;
339
+ }, "strict", z.ZodTypeAny, {
340
+ role: ArtStandardMessageRole;
341
+ content: string | Record<string, any> | null;
342
+ name?: string | undefined;
343
+ tool_calls?: {
344
+ function: {
345
+ name: string;
346
+ arguments: string;
347
+ };
348
+ type: "function";
349
+ id: string;
350
+ }[] | undefined;
351
+ tool_call_id?: string | undefined;
352
+ }, {
353
+ role: ArtStandardMessageRole;
354
+ content: string | Record<string, any> | null;
355
+ name?: string | undefined;
356
+ tool_calls?: {
357
+ function: {
358
+ name: string;
359
+ arguments: string;
360
+ };
361
+ type: "function";
362
+ id: string;
363
+ }[] | undefined;
364
+ tool_call_id?: string | undefined;
365
+ }>, {
366
+ role: ArtStandardMessageRole;
367
+ content: string | Record<string, any> | null;
368
+ name?: string | undefined;
369
+ tool_calls?: {
370
+ function: {
371
+ name: string;
372
+ arguments: string;
373
+ };
374
+ type: "function";
375
+ id: string;
376
+ }[] | undefined;
377
+ tool_call_id?: string | undefined;
378
+ }, {
379
+ role: ArtStandardMessageRole;
380
+ content: string | Record<string, any> | null;
381
+ name?: string | undefined;
382
+ tool_calls?: {
383
+ function: {
384
+ name: string;
385
+ arguments: string;
386
+ };
387
+ type: "function";
388
+ id: string;
389
+ }[] | undefined;
390
+ tool_call_id?: string | undefined;
391
+ }>, "many">;
392
+
91
393
  /**
92
394
  * Represents the role of a message sender in a conversation.
93
395
  */
@@ -332,13 +634,19 @@ interface ThreadConfig {
332
634
  enabledTools: string[];
333
635
  /** The maximum number of past messages (`ConversationMessage` objects) to retrieve for context. */
334
636
  historyLimit: number;
637
+ /** Optional system prompt string to be used for this thread, overriding instance or agent defaults. */
638
+ systemPrompt?: string;
335
639
  }
336
640
  /**
337
641
  * Represents non-configuration state associated with an agent or thread.
338
642
  * Could include user preferences, accumulated knowledge, etc. (Less defined for v1.0)
339
643
  */
340
644
  interface AgentState {
341
- /** A flexible object to store persistent, non-configuration data associated with a thread or user (e.g., preferences, summaries, intermediate results). Structure is application-defined. */
645
+ /** The primary data payload of the agent's state. Structure is application-defined. */
646
+ data: any;
647
+ /** An optional version number for the agent's state, useful for migrations or tracking changes. */
648
+ version?: number;
649
+ /** Allows for other arbitrary properties to be stored in the agent's state. */
342
650
  [key: string]: any;
343
651
  }
344
652
  /**
@@ -386,6 +694,8 @@ interface AgentOptions {
386
694
  stream?: boolean;
387
695
  /** Override the prompt template used for this specific call. */
388
696
  promptTemplateId?: string;
697
+ /** Optional system prompt string to override thread, instance, or agent defaults for this specific call. */
698
+ systemPrompt?: string;
389
699
  }
390
700
  /**
391
701
  * The final structured response returned by the agent core after processing.
@@ -609,13 +919,70 @@ interface ObservationFilter {
609
919
  /** Retrieve observations recorded after this Unix timestamp (milliseconds). */
610
920
  afterTimestamp?: number;
611
921
  }
922
+ /**
923
+ * Defines the strategy for saving AgentState.
924
+ * - 'explicit': AgentState is only saved when `StateManager.setAgentState()` is explicitly called by the agent.
925
+ * `StateManager.saveStateIfModified()` will be a no-op for AgentState persistence.
926
+ * - 'implicit': AgentState is loaded by `StateManager.loadThreadContext()`, and if modified by the agent,
927
+ * `StateManager.saveStateIfModified()` will attempt to automatically persist these changes
928
+ * by comparing the current state with a snapshot taken at load time.
929
+ * `StateManager.setAgentState()` will still work for explicit saves.
930
+ */
931
+ type StateSavingStrategy = 'explicit' | 'implicit';
932
+
933
+ /**
934
+ * Configuration for creating an ART instance.
935
+ */
936
+ interface ArtInstanceConfig {
937
+ /**
938
+ * Configuration for the storage adapter.
939
+ * Can be a pre-configured `StorageAdapter` instance,
940
+ * or an object specifying the type and options for a built-in adapter.
941
+ * Example: `{ type: 'indexedDB', dbName: 'MyArtDB' }`
942
+ */
943
+ storage: StorageAdapter | {
944
+ type: 'memory' | 'indexedDB';
945
+ dbName?: string;
946
+ version?: number;
947
+ objectStores?: any[];
948
+ };
949
+ /** Configuration for the ProviderManager, defining available LLM provider adapters. */
950
+ providers: ProviderManagerConfig;
951
+ /**
952
+ * The agent core implementation class to use.
953
+ * Defaults to `PESAgent` if not provided.
954
+ * Example: `MyCustomAgentClass`
955
+ */
956
+ agentCore?: new (dependencies: any) => IAgentCore;
957
+ /** An optional array of tool executor instances to register at initialization. */
958
+ tools?: IToolExecutor[];
959
+ /**
960
+ * Defines the strategy for saving `AgentState`. Defaults to 'explicit'.
961
+ * - 'explicit': `AgentState` is only saved when `StateManager.setAgentState()` is explicitly called by the agent.
962
+ * `StateManager.saveStateIfModified()` will be a no-op for `AgentState` persistence.
963
+ * - 'implicit': `AgentState` is loaded by `StateManager.loadThreadContext()`. If modified by the agent,
964
+ * `StateManager.saveStateIfModified()` will attempt to automatically persist these changes.
965
+ * `StateManager.setAgentState()` will still work for explicit saves in this mode.
966
+ */
967
+ stateSavingStrategy?: StateSavingStrategy;
968
+ /** Optional configuration for the framework's logger. */
969
+ logger?: {
970
+ /** Minimum log level to output. Defaults to 'info'. */
971
+ level?: LogLevel;
972
+ };
973
+ /**
974
+ * Optional default system prompt string to be used for the entire ART instance.
975
+ * This can be overridden at the thread level or at the individual call level.
976
+ */
977
+ defaultSystemPrompt?: string;
978
+ }
612
979
 
613
980
  type StreamEventTypeFilter = StreamEvent['type'] | Array<StreamEvent['type']>;
614
981
  /**
615
982
  * A dedicated socket for broadcasting LLM stream events (`StreamEvent`) to UI subscribers.
616
983
  * Extends the generic TypedSocket and implements filtering based on `StreamEvent.type`.
617
984
  */
618
- declare class LLMStreamSocket extends TypedSocket$1<StreamEvent, StreamEventTypeFilter> {
985
+ declare class LLMStreamSocket extends TypedSocket<StreamEvent, StreamEventTypeFilter> {
619
986
  constructor();
620
987
  /**
621
988
  * Notifies subscribers about a new LLM stream event.
@@ -630,7 +997,7 @@ declare class LLMStreamSocket extends TypedSocket$1<StreamEvent, StreamEventType
630
997
  * Allows filtering by ObservationType.
631
998
  * Can optionally fetch historical observations from a repository.
632
999
  */
633
- declare class ObservationSocket$1 extends TypedSocket$1<Observation, ObservationType | ObservationType[]> {
1000
+ declare class ObservationSocket$1 extends TypedSocket<Observation, ObservationType | ObservationType[]> {
634
1001
  private observationRepository?;
635
1002
  constructor(observationRepository?: IObservationRepository);
636
1003
  /**
@@ -656,7 +1023,7 @@ declare class ObservationSocket$1 extends TypedSocket$1<Observation, Observation
656
1023
  * Allows filtering by MessageRole.
657
1024
  * Can optionally fetch historical messages from a repository.
658
1025
  */
659
- declare class ConversationSocket$1 extends TypedSocket$1<ConversationMessage, MessageRole | MessageRole[]> {
1026
+ declare class ConversationSocket$1 extends TypedSocket<ConversationMessage, MessageRole | MessageRole[]> {
660
1027
  private conversationRepository?;
661
1028
  constructor(conversationRepository?: IConversationRepository);
662
1029
  /**
@@ -867,6 +1234,17 @@ interface StateManager {
867
1234
  * @returns A promise that resolves when the configuration is saved.
868
1235
  */
869
1236
  setThreadConfig(threadId: string, config: ThreadConfig): Promise<void>;
1237
+ /**
1238
+ * Sets or updates the AgentState for a specific thread.
1239
+ * This method allows an agent to explicitly persist its internal state.
1240
+ * It requires that a ThreadConfig already exists for the thread, which is typically
1241
+ * ensured by the application calling setThreadConfig() prior to agent execution.
1242
+ * @param threadId - The unique identifier of the thread.
1243
+ * @param state - The AgentState object to save.
1244
+ * @returns A promise that resolves when the state is saved.
1245
+ * @throws {ARTError} If no ThreadConfig exists for the threadId, or if the repository fails.
1246
+ */
1247
+ setAgentState(threadId: string, state: AgentState): Promise<void>;
870
1248
  }
871
1249
  /**
872
1250
  * Interface for managing conversation history.
@@ -911,7 +1289,7 @@ interface ObservationManager {
911
1289
  /**
912
1290
  * Generic interface for a typed publish/subscribe socket.
913
1291
  */
914
- interface TypedSocket<DataType, FilterType = any> {
1292
+ interface ITypedSocket<DataType, FilterType = any> {
915
1293
  /**
916
1294
  * Subscribes a callback function to receive data updates.
917
1295
  * @param callback The function to call with new data.
@@ -945,13 +1323,13 @@ interface TypedSocket<DataType, FilterType = any> {
945
1323
  * TypedSocket specifically for Observation data.
946
1324
  * FilterType is ObservationType or array of ObservationType.
947
1325
  */
948
- interface ObservationSocket extends TypedSocket<Observation, ObservationType | ObservationType[]> {
1326
+ interface ObservationSocket extends ITypedSocket<Observation, ObservationType | ObservationType[]> {
949
1327
  }
950
1328
  /**
951
1329
  * TypedSocket specifically for ConversationMessage data.
952
1330
  * FilterType is MessageRole or array of MessageRole.
953
1331
  */
954
- interface ConversationSocket extends TypedSocket<ConversationMessage, MessageRole | MessageRole[]> {
1332
+ interface ConversationSocket extends ITypedSocket<ConversationMessage, MessageRole | MessageRole[]> {
955
1333
  }
956
1334
 
957
1335
  /**
@@ -1042,99 +1420,6 @@ interface ArtInstance {
1042
1420
  readonly observationManager: ObservationManager;
1043
1421
  }
1044
1422
 
1045
- /**
1046
- * Defines the available logging levels, ordered from most verbose to least verbose.
1047
- */
1048
- declare enum LogLevel {
1049
- /** Detailed debugging information, useful for development. */
1050
- DEBUG = 0,
1051
- /** General informational messages about application flow. */
1052
- INFO = 1,
1053
- /** Potential issues or unexpected situations that don't prevent execution. */
1054
- WARN = 2,
1055
- /** Errors that indicate a failure or problem. */
1056
- ERROR = 3
1057
- }
1058
- /**
1059
- * Configuration options for the static Logger class.
1060
- */
1061
- interface LoggerConfig {
1062
- /** The minimum log level to output messages for. Messages below this level will be ignored. */
1063
- level: LogLevel;
1064
- /** An optional prefix string to prepend to all log messages (e.g., '[MyApp]'). Defaults to '[ART]'. */
1065
- prefix?: string;
1066
- }
1067
- /**
1068
- * A simple static logger class for outputting messages to the console at different levels.
1069
- * Configuration is global via the static `configure` method.
1070
- */
1071
- declare class Logger {
1072
- private static config;
1073
- /**
1074
- * Configures the static logger settings.
1075
- * @param config - A partial `LoggerConfig` object. Provided settings will override defaults.
1076
- */
1077
- static configure(config: Partial<LoggerConfig>): void;
1078
- /**
1079
- * Logs a message at the DEBUG level.
1080
- * Only outputs if the configured log level is DEBUG.
1081
- * @param message - The main log message string.
1082
- * @param args - Additional arguments to include in the console output (e.g., objects, arrays).
1083
- */
1084
- static debug(message: string, ...args: any[]): void;
1085
- /**
1086
- * Logs a message at the INFO level.
1087
- * Outputs if the configured log level is INFO or DEBUG.
1088
- * @param message - The main log message string.
1089
- * @param args - Additional arguments to include in the console output.
1090
- */
1091
- static info(message: string, ...args: any[]): void;
1092
- /**
1093
- * Logs a message at the WARN level.
1094
- * Outputs if the configured log level is WARN, INFO, or DEBUG.
1095
- * @param message - The main log message string.
1096
- * @param args - Additional arguments to include in the console output.
1097
- */
1098
- static warn(message: string, ...args: any[]): void;
1099
- /**
1100
- * Logs a message at the ERROR level.
1101
- * Outputs if the configured log level is ERROR, WARN, INFO, or DEBUG.
1102
- * @param message - The main log message string.
1103
- * @param args - Additional arguments to include in the console output (often an error object).
1104
- */
1105
- static error(message: string, ...args: any[]): void;
1106
- }
1107
-
1108
- /**
1109
- * Configuration for the Storage System adapter.
1110
- */
1111
- interface StorageConfig {
1112
- /** Specifies the type of storage adapter to use. */
1113
- type: 'memory' | 'indexedDB';
1114
- /** The name of the database to use (required for 'indexedDB'). */
1115
- dbName?: string;
1116
- /** Optional: Database version for schema migrations (for 'indexedDB'). Defaults might apply. */
1117
- version?: number;
1118
- /** Optional: Advanced configuration for IndexedDB object stores and indexes. Defaults are usually sufficient. */
1119
- objectStores?: any[];
1120
- }
1121
- /**
1122
- * Configuration object required by the AgentFactory and createArtInstance function.
1123
- */
1124
- interface AgentFactoryConfig {
1125
- /** Configuration for the storage adapter. */
1126
- storage: StorageConfig;
1127
- /** Configuration for the Provider Manager, defining available adapters and rules. */
1128
- providers: ProviderManagerConfig;
1129
- /** Optional array of tool executor instances to register at initialization. */
1130
- tools?: IToolExecutor[];
1131
- /** Optional: Specify a different Agent Core implementation class (defaults to PESAgent). */
1132
- agentCore?: new (dependencies: any) => IAgentCore;
1133
- /** Optional: Configuration for the logger. */
1134
- logger?: {
1135
- level?: LogLevel;
1136
- };
1137
- }
1138
1423
  /**
1139
1424
  * High-level factory function to create and initialize a complete ART framework instance.
1140
1425
  * This simplifies the setup process by handling the instantiation and wiring of all
@@ -1150,7 +1435,7 @@ interface AgentFactoryConfig {
1150
1435
  * });
1151
1436
  * const response = await art.process({ query: "Calculate 5*5", threadId: "thread1" });
1152
1437
  */
1153
- declare function createArtInstance(config: AgentFactoryConfig): Promise<ArtInstance>;
1438
+ declare function createArtInstance(config: ArtInstanceConfig): Promise<ArtInstance>;
1154
1439
 
1155
1440
  /**
1156
1441
  * Defines the dependencies required by the PESAgent constructor.
@@ -1159,6 +1444,12 @@ declare function createArtInstance(config: AgentFactoryConfig): Promise<ArtInsta
1159
1444
  interface PESAgentDependencies {
1160
1445
  /** Manages thread configuration and state. */
1161
1446
  stateManager: StateManager;
1447
+ /**
1448
+ * Optional default system prompt string provided at the ART instance level.
1449
+ * This serves as a custom prompt part if no thread-specific or call-specific
1450
+ * system prompt is provided. It's appended to the agent's base system prompt.
1451
+ */
1452
+ instanceDefaultCustomSystemPrompt?: string;
1162
1453
  /** Manages conversation history. */
1163
1454
  conversationManager: ConversationManager;
1164
1455
  /** Registry for available tools. */
@@ -1192,7 +1483,13 @@ interface PESAgentDependencies {
1192
1483
  */
1193
1484
  declare class PESAgent implements IAgentCore {
1194
1485
  private readonly deps;
1486
+ /** The base system prompt inherent to this agent. */
1195
1487
  private readonly defaultSystemPrompt;
1488
+ /**
1489
+ * Stores the instance-level default custom system prompt, passed during construction.
1490
+ * Used in the system prompt hierarchy if no thread or call-level prompt is specified.
1491
+ */
1492
+ private readonly instanceDefaultCustomSystemPrompt?;
1196
1493
  /**
1197
1494
  * Creates an instance of the PESAgent.
1198
1495
  * @param dependencies - An object containing instances of all required subsystems (managers, registries, etc.).
@@ -1202,8 +1499,11 @@ declare class PESAgent implements IAgentCore {
1202
1499
  * Executes the full Plan-Execute-Synthesize cycle for a given user query.
1203
1500
  *
1204
1501
  * **Workflow:**
1205
- * 1. **Initiation & Config:** Loads thread configuration and system prompt.
1206
- * 2. **Data Gathering:** Gathers history, available tools, system prompt, and query.
1502
+ * 1. **Initiation & Config:** Loads thread configuration. Resolves the final system prompt based on a hierarchy:
1503
+ * Call-level (`AgentProps.options.systemPrompt`) > Thread-level (`ThreadConfig.systemPrompt`) >
1504
+ * Instance-level (`ArtInstanceConfig.defaultSystemPrompt` via constructor) > Agent's base prompt.
1505
+ * The resolved custom part is appended to the agent's base prompt.
1506
+ * 2. **Data Gathering:** Gathers history, available tools, the resolved system prompt, and query.
1207
1507
  * 3. **Planning Prompt Construction:** Directly constructs the `ArtStandardPrompt` object/array for planning.
1208
1508
  * 4. **Planning LLM Call:** Sends the planning prompt object to the `reasoningEngine` (requesting streaming). Consumes the `StreamEvent` stream, buffers the output text, and handles potential errors.
1209
1509
  * 5. **Planning Output Parsing:** Parses the buffered planning output text to extract intent, plan, and tool calls using `outputParser.parsePlanningOutput`.
@@ -1730,6 +2030,73 @@ declare class DeepSeekAdapter implements ProviderAdapter {
1730
2030
  private translateToOpenAI;
1731
2031
  }
1732
2032
 
2033
+ /**
2034
+ * Configuration options required for the `OllamaAdapter`.
2035
+ */
2036
+ interface OllamaAdapterOptions {
2037
+ /**
2038
+ * The base URL for the Ollama API. Defaults to 'http://localhost:11434'.
2039
+ * The '/v1' suffix for OpenAI compatibility will be added automatically.
2040
+ */
2041
+ ollamaBaseUrl?: string;
2042
+ /**
2043
+ * The default Ollama model ID to use (e.g., 'llama3', 'mistral').
2044
+ * This can be overridden by `RuntimeProviderConfig.modelId` or `CallOptions.model`.
2045
+ * It's recommended to set this if you primarily use one model with Ollama.
2046
+ */
2047
+ defaultModel?: string;
2048
+ /**
2049
+ * API key for Ollama (if secured). Defaults to "ollama" as commonly used.
2050
+ */
2051
+ apiKey?: string;
2052
+ }
2053
+ /**
2054
+ * Implements the `ProviderAdapter` interface for interacting with Ollama's
2055
+ * OpenAI-compatible API endpoint.
2056
+ *
2057
+ * Handles formatting requests, parsing responses, streaming, and tool use.
2058
+ *
2059
+ * @implements {ProviderAdapter}
2060
+ */
2061
+ declare class OllamaAdapter implements ProviderAdapter {
2062
+ readonly providerName = "ollama";
2063
+ private client;
2064
+ private defaultModel?;
2065
+ private ollamaBaseUrl;
2066
+ /**
2067
+ * Creates an instance of the OllamaAdapter.
2068
+ * @param options - Configuration options.
2069
+ */
2070
+ constructor(options: OllamaAdapterOptions);
2071
+ /**
2072
+ * Sends a request to the Ollama API.
2073
+ * Translates `ArtStandardPrompt` to the OpenAI format and handles streaming and tool use.
2074
+ *
2075
+ * @param {ArtStandardPrompt} prompt - The standardized prompt messages.
2076
+ * @param {CallOptions} options - Call options.
2077
+ * @returns {Promise<AsyncIterable<StreamEvent>>} A promise resolving to an AsyncIterable of StreamEvent objects.
2078
+ */
2079
+ call(prompt: ArtStandardPrompt, options: CallOptions): Promise<AsyncIterable<StreamEvent>>;
2080
+ /**
2081
+ * Translates the provider-agnostic `ArtStandardPrompt` into the OpenAI API's `OpenAIMessage[]` format.
2082
+ * This is a common utility function that can be shared or adapted from other OpenAI-compatible adapters.
2083
+ */
2084
+ private translateToOpenAI;
2085
+ private mapArtMessageToOpenAIMessage;
2086
+ /**
2087
+ * Translates ART ToolSchema array to OpenAI's tool format.
2088
+ */
2089
+ private translateArtToolsToOpenAI;
2090
+ /**
2091
+ * Optional method for graceful shutdown.
2092
+ * For Ollama, which is typically a separate local server, this adapter
2093
+ * doesn't manage persistent connections that need explicit closing.
2094
+ * The OpenAI client used internally might have its own cleanup, but
2095
+ * it's generally handled by garbage collection.
2096
+ */
2097
+ shutdown(): Promise<void>;
2098
+ }
2099
+
1733
2100
  /**
1734
2101
  * An ART Framework tool that safely evaluates mathematical expressions using the mathjs library.
1735
2102
  * It supports basic arithmetic, variables via a scope, complex numbers, and a predefined list of safe functions.
@@ -1780,6 +2147,6 @@ declare const generateUUID: () => string;
1780
2147
  */
1781
2148
 
1782
2149
  /** The current version of the ART Framework package. */
1783
- declare const VERSION = "0.2.4";
2150
+ declare const VERSION = "0.2.8";
1784
2151
 
1785
- export { type AgentFinalResponse, type AgentOptions, type AgentProps, type AgentState, AnthropicAdapter, type ArtInstance, type ArtStandardMessage, type ArtStandardMessageRole, type ArtStandardPrompt, type AvailableProviderEntry, CalculatorTool, type CallOptions, type ConversationManager, type ConversationMessage, type ConversationSocket, DeepSeekAdapter, type ExecutionContext, type ExecutionMetadata, type FilterOptions, type FormattedPrompt, GeminiAdapter, type IAgentCore, type IConversationRepository, type IObservationRepository, type IProviderManager, type IStateRepository, type IToolExecutor, InMemoryStorageAdapter, IndexedDBStorageAdapter, type JsonObjectSchema, type JsonSchema, type LLMMetadata, LogLevel, Logger, type ManagedAdapterAccessor, type MessageOptions, MessageRole, ModelCapability, type Observation, type ObservationFilter, type ObservationManager, type ObservationSocket, ObservationType, OpenAIAdapter, OpenRouterAdapter, type OutputParser, PESAgent, type ParsedToolCall, type PromptContext, type PromptManager, type ProviderAdapter, type ProviderManagerConfig, type ReasoningEngine, type RuntimeProviderConfig, type StateManager, type StorageAdapter, type StreamEvent, type ThreadConfig, type ThreadContext, type ToolRegistry, type ToolResult, type ToolSchema, type ToolSystem, type TypedSocket, type UISystem, VERSION, createArtInstance, generateUUID };
2152
+ export { ARTError, AdapterInstantiationError, type AgentFinalResponse, type AgentOptions, type AgentProps, type AgentState, AnthropicAdapter, ApiQueueTimeoutError, type ArtInstance, type ArtInstanceConfig, type ArtStandardMessage, type ArtStandardMessageRole, ArtStandardMessageSchema, type ArtStandardPrompt, ArtStandardPromptSchema, type AvailableProviderEntry, CalculatorTool, type CallOptions, type ConversationManager, type ConversationMessage, type ConversationSocket, DeepSeekAdapter, ErrorCode, type ExecutionContext, type ExecutionMetadata, type FilterOptions, type FormattedPrompt, GeminiAdapter, type IAgentCore, type IConversationRepository, type IObservationRepository, type IProviderManager, type IStateRepository, type IToolExecutor, type ITypedSocket, InMemoryStorageAdapter, IndexedDBStorageAdapter, type JsonObjectSchema, type JsonSchema, type LLMMetadata, LLMStreamSocket, LocalInstanceBusyError, LocalProviderConflictError, LogLevel, Logger, type ManagedAdapterAccessor, type MessageOptions, MessageRole, ModelCapability, type Observation, type ObservationFilter, type ObservationManager, type ObservationSocket, ObservationType, OllamaAdapter, type OllamaAdapterOptions, OpenAIAdapter, OpenRouterAdapter, type OutputParser, PESAgent, type ParsedToolCall, type PromptContext, type PromptManager, type ProviderAdapter, type ProviderManagerConfig, type ReasoningEngine, type RuntimeProviderConfig, type StateManager, type StateSavingStrategy, type StorageAdapter, type StreamEvent, type ThreadConfig, type ThreadContext, type ToolRegistry, type ToolResult, type ToolSchema, type ToolSystem, TypedSocket, type UISystem, UnknownProviderError, type UnsubscribeFunction, VERSION, createArtInstance, generateUUID };