@elevasis/ui 2.60.0 → 2.60.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.
@@ -462,6 +462,9 @@ function PublicAgentChatFrame({
462
462
  }
463
463
  );
464
464
  }
465
+ function mergeIntakeMetadata(metadata, intakeValues) {
466
+ return Object.keys(intakeValues).length > 0 ? { ...intakeValues, ...metadata } : metadata;
467
+ }
465
468
  function PublicAgentChat({
466
469
  apiUrl,
467
470
  slug,
@@ -528,7 +531,7 @@ function PublicAgentChat({
528
531
  }, [apiUrl, slug, renderIntro]);
529
532
  const pendingFirstMessageRef = useRef(null);
530
533
  const authorize = useCallback(
531
- async (code) => {
534
+ async (code, onSuccessStatus = "ready") => {
532
535
  if (!grant) return;
533
536
  try {
534
537
  setError(null);
@@ -545,7 +548,7 @@ function PublicAgentChat({
545
548
  }
546
549
  );
547
550
  setCapabilityToken(authorization.capabilityToken);
548
- setStatus("ready");
551
+ setStatus(onSuccessStatus);
549
552
  } catch (requestError) {
550
553
  setError(requestError instanceof Error ? requestError.message : "Unable to start agent chat");
551
554
  setStatus(grant.requiresCode ? "code-required" : "error");
@@ -555,6 +558,7 @@ function PublicAgentChat({
555
558
  );
556
559
  const createSession = useCallback(
557
560
  async (boundCapabilityToken) => {
561
+ const mergedMetadata = mergeIntakeMetadata(metadata, intakeValues);
558
562
  const createdSession = await fetchJson(
559
563
  `${apiUrl}/api/public/agent-chat/${encodeURIComponent(slug)}/sessions`,
560
564
  {
@@ -562,7 +566,7 @@ function PublicAgentChat({
562
566
  headers: { "Content-Type": "application/json" },
563
567
  body: JSON.stringify({
564
568
  capabilityToken: boundCapabilityToken,
565
- ...metadata ? { metadata } : {}
569
+ ...mergedMetadata ? { metadata: mergedMetadata } : {}
566
570
  })
567
571
  }
568
572
  );
@@ -571,7 +575,7 @@ function PublicAgentChat({
571
575
  onSessionReady?.(createdSession);
572
576
  return createdSession;
573
577
  },
574
- [apiUrl, slug, metadata, onSessionReady]
578
+ [apiUrl, slug, metadata, intakeValues, onSessionReady]
575
579
  );
576
580
  const startSession = useCallback(
577
581
  async (code) => {
@@ -591,7 +595,7 @@ function PublicAgentChat({
591
595
  }
592
596
  );
593
597
  setCapabilityToken(authorization.capabilityToken);
594
- const mergedMetadata = Object.keys(intakeValues).length > 0 ? { ...intakeValues, ...metadata } : metadata;
598
+ const mergedMetadata = mergeIntakeMetadata(metadata, intakeValues);
595
599
  const createdSession = await fetchJson(
596
600
  `${apiUrl}/api/public/agent-chat/${encodeURIComponent(slug)}/sessions`,
597
601
  {
@@ -614,6 +618,21 @@ function PublicAgentChat({
614
618
  },
615
619
  [apiUrl, grant, intakeValues, metadata, onSessionReady, slug, visitorId]
616
620
  );
621
+ const beginSession = useCallback(async () => {
622
+ if (capabilityToken) {
623
+ try {
624
+ setError(null);
625
+ setStatus("authorizing");
626
+ await createSession(capabilityToken);
627
+ setStatus("ready");
628
+ } catch (requestError) {
629
+ setError(requestError instanceof Error ? requestError.message : "Unable to start agent chat");
630
+ setStatus(grant?.requiresCode ? "code-required" : "error");
631
+ }
632
+ return;
633
+ }
634
+ await startSession();
635
+ }, [capabilityToken, createSession, startSession, grant]);
617
636
  useEffect(() => {
618
637
  if (!grant || grant.requiresCode || renderIntro || hasIntroContent(grant) || resolveCaptureFields(grant).length > 0 || autoStartedRef.current) {
619
638
  return;
@@ -699,7 +718,9 @@ function PublicAgentChat({
699
718
  {
700
719
  onSubmit: (event) => {
701
720
  event.preventDefault();
702
- void startSession(accessCode);
721
+ if (!grant) return;
722
+ const next = renderIntro || hasIntroContent(grant) || resolveCaptureFields(grant).length > 0 ? "intro" : "ready";
723
+ void authorize(accessCode, next);
703
724
  },
704
725
  children: /* @__PURE__ */ jsxs(Stack, { children: [
705
726
  /* @__PURE__ */ jsxs(Group, { gap: "xs", children: [
@@ -731,7 +752,7 @@ function PublicAgentChat({
731
752
  if (renderIntro) {
732
753
  const ctx = {
733
754
  start: () => {
734
- void startSession();
755
+ void beginSession();
735
756
  },
736
757
  starting: status === "authorizing",
737
758
  title: displayTitle,
@@ -799,7 +820,7 @@ function PublicAgentChat({
799
820
  Button,
800
821
  {
801
822
  onClick: () => {
802
- void startSession();
823
+ void beginSession();
803
824
  },
804
825
  leftSection: /* @__PURE__ */ jsx(IconSend, { size: 16 }),
805
826
  children: ctaLabel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevasis/ui",
3
- "version": "2.60.0",
3
+ "version": "2.60.1",
4
4
  "description": "UI components and platform-aware hooks for building custom frontends on the Elevasis platform",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -274,11 +274,11 @@
274
274
  "typescript": "5.9.2",
275
275
  "vite": "^7.0.0",
276
276
  "vitest": "^3.2.4",
277
+ "@elevasis/sdk": "1.36.5",
277
278
  "@repo/core": "0.52.0",
278
- "@repo/elevasis-core": "1.0.0",
279
279
  "@repo/typescript-config": "0.0.0",
280
- "@repo/eslint-config": "0.0.0",
281
- "@elevasis/sdk": "1.36.5"
280
+ "@repo/elevasis-core": "1.0.0",
281
+ "@repo/eslint-config": "0.0.0"
282
282
  },
283
283
  "dependencies": {
284
284
  "@dagrejs/dagre": "^1.1.4",