@agent-native/core 0.7.82 → 0.7.83

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.
Files changed (57) hide show
  1. package/dist/cli/create.d.ts +1 -1
  2. package/dist/cli/create.d.ts.map +1 -1
  3. package/dist/cli/create.js +35 -10
  4. package/dist/cli/create.js.map +1 -1
  5. package/dist/client/FeedbackButton.d.ts +3 -2
  6. package/dist/client/FeedbackButton.d.ts.map +1 -1
  7. package/dist/client/FeedbackButton.js +18 -14
  8. package/dist/client/FeedbackButton.js.map +1 -1
  9. package/dist/client/builder-frame.d.ts +11 -0
  10. package/dist/client/builder-frame.d.ts.map +1 -1
  11. package/dist/client/builder-frame.js +40 -9
  12. package/dist/client/builder-frame.js.map +1 -1
  13. package/dist/client/composer/PromptComposer.d.ts +2 -0
  14. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  15. package/dist/client/composer/PromptComposer.js +2 -2
  16. package/dist/client/composer/PromptComposer.js.map +1 -1
  17. package/dist/client/composer/TiptapComposer.d.ts +3 -1
  18. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  19. package/dist/client/composer/TiptapComposer.js +17 -5
  20. package/dist/client/composer/TiptapComposer.js.map +1 -1
  21. package/dist/client/integrations/IntegrationsPanel.d.ts.map +1 -1
  22. package/dist/client/integrations/IntegrationsPanel.js +4 -1
  23. package/dist/client/integrations/IntegrationsPanel.js.map +1 -1
  24. package/dist/client/tools/ToolsSidebarSection.js +1 -1
  25. package/dist/client/tools/ToolsSidebarSection.js.map +1 -1
  26. package/dist/server/action-discovery.d.ts +15 -0
  27. package/dist/server/action-discovery.d.ts.map +1 -1
  28. package/dist/server/action-discovery.js +45 -0
  29. package/dist/server/action-discovery.js.map +1 -1
  30. package/dist/server/auth.d.ts +5 -4
  31. package/dist/server/auth.d.ts.map +1 -1
  32. package/dist/server/auth.js +80 -28
  33. package/dist/server/auth.js.map +1 -1
  34. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  35. package/dist/server/core-routes-plugin.js +1 -3
  36. package/dist/server/core-routes-plugin.js.map +1 -1
  37. package/dist/server/google-oauth.d.ts.map +1 -1
  38. package/dist/server/google-oauth.js +15 -3
  39. package/dist/server/google-oauth.js.map +1 -1
  40. package/dist/server/index.d.ts +2 -2
  41. package/dist/server/index.d.ts.map +1 -1
  42. package/dist/server/index.js +1 -1
  43. package/dist/server/index.js.map +1 -1
  44. package/dist/vite/client.d.ts.map +1 -1
  45. package/dist/vite/client.js +7 -0
  46. package/dist/vite/client.js.map +1 -1
  47. package/docs/content/template-analytics.md +10 -0
  48. package/docs/content/template-calendar.md +10 -0
  49. package/docs/content/template-clips.md +10 -0
  50. package/docs/content/template-content.md +10 -0
  51. package/docs/content/template-dispatch.md +10 -0
  52. package/docs/content/template-forms.md +10 -0
  53. package/docs/content/template-mail.md +10 -0
  54. package/docs/content/template-slides.md +11 -1
  55. package/docs/content/template-starter.md +10 -0
  56. package/docs/content/template-video.md +10 -0
  57. package/package.json +1 -1
@@ -6,6 +6,9 @@ import { IconMessage2, IconCheck } from "@tabler/icons-react";
6
6
  import { cn } from "./utils.js";
7
7
  import { useSession } from "./use-session.js";
8
8
  const DEFAULT_FEEDBACK_URL = "https://forms.agent-native.com/f/agent-native-feedback/_16ewV";
9
+ const DEFAULT_PLACEHOLDER = "Tell us what's on your mind…";
10
+ const DEFAULT_SUBMIT_TEXT = "Send feedback";
11
+ const DEFAULT_SUCCESS_MESSAGE = "Thanks for the feedback!";
9
12
  function parseTarget(url) {
10
13
  try {
11
14
  const u = new URL(url);
@@ -37,13 +40,7 @@ async function loadSchema(target) {
37
40
  body.fields[0];
38
41
  if (!field)
39
42
  throw new Error("form has no fields");
40
- return {
41
- formId: body.id,
42
- fieldId: field.id,
43
- placeholder: field.placeholder,
44
- submitText: body.settings?.submitText ?? "Send feedback",
45
- successMessage: body.settings?.successMessage ?? "Thanks for the feedback!",
46
- };
43
+ return { formId: body.id, fieldId: field.id };
47
44
  })();
48
45
  pending.catch(() => schemaCache.delete(key));
49
46
  schemaCache.set(key, pending);
@@ -138,15 +135,22 @@ export function FeedbackButton({ variant = "sidebar", label = "Feedback", url =
138
135
  setError(err instanceof Error ? err.message : "Couldn't send feedback");
139
136
  }
140
137
  }, [target, schema, value, honeypot, submitting, session?.email]);
141
- const trigger = variant === "icon" ? (_jsx(TooltipPrimitive.Provider, { delayDuration: 200, children: _jsxs(TooltipPrimitive.Root, { children: [_jsx(TooltipPrimitive.Trigger, { asChild: true, children: _jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": label, className: cn("flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent/50", className), children: _jsx(IconMessage2, { size: 14 }) }) }) }), _jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { sideOffset: 6, className: "z-[230] overflow-hidden rounded-md border border-border bg-popover px-2 py-1 text-[11px] text-foreground shadow-md animate-in fade-in-0 zoom-in-95", children: label }) })] }) })) : (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs("button", { type: "button", className: cn("flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground", className), children: [_jsx(IconMessage2, { className: "h-4 w-4" }), _jsx("span", { children: label })] }) }));
142
- const resolvedSide = side ?? (variant === "icon" ? "bottom" : "top");
143
- const resolvedPlaceholder = placeholder ?? schema?.placeholder ?? "Tell us what's on your mind…";
144
- return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [trigger, _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { side: resolvedSide, align: align, sideOffset: 8, collisionPadding: 16, className: "z-[300] overflow-hidden rounded-lg border border-border bg-popover shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", style: surfaceStyle, children: submitted ? (_jsxs("div", { className: "flex flex-col items-center justify-center gap-3 px-6 py-10 text-center", children: [_jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500", children: _jsx(IconCheck, { size: 20, stroke: 2.5 }) }), _jsx("div", { className: "text-sm font-medium text-foreground", children: schema?.successMessage ?? "Thanks for the feedback!" })] })) : (_jsxs("form", { onSubmit: submit, className: "flex flex-col gap-3 p-3", children: [_jsx("textarea", { ref: textareaRef, value: value, onChange: (e) => setValue(e.target.value), onKeyDown: (e) => {
138
+ let trigger;
139
+ if (variant === "icon") {
140
+ trigger = (_jsx(TooltipPrimitive.Provider, { delayDuration: 200, children: _jsxs(TooltipPrimitive.Root, { children: [_jsx(TooltipPrimitive.Trigger, { asChild: true, children: _jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": label, className: cn("flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent/50", className), children: _jsx(IconMessage2, { size: 14 }) }) }) }), _jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Content, { sideOffset: 6, className: "z-[230] overflow-hidden rounded-md border border-border bg-popover px-2 py-1 text-[11px] text-foreground shadow-md animate-in fade-in-0 zoom-in-95", children: label }) })] }) }));
141
+ }
142
+ else if (variant === "outlined") {
143
+ trigger = (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs("button", { type: "button", "aria-label": label, className: cn("flex h-8 items-center gap-2 rounded-md border border-border bg-transparent px-3 text-sm text-muted-foreground transition hover:border-foreground/40 hover:text-foreground", className), children: [_jsx(IconMessage2, { size: 14, stroke: 1.5 }), _jsx("span", { children: label })] }) }));
144
+ }
145
+ else {
146
+ trigger = (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs("button", { type: "button", className: cn("flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground", className), children: [_jsx(IconMessage2, { className: "h-4 w-4" }), _jsx("span", { children: label })] }) }));
147
+ }
148
+ const resolvedSide = side ?? (variant === "sidebar" ? "top" : "bottom");
149
+ const resolvedPlaceholder = placeholder ?? DEFAULT_PLACEHOLDER;
150
+ return (_jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [trigger, _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { side: resolvedSide, align: align, sideOffset: 8, collisionPadding: 16, className: "z-[300] overflow-hidden rounded-lg border border-border bg-popover shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", style: surfaceStyle, children: submitted ? (_jsxs("div", { className: "flex flex-col items-center justify-center gap-3 px-6 py-10 text-center", children: [_jsx("div", { className: "flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500", children: _jsx(IconCheck, { size: 20, stroke: 2.5 }) }), _jsx("div", { className: "text-sm font-medium text-foreground", children: DEFAULT_SUCCESS_MESSAGE })] })) : (_jsxs("form", { onSubmit: submit, className: "flex flex-col gap-3 p-3", children: [_jsx("textarea", { ref: textareaRef, value: value, onChange: (e) => setValue(e.target.value), onKeyDown: (e) => {
145
151
  if ((e.metaKey || e.ctrlKey) && e.key === "Enter")
146
152
  submit();
147
153
  }, placeholder: resolvedPlaceholder, rows: 5, maxLength: 10000, className: "w-full resize-none rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring" }), _jsx("input", { type: "text", tabIndex: -1, autoComplete: "off", "aria-hidden": "true", value: honeypot, onChange: (e) => setHoneypot(e.target.value), style: honeypotStyle }), _jsxs("div", { className: "flex items-center justify-between gap-3", children: [_jsx("div", { className: cn("text-[11px]", error ? "text-destructive" : "text-muted-foreground/75"), children: error ??
148
- `${/Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl"}+Enter to send` }), _jsx("button", { type: "submit", disabled: submitting || !value.trim(), className: "inline-flex h-8 items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50", children: submitting
149
- ? "Sending…"
150
- : (schema?.submitText ?? "Send feedback") })] })] })) }) })] }));
154
+ `${/Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl"}+Enter to send` }), _jsx("button", { type: "submit", disabled: submitting || !value.trim(), className: "inline-flex h-8 items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50", children: submitting ? "Sending…" : DEFAULT_SUBMIT_TEXT })] })] })) }) })] }));
151
155
  }
