@abraca/mcp 1.1.2 → 1.3.4

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.
@@ -19452,6 +19452,7 @@ var AbracadabraMCPServer = class {
19452
19452
  this._statusClearTimer = null;
19453
19453
  this._typingInterval = null;
19454
19454
  this._lastChatChannel = null;
19455
+ this._signFn = null;
19455
19456
  this.config = config;
19456
19457
  this.client = new _abraca_dabra.AbracadabraClient({
19457
19458
  url: config.url,
@@ -19487,6 +19488,7 @@ var AbracadabraMCPServer = class {
19487
19488
  const keypair = await loadOrCreateKeypair(this.config.keyFile);
19488
19489
  this._userId = keypair.publicKeyB64;
19489
19490
  const signFn = (challenge) => Promise.resolve(signChallenge(challenge, keypair.privateKey));
19491
+ this._signFn = signFn;
19490
19492
  try {
19491
19493
  await this.client.loginWithKey(keypair.publicKeyB64, signFn);
19492
19494
  } catch (err) {
@@ -19547,6 +19549,11 @@ var AbracadabraMCPServer = class {
19547
19549
  this._rootDocId = docId;
19548
19550
  return existing;
19549
19551
  }
19552
+ if (!this.client.isTokenValid() && this._signFn && this._userId) {
19553
+ console.error("[abracadabra-mcp] JWT expired, re-authenticating...");
19554
+ await this.client.loginWithKey(this._userId, this._signFn);
19555
+ console.error("[abracadabra-mcp] Re-authenticated successfully");
19556
+ }
19550
19557
  const doc = new yjs.Doc({ guid: docId });
19551
19558
  const provider = new _abraca_dabra.AbracadabraProvider({
19552
19559
  name: docId,
@@ -19611,6 +19618,11 @@ var AbracadabraMCPServer = class {
19611
19618
  }
19612
19619
  const activeProvider = this._activeConnection?.provider;
19613
19620
  if (!activeProvider) throw new Error("Not connected. Call connect() first.");
19621
+ if (!this.client.isTokenValid() && this._signFn && this._userId) {
19622
+ console.error("[abracadabra-mcp] JWT expired, re-authenticating...");
19623
+ await this.client.loginWithKey(this._userId, this._signFn);
19624
+ console.error("[abracadabra-mcp] Re-authenticated successfully");
19625
+ }
19614
19626
  const childProvider = await activeProvider.loadChild(docId);
19615
19627
  await waitForSync(childProvider);
19616
19628
  childProvider.awareness.setLocalStateField("user", {
@@ -19883,6 +19895,9 @@ function docToSpaceMeta(doc) {
19883
19895
  //#endregion
19884
19896
  //#region packages/mcp/src/tools/tree.ts
19885
19897
  /**
19898
+ * Document tree tools — operate on the root Y.Doc's "doc-tree" Y.Map.
19899
+ */
19900
+ /**
19886
19901
  * Normalize a document ID so the hub/root doc ID is treated as the tree root (null).
19887
19902
  * This lets callers pass the hub doc_id from list_spaces as parentId/rootId
19888
19903
  * and get the expected root-level results instead of an empty set.
@@ -19891,9 +19906,15 @@ function normalizeRootId(id, server) {
19891
19906
  if (id == null) return null;
19892
19907
  return id === server.rootDocId ? null : id;
19893
19908
  }
19909
+ /** Safely read a tree map value, converting Y.Map to plain object if needed. */
19910
+ function toPlain(val) {
19911
+ return val instanceof yjs.Map ? val.toJSON() : val;
19912
+ }
19894
19913
  function readEntries$1(treeMap) {
19895
19914
  const entries = [];
19896
- treeMap.forEach((value, id) => {
19915
+ treeMap.forEach((raw, id) => {
19916
+ const value = toPlain(raw);
19917
+ if (typeof value !== "object" || value === null) return;
19897
19918
  entries.push({
19898
19919
  id,
19899
19920
  label: value.label || "Untitled",
@@ -20096,14 +20117,15 @@ function registerTreeTools(mcp, server) {
20096
20117
  text: "Not connected"
20097
20118
  }] };
20098
20119
  }
20099
- const entry = treeMap.get(id);
20100
- if (!entry) {
20120
+ const raw = treeMap.get(id);
20121
+ if (!raw) {
20101
20122
  server.setActiveToolCall(null);
20102
20123
  return { content: [{
20103
20124
  type: "text",
20104
20125
  text: `Document ${id} not found`
20105
20126
  }] };
20106
20127
  }
20128
+ const entry = toPlain(raw);
20107
20129
  treeMap.set(id, {
20108
20130
  ...entry,
20109
20131
  label,
@@ -20133,14 +20155,15 @@ function registerTreeTools(mcp, server) {
20133
20155
  text: "Not connected"
20134
20156
  }] };
20135
20157
  }
20136
- const entry = treeMap.get(id);
20137
- if (!entry) {
20158
+ const raw = treeMap.get(id);
20159
+ if (!raw) {
20138
20160
  server.setActiveToolCall(null);
20139
20161
  return { content: [{
20140
20162
  type: "text",
20141
20163
  text: `Document ${id} not found`
20142
20164
  }] };
20143
20165
  }
20166
+ const entry = toPlain(raw);
20144
20167
  treeMap.set(id, {
20145
20168
  ...entry,
20146
20169
  parentId: normalizeRootId(newParentId, server),
@@ -20173,8 +20196,9 @@ function registerTreeTools(mcp, server) {
20173
20196
  const now = Date.now();
20174
20197
  rootDoc.transact(() => {
20175
20198
  for (const nid of toDelete) {
20176
- const entry = treeMap.get(nid);
20177
- if (!entry) continue;
20199
+ const raw = treeMap.get(nid);
20200
+ if (!raw) continue;
20201
+ const entry = toPlain(raw);
20178
20202
  trashMap.set(nid, {
20179
20203
  label: entry.label || "Untitled",
20180
20204
  parentId: entry.parentId ?? null,
@@ -20209,14 +20233,15 @@ function registerTreeTools(mcp, server) {
20209
20233
  text: "Not connected"
20210
20234
  }] };
20211
20235
  }
20212
- const entry = treeMap.get(id);
20213
- if (!entry) {
20236
+ const raw = treeMap.get(id);
20237
+ if (!raw) {
20214
20238
  server.setActiveToolCall(null);
20215
20239
  return { content: [{
20216
20240
  type: "text",
20217
20241
  text: `Document ${id} not found`
20218
20242
  }] };
20219
20243
  }
20244
+ const entry = toPlain(raw);
20220
20245
  treeMap.set(id, {
20221
20246
  ...entry,
20222
20247
  type,
@@ -20257,11 +20282,12 @@ function registerTreeTools(mcp, server) {
20257
20282
  type: "text",
20258
20283
  text: "Not connected"
20259
20284
  }] };
20260
- const entry = treeMap.get(id);
20261
- if (!entry) return { content: [{
20285
+ const raw = treeMap.get(id);
20286
+ if (!raw) return { content: [{
20262
20287
  type: "text",
20263
20288
  text: `Document ${id} not found`
20264
20289
  }] };
20290
+ const entry = toPlain(raw);
20265
20291
  const newId = crypto.randomUUID();
20266
20292
  treeMap.set(newId, {
20267
20293
  ...entry,