Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions apps/snow-leopard/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type Message,
createDataStreamResponse,
smoothStream,
streamText,
} from 'ai';
import { systemPrompt } from '@/lib/ai/prompts';
Expand Down Expand Up @@ -348,8 +347,7 @@ export async function POST(request: Request) {
system: enhancedSystemPrompt,
messages,
maxSteps: 5,
experimental_activeTools: activeToolsList,
experimental_transform: smoothStream({ chunking: 'line' }),
experimental_activeTools: activeToolsList,
experimental_generateMessageId: generateUUID,
tools: availableTools,
onFinish: async ({ response, reasoning }) => {
Expand Down
3 changes: 1 addition & 2 deletions apps/snow-leopard/app/api/inline-suggestion/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { streamText, smoothStream } from 'ai';
import { streamText } from 'ai';
import { getDocumentById } from '@/lib/db/queries';
import { myProvider } from '@/lib/ai/providers';
import { auth } from "@/lib/auth";
Expand Down Expand Up @@ -161,7 +161,6 @@ async function streamInlineSuggestion({
const { fullStream } = streamText({
model: myProvider.languageModel('artifact-model'),
system: getSystemPrompt(aiOptions?.customInstructions),
experimental_transform: smoothStream({ chunking: 'word' }),
prompt,
temperature: 0.4, // Fixed temperature for text
maxTokens: maxTokens,
Expand Down
37 changes: 37 additions & 0 deletions apps/snow-leopard/app/api/synonyms/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NextResponse } from 'next/server';
import { generateText } from 'ai'; // Using generateText for a non-streaming response
import { myProvider } from '@/lib/ai/providers'; // Assuming myProvider is configured

export async function POST(request: Request) {
try {
const { word, context } = await request.json();

if (!word) {
return NextResponse.json({ error: 'Missing word parameter' }, { status: 400 });
}

const prompt = context
? `Given the following text context: "${context}"\n\nProvide exactly two common synonyms for the word "${word}" that fit well within that context. Separate the synonyms with a comma. Do not include the original word. Only output the synonyms. Example: joyful, cheerful`
: `Provide exactly two common synonyms for the word "${word}". Separate the synonyms with a comma. Do not include the original word. Only output the synonyms. Example: happy -> joyful, cheerful`;

const { text } = await generateText({
model: myProvider.languageModel('artifact-model'),
prompt,
maxTokens: 20,
temperature: 0.3,
});

const synonyms = text.split(',')
.map(s => s.trim())
.filter(s => s !== '' && s.toLowerCase() !== word.toLowerCase())
.slice(0, 2);

return NextResponse.json({ synonyms });

} catch (error: any) {
if (error instanceof SyntaxError) {
return NextResponse.json({ error: 'Invalid request body' }, { status: 400 });
}
return NextResponse.json({ error: 'Failed to fetch synonyms' }, { status: 500 });
}
}
47 changes: 47 additions & 0 deletions apps/snow-leopard/components/document/text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { placeholderPlugin } from '@/lib/editor/placeholder-plugin';

import { savePlugin, savePluginKey, setSaveStatus, type SaveState, type SaveStatus } from '@/lib/editor/save-plugin';

import { synonymsPlugin } from '@/lib/editor/synonym-plugin';

type EditorProps = {
content: string;
status: 'streaming' | 'idle';
Expand Down Expand Up @@ -228,6 +230,7 @@ function PureEditor({
],
}),
inlineSuggestionPlugin({ requestSuggestion: requestInlineSuggestionCallback }),
synonymsPlugin(),
savePlugin({
saveFunction: performSave,
initialLastSaved: initialLastSaved,
Expand Down Expand Up @@ -568,6 +571,50 @@ function PureEditor({
div.ProseMirror {
position: relative;
}

.synonym-word {
/* Cursor is handled by the browser default for text */
position: relative; /* Needed for absolute positioning of pseudo-element */
display: inline-block; /* Ensure span takes space for overlay */
}
.synonym-overlay-menu {
/* Dark background like the image */
background: #282c34; /* Dark grey/black */
color: #fff; /* White text */
border: none; /* Remove default border */
padding: 4px;
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
display: flex; /* Arrange buttons horizontally */
gap: 4px; /* Spacing between buttons */
}
.synonym-overlay-menu .synonym-option {
background: none;
border: none;
padding: 2px 6px; /* Adjust padding */
margin: 0; /* Remove default margin */
cursor: pointer;
font: inherit;
color: inherit; /* Inherit white text color */
border-radius: 3px; /* Slightly rounded corners */
}
.synonym-overlay-menu .synonym-option:hover {
/* Slightly lighter background on hover */
background: rgba(255, 255, 255, 0.1);
}
/* Loading state overlay */
.synonym-loading::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(100, 100, 100, 0.2); /* Semi-transparent gray overlay */
border-radius: 2px; /* Optional: slightly rounded corners */
pointer-events: none; /* Allow clicks/hovers to pass through */
z-index: 1; /* Ensure it's above the text but below potential popups */
}
`}</style>
</>
);
Expand Down
Loading