@octavus/docs 0.0.4 → 0.0.6
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/content/01-getting-started/01-introduction.md +1 -1
- package/content/01-getting-started/02-quickstart.md +40 -37
- package/content/02-server-sdk/01-overview.md +13 -3
- package/content/02-server-sdk/02-sessions.md +38 -27
- package/content/03-client-sdk/01-overview.md +152 -60
- package/content/03-client-sdk/02-messages.md +153 -125
- package/content/03-client-sdk/03-streaming.md +112 -111
- package/content/03-client-sdk/04-execution-blocks.md +80 -176
- package/content/03-client-sdk/_meta.md +1 -1
- package/content/04-protocol/01-overview.md +0 -3
- package/content/04-protocol/02-input-resources.md +2 -0
- package/content/04-protocol/03-triggers.md +8 -9
- package/content/04-protocol/04-tools.md +17 -27
- package/content/04-protocol/06-agent-config.md +0 -7
- package/content/05-api-reference/02-sessions.md +20 -7
- package/dist/chunk-4WWUKU4V.js +421 -0
- package/dist/chunk-4WWUKU4V.js.map +1 -0
- package/dist/chunk-7F5WOCIL.js +421 -0
- package/dist/chunk-7F5WOCIL.js.map +1 -0
- package/dist/chunk-CHGY4G27.js +421 -0
- package/dist/chunk-CHGY4G27.js.map +1 -0
- package/dist/chunk-CI7JDWKU.js +421 -0
- package/dist/chunk-CI7JDWKU.js.map +1 -0
- package/dist/chunk-CVFWWRL7.js +421 -0
- package/dist/chunk-CVFWWRL7.js.map +1 -0
- package/dist/chunk-IUKE3XDN.js +421 -0
- package/dist/chunk-IUKE3XDN.js.map +1 -0
- package/dist/chunk-J7BMB3ZW.js +421 -0
- package/dist/chunk-J7BMB3ZW.js.map +1 -0
- package/dist/chunk-JOB6YWEF.js +421 -0
- package/dist/chunk-JOB6YWEF.js.map +1 -0
- package/dist/chunk-K3GFQUMC.js +421 -0
- package/dist/chunk-K3GFQUMC.js.map +1 -0
- package/dist/chunk-M2R2NDPR.js +421 -0
- package/dist/chunk-M2R2NDPR.js.map +1 -0
- package/dist/chunk-QCHDPR2D.js +421 -0
- package/dist/chunk-QCHDPR2D.js.map +1 -0
- package/dist/chunk-TWUMRHQ7.js +421 -0
- package/dist/chunk-TWUMRHQ7.js.map +1 -0
- package/dist/chunk-YPPXXV3I.js +421 -0
- package/dist/chunk-YPPXXV3I.js.map +1 -0
- package/dist/content.js +1 -1
- package/dist/docs.json +21 -21
- package/dist/index.js +1 -1
- package/dist/search-index.json +1 -1
- package/dist/search.js +1 -1
- package/dist/search.js.map +1 -1
- package/dist/sections.json +22 -22
- package/package.json +1 -1
|
@@ -88,6 +88,6 @@ sequenceDiagram
|
|
|
88
88
|
|
|
89
89
|
- [Quick Start](/docs/getting-started/quickstart) — Get your first agent running in minutes
|
|
90
90
|
- [Server SDK](/docs/server-sdk/overview) — Learn about backend integration
|
|
91
|
-
- [Client SDK](/docs/client-sdk/overview) — Build chat interfaces with React
|
|
91
|
+
- [Client SDK](/docs/client-sdk/overview) — Build chat interfaces with React (or other frameworks)
|
|
92
92
|
- [Protocol Reference](/docs/protocol/overview) — Deep dive into agent protocols
|
|
93
93
|
|
|
@@ -21,8 +21,8 @@ Install the Octavus SDKs in your project:
|
|
|
21
21
|
# Server SDK for backend
|
|
22
22
|
npm install @octavus/server-sdk
|
|
23
23
|
|
|
24
|
-
#
|
|
25
|
-
npm install @octavus/
|
|
24
|
+
# React bindings for frontend
|
|
25
|
+
npm install @octavus/react
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## Backend Setup
|
|
@@ -124,7 +124,7 @@ Use the `useOctavusChat` hook to build a chat interface:
|
|
|
124
124
|
// components/chat.tsx
|
|
125
125
|
'use client';
|
|
126
126
|
|
|
127
|
-
import { useOctavusChat } from '@octavus/
|
|
127
|
+
import { useOctavusChat, type UIMessage } from '@octavus/react';
|
|
128
128
|
import { useState } from 'react';
|
|
129
129
|
|
|
130
130
|
interface ChatProps {
|
|
@@ -134,14 +134,7 @@ interface ChatProps {
|
|
|
134
134
|
export function Chat({ sessionId }: ChatProps) {
|
|
135
135
|
const [inputValue, setInputValue] = useState('');
|
|
136
136
|
|
|
137
|
-
const {
|
|
138
|
-
messages,
|
|
139
|
-
status,
|
|
140
|
-
isLoading,
|
|
141
|
-
streamingText,
|
|
142
|
-
addUserMessage,
|
|
143
|
-
triggerAction,
|
|
144
|
-
} = useOctavusChat({
|
|
137
|
+
const { messages, status, error, send } = useOctavusChat({
|
|
145
138
|
onTrigger: async (triggerName, input) => {
|
|
146
139
|
return fetch('/api/trigger', {
|
|
147
140
|
method: 'POST',
|
|
@@ -151,18 +144,19 @@ export function Chat({ sessionId }: ChatProps) {
|
|
|
151
144
|
},
|
|
152
145
|
});
|
|
153
146
|
|
|
147
|
+
const isStreaming = status === 'streaming';
|
|
148
|
+
|
|
154
149
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
155
150
|
e.preventDefault();
|
|
156
|
-
if (!inputValue.trim() ||
|
|
151
|
+
if (!inputValue.trim() || isStreaming) return;
|
|
157
152
|
|
|
158
153
|
const message = inputValue.trim();
|
|
159
154
|
setInputValue('');
|
|
160
155
|
|
|
161
|
-
// Add user message
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
await triggerAction('user-message', { USER_MESSAGE: message });
|
|
156
|
+
// Add user message and trigger in one call
|
|
157
|
+
await send('user-message', { USER_MESSAGE: message }, {
|
|
158
|
+
userMessage: { content: message },
|
|
159
|
+
});
|
|
166
160
|
};
|
|
167
161
|
|
|
168
162
|
return (
|
|
@@ -170,24 +164,8 @@ export function Chat({ sessionId }: ChatProps) {
|
|
|
170
164
|
{/* Messages */}
|
|
171
165
|
<div className="flex-1 overflow-y-auto p-4 space-y-4">
|
|
172
166
|
{messages.map((msg) => (
|
|
173
|
-
<
|
|
174
|
-
key={msg.id}
|
|
175
|
-
className={`p-3 rounded-lg ${
|
|
176
|
-
msg.role === 'user'
|
|
177
|
-
? 'bg-blue-500 text-white ml-auto max-w-xs'
|
|
178
|
-
: 'bg-gray-100 max-w-md'
|
|
179
|
-
}`}
|
|
180
|
-
>
|
|
181
|
-
{msg.content}
|
|
182
|
-
</div>
|
|
167
|
+
<MessageBubble key={msg.id} message={msg} />
|
|
183
168
|
))}
|
|
184
|
-
|
|
185
|
-
{/* Streaming text */}
|
|
186
|
-
{streamingText && (
|
|
187
|
-
<div className="bg-gray-100 p-3 rounded-lg max-w-md">
|
|
188
|
-
{streamingText}
|
|
189
|
-
</div>
|
|
190
|
-
)}
|
|
191
169
|
</div>
|
|
192
170
|
|
|
193
171
|
{/* Input */}
|
|
@@ -199,11 +177,11 @@ export function Chat({ sessionId }: ChatProps) {
|
|
|
199
177
|
onChange={(e) => setInputValue(e.target.value)}
|
|
200
178
|
placeholder="Type a message..."
|
|
201
179
|
className="flex-1 px-4 py-2 border rounded-lg"
|
|
202
|
-
disabled={
|
|
180
|
+
disabled={isStreaming}
|
|
203
181
|
/>
|
|
204
182
|
<button
|
|
205
183
|
type="submit"
|
|
206
|
-
disabled={
|
|
184
|
+
disabled={isStreaming}
|
|
207
185
|
className="px-4 py-2 bg-blue-500 text-white rounded-lg disabled:opacity-50"
|
|
208
186
|
>
|
|
209
187
|
Send
|
|
@@ -213,6 +191,32 @@ export function Chat({ sessionId }: ChatProps) {
|
|
|
213
191
|
</div>
|
|
214
192
|
);
|
|
215
193
|
}
|
|
194
|
+
|
|
195
|
+
function MessageBubble({ message }: { message: UIMessage }) {
|
|
196
|
+
const isUser = message.role === 'user';
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<div className={`flex ${isUser ? 'justify-end' : 'justify-start'}`}>
|
|
200
|
+
<div
|
|
201
|
+
className={`p-3 rounded-lg max-w-md ${
|
|
202
|
+
isUser ? 'bg-blue-500 text-white' : 'bg-gray-100'
|
|
203
|
+
}`}
|
|
204
|
+
>
|
|
205
|
+
{message.parts.map((part, i) => {
|
|
206
|
+
if (part.type === 'text') {
|
|
207
|
+
return <p key={i}>{part.text}</p>;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
})}
|
|
211
|
+
|
|
212
|
+
{/* Streaming indicator */}
|
|
213
|
+
{message.status === 'streaming' && (
|
|
214
|
+
<span className="inline-block w-2 h-4 bg-gray-400 animate-pulse ml-1" />
|
|
215
|
+
)}
|
|
216
|
+
</div>
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
216
220
|
```
|
|
217
221
|
|
|
218
222
|
### 2. Create Session and Render Chat
|
|
@@ -271,4 +275,3 @@ Now that you have a basic integration working:
|
|
|
271
275
|
- [Learn about the protocol](/docs/protocol/overview) to define custom agent behavior
|
|
272
276
|
- [Explore the Server SDK](/docs/server-sdk/overview) for advanced backend features
|
|
273
277
|
- [Build rich UIs](/docs/client-sdk/overview) with the Client SDK
|
|
274
|
-
|
|
@@ -102,12 +102,23 @@ class AgentSessionsApi {
|
|
|
102
102
|
// Create a new session
|
|
103
103
|
async create(agentId: string, input?: Record<string, unknown>): Promise<string>;
|
|
104
104
|
|
|
105
|
-
// Get session state
|
|
106
|
-
async get(sessionId: string): Promise<
|
|
105
|
+
// Get session state (includes UI-ready messages)
|
|
106
|
+
async get(sessionId: string): Promise<UISessionState>;
|
|
107
107
|
|
|
108
108
|
// Attach to a session for triggering
|
|
109
109
|
attach(sessionId: string, options?: SessionAttachOptions): AgentSession;
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
interface UISessionState {
|
|
113
|
+
id: string;
|
|
114
|
+
agentId: string;
|
|
115
|
+
input: Record<string, unknown>;
|
|
116
|
+
variables: Record<string, unknown>;
|
|
117
|
+
resources: Record<string, unknown>;
|
|
118
|
+
messages: UIMessage[]; // UI-ready messages for session restore
|
|
119
|
+
createdAt: string;
|
|
120
|
+
updatedAt: string;
|
|
121
|
+
}
|
|
111
122
|
```
|
|
112
123
|
|
|
113
124
|
### AgentSession
|
|
@@ -132,4 +143,3 @@ class AgentSession {
|
|
|
132
143
|
- [Sessions](/docs/server-sdk/sessions) — Deep dive into session management
|
|
133
144
|
- [Tools](/docs/server-sdk/tools) — Implementing tool handlers
|
|
134
145
|
- [Streaming](/docs/server-sdk/streaming) — Understanding stream events
|
|
135
|
-
|
|
@@ -29,9 +29,35 @@ const sessionId = await client.agentSessions.create('support-chat', {
|
|
|
29
29
|
console.log('Session created:', sessionId);
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
## Session
|
|
32
|
+
## Getting Session Messages
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
To restore a conversation on page load, use `getMessages()` to retrieve UI-ready messages:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const session = await client.agentSessions.getMessages(sessionId);
|
|
38
|
+
|
|
39
|
+
console.log({
|
|
40
|
+
sessionId: session.sessionId,
|
|
41
|
+
agentId: session.agentId,
|
|
42
|
+
messages: session.messages.length, // UIMessage[] ready for frontend
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The returned messages can be passed directly to the client SDK's `initialMessages` option.
|
|
47
|
+
|
|
48
|
+
### UISessionState Interface
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
interface UISessionState {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
agentId: string;
|
|
54
|
+
messages: UIMessage[]; // UI-ready conversation history
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Full Session State (Debug)
|
|
59
|
+
|
|
60
|
+
For debugging or internal use, you can retrieve the complete session state including all variables and internal message format:
|
|
35
61
|
|
|
36
62
|
```typescript
|
|
37
63
|
const state = await client.agentSessions.get(sessionId);
|
|
@@ -39,7 +65,7 @@ const state = await client.agentSessions.get(sessionId);
|
|
|
39
65
|
console.log({
|
|
40
66
|
id: state.id,
|
|
41
67
|
agentId: state.agentId,
|
|
42
|
-
messages: state.messages.length,
|
|
68
|
+
messages: state.messages.length, // ChatMessage[] (internal format)
|
|
43
69
|
resources: state.resources,
|
|
44
70
|
variables: state.variables,
|
|
45
71
|
createdAt: state.createdAt,
|
|
@@ -47,20 +73,7 @@ console.log({
|
|
|
47
73
|
});
|
|
48
74
|
```
|
|
49
75
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
interface SessionState {
|
|
54
|
-
id: string;
|
|
55
|
-
agentId: string;
|
|
56
|
-
input: Record<string, unknown>; // Initial input (immutable)
|
|
57
|
-
variables: Record<string, unknown>; // Mutable session variables
|
|
58
|
-
resources: Record<string, unknown>; // Resources (synced to consumer)
|
|
59
|
-
messages: ChatMessage[]; // Conversation history
|
|
60
|
-
createdAt: string;
|
|
61
|
-
updatedAt: string;
|
|
62
|
-
}
|
|
63
|
-
```
|
|
76
|
+
> **Note**: Use `getMessages()` for client-facing code. The `get()` method returns internal message format that includes hidden content not intended for end users.
|
|
64
77
|
|
|
65
78
|
## Attaching to Sessions
|
|
66
79
|
|
|
@@ -116,8 +129,8 @@ flowchart TD
|
|
|
116
129
|
Stream events
|
|
117
130
|
Update state`"]
|
|
118
131
|
|
|
119
|
-
D -.- D1["`**client.agentSessions.
|
|
120
|
-
Get
|
|
132
|
+
D -.- D1["`**client.agentSessions.getMessages()**
|
|
133
|
+
Get UI-ready messages
|
|
121
134
|
Restore conversation`"]
|
|
122
135
|
|
|
123
136
|
E -.- E1["`Sessions expire after
|
|
@@ -130,17 +143,16 @@ When a user returns to your app, restore their session:
|
|
|
130
143
|
|
|
131
144
|
```typescript
|
|
132
145
|
// On page load
|
|
133
|
-
const
|
|
146
|
+
const session = await client.agentSessions.getMessages(sessionId);
|
|
134
147
|
|
|
135
|
-
// Pass messages to frontend
|
|
148
|
+
// Pass messages to frontend - they're already UI-ready
|
|
136
149
|
return {
|
|
137
|
-
sessionId,
|
|
138
|
-
messages:
|
|
139
|
-
resources: state.resources,
|
|
150
|
+
sessionId: session.sessionId,
|
|
151
|
+
messages: session.messages, // UIMessage[] with parts
|
|
140
152
|
};
|
|
141
153
|
```
|
|
142
154
|
|
|
143
|
-
The `messages` array
|
|
155
|
+
The `messages` array contains `UIMessage` objects with properly structured `parts`, enabling direct use with the client SDK's `initialMessages` option.
|
|
144
156
|
|
|
145
157
|
## Error Handling
|
|
146
158
|
|
|
@@ -148,7 +160,7 @@ The `messages` array includes all conversation history with proper content order
|
|
|
148
160
|
import { ApiError } from '@octavus/server-sdk';
|
|
149
161
|
|
|
150
162
|
try {
|
|
151
|
-
const
|
|
163
|
+
const session = await client.agentSessions.getMessages(sessionId);
|
|
152
164
|
} catch (error) {
|
|
153
165
|
if (error instanceof ApiError) {
|
|
154
166
|
if (error.status === 404) {
|
|
@@ -161,4 +173,3 @@ try {
|
|
|
161
173
|
throw error;
|
|
162
174
|
}
|
|
163
175
|
```
|
|
164
|
-
|
|
@@ -1,144 +1,236 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Overview
|
|
3
|
-
description: Introduction to the Octavus Client
|
|
3
|
+
description: Introduction to the Octavus Client SDKs for building chat interfaces.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Client SDK Overview
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Octavus provides two packages for frontend integration:
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
| Package | Purpose | Use When |
|
|
11
|
+
|---------|---------|----------|
|
|
12
|
+
| `@octavus/react` | React hooks and bindings | Building React applications |
|
|
13
|
+
| `@octavus/client-sdk` | Framework-agnostic core | Using Vue, Svelte, vanilla JS, or custom integrations |
|
|
14
|
+
|
|
15
|
+
**Most users should install `@octavus/react`** — it includes everything from `@octavus/client-sdk` plus React-specific hooks.
|
|
11
16
|
|
|
12
17
|
## Installation
|
|
13
18
|
|
|
19
|
+
### React Applications
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @octavus/react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Current version:** `{{VERSION:@octavus/react}}`
|
|
26
|
+
|
|
27
|
+
### Other Frameworks
|
|
28
|
+
|
|
14
29
|
```bash
|
|
15
30
|
npm install @octavus/client-sdk
|
|
16
31
|
```
|
|
17
32
|
|
|
18
|
-
|
|
33
|
+
**Current version:** `{{VERSION:@octavus/client-sdk}}`
|
|
34
|
+
|
|
35
|
+
## React Usage
|
|
36
|
+
|
|
37
|
+
The `useOctavusChat` hook provides state management and streaming for React applications:
|
|
19
38
|
|
|
20
39
|
```tsx
|
|
21
|
-
import { useOctavusChat } from '@octavus/
|
|
40
|
+
import { useOctavusChat, type UIMessage } from '@octavus/react';
|
|
22
41
|
|
|
23
42
|
function Chat({ sessionId }: { sessionId: string }) {
|
|
24
|
-
const {
|
|
25
|
-
messages,
|
|
26
|
-
status,
|
|
27
|
-
isLoading,
|
|
28
|
-
streamingText,
|
|
29
|
-
addUserMessage,
|
|
30
|
-
triggerAction,
|
|
31
|
-
} = useOctavusChat({
|
|
43
|
+
const { messages, status, send } = useOctavusChat({
|
|
32
44
|
onTrigger: async (triggerName, input) => {
|
|
33
|
-
return fetch(`/api/
|
|
45
|
+
return fetch(`/api/trigger`, {
|
|
34
46
|
method: 'POST',
|
|
35
|
-
body: JSON.stringify({ triggerName, input }),
|
|
47
|
+
body: JSON.stringify({ sessionId, triggerName, input }),
|
|
36
48
|
});
|
|
37
49
|
},
|
|
38
50
|
});
|
|
39
51
|
|
|
40
52
|
const sendMessage = async (text: string) => {
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
await send('user-message', { USER_MESSAGE: text }, {
|
|
54
|
+
userMessage: { content: text },
|
|
55
|
+
});
|
|
43
56
|
};
|
|
44
57
|
|
|
45
58
|
return (
|
|
46
59
|
<div>
|
|
47
60
|
{messages.map((msg) => (
|
|
48
|
-
<
|
|
61
|
+
<MessageBubble key={msg.id} message={msg} />
|
|
49
62
|
))}
|
|
50
|
-
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function MessageBubble({ message }: { message: UIMessage }) {
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
{message.parts.map((part, i) => {
|
|
71
|
+
if (part.type === 'text') {
|
|
72
|
+
return <p key={i}>{part.text}</p>;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
})}
|
|
51
76
|
</div>
|
|
52
77
|
);
|
|
53
78
|
}
|
|
54
79
|
```
|
|
55
80
|
|
|
81
|
+
## Framework-Agnostic Usage
|
|
82
|
+
|
|
83
|
+
The `OctavusChat` class can be used with any framework or vanilla JavaScript:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { OctavusChat } from '@octavus/client-sdk';
|
|
87
|
+
|
|
88
|
+
const chat = new OctavusChat({
|
|
89
|
+
onTrigger: async (triggerName, input) => {
|
|
90
|
+
return fetch('/api/trigger', {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
body: JSON.stringify({ sessionId, triggerName, input }),
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Subscribe to state changes
|
|
98
|
+
const unsubscribe = chat.subscribe(() => {
|
|
99
|
+
console.log('Messages:', chat.messages);
|
|
100
|
+
console.log('Status:', chat.status);
|
|
101
|
+
// Update your UI here
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Send a message
|
|
105
|
+
await chat.send('user-message', { USER_MESSAGE: 'Hello' }, {
|
|
106
|
+
userMessage: { content: 'Hello' },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Cleanup when done
|
|
110
|
+
unsubscribe();
|
|
111
|
+
```
|
|
112
|
+
|
|
56
113
|
## Key Features
|
|
57
114
|
|
|
58
|
-
###
|
|
115
|
+
### Unified Send Function
|
|
59
116
|
|
|
60
|
-
|
|
117
|
+
The `send` function handles both user message display and agent triggering in one call:
|
|
61
118
|
|
|
62
119
|
```tsx
|
|
63
|
-
const {
|
|
120
|
+
const { send } = useOctavusChat({...});
|
|
121
|
+
|
|
122
|
+
// Add user message to UI and trigger agent
|
|
123
|
+
await send('user-message', { USER_MESSAGE: text }, {
|
|
124
|
+
userMessage: { content: text },
|
|
125
|
+
});
|
|
64
126
|
|
|
65
|
-
//
|
|
66
|
-
|
|
127
|
+
// Trigger without adding a user message (e.g., button click)
|
|
128
|
+
await send('request-human');
|
|
67
129
|
```
|
|
68
130
|
|
|
69
|
-
### Message
|
|
131
|
+
### Message Parts
|
|
70
132
|
|
|
71
|
-
Messages
|
|
133
|
+
Messages contain ordered `parts` for rich content:
|
|
72
134
|
|
|
73
135
|
```tsx
|
|
74
136
|
const { messages } = useOctavusChat({...});
|
|
75
137
|
|
|
76
|
-
// Each message
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
138
|
+
// Each message has typed parts
|
|
139
|
+
message.parts.map((part) => {
|
|
140
|
+
switch (part.type) {
|
|
141
|
+
case 'text': // Text content
|
|
142
|
+
case 'reasoning': // Extended reasoning/thinking
|
|
143
|
+
case 'tool-call': // Tool execution
|
|
144
|
+
case 'operation': // Internal operations (set-resource, etc.)
|
|
145
|
+
}
|
|
146
|
+
});
|
|
83
147
|
```
|
|
84
148
|
|
|
85
|
-
###
|
|
86
|
-
|
|
87
|
-
Track what the agent is doing:
|
|
149
|
+
### Status Tracking
|
|
88
150
|
|
|
89
151
|
```tsx
|
|
90
|
-
const {
|
|
152
|
+
const { status } = useOctavusChat({...});
|
|
91
153
|
|
|
92
|
-
//
|
|
93
|
-
// Useful for progress indicators
|
|
154
|
+
// status: 'idle' | 'streaming' | 'error'
|
|
94
155
|
```
|
|
95
156
|
|
|
96
|
-
###
|
|
157
|
+
### Stop Streaming
|
|
97
158
|
|
|
98
159
|
```tsx
|
|
99
|
-
const {
|
|
160
|
+
const { stop } = useOctavusChat({...});
|
|
100
161
|
|
|
101
|
-
//
|
|
102
|
-
|
|
162
|
+
// Stop current stream and finalize message
|
|
163
|
+
stop();
|
|
103
164
|
```
|
|
104
165
|
|
|
105
|
-
## Hook Reference
|
|
166
|
+
## Hook Reference (React)
|
|
106
167
|
|
|
107
168
|
### useOctavusChat
|
|
108
169
|
|
|
109
170
|
```typescript
|
|
110
|
-
function useOctavusChat(options:
|
|
171
|
+
function useOctavusChat(options: OctavusChatOptions): UseOctavusChatReturn;
|
|
111
172
|
|
|
112
|
-
interface
|
|
173
|
+
interface OctavusChatOptions {
|
|
113
174
|
// Required: Function that calls your backend trigger endpoint
|
|
114
175
|
onTrigger: TriggerFunction;
|
|
115
176
|
|
|
116
177
|
// Optional: Pre-populate with existing messages (session restore)
|
|
117
|
-
initialMessages?:
|
|
178
|
+
initialMessages?: UIMessage[];
|
|
118
179
|
|
|
119
180
|
// Optional: Callbacks
|
|
120
|
-
onMessage?: (message: Message) => void;
|
|
121
181
|
onError?: (error: Error) => void;
|
|
122
|
-
|
|
182
|
+
onFinish?: () => void;
|
|
123
183
|
onResourceUpdate?: (name: string, value: unknown) => void;
|
|
124
|
-
onBlockStart?: (block: ExecutionBlock) => void;
|
|
125
|
-
onBlockEnd?: (block: ExecutionBlock) => void;
|
|
126
184
|
}
|
|
127
185
|
|
|
128
186
|
interface UseOctavusChatReturn {
|
|
129
187
|
// State
|
|
130
|
-
messages:
|
|
131
|
-
status: ChatStatus;
|
|
132
|
-
isLoading: boolean;
|
|
188
|
+
messages: UIMessage[];
|
|
189
|
+
status: ChatStatus; // 'idle' | 'streaming' | 'error'
|
|
133
190
|
error: Error | null;
|
|
134
|
-
streamingText: string;
|
|
135
|
-
streamingParts: MessagePart[];
|
|
136
|
-
executionBlocks: ExecutionBlock[];
|
|
137
|
-
reasoningText: string;
|
|
138
191
|
|
|
139
192
|
// Actions
|
|
140
|
-
|
|
141
|
-
|
|
193
|
+
send: (
|
|
194
|
+
triggerName: string,
|
|
195
|
+
input?: Record<string, unknown>,
|
|
196
|
+
options?: { userMessage?: UserMessageInput }
|
|
197
|
+
) => Promise<void>;
|
|
198
|
+
stop: () => void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type TriggerFunction = (
|
|
202
|
+
triggerName: string,
|
|
203
|
+
input?: Record<string, unknown>,
|
|
204
|
+
) => Promise<Response>;
|
|
205
|
+
|
|
206
|
+
interface UserMessageInput {
|
|
207
|
+
content: string;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Class Reference (Framework-Agnostic)
|
|
212
|
+
|
|
213
|
+
### OctavusChat
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
class OctavusChat {
|
|
217
|
+
constructor(options: OctavusChatOptions);
|
|
218
|
+
|
|
219
|
+
// State (read-only)
|
|
220
|
+
readonly messages: UIMessage[];
|
|
221
|
+
readonly status: ChatStatus;
|
|
222
|
+
readonly error: Error | null;
|
|
223
|
+
|
|
224
|
+
// Actions
|
|
225
|
+
send(
|
|
226
|
+
triggerName: string,
|
|
227
|
+
input?: Record<string, unknown>,
|
|
228
|
+
options?: { userMessage?: UserMessageInput }
|
|
229
|
+
): Promise<void>;
|
|
230
|
+
stop(): void;
|
|
231
|
+
|
|
232
|
+
// Subscription
|
|
233
|
+
subscribe(callback: () => void): () => void; // Returns unsubscribe function
|
|
142
234
|
}
|
|
143
235
|
```
|
|
144
236
|
|