@inferencesh/sdk 0.5.6 → 0.5.7
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 +2 -2
- package/dist/api/agents.d.ts +12 -0
- package/dist/api/agents.js +22 -9
- package/dist/api/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/agent/actions.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Action creators that handle side effects (API calls, streaming).
|
|
5
5
|
* These are created once per provider instance with access to dispatch.
|
|
6
6
|
*/
|
|
7
|
-
import { ToolInvocationStatusAwaitingInput, ToolTypeClient, } from '../types';
|
|
7
|
+
import { ToolInvocationStatusAwaitingInput, ToolTypeClient, ChatStatusBusy, } from '../types';
|
|
8
8
|
import { StreamManager } from '../http/stream';
|
|
9
9
|
import { PollManager } from '../http/poll';
|
|
10
10
|
import { isAdHocConfig, extractClientToolHandlers } from './types';
|
|
@@ -24,7 +24,7 @@ export function createActions(ctx) {
|
|
|
24
24
|
const setChat = (chat) => {
|
|
25
25
|
dispatch({ type: 'SET_CHAT', payload: chat });
|
|
26
26
|
if (chat) {
|
|
27
|
-
const status = chat.status ===
|
|
27
|
+
const status = chat.status === ChatStatusBusy ? 'streaming' : 'idle';
|
|
28
28
|
callbacks.onStatusChange?.(status);
|
|
29
29
|
}
|
|
30
30
|
};
|
package/dist/api/agents.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface SendMessageOptions {
|
|
|
32
32
|
/** Polling interval in ms when stream is false. Overrides client default. */
|
|
33
33
|
pollIntervalMs?: number;
|
|
34
34
|
}
|
|
35
|
+
export interface AgentRunOptions extends Omit<SendMessageOptions, 'stream'> {
|
|
36
|
+
/** Polling interval in ms (default: 2000) */
|
|
37
|
+
pollIntervalMs?: number;
|
|
38
|
+
}
|
|
35
39
|
/**
|
|
36
40
|
* Agent for chat interactions
|
|
37
41
|
*
|
|
@@ -71,6 +75,14 @@ export declare class Agent {
|
|
|
71
75
|
}): Promise<void>;
|
|
72
76
|
/** Stop streaming/polling and cleanup */
|
|
73
77
|
disconnect(): void;
|
|
78
|
+
/**
|
|
79
|
+
* Run the agent and return structured output.
|
|
80
|
+
*
|
|
81
|
+
* Sends a message, waits for completion (always polls, no SSE), then returns
|
|
82
|
+
* `chat.output` — the parsed finish tool result. Returns `null` if the agent
|
|
83
|
+
* finished without calling the finish tool.
|
|
84
|
+
*/
|
|
85
|
+
run(text: string, options?: AgentRunOptions): Promise<any>;
|
|
74
86
|
/** Reset the agent (start fresh chat) */
|
|
75
87
|
reset(): void;
|
|
76
88
|
/**
|
package/dist/api/agents.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StreamManager } from '../http/stream';
|
|
2
2
|
import { PollManager } from '../http/poll';
|
|
3
|
-
import { ToolTypeClient, ToolInvocationStatusAwaitingInput, } from '../types';
|
|
3
|
+
import { ToolTypeClient, ToolInvocationStatusAwaitingInput, ChatStatusBusy, } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Agent for chat interactions
|
|
6
6
|
*
|
|
@@ -62,12 +62,13 @@ export class Agent {
|
|
|
62
62
|
input: { text, images: imageUris, files: fileUris, role: 'user', context: [], system_prompt: '', context_size: 0 },
|
|
63
63
|
};
|
|
64
64
|
const useStream = options.stream ?? this.http.getStreamDefault();
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const shouldWait = useStream === false || hasCallbacks;
|
|
66
|
+
const waitFn = useStream === false
|
|
67
|
+
? (opts) => this.pollUntilIdle(opts)
|
|
68
|
+
: (opts) => this.streamUntilIdle(opts);
|
|
69
|
+
// For existing chats: Start waiting BEFORE POST so we don't miss updates
|
|
69
70
|
let waitPromise = null;
|
|
70
|
-
if (this.chatId &&
|
|
71
|
+
if (this.chatId && shouldWait) {
|
|
71
72
|
waitPromise = waitFn(options);
|
|
72
73
|
}
|
|
73
74
|
// Make the POST request
|
|
@@ -76,7 +77,7 @@ export class Agent {
|
|
|
76
77
|
const isNewChat = !this.chatId && response.assistant_message.chat_id;
|
|
77
78
|
if (isNewChat) {
|
|
78
79
|
this.chatId = response.assistant_message.chat_id;
|
|
79
|
-
if (
|
|
80
|
+
if (shouldWait) {
|
|
80
81
|
waitPromise = waitFn(options);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
@@ -113,6 +114,18 @@ export class Agent {
|
|
|
113
114
|
this.poller?.stop();
|
|
114
115
|
this.poller = null;
|
|
115
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Run the agent and return structured output.
|
|
119
|
+
*
|
|
120
|
+
* Sends a message, waits for completion (always polls, no SSE), then returns
|
|
121
|
+
* `chat.output` — the parsed finish tool result. Returns `null` if the agent
|
|
122
|
+
* finished without calling the finish tool.
|
|
123
|
+
*/
|
|
124
|
+
async run(text, options = {}) {
|
|
125
|
+
await this.sendMessage(text, { ...options, stream: false });
|
|
126
|
+
const chat = await this.getChat();
|
|
127
|
+
return chat?.output ?? null;
|
|
128
|
+
}
|
|
116
129
|
/** Reset the agent (start fresh chat) */
|
|
117
130
|
reset() {
|
|
118
131
|
this.disconnect();
|
|
@@ -139,7 +152,7 @@ export class Agent {
|
|
|
139
152
|
});
|
|
140
153
|
this.stream.addEventListener('chats', (chat) => {
|
|
141
154
|
options.onChat?.(chat);
|
|
142
|
-
if (chat.status
|
|
155
|
+
if (chat.status !== ChatStatusBusy) {
|
|
143
156
|
resolve();
|
|
144
157
|
}
|
|
145
158
|
});
|
|
@@ -217,7 +230,7 @@ export class Agent {
|
|
|
217
230
|
}
|
|
218
231
|
}
|
|
219
232
|
}
|
|
220
|
-
if (chat.status
|
|
233
|
+
if (chat.status !== ChatStatusBusy) {
|
|
221
234
|
this.poller?.stop();
|
|
222
235
|
this.poller = null;
|
|
223
236
|
resolve();
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { TasksAPI, createTasksAPI, RunOptions } from './tasks';
|
|
2
2
|
export { FilesAPI, createFilesAPI, UploadFileOptions } from './files';
|
|
3
|
-
export { AgentsAPI, createAgentsAPI, Agent, AgentOptions, SendMessageOptions } from './agents';
|
|
3
|
+
export { AgentsAPI, createAgentsAPI, Agent, AgentOptions, SendMessageOptions, AgentRunOptions } from './agents';
|
|
4
4
|
export { SessionsAPI, createSessionsAPI } from './sessions';
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { PollManager, PollManagerOptions } from './http/poll';
|
|
|
4
4
|
export { InferenceError, RequirementsNotMetException, SessionError, SessionNotFoundError, SessionExpiredError, SessionEndedError, WorkerLostError, } from './http/errors';
|
|
5
5
|
export { TasksAPI, RunOptions } from './api/tasks';
|
|
6
6
|
export { FilesAPI, UploadFileOptions } from './api/files';
|
|
7
|
-
export { AgentsAPI, Agent, AgentOptions, SendMessageOptions } from './api/agents';
|
|
7
|
+
export { AgentsAPI, Agent, AgentOptions, SendMessageOptions, AgentRunOptions } from './api/agents';
|
|
8
8
|
export { SessionsAPI } from './api/sessions';
|
|
9
9
|
export { AppsAPI } from './api/apps';
|
|
10
10
|
export { ChatsAPI } from './api/chats';
|