u
This commit is contained in:
@@ -17,6 +17,7 @@ import { createApiSuggestionsOrIssuesTool } from '../tools/apisuggestionsorissue
|
||||
import { createFindFilesTool } from '../tools/find-files.js';
|
||||
import { createReadFileTool } from '../tools/read-file.js';
|
||||
import { createPatchTool } from '../tools/patch.js';
|
||||
import { setCachedDraft, parseDraftPath } from '../services/draftManager.js';
|
||||
import { createRmTool } from '../tools/rm.js';
|
||||
import { createSearchImagesTool } from '../tools/search-images.js';
|
||||
import { createAnalyzeImageTool } from '../tools/analyze-image.js';
|
||||
@@ -501,6 +502,39 @@ export class ConversationManager {
|
||||
});
|
||||
toolMsg = await db.addMessage(googleAuthId, this.conversationId, { message: payload, role: 'tool' });
|
||||
await db.setState(googleAuthId, this.conversationId, 'busy');
|
||||
|
||||
// If this tool response is answering a draft read, cache the draft
|
||||
try {
|
||||
let parsedContent = null;
|
||||
try { parsedContent = JSON.parse(rawContent); } catch {}
|
||||
if (parsedContent && (parsedContent.manifest || parsedContent.lines)) {
|
||||
const messages = await db.listMessages(googleAuthId, this.conversationId);
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
const m = messages[i];
|
||||
if (m.role === 'assistant' || m.role === 'model') {
|
||||
let p = null;
|
||||
try { p = typeof m.message === 'string' ? JSON.parse(m.message) : m.message; } catch {}
|
||||
const tc = p?.tool_calls?.find((c) => c.id === tool_call_id);
|
||||
if (tc) {
|
||||
let tcArgs = {};
|
||||
try { tcArgs = typeof tc.function?.arguments === 'string' ? JSON.parse(tc.function.arguments) : (tc.function?.arguments || {}); } catch {}
|
||||
const draftInfo = parseDraftPath(tcArgs.filename || tcArgs.file || '');
|
||||
if (draftInfo.isDraft) {
|
||||
setCachedDraft({
|
||||
companyId: this.companyId,
|
||||
userId: googleAuthId,
|
||||
name: draftInfo.name,
|
||||
content: parsedContent,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[conversationManager] could not cache draft from tool message:', err.message);
|
||||
}
|
||||
} catch (err) {
|
||||
this.isProcessing = false;
|
||||
throw err;
|
||||
@@ -739,8 +773,8 @@ export class ConversationManager {
|
||||
// can never end up pointed at different companies.
|
||||
createJavascriptExecuteTool({ googleAuthId }),
|
||||
createFindFilesTool({ googleAuthId }),
|
||||
createReadFileTool({ googleAuthId }),
|
||||
createPatchTool({ googleAuthId }),
|
||||
createReadFileTool({ googleAuthId, conversationId: this.conversationId }),
|
||||
createPatchTool({ googleAuthId, conversationId: this.conversationId }),
|
||||
createRmTool({ googleAuthId }),
|
||||
createSearchImagesTool({ googleAuthId }),
|
||||
createAnalyzeImageTool({ googleAuthId, model }),
|
||||
|
||||
Reference in New Issue
Block a user