roboto-js 1.6.18 → 1.7.1

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.
@@ -13,12 +13,19 @@ var _lodash = _interopRequireDefault(require("lodash"));
13
13
  var _idb = require("idb");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
15
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
22
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
23
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
20
24
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
25
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
26
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
27
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
28
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
22
29
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
30
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
24
31
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -36,6 +43,15 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
36
43
  localStorageAdaptor = _ref$localStorageAdap === void 0 ? null : _ref$localStorageAdap;
37
44
  _classCallCheck(this, RbtApi);
38
45
  this.websocketClient = null;
46
+
47
+ // Object cache for sharing instances across multiple load() calls
48
+ this._objectCache = new Map();
49
+
50
+ // Track pending requests to prevent duplicate loads
51
+ this._pendingLoads = new Map();
52
+
53
+ // Track what we've already logged to reduce console spam
54
+ this._loggedCacheEvents = new Set();
39
55
  this.axios = _axios["default"].create({
40
56
  baseURL: baseUrl,
41
57
  headers: {
@@ -60,10 +76,35 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
60
76
  }
61
77
  };
62
78
  }
79
+
80
+ // Synchronous browser hydration: set auth header and in-memory user immediately
81
+ if (typeof localStorage !== 'undefined') {
82
+ try {
83
+ var token = localStorage.getItem('authtoken');
84
+ if (token) {
85
+ this.authtoken = token;
86
+ this.axios.defaults.headers.common['authtoken'] = token;
87
+ }
88
+ } catch (_unused) {}
89
+ try {
90
+ var cachedUser = localStorage.getItem('rbtUser');
91
+ if (cachedUser) {
92
+ var parsed = JSON.parse(cachedUser);
93
+ if (parsed && parsed.id) {
94
+ this.currentUser = new _rbt_user["default"]({
95
+ id: parsed.id
96
+ }, this.axios);
97
+ this.currentUser.setData(parsed);
98
+ }
99
+ }
100
+ } catch (_unused2) {}
101
+ }
63
102
  this.localDb = null;
64
103
  this.iac_session = null;
65
104
  this.appServiceHost = baseUrl;
66
105
  this.requestCache = {};
106
+ this._loadCurrentUserPromise = null;
107
+ this._loadCurrentUserExtendedPromise = null;
67
108
 
68
109
  // Use the storageAdaptor to get the authToken, if available
69
110
  this.initAuthToken(authtoken);
@@ -72,21 +113,104 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
72
113
  _createClass(RbtApi, [{
73
114
  key: "getWebSocketClient",
74
115
  value: function getWebSocketClient() {
75
- if (this.websocketClient) return this.websocketClient;
116
+ // Reuse existing WebSocket if it's OPEN or CONNECTING (to prevent race condition)
117
+ if (this.websocketClient && (this.websocketClient.readyState === WebSocket.OPEN || this.websocketClient.readyState === WebSocket.CONNECTING)) {
118
+ return this.websocketClient;
119
+ }
76
120
  var baseUrl = this.axios.defaults.baseURL;
77
121
  var wsProtocol = baseUrl.startsWith('https') ? 'wss://' : 'ws://';
78
122
  var wsUrl = baseUrl.replace(/^https?:\/\//, wsProtocol);
123
+ console.log('[RbtApi] Creating new WebSocket connection to:', wsUrl + '/realtime');
79
124
  this.websocketClient = new WebSocket("".concat(wsUrl, "/realtime"));
80
- this.websocketClient.onopen = function () {
125
+ this._setupWebSocketHandlers(this.websocketClient);
126
+ return this.websocketClient;
127
+ }
128
+ }, {
129
+ key: "_setupWebSocketHandlers",
130
+ value: function _setupWebSocketHandlers(ws) {
131
+ var _this = this;
132
+ ws.onopen = function () {
81
133
  console.log('[RbtApi] WebSocket connected.');
134
+ _this._wsReconnectAttempts = 0;
135
+ _this._wsConnected = true;
136
+
137
+ // Re-subscribe to all objects that were previously subscribed
138
+ if (_this._wsSubscriptions) {
139
+ var _iterator = _createForOfIteratorHelper(_this._wsSubscriptions),
140
+ _step;
141
+ try {
142
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
143
+ var objectId = _step.value;
144
+ ws.send(JSON.stringify({
145
+ type: 'subscribe',
146
+ objectId: objectId
147
+ }));
148
+ }
149
+ } catch (err) {
150
+ _iterator.e(err);
151
+ } finally {
152
+ _iterator.f();
153
+ }
154
+ }
82
155
  };
83
- this.websocketClient.onclose = function () {
84
- console.warn('[RbtApi] WebSocket closed.');
156
+ ws.onclose = function (event) {
157
+ console.warn('[RbtApi] WebSocket closed:', event.code, event.reason);
158
+ _this._wsConnected = false;
159
+
160
+ // Attempt reconnection with exponential backoff
161
+ if (!_this._wsManualClose && _this._wsReconnectAttempts < 5) {
162
+ var delay = Math.min(1000 * Math.pow(2, _this._wsReconnectAttempts), 30000);
163
+ console.log("[RbtApi] Attempting reconnection in ".concat(delay, "ms (attempt ").concat(_this._wsReconnectAttempts + 1, "/5)"));
164
+ setTimeout(function () {
165
+ _this._wsReconnectAttempts++;
166
+ _this.websocketClient = null; // Clear the old connection
167
+ _this.getWebSocketClient(); // Create new connection
168
+ }, delay);
169
+ }
85
170
  };
86
- this.websocketClient.onerror = function (err) {
87
- console.error('[RbtApi] WebSocket error:', err.message || err);
171
+ ws.onerror = function (err) {
172
+ console.error('[RbtApi] WebSocket error:', err);
173
+ _this._wsConnected = false;
88
174
  };
89
- return this.websocketClient;
175
+
176
+ // Handle ping/pong for keep-alive
177
+ ws.addEventListener('ping', function () {
178
+ if (ws.readyState === WebSocket.OPEN) {
179
+ ws.pong();
180
+ }
181
+ });
182
+
183
+ // Initialize connection tracking
184
+ this._wsReconnectAttempts = this._wsReconnectAttempts || 0;
185
+ this._wsConnected = false;
186
+ this._wsManualClose = false;
187
+ this._wsSubscriptions = this._wsSubscriptions || new Set();
188
+ }
189
+
190
+ // Method to track subscriptions for reconnection
191
+ }, {
192
+ key: "_trackSubscription",
193
+ value: function _trackSubscription(objectId) {
194
+ if (!this._wsSubscriptions) this._wsSubscriptions = new Set();
195
+ this._wsSubscriptions.add(objectId);
196
+ }
197
+ }, {
198
+ key: "_untrackSubscription",
199
+ value: function _untrackSubscription(objectId) {
200
+ if (this._wsSubscriptions) {
201
+ this._wsSubscriptions["delete"](objectId);
202
+ }
203
+ }
204
+
205
+ // Method to gracefully close WebSocket
206
+ }, {
207
+ key: "closeWebSocket",
208
+ value: function closeWebSocket() {
209
+ if (this.websocketClient) {
210
+ this._wsManualClose = true;
211
+ this.websocketClient.close();
212
+ this.websocketClient = null;
213
+ }
90
214
  }
91
215
  }, {
92
216
  key: "initAuthToken",
@@ -244,7 +368,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
244
368
  key: "login",
245
369
  value: (function () {
246
370
  var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
247
- var response;
371
+ var response, _this$iac_session;
248
372
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
249
373
  while (1) switch (_context5.prev = _context5.next) {
250
374
  case 0:
@@ -272,22 +396,29 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
272
396
  this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
273
397
  this.authtoken = response.data.authToken;
274
398
  if (!this.localStorageAdaptor) {
275
- _context5.next = 13;
399
+ _context5.next = 16;
276
400
  break;
277
401
  }
278
402
  _context5.next = 13;
279
403
  return this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
280
404
  case 13:
281
- return _context5.abrupt("return", response.data);
405
+ if (!((_this$iac_session = this.iac_session) !== null && _this$iac_session !== void 0 && _this$iac_session.user)) {
406
+ _context5.next = 16;
407
+ break;
408
+ }
409
+ _context5.next = 16;
410
+ return this.localStorageAdaptor.setItem('rbtUser', JSON.stringify(this.iac_session.user));
282
411
  case 16:
283
- _context5.prev = 16;
412
+ return _context5.abrupt("return", response.data);
413
+ case 19:
414
+ _context5.prev = 19;
284
415
  _context5.t0 = _context5["catch"](0);
285
416
  this._handleError(_context5.t0);
286
- case 19:
417
+ case 22:
287
418
  case "end":
288
419
  return _context5.stop();
289
420
  }
290
- }, _callee5, this, [[0, 16]]);
421
+ }, _callee5, this, [[0, 19]]);
291
422
  }));
292
423
  function login(_x4) {
293
424
  return _login.apply(this, arguments);
@@ -402,58 +533,91 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
402
533
  }, {
403
534
  key: "loadCurrentUser",
404
535
  value: function () {
405
- var _loadCurrentUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
406
- var response, _response$user;
407
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
408
- while (1) switch (_context8.prev = _context8.next) {
536
+ var _loadCurrentUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
537
+ var _this2 = this;
538
+ var result;
539
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
540
+ while (1) switch (_context9.prev = _context9.next) {
409
541
  case 0:
410
- _context8.prev = 0;
411
- if (!this.currentUser) {
412
- _context8.next = 3;
542
+ _context9.prev = 0;
543
+ if (!this._loadCurrentUserPromise) {
544
+ _context9.next = 3;
413
545
  break;
414
546
  }
415
- return _context8.abrupt("return", this.currentUser);
547
+ return _context9.abrupt("return", this._loadCurrentUserPromise);
416
548
  case 3:
417
- if (!this.apikey) {
418
- _context8.next = 7;
549
+ if (!this.currentUser) {
550
+ _context9.next = 5;
419
551
  break;
420
552
  }
421
- return _context8.abrupt("return", null);
422
- case 7:
423
- if (!this.authtoken) {
424
- _context8.next = 17;
553
+ return _context9.abrupt("return", this.currentUser);
554
+ case 5:
555
+ if (!this.apikey) {
556
+ _context9.next = 9;
425
557
  break;
426
558
  }
427
- _context8.next = 10;
428
- return this.refreshAuthToken(this.authtoken);
429
- case 10:
430
- response = _context8.sent;
431
- if (response) {
432
- _context8.next = 13;
559
+ return _context9.abrupt("return", null);
560
+ case 9:
561
+ if (!this.authtoken) {
562
+ _context9.next = 18;
433
563
  break;
434
564
  }
435
- return _context8.abrupt("return", null);
565
+ this._loadCurrentUserPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
566
+ var response, _response$user;
567
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
568
+ while (1) switch (_context8.prev = _context8.next) {
569
+ case 0:
570
+ _context8.next = 2;
571
+ return _this2.refreshAuthToken(_this2.authtoken);
572
+ case 2:
573
+ response = _context8.sent;
574
+ if (response) {
575
+ _context8.next = 5;
576
+ break;
577
+ }
578
+ return _context8.abrupt("return", null);
579
+ case 5:
580
+ if (!(response !== null && response !== void 0 && response.user)) {
581
+ _context8.next = 11;
582
+ break;
583
+ }
584
+ _this2.currentUser = new _rbt_user["default"]({
585
+ id: response === null || response === void 0 || (_response$user = response.user) === null || _response$user === void 0 ? void 0 : _response$user.id
586
+ }, _this2.axios);
587
+ _this2.currentUser.setData(response.user);
588
+ if (!_this2.localStorageAdaptor) {
589
+ _context8.next = 11;
590
+ break;
591
+ }
592
+ _context8.next = 11;
593
+ return _this2.localStorageAdaptor.setItem('rbtUser', JSON.stringify(response.user));
594
+ case 11:
595
+ return _context8.abrupt("return", _this2.currentUser);
596
+ case 12:
597
+ case "end":
598
+ return _context8.stop();
599
+ }
600
+ }, _callee8);
601
+ }))();
602
+ _context9.next = 13;
603
+ return this._loadCurrentUserPromise;
436
604
  case 13:
437
- if (response !== null && response !== void 0 && response.user) {
438
- this.currentUser = new _rbt_user["default"]({
439
- id: response === null || response === void 0 || (_response$user = response.user) === null || _response$user === void 0 ? void 0 : _response$user.id
440
- }, this.axios);
441
- this.currentUser.setData(response.user);
442
- }
443
- return _context8.abrupt("return", this.currentUser);
444
- case 17:
445
- this.currentUser = null;
605
+ result = _context9.sent;
606
+ this._loadCurrentUserPromise = null;
607
+ return _context9.abrupt("return", result);
446
608
  case 18:
447
- return _context8.abrupt("return", null);
448
- case 21:
449
- _context8.prev = 21;
450
- _context8.t0 = _context8["catch"](0);
451
- return _context8.abrupt("return", this._handleError(_context8.t0));
452
- case 24:
609
+ this.currentUser = null;
610
+ case 19:
611
+ return _context9.abrupt("return", null);
612
+ case 22:
613
+ _context9.prev = 22;
614
+ _context9.t0 = _context9["catch"](0);
615
+ return _context9.abrupt("return", this._handleError(_context9.t0));
616
+ case 25:
453
617
  case "end":
454
- return _context8.stop();
618
+ return _context9.stop();
455
619
  }
456
- }, _callee8, this, [[0, 21]]);
620
+ }, _callee9, this, [[0, 22]]);
457
621
  }));
