Skip to content

Commit fdc15b7

Browse files
authored
Merge pull request #9 from will-lp1/shift-synonym
Refactor chat and inline suggestion APIs to remove smoothStream usage…
2 parents c424f8a + ffd60d6 commit fdc15b7

File tree

5 files changed

+376
-5
lines changed

5 files changed

+376
-5
lines changed

apps/snow-leopard/app/api/chat/route.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
type Message,
33
createDataStreamResponse,
4-
smoothStream,
54
streamText,
65
} from 'ai';
76
import { systemPrompt } from '@/lib/ai/prompts';
@@ -348,8 +347,7 @@ export async function POST(request: Request) {
348347
system: enhancedSystemPrompt,
349348
messages,
350349
maxSteps: 5,
351-
experimental_activeTools: activeToolsList,
352-
experimental_transform: smoothStream({ chunking: 'line' }),
350+
experimental_activeTools: activeToolsList,
353351
experimental_generateMessageId: generateUUID,
354352
tools: availableTools,
355353
onFinish: async ({ response, reasoning }) => {

apps/snow-leopard/app/api/inline-suggestion/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextResponse } from 'next/server';
2-
import { streamText, smoothStream } from 'ai';
2+
import { streamText } from 'ai';
33
import { getDocumentById } from '@/lib/db/queries';
44
import { myProvider } from '@/lib/ai/providers';
55
import { auth } from "@/lib/auth";
@@ -161,7 +161,6 @@ async function streamInlineSuggestion({
161161
const { fullStream } = streamText({
162162
model: myProvider.languageModel('artifact-model'),
163163
system: getSystemPrompt(aiOptions?.customInstructions),
164-
experimental_transform: smoothStream({ chunking: 'word' }),
165164
prompt,
166165
temperature: 0.4, // Fixed temperature for text
167166
maxTokens: maxTokens,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { NextResponse } from 'next/server';
2+
import { generateText } from 'ai'; // Using generateText for a non-streaming response
3+
import { myProvider } from '@/lib/ai/providers'; // Assuming myProvider is configured
4+
5+
export async function POST(request: Request) {
6+
try {
7+
const { word, context } = await request.json();
8+
9+
if (!word) {
10+
return NextResponse.json({ error: 'Missing word parameter' }, { status: 400 });
11+
}
12+
13+
const prompt = context
14+
? `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`
15+
: `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`;
16+
17+
const { text } = await generateText({
18+
model: myProvider.languageModel('artifact-model'),
19+
prompt,
20+
maxTokens: 20,
21+
temperature: 0.3,
22+
});
23+
24+
const synonyms = text.split(',')
25+
.map(s => s.trim())
26+
.filter(s => s !== '' && s.toLowerCase() !== word.toLowerCase())
27+
.slice(0, 2);
28+
29+
return NextResponse.json({ synonyms });
30+
31+
} catch (error: any) {
32+
if (error instanceof SyntaxError) {
33+
return NextResponse.json({ error: 'Invalid request body' }, { status: 400 });
34+
}
35+
return NextResponse.json({ error: 'Failed to fetch synonyms' }, { status: 500 });
36+
}
37+
}

apps/snow-leopard/components/document/text-editor.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import { placeholderPlugin } from '@/lib/editor/placeholder-plugin';
3232

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

35+
import { synonymsPlugin } from '@/lib/editor/synonym-plugin';
36+
3537
type EditorProps = {
3638
content: string;
3739
status: 'streaming' | 'idle';
@@ -228,6 +230,7 @@ function PureEditor({
228230
],
229231
}),
230232
inlineSuggestionPlugin({ requestSuggestion: requestInlineSuggestionCallback }),
233+
synonymsPlugin(),
231234
savePlugin({
232235
saveFunction: performSave,
233236
initialLastSaved: initialLastSaved,
@@ -568,6 +571,50 @@ function PureEditor({
568571
div.ProseMirror {
569572
position: relative;
570573
}
574+
575+
.synonym-word {
576+
/* Cursor is handled by the browser default for text */
577+
position: relative; /* Needed for absolute positioning of pseudo-element */
578+
display: inline-block; /* Ensure span takes space for overlay */
579+
}
580+
.synonym-overlay-menu {
581+
/* Dark background like the image */
582+
background: #282c34; /* Dark grey/black */
583+
color: #fff; /* White text */
584+
border: none; /* Remove default border */
585+
padding: 4px;
586+
border-radius: 4px;
587+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
588+
display: flex; /* Arrange buttons horizontally */
589+
gap: 4px; /* Spacing between buttons */
590+
}
591+
.synonym-overlay-menu .synonym-option {
592+
background: none;
593+
border: none;
594+
padding: 2px 6px; /* Adjust padding */
595+
margin: 0; /* Remove default margin */
596+
cursor: pointer;
597+
font: inherit;
598+
color: inherit; /* Inherit white text color */
599+
border-radius: 3px; /* Slightly rounded corners */
600+
}
601+
.synonym-overlay-menu .synonym-option:hover {
602+
/* Slightly lighter background on hover */
603+
background: rgba(255, 255, 255, 0.1);
604+
}
605+
/* Loading state overlay */
606+
.synonym-loading::before {
607+
content: '';
608+
position: absolute;
609+
top: 0;
610+
left: 0;
611+
right: 0;
612+
bottom: 0;
613+
background-color: rgba(100, 100, 100, 0.2); /* Semi-transparent gray overlay */
614+
border-radius: 2px; /* Optional: slightly rounded corners */
615+
pointer-events: none; /* Allow clicks/hovers to pass through */
616+
z-index: 1; /* Ensure it's above the text but below potential popups */
617+
}
571618
`}</style>
572619
</>
573620
);

0 commit comments

Comments
 (0)