11import { objectPick } from '@namesmt/utils'
22import { ConvexError , v } from 'convex/values'
33import { messagesInThreadCounter } from './_counters'
4- import { internalMutation , internalQuery , mutation , query } from './_generated/server'
4+ import { internalMutation , internalQuery , query } from './_generated/server'
55import { assertThreadAccess } from './threads'
66
77export const listByThread = query ( {
@@ -61,11 +61,15 @@ export const get = query({
6161 } ,
6262} )
6363
64- export const add = mutation ( {
64+ export const add = internalMutation ( {
6565 args : {
6666 threadId : v . id ( 'threads' ) ,
6767 role : v . union ( v . literal ( 'user' ) , v . literal ( 'assistant' ) ) ,
6868 content : v . string ( ) ,
69+ context : v . optional ( v . object ( {
70+ from : v . optional ( v . string ( ) ) ,
71+ uid : v . optional ( v . string ( ) ) ,
72+ } ) ) ,
6973 isStreaming : v . optional ( v . boolean ( ) ) ,
7074 streamId : v . optional ( v . string ( ) ) ,
7175 provider : v . string ( ) ,
@@ -82,13 +86,13 @@ export const add = mutation({
8286 await messagesInThreadCounter . inc ( ctx , args . threadId )
8387
8488 return await ctx . db . insert ( 'messages' , {
85- ...objectPick ( args , [ 'threadId' , 'role' , 'content' , 'isStreaming' , 'streamId' , 'provider' , 'model' ] ) ,
89+ ...objectPick ( args , [ 'threadId' , 'role' , 'content' , 'context' , ' isStreaming', 'streamId' , 'provider' , 'model' ] ) ,
8690 timestamp : Date . now ( ) ,
8791 } )
8892 } ,
8993} )
9094
91- export const updateStreamingMessage = mutation ( {
95+ export const updateStreamingMessage = internalMutation ( {
9296 args : {
9397 messageId : v . id ( 'messages' ) ,
9498 content : v . string ( ) ,
@@ -147,6 +151,7 @@ export const finishStreaming = internalMutation({
147151 return
148152
149153 await ctx . db . patch ( message . _id , {
154+ streamId : undefined ,
150155 isStreaming : false ,
151156 } )
152157 } ,
0 commit comments