458
622
  function loadCurrentUser() {
459
623
  return _loadCurrentUser.apply(this, arguments);
@@ -463,35 +627,35 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
463
627
  }, {
464
628
  key: "confirmUserEmail",
465
629
  value: function () {
466
- var _confirmUserEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(confirmCode) {
630
+ var _confirmUserEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(confirmCode) {
467
631
  var params, response;
468
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
469
- while (1) switch (_context9.prev = _context9.next) {
632
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
633
+ while (1) switch (_context10.prev = _context10.next) {
470
634
  case 0:
471
635
  params = {
472
636
  emailConfirmCode: confirmCode
473
637
  };
474
- _context9.prev = 1;
475
- _context9.next = 4;
638
+ _context10.prev = 1;
639
+ _context10.next = 4;
476
640
  return this.axios.post('/user_service/confirmUserEmail', [params]);
477
641
  case 4:
478
- response = _context9.sent;
642
+ response = _context10.sent;
479
643
  if (!(response.data.ok === false)) {
480
- _context9.next = 7;
644
+ _context10.next = 7;
481
645
  break;
482
646
  }
483
- return _context9.abrupt("return", this._handleError(response));
647
+ return _context10.abrupt("return", this._handleError(response));
484
648
  case 7:
485
- return _context9.abrupt("return", response.data);
649
+ return _context10.abrupt("return", response.data);
486
650
  case 10:
487
- _context9.prev = 10;
488
- _context9.t0 = _context9["catch"](1);
489
- return _context9.abrupt("return", this._handleError(_context9.t0));
651
+ _context10.prev = 10;
652
+ _context10.t0 = _context10["catch"](1);
653
+ return _context10.abrupt("return", this._handleError(_context10.t0));
490
654
  case 13:
491
655
  case "end":
492
- return _context9.stop();
656
+ return _context10.stop();
493
657
  }
494
- }, _callee9, this, [[1, 10]]);
658
+ }, _callee10, this, [[1, 10]]);
495
659
  }));
496
660
  function confirmUserEmail(_x6) {
497
661
  return _confirmUserEmail.apply(this, arguments);
@@ -501,27 +665,53 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
501
665
  }, {
502
666
  key: "loadCurrentUserExtended",
503
667
  value: function () {
504
- var _loadCurrentUserExtended = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
505
- var currentUser;
506
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
507
- while (1) switch (_context10.prev = _context10.next) {
668
+ var _loadCurrentUserExtended = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
669
+ var _this3 = this;
670
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
671
+ while (1) switch (_context12.prev = _context12.next) {
508
672
  case 0:
509
- _context10.next = 2;
510
- return this.loadCurrentUser();
511
- case 2:
512
- currentUser = _context10.sent;
513
- if (!currentUser) {
514
- _context10.next = 7;
673
+ if (!this._loadCurrentUserExtendedPromise) {
674
+ _context12.next = 2;
515
675
  break;
516
676
  }
517
- return _context10.abrupt("return", this.loadUser(currentUser.id));
677
+ return _context12.abrupt("return", this._loadCurrentUserExtendedPromise);
678
+ case 2:
679
+ this._loadCurrentUserExtendedPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
680
+ var currentUser;
681
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
682
+ while (1) switch (_context11.prev = _context11.next) {
683
+ case 0:
684
+ _context11.next = 2;
685
+ return _this3.loadCurrentUser();
686
+ case 2:
687
+ currentUser = _context11.sent;
688
+ if (!currentUser) {
689
+ _context11.next = 7;
690
+ break;
691
+ }
692
+ return _context11.abrupt("return", _this3.loadUser(currentUser.id));
693
+ case 7:
694
+ return _context11.abrupt("return", null);
695
+ case 8:
696
+ case "end":
697
+ return _context11.stop();
698
+ }
699
+ }, _callee11);
700
+ }))();
701
+ _context12.prev = 3;
702
+ _context12.next = 6;
703
+ return this._loadCurrentUserExtendedPromise;
704
+ case 6:
705
+ return _context12.abrupt("return", _context12.sent);
518
706
  case 7:
519
- return _context10.abrupt("return", null);
520
- case 8:
707
+ _context12.prev = 7;
708
+ this._loadCurrentUserExtendedPromise = null;
709
+ return _context12.finish(7);
710
+ case 10:
521
711
  case "end":
522
- return _context10.stop();
712
+ return _context12.stop();
523
713
  }
524
- }, _callee10, this);
714
+ }, _callee12, this, [[3,, 7, 10]]);
525
715
  }));
526
716
  function loadCurrentUserExtended() {
527
717
  return _loadCurrentUserExtended.apply(this, arguments);
@@ -531,34 +721,64 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
531
721
  }, {
532
722
  key: "loadUser",
533
723
  value: function () {
534
- var _loadUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(userId) {
535
- var params, _response$data, response, userData, User;
536
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
537
- while (1) switch (_context11.prev = _context11.next) {
724
+ var _loadUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(userId) {
725
+ var _this4 = this;
726
+ var params, cacheKey, now, existing, p;
727
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
728
+ while (1) switch (_context14.prev = _context14.next) {
538
729
  case 0:
539
730
  params = {
540
731
  id: userId
541
732
  };
542
- _context11.prev = 1;
543
- _context11.next = 4;
544
- return this.axios.post('/user_service/loadUser', [params]);
545
- case 4:
546
- response = _context11.sent;
547
- userData = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.user;
548
- User = new _rbt_user["default"]({
549
- id: userData.id
550
- }, this.axios);
551
- User.setData(userData);
552
- return _context11.abrupt("return", User);
733
+ cacheKey = "loadUser:".concat(userId);
734
+ now = Date.now();
735
+ existing = this.requestCache[cacheKey];
736
+ if (!(existing && now - existing.time < 10000)) {
737
+ _context14.next = 6;
738
+ break;
739
+ }
740
+ return _context14.abrupt("return", existing.val);
741
+ case 6:
742
+ _context14.prev = 6;
743
+ p = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
744
+ var _response$data;
745
+ var response, userData, User;
746
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
747
+ while (1) switch (_context13.prev = _context13.next) {
748
+ case 0:
749
+ _context13.next = 2;
750
+ return _this4.axios.post('/user_service/loadUser', [params]);
751
+ case 2:
752
+ response = _context13.sent;
753
+ userData = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.user;
754
+ User = new _rbt_user["default"]({
755
+ id: userData.id
756
+ }, _this4.axios);
757
+ User.setData(userData);
758
+ return _context13.abrupt("return", User);
759
+ case 7:
760
+ case "end":
761
+ return _context13.stop();
762
+ }
763
+ }, _callee13);
764
+ }))();
765
+ this.requestCache[cacheKey] = {
766
+ val: p,
767
+ time: now
768
+ };
769
+ _context14.next = 11;
770
+ return p;
553
771
  case 11:
554
- _context11.prev = 11;
555
- _context11.t0 = _context11["catch"](1);
556
- return _context11.abrupt("return", this._handleError(_context11.t0));
772
+ return _context14.abrupt("return", _context14.sent);
557
773
  case 14:
774
+ _context14.prev = 14;
775
+ _context14.t0 = _context14["catch"](6);
776
+ return _context14.abrupt("return", this._handleError(_context14.t0));
777
+ case 17:
558
778
  case "end":
559
- return _context11.stop();
779
+ return _context14.stop();
560
780
  }
561
- }, _callee11, this, [[1, 11]]);
781
+ }, _callee14, this, [[6, 14]]);
562
782
  }));
563
783
  function loadUser(_x7) {
564
784
  return _loadUser.apply(this, arguments);
@@ -568,52 +788,52 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
568
788
  }, {
569
789
  key: "refreshAuthToken",
570
790
  value: function () {
571
- var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(authtoken) {
791
+ var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(authtoken) {
572
792
  var promise, response;
573
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
574
- while (1) switch (_context12.prev = _context12.next) {
793
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
794
+ while (1) switch (_context15.prev = _context15.next) {
575
795
  case 0:
576
796
  if (this.appServiceHost) {
577
- _context12.next = 3;
797
+ _context15.next = 3;
578
798
  break;
579
799
  }
580
800
  console.warn('RBTTOK not initialized');
581
- return _context12.abrupt("return", false);
801
+ return _context15.abrupt("return", false);
582
802
  case 3:
583
803
  if (!this.requestCache[authtoken]) {
584
- _context12.next = 5;
804
+ _context15.next = 5;
585
805
  break;
586
806
  }
587
- return _context12.abrupt("return", this.requestCache[authtoken]);
807
+ return _context15.abrupt("return", this.requestCache[authtoken]);
588
808
  case 5:
589
- _context12.prev = 5;
809
+ _context15.prev = 5;
590
810
  //console.log('RBTTOK Req', authtoken);
591
811
  // Create a new promise for the token refresh and store it in the cache
592
812
  promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
593
813
  this.requestCache[authtoken] = promise;
594
814
 
595
815
  // Await the promise to get the response
596
- _context12.next = 10;
816
+ _context15.next = 10;
597
817
  return promise;
598
818
  case 10:
599
- response = _context12.sent;
819
+ response = _context15.sent;
600
820
  //console.log('RBTTOK Response ',response);
601
821
  // Once the promise resolves, delete it from the cache to allow future refreshes
602
822
  delete this.requestCache[authtoken];
603
823
 
604
824
  // Return the response data
605
- return _context12.abrupt("return", response.data);
825
+ return _context15.abrupt("return", response.data);
606
826
  case 15:
607
- _context12.prev = 15;
608
- _context12.t0 = _context12["catch"](5);
827
+ _context15.prev = 15;
828
+ _context15.t0 = _context15["catch"](5);
609
829
  // On error, remove the cached promise to allow retries
610
830
  delete this.requestCache[authtoken];
611
- this._handleError(_context12.t0);
831
+ this._handleError(_context15.t0);
612
832
  case 19:
613
833
  case "end":
614
- return _context12.stop();
834
+ return _context15.stop();
615
835
  }
616
- }, _callee12, this, [[5, 15]]);
836
+ }, _callee15, this, [[5, 15]]);
617
837
  }));
618
838
  function refreshAuthToken(_x8) {
619
839
  return _refreshAuthToken.apply(this, arguments);
@@ -646,31 +866,31 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
646
866
  }, {
647
867
  key: "registerUser",
648
868
  value: function () {
649
- var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
869
+ var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
650
870
  var dataHash,
651
871
  response,
652
872
  record,
653
- _args13 = arguments;
654
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
655
- while (1) switch (_context13.prev = _context13.next) {
873
+ _args16 = arguments;
874
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
875
+ while (1) switch (_context16.prev = _context16.next) {
656
876
  case 0:
657
- dataHash = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
658
- _context13.prev = 1;
659
- _context13.next = 4;
877
+ dataHash = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {};
878
+ _context16.prev = 1;
879
+ _context16.next = 4;
660
880
  return this.axios.post('/user_service/registerUser', [dataHash]);
661
881
  case 4:
662
- response = _context13.sent;
882
+ response = _context16.sent;
663
883
  record = response.data;
664
- return _context13.abrupt("return", new _rbt_user["default"](record, this.axios));
884
+ return _context16.abrupt("return", new _rbt_user["default"](record, this.axios));
665
885
  case 9:
666
- _context13.prev = 9;
667
- _context13.t0 = _context13["catch"](1);
668
- return _context13.abrupt("return", this._handleError(_context13.t0));
886
+ _context16.prev = 9;
887
+ _context16.t0 = _context16["catch"](1);
888
+ return _context16.abrupt("return", this._handleError(_context16.t0));
669
889
  case 12:
670
890
  case "end":
671
- return _context13.stop();
891
+ return _context16.stop();
672
892
  }
673
- }, _callee13, this, [[1, 9]]);
893
+ }, _callee16, this, [[1, 9]]);
674
894
  }));
675
895
  function registerUser() {
676
896
  return _registerUser.apply(this, arguments);
@@ -687,30 +907,30 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
687
907
  }, {
688
908
  key: "createFile",
689
909
  value: (function () {
690
- var _createFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(dataHash) {
910
+ var _createFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(dataHash) {
691
911
  var response, record;
692
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
693
- while (1) switch (_context14.prev = _context14.next) {
912
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
913
+ while (1) switch (_context17.prev = _context17.next) {
694
914
  case 0:
695
- _context14.prev = 0;
696
- _context14.next = 3;
915
+ _context17.prev = 0;
916
+ _context17.next = 3;
697
917
  return this.axios.post('/object_service/createObject', ['<@filekit.file>', dataHash]);
698
918
  case 3:
699
- response = _context14.sent;
919
+ response = _context17.sent;
700
920
  record = response.data;
701
921
  if (dataHash) {
702
922
  record.data = dataHash;
703
923
  }
704
- return _context14.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
924
+ return _context17.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
705
925
  case 9:
706
- _context14.prev = 9;
707
- _context14.t0 = _context14["catch"](0);
708
- return _context14.abrupt("return", this._handleError(_context14.t0));
926
+ _context17.prev = 9;
927
+ _context17.t0 = _context17["catch"](0);
928
+ return _context17.abrupt("return", this._handleError(_context17.t0));
709
929
  case 12:
710
930
  case "end":
711
- return _context14.stop();
931
+ return _context17.stop();
712
932
  }
713
- }, _callee14, this, [[0, 9]]);
933
+ }, _callee17, this, [[0, 9]]);
714
934
  }));
715
935
  function createFile(_x9) {
716
936
  return _createFile.apply(this, arguments);
@@ -720,33 +940,33 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
720
940
  }, {
721
941
  key: "loadFile",
722
942
  value: function () {
723
- var _loadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(id) {
943
+ var _loadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(id) {
724
944
  var response, record;
725
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
726
- while (1) switch (_context15.prev = _context15.next) {
945
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
946
+ while (1) switch (_context18.prev = _context18.next) {
727
947
  case 0:
728
- _context15.prev = 0;
729
- _context15.next = 3;
948
+ _context18.prev = 0;
949
+ _context18.next = 3;
730
950
  return this.load('<@filekit.file>', id);
731
951
  case 3:
732
- response = _context15.sent;
952
+ response = _context18.sent;
733
953
  if (response) {
734
- _context15.next = 6;
954
+ _context18.next = 6;
735
955
  break;
736
956
  }
737
- return _context15.abrupt("return", null);
957
+ return _context18.abrupt("return", null);
738
958
  case 6:
739
959
  record = response.toRecord();
740
- return _context15.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
960
+ return _context18.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
741
961
  case 10:
742
- _context15.prev = 10;
743
- _context15.t0 = _context15["catch"](0);
744
- return _context15.abrupt("return", this._handleError(_context15.t0));
962
+ _context18.prev = 10;
963
+ _context18.t0 = _context18["catch"](0);
964
+ return _context18.abrupt("return", this._handleError(_context18.t0));
745
965
  case 13:
746
966
  case "end":
747
- return _context15.stop();
967
+ return _context18.stop();
748
968
  }
749
- }, _callee15, this, [[0, 10]]);
969
+ }, _callee18, this, [[0, 10]]);
750
970
  }));
751
971
  function loadFile(_x10) {
752
972
  return _loadFile.apply(this, arguments);
@@ -756,37 +976,37 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
756
976
  }, {
757
977
  key: "loadFiles",
758
978
  value: function () {
759
- var _loadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(ids) {
760
- var _this = this;
979
+ var _loadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(ids) {
980
+ var _this5 = this;
761
981
  var responses;
762
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
763
- while (1) switch (_context16.prev = _context16.next) {
982
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
983
+ while (1) switch (_context19.prev = _context19.next) {
764
984
  case 0:
765
- _context16.prev = 0;
766
- _context16.next = 3;
985
+ _context19.prev = 0;
986
+ _context19.next = 3;
767
987
  return this.load('<@filekit.file>', ids);
768
988
  case 3:
769
- responses = _context16.sent;
989
+ responses = _context19.sent;
770
990
  if (!(!responses || !Array.isArray(responses))) {
771
- _context16.next = 6;
991
+ _context19.next = 6;
772
992
  break;
773
993
  }
774
- return _context16.abrupt("return", []);
994
+ return _context19.abrupt("return", []);
775
995
  case 6:
776
- return _context16.abrupt("return", responses.map(function (response) {
996
+ return _context19.abrupt("return", responses.map(function (response) {
777
997
  var record = response.toRecord();
778
- return new _rbt_file["default"](record, _this.axios, _this.localDb);
998
+ return new _rbt_file["default"](record, _this5.axios, _this5.localDb);
779
999
  }));
780
1000
  case 9:
781
- _context16.prev = 9;
782
- _context16.t0 = _context16["catch"](0);
783
- this._handleError(_context16.t0); // Handle errors (log or process as needed)
784
- return _context16.abrupt("return", []);
1001
+ _context19.prev = 9;
1002
+ _context19.t0 = _context19["catch"](0);
1003
+ this._handleError(_context19.t0); // Handle errors (log or process as needed)
1004
+ return _context19.abrupt("return", []);
785
1005
  case 13:
786
1006
  case "end":
787
- return _context16.stop();
1007
+ return _context19.stop();
788
1008
  }
789
- }, _callee16, this, [[0, 9]]);
1009
+ }, _callee19, this, [[0, 9]]);
790
1010
  }));
791
1011
  function loadFiles(_x11) {
792
1012
  return _loadFiles.apply(this, arguments);
@@ -798,42 +1018,46 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
798
1018
  *
799
1019
  * @param {string} type - The type of object to create.
800
1020
  * @param {Object} dataHash - The data for the new object.
1021
+ * @param {Object} options - Additional options including enableRealtime.
801
1022
  * @returns {Promise<RbtObject>} - The newly created object as an RbtObject.
802
1023
  */
803
1024
  }, {
804
1025
  key: "create",
805
1026
  value: (function () {
806
- var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(type) {
1027
+ var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(type) {
807
1028
  var dataHash,
1029
+ options,
808
1030
  response,
809
1031
  record,
810
- _args17 = arguments;
811
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
812
- while (1) switch (_context17.prev = _context17.next) {
1032
+ _args20 = arguments;
1033
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1034
+ while (1) switch (_context20.prev = _context20.next) {
813
1035
  case 0:
814
- dataHash = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {};
815
- _context17.prev = 1;
816
- _context17.next = 4;
1036
+ dataHash = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : {};
1037
+ options = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
1038
+ _context20.prev = 2;
1039
+ _context20.next = 5;
817
1040
  return this.axios.post('/object_service/createObject', [type, dataHash]);
818
- case 4:
819
- response = _context17.sent;
1041
+ case 5:
1042
+ response = _context20.sent;
820
1043
  record = response.data;
821
1044
  if (dataHash) {
822
1045
  record.data = dataHash;
823
1046
  }
824
- return _context17.abrupt("return", new _rbt_object["default"](record, this.axios, {
1047
+ return _context20.abrupt("return", new _rbt_object["default"](record, this.axios, {
825
1048
  isNew: true,
826
- websocketClient: this.websocketClient
1049
+ websocketClient: this.websocketClient,
1050
+ enableRealtime: options.enableRealtime || false
827
1051
  }));
828
- case 10:
829
- _context17.prev = 10;
830
- _context17.t0 = _context17["catch"](1);
831
- return _context17.abrupt("return", this._handleError(_context17.t0));
832
- case 13:
1052
+ case 11:
1053
+ _context20.prev = 11;
1054
+ _context20.t0 = _context20["catch"](2);
1055
+ return _context20.abrupt("return", this._handleError(_context20.t0));
1056
+ case 14:
833
1057
  case "end":
834
- return _context17.stop();
1058
+ return _context20.stop();
835
1059
  }
836
- }, _callee17, this, [[1, 10]]);
1060
+ }, _callee20, this, [[2, 11]]);
837
1061
  }));
838
1062
  function create(_x12) {
839
1063
  return _create.apply(this, arguments);
@@ -872,8 +1096,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
872
1096
  }, {
873
1097
  key: "query",
874
1098
  value: (function () {
875
- var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(type) {
876
- var _this2 = this;
1099
+ var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(type) {
1100
+ var _this6 = this;
877
1101
  var params,
878
1102
  paramsKey,
879
1103
  defaultOrderBy,
@@ -883,12 +1107,12 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
883
1107
  cacheEntry,
884
1108
  responsePromise,
885
1109
  processingPromise,
886
- _args18 = arguments;
887
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
888
- while (1) switch (_context18.prev = _context18.next) {
1110
+ _args21 = arguments;
1111
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1112
+ while (1) switch (_context21.prev = _context21.next) {
889
1113
  case 0:
890
- params = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {};
891
- _context18.prev = 1;
1114
+ params = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {};
1115
+ _context21.prev = 1;
892
1116
  //console.log('RBTAPI.query INIT', type, params);
893
1117
  params.type = type;
894
1118
 
@@ -910,19 +1134,19 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
910
1134
  paramsKey = JSON.stringify(mergedParams);
911
1135
  cacheEntry = this.requestCache[paramsKey];
912
1136
  if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
913
- _context18.next = 11;
1137
+ _context21.next = 11;
914
1138
  break;
915
1139
  }
916
- return _context18.abrupt("return", cacheEntry.val);
1140
+ return _context21.abrupt("return", cacheEntry.val);
917
1141
  case 11:
918
1142
  // Create the response promise
919
1143
  responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Cache the promise of processing data, not just the raw response
920
1144
  processingPromise = responsePromise.then(function (response) {
921
- return _this2._processResponseData(response);
1145
+ return _this6._processResponseData(response, params);
922
1146
  })["catch"](function (e) {
923
- delete _this2.requestCache[paramsKey]; // Ensure cache cleanup on failure
1147
+ delete _this6.requestCache[paramsKey]; // Ensure cache cleanup on failure
924
1148
  //console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
925
- return _this2._handleError(e);
1149
+ return _this6._handleError(e);
926
1150
  }); // Store the promise of the processed data in the cache
927
1151
  this.requestCache[paramsKey] = {
928
1152
  val: processingPromise,
@@ -930,21 +1154,21 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
930
1154
  };
931
1155
 
932
1156
  // Await the processing promise for this call to get processed data
933
- _context18.next = 16;
1157
+ _context21.next = 16;
934
1158
  return processingPromise;
935
1159
  case 16:
936
- return _context18.abrupt("return", _context18.sent);
1160
+ return _context21.abrupt("return", _context21.sent);
937
1161
  case 19:
938
- _context18.prev = 19;
939
- _context18.t0 = _context18["catch"](1);
1162
+ _context21.prev = 19;
1163
+ _context21.t0 = _context21["catch"](1);
940
1164
  delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
941
1165
  //console.log('RBTAPI.query ERROR', paramsKey, e);
942
- return _context18.abrupt("return", this._handleError(_context18.t0));
1166
+ return _context21.abrupt("return", this._handleError(_context21.t0));
943
1167
  case 23:
944
1168
  case "end":
945
- return _context18.stop();
1169
+ return _context21.stop();
946
1170
  }
947
- }, _callee18, this, [[1, 19]]);
1171
+ }, _callee21, this, [[1, 19]]);
948
1172
  }));
949
1173
  function query(_x13) {
950
1174
  return _query.apply(this, arguments);
@@ -954,15 +1178,29 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
954
1178
  }, {
955
1179
  key: "_processResponseData",
956
1180
  value: function _processResponseData(response) {
957
- var _this3 = this;
1181
+ var _this7 = this;
1182
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
958
1183
  if (response.data.ok === false) {
959
1184
  return this._handleError(response);
960
1185
  }
961
1186
  if (Array.isArray(response.data.items)) {
962
1187
  //console.log('RBTAPI.query RESPONSE PRE', response.data.items);
1188
+
1189
+ // Ensure WebSocket client is available if realtime is requested
1190
+ var websocketClient = this.websocketClient;
1191
+ if (options.enableRealtime && !websocketClient) {
1192
+ console.log('[AgentProviderSync] Creating WebSocket client for realtime objects');
1193
+ websocketClient = this.getWebSocketClient();
1194
+ }
1195
+ console.log('[AgentProviderSync] _processResponseData creating objects with:', {
1196
+ enableRealtime: options.enableRealtime || false,
1197
+ hasWebSocketClient: !!websocketClient,
1198
+ itemCount: response.data.items.length
1199
+ });
963
1200
  response.data.items = response.data.items.map(function (record) {
964
- return new _rbt_object["default"](record, _this3.axios, {
965
- websocketClient: _this3.websocketClient
1201
+ return new _rbt_object["default"](record, _this7.axios, {
1202
+ websocketClient: websocketClient,
1203
+ enableRealtime: options.enableRealtime || false
966
1204
  });
967
1205
  });
968
1206
  }
@@ -982,51 +1220,377 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
982
1220
  }, {
983
1221
  key: "load",
984
1222
  value: (function () {
985
- var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(type, ids) {
1223
+ var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(type, ids) {
1224
+ var _this8 = this;
986
1225
  var params,
987
1226
  mergedParams,
988
- res,
989
- _args19 = arguments;
990
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
991
- while (1) switch (_context19.prev = _context19.next) {
1227
+ cachedObjects,
1228
+ missingIds,
1229
+ _iterator2,
1230
+ _step2,
1231
+ id,
1232
+ _cacheKey,
1233
+ cached,
1234
+ hitLogKey,
1235
+ loadedObjects,
1236
+ bulkMissLogKey,
1237
+ _iterator3,
1238
+ _step3,
1239
+ obj,
1240
+ cacheKey,
1241
+ setLogKey,
1242
+ result,
1243
+ _iterator4,
1244
+ _step4,
1245
+ _id,
1246
+ _cacheKey2,
1247
+ _obj,
1248
+ _cacheKey3,
1249
+ _cached,
1250
+ _hitLogKey,
1251
+ pendingKey,
1252
+ missLogKey,
1253
+ loadPromise,
1254
+ _args23 = arguments;
1255
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1256
+ while (1) switch (_context23.prev = _context23.next) {
992
1257
  case 0:
993
- params = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
994
- _context19.prev = 1;
1258
+ params = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
1259
+ if (type == '<@iac.user>') {
1260
+ debugger;
1261
+ }
1262
+ _context23.prev = 2;
995
1263
  if (!Array.isArray(ids)) {
996
- _context19.next = 7;
1264
+ _context23.next = 24;
997
1265
  break;
998
1266
  }
1267
+ // For array requests, check cache for each ID and only load missing ones
1268
+ cachedObjects = [];
1269
+ missingIds = [];
1270
+ _iterator2 = _createForOfIteratorHelper(ids);
1271
+ try {
1272
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1273
+ id = _step2.value;
1274
+ _cacheKey = "".concat(type, ":").concat(id);
1275
+ cached = this._objectCache.get(_cacheKey);
1276
+ if (cached) {
1277
+ // Only log cache hits once per object to reduce spam
1278
+ hitLogKey = "hit:".concat(_cacheKey);
1279
+ if (!this._loggedCacheEvents.has(hitLogKey)) {
1280
+ console.log('[AgentProviderSync] 🎯 roboto.load cache HIT:', {
1281
+ type: type,
1282
+ id: id,
1283
+ hasRealtime: !!cached._realtime,
1284
+ requestedRealtime: !!params.enableRealtime
1285
+ });
1286
+ this._loggedCacheEvents.add(hitLogKey);
1287
+ }
1288
+
1289
+ // If realtime is requested but cached object doesn't have it, upgrade it
1290
+ if (params.enableRealtime && !cached._realtime) {
1291
+ console.log('[AgentProviderSync] 🔄 Upgrading cached object to realtime:', {
1292
+ type: type,
1293
+ id: id
1294
+ });
1295
+ cached._initRealtime();
1296
+ }
1297
+ cachedObjects.push(cached);
1298
+ } else {
1299
+ missingIds.push(id);
1300
+ }
1301
+ }
1302
+
1303
+ // Load missing objects
1304
+ } catch (err) {
1305
+ _iterator2.e(err);
1306
+ } finally {
1307
+ _iterator2.f();
1308
+ }
1309
+ loadedObjects = [];
1310
+ if (!(missingIds.length > 0)) {
1311
+ _context23.next = 18;
1312
+ break;
1313
+ }
1314
+ // Only log bulk cache miss once
1315
+ bulkMissLogKey = "bulk-miss:".concat(type, ":").concat(missingIds.join(','));
1316
+ if (!this._loggedCacheEvents.has(bulkMissLogKey)) {
1317
+ console.log('[AgentProviderSync] 📦 roboto.load cache MISS, loading:', {
1318
+ type: type,
1319
+ ids: missingIds
1320
+ });
1321
+ this._loggedCacheEvents.add(bulkMissLogKey);
1322
+ }
999
1323
  mergedParams = _objectSpread(_objectSpread({}, params), {}, {
1000
- where: "id IN (\"".concat(ids.join("\",\""), "\")")
1001
- });
1002
- return _context19.abrupt("return", this.query(type, mergedParams));
1003
- case 7:
1004
- mergedParams = _objectSpread(_objectSpread({}, params), {}, {
1005
- where: "id=\"".concat(ids, "\"")
1324
+ where: "id IN (\"".concat(missingIds.join("\",\""), "\")")
1006
1325
  });
1007
- _context19.next = 10;
1326
+ _context23.next = 15;
1008
1327
  return this.query(type, mergedParams);
1009
- case 10:
1010
- res = _context19.sent;
1011
- return _context19.abrupt("return", res[0]);
1012
- case 12:
1013
- _context19.next = 17;
1328
+ case 15:
1329
+ loadedObjects = _context23.sent;
1330
+ // Cache the newly loaded objects
1331
+ _iterator3 = _createForOfIteratorHelper(loadedObjects);
1332
+ try {
1333
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1334
+ obj = _step3.value;
1335
+ cacheKey = "".concat(type, ":").concat(obj.id);
1336
+ this._objectCache.set(cacheKey, obj);
1337
+
1338
+ // Only log cache set once per object to reduce spam
1339
+ setLogKey = "set:".concat(cacheKey);
1340
+ if (!this._loggedCacheEvents.has(setLogKey)) {
1341
+ console.log('[AgentProviderSync] 💾 roboto.load cached object:', {
1342
+ type: type,
1343
+ id: obj.id
1344
+ });
1345
+ this._loggedCacheEvents.add(setLogKey);
1346
+ }
1347
+ }
1348
+ } catch (err) {
1349
+ _iterator3.e(err);
1350
+ } finally {
1351
+ _iterator3.f();
1352
+ }
1353
+ case 18:
1354
+ // Return combined results in original order
1355
+ result = [];
1356
+ _iterator4 = _createForOfIteratorHelper(ids);
1357
+ try {
1358
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1359
+ _id = _step4.value;
1360
+ _cacheKey2 = "".concat(type, ":").concat(_id);
1361
+ _obj = this._objectCache.get(_cacheKey2);
1362
+ if (_obj) {
1363
+ // Ensure realtime is enabled if requested
1364
+ if (params.enableRealtime && !_obj._realtime) {
1365
+ _obj._initRealtime();
1366
+ }
1367
+ result.push(_obj);
1368
+ }
1369
+ }
1370
+ } catch (err) {
1371
+ _iterator4.e(err);
1372
+ } finally {
1373
+ _iterator4.f();
1374
+ }
1375
+ return _context23.abrupt("return", result);
1376
+ case 24:
1377
+ // For single object requests, check cache first
1378
+ _cacheKey3 = "".concat(type, ":").concat(ids);
1379
+ _cached = this._objectCache.get(_cacheKey3);
1380
+ if (!_cached) {
1381
+ _context23.next = 31;
1382
+ break;
1383
+ }
1384
+ // Only log cache hits once per object to reduce spam
1385
+ _hitLogKey = "hit:".concat(_cacheKey3);
1386
+ if (!this._loggedCacheEvents.has(_hitLogKey) || console.log('[AgentProviderSync] 🎯 roboto.load cache HIT:', {
1387
+ type: type,
1388
+ id: ids,
1389
+ hasRealtime: !!_cached._realtime,
1390
+ requestedRealtime: !!params.enableRealtime
1391
+ })) {
1392
+ this._loggedCacheEvents.add(_hitLogKey);
1393
+ }
1394
+
1395
+ // If realtime is requested but cached object doesn't have it, upgrade it
1396
+ if (params.enableRealtime && !_cached._realtime) {
1397
+ console.log('[AgentProviderSync] 🔄 Upgrading cached object to realtime:', {
1398
+ type: type,
1399
+ id: ids
1400
+ });
1401
+ _cached._initRealtime();
1402
+ }
1403
+ return _context23.abrupt("return", _cached);
1404
+ case 31:
1405
+ // Check if we're already loading this object
1406
+ pendingKey = "".concat(type, ":").concat(ids);
1407
+ if (!this._pendingLoads.has(pendingKey)) {
1408
+ _context23.next = 36;
1409
+ break;
1410
+ }
1411
+ _context23.next = 35;
1412
+ return this._pendingLoads.get(pendingKey);
1413
+ case 35:
1414
+ return _context23.abrupt("return", _context23.sent);
1415
+ case 36:
1416
+ // Only log cache miss once per object to reduce spam
1417
+ missLogKey = "miss:".concat(_cacheKey3);
1418
+ if (!this._loggedCacheEvents.has(missLogKey)) {
1419
+ console.log('[AgentProviderSync] 📦 roboto.load cache MISS, loading:', {
1420
+ type: type,
1421
+ id: ids
1422
+ });
1423
+ this._loggedCacheEvents.add(missLogKey);
1424
+ }
1425
+
1426
+ // Create the loading promise and store it to prevent duplicate requests
1427
+ loadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1428
+ var res, _obj2, _setLogKey;
1429
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1430
+ while (1) switch (_context22.prev = _context22.next) {
1431
+ case 0:
1432
+ _context22.prev = 0;
1433
+ mergedParams = _objectSpread(_objectSpread({}, params), {}, {
1434
+ where: "id=\"".concat(ids, "\"")
1435
+ });
1436
+ _context22.next = 4;
1437
+ return _this8.query(type, mergedParams);
1438
+ case 4:
1439
+ res = _context22.sent;
1440
+ _obj2 = res[0];
1441
+ if (_obj2) {
1442
+ // Cache the loaded object
1443
+ _this8._objectCache.set(_cacheKey3, _obj2);
1444
+
1445
+ // Only log cache set once per object to reduce spam
1446
+ _setLogKey = "set:".concat(_cacheKey3);
1447
+ if (!_this8._loggedCacheEvents.has(_setLogKey)) {
1448
+ console.log('[AgentProviderSync] 💾 roboto.load cached object:', {
1449
+ type: type,
1450
+ id: ids
1451
+ });
1452
+ _this8._loggedCacheEvents.add(_setLogKey);
1453
+ }
1454
+ }
1455
+ return _context22.abrupt("return", _obj2);
1456
+ case 8:
1457
+ _context22.prev = 8;
1458
+ // Remove from pending loads
1459
+ _this8._pendingLoads["delete"](pendingKey);
1460
+ return _context22.finish(8);
1461
+ case 11:
1462
+ case "end":
1463
+ return _context22.stop();
1464
+ }
1465
+ }, _callee22, null, [[0,, 8, 11]]);
1466
+ }))(); // Store the promise so other concurrent requests can await it
1467
+ this._pendingLoads.set(pendingKey, loadPromise);
1468
+ _context23.next = 42;
1469
+ return loadPromise;
1470
+ case 42:
1471
+ return _context23.abrupt("return", _context23.sent);
1472
+ case 43:
1473
+ _context23.next = 48;
1014
1474
  break;
1015
- case 14:
1016
- _context19.prev = 14;
1017
- _context19.t0 = _context19["catch"](1);
1018
- return _context19.abrupt("return", this._handleError(_context19.t0));
1019
- case 17:
1475
+ case 45:
1476
+ _context23.prev = 45;
1477
+ _context23.t0 = _context23["catch"](2);
1478
+ return _context23.abrupt("return", this._handleError(_context23.t0));
1479
+ case 48:
1020
1480
  case "end":
1021
- return _context19.stop();
1481
+ return _context23.stop();
1022
1482
  }
1023
- }, _callee19, this, [[1, 14]]);
1483
+ }, _callee23, this, [[2, 45]]);
1024
1484
  }));
1025
1485
  function load(_x14, _x15) {
1026
1486
  return _load.apply(this, arguments);
1027
1487
  }
1028
1488
  return load;
1029
1489
  }()
1490
+ /**
1491
+ * Clears the object cache. Useful for cache invalidation.
1492
+ * @param {string} type - Optional object type to clear. If not provided, clears all.
1493
+ * @param {string} id - Optional object ID to clear. If not provided with type, clears all objects of that type.
1494
+ */
1495
+ )
1496
+ }, {
1497
+ key: "clearCache",
1498
+ value: function clearCache() {
1499
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1500
+ var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1501
+ if (type && id) {
1502
+ // Clear specific object
1503
+ var cacheKey = "".concat(type, ":").concat(id);
1504
+ var removed = this._objectCache["delete"](cacheKey);
1505
+
1506
+ // Clear related log tracking
1507
+ this._loggedCacheEvents["delete"]("hit:".concat(cacheKey));
1508
+ this._loggedCacheEvents["delete"]("miss:".concat(cacheKey));
1509
+ this._loggedCacheEvents["delete"]("set:".concat(cacheKey));
1510
+ console.log('[AgentProviderSync] 🗑️ roboto.clearCache specific object:', {
1511
+ type: type,
1512
+ id: id,
1513
+ removed: removed
1514
+ });
1515
+ } else if (type) {
1516
+ // Clear all objects of a specific type
1517
+ var removedCount = 0;
1518
+ var _iterator5 = _createForOfIteratorHelper(this._objectCache),
1519
+ _step5;
1520
+ try {
1521
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1522
+ var _step5$value = _slicedToArray(_step5.value, 1),
1523
+ key = _step5$value[0];
1524
+ if (key.startsWith("".concat(type, ":"))) {
1525
+ this._objectCache["delete"](key);
1526
+ removedCount++;
1527
+ }
1528
+ }
1529
+
1530
+ // Clear related log tracking for this type
1531
+ } catch (err) {
1532
+ _iterator5.e(err);
1533
+ } finally {
1534
+ _iterator5.f();
1535
+ }
1536
+ var _iterator6 = _createForOfIteratorHelper(this._loggedCacheEvents),
1537
+ _step6;
1538
+ try {
1539
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1540
+ var logKey = _step6.value;
1541
+ if (logKey.includes("".concat(type, ":"))) {
1542
+ this._loggedCacheEvents["delete"](logKey);
1543
+ }
1544
+ }
1545
+ } catch (err) {
1546
+ _iterator6.e(err);
1547
+ } finally {
1548
+ _iterator6.f();
1549
+ }
1550
+ console.log('[AgentProviderSync] 🗑️ roboto.clearCache by type:', {
1551
+ type: type,
1552
+ removedCount: removedCount
1553
+ });
1554
+ } else {
1555
+ // Clear all cached objects
1556
+ var size = this._objectCache.size;
1557
+ this._objectCache.clear();
1558
+ this._loggedCacheEvents.clear();
1559
+ this._pendingLoads.clear();
1560
+ console.log('[AgentProviderSync] 🗑️ roboto.clearCache all objects:', {
1561
+ clearedCount: size
1562
+ });
1563
+ }
1564
+ }
1565
+
1566
+ /**
1567
+ * Gets cache status for debugging
1568
+ * @returns {Object} Cache status information
1569
+ */
1570
+ }, {
1571
+ key: "getCacheStatus",
1572
+ value: function getCacheStatus() {
1573
+ var cacheEntries = Array.from(this._objectCache.entries()).map(function (_ref6) {
1574
+ var _obj$_internalData;
1575
+ var _ref7 = _slicedToArray(_ref6, 2),
1576
+ key = _ref7[0],
1577
+ obj = _ref7[1];
1578
+ return {
1579
+ key: key,
1580
+ id: obj.id,
1581
+ type: ((_obj$_internalData = obj._internalData) === null || _obj$_internalData === void 0 ? void 0 : _obj$_internalData.type) || 'unknown'
1582
+ };
1583
+ });
1584
+ var pendingLoads = Array.from(this._pendingLoads.keys());
1585
+ return {
1586
+ cacheSize: this._objectCache.size,
1587
+ pendingLoads: pendingLoads.length,
1588
+ loggedEvents: this._loggedCacheEvents.size,
1589
+ entries: cacheEntries,
1590
+ pendingKeys: pendingLoads
1591
+ };
1592
+ }
1593
+
1030
1594
  /**
1031
1595
  * Makes a POST request to a specific endpoint to run a task and handle progress updates.
1032
1596
  *
@@ -1045,11 +1609,10 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1045
1609
  * status: string // Can be 'RUNNING', 'DONE', or 'ERROR'
1046
1610
  * }
1047
1611
  */
1048
- )
1049
1612
  }, {
1050
1613
  key: "runTask",
1051
1614
  value: (function () {
1052
- var _runTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1615
+ var _runTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1053
1616
  var params,
1054
1617
  callbacks,
1055
1618
  onProgress,
@@ -1063,20 +1626,20 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1063
1626
  status,
1064
1627
  message,
1065
1628
  output,
1066
- _args20 = arguments;
1067
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1068
- while (1) switch (_context20.prev = _context20.next) {
1629
+ _args24 = arguments;
1630
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1631
+ while (1) switch (_context24.prev = _context24.next) {
1069
1632
  case 0:
1070
- params = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
1071
- callbacks = _args20.length > 1 && _args20[1] !== undefined ? _args20[1] : {};
1633
+ params = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
1634
+ callbacks = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {};
1072
1635
  onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onWaiting = callbacks.onWaiting, onDone = callbacks.onDone;
1073
- _context20.prev = 3;
1074
- _context20.next = 6;
1636
+ _context24.prev = 3;
1637
+ _context24.next = 6;
1075
1638
  return this.post('/task_service/runChain', params);
1076
1639
  case 6:
1077
- response = _context20.sent;
1640
+ response = _context24.sent;
1078
1641
  if (response) {
1079
- _context20.next = 9;
1642
+ _context24.next = 9;
1080
1643
  break;
1081
1644
  }
1082
1645
  throw new Error('Invalid server response');
@@ -1084,7 +1647,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1084
1647
  // Validate response structure
1085
1648
  ok = response.ok, jobId = response.jobId, status = response.status, message = response.message, output = response.output;
1086
1649
  if (!(!ok || typeof jobId !== 'string' || typeof status !== 'string')) {
1087
- _context20.next = 12;
1650
+ _context24.next = 12;
1088
1651
  break;
1089
1652
  }
1090
1653
  throw new Error('Invalid response structure');
@@ -1110,7 +1673,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1110
1673
  //console.log('Finish (request) ',response);
1111
1674
  onDone(response);
1112
1675
  }
1113
- return _context20.abrupt("return", {
1676
+ return _context24.abrupt("return", {
1114
1677
  ok: ok,
1115
1678
  jobId: jobId,
1116
1679
  status: status,
@@ -1118,24 +1681,24 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1118
1681
  output: output
1119
1682
  });
1120
1683
  case 20:
1121
- _context20.prev = 20;
1122
- _context20.t0 = _context20["catch"](3);
1684
+ _context24.prev = 20;
1685
+ _context24.t0 = _context24["catch"](3);
1123
1686
  if (typeof onError === 'function') {
1124
- onError(_context20.t0);
1687
+ onError(_context24.t0);
1125
1688
  } else {
1126
- console.error('Error in runTask:', _context20.t0);
1689
+ console.error('Error in runTask:', _context24.t0);
1127
1690
  }
1128
- return _context20.abrupt("return", {
1691
+ return _context24.abrupt("return", {
1129
1692
  ok: false,
1130
1693
  jobId: null,
1131
1694
  status: 'ERROR',
1132
- error: _context20.t0.message
1695
+ error: _context24.t0.message
1133
1696
  });
1134
1697
  case 24:
1135
1698
  case "end":
1136
- return _context20.stop();
1699
+ return _context24.stop();
1137
1700
  }
1138
- }, _callee20, this, [[3, 20]]);
1701
+ }, _callee24, this, [[3, 20]]);
1139
1702
  }));
