Skip to content

Commit db345da

Browse files
authored
chore (ai): remove exports of internal ui functions (#6517)
## Background After moving React, Svelte, and Vue to the chatstore abstraction, several functions do not need to be exported any longer and other functions can be removed. ## Summary Cleanup ui exports.
1 parent f2333d6 commit db345da

12 files changed

+430
-740
lines changed

‎.changeset/empty-fireants-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': major
3+
---
4+
5+
chore (ai): remove exports of internal ui functions

‎packages/ai/src/ui/append-client-message.test.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎packages/ai/src/ui/append-client-message.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎packages/ai/src/ui/call-chat-api.ts

Lines changed: 0 additions & 254 deletions
This file was deleted.

‎packages/ai/src/ui/chat-store.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ import {
1919
isAssistantMessageWithCompletedToolCalls,
2020
shouldResubmitMessages,
2121
} from './should-resubmit-messages';
22-
import type { CreateUIMessage, UIDataTypes, UIMessage } from './ui-messages';
23-
import { updateToolCallResult } from './update-tool-call-result';
22+
import type {
23+
CreateUIMessage,
24+
ToolInvocationUIPart,
25+
UIDataTypes,
26+
UIMessage,
27+
} from './ui-messages';
2428
import { ChatRequestOptions, UseChatOptions } from './use-chat';
2529

2630
export interface ChatStoreSubscriber {
@@ -608,3 +612,40 @@ export class ChatStore<
608612
}
609613
}
610614
}
615+
616+
/**
617+
* Updates the result of a specific tool invocation in the last message of the given messages array.
618+
*
619+
* @param {object} params - The parameters object.
620+
* @param {UIMessage[]} params.messages - An array of messages, from which the last one is updated.
621+
* @param {string} params.toolCallId - The unique identifier for the tool invocation to update.
622+
* @param {unknown} params.toolResult - The result object to attach to the tool invocation.
623+
* @returns {void} This function does not return anything.
624+
*/
625+
function updateToolCallResult({
626+
messages,
627+
toolCallId,
628+
toolResult: result,
629+
}: {
630+
messages: UIMessage[];
631+
toolCallId: string;
632+
toolResult: unknown;
633+
}) {
634+
const lastMessage = messages[messages.length - 1];
635+
636+
const invocationPart = lastMessage.parts.find(
637+
(part): part is ToolInvocationUIPart =>
638+
part.type === 'tool-invocation' &&
639+
part.toolInvocation.toolCallId === toolCallId,
640+
);
641+
642+
if (invocationPart == null) {
643+
return;
644+
}
645+
646+
invocationPart.toolInvocation = {
647+
...invocationPart.toolInvocation,
648+
state: 'result' as const,
649+
result,
650+
};
651+
}

0 commit comments

Comments
 (0)