@page-speed/agent-everywhere 0.1.0 → 0.3.0

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.cjs CHANGED
@@ -6,6 +6,7 @@ var tailwindMerge = require('tailwind-merge');
6
6
  var React4 = require('react');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
  var react = require('motion/react');
9
+ var markdownToJsx = require('@page-speed/markdown-to-jsx');
9
10
  var lucideReact = require('lucide-react');
10
11
  var reactSlot = require('@radix-ui/react-slot');
11
12
  var classVarianceAuthority = require('class-variance-authority');
@@ -1006,7 +1007,32 @@ function MessageBubble({ role, children, className, unstyled }) {
1006
1007
  }
1007
1008
  );
1008
1009
  }
1009
- function MessageContent({ children, className }) {
1010
+ var PROSE_CLASSES = cn(
1011
+ "text-sm leading-relaxed",
1012
+ "[&_p]:my-1.5 first:[&_p]:mt-0 last:[&_p]:mb-0",
1013
+ "[&_ul]:my-1.5 [&_ul]:list-disc [&_ul]:pl-5",
1014
+ "[&_ol]:my-1.5 [&_ol]:list-decimal [&_ol]:pl-5",
1015
+ "[&_li]:my-0.5",
1016
+ "[&_h1]:mt-2 [&_h1]:mb-1 [&_h1]:text-base [&_h1]:font-semibold",
1017
+ "[&_h2]:mt-2 [&_h2]:mb-1 [&_h2]:text-sm [&_h2]:font-semibold",
1018
+ "[&_h3]:mt-2 [&_h3]:mb-1 [&_h3]:text-sm [&_h3]:font-semibold",
1019
+ "[&_strong]:font-semibold",
1020
+ "[&_a]:underline [&_a]:underline-offset-2",
1021
+ "[&_code]:rounded [&_code]:bg-black/10 [&_code]:px-1 [&_code]:py-0.5 [&_code]:text-[0.85em]",
1022
+ "[&_pre]:my-1.5 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-black/10 [&_pre]:p-2 [&_pre]:text-xs",
1023
+ "[&_pre_code]:bg-transparent [&_pre_code]:p-0",
1024
+ "[&_blockquote]:border-l-2 [&_blockquote]:border-current/30 [&_blockquote]:pl-3 [&_blockquote]:opacity-90",
1025
+ "[&_hr]:my-2 [&_hr]:border-current/20",
1026
+ "whitespace-normal"
1027
+ );
1028
+ function MessageContent({
1029
+ children,
1030
+ className,
1031
+ markdown = true
1032
+ }) {
1033
+ if (markdown && typeof children === "string") {
1034
+ return /* @__PURE__ */ jsxRuntime.jsx(markdownToJsx.Markdown, { className: cn(PROSE_CLASSES, className), children });
1035
+ }
1010
1036
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("text-sm leading-relaxed whitespace-pre-wrap", className), children });
1011
1037
  }
1012
1038
  function MessageContainer({ role, children, className }) {
@@ -1082,23 +1108,6 @@ function StatusBadge({
1082
1108
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground text-[10px]", children: displayLabel })
1083
1109
  ] });
1084
1110
  }
