|
1 | | -import { createReducer, Draft } from "@reduxjs/toolkit"; |
| 1 | +import { createReducer } from "@reduxjs/toolkit"; |
2 | 2 | import { |
3 | 3 | Chat, |
4 | 4 | ChatThread, |
@@ -35,18 +35,11 @@ import { |
35 | 35 | fixBrokenToolMessages, |
36 | 36 | setIsNewChatSuggested, |
37 | 37 | setIsNewChatSuggestionRejected, |
38 | | - upsertToolCall, |
39 | 38 | } from "./actions"; |
40 | 39 | import { formatChatResponse } from "./utils"; |
41 | 40 | import { |
42 | | - ChatMessages, |
43 | 41 | DEFAULT_MAX_NEW_TOKENS, |
44 | | - isAssistantMessage, |
45 | | - isDiffMessage, |
46 | | - isMultiModalToolResult, |
47 | 42 | isToolCallMessage, |
48 | | - isToolMessage, |
49 | | - ToolMessage, |
50 | 43 | validateToolCall, |
51 | 44 | } from "../../../services/refact"; |
52 | 45 |
|
@@ -339,76 +332,76 @@ export const chatReducer = createReducer(initialState, (builder) => { |
339 | 332 | state.thread.messages = [...messages, newMessage]; |
340 | 333 | }); |
341 | 334 |
|
342 | | - builder.addCase(upsertToolCall, (state, action) => { |
343 | | - // if (action.payload.toolCallId !== state.thread.id && !(action.payload.chatId in state.cache)) return state; |
344 | | - if (action.payload.chatId === state.thread.id) { |
345 | | - maybeAppendToolCallResultFromIdeToMessages( |
346 | | - state.thread.messages, |
347 | | - action.payload.toolCallId, |
348 | | - action.payload.accepted, |
349 | | - ); |
350 | | - } else if (action.payload.chatId in state.cache) { |
351 | | - const thread = state.cache[action.payload.chatId]; |
352 | | - maybeAppendToolCallResultFromIdeToMessages( |
353 | | - thread.messages, |
354 | | - action.payload.toolCallId, |
355 | | - action.payload.accepted, |
356 | | - ); |
357 | | - } |
358 | | - }); |
| 335 | + // builder.addCase(upsertToolCall, (state, action) => { |
| 336 | + // // if (action.payload.toolCallId !== state.thread.id && !(action.payload.chatId in state.cache)) return state; |
| 337 | + // if (action.payload.chatId === state.thread.id) { |
| 338 | + // maybeAppendToolCallResultFromIdeToMessages( |
| 339 | + // state.thread.messages, |
| 340 | + // action.payload.toolCallId, |
| 341 | + // action.payload.accepted, |
| 342 | + // ); |
| 343 | + // } else if (action.payload.chatId in state.cache) { |
| 344 | + // const thread = state.cache[action.payload.chatId]; |
| 345 | + // maybeAppendToolCallResultFromIdeToMessages( |
| 346 | + // thread.messages, |
| 347 | + // action.payload.toolCallId, |
| 348 | + // action.payload.accepted, |
| 349 | + // ); |
| 350 | + // } |
| 351 | + // }); |
359 | 352 | }); |
360 | 353 |
|
361 | | -export function maybeAppendToolCallResultFromIdeToMessages( |
362 | | - messages: Draft<ChatMessages>, |
363 | | - toolCallId: string, |
364 | | - accepted: boolean | "indeterminate", |
365 | | -) { |
366 | | - const hasDiff = messages.find( |
367 | | - (d) => isDiffMessage(d) && d.tool_call_id === toolCallId, |
368 | | - ); |
369 | | - if (hasDiff) return; |
370 | | - |
371 | | - const message = messageForToolCall(accepted); |
372 | | - |
373 | | - const hasToolCall = messages.find( |
374 | | - (d) => isToolMessage(d) && d.content.tool_call_id === toolCallId, |
375 | | - ); |
376 | | - |
377 | | - if ( |
378 | | - hasToolCall && |
379 | | - isToolMessage(hasToolCall) && |
380 | | - typeof hasToolCall.content.content === "string" |
381 | | - ) { |
382 | | - hasToolCall.content.content = message; |
383 | | - return; |
384 | | - } else if ( |
385 | | - hasToolCall && |
386 | | - isToolMessage(hasToolCall) && |
387 | | - isMultiModalToolResult(hasToolCall.content) |
388 | | - ) { |
389 | | - hasToolCall.content.content.push({ m_type: "text", m_content: message }); |
390 | | - return; |
391 | | - } |
392 | | - |
393 | | - const assistantMessageIndex = messages.findIndex((message) => { |
394 | | - if (!isAssistantMessage(message)) return false; |
395 | | - return message.tool_calls?.find((toolCall) => toolCall.id === toolCallId); |
396 | | - }); |
397 | | - |
398 | | - if (assistantMessageIndex === -1) return; |
399 | | - const toolMessage: ToolMessage = { |
400 | | - role: "tool", |
401 | | - content: { |
402 | | - content: message, |
403 | | - tool_call_id: toolCallId, |
404 | | - }, |
405 | | - }; |
406 | | - |
407 | | - messages.splice(assistantMessageIndex + 1, 0, toolMessage); |
408 | | -} |
409 | | - |
410 | | -function messageForToolCall(accepted: boolean | "indeterminate") { |
411 | | - if (accepted === false) return "The user rejected the changes."; |
412 | | - if (accepted === true) return "The user accepted the changes."; |
413 | | - return "The user may have made modifications to changes."; |
414 | | -} |
| 354 | +// export function maybeAppendToolCallResultFromIdeToMessages( |
| 355 | +// messages: Draft<ChatMessages>, |
| 356 | +// toolCallId: string, |
| 357 | +// accepted: boolean | "indeterminate", |
| 358 | +// ) { |
| 359 | +// const hasDiff = messages.find( |
| 360 | +// (d) => isDiffMessage(d) && d.tool_call_id === toolCallId, |
| 361 | +// ); |
| 362 | +// if (hasDiff) return; |
| 363 | + |
| 364 | +// const message = messageForToolCall(accepted); |
| 365 | + |
| 366 | +// const hasToolCall = messages.find( |
| 367 | +// (d) => isToolMessage(d) && d.content.tool_call_id === toolCallId, |
| 368 | +// ); |
| 369 | + |
| 370 | +// if ( |
| 371 | +// hasToolCall && |
| 372 | +// isToolMessage(hasToolCall) && |
| 373 | +// typeof hasToolCall.content.content === "string" |
| 374 | +// ) { |
| 375 | +// hasToolCall.content.content = message; |
| 376 | +// return; |
| 377 | +// } else if ( |
| 378 | +// hasToolCall && |
| 379 | +// isToolMessage(hasToolCall) && |
| 380 | +// isMultiModalToolResult(hasToolCall.content) |
| 381 | +// ) { |
| 382 | +// hasToolCall.content.content.push({ m_type: "text", m_content: message }); |
| 383 | +// return; |
| 384 | +// } |
| 385 | + |
| 386 | +// const assistantMessageIndex = messages.findIndex((message) => { |
| 387 | +// if (!isAssistantMessage(message)) return false; |
| 388 | +// return message.tool_calls?.find((toolCall) => toolCall.id === toolCallId); |
| 389 | +// }); |
| 390 | + |
| 391 | +// if (assistantMessageIndex === -1) return; |
| 392 | +// const toolMessage: ToolMessage = { |
| 393 | +// role: "tool", |
| 394 | +// content: { |
| 395 | +// content: message, |
| 396 | +// tool_call_id: toolCallId, |
| 397 | +// }, |
| 398 | +// }; |
| 399 | + |
| 400 | +// messages.splice(assistantMessageIndex + 1, 0, toolMessage); |
| 401 | +// } |
| 402 | + |
| 403 | +// function messageForToolCall(accepted: boolean | "indeterminate") { |
| 404 | +// if (accepted === false) return "The user rejected the changes."; |
| 405 | +// if (accepted === true) return "The user accepted the changes."; |
| 406 | +// return "The user may have made modifications to changes."; |
| 407 | +// } |
0 commit comments