@octavus/client-sdk 0.0.4 → 0.0.5
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/dist/index.d.ts +34 -66
- package/dist/index.js +242 -276
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,83 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIMessage, UIMessagePart } from '@octavus/core';
|
|
2
2
|
export * from '@octavus/core';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
display: DisplayMode;
|
|
13
|
-
description?: string;
|
|
14
|
-
outputToChat: boolean;
|
|
15
|
-
summary?: string;
|
|
16
|
-
fullOutput?: string;
|
|
17
|
-
reasoning?: string;
|
|
18
|
-
toolCalls?: ToolCallWithDescription[];
|
|
19
|
-
thread?: string;
|
|
20
|
-
}
|
|
21
|
-
interface Message {
|
|
22
|
-
id: string;
|
|
23
|
-
role: 'user' | 'assistant' | 'system';
|
|
4
|
+
type ChatStatus = 'idle' | 'streaming' | 'error';
|
|
5
|
+
type TriggerFunction = (triggerName: string, input?: Record<string, unknown>) => Promise<Response>;
|
|
6
|
+
/**
|
|
7
|
+
* Input for creating a user message.
|
|
8
|
+
* Currently supports text content. Will be extended to support attachments, images, etc.
|
|
9
|
+
*/
|
|
10
|
+
interface UserMessageInput {
|
|
11
|
+
/** Text content of the message */
|
|
24
12
|
content: string;
|
|
25
|
-
toolCalls?: ToolCallWithDescription[];
|
|
26
|
-
executionSteps?: ExecutionStep[];
|
|
27
|
-
/** If false, message is not shown to user (internal directive) */
|
|
28
|
-
visible?: boolean;
|
|
29
|
-
/** Ordered message parts - single source of truth for display */
|
|
30
|
-
parts?: MessagePart[];
|
|
31
|
-
reasoning?: string;
|
|
32
|
-
createdAt: Date;
|
|
33
13
|
}
|
|
34
|
-
type BlockStatus = 'pending' | 'running' | 'completed' | 'error';
|
|
35
|
-
interface ExecutionBlock {
|
|
36
|
-
id: string;
|
|
37
|
-
name: string;
|
|
38
|
-
type: string;
|
|
39
|
-
status: BlockStatus;
|
|
40
|
-
display: DisplayMode;
|
|
41
|
-
description?: string;
|
|
42
|
-
/** False for independent blocks */
|
|
43
|
-
outputToChat: boolean;
|
|
44
|
-
thread?: string;
|
|
45
|
-
streamingText: string;
|
|
46
|
-
summary?: string;
|
|
47
|
-
reasoning?: string;
|
|
48
|
-
toolCalls: ToolCallWithDescription[];
|
|
49
|
-
startedAt: Date;
|
|
50
|
-
completedAt?: Date;
|
|
51
|
-
}
|
|
52
|
-
type ChatStatus = 'idle' | 'loading' | 'streaming' | 'error';
|
|
53
|
-
type TriggerFunction = (triggerName: string, input?: Record<string, unknown>) => Promise<Response>;
|
|
54
14
|
interface UseOctavusChatOptions {
|
|
15
|
+
/** Function to make the API call to trigger the agent */
|
|
55
16
|
onTrigger: TriggerFunction;
|
|
56
|
-
|
|
57
|
-
|
|
17
|
+
/** Initial messages (for session refresh) */
|
|
18
|
+
initialMessages?: UIMessage[];
|
|
19
|
+
/** Callback when an error occurs */
|
|
58
20
|
onError?: (error: Error) => void;
|
|
59
|
-
|
|
21
|
+
/** Callback when streaming finishes */
|
|
22
|
+
onFinish?: () => void;
|
|
23
|
+
/** Callback when a resource is updated */
|
|
60
24
|
onResourceUpdate?: (name: string, value: unknown) => void;
|
|
61
|
-
onBlockStart?: (block: ExecutionBlock) => void;
|
|
62
|
-
onBlockEnd?: (block: ExecutionBlock) => void;
|
|
63
25
|
}
|
|
64
26
|
interface UseOctavusChatReturn {
|
|
65
|
-
messages
|
|
27
|
+
/** All messages including the currently streaming one */
|
|
28
|
+
messages: UIMessage[];
|
|
29
|
+
/** Current status of the chat */
|
|
66
30
|
status: ChatStatus;
|
|
67
|
-
|
|
31
|
+
/** Error if status is 'error' */
|
|
68
32
|
error: Error | null;
|
|
69
33
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
34
|
+
* Trigger the agent and optionally add a user message to the chat.
|
|
35
|
+
*
|
|
36
|
+
* @param triggerName - The trigger name defined in the agent's protocol.yaml
|
|
37
|
+
* @param input - Input parameters for the trigger (variable substitutions)
|
|
38
|
+
* @param options.userMessage - If provided, adds a user message to the chat before triggering
|
|
72
39
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
executionBlocks: ExecutionBlock[];
|
|
79
|
-
reasoningText: string;
|
|
40
|
+
send: (triggerName: string, input?: Record<string, unknown>, options?: {
|
|
41
|
+
userMessage?: UserMessageInput;
|
|
42
|
+
}) => Promise<void>;
|
|
43
|
+
/** Stop the current streaming and finalize any partial message */
|
|
44
|
+
stop: () => void;
|
|
80
45
|
}
|
|
81
46
|
declare function useOctavusChat(options: UseOctavusChatOptions): UseOctavusChatReturn;
|
|
82
47
|
|
|
83
|
-
|
|
48
|
+
/** Non-main thread content (e.g., "summary") is typically displayed differently. */
|
|
49
|
+
declare function isOtherThread(part: UIMessagePart): boolean;
|
|
50
|
+
|
|
51
|
+
export { type ChatStatus, type TriggerFunction, type UseOctavusChatOptions, type UseOctavusChatReturn, type UserMessageInput, isOtherThread, useOctavusChat };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/hooks/use-octavus-chat.ts
|
|
2
2
|
import { useState, useCallback, useRef } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
generateId
|
|
5
|
+
} from "@octavus/core";
|
|
4
6
|
|
|
5
7
|
// src/stream/reader.ts
|
|
6
8
|
import { safeParseStreamEvent } from "@octavus/core";
|
|
@@ -40,299 +42,282 @@ async function* parseSSEStream(response) {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
// src/hooks/use-octavus-chat.ts
|
|
45
|
+
var OPERATION_BLOCK_TYPES = /* @__PURE__ */ new Set(["set-resource", "serialize-thread"]);
|
|
43
46
|
async function parseErrorResponse(response) {
|
|
44
47
|
try {
|
|
45
48
|
const data = await response.json();
|
|
46
|
-
return data.error ?? data.
|
|
49
|
+
return data.error ?? data.message ?? `Request failed: ${response.status}`;
|
|
47
50
|
} catch {
|
|
48
51
|
return `Request failed: ${response.status}`;
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
function createUserMessage(input) {
|
|
55
|
+
return {
|
|
56
|
+
id: generateId(),
|
|
57
|
+
role: "user",
|
|
58
|
+
parts: [{ type: "text", text: input.content, status: "done" }],
|
|
59
|
+
status: "done",
|
|
60
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createEmptyStreamingState() {
|
|
64
|
+
return {
|
|
65
|
+
messageId: generateId(),
|
|
66
|
+
parts: [],
|
|
67
|
+
activeBlock: null,
|
|
68
|
+
blocks: /* @__PURE__ */ new Map(),
|
|
69
|
+
currentTextPartIndex: null,
|
|
70
|
+
currentReasoningPartIndex: null
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function buildMessageFromState(state, status) {
|
|
74
|
+
return {
|
|
75
|
+
id: state.messageId,
|
|
76
|
+
role: "assistant",
|
|
77
|
+
parts: [...state.parts],
|
|
78
|
+
status,
|
|
79
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
65
80
|
};
|
|
66
|
-
parts.push(newPart);
|
|
67
|
-
return { part: newPart, index: parts.length - 1 };
|
|
68
81
|
}
|
|
69
82
|
function useOctavusChat(options) {
|
|
70
|
-
const {
|
|
71
|
-
onTrigger,
|
|
72
|
-
initialMessages = [],
|
|
73
|
-
onMessage,
|
|
74
|
-
onError,
|
|
75
|
-
onDone,
|
|
76
|
-
onResourceUpdate,
|
|
77
|
-
onBlockStart,
|
|
78
|
-
onBlockEnd
|
|
79
|
-
} = options;
|
|
83
|
+
const { onTrigger, initialMessages = [], onError, onFinish, onResourceUpdate } = options;
|
|
80
84
|
const [messages, setMessages] = useState(initialMessages);
|
|
81
85
|
const [status, setStatus] = useState("idle");
|
|
82
86
|
const [error, setError] = useState(null);
|
|
83
|
-
const [streamingText, setStreamingText] = useState("");
|
|
84
|
-
const [streamingParts, setStreamingParts] = useState([]);
|
|
85
|
-
const [executionBlocks, setExecutionBlocks] = useState([]);
|
|
86
|
-
const [reasoningText, setReasoningText] = useState("");
|
|
87
87
|
const abortControllerRef = useRef(null);
|
|
88
|
-
const
|
|
89
|
-
|
|
88
|
+
const streamingStateRef = useRef(null);
|
|
89
|
+
const updateStreamingMessage = useCallback(() => {
|
|
90
|
+
const state = streamingStateRef.current;
|
|
91
|
+
if (!state) return;
|
|
92
|
+
const msg = buildMessageFromState(state, "streaming");
|
|
93
|
+
setMessages((prev) => {
|
|
94
|
+
const lastMsg = prev[prev.length - 1];
|
|
95
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
96
|
+
return [...prev.slice(0, -1), msg];
|
|
97
|
+
}
|
|
98
|
+
return [...prev, msg];
|
|
99
|
+
});
|
|
100
|
+
}, []);
|
|
101
|
+
const send = useCallback(
|
|
102
|
+
async (triggerName, input, sendOptions) => {
|
|
90
103
|
abortControllerRef.current?.abort();
|
|
91
|
-
abortControllerRef.current = null;
|
|
92
104
|
const abortController = new AbortController();
|
|
93
105
|
abortControllerRef.current = abortController;
|
|
94
|
-
|
|
106
|
+
if (sendOptions?.userMessage !== void 0) {
|
|
107
|
+
const userMsg = createUserMessage(sendOptions.userMessage);
|
|
108
|
+
setMessages((prev) => [...prev, userMsg]);
|
|
109
|
+
}
|
|
110
|
+
setStatus("streaming");
|
|
95
111
|
setError(null);
|
|
96
|
-
|
|
97
|
-
setStreamingParts([]);
|
|
98
|
-
setExecutionBlocks([]);
|
|
99
|
-
setReasoningText("");
|
|
100
|
-
const blocks = [];
|
|
101
|
-
let activeBlock = null;
|
|
102
|
-
const toolCalls = [];
|
|
103
|
-
let visibleFullText = "";
|
|
104
|
-
let executionReasoningText = "";
|
|
105
|
-
const reasoningStack = [];
|
|
106
|
-
const getCurrentReasoning = () => reasoningStack[reasoningStack.length - 1];
|
|
107
|
-
const parts = [];
|
|
112
|
+
streamingStateRef.current = createEmptyStreamingState();
|
|
108
113
|
try {
|
|
109
114
|
const response = await onTrigger(triggerName, input);
|
|
110
115
|
if (!response.ok) {
|
|
111
116
|
const errorMessage = await parseErrorResponse(response);
|
|
112
117
|
throw new Error(errorMessage);
|
|
113
118
|
}
|
|
114
|
-
setStatus("streaming");
|
|
115
119
|
for await (const event of parseSSEStream(response)) {
|
|
116
120
|
if (abortController.signal.aborted) {
|
|
117
121
|
break;
|
|
118
122
|
}
|
|
123
|
+
const state = streamingStateRef.current;
|
|
124
|
+
if (!state) break;
|
|
119
125
|
switch (event.type) {
|
|
120
126
|
case "start":
|
|
121
127
|
break;
|
|
122
128
|
case "block-start": {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
status: "running",
|
|
129
|
+
const block = {
|
|
130
|
+
blockId: event.blockId,
|
|
131
|
+
blockName: event.blockName,
|
|
132
|
+
blockType: event.blockType,
|
|
128
133
|
display: event.display,
|
|
129
134
|
description: event.description,
|
|
130
|
-
outputToChat: event.outputToChat ??
|
|
135
|
+
outputToChat: event.outputToChat ?? true,
|
|
131
136
|
thread: event.thread,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
reasoning: "",
|
|
138
|
+
text: "",
|
|
139
|
+
toolCalls: /* @__PURE__ */ new Map()
|
|
135
140
|
};
|
|
136
|
-
blocks.
|
|
137
|
-
activeBlock =
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
state.blocks.set(event.blockId, block);
|
|
142
|
+
state.activeBlock = block;
|
|
143
|
+
const isOperation = OPERATION_BLOCK_TYPES.has(event.blockType);
|
|
144
|
+
const isHidden = event.display === "hidden";
|
|
145
|
+
if (isOperation && !isHidden) {
|
|
146
|
+
const thread = event.thread;
|
|
147
|
+
const operationPart = {
|
|
148
|
+
type: "operation",
|
|
149
|
+
operationId: event.blockId,
|
|
150
|
+
name: event.description || event.blockName,
|
|
151
|
+
operationType: event.blockType,
|
|
152
|
+
status: "running",
|
|
153
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
154
|
+
};
|
|
155
|
+
state.parts.push(operationPart);
|
|
156
|
+
}
|
|
157
|
+
state.currentTextPartIndex = null;
|
|
158
|
+
state.currentReasoningPartIndex = null;
|
|
159
|
+
updateStreamingMessage();
|
|
140
160
|
break;
|
|
141
161
|
}
|
|
142
162
|
case "block-end": {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
activeBlock = null;
|
|
163
|
+
const operationPartIndex = state.parts.findIndex(
|
|
164
|
+
(p) => p.type === "operation" && p.operationId === event.blockId
|
|
165
|
+
);
|
|
166
|
+
if (operationPartIndex >= 0) {
|
|
167
|
+
const part = state.parts[operationPartIndex];
|
|
168
|
+
state.parts[operationPartIndex] = { ...part, status: "done" };
|
|
150
169
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
case "text-delta":
|
|
154
|
-
if (activeBlock) {
|
|
155
|
-
activeBlock.streamingText += event.delta;
|
|
156
|
-
setExecutionBlocks([...blocks]);
|
|
157
|
-
const isNonMainThread = activeBlock.thread !== void 0 && activeBlock.thread !== "main";
|
|
158
|
-
const shouldCaptureText = activeBlock.outputToChat || isNonMainThread;
|
|
159
|
-
if (shouldCaptureText) {
|
|
160
|
-
const { part, index } = findOrCreateTextPart(parts, activeBlock.thread);
|
|
161
|
-
part.content = (part.content ?? "") + event.delta;
|
|
162
|
-
parts[index] = { ...part };
|
|
163
|
-
if (activeBlock.outputToChat) {
|
|
164
|
-
visibleFullText += event.delta;
|
|
165
|
-
setStreamingText(visibleFullText);
|
|
166
|
-
}
|
|
167
|
-
setStreamingParts([...parts]);
|
|
168
|
-
}
|
|
170
|
+
if (state.activeBlock?.blockId === event.blockId) {
|
|
171
|
+
state.activeBlock = null;
|
|
169
172
|
}
|
|
173
|
+
updateStreamingMessage();
|
|
170
174
|
break;
|
|
171
|
-
|
|
172
|
-
case "text-end":
|
|
173
|
-
break;
|
|
175
|
+
}
|
|
174
176
|
case "reasoning-start": {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const newPart = {
|
|
177
|
+
const thread = state.activeBlock?.thread;
|
|
178
|
+
const reasoningPart = {
|
|
178
179
|
type: "reasoning",
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
thread:
|
|
180
|
+
text: "",
|
|
181
|
+
status: "streaming",
|
|
182
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
182
183
|
};
|
|
183
|
-
parts.push(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
outputToChat: shouldCapture,
|
|
187
|
-
partIndex: parts.length - 1
|
|
188
|
-
});
|
|
189
|
-
setReasoningText("");
|
|
184
|
+
state.parts.push(reasoningPart);
|
|
185
|
+
state.currentReasoningPartIndex = state.parts.length - 1;
|
|
186
|
+
updateStreamingMessage();
|
|
190
187
|
break;
|
|
191
188
|
}
|
|
192
189
|
case "reasoning-delta": {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
parts[ctx.partIndex] = { ...reasoningPart };
|
|
190
|
+
if (state.currentReasoningPartIndex !== null) {
|
|
191
|
+
const part = state.parts[state.currentReasoningPartIndex];
|
|
192
|
+
part.text += event.delta;
|
|
193
|
+
state.parts[state.currentReasoningPartIndex] = { ...part };
|
|
198
194
|
}
|
|
199
|
-
if (activeBlock
|
|
200
|
-
|
|
195
|
+
if (state.activeBlock) {
|
|
196
|
+
state.activeBlock.reasoning += event.delta;
|
|
201
197
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
198
|
+
updateStreamingMessage();
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case "reasoning-end": {
|
|
202
|
+
if (state.currentReasoningPartIndex !== null) {
|
|
203
|
+
const part = state.parts[state.currentReasoningPartIndex];
|
|
204
|
+
part.status = "done";
|
|
205
|
+
state.parts[state.currentReasoningPartIndex] = { ...part };
|
|
206
|
+
state.currentReasoningPartIndex = null;
|
|
206
207
|
}
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
updateStreamingMessage();
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case "text-start": {
|
|
212
|
+
const thread = state.activeBlock?.thread;
|
|
213
|
+
const isOtherThread2 = Boolean(thread && thread !== "main");
|
|
214
|
+
const shouldAddPart = state.activeBlock?.outputToChat !== false || isOtherThread2;
|
|
215
|
+
if (shouldAddPart) {
|
|
216
|
+
const textPart = {
|
|
217
|
+
type: "text",
|
|
218
|
+
text: "",
|
|
219
|
+
status: "streaming",
|
|
220
|
+
thread: isOtherThread2 ? thread : void 0
|
|
221
|
+
};
|
|
222
|
+
state.parts.push(textPart);
|
|
223
|
+
state.currentTextPartIndex = state.parts.length - 1;
|
|
209
224
|
}
|
|
225
|
+
updateStreamingMessage();
|
|
210
226
|
break;
|
|
211
227
|
}
|
|
212
|
-
case "
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
228
|
+
case "text-delta": {
|
|
229
|
+
if (state.currentTextPartIndex !== null) {
|
|
230
|
+
const part = state.parts[state.currentTextPartIndex];
|
|
231
|
+
part.text += event.delta;
|
|
232
|
+
state.parts[state.currentTextPartIndex] = { ...part };
|
|
233
|
+
}
|
|
234
|
+
if (state.activeBlock) {
|
|
235
|
+
state.activeBlock.text += event.delta;
|
|
218
236
|
}
|
|
219
|
-
|
|
220
|
-
|
|
237
|
+
updateStreamingMessage();
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "text-end": {
|
|
241
|
+
if (state.currentTextPartIndex !== null) {
|
|
242
|
+
const part = state.parts[state.currentTextPartIndex];
|
|
243
|
+
part.status = "done";
|
|
244
|
+
state.parts[state.currentTextPartIndex] = { ...part };
|
|
245
|
+
state.currentTextPartIndex = null;
|
|
221
246
|
}
|
|
247
|
+
updateStreamingMessage();
|
|
222
248
|
break;
|
|
223
249
|
}
|
|
224
250
|
case "tool-input-start": {
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
const thread = state.activeBlock?.thread;
|
|
252
|
+
const toolPart = {
|
|
253
|
+
type: "tool-call",
|
|
254
|
+
toolCallId: event.toolCallId,
|
|
255
|
+
toolName: event.toolName,
|
|
256
|
+
displayName: event.title,
|
|
257
|
+
args: {},
|
|
258
|
+
status: "pending",
|
|
259
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
231
260
|
};
|
|
232
|
-
|
|
233
|
-
if (activeBlock) {
|
|
234
|
-
activeBlock.toolCalls
|
|
235
|
-
setExecutionBlocks([...blocks]);
|
|
236
|
-
}
|
|
237
|
-
const isVisibleBlock = activeBlock?.display !== "hidden";
|
|
238
|
-
if (isVisibleBlock) {
|
|
239
|
-
const toolPart = {
|
|
240
|
-
type: "tool-call",
|
|
241
|
-
visible: true,
|
|
242
|
-
toolCall: newToolCall,
|
|
243
|
-
thread: activeBlock?.thread
|
|
244
|
-
};
|
|
245
|
-
parts.push(toolPart);
|
|
246
|
-
setStreamingParts([...parts]);
|
|
261
|
+
state.parts.push(toolPart);
|
|
262
|
+
if (state.activeBlock) {
|
|
263
|
+
state.activeBlock.toolCalls.set(event.toolCallId, toolPart);
|
|
247
264
|
}
|
|
265
|
+
updateStreamingMessage();
|
|
248
266
|
break;
|
|
249
267
|
}
|
|
250
268
|
case "tool-input-delta": {
|
|
251
|
-
const
|
|
252
|
-
|
|
269
|
+
const toolPartIndex = state.parts.findIndex(
|
|
270
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
271
|
+
);
|
|
272
|
+
if (toolPartIndex >= 0) {
|
|
253
273
|
try {
|
|
254
|
-
|
|
274
|
+
const part = state.parts[toolPartIndex];
|
|
275
|
+
part.args = JSON.parse(event.inputTextDelta);
|
|
276
|
+
state.parts[toolPartIndex] = { ...part };
|
|
277
|
+
updateStreamingMessage();
|
|
255
278
|
} catch {
|
|
256
279
|
}
|
|
257
|
-
const argsPart = parts.find(
|
|
258
|
-
(p) => p.type === "tool-call" && p.toolCall?.id === event.toolCallId
|
|
259
|
-
);
|
|
260
|
-
if (argsPart?.toolCall) {
|
|
261
|
-
argsPart.toolCall = { ...argsPart.toolCall, arguments: toolCall.arguments };
|
|
262
|
-
setStreamingParts([...parts]);
|
|
263
|
-
}
|
|
264
|
-
if (activeBlock) {
|
|
265
|
-
setExecutionBlocks([...blocks]);
|
|
266
|
-
}
|
|
267
280
|
}
|
|
268
281
|
break;
|
|
269
282
|
}
|
|
270
|
-
case "tool-input-end":
|
|
283
|
+
case "tool-input-end":
|
|
271
284
|
break;
|
|
272
|
-
}
|
|
273
285
|
case "tool-input-available": {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
...inputPart.toolCall,
|
|
284
|
-
arguments: toolCall.arguments,
|
|
285
|
-
status: "available"
|
|
286
|
-
};
|
|
287
|
-
setStreamingParts([...parts]);
|
|
288
|
-
}
|
|
289
|
-
if (activeBlock) {
|
|
290
|
-
setExecutionBlocks([...blocks]);
|
|
291
|
-
}
|
|
286
|
+
const toolPartIndex = state.parts.findIndex(
|
|
287
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
288
|
+
);
|
|
289
|
+
if (toolPartIndex >= 0) {
|
|
290
|
+
const part = state.parts[toolPartIndex];
|
|
291
|
+
part.args = event.input;
|
|
292
|
+
part.status = "running";
|
|
293
|
+
state.parts[toolPartIndex] = { ...part };
|
|
294
|
+
updateStreamingMessage();
|
|
292
295
|
}
|
|
293
296
|
break;
|
|
294
297
|
}
|
|
295
298
|
case "tool-output-available": {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
...resultPart.toolCall,
|
|
306
|
-
status: "available",
|
|
307
|
-
result: event.output
|
|
308
|
-
};
|
|
309
|
-
setStreamingParts([...parts]);
|
|
310
|
-
}
|
|
311
|
-
if (activeBlock) {
|
|
312
|
-
setExecutionBlocks([...blocks]);
|
|
313
|
-
}
|
|
299
|
+
const toolPartIndex = state.parts.findIndex(
|
|
300
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
301
|
+
);
|
|
302
|
+
if (toolPartIndex >= 0) {
|
|
303
|
+
const part = state.parts[toolPartIndex];
|
|
304
|
+
part.result = event.output;
|
|
305
|
+
part.status = "done";
|
|
306
|
+
state.parts[toolPartIndex] = { ...part };
|
|
307
|
+
updateStreamingMessage();
|
|
314
308
|
}
|
|
315
309
|
break;
|
|
316
310
|
}
|
|
317
311
|
case "tool-output-error": {
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
...errorPart.toolCall,
|
|
328
|
-
status: "error",
|
|
329
|
-
error: event.errorText
|
|
330
|
-
};
|
|
331
|
-
setStreamingParts([...parts]);
|
|
332
|
-
}
|
|
333
|
-
if (activeBlock) {
|
|
334
|
-
setExecutionBlocks([...blocks]);
|
|
335
|
-
}
|
|
312
|
+
const toolPartIndex = state.parts.findIndex(
|
|
313
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
314
|
+
);
|
|
315
|
+
if (toolPartIndex >= 0) {
|
|
316
|
+
const part = state.parts[toolPartIndex];
|
|
317
|
+
part.error = event.errorText;
|
|
318
|
+
part.status = "error";
|
|
319
|
+
state.parts[toolPartIndex] = { ...part };
|
|
320
|
+
updateStreamingMessage();
|
|
336
321
|
}
|
|
337
322
|
break;
|
|
338
323
|
}
|
|
@@ -340,46 +325,25 @@ function useOctavusChat(options) {
|
|
|
340
325
|
onResourceUpdate?.(event.name, event.value);
|
|
341
326
|
break;
|
|
342
327
|
case "finish": {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
parts.splice(ctx.partIndex, 1);
|
|
328
|
+
const finalMessage = buildMessageFromState(state, "done");
|
|
329
|
+
finalMessage.parts = finalMessage.parts.map((part) => {
|
|
330
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
331
|
+
return { ...part, status: "done" };
|
|
348
332
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
reasoning: b.reasoning || void 0,
|
|
360
|
-
toolCalls: b.toolCalls.length > 0 ? b.toolCalls : void 0,
|
|
361
|
-
thread: b.thread
|
|
362
|
-
}));
|
|
363
|
-
if (visibleFullText || executionSteps.length > 0 || executionReasoningText) {
|
|
364
|
-
const assistantMessage = {
|
|
365
|
-
id: generateId(),
|
|
366
|
-
role: "assistant",
|
|
367
|
-
content: visibleFullText,
|
|
368
|
-
toolCalls: toolCalls.filter((tc) => tc.status === "available"),
|
|
369
|
-
executionSteps: executionSteps.length > 0 ? executionSteps : void 0,
|
|
370
|
-
parts: parts.length > 0 ? parts : void 0,
|
|
371
|
-
reasoning: executionReasoningText || void 0,
|
|
372
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
373
|
-
};
|
|
374
|
-
setMessages((prev) => [...prev, assistantMessage]);
|
|
375
|
-
onMessage?.(assistantMessage);
|
|
333
|
+
return part;
|
|
334
|
+
});
|
|
335
|
+
if (finalMessage.parts.length > 0) {
|
|
336
|
+
setMessages((prev) => {
|
|
337
|
+
const lastMsg = prev[prev.length - 1];
|
|
338
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
339
|
+
return [...prev.slice(0, -1), finalMessage];
|
|
340
|
+
}
|
|
341
|
+
return [...prev, finalMessage];
|
|
342
|
+
});
|
|
376
343
|
}
|
|
377
344
|
setStatus("idle");
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
setExecutionBlocks([]);
|
|
381
|
-
setReasoningText("");
|
|
382
|
-
onDone?.();
|
|
345
|
+
streamingStateRef.current = null;
|
|
346
|
+
onFinish?.();
|
|
383
347
|
break;
|
|
384
348
|
}
|
|
385
349
|
case "error":
|
|
@@ -392,44 +356,46 @@ function useOctavusChat(options) {
|
|
|
392
356
|
const errorObj = err instanceof Error ? err : new Error("Unknown error");
|
|
393
357
|
setError(errorObj);
|
|
394
358
|
setStatus("error");
|
|
395
|
-
|
|
396
|
-
activeBlock.status = "error";
|
|
397
|
-
setExecutionBlocks([...blocks]);
|
|
398
|
-
}
|
|
359
|
+
streamingStateRef.current = null;
|
|
399
360
|
onError?.(errorObj);
|
|
400
361
|
} finally {
|
|
401
362
|
abortControllerRef.current = null;
|
|
402
363
|
}
|
|
403
364
|
},
|
|
404
|
-
[onTrigger,
|
|
405
|
-
);
|
|
406
|
-
const addUserMessage = useCallback(
|
|
407
|
-
(content) => {
|
|
408
|
-
const userMessage = {
|
|
409
|
-
id: generateId(),
|
|
410
|
-
role: "user",
|
|
411
|
-
content,
|
|
412
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
413
|
-
};
|
|
414
|
-
setMessages((prev) => [...prev, userMessage]);
|
|
415
|
-
onMessage?.(userMessage);
|
|
416
|
-
},
|
|
417
|
-
[onMessage]
|
|
365
|
+
[onTrigger, onError, onFinish, onResourceUpdate, updateStreamingMessage]
|
|
418
366
|
);
|
|
367
|
+
const stop = useCallback(() => {
|
|
368
|
+
abortControllerRef.current?.abort();
|
|
369
|
+
abortControllerRef.current = null;
|
|
370
|
+
const state = streamingStateRef.current;
|
|
371
|
+
if (state && state.parts.length > 0) {
|
|
372
|
+
const finalMessage = buildMessageFromState(state, "done");
|
|
373
|
+
setMessages((prev) => {
|
|
374
|
+
const lastMsg = prev[prev.length - 1];
|
|
375
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
376
|
+
return [...prev.slice(0, -1), finalMessage];
|
|
377
|
+
}
|
|
378
|
+
return [...prev, finalMessage];
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
streamingStateRef.current = null;
|
|
382
|
+
setStatus("idle");
|
|
383
|
+
}, []);
|
|
419
384
|
return {
|
|
420
385
|
messages,
|
|
421
386
|
status,
|
|
422
|
-
isLoading: status === "loading" || status === "streaming",
|
|
423
387
|
error,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
streamingText,
|
|
427
|
-
streamingParts,
|
|
428
|
-
executionBlocks,
|
|
429
|
-
reasoningText
|
|
388
|
+
send,
|
|
389
|
+
stop
|
|
430
390
|
};
|
|
431
391
|
}
|
|
392
|
+
|
|
393
|
+
// src/utils/message-helpers.ts
|
|
394
|
+
function isOtherThread(part) {
|
|
395
|
+
return Boolean(part.thread && part.thread !== "main");
|
|
396
|
+
}
|
|
432
397
|
export {
|
|
398
|
+
isOtherThread,
|
|
433
399
|
useOctavusChat
|
|
434
400
|
};
|
|
435
401
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-octavus-chat.ts","../src/stream/reader.ts"],"sourcesContent":["'use client';\n\nimport { useState, useCallback, useRef } from 'react';\nimport { generateId, type ToolCallInfo, type DisplayMode, type MessagePart } from '@octavus/core';\nimport { parseSSEStream } from '@/stream/reader';\n\nexport interface ToolCallWithDescription extends ToolCallInfo {\n description?: string;\n display?: DisplayMode;\n}\n\nexport interface ExecutionStep {\n id: string;\n name: string;\n type: string;\n display: DisplayMode;\n description?: string;\n outputToChat: boolean;\n summary?: string;\n fullOutput?: string;\n reasoning?: string;\n toolCalls?: ToolCallWithDescription[];\n thread?: string;\n}\n\nexport interface Message {\n id: string;\n role: 'user' | 'assistant' | 'system';\n content: string;\n toolCalls?: ToolCallWithDescription[];\n executionSteps?: ExecutionStep[];\n /** If false, message is not shown to user (internal directive) */\n visible?: boolean;\n /** Ordered message parts - single source of truth for display */\n parts?: MessagePart[];\n reasoning?: string;\n createdAt: Date;\n}\n\nexport type BlockStatus = 'pending' | 'running' | 'completed' | 'error';\n\nexport interface ExecutionBlock {\n id: string;\n name: string;\n type: string;\n status: BlockStatus;\n display: DisplayMode;\n description?: string;\n /** False for independent blocks */\n outputToChat: boolean;\n thread?: string;\n streamingText: string;\n summary?: string;\n reasoning?: string;\n toolCalls: ToolCallWithDescription[];\n startedAt: Date;\n completedAt?: Date;\n}\n\nexport type ChatStatus = 'idle' | 'loading' | 'streaming' | 'error';\n\nexport type TriggerFunction = (\n triggerName: string,\n input?: Record<string, unknown>,\n) => Promise<Response>;\n\nexport interface UseOctavusChatOptions {\n onTrigger: TriggerFunction;\n initialMessages?: Message[];\n onMessage?: (message: Message) => void;\n onError?: (error: Error) => void;\n onDone?: () => void;\n onResourceUpdate?: (name: string, value: unknown) => void;\n onBlockStart?: (block: ExecutionBlock) => void;\n onBlockEnd?: (block: ExecutionBlock) => void;\n}\n\nexport interface UseOctavusChatReturn {\n messages: Message[];\n status: ChatStatus;\n isLoading: boolean;\n error: Error | null;\n /**\n * Add a user message to the UI state.\n * Does NOT trigger the agent - call triggerAction() after.\n */\n addUserMessage: (content: string) => void;\n triggerAction: (triggerName: string, input?: Record<string, unknown>) => Promise<void>;\n streamingText: string;\n /** Streaming parts in MessagePart format - single source of truth */\n streamingParts: MessagePart[];\n executionBlocks: ExecutionBlock[];\n reasoningText: string;\n}\n\ninterface ErrorResponse {\n error?: string;\n message?: string;\n errorText?: string;\n}\n\nasync function parseErrorResponse(response: Response): Promise<string> {\n try {\n const data = (await response.json()) as ErrorResponse;\n return data.error ?? data.errorText ?? data.message ?? `Request failed: ${response.status}`;\n } catch {\n return `Request failed: ${response.status}`;\n }\n}\n\n/**\n * Helper to find or create a text part for the current block\n */\nfunction findOrCreateTextPart(\n parts: MessagePart[],\n thread: string | undefined,\n): { part: MessagePart; index: number } {\n // Look for an existing text part for this thread at the end\n for (let i = parts.length - 1; i >= 0; i--) {\n const part = parts[i];\n if (!part) continue;\n if (part.type === 'text' && part.thread === thread) {\n return { part, index: i };\n }\n // If we hit a different part type, stop looking\n if (part.type !== 'text') break;\n }\n // Create new text part\n const newPart: MessagePart = {\n type: 'text',\n visible: true,\n content: '',\n thread,\n };\n parts.push(newPart);\n return { part: newPart, index: parts.length - 1 };\n}\n\nexport function useOctavusChat(options: UseOctavusChatOptions): UseOctavusChatReturn {\n const {\n onTrigger,\n initialMessages = [],\n onMessage,\n onError,\n onDone,\n onResourceUpdate,\n onBlockStart,\n onBlockEnd,\n } = options;\n\n const [messages, setMessages] = useState<Message[]>(initialMessages);\n const [status, setStatus] = useState<ChatStatus>('idle');\n const [error, setError] = useState<Error | null>(null);\n const [streamingText, setStreamingText] = useState('');\n const [streamingParts, setStreamingParts] = useState<MessagePart[]>([]);\n const [executionBlocks, setExecutionBlocks] = useState<ExecutionBlock[]>([]);\n const [reasoningText, setReasoningText] = useState('');\n\n const abortControllerRef = useRef<AbortController | null>(null);\n\n const triggerAction = useCallback(\n async (triggerName: string, input?: Record<string, unknown>) => {\n // Abort any previous request\n abortControllerRef.current?.abort();\n abortControllerRef.current = null;\n\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n setStatus('loading');\n setError(null);\n setStreamingText('');\n setStreamingParts([]);\n setExecutionBlocks([]);\n setReasoningText('');\n\n const blocks: ExecutionBlock[] = [];\n let activeBlock: ExecutionBlock | null = null;\n const toolCalls: ToolCallInfo[] = [];\n\n let visibleFullText = '';\n let executionReasoningText = '';\n\n interface ReasoningContext {\n id: string;\n outputToChat: boolean;\n partIndex: number;\n }\n const reasoningStack: ReasoningContext[] = [];\n const getCurrentReasoning = () => reasoningStack[reasoningStack.length - 1];\n\n // Build MessagePart[] directly during streaming\n const parts: MessagePart[] = [];\n\n try {\n const response = await onTrigger(triggerName, input);\n\n if (!response.ok) {\n const errorMessage = await parseErrorResponse(response);\n throw new Error(errorMessage);\n }\n\n setStatus('streaming');\n\n for await (const event of parseSSEStream(response)) {\n if (abortController.signal.aborted) {\n break;\n }\n\n switch (event.type) {\n case 'start':\n break;\n\n case 'block-start': {\n const newBlock: ExecutionBlock = {\n id: event.blockId,\n name: event.blockName,\n type: event.blockType,\n status: 'running',\n display: event.display,\n description: event.description,\n outputToChat: event.outputToChat ?? false,\n thread: event.thread,\n streamingText: '',\n toolCalls: [],\n startedAt: new Date(),\n };\n blocks.push(newBlock);\n activeBlock = newBlock;\n setExecutionBlocks([...blocks]);\n onBlockStart?.(newBlock);\n break;\n }\n\n case 'block-end': {\n if (activeBlock && activeBlock.id === event.blockId) {\n activeBlock.status = 'completed';\n activeBlock.summary = event.summary;\n activeBlock.completedAt = new Date();\n setExecutionBlocks([...blocks]);\n onBlockEnd?.(activeBlock);\n activeBlock = null;\n }\n break;\n }\n\n case 'text-delta':\n if (activeBlock) {\n activeBlock.streamingText += event.delta;\n setExecutionBlocks([...blocks]);\n\n // Capture text if outputToChat OR non-main thread\n const isNonMainThread =\n activeBlock.thread !== undefined && activeBlock.thread !== 'main';\n const shouldCaptureText = activeBlock.outputToChat || isNonMainThread;\n\n if (shouldCaptureText) {\n const { part, index } = findOrCreateTextPart(parts, activeBlock.thread);\n part.content = (part.content ?? '') + event.delta;\n parts[index] = { ...part };\n\n if (activeBlock.outputToChat) {\n visibleFullText += event.delta;\n setStreamingText(visibleFullText);\n }\n\n setStreamingParts([...parts]);\n }\n }\n break;\n\n case 'text-start':\n case 'text-end':\n break;\n\n case 'reasoning-start': {\n // Non-main threads always capture content (shown as orange cards)\n const isNonMainThread =\n activeBlock?.thread !== undefined && activeBlock.thread !== 'main';\n const shouldCapture = (activeBlock?.outputToChat ?? false) || isNonMainThread;\n\n const newPart: MessagePart = {\n type: 'reasoning',\n visible: false,\n content: '',\n thread: activeBlock?.thread,\n };\n parts.push(newPart);\n\n reasoningStack.push({\n id: event.id,\n outputToChat: shouldCapture,\n partIndex: parts.length - 1,\n });\n\n setReasoningText('');\n break;\n }\n\n case 'reasoning-delta': {\n const ctx = getCurrentReasoning();\n const reasoningPart = ctx ? parts[ctx.partIndex] : undefined;\n if (ctx && reasoningPart) {\n reasoningPart.content = (reasoningPart.content ?? '') + event.delta;\n parts[ctx.partIndex] = { ...reasoningPart };\n }\n\n if (activeBlock?.outputToChat) {\n executionReasoningText += event.delta;\n }\n setReasoningText((prev) => prev + event.delta);\n\n if (activeBlock) {\n activeBlock.reasoning = (activeBlock.reasoning ?? '') + event.delta;\n setExecutionBlocks([...blocks]);\n }\n\n if (ctx?.outputToChat) {\n setStreamingParts([...parts]);\n }\n break;\n }\n\n case 'reasoning-end': {\n const ctx = reasoningStack.pop();\n setReasoningText('');\n\n const endReasoningPart = ctx ? parts[ctx.partIndex] : undefined;\n if (ctx && endReasoningPart && !endReasoningPart.content?.trim()) {\n parts.splice(ctx.partIndex, 1);\n }\n\n // Update streaming parts\n if (ctx?.outputToChat) {\n setStreamingParts([...parts]);\n }\n break;\n }\n\n case 'tool-input-start': {\n const newToolCall: ToolCallWithDescription = {\n id: event.toolCallId,\n name: event.toolName,\n arguments: {},\n status: 'streaming',\n description: event.title,\n };\n toolCalls.push(newToolCall);\n\n if (activeBlock) {\n activeBlock.toolCalls = [...activeBlock.toolCalls, newToolCall];\n setExecutionBlocks([...blocks]);\n }\n\n // Add tool call part (visible unless hidden block)\n const isVisibleBlock = activeBlock?.display !== 'hidden';\n if (isVisibleBlock) {\n const toolPart: MessagePart = {\n type: 'tool-call',\n visible: true,\n toolCall: newToolCall,\n thread: activeBlock?.thread,\n };\n parts.push(toolPart);\n setStreamingParts([...parts]);\n }\n break;\n }\n\n case 'tool-input-delta': {\n const toolCall = toolCalls.find((tc) => tc.id === event.toolCallId);\n if (toolCall) {\n try {\n toolCall.arguments = JSON.parse(event.inputTextDelta) as Record<string, unknown>;\n } catch {\n // Partial args may not be valid JSON yet\n }\n\n const argsPart = parts.find(\n (p) => p.type === 'tool-call' && p.toolCall?.id === event.toolCallId,\n );\n if (argsPart?.toolCall) {\n argsPart.toolCall = { ...argsPart.toolCall, arguments: toolCall.arguments };\n setStreamingParts([...parts]);\n }\n\n if (activeBlock) {\n setExecutionBlocks([...blocks]);\n }\n }\n break;\n }\n\n case 'tool-input-end': {\n // Tool input streaming has ended - no action needed\n // The full input is available in tool-input-available\n break;\n }\n\n case 'tool-input-available': {\n const toolCall = toolCalls.find((tc) => tc.id === event.toolCallId);\n if (toolCall) {\n toolCall.arguments = event.input as Record<string, unknown>;\n toolCall.status = 'available';\n\n const inputPart = parts.find(\n (p) => p.type === 'tool-call' && p.toolCall?.id === event.toolCallId,\n );\n if (inputPart?.toolCall) {\n inputPart.toolCall = {\n ...inputPart.toolCall,\n arguments: toolCall.arguments,\n status: 'available',\n };\n setStreamingParts([...parts]);\n }\n\n if (activeBlock) {\n setExecutionBlocks([...blocks]);\n }\n }\n break;\n }\n\n case 'tool-output-available': {\n const toolCall = toolCalls.find((tc) => tc.id === event.toolCallId);\n if (toolCall) {\n toolCall.status = 'available';\n toolCall.result = event.output;\n\n const resultPart = parts.find(\n (p) => p.type === 'tool-call' && p.toolCall?.id === event.toolCallId,\n );\n if (resultPart?.toolCall) {\n resultPart.toolCall = {\n ...resultPart.toolCall,\n status: 'available',\n result: event.output,\n };\n setStreamingParts([...parts]);\n }\n\n if (activeBlock) {\n setExecutionBlocks([...blocks]);\n }\n }\n break;\n }\n\n case 'tool-output-error': {\n const toolCall = toolCalls.find((tc) => tc.id === event.toolCallId);\n if (toolCall) {\n toolCall.status = 'error';\n toolCall.error = event.errorText;\n\n const errorPart = parts.find(\n (p) => p.type === 'tool-call' && p.toolCall?.id === event.toolCallId,\n );\n if (errorPart?.toolCall) {\n errorPart.toolCall = {\n ...errorPart.toolCall,\n status: 'error',\n error: event.errorText,\n };\n setStreamingParts([...parts]);\n }\n\n if (activeBlock) {\n setExecutionBlocks([...blocks]);\n }\n }\n break;\n }\n\n case 'resource-update':\n onResourceUpdate?.(event.name, event.value);\n break;\n\n case 'finish': {\n while (reasoningStack.length > 0) {\n const ctx = reasoningStack.pop();\n const remainingPart = ctx ? parts[ctx.partIndex] : undefined;\n if (ctx && remainingPart && !remainingPart.content?.trim()) {\n parts.splice(ctx.partIndex, 1);\n }\n }\n\n const executionSteps: ExecutionStep[] = blocks\n .filter((b) => b.status === 'completed')\n .map((b) => ({\n id: b.id,\n name: b.name,\n type: b.type,\n display: b.display,\n description: b.description,\n outputToChat: b.outputToChat,\n summary: b.summary,\n fullOutput: b.streamingText || undefined,\n reasoning: b.reasoning || undefined,\n toolCalls: b.toolCalls.length > 0 ? b.toolCalls : undefined,\n thread: b.thread,\n }));\n\n if (visibleFullText || executionSteps.length > 0 || executionReasoningText) {\n const assistantMessage: Message = {\n id: generateId(),\n role: 'assistant',\n content: visibleFullText,\n toolCalls: toolCalls.filter((tc) => tc.status === 'available'),\n executionSteps: executionSteps.length > 0 ? executionSteps : undefined,\n parts: parts.length > 0 ? parts : undefined,\n reasoning: executionReasoningText || undefined,\n createdAt: new Date(),\n };\n setMessages((prev) => [...prev, assistantMessage]);\n onMessage?.(assistantMessage);\n }\n setStatus('idle');\n setStreamingText('');\n setStreamingParts([]);\n setExecutionBlocks([]);\n setReasoningText('');\n onDone?.();\n break;\n }\n\n case 'error':\n throw new Error(event.errorText);\n\n case 'tool-request':\n // Handled by server-sdk, should not reach client\n break;\n }\n }\n } catch (err) {\n const errorObj = err instanceof Error ? err : new Error('Unknown error');\n setError(errorObj);\n setStatus('error');\n\n if (activeBlock) {\n activeBlock.status = 'error';\n setExecutionBlocks([...blocks]);\n }\n\n onError?.(errorObj);\n } finally {\n abortControllerRef.current = null;\n }\n },\n [onTrigger, onMessage, onError, onDone, onResourceUpdate, onBlockStart, onBlockEnd],\n );\n\n const addUserMessage = useCallback(\n (content: string) => {\n const userMessage: Message = {\n id: generateId(),\n role: 'user',\n content,\n createdAt: new Date(),\n };\n setMessages((prev) => [...prev, userMessage]);\n onMessage?.(userMessage);\n },\n [onMessage],\n );\n\n return {\n messages,\n status,\n isLoading: status === 'loading' || status === 'streaming',\n error,\n addUserMessage,\n triggerAction,\n streamingText,\n streamingParts,\n executionBlocks,\n reasoningText,\n };\n}\n","import { safeParseStreamEvent, type StreamEvent } from '@octavus/core';\n\n/**\n * Parse SSE stream events\n */\nexport async function* parseSSEStream(\n response: Response,\n): AsyncGenerator<StreamEvent, void, unknown> {\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('Response body is not readable');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n let reading = true;\n while (reading) {\n const { done, value } = await reader.read();\n\n if (done) {\n reading = false;\n continue;\n }\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ') && line !== 'data: [DONE]') {\n try {\n const parsed = safeParseStreamEvent(JSON.parse(line.slice(6)));\n if (parsed.success) {\n yield parsed.data;\n }\n // Skip malformed events silently\n } catch {\n // Skip malformed JSON - no logging in production\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n"],"mappings":";AAEA,SAAS,UAAU,aAAa,cAAc;AAC9C,SAAS,kBAAyE;;;ACHlF,SAAS,4BAA8C;AAKvD,gBAAuB,eACrB,UAC4C;AAC5C,QAAM,SAAS,SAAS,MAAM,UAAU;AACxC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,QAAM,UAAU,IAAI,YAAY;AAChC,MAAI,SAAS;AAEb,MAAI;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AACnB,YAAM,cAAuB;AAAA,QAC3B,IAAI,WAAW;AAAA,QACf,MAAM;AAAA,QACN;AAAA,QACA,WAAW,oBAAI,KAAK;AAAA,MACtB;AACA,kBAAY,CAAC,SAAS,CAAC,GAAG,MAAM,WAAW,CAAC;AAC5C,kBAAY,WAAW;AAAA,IACzB;AAAA,IACA,CAAC,SAAS;AAAA,EACZ;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,WAAW,WAAW,aAAa,WAAW;AAAA,IAC9C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-octavus-chat.ts","../src/stream/reader.ts","../src/utils/message-helpers.ts"],"sourcesContent":["'use client';\n\nimport { useState, useCallback, useRef } from 'react';\nimport {\n generateId,\n type UIMessage,\n type UIMessagePart,\n type UITextPart,\n type UIReasoningPart,\n type UIToolCallPart,\n type UIOperationPart,\n type DisplayMode,\n} from '@octavus/core';\nimport { parseSSEStream } from '@/stream/reader';\n\n/** Block types that are internal operations (not LLM-driven) */\nconst OPERATION_BLOCK_TYPES = new Set(['set-resource', 'serialize-thread']);\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type ChatStatus = 'idle' | 'streaming' | 'error';\n\nexport type TriggerFunction = (\n triggerName: string,\n input?: Record<string, unknown>,\n) => Promise<Response>;\n\n/**\n * Input for creating a user message.\n * Currently supports text content. Will be extended to support attachments, images, etc.\n */\nexport interface UserMessageInput {\n /** Text content of the message */\n content: string;\n}\n\nexport interface UseOctavusChatOptions {\n /** Function to make the API call to trigger the agent */\n onTrigger: TriggerFunction;\n /** Initial messages (for session refresh) */\n initialMessages?: UIMessage[];\n /** Callback when an error occurs */\n onError?: (error: Error) => void;\n /** Callback when streaming finishes */\n onFinish?: () => void;\n /** Callback when a resource is updated */\n onResourceUpdate?: (name: string, value: unknown) => void;\n}\n\nexport interface UseOctavusChatReturn {\n /** All messages including the currently streaming one */\n messages: UIMessage[];\n /** Current status of the chat */\n status: ChatStatus;\n /** Error if status is 'error' */\n error: Error | null;\n /**\n * Trigger the agent and optionally add a user message to the chat.\n *\n * @param triggerName - The trigger name defined in the agent's protocol.yaml\n * @param input - Input parameters for the trigger (variable substitutions)\n * @param options.userMessage - If provided, adds a user message to the chat before triggering\n */\n send: (\n triggerName: string,\n input?: Record<string, unknown>,\n options?: { userMessage?: UserMessageInput },\n ) => Promise<void>;\n /** Stop the current streaming and finalize any partial message */\n stop: () => void;\n}\n\n// =============================================================================\n// Internal Types\n// =============================================================================\n\ninterface BlockState {\n blockId: string;\n blockName: string;\n blockType: string;\n display: DisplayMode;\n description?: string;\n outputToChat: boolean;\n thread?: string;\n reasoning: string;\n text: string;\n toolCalls: Map<string, UIToolCallPart>;\n}\n\ninterface StreamingState {\n messageId: string;\n parts: UIMessagePart[];\n activeBlock: BlockState | null;\n blocks: Map<string, BlockState>;\n // Track current text/reasoning part indices for delta updates\n currentTextPartIndex: number | null;\n currentReasoningPartIndex: number | null;\n}\n\n// =============================================================================\n// Helpers\n// =============================================================================\n\nasync function parseErrorResponse(response: Response): Promise<string> {\n try {\n const data = (await response.json()) as { error?: string; message?: string };\n return data.error ?? data.message ?? `Request failed: ${response.status}`;\n } catch {\n return `Request failed: ${response.status}`;\n }\n}\n\nfunction createUserMessage(input: UserMessageInput): UIMessage {\n return {\n id: generateId(),\n role: 'user',\n parts: [{ type: 'text', text: input.content, status: 'done' }],\n status: 'done',\n createdAt: new Date(),\n };\n}\n\nfunction createEmptyStreamingState(): StreamingState {\n return {\n messageId: generateId(),\n parts: [],\n activeBlock: null,\n blocks: new Map(),\n currentTextPartIndex: null,\n currentReasoningPartIndex: null,\n };\n}\n\nfunction buildMessageFromState(state: StreamingState, status: 'streaming' | 'done'): UIMessage {\n return {\n id: state.messageId,\n role: 'assistant',\n parts: [...state.parts],\n status,\n createdAt: new Date(),\n };\n}\n\n// =============================================================================\n// Hook Implementation\n// =============================================================================\n\nexport function useOctavusChat(options: UseOctavusChatOptions): UseOctavusChatReturn {\n const { onTrigger, initialMessages = [], onError, onFinish, onResourceUpdate } = options;\n\n const [messages, setMessages] = useState<UIMessage[]>(initialMessages);\n const [status, setStatus] = useState<ChatStatus>('idle');\n const [error, setError] = useState<Error | null>(null);\n\n const abortControllerRef = useRef<AbortController | null>(null);\n const streamingStateRef = useRef<StreamingState | null>(null);\n\n const updateStreamingMessage = useCallback(() => {\n const state = streamingStateRef.current;\n if (!state) return;\n\n const msg = buildMessageFromState(state, 'streaming');\n setMessages((prev) => {\n const lastMsg = prev[prev.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n // Update existing streaming message\n return [...prev.slice(0, -1), msg];\n }\n // Add new streaming message\n return [...prev, msg];\n });\n }, []);\n\n const send = useCallback(\n async (\n triggerName: string,\n input?: Record<string, unknown>,\n sendOptions?: { userMessage?: UserMessageInput },\n ) => {\n // Abort any previous request\n abortControllerRef.current?.abort();\n\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n // Add user message if provided\n if (sendOptions?.userMessage !== undefined) {\n const userMsg = createUserMessage(sendOptions.userMessage);\n setMessages((prev) => [...prev, userMsg]);\n }\n\n // Reset state\n setStatus('streaming');\n setError(null);\n streamingStateRef.current = createEmptyStreamingState();\n\n try {\n const response = await onTrigger(triggerName, input);\n\n if (!response.ok) {\n const errorMessage = await parseErrorResponse(response);\n throw new Error(errorMessage);\n }\n\n for await (const event of parseSSEStream(response)) {\n if (abortController.signal.aborted) {\n break;\n }\n\n const state: StreamingState | null = streamingStateRef.current;\n if (!state) break;\n\n switch (event.type) {\n case 'start':\n break;\n\n case 'block-start': {\n const block: BlockState = {\n blockId: event.blockId,\n blockName: event.blockName,\n blockType: event.blockType,\n display: event.display,\n description: event.description,\n outputToChat: event.outputToChat ?? true,\n thread: event.thread,\n reasoning: '',\n text: '',\n toolCalls: new Map(),\n };\n state.blocks.set(event.blockId, block);\n state.activeBlock = block;\n\n // Create operation part for internal operation blocks (if not hidden)\n const isOperation = OPERATION_BLOCK_TYPES.has(event.blockType);\n const isHidden = event.display === 'hidden';\n if (isOperation && !isHidden) {\n const thread = event.thread;\n const operationPart: UIOperationPart = {\n type: 'operation',\n operationId: event.blockId,\n name: event.description || event.blockName,\n operationType: event.blockType,\n status: 'running',\n thread: thread && thread !== 'main' ? thread : undefined,\n };\n state.parts.push(operationPart);\n }\n\n state.currentTextPartIndex = null;\n state.currentReasoningPartIndex = null;\n\n updateStreamingMessage();\n break;\n }\n\n case 'block-end': {\n // Mark operation part as done if it exists\n const operationPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'operation' && p.operationId === event.blockId,\n );\n if (operationPartIndex >= 0) {\n const part = state.parts[operationPartIndex] as UIOperationPart;\n state.parts[operationPartIndex] = { ...part, status: 'done' };\n }\n\n if (state.activeBlock?.blockId === event.blockId) {\n state.activeBlock = null;\n }\n updateStreamingMessage();\n break;\n }\n\n case 'reasoning-start': {\n const thread = state.activeBlock?.thread;\n const reasoningPart: UIReasoningPart = {\n type: 'reasoning',\n text: '',\n status: 'streaming',\n thread: thread && thread !== 'main' ? thread : undefined,\n };\n state.parts.push(reasoningPart);\n state.currentReasoningPartIndex = state.parts.length - 1;\n updateStreamingMessage();\n break;\n }\n\n case 'reasoning-delta': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.text += event.delta;\n state.parts[state.currentReasoningPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.reasoning += event.delta;\n }\n\n updateStreamingMessage();\n break;\n }\n\n case 'reasoning-end': {\n if (state.currentReasoningPartIndex !== null) {\n const part = state.parts[state.currentReasoningPartIndex] as UIReasoningPart;\n part.status = 'done';\n state.parts[state.currentReasoningPartIndex] = { ...part };\n state.currentReasoningPartIndex = null;\n }\n updateStreamingMessage();\n break;\n }\n\n case 'text-start': {\n const thread = state.activeBlock?.thread;\n const isOtherThread = Boolean(thread && thread !== 'main');\n const shouldAddPart = state.activeBlock?.outputToChat !== false || isOtherThread;\n\n if (shouldAddPart) {\n const textPart: UITextPart = {\n type: 'text',\n text: '',\n status: 'streaming',\n thread: isOtherThread ? thread : undefined,\n };\n state.parts.push(textPart);\n state.currentTextPartIndex = state.parts.length - 1;\n }\n updateStreamingMessage();\n break;\n }\n\n case 'text-delta': {\n if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.text += event.delta;\n state.parts[state.currentTextPartIndex] = { ...part };\n }\n\n if (state.activeBlock) {\n state.activeBlock.text += event.delta;\n }\n\n updateStreamingMessage();\n break;\n }\n\n case 'text-end': {\n if (state.currentTextPartIndex !== null) {\n const part = state.parts[state.currentTextPartIndex] as UITextPart;\n part.status = 'done';\n state.parts[state.currentTextPartIndex] = { ...part };\n state.currentTextPartIndex = null;\n }\n updateStreamingMessage();\n break;\n }\n\n case 'tool-input-start': {\n const thread = state.activeBlock?.thread;\n const toolPart: UIToolCallPart = {\n type: 'tool-call',\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n displayName: event.title,\n args: {},\n status: 'pending',\n thread: thread && thread !== 'main' ? thread : undefined,\n };\n state.parts.push(toolPart);\n\n if (state.activeBlock) {\n state.activeBlock.toolCalls.set(event.toolCallId, toolPart);\n }\n\n updateStreamingMessage();\n break;\n }\n\n case 'tool-input-delta': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n try {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = JSON.parse(event.inputTextDelta) as Record<string, unknown>;\n state.parts[toolPartIndex] = { ...part };\n updateStreamingMessage();\n } catch {\n // Partial JSON, ignore\n }\n }\n break;\n }\n\n case 'tool-input-end':\n break;\n\n case 'tool-input-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.args = event.input as Record<string, unknown>;\n part.status = 'running';\n state.parts[toolPartIndex] = { ...part };\n updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-available': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.result = event.output;\n part.status = 'done';\n state.parts[toolPartIndex] = { ...part };\n updateStreamingMessage();\n }\n break;\n }\n\n case 'tool-output-error': {\n const toolPartIndex = state.parts.findIndex(\n (p: UIMessagePart) => p.type === 'tool-call' && p.toolCallId === event.toolCallId,\n );\n if (toolPartIndex >= 0) {\n const part = state.parts[toolPartIndex] as UIToolCallPart;\n part.error = event.errorText;\n part.status = 'error';\n state.parts[toolPartIndex] = { ...part };\n updateStreamingMessage();\n }\n break;\n }\n\n case 'resource-update':\n onResourceUpdate?.(event.name, event.value);\n break;\n\n case 'finish': {\n const finalMessage = buildMessageFromState(state, 'done');\n\n finalMessage.parts = finalMessage.parts.map((part) => {\n if (part.type === 'text' || part.type === 'reasoning') {\n return { ...part, status: 'done' as const };\n }\n return part;\n });\n\n if (finalMessage.parts.length > 0) {\n setMessages((prev) => {\n const lastMsg = prev[prev.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n return [...prev.slice(0, -1), finalMessage];\n }\n return [...prev, finalMessage];\n });\n }\n\n setStatus('idle');\n streamingStateRef.current = null;\n onFinish?.();\n break;\n }\n\n case 'error':\n throw new Error(event.errorText);\n\n case 'tool-request':\n // Handled by server-sdk\n break;\n }\n }\n } catch (err) {\n const errorObj = err instanceof Error ? err : new Error('Unknown error');\n setError(errorObj);\n setStatus('error');\n streamingStateRef.current = null;\n onError?.(errorObj);\n } finally {\n abortControllerRef.current = null;\n }\n },\n [onTrigger, onError, onFinish, onResourceUpdate, updateStreamingMessage],\n );\n\n const stop = useCallback(() => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = null;\n\n const state = streamingStateRef.current;\n if (state && state.parts.length > 0) {\n const finalMessage = buildMessageFromState(state, 'done');\n setMessages((prev) => {\n const lastMsg = prev[prev.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n return [...prev.slice(0, -1), finalMessage];\n }\n return [...prev, finalMessage];\n });\n }\n\n streamingStateRef.current = null;\n setStatus('idle');\n }, []);\n\n return {\n messages,\n status,\n error,\n send,\n stop,\n };\n}\n","import { safeParseStreamEvent, type StreamEvent } from '@octavus/core';\n\n/**\n * Parse SSE stream events\n */\nexport async function* parseSSEStream(\n response: Response,\n): AsyncGenerator<StreamEvent, void, unknown> {\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('Response body is not readable');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n try {\n let reading = true;\n while (reading) {\n const { done, value } = await reader.read();\n\n if (done) {\n reading = false;\n continue;\n }\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ') && line !== 'data: [DONE]') {\n try {\n const parsed = safeParseStreamEvent(JSON.parse(line.slice(6)));\n if (parsed.success) {\n yield parsed.data;\n }\n // Skip malformed events silently\n } catch {\n // Skip malformed JSON - no logging in production\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n","import type { UIMessagePart } from '@octavus/core';\n\n/** Non-main thread content (e.g., \"summary\") is typically displayed differently. */\nexport function isOtherThread(part: UIMessagePart): boolean {\n return Boolean(part.thread && part.thread !== 'main');\n}\n"],"mappings":";AAEA,SAAS,UAAU,aAAa,cAAc;AAC9C;AAAA,EACE;AAAA,OAQK;;;ACZP,SAAS,4BAA8C;AAKvD,gBAAuB,eACrB,UAC4C;AAC5C,QAAM,SAAS,SAAS,MAAM,UAAU;AACxC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MA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AAe,QAAQ,MAAM,IAAI,MAAM,eAAe;AACvE,iBAAS,QAAQ;AACjB,kBAAU,OAAO;AACjB,0BAAkB,UAAU;AAC5B,kBAAU,QAAQ;AAAA,MACpB,UAAE;AACA,2BAAmB,UAAU;AAAA,MAC/B;AAAA,IACF;AAAA,IACA,CAAC,WAAW,SAAS,UAAU,kBAAkB,sBAAsB;AAAA,EACzE;AAEA,QAAM,OAAO,YAAY,MAAM;AAC7B,uBAAmB,SAAS,MAAM;AAClC,uBAAmB,UAAU;AAE7B,UAAM,QAAQ,kBAAkB;AAChC,QAAI,SAAS,MAAM,MAAM,SAAS,GAAG;AACnC,YAAM,eAAe,sBAAsB,OAAO,MAAM;AACxD,kBAAY,CAAC,SAAS;AACpB,cAAM,UAAU,KAAK,KAAK,SAAS,CAAC;AACpC,YAAI,WAAW,QAAQ,OAAO,MAAM,WAAW;AAC7C,iBAAO,CAAC,GAAG,KAAK,MAAM,GAAG,EAAE,GAAG,YAAY;AAAA,QAC5C;AACA,eAAO,CAAC,GAAG,MAAM,YAAY;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,sBAAkB,UAAU;AAC5B,cAAU,MAAM;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;AErgBO,SAAS,cAAc,MAA8B;AAC1D,SAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,MAAM;AACtD;","names":["isOtherThread"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octavus/client-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Client SDK for streaming Octavus agent responses",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Octavus AI <hello@octavus.ai>",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@octavus/core": "^0.0.
|
|
32
|
+
"@octavus/core": "^0.0.5"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=18.0.0"
|