1140
1703
  function runTask() {
1141
1704
  return _runTask.apply(this, arguments);
@@ -1145,37 +1708,37 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1145
1708
  }, {
1146
1709
  key: "stopJob",
1147
1710
  value: function () {
1148
- var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1711
+ var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
1149
1712
  var params,
1150
1713
  callbacks,
1151
1714
  response,
1152
- _args21 = arguments;
1153
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1154
- while (1) switch (_context21.prev = _context21.next) {
1715
+ _args25 = arguments;
1716
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1717
+ while (1) switch (_context25.prev = _context25.next) {
1155
1718
  case 0:
1156
- params = _args21.length > 0 && _args21[0] !== undefined ? _args21[0] : {};
1157
- callbacks = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {};
1158
- _context21.prev = 2;
1159
- _context21.next = 5;
1719
+ params = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
1720
+ callbacks = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {};
1721
+ _context25.prev = 2;
1722
+ _context25.next = 5;
1160
1723
  return this.post('/task_service/stopJob', params);
1161
1724
  case 5:
1162
- response = _context21.sent;
1725
+ response = _context25.sent;
1163
1726
  if (response) {
1164
- _context21.next = 8;
1727
+ _context25.next = 8;
1165
1728
  break;
1166
1729
  }
1167
1730
  throw new Error('Invalid server response');
1168
1731
  case 8:
1169
- return _context21.abrupt("return", true);
1732
+ return _context25.abrupt("return", true);
1170
1733
  case 11:
1171
- _context21.prev = 11;
1172
- _context21.t0 = _context21["catch"](2);
1734
+ _context25.prev = 11;
1735
+ _context25.t0 = _context25["catch"](2);
1173
1736
  throw 'Error in stopJob';
1174
1737
  case 14:
1175
1738
  case "end":
1176
- return _context21.stop();
1739
+ return _context25.stop();
1177
1740
  }
1178
- }, _callee21, this, [[2, 11]]);
1741
+ }, _callee25, this, [[2, 11]]);
1179
1742
  }));
