@inferencesh/sdk 0.5.8 → 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
  // =============================================================================
package/dist/types.d.ts CHANGED
@@ -367,6 +367,11 @@ export interface ApiAppRunRequest {
367
367
  * Session timeout in seconds (1-3600). Only valid when session="new"
368
368
  */
369
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;
370
375
  }
371
376
  /**
372
377
  * ApiAgentRunRequest is the request body for /agents/run endpoint.
@@ -533,6 +538,7 @@ export interface CreateAgentRequest {
533
538
  export interface SDKTypes {
534
539
  }
535
540
  export interface SkillPublishRequest {
541
+ namespace?: string;
536
542
  name: string;
537
543
  description: string;
538
544
  category: string;
@@ -977,6 +983,12 @@ export interface ResourceStatusDTO {
977
983
  status: any;
978
984
  updated_at: string;
979
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;
980
992
  export type ChatStatus = string;
981
993
  export declare const ChatStatusBusy: ChatStatus;
982
994
  export declare const ChatStatusIdle: ChatStatus;
@@ -1609,6 +1621,167 @@ export interface IntegrationDTO extends BaseModel, PermissionModelDTO {
1609
1621
  is_primary: boolean;
1610
1622
  error_message?: string;
1611
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
+ }
1612
1785
  /**
1613
1786
  * ProjectType represents different types of projects
1614
1787
  */
@@ -1936,21 +2109,17 @@ export interface HFCacheInfo {
1936
2109
  /**
1937
2110
  * TaskStatus represents the state of a task in its lifecycle.
1938
2111
  * DESIGN NOTES:
1939
- * - Stored as int in DB for compact storage and efficient equality checks.
1940
- * - The int values are ordered to allow SQL range queries (status < ?) for performance.
1941
- * - IMPORTANT: If you add new statuses in the MIDDLE of the sequence, you must:
1942
- * 1. Write a migration to shift existing values
1943
- * 2. Update SDKs and frontends
1944
- * - ALTERNATIVE: Add new statuses at the END to avoid migrations, but then you
1945
- * cannot use range comparisons (< >) and must use explicit checks (IN, NOT IN).
1946
- * - Kubernetes/Temporal use strings and explicit checks for maximum flexibility.
1947
- * 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.
1948
2117
  */
1949
2118
  export type TaskStatus = number;
1950
2119
  export declare const TaskStatusUnknown: TaskStatus;
1951
2120
  export declare const TaskStatusReceived: TaskStatus;
1952
2121
  export declare const TaskStatusQueued: TaskStatus;
1953
- export declare const TaskStatusScheduled: TaskStatus;
2122
+ export declare const TaskStatusDispatched: TaskStatus;
1954
2123
  export declare const TaskStatusPreparing: TaskStatus;
1955
2124
  export declare const TaskStatusServing: TaskStatus;
1956
2125
  export declare const TaskStatusSettingUp: TaskStatus;
@@ -2028,6 +2197,10 @@ export interface Task extends BaseModel, PermissionModel {
2028
2197
  * Session timeout in seconds (only used when session="new")
2029
2198
  */
2030
2199
  session_timeout?: number;
2200
+ /**
2201
+ * Scheduled execution time (UTC). Scheduler skips task until this time.
2202
+ */
2203
+ run_at?: string;
2031
2204
  }
2032
2205
  export interface TaskEvent {
2033
2206
  id: string;
@@ -2074,6 +2247,7 @@ export interface TaskDTO extends BaseModel, PermissionModelDTO {
2074
2247
  engine?: EngineStateSummary;
2075
2248
  worker_id?: string;
2076
2249
  worker?: WorkerStateSummary;
2250
+ run_at?: string;
2077
2251
  webhook?: string;
2078
2252
  setup?: any;
2079
2253
  input: any;
@@ -2116,6 +2290,10 @@ export interface Team extends BaseModel {
2116
2290
  * Personal teams start with SetupCompleted=false and a generated temporary username
2117
2291
  */
2118
2292
  setup_completed: boolean;
2293
+ /**
2294
+ * MaxConcurrency limits total active tasks for this team (0 = use default)
2295
+ */
2296
+ max_concurrency: number;
2119
2297
  }
2120
2298
  export interface TeamDTO extends BaseModel {
2121
2299
  type: TeamType;
@@ -2124,6 +2302,7 @@ export interface TeamDTO extends BaseModel {
2124
2302
  avatar_url: string;
2125
2303
  email: string;
2126
2304
  setup_completed: boolean;
2305
+ max_concurrency: number;
2127
2306
  }
2128
2307
  export type TeamRole = string;
2129
2308
  export declare const TeamRoleOwner: TeamRole;
@@ -2232,37 +2411,6 @@ export interface Transaction extends BaseModel {
2232
2411
  */
2233
2412
  side_effects_processed: boolean;
2234
2413
  }
2235
- /**
2236
- * PaymentRecordStatus represents the status of a payment
2237
- */
2238
- export type PaymentRecordStatus = number;
2239
- export declare const PaymentRecordStatusPending: PaymentRecordStatus;
2240
- export declare const PaymentRecordStatusComplete: PaymentRecordStatus;
2241
- export declare const PaymentRecordStatusFailed: PaymentRecordStatus;
2242
- export declare const PaymentRecordStatusExpired: PaymentRecordStatus;
2243
- /**
2244
- * PaymentRecordType represents the type of payment
2245
- */
2246
- export type PaymentRecordType = string;
2247
- export declare const PaymentRecordTypeCheckout: PaymentRecordType;
2248
- export declare const PaymentRecordTypeAutoRecharge: PaymentRecordType;
2249
- /**
2250
- * PaymentRecord stores Stripe payment details for both checkout sessions and direct charges
2251
- */
2252
- export interface PaymentRecord extends BaseModel, PermissionModel {
2253
- type: PaymentRecordType;
2254
- status: PaymentRecordStatus;
2255
- amount: number;
2256
- service_fee: number;
2257
- stripe_customer_id: string;
2258
- payment_intent_id: string;
2259
- receipt_url: string;
2260
- /**
2261
- * Checkout-specific fields (only set for checkout type)
2262
- */
2263
- session_id: string;
2264
- session_url: string;
2265
- }
2266
2414
  export type UsageEventResourceTier = string;
2267
2415
  export declare const UsageEventResourceTierPrivate: UsageEventResourceTier;
2268
2416
  export declare const UsageEventResourceTierCloud: UsageEventResourceTier;
@@ -2314,6 +2462,10 @@ export interface MetaItem {
2314
2462
  * Audio specific fields
2315
2463
  */
2316
2464
  sample_rate?: number;
2465
+ /**
2466
+ * Raw specific fields
2467
+ */
2468
+ cost?: number;
2317
2469
  /**
2318
2470
  * App-specific key-value pairs for custom pricing factors
2319
2471
  */
@@ -2348,6 +2500,17 @@ export interface DiscountItem {
2348
2500
  reason: string;
2349
2501
  amount: number;
2350
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
+ }
2351
2514
  export interface UsageBillingRecord extends BaseModel, PermissionModel {
2352
2515
  /**
2353
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";
@@ -109,6 +111,21 @@ export const GraphEdgeTypeDependency = "dependency"; // Blocking dependency
109
111
  export const GraphEdgeTypeFlow = "flow"; // Non-blocking flow
110
112
  export const GraphEdgeTypeConditional = "conditional"; // Conditional flow
111
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)
112
129
  export const ProjectTypeAgent = "agent";
113
130
  export const ProjectTypeApp = "app";
114
131
  export const ProjectTypeFlow = "flow";
@@ -153,7 +170,7 @@ export const InstanceStatusDeleted = "deleted";
153
170
  export const TaskStatusUnknown = 0; // 0
154
171
  export const TaskStatusReceived = 1; // 1
155
172
  export const TaskStatusQueued = 2; // 2
156
- export const TaskStatusScheduled = 3; // 3
173
+ export const TaskStatusDispatched = 3; // 3 - Worker assigned, task sent to worker
157
174
  export const TaskStatusPreparing = 4; // 4
158
175
  export const TaskStatusServing = 5; // 5
159
176
  export const TaskStatusSettingUp = 6; // 6
@@ -186,12 +203,6 @@ export const ToolInvocationStatusFailed = "failed";
186
203
  export const ToolInvocationStatusCancelled = "cancelled";
187
204
  export const TransactionTypeCredit = "credit"; // Adding credits
188
205
  export const TransactionTypeDebit = "debit"; // Removing credits
189
- export const PaymentRecordStatusPending = 0;
190
- export const PaymentRecordStatusComplete = 1;
191
- export const PaymentRecordStatusFailed = 2;
192
- export const PaymentRecordStatusExpired = 3;
193
- export const PaymentRecordTypeCheckout = "checkout"; // Stripe Checkout session (manual top-up)
194
- export const PaymentRecordTypeAutoRecharge = "auto_recharge"; // Direct charge (auto-recharge)
195
206
  export const UsageEventResourceTierPrivate = "private";
196
207
  export const UsageEventResourceTierCloud = "cloud";
197
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.8",
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",