@agents24/chat-react 0.3.0 → 0.3.2

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.
@@ -0,0 +1,2 @@
1
+ import type { ChatMcpOauthCompletion, WaitForMcpOauthCompleteInput } from "./types";
2
+ export declare function waitForMcpOauthComplete({ popup, callbackOrigin, serverId, timeoutMs, }: WaitForMcpOauthCompleteInput): Promise<ChatMcpOauthCompletion>;
package/dist/types.d.ts CHANGED
@@ -277,6 +277,16 @@ export type ChatMcpAuthStartInput = {
277
277
  };
278
278
  export type ChatMcpAuthStartResult = {
279
279
  authorization_url: string;
280
+ callback_origin: string;
281
+ };
282
+ export type ChatMcpOauthCompletion = {
283
+ connectionId: string;
284
+ };
285
+ export type WaitForMcpOauthCompleteInput = {
286
+ popup: Window | null;
287
+ callbackOrigin: string;
288
+ serverId: string;
289
+ timeoutMs?: number;
280
290
  };
281
291
  export type ChatTransport = {
282
292
  listThreads: (input?: {
@@ -0,0 +1,4 @@
1
+ import type { ChatHitlAction, ChatHitlPart } from "../types";
2
+ export declare function hitlActionLabel(part: ChatHitlPart, action: ChatHitlAction): string;
3
+ export declare function hitlTitle(part: ChatHitlPart): string;
4
+ export declare function resolvedHitlLabel(part: ChatHitlPart): string;
package/dist/ui/index.cjs CHANGED
@@ -76,7 +76,10 @@ __export(ui_exports, {
76
76
  attachmentVariants: () => attachmentVariants,
77
77
  bubbleVariants: () => bubbleVariants,
78
78
  cn: () => cn,
79
+ hitlActionLabel: () => hitlActionLabel,
80
+ hitlTitle: () => hitlTitle,
79
81
  markerVariants: () => markerVariants,
82
+ resolvedHitlLabel: () => resolvedHitlLabel,
80
83
  shouldCollapseUserMessage: () => shouldCollapseUserMessage
81
84
  });
82
85
  module.exports = __toCommonJS(ui_exports);
@@ -1040,18 +1043,47 @@ var MessageResponse = React3.memo(
1040
1043
  );
1041
1044
  MessageResponse.displayName = "MessageResponse";
1042
1045
 
1046
+ // src/ui/hitl-presentation.ts
1047
+ function optionalString(value) {
1048
+ return typeof value === "string" && value.trim() ? value.trim() : null;
1049
+ }
1050
+ function hitlActionLabel(part, action) {
1051
+ if (action === "approve") return ["tool_review", "app_data_permission"].includes(part.hitlKind) ? "Allow once" : "Approve";
1052
+ if (action === "reject") return ["tool_review", "app_data_permission"].includes(part.hitlKind) ? "Don\u2019t allow" : "Reject";
1053
+ if (action === "connect") return "Connect";
1054
+ return "Skip";
1055
+ }
1056
+ function hitlTitle(part) {
1057
+ const presentation = part.presentation || {};
1058
+ if (part.hitlKind === "tool_review") return `Run ${optionalString(presentation.tool_name) || "this tool"}?`;
1059
+ if (part.hitlKind === "mcp_auth") return `Connect ${optionalString(presentation.server_name) || "this service"} to continue`;
1060
+ if (part.hitlKind === "app_data_permission") return "Allow this data change?";
1061
+ return part.message;
1062
+ }
1063
+ function resolvedHitlLabel(part) {
1064
+ const outcome = String(part.resolution?.outcome || part.status).trim().toLowerCase();
1065
+ return {
1066
+ approved: part.hitlKind === "user_approval" ? "Approved" : "Allowed",
1067
+ rejected: part.hitlKind === "user_approval" ? "Rejected" : "Not allowed",
1068
+ connected: "Connected",
1069
+ skipped: "Skipped",
1070
+ timeout: "Timed out",
1071
+ expired: "Timed out",
1072
+ cancelled: "Cancelled",
1073
+ invalidated: "No longer available",
1074
+ policy_denied: "Not allowed"
1075
+ }[outcome] || outcome.replace(/_/g, " ");
1076
+ }
1077
+
1043
1078
  // src/ui/agent-response-timeline.tsx
1044
1079
  var import_jsx_runtime6 = require("react/jsx-runtime");
1045
- function asRecord(value) {
1046
- return value && typeof value === "object" && !Array.isArray(value) ? value : null;
1047
- }
1048
- function optionalString(value) {
1080
+ function optionalString2(value) {
1049
1081
  return typeof value === "string" && value.trim() ? value.trim() : null;
1050
1082
  }
1051
1083
  function presentationValue(part, key) {
1052
1084
  const presentation = part.presentation || {};
1053
1085
  const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
1054
- return optionalString(presentation[key]) || optionalString(presentation[snakeKey]);
1086
+ return optionalString2(presentation[key]) || optionalString2(presentation[snakeKey]);
1055
1087
  }
1056
1088
  function groupKey(part) {
1057
1089
  return presentationValue(part, "groupKey");
@@ -1140,12 +1172,6 @@ function ToolGroup({
1140
1172
  part.id
1141
1173
  )) }) });
1142
1174
  }
