@inferencesh/sdk 0.5.9 → 0.5.10

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/files.js CHANGED
@@ -1,3 +1,42 @@
1
+ /**
2
+ * Parse a data URI and return the media type and decoded data.
3
+ *
4
+ * Supports formats:
5
+ * - data:image/jpeg;base64,/9j/4AAQ...
6
+ * - data:text/plain,Hello%20World
7
+ * - data:;base64,SGVsbG8= (defaults to text/plain)
8
+ */
9
+ function parseDataUri(uri) {
10
+ // Match: data:[<mediatype>][;base64],<data>
11
+ const match = uri.match(/^data:([^;,]*)?(?:;(base64))?,(.*)$/s);
12
+ if (!match) {
13
+ throw new Error('Invalid data URI format');
14
+ }
15
+ const mediaType = match[1] || 'text/plain';
16
+ const isBase64 = match[2] === 'base64';
17
+ let dataStr = match[3];
18
+ if (isBase64) {
19
+ // Handle URL-safe base64 (- and _ instead of + and /)
20
+ dataStr = dataStr.replace(/-/g, '+').replace(/_/g, '/');
21
+ // Add padding if needed
22
+ const padding = 4 - (dataStr.length % 4);
23
+ if (padding !== 4) {
24
+ dataStr += '='.repeat(padding);
25
+ }
26
+ const binaryStr = atob(dataStr);
27
+ const bytes = new Uint8Array(binaryStr.length);
28
+ for (let i = 0; i < binaryStr.length; i++) {
29
+ bytes[i] = binaryStr.charCodeAt(i);
30
+ }
31
+ return { mediaType, data: bytes };
32
+ }
33
+ else {
34
+ // URL-encoded data
35
+ const decoded = decodeURIComponent(dataStr);
36
+ const encoder = new TextEncoder();
37
+ return { mediaType, data: encoder.encode(decoded) };
38
+ }
39
+ }
1
40
  /**
2
41
  * Files API
3
42
  */