152
156
  //# sourceMappingURL=FeedbackButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FeedbackButton.js","sourceRoot":"","sources":["../../src/client/FeedbackButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,WAAW,GAGZ,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,gBAAgB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,oBAAoB,GACxB,+DAA+D,CAAC;AAelE,SAAS,WAAW,CAAC,GAAW;IAC9B,IAAI,CAAC;QACH,MAAM,CAAC,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AC,CAAC,0BAA0B,CACxD,YAEA,KAAK;4CACJ,GAAG,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,gBAAgB,GAC3E,EACN,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACrC,SAAS,EAAC,4JAA4J,YAErK,UAAU;4CACT,CAAC,CAAC,UAAU;4CACZ,CAAC,CAAC,CAAC,MAAM,EAAE,UAAU,IAAI,eAAe,CAAC,GACpC,IACL,IACD,CACR,GACwB,GACH,IACJ,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import {\n useState,\n useEffect,\n useRef,\n useCallback,\n type CSSProperties,\n type FormEvent,\n} from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport * as TooltipPrimitive from \"@radix-ui/react-tooltip\";\nimport { IconMessage2, IconCheck } from \"@tabler/icons-react\";\nimport { cn } from \"./utils.js\";\nimport { useSession } from \"./use-session.js\";\n\nconst DEFAULT_FEEDBACK_URL =\n \"https://forms.agent-native.com/f/agent-native-feedback/_16ewV\";\n\ninterface ParsedTarget {\n endpoint: string;\n slug: string;\n}\n\ninterface FormSchema {\n formId: string;\n fieldId: string;\n placeholder?: string;\n submitText: string;\n successMessage: string;\n}\n\nfunction parseTarget(url: string): ParsedTarget | null {\n try {\n const u = new URL(url);\n const idx = u.pathname.indexOf(\"/f/\");\n if (idx === -1) return null;\n const slug = u.pathname.slice(idx + 3).replace(/\\/$/, \"\");\n if (!slug) return null;\n return { endpoint: u.origin, slug };\n } catch {\n return null;\n }\n}\n\nconst schemaCache = new Map<string, Promise<FormSchema>>();\n\nasync function loadSchema(target: ParsedTarget): Promise<FormSchema> {\n const key = `${target.endpoint}|${target.slug}`;\n let pending = schemaCache.get(key);\n if (pending) return pending;\n pending = (async () => {\n const res = await fetch(\n `${target.endpoint}/api/forms/public/${encodeURIComponent(target.slug)}`,\n { headers: { Accept: \"application/json\" } },\n );\n if (!res.ok) throw new Error(`form fetch ${res.status}`);\n const body = (await res.json()) as {\n id: string;\n fields: Array<{ id: string; type: string; placeholder?: string }>;\n settings?: { submitText?: string; successMessage?: string };\n };\n const field =\n body.fields.find((f) => f.type === \"textarea\") ??\n body.fields.find((f) => f.type === \"text\") ??\n body.fields[0];\n if (!field) throw new Error(\"form has no fields\");\n return {\n formId: body.id,\n fieldId: field.id,\n placeholder: field.placeholder,\n submitText: body.settings?.submitText ?? \"Send feedback\",\n successMessage:\n body.settings?.successMessage ?? \"Thanks for the feedback!\",\n };\n })();\n pending.catch(() => schemaCache.delete(key));\n schemaCache.set(key, pending);\n return pending;\n}\n\nexport interface FeedbackButtonProps {\n /**\n * \"sidebar\" renders a full-width row with icon + label (for app left sidebars).\n * \"icon\" renders a small icon-only button (for dense toolbars, e.g. the agent panel header).\n */\n variant?: \"sidebar\" | \"icon\";\n label?: string;\n url?: string;\n className?: string;\n /** Which side the popover opens on. Defaults match the variant. */\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n /** Placeholder text for the textarea. Falls back to the form's placeholder. */\n placeholder?: string;\n}\n\nconst surfaceStyle: CSSProperties = {\n width: \"min(380px, calc(100vw - 32px))\",\n};\n\nconst honeypotStyle: CSSProperties = {\n position: \"absolute\",\n left: \"-10000px\",\n top: \"auto\",\n width: \"1px\",\n height: \"1px\",\n overflow: \"hidden\",\n};\n\nexport function FeedbackButton({\n variant = \"sidebar\",\n label = \"Feedback\",\n url = DEFAULT_FEEDBACK_URL,\n className,\n side,\n align = \"end\",\n placeholder,\n}: FeedbackButtonProps) {\n const target = parseTarget(url);\n const { session } = useSession();\n\n const [open, setOpen] = useState(false);\n const [value, setValue] = useState(\"\");\n const [honeypot, setHoneypot] = useState(\"\");\n const [submitting, setSubmitting] = useState(false);\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [schema, setSchema] = useState<FormSchema | null>(null);\n const openedAtRef = useRef<number>(0);\n const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n // Reset transient state and kick off schema load on each open.\n useEffect(() => {\n if (!open) return;\n openedAtRef.current = Date.now();\n setValue(\"\");\n setHoneypot(\"\");\n setSubmitting(false);\n setSubmitted(false);\n setError(null);\n if (target) {\n loadSchema(target)\n .then((s) => setSchema(s))\n .catch((err) => {\n console.error(\"[FeedbackButton] schema load failed\", err);\n setError(\"Couldn't load feedback form\");\n });\n } else {\n setError(\"Invalid feedback URL\");\n }\n const t = setTimeout(() => textareaRef.current?.focus(), 30);\n return () => {\n clearTimeout(t);\n if (closeTimerRef.current) {\n clearTimeout(closeTimerRef.current);\n closeTimerRef.current = null;\n }\n };\n }, [open, url]);\n\n const submit = useCallback(\n async (e?: FormEvent) => {\n e?.preventDefault();\n if (!target || !schema || submitting) return;\n const trimmed = value.trim();\n if (!trimmed) {\n setError(\"Please write something first\");\n return;\n }\n setSubmitting(true);\n setError(null);\n try {\n const submitterEmail = session?.email;\n const res = await fetch(\n `${target.endpoint}/api/submit/${encodeURIComponent(schema.formId)}`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n data: { [schema.fieldId]: trimmed },\n _t: openedAtRef.current,\n _hp: honeypot,\n ...(submitterEmail ? { _meta: { submitterEmail } } : {}),\n }),\n },\n );\n if (!res.ok) {\n const body = (await res.json().catch(() => ({}))) as {\n error?: string;\n };\n throw new Error(body.error || `submit failed (${res.status})`);\n }\n setSubmitted(true);\n closeTimerRef.current = setTimeout(() => setOpen(false), 1400);\n } catch (err) {\n setSubmitting(false);\n setError(err instanceof Error ? err.message : \"Couldn't send feedback\");\n }\n },\n [target, schema, value, honeypot, submitting, session?.email],\n );\n\n const trigger =\n variant === \"icon\" ? (\n <TooltipPrimitive.Provider delayDuration={200}>\n <TooltipPrimitive.Root>\n <TooltipPrimitive.Trigger asChild>\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n aria-label={label}\n className={cn(\n \"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent/50\",\n className,\n )}\n >\n <IconMessage2 size={14} />\n </button>\n </PopoverPrimitive.Trigger>\n </TooltipPrimitive.Trigger>\n <TooltipPrimitive.Portal>\n <TooltipPrimitive.Content\n sideOffset={6}\n className=\"z-[230] overflow-hidden rounded-md border border-border bg-popover px-2 py-1 text-[11px] text-foreground shadow-md animate-in fade-in-0 zoom-in-95\"\n >\n {label}\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n </TooltipPrimitive.Provider>\n ) : (\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n className={cn(\n \"flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground\",\n className,\n )}\n >\n <IconMessage2 className=\"h-4 w-4\" />\n <span>{label}</span>\n </button>\n </PopoverPrimitive.Trigger>\n );\n\n const resolvedSide = side ?? (variant === \"icon\" ? \"bottom\" : \"top\");\n const resolvedPlaceholder =\n placeholder ?? schema?.placeholder ?? \"Tell us what's on your mind…\";\n\n return (\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n {trigger}\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n side={resolvedSide}\n align={align}\n sideOffset={8}\n collisionPadding={16}\n className=\"z-[300] overflow-hidden rounded-lg border border-border bg-popover shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2\"\n style={surfaceStyle}\n >\n {submitted ? (\n <div className=\"flex flex-col items-center justify-center gap-3 px-6 py-10 text-center\">\n <div className=\"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500\">\n <IconCheck size={20} stroke={2.5} />\n </div>\n <div className=\"text-sm font-medium text-foreground\">\n {schema?.successMessage ?? \"Thanks for the feedback!\"}\n </div>\n </div>\n ) : (\n <form onSubmit={submit} className=\"flex flex-col gap-3 p-3\">\n <textarea\n ref={textareaRef}\n value={value}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => {\n if ((e.metaKey || e.ctrlKey) && e.key === \"Enter\") submit();\n }}\n placeholder={resolvedPlaceholder}\n rows={5}\n maxLength={10000}\n className=\"w-full resize-none rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <input\n type=\"text\"\n tabIndex={-1}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n value={honeypot}\n onChange={(e) => setHoneypot(e.target.value)}\n style={honeypotStyle}\n />\n <div className=\"flex items-center justify-between gap-3\">\n <div\n className={cn(\n \"text-[11px]\",\n error ? \"text-destructive\" : \"text-muted-foreground/75\",\n )}\n >\n {error ??\n `${/Mac|iPhone|iPad/.test(navigator.userAgent) ? \"⌘\" : \"Ctrl\"}+Enter to send`}\n </div>\n <button\n type=\"submit\"\n disabled={submitting || !value.trim()}\n className=\"inline-flex h-8 items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50\"\n >\n {submitting\n ? \"Sending…\"\n : (schema?.submitText ?? \"Send feedback\")}\n </button>\n </div>\n </form>\n )}\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n );\n}\n"]}
