mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Skip somethings for chats idk
This commit is contained in:
3 files changed
+44
-22
No files matched your search
@@ -274,6 +274,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onUpdateMetadata,
|
||||
onAIError,
|
||||
workingDir: isChat ? cwd : undefined, // Pass working dir for chats
|
||||
isChat, // Pass isChat flag
|
||||
});
|
||||
|
||||
// Check if we should show the template info banner
|
||||
|
||||
@@ -14,6 +14,7 @@ interface UseAIChatSessionOptions {
|
||||
onUpdateMetadata?: (title: string, description: string) => void;
|
||||
onAIError?: (error: Error) => void;
|
||||
workingDir?: string; // Optional working directory (for chats)
|
||||
isChat?: boolean; // Whether this is a chat session (vs a project session)
|
||||
}
|
||||
|
||||
interface StreamingMessage {
|
||||
@@ -34,7 +35,8 @@ export function useAIChat({
|
||||
maxSteps = 50,
|
||||
onUpdateMetadata,
|
||||
onAIError,
|
||||
workingDir
|
||||
workingDir,
|
||||
isChat
|
||||
}: UseAIChatSessionOptions) {
|
||||
const sessionManager = useSessionManager();
|
||||
const { isConfigured } = useAISettings();
|
||||
@@ -48,14 +50,14 @@ export function useAIChat({
|
||||
|
||||
const initSession = useCallback(async () => {
|
||||
// Load or update session
|
||||
const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps, workingDir);
|
||||
const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps, workingDir, isChat);
|
||||
// Initialize individual state variables from existing session
|
||||
setMessages([...session.messages]);
|
||||
setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined);
|
||||
setIsLoading(session.isLoading);
|
||||
setTotalCost(session.totalCost || 0);
|
||||
setLastInputTokens(session.lastInputTokens || 0);
|
||||
}, [sessionManager, projectId, tools, customTools, maxSteps, workingDir]);
|
||||
}, [sessionManager, projectId, tools, customTools, maxSteps, workingDir, isChat]);
|
||||
|
||||
// Initialize session
|
||||
useEffect(() => {
|
||||
|
||||
+38
-19
@@ -42,6 +42,7 @@ export interface SessionState {
|
||||
lastInputTokens?: number; // Input tokens from the last AI request
|
||||
imagesNotSupported?: boolean; // Track if this session's model doesn't support images
|
||||
workingDir?: string; // Working directory (for chats, different from projects)
|
||||
isChat?: boolean; // Whether this is a chat session (vs a project session)
|
||||
}
|
||||
|
||||
export interface SessionManagerEvents {
|
||||
@@ -101,7 +102,8 @@ export class SessionManager {
|
||||
tools: Record<string, OpenAI.Chat.Completions.ChatCompletionTool>,
|
||||
customTools: Record<string, Tool<unknown>>,
|
||||
maxSteps?: number,
|
||||
workingDir?: string // Optional working directory (for chats, use chatsPath instead of projectsPath)
|
||||
workingDir?: string, // Optional working directory (for chats, use chatsPath instead of projectsPath)
|
||||
isChat?: boolean // Whether this is a chat session (vs a project session)
|
||||
): Promise<SessionState> {
|
||||
let messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [];
|
||||
let sessionName = DotAI.generateSessionName();
|
||||
@@ -112,7 +114,7 @@ export class SessionManager {
|
||||
const dir = workingDir || `${config.fsPathProjects}/${projectId}`;
|
||||
|
||||
// For chats, load messages from messages.jsonl directly
|
||||
if (workingDir && workingDir.includes(config.fsPathChats)) {
|
||||
if (isChat) {
|
||||
const messagesPath = `${dir}/messages.jsonl`;
|
||||
try {
|
||||
const content = await this.fs.readFile(messagesPath, 'utf8');
|
||||
@@ -157,14 +159,16 @@ export class SessionManager {
|
||||
messages,
|
||||
sessionName,
|
||||
workingDir,
|
||||
isChat,
|
||||
};
|
||||
|
||||
// Update session configuration
|
||||
session.projectId = projectId;
|
||||
session.tools = tools;
|
||||
|
||||
session.customTools = customTools;
|
||||
session.maxSteps = maxSteps;
|
||||
session.workingDir = workingDir;
|
||||
session.isChat = isChat;
|
||||
|
||||
this.sessions.set(projectId, session);
|
||||
|
||||
@@ -285,27 +289,33 @@ export class SessionManager {
|
||||
tool_calls: undefined
|
||||
};
|
||||
|
||||
// Get repository URL if available
|
||||
const workingDir = session.workingDir || `${config.fsPathProjects}/${projectId}`;
|
||||
|
||||
// Get repository URL if available (skip for chats)
|
||||
let repositoryUrl: string | undefined;
|
||||
try {
|
||||
const remoteUrl = await this.git.getRemoteURL(`${config.fsPathProjects}/${projectId}`, 'origin');
|
||||
repositoryUrl = remoteUrl || undefined;
|
||||
} catch {
|
||||
// No repository URL available
|
||||
if (!session.isChat) {
|
||||
try {
|
||||
const remoteUrl = await this.git.getRemoteURL(workingDir, 'origin');
|
||||
repositoryUrl = remoteUrl || undefined;
|
||||
} catch {
|
||||
// No repository URL available
|
||||
}
|
||||
}
|
||||
|
||||
// Get project template metadata if available
|
||||
// Get project template metadata if available (skip for chats)
|
||||
let projectTemplate: { name: string; description: string; url: string } | undefined;
|
||||
try {
|
||||
const dotai = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
||||
const template = await dotai.readTemplate();
|
||||
projectTemplate = template || undefined;
|
||||
} catch {
|
||||
// Template metadata not available
|
||||
if (!session.isChat) {
|
||||
try {
|
||||
const dotai = new DotAI(this.fs, workingDir);
|
||||
const template = await dotai.readTemplate();
|
||||
projectTemplate = template || undefined;
|
||||
} catch {
|
||||
// Template metadata not available
|
||||
}
|
||||
}
|
||||
|
||||
const systemPrompt = await makeSystemPrompt({
|
||||
cwd: `${config.fsPathProjects}/${projectId}`,
|
||||
cwd: workingDir,
|
||||
fs: this.fs,
|
||||
mode: "agent",
|
||||
tools: Object.values(session.tools),
|
||||
@@ -762,7 +772,7 @@ export class SessionManager {
|
||||
const config = this.getConfig();
|
||||
|
||||
// For chats, save directly to messages.jsonl
|
||||
if (session.workingDir && session.workingDir.includes(config.fsPathChats)) {
|
||||
if (session.isChat) {
|
||||
const messagesPath = `${session.workingDir}/messages.jsonl`;
|
||||
|
||||
// Convert messages to JSONL format
|
||||
@@ -786,9 +796,18 @@ export class SessionManager {
|
||||
* Accumulate request cost to the project's total cost file
|
||||
*/
|
||||
private async accumulateProjectCost(projectId: string, requestCost: number): Promise<void> {
|
||||
const session = this.sessions.get(projectId);
|
||||
if (!session) return;
|
||||
|
||||
try {
|
||||
const config = this.getConfig();
|
||||
const dotAI = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
||||
|
||||
// Skip cost accumulation for chats (they don't have .git/shakespeare/COST files)
|
||||
if (session.isChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dotAI = new DotAI(this.fs, session.workingDir || `${config.fsPathProjects}/${projectId}`);
|
||||
|
||||
// Read current project total
|
||||
const currentTotal = await dotAI.readCost();
|
||||
|
||||
Reference in new issue
Block a user