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/tevroc-sdk.esm.js CHANGED
@@ -3821,7 +3821,7 @@ var init_useGoogleAuth = __esm({
3821
3821
  debugLog("appId:", appId, "serviceUrl:", serviceUrl);
3822
3822
  debugLog(isCapacitor, isTauri);
3823
3823
  await initializeGoogleLogin();
3824
- let authUrl = `${serviceUrl}/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3824
+ let authUrl = `${serviceUrl}/auth/google/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3825
3825
  if (isCapacitor) {
3826
3826
  const { Browser: Browser3 } = await getCapacitorPlugins();
3827
3827
  await Browser3.open({ url: authUrl });
@@ -3830,7 +3830,7 @@ var init_useGoogleAuth = __esm({
3830
3830
  if (isTauri) {
3831
3831
  const WebviewWindow2 = await getTauriWebviewWindow();
3832
3832
  await closeAllTauriWebviews();
3833
- const url = `${serviceUrl}/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3833
+ const url = `${serviceUrl}/auth/google/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
3834
3834
  const win = new WebviewWindow2("auth", {
3835
3835
  url,
3836
3836
  title: `${appName} Login`,
@@ -3851,7 +3851,7 @@ var init_useGoogleAuth = __esm({
3851
3851
  const isLocalhost = true;
3852
3852
  const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
3853
3853
  const mode = isLocalhost ? "localhost" : "netlify";
3854
- const finalUrl = `${serviceUrl}/login?mode=${mode}&app=${encodeURIComponent(
3854
+ const finalUrl = `${serviceUrl}/auth/google/login?mode=${mode}&app=${encodeURIComponent(
3855
3855
  detectedAppId
3856
3856
  )}&name=${encodeURIComponent(appName)}`;
3857
3857
  if (isLocalhost) {
@@ -40762,6 +40762,131 @@ function createPdfApi() {
40762
40762
  };
40763
40763
  }
40764
40764
 
40765
+ // src/services/notifications.js
40766
+ var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
40767
+ function createNotificationService() {
40768
+ const listeners2 = /* @__PURE__ */ new Set();
40769
+ const scheduled = /* @__PURE__ */ new Map();
40770
+ let nativeListenerInstalled = false;
40771
+ const emit2 = (event) => listeners2.forEach((listener) => listener(event));
40772
+ const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
40773
+ const installNativeListener = () => {
40774
+ if (nativeListenerInstalled) return;
40775
+ const plugin = appPlugin();
40776
+ if (!plugin?.addListener) return;
40777
+ nativeListenerInstalled = true;
40778
+ plugin.addListener("notificationAction", (event) => {
40779
+ let data = event?.data || {};
40780
+ if (typeof data === "string") {
40781
+ try {
40782
+ data = JSON.parse(data);
40783
+ } catch {
40784
+ data = {};
40785
+ }
40786
+ }
40787
+ emit2({
40788
+ id: event?.id,
40789
+ action: event?.action || "open",
40790
+ reply: event?.reply || "",
40791
+ data,
40792
+ platform: "capacitor"
40793
+ });
40794
+ });
40795
+ plugin.consumePendingAction?.().catch?.(() => {
40796
+ });
40797
+ };
40798
+ const permission = async () => {
40799
+ const plugin = appPlugin();
40800
+ if (plugin?.checkPermissions) return plugin.checkPermissions();
40801
+ if (globalThis?.__TAURI_INTERNALS__) {
40802
+ try {
40803
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
40804
+ return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
40805
+ } catch {
40806
+ return { display: "denied" };
40807
+ }
40808
+ }
40809
+ return { display: isBrowser() ? Notification.permission : "denied" };
40810
+ };
40811
+ const requestPermission = async () => {
40812
+ const plugin = appPlugin();
40813
+ if (plugin?.requestPermissions) return plugin.requestPermissions();
40814
+ if (globalThis?.__TAURI_INTERNALS__) {
40815
+ try {
40816
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
40817
+ return { display: await tauri.requestPermission() };
40818
+ } catch {
40819
+ return { display: "denied" };
40820
+ }
40821
+ }
40822
+ return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
40823
+ };
40824
+ const show = async (options = {}) => {
40825
+ const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
40826
+ const request = {
40827
+ id,
40828
+ title: options.title || "Notification",
40829
+ body: options.body || "",
40830
+ data: options.data || {},
40831
+ actions: options.actions || [],
40832
+ silent: Boolean(options.silent),
40833
+ channel: options.channel || "general",
40834
+ style: options.style || {}
40835
+ };
40836
+ const plugin = appPlugin();
40837
+ if (plugin?.show) {
40838
+ installNativeListener();
40839
+ await plugin.show(request);
40840
+ return { id, platform: "capacitor" };
40841
+ }
40842
+ if (globalThis?.__TAURI_INTERNALS__) {
40843
+ try {
40844
+ const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
40845
+ const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
40846
+ if (current === "granted") {
40847
+ tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
40848
+ return { id, platform: "tauri" };
40849
+ }
40850
+ } catch {
40851
+ }
40852
+ }
40853
+ if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
40854
+ const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
40855
+ if (state !== "granted") throw new Error("Notification permission was not granted.");
40856
+ const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
40857
+ notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
40858
+ return { id, platform: "web", notification };
40859
+ };
40860
+ const schedule = async (options = {}) => {
40861
+ const at2 = new Date(options.at || Date.now()).getTime();
40862
+ const delay = Math.max(0, at2 - Date.now());
40863
+ const id = String(options.id || `notification_${at2}_${Math.random().toString(36).slice(2)}`);
40864
+ const timeout = setTimeout(() => {
40865
+ scheduled.delete(id);
40866
+ show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
40867
+ }, delay);
40868
+ scheduled.set(id, timeout);
40869
+ return { id, at: at2 };
40870
+ };
40871
+ const cancel = async (id) => {
40872
+ const timeout = scheduled.get(String(id));
40873
+ if (timeout) clearTimeout(timeout);
40874
+ scheduled.delete(String(id));
40875
+ await appPlugin()?.cancel?.({ id: String(id) });
40876
+ };
40877
+ const cancelAll = async () => {
40878
+ for (const timeout of scheduled.values()) clearTimeout(timeout);
40879
+ scheduled.clear();
40880
+ await appPlugin()?.cancelAll?.();
40881
+ };
40882
+ const onAction = (listener) => {
40883
+ installNativeListener();
40884
+ listeners2.add(listener);
40885
+ return () => listeners2.delete(listener);
40886
+ };
40887
+ return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
40888
+ }
40889
+
40765
40890
  // src/services/agentNotifications.js
40766
40891
  var toList = (result) => Array.isArray(result) ? result : result?.data || [];
40767
40892
  var latestByTime = (records) => [...records].sort((a3, b2) => {
@@ -40770,6 +40895,7 @@ var latestByTime = (records) => [...records].sort((a3, b2) => {
40770
40895
  return right - left;
40771
40896
  })[0] || null;
40772
40897
  function createAgentNotificationService(client) {
40898
+ const notifications = client.notifications || createNotificationService();
40773
40899
  let timer = null;
40774
40900
  let stopped = true;
40775
40901
  const seen = /* @__PURE__ */ new Map();
@@ -40777,8 +40903,17 @@ function createAgentNotificationService(client) {
40777
40903
  const notify = (event) => listeners2.forEach((listener) => listener(event));
40778
40904
  const getSessionId = (session) => session.sessionId || session.session_id || session.id;
40779
40905
  const getMessages = async (sessionId, appId) => {
40780
- const result = await client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 });
40781
- return toList(result);
40906
+ const [bySessionId, byLegacySessionId] = await Promise.all([
40907
+ client.entities.ChatMessage.query({ filter: { appId, sessionId }, limit: 100 }),
40908
+ client.entities.ChatMessage.query({ filter: { appId, session_id: sessionId }, limit: 100 })
40909
+ ]);
40910
+ const seenMessages = /* @__PURE__ */ new Set();
40911
+ return [...toList(bySessionId), ...toList(byLegacySessionId)].filter((message2) => {
40912
+ const key = message2?.id || `${message2?.createdAt || ""}:${message2?.content || ""}`;
40913
+ if (seenMessages.has(key)) return false;
40914
+ seenMessages.add(key);
40915
+ return true;
40916
+ });
40782
40917
  };
40783
40918
  const publish = (sessionId, payload) => {
40784
40919
  const connection = client.realtime.room(sessionId, {}, { maxReconnects: 2 });
@@ -40830,15 +40965,18 @@ function createAgentNotificationService(client) {
40830
40965
  };
40831
40966
  const dispatchAction = async ({ action, sessionId, reply: text2 }) => {
40832
40967
  const appId = client.appId;
40833
- const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }));
40834
- const session = sessions[0];
40968
+ const [bySessionId, byLegacySessionId] = await Promise.all([
40969
+ client.entities.ChatSession.query({ filter: { appId, sessionId }, limit: 1 }),
40970
+ client.entities.ChatSession.query({ filter: { appId, session_id: sessionId }, limit: 1 })
40971
+ ]);
40972
+ const session = toList(bySessionId)[0] || toList(byLegacySessionId)[0];
40835
40973
  if (!session) return;
40836
40974
  if (action === "open") return notify({ type: "open", sessionId, session });
40837
40975
  if (action === "accept") return accept(session);
40838
40976
  if (action === "reject") return reject(session);
40839
40977
  if (action === "reply") return reply(session, text2);
40840
40978
  };
40841
- const showNative = (request) => client.notifications.show({
40979
+ const showNative = (request) => notifications.show({
40842
40980
  id: `agent-request-${request.sessionId}`,
40843
40981
  title: request.title,
40844
40982
  body: request.body,
@@ -40917,7 +41055,7 @@ function createAgentNotificationService(client) {
40917
41055
  listeners2.add(listener);
40918
41056
  return () => listeners2.delete(listener);
40919
41057
  };
40920
- client.notifications.onAction(({ action, data, reply: text2 }) => {
41058
+ notifications.onAction(({ action, data, reply: text2 }) => {
40921
41059
  if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
40922
41060
  dispatchAction({ action, sessionId: data.sessionId, reply: text2 }).catch((error) => notify({ type: "error", error }));
40923
41061
  }
@@ -40925,138 +41063,14 @@ function createAgentNotificationService(client) {
40925
41063
  return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
40926
41064
  }
40927
41065
 
40928
- // src/services/notifications.js
40929
- var isBrowser = () => typeof window !== "undefined" && typeof Notification !== "undefined";
40930
- function createNotificationService() {
40931
- const listeners2 = /* @__PURE__ */ new Set();
40932
- const scheduled = /* @__PURE__ */ new Map();
40933
- let nativeListenerInstalled = false;
40934
- const emit2 = (event) => listeners2.forEach((listener) => listener(event));
40935
- const appPlugin = () => globalThis?.Capacitor?.Plugins?.AppNotifications;
40936
- const installNativeListener = () => {
40937
- if (nativeListenerInstalled) return;
40938
- const plugin = appPlugin();
40939
- if (!plugin?.addListener) return;
40940
- nativeListenerInstalled = true;
40941
- plugin.addListener("notificationAction", (event) => {
40942
- let data = event?.data || {};
40943
- if (typeof data === "string") {
40944
- try {
40945
- data = JSON.parse(data);
40946
- } catch {
40947
- data = {};
40948
- }
40949
- }
40950
- emit2({
40951
- id: event?.id,
40952
- action: event?.action || "open",
40953
- reply: event?.reply || "",
40954
- data,
40955
- platform: "capacitor"
40956
- });
40957
- });
40958
- plugin.consumePendingAction?.().catch?.(() => {
40959
- });
40960
- };
40961
- const permission = async () => {
40962
- const plugin = appPlugin();
40963
- if (plugin?.checkPermissions) return plugin.checkPermissions();
40964
- if (globalThis?.__TAURI_INTERNALS__) {
40965
- try {
40966
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
40967
- return { display: await tauri.isPermissionGranted() ? "granted" : "prompt" };
40968
- } catch {
40969
- return { display: "denied" };
40970
- }
40971
- }
40972
- return { display: isBrowser() ? Notification.permission : "denied" };
40973
- };
40974
- const requestPermission = async () => {
40975
- const plugin = appPlugin();
40976
- if (plugin?.requestPermissions) return plugin.requestPermissions();
40977
- if (globalThis?.__TAURI_INTERNALS__) {
40978
- try {
40979
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
40980
- return { display: await tauri.requestPermission() };
40981
- } catch {
40982
- return { display: "denied" };
40983
- }
40984
- }
40985
- return { display: isBrowser() ? await Notification.requestPermission() : "denied" };
40986
- };
40987
- const show = async (options = {}) => {
40988
- const id = String(options.id || `notification_${Date.now()}_${Math.random().toString(36).slice(2)}`);
40989
- const request = {
40990
- id,
40991
- title: options.title || "Notification",
40992
- body: options.body || "",
40993
- data: options.data || {},
40994
- actions: options.actions || [],
40995
- silent: Boolean(options.silent),
40996
- channel: options.channel || "general",
40997
- style: options.style || {}
40998
- };
40999
- const plugin = appPlugin();
41000
- if (plugin?.show) {
41001
- installNativeListener();
41002
- await plugin.show(request);
41003
- return { id, platform: "capacitor" };
41004
- }
41005
- if (globalThis?.__TAURI_INTERNALS__) {
41006
- try {
41007
- const tauri = await new Function("name", "return import(name)")("@tauri-apps/plugin-notification");
41008
- const current = await tauri.isPermissionGranted() ? "granted" : await tauri.requestPermission();
41009
- if (current === "granted") {
41010
- tauri.sendNotification({ title: request.title, body: request.body, extra: request.data });
41011
- return { id, platform: "tauri" };
41012
- }
41013
- } catch {
41014
- }
41015
- }
41016
- if (!isBrowser()) throw new Error("Notifications are not supported on this platform.");
41017
- const state = Notification.permission === "default" ? await Notification.requestPermission() : Notification.permission;
41018
- if (state !== "granted") throw new Error("Notification permission was not granted.");
41019
- const notification = new Notification(request.title, { body: request.body, tag: id, data: request.data, silent: request.silent });
41020
- notification.onclick = () => emit2({ id, action: "open", data: request.data, platform: "web" });
41021
- return { id, platform: "web", notification };
41022
- };
41023
- const schedule = async (options = {}) => {
41024
- const at2 = new Date(options.at || Date.now()).getTime();
41025
- const delay = Math.max(0, at2 - Date.now());
41026
- const id = String(options.id || `notification_${at2}_${Math.random().toString(36).slice(2)}`);
41027
- const timeout = setTimeout(() => {
41028
- scheduled.delete(id);
41029
- show({ ...options, id }).catch((error) => emit2({ type: "error", error }));
41030
- }, delay);
41031
- scheduled.set(id, timeout);
41032
- return { id, at: at2 };
41033
- };
41034
- const cancel = async (id) => {
41035
- const timeout = scheduled.get(String(id));
41036
- if (timeout) clearTimeout(timeout);
41037
- scheduled.delete(String(id));
41038
- await appPlugin()?.cancel?.({ id: String(id) });
41039
- };
41040
- const cancelAll = async () => {
41041
- for (const timeout of scheduled.values()) clearTimeout(timeout);
41042
- scheduled.clear();
41043
- await appPlugin()?.cancelAll?.();
41044
- };
41045
- const onAction = (listener) => {
41046
- installNativeListener();
41047
- listeners2.add(listener);
41048
- return () => listeners2.delete(listener);
41049
- };
41050
- return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
41051
- }
41052
-
41053
41066
  // src/services/chatNotifications.js
41054
41067
  function createChatNotificationService(client) {
41068
+ const notifications = client.notifications || createNotificationService();
41055
41069
  const listeners2 = /* @__PURE__ */ new Set();
41056
41070
  const emit2 = (event) => listeners2.forEach((listener) => listener(event));
41057
41071
  const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {}, style } = {}) => {
41058
41072
  if (!sessionId) return null;
41059
- return client.notifications.show({
41073
+ return notifications.show({
41060
41074
  id: `chat-message-${sessionId}-${Date.now()}`,
41061
41075
  title,
41062
41076
  body,
@@ -41071,7 +41085,7 @@ function createChatNotificationService(client) {
41071
41085
  };
41072
41086
  const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {}, style } = {}) => {
41073
41087
  if (!sessionId) return null;
41074
- return client.notifications.show({
41088
+ return notifications.show({
41075
41089
  id: `chat-status-${sessionId}-${Date.now()}`,
41076
41090
  title,
41077
41091
  body,
@@ -41085,7 +41099,7 @@ function createChatNotificationService(client) {
41085
41099
  listeners2.add(listener);
41086
41100
  return () => listeners2.delete(listener);
41087
41101
  };
41088
- client.notifications.onAction(({ action, data, reply }) => {
41102
+ notifications.onAction(({ action, data, reply }) => {
41089
41103
  if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
41090
41104
  emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
41091
41105
  }