@inferencesh/sdk 0.5.7 → 0.5.9

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/api/tasks.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { StreamManager } from '../http/stream';
2
2
  import { PollManager } from '../http/poll';
3
3
  import { TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, } from '../types';
4
+ import { parseStatus } from '../utils';
4
5
  //TODO: This is ugly...
5
6
  function stripTask(task) {
6
7
  return {
@@ -97,15 +98,15 @@ export class TasksAPI {
97
98
  accumulatedTask = { ...accumulatedTask, ...data };
98
99
  const stripped = stripTask(accumulatedTask);
99
100
  onUpdate?.(stripped);
100
- if (data.status === TaskStatusCompleted) {
101
+ if (parseStatus(data.status) === TaskStatusCompleted) {
101
102
  streamManager.stop();
102
103
  resolve(stripped);
103
104
  }
104
- else if (data.status === TaskStatusFailed) {
105
+ else if (parseStatus(data.status) === TaskStatusFailed) {
105
106
  streamManager.stop();
106
107
  reject(new Error(data.error || 'task failed'));
107
108
  }
108
- else if (data.status === TaskStatusCancelled) {
109
+ else if (parseStatus(data.status) === TaskStatusCancelled) {
109
110
  streamManager.stop();
110
111
  reject(new Error('task cancelled'));
111
112
  }
@@ -115,15 +116,15 @@ export class TasksAPI {
115
116
  accumulatedTask = { ...accumulatedTask, ...data };
116
117
  const stripped = stripTask(accumulatedTask);
117
118
  onPartialUpdate?.(stripped, fields);
118
- if (data.status === TaskStatusCompleted) {
119
+ if (parseStatus(data.status) === TaskStatusCompleted) {
119
120
  streamManager.stop();
120
121
  resolve(stripped);
121
122
  }
122
- else if (data.status === TaskStatusFailed) {
123
+ else if (parseStatus(data.status) === TaskStatusFailed) {
123
124
  streamManager.stop();
124
125
  reject(new Error(data.error || 'task failed'));
125
126
  }
126
- else if (data.status === TaskStatusCancelled) {
127
+ else if (parseStatus(data.status) === TaskStatusCancelled) {
127
128
  streamManager.stop();
128
129
  reject(new Error('task cancelled'));
129
130
  }
@@ -155,15 +156,15 @@ export class TasksAPI {
155
156
  const fullTask = await this.http.request('get', `/tasks/${task.id}`);
156
157
  const stripped = stripTask(fullTask);
157
158
  onUpdate?.(stripped);
158
- if (fullTask.status === TaskStatusCompleted) {
159
+ if (parseStatus(fullTask.status) === TaskStatusCompleted) {
159
160
  poller.stop();
160
161
  resolve(stripped);
161
162
  }
162
- else if (fullTask.status === TaskStatusFailed) {
163
+ else if (parseStatus(fullTask.status) === TaskStatusFailed) {
163
164
  poller.stop();
164
165
  reject(new Error(fullTask.error || 'task failed'));
165
166
  }
166
- else if (fullTask.status === TaskStatusCancelled) {
167
+ else if (parseStatus(fullTask.status) === TaskStatusCancelled) {
167
168
  poller.stop();
168
169
  reject(new Error('task cancelled'));
169
170
  }
@@ -23,10 +23,12 @@ export declare class InferenceError extends Error {
23
23
  *
24
24
  * @example
25
25
  * ```typescript
26
+ * import { isRequirementsNotMetException } from '@inferencesh/sdk';
27
+ *
26
28
  * try {
27
29
  * const task = await client.run(params);
28
30
  * } catch (e) {
29
- * if (e instanceof RequirementsNotMetException) {
31
+ * if (isRequirementsNotMetException(e)) {
30
32
  * for (const err of e.errors) {
31
33
  * console.log(`Missing ${err.type}: ${err.key}`);
32
34
  * if (err.action) {
@@ -130,3 +132,16 @@ export declare class SessionEndedError extends SessionError {
130
132
  export declare class WorkerLostError extends SessionError {
131
133
  constructor(sessionId: string, responseBody?: string);
132
134
  }
135
+ /**
136
+ * Type guard for RequirementsNotMetException.
137
+ * Handles cross-module issues where instanceof may fail.
138
+ */
139
+ export declare function isRequirementsNotMetException(err: unknown): err is RequirementsNotMetException;
140
+ /**
141
+ * Type guard for InferenceError.
142
+ */
143
+ export declare function isInferenceError(err: unknown): err is InferenceError;
144
+ /**
145
+ * Type guard for SessionError (or any subclass).
146
+ */
147
+ export declare function isSessionError(err: unknown): err is SessionError;
@@ -25,10 +25,12 @@ export class InferenceError extends Error {
25
25
  *
26
26
  * @example
27
27
  * ```typescript
28
+ * import { isRequirementsNotMetException } from '@inferencesh/sdk';
29
+ *
28
30
  * try {
29
31
  * const task = await client.run(params);
30
32
  * } catch (e) {
31
- * if (e instanceof RequirementsNotMetException) {
33
+ * if (isRequirementsNotMetException(e)) {
32
34
  * for (const err of e.errors) {
33
35
  * console.log(`Missing ${err.type}: ${err.key}`);
34
36
  * if (err.action) {
@@ -152,3 +154,44 @@ export class WorkerLostError extends SessionError {
152
154
  this.name = 'WorkerLostError';
153
155
  }
154
156
  }
157
+ // =============================================================================
158
+ // Type Guards
159
+ // =============================================================================
160
+ // These handle cross-module/bundle issues where instanceof may fail.
161
+ // Use these instead of instanceof for reliable error checking.
162
+ /**
163
+ * Type guard for RequirementsNotMetException.
164
+ * Handles cross-module issues where instanceof may fail.
165
+ */
166
+ export function isRequirementsNotMetException(err) {
167
+ if (err instanceof RequirementsNotMetException)
168
+ return true;
169
+ if (typeof err !== 'object' || err === null)
170
+ return false;
171
+ const e = err;
172
+ return e.name === 'RequirementsNotMetException' ||
173
+ (e.statusCode === 412 && Array.isArray(e.errors));
174
+ }
175
+ /**
176
+ * Type guard for InferenceError.
177
+ */
178
+ export function isInferenceError(err) {
179
+ if (err instanceof InferenceError)
180
+ return true;
181
+ if (typeof err !== 'object' || err === null)
182
+ return false;
183
+ const e = err;
184
+ return e.name === 'InferenceError' && typeof e.statusCode === 'number';
185
+ }
186
+ /**
187
+ * Type guard for SessionError (or any subclass).
188
+ */
189
+ export function isSessionError(err) {
190
+ if (err instanceof SessionError)
191
+ return true;
192
+ if (typeof err !== 'object' || err === null)
193
+ return false;
194
+ const e = err;
195
+ return typeof e.sessionId === 'string' && typeof e.statusCode === 'number' &&
196
+ ['SessionError', 'SessionNotFoundError', 'SessionExpiredError', 'SessionEndedError', 'WorkerLostError'].includes(e.name);
197
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { HttpClient, HttpClientConfig, ErrorHandler, createHttpClient } from './http/client';
2
2
  export { StreamManager, StreamManagerOptions, PartialDataWrapper } from './http/stream';
3
3
  export { PollManager, PollManagerOptions } from './http/poll';
4
- export { InferenceError, RequirementsNotMetException, SessionError, SessionNotFoundError, SessionExpiredError, SessionEndedError, WorkerLostError, } from './http/errors';
4
+ export { InferenceError, RequirementsNotMetException, SessionError, SessionNotFoundError, SessionExpiredError, SessionEndedError, WorkerLostError, isRequirementsNotMetException, isInferenceError, isSessionError, } from './http/errors';
5
5
  export { TasksAPI, RunOptions } from './api/tasks';
6
6
  export { FilesAPI, UploadFileOptions } from './api/files';
7
7
  export { AgentsAPI, Agent, AgentOptions, SendMessageOptions, AgentRunOptions } from './api/agents';
@@ -13,6 +13,7 @@ export { FlowRunsAPI } from './api/flow-runs';
13
13
  export { EnginesAPI } from './api/engines';
14
14
  export { tool, appTool, agentTool, webhookTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
15
15
  export type { ClientTool, ClientToolHandler } from './tool-builder';
16
+ export { parseStatus, isTerminalStatus } from './utils';
16
17
  export * from './types';
17
18
  export type { TaskDTO as Task } from './types';
18
19
  import { HttpClient, HttpClientConfig } from './http/client';
package/dist/index.js CHANGED
@@ -2,7 +2,9 @@
2
2
  export { HttpClient, createHttpClient } from './http/client';
3
3
  export { StreamManager } from './http/stream';
4
4
  export { PollManager } from './http/poll';
5
- export { InferenceError, RequirementsNotMetException, SessionError, SessionNotFoundError, SessionExpiredError, SessionEndedError, WorkerLostError, } from './http/errors';
5
+ export { InferenceError, RequirementsNotMetException, SessionError, SessionNotFoundError, SessionExpiredError, SessionEndedError, WorkerLostError,
6
+ // Type guards (use these instead of instanceof for reliability)
7
+ isRequirementsNotMetException, isInferenceError, isSessionError, } from './http/errors';
6
8
  // API modules
7
9
  export { TasksAPI } from './api/tasks';
8
10
  export { FilesAPI } from './api/files';
@@ -15,6 +17,8 @@ export { FlowRunsAPI } from './api/flow-runs';
15
17
  export { EnginesAPI } from './api/engines';
16
18
  // Tool Builder (fluent API)
17
19
  export { tool, appTool, agentTool, webhookTool, internalTools, string, number, integer, boolean, enumOf, object, array, optional, } from './tool-builder';
20
+ // Status utilities (handle both int and string status values)
21
+ export { parseStatus, isTerminalStatus } from './utils';
18
22
  // Types - includes TaskStatus constants and all DTOs
19
23
  export * from './types';
20
24
  // =============================================================================
@@ -76,6 +76,17 @@ describeIfApiKey('Integration Tests', () => {
76
76
  expect(result.id).toBeDefined();
77
77
  }, 30000);
78
78
  });
79
+ describe('Webhook', () => {
80
+ it('should deliver webhook on task completion', async () => {
81
+ const result = await client.run({
82
+ app: TEST_APP,
83
+ input: { template: 'Webhook test {1}', strings: ['hello'] },
84
+ webhook: 'https://webhook.site/bbe9ba01-3ab2-4056-a1b1-1cf6969987d5',
85
+ });
86
+ expect(result.status).toBe(TaskStatusCompleted);
87
+ expect(result.output).toBeDefined();
88
+ }, 60000);
89
+ });
79
90
  describe('Error Handling', () => {
80
91
  it('should throw an error for non-existent app', async () => {
81
92
  await expect(client.run({
package/dist/types.d.ts CHANGED
@@ -349,6 +349,11 @@ export interface ApiAppRunRequest {
349
349
  * If true, returns SSE stream instead of JSON response
350
350
  */
351
351
  stream?: boolean;
352
+ /**
353
+ * If true, holds the connection open until the task reaches a terminal state and returns the final result.
354
+ * Mutually exclusive with Stream.
355
+ */
356
+ wait?: boolean;
352
357
  /**
353
358
  * Function to call on multi-function apps (defaults to "run" or app's default_function)
354
359
  */
@@ -362,6 +367,11 @@ export interface ApiAppRunRequest {
362
367
  * Session timeout in seconds (1-3600). Only valid when session="new"
363
368
  */
364
369
  session_timeout?: number;
370
+ /**
371
+ * Schedule execution for a specific time (ISO 8601 UTC, e.g. "2026-02-24T15:30:00Z").
372
+ * Task stays queued until this time. Past timestamps run immediately.
373
+ */
374
+ run_at?: string;
365
375
  }
366
376
  /**
367
377
  * ApiAgentRunRequest is the request body for /agents/run endpoint.
@@ -436,6 +446,14 @@ export interface CreateAgentMessageResponse {
436
446
  export interface ToolResultRequest {
437
447
  result: string;
438
448
  }
449
+ /**
450
+ * WebhookEvent is the envelope for task webhook deliveries.
451
+ */
452
+ export interface WebhookEvent<T extends any> {
453
+ event: string;
454
+ timestamp: string;
455
+ data: T;
456
+ }
439
457
  /**
440
458
  * HookPayload represents the request body sent to a webhook when a hook tool is invoked
441
459
  */
@@ -520,6 +538,7 @@ export interface CreateAgentRequest {
520
538
  export interface SDKTypes {
521
539
  }
522
540
  export interface SkillPublishRequest {
541
+ namespace?: string;
523
542
  name: string;
524
543
  description: string;
525
544
  category: string;
@@ -720,6 +739,16 @@ export interface EngineConfig {
720
739
  network_name: string;
721
740
  cache_path: string;
722
741
  gpus: string[];
742
+ /**
743
+ * CallbackBasePort overrides the base port for engine↔worker callback APIs.
744
+ * If 0, derived from EnginePort: 5000 + (enginePort - 8163) * 100.
745
+ */
746
+ callback_base_port: number;
747
+ /**
748
+ * EngineInternalAPIURL is the URL workers use to reach the engine's main API.
749
+ * If empty, derived as http://host.docker.internal:{EnginePort}.
750
+ */
751
+ engine_internal_api_url: string;
723
752
  }
724
753
  export type AppCategory = string;
725
754
  export declare const AppCategoryImage: AppCategory;
@@ -954,6 +983,12 @@ export interface ResourceStatusDTO {
954
983
  status: any;
955
984
  updated_at: string;
956
985
  }
986
+ /**
987
+ * PaymentProvider represents the payment provider being used
988
+ */
989
+ export type PaymentProvider = string;
990
+ export declare const PaymentProviderNone: PaymentProvider;
991
+ export declare const PaymentProviderStripe: PaymentProvider;
957
992
  export type ChatStatus = string;
958
993
  export declare const ChatStatusBusy: ChatStatus;
959
994
  export declare const ChatStatusIdle: ChatStatus;
@@ -1188,6 +1223,7 @@ export declare const DeviceAuthStatusLoading: DeviceAuthStatus;
1188
1223
  export type EngineStatus = string;
1189
1224
  export declare const EngineStatusRunning: EngineStatus;
1190
1225
  export declare const EngineStatusPending: EngineStatus;
1226
+ export declare const EngineStatusDraining: EngineStatus;
1191
1227
  export declare const EngineStatusStopping: EngineStatus;
1192
1228
  export declare const EngineStatusStopped: EngineStatus;
1193
1229
  export interface EngineState extends BaseModel, PermissionModel {
@@ -1585,6 +1621,167 @@ export interface IntegrationDTO extends BaseModel, PermissionModelDTO {
1585
1621
  is_primary: boolean;
1586
1622
  error_message?: string;
1587
1623
  }
1624
+ /**
1625
+ * InvoiceType distinguishes invoices from credit notes
1626
+ */
1627
+ export type InvoiceType = string;
1628
+ export declare const InvoiceTypeInvoice: InvoiceType;
1629
+ export declare const InvoiceTypeCreditNote: InvoiceType;
1630
+ /**
1631
+ * InvoiceStatus represents the lifecycle status of an invoice
1632
+ */
1633
+ export type InvoiceStatus = string;
1634
+ export declare const InvoiceStatusDraft: InvoiceStatus;
1635
+ export declare const InvoiceStatusFinalized: InvoiceStatus;
1636
+ export declare const InvoiceStatusCorrected: InvoiceStatus;
1637
+ export declare const InvoiceStatusVoided: InvoiceStatus;
1638
+ /**
1639
+ * TaxMode determines how tax is handled on the invoice
1640
+ */
1641
+ export type TaxMode = string;
1642
+ export declare const TaxModeNone: TaxMode;
1643
+ export declare const TaxModeVAT: TaxMode;
1644
+ export declare const TaxModeReverseCharge: TaxMode;
1645
+ /**
1646
+ * Invoice represents a legal invoice or credit note
1647
+ */
1648
+ export interface Invoice extends BaseModel, PermissionModel {
1649
+ /**
1650
+ * Invoice Identity
1651
+ */
1652
+ type: InvoiceType;
1653
+ invoice_number: string;
1654
+ series: string;
1655
+ status: InvoiceStatus;
1656
+ /**
1657
+ * Dates
1658
+ */
1659
+ issue_date: string;
1660
+ service_period_start?: string;
1661
+ service_period_end?: string;
1662
+ finalized_at?: string;
1663
+ /**
1664
+ * Issuer Snapshot (frozen from admin settings at creation)
1665
+ */
1666
+ issuer_legal_name: string;
1667
+ issuer_address: string;
1668
+ issuer_country: string;
1669
+ issuer_tax_id: string;
1670
+ issuer_email: string;
1671
+ /**
1672
+ * Customer Snapshot (frozen from BillingSettings at creation)
1673
+ */
1674
+ customer_legal_name: string;
1675
+ customer_address: string;
1676
+ customer_country: string;
1677
+ customer_vat_number: string;
1678
+ customer_email: string;
1679
+ is_business_customer: boolean;
1680
+ customer_vat_validated: boolean;
1681
+ /**
1682
+ * Financial (all amounts in cents, matches PaymentRecord)
1683
+ * For credit notes, amounts are NEGATIVE
1684
+ */
1685
+ currency: string;
1686
+ subtotal_amount: number;
1687
+ service_fee: number;
1688
+ tax_rate: number;
1689
+ tax_amount: number;
1690
+ total_amount: number;
1691
+ tax_mode: TaxMode;
1692
+ /**
1693
+ * Linkage to payment
1694
+ */
1695
+ payment_record_id: string;
1696
+ provider_payment_id: string;
1697
+ /**
1698
+ * Corrections (for credit notes referencing original invoice)
1699
+ */
1700
+ original_invoice_id?: string;
1701
+ correction_reason: string;
1702
+ /**
1703
+ * Storage
1704
+ */
1705
+ pdf_path: string;
1706
+ snapshot: string;
1707
+ /**
1708
+ * Relations
1709
+ */
1710
+ items: InvoiceItem[];
1711
+ }
1712
+ /**
1713
+ * InvoiceItem represents a line item on an invoice
1714
+ */
1715
+ export interface InvoiceItem extends BaseModel {
1716
+ invoice_id: string;
1717
+ description: string;
1718
+ quantity: number;
1719
+ unit_price: number;
1720
+ line_total: number;
1721
+ }
1722
+ /**
1723
+ * PaymentRecordStatus represents the status of a payment
1724
+ */
1725
+ export type PaymentRecordStatus = number;
1726
+ export declare const PaymentRecordStatusPending: PaymentRecordStatus;
1727
+ export declare const PaymentRecordStatusComplete: PaymentRecordStatus;
1728
+ export declare const PaymentRecordStatusFailed: PaymentRecordStatus;
1729
+ export declare const PaymentRecordStatusExpired: PaymentRecordStatus;
1730
+ /**
1731
+ * PaymentRecordType represents the type of payment
1732
+ */
1733
+ export type PaymentRecordType = string;
1734
+ export declare const PaymentRecordTypeCheckout: PaymentRecordType;
1735
+ export declare const PaymentRecordTypeAutoRecharge: PaymentRecordType;
1736
+ /**
1737
+ * TaxBreakdownItem represents a single tax component
1738
+ */
1739
+ export interface TaxBreakdownItem {
1740
+ amount: number;
1741
+ rate: number;
1742
+ jurisdiction?: string;
1743
+ display_name?: string;
1744
+ inclusive?: boolean;
1745
+ }
1746
+ /**
1747
+ * PaymentRecord stores payment details for checkout sessions and direct charges (provider-agnostic)
1748
+ * Field naming follows Stripe conventions for financial clarity.
1749
+ */
1750
+ export interface PaymentRecord extends BaseModel, PermissionModel {
1751
+ type: PaymentRecordType;
1752
+ status: PaymentRecordStatus;
1753
+ currency: string;
1754
+ /**
1755
+ * Financial amounts (Stripe-style naming)
1756
+ */
1757
+ credit_amount: number;
1758
+ service_fee: number;
1759
+ amount_subtotal: number;
1760
+ amount_tax: number;
1761
+ amount_total: number;
1762
+ /**
1763
+ * Tax breakdown by jurisdiction (for invoicing)
1764
+ */
1765
+ tax_breakdown?: TaxBreakdownItem[];
1766
+ /**
1767
+ * Provider-agnostic fields
1768
+ */
1769
+ provider: PaymentProvider;
1770
+ provider_customer_id: string;
1771
+ provider_session_id: string;
1772
+ provider_payment_id: string;
1773
+ receipt_url: string;
1774
+ /**
1775
+ * Provider-specific details (checkout URLs, session IDs, etc.)
1776
+ */
1777
+ provider_metadata: {
1778
+ [key: string]: any;
1779
+ };
1780
+ /**
1781
+ * Related invoice (if one exists) - loaded via preload
1782
+ */
1783
+ invoice?: Invoice;
1784
+ }
1588
1785
  /**
1589
1786
  * ProjectType represents different types of projects
1590
1787
  */
@@ -1912,21 +2109,17 @@ export interface HFCacheInfo {
1912
2109
  /**
1913
2110
  * TaskStatus represents the state of a task in its lifecycle.
1914
2111
  * DESIGN NOTES:
1915
- * - Stored as int in DB for compact storage and efficient equality checks.
1916
- * - The int values are ordered to allow SQL range queries (status < ?) for performance.
1917
- * - IMPORTANT: If you add new statuses in the MIDDLE of the sequence, you must:
1918
- * 1. Write a migration to shift existing values
1919
- * 2. Update SDKs and frontends
1920
- * - ALTERNATIVE: Add new statuses at the END to avoid migrations, but then you
1921
- * cannot use range comparisons (< >) and must use explicit checks (IN, NOT IN).
1922
- * - Kubernetes/Temporal use strings and explicit checks for maximum flexibility.
1923
- * Consider switching to strings if range comparisons become a maintenance burden.
2112
+ * - Stored as int in DB for compact storage. New statuses can be added with any int value.
2113
+ * - Logical ordering is defined by statusOrder map, NOT by the int values.
2114
+ * - To add a new status: add const with next available int, add to statusOrder at correct position.
2115
+ * - SQL queries use explicit lists (IN, NOT IN) via helper functions, not range comparisons.
2116
+ * - This design allows future migration to string-based storage without breaking changes.
1924
2117
  */
1925
2118
  export type TaskStatus = number;
1926
2119
  export declare const TaskStatusUnknown: TaskStatus;
1927
2120
  export declare const TaskStatusReceived: TaskStatus;
1928
2121
  export declare const TaskStatusQueued: TaskStatus;
1929
- export declare const TaskStatusScheduled: TaskStatus;
2122
+ export declare const TaskStatusDispatched: TaskStatus;
1930
2123
  export declare const TaskStatusPreparing: TaskStatus;
1931
2124
  export declare const TaskStatusServing: TaskStatus;
1932
2125
  export declare const TaskStatusSettingUp: TaskStatus;
@@ -1979,7 +2172,7 @@ export interface Task extends BaseModel, PermissionModel {
1979
2172
  setup?: any;
1980
2173
  input: any;
1981
2174
  output: any;
1982
- error: string;
2175
+ error?: string;
1983
2176
  rating: ContentRating;
1984
2177
  /**
1985
2178
  * Relationships
@@ -2004,6 +2197,10 @@ export interface Task extends BaseModel, PermissionModel {
2004
2197
  * Session timeout in seconds (only used when session="new")
2005
2198
  */
2006
2199
  session_timeout?: number;
2200
+ /**
2201
+ * Scheduled execution time (UTC). Scheduler skips task until this time.
2202
+ */
2203
+ run_at?: string;
2007
2204
  }
2008
2205
  export interface TaskEvent {
2009
2206
  id: string;
@@ -2050,11 +2247,12 @@ export interface TaskDTO extends BaseModel, PermissionModelDTO {
2050
2247
  engine?: EngineStateSummary;
2051
2248
  worker_id?: string;
2052
2249
  worker?: WorkerStateSummary;
2250
+ run_at?: string;
2053
2251
  webhook?: string;
2054
2252
  setup?: any;
2055
2253
  input: any;
2056
2254
  output: any;
2057
- error: string;
2255
+ error?: string;
2058
2256
  rating: ContentRating;
2059
2257
  events: TaskEvent[];
2060
2258
  logs: TaskLog[];
@@ -2092,6 +2290,10 @@ export interface Team extends BaseModel {
2092
2290
  * Personal teams start with SetupCompleted=false and a generated temporary username
2093
2291
  */
2094
2292
  setup_completed: boolean;
2293
+ /**
2294
+ * MaxConcurrency limits total active tasks for this team (0 = use default)
2295
+ */
2296
+ max_concurrency: number;
2095
2297
  }
2096
2298
  export interface TeamDTO extends BaseModel {
2097
2299
  type: TeamType;
@@ -2100,6 +2302,7 @@ export interface TeamDTO extends BaseModel {
2100
2302
  avatar_url: string;
2101
2303
  email: string;
2102
2304
  setup_completed: boolean;
2305
+ max_concurrency: number;
2103
2306
  }
2104
2307
  export type TeamRole = string;
2105
2308
  export declare const TeamRoleOwner: TeamRole;
@@ -2208,37 +2411,6 @@ export interface Transaction extends BaseModel {
2208
2411
  */
2209
2412
  side_effects_processed: boolean;
2210
2413
  }
2211
- /**
2212
- * PaymentRecordStatus represents the status of a payment
2213
- */
2214
- export type PaymentRecordStatus = number;
2215
- export declare const PaymentRecordStatusPending: PaymentRecordStatus;
2216
- export declare const PaymentRecordStatusComplete: PaymentRecordStatus;
2217
- export declare const PaymentRecordStatusFailed: PaymentRecordStatus;
2218
- export declare const PaymentRecordStatusExpired: PaymentRecordStatus;
2219
- /**
2220
- * PaymentRecordType represents the type of payment
2221
- */
2222
- export type PaymentRecordType = string;
2223
- export declare const PaymentRecordTypeCheckout: PaymentRecordType;
2224
- export declare const PaymentRecordTypeAutoRecharge: PaymentRecordType;
2225
- /**
2226
- * PaymentRecord stores Stripe payment details for both checkout sessions and direct charges
2227
- */
2228
- export interface PaymentRecord extends BaseModel, PermissionModel {
2229
- type: PaymentRecordType;
2230
- status: PaymentRecordStatus;
2231
- amount: number;
2232
- service_fee: number;
2233
- stripe_customer_id: string;
2234
- payment_intent_id: string;
2235
- receipt_url: string;
2236
- /**
2237
- * Checkout-specific fields (only set for checkout type)
2238
- */
2239
- session_id: string;
2240
- session_url: string;
2241
- }
2242
2414
  export type UsageEventResourceTier = string;
2243
2415
  export declare const UsageEventResourceTierPrivate: UsageEventResourceTier;
2244
2416
  export declare const UsageEventResourceTierCloud: UsageEventResourceTier;
@@ -2290,6 +2462,10 @@ export interface MetaItem {
2290
2462
  * Audio specific fields
2291
2463
  */
2292
2464
  sample_rate?: number;
2465
+ /**
2466
+ * Raw specific fields
2467
+ */
2468
+ cost?: number;
2293
2469
  /**
2294
2470
  * App-specific key-value pairs for custom pricing factors
2295
2471
  */
@@ -2324,6 +2500,17 @@ export interface DiscountItem {
2324
2500
  reason: string;
2325
2501
  amount: number;
2326
2502
  }
2503
+ /**
2504
+ * FeeConfig controls which fees are enabled for billing.
2505
+ * Used in CEL evaluation context (as "fees") and stored for auditing.
2506
+ * true = fee is enabled/charged, false = fee is disabled/skipped.
2507
+ * nil FeeConfig defaults to all fees enabled.
2508
+ */
2509
+ export interface FeeConfig {
2510
+ inference?: boolean;
2511
+ royalty?: boolean;
2512
+ partner?: boolean;
2513
+ }
2327
2514
  export interface UsageBillingRecord extends BaseModel, PermissionModel {
2328
2515
  /**
2329
2516
  * Fee breakdown (all in microcents)
package/dist/types.js CHANGED
@@ -24,6 +24,8 @@ export const AppSessionStatusExpired = "expired";
24
24
  export const VisibilityPrivate = "private";
25
25
  export const VisibilityPublic = "public";
26
26
  export const VisibilityUnlisted = "unlisted";
27
+ export const PaymentProviderNone = "";
28
+ export const PaymentProviderStripe = "stripe";
27
29
  export const ChatStatusBusy = "busy";
28
30
  export const ChatStatusIdle = "idle";
29
31
  export const ChatStatusAwaitingInput = "awaiting_input";
@@ -80,6 +82,7 @@ export const DeviceAuthStatusInvalid = "invalid";
80
82
  export const DeviceAuthStatusLoading = "loading";
81
83
  export const EngineStatusRunning = "running";
82
84
  export const EngineStatusPending = "pending";
85
+ export const EngineStatusDraining = "draining";
83
86
  export const EngineStatusStopping = "stopping";
84
87
  export const EngineStatusStopped = "stopped";
85
88
  export const FlowRunStatusUnknown = 0; // 0
@@ -108,6 +111,21 @@ export const GraphEdgeTypeDependency = "dependency"; // Blocking dependency
108
111
  export const GraphEdgeTypeFlow = "flow"; // Non-blocking flow
109
112
  export const GraphEdgeTypeConditional = "conditional"; // Conditional flow
110
113
  export const GraphEdgeTypeExecution = "execution"; // Node → Resource execution link
114
+ export const InvoiceTypeInvoice = "invoice";
115
+ export const InvoiceTypeCreditNote = "credit_note";
116
+ export const InvoiceStatusDraft = "draft"; // Not yet finalized, can be edited
117
+ export const InvoiceStatusFinalized = "finalized"; // Locked, has invoice number
118
+ export const InvoiceStatusCorrected = "corrected"; // Superseded by a credit note
119
+ export const InvoiceStatusVoided = "voided"; // Cancelled before finalize
120
+ export const TaxModeNone = "none"; // No VAT (US domestic, non-EU)
121
+ export const TaxModeVAT = "vat"; // VAT charged (EU B2C)
122
+ export const TaxModeReverseCharge = "reverse_charge"; // Reverse charge (EU B2B)
123
+ export const PaymentRecordStatusPending = 0;
124
+ export const PaymentRecordStatusComplete = 1;
125
+ export const PaymentRecordStatusFailed = 2;
126
+ export const PaymentRecordStatusExpired = 3;
127
+ export const PaymentRecordTypeCheckout = "checkout"; // Checkout session (manual top-up)
128
+ export const PaymentRecordTypeAutoRecharge = "auto_recharge"; // Direct charge (auto-recharge)
111
129
  export const ProjectTypeAgent = "agent";
112
130
  export const ProjectTypeApp = "app";
113
131
  export const ProjectTypeFlow = "flow";
@@ -152,7 +170,7 @@ export const InstanceStatusDeleted = "deleted";
152
170
  export const TaskStatusUnknown = 0; // 0
153
171
  export const TaskStatusReceived = 1; // 1
154
172
  export const TaskStatusQueued = 2; // 2
155
- export const TaskStatusScheduled = 3; // 3
173
+ export const TaskStatusDispatched = 3; // 3 - Worker assigned, task sent to worker
156
174
  export const TaskStatusPreparing = 4; // 4
157
175
  export const TaskStatusServing = 5; // 5
158
176
  export const TaskStatusSettingUp = 6; // 6
@@ -185,12 +203,6 @@ export const ToolInvocationStatusFailed = "failed";
185
203
  export const ToolInvocationStatusCancelled = "cancelled";
186
204
  export const TransactionTypeCredit = "credit"; // Adding credits
187
205
  export const TransactionTypeDebit = "debit"; // Removing credits
188
- export const PaymentRecordStatusPending = 0;
189
- export const PaymentRecordStatusComplete = 1;
190
- export const PaymentRecordStatusFailed = 2;
191
- export const PaymentRecordStatusExpired = 3;
192
- export const PaymentRecordTypeCheckout = "checkout"; // Stripe Checkout session (manual top-up)
193
- export const PaymentRecordTypeAutoRecharge = "auto_recharge"; // Direct charge (auto-recharge)
194
206
  export const UsageEventResourceTierPrivate = "private";
195
207
  export const UsageEventResourceTierCloud = "cloud";
196
208
  export const MetaItemTypeText = "text";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Status utilities for handling both int and string-based status values.
3
+ * Provides future compatibility when API migrates from int to string status.
4
+ */
5
+ import { TaskStatus } from './types';
6
+ /**
7
+ * Parse task status from int or string to TaskStatus number.
8
+ * Handles both current int-based API and future string-based API.
9
+ */
10
+ export declare function parseStatus(status: number | string | undefined | null): TaskStatus;
11
+ /**
12
+ * Check if a task status is terminal (completed, failed, or cancelled).
13
+ * Handles both int and string status values.
14
+ */
15
+ export declare function isTerminalStatus(status: number | string | undefined | null): boolean;
package/dist/utils.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Status utilities for handling both int and string-based status values.
3
+ * Provides future compatibility when API migrates from int to string status.
4
+ */
5
+ import { TaskStatusUnknown, TaskStatusReceived, TaskStatusQueued, TaskStatusDispatched, TaskStatusPreparing, TaskStatusServing, TaskStatusSettingUp, TaskStatusRunning, TaskStatusCancelling, TaskStatusUploading, TaskStatusCompleted, TaskStatusFailed, TaskStatusCancelled, } from './types';
6
+ /** Map string status names to TaskStatus values (for future string-based API) */
7
+ const STATUS_STRING_MAP = {
8
+ unknown: TaskStatusUnknown,
9
+ received: TaskStatusReceived,
10
+ queued: TaskStatusQueued,
11
+ dispatched: TaskStatusDispatched,
12
+ preparing: TaskStatusPreparing,
13
+ serving: TaskStatusServing,
14
+ setting_up: TaskStatusSettingUp,
15
+ running: TaskStatusRunning,
16
+ cancelling: TaskStatusCancelling,
17
+ uploading: TaskStatusUploading,
18
+ completed: TaskStatusCompleted,
19
+ failed: TaskStatusFailed,
20
+ cancelled: TaskStatusCancelled,
21
+ };
22
+ /**
23
+ * Parse task status from int or string to TaskStatus number.
24
+ * Handles both current int-based API and future string-based API.
25
+ */
26
+ export function parseStatus(status) {
27
+ if (status === undefined || status === null) {
28
+ return TaskStatusUnknown;
29
+ }
30
+ if (typeof status === 'number') {
31
+ return status;
32
+ }
33
+ if (typeof status === 'string') {
34
+ return STATUS_STRING_MAP[status.toLowerCase()] ?? TaskStatusUnknown;
35
+ }
36
+ return TaskStatusUnknown;
37
+ }
38
+ /**
39
+ * Check if a task status is terminal (completed, failed, or cancelled).
40
+ * Handles both int and string status values.
41
+ */
42
+ export function isTerminalStatus(status) {
43
+ const parsed = parseStatus(status);
44
+ return parsed === TaskStatusCompleted || parsed === TaskStatusFailed || parsed === TaskStatusCancelled;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
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",