MCPcopy Create free account
hub / github.com/TanStack/ai / attachMessageToLatestIteration

Function attachMessageToLatestIteration

packages/ai-devtools/src/store/ai-context.tsx:1024–1058  ·  view source on GitHub ↗
(
    conversationId: string,
    messageId: string,
    requestId: string | undefined,
  )

Source from the content-addressed store, hash-verified

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,

Callers 1

recordStructuredOutputFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected