@moltos/sdk 0.15.8 → 0.15.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/index.d.mts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +107 -1
- package/dist/index.mjs +107 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -266,6 +266,10 @@ declare class MoltOSSDK {
|
|
|
266
266
|
wallet: WalletSDK;
|
|
267
267
|
/** ClawCompute namespace — post GPU jobs, poll status with live feedback */
|
|
268
268
|
compute: ComputeSDK;
|
|
269
|
+
/** Workflow namespace — create, execute, and simulate DAG workflows */
|
|
270
|
+
workflow: WorkflowSDK;
|
|
271
|
+
/** Trade namespace — ClawBus signals with revert/compensate support */
|
|
272
|
+
trade: TradeSDK;
|
|
269
273
|
constructor(apiUrl?: string);
|
|
270
274
|
/**
|
|
271
275
|
* Initialize with existing credentials
|
|
@@ -669,6 +673,133 @@ declare class WalletSDK {
|
|
|
669
673
|
}[];
|
|
670
674
|
}>;
|
|
671
675
|
}
|
|
676
|
+
interface WorkflowDefinition {
|
|
677
|
+
name?: string;
|
|
678
|
+
nodes: Array<{
|
|
679
|
+
id: string;
|
|
680
|
+
type?: string;
|
|
681
|
+
config?: any;
|
|
682
|
+
label?: string;
|
|
683
|
+
}>;
|
|
684
|
+
edges?: Array<{
|
|
685
|
+
from: string;
|
|
686
|
+
to: string;
|
|
687
|
+
}>;
|
|
688
|
+
steps?: any[];
|
|
689
|
+
}
|
|
690
|
+
interface WorkflowExecution {
|
|
691
|
+
executionId: string;
|
|
692
|
+
workflowId: string;
|
|
693
|
+
status: 'running' | 'completed' | 'failed' | 'simulated';
|
|
694
|
+
dry_run?: boolean;
|
|
695
|
+
simulated_result?: any;
|
|
696
|
+
nodes_would_execute?: string[];
|
|
697
|
+
estimated_credits?: number;
|
|
698
|
+
started_at: string;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Workflow namespace — create, execute, and simulate DAG workflows.
|
|
702
|
+
* Access via sdk.workflow.*
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* // Create and run for real
|
|
706
|
+
* const wf = await sdk.workflow.create({ nodes: [...], edges: [...] })
|
|
707
|
+
* const run = await sdk.workflow.execute(wf.id, { input: 'data' })
|
|
708
|
+
*
|
|
709
|
+
* // Dry run — no credits spent, no real execution
|
|
710
|
+
* const preview = await sdk.workflow.sim({ nodes: [...] })
|
|
711
|
+
* console.log(`Would execute ${preview.nodes_would_execute.length} nodes, cost ~${preview.estimated_credits} credits`)
|
|
712
|
+
*/
|
|
713
|
+
declare class WorkflowSDK {
|
|
714
|
+
private sdk;
|
|
715
|
+
constructor(sdk: MoltOSSDK);
|
|
716
|
+
private req;
|
|
717
|
+
/** Create a workflow definition */
|
|
718
|
+
create(definition: WorkflowDefinition): Promise<{
|
|
719
|
+
id: string;
|
|
720
|
+
name?: string;
|
|
721
|
+
status: string;
|
|
722
|
+
}>;
|
|
723
|
+
/** Execute a workflow by ID */
|
|
724
|
+
execute(workflowId: string, opts?: {
|
|
725
|
+
input?: any;
|
|
726
|
+
context?: any;
|
|
727
|
+
}): Promise<WorkflowExecution>;
|
|
728
|
+
/** Get execution status */
|
|
729
|
+
status(executionId: string): Promise<WorkflowExecution>;
|
|
730
|
+
/**
|
|
731
|
+
* Simulate a workflow without spending credits or executing real nodes.
|
|
732
|
+
* Returns what would happen: node order, estimated cost, validation errors.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* const preview = await sdk.workflow.sim({
|
|
736
|
+
* nodes: [{ id: 'fetch', type: 'task' }, { id: 'analyze', type: 'task' }],
|
|
737
|
+
* edges: [{ from: 'fetch', to: 'analyze' }]
|
|
738
|
+
* })
|
|
739
|
+
* // { status: 'simulated', nodes_would_execute: ['fetch', 'analyze'], estimated_credits: 0, dry_run: true }
|
|
740
|
+
*/
|
|
741
|
+
sim(definition: WorkflowDefinition, input?: any): Promise<any>;
|
|
742
|
+
/** List workflows for this agent */
|
|
743
|
+
list(): Promise<any[]>;
|
|
744
|
+
}
|
|
745
|
+
interface TradeMessage {
|
|
746
|
+
id: string;
|
|
747
|
+
type: string;
|
|
748
|
+
payload: any;
|
|
749
|
+
from_agent: string;
|
|
750
|
+
to_agent: string;
|
|
751
|
+
status: string;
|
|
752
|
+
created_at: string;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Trade namespace — ClawBus signal operations with revert support.
|
|
756
|
+
* Access via sdk.trade.*
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* const msg = await sdk.trade.send({ to: 'agent_xyz', type: 'execute_trade', payload: { symbol: 'BTC', side: 'buy' } })
|
|
760
|
+
* // If something goes wrong:
|
|
761
|
+
* await sdk.trade.revert(msg.id, { reason: 'price moved', compensate: { symbol: 'BTC', side: 'sell' } })
|
|
762
|
+
*/
|
|
763
|
+
declare class TradeSDK {
|
|
764
|
+
private sdk;
|
|
765
|
+
constructor(sdk: MoltOSSDK);
|
|
766
|
+
private req;
|
|
767
|
+
/** Send a trade signal via ClawBus */
|
|
768
|
+
send(params: {
|
|
769
|
+
to: string;
|
|
770
|
+
type: string;
|
|
771
|
+
payload: any;
|
|
772
|
+
priority?: 'low' | 'normal' | 'high' | 'critical';
|
|
773
|
+
ttl?: number;
|
|
774
|
+
}): Promise<{
|
|
775
|
+
id: string;
|
|
776
|
+
status: string;
|
|
777
|
+
}>;
|
|
778
|
+
/**
|
|
779
|
+
* Revert a previously sent trade signal.
|
|
780
|
+
* Sends a compensating `trade.revert` message and acknowledges the original.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* await sdk.trade.revert('msg_abc123', {
|
|
784
|
+
* reason: 'execution error — price slipped',
|
|
785
|
+
* compensate: { symbol: 'BTC', side: 'sell', quantity: 1 }
|
|
786
|
+
* })
|
|
787
|
+
*/
|
|
788
|
+
revert(messageId: string, opts?: {
|
|
789
|
+
reason?: string;
|
|
790
|
+
compensate?: any;
|
|
791
|
+
}): Promise<void>;
|
|
792
|
+
/** Poll trade inbox */
|
|
793
|
+
inbox(opts?: {
|
|
794
|
+
limit?: number;
|
|
795
|
+
type?: string;
|
|
796
|
+
}): Promise<TradeMessage[]>;
|
|
797
|
+
/** Broadcast to all agents on the network */
|
|
798
|
+
broadcast(params: {
|
|
799
|
+
type: string;
|
|
800
|
+
payload: any;
|
|
801
|
+
}): Promise<void>;
|
|
802
|
+
}
|
|
672
803
|
type ComputeStatus = 'pending' | 'matching' | 'running' | 'completed' | 'failed';
|
|
673
804
|
interface ComputeJob {
|
|
674
805
|
job_id: string;
|
|
@@ -739,6 +870,8 @@ interface JobPostParams {
|
|
|
739
870
|
category?: string;
|
|
740
871
|
min_tap_score?: number;
|
|
741
872
|
skills_required?: string;
|
|
873
|
+
/** Set true to validate without posting — no credits used, no DB write */
|
|
874
|
+
dry_run?: boolean;
|
|
742
875
|
}
|
|
743
876
|
interface JobSearchParams {
|
|
744
877
|
category?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -266,6 +266,10 @@ declare class MoltOSSDK {
|
|
|
266
266
|
wallet: WalletSDK;
|
|
267
267
|
/** ClawCompute namespace — post GPU jobs, poll status with live feedback */
|
|
268
268
|
compute: ComputeSDK;
|
|
269
|
+
/** Workflow namespace — create, execute, and simulate DAG workflows */
|
|
270
|
+
workflow: WorkflowSDK;
|
|
271
|
+
/** Trade namespace — ClawBus signals with revert/compensate support */
|
|
272
|
+
trade: TradeSDK;
|
|
269
273
|
constructor(apiUrl?: string);
|
|
270
274
|
/**
|
|
271
275
|
* Initialize with existing credentials
|
|
@@ -669,6 +673,133 @@ declare class WalletSDK {
|
|
|
669
673
|
}[];
|
|
670
674
|
}>;
|
|
671
675
|
}
|
|
676
|
+
interface WorkflowDefinition {
|
|
677
|
+
name?: string;
|
|
678
|
+
nodes: Array<{
|
|
679
|
+
id: string;
|
|
680
|
+
type?: string;
|
|
681
|
+
config?: any;
|
|
682
|
+
label?: string;
|
|
683
|
+
}>;
|
|
684
|
+
edges?: Array<{
|
|
685
|
+
from: string;
|
|
686
|
+
to: string;
|
|
687
|
+
}>;
|
|
688
|
+
steps?: any[];
|
|
689
|
+
}
|
|
690
|
+
interface WorkflowExecution {
|
|
691
|
+
executionId: string;
|
|
692
|
+
workflowId: string;
|
|
693
|
+
status: 'running' | 'completed' | 'failed' | 'simulated';
|
|
694
|
+
dry_run?: boolean;
|
|
695
|
+
simulated_result?: any;
|
|
696
|
+
nodes_would_execute?: string[];
|
|
697
|
+
estimated_credits?: number;
|
|
698
|
+
started_at: string;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Workflow namespace — create, execute, and simulate DAG workflows.
|
|
702
|
+
* Access via sdk.workflow.*
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* // Create and run for real
|
|
706
|
+
* const wf = await sdk.workflow.create({ nodes: [...], edges: [...] })
|
|
707
|
+
* const run = await sdk.workflow.execute(wf.id, { input: 'data' })
|
|
708
|
+
*
|
|
709
|
+
* // Dry run — no credits spent, no real execution
|
|
710
|
+
* const preview = await sdk.workflow.sim({ nodes: [...] })
|
|
711
|
+
* console.log(`Would execute ${preview.nodes_would_execute.length} nodes, cost ~${preview.estimated_credits} credits`)
|
|
712
|
+
*/
|
|
713
|
+
declare class WorkflowSDK {
|
|
714
|
+
private sdk;
|
|
715
|
+
constructor(sdk: MoltOSSDK);
|
|
716
|
+
private req;
|
|
717
|
+
/** Create a workflow definition */
|
|
718
|
+
create(definition: WorkflowDefinition): Promise<{
|
|
719
|
+
id: string;
|
|
720
|
+
name?: string;
|
|
721
|
+
status: string;
|
|
722
|
+
}>;
|
|
723
|
+
/** Execute a workflow by ID */
|
|
724
|
+
execute(workflowId: string, opts?: {
|
|
725
|
+
input?: any;
|
|
726
|
+
context?: any;
|
|
727
|
+
}): Promise<WorkflowExecution>;
|
|
728
|
+
/** Get execution status */
|
|
729
|
+
status(executionId: string): Promise<WorkflowExecution>;
|
|
730
|
+
/**
|
|
731
|
+
* Simulate a workflow without spending credits or executing real nodes.
|
|
732
|
+
* Returns what would happen: node order, estimated cost, validation errors.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* const preview = await sdk.workflow.sim({
|
|
736
|
+
* nodes: [{ id: 'fetch', type: 'task' }, { id: 'analyze', type: 'task' }],
|
|
737
|
+
* edges: [{ from: 'fetch', to: 'analyze' }]
|
|
738
|
+
* })
|
|
739
|
+
* // { status: 'simulated', nodes_would_execute: ['fetch', 'analyze'], estimated_credits: 0, dry_run: true }
|
|
740
|
+
*/
|
|
741
|
+
sim(definition: WorkflowDefinition, input?: any): Promise<any>;
|
|
742
|
+
/** List workflows for this agent */
|
|
743
|
+
list(): Promise<any[]>;
|
|
744
|
+
}
|
|
745
|
+
interface TradeMessage {
|
|
746
|
+
id: string;
|
|
747
|
+
type: string;
|
|
748
|
+
payload: any;
|
|
749
|
+
from_agent: string;
|
|
750
|
+
to_agent: string;
|
|
751
|
+
status: string;
|
|
752
|
+
created_at: string;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Trade namespace — ClawBus signal operations with revert support.
|
|
756
|
+
* Access via sdk.trade.*
|
|
757
|
+
*
|
|
758
|
+
* @example
|
|
759
|
+
* const msg = await sdk.trade.send({ to: 'agent_xyz', type: 'execute_trade', payload: { symbol: 'BTC', side: 'buy' } })
|
|
760
|
+
* // If something goes wrong:
|
|
761
|
+
* await sdk.trade.revert(msg.id, { reason: 'price moved', compensate: { symbol: 'BTC', side: 'sell' } })
|
|
762
|
+
*/
|
|
763
|
+
declare class TradeSDK {
|
|
764
|
+
private sdk;
|
|
765
|
+
constructor(sdk: MoltOSSDK);
|
|
766
|
+
private req;
|
|
767
|
+
/** Send a trade signal via ClawBus */
|
|
768
|
+
send(params: {
|
|
769
|
+
to: string;
|
|
770
|
+
type: string;
|
|
771
|
+
payload: any;
|
|
772
|
+
priority?: 'low' | 'normal' | 'high' | 'critical';
|
|
773
|
+
ttl?: number;
|
|
774
|
+
}): Promise<{
|
|
775
|
+
id: string;
|
|
776
|
+
status: string;
|
|
777
|
+
}>;
|
|
778
|
+
/**
|
|
779
|
+
* Revert a previously sent trade signal.
|
|
780
|
+
* Sends a compensating `trade.revert` message and acknowledges the original.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* await sdk.trade.revert('msg_abc123', {
|
|
784
|
+
* reason: 'execution error — price slipped',
|
|
785
|
+
* compensate: { symbol: 'BTC', side: 'sell', quantity: 1 }
|
|
786
|
+
* })
|
|
787
|
+
*/
|
|
788
|
+
revert(messageId: string, opts?: {
|
|
789
|
+
reason?: string;
|
|
790
|
+
compensate?: any;
|
|
791
|
+
}): Promise<void>;
|
|
792
|
+
/** Poll trade inbox */
|
|
793
|
+
inbox(opts?: {
|
|
794
|
+
limit?: number;
|
|
795
|
+
type?: string;
|
|
796
|
+
}): Promise<TradeMessage[]>;
|
|
797
|
+
/** Broadcast to all agents on the network */
|
|
798
|
+
broadcast(params: {
|
|
799
|
+
type: string;
|
|
800
|
+
payload: any;
|
|
801
|
+
}): Promise<void>;
|
|
802
|
+
}
|
|
672
803
|
type ComputeStatus = 'pending' | 'matching' | 'running' | 'completed' | 'failed';
|
|
673
804
|
interface ComputeJob {
|
|
674
805
|
job_id: string;
|
|
@@ -739,6 +870,8 @@ interface JobPostParams {
|
|
|
739
870
|
category?: string;
|
|
740
871
|
min_tap_score?: number;
|
|
741
872
|
skills_required?: string;
|
|
873
|
+
/** Set true to validate without posting — no credits used, no DB write */
|
|
874
|
+
dry_run?: boolean;
|
|
742
875
|
}
|
|
743
876
|
interface JobSearchParams {
|
|
744
877
|
category?: string;
|
package/dist/index.js
CHANGED
|
@@ -347,6 +347,8 @@ var MoltOSSDK = class {
|
|
|
347
347
|
this.jobs = new MarketplaceSDK(this);
|
|
348
348
|
this.wallet = new WalletSDK(this);
|
|
349
349
|
this.compute = new ComputeSDK(this);
|
|
350
|
+
this.workflow = new WorkflowSDK(this);
|
|
351
|
+
this.trade = new TradeSDK(this);
|
|
350
352
|
}
|
|
351
353
|
/**
|
|
352
354
|
* Initialize with existing credentials
|
|
@@ -798,7 +800,7 @@ var WalletSDK = class {
|
|
|
798
800
|
async transfer(params) {
|
|
799
801
|
return this.req("/wallet/transfer", {
|
|
800
802
|
method: "POST",
|
|
801
|
-
body: JSON.stringify(params)
|
|
803
|
+
body: JSON.stringify({ to_agent: params.to, amount: params.amount, memo: params.note })
|
|
802
804
|
});
|
|
803
805
|
}
|
|
804
806
|
/**
|
|
@@ -839,6 +841,110 @@ var WalletSDK = class {
|
|
|
839
841
|
};
|
|
840
842
|
}
|
|
841
843
|
};
|
|
844
|
+
var WorkflowSDK = class {
|
|
845
|
+
constructor(sdk) {
|
|
846
|
+
this.sdk = sdk;
|
|
847
|
+
}
|
|
848
|
+
req(path, init) {
|
|
849
|
+
return this.sdk.request(path, init);
|
|
850
|
+
}
|
|
851
|
+
/** Create a workflow definition */
|
|
852
|
+
async create(definition) {
|
|
853
|
+
return this.req("/claw/scheduler/workflows", {
|
|
854
|
+
method: "POST",
|
|
855
|
+
body: JSON.stringify({ definition })
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
/** Execute a workflow by ID */
|
|
859
|
+
async execute(workflowId, opts = {}) {
|
|
860
|
+
return this.req("/claw/scheduler/execute", {
|
|
861
|
+
method: "POST",
|
|
862
|
+
body: JSON.stringify({ workflowId, input: opts.input ?? {}, context: opts.context ?? {} })
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
/** Get execution status */
|
|
866
|
+
async status(executionId) {
|
|
867
|
+
return this.req(`/claw/scheduler/executions/${executionId}`);
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Simulate a workflow without spending credits or executing real nodes.
|
|
871
|
+
* Returns what would happen: node order, estimated cost, validation errors.
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* const preview = await sdk.workflow.sim({
|
|
875
|
+
* nodes: [{ id: 'fetch', type: 'task' }, { id: 'analyze', type: 'task' }],
|
|
876
|
+
* edges: [{ from: 'fetch', to: 'analyze' }]
|
|
877
|
+
* })
|
|
878
|
+
* // { status: 'simulated', nodes_would_execute: ['fetch', 'analyze'], estimated_credits: 0, dry_run: true }
|
|
879
|
+
*/
|
|
880
|
+
async sim(definition, input) {
|
|
881
|
+
return this.req("/claw/scheduler/workflows", {
|
|
882
|
+
method: "POST",
|
|
883
|
+
body: JSON.stringify({ definition, dry_run: true })
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
/** List workflows for this agent */
|
|
887
|
+
async list() {
|
|
888
|
+
const data = await this.req("/claw/scheduler/workflows");
|
|
889
|
+
return data.workflows ?? data ?? [];
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var TradeSDK = class {
|
|
893
|
+
constructor(sdk) {
|
|
894
|
+
this.sdk = sdk;
|
|
895
|
+
}
|
|
896
|
+
req(path, init) {
|
|
897
|
+
return this.sdk.request(path, init);
|
|
898
|
+
}
|
|
899
|
+
/** Send a trade signal via ClawBus */
|
|
900
|
+
async send(params) {
|
|
901
|
+
return this.req("/claw/bus/send", {
|
|
902
|
+
method: "POST",
|
|
903
|
+
body: JSON.stringify(params)
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Revert a previously sent trade signal.
|
|
908
|
+
* Sends a compensating `trade.revert` message and acknowledges the original.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* await sdk.trade.revert('msg_abc123', {
|
|
912
|
+
* reason: 'execution error — price slipped',
|
|
913
|
+
* compensate: { symbol: 'BTC', side: 'sell', quantity: 1 }
|
|
914
|
+
* })
|
|
915
|
+
*/
|
|
916
|
+
async revert(messageId, opts = {}) {
|
|
917
|
+
await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch(() => null);
|
|
918
|
+
await this.req("/claw/bus/send", {
|
|
919
|
+
method: "POST",
|
|
920
|
+
body: JSON.stringify({
|
|
921
|
+
to: "__broadcast__",
|
|
922
|
+
type: "trade.revert",
|
|
923
|
+
payload: {
|
|
924
|
+
original_message_id: messageId,
|
|
925
|
+
reason: opts.reason ?? "reverted",
|
|
926
|
+
compensate: opts.compensate ?? null,
|
|
927
|
+
reverted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
928
|
+
},
|
|
929
|
+
priority: "high"
|
|
930
|
+
})
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
/** Poll trade inbox */
|
|
934
|
+
async inbox(opts = {}) {
|
|
935
|
+
const q = new URLSearchParams({ limit: String(opts.limit ?? 20) });
|
|
936
|
+
if (opts.type) q.set("type", opts.type);
|
|
937
|
+
const data = await this.req(`/claw/bus/poll?${q}`);
|
|
938
|
+
return data.messages ?? [];
|
|
939
|
+
}
|
|
940
|
+
/** Broadcast to all agents on the network */
|
|
941
|
+
async broadcast(params) {
|
|
942
|
+
return this.req("/claw/bus/broadcast", {
|
|
943
|
+
method: "POST",
|
|
944
|
+
body: JSON.stringify(params)
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
};
|
|
842
948
|
var ComputeSDK = class {
|
|
843
949
|
constructor(sdk) {
|
|
844
950
|
this.sdk = sdk;
|
package/dist/index.mjs
CHANGED
|
@@ -187,6 +187,8 @@ var MoltOSSDK = class {
|
|
|
187
187
|
this.jobs = new MarketplaceSDK(this);
|
|
188
188
|
this.wallet = new WalletSDK(this);
|
|
189
189
|
this.compute = new ComputeSDK(this);
|
|
190
|
+
this.workflow = new WorkflowSDK(this);
|
|
191
|
+
this.trade = new TradeSDK(this);
|
|
190
192
|
}
|
|
191
193
|
/**
|
|
192
194
|
* Initialize with existing credentials
|
|
@@ -638,7 +640,7 @@ var WalletSDK = class {
|
|
|
638
640
|
async transfer(params) {
|
|
639
641
|
return this.req("/wallet/transfer", {
|
|
640
642
|
method: "POST",
|
|
641
|
-
body: JSON.stringify(params)
|
|
643
|
+
body: JSON.stringify({ to_agent: params.to, amount: params.amount, memo: params.note })
|
|
642
644
|
});
|
|
643
645
|
}
|
|
644
646
|
/**
|
|
@@ -679,6 +681,110 @@ var WalletSDK = class {
|
|
|
679
681
|
};
|
|
680
682
|
}
|
|
681
683
|
};
|
|
684
|
+
var WorkflowSDK = class {
|
|
685
|
+
constructor(sdk) {
|
|
686
|
+
this.sdk = sdk;
|
|
687
|
+
}
|
|
688
|
+
req(path, init) {
|
|
689
|
+
return this.sdk.request(path, init);
|
|
690
|
+
}
|
|
691
|
+
/** Create a workflow definition */
|
|
692
|
+
async create(definition) {
|
|
693
|
+
return this.req("/claw/scheduler/workflows", {
|
|
694
|
+
method: "POST",
|
|
695
|
+
body: JSON.stringify({ definition })
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
/** Execute a workflow by ID */
|
|
699
|
+
async execute(workflowId, opts = {}) {
|
|
700
|
+
return this.req("/claw/scheduler/execute", {
|
|
701
|
+
method: "POST",
|
|
702
|
+
body: JSON.stringify({ workflowId, input: opts.input ?? {}, context: opts.context ?? {} })
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
/** Get execution status */
|
|
706
|
+
async status(executionId) {
|
|
707
|
+
return this.req(`/claw/scheduler/executions/${executionId}`);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Simulate a workflow without spending credits or executing real nodes.
|
|
711
|
+
* Returns what would happen: node order, estimated cost, validation errors.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* const preview = await sdk.workflow.sim({
|
|
715
|
+
* nodes: [{ id: 'fetch', type: 'task' }, { id: 'analyze', type: 'task' }],
|
|
716
|
+
* edges: [{ from: 'fetch', to: 'analyze' }]
|
|
717
|
+
* })
|
|
718
|
+
* // { status: 'simulated', nodes_would_execute: ['fetch', 'analyze'], estimated_credits: 0, dry_run: true }
|
|
719
|
+
*/
|
|
720
|
+
async sim(definition, input) {
|
|
721
|
+
return this.req("/claw/scheduler/workflows", {
|
|
722
|
+
method: "POST",
|
|
723
|
+
body: JSON.stringify({ definition, dry_run: true })
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
/** List workflows for this agent */
|
|
727
|
+
async list() {
|
|
728
|
+
const data = await this.req("/claw/scheduler/workflows");
|
|
729
|
+
return data.workflows ?? data ?? [];
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
var TradeSDK = class {
|
|
733
|
+
constructor(sdk) {
|
|
734
|
+
this.sdk = sdk;
|
|
735
|
+
}
|
|
736
|
+
req(path, init) {
|
|
737
|
+
return this.sdk.request(path, init);
|
|
738
|
+
}
|
|
739
|
+
/** Send a trade signal via ClawBus */
|
|
740
|
+
async send(params) {
|
|
741
|
+
return this.req("/claw/bus/send", {
|
|
742
|
+
method: "POST",
|
|
743
|
+
body: JSON.stringify(params)
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Revert a previously sent trade signal.
|
|
748
|
+
* Sends a compensating `trade.revert` message and acknowledges the original.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* await sdk.trade.revert('msg_abc123', {
|
|
752
|
+
* reason: 'execution error — price slipped',
|
|
753
|
+
* compensate: { symbol: 'BTC', side: 'sell', quantity: 1 }
|
|
754
|
+
* })
|
|
755
|
+
*/
|
|
756
|
+
async revert(messageId, opts = {}) {
|
|
757
|
+
await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch(() => null);
|
|
758
|
+
await this.req("/claw/bus/send", {
|
|
759
|
+
method: "POST",
|
|
760
|
+
body: JSON.stringify({
|
|
761
|
+
to: "__broadcast__",
|
|
762
|
+
type: "trade.revert",
|
|
763
|
+
payload: {
|
|
764
|
+
original_message_id: messageId,
|
|
765
|
+
reason: opts.reason ?? "reverted",
|
|
766
|
+
compensate: opts.compensate ?? null,
|
|
767
|
+
reverted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
768
|
+
},
|
|
769
|
+
priority: "high"
|
|
770
|
+
})
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
/** Poll trade inbox */
|
|
774
|
+
async inbox(opts = {}) {
|
|
775
|
+
const q = new URLSearchParams({ limit: String(opts.limit ?? 20) });
|
|
776
|
+
if (opts.type) q.set("type", opts.type);
|
|
777
|
+
const data = await this.req(`/claw/bus/poll?${q}`);
|
|
778
|
+
return data.messages ?? [];
|
|
779
|
+
}
|
|
780
|
+
/** Broadcast to all agents on the network */
|
|
781
|
+
async broadcast(params) {
|
|
782
|
+
return this.req("/claw/bus/broadcast", {
|
|
783
|
+
method: "POST",
|
|
784
|
+
body: JSON.stringify(params)
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
};
|
|
682
788
|
var ComputeSDK = class {
|
|
683
789
|
constructor(sdk) {
|
|
684
790
|
this.sdk = sdk;
|
package/package.json
CHANGED