useAiChatStream
Conversation-transport composable for the AI Chat Companion.
Owns the full SSE lifecycle against OpenRegister's chat endpoints and exposes a
reactive state object plus send() / abort controls. Create one instance per
CnAiCompanion mount and pass state to CnAiChatPanel.
Signature
import { useAiChatStream } from '@conduction/nextcloud-vue'
// In CnAiCompanion's data()/setup, passing the component instance so the
// outgoing request body carries the current cnAiContext snapshot:
const { state, send, abort } = useAiChatStream(this)
| Argument | Type | Description |
|---|---|---|
contextInstance | object | Vue component instance to read cnAiContext from (via useAiContext) — pass the CnAiCompanion instance. |
Transport
- POSTs
/index.php/apps/openregister/api/chat/streamvia@microsoft/fetch-event-sourceand handles the six-event envelope:token,tool_call,tool_result,heartbeat,final,error. - Falls back to POST
/index.php/apps/openregister/api/chat/send(axios) when the streaming endpoint returns 404/501 or fails mid-handshake, synthesising a singlefinalevent so rendering code never branches.
Return value
A reactive state object — { isStreaming, currentText, toolCalls, error, messages } — plus the methods to drive it (send, abort, new-thread toggle).
Reference
- Implementation: src/composables/useAiChatStream.js
- Related: CnAiCompanion, CnAiChatPanel, useAiContext