@backtest-kit/ollama 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types.d.ts CHANGED
@@ -1,309 +1,261 @@
1
- import { IOutlineMessage, ISwarmCompletionArgs, ISwarmMessage, IOutlineCompletionArgs } from 'agent-swarm-kit';
2
- import { ZodType } from 'zod';
3
1
  import { ISignalDto } from 'backtest-kit';
4
2
  import * as di_scoped from 'di-scoped';
3
+ import { ISwarmCompletionArgs, ISwarmMessage, IOutlineCompletionArgs, IOutlineMessage } from 'agent-swarm-kit';
5
4
  import * as functools_kit from 'functools-kit';
6
5
 
7
6
  /**
8
- * Generate structured trading signal from Ollama models.
7
+ * Wrap async function with Ollama inference context.
9
8
  *
10
- * Supports token rotation by passing multiple API keys. Automatically enforces
11
- * the signal JSON schema defined in Signal.schema.ts.
9
+ * Creates a higher-order function that executes the provided async function
10
+ * within an Ollama inference context. Supports token rotation by passing multiple API keys.
12
11
  *
13
- * @param messages - Array of outline messages (user/assistant/system)
12
+ * @template T - Async function type
13
+ * @param fn - Async function to wrap
14
14
  * @param model - Ollama model name (e.g., "llama3.3:70b")
15
15
  * @param apiKey - Single API key or array of keys for rotation
16
- * @returns Promise resolving to structured trading signal
16
+ * @returns Wrapped function with same signature as input
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
20
  * import { ollama } from '@backtest-kit/ollama';
21
21
  *
22
- * const signal = await ollama(messages, 'llama3.3:70b', ['key1', 'key2']);
23
- * console.log(signal.position); // "long" | "short" | "wait"
22
+ * const wrappedFn = ollama(myAsyncFn, 'llama3.3:70b', ['key1', 'key2']);
23
+ * const result = await wrappedFn(args);
24
24
  * ```
25
25
  */
26
- declare const ollama: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
27
- id: string;
28
- position: "long" | "short";
29
- minuteEstimatedTime: number;
30
- priceStopLoss: number;
31
- priceTakeProfit: number;
32
- note: string;
33
- priceOpen: number;
34
- }>;
26
+ declare const ollama: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
35
27
  /**
36
- * Generate structured trading signal from Grok models.
28
+ * Wrap async function with Grok inference context.
37
29
  *
38
- * Uses xAI Grok models through direct API access. Does NOT support token rotation.
30
+ * Creates a higher-order function that executes the provided async function
31
+ * within a Grok (xAI) inference context.
39
32
  *
40
- * @param messages - Array of outline messages (user/assistant/system)
33
+ * @template T - Async function type
34
+ * @param fn - Async function to wrap
41
35
  * @param model - Grok model name (e.g., "grok-beta")
42
- * @param apiKey - Single API key (token rotation not supported)
43
- * @returns Promise resolving to structured trading signal
44
- * @throws Error if apiKey is an array (token rotation not supported)
36
+ * @param apiKey - Single API key or array of keys
37
+ * @returns Wrapped function with same signature as input
45
38
  *
46
39
  * @example
47
40
  * ```typescript
48
41
  * import { grok } from '@backtest-kit/ollama';
49
42
  *
50
- * const signal = await grok(messages, 'grok-beta', process.env.GROK_API_KEY);
43
+ * const wrappedFn = grok(myAsyncFn, 'grok-beta', process.env.GROK_API_KEY);
44
+ * const result = await wrappedFn(args);
51
45
  * ```
52
46
  */
53
- declare const grok: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
54
- id: string;
55
- position: "long" | "short";
56
- minuteEstimatedTime: number;
57
- priceStopLoss: number;
58
- priceTakeProfit: number;
59
- note: string;
60
- priceOpen: number;
61
- }>;
47
+ declare const grok: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
62
48
  /**
63
- * Generate structured trading signal from Hugging Face models.
49
+ * Wrap async function with HuggingFace inference context.
64
50
  *
65
- * Uses HuggingFace Router API for model access. Does NOT support token rotation.
51
+ * Creates a higher-order function that executes the provided async function
52
+ * within a HuggingFace Router API inference context.
66
53
  *
67
- * @param messages - Array of outline messages (user/assistant/system)
68
- * @param model - HuggingFace model name
69
- * @param apiKey - Single API key (token rotation not supported)
70
- * @returns Promise resolving to structured trading signal
54
+ * @template T - Async function type
55
+ * @param fn - Async function to wrap
56
+ * @param model - HuggingFace model name (e.g., "meta-llama/Llama-3-70b")
57
+ * @param apiKey - Single API key or array of keys
58
+ * @returns Wrapped function with same signature as input
71
59
  *
72
60
  * @example
73
61
  * ```typescript
74
62
  * import { hf } from '@backtest-kit/ollama';
75
63
  *
76
- * const signal = await hf(messages, 'meta-llama/Llama-3-70b', process.env.HF_API_KEY);
64
+ * const wrappedFn = hf(myAsyncFn, 'meta-llama/Llama-3-70b', process.env.HF_API_KEY);
65
+ * const result = await wrappedFn(args);
77
66
  * ```
78
67
  */
