@agents24/chat-react 0.3.0 → 0.3.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.
package/dist/ui/index.js CHANGED
@@ -824,18 +824,47 @@ var MessageResponse = React3.memo(
824
824
  );
825
825
  MessageResponse.displayName = "MessageResponse";
826
826
 
827
+ // src/ui/hitl-presentation.ts
828
+ function optionalString(value) {
829
+ return typeof value === "string" && value.trim() ? value.trim() : null;
830
+ }
831
+ function hitlActionLabel(part, action) {
832
+ if (action === "approve") return ["tool_review", "app_data_permission"].includes(part.hitlKind) ? "Allow once" : "Approve";
833
+ if (action === "reject") return ["tool_review", "app_data_permission"].includes(part.hitlKind) ? "Don\u2019t allow" : "Reject";
834
+ if (action === "connect") return "Connect";
835
+ return "Skip";
836
+ }
837
+ function hitlTitle(part) {
838
+ const presentation = part.presentation || {};
839
+ if (part.hitlKind === "tool_review") return `Run ${optionalString(presentation.tool_name) || "this tool"}?`;
840
+ if (part.hitlKind === "mcp_auth") return `Connect ${optionalString(presentation.server_name) || "this service"} to continue`;
841
+ if (part.hitlKind === "app_data_permission") return "Allow this data change?";
842
+ return part.message;
843
+ }
844
+ function resolvedHitlLabel(part) {
845
+ const outcome = String(part.resolution?.outcome || part.status).trim().toLowerCase();
846
+ return {
847
+ approved: part.hitlKind === "user_approval" ? "Approved" : "Allowed",
848
+ rejected: part.hitlKind === "user_approval" ? "Rejected" : "Not allowed",
849
+ connected: "Connected",
850
+ skipped: "Skipped",
851
+ timeout: "Timed out",
852
+ expired: "Timed out",
853
+ cancelled: "Cancelled",
854
+ invalidated: "No longer available",
855
+ policy_denied: "Not allowed"
856
+ }[outcome] || outcome.replace(/_/g, " ");
857
+ }
858
+
827
859
  // src/ui/agent-response-timeline.tsx
828
860
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
829
- function asRecord(value) {
830
- return value && typeof value === "object" && !Array.isArray(value) ? value : null;
831
- }
832
- function optionalString(value) {
861
+ function optionalString2(value) {
833
862
  return typeof value === "string" && value.trim() ? value.trim() : null;
834
863
  }
835
864
  function presentationValue(part, key) {
836
865
  const presentation = part.presentation || {};
837
866
  const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
838
- return optionalString(presentation[key]) || optionalString(presentation[snakeKey]);
867
+ return optionalString2(presentation[key]) || optionalString2(presentation[snakeKey]);
839
868
  }
840
869
  function groupKey(part) {
841
870
  return presentationValue(part, "groupKey");
@@ -924,12 +953,6 @@ function ToolGroup({
924
953
  part.id
925
954
  )) }) });
926
955
  }
