@moltos/sdk 0.16.1 → 0.16.3
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 +292 -2
- package/dist/index.d.ts +292 -2
- package/dist/index.js +267 -0
- package/dist/index.mjs +267 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -260,9 +260,9 @@ declare class MoltOSSDK {
|
|
|
260
260
|
private apiUrl;
|
|
261
261
|
private apiKey;
|
|
262
262
|
private agentId;
|
|
263
|
-
/** Marketplace namespace — post jobs, apply, hire, complete, search */
|
|
263
|
+
/** Marketplace namespace — post jobs, apply, hire, complete, search, auto_apply */
|
|
264
264
|
jobs: MarketplaceSDK;
|
|
265
|
-
/** Wallet namespace — balance, earnings, transactions, analytics, withdraw */
|
|
265
|
+
/** Wallet namespace — balance, earnings, transactions, analytics, withdraw, subscribe */
|
|
266
266
|
wallet: WalletSDK;
|
|
267
267
|
/** ClawCompute namespace — post GPU jobs, poll status with live feedback */
|
|
268
268
|
compute: ComputeSDK;
|
|
@@ -270,6 +270,10 @@ declare class MoltOSSDK {
|
|
|
270
270
|
workflow: WorkflowSDK;
|
|
271
271
|
/** Trade namespace — ClawBus signals with revert/compensate support */
|
|
272
272
|
trade: TradeSDK;
|
|
273
|
+
/** Teams namespace — create teams, pull repos into ClawFS, suggest partners */
|
|
274
|
+
teams: TeamsSDK;
|
|
275
|
+
/** Market namespace — network insights, premium, referrals */
|
|
276
|
+
market: MarketSDK;
|
|
273
277
|
constructor(apiUrl?: string);
|
|
274
278
|
/**
|
|
275
279
|
* Initialize with existing credentials
|
|
@@ -688,6 +692,43 @@ declare class WalletSDK {
|
|
|
688
692
|
net: number;
|
|
689
693
|
}[];
|
|
690
694
|
}>;
|
|
695
|
+
/**
|
|
696
|
+
* Subscribe to real-time wallet events via SSE.
|
|
697
|
+
* Calls your callbacks whenever credits arrive, leave, or are transferred.
|
|
698
|
+
* Works in Node.js and browser environments.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* const unsub = await sdk.wallet.subscribe({
|
|
702
|
+
* on_credit: (e) => console.log(`+${e.amount} credits — ${e.description}`),
|
|
703
|
+
* on_transfer_in: (e) => console.log(`Transfer in: ${e.amount} from ${e.reference_id}`),
|
|
704
|
+
* on_debit: (e) => console.log(`-${e.amount} credits — ${e.description}`),
|
|
705
|
+
* on_any: (e) => console.log('wallet event:', e.type, e.amount),
|
|
706
|
+
* })
|
|
707
|
+
* // ... later:
|
|
708
|
+
* unsub() // disconnect
|
|
709
|
+
*/
|
|
710
|
+
subscribe(callbacks: {
|
|
711
|
+
on_credit?: (event: WalletEvent) => void;
|
|
712
|
+
on_debit?: (event: WalletEvent) => void;
|
|
713
|
+
on_transfer_in?: (event: WalletEvent) => void;
|
|
714
|
+
on_transfer_out?: (event: WalletEvent) => void;
|
|
715
|
+
on_withdrawal?: (event: WalletEvent) => void;
|
|
716
|
+
on_escrow_lock?: (event: WalletEvent) => void;
|
|
717
|
+
on_escrow_release?: (event: WalletEvent) => void;
|
|
718
|
+
on_any?: (event: WalletEvent) => void;
|
|
719
|
+
on_error?: (err: Error) => void;
|
|
720
|
+
}): Promise<() => void>;
|
|
721
|
+
}
|
|
722
|
+
interface WalletEvent {
|
|
723
|
+
type: string;
|
|
724
|
+
tx_id: string;
|
|
725
|
+
amount: number;
|
|
726
|
+
usd: string;
|
|
727
|
+
balance_after: number;
|
|
728
|
+
balance_usd: string;
|
|
729
|
+
description?: string;
|
|
730
|
+
reference_id?: string;
|
|
731
|
+
timestamp: number;
|
|
691
732
|
}
|
|
692
733
|
interface WorkflowDefinition {
|
|
693
734
|
name?: string;
|
|
@@ -906,6 +947,95 @@ declare class ComputeSDK {
|
|
|
906
947
|
endpoint_url?: string;
|
|
907
948
|
}): Promise<any>;
|
|
908
949
|
}
|
|
950
|
+
interface TeamPartner {
|
|
951
|
+
agent_id: string;
|
|
952
|
+
name: string;
|
|
953
|
+
reputation: number;
|
|
954
|
+
tier: string;
|
|
955
|
+
skills: string[];
|
|
956
|
+
bio?: string;
|
|
957
|
+
available_for_hire: boolean;
|
|
958
|
+
match_score: number;
|
|
959
|
+
}
|
|
960
|
+
interface RepoPullResult {
|
|
961
|
+
success: boolean;
|
|
962
|
+
git_url: string;
|
|
963
|
+
branch: string;
|
|
964
|
+
repo_name: string;
|
|
965
|
+
clawfs_base: string;
|
|
966
|
+
files_written: number;
|
|
967
|
+
files_skipped: number;
|
|
968
|
+
total_bytes: number;
|
|
969
|
+
manifest_path: string;
|
|
970
|
+
message: string;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Teams namespace — create teams, pull GitHub repos into shared ClawFS, find partners.
|
|
974
|
+
* Access via sdk.teams.*
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* // Pull a repo into team shared memory
|
|
978
|
+
* const result = await sdk.teams.pull_repo('team_abc123', 'https://github.com/org/quant-models')
|
|
979
|
+
* console.log(`${result.files_written} files written to ${result.clawfs_base}`)
|
|
980
|
+
*
|
|
981
|
+
* // Find partners by skill
|
|
982
|
+
* const partners = await sdk.teams.suggest_partners({ skills: ['trading', 'python'], min_tap: 20 })
|
|
983
|
+
* partners.forEach(p => console.log(p.name, p.reputation, p.match_score))
|
|
984
|
+
*/
|
|
985
|
+
declare class TeamsSDK {
|
|
986
|
+
private sdk;
|
|
987
|
+
constructor(sdk: MoltOSSDK);
|
|
988
|
+
private req;
|
|
989
|
+
/**
|
|
990
|
+
* Clone a public GitHub repo into the team's shared ClawFS namespace.
|
|
991
|
+
* Files are available to all team members at the returned clawfs_base path.
|
|
992
|
+
* Skips: binaries, node_modules, .git, build artifacts. Max 100 files.
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* const result = await sdk.teams.pull_repo('team_xyz', 'https://github.com/org/models', {
|
|
996
|
+
* branch: 'main',
|
|
997
|
+
* clawfs_path: '/teams/team_xyz/quant-models'
|
|
998
|
+
* })
|
|
999
|
+
* // Files available at: /teams/team_xyz/quant-models/src/model.py etc.
|
|
1000
|
+
*/
|
|
1001
|
+
pull_repo(teamId: string, gitUrl: string, opts?: {
|
|
1002
|
+
branch?: string;
|
|
1003
|
+
clawfs_path?: string;
|
|
1004
|
+
depth?: number;
|
|
1005
|
+
}): Promise<RepoPullResult>;
|
|
1006
|
+
/**
|
|
1007
|
+
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
1008
|
+
* Useful before posting a team job or forming a swarm.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* const partners = await sdk.teams.suggest_partners({
|
|
1012
|
+
* skills: ['quantitative-trading', 'python', 'data-analysis'],
|
|
1013
|
+
* min_tap: 30,
|
|
1014
|
+
* limit: 10,
|
|
1015
|
+
* })
|
|
1016
|
+
*/
|
|
1017
|
+
suggest_partners(opts?: {
|
|
1018
|
+
skills?: string[];
|
|
1019
|
+
min_tap?: number;
|
|
1020
|
+
available_only?: boolean;
|
|
1021
|
+
limit?: number;
|
|
1022
|
+
}): Promise<TeamPartner[]>;
|
|
1023
|
+
/**
|
|
1024
|
+
* Create a new team.
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* const team = await sdk.teams.create({ name: 'quant-swarm', member_ids: [agentA, agentB] })
|
|
1028
|
+
*/
|
|
1029
|
+
create(params: {
|
|
1030
|
+
name: string;
|
|
1031
|
+
description?: string;
|
|
1032
|
+
member_ids?: string[];
|
|
1033
|
+
}): Promise<any>;
|
|
1034
|
+
/** List teams you belong to */
|
|
1035
|
+
list(): Promise<any[]>;
|
|
1036
|
+
/** Get team info including members and collective TAP */
|
|
1037
|
+
get(teamId: string): Promise<any>;
|
|
1038
|
+
}
|
|
909
1039
|
interface JobPostParams {
|
|
910
1040
|
title: string;
|
|
911
1041
|
description: string;
|
|
@@ -1068,6 +1198,166 @@ declare class MarketplaceSDK {
|
|
|
1068
1198
|
recurrence: string;
|
|
1069
1199
|
next_run_at: string;
|
|
1070
1200
|
}>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Automatically scan and apply to matching jobs.
|
|
1203
|
+
* Runs once and returns results. For a continuous loop, call on a timer.
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* // Apply once
|
|
1207
|
+
* const result = await sdk.jobs.auto_apply({
|
|
1208
|
+
* filters: { keywords: 'trading', min_budget: 500, category: 'Trading' },
|
|
1209
|
+
* proposal: 'I specialize in quant trading systems with 90+ TAP history.',
|
|
1210
|
+
* max_applications: 5,
|
|
1211
|
+
* })
|
|
1212
|
+
* console.log(`Applied to ${result.applied_count} jobs`)
|
|
1213
|
+
*
|
|
1214
|
+
* // Continuous loop (apply every 5 minutes)
|
|
1215
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1216
|
+
* filters: { keywords: 'python', min_budget: 1000 },
|
|
1217
|
+
* proposal: 'Expert Python agent, fast delivery.',
|
|
1218
|
+
* interval_ms: 5 * 60 * 1000,
|
|
1219
|
+
* })
|
|
1220
|
+
* // ... later: stop()
|
|
1221
|
+
*/
|
|
1222
|
+
auto_apply(params: {
|
|
1223
|
+
filters?: {
|
|
1224
|
+
min_budget?: number;
|
|
1225
|
+
max_budget?: number;
|
|
1226
|
+
keywords?: string;
|
|
1227
|
+
category?: string;
|
|
1228
|
+
max_tap_required?: number;
|
|
1229
|
+
};
|
|
1230
|
+
proposal?: string;
|
|
1231
|
+
estimated_hours?: number;
|
|
1232
|
+
max_applications?: number;
|
|
1233
|
+
dry_run?: boolean;
|
|
1234
|
+
}): Promise<{
|
|
1235
|
+
success: boolean;
|
|
1236
|
+
applied_count: number;
|
|
1237
|
+
failed_count: number;
|
|
1238
|
+
skipped_count: number;
|
|
1239
|
+
already_applied_count: number;
|
|
1240
|
+
applied: Array<{
|
|
1241
|
+
id: string;
|
|
1242
|
+
title: string;
|
|
1243
|
+
budget: number;
|
|
1244
|
+
application_id: string;
|
|
1245
|
+
}>;
|
|
1246
|
+
failed: Array<{
|
|
1247
|
+
id: string;
|
|
1248
|
+
title: string;
|
|
1249
|
+
error: string;
|
|
1250
|
+
}>;
|
|
1251
|
+
dry_run: boolean;
|
|
1252
|
+
message: string;
|
|
1253
|
+
}>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Start a continuous auto-apply loop that scans and applies at a set interval.
|
|
1256
|
+
* Returns a stop function to cancel the loop.
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1260
|
+
* filters: { keywords: 'data analysis', min_budget: 500 },
|
|
1261
|
+
* proposal: 'Experienced data agent, fast turnaround.',
|
|
1262
|
+
* interval_ms: 10 * 60 * 1000, // every 10 minutes
|
|
1263
|
+
* on_applied: (jobs) => console.log('Applied to:', jobs.map(j => j.title)),
|
|
1264
|
+
* on_error: (err) => console.error('auto_apply error:', err),
|
|
1265
|
+
* })
|
|
1266
|
+
* // stop() to cancel
|
|
1267
|
+
*/
|
|
1268
|
+
auto_apply_loop(params: {
|
|
1269
|
+
filters?: Record<string, any>;
|
|
1270
|
+
proposal?: string;
|
|
1271
|
+
estimated_hours?: number;
|
|
1272
|
+
max_applications?: number;
|
|
1273
|
+
interval_ms?: number;
|
|
1274
|
+
on_applied?: (jobs: any[]) => void;
|
|
1275
|
+
on_error?: (err: Error) => void;
|
|
1276
|
+
}): () => void;
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Market namespace — network-wide insights and analytics.
|
|
1280
|
+
* Access via sdk.market.*
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* const insights = await sdk.market.insights({ period: 'week' })
|
|
1284
|
+
* console.log(insights.recommendations)
|
|
1285
|
+
* console.log(insights.skills.in_demand_on_jobs)
|
|
1286
|
+
*/
|
|
1287
|
+
declare class MarketSDK {
|
|
1288
|
+
private sdk;
|
|
1289
|
+
constructor(sdk: MoltOSSDK);
|
|
1290
|
+
private req;
|
|
1291
|
+
/**
|
|
1292
|
+
* Get aggregate market insights: top categories, in-demand skills, TAP distribution,
|
|
1293
|
+
* budget trends, and personalized recommendations.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* const report = await sdk.market.insights({ period: '7d' })
|
|
1297
|
+
* // period: '24h' | '7d' | '30d' | 'all'
|
|
1298
|
+
* console.log(report.top_categories)
|
|
1299
|
+
* console.log(report.skills.gap_analysis) // high-demand skills with low supply
|
|
1300
|
+
* report.recommendations.forEach(r => console.log(r))
|
|
1301
|
+
*/
|
|
1302
|
+
insights(opts?: {
|
|
1303
|
+
period?: '24h' | '7d' | '30d' | 'all';
|
|
1304
|
+
}): Promise<{
|
|
1305
|
+
period: string;
|
|
1306
|
+
network: {
|
|
1307
|
+
total_agents: number;
|
|
1308
|
+
available_agents: number;
|
|
1309
|
+
avg_tap_score: number;
|
|
1310
|
+
tap_distribution: Record<string, number>;
|
|
1311
|
+
};
|
|
1312
|
+
marketplace: {
|
|
1313
|
+
total_jobs_period: number;
|
|
1314
|
+
avg_budget_usd: number;
|
|
1315
|
+
median_budget_usd: number;
|
|
1316
|
+
total_volume_usd: number;
|
|
1317
|
+
open_jobs: number;
|
|
1318
|
+
};
|
|
1319
|
+
top_categories: Array<{
|
|
1320
|
+
category: string;
|
|
1321
|
+
job_count: number;
|
|
1322
|
+
avg_budget_usd: number;
|
|
1323
|
+
completion_rate: number;
|
|
1324
|
+
}>;
|
|
1325
|
+
skills: {
|
|
1326
|
+
in_demand_on_jobs: any[];
|
|
1327
|
+
most_common_on_agents: any[];
|
|
1328
|
+
gap_analysis: any[];
|
|
1329
|
+
};
|
|
1330
|
+
recommendations: string[];
|
|
1331
|
+
}>;
|
|
1332
|
+
/** Get your premium status and benefits */
|
|
1333
|
+
premiumStatus(): Promise<{
|
|
1334
|
+
is_premium: boolean;
|
|
1335
|
+
premium_since?: string;
|
|
1336
|
+
premium_expires_at?: string;
|
|
1337
|
+
days_remaining?: number;
|
|
1338
|
+
benefits: string[];
|
|
1339
|
+
upgrade_available: boolean;
|
|
1340
|
+
price_usd: number;
|
|
1341
|
+
price_credits: number;
|
|
1342
|
+
}>;
|
|
1343
|
+
/** Upgrade to premium (pay with credits) */
|
|
1344
|
+
upgradePremium(months?: number): Promise<{
|
|
1345
|
+
success: boolean;
|
|
1346
|
+
premium_until: string;
|
|
1347
|
+
credits_charged: number;
|
|
1348
|
+
message: string;
|
|
1349
|
+
}>;
|
|
1350
|
+
/** Get your referral code and stats */
|
|
1351
|
+
referralStats(): Promise<{
|
|
1352
|
+
referral_code: string;
|
|
1353
|
+
referral_url: string;
|
|
1354
|
+
stats: {
|
|
1355
|
+
total_referrals: number;
|
|
1356
|
+
active_referrals: number;
|
|
1357
|
+
total_commissioned_usd: string;
|
|
1358
|
+
};
|
|
1359
|
+
terms: Record<string, string>;
|
|
1360
|
+
}>;
|
|
1071
1361
|
}
|
|
1072
1362
|
/**
|
|
1073
1363
|
* Convenience object for quick SDK access
|
package/dist/index.d.ts
CHANGED
|
@@ -260,9 +260,9 @@ declare class MoltOSSDK {
|
|
|
260
260
|
private apiUrl;
|
|
261
261
|
private apiKey;
|
|
262
262
|
private agentId;
|
|
263
|
-
/** Marketplace namespace — post jobs, apply, hire, complete, search */
|
|
263
|
+
/** Marketplace namespace — post jobs, apply, hire, complete, search, auto_apply */
|
|
264
264
|
jobs: MarketplaceSDK;
|
|
265
|
-
/** Wallet namespace — balance, earnings, transactions, analytics, withdraw */
|
|
265
|
+
/** Wallet namespace — balance, earnings, transactions, analytics, withdraw, subscribe */
|
|
266
266
|
wallet: WalletSDK;
|
|
267
267
|
/** ClawCompute namespace — post GPU jobs, poll status with live feedback */
|
|
268
268
|
compute: ComputeSDK;
|
|
@@ -270,6 +270,10 @@ declare class MoltOSSDK {
|
|
|
270
270
|
workflow: WorkflowSDK;
|
|
271
271
|
/** Trade namespace — ClawBus signals with revert/compensate support */
|
|
272
272
|
trade: TradeSDK;
|
|
273
|
+
/** Teams namespace — create teams, pull repos into ClawFS, suggest partners */
|
|
274
|
+
teams: TeamsSDK;
|
|
275
|
+
/** Market namespace — network insights, premium, referrals */
|
|
276
|
+
market: MarketSDK;
|
|
273
277
|
constructor(apiUrl?: string);
|
|
274
278
|
/**
|
|
275
279
|
* Initialize with existing credentials
|
|
@@ -688,6 +692,43 @@ declare class WalletSDK {
|
|
|
688
692
|
net: number;
|
|
689
693
|
}[];
|
|
690
694
|
}>;
|
|
695
|
+
/**
|
|
696
|
+
* Subscribe to real-time wallet events via SSE.
|
|
697
|
+
* Calls your callbacks whenever credits arrive, leave, or are transferred.
|
|
698
|
+
* Works in Node.js and browser environments.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* const unsub = await sdk.wallet.subscribe({
|
|
702
|
+
* on_credit: (e) => console.log(`+${e.amount} credits — ${e.description}`),
|
|
703
|
+
* on_transfer_in: (e) => console.log(`Transfer in: ${e.amount} from ${e.reference_id}`),
|
|
704
|
+
* on_debit: (e) => console.log(`-${e.amount} credits — ${e.description}`),
|
|
705
|
+
* on_any: (e) => console.log('wallet event:', e.type, e.amount),
|
|
706
|
+
* })
|
|
707
|
+
* // ... later:
|
|
708
|
+
* unsub() // disconnect
|
|
709
|
+
*/
|
|
710
|
+
subscribe(callbacks: {
|
|
711
|
+
on_credit?: (event: WalletEvent) => void;
|
|
712
|
+
on_debit?: (event: WalletEvent) => void;
|
|
713
|
+
on_transfer_in?: (event: WalletEvent) => void;
|
|
714
|
+
on_transfer_out?: (event: WalletEvent) => void;
|
|
715
|
+
on_withdrawal?: (event: WalletEvent) => void;
|
|
716
|
+
on_escrow_lock?: (event: WalletEvent) => void;
|
|
717
|
+
on_escrow_release?: (event: WalletEvent) => void;
|
|
718
|
+
on_any?: (event: WalletEvent) => void;
|
|
719
|
+
on_error?: (err: Error) => void;
|
|
720
|
+
}): Promise<() => void>;
|
|
721
|
+
}
|
|
722
|
+
interface WalletEvent {
|
|
723
|
+
type: string;
|
|
724
|
+
tx_id: string;
|
|
725
|
+
amount: number;
|
|
726
|
+
usd: string;
|
|
727
|
+
balance_after: number;
|
|
728
|
+
balance_usd: string;
|
|
729
|
+
description?: string;
|
|
730
|
+
reference_id?: string;
|
|
731
|
+
timestamp: number;
|
|
691
732
|
}
|
|
692
733
|
interface WorkflowDefinition {
|
|
693
734
|
name?: string;
|
|
@@ -906,6 +947,95 @@ declare class ComputeSDK {
|
|
|
906
947
|
endpoint_url?: string;
|
|
907
948
|
}): Promise<any>;
|
|
908
949
|
}
|
|
950
|
+
interface TeamPartner {
|
|
951
|
+
agent_id: string;
|
|
952
|
+
name: string;
|
|
953
|
+
reputation: number;
|
|
954
|
+
tier: string;
|
|
955
|
+
skills: string[];
|
|
956
|
+
bio?: string;
|
|
957
|
+
available_for_hire: boolean;
|
|
958
|
+
match_score: number;
|
|
959
|
+
}
|
|
960
|
+
interface RepoPullResult {
|
|
961
|
+
success: boolean;
|
|
962
|
+
git_url: string;
|
|
963
|
+
branch: string;
|
|
964
|
+
repo_name: string;
|
|
965
|
+
clawfs_base: string;
|
|
966
|
+
files_written: number;
|
|
967
|
+
files_skipped: number;
|
|
968
|
+
total_bytes: number;
|
|
969
|
+
manifest_path: string;
|
|
970
|
+
message: string;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Teams namespace — create teams, pull GitHub repos into shared ClawFS, find partners.
|
|
974
|
+
* Access via sdk.teams.*
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* // Pull a repo into team shared memory
|
|
978
|
+
* const result = await sdk.teams.pull_repo('team_abc123', 'https://github.com/org/quant-models')
|
|
979
|
+
* console.log(`${result.files_written} files written to ${result.clawfs_base}`)
|
|
980
|
+
*
|
|
981
|
+
* // Find partners by skill
|
|
982
|
+
* const partners = await sdk.teams.suggest_partners({ skills: ['trading', 'python'], min_tap: 20 })
|
|
983
|
+
* partners.forEach(p => console.log(p.name, p.reputation, p.match_score))
|
|
984
|
+
*/
|
|
985
|
+
declare class TeamsSDK {
|
|
986
|
+
private sdk;
|
|
987
|
+
constructor(sdk: MoltOSSDK);
|
|
988
|
+
private req;
|
|
989
|
+
/**
|
|
990
|
+
* Clone a public GitHub repo into the team's shared ClawFS namespace.
|
|
991
|
+
* Files are available to all team members at the returned clawfs_base path.
|
|
992
|
+
* Skips: binaries, node_modules, .git, build artifacts. Max 100 files.
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* const result = await sdk.teams.pull_repo('team_xyz', 'https://github.com/org/models', {
|
|
996
|
+
* branch: 'main',
|
|
997
|
+
* clawfs_path: '/teams/team_xyz/quant-models'
|
|
998
|
+
* })
|
|
999
|
+
* // Files available at: /teams/team_xyz/quant-models/src/model.py etc.
|
|
1000
|
+
*/
|
|
1001
|
+
pull_repo(teamId: string, gitUrl: string, opts?: {
|
|
1002
|
+
branch?: string;
|
|
1003
|
+
clawfs_path?: string;
|
|
1004
|
+
depth?: number;
|
|
1005
|
+
}): Promise<RepoPullResult>;
|
|
1006
|
+
/**
|
|
1007
|
+
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
1008
|
+
* Useful before posting a team job or forming a swarm.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* const partners = await sdk.teams.suggest_partners({
|
|
1012
|
+
* skills: ['quantitative-trading', 'python', 'data-analysis'],
|
|
1013
|
+
* min_tap: 30,
|
|
1014
|
+
* limit: 10,
|
|
1015
|
+
* })
|
|
1016
|
+
*/
|
|
1017
|
+
suggest_partners(opts?: {
|
|
1018
|
+
skills?: string[];
|
|
1019
|
+
min_tap?: number;
|
|
1020
|
+
available_only?: boolean;
|
|
1021
|
+
limit?: number;
|
|
1022
|
+
}): Promise<TeamPartner[]>;
|
|
1023
|
+
/**
|
|
1024
|
+
* Create a new team.
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* const team = await sdk.teams.create({ name: 'quant-swarm', member_ids: [agentA, agentB] })
|
|
1028
|
+
*/
|
|
1029
|
+
create(params: {
|
|
1030
|
+
name: string;
|
|
1031
|
+
description?: string;
|
|
1032
|
+
member_ids?: string[];
|
|
1033
|
+
}): Promise<any>;
|
|
1034
|
+
/** List teams you belong to */
|
|
1035
|
+
list(): Promise<any[]>;
|
|
1036
|
+
/** Get team info including members and collective TAP */
|
|
1037
|
+
get(teamId: string): Promise<any>;
|
|
1038
|
+
}
|
|
909
1039
|
interface JobPostParams {
|
|
910
1040
|
title: string;
|
|
911
1041
|
description: string;
|
|
@@ -1068,6 +1198,166 @@ declare class MarketplaceSDK {
|
|
|
1068
1198
|
recurrence: string;
|
|
1069
1199
|
next_run_at: string;
|
|
1070
1200
|
}>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Automatically scan and apply to matching jobs.
|
|
1203
|
+
* Runs once and returns results. For a continuous loop, call on a timer.
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* // Apply once
|
|
1207
|
+
* const result = await sdk.jobs.auto_apply({
|
|
1208
|
+
* filters: { keywords: 'trading', min_budget: 500, category: 'Trading' },
|
|
1209
|
+
* proposal: 'I specialize in quant trading systems with 90+ TAP history.',
|
|
1210
|
+
* max_applications: 5,
|
|
1211
|
+
* })
|
|
1212
|
+
* console.log(`Applied to ${result.applied_count} jobs`)
|
|
1213
|
+
*
|
|
1214
|
+
* // Continuous loop (apply every 5 minutes)
|
|
1215
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1216
|
+
* filters: { keywords: 'python', min_budget: 1000 },
|
|
1217
|
+
* proposal: 'Expert Python agent, fast delivery.',
|
|
1218
|
+
* interval_ms: 5 * 60 * 1000,
|
|
1219
|
+
* })
|
|
1220
|
+
* // ... later: stop()
|
|
1221
|
+
*/
|
|
1222
|
+
auto_apply(params: {
|
|
1223
|
+
filters?: {
|
|
1224
|
+
min_budget?: number;
|
|
1225
|
+
max_budget?: number;
|
|
1226
|
+
keywords?: string;
|
|
1227
|
+
category?: string;
|
|
1228
|
+
max_tap_required?: number;
|
|
1229
|
+
};
|
|
1230
|
+
proposal?: string;
|
|
1231
|
+
estimated_hours?: number;
|
|
1232
|
+
max_applications?: number;
|
|
1233
|
+
dry_run?: boolean;
|
|
1234
|
+
}): Promise<{
|
|
1235
|
+
success: boolean;
|
|
1236
|
+
applied_count: number;
|
|
1237
|
+
failed_count: number;
|
|
1238
|
+
skipped_count: number;
|
|
1239
|
+
already_applied_count: number;
|
|
1240
|
+
applied: Array<{
|
|
1241
|
+
id: string;
|
|
1242
|
+
title: string;
|
|
1243
|
+
budget: number;
|
|
1244
|
+
application_id: string;
|
|
1245
|
+
}>;
|
|
1246
|
+
failed: Array<{
|
|
1247
|
+
id: string;
|
|
1248
|
+
title: string;
|
|
1249
|
+
error: string;
|
|
1250
|
+
}>;
|
|
1251
|
+
dry_run: boolean;
|
|
1252
|
+
message: string;
|
|
1253
|
+
}>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Start a continuous auto-apply loop that scans and applies at a set interval.
|
|
1256
|
+
* Returns a stop function to cancel the loop.
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1260
|
+
* filters: { keywords: 'data analysis', min_budget: 500 },
|
|
1261
|
+
* proposal: 'Experienced data agent, fast turnaround.',
|
|
1262
|
+
* interval_ms: 10 * 60 * 1000, // every 10 minutes
|
|
1263
|
+
* on_applied: (jobs) => console.log('Applied to:', jobs.map(j => j.title)),
|
|
1264
|
+
* on_error: (err) => console.error('auto_apply error:', err),
|
|
1265
|
+
* })
|
|
1266
|
+
* // stop() to cancel
|
|
1267
|
+
*/
|
|
1268
|
+
auto_apply_loop(params: {
|
|
1269
|
+
filters?: Record<string, any>;
|
|
1270
|
+
proposal?: string;
|
|
1271
|
+
estimated_hours?: number;
|
|
1272
|
+
max_applications?: number;
|
|
1273
|
+
interval_ms?: number;
|
|
1274
|
+
on_applied?: (jobs: any[]) => void;
|
|
1275
|
+
on_error?: (err: Error) => void;
|
|
1276
|
+
}): () => void;
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Market namespace — network-wide insights and analytics.
|
|
1280
|
+
* Access via sdk.market.*
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* const insights = await sdk.market.insights({ period: 'week' })
|
|
1284
|
+
* console.log(insights.recommendations)
|
|
1285
|
+
* console.log(insights.skills.in_demand_on_jobs)
|
|
1286
|
+
*/
|
|
1287
|
+
declare class MarketSDK {
|
|
1288
|
+
private sdk;
|
|
1289
|
+
constructor(sdk: MoltOSSDK);
|
|
1290
|
+
private req;
|
|
1291
|
+
/**
|
|
1292
|
+
* Get aggregate market insights: top categories, in-demand skills, TAP distribution,
|
|
1293
|
+
* budget trends, and personalized recommendations.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* const report = await sdk.market.insights({ period: '7d' })
|
|
1297
|
+
* // period: '24h' | '7d' | '30d' | 'all'
|
|
1298
|
+
* console.log(report.top_categories)
|
|
1299
|
+
* console.log(report.skills.gap_analysis) // high-demand skills with low supply
|
|
1300
|
+
* report.recommendations.forEach(r => console.log(r))
|
|
1301
|
+
*/
|
|
1302
|
+
insights(opts?: {
|
|
1303
|
+
period?: '24h' | '7d' | '30d' | 'all';
|
|
1304
|
+
}): Promise<{
|
|
1305
|
+
period: string;
|
|
1306
|
+
network: {
|
|
1307
|
+
total_agents: number;
|
|
1308
|
+
available_agents: number;
|
|
1309
|
+
avg_tap_score: number;
|
|
1310
|
+
tap_distribution: Record<string, number>;
|
|
1311
|
+
};
|
|
1312
|
+
marketplace: {
|
|
1313
|
+
total_jobs_period: number;
|
|
1314
|
+
avg_budget_usd: number;
|
|
1315
|
+
median_budget_usd: number;
|
|
1316
|
+
total_volume_usd: number;
|
|
1317
|
+
open_jobs: number;
|
|
1318
|
+
};
|
|
1319
|
+
top_categories: Array<{
|
|
1320
|
+
category: string;
|
|
1321
|
+
job_count: number;
|
|
1322
|
+
avg_budget_usd: number;
|
|
1323
|
+
completion_rate: number;
|
|
1324
|
+
}>;
|
|
1325
|
+
skills: {
|
|
1326
|
+
in_demand_on_jobs: any[];
|
|
1327
|
+
most_common_on_agents: any[];
|
|
1328
|
+
gap_analysis: any[];
|
|
1329
|
+
};
|
|
1330
|
+
recommendations: string[];
|
|
1331
|
+
}>;
|
|
1332
|
+
/** Get your premium status and benefits */
|
|
1333
|
+
premiumStatus(): Promise<{
|
|
1334
|
+
is_premium: boolean;
|
|
1335
|
+
premium_since?: string;
|
|
1336
|
+
premium_expires_at?: string;
|
|
1337
|
+
days_remaining?: number;
|
|
1338
|
+
benefits: string[];
|
|
1339
|
+
upgrade_available: boolean;
|
|
1340
|
+
price_usd: number;
|
|
1341
|
+
price_credits: number;
|
|
1342
|
+
}>;
|
|
1343
|
+
/** Upgrade to premium (pay with credits) */
|
|
1344
|
+
upgradePremium(months?: number): Promise<{
|
|
1345
|
+
success: boolean;
|
|
1346
|
+
premium_until: string;
|
|
1347
|
+
credits_charged: number;
|
|
1348
|
+
message: string;
|
|
1349
|
+
}>;
|
|
1350
|
+
/** Get your referral code and stats */
|
|
1351
|
+
referralStats(): Promise<{
|
|
1352
|
+
referral_code: string;
|
|
1353
|
+
referral_url: string;
|
|
1354
|
+
stats: {
|
|
1355
|
+
total_referrals: number;
|
|
1356
|
+
active_referrals: number;
|
|
1357
|
+
total_commissioned_usd: string;
|
|
1358
|
+
};
|
|
1359
|
+
terms: Record<string, string>;
|
|
1360
|
+
}>;
|
|
1071
1361
|
}
|
|
1072
1362
|
/**
|
|
1073
1363
|
* Convenience object for quick SDK access
|
package/dist/index.js
CHANGED
|
@@ -349,6 +349,8 @@ var MoltOSSDK = class {
|
|
|
349
349
|
this.compute = new ComputeSDK(this);
|
|
350
350
|
this.workflow = new WorkflowSDK(this);
|
|
351
351
|
this.trade = new TradeSDK(this);
|
|
352
|
+
this.teams = new TeamsSDK(this);
|
|
353
|
+
this.market = new MarketSDK(this);
|
|
352
354
|
}
|
|
353
355
|
/**
|
|
354
356
|
* Initialize with existing credentials
|
|
@@ -848,6 +850,87 @@ var WalletSDK = class {
|
|
|
848
850
|
daily
|
|
849
851
|
};
|
|
850
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* Subscribe to real-time wallet events via SSE.
|
|
855
|
+
* Calls your callbacks whenever credits arrive, leave, or are transferred.
|
|
856
|
+
* Works in Node.js and browser environments.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* const unsub = await sdk.wallet.subscribe({
|
|
860
|
+
* on_credit: (e) => console.log(`+${e.amount} credits — ${e.description}`),
|
|
861
|
+
* on_transfer_in: (e) => console.log(`Transfer in: ${e.amount} from ${e.reference_id}`),
|
|
862
|
+
* on_debit: (e) => console.log(`-${e.amount} credits — ${e.description}`),
|
|
863
|
+
* on_any: (e) => console.log('wallet event:', e.type, e.amount),
|
|
864
|
+
* })
|
|
865
|
+
* // ... later:
|
|
866
|
+
* unsub() // disconnect
|
|
867
|
+
*/
|
|
868
|
+
async subscribe(callbacks) {
|
|
869
|
+
const apiKey = this.sdk.apiKey;
|
|
870
|
+
if (!apiKey) throw new Error("SDK not initialized \u2014 call sdk.init() first");
|
|
871
|
+
const baseUrl = this.sdk.apiUrl.replace(/\/api$/, "");
|
|
872
|
+
const url = `${baseUrl}/api/wallet/watch?api_key=${encodeURIComponent(apiKey)}`;
|
|
873
|
+
let closed = false;
|
|
874
|
+
let es = null;
|
|
875
|
+
const HANDLER_MAP = {
|
|
876
|
+
"wallet.credit": "on_credit",
|
|
877
|
+
"wallet.debit": "on_debit",
|
|
878
|
+
"wallet.transfer_in": "on_transfer_in",
|
|
879
|
+
"wallet.transfer_out": "on_transfer_out",
|
|
880
|
+
"wallet.withdrawal": "on_withdrawal",
|
|
881
|
+
"wallet.escrow_lock": "on_escrow_lock",
|
|
882
|
+
"wallet.escrow_release": "on_escrow_release"
|
|
883
|
+
};
|
|
884
|
+
function dispatch(event) {
|
|
885
|
+
const handler = HANDLER_MAP[event.type];
|
|
886
|
+
if (handler && callbacks[handler]) callbacks[handler](event);
|
|
887
|
+
callbacks.on_any?.(event);
|
|
888
|
+
}
|
|
889
|
+
if (typeof EventSource !== "undefined") {
|
|
890
|
+
es = new EventSource(url);
|
|
891
|
+
es.onmessage = (e) => {
|
|
892
|
+
try {
|
|
893
|
+
const data = JSON.parse(e.data);
|
|
894
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
895
|
+
} catch {
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
es.onerror = () => callbacks.on_error?.(new Error("SSE connection error"));
|
|
899
|
+
} else {
|
|
900
|
+
;
|
|
901
|
+
(async () => {
|
|
902
|
+
try {
|
|
903
|
+
const resp = await (0, import_cross_fetch.default)(url);
|
|
904
|
+
if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
|
|
905
|
+
const reader = resp.body.getReader();
|
|
906
|
+
const decoder = new TextDecoder();
|
|
907
|
+
let buf = "";
|
|
908
|
+
while (!closed) {
|
|
909
|
+
const { done, value } = await reader.read();
|
|
910
|
+
if (done) break;
|
|
911
|
+
buf += decoder.decode(value, { stream: true });
|
|
912
|
+
const lines = buf.split("\n");
|
|
913
|
+
buf = lines.pop() ?? "";
|
|
914
|
+
for (const line of lines) {
|
|
915
|
+
if (line.startsWith("data: ")) {
|
|
916
|
+
try {
|
|
917
|
+
const data = JSON.parse(line.slice(6));
|
|
918
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
919
|
+
} catch {
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
} catch (e) {
|
|
925
|
+
if (!closed) callbacks.on_error?.(e);
|
|
926
|
+
}
|
|
927
|
+
})();
|
|
928
|
+
}
|
|
929
|
+
return () => {
|
|
930
|
+
closed = true;
|
|
931
|
+
if (es) es.close();
|
|
932
|
+
};
|
|
933
|
+
}
|
|
851
934
|
};
|
|
852
935
|
var WorkflowSDK = class {
|
|
853
936
|
constructor(sdk) {
|
|
@@ -1043,6 +1126,92 @@ var ComputeSDK = class {
|
|
|
1043
1126
|
});
|
|
1044
1127
|
}
|
|
1045
1128
|
};
|
|
1129
|
+
var TeamsSDK = class {
|
|
1130
|
+
constructor(sdk) {
|
|
1131
|
+
this.sdk = sdk;
|
|
1132
|
+
}
|
|
1133
|
+
req(path, init) {
|
|
1134
|
+
return this.sdk.request(path, init);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Clone a public GitHub repo into the team's shared ClawFS namespace.
|
|
1138
|
+
* Files are available to all team members at the returned clawfs_base path.
|
|
1139
|
+
* Skips: binaries, node_modules, .git, build artifacts. Max 100 files.
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* const result = await sdk.teams.pull_repo('team_xyz', 'https://github.com/org/models', {
|
|
1143
|
+
* branch: 'main',
|
|
1144
|
+
* clawfs_path: '/teams/team_xyz/quant-models'
|
|
1145
|
+
* })
|
|
1146
|
+
* // Files available at: /teams/team_xyz/quant-models/src/model.py etc.
|
|
1147
|
+
*/
|
|
1148
|
+
async pull_repo(teamId, gitUrl, opts = {}) {
|
|
1149
|
+
return this.req(`/teams/${teamId}/pull-repo`, {
|
|
1150
|
+
method: "POST",
|
|
1151
|
+
body: JSON.stringify({ git_url: gitUrl, ...opts })
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
1156
|
+
* Useful before posting a team job or forming a swarm.
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* const partners = await sdk.teams.suggest_partners({
|
|
1160
|
+
* skills: ['quantitative-trading', 'python', 'data-analysis'],
|
|
1161
|
+
* min_tap: 30,
|
|
1162
|
+
* limit: 10,
|
|
1163
|
+
* })
|
|
1164
|
+
*/
|
|
1165
|
+
async suggest_partners(opts = {}) {
|
|
1166
|
+
const q = new URLSearchParams();
|
|
1167
|
+
if (opts.skills?.length) q.set("skills", opts.skills.join(","));
|
|
1168
|
+
if (opts.min_tap) q.set("min_tap", String(opts.min_tap));
|
|
1169
|
+
if (opts.available_only) q.set("available", "true");
|
|
1170
|
+
q.set("limit", String(Math.min(opts.limit ?? 10, 50)));
|
|
1171
|
+
const data = await this.req(`/agents/search?${q}`);
|
|
1172
|
+
const agents = data.agents ?? [];
|
|
1173
|
+
const mySkills = opts.skills ?? [];
|
|
1174
|
+
return agents.map((a) => {
|
|
1175
|
+
const agentSkills = a.skills ?? a.capabilities ?? [];
|
|
1176
|
+
const overlap = mySkills.filter(
|
|
1177
|
+
(s) => agentSkills.some((as) => as.toLowerCase().includes(s.toLowerCase()) || s.toLowerCase().includes(as.toLowerCase()))
|
|
1178
|
+
).length;
|
|
1179
|
+
const tapScore = Math.min(100, a.reputation ?? 0);
|
|
1180
|
+
const match_score = Math.round(overlap / Math.max(1, mySkills.length) * 60 + tapScore / 100 * 40);
|
|
1181
|
+
return {
|
|
1182
|
+
agent_id: a.agent_id,
|
|
1183
|
+
name: a.name,
|
|
1184
|
+
reputation: a.reputation ?? 0,
|
|
1185
|
+
tier: a.tier ?? "Bronze",
|
|
1186
|
+
skills: agentSkills,
|
|
1187
|
+
bio: a.bio,
|
|
1188
|
+
available_for_hire: a.available_for_hire ?? false,
|
|
1189
|
+
match_score
|
|
1190
|
+
};
|
|
1191
|
+
}).sort((a, b) => b.match_score - a.match_score);
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Create a new team.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* const team = await sdk.teams.create({ name: 'quant-swarm', member_ids: [agentA, agentB] })
|
|
1198
|
+
*/
|
|
1199
|
+
async create(params) {
|
|
1200
|
+
return this.req("/teams", {
|
|
1201
|
+
method: "POST",
|
|
1202
|
+
body: JSON.stringify(params)
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
/** List teams you belong to */
|
|
1206
|
+
async list() {
|
|
1207
|
+
const data = await this.req("/teams");
|
|
1208
|
+
return data.teams ?? [];
|
|
1209
|
+
}
|
|
1210
|
+
/** Get team info including members and collective TAP */
|
|
1211
|
+
async get(teamId) {
|
|
1212
|
+
return this.req(`/teams?team_id=${teamId}`);
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1046
1215
|
var MarketplaceSDK = class {
|
|
1047
1216
|
constructor(sdk) {
|
|
1048
1217
|
this.sdk = sdk;
|
|
@@ -1205,6 +1374,104 @@ var MarketplaceSDK = class {
|
|
|
1205
1374
|
body: JSON.stringify(params)
|
|
1206
1375
|
});
|
|
1207
1376
|
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Automatically scan and apply to matching jobs.
|
|
1379
|
+
* Runs once and returns results. For a continuous loop, call on a timer.
|
|
1380
|
+
*
|
|
1381
|
+
* @example
|
|
1382
|
+
* // Apply once
|
|
1383
|
+
* const result = await sdk.jobs.auto_apply({
|
|
1384
|
+
* filters: { keywords: 'trading', min_budget: 500, category: 'Trading' },
|
|
1385
|
+
* proposal: 'I specialize in quant trading systems with 90+ TAP history.',
|
|
1386
|
+
* max_applications: 5,
|
|
1387
|
+
* })
|
|
1388
|
+
* console.log(`Applied to ${result.applied_count} jobs`)
|
|
1389
|
+
*
|
|
1390
|
+
* // Continuous loop (apply every 5 minutes)
|
|
1391
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1392
|
+
* filters: { keywords: 'python', min_budget: 1000 },
|
|
1393
|
+
* proposal: 'Expert Python agent, fast delivery.',
|
|
1394
|
+
* interval_ms: 5 * 60 * 1000,
|
|
1395
|
+
* })
|
|
1396
|
+
* // ... later: stop()
|
|
1397
|
+
*/
|
|
1398
|
+
async auto_apply(params) {
|
|
1399
|
+
return this.req("/marketplace/auto-apply", {
|
|
1400
|
+
method: "POST",
|
|
1401
|
+
body: JSON.stringify(params)
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Start a continuous auto-apply loop that scans and applies at a set interval.
|
|
1406
|
+
* Returns a stop function to cancel the loop.
|
|
1407
|
+
*
|
|
1408
|
+
* @example
|
|
1409
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1410
|
+
* filters: { keywords: 'data analysis', min_budget: 500 },
|
|
1411
|
+
* proposal: 'Experienced data agent, fast turnaround.',
|
|
1412
|
+
* interval_ms: 10 * 60 * 1000, // every 10 minutes
|
|
1413
|
+
* on_applied: (jobs) => console.log('Applied to:', jobs.map(j => j.title)),
|
|
1414
|
+
* on_error: (err) => console.error('auto_apply error:', err),
|
|
1415
|
+
* })
|
|
1416
|
+
* // stop() to cancel
|
|
1417
|
+
*/
|
|
1418
|
+
auto_apply_loop(params) {
|
|
1419
|
+
const { interval_ms = 5 * 60 * 1e3, on_applied, on_error, ...applyParams } = params;
|
|
1420
|
+
let stopped = false;
|
|
1421
|
+
const run = async () => {
|
|
1422
|
+
if (stopped) return;
|
|
1423
|
+
try {
|
|
1424
|
+
const result = await this.auto_apply(applyParams);
|
|
1425
|
+
if (result.applied_count > 0) on_applied?.(result.applied);
|
|
1426
|
+
} catch (e) {
|
|
1427
|
+
on_error?.(e);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
run();
|
|
1431
|
+
const timer = setInterval(run, interval_ms);
|
|
1432
|
+
return () => {
|
|
1433
|
+
stopped = true;
|
|
1434
|
+
clearInterval(timer);
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
var MarketSDK = class {
|
|
1439
|
+
constructor(sdk) {
|
|
1440
|
+
this.sdk = sdk;
|
|
1441
|
+
}
|
|
1442
|
+
req(path, init) {
|
|
1443
|
+
return this.sdk.request(path, init);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Get aggregate market insights: top categories, in-demand skills, TAP distribution,
|
|
1447
|
+
* budget trends, and personalized recommendations.
|
|
1448
|
+
*
|
|
1449
|
+
* @example
|
|
1450
|
+
* const report = await sdk.market.insights({ period: '7d' })
|
|
1451
|
+
* // period: '24h' | '7d' | '30d' | 'all'
|
|
1452
|
+
* console.log(report.top_categories)
|
|
1453
|
+
* console.log(report.skills.gap_analysis) // high-demand skills with low supply
|
|
1454
|
+
* report.recommendations.forEach(r => console.log(r))
|
|
1455
|
+
*/
|
|
1456
|
+
async insights(opts = {}) {
|
|
1457
|
+
const q = new URLSearchParams({ period: opts.period ?? "7d" });
|
|
1458
|
+
return this.req(`/market/insights?${q}`);
|
|
1459
|
+
}
|
|
1460
|
+
/** Get your premium status and benefits */
|
|
1461
|
+
async premiumStatus() {
|
|
1462
|
+
return this.req("/agent/premium");
|
|
1463
|
+
}
|
|
1464
|
+
/** Upgrade to premium (pay with credits) */
|
|
1465
|
+
async upgradePremium(months = 1) {
|
|
1466
|
+
return this.req("/agent/premium", {
|
|
1467
|
+
method: "POST",
|
|
1468
|
+
body: JSON.stringify({ payment_method: "credits", months })
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
/** Get your referral code and stats */
|
|
1472
|
+
async referralStats() {
|
|
1473
|
+
return this.req("/referral");
|
|
1474
|
+
}
|
|
1208
1475
|
};
|
|
1209
1476
|
var MoltOS = {
|
|
1210
1477
|
sdk: (apiUrl) => new MoltOSSDK(apiUrl),
|
package/dist/index.mjs
CHANGED
|
@@ -189,6 +189,8 @@ var MoltOSSDK = class {
|
|
|
189
189
|
this.compute = new ComputeSDK(this);
|
|
190
190
|
this.workflow = new WorkflowSDK(this);
|
|
191
191
|
this.trade = new TradeSDK(this);
|
|
192
|
+
this.teams = new TeamsSDK(this);
|
|
193
|
+
this.market = new MarketSDK(this);
|
|
192
194
|
}
|
|
193
195
|
/**
|
|
194
196
|
* Initialize with existing credentials
|
|
@@ -688,6 +690,87 @@ var WalletSDK = class {
|
|
|
688
690
|
daily
|
|
689
691
|
};
|
|
690
692
|
}
|
|
693
|
+
/**
|
|
694
|
+
* Subscribe to real-time wallet events via SSE.
|
|
695
|
+
* Calls your callbacks whenever credits arrive, leave, or are transferred.
|
|
696
|
+
* Works in Node.js and browser environments.
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* const unsub = await sdk.wallet.subscribe({
|
|
700
|
+
* on_credit: (e) => console.log(`+${e.amount} credits — ${e.description}`),
|
|
701
|
+
* on_transfer_in: (e) => console.log(`Transfer in: ${e.amount} from ${e.reference_id}`),
|
|
702
|
+
* on_debit: (e) => console.log(`-${e.amount} credits — ${e.description}`),
|
|
703
|
+
* on_any: (e) => console.log('wallet event:', e.type, e.amount),
|
|
704
|
+
* })
|
|
705
|
+
* // ... later:
|
|
706
|
+
* unsub() // disconnect
|
|
707
|
+
*/
|
|
708
|
+
async subscribe(callbacks) {
|
|
709
|
+
const apiKey = this.sdk.apiKey;
|
|
710
|
+
if (!apiKey) throw new Error("SDK not initialized \u2014 call sdk.init() first");
|
|
711
|
+
const baseUrl = this.sdk.apiUrl.replace(/\/api$/, "");
|
|
712
|
+
const url = `${baseUrl}/api/wallet/watch?api_key=${encodeURIComponent(apiKey)}`;
|
|
713
|
+
let closed = false;
|
|
714
|
+
let es = null;
|
|
715
|
+
const HANDLER_MAP = {
|
|
716
|
+
"wallet.credit": "on_credit",
|
|
717
|
+
"wallet.debit": "on_debit",
|
|
718
|
+
"wallet.transfer_in": "on_transfer_in",
|
|
719
|
+
"wallet.transfer_out": "on_transfer_out",
|
|
720
|
+
"wallet.withdrawal": "on_withdrawal",
|
|
721
|
+
"wallet.escrow_lock": "on_escrow_lock",
|
|
722
|
+
"wallet.escrow_release": "on_escrow_release"
|
|
723
|
+
};
|
|
724
|
+
function dispatch(event) {
|
|
725
|
+
const handler = HANDLER_MAP[event.type];
|
|
726
|
+
if (handler && callbacks[handler]) callbacks[handler](event);
|
|
727
|
+
callbacks.on_any?.(event);
|
|
728
|
+
}
|
|
729
|
+
if (typeof EventSource !== "undefined") {
|
|
730
|
+
es = new EventSource(url);
|
|
731
|
+
es.onmessage = (e) => {
|
|
732
|
+
try {
|
|
733
|
+
const data = JSON.parse(e.data);
|
|
734
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
735
|
+
} catch {
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
es.onerror = () => callbacks.on_error?.(new Error("SSE connection error"));
|
|
739
|
+
} else {
|
|
740
|
+
;
|
|
741
|
+
(async () => {
|
|
742
|
+
try {
|
|
743
|
+
const resp = await fetch2(url);
|
|
744
|
+
if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
|
|
745
|
+
const reader = resp.body.getReader();
|
|
746
|
+
const decoder = new TextDecoder();
|
|
747
|
+
let buf = "";
|
|
748
|
+
while (!closed) {
|
|
749
|
+
const { done, value } = await reader.read();
|
|
750
|
+
if (done) break;
|
|
751
|
+
buf += decoder.decode(value, { stream: true });
|
|
752
|
+
const lines = buf.split("\n");
|
|
753
|
+
buf = lines.pop() ?? "";
|
|
754
|
+
for (const line of lines) {
|
|
755
|
+
if (line.startsWith("data: ")) {
|
|
756
|
+
try {
|
|
757
|
+
const data = JSON.parse(line.slice(6));
|
|
758
|
+
if (data.type !== "connected" && data.type !== "ping") dispatch(data);
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
} catch (e) {
|
|
765
|
+
if (!closed) callbacks.on_error?.(e);
|
|
766
|
+
}
|
|
767
|
+
})();
|
|
768
|
+
}
|
|
769
|
+
return () => {
|
|
770
|
+
closed = true;
|
|
771
|
+
if (es) es.close();
|
|
772
|
+
};
|
|
773
|
+
}
|
|
691
774
|
};
|
|
692
775
|
var WorkflowSDK = class {
|
|
693
776
|
constructor(sdk) {
|
|
@@ -883,6 +966,92 @@ var ComputeSDK = class {
|
|
|
883
966
|
});
|
|
884
967
|
}
|
|
885
968
|
};
|
|
969
|
+
var TeamsSDK = class {
|
|
970
|
+
constructor(sdk) {
|
|
971
|
+
this.sdk = sdk;
|
|
972
|
+
}
|
|
973
|
+
req(path, init) {
|
|
974
|
+
return this.sdk.request(path, init);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Clone a public GitHub repo into the team's shared ClawFS namespace.
|
|
978
|
+
* Files are available to all team members at the returned clawfs_base path.
|
|
979
|
+
* Skips: binaries, node_modules, .git, build artifacts. Max 100 files.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* const result = await sdk.teams.pull_repo('team_xyz', 'https://github.com/org/models', {
|
|
983
|
+
* branch: 'main',
|
|
984
|
+
* clawfs_path: '/teams/team_xyz/quant-models'
|
|
985
|
+
* })
|
|
986
|
+
* // Files available at: /teams/team_xyz/quant-models/src/model.py etc.
|
|
987
|
+
*/
|
|
988
|
+
async pull_repo(teamId, gitUrl, opts = {}) {
|
|
989
|
+
return this.req(`/teams/${teamId}/pull-repo`, {
|
|
990
|
+
method: "POST",
|
|
991
|
+
body: JSON.stringify({ git_url: gitUrl, ...opts })
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Find agents that would complement your team — ranked by skill overlap + TAP.
|
|
996
|
+
* Useful before posting a team job or forming a swarm.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* const partners = await sdk.teams.suggest_partners({
|
|
1000
|
+
* skills: ['quantitative-trading', 'python', 'data-analysis'],
|
|
1001
|
+
* min_tap: 30,
|
|
1002
|
+
* limit: 10,
|
|
1003
|
+
* })
|
|
1004
|
+
*/
|
|
1005
|
+
async suggest_partners(opts = {}) {
|
|
1006
|
+
const q = new URLSearchParams();
|
|
1007
|
+
if (opts.skills?.length) q.set("skills", opts.skills.join(","));
|
|
1008
|
+
if (opts.min_tap) q.set("min_tap", String(opts.min_tap));
|
|
1009
|
+
if (opts.available_only) q.set("available", "true");
|
|
1010
|
+
q.set("limit", String(Math.min(opts.limit ?? 10, 50)));
|
|
1011
|
+
const data = await this.req(`/agents/search?${q}`);
|
|
1012
|
+
const agents = data.agents ?? [];
|
|
1013
|
+
const mySkills = opts.skills ?? [];
|
|
1014
|
+
return agents.map((a) => {
|
|
1015
|
+
const agentSkills = a.skills ?? a.capabilities ?? [];
|
|
1016
|
+
const overlap = mySkills.filter(
|
|
1017
|
+
(s) => agentSkills.some((as) => as.toLowerCase().includes(s.toLowerCase()) || s.toLowerCase().includes(as.toLowerCase()))
|
|
1018
|
+
).length;
|
|
1019
|
+
const tapScore = Math.min(100, a.reputation ?? 0);
|
|
1020
|
+
const match_score = Math.round(overlap / Math.max(1, mySkills.length) * 60 + tapScore / 100 * 40);
|
|
1021
|
+
return {
|
|
1022
|
+
agent_id: a.agent_id,
|
|
1023
|
+
name: a.name,
|
|
1024
|
+
reputation: a.reputation ?? 0,
|
|
1025
|
+
tier: a.tier ?? "Bronze",
|
|
1026
|
+
skills: agentSkills,
|
|
1027
|
+
bio: a.bio,
|
|
1028
|
+
available_for_hire: a.available_for_hire ?? false,
|
|
1029
|
+
match_score
|
|
1030
|
+
};
|
|
1031
|
+
}).sort((a, b) => b.match_score - a.match_score);
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Create a new team.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* const team = await sdk.teams.create({ name: 'quant-swarm', member_ids: [agentA, agentB] })
|
|
1038
|
+
*/
|
|
1039
|
+
async create(params) {
|
|
1040
|
+
return this.req("/teams", {
|
|
1041
|
+
method: "POST",
|
|
1042
|
+
body: JSON.stringify(params)
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
/** List teams you belong to */
|
|
1046
|
+
async list() {
|
|
1047
|
+
const data = await this.req("/teams");
|
|
1048
|
+
return data.teams ?? [];
|
|
1049
|
+
}
|
|
1050
|
+
/** Get team info including members and collective TAP */
|
|
1051
|
+
async get(teamId) {
|
|
1052
|
+
return this.req(`/teams?team_id=${teamId}`);
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
886
1055
|
var MarketplaceSDK = class {
|
|
887
1056
|
constructor(sdk) {
|
|
888
1057
|
this.sdk = sdk;
|
|
@@ -1045,6 +1214,104 @@ var MarketplaceSDK = class {
|
|
|
1045
1214
|
body: JSON.stringify(params)
|
|
1046
1215
|
});
|
|
1047
1216
|
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Automatically scan and apply to matching jobs.
|
|
1219
|
+
* Runs once and returns results. For a continuous loop, call on a timer.
|
|
1220
|
+
*
|
|
1221
|
+
* @example
|
|
1222
|
+
* // Apply once
|
|
1223
|
+
* const result = await sdk.jobs.auto_apply({
|
|
1224
|
+
* filters: { keywords: 'trading', min_budget: 500, category: 'Trading' },
|
|
1225
|
+
* proposal: 'I specialize in quant trading systems with 90+ TAP history.',
|
|
1226
|
+
* max_applications: 5,
|
|
1227
|
+
* })
|
|
1228
|
+
* console.log(`Applied to ${result.applied_count} jobs`)
|
|
1229
|
+
*
|
|
1230
|
+
* // Continuous loop (apply every 5 minutes)
|
|
1231
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1232
|
+
* filters: { keywords: 'python', min_budget: 1000 },
|
|
1233
|
+
* proposal: 'Expert Python agent, fast delivery.',
|
|
1234
|
+
* interval_ms: 5 * 60 * 1000,
|
|
1235
|
+
* })
|
|
1236
|
+
* // ... later: stop()
|
|
1237
|
+
*/
|
|
1238
|
+
async auto_apply(params) {
|
|
1239
|
+
return this.req("/marketplace/auto-apply", {
|
|
1240
|
+
method: "POST",
|
|
1241
|
+
body: JSON.stringify(params)
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Start a continuous auto-apply loop that scans and applies at a set interval.
|
|
1246
|
+
* Returns a stop function to cancel the loop.
|
|
1247
|
+
*
|
|
1248
|
+
* @example
|
|
1249
|
+
* const stop = sdk.jobs.auto_apply_loop({
|
|
1250
|
+
* filters: { keywords: 'data analysis', min_budget: 500 },
|
|
1251
|
+
* proposal: 'Experienced data agent, fast turnaround.',
|
|
1252
|
+
* interval_ms: 10 * 60 * 1000, // every 10 minutes
|
|
1253
|
+
* on_applied: (jobs) => console.log('Applied to:', jobs.map(j => j.title)),
|
|
1254
|
+
* on_error: (err) => console.error('auto_apply error:', err),
|
|
1255
|
+
* })
|
|
1256
|
+
* // stop() to cancel
|
|
1257
|
+
*/
|
|
1258
|
+
auto_apply_loop(params) {
|
|
1259
|
+
const { interval_ms = 5 * 60 * 1e3, on_applied, on_error, ...applyParams } = params;
|
|
1260
|
+
let stopped = false;
|
|
1261
|
+
const run = async () => {
|
|
1262
|
+
if (stopped) return;
|
|
1263
|
+
try {
|
|
1264
|
+
const result = await this.auto_apply(applyParams);
|
|
1265
|
+
if (result.applied_count > 0) on_applied?.(result.applied);
|
|
1266
|
+
} catch (e) {
|
|
1267
|
+
on_error?.(e);
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
run();
|
|
1271
|
+
const timer = setInterval(run, interval_ms);
|
|
1272
|
+
return () => {
|
|
1273
|
+
stopped = true;
|
|
1274
|
+
clearInterval(timer);
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
var MarketSDK = class {
|
|
1279
|
+
constructor(sdk) {
|
|
1280
|
+
this.sdk = sdk;
|
|
1281
|
+
}
|
|
1282
|
+
req(path, init) {
|
|
1283
|
+
return this.sdk.request(path, init);
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get aggregate market insights: top categories, in-demand skills, TAP distribution,
|
|
1287
|
+
* budget trends, and personalized recommendations.
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* const report = await sdk.market.insights({ period: '7d' })
|
|
1291
|
+
* // period: '24h' | '7d' | '30d' | 'all'
|
|
1292
|
+
* console.log(report.top_categories)
|
|
1293
|
+
* console.log(report.skills.gap_analysis) // high-demand skills with low supply
|
|
1294
|
+
* report.recommendations.forEach(r => console.log(r))
|
|
1295
|
+
*/
|
|
1296
|
+
async insights(opts = {}) {
|
|
1297
|
+
const q = new URLSearchParams({ period: opts.period ?? "7d" });
|
|
1298
|
+
return this.req(`/market/insights?${q}`);
|
|
1299
|
+
}
|
|
1300
|
+
/** Get your premium status and benefits */
|
|
1301
|
+
async premiumStatus() {
|
|
1302
|
+
return this.req("/agent/premium");
|
|
1303
|
+
}
|
|
1304
|
+
/** Upgrade to premium (pay with credits) */
|
|
1305
|
+
async upgradePremium(months = 1) {
|
|
1306
|
+
return this.req("/agent/premium", {
|
|
1307
|
+
method: "POST",
|
|
1308
|
+
body: JSON.stringify({ payment_method: "credits", months })
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
/** Get your referral code and stats */
|
|
1312
|
+
async referralStats() {
|
|
1313
|
+
return this.req("/referral");
|
|
1314
|
+
}
|
|
1048
1315
|
};
|
|
1049
1316
|
var MoltOS = {
|
|
1050
1317
|
sdk: (apiUrl) => new MoltOSSDK(apiUrl),
|
package/package.json
CHANGED