79
- declare const hf: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
80
- id: string;
81
- position: "long" | "short";
82
- minuteEstimatedTime: number;
83
- priceStopLoss: number;
84
- priceTakeProfit: number;
85
- note: string;
86
- priceOpen: number;
87
- }>;
68
+ declare const hf: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
88
69
  /**
89
- * Generate structured trading signal from Claude models.
70
+ * Wrap async function with Claude inference context.
90
71
  *
91
- * Uses Anthropic Claude through OpenAI-compatible API. Does NOT support token rotation.
72
+ * Creates a higher-order function that executes the provided async function
73
+ * within an Anthropic Claude inference context.
92
74
  *
93
- * @param messages - Array of outline messages (user/assistant/system)
75
+ * @template T - Async function type
76
+ * @param fn - Async function to wrap
94
77
  * @param model - Claude model name (e.g., "claude-3-5-sonnet-20241022")
95
- * @param apiKey - Single API key (token rotation not supported)
96
- * @returns Promise resolving to structured trading signal
97
- * @throws Error if apiKey is an array (token rotation not supported)
78
+ * @param apiKey - Single API key or array of keys
79
+ * @returns Wrapped function with same signature as input
98
80
  *
99
81
  * @example
100
82
  * ```typescript
101
83
  * import { claude } from '@backtest-kit/ollama';
102
84
  *
103
- * const signal = await claude(messages, 'claude-3-5-sonnet-20241022', process.env.ANTHROPIC_API_KEY);
85
+ * const wrappedFn = claude(myAsyncFn, 'claude-3-5-sonnet-20241022', process.env.ANTHROPIC_API_KEY);
86
+ * const result = await wrappedFn(args);
104
87
  * ```
105
88
  */
106
- declare const claude: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
107
- id: string;
108
- position: "long" | "short";
109
- minuteEstimatedTime: number;
110
- priceStopLoss: number;
111
- priceTakeProfit: number;
112
- note: string;
113
- priceOpen: number;
114
- }>;
89
+ declare const claude: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
115
90
  /**
116
- * Generate structured trading signal from OpenAI GPT models.
91
+ * Wrap async function with OpenAI GPT inference context.
117
92
  *
118
- * Uses official OpenAI SDK with JSON schema enforcement. Does NOT support token rotation.
93
+ * Creates a higher-order function that executes the provided async function
94
+ * within an OpenAI GPT inference context.
119
95
  *
120
- * @param messages - Array of outline messages (user/assistant/system)
96
+ * @template T - Async function type
97
+ * @param fn - Async function to wrap
121
98
  * @param model - OpenAI model name (e.g., "gpt-4o", "gpt-4-turbo")
122
- * @param apiKey - Single API key (token rotation not supported)
123
- * @returns Promise resolving to structured trading signal
124
- * @throws Error if apiKey is an array (token rotation not supported)
99
+ * @param apiKey - Single API key or array of keys
100
+ * @returns Wrapped function with same signature as input
125
101
  *
126
102
  * @example
127
103
  * ```typescript
128
104
  * import { gpt5 } from '@backtest-kit/ollama';
129
105
  *
130
- * const signal = await gpt5(messages, 'gpt-4o', process.env.OPENAI_API_KEY);
106
+ * const wrappedFn = gpt5(myAsyncFn, 'gpt-4o', process.env.OPENAI_API_KEY);
107
+ * const result = await wrappedFn(args);
131
108
  * ```
132
109
  */
133
- declare const gpt5: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
134
- id: string;
135
- position: "long" | "short";
136
- minuteEstimatedTime: number;
137
- priceStopLoss: number;
138
- priceTakeProfit: number;
139
- note: string;
140
- priceOpen: number;
141
- }>;
110
+ declare const gpt5: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
142
111
  /**
143
- * Generate structured trading signal from DeepSeek models.
112
+ * Wrap async function with DeepSeek inference context.
144
113
  *
145
- * Uses DeepSeek AI through OpenAI-compatible API. Does NOT support token rotation.
114
+ * Creates a higher-order function that executes the provided async function
115
+ * within a DeepSeek AI inference context.
146
116
  *
147
- * @param messages - Array of outline messages (user/assistant/system)
117
+ * @template T - Async function type
118
+ * @param fn - Async function to wrap
148
119
  * @param model - DeepSeek model name (e.g., "deepseek-chat")
149
- * @param apiKey - Single API key (token rotation not supported)
150
- * @returns Promise resolving to structured trading signal
151
- * @throws Error if apiKey is an array (token rotation not supported)
120
+ * @param apiKey - Single API key or array of keys
121
+ * @returns Wrapped function with same signature as input
152
122
  *
153
123
  * @example
154
124
  * ```typescript
155
125
  * import { deepseek } from '@backtest-kit/ollama';
156
126
  *
157
- * const signal = await deepseek(messages, 'deepseek-chat', process.env.DEEPSEEK_API_KEY);
127
+ * const wrappedFn = deepseek(myAsyncFn, 'deepseek-chat', process.env.DEEPSEEK_API_KEY);
128
+ * const result = await wrappedFn(args);
158
129
  * ```
159
130
  */
