@octavus/client-sdk 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/dist/index.d.ts +86 -71
- package/dist/index.js +381 -360
- package/dist/index.js.map +1 -1
- package/package.json +3 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,83 +1,98 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIMessage, StreamEvent, 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
|
-
|
|
35
|
-
|
|
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
|
-
interface UseOctavusChatOptions {
|
|
14
|
+
interface OctavusChatOptions {
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
26
|
+
type Listener = () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Framework-agnostic chat client for Octavus agents.
|
|
29
|
+
* Manages chat state and streaming, allowing reactive frameworks to subscribe to updates.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const chat = new OctavusChat({
|
|
34
|
+
* onTrigger: (triggerName, input) =>
|
|
35
|
+
* fetch('/api/trigger', {
|
|
36
|
+
* method: 'POST',
|
|
37
|
+
* body: JSON.stringify({ sessionId, triggerName, input }),
|
|
38
|
+
* }),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Subscribe to updates
|
|
42
|
+
* const unsubscribe = chat.subscribe(() => {
|
|
43
|
+
* console.log('Messages:', chat.messages);
|
|
44
|
+
* console.log('Status:', chat.status);
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Send a message
|
|
48
|
+
* await chat.send('user-message', { USER_MESSAGE: 'Hello' }, { userMessage: { content: 'Hello' } });
|
|
49
|
+
*
|
|
50
|
+
* // Cleanup
|
|
51
|
+
* unsubscribe();
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare class OctavusChat {
|
|
55
|
+
private _messages;
|
|
56
|
+
private _status;
|
|
57
|
+
private _error;
|
|
58
|
+
private options;
|
|
59
|
+
private abortController;
|
|
60
|
+
private streamingState;
|
|
61
|
+
private listeners;
|
|
62
|
+
constructor(options: OctavusChatOptions);
|
|
63
|
+
get messages(): UIMessage[];
|
|
64
|
+
get status(): ChatStatus;
|
|
65
|
+
get error(): Error | null;
|
|
69
66
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
67
|
+
* Subscribe to state changes. The callback is called whenever messages, status, or error changes.
|
|
68
|
+
* @returns Unsubscribe function
|
|
72
69
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
subscribe(listener: Listener): () => void;
|
|
71
|
+
private notifyListeners;
|
|
72
|
+
private setMessages;
|
|
73
|
+
private setStatus;
|
|
74
|
+
private setError;
|
|
75
|
+
/**
|
|
76
|
+
* Trigger the agent and optionally add a user message to the chat.
|
|
77
|
+
*
|
|
78
|
+
* @param triggerName - The trigger name defined in the agent's protocol.yaml
|
|
79
|
+
* @param input - Input parameters for the trigger (variable substitutions)
|
|
80
|
+
* @param options.userMessage - If provided, adds a user message to the chat before triggering
|
|
81
|
+
*/
|
|
82
|
+
send(triggerName: string, input?: Record<string, unknown>, sendOptions?: {
|
|
83
|
+
userMessage?: UserMessageInput;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
/** Stop the current streaming and finalize any partial message */
|
|
86
|
+
stop(): void;
|
|
87
|
+
private updateStreamingMessage;
|
|
80
88
|
}
|
|
81
|
-
declare function useOctavusChat(options: UseOctavusChatOptions): UseOctavusChatReturn;
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Parse SSE stream events
|
|
92
|
+
*/
|
|
93
|
+
declare function parseSSEStream(response: Response): AsyncGenerator<StreamEvent, void, unknown>;
|
|
94
|
+
|
|
95
|
+
/** Non-main thread content (e.g., "summary") is typically displayed differently. */
|
|
96
|
+
declare function isOtherThread(part: UIMessagePart): boolean;
|
|
97
|
+
|
|
98
|
+
export { type ChatStatus, OctavusChat, type OctavusChatOptions, type TriggerFunction, type UserMessageInput, isOtherThread, parseSSEStream };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
// src/chat.ts
|
|
2
|
+
import {
|
|
3
|
+
generateId
|
|
4
|
+
} from "@octavus/core";
|
|
4
5
|
|
|
5
6
|
// src/stream/reader.ts
|
|
6
7
|
import { safeParseStreamEvent } from "@octavus/core";
|
|
@@ -39,397 +40,417 @@ async function* parseSSEStream(response) {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
// src/
|
|
43
|
+
// src/chat.ts
|
|
44
|
+
var OPERATION_BLOCK_TYPES = /* @__PURE__ */ new Set(["set-resource", "serialize-thread"]);
|
|
43
45
|
async function parseErrorResponse(response) {
|
|
44
46
|
try {
|
|
45
47
|
const data = await response.json();
|
|
46
|
-
return data.error ?? data.
|
|
48
|
+
return data.error ?? data.message ?? `Request failed: ${response.status}`;
|
|
47
49
|
} catch {
|
|
48
50
|
return `Request failed: ${response.status}`;
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
function createUserMessage(input) {
|
|
54
|
+
return {
|
|
55
|
+
id: generateId(),
|
|
56
|
+
role: "user",
|
|
57
|
+
parts: [{ type: "text", text: input.content, status: "done" }],
|
|
58
|
+
status: "done",
|
|
59
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function createEmptyStreamingState() {
|
|
63
|
+
return {
|
|
64
|
+
messageId: generateId(),
|
|
65
|
+
parts: [],
|
|
66
|
+
activeBlock: null,
|
|
67
|
+
blocks: /* @__PURE__ */ new Map(),
|
|
68
|
+
currentTextPartIndex: null,
|
|
69
|
+
currentReasoningPartIndex: null
|
|
65
70
|
};
|
|
66
|
-
parts.push(newPart);
|
|
67
|
-
return { part: newPart, index: parts.length - 1 };
|
|
68
71
|
}
|
|
69
|
-
function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
72
|
+
function buildMessageFromState(state, status) {
|
|
73
|
+
return {
|
|
74
|
+
id: state.messageId,
|
|
75
|
+
role: "assistant",
|
|
76
|
+
parts: [...state.parts],
|
|
77
|
+
status,
|
|
78
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var OctavusChat = class {
|
|
82
|
+
// Private state
|
|
83
|
+
_messages;
|
|
84
|
+
_status = "idle";
|
|
85
|
+
_error = null;
|
|
86
|
+
options;
|
|
87
|
+
abortController = null;
|
|
88
|
+
streamingState = null;
|
|
89
|
+
// Listener sets for reactive frameworks
|
|
90
|
+
listeners = /* @__PURE__ */ new Set();
|
|
91
|
+
constructor(options) {
|
|
92
|
+
this.options = options;
|
|
93
|
+
this._messages = options.initialMessages ?? [];
|
|
94
|
+
}
|
|
95
|
+
// =========================================================================
|
|
96
|
+
// Public Getters
|
|
97
|
+
// =========================================================================
|
|
98
|
+
get messages() {
|
|
99
|
+
return this._messages;
|
|
100
|
+
}
|
|
101
|
+
get status() {
|
|
102
|
+
return this._status;
|
|
103
|
+
}
|
|
104
|
+
get error() {
|
|
105
|
+
return this._error;
|
|
106
|
+
}
|
|
107
|
+
// =========================================================================
|
|
108
|
+
// Subscription Methods (for reactive frameworks)
|
|
109
|
+
// =========================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Subscribe to state changes. The callback is called whenever messages, status, or error changes.
|
|
112
|
+
* @returns Unsubscribe function
|
|
113
|
+
*/
|
|
114
|
+
subscribe(listener) {
|
|
115
|
+
this.listeners.add(listener);
|
|
116
|
+
return () => this.listeners.delete(listener);
|
|
117
|
+
}
|
|
118
|
+
notifyListeners() {
|
|
119
|
+
this.listeners.forEach((l) => l());
|
|
120
|
+
}
|
|
121
|
+
// =========================================================================
|
|
122
|
+
// Private Setters (notify listeners)
|
|
123
|
+
// =========================================================================
|
|
124
|
+
setMessages(messages) {
|
|
125
|
+
this._messages = messages;
|
|
126
|
+
this.notifyListeners();
|
|
127
|
+
}
|
|
128
|
+
setStatus(status) {
|
|
129
|
+
this._status = status;
|
|
130
|
+
this.notifyListeners();
|
|
131
|
+
}
|
|
132
|
+
setError(error) {
|
|
133
|
+
this._error = error;
|
|
134
|
+
this.notifyListeners();
|
|
135
|
+
}
|
|
136
|
+
// =========================================================================
|
|
137
|
+
// Public Methods
|
|
138
|
+
// =========================================================================
|
|
139
|
+
/**
|
|
140
|
+
* Trigger the agent and optionally add a user message to the chat.
|
|
141
|
+
*
|
|
142
|
+
* @param triggerName - The trigger name defined in the agent's protocol.yaml
|
|
143
|
+
* @param input - Input parameters for the trigger (variable substitutions)
|
|
144
|
+
* @param options.userMessage - If provided, adds a user message to the chat before triggering
|
|
145
|
+
*/
|
|
146
|
+
async send(triggerName, input, sendOptions) {
|
|
147
|
+
this.abortController?.abort();
|
|
148
|
+
const abortController = new AbortController();
|
|
149
|
+
this.abortController = abortController;
|
|
150
|
+
if (sendOptions?.userMessage !== void 0) {
|
|
151
|
+
const userMsg = createUserMessage(sendOptions.userMessage);
|
|
152
|
+
this.setMessages([...this._messages, userMsg]);
|
|
153
|
+
}
|
|
154
|
+
this.setStatus("streaming");
|
|
155
|
+
this.setError(null);
|
|
156
|
+
this.streamingState = createEmptyStreamingState();
|
|
157
|
+
try {
|
|
158
|
+
const response = await this.options.onTrigger(triggerName, input);
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
const errorMessage = await parseErrorResponse(response);
|
|
161
|
+
throw new Error(errorMessage);
|
|
162
|
+
}
|
|
163
|
+
for await (const event of parseSSEStream(response)) {
|
|
164
|
+
if (abortController.signal.aborted) {
|
|
165
|
+
break;
|
|
113
166
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
167
|
+
const state = this.streamingState;
|
|
168
|
+
if (!state) break;
|
|
169
|
+
switch (event.type) {
|
|
170
|
+
case "start":
|
|
117
171
|
break;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
172
|
+
case "block-start": {
|
|
173
|
+
const block = {
|
|
174
|
+
blockId: event.blockId,
|
|
175
|
+
blockName: event.blockName,
|
|
176
|
+
blockType: event.blockType,
|
|
177
|
+
display: event.display,
|
|
178
|
+
description: event.description,
|
|
179
|
+
outputToChat: event.outputToChat ?? true,
|
|
180
|
+
thread: event.thread,
|
|
181
|
+
reasoning: "",
|
|
182
|
+
text: "",
|
|
183
|
+
toolCalls: /* @__PURE__ */ new Map()
|
|
184
|
+
};
|
|
185
|
+
state.blocks.set(event.blockId, block);
|
|
186
|
+
state.activeBlock = block;
|
|
187
|
+
const isOperation = OPERATION_BLOCK_TYPES.has(event.blockType);
|
|
188
|
+
const isHidden = event.display === "hidden";
|
|
189
|
+
if (isOperation && !isHidden) {
|
|
190
|
+
const thread = event.thread;
|
|
191
|
+
const operationPart = {
|
|
192
|
+
type: "operation",
|
|
193
|
+
operationId: event.blockId,
|
|
194
|
+
name: event.description || event.blockName,
|
|
195
|
+
operationType: event.blockType,
|
|
127
196
|
status: "running",
|
|
128
|
-
|
|
129
|
-
description: event.description,
|
|
130
|
-
outputToChat: event.outputToChat ?? false,
|
|
131
|
-
thread: event.thread,
|
|
132
|
-
streamingText: "",
|
|
133
|
-
toolCalls: [],
|
|
134
|
-
startedAt: /* @__PURE__ */ new Date()
|
|
197
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
135
198
|
};
|
|
136
|
-
|
|
137
|
-
activeBlock = newBlock;
|
|
138
|
-
setExecutionBlocks([...blocks]);
|
|
139
|
-
onBlockStart?.(newBlock);
|
|
140
|
-
break;
|
|
199
|
+
state.parts.push(operationPart);
|
|
141
200
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
201
|
+
state.currentTextPartIndex = null;
|
|
202
|
+
state.currentReasoningPartIndex = null;
|
|
203
|
+
this.updateStreamingMessage();
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case "block-end": {
|
|
207
|
+
const operationPartIndex = state.parts.findIndex(
|
|
208
|
+
(p) => p.type === "operation" && p.operationId === event.blockId
|
|
209
|
+
);
|
|
210
|
+
if (operationPartIndex >= 0) {
|
|
211
|
+
const part = state.parts[operationPartIndex];
|
|
212
|
+
state.parts[operationPartIndex] = { ...part, status: "done" };
|
|
152
213
|
}
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
}
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
case "text-start":
|
|
172
|
-
case "text-end":
|
|
173
|
-
break;
|
|
174
|
-
case "reasoning-start": {
|
|
175
|
-
const isNonMainThread = activeBlock?.thread !== void 0 && activeBlock.thread !== "main";
|
|
176
|
-
const shouldCapture = (activeBlock?.outputToChat ?? false) || isNonMainThread;
|
|
177
|
-
const newPart = {
|
|
178
|
-
type: "reasoning",
|
|
179
|
-
visible: false,
|
|
180
|
-
content: "",
|
|
181
|
-
thread: activeBlock?.thread
|
|
182
|
-
};
|
|
183
|
-
parts.push(newPart);
|
|
184
|
-
reasoningStack.push({
|
|
185
|
-
id: event.id,
|
|
186
|
-
outputToChat: shouldCapture,
|
|
187
|
-
partIndex: parts.length - 1
|
|
188
|
-
});
|
|
189
|
-
setReasoningText("");
|
|
190
|
-
break;
|
|
214
|
+
if (state.activeBlock?.blockId === event.blockId) {
|
|
215
|
+
state.activeBlock = null;
|
|
191
216
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
217
|
+
this.updateStreamingMessage();
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case "reasoning-start": {
|
|
221
|
+
const thread = state.activeBlock?.thread;
|
|
222
|
+
const reasoningPart = {
|
|
223
|
+
type: "reasoning",
|
|
224
|
+
text: "",
|
|
225
|
+
status: "streaming",
|
|
226
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
227
|
+
};
|
|
228
|
+
state.parts.push(reasoningPart);
|
|
229
|
+
state.currentReasoningPartIndex = state.parts.length - 1;
|
|
230
|
+
this.updateStreamingMessage();
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "reasoning-delta": {
|
|
234
|
+
if (state.currentReasoningPartIndex !== null) {
|
|
235
|
+
const part = state.parts[state.currentReasoningPartIndex];
|
|
236
|
+
part.text += event.delta;
|
|
237
|
+
state.parts[state.currentReasoningPartIndex] = { ...part };
|
|
211
238
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
setReasoningText("");
|
|
215
|
-
const endReasoningPart = ctx ? parts[ctx.partIndex] : void 0;
|
|
216
|
-
if (ctx && endReasoningPart && !endReasoningPart.content?.trim()) {
|
|
217
|
-
parts.splice(ctx.partIndex, 1);
|
|
218
|
-
}
|
|
219
|
-
if (ctx?.outputToChat) {
|
|
220
|
-
setStreamingParts([...parts]);
|
|
221
|
-
}
|
|
222
|
-
break;
|
|
239
|
+
if (state.activeBlock) {
|
|
240
|
+
state.activeBlock.reasoning += event.delta;
|
|
223
241
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
242
|
+
this.updateStreamingMessage();
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "reasoning-end": {
|
|
246
|
+
if (state.currentReasoningPartIndex !== null) {
|
|
247
|
+
const part = state.parts[state.currentReasoningPartIndex];
|
|
248
|
+
part.status = "done";
|
|
249
|
+
state.parts[state.currentReasoningPartIndex] = { ...part };
|
|
250
|
+
state.currentReasoningPartIndex = null;
|
|
251
|
+
}
|
|
252
|
+
this.updateStreamingMessage();
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case "text-start": {
|
|
256
|
+
const thread = state.activeBlock?.thread;
|
|
257
|
+
const isOtherThread2 = Boolean(thread && thread !== "main");
|
|
258
|
+
const shouldAddPart = state.activeBlock?.outputToChat !== false || isOtherThread2;
|
|
259
|
+
if (shouldAddPart) {
|
|
260
|
+
const textPart = {
|
|
261
|
+
type: "text",
|
|
262
|
+
text: "",
|
|
229
263
|
status: "streaming",
|
|
230
|
-
|
|
264
|
+
thread: isOtherThread2 ? thread : void 0
|
|
231
265
|
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
activeBlock.toolCalls = [...activeBlock.toolCalls, newToolCall];
|
|
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]);
|
|
247
|
-
}
|
|
248
|
-
break;
|
|
266
|
+
state.parts.push(textPart);
|
|
267
|
+
state.currentTextPartIndex = state.parts.length - 1;
|
|
249
268
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
}
|
|
268
|
-
break;
|
|
269
|
+
this.updateStreamingMessage();
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "text-delta": {
|
|
273
|
+
if (state.currentTextPartIndex !== null) {
|
|
274
|
+
const part = state.parts[state.currentTextPartIndex];
|
|
275
|
+
part.text += event.delta;
|
|
276
|
+
state.parts[state.currentTextPartIndex] = { ...part };
|
|
269
277
|
}
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
if (state.activeBlock) {
|
|
279
|
+
state.activeBlock.text += event.delta;
|
|
272
280
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
inputPart.toolCall = {
|
|
283
|
-
...inputPart.toolCall,
|
|
284
|
-
arguments: toolCall.arguments,
|
|
285
|
-
status: "available"
|
|
286
|
-
};
|
|
287
|
-
setStreamingParts([...parts]);
|
|
288
|
-
}
|
|
289
|
-
if (activeBlock) {
|
|
290
|
-
setExecutionBlocks([...blocks]);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
break;
|
|
281
|
+
this.updateStreamingMessage();
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case "text-end": {
|
|
285
|
+
if (state.currentTextPartIndex !== null) {
|
|
286
|
+
const part = state.parts[state.currentTextPartIndex];
|
|
287
|
+
part.status = "done";
|
|
288
|
+
state.parts[state.currentTextPartIndex] = { ...part };
|
|
289
|
+
state.currentTextPartIndex = null;
|
|
294
290
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
setExecutionBlocks([...blocks]);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
break;
|
|
291
|
+
this.updateStreamingMessage();
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case "tool-input-start": {
|
|
295
|
+
const thread = state.activeBlock?.thread;
|
|
296
|
+
const toolPart = {
|
|
297
|
+
type: "tool-call",
|
|
298
|
+
toolCallId: event.toolCallId,
|
|
299
|
+
toolName: event.toolName,
|
|
300
|
+
displayName: event.title,
|
|
301
|
+
args: {},
|
|
302
|
+
status: "pending",
|
|
303
|
+
thread: thread && thread !== "main" ? thread : void 0
|
|
304
|
+
};
|
|
305
|
+
state.parts.push(toolPart);
|
|
306
|
+
if (state.activeBlock) {
|
|
307
|
+
state.activeBlock.toolCalls.set(event.toolCallId, toolPart);
|
|
316
308
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
setStreamingParts([...parts]);
|
|
332
|
-
}
|
|
333
|
-
if (activeBlock) {
|
|
334
|
-
setExecutionBlocks([...blocks]);
|
|
335
|
-
}
|
|
309
|
+
this.updateStreamingMessage();
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case "tool-input-delta": {
|
|
313
|
+
const toolPartIndex = state.parts.findIndex(
|
|
314
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
315
|
+
);
|
|
316
|
+
if (toolPartIndex >= 0) {
|
|
317
|
+
try {
|
|
318
|
+
const part = state.parts[toolPartIndex];
|
|
319
|
+
part.args = JSON.parse(event.inputTextDelta);
|
|
320
|
+
state.parts[toolPartIndex] = { ...part };
|
|
321
|
+
this.updateStreamingMessage();
|
|
322
|
+
} catch {
|
|
336
323
|
}
|
|
337
|
-
break;
|
|
338
324
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
case "tool-input-end":
|
|
328
|
+
break;
|
|
329
|
+
case "tool-input-available": {
|
|
330
|
+
const toolPartIndex = state.parts.findIndex(
|
|
331
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
332
|
+
);
|
|
333
|
+
if (toolPartIndex >= 0) {
|
|
334
|
+
const part = state.parts[toolPartIndex];
|
|
335
|
+
part.args = event.input;
|
|
336
|
+
part.status = "running";
|
|
337
|
+
state.parts[toolPartIndex] = { ...part };
|
|
338
|
+
this.updateStreamingMessage();
|
|
339
|
+
}
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case "tool-output-available": {
|
|
343
|
+
const toolPartIndex = state.parts.findIndex(
|
|
344
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
345
|
+
);
|
|
346
|
+
if (toolPartIndex >= 0) {
|
|
347
|
+
const part = state.parts[toolPartIndex];
|
|
348
|
+
part.result = event.output;
|
|
349
|
+
part.status = "done";
|
|
350
|
+
state.parts[toolPartIndex] = { ...part };
|
|
351
|
+
this.updateStreamingMessage();
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case "tool-output-error": {
|
|
356
|
+
const toolPartIndex = state.parts.findIndex(
|
|
357
|
+
(p) => p.type === "tool-call" && p.toolCallId === event.toolCallId
|
|
358
|
+
);
|
|
359
|
+
if (toolPartIndex >= 0) {
|
|
360
|
+
const part = state.parts[toolPartIndex];
|
|
361
|
+
part.error = event.errorText;
|
|
362
|
+
part.status = "error";
|
|
363
|
+
state.parts[toolPartIndex] = { ...part };
|
|
364
|
+
this.updateStreamingMessage();
|
|
365
|
+
}
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case "resource-update":
|
|
369
|
+
this.options.onResourceUpdate?.(event.name, event.value);
|
|
370
|
+
break;
|
|
371
|
+
case "finish": {
|
|
372
|
+
const finalMessage = buildMessageFromState(state, "done");
|
|
373
|
+
finalMessage.parts = finalMessage.parts.map((part) => {
|
|
374
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
375
|
+
return { ...part, status: "done" };
|
|
349
376
|
}
|
|
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);
|
|
377
|
+
return part;
|
|
378
|
+
});
|
|
379
|
+
if (finalMessage.parts.length > 0) {
|
|
380
|
+
const messages = [...this._messages];
|
|
381
|
+
const lastMsg = messages[messages.length - 1];
|
|
382
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
383
|
+
messages[messages.length - 1] = finalMessage;
|
|
384
|
+
} else {
|
|
385
|
+
messages.push(finalMessage);
|
|
376
386
|
}
|
|
377
|
-
|
|
378
|
-
setStreamingText("");
|
|
379
|
-
setStreamingParts([]);
|
|
380
|
-
setExecutionBlocks([]);
|
|
381
|
-
setReasoningText("");
|
|
382
|
-
onDone?.();
|
|
383
|
-
break;
|
|
387
|
+
this.setMessages(messages);
|
|
384
388
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
+
this.setStatus("idle");
|
|
390
|
+
this.streamingState = null;
|
|
391
|
+
this.options.onFinish?.();
|
|
392
|
+
break;
|
|
389
393
|
}
|
|
394
|
+
case "error":
|
|
395
|
+
throw new Error(event.errorText);
|
|
396
|
+
case "tool-request":
|
|
397
|
+
break;
|
|
390
398
|
}
|
|
391
|
-
} catch (err) {
|
|
392
|
-
const errorObj = err instanceof Error ? err : new Error("Unknown error");
|
|
393
|
-
setError(errorObj);
|
|
394
|
-
setStatus("error");
|
|
395
|
-
if (activeBlock) {
|
|
396
|
-
activeBlock.status = "error";
|
|
397
|
-
setExecutionBlocks([...blocks]);
|
|
398
|
-
}
|
|
399
|
-
onError?.(errorObj);
|
|
400
|
-
} finally {
|
|
401
|
-
abortControllerRef.current = null;
|
|
402
399
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
400
|
+
} catch (err) {
|
|
401
|
+
const errorObj = err instanceof Error ? err : new Error("Unknown error");
|
|
402
|
+
this.setError(errorObj);
|
|
403
|
+
this.setStatus("error");
|
|
404
|
+
this.streamingState = null;
|
|
405
|
+
this.options.onError?.(errorObj);
|
|
406
|
+
} finally {
|
|
407
|
+
this.abortController = null;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/** Stop the current streaming and finalize any partial message */
|
|
411
|
+
stop() {
|
|
412
|
+
this.abortController?.abort();
|
|
413
|
+
this.abortController = null;
|
|
414
|
+
const state = this.streamingState;
|
|
415
|
+
if (state && state.parts.length > 0) {
|
|
416
|
+
const finalMessage = buildMessageFromState(state, "done");
|
|
417
|
+
const messages = [...this._messages];
|
|
418
|
+
const lastMsg = messages[messages.length - 1];
|
|
419
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
420
|
+
messages[messages.length - 1] = finalMessage;
|
|
421
|
+
} else {
|
|
422
|
+
messages.push(finalMessage);
|
|
423
|
+
}
|
|
424
|
+
this.setMessages(messages);
|
|
425
|
+
}
|
|
426
|
+
this.streamingState = null;
|
|
427
|
+
this.setStatus("idle");
|
|
428
|
+
}
|
|
429
|
+
// =========================================================================
|
|
430
|
+
// Private Helpers
|
|
431
|
+
// =========================================================================
|
|
432
|
+
updateStreamingMessage() {
|
|
433
|
+
const state = this.streamingState;
|
|
434
|
+
if (!state) return;
|
|
435
|
+
const msg = buildMessageFromState(state, "streaming");
|
|
436
|
+
const messages = [...this._messages];
|
|
437
|
+
const lastMsg = messages[messages.length - 1];
|
|
438
|
+
if (lastMsg && lastMsg.id === state.messageId) {
|
|
439
|
+
messages[messages.length - 1] = msg;
|
|
440
|
+
} else {
|
|
441
|
+
messages.push(msg);
|
|
442
|
+
}
|
|
443
|
+
this.setMessages(messages);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/utils/message-helpers.ts
|
|
448
|
+
function isOtherThread(part) {
|
|
449
|
+
return Boolean(part.thread && part.thread !== "main");
|
|
431
450
|
}
|
|
432
451
|
export {
|
|
433
|
-
|
|
452
|
+
OctavusChat,
|
|
453
|
+
isOtherThread,
|
|
454
|
+
parseSSEStream
|
|
434
455
|
};
|
|
435
456
|
//# 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;AACF,QAAI,UAAU;AACd,WAAO,SAAS;AACd,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAE1C,UAAI,MAAM;AACR,kBAAU;AACV;AAAA,MACF;AAEA,gBAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAChD,YAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,eAAS,MAAM,IAAI,KAAK;AAExB,iBAAW,QAAQ,OAAO;AACxB,YAAI,KAAK,WAAW,QAAQ,KAAK,SAAS,gBAAgB;AACxD,cAAI;AACF,kBAAM,SAAS,qBAAqB,KAAK,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC;AAC7D,gBAAI,OAAO,SAAS;AAClB,oBAAM,OAAO;AAAA,YACf;A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"sourcesContent":["import {\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 OctavusChatOptions {\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\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\ntype Listener = () => void;\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// OctavusChat Class\n// =============================================================================\n\n/**\n * Framework-agnostic chat client for Octavus agents.\n * Manages chat state and streaming, allowing reactive frameworks to subscribe to updates.\n *\n * @example\n * ```typescript\n * const chat = new OctavusChat({\n * onTrigger: (triggerName, input) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * body: JSON.stringify({ sessionId, triggerName, input }),\n * }),\n * });\n *\n * // Subscribe to updates\n * const unsubscribe = chat.subscribe(() => {\n * console.log('Messages:', chat.messages);\n * console.log('Status:', chat.status);\n * });\n *\n * // Send a message\n * await chat.send('user-message', { USER_MESSAGE: 'Hello' }, { userMessage: { content: 'Hello' } });\n *\n * // Cleanup\n * unsubscribe();\n * ```\n */\nexport class OctavusChat {\n // Private state\n private _messages: UIMessage[];\n private _status: ChatStatus = 'idle';\n private _error: Error | null = null;\n private options: OctavusChatOptions;\n private abortController: AbortController | null = null;\n private streamingState: StreamingState | null = null;\n\n // Listener sets for reactive frameworks\n private listeners = new Set<Listener>();\n\n constructor(options: OctavusChatOptions) {\n this.options = options;\n this._messages = options.initialMessages ?? [];\n }\n\n // =========================================================================\n // Public Getters\n // =========================================================================\n\n get messages(): UIMessage[] {\n return this._messages;\n }\n\n get status(): ChatStatus {\n return this._status;\n }\n\n get error(): Error | null {\n return this._error;\n }\n\n // =========================================================================\n // Subscription Methods (for reactive frameworks)\n // =========================================================================\n\n /**\n * Subscribe to state changes. The callback is called whenever messages, status, or error changes.\n * @returns Unsubscribe function\n */\n subscribe(listener: Listener): () => void {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n private notifyListeners(): void {\n this.listeners.forEach((l) => l());\n }\n\n // =========================================================================\n // Private Setters (notify listeners)\n // =========================================================================\n\n private setMessages(messages: UIMessage[]): void {\n this._messages = messages;\n this.notifyListeners();\n }\n\n private setStatus(status: ChatStatus): void {\n this._status = status;\n this.notifyListeners();\n }\n\n private setError(error: Error | null): void {\n this._error = error;\n this.notifyListeners();\n }\n\n // =========================================================================\n // Public Methods\n // =========================================================================\n\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 async send(\n triggerName: string,\n input?: Record<string, unknown>,\n sendOptions?: { userMessage?: UserMessageInput },\n ): Promise<void> {\n // Abort any previous request\n this.abortController?.abort();\n\n const abortController = new AbortController();\n this.abortController = abortController;\n\n // Add user message if provided\n if (sendOptions?.userMessage !== undefined) {\n const userMsg = createUserMessage(sendOptions.userMessage);\n this.setMessages([...this._messages, userMsg]);\n }\n\n // Reset state\n this.setStatus('streaming');\n this.setError(null);\n this.streamingState = createEmptyStreamingState();\n\n try {\n const response = await this.options.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 = this.streamingState;\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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.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 this.updateStreamingMessage();\n }\n break;\n }\n\n case 'resource-update':\n this.options.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 const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.setStatus('idle');\n this.streamingState = null;\n this.options.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 this.setError(errorObj);\n this.setStatus('error');\n this.streamingState = null;\n this.options.onError?.(errorObj);\n } finally {\n this.abortController = null;\n }\n }\n\n /** Stop the current streaming and finalize any partial message */\n stop(): void {\n this.abortController?.abort();\n this.abortController = null;\n\n const state = this.streamingState;\n if (state && state.parts.length > 0) {\n const finalMessage = buildMessageFromState(state, 'done');\n const messages = [...this._messages];\n const lastMsg = messages[messages.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n messages[messages.length - 1] = finalMessage;\n } else {\n messages.push(finalMessage);\n }\n this.setMessages(messages);\n }\n\n this.streamingState = null;\n this.setStatus('idle');\n }\n\n // =========================================================================\n // Private Helpers\n // =========================================================================\n\n private updateStreamingMessage(): void {\n const state = this.streamingState;\n if (!state) return;\n\n const msg = buildMessageFromState(state, 'streaming');\n const messages = [...this._messages];\n\n const lastMsg = messages[messages.length - 1];\n if (lastMsg && lastMsg.id === state.messageId) {\n messages[messages.length - 1] = msg;\n } else {\n messages.push(msg);\n }\n\n this.setMessages(messages);\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');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AEA,SAAK,iBAAiB;AACtB,SAAK,UAAU,MAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAMQ,yBAA+B;AACrC,UAAM,QAAQ,KAAK;AACnB,QAAI,CAAC,MAAO;AAEZ,UAAM,MAAM,sBAAsB,OAAO,WAAW;AACpD,UAAM,WAAW,CAAC,GAAG,KAAK,SAAS;AAEnC,UAAM,UAAU,SAAS,SAAS,SAAS,CAAC;AAC5C,QAAI,WAAW,QAAQ,OAAO,MAAM,WAAW;AAC7C,eAAS,SAAS,SAAS,CAAC,IAAI;AAAA,IAClC,OAAO;AACL,eAAS,KAAK,GAAG;AAAA,IACnB;AAEA,SAAK,YAAY,QAAQ;AAAA,EAC3B;AACF;;;AE3kBO,SAAS,cAAc,MAA8B;AAC1D,SAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,MAAM;AACtD;","names":["isOtherThread"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octavus/client-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Framework-agnostic client SDK for Octavus agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Octavus AI <hello@octavus.ai>",
|
|
7
7
|
"keywords": [
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"ai",
|
|
10
10
|
"agents",
|
|
11
11
|
"sdk",
|
|
12
|
-
"react",
|
|
13
12
|
"streaming"
|
|
14
13
|
],
|
|
15
14
|
"type": "module",
|
|
@@ -29,14 +28,9 @@
|
|
|
29
28
|
"access": "public"
|
|
30
29
|
},
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"@octavus/core": "^0.0.
|
|
33
|
-
},
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"react": ">=18.0.0"
|
|
31
|
+
"@octavus/core": "^0.0.6"
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|
|
38
|
-
"@types/react": "^19.0.0",
|
|
39
|
-
"react": "^19.0.0",
|
|
40
34
|
"tsup": "^8.3.5",
|
|
41
35
|
"typescript": "^5.6.3"
|
|
42
36
|
},
|