@riotprompt/riotprompt 0.0.7 → 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.
Files changed (52) hide show
  1. package/.kodrdriv-test-cache.json +6 -0
  2. package/README.md +2 -2
  3. package/dist/builder.d.ts +3 -15
  4. package/dist/builder.js +3 -0
  5. package/dist/builder.js.map +1 -1
  6. package/dist/context-manager.d.ts +135 -0
  7. package/dist/context-manager.js +220 -0
  8. package/dist/context-manager.js.map +1 -0
  9. package/dist/conversation-logger.d.ts +283 -0
  10. package/dist/conversation-logger.js +454 -0
  11. package/dist/conversation-logger.js.map +1 -0
  12. package/dist/conversation.d.ts +271 -0
  13. package/dist/conversation.js +622 -0
  14. package/dist/conversation.js.map +1 -0
  15. package/dist/formatter.d.ts +27 -57
  16. package/dist/formatter.js +2 -2
  17. package/dist/formatter.js.map +1 -1
  18. package/dist/items/parameters.d.ts +1 -1
  19. package/dist/items/section.d.ts +2 -12
  20. package/dist/items/weighted.d.ts +3 -15
  21. package/dist/iteration-strategy.d.ts +231 -0
  22. package/dist/iteration-strategy.js +486 -0
  23. package/dist/iteration-strategy.js.map +1 -0
  24. package/dist/loader.d.ts +3 -11
  25. package/dist/loader.js +3 -0
  26. package/dist/loader.js.map +1 -1
  27. package/dist/message-builder.d.ts +156 -0
  28. package/dist/message-builder.js +254 -0
  29. package/dist/message-builder.js.map +1 -0
  30. package/dist/override.d.ts +3 -13
  31. package/dist/override.js +3 -0
  32. package/dist/override.js.map +1 -1
  33. package/dist/parser.d.ts +2 -8
  34. package/dist/recipes.d.ts +70 -268
  35. package/dist/recipes.js +189 -4
  36. package/dist/recipes.js.map +1 -1
  37. package/dist/reflection.d.ts +250 -0
  38. package/dist/reflection.js +416 -0
  39. package/dist/reflection.js.map +1 -0
  40. package/dist/riotprompt.cjs +3551 -220
  41. package/dist/riotprompt.cjs.map +1 -1
  42. package/dist/riotprompt.d.ts +18 -2
  43. package/dist/riotprompt.js +9 -1
  44. package/dist/riotprompt.js.map +1 -1
  45. package/dist/token-budget.d.ts +177 -0
  46. package/dist/token-budget.js +404 -0
  47. package/dist/token-budget.js.map +1 -0
  48. package/dist/tools.d.ts +239 -0
  49. package/dist/tools.js +324 -0
  50. package/dist/tools.js.map +1 -0
  51. package/package.json +35 -36
  52. package/.cursor/rules/focus-on-prompt.mdc +0 -5
