(
conversationId: string,
messageId: string,
requestId: string | undefined,
)
| 1022 | } |
| 1023 | |
| 1024 | function attachMessageToLatestIteration( |
| 1025 | conversationId: string, |
| 1026 | messageId: string, |
| 1027 | requestId: string | undefined, |
| 1028 | ): void { |
| 1029 | const conv = state.conversations[conversationId] |
| 1030 | if (!conv || conv.iterations.length === 0) return |
| 1031 | |
| 1032 | let iterIndex = -1 |
| 1033 | if (requestId) { |
| 1034 | for (let i = conv.iterations.length - 1; i >= 0; i--) { |
| 1035 | if (conv.iterations[i]?.requestId === requestId) { |
| 1036 | iterIndex = i |
| 1037 | break |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | if (iterIndex === -1) { |
| 1042 | iterIndex = conv.iterations.length - 1 |
| 1043 | } |
| 1044 | |
| 1045 | const iteration = conv.iterations[iterIndex] |
| 1046 | if (!iteration || iteration.messageIds.includes(messageId)) return |
| 1047 | |
| 1048 | setState( |
| 1049 | 'conversations', |
| 1050 | conversationId, |
| 1051 | 'iterations', |
| 1052 | iterIndex, |
| 1053 | 'messageIds', |
| 1054 | produce((arr: Array<string>) => { |
| 1055 | arr.push(messageId) |
| 1056 | }), |
| 1057 | ) |
| 1058 | } |
| 1059 | |
| 1060 | function setToolCalls( |
| 1061 | conversationId: string, |
no test coverage detected