1180
1743
  function stopJob() {
1181
1744
  return _stopJob.apply(this, arguments);
@@ -1195,26 +1758,26 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1195
1758
  }, {
1196
1759
  key: "pollTaskProgress",
1197
1760
  value: (function () {
1198
- var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(jobId, callbacks) {
1199
- var _this4 = this;
1761
+ var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(jobId, callbacks) {
1762
+ var _this9 = this;
1200
1763
  var onProgress, onError, onStopped, onWaiting, onDone, _callbacks$pollingInt, pollingInterval, checkProgress;
1201
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1202
- while (1) switch (_context23.prev = _context23.next) {
1764
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1765
+ while (1) switch (_context27.prev = _context27.next) {
1203
1766
  case 0:
1204
1767
  onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onWaiting = callbacks.onWaiting, onDone = callbacks.onDone, _callbacks$pollingInt = callbacks.pollingInterval, pollingInterval = _callbacks$pollingInt === void 0 ? 2000 : _callbacks$pollingInt;
1205
- _context23.prev = 1;
1768
+ _context27.prev = 1;
1206
1769
  checkProgress = /*#__PURE__*/function () {
1207
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1770
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
1208
1771
  var response;
1209
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1210
- while (1) switch (_context22.prev = _context22.next) {
1772
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
1773
+ while (1) switch (_context26.prev = _context26.next) {
1211
1774
  case 0:
1212
- _context22.next = 2;
1213
- return _this4.get("/task_service/pollChainProgress", {
1775
+ _context26.next = 2;
1776
+ return _this9.get("/task_service/pollChainProgress", {
1214
1777
  jobId: jobId
1215
1778
  });
1216
1779
  case 2:
1217
- response = _context22.sent;
1780
+ response = _context26.sent;
1218
1781
  // If the task is still in progress, start polling for updates
1219
1782
  if (response.status === 'DONE' && onDone) {
1220
1783
  // Provide the current progress to the callback function
@@ -1245,26 +1808,26 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1245
1808
  }
1246
1809
  case 9:
1247
1810
  case "end":
1248
- return _context22.stop();
1811
+ return _context26.stop();
1249
1812
  }
1250
- }, _callee22);
1813
+ }, _callee26);
1251
1814
  }));
1252
1815
  return function checkProgress() {
1253
- return _ref2.apply(this, arguments);
1816
+ return _ref8.apply(this, arguments);
1254
1817
  };
1255
1818
  }();
1256
1819
  checkProgress();
1257
- _context23.next = 9;
1820
+ _context27.next = 9;
1258
1821
  break;
1259
1822
  case 6:
1260
- _context23.prev = 6;
1261
- _context23.t0 = _context23["catch"](1);
1262
- return _context23.abrupt("return", this._handleError(_context23.t0));
1823
+ _context27.prev = 6;
1824
+ _context27.t0 = _context27["catch"](1);
1825
+ return _context27.abrupt("return", this._handleError(_context27.t0));
1263
1826
  case 9:
1264
1827
  case "end":
1265
- return _context23.stop();
1828
+ return _context27.stop();
1266
1829
  }
1267
- }, _callee23, this, [[1, 6]]);
1830
+ }, _callee27, this, [[1, 6]]);
1268
1831
  }));
1269
1832
  function pollTaskProgress(_x16, _x17) {
1270
1833
  return _pollTaskProgress.apply(this, arguments);
@@ -1286,43 +1849,43 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1286
1849
  }, {
1287
1850
  key: "get",
1288
1851
  value: (function () {
1289
- var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(endpoint) {
1852
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(endpoint) {
1290
1853
  var params,
1291
1854
  headers,
1292
1855
  response,
1293
- _args24 = arguments;
1294
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
1295
- while (1) switch (_context24.prev = _context24.next) {
1856
+ _args28 = arguments;
1857
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
1858
+ while (1) switch (_context28.prev = _context28.next) {
1296
1859
  case 0:
1297
- params = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {};
1298
- _context24.prev = 1;
1860
+ params = _args28.length > 1 && _args28[1] !== undefined ? _args28[1] : {};
1861
+ _context28.prev = 1;
1299
1862
  // Add the authToken to the headers
1300
1863
  headers = {
1301
1864
  authtoken: this.authtoken
1302
1865
  }; // Make the GET request using Axios
1303
- _context24.next = 5;
1866
+ _context28.next = 5;
1304
1867
  return this.axios.get(endpoint, {
1305
1868
  params: params,
1306
1869
  headers: headers
1307
1870
  });
1308
1871
  case 5:
1309
- response = _context24.sent;
1872
+ response = _context28.sent;
1310
1873
  if (!(response.data.ok === false)) {
1311
- _context24.next = 8;
1874
+ _context28.next = 8;
1312
1875
  break;
1313
1876
  }
1314
- return _context24.abrupt("return", this._handleError(response));
1877
+ return _context28.abrupt("return", this._handleError(response));
1315
1878
  case 8:
1316
- return _context24.abrupt("return", response.data);
1879
+ return _context28.abrupt("return", response.data);
1317
1880
  case 11:
1318
- _context24.prev = 11;
1319
- _context24.t0 = _context24["catch"](1);
1320
- return _context24.abrupt("return", this._handleError(_context24.t0));
1881
+ _context28.prev = 11;
1882
+ _context28.t0 = _context28["catch"](1);
1883
+ return _context28.abrupt("return", this._handleError(_context28.t0));
1321
1884
  case 14:
1322
1885
  case "end":
1323
- return _context24.stop();
1886
+ return _context28.stop();
1324
1887
  }
1325
- }, _callee24, this, [[1, 11]]);
1888
+ }, _callee28, this, [[1, 11]]);
1326
1889
  }));
1327
1890
  function get(_x18) {
1328
1891
  return _get.apply(this, arguments);
@@ -1345,42 +1908,42 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
1345
1908
  }, {
1346
1909
  key: "post",
1347
1910
  value: (function () {
1348
- var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(endpoint) {
1911
+ var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(endpoint) {
1349
1912
  var data,
1350
1913
  headers,
1351
1914
  response,
1352
- _args25 = arguments;
1353
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1354
- while (1) switch (_context25.prev = _context25.next) {
1915
+ _args29 = arguments;
1916
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
1917
+ while (1) switch (_context29.prev = _context29.next) {
1355
1918
  case 0:
1356
- data = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {};
1357
- _context25.prev = 1;
1919
+ data = _args29.length > 1 && _args29[1] !== undefined ? _args29[1] : {};
1920
+ _context29.prev = 1;
1358
1921
  // Add the authToken to the headers
1359
1922
  headers = {
1360
1923
  authtoken: this.authtoken
1361
1924
  }; // Make the POST request using Axios
1362
- _context25.next = 5;
1925
+ _context29.next = 5;
1363
1926
  return this.axios.post(endpoint, data, {
1364
1927
  headers: headers
1365
1928
  });
1366
1929
  case 5:
1367
- response = _context25.sent;
1930
+ response = _context29.sent;
1368
1931
  if (!(response.data.ok === false)) {
1369
- _context25.next = 8;
1932
+ _context29.next = 8;
1370
1933
  break;
1371
1934
  }
1372
- return _context25.abrupt("return", this._handleError(response));
1935
+ return _context29.abrupt("return", this._handleError(response));
1373
1936
  case 8:
1374
- return _context25.abrupt("return", response.data);
1937
+ return _context29.abrupt("return", response.data);
1375
1938
  case 11:
1376
- _context25.prev = 11;
1377
- _context25.t0 = _context25["catch"](1);
1378
- return _context25.abrupt("return", this._handleError(_context25.t0));
1939
+ _context29.prev = 11;
1940
+ _context29.t0 = _context29["catch"](1);
1941
+ return _context29.abrupt("return", this._handleError(_context29.t0));
1379
1942
  case 14:
1380
1943
  case "end":
1381
- return _context25.stop();
1944
+ return _context29.stop();
1382
1945
  }
1383
- }, _callee25, this, [[1, 11]]);
1946
+ }, _callee29, this, [[1, 11]]);
1384
1947
  }));
1385
1948
  function post(_x19) {
1386
1949
  return _post.apply(this, arguments);