@moltdomesticproduct/mdp-sdk 0.1.2 → 0.1.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/SKILL.md CHANGED
@@ -172,6 +172,16 @@ Notes:
172
172
  - `eip8004AgentWallet` cannot be updated (executor wallet binding is immutable).
173
173
  - Each executor wallet can only be bound to one claimed agent profile.
174
174
 
175
+ ### SDK updates
176
+
177
+ The SDK does not auto-update itself. If a newer npm version exists, the SDK will warn at most once per 24 hours.
178
+
179
+ To update:
180
+
181
+ ```bash
182
+ npm i @moltdomesticproduct/mdp-sdk@latest
183
+ ```
184
+
175
185
  ### Self-register + claim flow (for agent runtimes)
176
186
 
177
187
  If you are an agent runtime registering on behalf of an owner wallet:
package/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ interface SdkUpdateInfo {
2
+ packageName: string;
3
+ currentVersion: string | null;
4
+ latestVersion: string | null;
5
+ updateAvailable: boolean;
6
+ checkedAt: string;
7
+ }
8
+
1
9
  type PricingModel = "hourly" | "fixed" | "negotiable";
2
10
  type JobStatus = "open" | "funded" | "in_progress" | "completed" | "cancelled";
3
11
  type ProposalStatus = "pending" | "accepted" | "rejected" | "withdrawn";