160
- declare const deepseek: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
161
- id: string;
162
- position: "long" | "short";
163
- minuteEstimatedTime: number;
164
- priceStopLoss: number;
165
- priceTakeProfit: number;
166
- note: string;
167
- priceOpen: number;
168
- }>;
131
+ declare const deepseek: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
169
132
  /**
170
- * Generate structured trading signal from Mistral AI models.
133
+ * Wrap async function with Mistral AI inference context.
171
134
  *
172
- * Uses Mistral AI through OpenAI-compatible API. Does NOT support token rotation.
135
+ * Creates a higher-order function that executes the provided async function
136
+ * within a Mistral AI inference context.
173
137
  *
174
- * @param messages - Array of outline messages (user/assistant/system)
138
+ * @template T - Async function type
139
+ * @param fn - Async function to wrap
175
140
  * @param model - Mistral model name (e.g., "mistral-large-latest")
176
- * @param apiKey - Single API key (token rotation not supported)
177
- * @returns Promise resolving to structured trading signal
178
- * @throws Error if apiKey is an array (token rotation not supported)
141
+ * @param apiKey - Single API key or array of keys
142
+ * @returns Wrapped function with same signature as input
179
143
  *
180
144
  * @example
181
145
  * ```typescript
182
146
  * import { mistral } from '@backtest-kit/ollama';
183
147
  *
184
- * const signal = await mistral(messages, 'mistral-large-latest', process.env.MISTRAL_API_KEY);
148
+ * const wrappedFn = mistral(myAsyncFn, 'mistral-large-latest', process.env.MISTRAL_API_KEY);
149
+ * const result = await wrappedFn(args);
185
150
  * ```
186
151
  */
187
- declare const mistral: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
188
- id: string;
189
- position: "long" | "short";
190
- minuteEstimatedTime: number;
191
- priceStopLoss: number;
192
- priceTakeProfit: number;
193
- note: string;
194
- priceOpen: number;
195
- }>;
152
+ declare const mistral: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
196
153
  /**
197
- * Generate structured trading signal from Perplexity AI models.
154
+ * Wrap async function with Perplexity AI inference context.
198
155
  *
199
- * Uses Perplexity AI through OpenAI-compatible API. Does NOT support token rotation.
156
+ * Creates a higher-order function that executes the provided async function
157
+ * within a Perplexity AI inference context.
200
158
  *
201
- * @param messages - Array of outline messages (user/assistant/system)
159
+ * @template T - Async function type
160
+ * @param fn - Async function to wrap
202
161
  * @param model - Perplexity model name (e.g., "llama-3.1-sonar-huge-128k-online")
203
- * @param apiKey - Single API key (token rotation not supported)
204
- * @returns Promise resolving to structured trading signal
205
- * @throws Error if apiKey is an array (token rotation not supported)
162
+ * @param apiKey - Single API key or array of keys
163
+ * @returns Wrapped function with same signature as input
206
164
  *
207
165
  * @example
208
166
  * ```typescript
209
167
  * import { perplexity } from '@backtest-kit/ollama';
210
168
  *
211
- * const signal = await perplexity(messages, 'llama-3.1-sonar-huge-128k-online', process.env.PERPLEXITY_API_KEY);
169
+ * const wrappedFn = perplexity(myAsyncFn, 'llama-3.1-sonar-huge-128k-online', process.env.PERPLEXITY_API_KEY);
170
+ * const result = await wrappedFn(args);
212
171
  * ```
213
172
  */
214
- declare const perplexity: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
215
- id: string;
216
- position: "long" | "short";
217
- minuteEstimatedTime: number;
218
- priceStopLoss: number;
219
- priceTakeProfit: number;
220
- note: string;
221
- priceOpen: number;
222
- }>;
173
+ declare const perplexity: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
223
174
  /**
224
- * Generate structured trading signal from Cohere models.
175
+ * Wrap async function with Cohere inference context.
225
176
  *
226
- * Uses Cohere AI through OpenAI-compatible API. Does NOT support token rotation.
177
+ * Creates a higher-order function that executes the provided async function
178
+ * within a Cohere AI inference context.
227
179
  *
228
- * @param messages - Array of outline messages (user/assistant/system)
180
+ * @template T - Async function type
181
+ * @param fn - Async function to wrap
229
182
  * @param model - Cohere model name (e.g., "command-r-plus")
230
- * @param apiKey - Single API key (token rotation not supported)
231
- * @returns Promise resolving to structured trading signal
232
- * @throws Error if apiKey is an array (token rotation not supported)
183
+ * @param apiKey - Single API key or array of keys
184
+ * @returns Wrapped function with same signature as input
233
185
  *
234
186
  * @example
235
187
  * ```typescript
236
188
  * import { cohere } from '@backtest-kit/ollama';
237
189
  *
238
- * const signal = await cohere(messages, 'command-r-plus', process.env.COHERE_API_KEY);
190
+ * const wrappedFn = cohere(myAsyncFn, 'command-r-plus', process.env.COHERE_API_KEY);
191
+ * const result = await wrappedFn(args);
239
192
  * ```
240
193
  */
