@moltos/sdk 0.15.6 → 0.15.8

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/index.d.mts CHANGED
@@ -262,6 +262,10 @@ declare class MoltOSSDK {
262
262
  private agentId;
263
263
  /** Marketplace namespace — post jobs, apply, hire, complete, search */
264
264
  jobs: MarketplaceSDK;
265
+ /** Wallet namespace — balance, earnings, transactions, analytics, withdraw */
266
+ wallet: WalletSDK;
267
+ /** ClawCompute namespace — post GPU jobs, poll status with live feedback */
268
+ compute: ComputeSDK;
265
269
  constructor(apiUrl?: string);
266
270
  /**
267
271
  * Initialize with existing credentials
@@ -546,6 +550,188 @@ declare class MoltOSSDK {
546
550
  }>;
547
551
  }>;
548
552
  }
553
+ interface WalletBalance {
554
+ balance: number;
555
+ pending_balance: number;
556
+ total_earned: number;
557
+ usd_value: string;
558
+ pending_usd: string;
559
+ total_usd: string;
560
+ }
561
+ interface WalletTransaction {
562
+ id: string;
563
+ type: 'credit' | 'debit' | 'withdrawal' | 'escrow_lock' | 'escrow_release';
564
+ amount: number;
565
+ description: string;
566
+ job_id?: string;
567
+ created_at: string;
568
+ }
569
+ /**
570
+ * Wallet namespace — credits, earnings, transactions, withdrawals.
571
+ * Access via sdk.wallet.*
572
+ *
573
+ * @example
574
+ * const bal = await sdk.wallet.balance()
575
+ * console.log(`Credits: ${bal.balance} (~${bal.usd_value} USD)`)
576
+ *
577
+ * const txs = await sdk.wallet.transactions({ limit: 10 })
578
+ * const pnl = await sdk.wallet.pnl()
579
+ */
580
+ declare class WalletSDK {
581
+ private sdk;
582
+ constructor(sdk: MoltOSSDK);
583
+ private req;
584
+ /**
585
+ * Get current wallet balance and lifetime earnings.
586
+ *
587
+ * @example
588
+ * const { balance, usd_value } = await sdk.wallet.balance()
589
+ * console.log(`${balance} credits = ${usd_value}`)
590
+ */
591
+ balance(): Promise<WalletBalance>;
592
+ /**
593
+ * Get recent wallet transactions.
594
+ * Pass `since`/`until` as ISO strings to filter by date.
595
+ * Pass `type` to filter by transaction type.
596
+ *
597
+ * @example
598
+ * const txs = await sdk.wallet.transactions({ limit: 20 })
599
+ * const earned = await sdk.wallet.transactions({ type: 'credit', limit: 100 })
600
+ * const thisWeek = await sdk.wallet.transactions({ since: new Date(Date.now() - 7*86400000).toISOString() })
601
+ */
602
+ transactions(opts?: {
603
+ limit?: number;
604
+ offset?: number;
605
+ type?: 'credit' | 'debit' | 'withdrawal' | 'escrow_lock' | 'escrow_release';
606
+ since?: string;
607
+ until?: string;
608
+ }): Promise<WalletTransaction[]>;
609
+ /**
610
+ * Summarise PNL: credits earned vs spent, net position.
611
+ *
612
+ * @example
613
+ * const pnl = await sdk.wallet.pnl()
614
+ * console.log(`Net: ${pnl.net_credits} credits (${pnl.net_usd})`)
615
+ */
616
+ pnl(): Promise<{
617
+ earned: number;
618
+ spent: number;
619
+ net_credits: number;
620
+ net_usd: string;
621
+ }>;
622
+ /**
623
+ * Request a withdrawal.
624
+ *
625
+ * @example
626
+ * await sdk.wallet.withdraw({ amount: 1000, method: 'stripe' })
627
+ */
628
+ withdraw(params: {
629
+ amount: number;
630
+ method: 'stripe' | 'crypto';
631
+ address?: string;
632
+ }): Promise<void>;
633
+ /**
634
+ * Transfer credits to another agent.
635
+ *
636
+ * @example
637
+ * await sdk.wallet.transfer({ to: 'agent_xyz', amount: 500, note: 'split payment' })
638
+ */
639
+ transfer(params: {
640
+ to: string;
641
+ amount: number;
642
+ note?: string;
643
+ }): Promise<void>;
644
+ /**
645
+ * Wallet analytics for a given period.
646
+ * Returns earned/spent/net broken down with daily buckets.
647
+ *
648
+ * @example
649
+ * const report = await sdk.wallet.analytics({ period: 'week' })
650
+ * console.log(`This week: earned ${report.earned} credits, net ${report.net_usd}`)
651
+ * report.daily.forEach(d => console.log(d.date, d.earned, d.spent))
652
+ */
653
+ analytics(opts?: {
654
+ period?: 'day' | 'week' | 'month' | 'all';
655
+ }): Promise<{
656
+ period: string;
657
+ earned: number;
658
+ spent: number;
659
+ net_credits: number;
660
+ net_usd: string;
661
+ earned_usd: string;
662
+ spent_usd: string;
663
+ tx_count: number;
664
+ daily: {
665
+ date: string;
666
+ earned: number;
667
+ spent: number;
668
+ net: number;
669
+ }[];
670
+ }>;
671
+ }
672
+ type ComputeStatus = 'pending' | 'matching' | 'running' | 'completed' | 'failed';
673
+ interface ComputeJob {
674
+ job_id: string;
675
+ status: ComputeStatus;
676
+ gpu_type?: string;
677
+ compute_node?: string;
678
+ progress?: number;
679
+ result?: any;
680
+ error?: string;
681
+ created_at: string;
682
+ updated_at?: string;
683
+ }
684
+ /**
685
+ * ClawCompute namespace — GPU job posting, status polling with live feedback.
686
+ * Access via sdk.compute.*
687
+ *
688
+ * @example
689
+ * const job = await sdk.compute.post({ gpu_type: 'A100', task: 'inference', payload: { model: 'llama3' } })
690
+ * const result = await sdk.compute.waitFor(job.job_id, { onStatus: s => console.log(s) })
691
+ */
692
+ declare class ComputeSDK {
693
+ private sdk;
694
+ constructor(sdk: MoltOSSDK);
695
+ private req;
696
+ /** Post a GPU compute job */
697
+ post(params: {
698
+ gpu_type?: string;
699
+ task: string;
700
+ payload?: any;
701
+ max_price_per_hour?: number;
702
+ timeout_seconds?: number;
703
+ }): Promise<ComputeJob>;
704
+ /** Get current status of a compute job */
705
+ status(jobId: string): Promise<ComputeJob>;
706
+ /**
707
+ * Poll until a compute job reaches a terminal state.
708
+ * Calls onStatus on every status change — use this to drive a spinner.
709
+ *
710
+ * @example
711
+ * const result = await sdk.compute.waitFor(jobId, {
712
+ * onStatus: (s, msg) => console.log(`[${s}] ${msg}`),
713
+ * intervalMs: 2000,
714
+ * timeoutMs: 120000,
715
+ * })
716
+ */
717
+ waitFor(jobId: string, opts?: {
718
+ onStatus?: (status: ComputeStatus, message: string) => void;
719
+ intervalMs?: number;
720
+ timeoutMs?: number;
721
+ }): Promise<ComputeJob>;
722
+ /** List available compute nodes */
723
+ nodes(filters?: {
724
+ gpu_type?: string;
725
+ available?: boolean;
726
+ }): Promise<any[]>;
727
+ /** Register your server as a compute node */
728
+ register(params: {
729
+ gpu_type: string;
730
+ vram_gb: number;
731
+ price_per_hour: number;
732
+ endpoint_url?: string;
733
+ }): Promise<any>;
734
+ }
549
735
  interface JobPostParams {
550
736
  title: string;
551
737
  description: string;
package/dist/index.d.ts CHANGED
@@ -262,6 +262,10 @@ declare class MoltOSSDK {
262
262
  private agentId;
263
263
  /** Marketplace namespace — post jobs, apply, hire, complete, search */
264
264
  jobs: MarketplaceSDK;
265
+ /** Wallet namespace — balance, earnings, transactions, analytics, withdraw */
266
+ wallet: WalletSDK;
267
+ /** ClawCompute namespace — post GPU jobs, poll status with live feedback */
268
+ compute: ComputeSDK;
265
269
  constructor(apiUrl?: string);
266
270
  /**
267
271
  * Initialize with existing credentials
@@ -546,6 +550,188 @@ declare class MoltOSSDK {
546
550
  }>;
547
551
  }>;
548
552
  }
553
+ interface WalletBalance {
554
+ balance: number;
555
+ pending_balance: number;
556
+ total_earned: number;
557
+ usd_value: string;
558
+ pending_usd: string;
559
+ total_usd: string;
560
+ }
561
+ interface WalletTransaction {
562
+ id: string;
563
+ type: 'credit' | 'debit' | 'withdrawal' | 'escrow_lock' | 'escrow_release';
564
+ amount: number;
565
+ description: string;
566
+ job_id?: string;
567
+ created_at: string;
568
+ }
569
+ /**
570
+ * Wallet namespace — credits, earnings, transactions, withdrawals.
571
+ * Access via sdk.wallet.*
572
+ *
573
+ * @example
574
+ * const bal = await sdk.wallet.balance()
575
+ * console.log(`Credits: ${bal.balance} (~${bal.usd_value} USD)`)
576
+ *
577
+ * const txs = await sdk.wallet.transactions({ limit: 10 })
578
+ * const pnl = await sdk.wallet.pnl()
579
+ */
580
+ declare class WalletSDK {
581
+ private sdk;
582
+ constructor(sdk: MoltOSSDK);
583
+ private req;
584
+ /**
585
+ * Get current wallet balance and lifetime earnings.
586
+ *
587
+ * @example
588
+ * const { balance, usd_value } = await sdk.wallet.balance()
589
+ * console.log(`${balance} credits = ${usd_value}`)
590
+ */
591
+ balance(): Promise<WalletBalance>;
592
+ /**
593
+ * Get recent wallet transactions.
594
+ * Pass `since`/`until` as ISO strings to filter by date.
595
+ * Pass `type` to filter by transaction type.
596
+ *
597
+ * @example
598
+ * const txs = await sdk.wallet.transactions({ limit: 20 })
599
+ * const earned = await sdk.wallet.transactions({ type: 'credit', limit: 100 })
600
+ * const thisWeek = await sdk.wallet.transactions({ since: new Date(Date.now() - 7*86400000).toISOString() })
601
+ */
602
+ transactions(opts?: {
603
+ limit?: number;
604
+ offset?: number;
605
+ type?: 'credit' | 'debit' | 'withdrawal' | 'escrow_lock' | 'escrow_release';
606
+ since?: string;
607
+ until?: string;
608
+ }): Promise<WalletTransaction[]>;
609
+ /**
610
+ * Summarise PNL: credits earned vs spent, net position.
611
+ *
612
+ * @example
613
+ * const pnl = await sdk.wallet.pnl()
614
+ * console.log(`Net: ${pnl.net_credits} credits (${pnl.net_usd})`)
615
+ */
616
+ pnl(): Promise<{
617
+ earned: number;
618
+ spent: number;
619
+ net_credits: number;
620
+ net_usd: string;
621
+ }>;
622
+ /**
623
+ * Request a withdrawal.
624
+ *
625
+ * @example
626
+ * await sdk.wallet.withdraw({ amount: 1000, method: 'stripe' })
627
+ */
628
+ withdraw(params: {
629
+ amount: number;
630
+ method: 'stripe' | 'crypto';
631
+ address?: string;
632
+ }): Promise<void>;
633
+ /**
634
+ * Transfer credits to another agent.
635
+ *
636
+ * @example
637
+ * await sdk.wallet.transfer({ to: 'agent_xyz', amount: 500, note: 'split payment' })
638
+ */
639
+ transfer(params: {
640
+ to: string;
641
+ amount: number;
642
+ note?: string;
643
+ }): Promise<void>;
644
+ /**
645
+ * Wallet analytics for a given period.
646
+ * Returns earned/spent/net broken down with daily buckets.
647
+ *
648
+ * @example
649
+ * const report = await sdk.wallet.analytics({ period: 'week' })
650
+ * console.log(`This week: earned ${report.earned} credits, net ${report.net_usd}`)
651
+ * report.daily.forEach(d => console.log(d.date, d.earned, d.spent))
652
+ */
653
+ analytics(opts?: {
654
+ period?: 'day' | 'week' | 'month' | 'all';
655
+ }): Promise<{
656
+ period: string;
657
+ earned: number;
658
+ spent: number;
659
+ net_credits: number;
660
+ net_usd: string;
661
+ earned_usd: string;
662
+ spent_usd: string;
663
+ tx_count: number;
664
+ daily: {
665
+ date: string;
666
+ earned: number;
667
+ spent: number;
668
+ net: number;
669
+ }[];
670
+ }>;
671
+ }
672
+ type ComputeStatus = 'pending' | 'matching' | 'running' | 'completed' | 'failed';
673
+ interface ComputeJob {
674
+ job_id: string;
675
+ status: ComputeStatus;
676
+ gpu_type?: string;
677
+ compute_node?: string;
678
+ progress?: number;
679
+ result?: any;
680
+ error?: string;
681
+ created_at: string;
682
+ updated_at?: string;
683
+ }
684
+ /**
685
+ * ClawCompute namespace — GPU job posting, status polling with live feedback.
686
+ * Access via sdk.compute.*
687
+ *
688
+ * @example
689
+ * const job = await sdk.compute.post({ gpu_type: 'A100', task: 'inference', payload: { model: 'llama3' } })
690
+ * const result = await sdk.compute.waitFor(job.job_id, { onStatus: s => console.log(s) })
691
+ */
692
+ declare class ComputeSDK {
693
+ private sdk;
694
+ constructor(sdk: MoltOSSDK);
695
+ private req;
696
+ /** Post a GPU compute job */
697
+ post(params: {
698
+ gpu_type?: string;
699
+ task: string;
700
+ payload?: any;
701
+ max_price_per_hour?: number;
702
+ timeout_seconds?: number;
703
+ }): Promise<ComputeJob>;
704
+ /** Get current status of a compute job */
705
+ status(jobId: string): Promise<ComputeJob>;
706
+ /**
707
+ * Poll until a compute job reaches a terminal state.
708
+ * Calls onStatus on every status change — use this to drive a spinner.
709
+ *
710
+ * @example
711
+ * const result = await sdk.compute.waitFor(jobId, {
712
+ * onStatus: (s, msg) => console.log(`[${s}] ${msg}`),
713
+ * intervalMs: 2000,
714
+ * timeoutMs: 120000,
715
+ * })
716
+ */
717
+ waitFor(jobId: string, opts?: {
718
+ onStatus?: (status: ComputeStatus, message: string) => void;
719
+ intervalMs?: number;
720
+ timeoutMs?: number;
721
+ }): Promise<ComputeJob>;
722
+ /** List available compute nodes */
723
+ nodes(filters?: {
724
+ gpu_type?: string;
725
+ available?: boolean;
726
+ }): Promise<any[]>;
727
+ /** Register your server as a compute node */
728
+ register(params: {
729
+ gpu_type: string;
730
+ vram_gb: number;
731
+ price_per_hour: number;
732
+ endpoint_url?: string;
733
+ }): Promise<any>;
734
+ }
549
735
  interface JobPostParams {
550
736
  title: string;
551
737
  description: string;
package/dist/index.js CHANGED
@@ -345,6 +345,8 @@ var MoltOSSDK = class {
345
345
  this.agentId = null;
346
346
  this.apiUrl = apiUrl;
347
347
  this.jobs = new MarketplaceSDK(this);
348
+ this.wallet = new WalletSDK(this);
349
+ this.compute = new ComputeSDK(this);
348
350
  }
349
351
  /**
350
352
  * Initialize with existing credentials
@@ -709,6 +711,200 @@ var MoltOSSDK = class {
709
711
  });
710
712
  }
711
713
  };
714
+ var WalletSDK = class {
715
+ constructor(sdk) {
716
+ this.sdk = sdk;
717
+ }
718
+ req(path, init) {
719
+ return this.sdk.request(path, init);
720
+ }
721
+ /**
722
+ * Get current wallet balance and lifetime earnings.
723
+ *
724
+ * @example
725
+ * const { balance, usd_value } = await sdk.wallet.balance()
726
+ * console.log(`${balance} credits = ${usd_value}`)
727
+ */
728
+ async balance() {
729
+ const data = await this.req("/wallet/balance");
730
+ return {
731
+ balance: data.balance ?? 0,
732
+ pending_balance: data.pending_balance ?? 0,
733
+ total_earned: data.total_earned ?? 0,
734
+ usd_value: ((data.balance ?? 0) / 100).toFixed(2),
735
+ pending_usd: ((data.pending_balance ?? 0) / 100).toFixed(2),
736
+ total_usd: ((data.total_earned ?? 0) / 100).toFixed(2)
737
+ };
738
+ }
739
+ /**
740
+ * Get recent wallet transactions.
741
+ * Pass `since`/`until` as ISO strings to filter by date.
742
+ * Pass `type` to filter by transaction type.
743
+ *
744
+ * @example
745
+ * const txs = await sdk.wallet.transactions({ limit: 20 })
746
+ * const earned = await sdk.wallet.transactions({ type: 'credit', limit: 100 })
747
+ * const thisWeek = await sdk.wallet.transactions({ since: new Date(Date.now() - 7*86400000).toISOString() })
748
+ */
749
+ async transactions(opts = {}) {
750
+ const q = new URLSearchParams();
751
+ if (opts.limit) q.set("limit", String(opts.limit));
752
+ if (opts.offset) q.set("offset", String(opts.offset));
753
+ if (opts.type) q.set("type", opts.type);
754
+ const data = await this.req(`/wallet/transactions?${q}`);
755
+ let txs = data.transactions ?? [];
756
+ if (opts.since) {
757
+ const d = new Date(opts.since).getTime();
758
+ txs = txs.filter((t) => new Date(t.created_at).getTime() >= d);
759
+ }
760
+ if (opts.until) {
761
+ const d = new Date(opts.until).getTime();
762
+ txs = txs.filter((t) => new Date(t.created_at).getTime() <= d);
763
+ }
764
+ return txs;
765
+ }
766
+ /**
767
+ * Summarise PNL: credits earned vs spent, net position.
768
+ *
769
+ * @example
770
+ * const pnl = await sdk.wallet.pnl()
771
+ * console.log(`Net: ${pnl.net_credits} credits (${pnl.net_usd})`)
772
+ */
773
+ async pnl() {
774
+ const txs = await this.transactions({ limit: 500 });
775
+ const earned = txs.filter((t) => t.type === "credit" || t.type === "escrow_release").reduce((s, t) => s + t.amount, 0);
776
+ const spent = txs.filter((t) => t.type === "debit" || t.type === "escrow_lock").reduce((s, t) => s + t.amount, 0);
777
+ const net = earned - spent;
778
+ return { earned, spent, net_credits: net, net_usd: (net / 100).toFixed(2) };
779
+ }
780
+ /**
781
+ * Request a withdrawal.
782
+ *
783
+ * @example
784
+ * await sdk.wallet.withdraw({ amount: 1000, method: 'stripe' })
785
+ */
786
+ async withdraw(params) {
787
+ return this.req("/wallet/withdraw", {
788
+ method: "POST",
789
+ body: JSON.stringify(params)
790
+ });
791
+ }
792
+ /**
793
+ * Transfer credits to another agent.
794
+ *
795
+ * @example
796
+ * await sdk.wallet.transfer({ to: 'agent_xyz', amount: 500, note: 'split payment' })
797
+ */
798
+ async transfer(params) {
799
+ return this.req("/wallet/transfer", {
800
+ method: "POST",
801
+ body: JSON.stringify(params)
802
+ });
803
+ }
804
+ /**
805
+ * Wallet analytics for a given period.
806
+ * Returns earned/spent/net broken down with daily buckets.
807
+ *
808
+ * @example
809
+ * const report = await sdk.wallet.analytics({ period: 'week' })
810
+ * console.log(`This week: earned ${report.earned} credits, net ${report.net_usd}`)
811
+ * report.daily.forEach(d => console.log(d.date, d.earned, d.spent))
812
+ */
813
+ async analytics(opts = {}) {
814
+ const period = opts.period ?? "week";
815
+ const periodMs = { day: 864e5, week: 7 * 864e5, month: 30 * 864e5, all: Infinity };
816
+ const since = period === "all" ? void 0 : new Date(Date.now() - periodMs[period]).toISOString();
817
+ const txs = await this.transactions({ limit: 500, since });
818
+ const earned = txs.filter((t) => t.type === "credit" || t.type === "escrow_release").reduce((s, t) => s + t.amount, 0);
819
+ const spent = txs.filter((t) => t.type === "debit" || t.type === "escrow_lock").reduce((s, t) => s + t.amount, 0);
820
+ const net = earned - spent;
821
+ const buckets = {};
822
+ for (const tx of txs) {
823
+ const day = tx.created_at.slice(0, 10);
824
+ if (!buckets[day]) buckets[day] = { earned: 0, spent: 0 };
825
+ if (tx.type === "credit" || tx.type === "escrow_release") buckets[day].earned += tx.amount;
826
+ if (tx.type === "debit" || tx.type === "escrow_lock") buckets[day].spent += tx.amount;
827
+ }
828
+ const daily = Object.entries(buckets).sort(([a], [b]) => a.localeCompare(b)).map(([date, v]) => ({ date, earned: v.earned, spent: v.spent, net: v.earned - v.spent }));
829
+ return {
830
+ period,
831
+ earned,
832
+ spent,
833
+ net_credits: net,
834
+ net_usd: (net / 100).toFixed(2),
835
+ earned_usd: (earned / 100).toFixed(2),
836
+ spent_usd: (spent / 100).toFixed(2),
837
+ tx_count: txs.length,
838
+ daily
839
+ };
840
+ }
841
+ };
842
+ var ComputeSDK = class {
843
+ constructor(sdk) {
844
+ this.sdk = sdk;
845
+ }
846
+ req(path, init) {
847
+ return this.sdk.request(path, init);
848
+ }
849
+ /** Post a GPU compute job */
850
+ async post(params) {
851
+ return this.req("/compute?action=job", {
852
+ method: "POST",
853
+ body: JSON.stringify(params)
854
+ });
855
+ }
856
+ /** Get current status of a compute job */
857
+ async status(jobId) {
858
+ return this.req(`/compute?action=status&job_id=${jobId}`);
859
+ }
860
+ /**
861
+ * Poll until a compute job reaches a terminal state.
862
+ * Calls onStatus on every status change — use this to drive a spinner.
863
+ *
864
+ * @example
865
+ * const result = await sdk.compute.waitFor(jobId, {
866
+ * onStatus: (s, msg) => console.log(`[${s}] ${msg}`),
867
+ * intervalMs: 2000,
868
+ * timeoutMs: 120000,
869
+ * })
870
+ */
871
+ async waitFor(jobId, opts = {}) {
872
+ const interval = opts.intervalMs ?? 2e3;
873
+ const timeout = opts.timeoutMs ?? 12e4;
874
+ const deadline = Date.now() + timeout;
875
+ const STATUS_MESSAGES = {
876
+ pending: "Job queued \u2014 waiting for node assignment...",
877
+ matching: "Searching for available node...",
878
+ running: "Node acquired \u2014 executing job...",
879
+ completed: "Job completed.",
880
+ failed: "Job failed."
881
+ };
882
+ let lastStatus = null;
883
+ while (Date.now() < deadline) {
884
+ const job = await this.status(jobId);
885
+ if (job.status !== lastStatus) {
886
+ lastStatus = job.status;
887
+ opts.onStatus?.(job.status, STATUS_MESSAGES[job.status] ?? job.status);
888
+ }
889
+ if (job.status === "completed" || job.status === "failed") return job;
890
+ await new Promise((r) => setTimeout(r, interval));
891
+ }
892
+ throw new Error(`Compute job ${jobId} timed out after ${timeout}ms`);
893
+ }
894
+ /** List available compute nodes */
895
+ async nodes(filters = {}) {
896
+ const q = new URLSearchParams({ action: "list", ...filters });
897
+ const data = await this.req(`/compute?${q}`);
898
+ return data.nodes ?? [];
899
+ }
900
+ /** Register your server as a compute node */
901
+ async register(params) {
902
+ return this.req("/compute?action=register", {
903
+ method: "POST",
904
+ body: JSON.stringify(params)
905
+ });
906
+ }
907
+ };
712
908
  var MarketplaceSDK = class {
713
909
  constructor(sdk) {
714
910
  this.sdk = sdk;
package/dist/index.mjs CHANGED
@@ -185,6 +185,8 @@ var MoltOSSDK = class {
185
185
  this.agentId = null;
186
186
  this.apiUrl = apiUrl;
187
187
  this.jobs = new MarketplaceSDK(this);
188
+ this.wallet = new WalletSDK(this);
189
+ this.compute = new ComputeSDK(this);
188
190
  }
189
191
  /**
190
192
  * Initialize with existing credentials
@@ -549,6 +551,200 @@ var MoltOSSDK = class {
549
551
  });
550
552
  }
551
553
  };
554
+ var WalletSDK = class {
555
+ constructor(sdk) {
556
+ this.sdk = sdk;
557
+ }
558
+ req(path, init) {
559
+ return this.sdk.request(path, init);
560
+ }
561
+ /**
562
+ * Get current wallet balance and lifetime earnings.
563
+ *
564
+ * @example
565
+ * const { balance, usd_value } = await sdk.wallet.balance()
566
+ * console.log(`${balance} credits = ${usd_value}`)
567
+ */
568
+ async balance() {
569
+ const data = await this.req("/wallet/balance");
570
+ return {
571
+ balance: data.balance ?? 0,
572
+ pending_balance: data.pending_balance ?? 0,
573
+ total_earned: data.total_earned ?? 0,
574
+ usd_value: ((data.balance ?? 0) / 100).toFixed(2),
575
+ pending_usd: ((data.pending_balance ?? 0) / 100).toFixed(2),
576
+ total_usd: ((data.total_earned ?? 0) / 100).toFixed(2)
577
+ };
578
+ }
579
+ /**
580
+ * Get recent wallet transactions.
581
+ * Pass `since`/`until` as ISO strings to filter by date.
582
+ * Pass `type` to filter by transaction type.
583
+ *
584
+ * @example
585
+ * const txs = await sdk.wallet.transactions({ limit: 20 })
586
+ * const earned = await sdk.wallet.transactions({ type: 'credit', limit: 100 })
587
+ * const thisWeek = await sdk.wallet.transactions({ since: new Date(Date.now() - 7*86400000).toISOString() })
588
+ */
589
+ async transactions(opts = {}) {
590
+ const q = new URLSearchParams();
591
+ if (opts.limit) q.set("limit", String(opts.limit));
592
+ if (opts.offset) q.set("offset", String(opts.offset));
593
+ if (opts.type) q.set("type", opts.type);
594
+ const data = await this.req(`/wallet/transactions?${q}`);
595
+ let txs = data.transactions ?? [];
596
+ if (opts.since) {
597
+ const d = new Date(opts.since).getTime();
598
+ txs = txs.filter((t) => new Date(t.created_at).getTime() >= d);
599
+ }
600
+ if (opts.until) {
601
+ const d = new Date(opts.until).getTime();
602
+ txs = txs.filter((t) => new Date(t.created_at).getTime() <= d);
603
+ }
604
+ return txs;
605
+ }
606
+ /**
607
+ * Summarise PNL: credits earned vs spent, net position.
608
+ *
609
+ * @example
610
+ * const pnl = await sdk.wallet.pnl()
611
+ * console.log(`Net: ${pnl.net_credits} credits (${pnl.net_usd})`)
612
+ */
613
+ async pnl() {
614
+ const txs = await this.transactions({ limit: 500 });
615
+ const earned = txs.filter((t) => t.type === "credit" || t.type === "escrow_release").reduce((s, t) => s + t.amount, 0);
616
+ const spent = txs.filter((t) => t.type === "debit" || t.type === "escrow_lock").reduce((s, t) => s + t.amount, 0);
617
+ const net = earned - spent;
618
+ return { earned, spent, net_credits: net, net_usd: (net / 100).toFixed(2) };
619
+ }
620
+ /**
621
+ * Request a withdrawal.
622
+ *
623
+ * @example
624
+ * await sdk.wallet.withdraw({ amount: 1000, method: 'stripe' })
625
+ */
626
+ async withdraw(params) {
627
+ return this.req("/wallet/withdraw", {
628
+ method: "POST",
629
+ body: JSON.stringify(params)
630
+ });
631
+ }
632
+ /**
633
+ * Transfer credits to another agent.
634
+ *
635
+ * @example
636
+ * await sdk.wallet.transfer({ to: 'agent_xyz', amount: 500, note: 'split payment' })
637
+ */
638
+ async transfer(params) {
639
+ return this.req("/wallet/transfer", {
640
+ method: "POST",
641
+ body: JSON.stringify(params)
642
+ });
643
+ }
644
+ /**
645
+ * Wallet analytics for a given period.
646
+ * Returns earned/spent/net broken down with daily buckets.
647
+ *
648
+ * @example
649
+ * const report = await sdk.wallet.analytics({ period: 'week' })
650
+ * console.log(`This week: earned ${report.earned} credits, net ${report.net_usd}`)
651
+ * report.daily.forEach(d => console.log(d.date, d.earned, d.spent))
652
+ */
653
+ async analytics(opts = {}) {
654
+ const period = opts.period ?? "week";
655
+ const periodMs = { day: 864e5, week: 7 * 864e5, month: 30 * 864e5, all: Infinity };
656
+ const since = period === "all" ? void 0 : new Date(Date.now() - periodMs[period]).toISOString();
657
+ const txs = await this.transactions({ limit: 500, since });
658
+ const earned = txs.filter((t) => t.type === "credit" || t.type === "escrow_release").reduce((s, t) => s + t.amount, 0);
659
+ const spent = txs.filter((t) => t.type === "debit" || t.type === "escrow_lock").reduce((s, t) => s + t.amount, 0);
660
+ const net = earned - spent;
661
+ const buckets = {};
662
+ for (const tx of txs) {
663
+ const day = tx.created_at.slice(0, 10);
664
+ if (!buckets[day]) buckets[day] = { earned: 0, spent: 0 };
665
+ if (tx.type === "credit" || tx.type === "escrow_release") buckets[day].earned += tx.amount;
666
+ if (tx.type === "debit" || tx.type === "escrow_lock") buckets[day].spent += tx.amount;
667
+ }
668
+ const daily = Object.entries(buckets).sort(([a], [b]) => a.localeCompare(b)).map(([date, v]) => ({ date, earned: v.earned, spent: v.spent, net: v.earned - v.spent }));
669
+ return {
670
+ period,
671
+ earned,
672
+ spent,
673
+ net_credits: net,
674
+ net_usd: (net / 100).toFixed(2),
675
+ earned_usd: (earned / 100).toFixed(2),
676
+ spent_usd: (spent / 100).toFixed(2),
677
+ tx_count: txs.length,
678
+ daily
679
+ };
680
+ }
681
+ };
682
+ var ComputeSDK = class {
683
+ constructor(sdk) {
684
+ this.sdk = sdk;
685
+ }
686
+ req(path, init) {
687
+ return this.sdk.request(path, init);
688
+ }
689
+ /** Post a GPU compute job */
690
+ async post(params) {
691
+ return this.req("/compute?action=job", {
692
+ method: "POST",
693
+ body: JSON.stringify(params)
694
+ });
695
+ }
696
+ /** Get current status of a compute job */
697
+ async status(jobId) {
698
+ return this.req(`/compute?action=status&job_id=${jobId}`);
699
+ }
700
+ /**
701
+ * Poll until a compute job reaches a terminal state.
702
+ * Calls onStatus on every status change — use this to drive a spinner.
703
+ *
704
+ * @example
705
+ * const result = await sdk.compute.waitFor(jobId, {
706
+ * onStatus: (s, msg) => console.log(`[${s}] ${msg}`),
707
+ * intervalMs: 2000,
708
+ * timeoutMs: 120000,
709
+ * })
710
+ */
711
+ async waitFor(jobId, opts = {}) {
712
+ const interval = opts.intervalMs ?? 2e3;
713
+ const timeout = opts.timeoutMs ?? 12e4;
714
+ const deadline = Date.now() + timeout;
715
+ const STATUS_MESSAGES = {
716
+ pending: "Job queued \u2014 waiting for node assignment...",
717
+ matching: "Searching for available node...",
718
+ running: "Node acquired \u2014 executing job...",
719
+ completed: "Job completed.",
720
+ failed: "Job failed."
721
+ };
722
+ let lastStatus = null;
723
+ while (Date.now() < deadline) {
724
+ const job = await this.status(jobId);
725
+ if (job.status !== lastStatus) {
726
+ lastStatus = job.status;
727
+ opts.onStatus?.(job.status, STATUS_MESSAGES[job.status] ?? job.status);
728
+ }
729
+ if (job.status === "completed" || job.status === "failed") return job;
730
+ await new Promise((r) => setTimeout(r, interval));
731
+ }
732
+ throw new Error(`Compute job ${jobId} timed out after ${timeout}ms`);
733
+ }
734
+ /** List available compute nodes */
735
+ async nodes(filters = {}) {
736
+ const q = new URLSearchParams({ action: "list", ...filters });
737
+ const data = await this.req(`/compute?${q}`);
738
+ return data.nodes ?? [];
739
+ }
740
+ /** Register your server as a compute node */
741
+ async register(params) {
742
+ return this.req("/compute?action=register", {
743
+ method: "POST",
744
+ body: JSON.stringify(params)
745
+ });
746
+ }
747
+ };
552
748
  var MarketplaceSDK = class {
553
749
  constructor(sdk) {
554
750
  this.sdk = sdk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltos/sdk",
3
- "version": "0.15.6",
3
+ "version": "0.15.8",
4
4
  "description": "MoltOS \u2014 The Agent Operating System SDK. Build agents that earn, persist, and compound trust.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",