Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
5a41337
1
Parent(s): c04c757
backend sprint
Browse files
frontend/apps/customer/src/components/NexusMasterAgent.tsx
CHANGED
|
@@ -56,7 +56,7 @@ export const NexusMasterAgent: React.FC = () => {
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
|
| 59 |
-
const renderMessage = (m: any, index: number) => {
|
| 60 |
const isLatest = index === messages.length - 1;
|
| 61 |
|
| 62 |
// 1. User Message (Standard)
|
|
@@ -182,9 +182,28 @@ export const NexusMasterAgent: React.FC = () => {
|
|
| 182 |
}
|
| 183 |
|
| 184 |
// 5. Standard Assistant Message
|
| 185 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
};
|
| 187 |
|
|
|
|
|
|
|
|
|
|
| 188 |
return (
|
| 189 |
<>
|
| 190 |
<style>
|
|
@@ -210,6 +229,10 @@ export const NexusMasterAgent: React.FC = () => {
|
|
| 210 |
0%, 100% { transform: translateY(0); opacity: 0.3; }
|
| 211 |
50% { transform: translateY(-4px); opacity: 1; }
|
| 212 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
`}
|
| 214 |
</style>
|
| 215 |
|
|
@@ -339,12 +362,12 @@ export const NexusMasterAgent: React.FC = () => {
|
|
| 339 |
animation: 'nexus-slide-up 0.5s cubic-bezier(0.16, 1, 0.3, 1)',
|
| 340 |
position: 'relative'
|
| 341 |
}}>
|
| 342 |
-
{renderMessage(m, i)}
|
| 343 |
</div>
|
| 344 |
))}
|
| 345 |
|
| 346 |
-
{/* Thinking / Status Indicator */}
|
| 347 |
-
{loading && (
|
| 348 |
<div style={{
|
| 349 |
alignSelf: 'flex-start',
|
| 350 |
background: "var(--bg2)",
|
|
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
|
| 59 |
+
const renderMessage = (m: any, index: number, isStreaming = false) => {
|
| 60 |
const isLatest = index === messages.length - 1;
|
| 61 |
|
| 62 |
// 1. User Message (Standard)
|
|
|
|
| 182 |
}
|
| 183 |
|
| 184 |
// 5. Standard Assistant Message
|
| 185 |
+
return (
|
| 186 |
+
<>
|
| 187 |
+
<NexusMarkdown content={m.content} isMe={false} />
|
| 188 |
+
{isStreaming && (
|
| 189 |
+
<span style={{
|
| 190 |
+
display: 'inline-block',
|
| 191 |
+
width: 2,
|
| 192 |
+
height: '1em',
|
| 193 |
+
background: 'var(--primary)',
|
| 194 |
+
marginLeft: 2,
|
| 195 |
+
verticalAlign: 'text-bottom',
|
| 196 |
+
animation: 'nexus-cursor 1s steps(1) infinite',
|
| 197 |
+
borderRadius: 1,
|
| 198 |
+
}} />
|
| 199 |
+
)}
|
| 200 |
+
</>
|
| 201 |
+
);
|
| 202 |
};
|
| 203 |
|
| 204 |
+
const lastMsg = messages[messages.length - 1];
|
| 205 |
+
const isActivelyStreaming = loading && lastMsg?.role === 'assistant' && !!lastMsg?.content;
|
| 206 |
+
|
| 207 |
return (
|
| 208 |
<>
|
| 209 |
<style>
|
|
|
|
| 229 |
0%, 100% { transform: translateY(0); opacity: 0.3; }
|
| 230 |
50% { transform: translateY(-4px); opacity: 1; }
|
| 231 |
}
|
| 232 |
+
@keyframes nexus-cursor {
|
| 233 |
+
0%, 100% { opacity: 1; }
|
| 234 |
+
50% { opacity: 0; }
|
| 235 |
+
}
|
| 236 |
`}
|
| 237 |
</style>
|
| 238 |
|
|
|
|
| 362 |
animation: 'nexus-slide-up 0.5s cubic-bezier(0.16, 1, 0.3, 1)',
|
| 363 |
position: 'relative'
|
| 364 |
}}>
|
| 365 |
+
{renderMessage(m, i, isActivelyStreaming && i === messages.length - 1)}
|
| 366 |
</div>
|
| 367 |
))}
|
| 368 |
|
| 369 |
+
{/* Thinking / Status Indicator — hidden once tokens start flowing */}
|
| 370 |
+
{loading && !isActivelyStreaming && (
|
| 371 |
<div style={{
|
| 372 |
alignSelf: 'flex-start',
|
| 373 |
background: "var(--bg2)",
|
frontend/apps/internal/src/components/NexusMasterAgent.tsx
CHANGED
|
@@ -56,6 +56,9 @@ export const NexusMasterAgent: React.FC<{ workspaceId?: string; workspaceName?:
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
|
|
|
|
|
|
|
|
|
|
| 59 |
return (
|
| 60 |
<>
|
| 61 |
<style>
|
|
@@ -72,6 +75,10 @@ export const NexusMasterAgent: React.FC<{ workspaceId?: string; workspaceName?:
|
|
| 72 |
0%, 100% { transform: translateY(0); opacity: 0.3; }
|
| 73 |
50% { transform: translateY(-4px); opacity: 1; }
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
`}
|
| 76 |
</style>
|
| 77 |
|
|
@@ -250,6 +257,7 @@ export const NexusMasterAgent: React.FC<{ workspaceId?: string; workspaceName?:
|
|
| 250 |
} catch (e) {}
|
| 251 |
}
|
| 252 |
|
|
|
|
| 253 |
return (
|
| 254 |
<div key={i} style={{
|
| 255 |
alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
|
|
@@ -267,6 +275,18 @@ export const NexusMasterAgent: React.FC<{ workspaceId?: string; workspaceName?:
|
|
| 267 |
animation: 'nexus-slide-up 0.4s ease-out'
|
| 268 |
}}>
|
| 269 |
{textPart && <NexusMarkdown content={textPart} isMe={m.role === 'user'} />}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
{hasAction && actionData && pendingAction && (i === messages.length - 1) && (
|
| 272 |
<div style={{
|
|
@@ -335,8 +355,8 @@ export const NexusMasterAgent: React.FC<{ workspaceId?: string; workspaceName?:
|
|
| 335 |
);
|
| 336 |
})}
|
| 337 |
|
| 338 |
-
{/* Thinking / Status Indicator */}
|
| 339 |
-
{loading && (
|
| 340 |
<div style={{
|
| 341 |
alignSelf: 'flex-start',
|
| 342 |
background: 'var(--bg2)',
|
|
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
|
| 59 |
+
const lastMsg = messages[messages.length - 1];
|
| 60 |
+
const isActivelyStreaming = loading && lastMsg?.role === 'assistant' && !!lastMsg?.content;
|
| 61 |
+
|
| 62 |
return (
|
| 63 |
<>
|
| 64 |
<style>
|
|
|
|
| 75 |
0%, 100% { transform: translateY(0); opacity: 0.3; }
|
| 76 |
50% { transform: translateY(-4px); opacity: 1; }
|
| 77 |
}
|
| 78 |
+
@keyframes nexus-cursor {
|
| 79 |
+
0%, 100% { opacity: 1; }
|
| 80 |
+
50% { opacity: 0; }
|
| 81 |
+
}
|
| 82 |
`}
|
| 83 |
</style>
|
| 84 |
|
|
|
|
| 257 |
} catch (e) {}
|
| 258 |
}
|
| 259 |
|
| 260 |
+
const isStreamingThisMsg = isActivelyStreaming && i === messages.length - 1;
|
| 261 |
return (
|
| 262 |
<div key={i} style={{
|
| 263 |
alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
|
|
|
|
| 275 |
animation: 'nexus-slide-up 0.4s ease-out'
|
| 276 |
}}>
|
| 277 |
{textPart && <NexusMarkdown content={textPart} isMe={m.role === 'user'} />}
|
| 278 |
+
{isStreamingThisMsg && (
|
| 279 |
+
<span style={{
|
| 280 |
+
display: 'inline-block',
|
| 281 |
+
width: 2,
|
| 282 |
+
height: '1em',
|
| 283 |
+
background: 'var(--accent)',
|
| 284 |
+
marginLeft: 2,
|
| 285 |
+
verticalAlign: 'text-bottom',
|
| 286 |
+
animation: 'nexus-cursor 1s steps(1) infinite',
|
| 287 |
+
borderRadius: 1,
|
| 288 |
+
}} />
|
| 289 |
+
)}
|
| 290 |
|
| 291 |
{hasAction && actionData && pendingAction && (i === messages.length - 1) && (
|
| 292 |
<div style={{
|
|
|
|
| 355 |
);
|
| 356 |
})}
|
| 357 |
|
| 358 |
+
{/* Thinking / Status Indicator — hidden once tokens start flowing */}
|
| 359 |
+
{loading && !isActivelyStreaming && (
|
| 360 |
<div style={{
|
| 361 |
alignSelf: 'flex-start',
|
| 362 |
background: 'var(--bg2)',
|
frontend/packages/shared/src/components/NexusMarkdown.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import React, { useContext } from 'react';
|
| 2 |
import ReactMarkdown from 'react-markdown';
|
| 3 |
import remarkGfm from 'remark-gfm';
|
| 4 |
import remarkBreaks from 'remark-breaks';
|
|
@@ -15,14 +15,15 @@ interface NexusMarkdownProps {
|
|
| 15 |
isMe?: boolean;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
const { theme } = useTheme();
|
| 20 |
const { token } = useContext(AuthContext) || { token: null };
|
| 21 |
if (!content) return null;
|
| 22 |
|
| 23 |
// Pre-processing: Flatten technical identifiers that the AI mistakenly wraps in triple-backticks
|
| 24 |
// We use [\s\n]* to consume ALL surrounding whitespace, forcing these back into the paragraph flow.
|
| 25 |
-
|
|
|
|
| 26 |
.replace(
|
| 27 |
/(^|\s)(?<!\(|\[)(https?:\/\/\S+\.(?:png|jpg|jpeg|gif|webp|svg)(?:\?\S*)?)(?!\)|\])(\s|$)/gi,
|
| 28 |
'$1$3'
|
|
@@ -68,7 +69,7 @@ export const NexusMarkdown: React.FC<NexusMarkdownProps> = ({ content, isMe }) =
|
|
| 68 |
return ` \`${lines[0].trim()}\` `;
|
| 69 |
}
|
| 70 |
return match;
|
| 71 |
-
});
|
| 72 |
|
| 73 |
return (
|
| 74 |
<div className="nexus-markdown-content" style={{
|
|
@@ -308,3 +309,5 @@ export const NexusMarkdown: React.FC<NexusMarkdownProps> = ({ content, isMe }) =
|
|
| 308 |
</div>
|
| 309 |
);
|
| 310 |
};
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useContext, useMemo } from 'react';
|
| 2 |
import ReactMarkdown from 'react-markdown';
|
| 3 |
import remarkGfm from 'remark-gfm';
|
| 4 |
import remarkBreaks from 'remark-breaks';
|
|
|
|
| 15 |
isMe?: boolean;
|
| 16 |
}
|
| 17 |
|
| 18 |
+
const NexusMarkdownInner: React.FC<NexusMarkdownProps> = ({ content, isMe }) => {
|
| 19 |
const { theme } = useTheme();
|
| 20 |
const { token } = useContext(AuthContext) || { token: null };
|
| 21 |
if (!content) return null;
|
| 22 |
|
| 23 |
// Pre-processing: Flatten technical identifiers that the AI mistakenly wraps in triple-backticks
|
| 24 |
// We use [\s\n]* to consume ALL surrounding whitespace, forcing these back into the paragraph flow.
|
| 25 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 26 |
+
const processedContent = useMemo(() => content
|
| 27 |
.replace(
|
| 28 |
/(^|\s)(?<!\(|\[)(https?:\/\/\S+\.(?:png|jpg|jpeg|gif|webp|svg)(?:\?\S*)?)(?!\)|\])(\s|$)/gi,
|
| 29 |
'$1$3'
|
|
|
|
| 69 |
return ` \`${lines[0].trim()}\` `;
|
| 70 |
}
|
| 71 |
return match;
|
| 72 |
+
}), [content]);
|
| 73 |
|
| 74 |
return (
|
| 75 |
<div className="nexus-markdown-content" style={{
|
|
|
|
| 309 |
</div>
|
| 310 |
);
|
| 311 |
};
|
| 312 |
+
|
| 313 |
+
export const NexusMarkdown = React.memo(NexusMarkdownInner);
|
tasks/nexus_ai.py
CHANGED
|
@@ -256,7 +256,7 @@ async def nexus_stream_task(
|
|
| 256 |
accumulated_tokens.append(chunk)
|
| 257 |
yield_buffer.append(chunk)
|
| 258 |
buffer_text = "".join(yield_buffer)
|
| 259 |
-
if "\n" in chunk or len(buffer_text) >=
|
| 260 |
await publish({"type": "token", "content": buffer_text})
|
| 261 |
yield_buffer = []
|
| 262 |
|
|
|
|
| 256 |
accumulated_tokens.append(chunk)
|
| 257 |
yield_buffer.append(chunk)
|
| 258 |
buffer_text = "".join(yield_buffer)
|
| 259 |
+
if "\n" in chunk or len(buffer_text) >= 5:
|
| 260 |
await publish({"type": "token", "content": buffer_text})
|
| 261 |
yield_buffer = []
|
| 262 |
|