@dreamcash-org/mcp 0.3.11 → 0.3.13

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/README.md CHANGED
@@ -140,6 +140,20 @@ your agent for. A key that is still there but can't be read (a locked keychain,
140
140
  another user) is not lost: the agent says how to make it readable, and asks
141
141
  for no link.
142
142
 
143
+ ### When its key runs out
144
+
145
+ A key trades on its own for the days picked when it was approved. Three days
146
+ before it runs out, the app sends a push and the agent's page shows
147
+ **Renew**, and the agent's status says so too. Renewing picks how long the
148
+ next key lasts (the last length by default) and never approves the old key
149
+ again: on its next call, the package makes a new key on the agent's machine,
150
+ kept where the old one is, and the main wallet's approval of it waits on the
151
+ agent's page, in the same place and with the same limits. The page shows the
152
+ new key's last 4 characters, and the agent says the same 4. Once approved,
153
+ the package signs with the new key, and the old one stops working at
154
+ Dreamcash. After a key runs out, the agent asks for each trade until it is
155
+ renewed the same way. Renewing needs version 0.3.13 or later of this package.
156
+
143
157
  ### When you disconnected it
144
158
 
145
159
  Once you disconnect the agent in the app, its next call to Dreamcash finds
@@ -707,7 +707,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
707
707
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
708
708
  THE SOFTWARE.
709
709
 
710
- ## @noble/hashes 1.8.0 (MIT)
710
+ ## @noble/hashes 2.4.0 (MIT)
711
711
 
712
712
  The MIT License (MIT)
713
713
 
@@ -731,7 +731,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
731
731
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
732
732
  THE SOFTWARE.
733
733
 
734
- ## @noble/hashes 2.4.0 (MIT)
734
+ ## @noble/hashes 1.8.0 (MIT)
735
735
 
736
736
  The MIT License (MIT)
737
737
 
@@ -21085,6 +21085,8 @@ var StdioServerTransport = class {
21085
21085
  // src/shared/aiAgent.ts
21086
21086
  var AI_REPLY_STYLE = "How to reply: lead with the answer in a line or two, in the user's own words, and add detail only when asked. No tables or extra sections for a simple question. Never show tool or field names, and skip exchange mechanics the user didn't ask about. Say once in a chat, not in each reply, that what you suggest is your own analysis, not advice from Dreamcash. A liquidation price over 90% away means the position practically can't be liquidated: say that, not the number.";
21087
21087
  var AI_CLIENT_NAME_MAX_LENGTH = 60;
21088
+ var keyAddressEnding = (address) => address.slice(-4).toLowerCase();
21089
+ var RENEW_KEY_META = "xyz.dreamcash/renew_key";
21088
21090
  var TRADE_REQUEST_TTL_MS = 15 * 60 * 1000;
21089
21091
  var AI_AGENT_SIGNATURE_HEADER = "x-dreamcash-agent-signature";
21090
21092
  var AI_AGENT_TIMESTAMP_HEADER = "x-dreamcash-agent-timestamp";
@@ -21115,7 +21117,7 @@ import { createHash } from "node:crypto";
21115
21117
  // package.json
21116
21118
  var package_default = {
21117
21119
  name: "@dreamcash-org/mcp",
21118
- version: "0.3.11",
21120
+ version: "0.3.13",
21119
21121
  description: "Connect your own AI agent to your Dreamcash account: it reads your account and trades, each trade confirmed by you or on its own within your limits.",
21120
21122
  keywords: [
21121
21123
  "mcp",
@@ -21240,7 +21242,9 @@ var agentApi = (baseUrl, account) => {
21240
21242
  clientName: clientName.slice(0, AI_CLIENT_NAME_MAX_LENGTH),
21241
21243
  limits
21242
21244
  }),
21243
- connectLink: (clientName, limits = {}) => call("POST", "/api/ai-agent/links/request", { clientName: clientName.slice(0, AI_CLIENT_NAME_MAX_LENGTH), limits })
21245
+ connectLink: (clientName, limits = {}) => call("POST", "/api/ai-agent/links/request", { clientName: clientName.slice(0, AI_CLIENT_NAME_MAX_LENGTH), limits }),
21246
+ renewKey: (newKey) => call("POST", "/api/ai-agent/key-renewal", { agentAddress: newKey }),
21247
+ renewalStatus: () => call("GET", "/api/ai-agent/key-renewal")
21244
21248
  };
21245
21249
  };
