@inferencesh/sdk 0.5.12 → 0.5.13
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/agent/actions.js +15 -20
- package/dist/agent/api.d.ts +5 -5
- package/dist/agent/api.js +16 -25
- package/dist/agent/hooks.d.ts +9 -6
- package/dist/agent/hooks.js +9 -6
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.js +3 -2
- package/dist/agent/reducer.js +5 -14
- package/dist/agent/types.d.ts +9 -20
- package/dist/api/files.js +6 -1
- package/dist/types.d.ts +75 -0
- package/dist/types.js +15 -0
- package/package.json +1 -1
package/dist/agent/actions.js
CHANGED
|
@@ -77,7 +77,7 @@ export function createActions(ctx) {
|
|
|
77
77
|
existingManager.stop();
|
|
78
78
|
}
|
|
79
79
|
setStreamManager(undefined);
|
|
80
|
-
dispatch({ type: '
|
|
80
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'connecting' });
|
|
81
81
|
callbacks.onStatusChange?.('connecting');
|
|
82
82
|
try {
|
|
83
83
|
// Fetch initial chat
|
|
@@ -88,8 +88,7 @@ export function createActions(ctx) {
|
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
console.error('[AgentSDK] Failed to fetch chat:', error);
|
|
91
|
-
dispatch({ type: '
|
|
92
|
-
dispatch({ type: 'SET_IS_GENERATING', payload: false });
|
|
91
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
93
92
|
callbacks.onStatusChange?.('idle');
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
@@ -108,7 +107,7 @@ export function createActions(ctx) {
|
|
|
108
107
|
callbacks.onError?.(error);
|
|
109
108
|
},
|
|
110
109
|
onStart: () => {
|
|
111
|
-
dispatch({ type: '
|
|
110
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'streaming' });
|
|
112
111
|
callbacks.onStatusChange?.('streaming');
|
|
113
112
|
},
|
|
114
113
|
onEnd: () => {
|
|
@@ -117,8 +116,7 @@ export function createActions(ctx) {
|
|
|
117
116
|
// so getStreamManager() will be undefined and we skip the duplicate dispatch.
|
|
118
117
|
if (getStreamManager()) {
|
|
119
118
|
setStreamManager(undefined);
|
|
120
|
-
dispatch({ type: '
|
|
121
|
-
dispatch({ type: 'SET_IS_GENERATING', payload: false });
|
|
119
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
122
120
|
callbacks.onStatusChange?.('idle');
|
|
123
121
|
}
|
|
124
122
|
},
|
|
@@ -162,14 +160,13 @@ export function createActions(ctx) {
|
|
|
162
160
|
}
|
|
163
161
|
},
|
|
164
162
|
onStart: () => {
|
|
165
|
-
dispatch({ type: '
|
|
163
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'streaming' });
|
|
166
164
|
callbacks.onStatusChange?.('streaming');
|
|
167
165
|
},
|
|
168
166
|
onStop: () => {
|
|
169
167
|
if (getStreamManager()) {
|
|
170
168
|
setStreamManager(undefined);
|
|
171
|
-
dispatch({ type: '
|
|
172
|
-
dispatch({ type: 'SET_IS_GENERATING', payload: false });
|
|
169
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
173
170
|
callbacks.onStatusChange?.('idle');
|
|
174
171
|
}
|
|
175
172
|
},
|
|
@@ -188,8 +185,7 @@ export function createActions(ctx) {
|
|
|
188
185
|
if (manager) {
|
|
189
186
|
manager.stop();
|
|
190
187
|
}
|
|
191
|
-
dispatch({ type: '
|
|
192
|
-
dispatch({ type: 'SET_IS_GENERATING', payload: false });
|
|
188
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
193
189
|
callbacks.onStatusChange?.('idle');
|
|
194
190
|
};
|
|
195
191
|
// =========================================================================
|
|
@@ -207,7 +203,7 @@ export function createActions(ctx) {
|
|
|
207
203
|
if (!trimmedText)
|
|
208
204
|
return;
|
|
209
205
|
// Update status
|
|
210
|
-
dispatch({ type: '
|
|
206
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'streaming' });
|
|
211
207
|
dispatch({ type: 'SET_ERROR', payload: undefined });
|
|
212
208
|
try {
|
|
213
209
|
const result = await api.sendMessage(client, agentConfig, chatId, trimmedText, files);
|
|
@@ -226,15 +222,14 @@ export function createActions(ctx) {
|
|
|
226
222
|
}
|
|
227
223
|
else {
|
|
228
224
|
// API returned no result — reset status so we don't get stuck
|
|
229
|
-
dispatch({ type: '
|
|
230
|
-
dispatch({ type: 'SET_IS_GENERATING', payload: false });
|
|
225
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
231
226
|
callbacks.onStatusChange?.('idle');
|
|
232
227
|
}
|
|
233
228
|
}
|
|
234
229
|
catch (error) {
|
|
235
230
|
console.error('[AgentSDK] Failed to send message:', error);
|
|
236
231
|
const err = error instanceof Error ? error : new Error('Failed to send message');
|
|
237
|
-
dispatch({ type: '
|
|
232
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
|
|
238
233
|
dispatch({ type: 'SET_ERROR', payload: err.message });
|
|
239
234
|
callbacks.onError?.(err);
|
|
240
235
|
}
|
|
@@ -256,7 +251,7 @@ export function createActions(ctx) {
|
|
|
256
251
|
},
|
|
257
252
|
clearError: () => {
|
|
258
253
|
dispatch({ type: 'SET_ERROR', payload: undefined });
|
|
259
|
-
dispatch({ type: '
|
|
254
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'idle' });
|
|
260
255
|
},
|
|
261
256
|
submitToolResult: async (toolInvocationId, result) => {
|
|
262
257
|
try {
|
|
@@ -265,7 +260,7 @@ export function createActions(ctx) {
|
|
|
265
260
|
catch (error) {
|
|
266
261
|
console.error('[AgentSDK] Failed to submit tool result:', error);
|
|
267
262
|
const err = error instanceof Error ? error : new Error('Failed to submit tool result');
|
|
268
|
-
dispatch({ type: '
|
|
263
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
|
|
269
264
|
dispatch({ type: 'SET_ERROR', payload: err.message });
|
|
270
265
|
callbacks.onError?.(err);
|
|
271
266
|
throw error;
|
|
@@ -278,7 +273,7 @@ export function createActions(ctx) {
|
|
|
278
273
|
catch (error) {
|
|
279
274
|
console.error('[AgentSDK] Failed to approve tool:', error);
|
|
280
275
|
const err = error instanceof Error ? error : new Error('Failed to approve tool');
|
|
281
|
-
dispatch({ type: '
|
|
276
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
|
|
282
277
|
dispatch({ type: 'SET_ERROR', payload: err.message });
|
|
283
278
|
callbacks.onError?.(err);
|
|
284
279
|
throw error;
|
|
@@ -291,7 +286,7 @@ export function createActions(ctx) {
|
|
|
291
286
|
catch (error) {
|
|
292
287
|
console.error('[AgentSDK] Failed to reject tool:', error);
|
|
293
288
|
const err = error instanceof Error ? error : new Error('Failed to reject tool');
|
|
294
|
-
dispatch({ type: '
|
|
289
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
|
|
295
290
|
dispatch({ type: 'SET_ERROR', payload: err.message });
|
|
296
291
|
callbacks.onError?.(err);
|
|
297
292
|
throw error;
|
|
@@ -309,7 +304,7 @@ export function createActions(ctx) {
|
|
|
309
304
|
catch (error) {
|
|
310
305
|
console.error('[AgentSDK] Failed to always-allow tool:', error);
|
|
311
306
|
const err = error instanceof Error ? error : new Error('Failed to always-allow tool');
|
|
312
|
-
dispatch({ type: '
|
|
307
|
+
dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
|
|
313
308
|
dispatch({ type: 'SET_ERROR', payload: err.message });
|
|
314
309
|
callbacks.onError?.(err);
|
|
315
310
|
throw error;
|
package/dist/agent/api.d.ts
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* Uses the client passed in from the provider.
|
|
6
6
|
*/
|
|
7
7
|
import type { ChatDTO, ChatMessageDTO } from '../types';
|
|
8
|
-
import type { AdHocAgentConfig, TemplateAgentConfig, AgentOptions, AgentClient,
|
|
8
|
+
import type { AdHocAgentConfig, TemplateAgentConfig, AgentOptions, AgentClient, FileRef } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* File input that can be either a File to upload or an already-uploaded file
|
|
11
11
|
*/
|
|
12
|
-
export type FileInput = globalThis.File |
|
|
12
|
+
export type FileInput = globalThis.File | FileRef;
|
|
13
13
|
/**
|
|
14
14
|
* Send a message using ad-hoc agent config
|
|
15
15
|
*/
|
|
16
|
-
export declare function sendAdHocMessage(client: AgentClient, config: AdHocAgentConfig, chatId: string | null, text: string,
|
|
16
|
+
export declare function sendAdHocMessage(client: AgentClient, config: AdHocAgentConfig, chatId: string | null, text: string, attachments?: FileRef[]): Promise<{
|
|
17
17
|
chatId: string;
|
|
18
18
|
userMessage: ChatMessageDTO;
|
|
19
19
|
assistantMessage: ChatMessageDTO;
|
|
@@ -21,7 +21,7 @@ export declare function sendAdHocMessage(client: AgentClient, config: AdHocAgent
|
|
|
21
21
|
/**
|
|
22
22
|
* Send a message using template agent config
|
|
23
23
|
*/
|
|
24
|
-
export declare function sendTemplateMessage(client: AgentClient, config: TemplateAgentConfig, chatId: string | null, text: string,
|
|
24
|
+
export declare function sendTemplateMessage(client: AgentClient, config: TemplateAgentConfig, chatId: string | null, text: string, attachments?: FileRef[]): Promise<{
|
|
25
25
|
chatId: string;
|
|
26
26
|
userMessage: ChatMessageDTO;
|
|
27
27
|
assistantMessage: ChatMessageDTO;
|
|
@@ -67,7 +67,7 @@ export declare function alwaysAllowTool(client: AgentClient, chatId: string, too
|
|
|
67
67
|
/**
|
|
68
68
|
* Upload a file and return the uploaded file reference
|
|
69
69
|
*/
|
|
70
|
-
export declare function uploadFile(client: AgentClient, file: globalThis.File): Promise<
|
|
70
|
+
export declare function uploadFile(client: AgentClient, file: globalThis.File): Promise<FileRef>;
|
|
71
71
|
/**
|
|
72
72
|
* Get streamable config for chat streaming (NDJSON)
|
|
73
73
|
*/
|
package/dist/agent/api.js
CHANGED
|
@@ -8,13 +8,13 @@ import { isAdHocConfig, extractToolSchemas } from './types';
|
|
|
8
8
|
/**
|
|
9
9
|
* Check if input is an already-uploaded file
|
|
10
10
|
*/
|
|
11
|
-
function
|
|
11
|
+
function isFileRef(input) {
|
|
12
12
|
return 'uri' in input && typeof input.uri === 'string';
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Send a message using ad-hoc agent config
|
|
16
16
|
*/
|
|
17
|
-
export async function sendAdHocMessage(client, config, chatId, text,
|
|
17
|
+
export async function sendAdHocMessage(client, config, chatId, text, attachments) {
|
|
18
18
|
// Extract just the schemas from tools (handlers are stripped out)
|
|
19
19
|
const toolSchemas = config.tools ? extractToolSchemas(config.tools) : undefined;
|
|
20
20
|
const request = {
|
|
@@ -27,8 +27,7 @@ export async function sendAdHocMessage(client, config, chatId, text, imageUris,
|
|
|
27
27
|
agent_name: config.name,
|
|
28
28
|
input: {
|
|
29
29
|
text,
|
|
30
|
-
|
|
31
|
-
files: fileUris,
|
|
30
|
+
attachments,
|
|
32
31
|
context_size: 0,
|
|
33
32
|
system_prompt: '',
|
|
34
33
|
context: [],
|
|
@@ -51,15 +50,14 @@ export async function sendAdHocMessage(client, config, chatId, text, imageUris,
|
|
|
51
50
|
/**
|
|
52
51
|
* Send a message using template agent config
|
|
53
52
|
*/
|
|
54
|
-
export async function sendTemplateMessage(client, config, chatId, text,
|
|
53
|
+
export async function sendTemplateMessage(client, config, chatId, text, attachments) {
|
|
55
54
|
const request = {
|
|
56
55
|
chat_id: chatId ?? undefined,
|
|
57
56
|
// Only include agent if it's not empty (for existing chats, backend uses chat's agent)
|
|
58
57
|
agent: config.agent || undefined,
|
|
59
58
|
input: {
|
|
60
59
|
text,
|
|
61
|
-
|
|
62
|
-
files: fileUris,
|
|
60
|
+
attachments,
|
|
63
61
|
context_size: 0,
|
|
64
62
|
system_prompt: '',
|
|
65
63
|
context: [],
|
|
@@ -83,43 +81,36 @@ export async function sendTemplateMessage(client, config, chatId, text, imageUri
|
|
|
83
81
|
* Send a message (unified interface)
|
|
84
82
|
*/
|
|
85
83
|
export async function sendMessage(client, config, chatId, text, files) {
|
|
86
|
-
// Process files - upload if needed,
|
|
87
|
-
let
|
|
88
|
-
let fileUris;
|
|
84
|
+
// Process files - upload if needed, collect as FileRef attachments
|
|
85
|
+
let attachments;
|
|
89
86
|
if (files && files.length > 0) {
|
|
90
|
-
|
|
87
|
+
attachments = [];
|
|
91
88
|
for (const file of files) {
|
|
92
|
-
// Check if already uploaded
|
|
93
|
-
if (
|
|
94
|
-
|
|
89
|
+
// Check if already uploaded (FileRef)
|
|
90
|
+
if (isFileRef(file)) {
|
|
91
|
+
attachments.push(file);
|
|
95
92
|
continue;
|
|
96
93
|
}
|
|
97
94
|
// Upload the file
|
|
98
95
|
try {
|
|
99
96
|
const result = await client.files.upload(file);
|
|
100
97
|
if (result) {
|
|
101
|
-
|
|
98
|
+
attachments.push(result);
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
101
|
catch (error) {
|
|
105
102
|
console.error('[AgentSDK] Failed to upload file:', error);
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const otherFiles = uploadedFiles.filter(f => !f.content_type?.startsWith('image/'));
|
|
111
|
-
if (images.length > 0) {
|
|
112
|
-
imageUris = images.map(f => f.uri);
|
|
113
|
-
}
|
|
114
|
-
if (otherFiles.length > 0) {
|
|
115
|
-
fileUris = otherFiles.map(f => f.uri);
|
|
105
|
+
if (attachments.length === 0) {
|
|
106
|
+
attachments = undefined;
|
|
116
107
|
}
|
|
117
108
|
}
|
|
118
109
|
if (isAdHocConfig(config)) {
|
|
119
|
-
return sendAdHocMessage(client, config, chatId, text,
|
|
110
|
+
return sendAdHocMessage(client, config, chatId, text, attachments);
|
|
120
111
|
}
|
|
121
112
|
else {
|
|
122
|
-
return sendTemplateMessage(client, config, chatId, text,
|
|
113
|
+
return sendTemplateMessage(client, config, chatId, text, attachments);
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
116
|
/**
|
package/dist/agent/hooks.d.ts
CHANGED
|
@@ -8,13 +8,14 @@ import type { ChatMessageDTO } from '../types';
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook to access chat state
|
|
10
10
|
*
|
|
11
|
-
* @returns Chat state (
|
|
11
|
+
* @returns Chat state (chat, messages, connectionStatus, error)
|
|
12
12
|
* @throws Error if used outside AgentChatProvider
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
16
16
|
* function MyComponent() {
|
|
17
|
-
* const {
|
|
17
|
+
* const { chat, messages } = useAgentChat();
|
|
18
|
+
* const isBusy = chat?.status === 'busy';
|
|
18
19
|
* return <div>{messages.length} messages</div>;
|
|
19
20
|
* }
|
|
20
21
|
* ```
|
|
@@ -30,11 +31,12 @@ export declare function useAgentChat(): AgentChatState;
|
|
|
30
31
|
* ```tsx
|
|
31
32
|
* function SendButton() {
|
|
32
33
|
* const { sendMessage, stopGeneration } = useAgentActions();
|
|
33
|
-
* const {
|
|
34
|
+
* const { chat } = useAgentChat();
|
|
35
|
+
* const isBusy = chat?.status === 'busy';
|
|
34
36
|
*
|
|
35
37
|
* return (
|
|
36
|
-
* <button onClick={() =>
|
|
37
|
-
* {
|
|
38
|
+
* <button onClick={() => isBusy ? stopGeneration() : sendMessage('Hello!')}>
|
|
39
|
+
* {isBusy ? 'Stop' : 'Send'}
|
|
38
40
|
* </button>
|
|
39
41
|
* );
|
|
40
42
|
* }
|
|
@@ -67,11 +69,12 @@ export declare function useMessage(messageId: string): ChatMessageDTO | undefine
|
|
|
67
69
|
* function ChatInput() {
|
|
68
70
|
* const { state, actions } = useAgentChatContext();
|
|
69
71
|
* const [input, setInput] = useState('');
|
|
72
|
+
* const isBusy = state.chat?.status === 'busy';
|
|
70
73
|
*
|
|
71
74
|
* return (
|
|
72
75
|
* <form onSubmit={() => actions.sendMessage(input)}>
|
|
73
76
|
* <input value={input} onChange={e => setInput(e.target.value)} />
|
|
74
|
-
* <button disabled={
|
|
77
|
+
* <button disabled={isBusy}>Send</button>
|
|
75
78
|
* </form>
|
|
76
79
|
* );
|
|
77
80
|
* }
|
package/dist/agent/hooks.js
CHANGED
|
@@ -8,13 +8,14 @@ import { AgentChatContext } from './context';
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook to access chat state
|
|
10
10
|
*
|
|
11
|
-
* @returns Chat state (
|
|
11
|
+
* @returns Chat state (chat, messages, connectionStatus, error)
|
|
12
12
|
* @throws Error if used outside AgentChatProvider
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```tsx
|
|
16
16
|
* function MyComponent() {
|
|
17
|
-
* const {
|
|
17
|
+
* const { chat, messages } = useAgentChat();
|
|
18
|
+
* const isBusy = chat?.status === 'busy';
|
|
18
19
|
* return <div>{messages.length} messages</div>;
|
|
19
20
|
* }
|
|
20
21
|
* ```
|
|
@@ -37,11 +38,12 @@ export function useAgentChat() {
|
|
|
37
38
|
* ```tsx
|
|
38
39
|
* function SendButton() {
|
|
39
40
|
* const { sendMessage, stopGeneration } = useAgentActions();
|
|
40
|
-
* const {
|
|
41
|
+
* const { chat } = useAgentChat();
|
|
42
|
+
* const isBusy = chat?.status === 'busy';
|
|
41
43
|
*
|
|
42
44
|
* return (
|
|
43
|
-
* <button onClick={() =>
|
|
44
|
-
* {
|
|
45
|
+
* <button onClick={() => isBusy ? stopGeneration() : sendMessage('Hello!')}>
|
|
46
|
+
* {isBusy ? 'Stop' : 'Send'}
|
|
45
47
|
* </button>
|
|
46
48
|
* );
|
|
47
49
|
* }
|
|
@@ -84,11 +86,12 @@ export function useMessage(messageId) {
|
|
|
84
86
|
* function ChatInput() {
|
|
85
87
|
* const { state, actions } = useAgentChatContext();
|
|
86
88
|
* const [input, setInput] = useState('');
|
|
89
|
+
* const isBusy = state.chat?.status === 'busy';
|
|
87
90
|
*
|
|
88
91
|
* return (
|
|
89
92
|
* <form onSubmit={() => actions.sendMessage(input)}>
|
|
90
93
|
* <input value={input} onChange={e => setInput(e.target.value)} />
|
|
91
|
-
* <button disabled={
|
|
94
|
+
* <button disabled={isBusy}>Send</button>
|
|
92
95
|
* </form>
|
|
93
96
|
* );
|
|
94
97
|
* }
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -29,14 +29,15 @@
|
|
|
29
29
|
* }
|
|
30
30
|
*
|
|
31
31
|
* function ChatUI() {
|
|
32
|
-
* const {
|
|
32
|
+
* const { chat, messages } = useAgentChat();
|
|
33
33
|
* const { sendMessage, stopGeneration } = useAgentActions();
|
|
34
|
+
* const isBusy = chat?.status === 'busy';
|
|
34
35
|
*
|
|
35
36
|
* return (
|
|
36
37
|
* <div>
|
|
37
38
|
* {messages.map(m => <Message key={m.id} message={m} />)}
|
|
38
39
|
* <input onSubmit={(text) => sendMessage(text)} />
|
|
39
|
-
* {
|
|
40
|
+
* {isBusy && <button onClick={stopGeneration}>Stop</button>}
|
|
40
41
|
* </div>
|
|
41
42
|
* );
|
|
42
43
|
* }
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
export { AgentChatProvider } from './provider';
|
|
46
47
|
export { useAgentChat, useAgentActions, useAgentClient, useAgentChatContext, useMessage, } from './hooks';
|
|
47
48
|
export { AgentChatContext, type AgentChatContextValue } from './context';
|
|
48
|
-
export type { AgentClient,
|
|
49
|
+
export type { AgentClient, FileRef, AdHocAgentConfig, TemplateAgentConfig, AgentOptions, AgentChatState, AgentChatActions, ChatStatus, AgentChatProviderProps, ClientTool, ClientToolHandlerFn, } from './types';
|
|
49
50
|
export { isAdHocConfig, isTemplateConfig, isClientTool, extractToolSchemas, extractClientToolHandlers, } from './types';
|
package/dist/agent/index.js
CHANGED
|
@@ -29,14 +29,15 @@
|
|
|
29
29
|
* }
|
|
30
30
|
*
|
|
31
31
|
* function ChatUI() {
|
|
32
|
-
* const {
|
|
32
|
+
* const { chat, messages } = useAgentChat();
|
|
33
33
|
* const { sendMessage, stopGeneration } = useAgentActions();
|
|
34
|
+
* const isBusy = chat?.status === 'busy';
|
|
34
35
|
*
|
|
35
36
|
* return (
|
|
36
37
|
* <div>
|
|
37
38
|
* {messages.map(m => <Message key={m.id} message={m} />)}
|
|
38
39
|
* <input onSubmit={(text) => sendMessage(text)} />
|
|
39
|
-
* {
|
|
40
|
+
* {isBusy && <button onClick={stopGeneration}>Stop</button>}
|
|
40
41
|
* </div>
|
|
41
42
|
* );
|
|
42
43
|
* }
|
package/dist/agent/reducer.js
CHANGED
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
export const initialState = {
|
|
10
10
|
chatId: null,
|
|
11
11
|
messages: [],
|
|
12
|
-
|
|
13
|
-
isGenerating: false,
|
|
12
|
+
connectionStatus: 'idle',
|
|
14
13
|
error: undefined,
|
|
15
14
|
chat: null,
|
|
16
15
|
};
|
|
@@ -24,12 +23,10 @@ export function chatReducer(state, action) {
|
|
|
24
23
|
case 'SET_CHAT': {
|
|
25
24
|
const chat = action.payload;
|
|
26
25
|
if (!chat) {
|
|
27
|
-
return { ...state, chat: null, messages: [],
|
|
26
|
+
return { ...state, chat: null, messages: [], connectionStatus: 'idle' };
|
|
28
27
|
}
|
|
29
28
|
const messages = [...(chat.chat_messages || [])].sort((a, b) => a.order - b.order);
|
|
30
|
-
|
|
31
|
-
const status = isGenerating ? 'streaming' : 'idle';
|
|
32
|
-
return { ...state, chat, messages, isGenerating, status };
|
|
29
|
+
return { ...state, chat, messages };
|
|
33
30
|
}
|
|
34
31
|
case 'SET_MESSAGES':
|
|
35
32
|
return { ...state, messages: action.payload };
|
|
@@ -51,14 +48,8 @@ export function chatReducer(state, action) {
|
|
|
51
48
|
...state,
|
|
52
49
|
messages: [...state.messages, action.payload].sort((a, b) => a.order - b.order),
|
|
53
50
|
};
|
|
54
|
-
case '
|
|
55
|
-
return {
|
|
56
|
-
...state,
|
|
57
|
-
status: action.payload,
|
|
58
|
-
isGenerating: action.payload === 'streaming' || action.payload === 'connecting',
|
|
59
|
-
};
|
|
60
|
-
case 'SET_IS_GENERATING':
|
|
61
|
-
return { ...state, isGenerating: action.payload };
|
|
51
|
+
case 'SET_CONNECTION_STATUS':
|
|
52
|
+
return { ...state, connectionStatus: action.payload };
|
|
62
53
|
case 'SET_ERROR':
|
|
63
54
|
return { ...state, error: action.payload };
|
|
64
55
|
case 'RESET':
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -4,17 +4,11 @@
|
|
|
4
4
|
* Public types for the Agent chat module.
|
|
5
5
|
*/
|
|
6
6
|
import type { Dispatch } from 'react';
|
|
7
|
-
import type { ChatDTO, ChatMessageDTO, AgentTool, AgentConfig as GeneratedAgentConfig, CoreAppConfig } from '../types';
|
|
7
|
+
import type { ChatDTO, ChatMessageDTO, AgentTool, AgentConfig as GeneratedAgentConfig, CoreAppConfig, FileRef } from '../types';
|
|
8
8
|
import type { HttpClient } from '../http/client';
|
|
9
9
|
import type { StreamableManager } from '../http/streamable';
|
|
10
10
|
import type { PollManager } from '../http/poll';
|
|
11
|
-
|
|
12
|
-
* Minimal file interface returned by upload (just needs uri and content_type)
|
|
13
|
-
*/
|
|
14
|
-
export interface UploadedFile {
|
|
15
|
-
uri: string;
|
|
16
|
-
content_type?: string;
|
|
17
|
-
}
|
|
11
|
+
export type { FileRef } from '../types';
|
|
18
12
|
/**
|
|
19
13
|
* Minimal client interface required by the agent module.
|
|
20
14
|
* This allows extended clients (like the app client) to be used.
|
|
@@ -24,7 +18,7 @@ export interface AgentClient {
|
|
|
24
18
|
http: Pick<HttpClient, 'request' | 'getStreamableConfig' | 'getStreamDefault' | 'getPollIntervalMs'>;
|
|
25
19
|
/** Files API for uploads */
|
|
26
20
|
files: {
|
|
27
|
-
upload: (data: string | Blob | globalThis.File) => Promise<
|
|
21
|
+
upload: (data: string | Blob | globalThis.File) => Promise<FileRef>;
|
|
28
22
|
};
|
|
29
23
|
}
|
|
30
24
|
/**
|
|
@@ -93,11 +87,9 @@ export interface AgentChatState {
|
|
|
93
87
|
chatId: string | null;
|
|
94
88
|
/** Chat messages */
|
|
95
89
|
messages: ChatMessageDTO[];
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
isGenerating: boolean;
|
|
100
|
-
/** Error message if status is 'error' */
|
|
90
|
+
/** Connection status (stream/poll state, not chat.status) */
|
|
91
|
+
connectionStatus: ChatStatus;
|
|
92
|
+
/** Error message if connectionStatus is 'error' */
|
|
101
93
|
error?: string;
|
|
102
94
|
/** The full chat object (if loaded) */
|
|
103
95
|
chat: ChatDTO | null;
|
|
@@ -107,9 +99,9 @@ export interface AgentChatState {
|
|
|
107
99
|
*/
|
|
108
100
|
export interface AgentChatActions {
|
|
109
101
|
/** Send a message to the agent */
|
|
110
|
-
sendMessage: (text: string, files?:
|
|
102
|
+
sendMessage: (text: string, files?: FileRef[]) => Promise<void>;
|
|
111
103
|
/** Upload a file and return the uploaded file reference */
|
|
112
|
-
uploadFile: (file: File) => Promise<
|
|
104
|
+
uploadFile: (file: File) => Promise<FileRef>;
|
|
113
105
|
/** Stop the current generation */
|
|
114
106
|
stopGeneration: () => void;
|
|
115
107
|
/** Reset the chat (start fresh) */
|
|
@@ -194,11 +186,8 @@ export type ChatAction = {
|
|
|
194
186
|
type: 'ADD_MESSAGE';
|
|
195
187
|
payload: ChatMessageDTO;
|
|
196
188
|
} | {
|
|
197
|
-
type: '
|
|
189
|
+
type: 'SET_CONNECTION_STATUS';
|
|
198
190
|
payload: ChatStatus;
|
|
199
|
-
} | {
|
|
200
|
-
type: 'SET_IS_GENERATING';
|
|
201
|
-
payload: boolean;
|
|
202
191
|
} | {
|
|
203
192
|
type: 'SET_ERROR';
|
|
204
193
|
payload: string | undefined;
|
package/dist/api/files.js
CHANGED
|
@@ -81,10 +81,15 @@ export class FilesAPI {
|
|
|
81
81
|
contentType = 'application/octet-stream';
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
// Extract filename from File object if not provided in options
|
|
85
|
+
let filename = options.filename;
|
|
86
|
+
if (!filename && data instanceof globalThis.File) {
|
|
87
|
+
filename = data.name;
|
|
88
|
+
}
|
|
84
89
|
// Step 1: Create the file record
|
|
85
90
|
const fileRequest = {
|
|
86
91
|
uri: '', // Empty URI as it will be set by the server
|
|
87
|
-
filename
|
|
92
|
+
filename,
|
|
88
93
|
content_type: contentType,
|
|
89
94
|
path: options.path,
|
|
90
95
|
size: data instanceof Blob ? data.size : undefined,
|
package/dist/types.d.ts
CHANGED
|
@@ -509,6 +509,17 @@ export interface CreateFlowRunRequest {
|
|
|
509
509
|
flow: string;
|
|
510
510
|
input: any;
|
|
511
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* CreateAppRequest is the request body for POST /apps
|
|
514
|
+
*/
|
|
515
|
+
export interface CreateAppRequest extends App {
|
|
516
|
+
/**
|
|
517
|
+
* PreserveCurrentVersion prevents auto-promoting the new version to current.
|
|
518
|
+
* Default false = new versions become current (what most users expect).
|
|
519
|
+
* Set true for admin deployments where you want to test before promoting.
|
|
520
|
+
*/
|
|
521
|
+
preserve_current_version?: boolean;
|
|
522
|
+
}
|
|
512
523
|
/**
|
|
513
524
|
* CreateAgentRequest is the request body for POST /agents
|
|
514
525
|
* For new agents: omit ID, backend generates it
|
|
@@ -596,6 +607,7 @@ export interface DeviceAuthPollResponse {
|
|
|
596
607
|
export interface DeviceAuthApproveRequest {
|
|
597
608
|
code: string;
|
|
598
609
|
team_id: string;
|
|
610
|
+
scopes?: string[];
|
|
599
611
|
}
|
|
600
612
|
/**
|
|
601
613
|
* DeviceAuthApproveResponse is returned after approval
|
|
@@ -750,6 +762,51 @@ export interface EngineConfig {
|
|
|
750
762
|
*/
|
|
751
763
|
engine_internal_api_url: string;
|
|
752
764
|
}
|
|
765
|
+
/**
|
|
766
|
+
* ScopeGroup identifies a category of scopes for UI grouping
|
|
767
|
+
*/
|
|
768
|
+
export type ScopeGroup = string;
|
|
769
|
+
export declare const ScopeGroupAgents: ScopeGroup;
|
|
770
|
+
export declare const ScopeGroupApps: ScopeGroup;
|
|
771
|
+
export declare const ScopeGroupConversations: ScopeGroup;
|
|
772
|
+
export declare const ScopeGroupFiles: ScopeGroup;
|
|
773
|
+
export declare const ScopeGroupDatastores: ScopeGroup;
|
|
774
|
+
export declare const ScopeGroupFlows: ScopeGroup;
|
|
775
|
+
export declare const ScopeGroupProjects: ScopeGroup;
|
|
776
|
+
export declare const ScopeGroupTeams: ScopeGroup;
|
|
777
|
+
export declare const ScopeGroupBilling: ScopeGroup;
|
|
778
|
+
export declare const ScopeGroupSecrets: ScopeGroup;
|
|
779
|
+
export declare const ScopeGroupIntegrations: ScopeGroup;
|
|
780
|
+
export declare const ScopeGroupEngines: ScopeGroup;
|
|
781
|
+
export declare const ScopeGroupApiKeys: ScopeGroup;
|
|
782
|
+
export declare const ScopeGroupUser: ScopeGroup;
|
|
783
|
+
export declare const ScopeGroupSettings: ScopeGroup;
|
|
784
|
+
/**
|
|
785
|
+
* ScopeDefinition describes a single scope for UI rendering
|
|
786
|
+
*/
|
|
787
|
+
export interface ScopeDefinition {
|
|
788
|
+
value: string;
|
|
789
|
+
label: string;
|
|
790
|
+
description: string;
|
|
791
|
+
group: ScopeGroup;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* ScopeGroupDefinition describes a group of scopes for UI rendering
|
|
795
|
+
*/
|
|
796
|
+
export interface ScopeGroupDefinition {
|
|
797
|
+
id: ScopeGroup;
|
|
798
|
+
label: string;
|
|
799
|
+
description: string;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* ScopePreset represents a predefined bundle of scopes for common use cases
|
|
803
|
+
*/
|
|
804
|
+
export interface ScopePreset {
|
|
805
|
+
id: string;
|
|
806
|
+
label: string;
|
|
807
|
+
description: string;
|
|
808
|
+
scopes: string[];
|
|
809
|
+
}
|
|
753
810
|
export type AppCategory = string;
|
|
754
811
|
export declare const AppCategoryImage: AppCategory;
|
|
755
812
|
export declare const AppCategoryVideo: AppCategory;
|
|
@@ -1042,6 +1099,17 @@ export declare const IntegrationTypeSlack: IntegrationType;
|
|
|
1042
1099
|
export declare const IntegrationTypeDiscord: IntegrationType;
|
|
1043
1100
|
export declare const IntegrationTypeTeams: IntegrationType;
|
|
1044
1101
|
export declare const IntegrationTypeTelegram: IntegrationType;
|
|
1102
|
+
/**
|
|
1103
|
+
* FileRef is a lightweight reference to a file with essential metadata.
|
|
1104
|
+
* Used in chat inputs/context instead of full File objects.
|
|
1105
|
+
*/
|
|
1106
|
+
export interface FileRef {
|
|
1107
|
+
id?: string;
|
|
1108
|
+
uri: string;
|
|
1109
|
+
filename: string;
|
|
1110
|
+
content_type: string;
|
|
1111
|
+
size?: number;
|
|
1112
|
+
}
|
|
1045
1113
|
export interface ChatMessageContent {
|
|
1046
1114
|
type: ChatMessageContentType;
|
|
1047
1115
|
error?: string;
|
|
@@ -1078,6 +1146,13 @@ export interface ChatTaskInput {
|
|
|
1078
1146
|
role?: ChatMessageRole;
|
|
1079
1147
|
text?: string;
|
|
1080
1148
|
reasoning?: string;
|
|
1149
|
+
/**
|
|
1150
|
+
* Attachments is the SDK input field with full file metadata
|
|
1151
|
+
*/
|
|
1152
|
+
attachments?: FileRef[];
|
|
1153
|
+
/**
|
|
1154
|
+
* Images and Files are internal fields for task workers (filled from Attachments or context)
|
|
1155
|
+
*/
|
|
1081
1156
|
images?: string[];
|
|
1082
1157
|
files?: string[];
|
|
1083
1158
|
tools?: Tool[];
|
package/dist/types.js
CHANGED
|
@@ -4,6 +4,21 @@ export const ToolTypeAgent = "agent"; // Sub-agent tools - creates a sub-Chat
|
|
|
4
4
|
export const ToolTypeHook = "hook"; // Webhook tools - HTTP POST to external URL
|
|
5
5
|
export const ToolTypeClient = "client"; // Client tools - executed by frontend
|
|
6
6
|
export const ToolTypeInternal = "internal"; // Internal/built-in tools (plan, memory, widget, finish)
|
|
7
|
+
export const ScopeGroupAgents = "agents";
|
|
8
|
+
export const ScopeGroupApps = "apps";
|
|
9
|
+
export const ScopeGroupConversations = "conversations";
|
|
10
|
+
export const ScopeGroupFiles = "files";
|
|
11
|
+
export const ScopeGroupDatastores = "datastores";
|
|
12
|
+
export const ScopeGroupFlows = "flows";
|
|
13
|
+
export const ScopeGroupProjects = "projects";
|
|
14
|
+
export const ScopeGroupTeams = "teams";
|
|
15
|
+
export const ScopeGroupBilling = "billing";
|
|
16
|
+
export const ScopeGroupSecrets = "secrets";
|
|
17
|
+
export const ScopeGroupIntegrations = "integrations";
|
|
18
|
+
export const ScopeGroupEngines = "engines";
|
|
19
|
+
export const ScopeGroupApiKeys = "apikeys";
|
|
20
|
+
export const ScopeGroupUser = "user";
|
|
21
|
+
export const ScopeGroupSettings = "settings";
|
|
7
22
|
export const AppCategoryImage = "image";
|
|
8
23
|
export const AppCategoryVideo = "video";
|
|
9
24
|
export const AppCategoryAudio = "audio";
|