{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-assistant-composer",
  "type": "registry:block",
  "title": "App, assistant composer",
  "description": "The box a person writes to an assistant in, drawn by ChatComposer (the one chat input): a rounded pill with + for files, attachments as chips and a round send. Five states set by the state prop: ready, filled, sending (send becomes a quiet stop), disabled (with a notice), over the length limit (red edge, count, a line on how to fix it). Enter sends, Shift+Enter adds a line; no hint line. hint is kept for stored pages and not drawn.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/chat-composer.json",
    "https://ui.klarhimmel.com/r/editing.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-assistant-composer/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-assistant-composer/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  label: req(40),\n  state: z.enum(['ready', 'filled', 'sending', 'disabled', 'over-limit']),\n  placeholder: t(80),\n  value: t(1200),\n  attachments: z.array(z.object({ name: t(40), size: t(20) })).max(3),\n  attach: req(20),\n  send: req(20),\n  stop: t(20),\n  removeLabel: t(20),\n  hint: t(120),\n  counter: t(20),\n  overLimit: t(120),\n  notice: t(120),\n});\n\nexport const spec = defineSpec({\n  type: 'app-assistant-composer',\n  aliases: ['app/assistant-composer'],\n  name: 'App, assistant composer',\n  category: 'app',\n  role: 'body',\n  description: 'The box a person writes to an assistant in, drawn by ChatComposer (the one chat input): a rounded pill with + for files, attachments as chips and a round send. Five states set by the state prop: ready, filled, sending (send becomes a quiet stop), disabled (with a notice), over the length limit (red edge, count, a line on how to fix it). Enter sends, Shift+Enter adds a line; no hint line. hint is kept for stored pages and not drawn.',\n  schema,\n  defaults: {\n    \"label\": \"Name who the message goes to\",\n    \"state\": \"filled\",\n    \"placeholder\": \"Say what to ask or have done…\",\n    \"value\": \"Write the request in full, in the person's own words: say what to change, for whom and by when. Then add what to tell the people involved. Finish with any note the next person needs.\",\n    \"attachments\": [\n      {\n        \"name\": \"first-file.pdf\",\n        \"size\": \"00 KB\"\n      },\n      {\n        \"name\": \"second-file.csv\",\n        \"size\": \"00 KB\"\n      }\n    ],\n    \"attach\": \"Attach\",\n    \"send\": \"Send\",\n    \"stop\": \"Stop\",\n    \"removeLabel\": \"Remove\",\n    \"hint\": \"\",\n    \"counter\": \"000 / 000\",\n    \"overLimit\": \"Say by how much it is over and what to do to send it.\",\n    \"notice\": \"Say why writing is closed and how to carry on.\"\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-assistant-composer/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-assistant-composer/index.tsx",
      "content": "import { useEffect, useRef, useState, type KeyboardEvent, type Ref } from 'react';\nimport { Paperclip } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { ChatComposer, ComposerChip } from '../../ui/chat-composer';\nimport { Container, Section, useEditing, useNamed } from '../_shared/kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nexport interface ComposerHandlers {\n  /** With `onChange`, the textarea is controlled by the host. Without, it starts from `props.value`. */\n  value?: string;\n  onChange?: (value: string) => void;\n  onSend?: () => void;\n  onStop?: () => void;\n  onAttach?: () => void;\n  onRemove?: (index: number) => void;\n  /** The textarea, so a host can move focus back to it (after Start over, a suggestion). */\n  inputRef?: Ref<HTMLTextAreaElement>;\n}\n\nconst WRAP = '[overflow-wrap:anywhere]';\n\n/** Enter sends, Shift+Enter keeps the new line, and a keystroke inside an IME composition is left alone. */\nexport function sendOnEnter(e: KeyboardEvent, send: () => void) {\n  if (e.key !== 'Enter' || e.shiftKey || e.nativeEvent.isComposing) return;\n  e.preventDefault();\n  send();\n}\n\nexport function Composer({ props, value, onChange, onSend, onStop, onAttach, onRemove, inputRef, showUnwired }: { props: Props } & ComposerHandlers & {\n  /** The block's own preview (the directory): draw the + even with nothing wired, so the design shows whole. A host leaves it off. */\n  showUnwired?: boolean;\n}) {\n  const editing = useEditing();\n  const { state } = props;\n  const draft = state === 'ready' ? '' : props.value;\n  const [own, setOwn] = useState(draft);\n  useEffect(() => setOwn(draft), [draft]);\n  const text = onChange ? (value ?? draft) : own;\n  const over = state === 'over-limit';\n  const off = state === 'disabled';\n  const ta = useRef<HTMLTextAreaElement | null>(null);\n  const setRef = (el: HTMLTextAreaElement | null) => {\n    ta.current = el;\n    if (typeof inputRef === 'function') inputRef(el);\n    else if (inputRef) inputRef.current = el;\n  };\n  const named = useNamed(props.label); // the label names the box: an emptied one means no box\n  if (!named) return null;\n  // The look is ChatComposer's, the one chat input every app uses (docs/agent-chat.md); this block keeps its five states as props.\n  // Over the limit: the box is held to the length it was written for, so the count and the red edge come from the composer itself.\n  const limit = over ? Math.max(1, text.length - 1) : undefined;\n  const note = over ? props.overLimit : off ? props.notice : undefined;\n  return (\n    <div className=\"min-w-0\">\n      <ChatComposer\n        label={props.label}\n        placeholder={props.placeholder}\n        value={text}\n        onChange={onChange ?? setOwn}\n        onSend={() => {\n          onSend?.();\n          ta.current?.focus();\n        }}\n        busy={state === 'sending'}\n        onStop={onStop ?? (showUnwired ? () => {} : undefined)}\n        disabled={off}\n        maxLength={limit}\n        inputRef={setRef}\n        attach={props.attach && (onAttach || showUnwired) ? { onFiles: () => onAttach?.() } : undefined}\n        labels={{ ...(props.send && { send: props.send }), ...(props.stop && { stop: props.stop }), ...(props.attach && { attach: props.attach }), count: () => props.counter ?? '' }}\n        chips={props.attachments.length > 0 ? props.attachments.map((a, i) => (\n          <ComposerChip key={i} icon={<Paperclip />} title={`${a.name}, ${a.size}`} removeLabel={`${props.removeLabel} ${a.name}`}\n            onRemove={off ? undefined : () => { onRemove?.(i); ta.current?.focus(); }}>\n            {a.name} · {a.size}\n          </ComposerChip>\n        )) : undefined}\n        note={note && <span className={WRAP}>{note}</span>}\n      />\n      {editing && (\n        // The editor's handles for every string the composer draws as plain text.\n        <dl className=\"mt-3 grid gap-1 rounded-kh bg-kh-surface-2 p-3 text-kh-caption [&_dt]:text-kh-muted\">\n          {(['label', 'placeholder', 'value', 'attach', 'send', 'stop', 'removeLabel', 'counter', 'overLimit', 'notice'] as const).map((k) => (\n            <div key={k} className=\"grid gap-0.5\"><dt>{k}</dt><Text path={[k]} value={props[k]} as=\"dd\" className=\"whitespace-pre-line\" /></div>\n          ))}\n          {props.attachments.map((a, i) => (\n            <div key={i} className=\"grid gap-0.5\"><dt>attachment {i + 1}</dt>\n              <dd><Text path={['attachments', i, 'name']} value={a.name} as=\"span\" /> <Text path={['attachments', i, 'size']} value={a.size} as=\"span\" /></dd></div>\n          ))}\n        </dl>\n      )}\n    </div>\n  );\n}\n\nfunction AppAssistantComposer({ props }: BlockProps<Props>) {\n  return (\n    <Section>\n      <Container width=\"narrow\">\n        <Composer props={props} showUnwired />\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppAssistantComposer);\n"
    }
  ]
}
