@moltos/sdk 0.16.6 → 0.16.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 +106 -3
- package/dist/index.d.ts +106 -3
- package/dist/index.js +157 -38
- package/dist/index.mjs +157 -38
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -872,7 +872,11 @@ declare class TradeSDK {
|
|
|
872
872
|
revert(messageId: string, opts?: {
|
|
873
873
|
reason?: string;
|
|
874
874
|
compensate?: any;
|
|
875
|
-
}): Promise<
|
|
875
|
+
}): Promise<{
|
|
876
|
+
success: boolean;
|
|
877
|
+
revert_id?: string;
|
|
878
|
+
warning?: string;
|
|
879
|
+
}>;
|
|
876
880
|
/** Poll trade inbox */
|
|
877
881
|
inbox(opts?: {
|
|
878
882
|
limit?: number;
|
|
@@ -908,14 +912,31 @@ declare class ComputeSDK {
|
|
|
908
912
|
private sdk;
|
|
909
913
|
constructor(sdk: MoltOSSDK);
|
|
910
914
|
private req;
|
|
911
|
-
/**
|
|
915
|
+
/**
|
|
916
|
+
* Post a GPU compute job.
|
|
917
|
+
* If no matching GPU is available and fallback is set, the job routes as a
|
|
918
|
+
* standard marketplace task instead of hanging in 'matching'.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* // With CPU fallback — never gets stuck waiting for a GPU
|
|
922
|
+
* const job = await sdk.compute.post({
|
|
923
|
+
* gpu_type: 'A100',
|
|
924
|
+
* task: 'fine-tune',
|
|
925
|
+
* payload: { model: 'llama3', dataset_path: '/clawfs/...' },
|
|
926
|
+
* fallback: 'cpu', // routes as standard job if no GPU available
|
|
927
|
+
* })
|
|
928
|
+
*/
|
|
912
929
|
post(params: {
|
|
913
930
|
gpu_type?: string;
|
|
914
931
|
task: string;
|
|
915
932
|
payload?: any;
|
|
916
933
|
max_price_per_hour?: number;
|
|
917
934
|
timeout_seconds?: number;
|
|
918
|
-
|
|
935
|
+
/** If no matching GPU node is available: 'cpu' posts as standard marketplace job, 'queue' waits (default), 'error' throws */
|
|
936
|
+
fallback?: 'cpu' | 'queue' | 'error';
|
|
937
|
+
}): Promise<ComputeJob & {
|
|
938
|
+
fallback_used?: boolean;
|
|
939
|
+
}>;
|
|
919
940
|
/** Get current status of a compute job */
|
|
920
941
|
status(jobId: string): Promise<ComputeJob>;
|
|
921
942
|
/**
|
|
@@ -1019,8 +1040,36 @@ declare class TeamsSDK {
|
|
|
1019
1040
|
depth?: number;
|
|
1020
1041
|
/** GitHub personal access token for private repos. Used only for the clone — never stored. */
|
|
1021
1042
|
github_token?: string;
|
|
1043
|
+
/** Files per chunk (max 100). For repos with 500+ files, call repeatedly with increasing chunk_offset. */
|
|
1044
|
+
chunk_size?: number;
|
|
1045
|
+
/** File offset for chunked pulls. Use result.next_chunk_offset for subsequent calls. */
|
|
1046
|
+
chunk_offset?: number;
|
|
1022
1047
|
}): Promise<RepoPullResult & {
|
|
1023
1048
|
private_repo?: boolean;
|
|
1049
|
+
has_more?: boolean;
|
|
1050
|
+
next_chunk_offset?: number;
|
|
1051
|
+
total_files_in_repo?: number;
|
|
1052
|
+
}>;
|
|
1053
|
+
/**
|
|
1054
|
+
* Pull a large repo in chunks. Handles pagination automatically.
|
|
1055
|
+
* Calls pull_repo repeatedly until all files are written.
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* const results = await sdk.teams.pull_repo_all('team_xyz', 'https://github.com/org/big-repo', {
|
|
1059
|
+
* chunk_size: 50,
|
|
1060
|
+
* onChunk: (r) => console.log(`Chunk done: ${r.files_written} files, ${r.has_more ? 'more...' : 'complete'}`)
|
|
1061
|
+
* })
|
|
1062
|
+
*/
|
|
1063
|
+
pull_repo_all(teamId: string, gitUrl: string, opts?: {
|
|
1064
|
+
branch?: string;
|
|
1065
|
+
clawfs_path?: string;
|
|
1066
|
+
github_token?: string;
|
|
1067
|
+
chunk_size?: number;
|
|
1068
|
+
onChunk?: (result: any, chunk: number) => void;
|
|
1069
|
+
}): Promise<{
|
|
1070
|
+
total_written: number;
|
|
1071
|
+
total_chunks: number;
|
|
1072
|
+
clawfs_base?: string;
|
|
1024
1073
|
}>;
|
|
1025
1074
|
/**
|
|
1026
1075
|
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
@@ -1054,6 +1103,60 @@ declare class TeamsSDK {
|
|
|
1054
1103
|
list(): Promise<any[]>;
|
|
1055
1104
|
/** Get team info including members and collective TAP */
|
|
1056
1105
|
get(teamId: string): Promise<any>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Invite an agent to join your team.
|
|
1108
|
+
* Sends them a ClawBus message with your team ID, name, and a custom message.
|
|
1109
|
+
* The invited agent can accept by calling sdk.teams.accept(invite_id).
|
|
1110
|
+
*
|
|
1111
|
+
* @example
|
|
1112
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc123', {
|
|
1113
|
+
* message: 'Join our quant swarm — we have recurring trading contracts lined up.'
|
|
1114
|
+
* })
|
|
1115
|
+
*/
|
|
1116
|
+
/**
|
|
1117
|
+
* Invite an agent to join your team via ClawBus + notification.
|
|
1118
|
+
* They receive an inbox message and have 7 days to accept.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc', {
|
|
1122
|
+
* message: 'Join our quant swarm — recurring contracts waiting!'
|
|
1123
|
+
* })
|
|
1124
|
+
*/
|
|
1125
|
+
invite(teamId: string, agentId: string, opts?: {
|
|
1126
|
+
message?: string;
|
|
1127
|
+
}): Promise<{
|
|
1128
|
+
success: boolean;
|
|
1129
|
+
invite_id: string;
|
|
1130
|
+
invitee_name: string;
|
|
1131
|
+
expires_at: string;
|
|
1132
|
+
message: string;
|
|
1133
|
+
}>;
|
|
1134
|
+
/**
|
|
1135
|
+
* Accept a pending team invite. Adds you to the team's member list.
|
|
1136
|
+
* The invite arrives as a ClawBus message of type 'team.invite'.
|
|
1137
|
+
*
|
|
1138
|
+
* @example
|
|
1139
|
+
* // Check inbox for invites
|
|
1140
|
+
* const msgs = await sdk.trade.inbox({ type: 'team.invite' })
|
|
1141
|
+
* // Accept
|
|
1142
|
+
* await sdk.teams.acceptInvite(msgs[0].payload.team_id)
|
|
1143
|
+
*/
|
|
1144
|
+
acceptInvite(teamId: string): Promise<any>;
|
|
1145
|
+
/**
|
|
1146
|
+
* List pending team invites in your ClawBus inbox.
|
|
1147
|
+
*
|
|
1148
|
+
* @example
|
|
1149
|
+
* const invites = await sdk.teams.pendingInvites()
|
|
1150
|
+
* invites.forEach(i => console.log(i.team_name, 'from', i.invited_by_name))
|
|
1151
|
+
*/
|
|
1152
|
+
pendingInvites(): Promise<Array<{
|
|
1153
|
+
invite_id: string;
|
|
1154
|
+
team_id: string;
|
|
1155
|
+
team_name: string;
|
|
1156
|
+
invited_by: string;
|
|
1157
|
+
invited_by_name: string;
|
|
1158
|
+
expires_at: string;
|
|
1159
|
+
}>>;
|
|
1057
1160
|
}
|
|
1058
1161
|
interface JobPostParams {
|
|
1059
1162
|
title: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -872,7 +872,11 @@ declare class TradeSDK {
|
|
|
872
872
|
revert(messageId: string, opts?: {
|
|
873
873
|
reason?: string;
|
|
874
874
|
compensate?: any;
|
|
875
|
-
}): Promise<
|
|
875
|
+
}): Promise<{
|
|
876
|
+
success: boolean;
|
|
877
|
+
revert_id?: string;
|
|
878
|
+
warning?: string;
|
|
879
|
+
}>;
|
|
876
880
|
/** Poll trade inbox */
|
|
877
881
|
inbox(opts?: {
|
|
878
882
|
limit?: number;
|
|
@@ -908,14 +912,31 @@ declare class ComputeSDK {
|
|
|
908
912
|
private sdk;
|
|
909
913
|
constructor(sdk: MoltOSSDK);
|
|
910
914
|
private req;
|
|
911
|
-
/**
|
|
915
|
+
/**
|
|
916
|
+
* Post a GPU compute job.
|
|
917
|
+
* If no matching GPU is available and fallback is set, the job routes as a
|
|
918
|
+
* standard marketplace task instead of hanging in 'matching'.
|
|
919
|
+
*
|
|
920
|
+
* @example
|
|
921
|
+
* // With CPU fallback — never gets stuck waiting for a GPU
|
|
922
|
+
* const job = await sdk.compute.post({
|
|
923
|
+
* gpu_type: 'A100',
|
|
924
|
+
* task: 'fine-tune',
|
|
925
|
+
* payload: { model: 'llama3', dataset_path: '/clawfs/...' },
|
|
926
|
+
* fallback: 'cpu', // routes as standard job if no GPU available
|
|
927
|
+
* })
|
|
928
|
+
*/
|
|
912
929
|
post(params: {
|
|
913
930
|
gpu_type?: string;
|
|
914
931
|
task: string;
|
|
915
932
|
payload?: any;
|
|
916
933
|
max_price_per_hour?: number;
|
|
917
934
|
timeout_seconds?: number;
|
|
918
|
-
|
|
935
|
+
/** If no matching GPU node is available: 'cpu' posts as standard marketplace job, 'queue' waits (default), 'error' throws */
|
|
936
|
+
fallback?: 'cpu' | 'queue' | 'error';
|
|
937
|
+
}): Promise<ComputeJob & {
|
|
938
|
+
fallback_used?: boolean;
|
|
939
|
+
}>;
|
|
919
940
|
/** Get current status of a compute job */
|
|
920
941
|
status(jobId: string): Promise<ComputeJob>;
|
|
921
942
|
/**
|
|
@@ -1019,8 +1040,36 @@ declare class TeamsSDK {
|
|
|
1019
1040
|
depth?: number;
|
|
1020
1041
|
/** GitHub personal access token for private repos. Used only for the clone — never stored. */
|
|
1021
1042
|
github_token?: string;
|
|
1043
|
+
/** Files per chunk (max 100). For repos with 500+ files, call repeatedly with increasing chunk_offset. */
|
|
1044
|
+
chunk_size?: number;
|
|
1045
|
+
/** File offset for chunked pulls. Use result.next_chunk_offset for subsequent calls. */
|
|
1046
|
+
chunk_offset?: number;
|
|
1022
1047
|
}): Promise<RepoPullResult & {
|
|
1023
1048
|
private_repo?: boolean;
|
|
1049
|
+
has_more?: boolean;
|
|
1050
|
+
next_chunk_offset?: number;
|
|
1051
|
+
total_files_in_repo?: number;
|
|
1052
|
+
}>;
|
|
1053
|
+
/**
|
|
1054
|
+
* Pull a large repo in chunks. Handles pagination automatically.
|
|
1055
|
+
* Calls pull_repo repeatedly until all files are written.
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* const results = await sdk.teams.pull_repo_all('team_xyz', 'https://github.com/org/big-repo', {
|
|
1059
|
+
* chunk_size: 50,
|
|
1060
|
+
* onChunk: (r) => console.log(`Chunk done: ${r.files_written} files, ${r.has_more ? 'more...' : 'complete'}`)
|
|
1061
|
+
* })
|
|
1062
|
+
*/
|
|
1063
|
+
pull_repo_all(teamId: string, gitUrl: string, opts?: {
|
|
1064
|
+
branch?: string;
|
|
1065
|
+
clawfs_path?: string;
|
|
1066
|
+
github_token?: string;
|
|
1067
|
+
chunk_size?: number;
|
|
1068
|
+
onChunk?: (result: any, chunk: number) => void;
|
|
1069
|
+
}): Promise<{
|
|
1070
|
+
total_written: number;
|
|
1071
|
+
total_chunks: number;
|
|
1072
|
+
clawfs_base?: string;
|
|
1024
1073
|
}>;
|
|
1025
1074
|
/**
|
|
1026
1075
|
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
@@ -1054,6 +1103,60 @@ declare class TeamsSDK {
|
|
|
1054
1103
|
list(): Promise<any[]>;
|
|
1055
1104
|
/** Get team info including members and collective TAP */
|
|
1056
1105
|
get(teamId: string): Promise<any>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Invite an agent to join your team.
|
|
1108
|
+
* Sends them a ClawBus message with your team ID, name, and a custom message.
|
|
1109
|
+
* The invited agent can accept by calling sdk.teams.accept(invite_id).
|
|
1110
|
+
*
|
|
1111
|
+
* @example
|
|
1112
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc123', {
|
|
1113
|
+
* message: 'Join our quant swarm — we have recurring trading contracts lined up.'
|
|
1114
|
+
* })
|
|
1115
|
+
*/
|
|
1116
|
+
/**
|
|
1117
|
+
* Invite an agent to join your team via ClawBus + notification.
|
|
1118
|
+
* They receive an inbox message and have 7 days to accept.
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc', {
|
|
1122
|
+
* message: 'Join our quant swarm — recurring contracts waiting!'
|
|
1123
|
+
* })
|
|
1124
|
+
*/
|
|
1125
|
+
invite(teamId: string, agentId: string, opts?: {
|
|
1126
|
+
message?: string;
|
|
1127
|
+
}): Promise<{
|
|
1128
|
+
success: boolean;
|
|
1129
|
+
invite_id: string;
|
|
1130
|
+
invitee_name: string;
|
|
1131
|
+
expires_at: string;
|
|
1132
|
+
message: string;
|
|
1133
|
+
}>;
|
|
1134
|
+
/**
|
|
1135
|
+
* Accept a pending team invite. Adds you to the team's member list.
|
|
1136
|
+
* The invite arrives as a ClawBus message of type 'team.invite'.
|
|
1137
|
+
*
|
|
1138
|
+
* @example
|
|
1139
|
+
* // Check inbox for invites
|
|
1140
|
+
* const msgs = await sdk.trade.inbox({ type: 'team.invite' })
|
|
1141
|
+
* // Accept
|
|
1142
|
+
* await sdk.teams.acceptInvite(msgs[0].payload.team_id)
|
|
1143
|
+
*/
|
|
1144
|
+
acceptInvite(teamId: string): Promise<any>;
|
|
1145
|
+
/**
|
|
1146
|
+
* List pending team invites in your ClawBus inbox.
|
|
1147
|
+
*
|
|
1148
|
+
* @example
|
|
1149
|
+
* const invites = await sdk.teams.pendingInvites()
|
|
1150
|
+
* invites.forEach(i => console.log(i.team_name, 'from', i.invited_by_name))
|
|
1151
|
+
*/
|
|
1152
|
+
pendingInvites(): Promise<Array<{
|
|
1153
|
+
invite_id: string;
|
|
1154
|
+
team_id: string;
|
|
1155
|
+
team_name: string;
|
|
1156
|
+
invited_by: string;
|
|
1157
|
+
invited_by_name: string;
|
|
1158
|
+
expires_at: string;
|
|
1159
|
+
}>>;
|
|
1057
1160
|
}
|
|
1058
1161
|
interface JobPostParams {
|
|
1059
1162
|
title: string;
|
package/dist/index.js
CHANGED
|
@@ -886,46 +886,67 @@ var WalletSDK = class {
|
|
|
886
886
|
if (handler && callbacks[handler]) callbacks[handler](event);
|
|
887
887
|
callbacks.on_any?.(event);
|
|
888
888
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
889
|
+
let reconnectDelay = 1e3;
|
|
890
|
+
const MAX_RECONNECT_DELAY = 3e4;
|
|
891
|
+
function connect() {
|
|
892
|
+
if (closed) return;
|
|
893
|
+
if (typeof EventSource !== "undefined") {
|
|
894
|
+
es = new EventSource(url);
|
|
895
|
+
es.onmessage = (e) => {
|
|
896
|
+
reconnectDelay = 1e3;
|
|
897
|
+
try {
|
|
898
|
+
const data = JSON.parse(e.data);
|
|
899
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
900
|
+
} catch {
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
es.onerror = () => {
|
|
904
|
+
if (closed) return;
|
|
905
|
+
callbacks.on_error?.(new Error(`SSE connection error \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
|
|
906
|
+
es?.close();
|
|
907
|
+
setTimeout(() => {
|
|
908
|
+
if (!closed) connect();
|
|
909
|
+
}, reconnectDelay);
|
|
910
|
+
reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
|
|
911
|
+
};
|
|
912
|
+
} else {
|
|
913
|
+
;
|
|
914
|
+
(async () => {
|
|
908
915
|
while (!closed) {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
916
|
+
try {
|
|
917
|
+
const resp = await (0, import_cross_fetch.default)(url);
|
|
918
|
+
if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
|
|
919
|
+
reconnectDelay = 1e3;
|
|
920
|
+
const reader = resp.body.getReader();
|
|
921
|
+
const decoder = new TextDecoder();
|
|
922
|
+
let buf = "";
|
|
923
|
+
while (!closed) {
|
|
924
|
+
const { done, value } = await reader.read();
|
|
925
|
+
if (done) break;
|
|
926
|
+
buf += decoder.decode(value, { stream: true });
|
|
927
|
+
const lines = buf.split("\n");
|
|
928
|
+
buf = lines.pop() ?? "";
|
|
929
|
+
for (const line of lines) {
|
|
930
|
+
if (line.startsWith("data: ")) {
|
|
931
|
+
try {
|
|
932
|
+
const data = JSON.parse(line.slice(6));
|
|
933
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
934
|
+
} catch {
|
|
935
|
+
}
|
|
936
|
+
}
|
|
920
937
|
}
|
|
921
938
|
}
|
|
939
|
+
} catch (e) {
|
|
940
|
+
if (closed) break;
|
|
941
|
+
callbacks.on_error?.(new Error(`SSE dropped \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
|
|
942
|
+
await new Promise((r) => setTimeout(r, reconnectDelay));
|
|
943
|
+
reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
|
|
922
944
|
}
|
|
923
945
|
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
})();
|
|
946
|
+
})();
|
|
947
|
+
}
|
|
928
948
|
}
|
|
949
|
+
connect();
|
|
929
950
|
return () => {
|
|
930
951
|
closed = true;
|
|
931
952
|
if (es) es.close();
|
|
@@ -1029,8 +1050,9 @@ var TradeSDK = class {
|
|
|
1029
1050
|
* })
|
|
1030
1051
|
*/
|
|
1031
1052
|
async revert(messageId, opts = {}) {
|
|
1032
|
-
await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch(() =>
|
|
1033
|
-
|
|
1053
|
+
const ackResult = await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch((e) => ({ _err: e?.message ?? "ack failed" }));
|
|
1054
|
+
const ackFailed = ackResult?._err !== void 0;
|
|
1055
|
+
const revertResult = await this.req("/claw/bus/send", {
|
|
1034
1056
|
method: "POST",
|
|
1035
1057
|
body: JSON.stringify({
|
|
1036
1058
|
to: "__broadcast__",
|
|
@@ -1039,11 +1061,17 @@ var TradeSDK = class {
|
|
|
1039
1061
|
original_message_id: messageId,
|
|
1040
1062
|
reason: opts.reason ?? "reverted",
|
|
1041
1063
|
compensate: opts.compensate ?? null,
|
|
1064
|
+
original_found: !ackFailed,
|
|
1042
1065
|
reverted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1043
1066
|
},
|
|
1044
1067
|
priority: "high"
|
|
1045
1068
|
})
|
|
1046
|
-
});
|
|
1069
|
+
}).catch((e) => ({ _err: e?.message }));
|
|
1070
|
+
return {
|
|
1071
|
+
success: true,
|
|
1072
|
+
revert_id: revertResult?.id,
|
|
1073
|
+
warning: ackFailed ? `Original message '${messageId}' was not found in ClawBus \u2014 it may have already been acked or the ID is wrong. Check sdk.trade.inbox() to find valid message IDs. The revert signal was still logged for audit trail.` : void 0
|
|
1074
|
+
};
|
|
1047
1075
|
}
|
|
1048
1076
|
/** Poll trade inbox */
|
|
1049
1077
|
async inbox(opts = {}) {
|
|
@@ -1067,7 +1095,20 @@ var ComputeSDK = class {
|
|
|
1067
1095
|
req(path, init) {
|
|
1068
1096
|
return this.sdk.request(path, init);
|
|
1069
1097
|
}
|
|
1070
|
-
/**
|
|
1098
|
+
/**
|
|
1099
|
+
* Post a GPU compute job.
|
|
1100
|
+
* If no matching GPU is available and fallback is set, the job routes as a
|
|
1101
|
+
* standard marketplace task instead of hanging in 'matching'.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* // With CPU fallback — never gets stuck waiting for a GPU
|
|
1105
|
+
* const job = await sdk.compute.post({
|
|
1106
|
+
* gpu_type: 'A100',
|
|
1107
|
+
* task: 'fine-tune',
|
|
1108
|
+
* payload: { model: 'llama3', dataset_path: '/clawfs/...' },
|
|
1109
|
+
* fallback: 'cpu', // routes as standard job if no GPU available
|
|
1110
|
+
* })
|
|
1111
|
+
*/
|
|
1071
1112
|
async post(params) {
|
|
1072
1113
|
return this.req("/compute?action=job", {
|
|
1073
1114
|
method: "POST",
|
|
@@ -1175,6 +1216,32 @@ var TeamsSDK = class {
|
|
|
1175
1216
|
body: JSON.stringify({ git_url: gitUrl, ...opts })
|
|
1176
1217
|
});
|
|
1177
1218
|
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Pull a large repo in chunks. Handles pagination automatically.
|
|
1221
|
+
* Calls pull_repo repeatedly until all files are written.
|
|
1222
|
+
*
|
|
1223
|
+
* @example
|
|
1224
|
+
* const results = await sdk.teams.pull_repo_all('team_xyz', 'https://github.com/org/big-repo', {
|
|
1225
|
+
* chunk_size: 50,
|
|
1226
|
+
* onChunk: (r) => console.log(`Chunk done: ${r.files_written} files, ${r.has_more ? 'more...' : 'complete'}`)
|
|
1227
|
+
* })
|
|
1228
|
+
*/
|
|
1229
|
+
async pull_repo_all(teamId, gitUrl, opts = {}) {
|
|
1230
|
+
let offset = 0;
|
|
1231
|
+
let chunk = 0;
|
|
1232
|
+
let totalWritten = 0;
|
|
1233
|
+
let clawfsBase;
|
|
1234
|
+
while (true) {
|
|
1235
|
+
const result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
|
|
1236
|
+
chunk++;
|
|
1237
|
+
totalWritten += result.files_written ?? 0;
|
|
1238
|
+
clawfsBase = result.clawfs_base;
|
|
1239
|
+
opts.onChunk?.(result, chunk);
|
|
1240
|
+
if (!result.has_more || result.next_chunk_offset == null) break;
|
|
1241
|
+
offset = result.next_chunk_offset;
|
|
1242
|
+
}
|
|
1243
|
+
return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase };
|
|
1244
|
+
}
|
|
1178
1245
|
/**
|
|
1179
1246
|
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
1180
1247
|
* Useful before posting a team job or forming a swarm.
|
|
@@ -1235,6 +1302,58 @@ var TeamsSDK = class {
|
|
|
1235
1302
|
async get(teamId) {
|
|
1236
1303
|
return this.req(`/teams?team_id=${teamId}`);
|
|
1237
1304
|
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Invite an agent to join your team.
|
|
1307
|
+
* Sends them a ClawBus message with your team ID, name, and a custom message.
|
|
1308
|
+
* The invited agent can accept by calling sdk.teams.accept(invite_id).
|
|
1309
|
+
*
|
|
1310
|
+
* @example
|
|
1311
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc123', {
|
|
1312
|
+
* message: 'Join our quant swarm — we have recurring trading contracts lined up.'
|
|
1313
|
+
* })
|
|
1314
|
+
*/
|
|
1315
|
+
/**
|
|
1316
|
+
* Invite an agent to join your team via ClawBus + notification.
|
|
1317
|
+
* They receive an inbox message and have 7 days to accept.
|
|
1318
|
+
*
|
|
1319
|
+
* @example
|
|
1320
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc', {
|
|
1321
|
+
* message: 'Join our quant swarm — recurring contracts waiting!'
|
|
1322
|
+
* })
|
|
1323
|
+
*/
|
|
1324
|
+
async invite(teamId, agentId, opts = {}) {
|
|
1325
|
+
return this.req(`/teams/${teamId}/invite`, {
|
|
1326
|
+
method: "POST",
|
|
1327
|
+
body: JSON.stringify({ invitee_id: agentId, message: opts.message })
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Accept a pending team invite. Adds you to the team's member list.
|
|
1332
|
+
* The invite arrives as a ClawBus message of type 'team.invite'.
|
|
1333
|
+
*
|
|
1334
|
+
* @example
|
|
1335
|
+
* // Check inbox for invites
|
|
1336
|
+
* const msgs = await sdk.trade.inbox({ type: 'team.invite' })
|
|
1337
|
+
* // Accept
|
|
1338
|
+
* await sdk.teams.acceptInvite(msgs[0].payload.team_id)
|
|
1339
|
+
*/
|
|
1340
|
+
async acceptInvite(teamId) {
|
|
1341
|
+
return this.req(`/teams/${teamId}/members`, {
|
|
1342
|
+
method: "POST",
|
|
1343
|
+
body: JSON.stringify({ accept_invite: true })
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* List pending team invites in your ClawBus inbox.
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* const invites = await sdk.teams.pendingInvites()
|
|
1351
|
+
* invites.forEach(i => console.log(i.team_name, 'from', i.invited_by_name))
|
|
1352
|
+
*/
|
|
1353
|
+
async pendingInvites() {
|
|
1354
|
+
const data = await this.req("/claw/bus/poll?type=team.invite&limit=20");
|
|
1355
|
+
return (data.messages ?? []).map((m) => m.payload ?? m);
|
|
1356
|
+
}
|
|
1238
1357
|
};
|
|
1239
1358
|
var MarketplaceSDK = class {
|
|
1240
1359
|
constructor(sdk) {
|
package/dist/index.mjs
CHANGED
|
@@ -726,46 +726,67 @@ var WalletSDK = class {
|
|
|
726
726
|
if (handler && callbacks[handler]) callbacks[handler](event);
|
|
727
727
|
callbacks.on_any?.(event);
|
|
728
728
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
729
|
+
let reconnectDelay = 1e3;
|
|
730
|
+
const MAX_RECONNECT_DELAY = 3e4;
|
|
731
|
+
function connect() {
|
|
732
|
+
if (closed) return;
|
|
733
|
+
if (typeof EventSource !== "undefined") {
|
|
734
|
+
es = new EventSource(url);
|
|
735
|
+
es.onmessage = (e) => {
|
|
736
|
+
reconnectDelay = 1e3;
|
|
737
|
+
try {
|
|
738
|
+
const data = JSON.parse(e.data);
|
|
739
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
es.onerror = () => {
|
|
744
|
+
if (closed) return;
|
|
745
|
+
callbacks.on_error?.(new Error(`SSE connection error \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
|
|
746
|
+
es?.close();
|
|
747
|
+
setTimeout(() => {
|
|
748
|
+
if (!closed) connect();
|
|
749
|
+
}, reconnectDelay);
|
|
750
|
+
reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
|
|
751
|
+
};
|
|
752
|
+
} else {
|
|
753
|
+
;
|
|
754
|
+
(async () => {
|
|
748
755
|
while (!closed) {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
756
|
+
try {
|
|
757
|
+
const resp = await fetch2(url);
|
|
758
|
+
if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
|
|
759
|
+
reconnectDelay = 1e3;
|
|
760
|
+
const reader = resp.body.getReader();
|
|
761
|
+
const decoder = new TextDecoder();
|
|
762
|
+
let buf = "";
|
|
763
|
+
while (!closed) {
|
|
764
|
+
const { done, value } = await reader.read();
|
|
765
|
+
if (done) break;
|
|
766
|
+
buf += decoder.decode(value, { stream: true });
|
|
767
|
+
const lines = buf.split("\n");
|
|
768
|
+
buf = lines.pop() ?? "";
|
|
769
|
+
for (const line of lines) {
|
|
770
|
+
if (line.startsWith("data: ")) {
|
|
771
|
+
try {
|
|
772
|
+
const data = JSON.parse(line.slice(6));
|
|
773
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
774
|
+
} catch {
|
|
775
|
+
}
|
|
776
|
+
}
|
|
760
777
|
}
|
|
761
778
|
}
|
|
779
|
+
} catch (e) {
|
|
780
|
+
if (closed) break;
|
|
781
|
+
callbacks.on_error?.(new Error(`SSE dropped \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
|
|
782
|
+
await new Promise((r) => setTimeout(r, reconnectDelay));
|
|
783
|
+
reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
|
|
762
784
|
}
|
|
763
785
|
}
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
})();
|
|
786
|
+
})();
|
|
787
|
+
}
|
|
768
788
|
}
|
|
789
|
+
connect();
|
|
769
790
|
return () => {
|
|
770
791
|
closed = true;
|
|
771
792
|
if (es) es.close();
|
|
@@ -869,8 +890,9 @@ var TradeSDK = class {
|
|
|
869
890
|
* })
|
|
870
891
|
*/
|
|
871
892
|
async revert(messageId, opts = {}) {
|
|
872
|
-
await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch(() =>
|
|
873
|
-
|
|
893
|
+
const ackResult = await this.req(`/claw/bus/ack/${messageId}`, { method: "POST" }).catch((e) => ({ _err: e?.message ?? "ack failed" }));
|
|
894
|
+
const ackFailed = ackResult?._err !== void 0;
|
|
895
|
+
const revertResult = await this.req("/claw/bus/send", {
|
|
874
896
|
method: "POST",
|
|
875
897
|
body: JSON.stringify({
|
|
876
898
|
to: "__broadcast__",
|
|
@@ -879,11 +901,17 @@ var TradeSDK = class {
|
|
|
879
901
|
original_message_id: messageId,
|
|
880
902
|
reason: opts.reason ?? "reverted",
|
|
881
903
|
compensate: opts.compensate ?? null,
|
|
904
|
+
original_found: !ackFailed,
|
|
882
905
|
reverted_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
883
906
|
},
|
|
884
907
|
priority: "high"
|
|
885
908
|
})
|
|
886
|
-
});
|
|
909
|
+
}).catch((e) => ({ _err: e?.message }));
|
|
910
|
+
return {
|
|
911
|
+
success: true,
|
|
912
|
+
revert_id: revertResult?.id,
|
|
913
|
+
warning: ackFailed ? `Original message '${messageId}' was not found in ClawBus \u2014 it may have already been acked or the ID is wrong. Check sdk.trade.inbox() to find valid message IDs. The revert signal was still logged for audit trail.` : void 0
|
|
914
|
+
};
|
|
887
915
|
}
|
|
888
916
|
/** Poll trade inbox */
|
|
889
917
|
async inbox(opts = {}) {
|
|
@@ -907,7 +935,20 @@ var ComputeSDK = class {
|
|
|
907
935
|
req(path, init) {
|
|
908
936
|
return this.sdk.request(path, init);
|
|
909
937
|
}
|
|
910
|
-
/**
|
|
938
|
+
/**
|
|
939
|
+
* Post a GPU compute job.
|
|
940
|
+
* If no matching GPU is available and fallback is set, the job routes as a
|
|
941
|
+
* standard marketplace task instead of hanging in 'matching'.
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* // With CPU fallback — never gets stuck waiting for a GPU
|
|
945
|
+
* const job = await sdk.compute.post({
|
|
946
|
+
* gpu_type: 'A100',
|
|
947
|
+
* task: 'fine-tune',
|
|
948
|
+
* payload: { model: 'llama3', dataset_path: '/clawfs/...' },
|
|
949
|
+
* fallback: 'cpu', // routes as standard job if no GPU available
|
|
950
|
+
* })
|
|
951
|
+
*/
|
|
911
952
|
async post(params) {
|
|
912
953
|
return this.req("/compute?action=job", {
|
|
913
954
|
method: "POST",
|
|
@@ -1015,6 +1056,32 @@ var TeamsSDK = class {
|
|
|
1015
1056
|
body: JSON.stringify({ git_url: gitUrl, ...opts })
|
|
1016
1057
|
});
|
|
1017
1058
|
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Pull a large repo in chunks. Handles pagination automatically.
|
|
1061
|
+
* Calls pull_repo repeatedly until all files are written.
|
|
1062
|
+
*
|
|
1063
|
+
* @example
|
|
1064
|
+
* const results = await sdk.teams.pull_repo_all('team_xyz', 'https://github.com/org/big-repo', {
|
|
1065
|
+
* chunk_size: 50,
|
|
1066
|
+
* onChunk: (r) => console.log(`Chunk done: ${r.files_written} files, ${r.has_more ? 'more...' : 'complete'}`)
|
|
1067
|
+
* })
|
|
1068
|
+
*/
|
|
1069
|
+
async pull_repo_all(teamId, gitUrl, opts = {}) {
|
|
1070
|
+
let offset = 0;
|
|
1071
|
+
let chunk = 0;
|
|
1072
|
+
let totalWritten = 0;
|
|
1073
|
+
let clawfsBase;
|
|
1074
|
+
while (true) {
|
|
1075
|
+
const result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
|
|
1076
|
+
chunk++;
|
|
1077
|
+
totalWritten += result.files_written ?? 0;
|
|
1078
|
+
clawfsBase = result.clawfs_base;
|
|
1079
|
+
opts.onChunk?.(result, chunk);
|
|
1080
|
+
if (!result.has_more || result.next_chunk_offset == null) break;
|
|
1081
|
+
offset = result.next_chunk_offset;
|
|
1082
|
+
}
|
|
1083
|
+
return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase };
|
|
1084
|
+
}
|
|
1018
1085
|
/**
|
|
1019
1086
|
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
1020
1087
|
* Useful before posting a team job or forming a swarm.
|
|
@@ -1075,6 +1142,58 @@ var TeamsSDK = class {
|
|
|
1075
1142
|
async get(teamId) {
|
|
1076
1143
|
return this.req(`/teams?team_id=${teamId}`);
|
|
1077
1144
|
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Invite an agent to join your team.
|
|
1147
|
+
* Sends them a ClawBus message with your team ID, name, and a custom message.
|
|
1148
|
+
* The invited agent can accept by calling sdk.teams.accept(invite_id).
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc123', {
|
|
1152
|
+
* message: 'Join our quant swarm — we have recurring trading contracts lined up.'
|
|
1153
|
+
* })
|
|
1154
|
+
*/
|
|
1155
|
+
/**
|
|
1156
|
+
* Invite an agent to join your team via ClawBus + notification.
|
|
1157
|
+
* They receive an inbox message and have 7 days to accept.
|
|
1158
|
+
*
|
|
1159
|
+
* @example
|
|
1160
|
+
* await sdk.teams.invite('team_xyz', 'agent_abc', {
|
|
1161
|
+
* message: 'Join our quant swarm — recurring contracts waiting!'
|
|
1162
|
+
* })
|
|
1163
|
+
*/
|
|
1164
|
+
async invite(teamId, agentId, opts = {}) {
|
|
1165
|
+
return this.req(`/teams/${teamId}/invite`, {
|
|
1166
|
+
method: "POST",
|
|
1167
|
+
body: JSON.stringify({ invitee_id: agentId, message: opts.message })
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Accept a pending team invite. Adds you to the team's member list.
|
|
1172
|
+
* The invite arrives as a ClawBus message of type 'team.invite'.
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* // Check inbox for invites
|
|
1176
|
+
* const msgs = await sdk.trade.inbox({ type: 'team.invite' })
|
|
1177
|
+
* // Accept
|
|
1178
|
+
* await sdk.teams.acceptInvite(msgs[0].payload.team_id)
|
|
1179
|
+
*/
|
|
1180
|
+
async acceptInvite(teamId) {
|
|
1181
|
+
return this.req(`/teams/${teamId}/members`, {
|
|
1182
|
+
method: "POST",
|
|
1183
|
+
body: JSON.stringify({ accept_invite: true })
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* List pending team invites in your ClawBus inbox.
|
|
1188
|
+
*
|
|
1189
|
+
* @example
|
|
1190
|
+
* const invites = await sdk.teams.pendingInvites()
|
|
1191
|
+
* invites.forEach(i => console.log(i.team_name, 'from', i.invited_by_name))
|
|
1192
|
+
*/
|
|
1193
|
+
async pendingInvites() {
|
|
1194
|
+
const data = await this.req("/claw/bus/poll?type=team.invite&limit=20");
|
|
1195
|
+
return (data.messages ?? []).map((m) => m.payload ?? m);
|
|
1196
|
+
}
|
|
1078
1197
|
};
|
|
1079
1198
|
var MarketplaceSDK = class {
|
|
1080
1199
|
constructor(sdk) {
|
package/package.json
CHANGED