241
- declare const cohere: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
242
- id: string;
243
- position: "long" | "short";
244
- minuteEstimatedTime: number;
245
- priceStopLoss: number;
246
- priceTakeProfit: number;
247
- note: string;
248
- priceOpen: number;
249
- }>;
194
+ declare const cohere: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
250
195
  /**
251
- * Generate structured trading signal from Alibaba Cloud Qwen models.
196
+ * Wrap async function with Alibaba Qwen inference context.
252
197
  *
253
- * Uses Alibaba DashScope API through direct HTTP requests. Does NOT support token rotation.
198
+ * Creates a higher-order function that executes the provided async function
199
+ * within an Alibaba DashScope API inference context.
254
200
  *
255
- * @param messages - Array of outline messages (user/assistant/system)
201
+ * @template T - Async function type
202
+ * @param fn - Async function to wrap
256
203
  * @param model - Qwen model name (e.g., "qwen-max")
257
- * @param apiKey - Single API key (token rotation not supported)
258
- * @returns Promise resolving to structured trading signal
259
- * @throws Error if apiKey is an array (token rotation not supported)
204
+ * @param apiKey - Single API key or array of keys
205
+ * @returns Wrapped function with same signature as input
260
206
  *
261
207
  * @example
262
208
  * ```typescript
263
209
  * import { alibaba } from '@backtest-kit/ollama';
264
210
  *
265
- * const signal = await alibaba(messages, 'qwen-max', process.env.ALIBABA_API_KEY);
211
+ * const wrappedFn = alibaba(myAsyncFn, 'qwen-max', process.env.ALIBABA_API_KEY);
212
+ * const result = await wrappedFn(args);
266
213
  * ```
267
214
  */
268
- declare const alibaba: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
269
- id: string;
270
- position: "long" | "short";
271
- minuteEstimatedTime: number;
272
- priceStopLoss: number;
273
- priceTakeProfit: number;
274
- note: string;
275
- priceOpen: number;
276
- }>;
215
+ declare const alibaba: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
277
216
  /**
278
- * Generate structured trading signal from Zhipu AI GLM-4 models.
217
+ * Wrap async function with Zhipu AI GLM-4 inference context.
279
218
  *
280
- * Uses Zhipu AI's GLM-4 through OpenAI-compatible Z.ai API. Does NOT support token rotation.
281
- * GLM-4 is a powerful Chinese language model with strong reasoning capabilities.
219
+ * Creates a higher-order function that executes the provided async function
220
+ * within a Zhipu AI GLM-4 inference context via OpenAI-compatible Z.ai API.
282
221
  *
283
- * @param messages - Array of outline messages (user/assistant/system)
222
+ * @template T - Async function type
223
+ * @param fn - Async function to wrap
284
224
  * @param model - GLM-4 model name (e.g., "glm-4-plus", "glm-4-air")
285
- * @param apiKey - Single API key (token rotation not supported)
286
- * @returns Promise resolving to structured trading signal
287
- * @throws Error if apiKey is an array (token rotation not supported)
225
+ * @param apiKey - Single API key or array of keys
226
+ * @returns Wrapped function with same signature as input
288
227
  *
289
228
  * @example
290
229
  * ```typescript
291
230
  * import { glm4 } from '@backtest-kit/ollama';
292
231
  *
293
- * const signal = await glm4(messages, 'glm-4-plus', process.env.ZAI_API_KEY);
294
- * console.log(`Position: ${signal.position}`);
295
- * console.log(`Entry: ${signal.priceOpen}`);
232
+ * const wrappedFn = glm4(myAsyncFn, 'glm-4-plus', process.env.ZAI_API_KEY);
233
+ * const result = await wrappedFn(args);
296
234
  * ```
297
235
  */
298
- declare const glm4: (messages: IOutlineMessage[], model: string, apiKey?: string | string[]) => Promise<{
299
- id: string;
300
- position: "long" | "short";
301
- minuteEstimatedTime: number;
302
- priceStopLoss: number;
303
- priceTakeProfit: number;
304
- note: string;
305
- priceOpen: number;
306
- }>;
236
+ declare const glm4: <T extends (...args: any[]) => Promise<any>>(fn: T, model: string, apiKey?: string | string[]) => T;
237
+
238
+ /**
239
+ * Enumeration of completion strategy types.
240
+ *
241
+ * Defines unique identifiers for different completion execution modes.
242
+ * Used internally for routing completion requests to appropriate handlers.
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * import { CompletionName } from '@backtest-kit/ollama';
247
+ *
248
+ * const completionType = CompletionName.RunnerCompletion;
249
+ * ```
250
+ */
251
+ declare enum CompletionName {
252
+ /** Standard completion mode (full response at once) */
253
+ RunnerCompletion = "runner_completion",
254
+ /** Streaming completion mode (progressive response chunks) */
255
+ RunnerStreamCompletion = "runner_stream_completion",
256
+ /** Outline completion mode (structured JSON with schema validation) */
257
+ RunnerOutlineCompletion = "runner_outline_completion"
258
+ }
307
259
 
308
260
  /**
309
261
  * Logger interface for application logging.
@@ -373,59 +325,6 @@ interface ILogger {
373
325
  */
374
326
  declare const setLogger: (logger: ILogger) => void;
375
327
 
