spine-framework-cortex 0.2.23 → 0.2.24

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": "spine-framework-cortex",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "private": false,
5
5
  "description": "Cortex — AI-powered support, CRM, and knowledge base app for Spine Framework",
6
6
  "keywords": [
@@ -1,6 +1,7 @@
1
1
  import { useState, useEffect } from 'react'
2
2
  import { Send, Hash, MessageSquarePlus, AlertCircle } from 'lucide-react'
3
3
  import { apiFetch } from '@core/lib/api'
4
+ import { getTypeIdAsync } from '../../hooks/useTypeRegistry'
4
5
  import { Button } from '@core/components/ui/button'
5
6
  import { Input } from '@core/components/ui/input'
6
7
  import { Badge } from '@core/components/ui/badge'
@@ -20,6 +21,11 @@ function ThreadPane({ post }: { post: Post }) {
20
21
  const [loading, setLoading] = useState(true)
21
22
  const [replyText, setReplyText] = useState('')
22
23
  const [sending, setSending] = useState(false)
24
+ const [messageTypeId, setMessageTypeId] = useState<string | null>(null)
25
+
26
+ useEffect(() => {
27
+ getTypeIdAsync('message').then(id => setMessageTypeId(id))
28
+ }, [])
23
29
 
24
30
  useEffect(() => {
25
31
  setLoading(true)
@@ -33,14 +39,15 @@ function ThreadPane({ post }: { post: Post }) {
33
39
  }, [post.id])
34
40
 
35
41
  const handleSend = async () => {
36
- if (!replyText.trim() || !thread) return
42
+ if (!replyText.trim() || !thread || !messageTypeId) return
37
43
  setSending(true)
38
44
  try {
39
45
  const res = await apiFetch('/api/admin-data?action=create&entity=messages', {
40
46
  method: 'POST', headers: { 'Content-Type': 'application/json' },
41
- body: JSON.stringify({ thread_id: thread.id, content: replyText.trim(), direction: 'outbound', entity: 'messages', type_slug: 'message' }),
47
+ body: JSON.stringify({ thread_id: thread.id, type_id: messageTypeId, content: replyText.trim(), direction: 'outbound', entity: 'messages' }),
42
48
  })
43
- const msg = await res.json()
49
+ const raw = await res.json()
50
+ const msg = raw?.data ?? raw
44
51
  if (msg?.id) setMessages(prev => [...prev, msg])
45
52
  setReplyText('')
46
53
  } finally { setSending(false) }
@@ -66,7 +73,7 @@ function ThreadPane({ post }: { post: Post }) {
66
73
  <div className="border-t p-3 flex gap-2 shrink-0">
67
74
  <Input placeholder="Reply as agent…" value={replyText} onChange={e => setReplyText(e.target.value)}
68
75
  onKeyDown={e => e.key === 'Enter' && !e.shiftKey && handleSend()} className="flex-1" />
69
- <Button size="icon" onClick={handleSend} disabled={sending || !replyText.trim() || !thread}><Send size={14} /></Button>
76
+ <Button size="icon" onClick={handleSend} disabled={sending || !replyText.trim() || !thread || !messageTypeId}><Send size={14} /></Button>
70
77
  </div>
71
78
  </div>
72
79
  )