@inferencesh/sdk 0.35.0 → 0.36.0
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/CHANGELOG.md +14 -0
- package/dist/agent/actions.js +14 -14
- package/dist/agent/api.d.ts +2 -0
- package/dist/agent/api.js +4 -0
- package/dist/api/agents.d.ts +10 -0
- package/dist/api/agents.js +16 -0
- package/dist/tool-builder.d.ts +5 -1
- package/dist/types.d.ts +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.36.0] - 2026-10-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- A client tool handler can return `{ error }`: the call completes as failed and the model reads the error. `submitToolError` sends one directly.
|
|
14
|
+
- `ToolResultRequest.error`.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- A client tool with no handler, or whose handler throws, now fails its call. It used to complete with the error text as its result.
|
|
18
|
+
|
|
19
|
+
## [0.35.1] - 2026-10-28
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- `ChatDTO.project_id`: the project a chat is filed in. `ApiAgentRunRequest.project_id` files the chat a run starts in a project.
|
|
23
|
+
|
|
10
24
|
## [0.35.0] - 2026-10-28
|
|
11
25
|
|
|
12
26
|
### Breaking
|
package/dist/agent/actions.js
CHANGED
|
@@ -54,13 +54,18 @@ export function createActions(ctx) {
|
|
|
54
54
|
// A client tool's result is the only way its turn continues: the server
|
|
55
55
|
// waits on it. A result lost to a network drop left the turn stuck on
|
|
56
56
|
// "running" for good, so it is sent again until it lands or is refused.
|
|
57
|
-
|
|
57
|
+
// Posts a handler's output: a result, or an error that fails the call.
|
|
58
|
+
const deliverToolResult = async (invocationId, output) => {
|
|
58
59
|
for (let attempt = 1;; attempt++) {
|
|
59
60
|
try {
|
|
60
|
-
if (
|
|
61
|
-
await api.submitToolResult(client, invocationId,
|
|
61
|
+
if (typeof output === 'string')
|
|
62
|
+
await api.submitToolResult(client, invocationId, output);
|
|
63
|
+
else if ('error' in output)
|
|
64
|
+
await api.submitToolError(client, invocationId, output.error);
|
|
65
|
+
else if (output.attachments?.length)
|
|
66
|
+
await api.submitToolResult(client, invocationId, output.result, output.attachments);
|
|
62
67
|
else
|
|
63
|
-
await api.submitToolResult(client, invocationId, result);
|
|
68
|
+
await api.submitToolResult(client, invocationId, output.result);
|
|
64
69
|
return;
|
|
65
70
|
}
|
|
66
71
|
catch (err) {
|
|
@@ -112,24 +117,19 @@ export function createActions(ctx) {
|
|
|
112
117
|
const handler = clientToolHandlers.get(functionName);
|
|
113
118
|
if (!handler) {
|
|
114
119
|
console.warn(`[AgentSDK] No handler for client tool: ${functionName}`);
|
|
115
|
-
deliverToolResult(invocation.id,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}));
|
|
120
|
+
deliverToolResult(invocation.id, {
|
|
121
|
+
error: `Client tool "${functionName}" is not available in this environment`,
|
|
122
|
+
});
|
|
119
123
|
continue;
|
|
120
124
|
}
|
|
121
125
|
// Execute the handler (it captures any needed state via closure)
|
|
122
126
|
// Use Promise.resolve to handle both sync and async handlers
|
|
123
127
|
const args = invocation.function?.arguments || {};
|
|
124
128
|
Promise.resolve(handler(args))
|
|
125
|
-
.then((output) =>
|
|
126
|
-
? deliverToolResult(invocation.id, output)
|
|
127
|
-
: deliverToolResult(invocation.id, output.result, output.attachments))
|
|
129
|
+
.then((output) => deliverToolResult(invocation.id, output))
|
|
128
130
|
.catch((error) => {
|
|
129
131
|
console.error(`[AgentSDK] Client tool ${functionName} error:`, error);
|
|
130
|
-
return deliverToolResult(invocation.id,
|
|
131
|
-
error: String(error)
|
|
132
|
-
}));
|
|
132
|
+
return deliverToolResult(invocation.id, { error: String(error) });
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
}
|
package/dist/agent/api.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare function submitToolResult(client: AgentClient, toolInvocationId:
|
|
|
46
46
|
};
|
|
47
47
|
form_data?: Record<string, unknown>;
|
|
48
48
|
}, attachments?: FileRef[]): Promise<void>;
|
|
49
|
+
/** Fail a client tool call: the chat shows it failed and the model reads `error`. */
|
|
50
|
+
export declare function submitToolError(client: AgentClient, toolInvocationId: string, error: string): Promise<void>;
|
|
49
51
|
/**
|
|
50
52
|
* What "always allow" can save for a call awaiting approval, narrowest first.
|
|
51
53
|
* The api computes the options from the call; each one, saved, answers it again.
|
package/dist/agent/api.js
CHANGED
|
@@ -155,6 +155,10 @@ export async function submitToolResult(client, toolInvocationId, resultOrAction,
|
|
|
155
155
|
}
|
|
156
156
|
await client.http.request('post', `/tools/${toolInvocationId}`, { data });
|
|
157
157
|
}
|
|
158
|
+
/** Fail a client tool call: the chat shows it failed and the model reads `error`. */
|
|
159
|
+
export async function submitToolError(client, toolInvocationId, error) {
|
|
160
|
+
await client.http.request('post', `/tools/${toolInvocationId}`, { data: { error } });
|
|
161
|
+
}
|
|
158
162
|
/**
|
|
159
163
|
* What "always allow" can save for a call awaiting approval, narrowest first.
|
|
160
164
|
* The api computes the options from the call; each one, saved, answers it again.
|
package/dist/api/agents.d.ts
CHANGED
|
@@ -119,6 +119,11 @@ export declare class Agent {
|
|
|
119
119
|
};
|
|
120
120
|
form_data?: Record<string, unknown>;
|
|
121
121
|
}, attachments?: FileRef[]): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Fail a client tool call the caller could not run: the chat shows it
|
|
124
|
+
* failed and the model reads `error`.
|
|
125
|
+
*/
|
|
126
|
+
submitToolError(toolInvocationId: string, error: string): Promise<void>;
|
|
122
127
|
/** Stop streaming/polling and cleanup */
|
|
123
128
|
disconnect(): void;
|
|
124
129
|
/**
|
|
@@ -218,6 +223,11 @@ export declare class AgentsAPI {
|
|
|
218
223
|
};
|
|
219
224
|
form_data?: Record<string, unknown>;
|
|
220
225
|
}, attachments?: FileRef[]): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Fail a client tool call the caller could not run: the chat shows it
|
|
228
|
+
* failed and the model reads `error`.
|
|
229
|
+
*/
|
|
230
|
+
submitToolError(toolInvocationId: string, error: string): Promise<void>;
|
|
221
231
|
/**
|
|
222
232
|
* Resolve an interrupt on an agent run: a tool call waiting for approval, a
|
|
223
233
|
* wait, a hook gate or a held turn, all the same way. `reason`, with deny,
|
package/dist/api/agents.js
CHANGED
|
@@ -180,6 +180,14 @@ export class Agent {
|
|
|
180
180
|
}
|
|
181
181
|
await this.http.request('post', `/tools/${toolInvocationId}`, { data });
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Fail a client tool call the caller could not run: the chat shows it
|
|
185
|
+
* failed and the model reads `error`.
|
|
186
|
+
*/
|
|
187
|
+
async submitToolError(toolInvocationId, error) {
|
|
188
|
+
const data = { result: '', error };
|
|
189
|
+
await this.http.request('post', `/tools/${toolInvocationId}`, { data });
|
|
190
|
+
}
|
|
183
191
|
/** Stop streaming/polling and cleanup */
|
|
184
192
|
disconnect() {
|
|
185
193
|
this.stream?.stop();
|
|
@@ -521,6 +529,14 @@ export class AgentsAPI {
|
|
|
521
529
|
}
|
|
522
530
|
await this.http.request('post', `/tools/${toolInvocationId}`, { data });
|
|
523
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* Fail a client tool call the caller could not run: the chat shows it
|
|
534
|
+
* failed and the model reads `error`.
|
|
535
|
+
*/
|
|
536
|
+
async submitToolError(toolInvocationId, error) {
|
|
537
|
+
const data = { result: '', error };
|
|
538
|
+
await this.http.request('post', `/tools/${toolInvocationId}`, { data });
|
|
539
|
+
}
|
|
524
540
|
/**
|
|
525
541
|
* Resolve an interrupt on an agent run: a tool call waiting for approval, a
|
|
526
542
|
* wait, a hook gate or a held turn, all the same way. `reason`, with deny,
|
package/dist/tool-builder.d.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { AgentTool, FileRef, InternalToolsConfig } from './types.js';
|
|
5
5
|
/**
|
|
6
|
-
* What a client tool handler returns: the result text,
|
|
6
|
+
* What a client tool handler returns: the result text, the text plus files, or
|
|
7
|
+
* `{ error }` when the tool could not do what was asked. An error fails the
|
|
8
|
+
* call: the chat shows it failed and the model reads the error text.
|
|
7
9
|
*
|
|
8
10
|
* `attachments` are files already uploaded with POST /files (for example with
|
|
9
11
|
* `client.files.upload(dataUrlOrBlob)` or the chat's `uploadFile`), passed as
|
|
@@ -14,6 +16,8 @@ import { AgentTool, FileRef, InternalToolsConfig } from './types.js';
|
|
|
14
16
|
export type ClientToolResult = string | {
|
|
15
17
|
result: string;
|
|
16
18
|
attachments?: FileRef[];
|
|
19
|
+
} | {
|
|
20
|
+
error: string;
|
|
17
21
|
};
|
|
18
22
|
/** Handler function for client tools (executed in browser/Node) */
|
|
19
23
|
export type ClientToolHandler = (args: Record<string, unknown>) => Promise<ClientToolResult> | ClientToolResult;
|
package/dist/types.d.ts
CHANGED
|
@@ -504,6 +504,12 @@ export interface ApiAgentRunRequest {
|
|
|
504
504
|
[key: string]: string;
|
|
505
505
|
};
|
|
506
506
|
stream?: boolean;
|
|
507
|
+
/**
|
|
508
|
+
* ProjectID files the chat this message starts in a project. Ignored
|
|
509
|
+
* when the message posts into an existing chat (chat_id): a chat moves
|
|
510
|
+
* with POST /chats/{id}/project.
|
|
511
|
+
*/
|
|
512
|
+
project_id?: string;
|
|
507
513
|
}
|
|
508
514
|
export interface CreateAgentMessageResponse {
|
|
509
515
|
user_message?: ChatMessageDTO;
|
|
@@ -521,6 +527,12 @@ export interface ToolResultRequest {
|
|
|
521
527
|
* when it accepts images.
|
|
522
528
|
*/
|
|
523
529
|
attachments?: FileRef[];
|
|
530
|
+
/**
|
|
531
|
+
* Error, when set, says the call failed: it completes as failed and the
|
|
532
|
+
* model reads Error in place of Result. A client sets it when it has no
|
|
533
|
+
* handler for the tool or the handler failed.
|
|
534
|
+
*/
|
|
535
|
+
error?: string;
|
|
524
536
|
}
|
|
525
537
|
/**
|
|
526
538
|
* PartialFile is the clean DTO version (no gorm tags).
|
|
@@ -2319,7 +2331,7 @@ export interface ChatAgentDTO {
|
|
|
2319
2331
|
/**
|
|
2320
2332
|
* ChatDTO for API responses
|
|
2321
2333
|
*/
|
|
2322
|
-
export interface ChatDTO extends BaseModelDTO, PermissionModelDTO {
|
|
2334
|
+
export interface ChatDTO extends BaseModelDTO, PermissionModelDTO, ProjectModelDTO {
|
|
2323
2335
|
parent_id?: string;
|
|
2324
2336
|
parent?: ChatDTO;
|
|
2325
2337
|
children: (ChatDTO | undefined)[];
|