@@ -0,0 +1,271 @@
1
+ import { Model } from './chat';
2
+ import { ContextManager, DynamicContentItem } from './context-manager';
3
+ import { LogConfig } from './conversation-logger';
4
+ import { Content } from './items/content';
5
+ import { Context } from './items/context';
6
+ import { Instruction } from './items/instruction';
7
+ import { Section } from './items/section';
8
+ import { Prompt } from './prompt';
9
+ import { TokenBudgetConfig, TokenUsage, CompressionStrategy } from './token-budget';
10
+ import * as Formatter from "./formatter";
11
+ /**
12
+ * Options for injecting context
13
+ */
14
+ export interface InjectOptions {
15
+ position?: 'end' | 'before-last' | 'after-system' | number;
16
+ format?: 'structured' | 'inline' | 'reference';
17
+ deduplicate?: boolean;
18
+ deduplicateBy?: 'id' | 'content' | 'hash';
19
+ priority?: 'high' | 'medium' | 'low';
20
+ weight?: number;
21
+ category?: string;
22
+ source?: string;
23
+ }
24
+ /**
25
+ * Represents a tool call made by the assistant
26
+ */
27
+ export interface ToolCall {
28
+ id: string;
29
+ type: 'function';
30
+ function: {
31
+ name: string;
32
+ arguments: string;
33
+ };
34
+ }
35
+ /**
36
+ * Message in a conversation (compatible with OpenAI ChatCompletionMessageParam)
37
+ */
38
+ export interface ConversationMessage {
39
+ role: 'system' | 'user' | 'assistant' | 'tool';
40
+ content: string | null;
41
+ name?: string;
42
+ tool_calls?: ToolCall[];
43
+ tool_call_id?: string;
44
+ }
45
+ /**
46
+ * Configuration for ConversationBuilder
47
+ */
48
+ export interface ConversationBuilderConfig {
49
+ model: Model;
50
+ formatter?: Formatter.Instance;
51
+ trackContext?: boolean;
52
+ deduplicateContext?: boolean;
53
+ }
54
+ /**
55
+ * Metadata about the conversation
56
+ */
57
+ export interface ConversationMetadata {
58
+ model: Model;
59
+ created: Date;
60
+ lastModified: Date;
61
+ messageCount: number;
62
+ toolCallCount: number;
63
+ }
64
+ /**
65
+ * Internal state of a conversation
66
+ */
67
+ export interface ConversationState {
68
+ messages: ConversationMessage[];
69
+ metadata: ConversationMetadata;
70
+ contextProvided: Set<string>;
71
+ contextManager: ContextManager;
72
+ }
73
+ /**
74
+ * Serializable conversation state for persistence
75
+ */
76
+ export interface SerializedConversation {
77
+ messages: ConversationMessage[];
78
+ metadata: Omit<ConversationMetadata, 'created' | 'lastModified'> & {
79
+ created: string;
80
+ lastModified: string;
81
+ };
82
+ contextProvided: string[];
83
+ }
84
+ /**
85
+ * ConversationBuilder manages multi-turn conversations with full lifecycle support.
86
+ *
87
+ * Features:
88
+ * - Initialize from RiotPrompt prompts
89
+ * - Add messages of any type (system, user, assistant, tool)
90
+ * - Handle tool calls and results
91
+ * - Inject dynamic context
92
+ * - Clone for parallel exploration
93
+ * - Serialize/deserialize for persistence
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Create from prompt
98
+ * const conversation = ConversationBuilder.create()
99
+ * .fromPrompt(prompt, 'gpt-4o')
100
+ * .build();
101
+ *
102
+ * // Add messages
103
+ * conversation.addUserMessage('Analyze this code');
104
+ *
105
+ * // Handle tool calls
106
+ * conversation.addAssistantWithToolCalls(null, toolCalls);
107
+ * conversation.addToolResult(toolCallId, result);
108
+ *
109
+ * // Export
110
+ * const messages = conversation.toMessages();
111
+ * ```
112
+ */
113
+ export declare class ConversationBuilder {
114
+ private state;
115
+ private config;
116
+ private logger;
117
+ private budgetManager?;
118
+ private conversationLogger?;
119
+ private constructor();
120
+ /**
121
+ * Create a new ConversationBuilder instance
122
+ */
123
+ static create(config?: Partial<ConversationBuilderConfig>, logger?: any): ConversationBuilder;
124
+ /**
125
+ * Initialize conversation from a RiotPrompt prompt
126
+ */
127
+ fromPrompt(prompt: Prompt, model?: Model): this;
128
+ /**
129
+ * Add a system message
130
+ */
131
+ addSystemMessage(content: string | Section<Instruction>): this;
132
+ /**
133
+ * Add a user message (with automatic budget management)
134
+ */
135
+ addUserMessage(content: string | Section<Content>): this;
136
+ /**
137
+ * Add an assistant message
138
+ */
139
+ addAssistantMessage(content: string | null): this;
140
+ /**
141
+ * Add an assistant message with tool calls
142
+ */
143
+ addAssistantWithToolCalls(content: string | null, toolCalls: ToolCall[]): this;
144
+ /**
145
+ * Add a tool result message
146
+ */
147
+ addToolResult(toolCallId: string, content: string, toolName?: string): this;
148
+ /**
149
+ * Alias for addToolResult (more intuitive naming)
150
+ */
151
+ addToolMessage(toolCallId: string, content: string, toolName?: string): this;
152
+ /**
153
+ * Inject context into the conversation with advanced options
154
+ *
155
+ * @param context - Array of content items to inject
156
+ * @param options - Injection options (position, format, deduplication, etc.)
157
+ */
158
+ injectContext(context: DynamicContentItem[], options?: InjectOptions): this;
159
+ /**
160
+ * Inject system-level context
161
+ */
162
+ injectSystemContext(context: Section<Context> | string): this;
163
+ /**
164
+ * Get the number of messages in the conversation
165
+ */
166
+ getMessageCount(): number;
167
+ /**
168
+ * Get the last message in the conversation
169
+ */
170
+ getLastMessage(): ConversationMessage | undefined;
171
+ /**
172
+ * Get all messages
173
+ */
174
+ getMessages(): ConversationMessage[];
175
+ /**
176
+ * Check if conversation has any tool calls
177
+ */
178
+ hasToolCalls(): boolean;
179
+ /**
180
+ * Get conversation metadata
181
+ */
182
+ getMetadata(): ConversationMetadata;
183
+ /**
184
+ * Export messages in OpenAI format
185
+ */
186
+ toMessages(): ConversationMessage[];
187
+ /**
188
+ * Serialize conversation to JSON
189
+ */
190
+ toJSON(): string;
191
+ /**
192
+ * Restore conversation from JSON
193
+ */
194
+ static fromJSON(json: string, config?: Partial<ConversationBuilderConfig>, logger?: any): ConversationBuilder;
195
+ /**
196
+ * Clone the conversation for parallel exploration
197
+ */
198
+ clone(): ConversationBuilder;
199
+ /**
200
+ * Truncate conversation to last N messages
201
+ */
202
+ truncate(maxMessages: number): this;
203
+ /**
204
+ * Remove all messages of a specific type
205
+ */
206
+ removeMessagesOfType(role: 'system' | 'user' | 'assistant' | 'tool'): this;
207
+ /**
208
+ * Get the context manager
209
+ */
210
+ getContextManager(): ContextManager;
211
+ /**
212
+ * Get conversation state (for conditional injection)
213
+ */
214
+ getState(): ConversationState;
215
+ /**
216
+ * Add a system message using semantic builder
217
+ */
218
+ asSystem(content: string | Section<Instruction>): this;
219
+ /**
220
+ * Add a user message using semantic builder
221
+ */
222
+ asUser(content: string | Section<Content>): this;
223
+ /**
224
+ * Add an assistant message using semantic builder
225
+ */
226
+ asAssistant(content: string | null, toolCalls?: ToolCall[]): this;
227
+ /**
228
+ * Add a tool result message using semantic builder
229
+ */
230
+ asTool(callId: string, result: any, metadata?: Record<string, any>): this;
231
+ /**
232
+ * Configure token budget
233
+ */
234
+ withTokenBudget(config: TokenBudgetConfig): this;
235
+ /**
236
+ * Configure conversation logging
237
+ */
238
+ withLogging(config: LogConfig): this;
239
+ /**
240
+ * Save conversation log
241
+ */
242
+ saveLog(): Promise<string>;
243
+ /**
244
+ * Get current token usage
245
+ */
246
+ getTokenUsage(): TokenUsage;
247
+ /**
248
+ * Manually compress conversation
249
+ */
250
+ compress(_strategy?: CompressionStrategy): this;
251
+ /**
252
+ * Build and return the builder (for fluent API compatibility)
253
+ */
254
+ build(): this;
255
+ /**
256
+ * Calculate position for context injection
257
+ */
258
+ private calculatePosition;
259
+ /**
260
+ * Format context item based on format option
261
+ */
262
+ private formatContextItem;
263
+ /**
264
+ * Update metadata after state changes
265
+ */
266
+ private updateMetadata;
267
+ }
268
+ /**
269
+ * Export the builder for use in other modules
270
+ */
271
+ export default ConversationBuilder;