376
- /**
377
- * Overrides the default signal format schema for LLM-generated trading signals.
378
- *
379
- * This function allows customization of the structured output format used by the
380
- * SignalOutline. It replaces the default signal schema with a custom Zod schema,
381
- * enabling flexible signal structure definitions while maintaining type safety.
382
- *
383
- * The override affects all subsequent signal generation calls using SignalOutline
384
- * until the application restarts or the schema is overridden again.
385
- *
386
- * @template ZodInput - The Zod schema type used for validation and type inference
387
- *
388
- * @param {ZodInput} format - Custom Zod schema defining the signal structure.
389
- * Must be a valid Zod type (z.object, z.string, etc.)
390
- *
391
- * @example
392
- * ```typescript
393
- * import { z } from 'zod';
394
- * import { overrideSignalFormat } from '@backtest-kit/ollama';
395
- *
396
- * // Override with custom signal schema
397
- * const CustomSignalSchema = z.object({
398
- * position: z.enum(['long', 'short', 'wait']),
399
- * price_open: z.number(),
400
- * confidence: z.number().min(0).max(100),
401
- * custom_field: z.string()
402
- * });
403
- *
404
- * overrideSignalFormat(CustomSignalSchema);
405
- * ```
406
- *
407
- * @example
408
- * ```typescript
409
- * // Override with simplified schema
410
- * const SimpleSignalSchema = z.object({
411
- * action: z.enum(['buy', 'sell', 'hold']),
412
- * price: z.number()
413
- * });
414
- *
415
- * overrideSignalFormat(SimpleSignalSchema);
416
- * ```
417
- *
418
- * @remarks
419
- * - The custom schema replaces the default SignalSchema completely
420
- * - Schema name in OpenAI format is always "position_open_decision"
421
- * - Changes persist until application restart or next override
422
- * - Ensure the custom schema matches your signal processing logic
423
- *
424
- * @see {@link SignalSchema} - Default signal schema structure
425
- * @see {@link OutlineName.SignalOutline} - Outline being overridden
426
- */
427
- declare function overrideSignalFormat<ZodInput extends ZodType>(format: ZodInput): void;
428
-
429
328
  /**
430
329
  * Message role type for LLM conversation context.
431
330
  * Defines the sender of a message in a chat-based interaction.
@@ -596,6 +495,129 @@ interface ValidateArgs<T = Enum> {
596
495
  */
597
496
  declare function validate(args?: Partial<Args>): Promise<void>;
598
497
 