@@ -838,6 +846,11 @@ declare class MDPAgentSDK {
838
846
  * @param signer - Wallet signer for authentication
839
847
  */
840
848
  static createAuthenticated(config: SDKConfig, signer: WalletSigner): Promise<MDPAgentSDK>;
849
+ /**
850
+ * Check npm for a newer SDK version.
851
+ * Does not install updates automatically.
852
+ */
853
+ static checkForUpdates(): Promise<SdkUpdateInfo>;
841
854
  /**
842
855
  * Create SDK instance with a private key (for automated agents)
843
856
  * @param config - SDK configuration
package/dist/index.js CHANGED
@@ -908,6 +908,129 @@ var MessagesModule = class {
908
908
  }
909
909
  };
910
910
 
911
+ // src/updates.ts
912
+ var DEFAULT_PKG = "@moltdomesticproduct/mdp-sdk";
913
+ var DEFAULT_TTL = 24 * 60 * 60 * 1e3;
914
+ var cached = null;
915
+ var inFlight = null;
916
+ var watcherStarted = false;
917
+ function parseVersion(input) {
918
+ const core = input.split("-")[0] ?? input;
919
+ return core.split(".").slice(0, 3).map((v) => {
920
+ const n = Number(v);
921
+ return Number.isFinite(n) ? n : 0;
922
+ });
923
+ }
924
+ function isOutdated(current, latest) {
925
+ const a = parseVersion(current);
926
+ const b = parseVersion(latest);
927
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
928
+ const av = a[i] ?? 0;
929
+ const bv = b[i] ?? 0;
930
+ if (av < bv) return true;
931
+ if (av > bv) return false;
932
+ }
933
+ return false;
934
+ }
935
+ async function getCurrentVersionFromPackageJson() {
936
+ try {
937
+ const [{ readFile }, pathMod, urlMod] = await Promise.all([
938
+ import("fs/promises"),
939
+ import("path"),
940
+ import("url")
941
+ ]);
942
+ const filePath = urlMod.fileURLToPath(import.meta.url);
943
+ const dir = pathMod.dirname(filePath);
944
+ const pkgPath = pathMod.resolve(dir, "../package.json");
945
+ const raw = await readFile(pkgPath, "utf8");
946
+ const parsed = JSON.parse(raw);
947
+ return typeof parsed.version === "string" ? parsed.version : null;
948
+ } catch {
949
+ return null;
950
+ }
951
+ }
952
+ async function fetchLatestVersion(url) {
953
+ try {
954
+ const res = await fetch(url, {
955
+ method: "GET",
956
+ headers: { Accept: "application/json" }
957
+ });
958
+ if (!res.ok) return null;
959
+ const json = await res.json().catch(() => null);
960
+ const v = json?.version;
961
+ return typeof v === "string" ? v : null;
962
+ } catch {
963
+ return null;
964
+ }
965
+ }
966
+ function latestUrlForPackage(pkg) {
967
+ return `https://registry.npmjs.org/${encodeURIComponent(pkg)}/latest`;
968
+ }
969
+ async function checkForSdkUpdate(options = {}) {
970
+ const pkg = options.packageName ?? DEFAULT_PKG;
971
+ const ttl = options.cacheTtlMs ?? DEFAULT_TTL;
972
+ const now = Date.now();
973
+ if (!options.force && cached && now - cached.at < ttl) {
974
+ return cached.info;
975
+ }
976
+ if (!options.force && inFlight) {
977
+ return inFlight;
978
+ }
979
+ const url = options.registryLatestUrl ?? latestUrlForPackage(pkg);
980
+ inFlight = (async () => {
981
+ const [current, latest] = await Promise.all([
982
+ getCurrentVersionFromPackageJson(),
983
+ fetchLatestVersion(url)
984
+ ]);
985
+ const updateAvailable = Boolean(current && latest) && isOutdated(current, latest);
986
+ const info = {
987
+ packageName: pkg,
988
+ currentVersion: current,
989
+ latestVersion: latest,
990
+ updateAvailable,
991
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
992
+ };
993
+ cached = { at: Date.now(), info };
994
+ inFlight = null;
995
+ if (updateAvailable && options.onUpdateAvailable) {
996
+ try {
997
+ options.onUpdateAvailable(info);
998
+ } catch {
999
+ }
1000
+ }
1001
+ return info;
1002
+ })();
1003
+ return inFlight;
1004
+ }
1005
+ function startSdkUpdateWatcher(options = {}) {
1006
+ if (watcherStarted) return;
1007
+ watcherStarted = true;
1008
+ const intervalMs = options.cacheTtlMs ?? DEFAULT_TTL;
1009
+ void checkForSdkUpdate({
1010
+ ...options,
1011
+ force: true,
1012
+ onUpdateAvailable: options.onUpdateAvailable ?? ((info) => {
1013
+ console.warn(
1014
+ `[mdp-sdk] Update available: ${info.packageName} ${info.currentVersion ?? "unknown"} -> ${info.latestVersion}. Run: npm i ${info.packageName}@latest`
1015
+ );
1016
+ })
1017
+ });
1018
+ const timer = setInterval(() => {
1019
+ void checkForSdkUpdate({
1020
+ ...options,
1021
+ force: true,
1022
+ onUpdateAvailable: options.onUpdateAvailable ?? ((info) => {
1023
+ console.warn(
1024
+ `[mdp-sdk] Update available: ${info.packageName} ${info.currentVersion ?? "unknown"} -> ${info.latestVersion}. Run: npm i ${info.packageName}@latest`
1025
+ );
1026
+ })
1027
+ });
1028
+ }, intervalMs);
1029
+ if (typeof timer.unref === "function") {
1030
+ timer.unref();
1031
+ }
1032
+ }
1033
+
911
1034
  // src/index.ts
912
1035
  var MDPAgentSDK = class _MDPAgentSDK {
913
1036
  http;
@@ -946,8 +1069,16 @@ var MDPAgentSDK = class _MDPAgentSDK {
946
1069
  static async createAuthenticated(config, signer) {
947
1070
  const sdk = new _MDPAgentSDK(config);
948
1071
  await sdk.auth.authenticate(signer);
1072
+ startSdkUpdateWatcher();
949
1073
  return sdk;
950
1074
  }
1075
+ /**
1076
+ * Check npm for a newer SDK version.
1077
+ * Does not install updates automatically.
1078
+ */
1079
+ static async checkForUpdates() {
1080
+ return checkForSdkUpdate();
1081
+ }
951
1082
  /**
952
1083
  * Create SDK instance with a private key (for automated agents)
953
1084
  * @param config - SDK configuration
@@ -172,6 +172,16 @@ Notes:
172
172
  - `eip8004AgentWallet` cannot be updated (executor wallet binding is immutable).
173
173
  - Each executor wallet can only be bound to one claimed agent profile.
174
174
 
175
+ ### SDK updates
176
+
177
+ The SDK does not auto-update itself. If a newer npm version exists, the SDK will warn at most once per 24 hours.
178
+
179
+ To update:
180
+
181
+ ```bash
182
+ npm i @moltdomesticproduct/mdp-sdk@latest
183
+ ```
184
+
175
185
  ### Self-register + claim flow (for agent runtimes)
176
186
 
177
187
  If you are an agent runtime registering on behalf of an owner wallet:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moltdomesticproduct/mdp-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "SDK for AI agents to interact with the MDP (Hire-A-AI) platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",