1
+ {"version":3,"file":"FeedbackButton.js","sourceRoot":"","sources":["../../src/client/FeedbackButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,WAAW,GAG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QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACzC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;oCACf,IAAI,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO;wCAAE,MAAM,EAAE,CAAC;gCAC9D,CAAC,EACD,WAAW,EAAE,mBAAmB,EAChC,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,KAAK,EAChB,SAAS,EAAC,qLAAqL,GAC/L,EACF,gBACE,IAAI,EAAC,MAAM,EACX,QAAQ,EAAE,CAAC,CAAC,EACZ,YAAY,EAAC,KAAK,iBACN,MAAM,EAClB,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC5C,KAAK,EAAE,aAAa,GACpB,EACF,eAAK,SAAS,EAAC,yCAAyC,aACtD,cACE,SAAS,EAAE,EAAE,CACX,aAAa,EACb,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,0BAA0B,CACxD,YAEA,KAAK;4CACJ,GAAG,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,gBAAgB,GAC3E,EACN,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EACrC,SAAS,EAAC,4JAA4J,YAErK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,GACvC,IACL,IACD,CACR,GACwB,GACH,IACJ,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import {\n useState,\n useEffect,\n useRef,\n useCallback,\n type CSSProperties,\n type FormEvent,\n} from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport * as TooltipPrimitive from \"@radix-ui/react-tooltip\";\nimport { IconMessage2, IconCheck } from \"@tabler/icons-react\";\nimport { cn } from \"./utils.js\";\nimport { useSession } from \"./use-session.js\";\n\nconst DEFAULT_FEEDBACK_URL =\n \"https://forms.agent-native.com/f/agent-native-feedback/_16ewV\";\n\ninterface ParsedTarget {\n endpoint: string;\n slug: string;\n}\n\ninterface FormSchema {\n formId: string;\n fieldId: string;\n}\n\nconst DEFAULT_PLACEHOLDER = \"Tell us what's on your mind…\";\nconst DEFAULT_SUBMIT_TEXT = \"Send feedback\";\nconst DEFAULT_SUCCESS_MESSAGE = \"Thanks for the feedback!\";\n\nfunction parseTarget(url: string): ParsedTarget | null {\n try {\n const u = new URL(url);\n const idx = u.pathname.indexOf(\"/f/\");\n if (idx === -1) return null;\n const slug = u.pathname.slice(idx + 3).replace(/\\/$/, \"\");\n if (!slug) return null;\n return { endpoint: u.origin, slug };\n } catch {\n return null;\n }\n}\n\nconst schemaCache = new Map<string, Promise<FormSchema>>();\n\nasync function loadSchema(target: ParsedTarget): Promise<FormSchema> {\n const key = `${target.endpoint}|${target.slug}`;\n let pending = schemaCache.get(key);\n if (pending) return pending;\n pending = (async () => {\n const res = await fetch(\n `${target.endpoint}/api/forms/public/${encodeURIComponent(target.slug)}`,\n { headers: { Accept: \"application/json\" } },\n );\n if (!res.ok) throw new Error(`form fetch ${res.status}`);\n const body = (await res.json()) as {\n id: string;\n fields: Array<{ id: string; type: string }>;\n };\n const field =\n body.fields.find((f) => f.type === \"textarea\") ??\n body.fields.find((f) => f.type === \"text\") ??\n body.fields[0];\n if (!field) throw new Error(\"form has no fields\");\n return { formId: body.id, fieldId: field.id };\n })();\n pending.catch(() => schemaCache.delete(key));\n schemaCache.set(key, pending);\n return pending;\n}\n\nexport interface FeedbackButtonProps {\n /**\n * \"sidebar\" renders a full-width row with icon + label (for app left sidebars).\n * \"icon\" renders a small icon-only button (for dense toolbars, e.g. the agent panel header).\n * \"outlined\" renders an outlined pill button with icon + label (for top-nav bars, e.g. docs).\n */\n variant?: \"sidebar\" | \"icon\" | \"outlined\";\n label?: string;\n url?: string;\n className?: string;\n /** Which side the popover opens on. Defaults match the variant. */\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n /** Placeholder text for the textarea. */\n placeholder?: string;\n}\n\nconst surfaceStyle: CSSProperties = {\n width: \"min(380px, calc(100vw - 32px))\",\n};\n\nconst honeypotStyle: CSSProperties = {\n position: \"absolute\",\n left: \"-10000px\",\n top: \"auto\",\n width: \"1px\",\n height: \"1px\",\n overflow: \"hidden\",\n};\n\nexport function FeedbackButton({\n variant = \"sidebar\",\n label = \"Feedback\",\n url = DEFAULT_FEEDBACK_URL,\n className,\n side,\n align = \"end\",\n placeholder,\n}: FeedbackButtonProps) {\n const target = parseTarget(url);\n const { session } = useSession();\n\n const [open, setOpen] = useState(false);\n const [value, setValue] = useState(\"\");\n const [honeypot, setHoneypot] = useState(\"\");\n const [submitting, setSubmitting] = useState(false);\n const [submitted, setSubmitted] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [schema, setSchema] = useState<FormSchema | null>(null);\n const openedAtRef = useRef<number>(0);\n const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n // Reset transient state and kick off schema load on each open.\n useEffect(() => {\n if (!open) return;\n openedAtRef.current = Date.now();\n setValue(\"\");\n setHoneypot(\"\");\n setSubmitting(false);\n setSubmitted(false);\n setError(null);\n if (target) {\n loadSchema(target)\n .then((s) => setSchema(s))\n .catch((err) => {\n console.error(\"[FeedbackButton] schema load failed\", err);\n setError(\"Couldn't load feedback form\");\n });\n } else {\n setError(\"Invalid feedback URL\");\n }\n const t = setTimeout(() => textareaRef.current?.focus(), 30);\n return () => {\n clearTimeout(t);\n if (closeTimerRef.current) {\n clearTimeout(closeTimerRef.current);\n closeTimerRef.current = null;\n }\n };\n }, [open, url]);\n\n const submit = useCallback(\n async (e?: FormEvent) => {\n e?.preventDefault();\n if (!target || !schema || submitting) return;\n const trimmed = value.trim();\n if (!trimmed) {\n setError(\"Please write something first\");\n return;\n }\n setSubmitting(true);\n setError(null);\n try {\n const submitterEmail = session?.email;\n const res = await fetch(\n `${target.endpoint}/api/submit/${encodeURIComponent(schema.formId)}`,\n {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n data: { [schema.fieldId]: trimmed },\n _t: openedAtRef.current,\n _hp: honeypot,\n ...(submitterEmail ? { _meta: { submitterEmail } } : {}),\n }),\n },\n );\n if (!res.ok) {\n const body = (await res.json().catch(() => ({}))) as {\n error?: string;\n };\n throw new Error(body.error || `submit failed (${res.status})`);\n }\n setSubmitted(true);\n closeTimerRef.current = setTimeout(() => setOpen(false), 1400);\n } catch (err) {\n setSubmitting(false);\n setError(err instanceof Error ? err.message : \"Couldn't send feedback\");\n }\n },\n [target, schema, value, honeypot, submitting, session?.email],\n );\n\n let trigger;\n if (variant === \"icon\") {\n trigger = (\n <TooltipPrimitive.Provider delayDuration={200}>\n <TooltipPrimitive.Root>\n <TooltipPrimitive.Trigger asChild>\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n aria-label={label}\n className={cn(\n \"flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent/50\",\n className,\n )}\n >\n <IconMessage2 size={14} />\n </button>\n </PopoverPrimitive.Trigger>\n </TooltipPrimitive.Trigger>\n <TooltipPrimitive.Portal>\n <TooltipPrimitive.Content\n sideOffset={6}\n className=\"z-[230] overflow-hidden rounded-md border border-border bg-popover px-2 py-1 text-[11px] text-foreground shadow-md animate-in fade-in-0 zoom-in-95\"\n >\n {label}\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n </TooltipPrimitive.Provider>\n );\n } else if (variant === \"outlined\") {\n trigger = (\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n aria-label={label}\n className={cn(\n \"flex h-8 items-center gap-2 rounded-md border border-border bg-transparent px-3 text-sm text-muted-foreground transition hover:border-foreground/40 hover:text-foreground\",\n className,\n )}\n >\n <IconMessage2 size={14} stroke={1.5} />\n <span>{label}</span>\n </button>\n </PopoverPrimitive.Trigger>\n );\n } else {\n trigger = (\n <PopoverPrimitive.Trigger asChild>\n <button\n type=\"button\"\n className={cn(\n \"flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground\",\n className,\n )}\n >\n <IconMessage2 className=\"h-4 w-4\" />\n <span>{label}</span>\n </button>\n </PopoverPrimitive.Trigger>\n );\n }\n\n const resolvedSide = side ?? (variant === \"sidebar\" ? \"top\" : \"bottom\");\n const resolvedPlaceholder = placeholder ?? DEFAULT_PLACEHOLDER;\n\n return (\n <PopoverPrimitive.Root open={open} onOpenChange={setOpen}>\n {trigger}\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n side={resolvedSide}\n align={align}\n sideOffset={8}\n collisionPadding={16}\n className=\"z-[300] overflow-hidden rounded-lg border border-border bg-popover shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2\"\n style={surfaceStyle}\n >\n {submitted ? (\n <div className=\"flex flex-col items-center justify-center gap-3 px-6 py-10 text-center\">\n <div className=\"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500\">\n <IconCheck size={20} stroke={2.5} />\n </div>\n <div className=\"text-sm font-medium text-foreground\">\n {DEFAULT_SUCCESS_MESSAGE}\n </div>\n </div>\n ) : (\n <form onSubmit={submit} className=\"flex flex-col gap-3 p-3\">\n <textarea\n ref={textareaRef}\n value={value}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => {\n if ((e.metaKey || e.ctrlKey) && e.key === \"Enter\") submit();\n }}\n placeholder={resolvedPlaceholder}\n rows={5}\n maxLength={10000}\n className=\"w-full resize-none rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring\"\n />\n <input\n type=\"text\"\n tabIndex={-1}\n autoComplete=\"off\"\n aria-hidden=\"true\"\n value={honeypot}\n onChange={(e) => setHoneypot(e.target.value)}\n style={honeypotStyle}\n />\n <div className=\"flex items-center justify-between gap-3\">\n <div\n className={cn(\n \"text-[11px]\",\n error ? \"text-destructive\" : \"text-muted-foreground/75\",\n )}\n >\n {error ??\n `${/Mac|iPhone|iPad/.test(navigator.userAgent) ? \"⌘\" : \"Ctrl\"}+Enter to send`}\n </div>\n <button\n type=\"submit\"\n disabled={submitting || !value.trim()}\n className=\"inline-flex h-8 items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50\"\n >\n {submitting ? \"Sending…\" : DEFAULT_SUBMIT_TEXT}\n </button>\n </div>\n </form>\n )}\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n );\n}\n"]}
@@ -1,3 +1,14 @@
1
+ /**
2
+ * For *.builder.io / *.builder.my the parent origin alone is sufficient — those
3
+ * are Builder-owned hosts and any iframe they load is by definition a Builder
4
+ * editor session. For localhost we still require the legacy `?builder.*` query
5
+ * params, because "parent is localhost" can mean anything in dev. The params
6
+ * check existed historically as a belt-and-suspenders signal, but Builder's
7
+ * Interact mode tunnels straight to the iframe URL without appending them, so
8
+ * requiring them everywhere caused `isInBuilderFrame()` to return false for
9
+ * real Builder editor sessions and `HomeChatPanel` submissions silently fell
10
+ * through to `agentNative.submitChat` (which Builder ignores).
11
+ */
1
12
  export declare function getBuilderParentOrigin(): string | null;
