@unicitylabs/sphere-sdk 0.6.13 → 0.6.14

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.cts CHANGED
@@ -3519,6 +3519,12 @@ interface CommunicationsModuleConfig {
3519
3519
  maxPerConversation?: number;
3520
3520
  /** Enable read receipts */
3521
3521
  readReceipts?: boolean;
3522
+ /** Cache messages in memory and storage (default: true).
3523
+ * When false, DMs flow through onDirectMessage handlers and events
3524
+ * but are never stored. Useful for anonymous/ephemeral agents.
3525
+ * Note: deduplication is skipped when caching is disabled, so duplicate
3526
+ * events may occur if the relay delivers the same message twice. */
3527
+ cacheMessages?: boolean;
3522
3528
  }
3523
3529
  interface ConversationPage {
3524
3530
  messages: DirectMessage[];
@@ -4463,6 +4469,8 @@ interface SphereCreateOptions {
4463
4469
  groupChat?: GroupChatModuleConfig | boolean;
4464
4470
  /** Market module configuration. true = enable with defaults, object = custom config. */
4465
4471
  market?: MarketModuleConfig | boolean;
4472
+ /** Communications module configuration. */
4473
+ communications?: CommunicationsModuleConfig;
4466
4474
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
4467
4475
  password?: string;
4468
4476
  /**
@@ -4501,6 +4509,8 @@ interface SphereLoadOptions {
4501
4509
  groupChat?: GroupChatModuleConfig | boolean;
4502
4510
  /** Market module configuration. true = enable with defaults, object = custom config. */
4503
4511
  market?: MarketModuleConfig | boolean;
4512
+ /** Communications module configuration. */
4513
+ communications?: CommunicationsModuleConfig;
4504
4514
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
4505
4515
  password?: string;
4506
4516
  /**
@@ -4547,6 +4557,8 @@ interface SphereImportOptions {
4547
4557
  groupChat?: GroupChatModuleConfig | boolean;
4548
4558
  /** Market module configuration. true = enable with defaults, object = custom config. */
4549
4559
  market?: MarketModuleConfig | boolean;
4560
+ /** Communications module configuration. */
4561
+ communications?: CommunicationsModuleConfig;
4550
4562
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
4551
4563
  password?: string;
4552
4564
  /**
@@ -4623,6 +4635,8 @@ interface SphereInitOptions {
4623
4635
  * Without this, a fresh wallet starts from "now" and misses older DMs.
4624
4636
  */
4625
4637
  dmSince?: number;
4638
+ /** Communications module configuration. */
4639
+ communications?: CommunicationsModuleConfig;
4626
4640
  /** Enable debug logging (default: false) */
4627
4641
  debug?: boolean;
4628
4642
  /** Optional callback to report initialization progress steps */
@@ -4672,6 +4686,7 @@ declare class Sphere {
4672
4686
  private _l1Config;
4673
4687
  private _groupChatConfig;
4674
4688
  private _marketConfig;
4689
+ private _communicationsConfig;
4675
4690
  private eventHandlers;
4676
4691
  private _disabledProviders;
4677
4692
  private _providerEventCleanups;
package/dist/index.d.ts CHANGED
@@ -3519,6 +3519,12 @@ interface CommunicationsModuleConfig {
3519
3519
  maxPerConversation?: number;
3520
3520
  /** Enable read receipts */
3521
3521
  readReceipts?: boolean;
3522
+ /** Cache messages in memory and storage (default: true).
3523
+ * When false, DMs flow through onDirectMessage handlers and events
3524
+ * but are never stored. Useful for anonymous/ephemeral agents.
3525
+ * Note: deduplication is skipped when caching is disabled, so duplicate
3526
+ * events may occur if the relay delivers the same message twice. */
3527
+ cacheMessages?: boolean;
3522
3528
  }
3523
3529
  interface ConversationPage {
3524
3530
  messages: DirectMessage[];
@@ -4463,6 +4469,8 @@ interface SphereCreateOptions {
4463
4469
  groupChat?: GroupChatModuleConfig | boolean;
4464
4470
  /** Market module configuration. true = enable with defaults, object = custom config. */
4465
4471
  market?: MarketModuleConfig | boolean;
4472
+ /** Communications module configuration. */
4473
+ communications?: CommunicationsModuleConfig;
4466
4474
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
4467
4475
  password?: string;
4468
4476
  /**
@@ -4501,6 +4509,8 @@ interface SphereLoadOptions {
4501
4509
  groupChat?: GroupChatModuleConfig | boolean;
4502
4510
  /** Market module configuration. true = enable with defaults, object = custom config. */
4503
4511
  market?: MarketModuleConfig | boolean;
4512
+ /** Communications module configuration. */
4513
+ communications?: CommunicationsModuleConfig;
4504
4514
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
4505
4515
  password?: string;
4506
4516
  /**
@@ -4547,6 +4557,8 @@ interface SphereImportOptions {
4547
4557
  groupChat?: GroupChatModuleConfig | boolean;
4548
4558
  /** Market module configuration. true = enable with defaults, object = custom config. */
4549
4559
  market?: MarketModuleConfig | boolean;
4560
+ /** Communications module configuration. */
4561
+ communications?: CommunicationsModuleConfig;
4550
4562
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
4551
4563
  password?: string;
4552
4564
  /**
@@ -4623,6 +4635,8 @@ interface SphereInitOptions {
4623
4635
  * Without this, a fresh wallet starts from "now" and misses older DMs.
4624
4636
  */
4625
4637
  dmSince?: number;
4638
+ /** Communications module configuration. */
4639
+ communications?: CommunicationsModuleConfig;
4626
4640
  /** Enable debug logging (default: false) */
4627
4641
  debug?: boolean;
4628
4642
  /** Optional callback to report initialization progress steps */
@@ -4672,6 +4686,7 @@ declare class Sphere {
4672
4686
  private _l1Config;
4673
4687
  private _groupChatConfig;
4674
4688
  private _marketConfig;
4689
+ private _communicationsConfig;
4675
4690
  private eventHandlers;
4676
4691
  private _disabledProviders;
4677
4692
  private _providerEventCleanups;
package/dist/index.js CHANGED
@@ -11843,7 +11843,8 @@ var CommunicationsModule = class {
11843
11843
  autoSave: config?.autoSave ?? true,
11844
11844
  maxMessages: config?.maxMessages ?? 1e3,
11845
11845
  maxPerConversation: config?.maxPerConversation ?? 200,
11846
- readReceipts: config?.readReceipts ?? true
11846
+ readReceipts: config?.readReceipts ?? true,
11847
+ cacheMessages: config?.cacheMessages ?? true
11847
11848
  };
11848
11849
  }
11849
11850
  // ===========================================================================
@@ -11899,6 +11900,7 @@ var CommunicationsModule = class {
11899
11900
  * Falls back to legacy global 'direct_messages' key for migration.
11900
11901
  */
11901
11902
  async load() {
11903
+ if (!this.config.cacheMessages) return;
11902
11904
  this.ensureInitialized();
11903
11905
  this.messages.clear();
11904
11906
  let data = await this.deps.storage.get(STORAGE_KEYS_ADDRESS.MESSAGES);
@@ -11958,9 +11960,11 @@ var CommunicationsModule = class {
11958
11960
  timestamp: Date.now(),
11959
11961
  isRead: false
11960
11962
  };
11961
- this.messages.set(message.id, message);
11962
- if (this.config.autoSave) {
11963
- await this.save();
11963
+ if (this.config.cacheMessages) {
11964
+ this.messages.set(message.id, message);
11965
+ if (this.config.autoSave) {
11966
+ await this.save();
11967
+ }
11964
11968
  }
11965
11969
  return message;
11966
11970
  }
@@ -11999,7 +12003,7 @@ var CommunicationsModule = class {
11999
12003
  msg.isRead = true;
12000
12004
  }
12001
12005
  }
12002
- if (this.config.autoSave) {
12006
+ if (this.config.cacheMessages && this.config.autoSave) {
12003
12007
  await this.save();
12004
12008
  }
12005
12009
  if (this.config.readReceipts && this.deps?.transport.sendReadReceipt) {
@@ -12047,6 +12051,7 @@ var CommunicationsModule = class {
12047
12051
  * Delete all messages in a conversation with a peer
12048
12052
  */
12049
12053
  async deleteConversation(peerPubkey) {
12054
+ if (!this.config.cacheMessages) return;
12050
12055
  for (const [id, msg] of this.messages) {
12051
12056
  if (msg.senderPubkey === peerPubkey || msg.recipientPubkey === peerPubkey) {
12052
12057
  this.messages.delete(id);
@@ -12173,7 +12178,7 @@ var CommunicationsModule = class {
12173
12178
  handleIncomingMessage(msg) {
12174
12179
  const isHistorical = msg.timestamp < this.initializedAt;
12175
12180
  if (msg.isSelfWrap && msg.recipientTransportPubkey) {
12176
- if (this.messages.has(msg.id)) return;
12181
+ if (this.config.cacheMessages && this.messages.has(msg.id)) return;
12177
12182
  const message2 = {
12178
12183
  id: msg.id,
12179
12184
  senderPubkey: this.deps.identity.chainPubkey,
@@ -12183,9 +12188,11 @@ var CommunicationsModule = class {
12183
12188
  timestamp: msg.timestamp,
12184
12189
  isRead: isHistorical
12185
12190
  };
12186
- this.messages.set(message2.id, message2);
12191
+ if (this.config.cacheMessages) {
12192
+ this.messages.set(message2.id, message2);
12193
+ }
12187
12194
  this.deps.emitEvent("message:dm", message2);
12188
- if (this.config.autoSave) {
12195
+ if (this.config.cacheMessages && this.config.autoSave) {
12189
12196
  this.save();
12190
12197
  }
12191
12198
  return;
@@ -12196,7 +12203,7 @@ var CommunicationsModule = class {
12196
12203
  if (tp === ownChainPubkey) return;
12197
12204
  if (ownChainPubkey.length === 66 && (ownChainPubkey.startsWith("02") || ownChainPubkey.startsWith("03")) && tp === ownChainPubkey.slice(2)) return;
12198
12205
  }
12199
- if (this.messages.has(msg.id)) return;
12206
+ if (this.config.cacheMessages && this.messages.has(msg.id)) return;
12200
12207
  const message = {
12201
12208
  id: msg.id,
12202
12209
  senderPubkey: msg.senderTransportPubkey,
@@ -12206,7 +12213,9 @@ var CommunicationsModule = class {
12206
12213
  timestamp: msg.timestamp,
12207
12214
  isRead: isHistorical
12208
12215
  };
12209
- this.messages.set(message.id, message);
12216
+ if (this.config.cacheMessages) {
12217
+ this.messages.set(message.id, message);
12218
+ }
12210
12219
  this.deps.emitEvent("message:dm", message);
12211
12220
  for (const handler of this.dmHandlers) {
12212
12221
  try {
@@ -12215,10 +12224,12 @@ var CommunicationsModule = class {
12215
12224
  logger.error("Communications", "Handler error:", error);
12216
12225
  }
12217
12226
  }
12218
- if (this.config.autoSave) {
12219
- this.save();
12227
+ if (this.config.cacheMessages) {
12228
+ if (this.config.autoSave) {
12229
+ this.save();
12230
+ }
12231
+ this.pruneIfNeeded();
12220
12232
  }
12221
- this.pruneIfNeeded();
12222
12233
  }
12223
12234
  handleComposingIndicator(indicator) {
12224
12235
  const composing = {
@@ -16744,6 +16755,7 @@ var Sphere = class _Sphere {
16744
16755
  _l1Config;
16745
16756
  _groupChatConfig;
16746
16757
  _marketConfig;
16758
+ _communicationsConfig;
16747
16759
  // Events
16748
16760
  eventHandlers = /* @__PURE__ */ new Map();
16749
16761
  // Provider management
@@ -16753,7 +16765,7 @@ var Sphere = class _Sphere {
16753
16765
  // ===========================================================================
16754
16766
  // Constructor (private)
16755
16767
  // ===========================================================================
16756
- constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig) {
16768
+ constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig, communicationsConfig) {
16757
16769
  this._storage = storage;
16758
16770
  this._transport = transport;
16759
16771
  this._oracle = oracle;
@@ -16764,8 +16776,9 @@ var Sphere = class _Sphere {
16764
16776
  this._l1Config = l1Config;
16765
16777
  this._groupChatConfig = groupChatConfig;
16766
16778
  this._marketConfig = marketConfig;
16779
+ this._communicationsConfig = communicationsConfig;
16767
16780
  this._payments = createPaymentsModule({ l1: l1Config });
16768
- this._communications = createCommunicationsModule();
16781
+ this._communications = createCommunicationsModule(communicationsConfig);
16769
16782
  this._groupChat = groupChatConfig ? createGroupChatModule(groupChatConfig) : null;
16770
16783
  this._market = marketConfig ? createMarketModule(marketConfig) : null;
16771
16784
  }
@@ -16953,7 +16966,8 @@ var Sphere = class _Sphere {
16953
16966
  options.l1,
16954
16967
  options.price,
16955
16968
  groupChatConfig,
16956
- marketConfig
16969
+ marketConfig,
16970
+ options.communications
16957
16971
  );
16958
16972
  sphere._password = options.password ?? null;
16959
16973
  progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
@@ -17011,7 +17025,8 @@ var Sphere = class _Sphere {
17011
17025
  options.l1,
17012
17026
  options.price,
17013
17027
  groupChatConfig,
17014
- marketConfig
17028
+ marketConfig,
17029
+ options.communications
17015
17030
  );
17016
17031
  sphere._password = options.password ?? null;
17017
17032
  if (!options.storage.isConnected()) {
@@ -17089,7 +17104,8 @@ var Sphere = class _Sphere {
17089
17104
  options.l1,
17090
17105
  options.price,
17091
17106
  groupChatConfig,
17092
- marketConfig
17107
+ marketConfig,
17108
+ options.communications
17093
17109
  );
17094
17110
  sphere._password = options.password ?? null;
17095
17111
  progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
@@ -18155,7 +18171,7 @@ var Sphere = class _Sphere {
18155
18171
  addressTransport.setFallbackDmSince(this._dmSince);
18156
18172
  }
18157
18173
  const payments = createPaymentsModule({ l1: this._l1Config });
18158
- const communications = createCommunicationsModule();
18174
+ const communications = createCommunicationsModule(this._communicationsConfig);
18159
18175
  const groupChat = this._groupChatConfig ? createGroupChatModule(this._groupChatConfig) : null;
18160
18176
  const market = this._marketConfig ? createMarketModule(this._marketConfig) : null;
18161
18177
  payments.initialize({