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

Function upsertStructuredOutputPart

packages/ai-devtools/src/store/ai-context.tsx:954–1022  ·  view source on GitHub ↗
(
    conversationId: string,
    input: {
      messageId: string
      timestamp: number
      source: 'client' | 'server'
      requestId?: string
      status: 'streaming' | 'complete' | 'error'
      raw: string
      partial?: unknown
      data?: unknown
      reasoning?: string
      errorMessage?: string
    },
  )

Source from the content-addressed store, hash-verified

952 }
953
954 function upsertStructuredOutputPart(
955 conversationId: string,
956 input: {
957 messageId: string
958 timestamp: number
959 source: 'client' | 'server'
960 requestId?: string
961 status: 'streaming' | 'complete' | 'error'
962 raw: string
963 partial?: unknown
964 data?: unknown
965 reasoning?: string
966 errorMessage?: string
967 },
968 ): number | undefined {
969 const conv = state.conversations[conversationId]
970 if (!conv) return undefined
971
972 const part: MessagePart = {
973 type: 'structured-output',
974 status: input.status,
975 raw: input.raw,
976 ...(input.partial !== undefined ? { partial: input.partial } : {}),
977 ...(input.data !== undefined ? { data: input.data } : {}),
978 ...(input.reasoning !== undefined ? { reasoning: input.reasoning } : {}),
979 ...(input.errorMessage !== undefined
980 ? { errorMessage: input.errorMessage }
981 : {}),
982 }
983
984 let messageIndex = conv.messages.findIndex(
985 (message) => message.id === input.messageId,
986 )
987
988 if (messageIndex === -1) {
989 messageIndex = conv.messages.length
990 addMessage(conversationId, {
991 id: input.messageId,
992 role: 'assistant',
993 content: '',
994 timestamp: input.timestamp,
995 parts: [part],
996 source: input.source,
997 ...(input.requestId ? { requestId: input.requestId } : {}),
998 })
999 } else {
1000 setState(
1001 'conversations',
1002 conversationId,
1003 'messages',
1004 messageIndex,
1005 'parts',
1006 produce((parts: Array<MessagePart> | undefined) => {
1007 const next = parts ? [...parts] : []
1008 const existingIndex = next.findIndex(
1009 (candidate) => candidate.type === 'structured-output',
1010 )
1011 if (existingIndex >= 0) {

Callers 1

recordStructuredOutputFunction · 0.85

Calls 2

addMessageFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected