@trops/dash-core 0.1.15 → 0.1.16

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.
@@ -4135,7 +4135,7 @@ const {
4135
4135
  const appName$2 = "Dashboard";
4136
4136
  const configFilename$2 = "providers.json";
4137
4137
 
4138
- const providerController$1 = {
4138
+ const providerController$2 = {
4139
4139
  /**
4140
4140
  * saveProvider
4141
4141
  * Save a new provider with encrypted credentials
@@ -4395,7 +4395,7 @@ const providerController$1 = {
4395
4395
  },
4396
4396
  };
4397
4397
 
4398
- var providerController_1 = providerController$1;
4398
+ var providerController_1 = providerController$2;
4399
4399
 
4400
4400
  const { app: app$2 } = require$$0;
4401
4401
  const path$7 = require$$1$1;
@@ -5954,6 +5954,97 @@ const pluginController$1 = {
5954
5954
 
5955
5955
  var pluginController_1 = pluginController$1;
5956
5956
 
5957
+ /**
5958
+ * clientCache
5959
+ *
5960
+ * Generic provider client cache for the main process.
5961
+ * Caches API clients (e.g., algoliasearch, Stripe) by provider hash.
5962
+ * Factories are registered per provider type; credentials are resolved
5963
+ * from the encrypted store — renderer never sends credential fields.
5964
+ */
5965
+
5966
+ const providerController$1 = providerController_1;
5967
+
5968
+ const clients = new Map(); // hash → client
5969
+ const factories = new Map(); // providerType → factoryFn(credentials)
5970
+ const pendingClients = new Map(); // hash → Promise (dedup in-flight)
5971
+ const providerLookup = new Map(); // "appId:providerName" → hash (reverse lookup)
5972
+
5973
+ const clientCache$1 = {
5974
+ registerFactory(providerType, factoryFn) {
5975
+ factories.set(providerType, factoryFn);
5976
+ },
5977
+
5978
+ async getClient(providerHash, appId, providerName) {
5979
+ // Cache hit
5980
+ if (clients.has(providerHash)) {
5981
+ return clients.get(providerHash);
5982
+ }
5983
+
5984
+ // Dedup in-flight (same pattern as mcpController.pendingStarts)
5985
+ if (pendingClients.has(providerHash)) {
5986
+ return pendingClients.get(providerHash);
5987
+ }
5988
+
5989
+ const promise = this._resolve(providerHash, appId, providerName);
5990
+ pendingClients.set(providerHash, promise);
5991
+ try {
5992
+ return await promise;
5993
+ } finally {
5994
+ pendingClients.delete(providerHash);
5995
+ }
5996
+ },
5997
+
5998
+ async _resolve(providerHash, appId, providerName) {
5999
+ const result = providerController$1.getProvider(null, appId, providerName);
6000
+ if (result.error) throw new Error(result.message);
6001
+
6002
+ const { provider } = result;
6003
+ const factory = factories.get(provider.type);
6004
+ if (!factory) {
6005
+ throw new Error(`No client factory for type: ${provider.type}`);
6006
+ }
6007
+
6008
+ const client = factory(provider.credentials);
6009
+ clients.set(providerHash, client);
6010
+ providerLookup.set(`${appId}:${providerName}`, providerHash);
6011
+ console.log(
6012
+ `[clientCache] Created ${provider.type} client (hash: ${providerHash.slice(0, 8)}...)`
6013
+ );
6014
+ return client;
6015
+ },
6016
+
6017
+ invalidate(appId, providerName) {
6018
+ const lookupKey = `${appId}:${providerName}`;
6019
+ const hash = providerLookup.get(lookupKey);
6020
+ if (hash) {
6021
+ clients.delete(hash);
6022
+ providerLookup.delete(lookupKey);
6023
+ console.log(
6024
+ `[clientCache] Invalidated ${providerName} (hash: ${hash.slice(0, 8)}...)`
6025
+ );
6026
+ }
6027
+ },
6028
+
6029
+ invalidateAll() {
6030
+ const count = clients.size;
6031
+ clients.clear();
6032
+ providerLookup.clear();
6033
+ pendingClients.clear();
6034
+ console.log(
6035
+ `[clientCache] Invalidated all (${count} clients cleared)`
6036
+ );
6037
+ },
6038
+
6039
+ clear() {
6040
+ clients.clear();
6041
+ providerLookup.clear();
6042
+ pendingClients.clear();
6043
+ },
6044
+ };
6045
+
6046
+ var clientCache_1 = clientCache$1;
6047
+
5957
6048
  /**
5958
6049
  * Controller exports.
5959
6050
  */
@@ -8634,6 +8725,9 @@ const openaiController = openaiController_1;
8634
8725
  const menuItemsController = menuItemsController_1;
8635
8726
  const pluginController = pluginController_1;
8636
8727
 
8728
+ // --- Utils ---
8729
+ const clientCache = clientCache_1;
8730
+
8637
8731
  // --- Controller functions (flat, for convenient destructuring) ---
8638
8732
  const controllers = controller;
8639
8733
 
@@ -8713,6 +8807,9 @@ var electron = {
8713
8807
  // Factory
8714
8808
  createMainApi,
8715
8809
  defaultMainApi,
8810
+
8811
+ // Utils
8812
+ clientCache,
8716
8813
  };
8717
8814
 
8718
8815
  var index = /*@__PURE__*/getDefaultExportFromCjs(electron);