@nexo-labs/chat-agent 1.9.9 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexo-labs/chat-agent",
3
- "version": "1.9.9",
3
+ "version": "1.10.0",
4
4
  "description": "Floating chat agent component for React applications with AI integration",
5
5
  "keywords": [
6
6
  "react",
@@ -4,28 +4,30 @@ import type {
4
4
  PublicAgentInfo,
5
5
  SendMessageContext,
6
6
  SessionSummary,
7
+ Source,
7
8
  StreamCallbacks
8
9
  } from './ChatAdapter'
9
10
 
10
- interface SSEEvent {
11
- type: string
12
- data?: unknown
13
- }
11
+ type SSEEvent =
12
+ | { type: 'conversation_id'; data: string }
13
+ | { type: 'token'; data: string }
14
+ | { type: 'sources'; data: Source[] }
15
+ | { type: 'done' }
16
+ | { type: 'usage'; data: { daily_limit: number; daily_used: number; daily_remaining: number; reset_at: string } }
17
+ | { type: 'error'; data?: { error?: string; message?: string; chatId?: string } }
14
18
 
15
19
  function handleSSEEvent(event: SSEEvent, callbacks: StreamCallbacks): void {
16
20
  switch (event.type) {
17
21
  case 'conversation_id':
18
- callbacks.onConversationId?.(event.data as string)
22
+ callbacks.onConversationId?.(event.data)
19
23
  break
20
24
 
21
25
  case 'token':
22
- callbacks.onToken?.(event.data as string)
26
+ callbacks.onToken?.(event.data)
23
27
  break
24
28
 
25
29
  case 'sources':
26
- if (Array.isArray(event.data)) {
27
- callbacks.onSources?.(event.data)
28
- }
30
+ callbacks.onSources?.(event.data)
29
31
  break
30
32
 
31
33
  case 'done':
@@ -33,9 +35,7 @@ function handleSSEEvent(event: SSEEvent, callbacks: StreamCallbacks): void {
33
35
  break
34
36
 
35
37
  case 'usage':
36
- callbacks.onUsage?.(
37
- event.data as { daily_limit: number; daily_used: number; daily_remaining: number; reset_at: string }
38
- )
38
+ callbacks.onUsage?.(event.data)
39
39
  break
40
40
 
41
41
  case 'error':
@@ -44,18 +44,18 @@ function handleSSEEvent(event: SSEEvent, callbacks: StreamCallbacks): void {
44
44
  }
45
45
  }
46
46
 
47
- function handleSSEError(event: SSEEvent): never {
48
- const errorData = event.data as Record<string, unknown> | undefined
47
+ function handleSSEError(event: Extract<SSEEvent, { type: 'error' }>): never {
48
+ const errorData = event.data
49
49
  if (errorData?.error === 'EXPIRED_CONVERSATION') {
50
- const error = new Error((errorData?.message as string) || 'Esta conversación ha expirado') as Error & {
50
+ const error = new Error(errorData?.message || 'Esta conversación ha expirado') as Error & {
51
51
  code: string
52
52
  chatId: string
53
53
  }
54
54
  error.code = 'EXPIRED_CONVERSATION'
55
- error.chatId = errorData?.chatId as string
55
+ error.chatId = errorData?.chatId || ''
56
56
  throw error
57
57
  }
58
- throw new Error((errorData?.error as string) || 'Streaming error')
58
+ throw new Error(errorData?.error || 'Streaming error')
59
59
  }
60
60
 
61
61
  function parseSSELine(line: string): { done: boolean; event: SSEEvent | null } {
@@ -3,6 +3,7 @@
3
3
  import { AnimatePresence, motion } from 'framer-motion'
4
4
  import { ChevronDown, FileText, List, Loader2, X } from 'lucide-react'
5
5
  import React, { useState } from 'react'
6
+ import type { Source } from '../adapters/ChatAdapter'
6
7
  import { useChunkLoader } from '../hooks/useChunkLoader'
7
8
  import { cn } from '../lib/utils'
8
9
  import type { LinkComponent } from '../types/components'
@@ -10,17 +11,6 @@ import { MarkdownText } from './assistant-ui/markdown-text'
10
11
  import { ViewMoreLink } from './buttons/ViewMoreLink'
11
12
  import { useChat } from './chat-context'
12
13
 
13
- interface Source {
14
- id: string
15
- title: string
16
- slug: string
17
- type: string
18
- chunkIndex: number
19
- relevanceScore: number
20
- content: string
21
- excerpt?: string
22
- }
23
-
24
14
  interface SourcesListProps {
25
15
  sources: Source[]
26
16
  isMaximized?: boolean