@moltos/sdk 0.16.8 → 0.16.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -717,6 +717,8 @@ declare class WalletSDK {
717
717
  on_escrow_release?: (event: WalletEvent) => void;
718
718
  on_any?: (event: WalletEvent) => void;
719
719
  on_error?: (err: Error) => void;
720
+ /** Called each time the connection is successfully (re)established after a drop */
721
+ on_reconnect?: (attempt: number) => void;
720
722
  }): Promise<() => void>;
721
723
  }
722
724
  interface WalletEvent {
@@ -1065,11 +1067,16 @@ declare class TeamsSDK {
1065
1067
  clawfs_path?: string;
1066
1068
  github_token?: string;
1067
1069
  chunk_size?: number;
1070
+ /** Resume from a specific offset (e.g. after a partial failure) */
1071
+ start_offset?: number;
1068
1072
  onChunk?: (result: any, chunk: number) => void;
1069
1073
  }): Promise<{
1070
1074
  total_written: number;
1071
1075
  total_chunks: number;
1072
1076
  clawfs_base?: string;
1077
+ last_offset?: number;
1078
+ completed: boolean;
1079
+ error?: string;
1073
1080
  }>;
1074
1081
  /**
1075
1082
  * Find agents that would complement your team — ranked by skill overlap + TAP.
package/dist/index.d.ts CHANGED
@@ -717,6 +717,8 @@ declare class WalletSDK {
717
717
  on_escrow_release?: (event: WalletEvent) => void;
718
718
  on_any?: (event: WalletEvent) => void;
719
719
  on_error?: (err: Error) => void;
720
+ /** Called each time the connection is successfully (re)established after a drop */
721
+ on_reconnect?: (attempt: number) => void;
720
722
  }): Promise<() => void>;
721
723
  }
722
724
  interface WalletEvent {
@@ -1065,11 +1067,16 @@ declare class TeamsSDK {
1065
1067
  clawfs_path?: string;
1066
1068
  github_token?: string;
1067
1069
  chunk_size?: number;
1070
+ /** Resume from a specific offset (e.g. after a partial failure) */
1071
+ start_offset?: number;
1068
1072
  onChunk?: (result: any, chunk: number) => void;
1069
1073
  }): Promise<{
1070
1074
  total_written: number;
1071
1075
  total_chunks: number;
1072
1076
  clawfs_base?: string;
1077
+ last_offset?: number;
1078
+ completed: boolean;
1079
+ error?: string;
1073
1080
  }>;
1074
1081
  /**
1075
1082
  * Find agents that would complement your team — ranked by skill overlap + TAP.
package/dist/index.js CHANGED
@@ -888,12 +888,17 @@ var WalletSDK = class {
888
888
  }
889
889
  let reconnectDelay = 1e3;
890
890
  const MAX_RECONNECT_DELAY = 3e4;
891
+ let reconnectAttempt = 0;
891
892
  function connect() {
892
893
  if (closed) return;
893
894
  if (typeof EventSource !== "undefined") {
894
895
  es = new EventSource(url);
895
896
  es.onmessage = (e) => {
896
- reconnectDelay = 1e3;
897
+ if (reconnectDelay !== 1e3) {
898
+ reconnectDelay = 1e3;
899
+ reconnectAttempt = 0;
900
+ callbacks.on_reconnect?.(reconnectAttempt);
901
+ }
897
902
  try {
898
903
  const data = JSON.parse(e.data);
899
904
  if (data.type !== "connected" && data.type !== "ping") dispatch(data);
@@ -902,6 +907,7 @@ var WalletSDK = class {
902
907
  };
903
908
  es.onerror = () => {
904
909
  if (closed) return;
910
+ reconnectAttempt++;
905
911
  callbacks.on_error?.(new Error(`SSE connection error \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
906
912
  es?.close();
907
913
  setTimeout(() => {
@@ -916,7 +922,9 @@ var WalletSDK = class {
916
922
  try {
917
923
  const resp = await (0, import_cross_fetch.default)(url);
918
924
  if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
925
+ if (reconnectAttempt > 0) callbacks.on_reconnect?.(reconnectAttempt);
919
926
  reconnectDelay = 1e3;
927
+ reconnectAttempt = 0;
920
928
  const reader = resp.body.getReader();
921
929
  const decoder = new TextDecoder();
922
930
  let buf = "";
@@ -938,6 +946,7 @@ var WalletSDK = class {
938
946
  }
939
947
  } catch (e) {
940
948
  if (closed) break;
949
+ reconnectAttempt++;
941
950
  callbacks.on_error?.(new Error(`SSE dropped \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
942
951
  await new Promise((r) => setTimeout(r, reconnectDelay));
943
952
  reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
@@ -1227,12 +1236,24 @@ var TeamsSDK = class {
1227
1236
  * })
1228
1237
  */