498
+ declare class Module {
499
+ readonly path: string;
500
+ readonly baseDir: string;
501
+ private readonly __type__;
502
+ private constructor();
503
+ static fromPath: (path: string, baseDir?: string) => Module;
504
+ static isModule: (value: unknown) => value is Module;
505
+ }
506
+
507
+ type StrategyName$2 = string;
508
+ type ExchangeName$2 = string;
509
+ type FrameName$2 = string;
510
+ /**
511
+ * Function type for generating dynamic system prompts.
512
+ *
513
+ * System prompt functions enable context-aware AI prompt generation based on:
514
+ * - Trading symbol and market conditions
515
+ * - Strategy-specific requirements
516
+ * - Exchange platform characteristics
517
+ * - Timeframe considerations
518
+ * - Execution mode (backtest vs live)
519
+ *
520
+ * @param symbol - Trading symbol (e.g., "BTCUSDT", "ETHUSDT")
521
+ * @param strategyName - Strategy identifier for configuration lookup
522
+ * @param exchangeName - Exchange platform identifier
523
+ * @param frameName - Timeframe identifier (e.g., "1m", "5m", "1h")
524
+ * @param backtest - Whether running in backtest mode (true) or live trading (false)
525
+ * @returns Promise resolving to array of system prompt strings, or array directly
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * const systemPromptFn: SystemPromptFn = async (symbol, strategyName, exchangeName, frameName, backtest) => {
530
+ * return [
531
+ * `You are analyzing ${symbol} on ${exchangeName}`,
532
+ * `Strategy: ${strategyName}, Timeframe: ${frameName}`,
533
+ * backtest ? "Running in backtest mode" : "Running in live mode"
534
+ * ];
535
+ * };
536
+ * ```
537
+ */
538
+ type SystemPromptFn = (symbol: string, strategyName: StrategyName$2, exchangeName: ExchangeName$2, frameName: FrameName$2, backtest: boolean) => Promise<string[]> | string[];
539
+ /**
540
+ * Function type for generating dynamic user prompts.
541
+ *
542
+ * User prompt functions enable context-aware AI query generation based on:
543
+ * - Trading symbol and market conditions
544
+ * - Strategy-specific requirements
545
+ * - Exchange platform characteristics
546
+ * - Timeframe considerations
547
+ * - Execution mode (backtest vs live)
548
+ *
549
+ * @param symbol - Trading symbol (e.g., "BTCUSDT", "ETHUSDT")
550
+ * @param strategyName - Strategy identifier for configuration lookup
551
+ * @param exchangeName - Exchange platform identifier
552
+ * @param frameName - Timeframe identifier (e.g., "1m", "5m", "1h")
553
+ * @param backtest - Whether running in backtest mode (true) or live trading (false)
554
+ * @returns Promise resolving to user prompt string, or string directly
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const userPromptFn: UserPromptFn = async (symbol, strategyName, exchangeName, frameName, backtest) => {
559
+ * return `Analyze ${symbol} for ${strategyName} strategy on ${frameName} timeframe`;
560
+ * };
561
+ * ```
562
+ */
563
+ type UserPromptFn = (symbol: string, strategyName: StrategyName$2, exchangeName: ExchangeName$2, frameName: FrameName$2, backtest: boolean) => Promise<string> | string;
564
+ /**
565
+ * Prompt configuration model for AI/LLM integrations.
566
+ *
567
+ * Defines the structure for AI prompts used in trading strategy analysis.
568
+ * Supports both static prompts and dynamic functions for context-aware generation.
569
+ *
570
+ * Key features:
571
+ * - System prompts: Provide AI context and instructions (optional)
572
+ * - User prompts: Define specific queries or tasks (required)
573
+ * - Static values: Use fixed strings/arrays for consistent prompts
574
+ * - Dynamic functions: Generate prompts based on runtime context
575
+ *
576
+ * Used by PromptService implementations to load and process prompt configurations
577
+ * from config/prompt/*.prompt.cjs files.
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * // Static prompts
582
+ * const staticPrompt: PromptModel = {
583
+ * system: ["You are a trading analyst", "Focus on risk management"],
584
+ * user: "Should I enter this trade?"
585
+ * };
586
+ *
587
+ * // Dynamic prompts
588
+ * const dynamicPrompt: PromptModel = {
589
+ * system: async (symbol, strategy, exchange, frame, backtest) => [
590
+ * `Analyzing ${symbol} on ${exchange}`,
591
+ * `Strategy: ${strategy}, Timeframe: ${frame}`
592
+ * ],
593
+ * user: async (symbol, strategy, exchange, frame, backtest) =>
594
+ * `Evaluate ${symbol} for ${strategy} strategy`
595
+ * };
596
+ * ```
597
+ */
598
+ interface PromptModel {
599
+ /**
600
+ * System prompts for AI context.
601
+ * Can be static array of strings or dynamic function returning string array.
602
+ * Used to set AI behavior, constraints, and domain knowledge.
603
+ */
604
+ system?: string[] | SystemPromptFn;
605
+ /**
606
+ * User prompt for AI input.
607
+ * Can be static string or dynamic function returning string.
608
+ * Defines the specific question or task for the AI to perform.
609
+ */
610
+ user: string | UserPromptFn;
611
+ }
612
+
613
+ declare class Prompt {
614
+ readonly source: PromptModel;
615
+ private readonly __type__;
616
+ private constructor();
617
+ static fromPrompt: (source: PromptModel) => Prompt;
618
+ static isPrompt: (value: unknown) => value is Prompt;
619
+ }
620
+
599
621
  /**
600
622
  * Commits signal prompt history to the message array.
601
623
  *
@@ -604,23 +626,18 @@ declare function validate(args?: Partial<Args>): Promise<void>;
604
626
  * at the end of the history array if they are not empty.
605
627
  *
606
628
  * Context extraction:
607
- * - symbol: Provided as parameter for debugging convenience
608
- * - backtest mode: From ExecutionContext
609
- * - strategyName, exchangeName, frameName: From MethodContext
629
+ * - symbol: From getSymbol()
630
+ * - backtest mode: From getMode()
631
+ * - strategyName, exchangeName, frameName: From getContext()
610
632
  *
611
- * @param symbol - Trading symbol (e.g., "BTCUSDT") for debugging convenience
633
+ * @param source - Module object containing path to .cjs module
612
634
  * @param history - Message array to append prompts to
613
635
  * @returns Promise that resolves when prompts are added
614
636
  * @throws Error if ExecutionContext or MethodContext is not active
615
637
  *
616
- * @example
617
- * ```typescript
618
- * const messages: MessageModel[] = [];
619
- * await commitSignalPromptHistory("BTCUSDT", messages);
620
- * // messages now contains system prompts at start and user prompt at end
621
638
  * ```
622
639
  */
623
- declare function commitSignalPromptHistory(symbol: string, history: MessageModel[]): Promise<void>;
640
+ declare function commitPrompt(source: Module | Prompt, history: MessageModel[]): Promise<void>;
624
641
 
625
642
  /**
626
643
  * Candle interval type for trading timeframes.
@@ -1376,7 +1393,7 @@ interface IContext {
1376
1393
  /** Model name/identifier for the provider */
1377
1394
  model: string;
1378
1395
  /** API key or array of keys for token rotation */
1379
- apiKey: string | string[];
1396
+ apiKey?: string | string[];
1380
1397
  }
