feat: immutable entries + full task logging
Entries now immutable once journal is generated: - Edit/delete returns ENTRY_IMMUTABLE error if journal exists - Frontend shows lock message and hides delete button - Delete Journal button to unlock entries Task logging now stores full JSON: - request: full JSON request sent to AI provider - response: full JSON response from AI provider - prompt: formatted human-readable prompt Prompt structure: 1. System prompt 2. Previous diary entries (journals) 3. Today's entries
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { AIProvider, AIProviderConfig } from './provider';
|
||||
import type { AIProvider, AIProviderConfig, AIProviderResult } from './provider';
|
||||
|
||||
export class GroqProvider implements AIProvider {
|
||||
provider = 'groq' as const;
|
||||
@@ -12,7 +12,7 @@ export class GroqProvider implements AIProvider {
|
||||
this.baseUrl = config.baseUrl || 'https://api.groq.com/openai/v1';
|
||||
}
|
||||
|
||||
async generate(prompt: string, systemPrompt?: string): Promise<string> {
|
||||
async generate(prompt: string, systemPrompt?: string): Promise<AIProviderResult> {
|
||||
const messages: Array<{ role: string; content: string }> = [];
|
||||
|
||||
if (systemPrompt) {
|
||||
@@ -21,27 +21,36 @@ export class GroqProvider implements AIProvider {
|
||||
|
||||
messages.push({ role: 'user', content: prompt });
|
||||
|
||||
const requestBody = {
|
||||
model: this.model,
|
||||
messages,
|
||||
temperature: 0.7,
|
||||
max_tokens: 2000,
|
||||
};
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${this.apiKey}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: this.model,
|
||||
messages,
|
||||
temperature: 0.7,
|
||||
max_tokens: 2000,
|
||||
}),
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
const responseText = await response.text();
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
throw new Error(`Groq API error: ${response.status} ${error}`);
|
||||
throw new Error(`Groq API error: ${response.status} ${responseText}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as { choices: Array<{ message: { content: string } }> };
|
||||
return data.choices[0]?.message?.content || '';
|
||||
const responseData = JSON.parse(responseText);
|
||||
const content = responseData.choices?.[0]?.message?.content || '';
|
||||
|
||||
return {
|
||||
content,
|
||||
request: requestBody,
|
||||
response: responseData,
|
||||
};
|
||||
}
|
||||
|
||||
async validate(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user