@inferencesh/sdk 0.5.15 → 0.5.17

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  official javascript/typescript sdk for [inference.sh](https://inference.sh) — the ai agent runtime for serverless ai inference.
9
9
 
10
- run ai models, build ai agents, and deploy generative ai applications with a simple api. access 150+ models including flux, stable diffusion, llms (claude, gpt, gemini), video generation (veo, seedance), and more.
10
+ run ai models, build ai agents, and deploy generative ai applications with a simple api. access 250+ models including flux, stable diffusion, llms (claude, gpt, gemini), video generation (veo, seedance), and more.
11
11
 
12
12
  ## Installation
13
13
 
@@ -408,7 +408,7 @@ import type { Task, ApiTaskRequest, RunOptions } from '@inferencesh/sdk';
408
408
 
409
409
  - [documentation](https://inference.sh/docs) — getting started guides and api reference
410
410
  - [blog](https://inference.sh/blog) — tutorials on ai agents, image generation, and more
411
- - [app store](https://app.inference.sh) — browse 150+ ai models
411
+ - [app store](https://app.inference.sh) — browse 250+ ai models
412
412
  - [discord](https://discord.gg/RM77SWSbyT) — community support
413
413
  - [github](https://github.com/inference-sh) — open source projects
414
414
 
@@ -30,7 +30,9 @@ export function createActions(ctx) {
30
30
  };
31
31
  const updateMessage = (message) => {
32
32
  const chatId = getChatId();
33
- if (message.chat_id !== chatId)
33
+ // TODO: remove startsWith once the provider normalizes chatId to full ID after first fetchChat
34
+ // Support short ID matching (URL short IDs are prefixes of full IDs)
35
+ if (chatId && message.chat_id !== chatId && !message.chat_id.startsWith(chatId))
34
36
  return;
35
37
  dispatch({ type: 'UPDATE_MESSAGE', payload: message });
36
38
  // Check for client tool invocations that need execution
@@ -121,9 +123,13 @@ export function createActions(ctx) {
121
123
  }
122
124
  },
123
125
  });
124
- // Listen for Chat object updates (status changes)
126
+ // Listen for Chat object updates (status changes only — don't replace messages)
125
127
  manager.addEventListener('chats', (chatData) => {
126
- setChat(chatData);
128
+ dispatch({ type: 'UPDATE_CHAT', payload: chatData });
129
+ if (chatData) {
130
+ const status = chatData.status === ChatStatusBusy ? 'streaming' : 'idle';
131
+ callbacks.onStatusChange?.(status);
132
+ }
127
133
  });
128
134
  // Listen for ChatMessage updates
129
135
  manager.addEventListener('chat_messages', (message) => {
@@ -28,6 +28,13 @@ export function chatReducer(state, action) {
28
28
  const messages = [...(chat.chat_messages || [])].sort((a, b) => a.order - b.order);
29
29
  return { ...state, chat, messages };
30
30
  }
31
+ case 'UPDATE_CHAT': {
32
+ // Update chat metadata (e.g. status) without replacing messages
33
+ const chat = action.payload;
34
+ if (!chat)
35
+ return state;
36
+ return { ...state, chat };
37
+ }
31
38
  case 'SET_MESSAGES':
32
39
  return { ...state, messages: action.payload };
33
40
  case 'UPDATE_MESSAGE': {
@@ -176,6 +176,9 @@ export type ChatAction = {
176
176
  } | {
177
177
  type: 'SET_CHAT';
178
178
  payload: ChatDTO | null;
179
+ } | {
180
+ type: 'UPDATE_CHAT';
181
+ payload: ChatDTO | null;
179
182
  } | {
180
183
  type: 'SET_MESSAGES';
181
184
  payload: ChatMessageDTO[];
@@ -16,9 +16,7 @@ export class HttpClient {
16
16
  this.baseUrl = config.baseUrl || 'https://api.inference.sh';
17
17
  this.proxyUrl = config.proxyUrl;
18
18
  this.getToken = config.getToken;
19
- const isBrowser = typeof window !== 'undefined';
20
- const sourceKey = isBrowser ? 'X-Client-Source' : 'User-Agent';
21
- this.customHeaders = { [sourceKey]: 'inference-sdk-js/0.5.13', ...config.headers };
19
+ this.customHeaders = { 'X-Client-Source': 'inference-sdk-js/0.5.13', ...config.headers };
22
20
  this.credentials = config.credentials || 'include';
23
21
  this.onError = config.onError;
24
22
  this.streamDefault = config.stream ?? true;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { ChatsAPI } from './api/chats';
12
12
  export { FlowsAPI } from './api/flows';
13
13
  export { FlowRunsAPI } from './api/flow-runs';
14
14
  export { EnginesAPI } from './api/engines';
15
- export { tool, appTool, agentTool, webhookTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
15
+ export { tool, appTool, agentTool, webhookTool, httpTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
16
16
  export type { ClientTool, ClientToolHandler } from './tool-builder';
17
17
  export { parseStatus, isTerminalStatus } from './utils';
18
18
  export * from './types';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ export { FlowsAPI } from './api/flows';
17
17
  export { FlowRunsAPI } from './api/flow-runs';
18
18
  export { EnginesAPI } from './api/engines';
19
19
  // Tool Builder (fluent API)
20
- export { tool, appTool, agentTool, webhookTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
20
+ export { tool, appTool, agentTool, webhookTool, httpTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
21
21
  // Status utilities (handle both int and string status values)
22
22
  export { parseStatus, isTerminalStatus } from './utils';
23
23
  // Types - includes TaskStatus constants and all DTOs
@@ -79,6 +79,23 @@ declare class WebhookToolBuilder extends ToolBuilder {
79
79
  secret(key: string): this;
80
80
  build(): AgentTool;
81
81
  }
82
+ declare class HTTPToolBuilder extends ToolBuilder {
83
+ private url;
84
+ private httpMethod;
85
+ private authConfig?;
86
+ private headerMap;
87
+ constructor(name: string, url: string);
88
+ method(m: string): this;
89
+ auth(config: {
90
+ integration?: string;
91
+ integrationId?: string;
92
+ apiKey?: string;
93
+ bearer?: string;
94
+ header?: string;
95
+ }): this;
96
+ header(name: string, value: string): this;
97
+ build(): AgentTool;
98
+ }
82
99
  /** Create a client tool (executed by SDK consumer) */
83
100
  export declare const tool: (name: string) => ClientToolBuilder;
84
101
  /** Create an app tool (runs another inference app) */
@@ -87,6 +104,8 @@ export declare const appTool: (name: string, appRef: string) => AppToolBuilder;
87
104
  export declare const agentTool: (name: string, agentRef: string) => AgentToolBuilder;
88
105
  /** Create a webhook tool (calls external URL) */
89
106
  export declare const webhookTool: (name: string, url: string) => WebhookToolBuilder;
107
+ /** Create an HTTP tool with credential injection (replaces webhookTool for new code) */
108
+ export declare const httpTool: (name: string, url: string) => HTTPToolBuilder;
90
109
  declare class InternalToolsBuilder {
91
110
  private config;
92
111
  /** Enable plan tools (Create, Update, Load) */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tool Builder - Fluent API for defining agent tools
3
3
  */
4
- import { ToolTypeClient, ToolTypeApp, ToolTypeAgent, ToolTypeHook } from './types';
4
+ import { ToolTypeClient, ToolTypeApp, ToolTypeAgent, ToolTypeHook, ToolTypeHTTP } from './types';
5
5
  // =============================================================================
6
6
  // Schema Builders
7
7
  // =============================================================================
@@ -172,6 +172,50 @@ class WebhookToolBuilder extends ToolBuilder {
172
172
  };
173
173
  }
174
174
  }
175
+ class HTTPToolBuilder extends ToolBuilder {
176
+ constructor(name, url) {
177
+ super(name);
178
+ this.httpMethod = 'POST';
179
+ this.headerMap = {};
180
+ this.url = url;
181
+ }
182
+ method(m) {
183
+ this.httpMethod = m;
184
+ return this;
185
+ }
186
+ auth(config) {
187
+ if (config.integration) {
188
+ this.authConfig = { type: 'integration', provider: config.integration, integration_id: config.integrationId };
189
+ }
190
+ else if (config.apiKey) {
191
+ this.authConfig = { type: 'api_key', secret: config.apiKey, header: config.header || 'X-API-Key' };
192
+ }
193
+ else if (config.bearer) {
194
+ this.authConfig = { type: 'bearer', secret: config.bearer };
195
+ }
196
+ return this;
197
+ }
198
+ header(name, value) {
199
+ this.headerMap[name] = value;
200
+ return this;
201
+ }
202
+ build() {
203
+ return {
204
+ name: this.name,
205
+ display_name: this.displayNameValue || this.name,
206
+ description: this.desc,
207
+ type: ToolTypeHTTP,
208
+ require_approval: this.approval || undefined,
209
+ http: {
210
+ url: this.url,
211
+ method: this.httpMethod !== 'POST' ? this.httpMethod : undefined,
212
+ auth: this.authConfig,
213
+ headers: Object.keys(this.headerMap).length ? this.headerMap : undefined,
214
+ input_schema: toJsonSchema(this.params),
215
+ },
216
+ };
217
+ }
218
+ }
175
219
  // =============================================================================
176
220
  // Public API
177
221
  // =============================================================================
@@ -183,6 +227,8 @@ export const appTool = (name, appRef) => new AppToolBuilder(name, appRef);
183
227
  export const agentTool = (name, agentRef) => new AgentToolBuilder(name, agentRef);
184
228
  /** Create a webhook tool (calls external URL) */
185
229
  export const webhookTool = (name, url) => new WebhookToolBuilder(name, url);
230
+ /** Create an HTTP tool with credential injection (replaces webhookTool for new code) */
231
+ export const httpTool = (name, url) => new HTTPToolBuilder(name, url);
186
232
  // =============================================================================
187
233
  // Internal Tools Builder
188
234
  // =============================================================================
package/dist/types.d.ts CHANGED
@@ -16,6 +16,8 @@ export type ToolType = string;
16
16
  export declare const ToolTypeApp: ToolType;
17
17
  export declare const ToolTypeAgent: ToolType;
18
18
  export declare const ToolTypeHook: ToolType;
19
+ export declare const ToolTypeHTTP: ToolType;
20
+ export declare const ToolTypeMCP: ToolType;
19
21
  export declare const ToolTypeClient: ToolType;
20
22
  export declare const ToolTypeInternal: ToolType;
21
23
  /**
@@ -86,6 +88,57 @@ export interface ClientToolConfig {
86
88
  input_schema?: any;
87
89
  output_schema?: any;
88
90
  }
91
+ /**
92
+ * ToolAuthConfig declares how a tool authenticates. Resolved at runtime — never contains actual credentials.
93
+ */
94
+ export interface ToolAuthConfig {
95
+ /**
96
+ * Type: "integration", "api_key", "bearer", "none"
97
+ */
98
+ type: string;
99
+ /**
100
+ * For type=integration: which provider to look up (e.g. "google", "mcp", "slack")
101
+ */
102
+ provider?: string;
103
+ /**
104
+ * For type=integration: specific integration ID (optional — if empty, uses team's primary for provider)
105
+ */
106
+ integration_id?: string;
107
+ /**
108
+ * For type=api_key or bearer: name of the secret in the team's secret store
109
+ */
110
+ secret?: string;
111
+ /**
112
+ * For type=api_key: which header to inject (default: "X-API-Key")
113
+ */
114
+ header?: string;
115
+ }
116
+ /**
117
+ * HTTPToolConfig contains configuration for an authenticated HTTP tool
118
+ */
119
+ export interface HTTPToolConfig {
120
+ url: string;
121
+ method?: string;
122
+ auth?: ToolAuthConfig;
123
+ headers?: {
124
+ [key: string]: string;
125
+ };
126
+ input_schema?: any;
127
+ output_schema?: any;
128
+ }
129
+ /**
130
+ * MCPToolConfig contains configuration for a remote MCP server tool
131
+ */
132
+ export interface MCPToolConfig {
133
+ /**
134
+ * IntegrationID references the MCP integration (has server_url, tokens, cached tools)
135
+ */
136
+ integration_id: string;
137
+ /**
138
+ * ToolName is the tool name on the remote MCP server
139
+ */
140
+ tool_name: string;
141
+ }
89
142
  /**
90
143
  * AgentTool represents a unified tool that can be used by an agent
91
144
  */
@@ -104,6 +157,8 @@ export interface AgentTool {
104
157
  app?: AppToolConfig;
105
158
  agent?: AgentToolConfig;
106
159
  hook?: HookToolConfig;
160
+ http?: HTTPToolConfig;
161
+ mcp?: MCPToolConfig;
107
162
  client?: ClientToolConfig;
108
163
  internal?: InternalToolConfig;
109
164
  }
@@ -129,6 +184,8 @@ export interface AgentToolDTO {
129
184
  app?: AppToolConfigDTO;
130
185
  agent?: AgentToolConfigDTO;
131
186
  hook?: HookToolConfigDTO;
187
+ http?: HTTPToolConfigDTO;
188
+ mcp?: MCPToolConfigDTO;
132
189
  client?: ClientToolConfigDTO;
133
190
  }
134
191
  export interface AppToolConfigDTO {
@@ -166,6 +223,20 @@ export interface ClientToolConfigDTO {
166
223
  input_schema?: any;
167
224
  output_schema?: any;
168
225
  }
226
+ export interface HTTPToolConfigDTO {
227
+ url: string;
228
+ method?: string;
229
+ auth?: ToolAuthConfig;
230
+ headers?: {
231
+ [key: string]: string;
232
+ };
233
+ input_schema?: any;
234
+ output_schema?: any;
235
+ }
236
+ export interface MCPToolConfigDTO {
237
+ integration_id: string;
238
+ tool_name: string;
239
+ }
169
240
  /**
170
241
  * CoreAppConfig references an app used as the agent's core
171
242
  */
@@ -375,6 +446,10 @@ export interface ApiAppRunRequest {
375
446
  * Task stays queued until this time. Past timestamps run immediately.
376
447
  */
377
448
  run_at?: string;
449
+ /**
450
+ * Optional metadata (e.g., action to trigger on completion)
451
+ */
452
+ metadata?: TaskMetadata;
378
453
  }
379
454
  /**
380
455
  * ApiAgentRunRequest is the request body for /agents/run endpoint.
@@ -592,6 +667,15 @@ export interface CheckoutCompleteRequest {
592
667
  */
593
668
  export type StripeCheckoutCreateRequest = CheckoutCreateRequest;
594
669
  export type StripeCheckoutCompleteRequest = CheckoutCompleteRequest;
670
+ /**
671
+ * AuthResponse is returned after successful authentication (OAuth, magic link, SSO)
672
+ */
673
+ export interface AuthResponse {
674
+ user?: UserDTO;
675
+ session_id: string;
676
+ otp_required?: boolean;
677
+ redirect_to?: string;
678
+ }
595
679
  /**
596
680
  * DeviceAuthResponse is returned when a device initiates auth
597
681
  */
@@ -740,8 +824,13 @@ export interface MoveAgentToProjectRequest {
740
824
  agent_id: string;
741
825
  project_id: string;
742
826
  }
827
+ /**
828
+ * WorkerGPUConfig holds GPU identifiers for a worker.
829
+ * GPUs accepts both integer indexes (legacy) and string GPU IDs.
830
+ * Use GPUIndexes() and GPUIDs() to separate them after unmarshaling.
831
+ */
743
832
  export interface WorkerGPUConfig {
744
- gpus: number[];
833
+ gpus: any[];
745
834
  }
746
835
  export interface WorkerCPUConfig {
747
836
  count: number;
@@ -1339,6 +1428,7 @@ export interface WorkerState extends BaseModel, PermissionModel {
1339
1428
  index: number;
1340
1429
  status: WorkerStatus;
1341
1430
  status_updated_at?: string;
1431
+ heartbeat_at?: string;
1342
1432
  engine_id: string;
1343
1433
  engine?: EngineState;
1344
1434
  task_id?: string;
@@ -1434,6 +1524,7 @@ export interface File extends BaseModel, PermissionModel {
1434
1524
  content_type: string;
1435
1525
  size: number;
1436
1526
  filename: string;
1527
+ category: string;
1437
1528
  rating: ContentRating;
1438
1529
  metadata?: FileMetadata;
1439
1530
  }
@@ -1445,6 +1536,7 @@ export interface FileDTO extends BaseModel, PermissionModelDTO {
1445
1536
  content_type: string;
1446
1537
  size: number;
1447
1538
  filename: string;
1539
+ category: string;
1448
1540
  rating: ContentRating;
1449
1541
  metadata?: FileMetadata;
1450
1542
  }
@@ -1462,6 +1554,10 @@ export interface FlowVersion extends BaseModel {
1462
1554
  * ConfigHash for deduplication - SHA256 of config content
1463
1555
  */
1464
1556
  config_hash: string;
1557
+ /**
1558
+ * GraphVersion is an incrementing counter for optimistic locking on action-based edits
1559
+ */
1560
+ graph_version: number;
1465
1561
  /**
1466
1562
  * Flow graph configuration
1467
1563
  */
@@ -1554,6 +1650,7 @@ export interface FlowDTO extends BaseModel, PermissionModelDTO {
1554
1650
  viewport?: FlowViewport;
1555
1651
  }
1556
1652
  export interface FlowVersionDTO extends BaseModel {
1653
+ graph_version: number;
1557
1654
  input_schema: any;
1558
1655
  input: FlowRunInputs;
1559
1656
  output_schema: any;
@@ -1690,6 +1787,7 @@ export type StringSlice = string[];
1690
1787
  export interface IntegrationDTO extends BaseModel, PermissionModelDTO {
1691
1788
  provider: string;
1692
1789
  type: string;
1790
+ auth: string;
1693
1791
  status: string;
1694
1792
  display_name: string;
1695
1793
  scopes: StringSlice;
@@ -1703,6 +1801,17 @@ export interface IntegrationDTO extends BaseModel, PermissionModelDTO {
1703
1801
  is_primary: boolean;
1704
1802
  error_message?: string;
1705
1803
  }
1804
+ /**
1805
+ * KnowledgeFile represents a file in a knowledge entry (stored as JSONB in knowledge_versions)
1806
+ */
1807
+ export interface KnowledgeFile {
1808
+ path: string;
1809
+ uri?: string;
1810
+ size: number;
1811
+ hash: string;
1812
+ content?: string;
1813
+ }
1814
+ export type SkillFile = KnowledgeFile;
1706
1815
  /**
1707
1816
  * ProjectType represents different types of projects
1708
1817
  */
@@ -1903,16 +2012,6 @@ export interface InstanceEnvVar {
1903
2012
  name: string;
1904
2013
  value: string;
1905
2014
  }
1906
- /**
1907
- * SkillFile represents a file in the skill directory (stored as JSONB in skill_versions)
1908
- */
1909
- export interface SkillFile {
1910
- path: string;
1911
- uri?: string;
1912
- size: number;
1913
- hash: string;
1914
- content?: string;
1915
- }
1916
2015
  /**
1917
2016
  * Hardware/System related types
1918
2017
  */
@@ -2054,6 +2153,21 @@ export type Infra = string;
2054
2153
  export declare const InfraPrivate: Infra;
2055
2154
  export declare const InfraCloud: Infra;
2056
2155
  export declare const InfraPrivateFirst: Infra;
2156
+ /**
2157
+ * TaskAction defines an action to execute when a task reaches a specific status.
2158
+ * Used by the action projector to trigger side effects (e.g., updating app covers).
2159
+ */
2160
+ export interface TaskAction {
2161
+ key: string;
2162
+ on: string;
2163
+ params?: any;
2164
+ }
2165
+ /**
2166
+ * TaskMetadata holds optional metadata attached to a task.
2167
+ */
2168
+ export interface TaskMetadata {
2169
+ action?: TaskAction;
2170
+ }
2057
2171
  export interface Task extends BaseModel, PermissionModel {
2058
2172
  is_featured: boolean;
2059
2173
  status: TaskStatus;
@@ -2090,6 +2204,7 @@ export interface Task extends BaseModel, PermissionModel {
2090
2204
  */
2091
2205
  sub_flow_run_id?: string;
2092
2206
  webhook?: string;
2207
+ metadata?: TaskMetadata;
2093
2208
  setup?: any;
2094
2209
  input: any;
2095
2210
  output: any;
package/dist/types.js CHANGED
@@ -1,7 +1,9 @@
1
- // Code generated by tygo. DO NOT EDIT.
1
+ // Code generated by gotypegen. DO NOT EDIT.
2
2
  export const ToolTypeApp = "app"; // App tools - creates a Task
3
3
  export const ToolTypeAgent = "agent"; // Sub-agent tools - creates a sub-Chat
4
- export const ToolTypeHook = "hook"; // Webhook tools - HTTP POST to external URL
4
+ export const ToolTypeHook = "hook"; // Webhook tools - HTTP POST to external URL (legacy)
5
+ export const ToolTypeHTTP = "http"; // HTTP tools - authenticated HTTP request/response
6
+ export const ToolTypeMCP = "mcp"; // MCP tools - calls remote MCP server
5
7
  export const ToolTypeClient = "client"; // Client tools - executed by frontend
6
8
  export const ToolTypeInternal = "internal"; // Internal/built-in tools (plan, memory, widget, finish)
7
9
  export const ScopeGroupAgents = "agents";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
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",