@inferencesh/sdk 0.4.13 → 0.4.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/dist/client.d.ts CHANGED
@@ -111,11 +111,41 @@ export declare class Inference {
111
111
  run(params: ApiAppRunRequest, options?: RunOptions): Promise<Task>;
112
112
  uploadFile(data: string | Blob, options?: UploadFileOptions): Promise<File>;
113
113
  /**
114
- * Cancel a running task
115
- *
116
- * @param taskId - The ID of the task to cancel
117
- */
114
+ * Cancel a running task
115
+ *
116
+ * @param taskId - The ID of the task to cancel
117
+ */
118
118
  cancel(taskId: string): Promise<void>;
119
+ /**
120
+ * Get a task by ID
121
+ *
122
+ * @param taskId - The ID of the task to fetch
123
+ * @returns The task data
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const task = await client.getTask('abc123');
128
+ * console.log(task.status, task.output);
129
+ * ```
130
+ */
131
+ getTask(taskId: string): Promise<Task>;
132
+ /**
133
+ * Create an EventSource for streaming task updates
134
+ *
135
+ * @param taskId - The ID of the task to stream
136
+ * @returns EventSource for SSE streaming
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const eventSource = client.streamTask('abc123');
141
+ * // Use with StreamManager for handling updates
142
+ * const manager = new StreamManager({
143
+ * createEventSource: () => client.streamTask(taskId),
144
+ * onData: (task) => console.log(task),
145
+ * });
146
+ * ```
147
+ */
148
+ streamTask(taskId: string): EventSource;
119
149
  /**
120
150
  * Create an agent for chat interactions
121
151
  *
package/dist/client.js CHANGED
@@ -342,13 +342,47 @@ class Inference {
342
342
  return file;
343
343
  }
344
344
  /**
345
- * Cancel a running task
346
- *
347
- * @param taskId - The ID of the task to cancel
348
- */
345
+ * Cancel a running task
346
+ *
347
+ * @param taskId - The ID of the task to cancel
348
+ */
349
349
  async cancel(taskId) {
350
350
  return this._request("post", `/tasks/${taskId}/cancel`);
351
351
  }
352
+ /**
353
+ * Get a task by ID
354
+ *
355
+ * @param taskId - The ID of the task to fetch
356
+ * @returns The task data
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const task = await client.getTask('abc123');
361
+ * console.log(task.status, task.output);
362
+ * ```
363
+ */
364
+ async getTask(taskId) {
365
+ return this._request("get", `/tasks/${taskId}`);
366
+ }
367
+ /**
368
+ * Create an EventSource for streaming task updates
369
+ *
370
+ * @param taskId - The ID of the task to stream
371
+ * @returns EventSource for SSE streaming
372
+ *
373
+ * @example
374
+ * ```typescript
375
+ * const eventSource = client.streamTask('abc123');
376
+ * // Use with StreamManager for handling updates
377
+ * const manager = new StreamManager({
378
+ * createEventSource: () => client.streamTask(taskId),
379
+ * onData: (task) => console.log(task),
380
+ * });
381
+ * ```
382
+ */
383
+ streamTask(taskId) {
384
+ return this._createEventSource(`/tasks/${taskId}/stream`);
385
+ }
352
386
  /**
353
387
  * Create an agent for chat interactions
354
388
  *
@@ -409,7 +443,7 @@ class Agent {
409
443
  const isTemplate = typeof this.config === 'string';
410
444
  const hasCallbacks = !!(options.onMessage || options.onChat || options.onToolCall);
411
445
  // Process files - either already uploaded (FileDTO with uri) or needs upload (Blob)
412
- let imageUri;
446
+ let imageUris;
413
447
  let fileUris;
414
448
  if (options.files && options.files.length > 0) {
415
449
  // Separate files that need uploading from those already uploaded
@@ -434,7 +468,7 @@ class Agent {
434
468
  const images = allFiles.filter((f) => f.content_type?.startsWith('image/'));
435
469
  const others = allFiles.filter((f) => !f.content_type?.startsWith('image/'));
436
470
  if (images.length > 0)
437
- imageUri = images[0].uri;
471
+ imageUris = images.map((f) => f.uri);
438
472
  if (others.length > 0)
439
473
  fileUris = others.map((f) => f.uri);
440
474
  }
@@ -442,13 +476,13 @@ class Agent {
442
476
  ? {
443
477
  chat_id: this.chatId,
444
478
  agent: this.config,
445
- input: { text, image: imageUri, files: fileUris, role: 'user', context: [], system_prompt: '', context_size: 0 },
479
+ input: { text, images: imageUris, files: fileUris, role: 'user', context: [], system_prompt: '', context_size: 0 },
446
480
  }
447
481
  : {
448
482
  chat_id: this.chatId,
449
483
  agent_config: this.config,
450
484
  agent_name: this.agentName,
451
- input: { text, image: imageUri, files: fileUris, role: 'user', context: [], system_prompt: '', context_size: 0 },
485
+ input: { text, images: imageUris, files: fileUris, role: 'user', context: [], system_prompt: '', context_size: 0 },
452
486
  };
453
487
  // For existing chats with callbacks: Start streaming BEFORE POST so we don't miss updates
454
488
  let streamPromise = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.4.13",
3
+ "version": "0.4.17",
4
4
  "description": "Official JavaScript/TypeScript SDK for inference.sh - Run AI models with a simple API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",