Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9f72f9b
Remove bun.lock file
dakdevs Apr 25, 2025
c8e6b1b
Refactor AI email body generation to use `generateEmailBodyV2`.
dakdevs Apr 25, 2025
fa67c73
Merge branch 'main' into dakdevs/ai-compose
dakdevs Apr 25, 2025
07ab62f
Remove redundant files and update npm configuration
dakdevs Apr 25, 2025
5bd5a10
Refactor AI module and clean up unused dependencies
dakdevs Apr 25, 2025
009afbd
Handle errors during writing style matrix update
dakdevs Apr 25, 2025
4f51f31
Rename API key check to use OpenAI key instead of Groq.
dakdevs Apr 25, 2025
4ee6198
Refactor email body generation to simplify function structure
dakdevs Apr 25, 2025
748b46f
Remove conversation history handling from AI prompt generation
dakdevs Apr 25, 2025
7e7e355
Escape user prompt content in XML message
dakdevs Apr 25, 2025
e96953e
Fix incorrect totals in writing style initialization
dakdevs Apr 25, 2025
7a76316
Remove unused conversationId and signatureHash handling
dakdevs Apr 25, 2025
f7df688
Enhance email style analysis with new metrics and refinements.
dakdevs Apr 25, 2025
feab9c4
Refactor writing style metrics to use Welford's algorithm.
dakdevs Apr 25, 2025
db7be1d
Refactor writing style matrix to streamline key handling
dakdevs Apr 25, 2025
67af3d1
Remove unused conversationHistory parameter from function
dakdevs Apr 25, 2025
097bbe2
Remove unused conversationHistories object.
dakdevs Apr 25, 2025
beafd43
**Fix HTML markup and standardize prompt instructions**
dakdevs Apr 25, 2025
a5c5761
THIS IS A CHECKPOINT COMMIT
dakdevs Apr 25, 2025
ad4a0b7
Refactor email generation prompt for clarity and precision.
dakdevs Apr 25, 2025
1915f68
Merge branch 'main' into dakdevs/ai-compose
dakdevs Apr 26, 2025
d708c74
Add style matrix seeder and update email summary handling
dakdevs Apr 26, 2025
48b7710
Merge branch 'main' into dakdevs/ai-compose
dakdevs Apr 26, 2025
8e01f01
Update AI model, increase retries, and adjust dependencies
dakdevs Apr 27, 2025
812857d
Remove unnecessary blank line in prompts.ts
dakdevs Apr 27, 2025
29804af
Refactor AI body generation and improve seeder robustness
dakdevs Apr 27, 2025
6377275
Refactor seed-style-matrix to seed-style and improve docs
dakdevs Apr 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# don't show warnings if package versions don't match
strict-peer-dependencies=false
auto-install-peers=true
save-exact=true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to auto-pin dependencies.

1 change: 1 addition & 0 deletions apps/mail/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
18 changes: 8 additions & 10 deletions apps/mail/actions/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function generateAIEmailBody({
currentContent,
subject,
to,
conversationId,
userContext,
}: {
prompt: string;
Expand All @@ -45,15 +44,14 @@ export async function generateAIEmailBody({
type: 'system',
};
}
const responses = await generateEmailBody(

const responses = await generateEmailBody({
prompt,
currentContent,
to,
recipients: to,
subject,
conversationId,
userContext,
);
});

const response = responses[0];
if (!response) {
Expand All @@ -72,7 +70,7 @@ export async function generateAIEmailBody({
console.log("--- End Action Layer (Body) Log ---");

const responseBody = response.body ?? '';

if (!responseBody) {
console.error('AI Action Error (Body): Missing body field on response');
const errorMsg = 'AI returned an unexpected format.';
Expand All @@ -82,15 +80,15 @@ export async function generateAIEmailBody({
type: 'system',
};
}

const jsonContent = createJsonContentFromBody(responseBody);

return {
content: responseBody,
jsonContent,
type: response.type,
};

} catch (error) {
console.error('Error in generateAIEmailBody action:', error);
const errorMsg = 'Sorry, I encountered an unexpected error while generating the email body.';
Expand Down Expand Up @@ -145,7 +143,7 @@ function createJsonContentFromBody(bodyText: string): JSONContent {
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: bodyText.trim() }],
content: [{ type: 'text', text: bodyText.trim() }],
}
],
};
Expand Down
13 changes: 13 additions & 0 deletions apps/mail/actions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { createDriver } from '@/app/api/driver';
import { getActiveConnection } from './utils';
import { Sender } from '@/types';
import { after } from 'next/server';
import { updateWritingStyleMatrix } from '@/services/writing-style-service';

export async function sendEmail({
to,
Expand Down Expand Up @@ -63,5 +65,16 @@ export async function sendEmail({
await driver.create(emailData);
}

after(async () => {
try {
console.warn('Saving writing style matrix...')
await updateWritingStyleMatrix(connection.id, message)
console.warn('Saved writing style matrix.')
} catch (error) {
console.error('Failed to save writing style matrix', error)
}
})
Comment on lines +68 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way once the email sends, the user gets feedback immediately while the style matrix gets update in the background.


return { success: true };
}

5 changes: 2 additions & 3 deletions apps/mail/components/create/ai-assistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ export const AIAssistant = ({
currentContent: generatedBody?.content || currentContent,
subject,
to: recipients,
conversationId,
userContext: { name: userName, email: userEmail },
});
console.log('AI Assistant: Received Body Result:', JSON.stringify(bodyResult));
Expand Down Expand Up @@ -314,7 +313,7 @@ export const AIAssistant = ({
console.log('AI Assistant: Requesting email subject...');
const subjectResult = await generateAISubject({ body: bodyResult.content });
console.log('AI Assistant: Received Subject Result:', subjectResult);

if (subjectResult && subjectResult.trim() !== '') {
finalSubject = subjectResult;
setGeneratedSubject(finalSubject);
Expand All @@ -330,7 +329,7 @@ export const AIAssistant = ({
setErrorOccurred(true);
throw new Error("Body generation resulted in empty content.");
}

setShowActions(true);
setPrompt('');

Expand Down
Loading