@inferencesh/sdk 0.35.1 → 0.36.1

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 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.1] - 2026-10-28
11
+
12
+ ### Added
13
+ - `ProxyEndpoint.also` and `ProxyManifestEndpoint.also`: scopes a proxied call asks for in part of what it does (filing a chat in a project takes `projects:read`). A key without one is refused that part only. `src/proxy/endpoints.json` is regenerated from the API.
14
+
15
+ ## [0.36.0] - 2026-10-28
16
+
17
+ ### Added
18
+ - A client tool handler can return `{ error }`: the call completes as failed and the model reads the error. `submitToolError` sends one directly.
19
+ - `ToolResultRequest.error`.
20
+
21
+ ### Changed
22
+ - 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.
23
+
10
24
  ## [0.35.1] - 2026-10-28
11
25
 
12
26
  ### Added
@@ -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
- const deliverToolResult = async (invocationId, result, attachments) => {
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 (attachments?.length)
61
- await api.submitToolResult(client, invocationId, result, attachments);
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, JSON.stringify({
116
- status: 'not_available',
117
- message: `Client tool "${functionName}" is not available in this environment`,
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) => typeof output === 'string'
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, JSON.stringify({
131
- error: String(error)
132
- }));
132
+ return deliverToolResult(invocation.id, { error: String(error) });
133
133
  });
134
134
  }
135
135
  }
@@ -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.
@@ -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,
@@ -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,
@@ -10,6 +10,12 @@
10
10
  "apps:execute",
11
11
  "apps:read",
12
12
  "conversations:read"
13
+ ],
14
+ "also": [
15
+ "billing:read",
16
+ "conversations:write",
17
+ "credentials:read",
18
+ "secrets:reveal"
13
19
  ]
14
20
  },
15
21
  {
@@ -52,6 +58,9 @@
52
58
  "purpose": "cancel a task",
53
59
  "scopes": [
54
60
  "apps:execute"
61
+ ],
62
+ "also": [
63
+ "engines:write"
55
64
  ]
56
65
  },
57
66
  {
@@ -61,6 +70,22 @@
61
70
  "scopes": [
62
71
  "agents:execute",
63
72
  "conversations:read"
73
+ ],
74
+ "also": [
75
+ "agents:read",
76
+ "agents:write",
77
+ "apps:execute",
78
+ "apps:read",
79
+ "billing:read",
80
+ "conversations:read",
81
+ "conversations:write",
82
+ "credentials:read",
83
+ "files:read",
84
+ "knowledge:read",
85
+ "knowledge:write",
86
+ "projects:read",
87
+ "remotes:read",
88
+ "secrets:reveal"
64
89
  ]
65
90
  },
66
91
  {
@@ -69,6 +94,12 @@
69
94
  "purpose": "start a chat with an agent",
70
95
  "scopes": [
71
96
  "conversations:write"
97
+ ],
98
+ "also": [
99
+ "agents:read",
100
+ "apps:read",
101
+ "conversations:read",
102
+ "projects:read"
72
103
  ]
73
104
  },
74
105
  {
@@ -77,6 +108,22 @@
77
108
  "purpose": "send a message in a chat",
78
109
  "scopes": [
79
110
  "agents:execute"
111
+ ],
112
+ "also": [
113
+ "agents:read",
114
+ "agents:write",
115
+ "apps:execute",
116
+ "apps:read",
117
+ "billing:read",
118
+ "conversations:read",
119
+ "conversations:write",
120
+ "credentials:read",
121
+ "files:read",
122
+ "knowledge:read",
123
+ "knowledge:write",
124
+ "projects:read",
125
+ "remotes:read",
126
+ "secrets:reveal"
80
127
  ]
81
128
  },
82
129
  {
@@ -85,6 +132,11 @@
85
132
  "purpose": "hand a chat to another agent",
86
133
  "scopes": [
87
134
  "conversations:write"
135
+ ],
136
+ "also": [
137
+ "agents:read",
138
+ "apps:read",
139
+ "conversations:read"
88
140
  ]
89
141
  },
90
142
  {
@@ -93,6 +145,9 @@
93
145
  "purpose": "read an agent's info",
94
146
  "scopes": [
95
147
  "agents:read"
148
+ ],
149
+ "also": [
150
+ "apps:read"
96
151
  ]
97
152
  },
98
153
  {
@@ -133,6 +188,20 @@
133
188
  "purpose": "stop a chat",
134
189
  "scopes": [
135
190
  "conversations:write"
191
+ ],
192
+ "also": [
193
+ "agents:execute",
194
+ "agents:read",
195
+ "apps:execute",
196
+ "apps:read",
197
+ "billing:read",
198
+ "conversations:read",
199
+ "credentials:read",
200
+ "engines:write",
201
+ "knowledge:read",
202
+ "remotes:read",
203
+ "remotes:write",
204
+ "secrets:reveal"
136
205
  ]
137
206
  },
138
207
  {
@@ -141,6 +210,9 @@
141
210
  "purpose": "cancel a message",
142
211
  "scopes": [
143
212
  "conversations:write"
213
+ ],
214
+ "also": [
215
+ "conversations:read"
144
216
  ]
145
217
  },
146
218
  {
@@ -149,6 +221,9 @@
149
221
  "purpose": "answer a client tool call",
150
222
  "scopes": [
151
223
  "conversations:write"
224
+ ],
225
+ "also": [
226
+ "conversations:read"
152
227
  ]
153
228
  }
154
229
  ]
@@ -160,6 +160,8 @@ export interface ProxyManifestEndpoint {
160
160
  purpose: string;
161
161
  /** Scopes the call takes: what the site's API key must hold (the manifest's preset grants them all). */
162
162
  scopes: string[];
163
+ /** Scopes the call asks for in part of what it does (filing a chat in a project takes projects:read): a key without one is refused that part only. */
164
+ also?: string[];
163
165
  }
164
166
  export interface ProxyEndpoint {
165
167
  method: "GET" | "POST";
@@ -171,6 +173,8 @@ export interface ProxyEndpoint {
171
173
  purpose: string;
172
174
  /** Scopes the call takes, from the manifest. */
173
175
  scopes: readonly string[];
176
+ /** Scopes it asks for in part of what it does, from the manifest. */
177
+ also: readonly string[];
174
178
  /** Set when the request names an app or agent: checked against allowedEndpoints. */
175
179
  ref?: RefSource;
176
180
  /** Set when only these body fields may be sent. */
@@ -123,6 +123,7 @@ function fromManifest(e) {
123
123
  path: pathPattern(e.path),
124
124
  purpose: e.purpose,
125
125
  scopes: e.scopes,
126
+ also: e.also ?? [],
126
127
  ...RULES_BY_KEY.get(routeKey(route)),
127
128
  };
128
129
  }
@@ -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, or the text plus files.
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
@@ -527,6 +527,12 @@ export interface ToolResultRequest {
527
527
  * when it accepts images.
528
528
  */
529
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;
530
536
  }
531
537
  /**
532
538
  * PartialFile is the clean DTO version (no gorm tags).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.35.1",
3
+ "version": "0.36.1",
4
4
  "description": "Official JavaScript/TypeScript SDK for inference.sh - Run AI models with a simple API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",