@riotprompt/riotprompt 0.0.8 → 0.0.9
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/README.md +2 -2
- package/dist/builder.js +3 -0
- package/dist/builder.js.map +1 -1
- package/dist/context-manager.d.ts +135 -0
- package/dist/context-manager.js +220 -0
- package/dist/context-manager.js.map +1 -0
- package/dist/conversation-logger.d.ts +283 -0
- package/dist/conversation-logger.js +454 -0
- package/dist/conversation-logger.js.map +1 -0
- package/dist/conversation.d.ts +271 -0
- package/dist/conversation.js +622 -0
- package/dist/conversation.js.map +1 -0
- package/dist/formatter.js.map +1 -1
- package/dist/iteration-strategy.d.ts +231 -0
- package/dist/iteration-strategy.js +486 -0
- package/dist/iteration-strategy.js.map +1 -0
- package/dist/loader.js +3 -0
- package/dist/loader.js.map +1 -1
- package/dist/message-builder.d.ts +156 -0
- package/dist/message-builder.js +254 -0
- package/dist/message-builder.js.map +1 -0
- package/dist/override.js +3 -0
- package/dist/override.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 +416 -0
- package/dist/reflection.js.map +1 -0
- package/dist/riotprompt.cjs +3549 -218
- package/dist/riotprompt.cjs.map +1 -1
- package/dist/riotprompt.d.ts +18 -2
- package/dist/riotprompt.js +9 -1
- package/dist/riotprompt.js.map +1 -1
- package/dist/token-budget.d.ts +177 -0
- package/dist/token-budget.js +404 -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/package.json +23 -20
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { ConversationMessage, ToolCall } from './conversation';
|
|
2
|
+
/**
|
|
3
|
+
* Log format
|
|
4
|
+
*/
|
|
5
|
+
export type LogFormat = 'json' | 'markdown' | 'jsonl';
|
|
6
|
+
/**
|
|
7
|
+
* Log configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface LogConfig {
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
outputPath?: string;
|
|
12
|
+
format?: LogFormat;
|
|
13
|
+
filenameTemplate?: string;
|
|
14
|
+
includeMetadata?: boolean;
|
|
15
|
+
includePrompt?: boolean;
|
|
16
|
+
redactSensitive?: boolean;
|
|
17
|
+
redactPatterns?: RegExp[];
|
|
18
|
+
onSaved?: (path: string) => void;
|
|
19
|
+
onError?: (error: Error) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Logged conversation structure
|
|
23
|
+
*/
|
|
24
|
+
export interface LoggedConversation {
|
|
25
|
+
id: string;
|
|
26
|
+
metadata: ConversationLogMetadata;
|
|
27
|
+
prompt?: PromptSnapshot;
|
|
28
|
+
messages: LoggedMessage[];
|
|
29
|
+
summary: ConversationSummary;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Conversation metadata for logging
|
|
33
|
+
*/
|
|
34
|
+
export interface ConversationLogMetadata {
|
|
35
|
+
startTime: Date;
|
|
36
|
+
endTime?: Date;
|
|
37
|
+
duration?: number;
|
|
38
|
+
model: string;
|
|
39
|
+
template?: string;
|
|
40
|
+
userContext?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Snapshot of prompt configuration
|
|
44
|
+
*/
|
|
45
|
+
export interface PromptSnapshot {
|
|
46
|
+
persona?: string;
|
|
47
|
+
instructions?: string;
|
|
48
|
+
content?: string[];
|
|
49
|
+
context?: string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Logged message with metadata
|
|
53
|
+
*/
|
|
54
|
+
export interface LoggedMessage {
|
|
55
|
+
index: number;
|
|
56
|
+
timestamp: string;
|
|
57
|
+
role: string;
|
|
58
|
+
content: string | null;
|
|
59
|
+
tool_calls?: ToolCall[];
|
|
60
|
+
tool_call_id?: string;
|
|
61
|
+
metadata?: MessageLogMetadata;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Message metadata for logging
|
|
65
|
+
*/
|
|
66
|
+
export interface MessageLogMetadata {
|
|
67
|
+
tokens?: number;
|
|
68
|
+
source?: string;
|
|
69
|
+
latency?: number;
|
|
70
|
+
tool?: string;
|
|
71
|
+
duration?: number;
|
|
72
|
+
success?: boolean;
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Conversation summary
|
|
77
|
+
*/
|
|
78
|
+
export interface ConversationSummary {
|
|
79
|
+
totalMessages: number;
|
|
80
|
+
totalTokens?: number;
|
|
81
|
+
toolCallsExecuted: number;
|
|
82
|
+
iterations: number;
|
|
83
|
+
finalOutput?: string;
|
|
84
|
+
success: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Tool call log entry
|
|
88
|
+
*/
|
|
89
|
+
export interface ToolCallLog {
|
|
90
|
+
callId: string;
|
|
91
|
+
toolName: string;
|
|
92
|
+
timestamp: string;
|
|
93
|
+
iteration: number;
|
|
94
|
+
arguments: any;
|
|
95
|
+
result: any;
|
|
96
|
+
duration: number;
|
|
97
|
+
success: boolean;
|
|
98
|
+
error?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* ConversationLogger logs conversations to various formats.
|
|
102
|
+
*
|
|
103
|
+
* Features:
|
|
104
|
+
* - Multiple formats (JSON, Markdown, JSONL)
|
|
105
|
+
* - Automatic timestamping
|
|
106
|
+
* - Metadata tracking
|
|
107
|
+
* - Sensitive data redaction
|
|
108
|
+
* - Streaming support (JSONL)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const logger = new ConversationLogger({
|
|
113
|
+
* enabled: true,
|
|
114
|
+
* outputPath: 'logs/conversations',
|
|
115
|
+
* format: 'json',
|
|
116
|
+
* includeMetadata: true
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* logger.onConversationStart({ model: 'gpt-4o', startTime: new Date() });
|
|
120
|
+
* logger.onMessageAdded(message);
|
|
121
|
+
* const path = await logger.save();
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare class ConversationLogger {
|
|
125
|
+
private config;
|
|
126
|
+
private conversationId;
|
|
127
|
+
private metadata;
|
|
128
|
+
private messages;
|
|
129
|
+
private toolCalls;
|
|
130
|
+
private startTime;
|
|
131
|
+
private logger;
|
|
132
|
+
private messageIndex;
|
|
133
|
+
constructor(config: LogConfig, logger?: any);
|
|
134
|
+
/**
|
|
135
|
+
* Start conversation logging
|
|
136
|
+
*/
|
|
137
|
+
onConversationStart(metadata: Partial<ConversationLogMetadata>): void;
|
|
138
|
+
/**
|
|
139
|
+
* Log a message
|
|
140
|
+
*/
|
|
141
|
+
onMessageAdded(message: ConversationMessage, metadata?: MessageLogMetadata): void;
|
|
142
|
+
/**
|
|
143
|
+
* Log a tool call
|
|
144
|
+
*/
|
|
145
|
+
onToolCall(callId: string, toolName: string, iteration: number, args: any, result: any, duration: number, success: boolean, error?: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* End conversation logging
|
|
148
|
+
*/
|
|
149
|
+
onConversationEnd(_summary: ConversationSummary): void;
|
|
150
|
+
/**
|
|
151
|
+
* Save conversation to disk
|
|
152
|
+
*/
|
|
153
|
+
save(): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Get logged conversation object
|
|
156
|
+
*/
|
|
157
|
+
getConversation(): LoggedConversation;
|
|
158
|
+
/**
|
|
159
|
+
* Generate unique conversation ID
|
|
160
|
+
*/
|
|
161
|
+
private generateId;
|
|
162
|
+
/**
|
|
163
|
+
* Get output file path
|
|
164
|
+
*/
|
|
165
|
+
private getOutputPath;
|
|
166
|
+
/**
|
|
167
|
+
* Save as JSON
|
|
168
|
+
*/
|
|
169
|
+
private saveAsJSON;
|
|
170
|
+
/**
|
|
171
|
+
* Save as Markdown
|
|
172
|
+
*/
|
|
173
|
+
private saveAsMarkdown;
|
|
174
|
+
/**
|
|
175
|
+
* Append to JSONL file (streaming)
|
|
176
|
+
*/
|
|
177
|
+
private appendToJSONL;
|
|
178
|
+
/**
|
|
179
|
+
* Redact sensitive content
|
|
180
|
+
*/
|
|
181
|
+
private redactContent;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Replay options
|
|
185
|
+
*/
|
|
186
|
+
export interface ReplayOptions {
|
|
187
|
+
model?: string;
|
|
188
|
+
maxIterations?: number;
|
|
189
|
+
retryFailedTools?: boolean;
|
|
190
|
+
toolTimeout?: number;
|
|
191
|
+
expectSimilarOutput?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Replay result
|
|
195
|
+
*/
|
|
196
|
+
export interface ReplayResult {
|
|
197
|
+
success: boolean;
|
|
198
|
+
conversation: LoggedConversation;
|
|
199
|
+
errors?: Error[];
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Comparison result
|
|
203
|
+
*/
|
|
204
|
+
export interface ComparisonResult {
|
|
205
|
+
messageDiff: number;
|
|
206
|
+
toolCallDiff: number;
|
|
207
|
+
tokenDiff?: number;
|
|
208
|
+
outputSimilarity: number;
|
|
209
|
+
costSavings?: number;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* ConversationReplayer loads and replays logged conversations.
|
|
213
|
+
*
|
|
214
|
+
* Features:
|
|
215
|
+
* - Load from various formats
|
|
216
|
+
* - Replay conversations
|
|
217
|
+
* - Compare replays with originals
|
|
218
|
+
* - Export to different formats
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const replayer = await ConversationReplayer.load('logs/conv.json');
|
|
223
|
+
*
|
|
224
|
+
* console.log('Messages:', replayer.messages.length);
|
|
225
|
+
* console.log('Tool calls:', replayer.getToolCalls().length);
|
|
226
|
+
*
|
|
227
|
+
* const timeline = replayer.getTimeline();
|
|
228
|
+
* console.log('Events:', timeline.length);
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare class ConversationReplayer {
|
|
232
|
+
private conversation;
|
|
233
|
+
private logger;
|
|
234
|
+
private constructor();
|
|
235
|
+
/**
|
|
236
|
+
* Load conversation from file
|
|
237
|
+
*/
|
|
238
|
+
static load(filePath: string, logger?: any): Promise<ConversationReplayer>;
|
|
239
|
+
/**
|
|
240
|
+
* Load latest conversation from directory
|
|
241
|
+
*/
|
|
242
|
+
static loadLatest(directory: string, logger?: any): Promise<ConversationReplayer>;
|
|
243
|
+
/**
|
|
244
|
+
* Get all messages
|
|
245
|
+
*/
|
|
246
|
+
get messages(): LoggedMessage[];
|
|
247
|
+
/**
|
|
248
|
+
* Get conversation metadata
|
|
249
|
+
*/
|
|
250
|
+
getMetadata(): ConversationLogMetadata;
|
|
251
|
+
/**
|
|
252
|
+
* Get tool calls
|
|
253
|
+
*/
|
|
254
|
+
getToolCalls(): ToolCallLog[];
|
|
255
|
+
/**
|
|
256
|
+
* Get message at index
|
|
257
|
+
*/
|
|
258
|
+
getMessageAt(index: number): LoggedMessage | undefined;
|
|
259
|
+
/**
|
|
260
|
+
* Get timeline of events
|
|
261
|
+
*/
|
|
262
|
+
getTimeline(): TimelineEvent[];
|
|
263
|
+
/**
|
|
264
|
+
* Export to format
|
|
265
|
+
*/
|
|
266
|
+
exportToFormat(format: LogFormat, outputPath: string): Promise<string>;
|
|
267
|
+
/**
|
|
268
|
+
* Export as markdown
|
|
269
|
+
*/
|
|
270
|
+
private exportMarkdown;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Timeline event interface
|
|
274
|
+
*/
|
|
275
|
+
interface TimelineEvent {
|
|
276
|
+
timestamp: string;
|
|
277
|
+
iteration: number;
|
|
278
|
+
type: string;
|
|
279
|
+
description: string;
|
|
280
|
+
duration?: number;
|
|
281
|
+
success?: boolean;
|
|
282
|
+
}
|
|
283
|
+
export default ConversationLogger;
|