@informedai/react 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -359,19 +359,55 @@ function InformedAIProvider({ config, children }) {
359
359
  if (sessionIdToResume) {
360
360
  try {
361
361
  const resumedSession = await clientRef.current.getSession(sessionIdToResume);
362
- sess = resumedSession;
363
- doc = resumedSession.document;
364
- const embeddedDt = resumedSession.document.documentType;
365
- dt = {
366
- id: embeddedDt.id,
367
- name: embeddedDt.name,
368
- displayName: embeddedDt.displayName,
369
- schema: embeddedDt.schema,
370
- workspaceId: "",
371
- taskConfigs: {},
372
- createdAt: "",
373
- updatedAt: ""
374
- };
362
+ if (resumedSession.status === "ended") {
363
+ console.warn("Session was ended, creating new one");
364
+ if (shouldPersist && typeof window !== "undefined") {
365
+ try {
366
+ localStorage.removeItem(storageKey);
367
+ } catch (e) {
368
+ }
369
+ }
370
+ } else if (resumedSession.status === "abandoned") {
371
+ console.log("[InformedAI] Session was abandoned, resuming...");
372
+ try {
373
+ const activeSession = await clientRef.current.resumeSession(sessionIdToResume);
374
+ sess = activeSession;
375
+ doc = resumedSession.document;
376
+ const embeddedDt = resumedSession.document.documentType;
377
+ dt = {
378
+ id: embeddedDt.id,
379
+ name: embeddedDt.name,
380
+ displayName: embeddedDt.displayName,
381
+ schema: embeddedDt.schema,
382
+ workspaceId: "",
383
+ taskConfigs: {},
384
+ createdAt: "",
385
+ updatedAt: ""
386
+ };
387
+ } catch (resumeErr) {
388
+ console.error("[InformedAI] Failed to resume abandoned session:", resumeErr);
389
+ if (shouldPersist && typeof window !== "undefined") {
390
+ try {
391
+ localStorage.removeItem(storageKey);
392
+ } catch (e) {
393
+ }
394
+ }
395
+ }
396
+ } else {
397
+ sess = resumedSession;
398
+ doc = resumedSession.document;
399
+ const embeddedDt = resumedSession.document.documentType;
400
+ dt = {
401
+ id: embeddedDt.id,
402
+ name: embeddedDt.name,
403
+ displayName: embeddedDt.displayName,
404
+ schema: embeddedDt.schema,
405
+ workspaceId: "",
406
+ taskConfigs: {},
407
+ createdAt: "",
408
+ updatedAt: ""
409
+ };
410
+ }
375
411
  } catch (e) {
376
412
  console.warn("Failed to resume session, creating new one");
377
413
  if (shouldPersist && typeof window !== "undefined") {
@@ -477,17 +513,6 @@ function InformedAIProvider({ config, children }) {
477
513
  window.document.removeEventListener("visibilitychange", handleVisibilityChange);
478
514
  };
479
515
  }, [session?.id, startHeartbeat, stopHeartbeat, handleSessionDeleted, config]);
480
- (0, import_react.useEffect)(() => {
481
- const handleBeforeUnload = () => {
482
- if (clientRef.current && sessionIdRef.current) {
483
- clientRef.current.endSessionBeacon(sessionIdRef.current);
484
- }
485
- };
486
- window.addEventListener("beforeunload", handleBeforeUnload);
487
- return () => {
488
- window.removeEventListener("beforeunload", handleBeforeUnload);
489
- };
490
- }, []);
491
516
  const handleSSEEvent = (0, import_react.useCallback)((event) => {
492
517
  if (event.type === "content" && event.content) {
493
518
  setStreamingContent((prev) => prev + event.content);
package/dist/index.mjs CHANGED
@@ -329,19 +329,55 @@ function InformedAIProvider({ config, children }) {
329
329
  if (sessionIdToResume) {
330
330
  try {
331
331
  const resumedSession = await clientRef.current.getSession(sessionIdToResume);
332
- sess = resumedSession;
333
- doc = resumedSession.document;
334
- const embeddedDt = resumedSession.document.documentType;
335
- dt = {
336
- id: embeddedDt.id,
337
- name: embeddedDt.name,
338
- displayName: embeddedDt.displayName,
339
- schema: embeddedDt.schema,
340
- workspaceId: "",
341
- taskConfigs: {},
342
- createdAt: "",
343
- updatedAt: ""
344
- };
332
+ if (resumedSession.status === "ended") {
333
+ console.warn("Session was ended, creating new one");
334
+ if (shouldPersist && typeof window !== "undefined") {
335
+ try {
336
+ localStorage.removeItem(storageKey);
337
+ } catch (e) {
338
+ }
339
+ }
340
+ } else if (resumedSession.status === "abandoned") {
341
+ console.log("[InformedAI] Session was abandoned, resuming...");
342
+ try {
343
+ const activeSession = await clientRef.current.resumeSession(sessionIdToResume);
344
+ sess = activeSession;
345
+ doc = resumedSession.document;
346
+ const embeddedDt = resumedSession.document.documentType;
347
+ dt = {
348
+ id: embeddedDt.id,
349
+ name: embeddedDt.name,
350
+ displayName: embeddedDt.displayName,
351
+ schema: embeddedDt.schema,
352
+ workspaceId: "",
353
+ taskConfigs: {},
354
+ createdAt: "",
355
+ updatedAt: ""
356
+ };
357
+ } catch (resumeErr) {
358
+ console.error("[InformedAI] Failed to resume abandoned session:", resumeErr);
359
+ if (shouldPersist && typeof window !== "undefined") {
360
+ try {
361
+ localStorage.removeItem(storageKey);
362
+ } catch (e) {
363
+ }
364
+ }
365
+ }
366
+ } else {
367
+ sess = resumedSession;
368
+ doc = resumedSession.document;
369
+ const embeddedDt = resumedSession.document.documentType;
370
+ dt = {
371
+ id: embeddedDt.id,
372
+ name: embeddedDt.name,
373
+ displayName: embeddedDt.displayName,
374
+ schema: embeddedDt.schema,
375
+ workspaceId: "",
376
+ taskConfigs: {},
377
+ createdAt: "",
378
+ updatedAt: ""
379
+ };
380
+ }
345
381
  } catch (e) {
346
382
  console.warn("Failed to resume session, creating new one");
347
383
  if (shouldPersist && typeof window !== "undefined") {
@@ -447,17 +483,6 @@ function InformedAIProvider({ config, children }) {
447
483
  window.document.removeEventListener("visibilitychange", handleVisibilityChange);
448
484
  };
449
485
  }, [session?.id, startHeartbeat, stopHeartbeat, handleSessionDeleted, config]);
450
- useEffect(() => {
451
- const handleBeforeUnload = () => {
452
- if (clientRef.current && sessionIdRef.current) {
453
- clientRef.current.endSessionBeacon(sessionIdRef.current);
454
- }
455
- };
456
- window.addEventListener("beforeunload", handleBeforeUnload);
457
- return () => {
458
- window.removeEventListener("beforeunload", handleBeforeUnload);
459
- };
460
- }, []);
461
486
  const handleSSEEvent = useCallback((event) => {
462
487
  if (event.type === "content" && event.content) {
463
488
  setStreamingContent((prev) => prev + event.content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@informedai/react",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "React SDK for InformedAI Assistant - AI-powered content creation widget",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",