1085
- var Input = React4__namespace.forwardRef(
1086
- ({ className, type, ...props }, ref) => {
1087
- return /* @__PURE__ */ jsxRuntime.jsx(
1088
- "input",
1089
- {
1090
- type,
1091
- className: cn(
1092
- "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
1093
- className
1094
- ),
1095
- ref,
1096
- ...props
1097
- }
1098
- );
1099
- }
1100
- );
1101
- Input.displayName = "Input";
1102
1111
  var buttonVariants = classVarianceAuthority.cva(
1103
1112
  "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
1104
1113
  {
@@ -1138,6 +1147,8 @@ var Button = React4__namespace.forwardRef(
1138
1147
  }
1139
1148
  );
1140
1149
  Button.displayName = "Button";
1150
+ var LINE_HEIGHT_PX = 20;
1151
+ var VERTICAL_PADDING_PX = 8;
1141
1152
  var PromptInput = React4.forwardRef(
1142
1153
  ({
1143
1154
  value,
@@ -1153,11 +1164,28 @@ var PromptInput = React4.forwardRef(
1153
1164
  rightActions,
1154
1165
  className,
1155
1166
  inputClassName,
1156
- variant = "default"
1167
+ variant = "default",
1168
+ minRows = 1,
1169
+ maxRows = 6
1157
1170
  }, ref) => {
1171
+ const textareaRef = React4.useRef(null);
1172
+ React4.useImperativeHandle(ref, () => textareaRef.current);
1173
+ const resize = React4.useCallback(() => {
1174
+ const el = textareaRef.current;
1175
+ if (!el) return;
1176
+ el.style.height = "auto";
1177
+ const maxHeight = maxRows * LINE_HEIGHT_PX + VERTICAL_PADDING_PX;
1178
+ const minHeight = minRows * LINE_HEIGHT_PX + VERTICAL_PADDING_PX;
1179
+ const next = Math.min(Math.max(el.scrollHeight, minHeight), maxHeight);
1180
+ el.style.height = `${next}px`;
1181
+ el.style.overflowY = el.scrollHeight > maxHeight ? "auto" : "hidden";
1182
+ }, [maxRows, minRows]);
1183
+ React4.useLayoutEffect(() => {
1184
+ resize();
1185
+ }, [value, resize]);
1158
1186
  const handleSubmit = React4.useCallback(
1159
1187
  (e) => {
1160
- e.preventDefault();
1188
+ e?.preventDefault();
1161
1189
  if (!value.trim() || disabled || loading) return;
1162
1190
  onSubmit();
1163
1191
  },
@@ -1167,7 +1195,7 @@ var PromptInput = React4.forwardRef(
1167
1195
  (e) => {
1168
1196
  if (e.key === "Enter" && !e.shiftKey) {
1169
1197
  e.preventDefault();
1170
- handleSubmit(e);
1198
+ handleSubmit();
1171
1199
  }
1172
1200
  },
1173
1201
  [handleSubmit]
@@ -1178,48 +1206,65 @@ var PromptInput = React4.forwardRef(
1178
1206
  bordered: "border rounded-lg px-3 py-2.5"
1179
1207
  };
1180
1208
  const inputVariantStyles = {
1181
- default: "h-9 border-0 bg-transparent shadow-none focus-visible:ring-0",
1182
- minimal: "h-8 border-0 bg-transparent shadow-none focus-visible:ring-0 px-0",
1183
- bordered: "h-9 border-0 bg-muted/50 shadow-none focus-visible:ring-0"
1209
+ default: "bg-transparent",
1210
+ minimal: "bg-transparent px-0",
1211
+ bordered: "bg-muted/50"
1184
1212
  };
1213
+ return /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleSubmit, className: cn(variantStyles[variant], className), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
1214
+ leftActions,
1215
+ /* @__PURE__ */ jsxRuntime.jsx(
1216
+ "textarea",
1217
+ {
1218
+ ref: textareaRef,
1219
+ value,
1220
+ onChange: (e) => onChange(e.target.value),
1221
+ onKeyDown: handleKeyDown,
1222
+ placeholder,
1223
+ disabled: disabled || loading,
1224
+ autoFocus,
1225
+ rows: minRows,
1226
+ className: cn(
1227
+ "flex-1 resize-none border-0 px-0 py-1 text-sm leading-5 shadow-none",
1228
+ "placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-0",
1229
+ "disabled:cursor-not-allowed disabled:opacity-50",
1230
+ inputVariantStyles[variant],
1231
+ inputClassName
1232
+ )
1233
+ }
1234
+ ),
1235
+ rightActions,
1236
+ showSendButton && /* @__PURE__ */ jsxRuntime.jsx(
1237
+ Button,
1238
+ {
1239
+ type: "submit",
1240
+ size: "sm",
1241
+ variant: variant === "minimal" ? "ghost" : "outline",
1242
+ disabled: !value.trim() || disabled || loading,
1243
+ className: "size-8 shrink-0 p-0",
1244
+ children: sendButtonContent || /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SendIcon, { className: "size-4" })
1245
+ }
1246
+ )
1247
+ ] }) });
1248
+ }
1249
+ );
1250
+ PromptInput.displayName = "PromptInput";
1251
+ var Input = React4__namespace.forwardRef(
1252
+ ({ className, type, ...props }, ref) => {
1185
1253
  return /* @__PURE__ */ jsxRuntime.jsx(
1186
- "form",
1254
+ "input",
1187
1255
  {
1188
- onSubmit: handleSubmit,
1189
- className: cn(variantStyles[variant], className),
1190
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
1191
- leftActions,
1192
- /* @__PURE__ */ jsxRuntime.jsx(
1193
- Input,
1194
- {
1195
- ref,
1196
- value,
1197
- onChange: (e) => onChange(e.target.value),
1198
- onKeyDown: handleKeyDown,
1199
- placeholder,
1200
- disabled: disabled || loading,
1201
- autoFocus,
1202
- className: cn("flex-1 text-sm", inputVariantStyles[variant], inputClassName)
1203
- }
1204
- ),
1205
- rightActions,
1206
- showSendButton && /* @__PURE__ */ jsxRuntime.jsx(
1207
- Button,
1208
- {
1209
- type: "submit",
1210
- size: "sm",
1211
- variant: variant === "minimal" ? "ghost" : "outline",
1212
- disabled: !value.trim() || disabled || loading,
1213
- className: "size-8 shrink-0 p-0",
1214
- children: sendButtonContent || /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SendIcon, { className: "size-4" })
1215
- }
1216
- )
1217
- ] })
1256
+ type,
1257
+ className: cn(
1258
+ "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
1259
+ className
1260
+ ),
1261
+ ref,
1262
+ ...props
1218
1263
  }
1219
1264
  );
1220
1265
  }
1221
1266
  );
1222
- PromptInput.displayName = "PromptInput";
1267
+ Input.displayName = "Input";
1223
1268
  var attachmentIcons = {
1224
1269
  image: lucideReact.ImageIcon,
1225
1270
  audio: lucideReact.MicIcon,
@@ -6253,7 +6298,7 @@ function FloatingWidget({
6253
6298
  children,
6254
6299
  isLoading && /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, { size: "sm" })
6255
6300
  ] }) }),
6256
- quickReplies && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1.5 overflow-x-auto px-4 pb-2", children: quickReplies }),
6301
+ quickReplies && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-[40%] shrink-0 overflow-y-auto border-t bg-muted/30 px-4 py-2", children: quickReplies }),
6257
6302
  input,
6258
6303
  footer && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t px-4 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-center text-[10px] text-muted-foreground", children: footer }) })
6259
6304
  ]