@@ -36,50 +36,51 @@ export default function App() {
3636 ai : aiEn , // add default translations for the AI extension
3737 } ,
3838 // Register the AI extension
39- extensions : [ AIExtension ( ) ] ,
40- ai : {
41- // similar to https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence#sending-only-the-last-message
42- // we adjust the transport to not send all messages to the backend
43- transport : new DefaultChatTransport ( {
44- // (see packages/xl-ai-server/src/routes/vercelAiSdkPersistence.ts)
45- api : `${ BASE_URL } /server-promptbuilder/streamText` ,
46- prepareSendMessagesRequest ( { id, body, messages, requestMetadata } ) {
47- // we don't send the messages, just the information we need to compose / append messages server-side:
48- // - the conversation id
49- // - the promptData
50- // - the tool results of the last message
39+ extensions : [
40+ AIExtension ( {
41+ // similar to https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence#sending-only-the-last-message
42+ // we adjust the transport to not send all messages to the backend
43+ transport : new DefaultChatTransport ( {
44+ // (see packages/xl-ai-server/src/routes/vercelAiSdkPersistence.ts)
45+ api : `${ BASE_URL } /server-promptbuilder/streamText` ,
46+ prepareSendMessagesRequest ( { id, body, messages, requestMetadata } ) {
47+ // we don't send the messages, just the information we need to compose / append messages server-side:
48+ // - the conversation id
49+ // - the promptData
50+ // - the tool results of the last message
5151
52- // we need to share data about tool calls with the backend,
53- // as these can be client-side executed. The backend needs to know the tool outputs
54- // in order to compose a new valid LLM request
55- const lastToolParts =
56- messages . length > 0
57- ? messages [ messages . length - 1 ] . parts . filter ( ( part ) =>
58- isToolOrDynamicToolUIPart ( part ) ,
59- )
60- : [ ] ;
52+ // we need to share data about tool calls with the backend,
53+ // as these can be client-side executed. The backend needs to know the tool outputs
54+ // in order to compose a new valid LLM request
55+ const lastToolParts =
56+ messages . length > 0
57+ ? messages [ messages . length - 1 ] . parts . filter ( ( part ) =>
58+ isToolOrDynamicToolUIPart ( part ) ,
59+ )
60+ : [ ] ;
6161
62- return {
63- body : {
64- ...body ,
65- // TODO: this conversation id is client-side generated, we
66- // should have a server-side generated id to ensure uniqueness
67- // see https://github.com/vercel/ai/issues/7340#issuecomment-3307559636
68- id,
69- // get the promptData from requestMetadata (set by `promptAIRequestSender`) and send to backend
70- promptData : ( requestMetadata as any ) . promptData ,
71- lastToolParts,
72- // messages, -> we explicitly don't send the messages array as we compose messages server-side
73- } ,
74- } ;
75- } ,
62+ return {
63+ body : {
64+ ...body ,
65+ // TODO: this conversation id is client-side generated, we
66+ // should have a server-side generated id to ensure uniqueness
67+ // see https://github.com/vercel/ai/issues/7340#issuecomment-3307559636
68+ id,
69+ // get the promptData from requestMetadata (set by `promptAIRequestSender`) and send to backend
70+ promptData : ( requestMetadata as any ) . promptData ,
71+ lastToolParts,
72+ // messages, -> we explicitly don't send the messages array as we compose messages server-side
73+ } ,
74+ } ;
75+ } ,
76+ } ) ,
77+ // customize the aiRequestSender to not update the messages array on the client-side
78+ aiRequestSender : defaultAIRequestSender (
79+ async ( ) => { } , // disable the client-side promptbuilder
80+ aiDocumentFormats . html . defaultPromptInputDataBuilder ,
81+ ) ,
7682 } ) ,
77- // customize the aiRequestSender to not update the messages array on the client-side
78- aiRequestSender : defaultAIRequestSender (
79- async ( ) => { } , // disable the client-side promptbuilder
80- aiDocumentFormats . html . defaultPromptInputDataBuilder ,
81- ) ,
82- } ,
83+ ] ,
8384 // We set some initial content for demo purposes
8485 initialContent : [
8586 {
0 commit comments