1143
- function actionLabel(part, action) {
1144
- if (action === "approve") return part.hitlKind === "tool_review" ? "Allow once" : "Approve";
1145
- if (action === "reject") return part.hitlKind === "tool_review" ? "Don\u2019t allow" : "Reject";
1146
- if (action === "connect") return "Connect";
1147
- return "Skip";
1148
- }
1149
1175
  function HitlPartRow({
1150
1176
  getHitlActionState,
1151
1177
  isLoading,
@@ -1155,64 +1181,36 @@ function HitlPartRow({
1155
1181
  const state = getHitlActionState?.(part);
1156
1182
  const [comment, setComment] = React4.useState("");
1157
1183
  const presentation = part.presentation || {};
1158
- const details = asRecord(presentation.sanitized_arguments);
1159
1184
  const requireComment = presentation.require_comment === true;
1160
1185
  const isTerminal = part.status !== "pending";
1161
1186
  if (isTerminal) {
1162
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "rounded-xl border border-border/60 bg-muted/30 px-3 py-2 text-sm text-muted-foreground", children: [
1163
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "font-medium text-foreground", children: part.resolution?.outcome || part.status }),
1164
- part.resolution?.reason ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "ml-1", children: [
1165
- "\xB7 ",
1166
- part.resolution.reason
1167
- ] }) : null
1168
- ] });
1187
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "px-1 py-1 text-sm text-muted-foreground", children: resolvedHitlLabel(part) });
1169
1188
  }
1170
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-3 rounded-xl border border-amber-500/30 bg-amber-500/5 p-3", children: [
1171
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1", children: [
1172
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "text-sm font-semibold text-foreground", children: optionalString(presentation.tool_name) || optionalString(presentation.server_name) || "Action required" }),
1173
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MessageResponse, { children: part.message }),
1174
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
1175
- optionalString(presentation.source) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
1176
- "Source: ",
1177
- optionalString(presentation.source)
1178
- ] }) : null,
1179
- optionalString(presentation.risk) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
1180
- "Risk: ",
1181
- optionalString(presentation.risk)
1182
- ] }) : null,
1183
- optionalString(presentation.credential_scope) ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
1184
- "Credentials: ",
1185
- optionalString(presentation.credential_scope)
1186
- ] }) : null
1187
- ] })
1188
- ] }),
1189
- details ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("details", { className: "text-xs text-muted-foreground", children: [
1190
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("summary", { className: "cursor-pointer select-none font-medium", children: "Details" }),
1191
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("pre", { className: "mt-2 max-h-48 overflow-auto rounded-lg bg-background/80 p-2 text-[11px]", children: JSON.stringify(details, null, 2) })
1192
- ] }) : null,
1189
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-2.5 rounded-lg bg-muted/45 px-3 py-2.5", children: [
1190
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "text-sm font-medium text-foreground text-pretty", children: hitlTitle(part) }),
1193
1191
  requireComment ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1194
1192
  "textarea",
1195
1193
  {
1196
1194
  "aria-label": "Approval comment",
1197
- 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",
1195
+ 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",
1198
1196
  onChange: (event) => setComment(event.target.value),
1199
1197
  placeholder: "Comment required",
1200
1198
  value: comment
1201
1199
  }
1202
1200
  ) : null,
1203
1201
  state?.error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "text-sm text-destructive", children: state.error }) : null,
1204
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "flex flex-wrap items-center gap-2", children: part.allowedActions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1202
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "flex flex-wrap items-center gap-1.5", children: part.allowedActions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1205
1203
  "button",
1206
1204
  {
1207
- "aria-label": actionLabel(part, action),
1205
+ "aria-label": hitlActionLabel(part, action),
1208
1206
  className: cn(
1209
- "min-w-24 rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:pointer-events-none disabled:opacity-60",
1210
- 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"
1207
+ "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",
1208
+ 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"
1211
1209
  ),
1212
1210
  disabled: !onHitlAction || isLoading || state?.status === "connecting" || state?.status === "resuming" || requireComment && !comment.trim(),
1213
1211
  onClick: () => onHitlAction?.(part, action, comment.trim() || void 0),
1214
1212
  type: "button",
1215
- children: actionLabel(part, action)
1213
+ children: hitlActionLabel(part, action)
1216
1214
  },
1217
1215
  action
1218
1216
  )) })
@@ -1688,7 +1686,10 @@ function McpConnectRequiredCard({
1688
1686
  attachmentVariants,
1689
1687
  bubbleVariants,
1690
1688
  cn,
1689
+ hitlActionLabel,
1690
+ hitlTitle,
1691
1691
  markerVariants,
1692
+ resolvedHitlLabel,
1692
1693
  shouldCollapseUserMessage
1693
1694
  });
1694
1695
  //# sourceMappingURL=index.cjs.map