tevrocsdk 0.1.75 → 0.1.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tevrocsdk",
3
- "version": "0.1.75",
3
+ "version": "0.1.77",
4
4
  "description": "JavaScript SDK for the Tevroc API.",
5
5
  "main": "./tevroc-sdk.umd.js",
6
6
  "module": "./tevroc-sdk.esm.js",
package/tevroc-sdk.cjs.js CHANGED
@@ -3803,7 +3803,7 @@ var init_useGoogleAuth = __esm({
3803
3803
  debugLog("appId:", appId, "serviceUrl:", serviceUrl);
3804
3804
  debugLog(isCapacitor, isTauri);
3805
3805
  await initializeGoogleLogin();
3806
- let authUrl = `${serviceUrl}/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3806
+ let authUrl = `${serviceUrl}/auth/google/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3807
3807
  if (isCapacitor) {
3808
3808
  const { Browser } = await getCapacitorPlugins();
3809
3809
  await Browser.open({ url: authUrl });
@@ -3812,7 +3812,7 @@ var init_useGoogleAuth = __esm({
3812
3812
  if (isTauri) {
3813
3813
  const WebviewWindow2 = await getTauriWebviewWindow();
3814
3814
  await closeAllTauriWebviews();
3815
- const url = `${serviceUrl}/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3815
+ const url = `${serviceUrl}/auth/google/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3816
3816
  const win = new WebviewWindow2("auth", {
3817
3817
  url,
3818
3818
  title: `${appName} Login`,
@@ -3833,7 +3833,7 @@ var init_useGoogleAuth = __esm({
3833
3833
  const isLocalhost = true;
3834
3834
  const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
3835
3835
  const mode = isLocalhost ? "localhost" : "netlify";
3836
- const finalUrl = `${serviceUrl}/login?mode=${mode}&app=${encodeURIComponent(
3836
+ const finalUrl = `${serviceUrl}/auth/google/login?mode=${mode}&app=${encodeURIComponent(
3837
3837
  detectedAppId
3838
3838
  )}&name=${encodeURIComponent(appName)}`;
3839
3839
  if (isLocalhost) {
@@ -47243,6 +47243,131 @@ function createPdfApi() {
47243
47243
  };
47244
47244
  }
47245
47245
 
47246
+ // src/services/notifications.js
47247
+ var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
47248
+ function createNotificationService() {
47249
+ const listeners2 = /* @__PURE__ */ new Set();
47250
+ const scheduled = /* @__PURE__ */ new Map();
47251
+ let nativeListenerInstalled = false;
47252
+ const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47253
+ const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
47254
+ const installNativeListener = () => {
47255
+ if (nativeListenerInstalled) return;
47256
+ const plugin = appPlugin();
47257
+ if (!plugin?.addListener) return;
47258
+ nativeListenerInstalled = true;
47259
+ plugin.addListener("notificationAction", (event) => {
47260
+ let data = event?.data || {};
47261
+ if (typeof data === "string") {
47262
+ try {
47263
+ data = JSON.parse(data);
47264
+ } catch {
47265
+ data = {};
47266
+ }
47267
+ }
47268
+ emit2({
47269
+ id: event?.id,
47270
+ action: event?.action || "open",
47271
+ reply: event?.reply || "",
47272
+ data,
47273
+ platform: "capacitor"
47274
+ });
47275
+ });
47276
+ plugin.consumePendingAction?.().catch?.(() => {
47277
+ });
47278
+ };
47279
+ const permission = async () => {
47280
+ const plugin = appPlugin();
47281
+ if (plugin?.checkPermissions) return plugin.checkPermissions();
47282
+ if (globalThis?.__TAURI_INTERNALS__) {
47283
+ try {
47284
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47285
+ return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
47286
+ } catch {
47287
+ return { display: "denied" };
47288
+ }
47289
+ }
47290
+ return { display: isBrowser() ? Notification.permission : "denied" };
47291
+ };
47292
+ const requestPermission = async () => {
47293
+ const plugin = appPlugin();
47294
+ if (plugin?.requestPermissions) return plugin.requestPermissions();
47295
+ if (globalThis?.__TAURI_INTERNALS__) {
47296
+ try {
47297
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47298
+ return { display: await tauri.requestPermission() };
47299
+ } catch {
47300
+ return { display: "denied" };
47301
+ }
47302
+ }
47303
+ return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
47304
+ };
47305
+ const show = async (options = {}) => {
47306
+ const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
47307
+ const request = {
47308
+ id,
47309
+ title: options.title || "Notification",
47310
+ body: options.body || "",
47311
+ data: options.data || {},
47312
+ actions: options.actions || [],
47313
+ silent: Boolean(options.silent),
47314
+ channel: options.channel || "general",
47315
+ style: options.style || {}
47316
+ };
47317
+ const plugin = appPlugin();
47318
+ if (plugin?.show) {
47319
+ installNativeListener();
47320
+ await plugin.show(request);
47321
+ return { id, platform: "capacitor" };
47322
+ }
47323
+ if (globalThis?.__TAURI_INTERNALS__) {
47324
+ try {
47325
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47326
+ const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
47327
+ if (current === "granted") {
47328
+ tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
47329
+ return { id, platform: "tauri" };
47330
+ }
47331
+ } catch {
47332
+ }
47333
+ }
47334
+ if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
47335
+ const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
47336
+ if (state !== "granted") throw new Error("Notification permission was not granted.");
47337
+ const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
47338
+ notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
47339
+ return { id, platform: "web", notification };
47340
+ };
47341
+ const schedule = async (options = {}) => {
47342
+ const at = new Date(options.at || Date.now()).getTime();
47343
+ const delay = Math.max(0, at - Date.now());
47344
+ const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
47345
+ const timeout = setTimeout(() => {
47346
+ scheduled.delete(id);
47347
+ show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
47348
+ }, delay);
47349
+ scheduled.set(id, timeout);
47350
+ return { id, at };
47351
+ };
47352
+ const cancel = async (id) => {
47353
+ const timeout = scheduled.get(String(id));
47354
+ if (timeout) clearTimeout(timeout);
47355
+ scheduled.delete(String(id));
47356
+ await appPlugin()?.cancel?.({ id: String(id) });
47357
+ };
47358
+ const cancelAll = async () => {
47359
+ for (const timeout of scheduled.values()) clearTimeout(timeout);
47360
+ scheduled.clear();
47361
+ await appPlugin()?.cancelAll?.();
47362
+ };
47363
+ const onAction = (listener) => {
47364
+ installNativeListener();
47365
+ listeners2.add(listener);
47366
+ return () => listeners2.delete(listener);
47367
+ };
47368
+ return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
47369
+ }
47370
+
47246
47371
  // src/services/agentNotifications.js
47247
47372
  var toList = (result) => Array.isArray(result) ? result : result?.data || [];
47248
47373
  var latestByTime = (records) => [...records].sort((a, b) => {
@@ -47251,6 +47376,7 @@ var latestByTime = (records) => [...records].sort((a, b) => {
47251
47376
  return right - left;
47252
47377
  })[0] || null;
47253
47378
  function createAgentNotificationService(client) {
47379
+ const notifications = client.notifications || createNotificationService();
47254
47380
  let timer = null;
47255
47381
  let stopped = true;
47256
47382
  const seen = /* @__PURE__ */ new Map();
@@ -47258,8 +47384,17 @@ function createAgentNotificationService(client) {
47258
47384
  const notify = (event) => listeners2.forEach((listener) => listener(event));
47259
47385
  const getSessionId = (session) => session.sessionId || session.session_id || session.id;
47260
47386
  const getMessages = async (sessionId, appId) => {
47261
- const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
47262
- return toList(result);
47387
+ const [bySessionId, byLegacySessionId] = await Promise.all([
47388
+ client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 }),
47389
+ client.entities.ChatMessage.query({ filter: { appId, session_id: sessionId }, limit: 100 })
47390
+ ]);
47391
+ const seenMessages = /* @__PURE__ */ new Set();
47392
+ return [...toList(bySessionId), ...toList(byLegacySessionId)].filter((message2) => {
47393
+ const key = message2?.id || `${message2?.createdAt || ""}:${message2?.content || ""}`;
47394
+ if (seenMessages.has(key)) return false;
47395
+ seenMessages.add(key);
47396
+ return true;
47397
+ });
47263
47398
  };
47264
47399
  const publish = (sessionId, payload) => {
47265
47400
  const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
@@ -47311,15 +47446,18 @@ function createAgentNotificationService(client) {
47311
47446
  };
47312
47447
  const dispatchAction = async ({ action, sessionId, reply: text }) => {
47313
47448
  const appId = client.appId;
47314
- const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
47315
- const session = sessions[0];
47449
+ const [bySessionId, byLegacySessionId] = await Promise.all([
47450
+ client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }),
47451
+ client.entities.ChatSession.query({ filter: { appId, session_id: sessionId }, limit: 1 })
47452
+ ]);
47453
+ const session = toList(bySessionId)[0] || toList(byLegacySessionId)[0];
47316
47454
  if (!session) return;
47317
47455
  if (action === "open") return notify({ type: "open", sessionId, session });
47318
47456
  if (action === "accept") return accept(session);
47319
47457
  if (action === "reject") return reject(session);
47320
47458
  if (action === "reply") return reply(session, text);
47321
47459
  };
47322
- const showNative = (request) => client.notifications.show({
47460
+ const showNative = (request) => notifications.show({
47323
47461
  id: `agent-request-${request.sessionId}`,
47324
47462
  title: request.title,
47325
47463
  body: request.body,
@@ -47398,7 +47536,7 @@ function createAgentNotificationService(client) {
47398
47536
  listeners2.add(listener);
47399
47537
  return () => listeners2.delete(listener);
47400
47538
  };
47401
- client.notifications.onAction(({ action, data, reply: text }) => {
47539
+ notifications.onAction(({ action, data, reply: text }) => {
47402
47540
  if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
47403
47541
  dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
47404
47542
  }
@@ -47406,138 +47544,14 @@ function createAgentNotificationService(client) {
47406
47544
  return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
47407
47545
  }
47408
47546
 
47409
- // src/services/notifications.js
47410
- var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
47411
- function createNotificationService() {
47412
- const listeners2 = /* @__PURE__ */ new Set();
47413
- const scheduled = /* @__PURE__ */ new Map();
47414
- let nativeListenerInstalled = false;
47415
- const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47416
- const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
47417
- const installNativeListener = () => {
47418
- if (nativeListenerInstalled) return;
47419
- const plugin = appPlugin();
47420
- if (!plugin?.addListener) return;
47421
- nativeListenerInstalled = true;
47422
- plugin.addListener("notificationAction", (event) => {
47423
- let data = event?.data || {};
47424
- if (typeof data === "string") {
47425
- try {
47426
- data = JSON.parse(data);
47427
- } catch {
47428
- data = {};
47429
- }
47430
- }
47431
- emit2({
47432
- id: event?.id,
47433
- action: event?.action || "open",
47434
- reply: event?.reply || "",
47435
- data,
47436
- platform: "capacitor"
47437
- });
47438
- });
47439
- plugin.consumePendingAction?.().catch?.(() => {
47440
- });
47441
- };
47442
- const permission = async () => {
47443
- const plugin = appPlugin();
47444
- if (plugin?.checkPermissions) return plugin.checkPermissions();
47445
- if (globalThis?.__TAURI_INTERNALS__) {
47446
- try {
47447
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47448
- return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
47449
- } catch {
47450
- return { display: "denied" };
47451
- }
47452
- }
47453
- return { display: isBrowser() ? Notification.permission : "denied" };
47454
- };
47455
- const requestPermission = async () => {
47456
- const plugin = appPlugin();
47457
- if (plugin?.requestPermissions) return plugin.requestPermissions();
47458
- if (globalThis?.__TAURI_INTERNALS__) {
47459
- try {
47460
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47461
- return { display: await tauri.requestPermission() };
47462
- } catch {
47463
- return { display: "denied" };
47464
- }
47465
- }
47466
- return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
47467
- };
47468
- const show = async (options = {}) => {
47469
- const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
47470
- const request = {
47471
- id,
47472
- title: options.title || "Notification",
47473
- body: options.body || "",
47474
- data: options.data || {},
47475
- actions: options.actions || [],
47476
- silent: Boolean(options.silent),
47477
- channel: options.channel || "general",
47478
- style: options.style || {}
47479
- };
47480
- const plugin = appPlugin();
47481
- if (plugin?.show) {
47482
- installNativeListener();
47483
- await plugin.show(request);
47484
- return { id, platform: "capacitor" };
47485
- }
47486
- if (globalThis?.__TAURI_INTERNALS__) {
47487
- try {
47488
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
47489
- const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
47490
- if (current === "granted") {
47491
- tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
47492
- return { id, platform: "tauri" };
47493
- }
47494
- } catch {
47495
- }
47496
- }
47497
- if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
47498
- const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
47499
- if (state !== "granted") throw new Error("Notification permission was not granted.");
47500
- const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
47501
- notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
47502
- return { id, platform: "web", notification };
47503
- };
47504
- const schedule = async (options = {}) => {
47505
- const at = new Date(options.at || Date.now()).getTime();
47506
- const delay = Math.max(0, at - Date.now());
47507
- const id = String(options.id || `notification_${at}_${Math.random().toString(36).slice(2)}`);
47508
- const timeout = setTimeout(() => {
47509
- scheduled.delete(id);
47510
- show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
47511
- }, delay);
47512
- scheduled.set(id, timeout);
47513
- return { id, at };
47514
- };
47515
- const cancel = async (id) => {
47516
- const timeout = scheduled.get(String(id));
47517
- if (timeout) clearTimeout(timeout);
47518
- scheduled.delete(String(id));
47519
- await appPlugin()?.cancel?.({ id: String(id) });
47520
- };
47521
- const cancelAll = async () => {
47522
- for (const timeout of scheduled.values()) clearTimeout(timeout);
47523
- scheduled.clear();
47524
- await appPlugin()?.cancelAll?.();
47525
- };
47526
- const onAction = (listener) => {
47527
- installNativeListener();
47528
- listeners2.add(listener);
47529
- return () => listeners2.delete(listener);
47530
- };
47531
- return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
47532
- }
47533
-
47534
47547
  // src/services/chatNotifications.js
47535
47548
  function createChatNotificationService(client) {
47549
+ const notifications = client.notifications || createNotificationService();
47536
47550
  const listeners2 = /* @__PURE__ */ new Set();
47537
47551
  const emit2 = (event) => listeners2.forEach((listener) => listener(event));
47538
47552
  const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {}, style } = {}) => {
47539
47553
  if (!sessionId) return null;
47540
- return client.notifications.show({
47554
+ return notifications.show({
47541
47555
  id: `chat-message-${sessionId}-${Date.now()}`,
47542
47556
  title,
47543
47557
  body,
@@ -47552,7 +47566,7 @@ function createChatNotificationService(client) {
47552
47566
  };
47553
47567
  const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {}, style } = {}) => {
47554
47568
  if (!sessionId) return null;
47555
- return client.notifications.show({
47569
+ return notifications.show({
47556
47570
  id: `chat-status-${sessionId}-${Date.now()}`,
47557
47571
  title,
47558
47572
  body,
@@ -47566,7 +47580,7 @@ function createChatNotificationService(client) {
47566
47580
  listeners2.add(listener);
47567
47581
  return () => listeners2.delete(listener);
47568
47582
  };
47569
- client.notifications.onAction(({ action, data, reply }) => {
47583
+ notifications.onAction(({ action, data, reply }) => {
47570
47584
  if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
47571
47585
  emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
47572
47586
  }