@riotprompt/riotprompt 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.kodrdriv-test-cache.json +6 -0
- package/BUG-ANALYSIS.md +523 -0
- package/CODE-REVIEW-SUMMARY.md +330 -0
- package/FIXES-APPLIED.md +437 -0
- package/README.md +2 -2
- package/dist/builder.js +3 -0
- package/dist/builder.js.map +1 -1
- package/dist/chat.d.ts +1 -1
- package/dist/chat.js +2 -5
- package/dist/chat.js.map +1 -1
- package/dist/constants.js +1 -2
- package/dist/constants.js.map +1 -1
- package/dist/context-manager.d.ts +136 -0
- package/dist/context-manager.js +243 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/conversation-logger.d.ts +285 -0
- package/dist/conversation-logger.js +491 -0
- package/dist/conversation-logger.js.map +1 -0
- package/dist/conversation.d.ts +277 -0
- package/dist/conversation.js +649 -0
- package/dist/conversation.js.map +1 -0
- package/dist/formatter.js.map +1 -1
- package/dist/items/section.js +3 -3
- package/dist/items/section.js.map +1 -1
- package/dist/iteration-strategy.d.ts +233 -0
- package/dist/iteration-strategy.js +520 -0
- package/dist/iteration-strategy.js.map +1 -0
- package/dist/loader.js +21 -3
- package/dist/loader.js.map +1 -1
- package/dist/message-builder.d.ts +156 -0
- package/dist/message-builder.js +256 -0
- package/dist/message-builder.js.map +1 -0
- package/dist/model-config.d.ts +115 -0
- package/dist/model-config.js +205 -0
- package/dist/model-config.js.map +1 -0
- package/dist/override.js +8 -1
- package/dist/override.js.map +1 -1
- package/dist/parser.js +3 -3
- package/dist/parser.js.map +1 -1
- package/dist/recipes.d.ts +42 -0
- package/dist/recipes.js +189 -4
- package/dist/recipes.js.map +1 -1
- package/dist/reflection.d.ts +250 -0
- package/dist/reflection.js +419 -0
- package/dist/reflection.js.map +1 -0
- package/dist/riotprompt.cjs +3854 -178
- package/dist/riotprompt.cjs.map +1 -1
- package/dist/riotprompt.d.ts +20 -2
- package/dist/riotprompt.js +10 -1
- package/dist/riotprompt.js.map +1 -1
- package/dist/token-budget.d.ts +177 -0
- package/dist/token-budget.js +401 -0
- package/dist/token-budget.js.map +1 -0
- package/dist/tools.d.ts +239 -0
- package/dist/tools.js +324 -0
- package/dist/tools.js.map +1 -0
- package/dist/util/general.js +1 -1
- package/dist/util/general.js.map +1 -1
- package/package.json +23 -20
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Configuration System
|
|
3
|
+
*
|
|
4
|
+
* Provides a flexible, user-configurable system for model detection and configuration
|
|
5
|
+
* that doesn't hardcode model names.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Model role mapping for persona/system messages
|
|
9
|
+
*/
|
|
10
|
+
export type PersonaRole = 'system' | 'developer';
|
|
11
|
+
/**
|
|
12
|
+
* Tokenizer encoding to use for token counting
|
|
13
|
+
*/
|
|
14
|
+
export type TokenizerEncoding = 'gpt-4o' | 'cl100k_base' | 'o200k_base';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for a model or model family
|
|
17
|
+
*/
|
|
18
|
+
export interface ModelConfig {
|
|
19
|
+
pattern?: RegExp;
|
|
20
|
+
exactMatch?: string;
|
|
21
|
+
personaRole: PersonaRole;
|
|
22
|
+
encoding: TokenizerEncoding;
|
|
23
|
+
supportsToolCalls?: boolean;
|
|
24
|
+
maxTokens?: number;
|
|
25
|
+
family?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Model registry for managing model configurations
|
|
30
|
+
*/
|
|
31
|
+
export declare class ModelRegistry {
|
|
32
|
+
private configs;
|
|
33
|
+
private cache;
|
|
34
|
+
private logger;
|
|
35
|
+
constructor(logger?: any);
|
|
36
|
+
/**
|
|
37
|
+
* Register default model configurations
|
|
38
|
+
*/
|
|
39
|
+
private registerDefaults;
|
|
40
|
+
/**
|
|
41
|
+
* Register a model configuration
|
|
42
|
+
* Configs are checked in registration order (first match wins)
|
|
43
|
+
*/
|
|
44
|
+
register(config: ModelConfig): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get configuration for a model
|
|
47
|
+
*/
|
|
48
|
+
getConfig(model: string): ModelConfig;
|
|
49
|
+
/**
|
|
50
|
+
* Get persona role for a model
|
|
51
|
+
*/
|
|
52
|
+
getPersonaRole(model: string): PersonaRole;
|
|
53
|
+
/**
|
|
54
|
+
* Get tokenizer encoding for a model
|
|
55
|
+
*/
|
|
56
|
+
getEncoding(model: string): TokenizerEncoding;
|
|
57
|
+
/**
|
|
58
|
+
* Check if model supports tool calls
|
|
59
|
+
*/
|
|
60
|
+
supportsToolCalls(model: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get model family
|
|
63
|
+
*/
|
|
64
|
+
getFamily(model: string): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all registered configs and reset to defaults
|
|
67
|
+
*/
|
|
68
|
+
reset(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Clear cache (useful if configs are modified)
|
|
71
|
+
*/
|
|
72
|
+
clearCache(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get all registered configurations
|
|
75
|
+
*/
|
|
76
|
+
getAllConfigs(): ModelConfig[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the global model registry
|
|
80
|
+
*/
|
|
81
|
+
export declare function getModelRegistry(logger?: any): ModelRegistry;
|
|
82
|
+
/**
|
|
83
|
+
* Reset the global registry (useful for testing)
|
|
84
|
+
*/
|
|
85
|
+
export declare function resetModelRegistry(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Helper functions using global registry
|
|
88
|
+
*/
|
|
89
|
+
export declare function getPersonaRole(model: string): PersonaRole;
|
|
90
|
+
export declare function getEncoding(model: string): TokenizerEncoding;
|
|
91
|
+
export declare function supportsToolCalls(model: string): boolean;
|
|
92
|
+
export declare function getModelFamily(model: string): string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Configure a custom model
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Add support for a new model family
|
|
99
|
+
* configureModel({
|
|
100
|
+
* pattern: /^gemini/i,
|
|
101
|
+
* personaRole: 'system',
|
|
102
|
+
* encoding: 'cl100k_base',
|
|
103
|
+
* family: 'gemini'
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // Add specific model override
|
|
107
|
+
* configureModel({
|
|
108
|
+
* exactMatch: 'custom-model-v1',
|
|
109
|
+
* personaRole: 'developer',
|
|
110
|
+
* encoding: 'gpt-4o'
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function configureModel(config: ModelConfig): void;
|
|
115
|
+
export default ModelRegistry;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { wrapLogger, DEFAULT_LOGGER } from './logger.js';
|
|
2
|
+
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) {
|
|
5
|
+
Object.defineProperty(obj, key, {
|
|
6
|
+
value: value,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
});
|
|
11
|
+
} else {
|
|
12
|
+
obj[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Model registry for managing model configurations
|
|
18
|
+
*/ class ModelRegistry {
|
|
19
|
+
/**
|
|
20
|
+
* Register default model configurations
|
|
21
|
+
*/ registerDefaults() {
|
|
22
|
+
// GPT-4 family (uses 'system' role)
|
|
23
|
+
this.register({
|
|
24
|
+
pattern: /^gpt-4/i,
|
|
25
|
+
personaRole: 'system',
|
|
26
|
+
encoding: 'gpt-4o',
|
|
27
|
+
supportsToolCalls: true,
|
|
28
|
+
family: 'gpt-4',
|
|
29
|
+
description: 'GPT-4 family models'
|
|
30
|
+
});
|
|
31
|
+
// O-series models (uses 'developer' role)
|
|
32
|
+
this.register({
|
|
33
|
+
pattern: /^o\d+/i,
|
|
34
|
+
personaRole: 'developer',
|
|
35
|
+
encoding: 'gpt-4o',
|
|
36
|
+
supportsToolCalls: true,
|
|
37
|
+
family: 'o-series',
|
|
38
|
+
description: 'O-series reasoning models'
|
|
39
|
+
});
|
|
40
|
+
// Claude family (uses 'system' role)
|
|
41
|
+
this.register({
|
|
42
|
+
pattern: /^claude/i,
|
|
43
|
+
personaRole: 'system',
|
|
44
|
+
encoding: 'cl100k_base',
|
|
45
|
+
supportsToolCalls: true,
|
|
46
|
+
family: 'claude',
|
|
47
|
+
description: 'Claude family models'
|
|
48
|
+
});
|
|
49
|
+
// Default fallback
|
|
50
|
+
this.register({
|
|
51
|
+
pattern: /.*/,
|
|
52
|
+
personaRole: 'system',
|
|
53
|
+
encoding: 'gpt-4o',
|
|
54
|
+
supportsToolCalls: true,
|
|
55
|
+
family: 'unknown',
|
|
56
|
+
description: 'Default fallback configuration'
|
|
57
|
+
});
|
|
58
|
+
this.logger.debug('Registered default model configurations');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register a model configuration
|
|
62
|
+
* Configs are checked in registration order (first match wins)
|
|
63
|
+
*/ register(config) {
|
|
64
|
+
var _config_pattern;
|
|
65
|
+
// Validate config
|
|
66
|
+
if (!config.pattern && !config.exactMatch) {
|
|
67
|
+
throw new Error('Model config must have either pattern or exactMatch');
|
|
68
|
+
}
|
|
69
|
+
this.configs.push(config);
|
|
70
|
+
this.cache.clear(); // Clear cache when new config is added
|
|
71
|
+
this.logger.debug('Registered model config', {
|
|
72
|
+
family: config.family,
|
|
73
|
+
pattern: (_config_pattern = config.pattern) === null || _config_pattern === void 0 ? void 0 : _config_pattern.source,
|
|
74
|
+
exactMatch: config.exactMatch
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get configuration for a model
|
|
79
|
+
*/ getConfig(model) {
|
|
80
|
+
// Check cache first
|
|
81
|
+
if (this.cache.has(model)) {
|
|
82
|
+
return this.cache.get(model);
|
|
83
|
+
}
|
|
84
|
+
// Find matching config (first match wins)
|
|
85
|
+
for (const config of this.configs){
|
|
86
|
+
if (config.exactMatch && config.exactMatch === model) {
|
|
87
|
+
this.cache.set(model, config);
|
|
88
|
+
return config;
|
|
89
|
+
}
|
|
90
|
+
if (config.pattern && config.pattern.test(model)) {
|
|
91
|
+
this.cache.set(model, config);
|
|
92
|
+
return config;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Should never happen due to default fallback, but just in case
|
|
96
|
+
throw new Error(`No configuration found for model: ${model}`);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get persona role for a model
|
|
100
|
+
*/ getPersonaRole(model) {
|
|
101
|
+
return this.getConfig(model).personaRole;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get tokenizer encoding for a model
|
|
105
|
+
*/ getEncoding(model) {
|
|
106
|
+
return this.getConfig(model).encoding;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if model supports tool calls
|
|
110
|
+
*/ supportsToolCalls(model) {
|
|
111
|
+
var _this_getConfig_supportsToolCalls;
|
|
112
|
+
return (_this_getConfig_supportsToolCalls = this.getConfig(model).supportsToolCalls) !== null && _this_getConfig_supportsToolCalls !== void 0 ? _this_getConfig_supportsToolCalls : true;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get model family
|
|
116
|
+
*/ getFamily(model) {
|
|
117
|
+
return this.getConfig(model).family;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Clear all registered configs and reset to defaults
|
|
121
|
+
*/ reset() {
|
|
122
|
+
this.configs = [];
|
|
123
|
+
this.cache.clear();
|
|
124
|
+
this.registerDefaults();
|
|
125
|
+
this.logger.debug('Reset model configurations to defaults');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clear cache (useful if configs are modified)
|
|
129
|
+
*/ clearCache() {
|
|
130
|
+
this.cache.clear();
|
|
131
|
+
this.logger.debug('Cleared model configuration cache');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get all registered configurations
|
|
135
|
+
*/ getAllConfigs() {
|
|
136
|
+
return [
|
|
137
|
+
...this.configs
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
constructor(logger){
|
|
141
|
+
_define_property(this, "configs", void 0);
|
|
142
|
+
_define_property(this, "cache", void 0);
|
|
143
|
+
_define_property(this, "logger", void 0);
|
|
144
|
+
this.configs = [];
|
|
145
|
+
this.cache = new Map();
|
|
146
|
+
this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'ModelRegistry');
|
|
147
|
+
// Register default configurations
|
|
148
|
+
this.registerDefaults();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Global registry instance
|
|
152
|
+
let globalRegistry = null;
|
|
153
|
+
/**
|
|
154
|
+
* Get the global model registry
|
|
155
|
+
*/ function getModelRegistry(logger) {
|
|
156
|
+
if (!globalRegistry) {
|
|
157
|
+
globalRegistry = new ModelRegistry(logger);
|
|
158
|
+
}
|
|
159
|
+
return globalRegistry;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Reset the global registry (useful for testing)
|
|
163
|
+
*/ function resetModelRegistry() {
|
|
164
|
+
globalRegistry = null;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Helper functions using global registry
|
|
168
|
+
*/ function getPersonaRole(model) {
|
|
169
|
+
return getModelRegistry().getPersonaRole(model);
|
|
170
|
+
}
|
|
171
|
+
function getEncoding(model) {
|
|
172
|
+
return getModelRegistry().getEncoding(model);
|
|
173
|
+
}
|
|
174
|
+
function supportsToolCalls(model) {
|
|
175
|
+
return getModelRegistry().supportsToolCalls(model);
|
|
176
|
+
}
|
|
177
|
+
function getModelFamily(model) {
|
|
178
|
+
return getModelRegistry().getFamily(model);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Configure a custom model
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Add support for a new model family
|
|
186
|
+
* configureModel({
|
|
187
|
+
* pattern: /^gemini/i,
|
|
188
|
+
* personaRole: 'system',
|
|
189
|
+
* encoding: 'cl100k_base',
|
|
190
|
+
* family: 'gemini'
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Add specific model override
|
|
194
|
+
* configureModel({
|
|
195
|
+
* exactMatch: 'custom-model-v1',
|
|
196
|
+
* personaRole: 'developer',
|
|
197
|
+
* encoding: 'gpt-4o'
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/ function configureModel(config) {
|
|
201
|
+
getModelRegistry().register(config);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { ModelRegistry, configureModel, ModelRegistry as default, getEncoding, getModelFamily, getModelRegistry, getPersonaRole, resetModelRegistry, supportsToolCalls };
|
|
205
|
+
//# sourceMappingURL=model-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-config.js","sources":["../src/model-config.ts"],"sourcesContent":["/**\n * Model Configuration System\n *\n * Provides a flexible, user-configurable system for model detection and configuration\n * that doesn't hardcode model names.\n */\n\nimport { DEFAULT_LOGGER, wrapLogger } from \"./logger\";\n\n// ===== TYPE DEFINITIONS =====\n\n/**\n * Model role mapping for persona/system messages\n */\nexport type PersonaRole = 'system' | 'developer';\n\n/**\n * Tokenizer encoding to use for token counting\n */\nexport type TokenizerEncoding = 'gpt-4o' | 'cl100k_base' | 'o200k_base';\n\n/**\n * Configuration for a model or model family\n */\nexport interface ModelConfig {\n // Model identification\n pattern?: RegExp; // Pattern to match model name\n exactMatch?: string; // Exact model name match\n\n // Model characteristics\n personaRole: PersonaRole; // Role to use for persona/system messages\n encoding: TokenizerEncoding; // Tokenizer encoding\n\n // Capabilities\n supportsToolCalls?: boolean;\n maxTokens?: number;\n\n // Metadata\n family?: string; // Model family (e.g., 'gpt-4', 'o-series', 'claude')\n description?: string;\n}\n\n/**\n * Model registry for managing model configurations\n */\nexport class ModelRegistry {\n private configs: ModelConfig[];\n private cache: Map<string, ModelConfig>;\n private logger: any;\n\n constructor(logger?: any) {\n this.configs = [];\n this.cache = new Map();\n this.logger = wrapLogger(logger || DEFAULT_LOGGER, 'ModelRegistry');\n\n // Register default configurations\n this.registerDefaults();\n }\n\n /**\n * Register default model configurations\n */\n private registerDefaults(): void {\n // GPT-4 family (uses 'system' role)\n this.register({\n pattern: /^gpt-4/i,\n personaRole: 'system',\n encoding: 'gpt-4o',\n supportsToolCalls: true,\n family: 'gpt-4',\n description: 'GPT-4 family models'\n });\n\n // O-series models (uses 'developer' role)\n this.register({\n pattern: /^o\\d+/i, // Matches o1, o2, o3, o4, etc.\n personaRole: 'developer',\n encoding: 'gpt-4o',\n supportsToolCalls: true,\n family: 'o-series',\n description: 'O-series reasoning models'\n });\n\n // Claude family (uses 'system' role)\n this.register({\n pattern: /^claude/i,\n personaRole: 'system',\n encoding: 'cl100k_base',\n supportsToolCalls: true,\n family: 'claude',\n description: 'Claude family models'\n });\n\n // Default fallback\n this.register({\n pattern: /.*/, // Matches anything\n personaRole: 'system',\n encoding: 'gpt-4o',\n supportsToolCalls: true,\n family: 'unknown',\n description: 'Default fallback configuration'\n });\n\n this.logger.debug('Registered default model configurations');\n }\n\n /**\n * Register a model configuration\n * Configs are checked in registration order (first match wins)\n */\n register(config: ModelConfig): void {\n // Validate config\n if (!config.pattern && !config.exactMatch) {\n throw new Error('Model config must have either pattern or exactMatch');\n }\n\n this.configs.push(config);\n this.cache.clear(); // Clear cache when new config is added\n\n this.logger.debug('Registered model config', {\n family: config.family,\n pattern: config.pattern?.source,\n exactMatch: config.exactMatch\n });\n }\n\n /**\n * Get configuration for a model\n */\n getConfig(model: string): ModelConfig {\n // Check cache first\n if (this.cache.has(model)) {\n return this.cache.get(model)!;\n }\n\n // Find matching config (first match wins)\n for (const config of this.configs) {\n if (config.exactMatch && config.exactMatch === model) {\n this.cache.set(model, config);\n return config;\n }\n\n if (config.pattern && config.pattern.test(model)) {\n this.cache.set(model, config);\n return config;\n }\n }\n\n // Should never happen due to default fallback, but just in case\n throw new Error(`No configuration found for model: ${model}`);\n }\n\n /**\n * Get persona role for a model\n */\n getPersonaRole(model: string): PersonaRole {\n return this.getConfig(model).personaRole;\n }\n\n /**\n * Get tokenizer encoding for a model\n */\n getEncoding(model: string): TokenizerEncoding {\n return this.getConfig(model).encoding;\n }\n\n /**\n * Check if model supports tool calls\n */\n supportsToolCalls(model: string): boolean {\n return this.getConfig(model).supportsToolCalls ?? true;\n }\n\n /**\n * Get model family\n */\n getFamily(model: string): string | undefined {\n return this.getConfig(model).family;\n }\n\n /**\n * Clear all registered configs and reset to defaults\n */\n reset(): void {\n this.configs = [];\n this.cache.clear();\n this.registerDefaults();\n this.logger.debug('Reset model configurations to defaults');\n }\n\n /**\n * Clear cache (useful if configs are modified)\n */\n clearCache(): void {\n this.cache.clear();\n this.logger.debug('Cleared model configuration cache');\n }\n\n /**\n * Get all registered configurations\n */\n getAllConfigs(): ModelConfig[] {\n return [...this.configs];\n }\n}\n\n// Global registry instance\nlet globalRegistry: ModelRegistry | null = null;\n\n/**\n * Get the global model registry\n */\nexport function getModelRegistry(logger?: any): ModelRegistry {\n if (!globalRegistry) {\n globalRegistry = new ModelRegistry(logger);\n }\n return globalRegistry;\n}\n\n/**\n * Reset the global registry (useful for testing)\n */\nexport function resetModelRegistry(): void {\n globalRegistry = null;\n}\n\n/**\n * Helper functions using global registry\n */\nexport function getPersonaRole(model: string): PersonaRole {\n return getModelRegistry().getPersonaRole(model);\n}\n\nexport function getEncoding(model: string): TokenizerEncoding {\n return getModelRegistry().getEncoding(model);\n}\n\nexport function supportsToolCalls(model: string): boolean {\n return getModelRegistry().supportsToolCalls(model);\n}\n\nexport function getModelFamily(model: string): string | undefined {\n return getModelRegistry().getFamily(model);\n}\n\n/**\n * Configure a custom model\n *\n * @example\n * ```typescript\n * // Add support for a new model family\n * configureModel({\n * pattern: /^gemini/i,\n * personaRole: 'system',\n * encoding: 'cl100k_base',\n * family: 'gemini'\n * });\n *\n * // Add specific model override\n * configureModel({\n * exactMatch: 'custom-model-v1',\n * personaRole: 'developer',\n * encoding: 'gpt-4o'\n * });\n * ```\n */\nexport function configureModel(config: ModelConfig): void {\n getModelRegistry().register(config);\n}\n\nexport default ModelRegistry;\n\n"],"names":["ModelRegistry","registerDefaults","register","pattern","personaRole","encoding","supportsToolCalls","family","description","logger","debug","config","exactMatch","Error","configs","push","cache","clear","source","getConfig","model","has","get","set","test","getPersonaRole","getEncoding","getFamily","reset","clearCache","getAllConfigs","Map","wrapLogger","DEFAULT_LOGGER","globalRegistry","getModelRegistry","resetModelRegistry","getModelFamily","configureModel"],"mappings":";;;;;;;;;;;;;;;AA0CA;;AAEC,IACM,MAAMA,aAAAA,CAAAA;AAcT;;AAEC,QACD,gBAAQC,GAAyB;;QAE7B,IAAI,CAACC,QAAQ,CAAC;YACVC,OAAAA,EAAS,SAAA;YACTC,WAAAA,EAAa,QAAA;YACbC,QAAAA,EAAU,QAAA;YACVC,iBAAAA,EAAmB,IAAA;YACnBC,MAAAA,EAAQ,OAAA;YACRC,WAAAA,EAAa;AACjB,SAAA,CAAA;;QAGA,IAAI,CAACN,QAAQ,CAAC;YACVC,OAAAA,EAAS,QAAA;YACTC,WAAAA,EAAa,WAAA;YACbC,QAAAA,EAAU,QAAA;YACVC,iBAAAA,EAAmB,IAAA;YACnBC,MAAAA,EAAQ,UAAA;YACRC,WAAAA,EAAa;AACjB,SAAA,CAAA;;QAGA,IAAI,CAACN,QAAQ,CAAC;YACVC,OAAAA,EAAS,UAAA;YACTC,WAAAA,EAAa,QAAA;YACbC,QAAAA,EAAU,aAAA;YACVC,iBAAAA,EAAmB,IAAA;YACnBC,MAAAA,EAAQ,QAAA;YACRC,WAAAA,EAAa;AACjB,SAAA,CAAA;;QAGA,IAAI,CAACN,QAAQ,CAAC;YACVC,OAAAA,EAAS,IA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,KAAa,EAAA;IAC3C,OAAOe,gBAAAA,EAAAA,CAAmB7B,iBAAiB,CAACc,KAAAA,CAAAA;AAChD;AAEO,SAASiB,eAAejB,KAAa,EAAA;IACxC,OAAOe,gBAAAA,EAAAA,CAAmBR,SAAS,CAACP,KAAAA,CAAAA;AACxC;AAEA;;;;;;;;;;;;;;;;;;;;IAqBO,SAASkB,cAAAA,CAAe3B,MAAmB,EAAA;AAC9CwB,IAAAA,gBAAAA,EAAAA,CAAmBjC,QAAQ,CAACS,MAAAA,CAAAA;AAChC;;;;"}
|
package/dist/override.js
CHANGED
|
@@ -9,6 +9,9 @@ import { create as create$3 } from './parser.js';
|
|
|
9
9
|
import './loader.js';
|
|
10
10
|
import './builder.js';
|
|
11
11
|
import './recipes.js';
|
|
12
|
+
import './conversation.js';
|
|
13
|
+
import 'tiktoken';
|
|
14
|
+
import './tools.js';
|
|
12
15
|
import { create as create$2 } from './util/storage.js';
|
|
13
16
|
|
|
14
17
|
const OptionsSchema = z.object({
|
|
@@ -102,7 +105,11 @@ const create = (overrideOptions = {})=>{
|
|
|
102
105
|
finalSection = finalSection.prepend(prepend);
|
|
103
106
|
}
|
|
104
107
|
// Apply appends in reverse order (furthest layers first, then closest)
|
|
105
|
-
|
|
108
|
+
// Create a copy to avoid mutating the original array
|
|
109
|
+
const reversedAppends = [
|
|
110
|
+
...appends
|
|
111
|
+
].reverse();
|
|
112
|
+
for (const append of reversedAppends){
|
|
106
113
|
logger.silly('Append found, adding to content from file %s', append);
|
|
107
114
|
finalSection = finalSection.append(append);
|
|
108
115
|
}
|
package/dist/override.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n for (const append of appends.reverse()) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","append","reverse","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYP,EAAEQ,KAAK,CAACR,EAAES,MAAM,EAAA,CAAA,CAAIJ,OAAO,CAAC;AAAC,QAAA;AAAc,KAAA,CAAA;AACvDK,IAAAA,SAAAA,EAAWV,CAAAA,CAAEW,OAAO,EAAA,CAAGN,OAAO,CAAC,KAAA,CAAA;AAC/BO,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBT,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAYO,MAAMS,MAAAA,GAAS,CAACC,eAAAA,GAAgC,EAAE,GAAA;IACrD,MAAMC,OAAAA,GAA6BjB,aAAAA,CAAckB,KAAK,CAACF,eAAAA,CAAAA;IAEvD,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;AAErC,IAAA,MAAMV,SAASgB,UAAAA,CAAWF,OAAAA,KAAAA,IAAAA,IAAAA,OAAAA,KAAAA,MAAAA,GAAAA,MAAAA,GAAAA,OAAAA,CAASd,MAAM,EAAE,UAAA,CAAA;IAC3C,MAAMiB,OAAAA,GAAUC,QAAc,CAAC;AAAEC,QAAAA,GAAAA,EAAKnB,OAAO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AO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO4D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACP,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"override.js","sources":["../src/override.ts"],"sourcesContent":["import path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { SectionOptions, SectionOptionsSchema } from './items/section';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { Formatter, Parser, Section, Weighted } from './riotprompt';\nimport * as Storage from './util/storage';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n configDirs: z.array(z.string()).default(['./overrides']),\n overrides: z.boolean().default(false),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n customize: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) => Promise<Section<T>>;\n override: <T extends Weighted>(overrideFile: string, section: Section<T>, sectionOptions?: SectionOptions) =>\n Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }>;\n}\n\nexport const create = (overrideOptions: OptionsParam = {}): Instance => {\n const options: Required<Options> = OptionsSchema.parse(overrideOptions) as Required<Options>;\n\n const parameters = options.parameters;\n\n const logger = wrapLogger(options?.logger, 'Override');\n const storage = Storage.create({ log: logger.debug });\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const override = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<{ override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] }> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const response: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = {\n prepends: [],\n appends: []\n };\n\n // Process directories in order (closest to furthest)\n for (let i = 0; i < options.configDirs.length; i++) {\n const configDir = options.configDirs[i];\n const baseFile = path.join(configDir, overrideFile);\n const preFile = baseFile.replace('.md', '-pre.md');\n const postFile = baseFile.replace('.md', '-post.md');\n\n // Check for prepend files (-pre.md)\n if (await storage.exists(preFile)) {\n logger.silly('Found pre file %s (layer %d)', preFile, i + 1);\n const parser = Parser.create({ logger });\n const prependSection = await parser.parseFile<T>(preFile, currentSectionOptions);\n response.prepends.push(prependSection);\n }\n\n // Check for append files (-post.md)\n if (await storage.exists(postFile)) {\n logger.silly('Found post file %s (layer %d)', postFile, i + 1);\n const parser = Parser.create({ logger });\n const appendSection = await parser.parseFile<T>(postFile, currentSectionOptions);\n response.appends.push(appendSection);\n }\n\n // Check for complete override files - use the first (closest) one found\n if (!response.override && await storage.exists(baseFile)) {\n logger.silly('Found base file %s (layer %d)', baseFile, i + 1);\n if (options.overrides) {\n logger.warn('WARNING: Core directives are being overwritten by custom configuration at layer %d', i + 1);\n const parser = Parser.create({ logger });\n response.override = await parser.parseFile<T>(baseFile, currentSectionOptions);\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n }\n\n return response;\n }\n\n const customize = async <T extends Weighted>(\n overrideFile: string,\n section: Section<T>,\n sectionOptions: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentSectionOptions = loadOptions(sectionOptions);\n\n const { override: overrideContent, prepends, appends }: { override?: Section<T>, prepends: Section<T>[], appends: Section<T>[] } = await override(overrideFile, section, currentSectionOptions);\n let finalSection: Section<T> = section;\n\n if (overrideContent) {\n if (options.overrides) {\n logger.warn('Override found, replacing content from file %s', overrideContent);\n finalSection = overrideContent;\n } else {\n logger.error('ERROR: Core directives are being overwritten by custom configuration');\n throw new Error('Core directives are being overwritten by custom configuration, but overrides are not enabled. Please enable --overrides to use this feature.');\n }\n }\n\n // Apply prepends in order (closest layer first)\n for (const prepend of prepends) {\n logger.silly('Prepend found, adding to content from file %s', prepend);\n finalSection = finalSection.prepend(prepend);\n }\n\n // Apply appends in reverse order (furthest layers first, then closest)\n // Create a copy to avoid mutating the original array\n const reversedAppends = [...appends].reverse();\n for (const append of reversedAppends) {\n logger.silly('Append found, adding to content from file %s', append);\n finalSection = finalSection.append(append);\n }\n\n const formatter = Formatter.create({ logger });\n logger.silly('Final section %s:\\n\\n%s\\n\\n', logger.name, formatter.format(finalSection));\n\n return finalSection;\n }\n\n return {\n override,\n customize,\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","configDirs","array","string","overrides","boolean","parameters","ParametersSchema","create","overrideOptions","options","parse","wrapLogger","storage","Storage","log","debug","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","override","overrideFile","section","currentSectionOptions","response","prepends","appends","i","length","configDir","baseFile","path","join","preFile","replace","postFile","exists","silly","parser","Parser","prependSection","parseFile","push","appendSection","warn","error","Error","customize","overrideContent","finalSection","prepend","reversedAppends","reverse","append","formatter","Formatter","name","format"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYP,EAAEQ,KAAK,CAACR,EAAES,MAAM,EAAA,CAAA,CAAIJ,OAAO,CAAC;AAAC,QAAA;AAAc,KAAA,CAAA;AACvDK,IAAAA,SAAAA,EAAWV,CAAAA,CAAEW,OAAO,EAAA,CAA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BAAA,MAAM,IAAIC,KAAAA,CAAM,+IAAA,CAAA;AACpB,YAAA;AACJ,QAAA;;QAGA,KAAK,MAAMI,WAAWzB,QAAAA,CAAU;YAC5B9B,MAAAA,CAAO0C,KAAK,CAAC,+CAAA,EAAiDa,OAAAA,CAAAA;YAC9DD,YAAAA,GAAeA,YAAAA,CAAaC,OAAO,CAACA,OAAAA,CAAAA;AACxC,QAAA;;;AAIA,QAAA,MAAMC,eAAAA,GAAkB;AAAIzB,YAAAA,GAAAA;AAAQ,SAAA,CAAC0B,OAAO,EAAA;QAC5C,KAAK,MAAMC,UAAUF,eAAAA,CAAiB;YAClCxD,MAAAA,CAAO0C,KAAK,CAAC,8CAAA,EAAgDgB,MAAAA,CAAAA;YAC7DJ,YAAAA,GAAeA,YAAAA,CAAaI,MAAM,CAACA,MAAAA,CAAAA;AACvC,QAAA;QAEA,MAAMC,WAAAA,GAAYC,QAAgB,CAAC;AAAE5D,YAAAA;AAAO,SAAA,CAAA;QAC5CA,MAAAA,CAAO0C,KAAK,CAAC,6BAAA,EAA+B1C,MAAAA,CAAO6D,IAAI,EAAEF,WAAAA,CAAUG,MAAM,CAACR,YAAAA,CAAAA,CAAAA;QAE1E,OAAOA,YAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACH7B,QAAAA,QAAAA;AACA2B,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
package/dist/parser.js
CHANGED
|
@@ -39,13 +39,13 @@ const create = (parserOptions)=>{
|
|
|
39
39
|
});
|
|
40
40
|
} catch (error) {
|
|
41
41
|
// Log the error or handle it appropriately
|
|
42
|
-
logger.error(`Error reading or parsing file
|
|
43
|
-
throw new Error(`Failed to parse
|
|
42
|
+
logger.error(`Error reading or parsing file at ${filePath}:`, error);
|
|
43
|
+
throw new Error(`Failed to parse content from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
/**
|
|
47
47
|
* Reads Markdown content and parses it into a single Section.
|
|
48
|
-
*
|
|
48
|
+
*
|
|
49
49
|
* - If the content starts with a heading, that becomes the title of the returned Section
|
|
50
50
|
* - If no heading at the start, creates a Section with no title
|
|
51
51
|
* - Headers within the content create nested sections based on their depth
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Promise<Section<T>>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return await parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file
|
|
1
|
+
{"version":3,"file":"parser.js","sources":["../src/parser.ts"],"sourcesContent":["import * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { z } from 'zod';\nimport { ParametersSchema } from './items/parameters';\nimport { Section, SectionOptions, SectionOptionsSchema } from './items/section';\nimport { Weighted } from './items/weighted';\nimport { DEFAULT_LOGGER, wrapLogger } from './logger';\nimport { parseMarkdown } from './parse/markdown';\nimport { parseText } from './parse/text';\nimport { isMarkdown } from './util/markdown';\nimport { isText } from './util/text';\n\nconst OptionsSchema = z.object({\n logger: z.any().optional().default(DEFAULT_LOGGER),\n parameters: ParametersSchema.optional().default({}),\n});\n\nexport type Options = z.infer<typeof OptionsSchema>;\n\nexport type OptionsParam = Partial<Options>;\n\nexport interface Instance {\n parse: <T extends Weighted>(input: string | Buffer, options?: SectionOptions) => Promise<Section<T>>;\n parseFile: <T extends Weighted>(filePath: string, options?: SectionOptions) => Promise<Section<T>>;\n}\n\nexport const create = (parserOptions?: OptionsParam): Instance => {\n const options: Required<Options> = OptionsSchema.parse(parserOptions || {}) as Required<Options>;\n const parameters = options.parameters;\n\n const logger = wrapLogger(options.logger, 'Parser');\n\n const loadOptions = (sectionOptions: Partial<SectionOptions> = {}): SectionOptions => {\n const currentOptions = SectionOptionsSchema.parse(sectionOptions);\n return {\n ...currentOptions,\n parameters: {\n ...parameters,\n ...currentOptions.parameters\n }\n }\n }\n\n const parseFile = async <T extends Weighted>(\n filePath: string,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n // Only use the filename as title if no title was explicitly provided\n const fileName = path.basename(filePath, path.extname(filePath));\n return await parse(content, {\n ...currentOptions,\n title: currentOptions?.title || fileName\n });\n } catch (error) {\n // Log the error or handle it appropriately\n logger.error(`Error reading or parsing file at ${filePath}:`, error);\n throw new Error(`Failed to parse content from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n /**\n * Reads Markdown content and parses it into a single Section.\n *\n * - If the content starts with a heading, that becomes the title of the returned Section\n * - If no heading at the start, creates a Section with no title\n * - Headers within the content create nested sections based on their depth\n * - All content is organized in a hierarchical structure based on heading levels\n *\n * @param content The content to parse\n * @returns A Section containing all content in a hierarchical structure\n */\n const parse = async <T extends Weighted>(\n content: string | Buffer,\n options: Partial<SectionOptions> = {}\n ): Promise<Section<T>> => {\n const currentOptions = loadOptions(options);\n\n let mainSection: Section<T>;\n if (isMarkdown(content)) {\n mainSection = await parseMarkdown<T>(content, currentOptions);\n } else if (isText(content)) {\n mainSection = parseText<T>(content, currentOptions);\n } else {\n throw new Error(`Unsupported content supplied to parse, riotprompt currently only supports markdown and text`);\n }\n return mainSection;\n }\n\n return {\n parse,\n parseFile\n }\n}\n"],"names":["OptionsSchema","z","object","logger","any","optional","default","DEFAULT_LOGGER","parameters","ParametersSchema","create","parserOptions","options","parse","wrapLogger","loadOptions","sectionOptions","currentOptions","SectionOptionsSchema","parseFile","filePath","content","fs","readFile","fileName","path","basename","extname","title","error","Error","message","String","mainSection","isMarkdown","parseMarkdown","isText","parseText"],"mappings":";;;;;;;;;;;AAYA,MAAMA,aAAAA,GAAgBC,CAAAA,CAAEC,MAAM,CAAC;AAC3BC,IAAAA,MAAAA,EAAQF,EAAEG,GAAG,EAAA,CAAGC,QAAQ,EAAA,CAAGC,OAAO,CAACC,cAAAA,CAAAA;AACnCC,IAAAA,UAAAA,EAAYC,gBAAAA,CAAiBJ,QAAQ,EAAA,CAAGC,OAAO,CAAC,EAAC;AACrD,CAAA,CAAA;AAWO,MAAMI,SAAS,CAACC,aAAAA,GAAAA;AACnB,IAAA,MAAMC,OAAAA,GAA6BZ,aAAAA,CAAca,KAAK,CAACF,iBAAiB,EAAC,CAAA;IACzE,MAAMH,UAAAA,GAAaI,QAAQJ,UAAU;A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KAAAA,CAAME,OAAO,GAAGC,OAAOH,KAAAA,CAAAA,CAAAA,CAAQ,CAAA;AACzH,QAAA;AACJ,IAAA,CAAA;AAEA;;;;;;;;;;AAUC,QACD,MAAMhB,KAAAA,GAAQ,OACVQ,OAAAA,EACAT,OAAAA,GAAmC,EAAE,GAAA;AAErC,QAAA,MAAMK,iBAAiBF,WAAAA,CAAYH,OAAAA,CAAAA;QAEnC,IAAIqB,WAAAA;AACJ,QAAA,IAAIC,WAAWb,OAAAA,CAAAA,EAAU;YACrBY,WAAAA,GAAc,MAAME,cAAiBd,OAAAA,EAASJ,cAAAA,CAAAA;QAClD,CAAA,MAAO,IAAImB,OAAOf,OAAAA,CAAAA,EAAU;AACxBY,YAAAA,WAAAA,GAAcI,UAAahB,OAAAA,EAASJ,cAAAA,CAAAA;QACxC,CAAA,MAAO;AACH,YAAA,MAAM,IAAIa,KAAAA,CAAM,CAAC,2FAA2F,CAAC,CAAA;AACjH,QAAA;QACA,OAAOG,WAAAA;AACX,IAAA,CAAA;IAEA,OAAO;AACHpB,QAAAA,KAAAA;AACAM,QAAAA;AACJ,KAAA;AACJ;;;;"}
|
package/dist/recipes.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { Model } from './chat';
|
|
3
|
+
import { ConversationBuilder } from './conversation';
|
|
2
4
|
import { Prompt } from './riotprompt';
|
|
5
|
+
import { TokenBudgetConfig } from './token-budget';
|
|
6
|
+
import { Tool, ToolRegistry } from './tools';
|
|
7
|
+
import { IterationStrategy, LLMClient, StrategyResult } from './iteration-strategy';
|
|
3
8
|
declare const ContentItemSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
4
9
|
content: z.ZodString;
|
|
5
10
|
title: z.ZodOptional<z.ZodString>;
|
|
@@ -73,14 +78,40 @@ declare const RecipeConfigSchema: z.ZodObject<{
|
|
|
73
78
|
}, z.core.$strip>]>>>>;
|
|
74
79
|
extends: z.ZodOptional<z.ZodString>;
|
|
75
80
|
template: z.ZodOptional<z.ZodString>;
|
|
81
|
+
tools: z.ZodOptional<z.ZodAny>;
|
|
82
|
+
toolGuidance: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
83
|
+
auto: "auto";
|
|
84
|
+
minimal: "minimal";
|
|
85
|
+
detailed: "detailed";
|
|
86
|
+
}>, z.ZodObject<{
|
|
87
|
+
strategy: z.ZodEnum<{
|
|
88
|
+
adaptive: "adaptive";
|
|
89
|
+
minimal: "minimal";
|
|
90
|
+
prescriptive: "prescriptive";
|
|
91
|
+
}>;
|
|
92
|
+
includeExamples: z.ZodOptional<z.ZodBoolean>;
|
|
93
|
+
explainWhenToUse: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
includeCategories: z.ZodOptional<z.ZodBoolean>;
|
|
95
|
+
customInstructions: z.ZodOptional<z.ZodString>;
|
|
96
|
+
}, z.core.$strip>]>>;
|
|
97
|
+
toolCategories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
98
|
}, z.core.$strip>;
|
|
77
99
|
type RecipeConfig = z.infer<typeof RecipeConfigSchema>;
|
|
78
100
|
type ContentItem = z.infer<typeof ContentItemSchema>;
|
|
101
|
+
export interface ToolGuidanceConfig {
|
|
102
|
+
strategy: 'adaptive' | 'prescriptive' | 'minimal';
|
|
103
|
+
includeExamples?: boolean;
|
|
104
|
+
explainWhenToUse?: boolean;
|
|
105
|
+
includeCategories?: boolean;
|
|
106
|
+
customInstructions?: string;
|
|
107
|
+
}
|
|
79
108
|
export interface TemplateConfig {
|
|
80
109
|
persona?: ContentItem;
|
|
81
110
|
instructions?: ContentItem[];
|
|
82
111
|
content?: ContentItem[];
|
|
83
112
|
context?: ContentItem[];
|
|
113
|
+
tools?: Tool[] | ToolRegistry;
|
|
114
|
+
toolGuidance?: Partial<ToolGuidanceConfig> | 'auto' | 'minimal' | 'detailed';
|
|
84
115
|
}
|
|
85
116
|
/**
|
|
86
117
|
* Register custom templates with the recipes system
|
|
@@ -109,6 +140,10 @@ export declare const getTemplates: () => Record<string, TemplateConfig>;
|
|
|
109
140
|
* Clear all registered templates
|
|
110
141
|
*/
|
|
111
142
|
export declare const clearTemplates: () => void;
|
|
143
|
+
/**
|
|
144
|
+
* Generate tool guidance instructions based on strategy
|
|
145
|
+
*/
|
|
146
|
+
export declare const generateToolGuidance: (tools: Tool[], guidance: ToolGuidanceConfig | "auto" | "minimal" | "detailed") => string;
|
|
112
147
|
export declare const cook: (config: Partial<RecipeConfig> & {
|
|
113
148
|
basePath: string;
|
|
114
149
|
}) => Promise<Prompt>;
|
|
@@ -122,6 +157,13 @@ export declare const recipe: (basePath: string) => {
|
|
|
122
157
|
parameters: (parameters: any) => /*elided*/ any;
|
|
123
158
|
overrides: (enabled: boolean) => /*elided*/ any;
|
|
124
159
|
overridePaths: (paths: string[]) => /*elided*/ any;
|
|
160
|
+
tools: (tools: Tool[] | ToolRegistry) => /*elided*/ any;
|
|
161
|
+
toolRegistry: (registry: ToolRegistry) => /*elided*/ any;
|
|
162
|
+
toolGuidance: (guidance: ToolGuidanceConfig | "auto" | "minimal" | "detailed") => /*elided*/ any;
|
|
163
|
+
toolCategories: (categories: string[]) => /*elided*/ any;
|
|
125
164
|
cook: () => Promise<Prompt>;
|
|
165
|
+
buildConversation: (model: Model, tokenBudget?: TokenBudgetConfig) => Promise<ConversationBuilder>;
|
|
166
|
+
getToolRegistry: () => ToolRegistry | undefined;
|
|
167
|
+
executeWith: (llm: LLMClient, strategy: IterationStrategy, model?: Model, tokenBudget?: TokenBudgetConfig) => Promise<StrategyResult>;
|
|
126
168
|
};
|
|
127
169
|
export type { RecipeConfig, ContentItem };
|