1381
1398
  /**
1382
1399
  * Scoped context service for isolated execution contexts.
@@ -1777,144 +1794,10 @@ declare class LoggerService implements ILogger {
1777
1794
  setLogger: (logger: ILogger) => void;
1778
1795
  }
1779
1796
 
1780
- /**
1781
- * Private service for processing structured outline completions.
1782
- *
1783
- * Handles the core logic for executing outline-based AI completions with schema validation.
1784
- * Processes AI responses through the agent-swarm-kit json function to extract and validate
1785
- * structured trading signal data.
1786
- *
1787
- * Key features:
1788
- * - JSON schema validation using agent-swarm-kit
1789
- * - Trading signal extraction and transformation
1790
- * - Type conversion for numeric fields
1791
- * - Markdown formatting cleanup for notes
1792
- * - Error handling for validation failures
1793
- *
1794
- * @example
1795
- * ```typescript
1796
- * const outlinePrivate = inject<OutlinePrivateService>(TYPES.outlinePrivateService);
1797
- * const signal = await outlinePrivate.getCompletion([
1798
- * { role: "user", content: "Analyze market" }
1799
- * ]);
1800
- * ```
1801
- */
1802
- declare class OutlinePrivateService {
1803
- /** Logger service for operation tracking */
1804
- private readonly loggerService;
1805
- /**
1806
- * Processes outline completion messages and extracts structured signal data.
1807
- *
1808
- * Sends messages to the AI provider, validates the response against the signal schema,
1809
- * and transforms the data into a structured format. Returns null if the AI decides
1810
- * to wait (no position).
1811
- *
1812
- * @param messages - Array of conversation messages for the AI
1813
- * @returns Promise resolving to structured signal data or null if position is "wait"
1814
- * @throws Error if validation fails or AI returns an error
1815
- *
1816
- * @example
1817
- * ```typescript
1818
- * const signal = await outlinePrivateService.getCompletion([
1819
- * { role: "system", content: "Trading analyst role" },
1820
- * { role: "user", content: "Market analysis data..." }
1821
- * ]);
1822
- *
1823
- * if (signal) {
1824
- * console.log(`Position: ${signal.position}`);
1825
- * console.log(`Entry: ${signal.priceOpen}`);
1826
- * console.log(`SL: ${signal.priceStopLoss}`);
1827
- * console.log(`TP: ${signal.priceTakeProfit}`);
1828
- * }
1829
- * ```
1830
- */
1831
- getCompletion: (messages: IOutlineMessage[]) => Promise<{
1832
- id: string;
1833
- position: "long" | "short";
1834
- minuteEstimatedTime: number;
1835
- priceStopLoss: number;
1836
- priceTakeProfit: number;
1837
- note: string;
1838
- priceOpen: number;
1839
- }>;
1840
- }
1841
-
1842
- /**
1843
- * Public-facing service for structured AI outline completions.
1844
- *
1845
- * Provides a simplified interface for executing structured AI completions with schema validation.
1846
- * Handles context creation and isolation for outline-based operations.
1847
- * Used for extracting structured data from AI responses (e.g., trading signals).
1848
- *
1849
- * Key features:
1850
- * - Simplified API with automatic context management
1851
- * - JSON schema validation for structured outputs
1852
- * - Support for multiple AI providers
1853
- * - Optional API key parameter with fallback
1854
- * - Logging integration
1855
- *
1856
- * @example
1857
- * ```typescript
1858
- * import { engine } from "./lib";
1859
- * import { InferenceName } from "./enum/InferenceName";
1860
- *
1861
- * const signal = await engine.outlinePublicService.getCompletion(
1862
- * [{ role: "user", content: "Analyze BTC/USDT and decide position" }],
1863
- * InferenceName.ClaudeInference,
1864
- * "claude-3-5-sonnet-20240620",
1865
- * "sk-ant-..."
1866
- * );
1867
- *
1868
- * // Returns structured signal:
1869
- * // {
1870
- * // position: "long",
1871
- * // priceOpen: 50000,
1872
- * // priceStopLoss: 48000,
1873
- * // priceTakeProfit: 52000,
1874
- * // minuteEstimatedTime: 120,
1875
- * // note: "Strong bullish momentum..."
1876
- * // }
1877
- * ```
1878
- */
1879
- declare class OutlinePublicService {
1880
- /** Logger service for operation tracking */
1797
+ declare class PromptCacheService {
1881
1798
  private readonly loggerService;
1882
- /** Private service handling outline completion logic */
1883
- private readonly outlinePrivateService;
1884
- /**
1885
- * Executes a structured outline completion with schema validation.
1886
- *
1887
- * Creates an isolated execution context and processes messages through the AI provider
1888
- * to generate a structured response conforming to a predefined schema.
1889
- *
1890
- * @param messages - Array of conversation messages for the AI
1891
- * @param inference - AI provider identifier
1892
- * @param model - Model name/identifier
1893
- * @param apiKey - Optional API key(s), required for most providers
1894
- * @returns Promise resolving to structured signal data or null if position is "wait"
1895
- *
1896
- * @example
1897
- * ```typescript
1898
- * const result = await outlinePublicService.getCompletion(
1899
- * [
1900
- * { role: "system", content: "You are a trading analyst" },
1901
- * { role: "user", content: "Analyze current BTC market" }
1902
- * ],
1903
- * InferenceName.DeepseekInference,
1904
- * "deepseek-chat",
1905
- * "sk-..."
1906
- * );
1907
- * ```
1908
- */
1909
- getCompletion: (messages: IOutlineMessage[], inference: InferenceName, model: string, apiKey?: string | string[]) => Promise<{
1910
- id: string;
1911
- position: "long" | "short";
1912
- minuteEstimatedTime: number;
1913
- priceStopLoss: number;
1914
- priceTakeProfit: number;
1915
- note: string;
1916
- priceOpen: number;
1917
- }>;
1799
+ readModule: (module: Module) => Prompt;
1800
+ clear: (module?: Module) => void;
1918
1801
  }
1919
1802
 
1920
1803
  type StrategyName = string;
@@ -1923,18 +1806,16 @@ type FrameName = string;
1923
1806
  /**
1924
1807
  * Service for managing signal prompts for AI/LLM integrations.
1925
1808
  *
1926
- * Provides access to system and user prompts configured in signal.prompt.cjs.
1809
+ * Provides access to system and user prompts from Prompt.
1927
1810
  * Supports both static prompt arrays and dynamic prompt functions.
1928
1811
  *
1929
1812
  * Key responsibilities:
1930
- * - Lazy-loads prompt configuration from config/prompt/signal.prompt.cjs
1931
1813
  * - Resolves system prompts (static arrays or async functions)
1932
1814
  * - Provides user prompt strings
1933
- * - Falls back to empty prompts if configuration is missing
1934
1815
  *
1935
1816
  * Used for AI-powered signal analysis and strategy recommendations.
1936
1817
  */
1937
- declare class SignalPromptService {
1818
+ declare class ResolvePromptService {
1938
1819
  private readonly loggerService;
1939
1820
  /**
1940
1821
  * Retrieves system prompts for AI context.
@@ -1944,6 +1825,7 @@ declare class SignalPromptService {
1944
1825
  * - Async/sync function returning string array (executed and awaited)
1945
1826
  * - Undefined (returns empty array)
1946
1827
  *
1828
+ * @param prompt - Prompt containing the loaded module
1947
1829
  * @param symbol - Trading symbol (e.g., "BTCUSDT")
1948
1830
  * @param strategyName - Strategy identifier
1949
1831
  * @param exchangeName - Exchange identifier
@@ -1951,10 +1833,11 @@ declare class SignalPromptService {
1951
1833
  * @param backtest - Whether running in backtest mode
1952
1834
  * @returns Promise resolving to array of system prompt strings
1953
1835
  */
1954
- getSystemPrompt: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string[]>;
1836
+ getSystemPrompt: (prompt: Prompt, symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string[]>;
1955
1837
  /**
1956
1838
  * Retrieves user prompt string for AI input.
1957
1839
  *
1840
+ * @param prompt - Prompt containing the loaded module
1958
1841
  * @param symbol - Trading symbol (e.g., "BTCUSDT")
1959
1842
  * @param strategyName - Strategy identifier
1960
1843
  * @param exchangeName - Exchange identifier
@@ -1962,7 +1845,7 @@ declare class SignalPromptService {
1962
1845
  * @param backtest - Whether running in backtest mode
1963
1846
  * @returns Promise resolving to user prompt string
1964
1847
  */
1965
- getUserPrompt: (symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string>;
1848
+ getUserPrompt: (prompt: Prompt, symbol: string, strategyName: StrategyName, exchangeName: ExchangeName, frameName: FrameName, backtest: boolean) => Promise<string>;
1966
1849
  }
1967
1850
 
1968
1851
  /**
@@ -2376,21 +2259,20 @@ declare class OptimizerGlobalService implements TOptimizer {
2376
2259
  * Provides unified access to the entire service layer.
2377
2260
  */
2378
2261
  declare const engine: {
2379
- optimizerTemplateService: OptimizerTemplateService;
2380
- optimizerSchemaService: OptimizerSchemaService;
2381
- optimizerValidationService: OptimizerValidationService;
2382
- optimizerConnectionService: OptimizerConnectionService;
2383
2262
  optimizerGlobalService: OptimizerGlobalService;
2263
+ optimizerConnectionService: OptimizerConnectionService;
2264
+ optimizerValidationService: OptimizerValidationService;
2265
+ optimizerSchemaService: OptimizerSchemaService;
2266
+ optimizerTemplateService: OptimizerTemplateService;
2384
2267
  outlineMarkdownService: OutlineMarkdownService;
2385
- signalPromptService: SignalPromptService;
2268
+ promptCacheService: PromptCacheService;
2269
+ resolvePromptService: ResolvePromptService;
2386
2270
  runnerPublicService: RunnerPublicService;
2387
- outlinePublicService: OutlinePublicService;
2388
2271
  runnerPrivateService: RunnerPrivateService;
2389
- outlinePrivateService: OutlinePrivateService;
2390
2272
  contextService: {
2391
2273
  readonly context: IContext;
2392
2274
  };
2393
2275
  loggerService: LoggerService;
2394
2276
  };
2395
2277
 
2396
- export { type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type MessageModel, type MessageRole, Optimizer, type ProgressOptimizerContract, addOptimizerSchema, alibaba, claude, cohere, commitSignalPromptHistory, deepseek, dumpSignalData, getOptimizerSchema, glm4, gpt5, grok, hf, engine as lib, listOptimizerSchema, listenError, listenOptimizerProgress, mistral, ollama, overrideSignalFormat, perplexity, setLogger, validate };
2278
+ export { CompletionName, type IOptimizerCallbacks, type IOptimizerData, type IOptimizerFetchArgs, type IOptimizerFilterArgs, type IOptimizerRange, type IOptimizerSchema, type IOptimizerSource, type IOptimizerStrategy, type IOptimizerTemplate, type MessageModel, type MessageRole, Module, Optimizer, type ProgressOptimizerContract, Prompt, type PromptModel, addOptimizerSchema, alibaba, claude, cohere, commitPrompt, deepseek, dumpSignalData, getOptimizerSchema, glm4, gpt5, grok, hf, engine as lib, listOptimizerSchema, listenError, listenOptimizerProgress, mistral, ollama, perplexity, setLogger, validate };