21246
21250
 
@@ -26106,6 +26110,7 @@ function privateKeyToAccount(privateKey, options = {}) {
26106
26110
  // src/agentKey.ts
26107
26111
  var defaultKeyFile = () => process.env.DREAMCASH_AGENT_KEY_FILE ?? join(homedir(), ".dreamcash", "agent-key.json");
26108
26112
  var pendingKeyFile = (file) => `${file}.pending`;
26113
+ var renewalKeyFile = (file) => `${file}.renewal`;
26109
26114
  var COMMAND_TIMEOUT_MS = 15000;
26110
26115
  var runCommand = (command, args, input = "") => new Promise((resolve, reject) => {
26111
26116
  const child = execFile(command, args, { timeout: COMMAND_TIMEOUT_MS, windowsHide: true }, (error2, stdout, stderr) => {
@@ -26392,18 +26397,28 @@ var newAgentAccount = async (file = defaultKeyFile(), store = KEY_FILE_ONLY) =>
26392
26397
  await forgetStoredCopy(replaced, store);
26393
26398
  return account;
26394
26399
  };
26395
- var adoptPendingKey = async (file, store = KEY_FILE_ONLY) => {
26396
- const pending = await readRecord(pendingKeyFile(file)).catch(() => {
26400
+ var adoptKeyFile = async (from, file, store) => {
26401
+ const adopted = await readRecord(from).catch(() => {
26397
26402
  return;
26398
26403
  });
26399
26404
  const replaced = await readRecord(file).catch(() => {
26400
26405
  return;
26401
26406
  });
26402
- await rename(pendingKeyFile(file), file);
26403
- if (replaced?.address !== pending?.address) {
26407
+ await rename(from, file);
26408
+ if (replaced?.address !== adopted?.address) {
26404
26409
  await forgetStoredCopy(replaced, store);
26405
26410
  }
26406
26411
  };
26412
+ var adoptPendingKey = (file, store = KEY_FILE_ONLY) => adoptKeyFile(pendingKeyFile(file), file, store);
26413
+ var adoptRenewalKey = (file, store = KEY_FILE_ONLY) => adoptKeyFile(renewalKeyFile(file), file, store);
26414
+ var forgetRenewalKey = async (file, store = KEY_FILE_ONLY) => {
26415
+ const renewal = renewalKeyFile(file);
26416
+ const record2 = await readRecord(renewal).catch(() => {
26417
+ return;
26418
+ });
26419
+ await rm(renewal, { force: true });
26420
+ await forgetStoredCopy(record2, store);
26421
+ };
26407
26422
 
26408
26423
  // src/shared/coinId.ts
26409
26424
  var yesCoinId = (outcomeId) => `#${outcomeId * 10}`;
@@ -48958,7 +48973,7 @@ var toolDefinitions_default = [
48958
48973
  {
48959
48974
  name: "get_status",
48960
48975
  title: "What you can do now",
48961
- description: "Your connection to this Dreamcash account: whether you can trade and how (each trade confirmed by the user, or on your own with your key, until when), your limits and what's left of them today (counting every chat that uses this connection, not only this one: get_my_trade_requests lists them), each request still open (its request_id for get_trade_request), and how to unlock more. Call it whenever you're unsure why something was refused.",
48976
+ description: "Your connection to this Dreamcash account: whether you can trade and how (each trade confirmed by the user, or on your own with your key, until when, and from 3 days before your key expires that it needs renewing in the app), your limits and what's left of them today (counting every chat that uses this connection, not only this one: get_my_trade_requests lists them), each request still open (its request_id for get_trade_request), and how to unlock more. Call it whenever you're unsure why something was refused. Also your own results, this AI's alone, as the user's app shows them on your page (this_ai_trading: trades, volume, fees, realized PnL after fees, and your open positions' unrealized PnL): call it when the user asks how you're doing, your PnL or ROI.",
48962
48977
  inputSchema: {
48963
48978
  type: "object",
48964
48979
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -49037,7 +49052,7 @@ var toolDefinitions_default = [
49037
49052
  {
49038
49053
  name: "get_trade_history",
49039
49054
  title: "Trade history and stats",
49040
- description: "The user's fills over the last N days with stats per wallet: volume, realized PnL, fees (dreamcashFeesUsd is Dreamcash's part of them, the rest Hyperliquid's), net PnL, win rate over closing trades, best and worst trade, liquidations, a per-market breakdown and the latest fills (a fill's realizedPnlUsd is before its feeUsd). Use it to report how their trading went.",
49055
+ description: "The whole account's fills over the last N days with stats per wallet: every trade on it (the user's own, every AI's, yours too), not only yours. Volume, realized PnL, fees (dreamcashFeesUsd is Dreamcash's part of them, the rest Hyperliquid's), net PnL, win rate over closing trades, best and worst trade, liquidations, a per-market breakdown and the latest fills (a fill's realizedPnlUsd is before its feeUsd). Use it to report how the account's trading went; your own results are get_status's this_ai_trading.",
49041
49056
  inputSchema: {
49042
49057
  type: "object",
49043
49058
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -49072,7 +49087,7 @@ var toolDefinitions_default = [
49072
49087
  {
49073
49088
  name: "get_performance",
49074
49089
  title: "Performance",
49075
- description: "Account value at the start and end of a period, PnL and traded volume, per wallet: Hyperliquid's own portfolio figures, as the Dreamcash app shows them.",
49090
+ description: "The whole account's value at the start of a period and now, its PnL and traded volume, per wallet: Hyperliquid's own portfolio figures, as the Dreamcash app shows them. They hold every trade on the account (the user's own, every AI's, yours too), funding and the price moves of everything held, not only your trading: your own results are get_status's this_ai_trading.",
49076
49091
  inputSchema: {
49077
49092
  type: "object",
49078
49093
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -50355,7 +50370,7 @@ var toolDefinitions_default = [
50355
50370
  {
50356
50371
  name: "request_autonomous_trading",
50357
50372
  title: "Trade without asking each time",
50358
- description: "Ask the user to let you trade their main wallet on your own: they approve your key (the one your Dreamcash MCP keeps on your machine; Dreamcash never sees it) once in their Dreamcash app, and your request_* calls then place trades at once. The key trades until the expiry the user approves (days from now); it can't withdraw or move funds out of Hyperliquid, but on Hyperliquid itself, outside Dreamcash and its limits, it can trade any market and deposit into HLP. Up to two AIs trade on their own on the main wallet: your key takes a free place, and when two other AIs hold both, the user picks one to replace in the app. It's the same approval the app already offers after pairing, with the limits you passed when you connected filled in: call it only if the user asks you to send it to their app, or names limits after you connected and before approving (pass them here and the app's setup starts from them). Never call it after they approved to send limits: the limits are part of the one approval, and after it they're the user's to change in the app.",
50373
+ description: "Ask the user to let you trade their main wallet on your own: they approve your key (the one your Dreamcash MCP keeps on your machine; Dreamcash never sees it) once in their Dreamcash app, and your request_* calls then place trades at once. The key trades until the expiry the user approves (days from now); it can't withdraw or move funds out of Hyperliquid, but on Hyperliquid itself, outside Dreamcash and its limits, it can trade any market and deposit into HLP. Up to two AIs trade on their own on the main wallet: your key takes a free place, and when two other AIs hold both, the user picks one to replace in the app. It's the same approval the app already offers after pairing, with the limits you passed when you connected filled in: call it only if the user asks you to send it to their app, or names limits after you connected and before approving (pass them here and the app's setup starts from them). Never call it after they approved to send limits: the limits are part of the one approval, and after it they're the user's to change in the app. Not for renewing a key they approved before: they tap Renew in the app, and this Dreamcash MCP makes a new key.",
50359
50374
  inputSchema: {
50360
50375
  type: "object",
50361
50376
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -50610,6 +50625,25 @@ var USER_APPROVES_KEY = {
50610
50625
  what_to_do: "The user approves it in their Dreamcash app, which got a push for it: tell them, then call get_trade_request with request_id.",
50611
50626
  can_retry: "after_user_action"
50612
50627
  };
50628
+ var KEY_RENEWED = {
50629
+ code: "key_renewed",
50630
+ what_happened: "The user approved this agent's new key while this call went out, signed by the key it replaced. Nothing was done.",
50631
+ what_to_do: "Call it again: this Dreamcash MCP signs with the new key now.",
50632
+ can_retry: "yes"
50633
+ };
50634
+ var renewalAsked = (keyEnding) => ({
50635
+ new_key_ending: keyEnding,
50636
+ what_to_do: "Pass tell_the_user on to the user once, now. Keep using Dreamcash meanwhile: the current key works until the new one is approved, and this Dreamcash MCP switches to it by itself.",
50637
+ tell_the_user: `I made a new key to renew my Dreamcash key. Approve it on my page in the Dreamcash app (Settings › Connected AI), and check the key shown there ends in ${keyEnding}.`
50638
+ });
50639
+ var asksToRenewKey = (result) => result._meta?.[RENEW_KEY_META] === true;
50640
+ var withoutRenewSignal = ({
50641
+ _meta,
50642
+ ...result
50643
+ }) => {
50644
+ const { [RENEW_KEY_META]: _signal, ...meta3 } = _meta ?? {};
50645
+ return Object.keys(meta3).length > 0 ? { ...result, _meta: meta3 } : result;
50646
+ };
50613
50647
  var unreachable = (error2) => ({
50614
50648
  code: "dreamcash_unreachable",
50615
50649
  what_happened: `Couldn't reach Dreamcash: ${messageOf(error2)}`,
@@ -50794,8 +50828,10 @@ var createDreamcashServer = ({
50794
50828
  instructions: INSTRUCTIONS
50795
50829
  });
50796
50830
  const pendingFile = pendingKeyFile(keyFile);
50831
+ const renewalFile = renewalKeyFile(keyFile);
50797
50832
  let account;
50798
50833
  let pairingKey;
50834
+ let renewalKey;
50799
50835
  let upstream;
50800
50836
  let toolsStale = true;
50801
50837
  let disconnected = false;
@@ -50877,6 +50913,49 @@ var createDreamcashServer = ({
50877
50913
  throw new KeyNotSaved(file, error2);
50878
50914
  }
50879
50915
  };
50916
+ const settleRenewal = async () => {
50917
+ renewalKey ??= await storedAgentAccount(renewalFile, keyStore).catch(() => {
50918
+ return;
50919
+ });
50920
+ if (!renewalKey)
50921
+ return;
50922
+ const status = await agentApi(apiUrl, renewalKey).renewalStatus().then((answer) => answer.status, () => {
50923
+ return;
50924
+ });
50925
+ if (status === "approved") {
50926
+ await adoptRenewalKey(keyFile, keyStore).catch((error2) => {
50927
+ throw new KeyNotSaved(keyFile, error2);
50928
+ });
50929
+ account = renewalKey;
50930
+ renewalKey = undefined;
50931
+ upstream = undefined;
50932
+ disconnected = false;
50933
+ } else if (status === "ended") {
50934
+ await forgetRenewalKey(keyFile, keyStore).catch(() => {});
50935
+ renewalKey = undefined;
50936
+ }
50937
+ return status;
50938
+ };
50939
+ const renewIfAsked = async (result, key) => {
50940
+ if (!asksToRenewKey(result))
50941
+ return result;
50942
+ let renewal;
50943
+ try {
50944
+ renewalKey ??= await freshAccount(renewalFile);
50945
+ await agentApi(apiUrl, key).renewKey(renewalKey.address);
50946
+ renewal = renewalAsked(keyAddressEnding(renewalKey.address));
50947
+ } catch (error2) {
50948
+ if (error2 instanceof AgentApiError) {
50949
+ await forgetRenewalKey(keyFile, keyStore).catch(() => {});
50950
+ renewalKey = undefined;
50951
+ }
50952
+ renewal = { error: guidanceFor(error2) };
50953
+ }
50954
+ return withoutRenewSignal({
50955
+ ...result,
50956
+ content: withField(result.content, "new_key", renewal)
50957
+ });
50958
+ };
50880
50959
  const finishPairing = async (key) => {
50881
50960
  await adopt(key);
50882
50961
  const client = await linked();
@@ -51021,6 +51100,9 @@ var createDreamcashServer = ({
51021
51100
  };
51022
51101
  };
51023
51102
  server.setRequestHandler("tools/list", async () => {
51103
+ await settleRenewal().catch(() => {
51104
+ return;
51105
+ });
51024
51106
  const tools = await linked().then((client) => client?.listTools()).then((listed) => listed?.tools).catch(async (error2) => {
51025
51107
  if (isUnauthorized(error2))
51026
51108
  await markDisconnected();
@@ -51041,28 +51123,33 @@ var createDreamcashServer = ({
51041
51123
  try {
51042
51124
  if (name === CONNECT_TOOL.name)
51043
51125
  return await connect(args);
51126
+ await settleRenewal();
51044
51127
  const client = await linked();
51045
- if (!client || !account) {
51128
+ const key = account;
51129
+ if (!client || !key) {
51046
51130
  return disconnected ? await approveByLink() : failure2(NOT_CONNECTED);
51047
51131
  }
51048
51132
  if (toolsStale)
51049
51133
  await toolsChanged();
51050
- const { result, toExecute, executed } = await callAndCarryOut(client, account, name, args);
51134
+ const { result, toExecute, executed } = await callAndCarryOut(client, key, name, args);
51051
51135
  const legs = toExecute && legsFromFill(toExecute.id, toExecute.asked, executed);
51052
51136
  if (!legs)
51053
- return result;
51054
- const legsSet = "problem" in legs ? { set: false, warning: legs.problem } : await callAndCarryOut(client, account, SET_LEGS_TOOL, legs.call).then((set) => legsSetBy(legs.call, set.result)).catch((error2) => ({
51137
+ return await renewIfAsked(result, key);
51138
+ const legsSet = "problem" in legs ? { set: false, warning: legs.problem } : await callAndCarryOut(client, key, SET_LEGS_TOOL, legs.call).then((set) => legsSetBy(legs.call, set.result)).catch((error2) => ({
51055
51139
  set: false,
51056
51140
  error: guidanceFor(error2),
51057
51141
  warning: LEGS_NOT_SET
51058
51142
  }));
51059
- return {
51143
+ return await renewIfAsked({
51060
51144
  ...result,
51061
51145
  content: withField(result.content, "legs_from_fill", legsSet)
51062
- };
51146
+ }, key);
51063
51147
  } catch (error2) {
51064
51148
  if (!isUnauthorized(error2))
51065
51149
  return failure2(guidanceFor(error2));
51150
+ const renewed = await settleRenewal().then((status) => status === "approved", () => false);
51151
+ if (renewed)
51152
+ return failure2(KEY_RENEWED);
51066
51153
  await markDisconnected();
51067
51154
  return approveByLink().catch((linkError) => failure2(guidanceFor(linkError)));
51068
51155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dreamcash-org/mcp",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Connect your own AI agent to your Dreamcash account: it reads your account and trades, each trade confirmed by you or on its own within your limits.",
5
5
  "keywords": [
6
6
  "mcp",