2
13
  export declare function isInBuilderFrame(): boolean;
3
14
  export declare function isTrustedBuilderMessage(event: MessageEvent): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"builder-frame.d.ts","sourceRoot":"","sources":["../../src/client/builder-frame.ts"],"names":[],"mappings":"AAkDA,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAStD;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAG1C;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAKpE;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAyBnE;AAQD;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAI1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,OAAO,CAIT"}
1
+ {"version":3,"file":"builder-frame.d.ts","sourceRoot":"","sources":["../../src/client/builder-frame.ts"],"names":[],"mappings":"AA2DA;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAgBtD;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAG1C;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAKpE;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAyBnE;AAQD;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAI1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,OAAO,CAIT"}
@@ -19,7 +19,7 @@ function ancestorOrigin() {
19
19
  return fromAncestor;
20
20
  return normalizeOrigin(document.referrer);
21
21
  }
22
- function isBuilderLikeOrigin(origin) {
22
+ function isStrictBuilderHost(origin) {
23
23
  if (!origin)
24
24
  return false;
25
25
  try {
@@ -27,9 +27,20 @@ function isBuilderLikeOrigin(origin) {
27
27
  return (hostname === "builder.io" ||
28
28
  hostname.endsWith(".builder.io") ||
29
29
  hostname === "builder.my" ||
30
- hostname.endsWith(".builder.my") ||
31
- hostname === "localhost" ||
32
- hostname === "127.0.0.1");
30
+ hostname.endsWith(".builder.my"));
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ function isBuilderLikeOrigin(origin) {
37
+ if (!origin)
38
+ return false;
39
+ if (isStrictBuilderHost(origin))
40
+ return true;
41
+ try {
42
+ const hostname = new URL(origin).hostname.toLowerCase();
43
+ return hostname === "localhost" || hostname === "127.0.0.1";
33
44
  }
34
45
  catch {
35
46
  return false;
@@ -44,15 +55,35 @@ function hasBuilderPreviewParams() {
44
55
  params.has("builder.user.permissions") ||
45
56
  params.has("builder.user.role.name"));
46
57
  }
58
+ /**
59
+ * For *.builder.io / *.builder.my the parent origin alone is sufficient — those
60
+ * are Builder-owned hosts and any iframe they load is by definition a Builder
61
+ * editor session. For localhost we still require the legacy `?builder.*` query
62
+ * params, because "parent is localhost" can mean anything in dev. The params
63
+ * check existed historically as a belt-and-suspenders signal, but Builder's
64
+ * Interact mode tunnels straight to the iframe URL without appending them, so
65
+ * requiring them everywhere caused `isInBuilderFrame()` to return false for
66
+ * real Builder editor sessions and `HomeChatPanel` submissions silently fell
67
+ * through to `agentNative.submitChat` (which Builder ignores).
68
+ */
47
69
  export function getBuilderParentOrigin() {
48
70
  const frameOrigin = getFrameOrigin();
49
- if (isBuilderLikeOrigin(frameOrigin) && hasBuilderPreviewParams()) {
50
- return frameOrigin;
71
+ if (frameOrigin) {
72
+ if (isStrictBuilderHost(frameOrigin))
73
+ return frameOrigin;
74
+ if (isBuilderLikeOrigin(frameOrigin) && hasBuilderPreviewParams()) {
75
+ return frameOrigin;
76
+ }
51
77
  }
52
78
  const origin = ancestorOrigin();
53
- return isBuilderLikeOrigin(origin) && hasBuilderPreviewParams()
54
- ? origin
55
- : null;
79
+ if (origin) {
80
+ if (isStrictBuilderHost(origin))
81
+ return origin;
82
+ if (isBuilderLikeOrigin(origin) && hasBuilderPreviewParams()) {
83
+ return origin;
84
+ }
85
+ }
86
+ return null;
56
87
  }
57
88
  export function isInBuilderFrame() {
58
89
  if (typeof window === "undefined" || window.parent === window)
@@ -1 +1 @@
1
- {"version":3,"file":"builder-frame.js","sourceRoot":"","sources":["../../src/client/builder-frame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,CAAC;IAC5D,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,cAAc;IACrB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,OAAO,GACX,MAAM,CAAC,QACR,CAAC,eAAe,CAAC;IAClB,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IACtC,OAAO,eAAe,CAAC,QAAQ,CAA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E,CAAC,CACrD,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qEAAqE;AACrE,2EAA2E;AAC3E,8DAA8D;AAC9D,MAAM,qBAAqB,GACzB,kHAAkH,CAAC;AAErH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAwB;IAC/D,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gCAAgC,CAC9C,IAAwB;IAExB,IAAI,CAAC,gBAAgB,EAAE;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,OAAO,iBAAiB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import { getFrameOrigin } from \"./frame.js\";\n\nfunction normalizeOrigin(value: unknown): string | null {\n if (typeof value !== \"string\" || !value.trim()) return null;\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nfunction ancestorOrigin(): string | null {\n if (typeof window === \"undefined\") return null;\n const origins = (\n window.location as Location & { ancestorOrigins?: DOMStringList }\n ).ancestorOrigins;\n const first = origins?.[0];\n const fromAncestor = normalizeOrigin(first);\n if (fromAncestor) return fromAncestor;\n return normalizeOrigin(document.referrer);\n}\n\nfunction isBuilderLikeOrigin(origin: string | null): boolean {\n if (!origin) return false;\n try {\n const hostname = new URL(origin).hostname.toLowerCase();\n return (\n hostname === \"builder.io\" ||\n hostname.endsWith(\".builder.io\") ||\n hostname === \"builder.my\" ||\n hostname.endsWith(\".builder.my\") ||\n hostname === \"localhost\" ||\n hostname === \"127.0.0.1\"\n );\n } catch {\n return false;\n }\n}\n\nfunction hasBuilderPreviewParams(): boolean {\n if (typeof window === \"undefined\") return false;\n const params = new URLSearchParams(window.location.search);\n return (\n params.has(\"builder.space\") ||\n params.has(\"builder.preview\") ||\n params.has(\"builder.user.permissions\") ||\n params.has(\"builder.user.role.name\")\n );\n}\n\nexport function getBuilderParentOrigin(): string | null {\n const frameOrigin = getFrameOrigin();\n if (isBuilderLikeOrigin(frameOrigin) && hasBuilderPreviewParams()) {\n return frameOrigin;\n }\n const origin = ancestorOrigin();\n return isBuilderLikeOrigin(origin) && hasBuilderPreviewParams()\n ? origin\n : null;\n}\n\nexport function isInBuilderFrame(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n return getBuilderParentOrigin() !== null;\n}\n\nexport function isTrustedBuilderMessage(event: MessageEvent): boolean {\n if (typeof window === \"undefined\") return false;\n const origin = getBuilderParentOrigin();\n if (!origin) return false;\n return event.origin === origin && event.source === window.parent;\n}\n\nexport interface BuilderChatMessage {\n message: string;\n context?: string;\n submit?: boolean;\n}\n\nexport function sendToBuilderChat(opts: BuilderChatMessage): boolean {\n if (typeof window === \"undefined\" || !opts.message?.trim()) return false;\n const target = window.parent !== window ? window.parent : window;\n const targetOrigin = getBuilderParentOrigin() ?? \"*\";\n const payload = {\n type: \"builder.submitChat\",\n data: {\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n },\n };\n target.postMessage(payload, targetOrigin);\n\n // Builder's Electron/webview relay watches console output because webviews\n // cannot always post directly to the app frame. Keep the payload small and\n // never include credential values in callers' context.\n try {\n console.log(\n \"BUILDER_PARENT_MESSAGE:\" +\n JSON.stringify({ message: payload, targetOrigin }),\n );\n } catch {}\n\n return true;\n}\n\n// Detect \"build/create/make/scaffold a new app/agent\" style prompts.\n// Within agent-native, \"agent\" and \"app\" are synonyms — every agent-native\n// app is an agent, so users phrase build requests either way.\nconst BUILD_APP_OR_AGENT_RE =\n /\\b(?:build|create|make|scaffold|generate)\\b[^.!?\\n]*?\\b(?:agent[-\\s]native\\s+)?(?:workspace\\s+)?(?:app|agent)\\b/i;\n\n/**\n * Returns true if `text` looks like a \"build me an app/agent\" request that\n * should hand off to the code-writing agent (Builder, local code agent, etc.)\n * rather than be answered by the embedded app's domain agent.\n *\n * Conservative: requires both an imperative build verb AND an explicit\n * \"app\" / \"agent\" target word in the same sentence. \"Build me a tool\",\n * \"build a recurring job\", \"create a destination\" do not match — they\n * don't end in \"app\"/\"agent\" so they stay on the local agent. \"Build me\n * an email app\" / \"create me an email agent\" do match — the target\n * word is \"app\" / \"agent\", not \"email\".\n */\nexport function isBuildAppOrAgentRequest(text: string | undefined): boolean {\n const t = (text ?? \"\").trim();\n if (!t) return false;\n return BUILD_APP_OR_AGENT_RE.test(t);\n}\n\n/**\n * If the user typed a \"build me an app/agent\" prompt while running inside\n * the Builder.io webview/iframe, hand the prompt up to the parent Builder\n * chat via `builder.submitChat`. Returns true when delegated.\n *\n * Why: Builder is the code-writing agent. When a workspace app (Dispatch,\n * Mail, etc.) is mounted inside Builder's webview and the user asks the\n * embedded chat to \"build an app\", the user almost certainly means the\n * already-open Builder chat session — not a separate Builder agent run\n * spawned through `start-workspace-app-creation`.\n */\nexport function tryDelegateBuildRequestToBuilder(\n text: string | undefined,\n): boolean {\n if (!isInBuilderFrame()) return false;\n if (!isBuildAppOrAgentRequest(text)) return false;\n return sendToBuilderChat({ message: (text ?? \"\").trim(), submit: true });\n}\n"]}
1
+ {"version":3,"file":"builder-frame.js","sourceRoot":"","sources":["../../src/client/builder-frame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,SAAS,eAAe,CAAC,KAAc;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;QAAE,OAAO,IAAI,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,qBAAqB,GACzB,kHAAkH,CAAC;AAErH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAwB;IAC/D,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gCAAgC,CAC9C,IAAwB;IAExB,IAAI,CAAC,gBAAgB,EAAE;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,OAAO,iBAAiB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import { getFrameOrigin } from \"./frame.js\";\n\nfunction normalizeOrigin(value: unknown): string | null {\n if (typeof value !== \"string\" || !value.trim()) return null;\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nfunction ancestorOrigin(): string | null {\n if (typeof window === \"undefined\") return null;\n const origins = (\n window.location as Location & { ancestorOrigins?: DOMStringList }\n ).ancestorOrigins;\n const first = origins?.[0];\n const fromAncestor = normalizeOrigin(first);\n if (fromAncestor) return fromAncestor;\n return normalizeOrigin(document.referrer);\n}\n\nfunction isStrictBuilderHost(origin: string | null): boolean {\n if (!origin) return false;\n try {\n const hostname = new URL(origin).hostname.toLowerCase();\n return (\n hostname === \"builder.io\" ||\n hostname.endsWith(\".builder.io\") ||\n hostname === \"builder.my\" ||\n hostname.endsWith(\".builder.my\")\n );\n } catch {\n return false;\n }\n}\n\nfunction isBuilderLikeOrigin(origin: string | null): boolean {\n if (!origin) return false;\n if (isStrictBuilderHost(origin)) return true;\n try {\n const hostname = new URL(origin).hostname.toLowerCase();\n return hostname === \"localhost\" || hostname === \"127.0.0.1\";\n } catch {\n return false;\n }\n}\n\nfunction hasBuilderPreviewParams(): boolean {\n if (typeof window === \"undefined\") return false;\n const params = new URLSearchParams(window.location.search);\n return (\n params.has(\"builder.space\") ||\n params.has(\"builder.preview\") ||\n params.has(\"builder.user.permissions\") ||\n params.has(\"builder.user.role.name\")\n );\n}\n\n/**\n * For *.builder.io / *.builder.my the parent origin alone is sufficient — those\n * are Builder-owned hosts and any iframe they load is by definition a Builder\n * editor session. For localhost we still require the legacy `?builder.*` query\n * params, because \"parent is localhost\" can mean anything in dev. The params\n * check existed historically as a belt-and-suspenders signal, but Builder's\n * Interact mode tunnels straight to the iframe URL without appending them, so\n * requiring them everywhere caused `isInBuilderFrame()` to return false for\n * real Builder editor sessions and `HomeChatPanel` submissions silently fell\n * through to `agentNative.submitChat` (which Builder ignores).\n */\nexport function getBuilderParentOrigin(): string | null {\n const frameOrigin = getFrameOrigin();\n if (frameOrigin) {\n if (isStrictBuilderHost(frameOrigin)) return frameOrigin;\n if (isBuilderLikeOrigin(frameOrigin) && hasBuilderPreviewParams()) {\n return frameOrigin;\n }\n }\n const origin = ancestorOrigin();\n if (origin) {\n if (isStrictBuilderHost(origin)) return origin;\n if (isBuilderLikeOrigin(origin) && hasBuilderPreviewParams()) {\n return origin;\n }\n }\n return null;\n}\n\nexport function isInBuilderFrame(): boolean {\n if (typeof window === \"undefined\" || window.parent === window) return false;\n return getBuilderParentOrigin() !== null;\n}\n\nexport function isTrustedBuilderMessage(event: MessageEvent): boolean {\n if (typeof window === \"undefined\") return false;\n const origin = getBuilderParentOrigin();\n if (!origin) return false;\n return event.origin === origin && event.source === window.parent;\n}\n\nexport interface BuilderChatMessage {\n message: string;\n context?: string;\n submit?: boolean;\n}\n\nexport function sendToBuilderChat(opts: BuilderChatMessage): boolean {\n if (typeof window === \"undefined\" || !opts.message?.trim()) return false;\n const target = window.parent !== window ? window.parent : window;\n const targetOrigin = getBuilderParentOrigin() ?? \"*\";\n const payload = {\n type: \"builder.submitChat\",\n data: {\n message: opts.message,\n context: opts.context,\n submit: opts.submit,\n },\n };\n target.postMessage(payload, targetOrigin);\n\n // Builder's Electron/webview relay watches console output because webviews\n // cannot always post directly to the app frame. Keep the payload small and\n // never include credential values in callers' context.\n try {\n console.log(\n \"BUILDER_PARENT_MESSAGE:\" +\n JSON.stringify({ message: payload, targetOrigin }),\n );\n } catch {}\n\n return true;\n}\n\n// Detect \"build/create/make/scaffold a new app/agent\" style prompts.\n// Within agent-native, \"agent\" and \"app\" are synonyms — every agent-native\n// app is an agent, so users phrase build requests either way.\nconst BUILD_APP_OR_AGENT_RE =\n /\\b(?:build|create|make|scaffold|generate)\\b[^.!?\\n]*?\\b(?:agent[-\\s]native\\s+)?(?:workspace\\s+)?(?:app|agent)\\b/i;\n\n/**\n * Returns true if `text` looks like a \"build me an app/agent\" request that\n * should hand off to the code-writing agent (Builder, local code agent, etc.)\n * rather than be answered by the embedded app's domain agent.\n *\n * Conservative: requires both an imperative build verb AND an explicit\n * \"app\" / \"agent\" target word in the same sentence. \"Build me a tool\",\n * \"build a recurring job\", \"create a destination\" do not match — they\n * don't end in \"app\"/\"agent\" so they stay on the local agent. \"Build me\n * an email app\" / \"create me an email agent\" do match — the target\n * word is \"app\" / \"agent\", not \"email\".\n */\nexport function isBuildAppOrAgentRequest(text: string | undefined): boolean {\n const t = (text ?? \"\").trim();\n if (!t) return false;\n return BUILD_APP_OR_AGENT_RE.test(t);\n}\n\n/**\n * If the user typed a \"build me an app/agent\" prompt while running inside\n * the Builder.io webview/iframe, hand the prompt up to the parent Builder\n * chat via `builder.submitChat`. Returns true when delegated.\n *\n * Why: Builder is the code-writing agent. When a workspace app (Dispatch,\n * Mail, etc.) is mounted inside Builder's webview and the user asks the\n * embedded chat to \"build an app\", the user almost certainly means the\n * already-open Builder chat session — not a separate Builder agent run\n * spawned through `start-workspace-app-creation`.\n */\nexport function tryDelegateBuildRequestToBuilder(\n text: string | undefined,\n): boolean {\n if (!isInBuilderFrame()) return false;\n if (!isBuildAppOrAgentRequest(text)) return false;\n return sendToBuilderChat({ message: (text ?? \"\").trim(), submit: true });\n}\n"]}
@@ -22,6 +22,8 @@ export interface PromptComposerProps {
22
22
  voiceEnabled?: boolean;
23
23
  /** Show file upload controls and pass submitted files to onSubmit (default: true). */
24
24
  attachmentsEnabled?: boolean;
25
+ /** Called whenever the plain editor text changes. */
26
+ onTextChange?: (text: string) => void;
25
27
  /** Imperative handle for focusing the composer. */
26
28
  composerRef?: Ref<TiptapComposerHandle>;
27
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PromptComposer.d.ts","sourceRoot":"","sources":["../../../src/client/composer/PromptComposer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA2C,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAuB1E,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,kBAAkB,EAAE,EAC3B,UAAU,EAAE,SAAS,EAAE,KACpB,IAAI,CAAC;IACV,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,uDAAuD;IACvD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sFAAsF;IACtF,kBAAkB,CAAC,EAAE,OAAO,CA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CAqBxD"}
@@ -77,7 +77,7 @@ function PromptAttachmentStrip() {
77
77
  return null;
78
78
  return (_jsx("div", { className: "flex flex-wrap gap-2 px-2 pt-2", children: attachments.map((attachment) => (_jsx(AttachmentChip, { attachment: attachment, onRemove: handleRemove }, attachment.id))) }));
79
79
  }
80
- function PromptComposerInner({ onSubmit, placeholder, disabled, autoFocus, className, draftScope, showModelSelector = true, voiceEnabled = true, attachmentsEnabled = true, composerRef, }) {
80
+ function PromptComposerInner({ onSubmit, placeholder, disabled, autoFocus, className, draftScope, showModelSelector = true, voiceEnabled = true, attachmentsEnabled = true, onTextChange, composerRef, }) {
81
81
  const localRef = useRef(null);
82
82
  const handleRef = composerRef ?? localRef;
83
83
  const models = useChatModels();
@@ -125,7 +125,7 @@ function PromptComposerInner({ onSubmit, placeholder, disabled, autoFocus, class
125
125
  : text;
126
126
  onSubmit(finalText, files, references);
127
127
  }, [onSubmit]);
128
- return (_jsx("div", { className: cn("agent-composer-area flex flex-col rounded-lg border border-input bg-background focus-within:ring-1 focus-within:ring-ring", className), children: _jsxs(ComposerPrimitive.Root, { className: "flex flex-col", children: [_jsx(PromptAttachmentStrip, {}), _jsx(TiptapComposer, { focusRef: handleRef, disabled: disabled, placeholder: placeholder, onSubmit: handleSubmit, plusMenuMode: attachmentsEnabled ? "upload-only" : "hidden", voiceEnabled: voiceEnabled, draftScope: draftScope, selectedModel: showModelSelector ? models.selectedModel : undefined, selectedEffort: showModelSelector ? models.selectedEffort : undefined, availableModels: showModelSelector ? models.availableModels : undefined, onModelChange: showModelSelector ? models.onModelChange : undefined, onEffortChange: showModelSelector ? models.onEffortChange : undefined })] }) }));
128
+ return (_jsx("div", { className: cn("agent-composer-area flex flex-col rounded-lg border border-input bg-background focus-within:ring-1 focus-within:ring-ring", className), children: _jsxs(ComposerPrimitive.Root, { className: "flex flex-col", children: [_jsx(PromptAttachmentStrip, {}), _jsx(TiptapComposer, { focusRef: handleRef, disabled: disabled, placeholder: placeholder, onSubmit: handleSubmit, plusMenuMode: attachmentsEnabled ? "upload-only" : "hidden", voiceEnabled: voiceEnabled, onTextChange: onTextChange, draftScope: draftScope, selectedModel: showModelSelector ? models.selectedModel : undefined, selectedEffort: showModelSelector ? models.selectedEffort : undefined, availableModels: showModelSelector ? models.availableModels : undefined, onModelChange: showModelSelector ? models.onModelChange : undefined, onEffortChange: showModelSelector ? models.onEffortChange : undefined })] }) }));
129
129
  }
130
130
  /**
131
131
  * Standalone composer that mirrors the agent sidebar's input experience —
@@ -1 +1 @@
1
- {"version":3,"file":"PromptComposer.js","sourceRoot":"","sources":["../../../src/client/composer/PromptComposer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAY,MAAM,OAAO,CAAC;AAC1E,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,MAAM,EACN,WAAW,EACX,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAgCrD,sEAAsE;AACtE,mEAAmE;AACnE,sEAAsE;AACtE,MAAM,YAAY,GAAqB;IACrC,KAAK,CAAC,CAAC,GAAG;QACR,OAAO;IACT,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,+BAA+B;IAC5B,MAAM,GACX,sGAAsG,CAAC;IAElG,KAAK,CAAC,GAAG,CAAC,KAAqB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,IAAI,4BAA4B,EAAE;QAClC,IAAI,+BAA+B,EAAE;QACrC,IAAI,2BAA2B,EAAE;KAClC,CAAC,EACJ,EAAE,CACH,CAAC;IACF,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,EAAE;QAC5C,QAAQ,EAAE,EAAE,WAAW,EAAE,iBAAiB,EAAE;KAC7C,CAAC,CAAC;IAEH,OAAO,CACL,KAAC,wBAAwB,IAAC,OAAO,EAAE,OAAO,YACxC,KAAC,eAAe,CAAC,IAAI,IAAC,SAAS,EAAC,UAAU,YACxC,KAAC,mBAAmB,OAAK,KAAK,GAAI,GACb,GACE,CAC5B,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, type Ref } from \"react\";\nimport {\n AssistantRuntimeProvider,\n ComposerPrimitive,\n ThreadPrimitive,\n useAui,\n useComposer,\n useLocalRuntime,\n} from \"@assistant-ui/react\";\nimport type {\n Attachment,\n AttachmentAdapter,\n ChatModelAdapter,\n CompleteAttachment,\n PendingAttachment,\n} from \"@assistant-ui/react\";\nimport {\n CompositeAttachmentAdapter,\n SimpleImageAttachmentAdapter,\n SimpleTextAttachmentAdapter,\n} from \"@assistant-ui/react\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../utils.js\";\nimport { TiptapComposer, type TiptapComposerHandle } from \"./TiptapComposer.js\";\nimport type { Reference } from \"./types.js\";\nimport { useChatModels } from \"../use-chat-models.js\";\nimport { isPastedTextAttachmentName } from \"./pasted-text.js\";\nimport { PastedTextChip } from \"./PastedTextChip.js\";\n\n/**\n * Files the user attached via the \"+\" button in PromptComposer. The host owns\n * what to do with them — typically POST to a per-app upload endpoint and pass\n * the resulting URLs/paths into the prompt that gets sent to the agent.\n */\nexport type PromptComposerFile = File;\n\nexport interface PromptComposerProps {\n /** Called when the user submits the composer. */\n onSubmit: (\n text: string,\n files: PromptComposerFile[],\n references: Reference[],\n ) => void;\n placeholder?: string;\n disabled?: boolean;\n autoFocus?: boolean;\n className?: string;\n /** Forwarded to TiptapComposer for draft persistence. */\n draftScope?: string;\n /** Show the model selector (default: true). */\n showModelSelector?: boolean;\n /** Show the voice dictation button (default: true). */\n voiceEnabled?: boolean;\n /** Show file upload controls and pass submitted files to onSubmit (default: true). */\n attachmentsEnabled?: boolean;\n /** Imperative handle for focusing the composer. */\n composerRef?: Ref<TiptapComposerHandle>;\n}\n\n// Minimal pass-through adapter. PromptComposer always submits through\n// onSubmitOverride, so the runtime never actually calls this — but\n// `useLocalRuntime` needs *something* shaped like a ChatModelAdapter.\nconst NOOP_ADAPTER: ChatModelAdapter = {\n async *run() {\n return;\n },\n};\n\n/**\n * Local clone of AssistantChat's BinaryDocumentAttachmentAdapter so PDFs and\n * PPTX files can be attached without dragging the whole assistant chat module\n * into bundles that just want a prompt popover.\n */\nclass BinaryDocumentAttachmentAdapter implements AttachmentAdapter {\n public accept =\n \"application/pdf,application/vnd.openxmlformats-officedocument.presentationml.presentation,.pdf,.pptx\";\n\n public async add(state: { file: File }): Promise<PendingAttachment> {\n return {\n id: state.file.name,\n type: \"document\",\n name: state.file.name,\n contentType: state.file.type || \"application/octet-stream\",\n file: state.file,\n status: { type: \"requires-action\", reason: \"composer-send\" },\n };\n }\n\n public async send(\n attachment: PendingAttachment,\n ): Promise<CompleteAttachment> {\n return {\n ...attachment,\n status: { type: \"complete\" },\n content: [],\n };\n }\n\n public async remove() {\n /* noop */\n }\n}\n\nfunction getImageSrc(attachment: Attachment): string | null {\n if (attachment.type !== \"image\") return null;\n if (\"file\" in attachment && attachment.file) {\n return URL.createObjectURL(attachment.file);\n }\n const imagePart = attachment.content?.find((part) => part.type === \"image\");\n return imagePart && \"image\" in imagePart ? imagePart.image : null;\n}\n\nfunction AttachmentChip({\n attachment,\n onRemove,\n}: {\n attachment: Attachment;\n onRemove: (id: string) => void;\n}) {\n const src = useMemo(() => getImageSrc(attachment), [attachment]);\n useEffect(\n () => () => {\n if (src?.startsWith(\"blob:\")) URL.revokeObjectURL(src);\n },\n [src],\n );\n\n if (isPastedTextAttachmentName(attachment.name)) {\n return <PastedTextChip attachment={attachment} onRemove={onRemove} />;\n }\n\n if (src) {\n return (\n <div className=\"group relative h-16 w-16 overflow-hidden rounded-lg border border-border/70 bg-muted/50\">\n <img\n src={src}\n alt={attachment.name}\n className=\"h-full w-full object-cover\"\n />\n <button\n type=\"button\"\n onClick={() => onRemove(attachment.id)}\n aria-label={`Remove ${attachment.name}`}\n className=\"absolute right-1 top-1 flex h-5 w-5 cursor-pointer items-center justify-center rounded-full border border-border/60 bg-background/90 text-muted-foreground hover:text-foreground\"\n >\n <IconX className=\"h-3 w-3\" />\n </button>\n </div>\n );\n }\n\n return (\n <div className=\"group relative inline-flex max-w-[200px] items-center gap-2 rounded-md border border-border/70 bg-muted/50 px-2 py-1.5 text-xs\">\n <div className=\"flex h-6 w-6 shrink-0 items-center justify-center rounded bg-background text-[9px] font-semibold uppercase text-muted-foreground\">\n {attachment.name.split(\".\").pop() || \"file\"}\n </div>\n <span className=\"min-w-0 truncate font-medium\">{attachment.name}</span>\n <button\n type=\"button\"\n onClick={() => onRemove(attachment.id)}\n aria-label={`Remove ${attachment.name}`}\n className=\"flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground hover:text-foreground\"\n >\n <IconX className=\"h-3 w-3\" />\n </button>\n </div>\n );\n}\n\nfunction PromptAttachmentStrip() {\n const attachments = useComposer((state) => state.attachments);\n const aui = useAui();\n\n const handleRemove = useCallback(\n (id: string) => {\n void aui.composer().attachment({ id }).remove();\n },\n [aui],\n );\n\n if (attachments.length === 0) return null;\n return (\n <div className=\"flex flex-wrap gap-2 px-2 pt-2\">\n {attachments.map((attachment) => (\n <AttachmentChip\n key={attachment.id}\n attachment={attachment}\n onRemove={handleRemove}\n />\n ))}\n </div>\n );\n}\n\nfunction PromptComposerInner({\n onSubmit,\n placeholder,\n disabled,\n autoFocus,\n className,\n draftScope,\n showModelSelector = true,\n voiceEnabled = true,\n attachmentsEnabled = true,\n composerRef,\n}: PromptComposerProps) {\n const localRef = useRef<TiptapComposerHandle>(null);\n const handleRef = composerRef ?? localRef;\n const models = useChatModels();\n\n useEffect(() => {\n if (!autoFocus) return;\n const id = window.setTimeout(() => {\n const target =\n typeof handleRef === \"object\" && handleRef && \"current\" in handleRef\n ? handleRef.current\n : null;\n target?.focus();\n }, 50);\n return () => window.clearTimeout(id);\n }, [autoFocus, handleRef]);\n\n const handleSubmit = useCallback(\n async (\n text: string,\n references: Reference[],\n attachments?: ReadonlyArray<unknown>,\n ) => {\n // PromptComposer hosts (NewWorkspaceAppFlow, create-tool, create-deck,\n // …) submit a single string prompt — they don't run the assistant-ui\n // attachment send pipeline. TiptapComposer auto-converts large pastes\n // into a \"Pasted text\" chip, which would otherwise disappear into an\n // unprocessed File. Inline the chip body back into the prompt text so\n // newlines and full content survive the round-trip.\n const files: File[] = [];\n const pastedTextBlocks: string[] = [];\n for (const att of attachments ?? []) {\n const a = att as Attachment;\n if (\"file\" in a && a.file instanceof File) {\n const file = a.file;\n if (isPastedTextAttachmentName(file.name)) {\n try {\n pastedTextBlocks.push(await file.text());\n } catch {\n // If we can't read it, fall back to surfacing it as a regular\n // attachment file rather than silently losing it.\n files.push(file);\n }\n } else {\n files.push(file);\n }\n }\n }\n const finalText = pastedTextBlocks.length\n ? [text.trim(), ...pastedTextBlocks].filter(Boolean).join(\"\\n\\n\")\n : text;\n onSubmit(finalText, files, references);\n },\n [onSubmit],\n );\n\n return (\n <div\n className={cn(\n \"agent-composer-area flex flex-col rounded-lg border border-input bg-background focus-within:ring-1 focus-within:ring-ring\",\n className,\n )}\n >\n <ComposerPrimitive.Root className=\"flex flex-col\">\n <PromptAttachmentStrip />\n <TiptapComposer\n focusRef={handleRef}\n disabled={disabled}\n placeholder={placeholder}\n onSubmit={handleSubmit}\n plusMenuMode={attachmentsEnabled ? \"upload-only\" : \"hidden\"}\n voiceEnabled={voiceEnabled}\n draftScope={draftScope}\n selectedModel={showModelSelector ? models.selectedModel : undefined}\n selectedEffort={showModelSelector ? models.selectedEffort : undefined}\n availableModels={\n showModelSelector ? models.availableModels : undefined\n }\n onModelChange={showModelSelector ? models.onModelChange : undefined}\n onEffortChange={showModelSelector ? models.onEffortChange : undefined}\n />\n </ComposerPrimitive.Root>\n </div>\n );\n}\n\n/**\n * Standalone composer that mirrors the agent sidebar's input experience —\n * voice dictation, file upload, model selector, submit-on-Enter — for use in\n * popovers and inline prompt forms (create tool, create deck, create dashboard,\n * the Dispatch new-app flow, etc.).\n *\n * The host owns submission: when the user presses Enter or clicks submit,\n * `onSubmit(text, files, references)` is called. PromptComposer runs its own\n * minimal assistant-ui runtime so it can be dropped into any subtree without\n * needing the outer chat to be mounted.\n */\nexport function PromptComposer(props: PromptComposerProps) {\n const attachmentAdapter = useMemo(\n () =>\n new CompositeAttachmentAdapter([\n new SimpleImageAttachmentAdapter(),\n new BinaryDocumentAttachmentAdapter(),\n new SimpleTextAttachmentAdapter(),\n ]),\n [],\n );\n const runtime = useLocalRuntime(NOOP_ADAPTER, {\n adapters: { attachments: attachmentAdapter },\n });\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n <ThreadPrimitive.Root className=\"contents\">\n <PromptComposerInner {...props} />\n </ThreadPrimitive.Root>\n </AssistantRuntimeProvider>\n );\n}\n"]}
1
+ {"version":3,"file":"PromptComposer.js","sourceRoot":"","sources":["../../../src/client/composer/PromptComposer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAY,MAAM,OAAO,CAAC;AAC1E,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,MAAM,EACN,WAAW,EACX,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,E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c,EAAE,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,EACrE,eAAe,EACb,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,EAExD,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,EACnE,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,GACrE,IACqB,GACrB,CACP,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,MAAM,iBAAiB,GAAG,OAAO,CAC/B,GAAG,EAAE,CACH,IAAI,0BAA0B,CAAC;QAC7B,IAAI,4BAA4B,EAAE;QAClC,IAAI,+BAA+B,EAAE;QACrC,IAAI,2BAA2B,EAAE;KAClC,CAAC,EACJ,EAAE,CACH,CAAC;IACF,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,EAAE;QAC5C,QAAQ,EAAE,EAAE,WAAW,EAAE,iBAAiB,EAAE;KAC7C,CAAC,CAAC;IAEH,OAAO,CACL,KAAC,wBAAwB,IAAC,OAAO,EAAE,OAAO,YACxC,KAAC,eAAe,CAAC,IAAI,IAAC,SAAS,EAAC,UAAU,YACxC,KAAC,mBAAmB,OAAK,KAAK,GAAI,GACb,GACE,CAC5B,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, type Ref } from \"react\";\nimport {\n AssistantRuntimeProvider,\n ComposerPrimitive,\n ThreadPrimitive,\n useAui,\n useComposer,\n useLocalRuntime,\n} from \"@assistant-ui/react\";\nimport type {\n Attachment,\n AttachmentAdapter,\n ChatModelAdapter,\n CompleteAttachment,\n PendingAttachment,\n} from \"@assistant-ui/react\";\nimport {\n CompositeAttachmentAdapter,\n SimpleImageAttachmentAdapter,\n SimpleTextAttachmentAdapter,\n} from \"@assistant-ui/react\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { cn } from \"../utils.js\";\nimport { TiptapComposer, type TiptapComposerHandle } from \"./TiptapComposer.js\";\nimport type { Reference } from \"./types.js\";\nimport { useChatModels } from \"../use-chat-models.js\";\nimport { isPastedTextAttachmentName } from \"./pasted-text.js\";\nimport { PastedTextChip } from \"./PastedTextChip.js\";\n\n/**\n * Files the user attached via the \"+\" button in PromptComposer. The host owns\n * what to do with them — typically POST to a per-app upload endpoint and pass\n * the resulting URLs/paths into the prompt that gets sent to the agent.\n */\nexport type PromptComposerFile = File;\n\nexport interface PromptComposerProps {\n /** Called when the user submits the composer. */\n onSubmit: (\n text: string,\n files: PromptComposerFile[],\n references: Reference[],\n ) => void;\n placeholder?: string;\n disabled?: boolean;\n autoFocus?: boolean;\n className?: string;\n /** Forwarded to TiptapComposer for draft persistence. */\n draftScope?: string;\n /** Show the model selector (default: true). */\n showModelSelector?: boolean;\n /** Show the voice dictation button (default: true). */\n voiceEnabled?: boolean;\n /** Show file upload controls and pass submitted files to onSubmit (default: true). */\n attachmentsEnabled?: boolean;\n /** Called whenever the plain editor text changes. */\n onTextChange?: (text: string) => void;\n /** Imperative handle for focusing the composer. */\n composerRef?: Ref<TiptapComposerHandle>;\n}\n\n// Minimal pass-through adapter. PromptComposer always submits through\n// onSubmitOverride, so the runtime never actually calls this — but\n// `useLocalRuntime` needs *something* shaped like a ChatModelAdapter.\nconst NOOP_ADAPTER: ChatModelAdapter = {\n async *run() {\n return;\n },\n};\n\n/**\n * Local clone of AssistantChat's BinaryDocumentAttachmentAdapter so PDFs and\n * PPTX files can be attached without dragging the whole assistant chat module\n * into bundles that just want a prompt popover.\n */\nclass BinaryDocumentAttachmentAdapter implements AttachmentAdapter {\n public accept =\n \"application/pdf,application/vnd.openxmlformats-officedocument.presentationml.presentation,.pdf,.pptx\";\n\n public async add(state: { file: File }): Promise<PendingAttachment> {\n return {\n id: state.file.name,\n type: \"document\",\n name: state.file.name,\n contentType: state.file.type || \"application/octet-stream\",\n file: state.file,\n status: { type: \"requires-action\", reason: \"composer-send\" },\n };\n }\n\n public async send(\n attachment: PendingAttachment,\n ): Promise<CompleteAttachment> {\n return {\n ...attachment,\n status: { type: \"complete\" },\n content: [],\n };\n }\n\n public async remove() {\n /* noop */\n }\n}\n\nfunction getImageSrc(attachment: Attachment): string | null {\n if (attachment.type !== \"image\") return null;\n if (\"file\" in attachment && attachment.file) {\n return URL.createObjectURL(attachment.file);\n }\n const imagePart = attachment.content?.find((part) => part.type === \"image\");\n return imagePart && \"image\" in imagePart ? imagePart.image : null;\n}\n\nfunction AttachmentChip({\n attachment,\n onRemove,\n}: {\n attachment: Attachment;\n onRemove: (id: string) => void;\n}) {\n const src = useMemo(() => getImageSrc(attachment), [attachment]);\n useEffect(\n () => () => {\n if (src?.startsWith(\"blob:\")) URL.revokeObjectURL(src);\n },\n [src],\n );\n\n if (isPastedTextAttachmentName(attachment.name)) {\n return <PastedTextChip attachment={attachment} onRemove={onRemove} />;\n }\n\n if (src) {\n return (\n <div className=\"group relative h-16 w-16 overflow-hidden rounded-lg border border-border/70 bg-muted/50\">\n <img\n src={src}\n alt={attachment.name}\n className=\"h-full w-full object-cover\"\n />\n <button\n type=\"button\"\n onClick={() => onRemove(attachment.id)}\n aria-label={`Remove ${attachment.name}`}\n className=\"absolute right-1 top-1 flex h-5 w-5 cursor-pointer items-center justify-center rounded-full border border-border/60 bg-background/90 text-muted-foreground hover:text-foreground\"\n >\n <IconX className=\"h-3 w-3\" />\n </button>\n </div>\n );\n }\n\n return (\n <div className=\"group relative inline-flex max-w-[200px] items-center gap-2 rounded-md border border-border/70 bg-muted/50 px-2 py-1.5 text-xs\">\n <div className=\"flex h-6 w-6 shrink-0 items-center justify-center rounded bg-background text-[9px] font-semibold uppercase text-muted-foreground\">\n {attachment.name.split(\".\").pop() || \"file\"}\n </div>\n <span className=\"min-w-0 truncate font-medium\">{attachment.name}</span>\n <button\n type=\"button\"\n onClick={() => onRemove(attachment.id)}\n aria-label={`Remove ${attachment.name}`}\n className=\"flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground hover:text-foreground\"\n >\n <IconX className=\"h-3 w-3\" />\n </button>\n </div>\n );\n}\n\nfunction PromptAttachmentStrip() {\n const attachments = useComposer((state) => state.attachments);\n const aui = useAui();\n\n const handleRemove = useCallback(\n (id: string) => {\n void aui.composer().attachment({ id }).remove();\n },\n [aui],\n );\n\n if (attachments.length === 0) return null;\n return (\n <div className=\"flex flex-wrap gap-2 px-2 pt-2\">\n {attachments.map((attachment) => (\n <AttachmentChip\n key={attachment.id}\n attachment={attachment}\n onRemove={handleRemove}\n />\n ))}\n </div>\n );\n}\n\nfunction PromptComposerInner({\n onSubmit,\n placeholder,\n disabled,\n autoFocus,\n className,\n draftScope,\n showModelSelector = true,\n voiceEnabled = true,\n attachmentsEnabled = true,\n onTextChange,\n composerRef,\n}: PromptComposerProps) {\n const localRef = useRef<TiptapComposerHandle>(null);\n const handleRef = composerRef ?? localRef;\n const models = useChatModels();\n\n useEffect(() => {\n if (!autoFocus) return;\n const id = window.setTimeout(() => {\n const target =\n typeof handleRef === \"object\" && handleRef && \"current\" in handleRef\n ? handleRef.current\n : null;\n target?.focus();\n }, 50);\n return () => window.clearTimeout(id);\n }, [autoFocus, handleRef]);\n\n const handleSubmit = useCallback(\n async (\n text: string,\n references: Reference[],\n attachments?: ReadonlyArray<unknown>,\n ) => {\n // PromptComposer hosts (NewWorkspaceAppFlow, create-tool, create-deck,\n // …) submit a single string prompt — they don't run the assistant-ui\n // attachment send pipeline. TiptapComposer auto-converts large pastes\n // into a \"Pasted text\" chip, which would otherwise disappear into an\n // unprocessed File. Inline the chip body back into the prompt text so\n // newlines and full content survive the round-trip.\n const files: File[] = [];\n const pastedTextBlocks: string[] = [];\n for (const att of attachments ?? []) {\n const a = att as Attachment;\n if (\"file\" in a && a.file instanceof File) {\n const file = a.file;\n if (isPastedTextAttachmentName(file.name)) {\n try {\n pastedTextBlocks.push(await file.text());\n } catch {\n // If we can't read it, fall back to surfacing it as a regular\n // attachment file rather than silently losing it.\n files.push(file);\n }\n } else {\n files.push(file);\n }\n }\n }\n const finalText = pastedTextBlocks.length\n ? [text.trim(), ...pastedTextBlocks].filter(Boolean).join(\"\\n\\n\")\n : text;\n onSubmit(finalText, files, references);\n },\n [onSubmit],\n );\n\n return (\n <div\n className={cn(\n \"agent-composer-area flex flex-col rounded-lg border border-input bg-background focus-within:ring-1 focus-within:ring-ring\",\n className,\n )}\n >\n <ComposerPrimitive.Root className=\"flex flex-col\">\n <PromptAttachmentStrip />\n <TiptapComposer\n focusRef={handleRef}\n disabled={disabled}\n placeholder={placeholder}\n onSubmit={handleSubmit}\n plusMenuMode={attachmentsEnabled ? \"upload-only\" : \"hidden\"}\n voiceEnabled={voiceEnabled}\n onTextChange={onTextChange}\n draftScope={draftScope}\n selectedModel={showModelSelector ? models.selectedModel : undefined}\n selectedEffort={showModelSelector ? models.selectedEffort : undefined}\n availableModels={\n showModelSelector ? models.availableModels : undefined\n }\n onModelChange={showModelSelector ? models.onModelChange : undefined}\n onEffortChange={showModelSelector ? models.onEffortChange : undefined}\n />\n </ComposerPrimitive.Root>\n </div>\n );\n}\n\n/**\n * Standalone composer that mirrors the agent sidebar's input experience —\n * voice dictation, file upload, model selector, submit-on-Enter — for use in\n * popovers and inline prompt forms (create tool, create deck, create dashboard,\n * the Dispatch new-app flow, etc.).\n *\n * The host owns submission: when the user presses Enter or clicks submit,\n * `onSubmit(text, files, references)` is called. PromptComposer runs its own\n * minimal assistant-ui runtime so it can be dropped into any subtree without\n * needing the outer chat to be mounted.\n */\nexport function PromptComposer(props: PromptComposerProps) {\n const attachmentAdapter = useMemo(\n () =>\n new CompositeAttachmentAdapter([\n new SimpleImageAttachmentAdapter(),\n new BinaryDocumentAttachmentAdapter(),\n new SimpleTextAttachmentAdapter(),\n ]),\n [],\n );\n const runtime = useLocalRuntime(NOOP_ADAPTER, {\n adapters: { attachments: attachmentAdapter },\n });\n\n return (\n <AssistantRuntimeProvider runtime={runtime}>\n <ThreadPrimitive.Root className=\"contents\">\n <PromptComposerInner {...props} />\n </ThreadPrimitive.Root>\n </AssistantRuntimeProvider>\n );\n}\n"]}
@@ -15,6 +15,8 @@ interface TiptapComposerProps {
15
15
  * attachments so callers (e.g. PromptComposer) can surface uploaded files.
16
16
  */
17
17
  onSubmit?: (text: string, references: Reference[], attachments?: ReadonlyArray<unknown>) => void;
18
+ /** Called whenever the plain editor text changes. */
19
+ onTextChange?: (text: string) => void;
18
20
  /** Custom action button (e.g. stop button) to render instead of the default send button. */
19
21
  actionButton?: React.ReactNode;
20
22
  /** Extra button to render alongside the default send button (e.g. stop while running). */
@@ -64,6 +66,6 @@ interface TiptapComposerProps {
64
66
  */
65
67
  interceptBuildRequestsForBuilder?: boolean;
66
68
  }
67
- export declare function TiptapComposer({ placeholder, disabled, focusRef, onSubmit, actionButton, extraActionButton, attachButton, onSlashCommand, execMode, onExecModeChange, voiceEnabled, selectedModel, selectedEffort, availableModels, onModelChange, onEffortChange, draftScope, plusMenuMode, interceptBuildRequestsForBuilder, }: TiptapComposerProps): import("react/jsx-runtime").JSX.Element;
69
+ export declare function TiptapComposer({ placeholder, disabled, focusRef, onSubmit, onTextChange, actionButton, extraActionButton, attachButton, onSlashCommand, execMode, onExecModeChange, voiceEnabled, selectedModel, selectedEffort, availableModels, onModelChange, onEffortChange, draftScope, plusMenuMode, interceptBuildRequestsForBuilder, }: TiptapComposerProps): import("react/jsx-runtime").JSX.Element;
68
70
  export {};
69
71
  //# sourceMappingURL=TiptapComposer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TiptapComposer.d.ts","sourceRoot":"","sources":["../../../src/client/composer/TiptapComposer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAgCf,OAAO,KAAK,EAGV,SAAS,EAGV,MAAM,YAAY,CAAC;AAWpB,OAAO,EAGL,KAAK,eAAe,EAC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,GAAG,aAAa,GAAG,QAAQ,CAAC;IACjD;;;;;;;;OAQG;IACH,gCAAgC,CAAC,EAAE,OAAO,CAAC;CAC5C;AA8YD,wBAAgB,cAAc,CAAC,EAC7B,WAAgC,EAChC,QAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,YAAmB,EACnB,aAAa,EACb,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACd,UAAU,EACV,YAAqB,EACrB,gCAAwC,GACzC,EAAE,mBAAmB,2CAi6BrB"}
@@ -263,7 +263,7 @@ function ModelSelector({ model, effort = "auto", engines, onChange, onEffortChan
263
263
  : "opacity-40 cursor-default"}`, children: [_jsx("span", { className: "flex-1 min-w-0 text-[13px] text-foreground truncate", children: friendlyModelName(m) }), m === model && group.configured && (_jsx(IconCheck, { className: "h-3.5 w-3.5 shrink-0 text-blue-500" }))] }, m)))] }, groupKey));
264
264
  }), effortOptions.length > 0 && (_jsxs(_Fragment, { children: [_jsx("div", { className: "my-1 border-t border-border" }), _jsx("div", { className: "px-3 py-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wide", children: "Effort" }), effortOptions.map((option) => (_jsxs("button", { type: "button", onClick: () => onEffortChange?.(option), className: "flex w-full items-center gap-3 px-3 py-1.5 text-left hover:bg-accent/50", children: [_jsx("span", { className: "flex-1 min-w-0 text-[13px] text-foreground truncate", children: reasoningEffortLabel(option) }), option === effort && (_jsx(IconCheck, { className: "h-3.5 w-3.5 shrink-0 text-blue-500" }))] }, option)))] }))] }) })] }));
265
265
  }
266
- export function TiptapComposer({ placeholder = "Message agent...", disabled = false, focusRef, onSubmit, actionButton, extraActionButton, attachButton, onSlashCommand, execMode, onExecModeChange, voiceEnabled = true, selectedModel, selectedEffort, availableModels, onModelChange, onEffortChange, draftScope, plusMenuMode = "full", interceptBuildRequestsForBuilder = false, }) {
266
+ export function TiptapComposer({ placeholder = "Message agent...", disabled = false, focusRef, onSubmit, onTextChange, actionButton, extraActionButton, attachButton, onSlashCommand, execMode, onExecModeChange, voiceEnabled = true, selectedModel, selectedEffort, availableModels, onModelChange, onEffortChange, draftScope, plusMenuMode = "full", interceptBuildRequestsForBuilder = false, }) {
267
267
  const [popover, setPopover] = useState(null);
268
268
  const popoverRef = useRef(null);
269
269
  const composerRuntime = useComposerRuntime();
@@ -309,6 +309,8 @@ export function TiptapComposer({ placeholder = "Message agent...", disabled = fa
309
309
  filteredSkillsRef.current = filteredSkills;
310
310
  const onSlashCommandRef = useRef(onSlashCommand);
311
311
  onSlashCommandRef.current = onSlashCommand;
312
+ const onTextChangeRef = useRef(onTextChange);
313
+ onTextChangeRef.current = onTextChange;
312
314
  const closePopover = useCallback(() => {
313
315
  setPopover(null);
314
316
  popoverStateRef.current = null;
@@ -358,6 +360,7 @@ export function TiptapComposer({ placeholder = "Message agent...", disabled = fa
358
360
  ed.commands.focus("end");
359
361
  setEditorHasText(ed.state.doc.textContent.trim().length > 0);
360
362
  }
363
+ onTextChangeRef.current?.(ed.state.doc.textContent.trim());
361
364
  }
362
365
  catch { }
363
366
  },
@@ -377,6 +380,7 @@ export function TiptapComposer({ placeholder = "Message agent...", disabled = fa
377
380
  });
378
381
  }
379
382
  setEditorHasText(hasContent);
383
+ onTextChangeRef.current?.(ed.state.doc.textContent.trim());
380
384
  // Debounce-save draft to localStorage
381
385
  clearTimeout(draftTimerRef.current);
382
386
  draftTimerRef.current = setTimeout(() => {
@@ -398,24 +402,32 @@ export function TiptapComposer({ placeholder = "Message agent...", disabled = fa
398
402
  class: "flex-1 resize-none bg-transparent text-sm text-foreground outline-none leading-[1.625rem] min-h-[3.25rem] max-h-[10rem] overflow-y-auto",
399
403
  },
400
404
  handlePaste: (_view, event) => {
405
+ const pastedText = event.clipboardData?.getData("text/plain") ?? "";
401
406
  const files = Array.from(event.clipboardData?.files ?? []).filter((file) => file.type.startsWith("image/"));
402
407
  if (files.length > 0) {
403
408
  event.preventDefault();
404
- void Promise.all(files.map((file) => {
409
+ const attachments = files.map((file) => {
405
410
  // SimpleImageAttachmentAdapter uses file.name as the attachment id.
406
411
  // Clipboard images (e.g. screenshots) are typically all named
407
412
  // "image.png", so a second paste would replace the first instead of
408
413
  // appending. Prepend a unique token so each paste gets a distinct id.
409
414
  const uniqueName = `${Date.now()}-${Math.random().toString(36).slice(2)}-${file.name}`;
410
- return composerRuntime.addAttachment(new File([file], uniqueName, { type: file.type }));
411
- })).catch((error) => {
415
+ return new File([file], uniqueName, { type: file.type });
416
+ });
417
+ // Google Docs rich clipboard payloads can contain both embedded
418
+ // image files and the document text. Since handling files means we
419
+ // prevent Tiptap's default paste, preserve any text as its own chip
420
+ // instead of silently dropping the source material.
421
+ if (pastedText.trim()) {
422
+ attachments.push(createPastedTextFile(pastedText));
423
+ }
424
+ void Promise.all(attachments.map((file) => composerRuntime.addAttachment(file))).catch((error) => {
412
425
  console.error("Error adding pasted attachment:", error);
413
426
  });
414
427
  return true;
415
428
  }
416
429
  // Large text pastes turn into a `Pasted text` attachment chip so the
417
430
  // prompt stays readable. Matches Claude.ai / Claude Code's UX.
418
- const pastedText = event.clipboardData?.getData("text/plain") ?? "";
419
431
  if (shouldConvertPasteToAttachment(pastedText)) {
420
432
  event.preventDefault();
421
433
  void composerRuntime