@@ -27,11 +66,26 @@ export class FilesAPI {
27
66
  * Upload a file (Blob or base64 string)
28
67
  */
29
68
  async upload(data, options = {}) {
69
+ // Determine content type
70
+ let contentType = options.contentType;
71
+ if (!contentType) {
72
+ if (data instanceof Blob) {
73
+ contentType = data.type;
74
+ }
75
+ else if (typeof data === 'string' && data.startsWith('data:')) {
76
+ // Extract media type from data URI
77
+ const match = data.match(/^data:([^;,]*)?/);
78
+ contentType = match?.[1] || 'application/octet-stream';
79
+ }
80
+ else {
81
+ contentType = 'application/octet-stream';
82
+ }
83
+ }
30
84
  // Step 1: Create the file record
31
85
  const fileRequest = {
32
86
  uri: '', // Empty URI as it will be set by the server
33
87
  filename: options.filename,
34
- content_type: options.contentType || (data instanceof Blob ? data.type : 'application/octet-stream'),
88
+ content_type: contentType,
35
89
  path: options.path,
36
90
  size: data instanceof Blob ? data.size : undefined,
37
91
  };
@@ -50,16 +104,8 @@ export class FilesAPI {
50
104
  else {
51
105
  // If it's a base64 string, convert it to a Blob
52
106
  if (data.startsWith('data:')) {
53
- const matches = data.match(/^data:([^;]+);base64,(.+)$/);
54
- if (!matches) {
55
- throw new Error('Invalid base64 data URI format');
56
- }
57
- const binaryStr = atob(matches[2]);
58
- const bytes = new Uint8Array(binaryStr.length);
59
- for (let i = 0; i < binaryStr.length; i++) {
60
- bytes[i] = binaryStr.charCodeAt(i);
61
- }
62
- contentToUpload = new Blob([bytes], { type: matches[1] });
107
+ const parsed = parseDataUri(data);
108
+ contentToUpload = new Blob([parsed.data.buffer], { type: parsed.mediaType });
63
109
  }
64
110
  else {
65
111
  // Assume it's a clean base64 string
@@ -68,7 +114,7 @@ export class FilesAPI {
68
114
  for (let i = 0; i < binaryStr.length; i++) {
69
115
  bytes[i] = binaryStr.charCodeAt(i);
70
116
  }
71
- contentToUpload = new Blob([bytes], { type: options.contentType || 'application/octet-stream' });
117
+ contentToUpload = new Blob([bytes.buffer], { type: options.contentType || 'application/octet-stream' });
72
118
  }
73
119
  }
74
120
  // Upload to S3 using the signed URL
package/dist/api/tasks.js CHANGED
@@ -192,7 +192,7 @@ export class TasksAPI {
192
192
  * Feature/unfeature a task
193
193
  */
194
194
  async feature(taskId, featured) {
195
- return this.http.request('post', `/tasks/${taskId}/featured`, { data: { featured } });
195
+ return this.http.request('post', `/tasks/${taskId}/featured`, { data: { is_featured: featured } });
196
196
  }
197
197
  }
198
198
  export function createTasksAPI(http) {
@@ -80,7 +80,9 @@ export class HttpClient {
80
80
  if (options.params) {
81
81
  Object.entries(options.params).forEach(([key, value]) => {
82
82
  if (value !== undefined && value !== null) {
83
- targetUrl.searchParams.append(key, String(value));
83
+ // Serialize arrays and objects as JSON, primitives as strings
84
+ const serialized = typeof value === 'object' ? JSON.stringify(value) : String(value);
85
+ targetUrl.searchParams.append(key, serialized);
84
86
  }
85
87
  });
86
88
  }
package/dist/types.d.ts CHANGED
@@ -447,9 +447,9 @@ export interface ToolResultRequest {
447
447
  result: string;
448
448
  }
449
449
  /**
450
- * WebhookEvent is the envelope for task webhook deliveries.
450
+ * WebhookPayload is the envelope for outbound webhook deliveries (e.g., task webhooks).
451
451
  */
452
- export interface WebhookEvent<T extends any> {
452
+ export interface WebhookPayload<T extends any> {
453
453
  event: string;
454
454
  timestamp: string;
455
455
  data: T;
@@ -983,12 +983,6 @@ export interface ResourceStatusDTO {
983
983
  status: any;
984
984
  updated_at: string;
985
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;
992
986
  export type ChatStatus = string;
993
987
  export declare const ChatStatusBusy: ChatStatus;
994
988
  export declare const ChatStatusIdle: ChatStatus;
@@ -1621,167 +1615,6 @@ export interface IntegrationDTO extends BaseModel, PermissionModelDTO {
1621
1615
  is_primary: boolean;
1622
1616
  error_message?: string;
1623
1617
  }
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
- }
1785
1618
  /**
1786
1619
  * ProjectType represents different types of projects
1787
1620
  */
@@ -2181,8 +2014,6 @@ export interface Task extends BaseModel, PermissionModel {
2181
2014
  logs: TaskLog[];
2182
2015
  telemetry: TimescaleTask[];
2183
2016
  usage_events: (UsageEvent | undefined)[];
2184
- transaction_id?: string;
2185
- transaction?: Transaction;
2186
2017
  /**
2187
2018
  * Secret refs for billing (tracks ownership to determine partner fee)
2188
2019
  */
@@ -2258,8 +2089,6 @@ export interface TaskDTO extends BaseModel, PermissionModelDTO {
2258
2089
  logs: TaskLog[];
2259
2090
  telemetry: TimescaleTask[];
2260
2091
  usage_events: (UsageEvent | undefined)[];
2261
- transaction_id?: string;
2262
- transaction?: Transaction;
2263
2092
  session_id?: string;
2264
2093
  session_timeout?: number;
2265
2094
  }
@@ -2383,103 +2212,9 @@ export interface ToolParameterProperty {
2383
2212
  items?: ToolParameterProperty;
2384
2213
  required?: string[];
2385
2214
  }
2386
- /**
2387
- * TransactionType represents the type of credit transaction
2388
- */
2389
- export type TransactionType = string;
2390
- export declare const TransactionTypeCredit: TransactionType;
2391
- export declare const TransactionTypeDebit: TransactionType;
2392
- /**
2393
- * Transaction represents a single credit transaction
2394
- */
2395
- export interface Transaction extends BaseModel {
2396
- PermissionModel: PermissionModel;
2397
- type: TransactionType;
2398
- amount: number;
2399
- reference: string;
2400
- notes: string;
2401
- /**
2402
- * Metadata for the transaction
2403
- */
2404
- metadata: {
2405
- [key: string]: any;
2406
- };
2407
- /**
2408
- * SideEffectsProcessed tracks whether side effects (notifications, auto-recharge,
2409
- * billing status changes) have been processed for this transaction.
2410
- * Set to true via WithSkipTxSideEffects context to skip side effects (e.g. migrations).
2411
- */
2412
- side_effects_processed: boolean;
2413
- }
2414
2215
  export type UsageEventResourceTier = string;
2415
2216
  export declare const UsageEventResourceTierPrivate: UsageEventResourceTier;
2416
2217
  export declare const UsageEventResourceTierCloud: UsageEventResourceTier;
2417
- /**
2418
- * MetaItemType is the type discriminator for MetaItem
2419
- */
2420
- export type MetaItemType = string;
2421
- export declare const MetaItemTypeText: MetaItemType;
2422
- export declare const MetaItemTypeImage: MetaItemType;
2423
- export declare const MetaItemTypeVideo: MetaItemType;
2424
- export declare const MetaItemTypeAudio: MetaItemType;
2425
- export declare const MetaItemTypeRaw: MetaItemType;
2426
- /**
2427
- * VideoResolution represents standard video resolution presets
2428
- */
2429
- export type VideoResolution = string;
2430
- export declare const VideoRes480P: VideoResolution;
2431
- export declare const VideoRes720P: VideoResolution;
2432
- export declare const VideoRes1080P: VideoResolution;
2433
- export declare const VideoRes1440P: VideoResolution;
2434
- export declare const VideoRes4K: VideoResolution;
2435
- /**
2436
- * MetaItem represents metadata about an input or output item
2437
- */
2438
- export interface MetaItem {
2439
- type: MetaItemType;
2440
- /**
2441
- * Text fields
2442
- */
2443
- tokens?: number;
2444
- /**
2445
- * Image/Video shared fields
2446
- */
2447
- width?: number;
2448
- height?: number;
2449
- resolution_mp?: number;
2450
- /**
2451
- * Image specific fields
2452
- */
2453
- steps?: number;
2454
- count?: number;
2455
- /**
2456
- * Video specific fields
2457
- */
2458
- resolution?: VideoResolution;
2459
- seconds?: number;
2460
- fps?: number;
2461
- /**
2462
- * Audio specific fields
2463
- */
2464
- sample_rate?: number;
2465
- /**
2466
- * Raw specific fields
2467
- */
2468
- cost?: number;
2469
- /**
2470
- * App-specific key-value pairs for custom pricing factors
2471
- */
2472
- extra?: {
2473
- [key: string]: any;
2474
- };
2475
- }
2476
- /**
2477
- * OutputMeta contains structured metadata about task inputs and outputs for pricing calculation
2478
- */
2479
- export interface OutputMeta {
2480
- inputs: MetaItem[];
2481
- outputs: MetaItem[];
2482
- }
2483
2218
  export interface UsageEvent extends BaseModel, PermissionModel {
2484
2219
  usage_billing_record_id: string;
2485
2220
  reference_id: string;
@@ -2493,85 +2228,6 @@ export interface UsageEvent extends BaseModel, PermissionModel {
2493
2228
  quantity: number;
2494
2229
  unit: string;
2495
2230
  }
2496
- /**
2497
- * DiscountItem represents a single discount applied to a billing record
2498
- */
2499
- export interface DiscountItem {
2500
- reason: string;
2501
- amount: number;
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
- }
2514
- export interface UsageBillingRecord extends BaseModel, PermissionModel {
2515
- /**
2516
- * Fee breakdown (all in microcents)
2517
- */
2518
- total: number;
2519
- discount: number;
2520
- /**
2521
- * User debit (total charged)
2522
- */
2523
- user_debit_transaction_id: string;
2524
- user_debit_transaction?: Transaction;
2525
- /**
2526
- * Resource owner credit (for providing compute)
2527
- */
2528
- resource_credit_transaction_id: string;
2529
- resource_credit_transaction?: Transaction;
2530
- /**
2531
- * Creator royalty credit (app creator earnings)
2532
- */
2533
- royalty_credit_transaction_id: string;
2534
- royalty_credit_transaction?: Transaction;
2535
- /**
2536
- * Inference fee credit (platform fee)
2537
- */
2538
- inference_credit_transaction_id: string;
2539
- inference_credit_transaction?: Transaction;
2540
- /**
2541
- * Partner fee credit (cloud API fee)
2542
- */
2543
- partner_credit_transaction_id: string;
2544
- partner_credit_transaction?: Transaction;
2545
- }
2546
- export interface UsageBillingRefund extends BaseModel, PermissionModel {
2547
- usage_billing_record_id: string;
2548
- usage_billing_record?: UsageBillingRecord;
2549
- /**
2550
- * User refund (total refunded)
2551
- */
2552
- user_debit_refund_transaction_id: string;
2553
- user_debit_refund_transaction?: Transaction;
2554
- /**
2555
- * Resource owner reversal
2556
- */
2557
- resource_credit_refund_transaction_id: string;
2558
- resource_credit_refund_transaction?: Transaction;
2559
- /**
2560
- * Creator royalty reversal
2561
- */
2562
- royalty_credit_refund_transaction_id: string;
2563
- royalty_credit_refund_transaction?: Transaction;
2564
- /**
2565
- * Inference fee reversal
2566
- */
2567
- inference_credit_refund_transaction_id: string;
2568
- inference_credit_refund_transaction?: Transaction;
2569
- /**
2570
- * Partner fee reversal
2571
- */
2572
- partner_credit_refund_transaction_id: string;
2573
- partner_credit_refund_transaction?: Transaction;
2574
- }
2575
2231
  /**
2576
2232
  * User-related types
2577
2233
  */
package/dist/types.js CHANGED
@@ -24,8 +24,6 @@ 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";
29
27
  export const ChatStatusBusy = "busy";
30
28
  export const ChatStatusIdle = "idle";
31
29
  export const ChatStatusAwaitingInput = "awaiting_input";
@@ -111,21 +109,6 @@ export const GraphEdgeTypeDependency = "dependency"; // Blocking dependency
111
109
  export const GraphEdgeTypeFlow = "flow"; // Non-blocking flow
112
110
  export const GraphEdgeTypeConditional = "conditional"; // Conditional flow
113
111
  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)
129
112
  export const ProjectTypeAgent = "agent";
130
113
  export const ProjectTypeApp = "app";
131
114
  export const ProjectTypeFlow = "flow";
@@ -201,20 +184,8 @@ export const ToolInvocationStatusAwaitingApproval = "awaiting_approval"; // Wait
201
184
  export const ToolInvocationStatusCompleted = "completed";
202
185
  export const ToolInvocationStatusFailed = "failed";
203
186
  export const ToolInvocationStatusCancelled = "cancelled";
204
- export const TransactionTypeCredit = "credit"; // Adding credits
205
- export const TransactionTypeDebit = "debit"; // Removing credits
206
187
  export const UsageEventResourceTierPrivate = "private";
207
188
  export const UsageEventResourceTierCloud = "cloud";
208
- export const MetaItemTypeText = "text";
209
- export const MetaItemTypeImage = "image";
210
- export const MetaItemTypeVideo = "video";
211
- export const MetaItemTypeAudio = "audio";
212
- export const MetaItemTypeRaw = "raw";
213
- export const VideoRes480P = "480p";
214
- export const VideoRes720P = "720p";
215
- export const VideoRes1080P = "1080p";
216
- export const VideoRes1440P = "1440p";
217
- export const VideoRes4K = "4k";
218
189
  export const RoleGuest = "guest";
219
190
  export const RoleUser = "user";
220
191
  export const RoleAdmin = "admin";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
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",