WIP - ai process builder codex attempt

This commit is contained in:
Francisco Gaona
2026-01-17 20:16:04 +01:00
parent 20fc90a3fb
commit ded413b99b
34 changed files with 2199 additions and 13 deletions

View File

@@ -16,6 +16,12 @@ const messages = ref<{ role: 'user' | 'assistant'; text: string }[]>([])
const sending = ref(false)
const route = useRoute()
const { api } = useApi()
const sessionId = ref<string | null>(null)
const getTenantId = () => {
if (!import.meta.client) return 'tenant1'
return localStorage.getItem('tenantId') || 'tenant1'
}
const buildContext = () => {
const recordId = route.params.recordId ? String(route.params.recordId) : undefined
@@ -43,27 +49,39 @@ const handleSend = async () => {
try {
const history = messages.value.slice(0, -1).slice(-6)
const response = await api.post('/ai/chat', {
const response = await api.post(`/tenants/${getTenantId()}/ai-chat/messages`, {
message,
history,
context: buildContext(),
sessionId: sessionId.value || undefined,
})
if (response.sessionId) {
sessionId.value = response.sessionId
}
if (response.reply) {
messages.value.push({
role: 'assistant',
text: response.reply,
})
if (response.action === 'create_record') {
window.dispatchEvent(
new CustomEvent('ai-record-created', {
detail: {
objectApiName: buildContext().objectApiName,
record: response.record,
},
}),
)
}
return
}
messages.value.push({
role: 'assistant',
text: response.reply || 'Let me know what else you need.',
text: 'Process started. I will post updates as soon as they are ready.',
})
if (response.action === 'create_record') {
window.dispatchEvent(
new CustomEvent('ai-record-created', {
detail: {
objectApiName: buildContext().objectApiName,
record: response.record,
},
}),
)
}
} catch (error: any) {
console.error('Failed to send AI chat message:', error)
messages.value.push({