mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Remove projectName variable, memoize onUpdateMetadata
This commit is contained in:
5 files changed
+25
-33
No files matched your search
@@ -32,7 +32,7 @@ export function SessionMonitor() {
|
||||
if (!isCurrentProject) {
|
||||
toast({
|
||||
title: "AI Session Complete",
|
||||
description: `Finished working on ${session.projectName}`,
|
||||
description: `Finished working on ${session.projectId}`,
|
||||
action: (
|
||||
<button
|
||||
onClick={() => navigate(`/project/${session.projectId}`)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useRef, useEffect, forwardRef, useImperativeHandle, useMemo } from 'react';
|
||||
import { useState, useRef, useEffect, forwardRef, useImperativeHandle, useMemo, useCallback } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
@@ -40,7 +40,6 @@ import { assistantContentEmpty } from '@/lib/ai-messages';
|
||||
|
||||
interface ChatPaneProps {
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
onNewChat?: () => void;
|
||||
onBuild?: () => void;
|
||||
onDeploy?: () => void;
|
||||
@@ -57,7 +56,6 @@ export interface ChatPaneRef {
|
||||
|
||||
export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
projectId,
|
||||
projectName,
|
||||
onNewChat: _onNewChat,
|
||||
onBuild: _onBuild,
|
||||
onDeploy: _onDeploy,
|
||||
@@ -128,6 +126,25 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
return result;
|
||||
}, [customTools]);
|
||||
|
||||
// Keep-alive functionality to prevent tab throttling during AI processing
|
||||
const { updateMetadata } = useKeepAlive({
|
||||
enabled: externalIsLoading || isBuildLoading || isDeployLoading,
|
||||
title: 'Shakespeare',
|
||||
artist: `Working on ${projectId}...`,
|
||||
artwork: [
|
||||
{
|
||||
src: '/favicon.png',
|
||||
sizes: '512x512',
|
||||
type: 'image/png'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Memoize the metadata update callback to avoid unnecessary re-renders
|
||||
const onUpdateMetadata = useCallback((title: string, description: string) => {
|
||||
updateMetadata(title, description);
|
||||
}, [updateMetadata]);
|
||||
|
||||
useEffect(() => {
|
||||
makeSystemPrompt({
|
||||
cwd,
|
||||
@@ -151,13 +168,10 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
startNewSession: internalStartNewSession,
|
||||
} = useAIChat({
|
||||
projectId,
|
||||
projectName,
|
||||
tools,
|
||||
customTools,
|
||||
systemPrompt,
|
||||
onUpdateMetadata: (title, description) => {
|
||||
updateMetadata(title, description);
|
||||
}
|
||||
onUpdateMetadata,
|
||||
});
|
||||
|
||||
// Use external loading state if provided, otherwise use internal state
|
||||
@@ -214,20 +228,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
}, [searchParams, setSearchParams, isConfigured, messages, isLoading, startGeneration, providerModel, setProviderModel, addRecentlyUsedModel]);
|
||||
|
||||
// Keep-alive functionality to prevent tab throttling during AI processing
|
||||
const { updateMetadata } = useKeepAlive({
|
||||
enabled: isLoading || isBuildLoading || isDeployLoading,
|
||||
title: 'Shakespeare',
|
||||
artist: `Working on ${projectName}...`,
|
||||
artwork: [
|
||||
{
|
||||
src: '/favicon.png',
|
||||
sizes: '512x512',
|
||||
type: 'image/png'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// Function to check if user is at the bottom of the scroll area
|
||||
const checkScrollPosition = () => {
|
||||
if (!scrollAreaRef.current) return;
|
||||
|
||||
@@ -8,7 +8,6 @@ import type { Tool } from '@/lib/tools/Tool';
|
||||
|
||||
interface UseAIChatSessionOptions {
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
tools?: Record<string, OpenAI.Chat.Completions.ChatCompletionTool>;
|
||||
customTools?: Record<string, Tool<unknown>>;
|
||||
systemPrompt?: string;
|
||||
@@ -28,7 +27,6 @@ interface StreamingMessage {
|
||||
*/
|
||||
export function useAIChat({
|
||||
projectId,
|
||||
projectName,
|
||||
tools = {},
|
||||
customTools = {},
|
||||
systemPrompt,
|
||||
@@ -75,7 +73,6 @@ export function useAIChat({
|
||||
const config: SessionConfig = {
|
||||
id: generatedSessionId,
|
||||
projectId,
|
||||
projectName,
|
||||
tools,
|
||||
customTools,
|
||||
systemPrompt,
|
||||
@@ -98,7 +95,7 @@ export function useAIChat({
|
||||
};
|
||||
|
||||
initSession();
|
||||
}, [sessionManager, projectId, projectName, tools, customTools, systemPrompt, maxSteps, generatedSessionId]);
|
||||
}, [sessionManager, projectId, tools, customTools, systemPrompt, maxSteps, generatedSessionId]);
|
||||
|
||||
// Subscribe to atomic session events for efficient updates
|
||||
useSessionSubscription('messageAdded', (updatedSessionId: string, message: AIMessage) => {
|
||||
@@ -127,10 +124,10 @@ export function useAIChat({
|
||||
}
|
||||
|
||||
if (onUpdateMetadata && loading) {
|
||||
onUpdateMetadata('Shakespeare', `Working on ${projectName}...`);
|
||||
onUpdateMetadata('Shakespeare', `Working on ${projectId}...`);
|
||||
}
|
||||
}
|
||||
}, [sessionId, onUpdateMetadata, projectName]);
|
||||
}, [sessionId, onUpdateMetadata, projectId]);
|
||||
|
||||
useSessionSubscription('costUpdated', (updatedSessionId: string, cost: number) => {
|
||||
if (updatedSessionId === sessionId) {
|
||||
|
||||
@@ -9,7 +9,6 @@ export type AIMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
||||
export interface SessionConfig {
|
||||
id: string;
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
tools: Record<string, OpenAI.Chat.Completions.ChatCompletionTool>;
|
||||
customTools: Record<string, Tool<unknown>>;
|
||||
systemPrompt?: string;
|
||||
@@ -19,7 +18,6 @@ export interface SessionConfig {
|
||||
export interface SessionState {
|
||||
id: string;
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
messages: AIMessage[];
|
||||
streamingMessage?: {
|
||||
role: 'assistant';
|
||||
@@ -77,7 +75,6 @@ export class SessionManager {
|
||||
const sessionState: SessionState = {
|
||||
id: config.id,
|
||||
projectId: config.projectId,
|
||||
projectName: config.projectName,
|
||||
messages: [],
|
||||
isLoading: false,
|
||||
sessionName: DotAI.generateSessionName(),
|
||||
|
||||
@@ -289,7 +289,6 @@ export function ProjectView() {
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
@@ -435,7 +434,6 @@ export function ProjectView() {
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
|
||||
Reference in new issue
Block a user