1229
1238
  async pull_repo_all(teamId, gitUrl, opts = {}) {
1230
- let offset = 0;
1239
+ let offset = opts.start_offset ?? 0;
1231
1240
  let chunk = 0;
1232
1241
  let totalWritten = 0;
1233
1242
  let clawfsBase;
1234
1243
  while (true) {
1235
- const result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
1244
+ let result;
1245
+ try {
1246
+ result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
1247
+ } catch (e) {
1248
+ return {
1249
+ total_written: totalWritten,
1250
+ total_chunks: chunk,
1251
+ clawfs_base: clawfsBase,
1252
+ last_offset: offset,
1253
+ completed: false,
1254
+ error: `Failed at chunk ${chunk + 1} (offset ${offset}): ${e?.message ?? String(e)}. Resume with start_offset: ${offset}`
1255
+ };
1256
+ }
1236
1257
  chunk++;
1237
1258
  totalWritten += result.files_written ?? 0;
1238
1259
  clawfsBase = result.clawfs_base;
@@ -1240,7 +1261,7 @@ var TeamsSDK = class {
1240
1261
  if (!result.has_more || result.next_chunk_offset == null) break;
1241
1262
  offset = result.next_chunk_offset;
1242
1263
  }
1243
- return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase };
1264
+ return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase, completed: true };
1244
1265
  }
1245
1266
  /**
1246
1267
  * Find agents that would complement your team — ranked by skill overlap + TAP.
package/dist/index.mjs CHANGED
@@ -728,12 +728,17 @@ var WalletSDK = class {
728
728
  }
729
729
  let reconnectDelay = 1e3;
730
730
  const MAX_RECONNECT_DELAY = 3e4;
731
+ let reconnectAttempt = 0;
731
732
  function connect() {
732
733
  if (closed) return;
733
734
  if (typeof EventSource !== "undefined") {
734
735
  es = new EventSource(url);
735
736
  es.onmessage = (e) => {
736
- reconnectDelay = 1e3;
737
+ if (reconnectDelay !== 1e3) {
738
+ reconnectDelay = 1e3;
739
+ reconnectAttempt = 0;
740
+ callbacks.on_reconnect?.(reconnectAttempt);
741
+ }
737
742
  try {
738
743
  const data = JSON.parse(e.data);
739
744
  if (data.type !== "connected" && data.type !== "ping") dispatch(data);
@@ -742,6 +747,7 @@ var WalletSDK = class {
742
747
  };
743
748
  es.onerror = () => {
744
749
  if (closed) return;
750
+ reconnectAttempt++;
745
751
  callbacks.on_error?.(new Error(`SSE connection error \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
746
752
  es?.close();
747
753
  setTimeout(() => {
@@ -756,7 +762,9 @@ var WalletSDK = class {
756
762
  try {
757
763
  const resp = await fetch2(url);
758
764
  if (!resp.ok || !resp.body) throw new Error(`SSE connect failed: ${resp.status}`);
765
+ if (reconnectAttempt > 0) callbacks.on_reconnect?.(reconnectAttempt);
759
766
  reconnectDelay = 1e3;
767
+ reconnectAttempt = 0;
760
768
  const reader = resp.body.getReader();
761
769
  const decoder = new TextDecoder();
762
770
  let buf = "";
@@ -778,6 +786,7 @@ var WalletSDK = class {
778
786
  }
779
787
  } catch (e) {
780
788
  if (closed) break;
789
+ reconnectAttempt++;
781
790
  callbacks.on_error?.(new Error(`SSE dropped \u2014 reconnecting in ${reconnectDelay / 1e3}s`));
782
791
  await new Promise((r) => setTimeout(r, reconnectDelay));
783
792
  reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY);
@@ -1067,12 +1076,24 @@ var TeamsSDK = class {
1067
1076
  * })
1068
1077
  */
1069
1078
  async pull_repo_all(teamId, gitUrl, opts = {}) {
1070
- let offset = 0;
1079
+ let offset = opts.start_offset ?? 0;
1071
1080
  let chunk = 0;
1072
1081
  let totalWritten = 0;
1073
1082
  let clawfsBase;
1074
1083
  while (true) {
1075
- const result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
1084
+ let result;
1085
+ try {
1086
+ result = await this.pull_repo(teamId, gitUrl, { ...opts, chunk_offset: offset });
1087
+ } catch (e) {
1088
+ return {
1089
+ total_written: totalWritten,
1090
+ total_chunks: chunk,
1091
+ clawfs_base: clawfsBase,
1092
+ last_offset: offset,
1093
+ completed: false,
1094
+ error: `Failed at chunk ${chunk + 1} (offset ${offset}): ${e?.message ?? String(e)}. Resume with start_offset: ${offset}`
1095
+ };
1096
+ }
1076
1097
  chunk++;
1077
1098
  totalWritten += result.files_written ?? 0;
1078
1099
  clawfsBase = result.clawfs_base;
@@ -1080,7 +1101,7 @@ var TeamsSDK = class {
1080
1101
  if (!result.has_more || result.next_chunk_offset == null) break;
1081
1102
  offset = result.next_chunk_offset;
1082
1103
  }
1083
- return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase };
1104
+ return { total_written: totalWritten, total_chunks: chunk, clawfs_base: clawfsBase, completed: true };
1084
1105
  }
1085
1106
  /**
1086
1107
  * Find agents that would complement your team — ranked by skill overlap + TAP.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltos/sdk",
3
- "version": "0.16.8",
3
+ "version": "0.16.10",
4
4
  "description": "MoltOS \u2014 The Agent Operating System SDK. Build agents that earn, persist, and compound trust.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",