927
- function actionLabel(part, action) {
928
- if (action === "approve") return part.hitlKind === "tool_review" ? "Allow once" : "Approve";
929
- if (action === "reject") return part.hitlKind === "tool_review" ? "Don\u2019t allow" : "Reject";
930
- if (action === "connect") return "Connect";
931
- return "Skip";
932
- }
933
956
  function HitlPartRow({
934
957
  getHitlActionState,
935
958
  isLoading,
@@ -939,64 +962,36 @@ function HitlPartRow({
939
962
  const state = getHitlActionState?.(part);
940
963
  const [comment, setComment] = React4.useState("");
941
964
  const presentation = part.presentation || {};
942
- const details = asRecord(presentation.sanitized_arguments);
943
965
  const requireComment = presentation.require_comment === true;
944
966
  const isTerminal = part.status !== "pending";
945
967
  if (isTerminal) {
946
- return /* @__PURE__ */ jsxs3("div", { className: "rounded-xl border border-border/60 bg-muted/30 px-3 py-2 text-sm text-muted-foreground", children: [
947
- /* @__PURE__ */ jsx6("span", { className: "font-medium text-foreground", children: part.resolution?.outcome || part.status }),
948
- part.resolution?.reason ? /* @__PURE__ */ jsxs3("span", { className: "ml-1", children: [
949
- "\xB7 ",
950
- part.resolution.reason
951
- ] }) : null
952
- ] });
968
+ return /* @__PURE__ */ jsx6("div", { className: "px-1 py-1 text-sm text-muted-foreground", children: resolvedHitlLabel(part) });
953
969
  }
954
- return /* @__PURE__ */ jsxs3("div", { className: "space-y-3 rounded-xl border border-amber-500/30 bg-amber-500/5 p-3", children: [
955
- /* @__PURE__ */ jsxs3("div", { className: "space-y-1", children: [
956
- /* @__PURE__ */ jsx6("div", { className: "text-sm font-semibold text-foreground", children: optionalString(presentation.tool_name) || optionalString(presentation.server_name) || "Action required" }),
957
- /* @__PURE__ */ jsx6(MessageResponse, { children: part.message }),
958
- /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
959
- optionalString(presentation.source) ? /* @__PURE__ */ jsxs3("span", { children: [
960
- "Source: ",
961
- optionalString(presentation.source)
962
- ] }) : null,
963
- optionalString(presentation.risk) ? /* @__PURE__ */ jsxs3("span", { children: [
964
- "Risk: ",
965
- optionalString(presentation.risk)
966
- ] }) : null,
967
- optionalString(presentation.credential_scope) ? /* @__PURE__ */ jsxs3("span", { children: [
968
- "Credentials: ",
969
- optionalString(presentation.credential_scope)
970
- ] }) : null
971
- ] })
972
- ] }),
973
- details ? /* @__PURE__ */ jsxs3("details", { className: "text-xs text-muted-foreground", children: [
974
- /* @__PURE__ */ jsx6("summary", { className: "cursor-pointer select-none font-medium", children: "Details" }),
975
- /* @__PURE__ */ jsx6("pre", { className: "mt-2 max-h-48 overflow-auto rounded-lg bg-background/80 p-2 text-[11px]", children: JSON.stringify(details, null, 2) })
976
- ] }) : null,
970
+ return /* @__PURE__ */ jsxs3("div", { className: "space-y-2.5 rounded-lg bg-muted/45 px-3 py-2.5", children: [
971
+ /* @__PURE__ */ jsx6("div", { className: "text-sm font-medium text-foreground text-pretty", children: hitlTitle(part) }),
977
972
  requireComment ? /* @__PURE__ */ jsx6(
978
973
  "textarea",
979
974
  {
980
975
  "aria-label": "Approval comment",
981
- className: "min-h-20 w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",
976
+ className: "min-h-20 w-full resize-y rounded-md border border-border/60 bg-background px-3 py-2 text-sm outline-none focus-visible:border-neutral-300 focus-visible:ring-0 dark:focus-visible:border-neutral-600",
982
977
  onChange: (event) => setComment(event.target.value),
983
978
  placeholder: "Comment required",
984
979
  value: comment
985
980
  }
986
981
  ) : null,
987
982
  state?.error ? /* @__PURE__ */ jsx6("div", { className: "text-sm text-destructive", children: state.error }) : null,
988
- /* @__PURE__ */ jsx6("div", { className: "flex flex-wrap items-center gap-2", children: part.allowedActions.map((action) => /* @__PURE__ */ jsx6(
983
+ /* @__PURE__ */ jsx6("div", { className: "flex flex-wrap items-center gap-1.5", children: part.allowedActions.map((action) => /* @__PURE__ */ jsx6(
989
984
  "button",
990
985
  {
991
- "aria-label": actionLabel(part, action),
986
+ "aria-label": hitlActionLabel(part, action),
992
987
  className: cn(
993
- "min-w-24 rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:pointer-events-none disabled:opacity-60",
994
- action === "approve" || action === "connect" ? "border-neutral-900 bg-neutral-900 text-white hover:bg-neutral-800" : "border-border bg-background text-foreground hover:bg-muted"
988
+ "min-h-10 rounded-md px-3 text-sm font-medium transition-[background-color,color,opacity,transform] duration-150 ease-out active:scale-[0.96] disabled:pointer-events-none disabled:opacity-60",
989
+ action === "approve" || action === "connect" ? "bg-neutral-900 text-white hover:bg-neutral-800 dark:bg-neutral-100 dark:text-neutral-900 dark:hover:bg-white" : "bg-transparent text-muted-foreground hover:bg-background/80 hover:text-foreground"
995
990
  ),
996
991
  disabled: !onHitlAction || isLoading || state?.status === "connecting" || state?.status === "resuming" || requireComment && !comment.trim(),
997
992
  onClick: () => onHitlAction?.(part, action, comment.trim() || void 0),
998
993
  type: "button",
999
- children: actionLabel(part, action)
994
+ children: hitlActionLabel(part, action)
1000
995
  },
1001
996
  action
1002
997
  )) })
@@ -1471,7 +1466,10 @@ export {
1471
1466
  attachmentVariants,
1472
1467
  bubbleVariants,
1473
1468
  cn,
1469
+ hitlActionLabel,
1470
+ hitlTitle,
1474
1471
  markerVariants,
1472
+ resolvedHitlLabel,
1475
1473
  shouldCollapseUserMessage
1476
1474
  };
1477
1475
  //# sourceMappingURL=index.js.map